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

XFESpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/XFESpaceNinjaServer

fix: provide LoadOutPresets & Ships in missionInventoryUpdate response (#869)

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

代码差异

2 个文件 +13 -16
Modified src/controllers/api/inventoryController.ts +10 -10
@@ -1,6 +1,6 @@
1 1 import { RequestHandler } from "express";
2 2 import { getAccountForRequest } from "@/src/services/loginService";
3 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
3 import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
4 4 import { config } from "@/src/services/configService";
5 5 import allDialogue from "@/static/fixed_responses/allDialogue.json";
6 6 import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
@@ -51,6 +51,13 @@ export const inventoryController: RequestHandler = async (request, response) =>
51 51 await inventory.save();
52 52 }
53 53
54 response.json(await getInventoryResponse(inventory, "xpBasedLevelCapDisabled" in request.query));
55 };
56
57 export const getInventoryResponse = async (
58 inventory: TInventoryDatabaseDocument,
59 xpBasedLevelCapDisabled: boolean
60 ): Promise<IInventoryClient> => {
54 61 const inventoryWithLoadOutPresets = await inventory.populate<{ LoadOutPresets: ILoadoutDatabase }>(
55 62 "LoadOutPresets"
56 63 );
@@ -59,15 +66,6 @@ export const inventoryController: RequestHandler = async (request, response) =>
59 66 );
60 67 const inventoryResponse = inventoryWithLoadOutPresetsAndShips.toJSON<IInventoryClient>();
61 68
62 applyInventoryResponseOverrides(inventoryResponse, "xpBasedLevelCapDisabled" in request.query);
63
64 response.json(inventoryResponse);
65 };
66
67 export const applyInventoryResponseOverrides = (
68 inventoryResponse: IInventoryClient,
69 xpBasedLevelCapDisabled: boolean
70 ): void => {
71 69 if (config.infiniteCredits) {
72 70 inventoryResponse.RegularCredits = 999999999;
73 71 }
@@ -260,6 +258,8 @@ export const applyInventoryResponseOverrides = (
260 258 inventoryResponse.HasOwnedVoidProjectionsPreviously = true;
261 259
262 260 inventoryResponse.LastInventorySync = toOid(new Types.ObjectId());
261
262 return inventoryResponse;
263 263 };
264 264
265 265 const addString = (arr: string[], str: string): void => {
Modified src/controllers/api/missionInventoryUpdateController.ts +3 -6
@@ -8,8 +8,7 @@ import {
8 8 calculateFinalCredits
9 9 } from "@/src/services/missionInventoryUpdateService";
10 10 import { getInventory } from "@/src/services/inventoryService";
11 import { applyInventoryResponseOverrides } from "./inventoryController";
12 import { IInventoryClient } from "@/src/types/inventoryTypes/inventoryTypes";
11 import { getInventoryResponse } from "./inventoryController";
13 12
14 13 /*
15 14 **** INPUT ****
@@ -61,8 +60,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
61 60
62 61 if (missionReport.MissionStatus !== "GS_SUCCESS") {
63 62 await inventory.save();
64 const inventoryResponse = inventory.toJSON<IInventoryClient>();
65 applyInventoryResponseOverrides(inventoryResponse, true);
63 const inventoryResponse = await getInventoryResponse(inventory, true);
66 64 res.json({
67 65 InventoryJson: JSON.stringify(inventoryResponse),
68 66 MissionRewards: []
@@ -83,8 +81,7 @@ export const missionInventoryUpdateController: RequestHandler = async (req, res)
83 81 });
84 82
85 83 await inventory.save();
86 const inventoryResponse = inventory.toJSON<IInventoryClient>();
87 applyInventoryResponseOverrides(inventoryResponse, true);
84 const inventoryResponse = await getInventoryResponse(inventory, true);
88 85
89 86 //TODO: figure out when to send inventory. it is needed for many cases.
90 87 res.json({