diff --git a/project/src/services/RagfairOfferService.ts b/project/src/services/RagfairOfferService.ts index 7b12174c..6ac95cfb 100644 --- a/project/src/services/RagfairOfferService.ts +++ b/project/src/services/RagfairOfferService.ts @@ -25,7 +25,7 @@ export class RagfairOfferService protected expiredOffers: Record = {}; protected ragfairConfig: IRagfairConfig; - protected ragfairOfferHandler: RagfairOfferHolder = new RagfairOfferHolder(); + protected ragfairOfferHandler: RagfairOfferHolder; constructor( @inject("WinstonLogger") protected logger: ILogger, @@ -41,6 +41,10 @@ export class RagfairOfferService ) { this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR); + this.ragfairOfferHandler = new RagfairOfferHolder( + this.ragfairConfig.dynamic.offerItemCount.max, + ragfairServerHelper, + ); } /** diff --git a/project/src/utils/RagfairOfferHolder.ts b/project/src/utils/RagfairOfferHolder.ts index 84dd6b09..21367593 100644 --- a/project/src/utils/RagfairOfferHolder.ts +++ b/project/src/utils/RagfairOfferHolder.ts @@ -1,3 +1,4 @@ +import { RagfairServerHelper } from "@spt-aki/helpers/RagfairServerHelper"; import { IRagfairOffer } from "@spt-aki/models/eft/ragfair/IRagfairOffer"; export class RagfairOfferHolder @@ -6,7 +7,7 @@ export class RagfairOfferHolder protected offersByTemplate: Map>; protected offersByTrader: Map>; - constructor() + constructor(protected maxOffersPerTemplate: number, protected ragfairServerHelper: RagfairServerHelper) { this.offersById = new Map(); this.offersByTemplate = new Map(); @@ -62,6 +63,15 @@ export class RagfairOfferHolder const trader = offer.user.id; const offerId = offer._id; const itemTpl = offer.items[0]._tpl; + // If its an NPC PMC offer AND we have already reached the maximum amount of possible offers + // for this template, just dont add in more + if ( + !(this.ragfairServerHelper.isTrader(trader) || this.ragfairServerHelper.isPlayer(trader)) + && this.getOffersByTemplate(itemTpl)?.length >= this.maxOffersPerTemplate + ) + { + return; + } this.offersById.set(offerId, offer); this.addOfferByTrader(trader, offer); this.addOfferByTemplates(itemTpl, offer);