Added extra guard against adding cartridges to box sold by fence

Skip adding cartridges to ammo box inside `addCartridgesToAmmoBox()` if cartridge already exists
This commit is contained in:
Dev 2024-04-28 23:04:37 +01:00
parent 995d50dba4
commit a1070f941c
2 changed files with 11 additions and 1 deletions

View File

@ -106,7 +106,11 @@ export class FenceBaseAssortGenerator
if (this.itemHelper.isOfBaseclass(rootItemDb._id, BaseClasses.AMMO_BOX)) if (this.itemHelper.isOfBaseclass(rootItemDb._id, BaseClasses.AMMO_BOX))
{ {
this.itemHelper.addCartridgesToAmmoBox(itemWithChildrenToAdd, rootItemDb); // Only add cartridges to box if box has no children
if (itemWithChildrenToAdd.length === 1)
{
this.itemHelper.addCartridgesToAmmoBox(itemWithChildrenToAdd, rootItemDb);
}
} }
// Ensure IDs are unique // Ensure IDs are unique

View File

@ -1090,6 +1090,12 @@ export class ItemHelper
const cartridgeDetails = this.getItem(cartridgeTpl); const cartridgeDetails = this.getItem(cartridgeTpl);
const cartridgeMaxStackSize = cartridgeDetails[1]._props.StackMaxSize; const cartridgeMaxStackSize = cartridgeDetails[1]._props.StackMaxSize;
// Exit if ammo already exists in box
if (ammoBox.find((item) => item._tpl === cartridgeTpl))
{
return;
}
// Add new stack-size-correct items to ammo box // Add new stack-size-correct items to ammo box
let currentStoredCartridgeCount = 0; let currentStoredCartridgeCount = 0;
const maxPerStack = Math.min(ammoBoxMaxCartridgeCount, cartridgeMaxStackSize); const maxPerStack = Math.min(ammoBoxMaxCartridgeCount, cartridgeMaxStackSize);