fix: handle recipes requiring non-MiscItem items (#1348)
Some checks failed
Build Docker image / docker (push) Waiting to run
Build / build (22) (push) Has been cancelled
Build / build (18) (push) Has been cancelled
Build / build (20) (push) Has been cancelled

e.g. mutagens and antigens require vome and fass residue which are consumables

Reviewed-on: #1348
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2025-03-28 03:07:30 -07:00 committed by Sainan
parent 24c288fe61
commit b14927d605
2 changed files with 14 additions and 19 deletions

View File

@ -11,13 +11,13 @@ import {
getInventory, getInventory,
updateCurrency, updateCurrency,
addItem, addItem,
addMiscItems,
addRecipes, addRecipes,
occupySlot occupySlot,
combineInventoryChanges
} from "@/src/services/inventoryService"; } from "@/src/services/inventoryService";
import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { IInventoryChanges } from "@/src/types/purchaseTypes";
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes"; import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
export interface IClaimCompletedRecipeRequest { export interface IClaimCompletedRecipeRequest {
RecipeIds: IOid[]; RecipeIds: IOid[];
@ -51,14 +51,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
...updateCurrency(inventory, recipe.buildPrice * -1, false) ...updateCurrency(inventory, recipe.buildPrice * -1, false)
}; };
const nonMiscItemIngredients = new Set(); const equipmentIngredients = new Set();
for (const category of ["LongGuns", "Pistols", "Melee"] as const) { for (const category of ["LongGuns", "Pistols", "Melee"] as const) {
if (pendingRecipe[category]) { if (pendingRecipe[category]) {
pendingRecipe[category].forEach(item => { pendingRecipe[category].forEach(item => {
const index = inventory[category].push(item) - 1; const index = inventory[category].push(item) - 1;
inventoryChanges[category] ??= []; inventoryChanges[category] ??= [];
inventoryChanges[category].push(inventory[category][index].toJSON<IEquipmentClient>()); inventoryChanges[category].push(inventory[category][index].toJSON<IEquipmentClient>());
nonMiscItemIngredients.add(item.ItemType); equipmentIngredients.add(item.ItemType);
occupySlot(inventory, InventorySlot.WEAPONS, false); occupySlot(inventory, InventorySlot.WEAPONS, false);
inventoryChanges.WeaponBin ??= { Slots: 0 }; inventoryChanges.WeaponBin ??= { Slots: 0 };
@ -66,14 +66,14 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
}); });
} }
} }
const miscItemChanges: IMiscItem[] = []; for (const ingredient of recipe.ingredients) {
recipe.ingredients.forEach(ingredient => { if (!equipmentIngredients.has(ingredient.ItemType)) {
if (!nonMiscItemIngredients.has(ingredient.ItemType)) { combineInventoryChanges(
miscItemChanges.push(ingredient); inventoryChanges,
await addItem(inventory, ingredient.ItemType, ingredient.ItemCount)
);
} }
}); }
addMiscItems(inventory, miscItemChanges);
inventoryChanges.MiscItems = miscItemChanges;
await inventory.save(); await inventory.save();
res.json(inventoryChanges); // Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root. res.json(inventoryChanges); // Not a bug: In the specific case of cancelling a recipe, InventoryChanges are expected to be the root.

View File

@ -3,7 +3,7 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { getRecipe } from "@/src/services/itemDataService"; import { getRecipe } from "@/src/services/itemDataService";
import { addMiscItems, freeUpSlot, getInventory, updateCurrency } from "@/src/services/inventoryService"; import { addItem, freeUpSlot, getInventory, updateCurrency } from "@/src/services/inventoryService";
import { unixTimesInMs } from "@/src/constants/timeConstants"; import { unixTimesInMs } from "@/src/constants/timeConstants";
import { Types } from "mongoose"; import { Types } from "mongoose";
import { InventorySlot, ISpectreLoadout } from "@/src/types/inventoryTypes/inventoryTypes"; import { InventorySlot, ISpectreLoadout } from "@/src/types/inventoryTypes/inventoryTypes";
@ -55,12 +55,7 @@ export const startRecipeController: RequestHandler = async (req, res) => {
inventory[category].splice(equipmentIndex, 1); inventory[category].splice(equipmentIndex, 1);
freeUpSlot(inventory, InventorySlot.WEAPONS); freeUpSlot(inventory, InventorySlot.WEAPONS);
} else { } else {
addMiscItems(inventory, [ await addItem(inventory, recipe.ingredients[i].ItemType, recipe.ingredients[i].ItemCount * -1);
{
ItemType: recipe.ingredients[i].ItemType,
ItemCount: recipe.ingredients[i].ItemCount * -1
}
]);
} }
} }