From 45c32b087d63d381d13c5bc6d1b2b606ed54c3ed Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 19 Jan 2025 12:29:19 +0100 Subject: [PATCH] chore: handle addMiscItems & addMods resulting in account having 0 or less of a type (#821) --- src/services/inventoryService.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index c58a17df..e25f9f70 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -661,7 +661,13 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray: if (itemIndex !== -1) { MiscItems[itemIndex].ItemCount += ItemCount; - inventory.markModified(`MiscItems.${itemIndex}.ItemCount`); + if (MiscItems[itemIndex].ItemCount <= 0) { + if (MiscItems[itemIndex].ItemCount == 0) { + MiscItems.splice(itemIndex, 1); + } else { + logger.warn(`account now owns a negative amount of ${ItemType}`); + } + } } else { MiscItems.push({ ItemCount, ItemType }); } @@ -723,7 +729,13 @@ export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawU if (itemIndex !== -1) { RawUpgrades[itemIndex].ItemCount += ItemCount; - inventory.markModified(`RawUpgrades.${itemIndex}.ItemCount`); + if (RawUpgrades[itemIndex].ItemCount <= 0) { + if (RawUpgrades[itemIndex].ItemCount == 0) { + RawUpgrades.splice(itemIndex, 1); + } else { + logger.warn(`account now owns a negative amount of ${ItemType}`); + } + } } else { RawUpgrades.push({ ItemCount, ItemType }); }