fix: 'account now owns a negative amount' not showing when it had 0 (#877)

This commit is contained in:
Sainan 2025-01-31 17:02:27 +01:00 committed by GitHub
parent 50c280cf01
commit 9de87f0959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -819,20 +819,21 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
const { MiscItems } = inventory; const { MiscItems } = inventory;
itemsArray?.forEach(({ ItemCount, ItemType }) => { itemsArray?.forEach(({ ItemCount, ItemType }) => {
const itemIndex = MiscItems.findIndex(miscItem => miscItem.ItemType === ItemType); if (ItemCount == 0) {
return;
}
let itemIndex = MiscItems.findIndex(x => x.ItemType === ItemType);
if (itemIndex == -1) {
itemIndex = MiscItems.push({ ItemType, ItemCount: 0 }) - 1;
}
if (itemIndex !== -1) {
MiscItems[itemIndex].ItemCount += ItemCount; MiscItems[itemIndex].ItemCount += ItemCount;
if (MiscItems[itemIndex].ItemCount <= 0) {
if (MiscItems[itemIndex].ItemCount == 0) { if (MiscItems[itemIndex].ItemCount == 0) {
MiscItems.splice(itemIndex, 1); MiscItems.splice(itemIndex, 1);
} else { } else if (MiscItems[itemIndex].ItemCount <= 0) {
logger.warn(`account now owns a negative amount of ${ItemType}`); logger.warn(`account now owns a negative amount of ${ItemType}`);
} }
}
} else {
MiscItems.push({ ItemCount, ItemType });
}
}); });
}; };
@ -886,21 +887,23 @@ export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: IT
export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => { export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => {
const { RawUpgrades } = inventory; const { RawUpgrades } = inventory;
itemsArray?.forEach(({ ItemType, ItemCount }) => {
const itemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
if (itemIndex !== -1) { itemsArray?.forEach(({ ItemType, ItemCount }) => {
if (ItemCount == 0) {
return;
}
let itemIndex = RawUpgrades.findIndex(x => x.ItemType === ItemType);
if (itemIndex == -1) {
itemIndex = RawUpgrades.push({ ItemType, ItemCount: 0 }) - 1;
}
RawUpgrades[itemIndex].ItemCount += ItemCount; RawUpgrades[itemIndex].ItemCount += ItemCount;
if (RawUpgrades[itemIndex].ItemCount <= 0) {
if (RawUpgrades[itemIndex].ItemCount == 0) { if (RawUpgrades[itemIndex].ItemCount == 0) {
RawUpgrades.splice(itemIndex, 1); RawUpgrades.splice(itemIndex, 1);
} else { } else if (RawUpgrades[itemIndex].ItemCount <= 0) {
logger.warn(`account now owns a negative amount of ${ItemType}`); logger.warn(`account now owns a negative amount of ${ItemType}`);
} }
}
} else {
RawUpgrades.push({ ItemCount, ItemType });
}
}); });
}; };