feat: implement polarity swapping (#283)
This commit is contained in:
parent
c1f5a2b464
commit
656e70227c
@ -1,6 +1,6 @@
|
||||
import { RequestHandler } from "express";
|
||||
import { IUpgradesRequest } from "@/src/types/requestTypes";
|
||||
import { IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { IGenericItemDatabase, IMiscItem, TGenericItemKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
|
||||
@ -64,11 +64,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
|
||||
if (item._id.toString() == payload.ItemId.$oid) {
|
||||
item.XP = 0;
|
||||
item.Polarity ??= [];
|
||||
item.Polarity.push({
|
||||
Slot: operation.PolarizeSlot,
|
||||
Value: operation.PolarizeValue
|
||||
} satisfies IPolarity);
|
||||
setSlotPolarity(item, operation.PolarizeSlot, operation.PolarizeValue);
|
||||
item.Polarized ??= 0;
|
||||
item.Polarized += 1;
|
||||
break;
|
||||
@ -105,6 +101,19 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "":
|
||||
console.assert(operation.OperationType == "UOT_SWAP_POLARITY");
|
||||
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
|
||||
if (item._id.toString() == payload.ItemId.$oid) {
|
||||
for (let i = 0; i != operation.PolarityRemap.length; ++i) {
|
||||
if (operation.PolarityRemap[i].Slot != i) {
|
||||
setSlotPolarity(item, i, operation.PolarityRemap[i].Value);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported upgrade: " + operation.UpgradeRequirement);
|
||||
}
|
||||
@ -112,3 +121,13 @@ export const upgradesController: RequestHandler = async (req, res) => {
|
||||
await inventory.save();
|
||||
res.json({ InventoryChanges });
|
||||
};
|
||||
|
||||
const setSlotPolarity = (item: IGenericItemDatabase, slot: number, polarity: FocusSchool): void => {
|
||||
item.Polarity ??= [];
|
||||
const entry = item.Polarity.find(entry => entry.Slot == slot);
|
||||
if (entry) {
|
||||
entry.Value = polarity;
|
||||
} else {
|
||||
item.Polarity.push({ Slot: slot, Value: polarity });
|
||||
}
|
||||
};
|
||||
|
@ -97,10 +97,13 @@ pendingRecipeSchema.set("toJSON", {
|
||||
}
|
||||
});
|
||||
|
||||
const polaritySchema = new Schema<IPolarity>({
|
||||
const polaritySchema = new Schema<IPolarity>(
|
||||
{
|
||||
Slot: Number,
|
||||
Value: String
|
||||
});
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const abilityOverrideSchema = new Schema<IAbilityOverride>({
|
||||
Ability: String,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { IOid } from "./commonTypes";
|
||||
import { FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { IPolarity, FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import {
|
||||
IBooster,
|
||||
IChallengeProgress,
|
||||
@ -95,5 +95,5 @@ export interface IUpgradeOperation {
|
||||
UpgradeRequirement: string; // uniqueName of item being consumed
|
||||
PolarizeSlot: number;
|
||||
PolarizeValue: FocusSchool;
|
||||
PolarityRemap: object[];
|
||||
PolarityRemap: IPolarity[];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user