From a1070f941c6457cb74e48958ed71f7b948ec99a4 Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 28 Apr 2024 23:04:37 +0100 Subject: [PATCH] Added extra guard against adding cartridges to box sold by fence Skip adding cartridges to ammo box inside `addCartridgesToAmmoBox()` if cartridge already exists --- project/src/generators/FenceBaseAssortGenerator.ts | 6 +++++- project/src/helpers/ItemHelper.ts | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/project/src/generators/FenceBaseAssortGenerator.ts b/project/src/generators/FenceBaseAssortGenerator.ts index be6ac7a2..a1e92070 100644 --- a/project/src/generators/FenceBaseAssortGenerator.ts +++ b/project/src/generators/FenceBaseAssortGenerator.ts @@ -106,7 +106,11 @@ export class FenceBaseAssortGenerator 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 diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index 05aa54de..481780f0 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1090,6 +1090,12 @@ export class ItemHelper const cartridgeDetails = this.getItem(cartridgeTpl); 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 let currentStoredCartridgeCount = 0; const maxPerStack = Math.min(ammoBoxMaxCartridgeCount, cartridgeMaxStackSize);