diff --git a/project/src/controllers/RagfairController.ts b/project/src/controllers/RagfairController.ts index a94bb180..32043530 100644 --- a/project/src/controllers/RagfairController.ts +++ b/project/src/controllers/RagfairController.ts @@ -103,12 +103,6 @@ export class RagfairController result.categories = this.getSpecificCategories(pmcProfile, searchRequest, result.offers); } - // Client requested "required search" - if (searchRequest.neededSearchId) - { - this.addRequiredOffersToResult(searchRequest, traderAssorts, pmcProfile, result); - } - this.addIndexValueToOffers(result.offers); // Sort offers @@ -186,7 +180,7 @@ export class RagfairController if (searchRequest.neededSearchId?.length > 0) { - return this.ragfairOfferHelper.getOffersThatRequireItem(searchRequest); + return this.ragfairOfferHelper.getOffersThatRequireItem(searchRequest, pmcProfile); } // Searching for general items @@ -213,7 +207,7 @@ export class RagfairController { offerPool = offers; } - else if ((searchRequest.linkedSearchId === "" && searchRequest.neededSearchId === "")) + else if ((!this.isLinkedSearch(searchRequest) && !this.isRequiredSearch(searchRequest))) { // Get all categories offerPool = this.ragfairOfferService.getOffers(); @@ -228,30 +222,6 @@ export class RagfairController return this.ragfairServer.getAllActiveCategories(playerHasFleaUnlocked, searchRequest, offerPool); } - /** - * Add Required offers to offers result - * @param searchRequest Client search request data - * @param assorts - * @param pmcProfile Player profile - * @param result Result object being sent back to client - */ - protected addRequiredOffersToResult( - searchRequest: ISearchRequestData, - assorts: Record, - pmcProfile: IPmcData, - result: IGetOffersResult, - ): void - { - const requiredOffers = this.ragfairRequiredItemsService.getRequiredItemsById(searchRequest.neededSearchId); - for (const requiredOffer of requiredOffers) - { - if (this.ragfairOfferHelper.isDisplayableOffer(searchRequest, null, assorts, requiredOffer, pmcProfile)) - { - result.offers.push(requiredOffer); - } - } - } - /** * Add index to all offers passed in (0-indexed) * @param offers Offers to add index value to diff --git a/project/src/helpers/RagfairOfferHelper.ts b/project/src/helpers/RagfairOfferHelper.ts index ae3fc6fa..cf2cc54b 100644 --- a/project/src/helpers/RagfairOfferHelper.ts +++ b/project/src/helpers/RagfairOfferHelper.ts @@ -31,6 +31,7 @@ import { LocaleService } from "@spt-aki/services/LocaleService"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { MailSendService } from "@spt-aki/services/MailSendService"; import { RagfairOfferService } from "@spt-aki/services/RagfairOfferService"; +import { RagfairRequiredItemsService } from "@spt-aki/services/RagfairRequiredItemsService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @@ -57,6 +58,7 @@ export class RagfairOfferHelper @inject("RagfairSortHelper") protected ragfairSortHelper: RagfairSortHelper, @inject("RagfairHelper") protected ragfairHelper: RagfairHelper, @inject("RagfairOfferService") protected ragfairOfferService: RagfairOfferService, + @inject("RagfairRequiredItemsService") protected ragfairRequiredItemsService: RagfairRequiredItemsService, @inject("LocaleService") protected localeService: LocaleService, @inject("LocalisationService") protected localisationService: LocalisationService, @inject("MailSendService") protected mailSendService: MailSendService, @@ -82,16 +84,34 @@ export class RagfairOfferHelper pmcProfile: IPmcData, ): IRagfairOffer[] { - return this.ragfairOfferService.getOffers().filter((x) => - this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, x, pmcProfile) + return this.ragfairOfferService.getOffers().filter((offer) => + this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcProfile) ); } - public getOffersThatRequireItem(searchRequest: ISearchRequestData): IRagfairOffer[] + /** + * Get matching offers that require the desired item and filter out offers from non traders if player is below ragfair unlock level + * @param searchRequest Search request from client + * @param pmcDataPlayer profile + * @returns Matching IRagfairOffer objects + */ + public getOffersThatRequireItem(searchRequest: ISearchRequestData, pmcData: IPmcData): IRagfairOffer[] { - return this.ragfairOfferService.getOffers().filter((offer) => - this.isDisplayableOfferThatNeedsItem(searchRequest, offer) - ); + // Get all offers that requre the desired item and filter out offers from non traders if player below ragifar unlock + const requiredOffers = this.ragfairRequiredItemsService.getRequiredItemsById(searchRequest.neededSearchId); + return requiredOffers.filter((offer: IRagfairOffer) => + { + if ( + pmcData.Info.Level < this.databaseServer.getTables().globals.config.RagFair.minUserLevel + && offer.user.memberType === MemberCategory.DEFAULT + ) + { + // Skip item if player is < global unlock level (default is 15) and item is from a dynamically generated source (non-trader) + return false; + } + + return true; + }); } /** @@ -684,19 +704,6 @@ 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 diff --git a/project/src/services/RagfairRequiredItemsService.ts b/project/src/services/RagfairRequiredItemsService.ts index 23e90891..94f51b78 100644 --- a/project/src/services/RagfairRequiredItemsService.ts +++ b/project/src/services/RagfairRequiredItemsService.ts @@ -1,6 +1,7 @@ import { inject, injectable } from "tsyringe"; import { PaymentHelper } from "@spt-aki/helpers/PaymentHelper"; +import { IRagfairOffer } from "@spt-aki/models/eft/ragfair/IRagfairOffer"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { RagfairOfferService } from "@spt-aki/services/RagfairOfferService"; @@ -16,9 +17,9 @@ export class RagfairRequiredItemsService ) {} - public getRequiredItemsById(searchId: string): any + public getRequiredItemsById(searchId: string): IRagfairOffer[] { - return this.requiredItemsCache[searchId] || []; + return Array.from(this.requiredItemsCache[searchId]) || []; } public buildRequiredItemTable(): void