2024-06-27 10:21:02 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
|
|
|
import { getInventory } from "@/src/services/inventoryService";
|
|
|
|
import { WeaponTypeInternal } from "@/src/services/itemDataService";
|
|
|
|
import { ArtifactPolarity, EquipmentFeatures } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
|
|
|
|
|
|
|
const modularWeaponCategory: (WeaponTypeInternal | "Hoverboards")[] = [
|
|
|
|
"LongGuns",
|
|
|
|
"Pistols",
|
|
|
|
"Melee",
|
|
|
|
"OperatorAmps",
|
|
|
|
"Hoverboards" // Not sure about hoverboards just coppied from modual crafting
|
|
|
|
];
|
|
|
|
|
|
|
|
interface IGildWeaponRequest {
|
|
|
|
ItemName: string;
|
|
|
|
Recipe: string; // /Lotus/Weapons/SolarisUnited/LotusGildKitgunBlueprint
|
|
|
|
PolarizeSlot?: number;
|
|
|
|
PolarizeValue?: ArtifactPolarity;
|
|
|
|
ItemId: string;
|
|
|
|
Category: WeaponTypeInternal | "Hoverboards";
|
|
|
|
}
|
|
|
|
|
|
|
|
// In export there no recipes for gild action, so reputation and ressources only consumed visually
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (!modularWeaponCategory.includes(req.query.Category as WeaponTypeInternal | "Hoverboards")) {
|
2024-12-30 00:07:53 +01:00
|
|
|
throw new Error(`Unknown modular weapon Category: ${String(req.query.Category)}`);
|
2024-06-27 10:21:02 +02:00
|
|
|
}
|
|
|
|
data.Category = req.query.Category as WeaponTypeInternal | "Hoverboards";
|
|
|
|
|
|
|
|
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];
|
|
|
|
weapon.Features = EquipmentFeatures.GILDED; // maybe 9 idk if DOUBLE_CAPACITY is also given
|
|
|
|
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;
|
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
[data.Category]: [weapon]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|