From 5136d69050f052f0e5001a5ce05070b0f468f89d Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 2 Feb 2024 19:23:08 +0000 Subject: [PATCH] Implement flea required searching --- project/src/controllers/RagfairController.ts | 5 +++++ project/src/helpers/RagfairOfferHelper.ts | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/project/src/controllers/RagfairController.ts b/project/src/controllers/RagfairController.ts index f6713bde..83519000 100644 --- a/project/src/controllers/RagfairController.ts +++ b/project/src/controllers/RagfairController.ts @@ -184,6 +184,11 @@ export class RagfairController return this.ragfairOfferHelper.getOffersForBuild(searchRequest, itemsToAdd, traderAssorts, pmcProfile); } + if (searchRequest.neededSearchId?.length > 0) + { + return this.ragfairOfferHelper.getOffersThatRequireItem(searchRequest); + } + // Searching for general items return this.ragfairOfferHelper.getValidOffers(searchRequest, itemsToAdd, traderAssorts, pmcProfile); } diff --git a/project/src/helpers/RagfairOfferHelper.ts b/project/src/helpers/RagfairOfferHelper.ts index e6ec0bf2..26532e0f 100644 --- a/project/src/helpers/RagfairOfferHelper.ts +++ b/project/src/helpers/RagfairOfferHelper.ts @@ -87,6 +87,13 @@ export class RagfairOfferHelper ); } + public getOffersThatRequireItem(searchRequest: ISearchRequestData): IRagfairOffer[] + { + return this.ragfairOfferService.getOffers().filter((offer) => + this.isDisplayableOfferThatNeedsItem(searchRequest, offer) + ); + } + /** * Get offers from flea/traders specifically when building weapon preset * @param searchRequest Search request data @@ -673,6 +680,19 @@ export class RagfairOfferHelper return true; } + public isDisplayableOfferThatNeedsItem( + searchRequest: ISearchRequestData, + offer: IRagfairOffer, + ): boolean + { + if (offer.requirements.some(requirement => requirement._tpl === searchRequest.neededSearchId)) + { + return true; + } + + return false; + } + /** * Does the passed in item have a condition property * @param item Item to check