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