Adjust servers handling of item stacks, when item has a StackMaxSize value of 1, use that instead of items db property StackMaxRandom

This commit is contained in:
Dev 2023-10-28 19:39:45 +01:00
parent 6d30d86ea4
commit fd7e59d1d2
3 changed files with 18 additions and 9 deletions

View File

@ -528,10 +528,11 @@ export class BotLootGenerator
// only add if no upd or stack objects exist - preserves existing stack count // only add if no upd or stack objects exist - preserves existing stack count
if (!ammoItem.upd?.StackObjectsCount) if (!ammoItem.upd?.StackObjectsCount)
{ {
const minStackSize = itemTemplate._props.StackMinRandom; const randomSize = itemTemplate._props.StackMaxSize === 1
const maxStackSize = itemTemplate._props.StackMaxSize; ? 1
: this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom);
ammoItem.upd = { "StackObjectsCount": this.randomUtil.getInt(minStackSize, maxStackSize) }; ammoItem.upd = { StackObjectsCount: randomSize };
} }
} }

View File

@ -660,12 +660,16 @@ export class LocationGenerator
// Item array to return // Item array to return
const itemWithMods: Item[] = []; const itemWithMods: Item[] = [];
// Money/Ammo - don't rely on items in spawnPoint.template.Items so we can randomise it ourselves // Money/Ammo - don't rely on items in spawnPoint.template.Items so we can randomise it ourselves
if (this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.MONEY) || this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.AMMO)) if (this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.MONEY) || this.itemHelper.isOfBaseclass(chosenTpl, BaseClasses.AMMO))
{ {
const itemTemplate = this.itemHelper.getItem(chosenTpl)[1]; const itemTemplate = this.itemHelper.getItem(chosenTpl)[1];
const stackCount = this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom);
const stackCount = itemTemplate._props.StackMaxSize === 1
? 1
: this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom);
itemWithMods.push( itemWithMods.push(
{ {
_id: this.objectId.generate(), _id: this.objectId.generate(),
@ -777,7 +781,10 @@ export class LocationGenerator
if (this.itemHelper.isOfBaseclass(tpl, BaseClasses.MONEY) || this.itemHelper.isOfBaseclass(tpl, BaseClasses.AMMO)) if (this.itemHelper.isOfBaseclass(tpl, BaseClasses.MONEY) || this.itemHelper.isOfBaseclass(tpl, BaseClasses.AMMO))
{ {
const stackCount = this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom); // Edge case - some ammos e.g. flares or M406 grenades shouldn't be stacked
const stackCount = itemTemplate._props.StackMaxSize === 1
? 1
: this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom);
items[0].upd = { StackObjectsCount: stackCount }; items[0].upd = { StackObjectsCount: stackCount };
} }
// No spawn point, use default template // No spawn point, use default template

View File

@ -465,7 +465,7 @@ export class FenceService
} }
/** /**
* Get stack size ofr a singular item (no mods) * Get stack size of a singular item (no mods)
* @param itemDbDetails item being added to fence * @param itemDbDetails item being added to fence
* @returns Stack size * @returns Stack size
*/ */
@ -478,11 +478,12 @@ export class FenceService
return this.randomUtil.getInt(overrideValues.min, overrideValues.max); 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)) if (this.itemHelper.isOfBaseclass(itemDbDetails._id, BaseClasses.AMMO))
{ {
// No override, use stack max size from item db // No override, use stack max size from item db
return this.randomUtil.getInt(1, itemDbDetails._props.StackMaxSize); return itemDbDetails._props.StackMaxSize === 1
? 1
: this.randomUtil.getInt(itemDbDetails._props.StackMinRandom, itemDbDetails._props.StackMaxRandom);
} }
return 1; return 1;