import type { RequestHandler } from "express";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
import { addMiscItems, getInventory2 } from "../../services/inventoryService.ts";
import type { TEquipmentKey } from "../../types/inventoryTypes/inventoryTypes.ts";
import type { TArtifactPolarity } from "../../types/inventoryTypes/commonInventoryTypes.ts";
import { ExportRecipes } from "warframe-public-export-plus";
import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
import type { IEquipmentClient } from "../../types/equipmentTypes.ts";
import { eEquipmentFeatures } from "../../types/equipmentTypes.ts";
interface IGildWeaponRequest {
ItemName: string;
Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
PolarizeSlot?: number;
PolarizeValue?: TArtifactPolarity;
ItemId: string;
Category: TEquipmentKey;
}
export const gildWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
data.ItemId = String(req.query.ItemId);
data.Category = req.query.Category as TEquipmentKey;
const inventory = await getInventory2(accountId, data.Category, "MiscItems", "Affiliations");
const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
if (weaponIndex === -1) {
throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`);
}
const weapon = inventory[data.Category][weaponIndex];
weapon.Features ??= 0;
weapon.Features |= eEquipmentFeatures.GILDED;
weapon.ItemName = data.ItemName;
weapon.XP = 0;
if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
weapon.Polarity = [
{
Slot: data.PolarizeSlot,
Value: data.PolarizeValue
}
];
}
inventory[data.Category][weaponIndex] = weapon;
const inventoryChanges: IInventoryChanges = {};
inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
const affiliationMods = [];
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();
res.json({
InventoryChanges: inventoryChanges,
AffiliationMods: affiliationMods
});
broadcastInventoryUpdate(req);
};
import type { RequestHandler } from "express";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
import { addMiscItems, getInventory2 } from "../../services/inventoryService.ts";
import type { TEquipmentKey } from "../../types/inventoryTypes/inventoryTypes.ts";
import type { TArtifactPolarity } from "../../types/inventoryTypes/commonInventoryTypes.ts";
import { ExportRecipes } from "warframe-public-export-plus";
import type { IInventoryChanges } from "../../types/purchaseTypes.ts";
import type { IEquipmentClient } from "../../types/equipmentTypes.ts";
import { eEquipmentFeatures } from "../../types/equipmentTypes.ts";
interface IGildWeaponRequest {
ItemName: string;
Recipe: string; // e.g. /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
PolarizeSlot?: number;
PolarizeValue?: TArtifactPolarity;
ItemId: string;
Category: TEquipmentKey;
}
export const gildWeaponController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req);
const data = getJSONfromString<IGildWeaponRequest>(String(req.body));
data.ItemId = String(req.query.ItemId);
data.Category = req.query.Category as TEquipmentKey;
const inventory = await getInventory2(accountId, data.Category, "MiscItems", "Affiliations");
const weaponIndex = inventory[data.Category].findIndex(x => String(x._id) === data.ItemId);
if (weaponIndex === -1) {
throw new Error(`Weapon with ${data.ItemId} not found in category ${String(req.query.Category)}`);
}
const weapon = inventory[data.Category][weaponIndex];
weapon.Features ??= 0;
weapon.Features |= eEquipmentFeatures.GILDED;
weapon.ItemName = data.ItemName;
weapon.XP = 0;
if (data.Category != "OperatorAmps" && data.PolarizeSlot && data.PolarizeValue) {
weapon.Polarity = [
{
Slot: data.PolarizeSlot,
Value: data.PolarizeValue
}
];
}
inventory[data.Category][weaponIndex] = weapon;
const inventoryChanges: IInventoryChanges = {};
inventoryChanges[data.Category] = [weapon.toJSON<IEquipmentClient>()];
const affiliationMods = [];
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();
res.json({
InventoryChanges: inventoryChanges,
AffiliationMods: affiliationMods
});
broadcastInventoryUpdate(req);
};