Make randomiseAmmoStackSize() and randomiseMoneyStackSize() not purge the entire upd object

Always randomise the ammo stack size, not only if it doesnt have one
This commit is contained in:
Dev 2023-11-04 09:08:33 +00:00
parent 93209e4a76
commit 432f778512

View File

@ -333,7 +333,7 @@ export class BotLootGenerator
{ {
this.itemHelper.addCartridgesToAmmoBox(itemsToAdd, itemToAddTemplate); this.itemHelper.addCartridgesToAmmoBox(itemsToAdd, itemToAddTemplate);
} }
// make money a stack // Make money a stack
else if (this.itemHelper.isOfBaseclass(itemToAddTemplate._id, BaseClasses.MONEY)) else if (this.itemHelper.isOfBaseclass(itemToAddTemplate._id, BaseClasses.MONEY))
{ {
this.randomiseMoneyStackSize(isPmc, itemToAddTemplate, itemsToAdd[0]); this.randomiseMoneyStackSize(isPmc, itemToAddTemplate, itemsToAdd[0]);
@ -374,14 +374,13 @@ export class BotLootGenerator
} }
} }
/** /**
* Add generated weapons to inventory as loot * Add generated weapons to inventory as loot
* @param botInventory inventory to add preset to * @param botInventory inventory to add preset to
* @param equipmentSlot slot to place the preset in (backpack) * @param equipmentSlot slot to place the preset in (backpack)
* @param templateInventory bots template, assault.json * @param templateInventory bots template, assault.json
* @param modChances chances for mods to spawn on weapon * @param modChances chances for mods to spawn on weapon
* @param botRole bots role, .e.g. pmcBot * @param botRole bots role .e.g. pmcBot
* @param isPmc are we generating for a pmc * @param isPmc are we generating for a pmc
*/ */
protected addLooseWeaponsToInventorySlot(sessionId: string, botInventory: PmcInventory, equipmentSlot: string, templateInventory: Inventory, modChances: ModsChances, botRole: string, isPmc: boolean, botLevel: number): void protected addLooseWeaponsToInventorySlot(sessionId: string, botInventory: PmcInventory, equipmentSlot: string, templateInventory: Inventory, modChances: ModsChances, botRole: string, isPmc: boolean, botLevel: number): void
@ -498,42 +497,45 @@ export class BotLootGenerator
/** /**
* Randomise the stack size of a money object, uses different values for pmc or scavs * Randomise the stack size of a money object, uses different values for pmc or scavs
* @param isPmc is this a PMC * @param isPmc Is money on a PMC bot
* @param itemTemplate item details * @param itemTemplate item details from db
* @param moneyItem Money stack to randomise * @param moneyItem Money item to randomise
*/ */
protected randomiseMoneyStackSize(isPmc: boolean, itemTemplate: ITemplateItem, moneyItem: Item): void protected randomiseMoneyStackSize(isPmc: boolean, itemTemplate: ITemplateItem, moneyItem: Item): void
{
// Only add if no upd or stack objects exist - preserves existing stack count
if (!moneyItem.upd?.StackObjectsCount)
{ {
// PMCs have a different stack max size // PMCs have a different stack max size
const minStackSize = itemTemplate._props.StackMinRandom; const minStackSize = itemTemplate._props.StackMinRandom;
const maxStackSize = (isPmc) const maxStackSize = (isPmc)
? this.pmcConfig.dynamicLoot.moneyStackLimits[itemTemplate._id] ? this.pmcConfig.dynamicLoot.moneyStackLimits[itemTemplate._id]
: itemTemplate._props.StackMaxRandom; : itemTemplate._props.StackMaxRandom;
const randomSize = this.randomUtil.getInt(minStackSize, maxStackSize);
moneyItem.upd = { "StackObjectsCount": this.randomUtil.getInt(minStackSize, maxStackSize) }; if (!moneyItem.upd)
{
moneyItem.upd = {};
} }
moneyItem.upd.StackObjectsCount = randomSize;
} }
/** /**
* Randomise the size of an ammo stack * Randomise the size of an ammo stack
* @param isPmc is this a PMC * @param isPmc Is ammo on a PMC bot
* @param itemTemplate item details * @param itemTemplate item details from db
* @param ammoItem Ammo stack to randomise * @param ammoItem Ammo item to randomise
*/ */
protected randomiseAmmoStackSize(isPmc: boolean, itemTemplate: ITemplateItem, ammoItem: Item): void protected randomiseAmmoStackSize(isPmc: boolean, itemTemplate: ITemplateItem, ammoItem: Item): void
{
// only add if no upd or stack objects exist - preserves existing stack count
if (!ammoItem.upd?.StackObjectsCount)
{ {
const randomSize = itemTemplate._props.StackMaxSize === 1 const randomSize = itemTemplate._props.StackMaxSize === 1
? 1 ? 1
: this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom); : this.randomUtil.getInt(itemTemplate._props.StackMinRandom, itemTemplate._props.StackMaxRandom);
ammoItem.upd = { StackObjectsCount: randomSize }; if (!ammoItem.upd)
{
ammoItem.upd = {};
} }
ammoItem.upd.StackObjectsCount = randomSize ;
} }
/** /**