XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

fix: item count validation when starting a recipe (#3030)

Can't assume it's all MiscItems. Instead upgraded the warnings to errors in the inventoryService functions. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3030 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

55d051ff
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

2 个文件 +14 -15
Modified src/controllers/api/startRecipeController.ts +1 -8
@@ -71,14 +71,7 @@ export const startRecipeController: RequestHandler = async (req, res) => {
71 71 } else {
72 72 const itemType = recipe.ingredients[i].ItemType;
73 73 const itemCount = recipe.ingredients[i].ItemCount;
74 const inventoryItem = inventory.MiscItems.find(i => i.ItemType === itemType);
75 if (inventoryItem && inventoryItem.ItemCount >= itemCount) {
76 await addItem(inventory, itemType, itemCount * -1);
77 } else {
78 throw new Error(
79 `insufficient ${itemType} (in inventory ${inventoryItem?.ItemCount} - needed ${itemCount}) for recipe ${recipeName}`
80 );
81 }
74 await addItem(inventory, itemType, itemCount * -1);
82 75 }
83 76 }
84 77
Modified src/services/inventoryService.ts +13 -7
@@ -1849,8 +1849,8 @@ export const addMiscItems = (inventory: TInventoryDatabaseDocument, itemsArray:
1849 1849
1850 1850 if (MiscItems[itemIndex].ItemCount == 0) {
1851 1851 MiscItems.splice(itemIndex, 1);
1852 } else if (MiscItems[itemIndex].ItemCount <= 0) {
1853 logger.warn(`inventory.MiscItems has a negative count for ${ItemType}`);
1852 } else if (MiscItems[itemIndex].ItemCount < 0) {
1853 throw new Error(`inventory.MiscItems has a negative count for ${ItemType} after subtracting ${ItemCount}`);
1854 1854 }
1855 1855 });
1856 1856 };
@@ -1871,8 +1871,10 @@ const applyArrayChanges = (
1871 1871 arr[itemIndex].ItemCount += change.ItemCount;
1872 1872 if (arr[itemIndex].ItemCount == 0) {
1873 1873 arr.splice(itemIndex, 1);
1874 } else if (arr[itemIndex].ItemCount <= 0) {
1875 logger.warn(`inventory.${key} has a negative count for ${change.ItemType}`);
1874 } else if (arr[itemIndex].ItemCount < 0) {
1875 throw new Error(
1876 `inventory.${key} has a negative count for ${change.ItemType} after subtracting ${change.ItemCount}`
1877 );
1876 1878 }
1877 1879 }
1878 1880 }
@@ -1918,8 +1920,10 @@ export const addMods = (inventory: TInventoryDatabaseDocument, itemsArray: IRawU
1918 1920 RawUpgrades[itemIndex].ItemCount += ItemCount;
1919 1921 if (RawUpgrades[itemIndex].ItemCount == 0) {
1920 1922 RawUpgrades.splice(itemIndex, 1);
1921 } else if (RawUpgrades[itemIndex].ItemCount <= 0) {
1922 logger.warn(`inventory.RawUpgrades has a negative count for ${ItemType}`);
1923 } else if (RawUpgrades[itemIndex].ItemCount < 0) {
1924 throw new Error(
1925 `inventory.RawUpgrades has a negative count for ${ItemType} after subtracting ${ItemCount}`
1926 );
1923 1927 }
1924 1928 });
1925 1929 };
@@ -1934,7 +1938,9 @@ export const addFusionTreasures = (inventory: TInventoryDatabaseDocument, itemsA
1934 1938 if (FusionTreasures[itemIndex].ItemCount == 0) {
1935 1939 FusionTreasures.splice(itemIndex, 1);
1936 1940 } else if (FusionTreasures[itemIndex].ItemCount <= 0) {
1937 logger.warn(`inventory.FusionTreasures has a negative count for ${ItemType}`);
1941 throw new Error(
1942 `inventory.FusionTreasures has a negative count for ${ItemType} after subtracting ${ItemCount}`
1943 );
1938 1944 }
1939 1945 } else {
1940 1946 FusionTreasures.push({ ItemCount, ItemType, Sockets });