2024-06-18 02:03:07 +02:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
|
|
|
import { getJSONfromString } from "@/src/helpers/stringHelpers";
|
2024-06-29 15:11:12 +02:00
|
|
|
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-02-25 04:41:14 -08:00
|
|
|
import {
|
|
|
|
getInventory,
|
|
|
|
updateCurrency,
|
|
|
|
addEquipment,
|
|
|
|
addMiscItems,
|
|
|
|
applyDefaultUpgrades
|
|
|
|
} from "@/src/services/inventoryService";
|
|
|
|
import { ExportWeapons } from "warframe-public-export-plus";
|
2024-06-18 02:03:07 +02:00
|
|
|
|
2024-06-29 15:11:12 +02:00
|
|
|
const modularWeaponTypes: Record<string, TEquipmentKey> = {
|
2025-01-03 09:09:53 +01:00
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimary": "LongGuns",
|
2024-06-18 02:03:07 +02:00
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryBeam": "LongGuns",
|
2025-01-03 09:09:53 +01:00
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryLauncher": "LongGuns",
|
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryShotgun": "LongGuns",
|
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimarySniper": "LongGuns",
|
2024-06-18 02:03:07 +02:00
|
|
|
"/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondary": "Pistols",
|
|
|
|
"/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryBeam": "Pistols",
|
|
|
|
"/Lotus/Weapons/SolarisUnited/Secondary/LotusModularSecondaryShotgun": "Pistols",
|
|
|
|
"/Lotus/Weapons/Ostron/Melee/LotusModularWeapon": "Melee",
|
2024-06-20 22:27:32 +02:00
|
|
|
"/Lotus/Weapons/Sentients/OperatorAmplifiers/OperatorAmpWeapon": "OperatorAmps",
|
2024-06-29 15:11:12 +02:00
|
|
|
"/Lotus/Types/Vehicles/Hoverboard/HoverboardSuit": "Hoverboards",
|
2024-06-30 13:12:27 +02:00
|
|
|
"/Lotus/Types/Friendly/Pets/MoaPets/MoaPetPowerSuit": "MoaPets",
|
|
|
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetAPowerSuit": "MoaPets",
|
|
|
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetBPowerSuit": "MoaPets",
|
|
|
|
"/Lotus/Types/Friendly/Pets/ZanukaPets/ZanukaPetCPowerSuit": "MoaPets"
|
2024-06-18 02:03:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
interface IModularCraftRequest {
|
|
|
|
WeaponType: string;
|
|
|
|
Parts: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export const modularWeaponCraftingController: RequestHandler = async (req, res) => {
|
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-01-24 14:27:10 +01:00
|
|
|
const data = getJSONfromString<IModularCraftRequest>(String(req.body));
|
2024-06-18 02:03:07 +02:00
|
|
|
if (!(data.WeaponType in modularWeaponTypes)) {
|
|
|
|
throw new Error(`unknown modular weapon type: ${data.WeaponType}`);
|
|
|
|
}
|
|
|
|
const category = modularWeaponTypes[data.WeaponType];
|
2025-01-04 00:25:09 +01:00
|
|
|
const inventory = await getInventory(accountId);
|
2024-06-18 02:03:07 +02:00
|
|
|
|
2025-02-25 04:41:14 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
|
|
const configs = applyDefaultUpgrades(inventory, ExportWeapons[data.Parts[0]]?.defaultUpgrades);
|
|
|
|
|
2024-06-18 02:03:07 +02:00
|
|
|
// Give weapon
|
2025-02-25 04:41:14 -08:00
|
|
|
const inventoryChanges = addEquipment(inventory, category, data.WeaponType, data.Parts, {}, { Configs: configs });
|
2024-06-18 02:03:07 +02:00
|
|
|
|
2024-12-31 01:41:29 +01:00
|
|
|
// Remove credits & parts
|
2024-06-18 02:03:07 +02:00
|
|
|
const miscItemChanges = [];
|
|
|
|
for (const part of data.Parts) {
|
|
|
|
miscItemChanges.push({
|
|
|
|
ItemType: part,
|
|
|
|
ItemCount: -1
|
|
|
|
});
|
|
|
|
}
|
2024-12-31 01:41:29 +01:00
|
|
|
const currencyChanges = updateCurrency(
|
|
|
|
inventory,
|
2025-03-13 04:26:06 -07:00
|
|
|
category == "Hoverboards" || category == "MoaPets" || category == "LongGuns" || category == "Pistols"
|
|
|
|
? 5000
|
|
|
|
: 4000, // Definitely correct for Melee & OperatorAmps
|
2024-12-31 01:41:29 +01:00
|
|
|
false
|
|
|
|
);
|
2024-06-18 02:03:07 +02:00
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
// Tell client what we did
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
2025-02-25 04:41:14 -08:00
|
|
|
...inventoryChanges,
|
2024-06-18 02:03:07 +02:00
|
|
|
...currencyChanges,
|
|
|
|
MiscItems: miscItemChanges
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|