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 { 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" ||
|
||||||
ItemType: operation.UpgradeRequirement,
|
operation.UpgradeRequirement == "/Lotus/Types/Items/MiscItems/CustomizationSlotUnlocker"
|
||||||
ItemCount: -1
|
) {
|
||||||
} satisfies IMiscItem
|
updateCurrency(10, true, accountId);
|
||||||
]);
|
} else {
|
||||||
|
addMiscItems(inventory, [
|
||||||
|
{
|
||||||
|
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":
|
||||||
@ -43,6 +52,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
|||||||
if (item._id.toString() == payload.ItemId.$oid) {
|
if (item._id.toString() == payload.ItemId.$oid) {
|
||||||
item.Features ??= 0;
|
item.Features ??= 0;
|
||||||
item.Features |= 32;
|
item.Features |= 32;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -61,10 +71,40 @@ 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;
|
||||||
|
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:
|
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 });
|
||||||
};
|
};
|
||||||
|
@ -193,6 +193,7 @@ const WeaponSchema = new Schema<IWeaponDatabase>(
|
|||||||
Polarity: [polaritySchema],
|
Polarity: [polaritySchema],
|
||||||
FocusLens: String,
|
FocusLens: String,
|
||||||
ModSlotPurchases: Number,
|
ModSlotPurchases: Number,
|
||||||
|
CustomizationSlotPurchases: Number,
|
||||||
UpgradeType: Schema.Types.Mixed, //todo
|
UpgradeType: Schema.Types.Mixed, //todo
|
||||||
UpgradeFingerprint: String,
|
UpgradeFingerprint: String,
|
||||||
ItemName: String,
|
ItemName: String,
|
||||||
@ -275,6 +276,7 @@ const suitSchema = new Schema<ISuitDatabase>(
|
|||||||
Polarity: [polaritySchema],
|
Polarity: [polaritySchema],
|
||||||
Polarized: Number,
|
Polarized: Number,
|
||||||
ModSlotPurchases: Number,
|
ModSlotPurchases: Number,
|
||||||
|
CustomizationSlotPurchases: Number,
|
||||||
FocusLens: String,
|
FocusLens: String,
|
||||||
UnlockLevel: Number
|
UnlockLevel: Number
|
||||||
},
|
},
|
||||||
|
@ -17,6 +17,7 @@ export interface ISuitDatabase {
|
|||||||
Polarity?: IPolarity[];
|
Polarity?: IPolarity[];
|
||||||
Polarized?: number;
|
Polarized?: number;
|
||||||
ModSlotPurchases?: number;
|
ModSlotPurchases?: number;
|
||||||
|
CustomizationSlotPurchases?: number;
|
||||||
FocusLens?: string;
|
FocusLens?: string;
|
||||||
UnlockLevel?: number;
|
UnlockLevel?: number;
|
||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
|
@ -94,6 +94,8 @@ export interface IGenericItem {
|
|||||||
Features?: number;
|
Features?: number;
|
||||||
Polarity?: IPolarity[];
|
Polarity?: IPolarity[];
|
||||||
Polarized?: number;
|
Polarized?: number;
|
||||||
|
ModSlotPurchases?: number;
|
||||||
|
CustomizationSlotPurchases?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IGenericItemDatabase extends Omit<IGenericItem, "ItemId"> {
|
export interface IGenericItemDatabase extends Omit<IGenericItem, "ItemId"> {
|
||||||
|
@ -17,6 +17,7 @@ export interface IWeaponDatabase {
|
|||||||
Polarity?: IPolarity[];
|
Polarity?: IPolarity[];
|
||||||
FocusLens?: string;
|
FocusLens?: string;
|
||||||
ModSlotPurchases?: number;
|
ModSlotPurchases?: number;
|
||||||
|
CustomizationSlotPurchases?: number;
|
||||||
UpgradeType?: string;
|
UpgradeType?: string;
|
||||||
UpgradeFingerprint?: string;
|
UpgradeFingerprint?: string;
|
||||||
ItemName?: string;
|
ItemName?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user