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: subsuming warframes (#686)

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

代码差异

4 个文件 +130 -10
Modified src/controllers/api/infestedFoundryController.ts +94 -3
@@ -1,10 +1,17 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { getJSONfromString } from "@/src/helpers/stringHelpers";
4 import { getInventory, addMiscItems } from "@/src/services/inventoryService";
4 import { getInventory, addMiscItems, updateCurrency, addRecipes } from "@/src/services/inventoryService";
5 5 import { IOid } from "@/src/types/commonTypes";
6 import { IInfestedFoundry, IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
7 import { ExportMisc } from "warframe-public-export-plus";
6 import {
7 IConsumedSuit,
8 IInfestedFoundry,
9 IInventoryDatabaseDocument,
10 IMiscItem,
11 ITypeCount
12 } from "@/src/types/inventoryTypes/inventoryTypes";
13 import { ExportMisc, ExportRecipes } from "warframe-public-export-plus";
14 import { getRecipe } from "@/src/services/itemDataService";
8 15
9 16 export const infestedFoundryController: RequestHandler = async (req, res) => {
10 17 const accountId = await getAccountIdForRequest(req);
@@ -110,6 +117,67 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
110 117 res.status(404).end();
111 118 break;
112 119
120 case "a": {
121 // subsume warframe
122 const request = getJSONfromString(String(req.body)) as IHelminthSubsumeRequest;
123 const inventory = await getInventory(accountId);
124 const recipe = getRecipe(request.Recipe)!;
125 for (const ingredient of recipe.secretIngredients!) {
126 const resource = inventory.InfestedFoundry!.Resources!.find(x => x.ItemType == ingredient.ItemType);
127 if (resource) {
128 resource.Count -= ingredient.ItemCount;
129 }
130 }
131 const suit = inventory.Suits.find(x => x._id.toString() == request.SuitId.$oid)!;
132 inventory.Suits.pull(suit);
133 const consumedSuit: IConsumedSuit = { s: suit.ItemType };
134 if (suit.Configs && suit.Configs[0] && suit.Configs[0].pricol) {
135 consumedSuit.c = suit.Configs[0].pricol;
136 }
137 inventory.InfestedFoundry!.Slots!--;
138 inventory.InfestedFoundry!.ConsumedSuits ??= [];
139 inventory.InfestedFoundry!.ConsumedSuits?.push(consumedSuit);
140 inventory.InfestedFoundry!.LastConsumedSuit = suit;
141 inventory.InfestedFoundry!.AbilityOverrideUnlockCooldown = new Date(
142 new Date().getTime() + 24 * 60 * 60 * 1000
143 );
144 addInfestedFoundryXP(inventory.InfestedFoundry!, 1600_00);
145 await inventory.save();
146 console.log(inventory.toJSON().InfestedFoundry);
147 res.json({
148 InventoryChanges: {
149 RemovedIdItems: [
150 {
151 ItemId: request.SuitId
152 }
153 ],
154 SuitBin: {
155 count: -1,
156 platinum: 0,
157 Slots: 1
158 },
159 InfestedFoundry: inventory.toJSON().InfestedFoundry
160 }
161 });
162 break;
163 }
164
165 case "r": {
166 // rush subsume
167 const inventory = await getInventory(accountId);
168 const currencyChanges = updateCurrency(inventory, 50, true);
169 const recipeChanges = handleSubsumeCompletion(inventory);
170 await inventory.save();
171 res.json({
172 InventoryChanges: {
173 ...currencyChanges,
174 Recipes: recipeChanges,
175 InfestedFoundry: inventory.toJSON().InfestedFoundry
176 }
177 });
178 break;
179 }
180
113 181 default:
114 182 throw new Error(`unhandled infestedFoundry mode: ${String(req.query.mode)}`);
115 183 }
@@ -165,3 +233,26 @@ const addInfestedFoundryXP = (infestedFoundry: IInfestedFoundry, delta: number):
165 233 infestedFoundry.Slots += 20;
166 234 }
167 235 };
236
237 interface IHelminthSubsumeRequest {
238 SuitId: IOid;
239 Recipe: string;
240 }
241
242 export const handleSubsumeCompletion = (inventory: IInventoryDatabaseDocument): ITypeCount[] => {
243 const [recipeType] = Object.entries(ExportRecipes).find(
244 ([_recipeType, recipe]) =>
245 recipe.secretIngredientAction == "SIA_WARFRAME_ABILITY" &&
246 recipe.secretIngredients![0].ItemType == inventory.InfestedFoundry!.LastConsumedSuit!.ItemType
247 )!;
248 inventory.InfestedFoundry!.LastConsumedSuit = undefined;
249 inventory.InfestedFoundry!.AbilityOverrideUnlockCooldown = undefined;
250 const recipeChanges: ITypeCount[] = [
251 {
252 ItemType: recipeType,
253 ItemCount: 1
254 }
255 ];
256 addRecipes(inventory, recipeChanges);
257 return recipeChanges;
258 };
Modified src/controllers/api/inventoryController.ts +11 -1
@@ -5,7 +5,7 @@ import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
5 5 import { config } from "@/src/services/configService";
6 6 import allDialogue from "@/static/fixed_responses/allDialogue.json";
7 7 import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
8 import { IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
8 import { IInventoryDatabaseDocument, IShipInventory, equipmentKeys } from "@/src/types/inventoryTypes/inventoryTypes";
9 9 import { IPolarity, ArtifactPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
10 10 import {
11 11 ExportCustoms,
@@ -15,6 +15,7 @@ import {
15 15 ExportResources,
16 16 ExportVirtuals
17 17 } from "warframe-public-export-plus";
18 import { handleSubsumeCompletion } from "./infestedFoundryController";
18 19
19 20 export const inventoryController: RequestHandler = async (request, response) => {
20 21 let account;
@@ -57,6 +58,15 @@ export const inventoryController: RequestHandler = async (request, response) =>
57 58 await inventory.save();
58 59 }
59 60
61 if (
62 inventory.InfestedFoundry &&
63 inventory.InfestedFoundry.AbilityOverrideUnlockCooldown &&
64 new Date() >= inventory.InfestedFoundry.AbilityOverrideUnlockCooldown
65 ) {
66 handleSubsumeCompletion(inventory as unknown as IInventoryDatabaseDocument);
67 await inventory.save();
68 }
69
60 70 //TODO: make a function that converts from database representation to client
61 71 const inventoryJSON = inventory.toJSON();
62 72
Modified src/models/inventoryModels/inventoryModel.ts +19 -5
@@ -459,10 +459,13 @@ const settingsSchema = new Schema<ISettings>({
459 459 TradingRulesConfirmed: Boolean
460 460 });
461 461
462 const consumedSchuitsSchema = new Schema<IConsumedSuit>({
463 s: String,
464 c: colorSchema
465 });
462 const consumedSchuitsSchema = new Schema<IConsumedSuit>(
463 {
464 s: String,
465 c: colorSchema
466 },
467 { _id: false }
468 );
466 469
467 470 const helminthResourceSchema = new Schema<IHelminthResource>({ ItemType: String, Count: Number }, { _id: false });
468 471
@@ -475,11 +478,22 @@ const infestedFoundrySchema = new Schema<IInfestedFoundry>(
475 478 ConsumedSuits: { type: [consumedSchuitsSchema], default: undefined },
476 479 InvigorationIndex: Number,
477 480 InvigorationSuitOfferings: { type: [String], default: undefined },
478 InvigorationsApplied: Number
481 InvigorationsApplied: Number,
482 LastConsumedSuit: { type: EquipmentSchema, default: undefined },
483 AbilityOverrideUnlockCooldown: Date
479 484 },
480 485 { _id: false }
481 486 );
482 487
488 infestedFoundrySchema.set("toJSON", {
489 transform(_doc, ret, _options) {
490 if (ret.AbilityOverrideUnlockCooldown) {
491 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
492 ret.AbilityOverrideUnlockCooldown = toMongoDate(ret.AbilityOverrideUnlockCooldown);
493 }
494 }
495 });
496
483 497 const questProgressSchema = new Schema<IQuestProgress>({
484 498 c: Number,
485 499 i: Boolean,
Modified src/types/inventoryTypes/inventoryTypes.ts +6 -1
@@ -518,10 +518,13 @@ export interface IFusionTreasure {
518 518 Sockets: number;
519 519 }
520 520
521 // Like ITypeCount except 'Count' instead of 'ItemCount'
522 521 export interface IHelminthResource {
523 522 ItemType: string;
524 523 Count: number;
524 RecentlyConvertedResources?: {
525 ItemType: string;
526 Date: number;
527 }[];
525 528 }
526 529
527 530 export interface IInfestedFoundry {
@@ -533,6 +536,8 @@ export interface IInfestedFoundry {
533 536 InvigorationIndex?: number;
534 537 InvigorationSuitOfferings?: string[];
535 538 InvigorationsApplied?: number;
539 LastConsumedSuit?: IEquipmentDatabase;
540 AbilityOverrideUnlockCooldown?: Date;
536 541 }
537 542
538 543 export interface IConsumedSuit {