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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

fix: handle recipes requiring non-MiscItem items (#1348)

e.g. mutagens and antigens require vome and fass residue which are consumables Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1348 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

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

代码差异

2 个文件 +14 -19
Modified src/controllers/api/claimCompletedRecipeController.ts +12 -12
@@ -11,13 +11,13 @@ import {
11 11 getInventory,
12 12 updateCurrency,
13 13 addItem,
14 addMiscItems,
15 14 addRecipes,
16 occupySlot
15 occupySlot,
16 combineInventoryChanges
17 17 } from "@/src/services/inventoryService";
18 18 import { IInventoryChanges } from "@/src/types/purchaseTypes";
19 19 import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
20 import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
20 import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
21 21
22 22 export interface IClaimCompletedRecipeRequest {
23 23 RecipeIds: IOid[];
@@ -51,14 +51,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
51 51 ...updateCurrency(inventory, recipe.buildPrice * -1, false)
52 52 };
53 53
54 const nonMiscItemIngredients = new Set();
54 const equipmentIngredients = new Set();
55 55 for (const category of ["LongGuns", "Pistols", "Melee"] as const) {
56 56 if (pendingRecipe[category]) {
57 57 pendingRecipe[category].forEach(item => {
58 58 const index = inventory[category].push(item) - 1;
59 59 inventoryChanges[category] ??= [];
60 60 inventoryChanges[category].push(inventory[category][index].toJSON<IEquipmentClient>());
61 nonMiscItemIngredients.add(item.ItemType);
61 equipmentIngredients.add(item.ItemType);
62 62
63 63 occupySlot(inventory, InventorySlot.WEAPONS, false);
64 64 inventoryChanges.WeaponBin ??= { Slots: 0 };
@@ -66,14 +66,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
66 66 });
67 67 }
68 68 }
69 const miscItemChanges: IMiscItem[] = [];
70 recipe.ingredients.forEach(ingredient => {
71 if (!nonMiscItemIngredients.has(ingredient.ItemType)) {
72 miscItemChanges.push(ingredient);
69 for (const ingredient of recipe.ingredients) {
70 if (!equipmentIngredients.has(ingredient.ItemType)) {
71 combineInventoryChanges(
72 inventoryChanges,
73 await addItem(inventory, ingredient.ItemType, ingredient.ItemCount)
74 );
73 75 }
74 });
75 addMiscItems(inventory, miscItemChanges);
76 inventoryChanges.MiscItems = miscItemChanges;
76 }
77 77
78 78 await inventory.save();
79 79 res.json(inventoryChanges); // Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.
Modified src/controllers/api/startRecipeController.ts +2 -7
@@ -3,7 +3,7 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers";
3 3 import { logger } from "@/src/utils/logger";
4 4 import { RequestHandler } from "express";
5 5 import { getRecipe } from "@/src/services/itemDataService";
6 import { addMiscItems, freeUpSlot, getInventory, updateCurrency } from "@/src/services/inventoryService";
6 import { addItem, freeUpSlot, getInventory, updateCurrency } from "@/src/services/inventoryService";
7 7 import { unixTimesInMs } from "@/src/constants/timeConstants";
8 8 import { Types } from "mongoose";
9 9 import { InventorySlot, ISpectreLoadout } from "@/src/types/inventoryTypes/inventoryTypes";
@@ -55,12 +55,7 @@ export const startRecipeController: RequestHandler = async (req, res) => {
55 55 inventory[category].splice(equipmentIndex, 1);
56 56 freeUpSlot(inventory, InventorySlot.WEAPONS);
57 57 } else {
58 addMiscItems(inventory, [
59 {
60 ItemType: recipe.ingredients[i].ItemType,
61 ItemCount: recipe.ingredients[i].ItemCount * -1
62 }
63 ]);
58 await addItem(inventory, recipe.ingredients[i].ItemType, recipe.ingredients[i].ItemCount * -1);
64 59 }
65 60 }
66 61