2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-01-04 00:25:09 +01:00
|
|
|
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
|
2023-12-28 16:24:52 +01:00
|
|
|
import { RequestHandler } from "express";
|
|
|
|
import { updateSlots } from "@/src/services/inventoryService";
|
2024-06-15 02:50:43 +02:00
|
|
|
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
|
2025-02-25 21:06:21 -08:00
|
|
|
import { logger } from "@/src/utils/logger";
|
2023-12-28 16:24:52 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
loadout slots are additionally purchased slots only
|
|
|
|
1 slot per mastery rank is automatically given above mr10, without database needing to save the mastery slots
|
|
|
|
extra = everything above the base + 2 slots (e.g. for warframes)
|
|
|
|
new slot = extra + 1 and slots +1
|
|
|
|
using slot = slots -1, except for when purchased with platinum, then slots are included in price
|
|
|
|
|
|
|
|
e.g. number of frames:
|
|
|
|
19 slots, 71 extra
|
|
|
|
= 71 - 19 + 2 = 54
|
|
|
|
19 actually available slots in ingame inventory = 17 extra + 2 Base (base amount depends on slot) (+ 1 for every mastery rank above 10)
|
|
|
|
number of frames = extra - slots + 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
export const inventorySlotsController: RequestHandler = async (req, res) => {
|
2024-05-28 13:45:06 +02:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2025-02-25 21:06:21 -08:00
|
|
|
const body = JSON.parse(req.body as string) as IInventorySlotsRequest;
|
2023-12-28 16:24:52 +01:00
|
|
|
|
2025-02-25 21:06:21 -08:00
|
|
|
if (body.Bin != InventorySlot.SUITS && body.Bin != InventorySlot.PVE_LOADOUTS) {
|
|
|
|
logger.warn(`unexpected slot purchase of type ${body.Bin}, account may be overcharged`);
|
|
|
|
}
|
2023-12-28 16:24:52 +01:00
|
|
|
|
2025-01-04 00:25:09 +01:00
|
|
|
const inventory = await getInventory(accountId);
|
|
|
|
const currencyChanges = updateCurrency(inventory, 20, true);
|
2025-02-25 21:06:21 -08:00
|
|
|
updateSlots(inventory, body.Bin, 1, 1);
|
2025-01-04 00:25:09 +01:00
|
|
|
await inventory.save();
|
2023-12-28 16:24:52 +01:00
|
|
|
|
|
|
|
res.json({ InventoryChanges: currencyChanges });
|
|
|
|
};
|
2025-02-25 21:06:21 -08:00
|
|
|
|
|
|
|
interface IInventorySlotsRequest {
|
|
|
|
Bin: InventorySlot;
|
|
|
|
}
|