diff --git a/src/controllers/api/claimCompletedRecipeController.ts b/src/controllers/api/claimCompletedRecipeController.ts index 034b2e10..43abc899 100644 --- a/src/controllers/api/claimCompletedRecipeController.ts +++ b/src/controllers/api/claimCompletedRecipeController.ts @@ -48,6 +48,9 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) = res.json({}); } else { logger.debug("Claiming Recipe", { buildable, pendingRecipe }); + if (buildable.consumeOnUse) { + // TODO: Remove one instance of this recipe, and include that in InventoryChanges. + } let currencyChanges = {}; if (req.query.rush && buildable.skipBuildTimePrice) { currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId); @@ -55,7 +58,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) = res.json({ InventoryChanges: { ...currencyChanges, - ...(await addItem(accountId, buildable.uniqueName, buildable.buildQuantity)).InventoryChanges + ...(await addItem(accountId, buildable.resultType, buildable.num)).InventoryChanges } }); } diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index b06dcd14..64ed6f94 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -26,6 +26,7 @@ import { logger } from "@/src/utils/logger"; import { WeaponTypeInternal, getWeaponType, getExalted } from "@/src/services/itemDataService"; import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes"; import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes"; +import { ExportRecipes } from "warframe-public-export-plus"; export const createInventory = async ( accountOwnerId: Types.ObjectId, @@ -70,6 +71,25 @@ export const addItem = async ( typeName: string, quantity: number = 1 ): Promise<{ InventoryChanges: object }> => { + // Strict typing + if (typeName in ExportRecipes) { + const inventory = await getInventory(accountId); + const recipeChanges = [ + { + ItemType: typeName, + ItemCount: quantity + } satisfies ITypeCount + ]; + addRecipes(inventory, recipeChanges); + await inventory.save(); + return { + InventoryChanges: { + Recipes: recipeChanges + } + }; + } + + // Path-based duck typing switch (typeName.substr(1).split("/")[1]) { case "Powersuits": if (typeName.includes("EntratiMech")) { @@ -187,24 +207,6 @@ export const addItem = async ( } } } - case "Recipes": - case "Consumables": { - // Blueprints for Ciphers, Antitoxins - const inventory = await getInventory(accountId); - const recipeChanges = [ - { - ItemType: typeName, - ItemCount: quantity - } satisfies ITypeCount - ]; - addRecipes(inventory, recipeChanges); - await inventory.save(); - return { - InventoryChanges: { - Recipes: recipeChanges - } - }; - } case "Restoratives": // Codex Scanner, Remote Observer, Starburst const inventory = await getInventory(accountId); const consumablesChanges = [ diff --git a/src/services/itemDataService.ts b/src/services/itemDataService.ts index 46a785ba..c755336d 100644 --- a/src/services/itemDataService.ts +++ b/src/services/itemDataService.ts @@ -1,8 +1,15 @@ import { getIndexAfter } from "@/src/helpers/stringHelpers"; import { logger } from "@/src/utils/logger"; -import Items, { Buildable, Category, MinimalItem, Warframe, Weapon } from "warframe-items"; +import Items, { Category, MinimalItem, Warframe, Weapon } from "warframe-items"; import badItems from "@/static/json/exclude-mods.json"; -import { dict_en, ExportWarframes, ExportWeapons, IPowersuit } from "warframe-public-export-plus"; +import { + dict_en, + ExportRecipes, + ExportWarframes, + ExportWeapons, + IPowersuit, + IRecipe +} from "warframe-public-export-plus"; export type MinWarframe = Omit; export type MinWeapon = Omit; @@ -100,13 +107,9 @@ export const blueprintNames = Object.fromEntries( .map(name => [name, craftNames[name]]) ); -const buildables = items.filter(item => !!(item as Buildable).components); - -export const getItemByBlueprint = (uniqueName: string): (MinItem & Buildable) | undefined => { - const item = buildables.find(item => - (item as Buildable).components?.find(component => component.uniqueName === uniqueName) - ); - return item; +// Gets a recipe by its uniqueName +export const getItemByBlueprint = (uniqueName: string): IRecipe | undefined => { + return ExportRecipes[uniqueName]; }; export const getExalted = (uniqueName: string) => { diff --git a/src/services/recipeService.ts b/src/services/recipeService.ts index 953992f6..c9d315bd 100644 --- a/src/services/recipeService.ts +++ b/src/services/recipeService.ts @@ -34,9 +34,9 @@ export const startRecipe = async (recipeName: string, accountId: string) => { throw new Error(`unknown recipe ${recipeName}`); } - const componentsNeeded = recipe.components?.map(component => ({ - uniqueName: component.uniqueName, - count: component.itemCount + const componentsNeeded = recipe.ingredients.map(component => ({ + uniqueName: component.ItemType, + count: component.ItemCount })); if (!componentsNeeded) { @@ -47,11 +47,6 @@ export const startRecipe = async (recipeName: string, accountId: string) => { //TODO: consume components used //await updateResources(accountId, componentsNeeded); - //might be redundant - if (recipe.consumeOnBuild) { - //consume - } - if (!recipe.buildTime) { logger.error(`recipe ${recipeName} has no build time`); throw new Error(`recipe ${recipeName} has no build time`);