feat: implement purchasing of additional mod slots
This commit is contained in:
parent
656ceac4ac
commit
dff85de691
@ -2,19 +2,25 @@ import { RequestHandler } from "express";
|
|||||||
import { IUpgradesRequest } from "@/src/types/requestTypes";
|
import { IUpgradesRequest } from "@/src/types/requestTypes";
|
||||||
import { IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
import { IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||||
import { IGenericItemDatabase, IMiscItem, TGenericItemKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
import { IGenericItemDatabase, IMiscItem, TGenericItemKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||||
import { addMiscItems, getInventory } from "@/src/services/inventoryService";
|
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||||
|
|
||||||
export const upgradesController: RequestHandler = async (req, res) => {
|
export const upgradesController: RequestHandler = async (req, res) => {
|
||||||
const accountId = req.query.accountId as string;
|
const accountId = req.query.accountId as string;
|
||||||
const payload = JSON.parse(req.body.toString()) as IUpgradesRequest;
|
const payload = JSON.parse(req.body.toString()) as IUpgradesRequest;
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
|
const InventoryChanges: any = {};
|
||||||
for (const operation of payload.Operations) {
|
for (const operation of payload.Operations) {
|
||||||
addMiscItems(inventory, [
|
if (operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/ModSlotUnlocker") {
|
||||||
{
|
updateCurrency(10, true, accountId);
|
||||||
ItemType: operation.UpgradeRequirement,
|
} else {
|
||||||
ItemCount: -1
|
addMiscItems(inventory, [
|
||||||
} satisfies IMiscItem
|
{
|
||||||
]);
|
ItemType: operation.UpgradeRequirement,
|
||||||
|
ItemCount: -1
|
||||||
|
} satisfies IMiscItem
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
switch (operation.UpgradeRequirement) {
|
switch (operation.UpgradeRequirement) {
|
||||||
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
||||||
case "/Lotus/Types/Items/MiscItems/OrokinCatalyst":
|
case "/Lotus/Types/Items/MiscItems/OrokinCatalyst":
|
||||||
@ -62,10 +68,25 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "/Lotus/Types/Items/MiscItems/ModSlotUnlocker":
|
||||||
|
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
|
||||||
|
if (item._id.toString() == payload.ItemId.$oid) {
|
||||||
|
item.ModSlotPurchases ??= 0;
|
||||||
|
item.ModSlotPurchases += 1;
|
||||||
|
InventoryChanges[payload.ItemCategory] = {
|
||||||
|
ItemId: {
|
||||||
|
$oid: payload.ItemId.$oid
|
||||||
|
},
|
||||||
|
ModSlotPurchases: item.ModSlotPurchases
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("Unsupported upgrade: " + operation.UpgradeRequirement);
|
throw new Error("Unsupported upgrade: " + operation.UpgradeRequirement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
res.end();
|
res.json({ InventoryChanges });
|
||||||
};
|
};
|
||||||
|
@ -94,6 +94,7 @@ export interface IGenericItem {
|
|||||||
Features?: number;
|
Features?: number;
|
||||||
Polarity?: IPolarity[];
|
Polarity?: IPolarity[];
|
||||||
Polarized?: number;
|
Polarized?: number;
|
||||||
|
ModSlotPurchases?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGenericItemDatabase extends Omit<IGenericItem, "ItemId"> {
|
export interface IGenericItemDatabase extends Omit<IGenericItem, "ItemId"> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user