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";
|
|
|
|
import { getInventory, updateCurrency, addEquipment, addMiscItems } from "@/src/services/inventoryService";
|
2024-06-18 02:03:07 +02:00
|
|
|
|
2024-06-29 15:11:12 +02:00
|
|
|
const modularWeaponTypes: Record<string, TEquipmentKey> = {
|
2024-06-18 02:03:07 +02:00
|
|
|
"/Lotus/Weapons/SolarisUnited/Primary/LotusModularPrimaryBeam": "LongGuns",
|
|
|
|
"/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);
|
2024-06-24 12:37:28 +02:00
|
|
|
const data = getJSONfromString(String(req.body)) as IModularCraftRequest;
|
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];
|
|
|
|
|
|
|
|
// Give weapon
|
2024-06-29 15:11:12 +02:00
|
|
|
const weapon = await addEquipment(category, data.WeaponType, accountId, data.Parts);
|
2024-06-18 02:03:07 +02:00
|
|
|
|
2024-06-20 22:27:32 +02:00
|
|
|
// Remove credits
|
2024-06-29 15:11:12 +02:00
|
|
|
const currencyChanges = await updateCurrency(
|
|
|
|
category == "Hoverboards" || category == "MoaPets" ? 5000 : 4000,
|
|
|
|
false,
|
|
|
|
accountId
|
|
|
|
);
|
2024-06-18 02:03:07 +02:00
|
|
|
|
|
|
|
// Remove parts
|
|
|
|
const miscItemChanges = [];
|
|
|
|
for (const part of data.Parts) {
|
|
|
|
miscItemChanges.push({
|
|
|
|
ItemType: part,
|
|
|
|
ItemCount: -1
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
addMiscItems(inventory, miscItemChanges);
|
|
|
|
await inventory.save();
|
|
|
|
|
|
|
|
// Tell client what we did
|
|
|
|
res.json({
|
|
|
|
InventoryChanges: {
|
|
|
|
...currencyChanges,
|
|
|
|
[category]: [weapon],
|
|
|
|
MiscItems: miscItemChanges
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|