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

chore: move syndicate sacrifice stuff into syndicateSacrificeController (#682)

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

代码差异

3 个文件 +50 -72
Modified src/controllers/api/syndicateSacrificeController.ts +50 -15
@@ -1,24 +1,59 @@
1 1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 import { syndicateSacrifice } from "@/src/services/inventoryService";
3 import { ISyndicateSacrifice } from "@/src/types/syndicateTypes";
4 2 import { RequestHandler } from "express";
5 3 import { getAccountIdForRequest } from "@/src/services/loginService";
4 import { ExportSyndicates } from "warframe-public-export-plus";
5 import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
6 import { getInventory } from "@/src/services/inventoryService";
7 import { IInventoryChanges } from "@/src/types/purchaseTypes";
6 8
7 const syndicateSacrificeController: RequestHandler = async (request, response) => {
9 export const syndicateSacrificeController: RequestHandler = async (request, response) => {
8 10 const accountId = await getAccountIdForRequest(request);
9 const update = getJSONfromString(String(request.body)) as ISyndicateSacrifice;
10 let reply = {};
11 try {
12 if (typeof update !== "object") {
13 throw new Error("Invalid data format");
14 }
15
16 reply = await syndicateSacrifice(update, accountId);
17 } catch (err) {
18 console.error("Error parsing JSON data:", err);
11 const inventory = await getInventory(accountId);
12 const data = getJSONfromString(String(request.body)) as ISyndicateSacrifice;
13
14 let syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
15 if (!syndicate) {
16 syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
17 }
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 const level = data.SacrificeLevel - (syndicate.Title ?? 0);
28 const res: ISyndicateSacrificeResponse = {
29 AffiliationTag: data.AffiliationTag,
30 InventoryChanges: {},
31 Level: data.SacrificeLevel,
32 LevelIncrease: level <= 0 ? 1 : level,
33 NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
34 };
35
36 if (syndicate?.Title !== undefined) syndicate.Title += 1;
37
38 await inventory.save();
39
40 if (reward) {
41 res.InventoryChanges = (await handleStoreItemAcquisition(reward, accountId)).InventoryChanges;
19 42 }
20 43
21 response.json(reply);
44 response.json(res);
22 45 };
23 46
24 export { syndicateSacrificeController };
47 interface ISyndicateSacrifice {
48 AffiliationTag: string;
49 SacrificeLevel: number;
50 AllowMultiple: boolean;
51 }
52
53 interface ISyndicateSacrificeResponse {
54 AffiliationTag: string;
55 Level: number;
56 LevelIncrease: number;
57 InventoryChanges: IInventoryChanges;
58 NewEpisodeReward: boolean;
59 }
Modified src/services/inventoryService.ts +0 -42
@@ -28,7 +28,6 @@ import {
28 28 } from "../types/requestTypes";
29 29 import { logger } from "@/src/utils/logger";
30 30 import { getWeaponType, getExalted } from "@/src/services/itemDataService";
31 import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
32 31 import { IEquipmentClient, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
33 32 import {
34 33 ExportArcanes,
@@ -38,11 +37,9 @@ import {
38 37 ExportRecipes,
39 38 ExportResources,
40 39 ExportSentinels,
41 ExportSyndicates,
42 40 ExportUpgrades
43 41 } from "warframe-public-export-plus";
44 42 import { createShip } from "./shipService";
45 import { handleStoreItemAcquisition } from "./purchaseService";
46 43
47 44 export const createInventory = async (
48 45 accountOwnerId: Types.ObjectId,
@@ -552,45 +549,6 @@ export const updateTheme = async (data: IThemeUpdateRequest, accountId: string):
552 549 await inventory.save();
553 550 };
554 551
555 export const syndicateSacrifice = async (
556 data: ISyndicateSacrifice,
557 accountId: string
558 ): Promise<ISyndicateSacrificeResponse> => {
559 const inventory = await getInventory(accountId);
560
561 let syndicate = inventory.Affiliations.find(x => x.Tag == data.AffiliationTag);
562 if (!syndicate) {
563 syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: data.AffiliationTag, Standing: 0 }) - 1];
564 }
565
566 let reward: string | undefined;
567
568 const manifest = ExportSyndicates[data.AffiliationTag];
569 if (manifest?.initiationReward && data.SacrificeLevel == 0) {
570 reward = manifest.initiationReward;
571 syndicate.Initiated = true;
572 }
573
574 const level = data.SacrificeLevel - (syndicate.Title ?? 0);
575 const res: ISyndicateSacrificeResponse = {
576 AffiliationTag: data.AffiliationTag,
577 InventoryChanges: {},
578 Level: data.SacrificeLevel,
579 LevelIncrease: level <= 0 ? 1 : level,
580 NewEpisodeReward: syndicate?.Tag == "RadioLegionIntermission9Syndicate"
581 };
582
583 if (syndicate?.Title !== undefined) syndicate.Title += 1;
584
585 await inventory.save();
586
587 if (reward) {
588 res.InventoryChanges = (await handleStoreItemAcquisition(reward, accountId)).InventoryChanges;
589 }
590
591 return res;
592 };
593
594 552 export const addEquipment = async (
595 553 category: TEquipmentKey,
596 554 type: string,
Deleted src/types/syndicateTypes.ts +0 -15
@@ -1,15 +0,0 @@
1 import { IInventoryChanges } from "./purchaseTypes";
2
3 export interface ISyndicateSacrifice {
4 AffiliationTag: string;
5 SacrificeLevel: number;
6 AllowMultiple: boolean;
7 }
8
9 export interface ISyndicateSacrificeResponse {
10 AffiliationTag: string;
11 Level: number;
12 LevelIncrease: number;
13 InventoryChanges: IInventoryChanges;
14 NewEpisodeReward: boolean;
15 }