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: not being able to purchase or craft some recipes (#314)

e8d7e176
Sainan <sainan@calamity.gg>
提交于

代码差异

4 个文件 +39 -36
Modified src/controllers/api/claimCompletedRecipeController.ts +4 -1
@@ -48,6 +48,9 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
48 48 res.json({});
49 49 } else {
50 50 logger.debug("Claiming Recipe", { buildable, pendingRecipe });
51 if (buildable.consumeOnUse) {
52 // TODO: Remove one instance of this recipe, and include that in InventoryChanges.
53 }
51 54 let currencyChanges = {};
52 55 if (req.query.rush && buildable.skipBuildTimePrice) {
53 56 currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId);
@@ -55,7 +58,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
55 58 res.json({
56 59 InventoryChanges: {
57 60 ...currencyChanges,
58 ...(await addItem(accountId, buildable.uniqueName, buildable.buildQuantity)).InventoryChanges
61 ...(await addItem(accountId, buildable.resultType, buildable.num)).InventoryChanges
59 62 }
60 63 });
61 64 }
Modified src/services/inventoryService.ts +20 -18
@@ -26,6 +26,7 @@ import { logger } from "@/src/utils/logger";
26 26 import { WeaponTypeInternal, getWeaponType, getExalted } from "@/src/services/itemDataService";
27 27 import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
28 28 import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes";
29 import { ExportRecipes } from "warframe-public-export-plus";
29 30
30 31 export const createInventory = async (
31 32 accountOwnerId: Types.ObjectId,
@@ -70,6 +71,25 @@ export const addItem = async (
70 71 typeName: string,
71 72 quantity: number = 1
72 73 ): Promise<{ InventoryChanges: object }> => {
74 // Strict typing
75 if (typeName in ExportRecipes) {
76 const inventory = await getInventory(accountId);
77 const recipeChanges = [
78 {
79 ItemType: typeName,
80 ItemCount: quantity
81 } satisfies ITypeCount
82 ];
83 addRecipes(inventory, recipeChanges);
84 await inventory.save();
85 return {
86 InventoryChanges: {
87 Recipes: recipeChanges
88 }
89 };
90 }
91
92 // Path-based duck typing
73 93 switch (typeName.substr(1).split("/")[1]) {
74 94 case "Powersuits":
75 95 if (typeName.includes("EntratiMech")) {
@@ -187,24 +207,6 @@ export const addItem = async (
187 207 }
188 208 }
189 209 }
190 case "Recipes":
191 case "Consumables": {
192 // Blueprints for Ciphers, Antitoxins
193 const inventory = await getInventory(accountId);
194 const recipeChanges = [
195 {
196 ItemType: typeName,
197 ItemCount: quantity
198 } satisfies ITypeCount
199 ];
200 addRecipes(inventory, recipeChanges);
201 await inventory.save();
202 return {
203 InventoryChanges: {
204 Recipes: recipeChanges
205 }
206 };
207 }
208 210 case "Restoratives": // Codex Scanner, Remote Observer, Starburst
209 211 const inventory = await getInventory(accountId);
210 212 const consumablesChanges = [
Modified src/services/itemDataService.ts +12 -9
@@ -1,8 +1,15 @@
1 1 import { getIndexAfter } from "@/src/helpers/stringHelpers";
2 2 import { logger } from "@/src/utils/logger";
3 import Items, { Buildable, Category, MinimalItem, Warframe, Weapon } from "warframe-items";
3 import Items, { Category, MinimalItem, Warframe, Weapon } from "warframe-items";
4 4 import badItems from "@/static/json/exclude-mods.json";
5 import { dict_en, ExportWarframes, ExportWeapons, IPowersuit } from "warframe-public-export-plus";
5 import {
6 dict_en,
7 ExportRecipes,
8 ExportWarframes,
9 ExportWeapons,
10 IPowersuit,
11 IRecipe
12 } from "warframe-public-export-plus";
6 13
7 14 export type MinWarframe = Omit<Warframe, "patchlogs">;
8 15 export type MinWeapon = Omit<Weapon, "patchlogs">;
@@ -100,13 +107,9 @@ export const blueprintNames = Object.fromEntries(
100 107 .map(name => [name, craftNames[name]])
101 108 );
102 109
103 const buildables = items.filter(item => !!(item as Buildable).components);
104
105 export const getItemByBlueprint = (uniqueName: string): (MinItem & Buildable) | undefined => {
106 const item = buildables.find(item =>
107 (item as Buildable).components?.find(component => component.uniqueName === uniqueName)
108 );
109 return item;
110 // Gets a recipe by its uniqueName
111 export const getItemByBlueprint = (uniqueName: string): IRecipe | undefined => {
112 return ExportRecipes[uniqueName];
110 113 };
111 114
112 115 export const getExalted = (uniqueName: string) => {
Modified src/services/recipeService.ts +3 -8
@@ -34,9 +34,9 @@ export const startRecipe = async (recipeName: string, accountId: string) => {
34 34 throw new Error(`unknown recipe ${recipeName}`);
35 35 }
36 36
37 const componentsNeeded = recipe.components?.map(component => ({
38 uniqueName: component.uniqueName,
39 count: component.itemCount
37 const componentsNeeded = recipe.ingredients.map(component => ({
38 uniqueName: component.ItemType,
39 count: component.ItemCount
40 40 }));
41 41
42 42 if (!componentsNeeded) {
@@ -47,11 +47,6 @@ export const startRecipe = async (recipeName: string, accountId: string) => {
47 47 //TODO: consume components used
48 48 //await updateResources(accountId, componentsNeeded);
49 49
50 //might be redundant
51 if (recipe.consumeOnBuild) {
52 //consume
53 }
54
55 50 if (!recipe.buildTime) {
56 51 logger.error(`recipe ${recipeName} has no build time`);
57 52 throw new Error(`recipe ${recipeName} has no build time`);