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

chore(webui): use gildWeaponController (#1518)

also use `TEquipmentKey` instead `WeaponTypeInternal | "Hoverboards"` Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

540961ff
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

4 个文件 +27 -59
Modified src/controllers/api/gildWeaponController.ts +24 -30
@@ -2,36 +2,25 @@ import { RequestHandler } from "express";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { getJSONfromString } from "@/src/helpers/stringHelpers";
4 4 import { addMiscItems, getInventory } from "@/src/services/inventoryService";
5 import { WeaponTypeInternal } from "@/src/services/itemDataService";
5 import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
6 6 import { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
7 7 import { ExportRecipes } from "warframe-public-export-plus";
8 8 import { IInventoryChanges } from "@/src/types/purchaseTypes";
9 9
10 const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [
11 "LongGuns",
12 "Pistols",
13 "Melee",
14 "OperatorAmps",
15 "Hoverboards"
16 ];
17
18 10 interface IGildWeaponRequest {
19 11 ItemName: string;
20 12 Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
21 13 PolarizeSlot?: number;
22 14 PolarizeValue?: ArtifactPolarity;
23 15 ItemId: string;
24 Category: WeaponTypeInternal | "Hoverboards";
16 Category: TEquipmentKey;
25 17 }
26 18
27 19 export const gildWeaponController: RequestHandler = async (req, res) => {
28 20 const accountId = await getAccountIdForRequest(req);
29 21 const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
30 22 data.ItemId = String(req.query.ItemId);
31 if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) {
32 throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`);
33 }
34 data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
23 data.Category = req.query.Category as TEquipmentKey;
35 24
36 25 const inventory = await getInventory(accountId);
37 26 const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
@@ -42,8 +31,10 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
42 31 const weapon = inventory[data.Category][weaponIndex];
43 32 weapon.Features ??= 0;
44 33 weapon.Features |= EquipmentFeatures.GILDED;
45 weapon.ItemName = data.ItemName;
46 weapon.XP = 0;
34 if (data.Recipe != "webui") {
35 weapon.ItemName = data.ItemName;
36 weapon.XP = 0;
37 }
47 38 if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
48 39 weapon.Polarity = [
49 40 {
@@ -56,21 +47,24 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
56 47 const inventoryChanges: IInventoryChanges = {};
57 48 inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
58 49
59 const recipe = ExportRecipes[data.Recipe];
60 inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
61 ItemType: ingredient.ItemType,
62 ItemCount: ingredient.ItemCount * -1
63 }));
64 addMiscItems(inventory, inventoryChanges.MiscItems);
65
66 50 const affiliationMods = [];
67 if (recipe.syndicateStandingChange) {
68 const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!;
69 affiliation.Standing += recipe.syndicateStandingChange.value;
70 affiliationMods.push({
71 Tag: recipe.syndicateStandingChange.tag,
72 Standing: recipe.syndicateStandingChange.value
73 });
51
52 if (data.Recipe != "webui") {
53 const recipe = ExportRecipes[data.Recipe];
54 inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
55 ItemType: ingredient.ItemType,
56 ItemCount: ingredient.ItemCount * -1
57 }));
58 addMiscItems(inventory, inventoryChanges.MiscItems);
59
60 if (recipe.syndicateStandingChange) {
61 const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!;
62 affiliation.Standing += recipe.syndicateStandingChange.value;
63 affiliationMods.push({
64 Tag: recipe.syndicateStandingChange.tag,
65 Standing: recipe.syndicateStandingChange.value
66 });
67 }
74 68 }
75 69
76 70 await inventory.save();
Deleted src/controllers/custom/gildEquipmentController.ts +0 -23
@@ -1,23 +0,0 @@
1 import { getInventory } from "@/src/services/inventoryService";
2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
4 import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
5 import { RequestHandler } from "express";
6
7 export const gildEquipmentController: RequestHandler = async (req, res) => {
8 const accountId = await getAccountIdForRequest(req);
9 const request = req.body as IGildEquipmentRequest;
10 const inventory = await getInventory(accountId, request.Category);
11 const weapon = inventory[request.Category].id(request.ItemId);
12 if (weapon) {
13 weapon.Features ??= 0;
14 weapon.Features |= EquipmentFeatures.GILDED;
15 await inventory.save();
16 }
17 res.end();
18 };
19
20 type IGildEquipmentRequest = {
21 ItemId: string;
22 Category: TEquipmentKey;
23 };
Modified src/routes/custom.ts +0 -2
@@ -17,7 +17,6 @@ import { addCurrencyController } from "@/src/controllers/custom/addCurrencyContr
17 17 import { addItemsController } from "@/src/controllers/custom/addItemsController";
18 18 import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController";
19 19 import { addXpController } from "@/src/controllers/custom/addXpController";
20 import { gildEquipmentController } from "@/src/controllers/custom/gildEquipmentController";
21 20 import { importController } from "@/src/controllers/custom/importController";
22 21
23 22 import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
@@ -43,7 +42,6 @@ customRouter.post("/addCurrency", addCurrencyController);
43 42 customRouter.post("/addItems", addItemsController);
44 43 customRouter.post("/addModularEquipment", addModularEquipmentController);
45 44 customRouter.post("/addXp", addXpController);
46 customRouter.post("/gildEquipment", gildEquipmentController);
47 45 customRouter.post("/import", importController);
48 46 customRouter.post("/manageQuests", manageQuestsController);
49 47
Modified static/webui/script.js +3 -4
@@ -1127,11 +1127,10 @@ function disposeOfItems(category, type, count) {
1127 1127 function gildEquipment(category, oid) {
1128 1128 revalidateAuthz(() => {
1129 1129 $.post({
1130 url: "/custom/gildEquipment?" + window.authz,
1131 contentType: "application/json",
1130 url: "/api/gildWeapon.php?" + window.authz + "&ItemId=" + oid + "&Category=" + category,
1131 contentType: "application/octet-stream",
1132 1132 data: JSON.stringify({
1133 ItemId: oid,
1134 Category: category
1133 Recipe: "webui"
1135 1134 })
1136 1135 }).done(function () {
1137 1136 updateInventory();