feat: replicate dojo research
This commit is contained in:
		
							parent
							
								
									7a6ffd94dc
								
							
						
					
					
						commit
						3f0bf48750
					
				@ -2,7 +2,7 @@ import { RequestHandler } from "express";
 | 
				
			|||||||
import { getGuildForRequestEx } from "@/src/services/guildService";
 | 
					import { getGuildForRequestEx } from "@/src/services/guildService";
 | 
				
			||||||
import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
					import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
 | 
					import { addMiscItems, addRecipes, getInventory, updateCurrency } from "@/src/services/inventoryService";
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
					import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -11,11 +11,12 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
    const inventory = await getInventory(accountId);
 | 
					    const inventory = await getInventory(accountId);
 | 
				
			||||||
    const guild = await getGuildForRequestEx(req, inventory);
 | 
					    const guild = await getGuildForRequestEx(req, inventory);
 | 
				
			||||||
    const data = JSON.parse(String(req.body)) as TGuildTechRequest;
 | 
					    const data = JSON.parse(String(req.body)) as TGuildTechRequest;
 | 
				
			||||||
    if (data.Action == "Sync") {
 | 
					    const action = data.Action.split(",")[0];
 | 
				
			||||||
 | 
					    if (action == "Sync") {
 | 
				
			||||||
        res.json({
 | 
					        res.json({
 | 
				
			||||||
            TechProjects: guild.toJSON().TechProjects
 | 
					            TechProjects: guild.toJSON().TechProjects
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    } else if (data.Action == "Start") {
 | 
					    } else if (action == "Start") {
 | 
				
			||||||
        const recipe = ExportDojoRecipes.research[data.RecipeType!];
 | 
					        const recipe = ExportDojoRecipes.research[data.RecipeType!];
 | 
				
			||||||
        guild.TechProjects ??= [];
 | 
					        guild.TechProjects ??= [];
 | 
				
			||||||
        if (!guild.TechProjects.find(x => x.ItemType == data.RecipeType)) {
 | 
					        if (!guild.TechProjects.find(x => x.ItemType == data.RecipeType)) {
 | 
				
			||||||
@ -31,7 +32,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        await guild.save();
 | 
					        await guild.save();
 | 
				
			||||||
        res.end();
 | 
					        res.end();
 | 
				
			||||||
    } else if (data.Action == "Contribute") {
 | 
					    } else if (action == "Contribute") {
 | 
				
			||||||
        const contributions = data as IGuildTechContributeFields;
 | 
					        const contributions = data as IGuildTechContributeFields;
 | 
				
			||||||
        const techProject = guild.TechProjects!.find(x => x.ItemType == contributions.RecipeType)!;
 | 
					        const techProject = guild.TechProjects!.find(x => x.ItemType == contributions.RecipeType)!;
 | 
				
			||||||
        if (contributions.RegularCredits > techProject.ReqCredits) {
 | 
					        if (contributions.RegularCredits > techProject.ReqCredits) {
 | 
				
			||||||
@ -70,6 +71,30 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
        res.json({
 | 
					        res.json({
 | 
				
			||||||
            InventoryChanges: inventoryChanges
 | 
					            InventoryChanges: inventoryChanges
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					    } else if (action == "Buy") {
 | 
				
			||||||
 | 
					        const purchase = data as IGuildTechBuyFields;
 | 
				
			||||||
 | 
					        const quantity = parseInt(data.Action.split(",")[1]);
 | 
				
			||||||
 | 
					        const inventory = await getInventory(accountId);
 | 
				
			||||||
 | 
					        const recipeChanges = [
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ItemType: purchase.RecipeType,
 | 
				
			||||||
 | 
					                ItemCount: quantity
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					        addRecipes(inventory, recipeChanges);
 | 
				
			||||||
 | 
					        const currencyChanges = updateCurrency(
 | 
				
			||||||
 | 
					            inventory,
 | 
				
			||||||
 | 
					            ExportDojoRecipes.research[purchase.RecipeType].replicatePrice,
 | 
				
			||||||
 | 
					            false
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        await inventory.save();
 | 
				
			||||||
 | 
					        // Not a mistake: This response uses `inventoryChanges` instead of `InventoryChanges`.
 | 
				
			||||||
 | 
					        res.json({
 | 
				
			||||||
 | 
					            inventoryChanges: {
 | 
				
			||||||
 | 
					                ...currencyChanges,
 | 
				
			||||||
 | 
					                Recipes: recipeChanges
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        throw new Error(`unknown guildTech action: ${data.Action}`);
 | 
					        throw new Error(`unknown guildTech action: ${data.Action}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -85,6 +110,8 @@ interface IGuildTechStartFields {
 | 
				
			|||||||
    RecipeType: string;
 | 
					    RecipeType: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type IGuildTechBuyFields = IGuildTechStartFields;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface IGuildTechContributeFields {
 | 
					interface IGuildTechContributeFields {
 | 
				
			||||||
    ResearchId: "";
 | 
					    ResearchId: "";
 | 
				
			||||||
    RecipeType: string;
 | 
					    RecipeType: string;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user