返回提交历史
Added
src/controllers/api/fishmongerController.ts
+38
-0
Modified
src/routes/api.ts
+2
-0
XFEstudio/XFESpaceNinjaServer
feat: fish dissection (#663)
d930c3d9
代码差异
2 个文件
+40
-0
@@ -0,0 +1,38 @@
1
import { getJSONfromString } from "@/src/helpers/stringHelpers";
2
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
3
import { getAccountIdForRequest } from "@/src/services/loginService";
4
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
5
import { RequestHandler } from "express";
6
import { ExportResources } from "warframe-public-export-plus";
7
8
export const fishmongerController: RequestHandler = async (req, res) => {
9
if (!req.query.dissect) {
10
throw new Error("expected fishmonger request to be for dissection");
11
}
12
const accountId = await getAccountIdForRequest(req);
13
const inventory = await getInventory(accountId);
14
const body = getJSONfromString(String(req.body)) as IFishmongerRequest;
15
const miscItemChanges: IMiscItem[] = [];
16
for (const fish of body.Fish) {
17
for (const part of ExportResources[fish.ItemType].dissectionParts!) {
18
const partItem = miscItemChanges.find(x => x.ItemType == part.ItemType);
19
if (partItem) {
20
partItem.ItemCount += part.ItemCount;
21
} else {
22
miscItemChanges.push(part);
23
}
24
}
25
miscItemChanges.push({ ItemType: fish.ItemType, ItemCount: fish.ItemCount * -1 });
26
}
27
addMiscItems(inventory, miscItemChanges);
28
await inventory.save();
29
res.json({
30
InventoryChanges: {
31
MiscItems: miscItemChanges
32
}
33
});
34
};
35
36
interface IFishmongerRequest {
37
Fish: IMiscItem[];
38
}
@@ -11,6 +11,7 @@ import { dronesController } from "@/src/controllers/api/dronesController";
11
11
import { endlessXpController } from "@/src/controllers/api/endlessXpController";
12
12
import { evolveWeaponController } from "@/src/controllers/api/evolveWeaponController";
13
13
import { findSessionsController } from "@/src/controllers/api/findSessionsController";
14
import { fishmongerController } from "@/src/controllers/api/fishmongerController";
14
15
import { focusController } from "@/src/controllers/api/focusController";
15
16
import { fusionTreasuresController } from "@/src/controllers/api/fusionTreasuresController";
16
17
import { genericUpdateController } from "@/src/controllers/api/genericUpdateController";
@@ -113,6 +114,7 @@ apiRouter.post("/createGuild.php", createGuildController);
113
114
apiRouter.post("/endlessXp.php", endlessXpController);
114
115
apiRouter.post("/evolveWeapon.php", evolveWeaponController);
115
116
apiRouter.post("/findSessions.php", findSessionsController);
117
apiRouter.post("/fishmonger.php", fishmongerController);
116
118
apiRouter.post("/focus.php", focusController);
117
119
apiRouter.post("/fusionTreasures.php", fusionTreasuresController);
118
120
apiRouter.post("/genericUpdate.php", genericUpdateController);