forked from OpenWF/SpaceNinjaServer
feat: replicate dojo research (#701)
This commit is contained in:
parent
74ed098692
commit
e77f8b0e51
@ -2,7 +2,7 @@ import { RequestHandler } from "express";
|
||||
import { getGuildForRequestEx } from "@/src/services/guildService";
|
||||
import { ExportDojoRecipes } from "warframe-public-export-plus";
|
||||
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 { IInventoryChanges } from "@/src/types/purchaseTypes";
|
||||
|
||||
@ -11,11 +11,12 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
||||
const inventory = await getInventory(accountId);
|
||||
const guild = await getGuildForRequestEx(req, inventory);
|
||||
const data = JSON.parse(String(req.body)) as TGuildTechRequest;
|
||||
if (data.Action == "Sync") {
|
||||
const action = data.Action.split(",")[0];
|
||||
if (action == "Sync") {
|
||||
res.json({
|
||||
TechProjects: guild.toJSON().TechProjects
|
||||
});
|
||||
} else if (data.Action == "Start") {
|
||||
} else if (action == "Start") {
|
||||
const recipe = ExportDojoRecipes.research[data.RecipeType!];
|
||||
guild.TechProjects ??= [];
|
||||
if (!guild.TechProjects.find(x => x.ItemType == data.RecipeType)) {
|
||||
@ -31,7 +32,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
await guild.save();
|
||||
res.end();
|
||||
} else if (data.Action == "Contribute") {
|
||||
} else if (action == "Contribute") {
|
||||
const contributions = data as IGuildTechContributeFields;
|
||||
const techProject = guild.TechProjects!.find(x => x.ItemType == contributions.RecipeType)!;
|
||||
if (contributions.RegularCredits > techProject.ReqCredits) {
|
||||
@ -70,6 +71,30 @@ export const guildTechController: RequestHandler = async (req, res) => {
|
||||
res.json({
|
||||
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 {
|
||||
throw new Error(`unknown guildTech action: ${data.Action}`);
|
||||
}
|
||||
@ -85,6 +110,8 @@ interface IGuildTechStartFields {
|
||||
RecipeType: string;
|
||||
}
|
||||
|
||||
type IGuildTechBuyFields = IGuildTechStartFields;
|
||||
|
||||
interface IGuildTechContributeFields {
|
||||
ResearchId: "";
|
||||
RecipeType: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user