Allow modders to set item min/max stack size limits for any item on fence

This commit is contained in:
Dev 2023-07-20 12:00:24 +01:00
parent 2917c8a167
commit a79a5f7aec
3 changed files with 31 additions and 1 deletions

View File

@ -86,6 +86,10 @@
"min": 35, "min": 35,
"max": 60 "max": 60
}, },
"itemStackSizeOverrideMinMax":
{
"59e690b686f7746c9f75e848": {"min": 5, "max": 15}
},
"blacklist": [ "blacklist": [
"5661632d4bdc2d903d8b456b", "5661632d4bdc2d903d8b456b",
"543be5e94bdc2df1348b4568", "543be5e94bdc2df1348b4568",

View File

@ -30,6 +30,8 @@ export interface FenceConfig
presetPriceMult: number presetPriceMult: number
armorMaxDurabilityPercentMinMax: MinMax armorMaxDurabilityPercentMinMax: MinMax
presetMaxDurabilityPercentMinMax: MinMax presetMaxDurabilityPercentMinMax: MinMax
/** Key: item tpl */
itemStackSizeOverrideMinMax: Record<string, MinMax>
itemTypeLimits: Record<string, number> itemTypeLimits: Record<string, number>
regenerateAssortsOnRefresh: boolean regenerateAssortsOnRefresh: boolean
blacklist: string[] blacklist: string[]

View File

@ -428,7 +428,7 @@ export class FenceService
this.randomiseItemUpdProperties(itemDbDetails, toPush); this.randomiseItemUpdProperties(itemDbDetails, toPush);
toPush.upd.StackObjectsCount = 1; toPush.upd.StackObjectsCount = this.getSingleItemStackCount(itemDbDetails);
toPush.upd.BuyRestrictionCurrent = 0; toPush.upd.BuyRestrictionCurrent = 0;
toPush.upd.UnlimitedCount = false; 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 * Add preset weapons to fence presets
* @param assortCount how many assorts to add to assorts * @param assortCount how many assorts to add to assorts