2024-06-27 10:21:02 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
2025-03-09 07:47:24 -07:00
|
|
|
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
|
2025-04-10 07:14:53 -07:00
|
|
|
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-03-09 07:47:24 -07:00
|
|
|
import { ArtifactPolarity, EquipmentFeatures, IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
|
|
|
import { ExportRecipes } from "warframe-public-export-plus";
|
|
|
|
import { IInventoryChanges } from "@/src/types/purchaseTypes";
|
2024-06-27 10:21:02 +02:00
|
|
|
|
|
|
|
interface IGildWeaponRequest {
|
|
|
|
ItemName: string;
|
2025-03-09 07:47:24 -07:00
|
|
|
Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
|
2024-06-27 10:21:02 +02:00
|
|
|
PolarizeSlot?: number;
|
|
|
|
PolarizeValue?: ArtifactPolarity;
|
|
|
|
ItemId: string;
|
2025-04-10 07:14:53 -07:00
|
|
|
Category: TEquipmentKey;
|
2024-06-27 10:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const gildWeaponController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-01-24 14:27:10 +01:00
|
|
|
const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
|
2024-06-27 10:21:02 +02:00
|
|
|
data.ItemId = String(req.query.ItemId);
|
2025-04-10 07:14:53 -07:00
|
|
|
data.Category = req.query.Category as TEquipmentKey;
|
2024-06-27 10:21:02 +02:00
|
|
|
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
|
|
|
|
if (weaponIndex === -1) {
|
2024-12-30 00:07:53 +01:00
|
|
|
throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`);
|
2024-06-27 10:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const weapon = inventory[data.Category][weaponIndex];
|
2025-03-09 07:47:24 -07:00
|
|
|
weapon.Features ??= 0;
|
|
|
|
weapon.Features |= EquipmentFeatures.GILDED;
|
2025-04-10 07:14:53 -07:00
|
|
|
if (data.Recipe != "webui") {
|
|
|
|
weapon.ItemName = data.ItemName;
|
|
|
|
weapon.XP = 0;
|
|
|
|
}
|
2024-06-27 10:21:02 +02:00
|
|
|
if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
|
|
|
|
weapon.Polarity = [
|
|
|
|
{
|
|
|
|
Slot: data.PolarizeSlot,
|
|
|
|
Value: data.PolarizeValue
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
inventory[data.Category][weaponIndex] = weapon;
|
2025-03-09 07:47:24 -07:00
|
|
|
const inventoryChanges: IInventoryChanges = {};
|
|
|
|
inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
|
|
|
|
|
|
|
|
const affiliationMods = [];
|
2025-04-10 07:14:53 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
2025-03-09 07:47:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
await inventory.save();
|
2024-06-27 10:21:02 +02:00
|
|
|
res.json({
|
2025-03-09 07:47:24 -07:00
|
|
|
InventoryChanges: inventoryChanges,
|
|
|
|
AffiliationMods: affiliationMods
|
2024-06-27 10:21:02 +02:00
|
|
|
});
|
|
|
|
};
|