forked from OpenWF/SpaceNinjaServer
feat: implement purchasing of additional mod & customization slots (#206)
This commit is contained in:
parent
971d149122
commit
a081d065cb
@ -2,19 +2,28 @@ import { RequestHandler } from "express";
|
||||
import { IUpgradesRequest } from "@/src/types/requestTypes";
|
||||
import { IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
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) => {
|
||||
const accountId = req.query.accountId as string;
|
||||
const payload = JSON.parse(req.body.toString()) as IUpgradesRequest;
|
||||
const inventory = await getInventory(accountId);
|
||||
const InventoryChanges: any = {};
|
||||
for (const operation of payload.Operations) {
|
||||
addMiscItems(inventory, [
|
||||
{
|
||||
ItemType: operation.UpgradeRequirement,
|
||||
ItemCount: -1
|
||||
} satisfies IMiscItem
|
||||
]);
|
||||
if (
|
||||
operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/ModSlotUnlocker" ||
|
||||
operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/CustomizationSlotUnlocker"
|
||||
) {
|
||||
updateCurrency(10, true, accountId);
|
||||
} else {
|
||||
addMiscItems(inventory, [
|
||||
{
|
||||
ItemType: operation.UpgradeRequirement,
|
||||
ItemCount: -1
|
||||
} satisfies IMiscItem
|
||||
]);
|
||||
}
|
||||
|
||||
switch (operation.UpgradeRequirement) {
|
||||
case "/Lotus/Types/Items/MiscItems/OrokinReactor":
|
||||
case "/Lotus/Types/Items/MiscItems/OrokinCatalyst":
|
||||
@ -43,6 +52,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
if (item._id.toString() == payload.ItemId.$oid) {
|
||||
item.Features ??= 0;
|
||||
item.Features |= 32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -61,10 +71,40 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
}
|
||||
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;
|
||||
case "/Lotus/Types/Items/MiscItems/CustomizationSlotUnlocker":
|
||||
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
|
||||
if (item._id.toString() == payload.ItemId.$oid) {
|
||||
item.CustomizationSlotPurchases ??= 0;
|
||||
item.CustomizationSlotPurchases += 1;
|
||||
InventoryChanges[payload.ItemCategory] = {
|
||||
ItemId: {
|
||||
$oid: payload.ItemId.$oid
|
||||
},
|
||||
CustomizationSlotPurchases: item.CustomizationSlotPurchases
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported upgrade: " + operation.UpgradeRequirement);
|
||||
}
|
||||
}
|
||||
await inventory.save();
|
||||
res.end();
|
||||
res.json({ InventoryChanges });
|
||||
};
|
||||
|
@ -193,6 +193,7 @@ const WeaponSchema = new Schema<IWeaponDatabase>(
|
||||
Polarity: [polaritySchema],
|
||||
FocusLens: String,
|
||||
ModSlotPurchases: Number,
|
||||
CustomizationSlotPurchases: Number,
|
||||
UpgradeType: Schema.Types.Mixed, //todo
|
||||
UpgradeFingerprint: String,
|
||||
ItemName: String,
|
||||
@ -275,6 +276,7 @@ const suitSchema = new Schema<ISuitDatabase>(
|
||||
Polarity: [polaritySchema],
|
||||
Polarized: Number,
|
||||
ModSlotPurchases: Number,
|
||||
CustomizationSlotPurchases: Number,
|
||||
FocusLens: String,
|
||||
UnlockLevel: Number
|
||||
},
|
||||
|
@ -17,6 +17,7 @@ export interface ISuitDatabase {
|
||||
Polarity?: IPolarity[];
|
||||
Polarized?: number;
|
||||
ModSlotPurchases?: number;
|
||||
CustomizationSlotPurchases?: number;
|
||||
FocusLens?: string;
|
||||
UnlockLevel?: number;
|
||||
_id: Types.ObjectId;
|
||||
|
@ -94,6 +94,8 @@ export interface IGenericItem {
|
||||
Features?: number;
|
||||
Polarity?: IPolarity[];
|
||||
Polarized?: number;
|
||||
ModSlotPurchases?: number;
|
||||
CustomizationSlotPurchases?: number;
|
||||
}
|
||||
|
||||
export interface IGenericItemDatabase extends Omit<IGenericItem, "ItemId"> {
|
||||
|
@ -17,6 +17,7 @@ export interface IWeaponDatabase {
|
||||
Polarity?: IPolarity[];
|
||||
FocusLens?: string;
|
||||
ModSlotPurchases?: number;
|
||||
CustomizationSlotPurchases?: number;
|
||||
UpgradeType?: string;
|
||||
UpgradeFingerprint?: string;
|
||||
ItemName?: string;
|
||||
|
Loading…
x
Reference in New Issue
Block a user