XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

feat: replicate dojo research (#701)

e77f8b0e
Sainan <sainan@calamity.inc>
提交于

代码差异

1 个文件 +31 -4
Modified src/controllers/api/guildTechController.ts +31 -4
@@ -2,7 +2,7 @@ import { RequestHandler } from "express";
2 2 import { getGuildForRequestEx } from "@/src/services/guildService";
3 3 import { ExportDojoRecipes } from "warframe-public-export-plus";
4 4 import { getAccountIdForRequest } from "@/src/services/loginService";
5 import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
5 import { addMiscItems, addRecipes, getInventory, updateCurrency } from "@/src/services/inventoryService";
6 6 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
7 7 import { IInventoryChanges } from "@/src/types/purchaseTypes";
8 8
@@ -11,11 +11,12 @@ export const guildTechController: RequestHandler = async (req, res) => {
11 11 const inventory = await getInventory(accountId);
12 12 const guild = await getGuildForRequestEx(req, inventory);
13 13 const data = JSON.parse(String(req.body)) as TGuildTechRequest;
14 if (data.Action == "Sync") {
14 const action = data.Action.split(",")[0];
15 if (action == "Sync") {
15 16 res.json({
16 17 TechProjects: guild.toJSON().TechProjects
17 18 });
18 } else if (data.Action == "Start") {
19 } else if (action == "Start") {
19 20 const recipe = ExportDojoRecipes.research[data.RecipeType!];
20 21 guild.TechProjects ??= [];
21 22 if (!guild.TechProjects.find(x => x.ItemType == data.RecipeType)) {
@@ -31,7 +32,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
31 32 }
32 33 await guild.save();
33 34 res.end();
34 } else if (data.Action == "Contribute") {
35 } else if (action == "Contribute") {
35 36 const contributions = data as IGuildTechContributeFields;
36 37 const techProject = guild.TechProjects!.find(x => x.ItemType == contributions.RecipeType)!;
37 38 if (contributions.RegularCredits > techProject.ReqCredits) {
@@ -70,6 +71,30 @@ export const guildTechController: RequestHandler = async (req, res) => {
70 71 res.json({
71 72 InventoryChanges: inventoryChanges
72 73 });
74 } else if (action == "Buy") {
75 const purchase = data as IGuildTechBuyFields;
76 const quantity = parseInt(data.Action.split(",")[1]);
77 const inventory = await getInventory(accountId);
78 const recipeChanges = [
79 {
80 ItemType: purchase.RecipeType,
81 ItemCount: quantity
82 }
83 ];
84 addRecipes(inventory, recipeChanges);
85 const currencyChanges = updateCurrency(
86 inventory,
87 ExportDojoRecipes.research[purchase.RecipeType].replicatePrice,
88 false
89 );
90 await inventory.save();
91 // Not a mistake: This response uses `inventoryChanges` instead of `InventoryChanges`.
92 res.json({
93 inventoryChanges: {
94 ...currencyChanges,
95 Recipes: recipeChanges
96 }
97 });
73 98 } else {
74 99 throw new Error(`unknown guildTech action: ${data.Action}`);
75 100 }
@@ -85,6 +110,8 @@ interface IGuildTechStartFields {
85 110 RecipeType: string;
86 111 }
87 112
113 type IGuildTechBuyFields = IGuildTechStartFields;
114
88 115 interface IGuildTechContributeFields {
89 116 ResearchId: "";
90 117 RecipeType: string;