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: remove syndicate sacrifices from inventory (#735)

2c875cad
Sainan <sainan@calamity.inc>
提交于

代码差异

1 个文件 +30 -13
Modified src/controllers/api/syndicateSacrificeController.ts +30 -13
@@ -1,29 +1,21 @@
1 1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 2 import { RequestHandler } from "express";
3 3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 import { ExportSyndicates } from "warframe-public-export-plus";
4 import { ExportSyndicates, ISyndicateSacrifice } from "warframe-public-export-plus";
5 5 import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
6 import { getInventory } from "@/src/services/inventoryService";
6 import { addMiscItems, combineInventoryChanges, getInventory, updateCurrency } from "@/src/services/inventoryService";
7 7 import { IInventoryChanges } from "@/src/types/purchaseTypes";
8 8
9 9 export const syndicateSacrificeController: RequestHandler = async (request, response) => {
10 10 const accountId = await getAccountIdForRequest(request);
11 11 const inventory = await getInventory(accountId);
12 const data = getJSONfromString(String(request.body)) as ISyndicateSacrifice;
12 const data = getJSONfromString(String(request.body)) as ISyndicateSacrificeRequest;
13 13
14 14 let syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
15 15 if (!syndicate) {
16 16 syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
17 17 }
18 18
19 let reward: string | undefined;
20
21 const manifest = ExportSyndicates[data.AffiliationTag];
22 if (manifest?.initiationReward && data.SacrificeLevel == 0) {
23 reward = manifest.initiationReward;
24 syndicate.Initiated = true;
25 }
26
27 19 const level = data.SacrificeLevel - (syndicate.Title ?? 0);
28 20 const res: ISyndicateSacrificeResponse = {
29 21 AffiliationTag: data.AffiliationTag,
@@ -33,18 +25,43 @@ export const syndicateSacrificeController: RequestHandler = async (request, resp
33 25 NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
34 26 };
35 27
28 const manifest = ExportSyndicates[data.AffiliationTag];
29 let sacrifice: ISyndicateSacrifice | undefined;
30 let reward: string | undefined;
31 if (data.SacrificeLevel == 0) {
32 sacrifice = manifest.initiationSacrifice;
33 reward = manifest.initiationReward;
34 syndicate.Initiated = true;
35 } else {
36 sacrifice = manifest.titles?.find(x => x.level == data.SacrificeLevel)?.sacrifice;
37 }
38
39 if (sacrifice) {
40 res.InventoryChanges = { ...updateCurrency(inventory, sacrifice.credits, false) };
41
42 const miscItemChanges = sacrifice.items.map(x => ({
43 ItemType: x.ItemType,
44 ItemCount: x.ItemCount * -1
45 }));
46 addMiscItems(inventory, miscItemChanges);
47 res.InventoryChanges.MiscItems = miscItemChanges;
48 }
49
36 50 if (syndicate?.Title !== undefined) syndicate.Title += 1;
37 51
38 52 await inventory.save();
39 53
40 54 if (reward) {
41 res.InventoryChanges = (await handleStoreItemAcquisition(reward, accountId)).InventoryChanges;
55 combineInventoryChanges(
56 res.InventoryChanges,
57 (await handleStoreItemAcquisition(reward, accountId)).InventoryChanges
58 );
42 59 }
43 60
44 61 response.json(res);
45 62 };
46 63
47 interface ISyndicateSacrifice {
64 interface ISyndicateSacrificeRequest {
48 65 AffiliationTag: string;
49 66 SacrificeLevel: number;
50 67 AllowMultiple: boolean;