chore(webui): use gildWeaponController #1518

Merged
Sainan merged 1 commits from AMelonInsideLemon/SpaceNinjaServer:gild-weapon-controller into main 2025-04-10 07:14:54 -07:00
4 changed files with 27 additions and 59 deletions

View File

@ -2,36 +2,25 @@ import { RequestHandler } from "express";
import { getAccountIdForRequest } from "@/src/services/loginService"; import { getAccountIdForRequest } from "@/src/services/loginService";
import { getJSONfromString } from "@/src/helpers/stringHelpers"; import { getJSONfromString } from "@/src/helpers/stringHelpers";
import { addMiscItems, getInventory } from "@/src/services/inventoryService"; 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 { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
import { ExportRecipes } from "warframe-public-export-plus"; import { ExportRecipes } from "warframe-public-export-plus";
import { IInventoryChanges } from "@/src/types/purchaseTypes"; import { IInventoryChanges } from "@/src/types/purchaseTypes";
const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [
"LongGuns",
"Pistols",
"Melee",
"OperatorAmps",
"Hoverboards"
];
interface IGildWeaponRequest { interface IGildWeaponRequest {
ItemName: string; ItemName: string;
Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
PolarizeSlot?: number; PolarizeSlot?: number;
PolarizeValue?: ArtifactPolarity; PolarizeValue?: ArtifactPolarity;
ItemId: string; ItemId: string;
Category: WeaponTypeInternal | "Hoverboards"; Category: TEquipmentKey;
} }
export const gildWeaponController: RequestHandler = async (req, res) => { export const gildWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const data = getJSONfromString<IGildWeaponRequest>(String(req.body)); const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
data.ItemId = String(req.query.ItemId); data.ItemId = String(req.query.ItemId);
if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) { data.Category = req.query.Category as TEquipmentKey;
throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`);
}
data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId); 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]; const weapon = inventory[data.Category][weaponIndex];
weapon.Features ??= 0; weapon.Features ??= 0;
weapon.Features |= EquipmentFeatures.GILDED; weapon.Features |= EquipmentFeatures.GILDED;
weapon.ItemName = data.ItemName; if (data.Recipe != "webui") {
weapon.XP = 0; weapon.ItemName = data.ItemName;
weapon.XP = 0;
}
if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) { if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
weapon.Polarity = [ weapon.Polarity = [
{ {
@ -56,21 +47,24 @@ export const gildWeaponController: RequestHandler = async (req, res) => {
const inventoryChanges: IInventoryChanges = {}; const inventoryChanges: IInventoryChanges = {};
inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()]; inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
const recipe = ExportRecipes[data.Recipe];
inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
ItemType: ingredient.ItemType,
ItemCount: ingredient.ItemCount * -1
}));
addMiscItems(inventory, inventoryChanges.MiscItems);
const affiliationMods = []; const affiliationMods = [];
if (recipe.syndicateStandingChange) {
const affiliation = inventory.Affiliations.find(x => x.Tag == recipe.syndicateStandingChange!.tag)!; if (data.Recipe != "webui") {
affiliation.Standing += recipe.syndicateStandingChange.value; const recipe = ExportRecipes[data.Recipe];
affiliationMods.push({ inventoryChanges.MiscItems = recipe.secretIngredients!.map(ingredient => ({
Tag: recipe.syndicateStandingChange.tag, ItemType: ingredient.ItemType,
Standing: recipe.syndicateStandingChange.value 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(); await inventory.save();

View File

@ -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;
};

View File

@ -17,7 +17,6 @@ import { addCurrencyController } from "@/src/controllers/custom/addCurrencyContr
import { addItemsController } from "@/src/controllers/custom/addItemsController"; import { addItemsController } from "@/src/controllers/custom/addItemsController";
import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController"; import { addModularEquipmentController } from "@/src/controllers/custom/addModularEquipmentController";
import { addXpController } from "@/src/controllers/custom/addXpController"; import { addXpController } from "@/src/controllers/custom/addXpController";
import { gildEquipmentController } from "@/src/controllers/custom/gildEquipmentController";
import { importController } from "@/src/controllers/custom/importController"; import { importController } from "@/src/controllers/custom/importController";
import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController"; import { getConfigDataController } from "@/src/controllers/custom/getConfigDataController";
@ -43,7 +42,6 @@ customRouter.post("/addCurrency", addCurrencyController);
customRouter.post("/addItems", addItemsController); customRouter.post("/addItems", addItemsController);
customRouter.post("/addModularEquipment", addModularEquipmentController); customRouter.post("/addModularEquipment", addModularEquipmentController);
customRouter.post("/addXp", addXpController); customRouter.post("/addXp", addXpController);
customRouter.post("/gildEquipment", gildEquipmentController);
customRouter.post("/import", importController); customRouter.post("/import", importController);
customRouter.post("/manageQuests", manageQuestsController); customRouter.post("/manageQuests", manageQuestsController);

View File

@ -1127,11 +1127,10 @@ function disposeOfItems(category, type, count) {
function gildEquipment(category, oid) { function gildEquipment(category, oid) {
revalidateAuthz(() => { revalidateAuthz(() => {
$.post({ $.post({
url: "/custom/gildEquipment?" + window.authz, url: "/api/gildWeapon.php?" + window.authz + "&ItemId=" + oid + "&Category=" + category,
contentType: "application/json", contentType: "application/octet-stream",
data: JSON.stringify({ data: JSON.stringify({
ItemId: oid, Recipe: "webui"
Category: category
}) })
}).done(function () { }).done(function () {
updateInventory(); updateInventory();