From 540961ff9e425da007175d1926b8401e3d92e1ab Mon Sep 17 00:00:00 2001 From: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Date: Thu, 10 Apr 2025 07:14:53 -0700 Subject: [PATCH] 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> --- src/controllers/api/gildWeaponController.ts | 54 +++++++++---------- .../custom/gildEquipmentController.ts | 23 -------- src/routes/custom.ts | 2 - static/webui/script.js | 7 ++- 4 files changed, 27 insertions(+), 59 deletions(-) delete mode 100644 src/controllers/custom/gildEquipmentController.ts diff --git a/src/controllers/api/gildWeaponController.ts b/src/controllers/api/gildWeaponController.ts index 3914b81a..fac741fc 100644 --- a/src/controllers/api/gildWeaponController.ts +++ b/src/controllers/api/gildWeaponController.ts @@ -2,36 +2,25 @@ import { RequestHandler } from "express"; import { getAccountIdForRequest } from "@/src/services/loginService"; import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { addMiscItems, getInventory } from "@/src/services/inventoryService"; -import { WeaponTypeInternal } from "@/src/services/itemDataService"; +import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; import { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes"; import { ExportRecipes } from "warframe-public-export-plus"; import { IInventoryChanges } from "@/src/types/purchaseTypes"; -const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [ - "LongGuns", - "Pistols", - "Melee", - "OperatorAmps", - "Hoverboards" -]; - interface IGildWeaponRequest { ItemName: string; Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint PolarizeSlot?: number; PolarizeValue?: ArtifactPolarity; ItemId: string; - Category: WeaponTypeInternal | "Hoverboards"; + Category: TEquipmentKey; } export const gildWeaponController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); const data = getJSONfromString(String(req.body)); data.ItemId = String(req.query.ItemId); - if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) { - throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`); - } - data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards"; + data.Category = req.query.Category as TEquipmentKey; const inventory = await getInventory(accountId); const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId); @@ -42,8 +31,10 @@ export const gildWeaponController: RequestHandler = async (req, res) => { const weapon = inventory[data.Category][weaponIndex]; weapon.Features ??= 0; weapon.Features |= EquipmentFeatures.GILDED; - weapon.ItemName = data.ItemName; - weapon.XP = 0; + if (data.Recipe != "webui") { + weapon.ItemName = data.ItemName; + weapon.XP = 0; + } if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) { weapon.Polarity = [ { @@ -56,21 +47,24 @@ export const gildWeaponController: RequestHandler = async (req, res) => { const inventoryChanges: IInventoryChanges = {}; inventoryChanges[data.Category] = [weapon.toJSON()]; - const recipe = ExportRecipes[data.Recipe]; - inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({ - ItemType: ingredient.ItemType, - ItemCount: ingredient.ItemCount * -1 - })); - addMiscItems(inventory, inventoryChanges.MiscItems); - const affiliationMods = []; - if (recipe.syndicateStandingChange) { - const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!; - affiliation.Standing += recipe.syndicateStandingChange.value; - affiliationMods.push({ - Tag: recipe.syndicateStandingChange.tag, - Standing: recipe.syndicateStandingChange.value - }); + + if (data.Recipe != "webui") { + const recipe = ExportRecipes[data.Recipe]; + inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({ + ItemType: ingredient.ItemType, + ItemCount: ingredient.ItemCount * -1 + })); + addMiscItems(inventory, inventoryChanges.MiscItems); + + if (recipe.syndicateStandingChange) { + const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!; + affiliation.Standing += recipe.syndicateStandingChange.value; + affiliationMods.push({ + Tag: recipe.syndicateStandingChange.tag, + Standing: recipe.syndicateStandingChange.value + }); + } } await inventory.save(); diff --git a/src/controllers/custom/gildEquipmentController.ts b/src/controllers/custom/gildEquipmentController.ts deleted file mode 100644 index 46716207..00000000 --- a/src/controllers/custom/gildEquipmentController.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { getInventory } from "@/src/services/inventoryService"; -import { getAccountIdForRequest } from "@/src/services/loginService"; -import { EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes"; -import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes"; -import { RequestHandler } from "express"; - -export const gildEquipmentController: RequestHandler = async (req, res) => { - const accountId = await getAccountIdForRequest(req); - const request = req.body as IGildEquipmentRequest; - const inventory = await getInventory(accountId, request.Category); - const weapon = inventory[request.Category].id(request.ItemId); - if (weapon) { - weapon.Features ??= 0; - weapon.Features |= EquipmentFeatures.GILDED; - await inventory.save(); - } - res.end(); -}; - -type IGildEquipmentRequest = { - ItemId: string; - Category: TEquipmentKey; -}; diff --git a/src/routes/custom.ts b/src/routes/custom.ts index 0834f90b..16359226 100644 --- a/src/routes/custom.ts +++ b/src/routes/custom.ts @@ -17,7 +17,6 @@ import { addCurrencyController } from "@/src/controllers/custom/addCurrencyContr import { addItemsController } from "@/src/controllers/custom/addItemsController"; import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController"; import { addXpController } from "@/src/controllers/custom/addXpController"; -import { gildEquipmentController } from "@/src/controllers/custom/gildEquipmentController"; import { importController } from "@/src/controllers/custom/importController"; import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController"; @@ -43,7 +42,6 @@ customRouter.post("/addCurrency", addCurrencyController); customRouter.post("/addItems", addItemsController); customRouter.post("/addModularEquipment", addModularEquipmentController); customRouter.post("/addXp", addXpController); -customRouter.post("/gildEquipment", gildEquipmentController); customRouter.post("/import", importController); customRouter.post("/manageQuests", manageQuestsController); diff --git a/static/webui/script.js b/static/webui/script.js index d55219a0..53dbf126 100644 --- a/static/webui/script.js +++ b/static/webui/script.js @@ -1127,11 +1127,10 @@ function disposeOfItems(category, type, count) { function gildEquipment(category, oid) { revalidateAuthz(() => { $.post({ - url: "/custom/gildEquipment?" + window.authz, - contentType: "application/json", + url: "/api/gildWeapon.php?" + window.authz + "&ItemId=" + oid + "&Category=" + category, + contentType: "application/octet-stream", data: JSON.stringify({ - ItemId: oid, - Category: category + Recipe: "webui" }) }).done(function () { updateInventory();