feat: handle all slot types in inventorySlots.php (#2443)

Reviewed-on: OpenWF/SpaceNinjaServer#2443
Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com>
Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
Sainan 2025-07-08 20:51:35 -07:00 committed by Sainan
parent 5a75d88385
commit dcb26471c9
3 changed files with 40 additions and 6 deletions

View File

@ -2,7 +2,7 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
import { getInventory, updateCurrency, updateSlots } from "@/src/services/inventoryService"; import { getInventory, updateCurrency, updateSlots } from "@/src/services/inventoryService";
import { RequestHandler } from "express"; import { RequestHandler } from "express";
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes"; import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
import { logger } from "@/src/utils/logger"; import { exhaustive } from "@/src/utils/ts-utils";
/* /*
loadout slots are additionally purchased slots only loadout slots are additionally purchased slots only
@ -22,13 +22,44 @@ export const inventorySlotsController: RequestHandler = async (req, res) => {
const accountId = await getAccountIdForRequest(req); const accountId = await getAccountIdForRequest(req);
const body = JSON.parse(req.body as string) as IInventorySlotsRequest; const body = JSON.parse(req.body as string) as IInventorySlotsRequest;
if (body.Bin != InventorySlot.SUITS && body.Bin != InventorySlot.PVE_LOADOUTS) { let price;
logger.warn(`unexpected slot purchase of type ${body.Bin}, account may be overcharged`); let amount;
switch (body.Bin) {
case InventorySlot.SUITS:
case InventorySlot.MECHSUITS:
case InventorySlot.PVE_LOADOUTS:
case InventorySlot.CREWMEMBERS:
price = 20;
amount = 1;
break;
case InventorySlot.SPACESUITS:
price = 12;
amount = 1;
break;
case InventorySlot.WEAPONS:
case InventorySlot.SPACEWEAPONS:
case InventorySlot.SENTINELS:
case InventorySlot.RJ_COMPONENT_AND_ARMAMENTS:
case InventorySlot.AMPS:
price = 12;
amount = 2;
break;
case InventorySlot.RIVENS:
price = 60;
amount = 3;
break;
default:
exhaustive(body.Bin);
throw new Error(`unexpected slot purchase of type ${body.Bin as string}`);
} }
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const currencyChanges = updateCurrency(inventory, 20, true); const currencyChanges = updateCurrency(inventory, price, true);
updateSlots(inventory, body.Bin, 1, 1); updateSlots(inventory, body.Bin, amount, amount);
await inventory.save(); await inventory.save();
res.json({ InventoryChanges: currencyChanges }); res.json({ InventoryChanges: currencyChanges });

View File

@ -520,7 +520,8 @@ export enum InventorySlot {
SENTINELS = "SentinelBin", SENTINELS = "SentinelBin",
AMPS = "OperatorAmpBin", AMPS = "OperatorAmpBin",
RJ_COMPONENT_AND_ARMAMENTS = "CrewShipSalvageBin", RJ_COMPONENT_AND_ARMAMENTS = "CrewShipSalvageBin",
CREWMEMBERS = "CrewMemberBin" CREWMEMBERS = "CrewMemberBin",
RIVENS = "RandomModBin"
} }
export interface ISlots { export interface ISlots {

View File

@ -3,3 +3,5 @@ type Entries<T, K extends keyof T = keyof T> = (K extends unknown ? [K, T[K]] :
export function getEntriesUnsafe<T extends object>(object: T): Entries<T> { export function getEntriesUnsafe<T extends object>(object: T): Entries<T> {
return Object.entries(object) as Entries<T>; return Object.entries(object) as Entries<T>;
} }
export const exhaustive = (_: never): void => {};