From 0740a84f6fdb24fc7db73164806b79e9487c6f3d Mon Sep 17 00:00:00 2001 From: Cj Date: Tue, 5 Mar 2024 08:49:10 +0000 Subject: [PATCH] [Enhancement] Ability to prevent duplicate fence offers by parentId (!245) In relation to this QoL issue: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/547 This PR allows us to prevent fence selling duplicate items by parentId. It adds a new property to `trader.json` `fence.preventDuplicateOffersOfCategory` its an array that takes parentIds. The scope of this PR only extends to ammo and ammo boxes. It can be expanded upon in the future with no code changes should the need arise. The reason for this change is because currently fence can have duplicate stacks of identical ammo with different prices, which makes no sense. If you have any questions feel free to ping me on discord. Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/245 Co-authored-by: Cj Co-committed-by: Cj --- project/assets/configs/trader.json | 4 ++++ project/src/models/spt/config/ITraderConfig.ts | 2 ++ project/src/services/FenceService.ts | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/project/assets/configs/trader.json b/project/assets/configs/trader.json index 64831068..2ce405a4 100644 --- a/project/assets/configs/trader.json +++ b/project/assets/configs/trader.json @@ -123,6 +123,10 @@ "5671435f4bdc2d96058b4569": 0, "543be5cb4bdc2deb348b4568": 3 }, + "preventDuplicateOffersOfCategory": [ + "543be5cb4bdc2deb348b4568", + "5485a8684bdc2da71d8b4567" + ], "weaponDurabilityPercentMinMax": { "current": { "min": 40, diff --git a/project/src/models/spt/config/ITraderConfig.ts b/project/src/models/spt/config/ITraderConfig.ts index 71988b85..9af3fc4d 100644 --- a/project/src/models/spt/config/ITraderConfig.ts +++ b/project/src/models/spt/config/ITraderConfig.ts @@ -36,6 +36,8 @@ export interface FenceConfig /** Key: item tpl */ itemStackSizeOverrideMinMax: Record; itemTypeLimits: Record; + /** Prevent duplicate offers of items of specific categories by parentId*/ + preventDuplicateOffersOfCategory: string[]; regenerateAssortsOnRefresh: boolean; /** Max rouble price before item is not listed on flea */ itemCategoryRoublePriceLimit: Record; diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 550f2503..934709ca 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -613,6 +613,18 @@ export class FenceService // rootItemBeingAdded.upd.BuyRestrictionCurrent = 0; // rootItemBeingAdded.upd.UnlimitedCount = false; + // Skip items already in the assort if it exists in the prevent duplicate list + if ( + assorts.items.some((item) => item._tpl === rootItemBeingAdded._tpl) + && this.traderConfig.fence.preventDuplicateOffersOfCategory.includes( + this.itemHelper.getItem(rootItemBeingAdded._tpl)[1]._parent, + ) + ) + { + i--; + continue; + } + // Only randomise single items const isSingleStack = rootItemBeingAdded.upd.StackObjectsCount === 1; if (isSingleStack)