forked from OpenWF/SpaceNinjaServer
		
	fix: not being able to purchase or craft some recipes (#314)
This commit is contained in:
		
							parent
							
								
									f15105a048
								
							
						
					
					
						commit
						e8d7e17611
					
				@ -48,6 +48,9 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
 | 
				
			|||||||
        res.json({});
 | 
					        res.json({});
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        logger.debug("Claiming Recipe", { buildable, pendingRecipe });
 | 
					        logger.debug("Claiming Recipe", { buildable, pendingRecipe });
 | 
				
			||||||
 | 
					        if (buildable.consumeOnUse) {
 | 
				
			||||||
 | 
					            // TODO: Remove one instance of this recipe, and include that in InventoryChanges.
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        let currencyChanges = {};
 | 
					        let currencyChanges = {};
 | 
				
			||||||
        if (req.query.rush && buildable.skipBuildTimePrice) {
 | 
					        if (req.query.rush && buildable.skipBuildTimePrice) {
 | 
				
			||||||
            currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId);
 | 
					            currencyChanges = await updateCurrency(buildable.skipBuildTimePrice, true, accountId);
 | 
				
			||||||
@ -55,7 +58,7 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
 | 
				
			|||||||
        res.json({
 | 
					        res.json({
 | 
				
			||||||
            InventoryChanges: {
 | 
					            InventoryChanges: {
 | 
				
			||||||
                ...currencyChanges,
 | 
					                ...currencyChanges,
 | 
				
			||||||
                ...(await addItem(accountId, buildable.uniqueName, buildable.buildQuantity)).InventoryChanges
 | 
					                ...(await addItem(accountId, buildable.resultType, buildable.num)).InventoryChanges
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -26,6 +26,7 @@ import { logger } from "@/src/utils/logger";
 | 
				
			|||||||
import { WeaponTypeInternal, getWeaponType, getExalted } from "@/src/services/itemDataService";
 | 
					import { WeaponTypeInternal, getWeaponType, getExalted } from "@/src/services/itemDataService";
 | 
				
			||||||
import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
 | 
					import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
 | 
				
			||||||
import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes";
 | 
					import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
 | 
					import { ExportRecipes } from "warframe-public-export-plus";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const createInventory = async (
 | 
					export const createInventory = async (
 | 
				
			||||||
    accountOwnerId: Types.ObjectId,
 | 
					    accountOwnerId: Types.ObjectId,
 | 
				
			||||||
@ -70,6 +71,25 @@ export const addItem = async (
 | 
				
			|||||||
    typeName: string,
 | 
					    typeName: string,
 | 
				
			||||||
    quantity: number = 1
 | 
					    quantity: number = 1
 | 
				
			||||||
): Promise<{ InventoryChanges: object }> => {
 | 
					): 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]) {
 | 
					    switch (typeName.substr(1).split("/")[1]) {
 | 
				
			||||||
        case "Powersuits":
 | 
					        case "Powersuits":
 | 
				
			||||||
            if (typeName.includes("EntratiMech")) {
 | 
					            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
 | 
					                case "Restoratives": // Codex Scanner, Remote Observer, Starburst
 | 
				
			||||||
                    const inventory = await getInventory(accountId);
 | 
					                    const inventory = await getInventory(accountId);
 | 
				
			||||||
                    const consumablesChanges = [
 | 
					                    const consumablesChanges = [
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,15 @@
 | 
				
			|||||||
import { getIndexAfter } from "@/src/helpers/stringHelpers";
 | 
					import { getIndexAfter } from "@/src/helpers/stringHelpers";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					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 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<Warframe, "patchlogs">;
 | 
					export type MinWarframe = Omit<Warframe, "patchlogs">;
 | 
				
			||||||
export type MinWeapon = Omit<Weapon, "patchlogs">;
 | 
					export type MinWeapon = Omit<Weapon, "patchlogs">;
 | 
				
			||||||
@ -100,13 +107,9 @@ export const blueprintNames = Object.fromEntries(
 | 
				
			|||||||
        .map(name => [name, craftNames[name]])
 | 
					        .map(name => [name, craftNames[name]])
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const buildables = items.filter(item => !!(item as Buildable).components);
 | 
					// Gets a recipe by its uniqueName
 | 
				
			||||||
 | 
					export const getItemByBlueprint = (uniqueName: string): IRecipe | undefined => {
 | 
				
			||||||
export const getItemByBlueprint = (uniqueName: string): (MinItem & Buildable) | undefined => {
 | 
					    return ExportRecipes[uniqueName];
 | 
				
			||||||
    const item = buildables.find(item =>
 | 
					 | 
				
			||||||
        (item as Buildable).components?.find(component => component.uniqueName === uniqueName)
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
    return item;
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getExalted = (uniqueName: string) => {
 | 
					export const getExalted = (uniqueName: string) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -34,9 +34,9 @@ export const startRecipe = async (recipeName: string, accountId: string) => {
 | 
				
			|||||||
        throw new Error(`unknown recipe ${recipeName}`);
 | 
					        throw new Error(`unknown recipe ${recipeName}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const componentsNeeded = recipe.components?.map(component => ({
 | 
					    const componentsNeeded = recipe.ingredients.map(component => ({
 | 
				
			||||||
        uniqueName: component.uniqueName,
 | 
					        uniqueName: component.ItemType,
 | 
				
			||||||
        count: component.itemCount
 | 
					        count: component.ItemCount
 | 
				
			||||||
    }));
 | 
					    }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!componentsNeeded) {
 | 
					    if (!componentsNeeded) {
 | 
				
			||||||
@ -47,11 +47,6 @@ export const startRecipe = async (recipeName: string, accountId: string) => {
 | 
				
			|||||||
    //TODO: consume components used
 | 
					    //TODO: consume components used
 | 
				
			||||||
    //await updateResources(accountId, componentsNeeded);
 | 
					    //await updateResources(accountId, componentsNeeded);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //might be redundant
 | 
					 | 
				
			||||||
    if (recipe.consumeOnBuild) {
 | 
					 | 
				
			||||||
        //consume
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!recipe.buildTime) {
 | 
					    if (!recipe.buildTime) {
 | 
				
			||||||
        logger.error(`recipe ${recipeName} has no build time`);
 | 
					        logger.error(`recipe ${recipeName} has no build time`);
 | 
				
			||||||
        throw new Error(`recipe ${recipeName} has no build time`);
 | 
					        throw new Error(`recipe ${recipeName} has no build time`);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user