返回提交历史
Modified
src/services/inventoryService.ts
+27
-24
XFEstudio/XFESpaceNinjaServer
fix: 'account now owns a negative amount' not showing when it had 0 (#877)
9de87f09
代码差异
1 个文件
+27
-24
@@ -819,19 +819,20 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
819
819
const { MiscItems } = inventory;
820
820
821
821
itemsArray?.forEach(({ ItemCount, ItemType }) => {
822
const itemIndex = MiscItems.findIndex(miscItem => miscItem.ItemType === ItemType);
822
if (ItemCount == 0) {
823
return;
824
}
823
825
824
if (itemIndex !== -1) {
825
MiscItems[itemIndex].ItemCount += ItemCount;
826
if (MiscItems[itemIndex].ItemCount <= 0) {
827
if (MiscItems[itemIndex].ItemCount == 0) {
828
MiscItems.splice(itemIndex, 1);
829
} else {
830
logger.warn(`account now owns a negative amount of ${ItemType}`);
831
}
832
}
833
} else {
834
MiscItems.push({ ItemCount, ItemType });
826
let itemIndex = MiscItems.findIndex(x => x.ItemType === ItemType);
827
if (itemIndex == -1) {
828
itemIndex = MiscItems.push({ ItemType, ItemCount: 0 }) - 1;
829
}
830
831
MiscItems[itemIndex].ItemCount += ItemCount;
832
if (MiscItems[itemIndex].ItemCount == 0) {
833
MiscItems.splice(itemIndex, 1);
834
} else if (MiscItems[itemIndex].ItemCount <= 0) {
835
logger.warn(`account now owns a negative amount of ${ItemType}`);
835
836
}
836
837
});
837
838
};
@@ -886,20 +887,22 @@ export const addRecipes = (inventory: TInventoryDatabaseDocument, itemsArray: IT
886
887
887
888
export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawUpgrade[] | undefined): void => {
888
889
const { RawUpgrades } = inventory;
890
889
891
itemsArray?.forEach(({ ItemType, ItemCount }) => {
890
const itemIndex = RawUpgrades.findIndex(i => i.ItemType === ItemType);
892
if (ItemCount == 0) {
893
return;
894
}
891
895
892
if (itemIndex !== -1) {
893
RawUpgrades[itemIndex].ItemCount += ItemCount;
894
if (RawUpgrades[itemIndex].ItemCount <= 0) {
895
if (RawUpgrades[itemIndex].ItemCount == 0) {
896
RawUpgrades.splice(itemIndex, 1);
897
} else {
898
logger.warn(`account now owns a negative amount of ${ItemType}`);
899
}
900
}
901
} else {
902
RawUpgrades.push({ ItemCount, ItemType });
896
let itemIndex = RawUpgrades.findIndex(x => x.ItemType === ItemType);
897
if (itemIndex == -1) {
898
itemIndex = RawUpgrades.push({ ItemType, ItemCount: 0 }) - 1;
899
}
900
901
RawUpgrades[itemIndex].ItemCount += ItemCount;
902
if (RawUpgrades[itemIndex].ItemCount == 0) {
903
RawUpgrades.splice(itemIndex, 1);
904
} else if (RawUpgrades[itemIndex].ItemCount <= 0) {
905
logger.warn(`account now owns a negative amount of ${ItemType}`);
903
906
}
904
907
});
905
908
};