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

fix: handle standing limits in fishmongerController (#795)

79f19374
Sainan <sainan@calamity.inc>
提交于

代码差异

3 个文件 +37 -26
Modified src/controllers/api/fishmongerController.ts +23 -14
@@ -1,9 +1,10 @@
1 1 import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 import { addMiscItems, getInventory } from "@/src/services/inventoryService";
2 import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
3 import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
3 4 import { getAccountIdForRequest } from "@/src/services/loginService";
4 5 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
5 6 import { RequestHandler } from "express";
6 import { ExportResources } from "warframe-public-export-plus";
7 import { ExportResources, ExportSyndicates } from "warframe-public-export-plus";
7 8
8 9 export const fishmongerController: RequestHandler = async (req, res) => {
9 10 const accountId = await getAccountIdForRequest(req);
@@ -11,7 +12,7 @@ export const fishmongerController: RequestHandler = async (req, res) => {
11 12 const body = getJSONfromString(String(req.body)) as IFishmongerRequest;
12 13 const miscItemChanges: IMiscItem[] = [];
13 14 let syndicateTag: string | undefined;
14 let standingChange = 0;
15 let gainedStanding = 0;
15 16 for (const fish of body.Fish) {
16 17 const fishData = ExportResources[fish.ItemType];
17 18 if (req.query.dissect == "1") {
@@ -25,21 +26,29 @@ export const fishmongerController: RequestHandler = async (req, res) => {
25 26 }
26 27 } else {
27 28 syndicateTag = fishData.syndicateTag!;
28 standingChange += fishData.standingBonus! * fish.ItemCount;
29 gainedStanding += fishData.standingBonus! * fish.ItemCount;
29 30 }
30 31 miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
31 32 }
32 33 addMiscItems(inventory, miscItemChanges);
33 if (standingChange && syndicateTag) {
34 const syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
35 if (syndicate !== undefined) {
36 syndicate.Standing += standingChange;
37 } else {
38 inventory.Affiliations.push({
39 Tag: syndicateTag,
40 Standing: standingChange
41 });
34 if (gainedStanding && syndicateTag) {
35 let syndicate = inventory.Affiliations.find(x => x.Tag == syndicateTag);
36 if (!syndicate) {
37 syndicate = inventory.Affiliations[inventory.Affiliations.push({ Tag: syndicateTag, Standing: 0 }) - 1];
38 }
39 const syndicateMeta = ExportSyndicates[syndicateTag];
40
41 const max = getMaxStanding(syndicateMeta, syndicate.Title ?? 0);
42 if (syndicate.Standing + gainedStanding > max) {
43 gainedStanding = max - syndicate.Standing;
42 44 }
45 if (gainedStanding > getStandingLimit(inventory, syndicateMeta.dailyLimitBin)) {
46 gainedStanding = getStandingLimit(inventory, syndicateMeta.dailyLimitBin);
47 }
48
49 syndicate.Standing += gainedStanding;
50
51 updateStandingLimit(inventory, syndicateMeta.dailyLimitBin, gainedStanding);
43 52 }
44 53 await inventory.save();
45 54 res.json({
@@ -47,7 +56,7 @@ export const fishmongerController: RequestHandler = async (req, res) => {
47 56 MiscItems: miscItemChanges
48 57 },
49 58 SyndicateTag: syndicateTag,
50 StandingChange: standingChange
59 StandingChange: gainedStanding
51 60 });
52 61 };
53 62
Modified src/controllers/api/syndicateStandingBonusController.ts +2 -12
@@ -3,7 +3,8 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { addMiscItems, getInventory, getStandingLimit, updateStandingLimit } from "@/src/services/inventoryService";
4 4 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
5 5 import { IOid } from "@/src/types/commonTypes";
6 import { ExportSyndicates, ISyndicate } from "warframe-public-export-plus";
6 import { ExportSyndicates } from "warframe-public-export-plus";
7 import { getMaxStanding } from "@/src/helpers/syndicateStandingHelper";
7 8
8 9 export const syndicateStandingBonusController: RequestHandler = async (req, res) => {
9 10 const accountId = await getAccountIdForRequest(req);
@@ -67,14 +68,3 @@ interface ISyndicateStandingBonusRequest {
67 68 };
68 69 ModularWeaponId: IOid; // Seems to just be "000000000000000000000000", also note there's a "Category" query field
69 70 }
70
71 const getMaxStanding = (syndicate: ISyndicate, title: number): number => {
72 if (!syndicate.titles) {
73 // LibrarySyndicate
74 return 125000;
75 }
76 if (title == 0) {
77 return syndicate.titles.find(x => x.level == 1)!.minStanding;
78 }
79 return syndicate.titles.find(x => x.level == title)!.maxStanding;
80 };
Added src/helpers/syndicateStandingHelper.ts +12 -0
@@ -0,0 +1,12 @@
1 import { ISyndicate } from "warframe-public-export-plus";
2
3 export const getMaxStanding = (syndicate: ISyndicate, title: number): number => {
4 if (!syndicate.titles) {
5 // LibrarySyndicate
6 return 125000;
7 }
8 if (title == 0) {
9 return syndicate.titles.find(x => x.level == 1)!.minStanding;
10 }
11 return syndicate.titles.find(x => x.level == title)!.maxStanding;
12 };