From a79a5f7aecbeb081aa1c83a654686ac345262803 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 20 Jul 2023 12:00:24 +0100 Subject: [PATCH] Allow modders to set item min/max stack size limits for any item on fence --- project/assets/configs/trader.json | 4 +++ .../src/models/spt/config/ITraderConfig.ts | 2 ++ project/src/services/FenceService.ts | 26 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/project/assets/configs/trader.json b/project/assets/configs/trader.json index 8cf5f629..067c80c8 100644 --- a/project/assets/configs/trader.json +++ b/project/assets/configs/trader.json @@ -86,6 +86,10 @@ "min": 35, "max": 60 }, + "itemStackSizeOverrideMinMax": + { + "59e690b686f7746c9f75e848": {"min": 5, "max": 15} + }, "blacklist": [ "5661632d4bdc2d903d8b456b", "543be5e94bdc2df1348b4568", diff --git a/project/src/models/spt/config/ITraderConfig.ts b/project/src/models/spt/config/ITraderConfig.ts index ae9b28fa..8e8922c9 100644 --- a/project/src/models/spt/config/ITraderConfig.ts +++ b/project/src/models/spt/config/ITraderConfig.ts @@ -30,6 +30,8 @@ export interface FenceConfig presetPriceMult: number armorMaxDurabilityPercentMinMax: MinMax presetMaxDurabilityPercentMinMax: MinMax + /** Key: item tpl */ + itemStackSizeOverrideMinMax: Record itemTypeLimits: Record regenerateAssortsOnRefresh: boolean blacklist: string[] diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 664f9feb..78997d42 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -428,7 +428,7 @@ export class FenceService this.randomiseItemUpdProperties(itemDbDetails, toPush); - toPush.upd.StackObjectsCount = 1; + toPush.upd.StackObjectsCount = this.getSingleItemStackCount(itemDbDetails); toPush.upd.BuyRestrictionCurrent = 0; toPush.upd.UnlimitedCount = false; @@ -440,6 +440,30 @@ export class FenceService } } + /** + * Get stack size ofr a singular item (no mods) + * @param itemDbDetails item being added to fence + * @returns Stack size + */ + protected getSingleItemStackCount(itemDbDetails: ITemplateItem): number + { + // Check for override in config, use values if exists + const overrideValues = this.traderConfig.fence.itemStackSizeOverrideMinMax[itemDbDetails._id]; + if (overrideValues) + { + return this.randomUtil.getInt(overrideValues.min, overrideValues.max); + } + + // Fence doesn't sell ammo by default, but handle it as players mod fence + if (this.itemHelper.isOfBaseclass(itemDbDetails._id, BaseClasses.AMMO)) + { + // No override, use stack max size from item db + return this.randomUtil.getInt(1, itemDbDetails._props.StackMaxSize); + } + + return 1; + } + /** * Add preset weapons to fence presets * @param assortCount how many assorts to add to assorts