返回提交历史
Modified
src/controllers/api/inventorySlotsController.ts
+36
-5
Modified
src/types/inventoryTypes/inventoryTypes.ts
+2
-1
Modified
src/utils/ts-utils.ts
+2
-0
XFEstudio/XFESpaceNinjaServer
feat: handle all slot types in inventorySlots.php (#2443)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2443 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
dcb26471
代码差异
3 个文件
+40
-6
@@ -2,7 +2,7 @@ import { getAccountIdForRequest } from "@/src/services/loginService";
2
2
import { getInventory, updateCurrency, updateSlots } from "@/src/services/inventoryService";
3
3
import { RequestHandler } from "express";
4
4
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
5
import { logger } from "@/src/utils/logger";
5
import { exhaustive } from "@/src/utils/ts-utils";
6
6
7
7
/*
8
8
loadout slots are additionally purchased slots only
@@ -22,13 +22,44 @@ export const inventorySlotsController: RequestHandler = async (req, res) => {
22
22
const accountId = await getAccountIdForRequest(req);
23
23
const body = JSON.parse(req.body as string) as IInventorySlotsRequest;
24
24
25
if (body.Bin != InventorySlot.SUITS && body.Bin != InventorySlot.PVE_LOADOUTS) {
26
logger.warn(`unexpected slot purchase of type ${body.Bin}, account may be overcharged`);
25
let price;
26
let amount;
27
switch (body.Bin) {
28
case InventorySlot.SUITS:
29
case InventorySlot.MECHSUITS:
30
case InventorySlot.PVE_LOADOUTS:
31
case InventorySlot.CREWMEMBERS:
32
price = 20;
33
amount = 1;
34
break;
35
36
case InventorySlot.SPACESUITS:
37
price = 12;
38
amount = 1;
39
break;
40
41
case InventorySlot.WEAPONS:
42
case InventorySlot.SPACEWEAPONS:
43
case InventorySlot.SENTINELS:
44
case InventorySlot.RJ_COMPONENT_AND_ARMAMENTS:
45
case InventorySlot.AMPS:
46
price = 12;
47
amount = 2;
48
break;
49
50
case InventorySlot.RIVENS:
51
price = 60;
52
amount = 3;
53
break;
54
55
default:
56
exhaustive(body.Bin);
57
throw new Error(`unexpected slot purchase of type ${body.Bin as string}`);
27
58
}
28
59
29
60
const inventory = await getInventory(accountId);
30
const currencyChanges = updateCurrency(inventory, 20, true);
31
updateSlots(inventory, body.Bin, 1, 1);
61
const currencyChanges = updateCurrency(inventory, price, true);
62
updateSlots(inventory, body.Bin, amount, amount);
32
63
await inventory.save();
33
64
34
65
res.json({ InventoryChanges: currencyChanges });
@@ -520,7 +520,8 @@ export enum InventorySlot {
520
520
SENTINELS = "SentinelBin",
521
521
AMPS = "OperatorAmpBin",
522
522
RJ_COMPONENT_AND_ARMAMENTS = "CrewShipSalvageBin",
523
CREWMEMBERS = "CrewMemberBin"
523
CREWMEMBERS = "CrewMemberBin",
524
RIVENS = "RandomModBin"
524
525
}
525
526
526
527
export interface ISlots {
@@ -3,3 +3,5 @@ type Entries<T, K extends keyof T = keyof T> = (K extends unknown ? [K, T[K]] :
3
3
export function getEntriesUnsafe<T extends object>(object: T): Entries<T> {
4
4
return Object.entries(object) as Entries<T>;
5
5
}
6
7
export const exhaustive = (_: never): void => {};