返回提交历史
Modified
src/controllers/api/upgradesController.ts
+25
-6
Modified
src/models/inventoryModels/inventoryModel.ts
+7
-4
Modified
src/types/requestTypes.ts
+2
-2
XFEstudio/SpaceNinjaServer
feat: implement polarity swapping (#283)
656e7022
代码差异
3 个文件
+34
-12
@@ -1,6 +1,6 @@
1
1
import { RequestHandler } from "express";
2
2
import { IUpgradesRequest } from "@/src/types/requestTypes";
3
import { IPolarity } from "@/src/types/inventoryTypes/commonInventoryTypes";
3
import { FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
4
4
import { IGenericItemDatabase, IMiscItem, TGenericItemKey } from "@/src/types/inventoryTypes/inventoryTypes";
5
5
import { getAccountIdForRequest } from "@/src/services/loginService";
6
6
import { addMiscItems, getInventory, updateCurrency } from "@/src/services/inventoryService";
@@ -64,11 +64,7 @@ export const upgradesController: RequestHandler = async (req, res) => {
64
64
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
65
65
if (item._id.toString() == payload.ItemId.$oid) {
66
66
item.XP = 0;
67
item.Polarity ??= [];
68
item.Polarity.push({
69
Slot: operation.PolarizeSlot,
70
Value: operation.PolarizeValue
71
} satisfies IPolarity);
67
setSlotPolarity(item, operation.PolarizeSlot, operation.PolarizeValue);
72
68
item.Polarized ??= 0;
73
69
item.Polarized += 1;
74
70
break;
@@ -105,6 +101,19 @@ export const upgradesController: RequestHandler = async (req, res) => {
105
101
}
106
102
}
107
103
break;
104
case "":
105
console.assert(operation.OperationType == "UOT_SWAP_POLARITY");
106
for (const item of inventory[payload.ItemCategory as TGenericItemKey] as IGenericItemDatabase[]) {
107
if (item._id.toString() == payload.ItemId.$oid) {
108
for (let i = 0; i != operation.PolarityRemap.length; ++i) {
109
if (operation.PolarityRemap[i].Slot != i) {
110
setSlotPolarity(item, i, operation.PolarityRemap[i].Value);
111
}
112
}
113
break;
114
}
115
}
116
break;
108
117
default:
109
118
throw new Error("Unsupported upgrade: " + operation.UpgradeRequirement);
110
119
}
@@ -112,3 +121,13 @@ export const upgradesController: RequestHandler = async (req, res) => {
112
121
await inventory.save();
113
122
res.json({ InventoryChanges });
114
123
};
124
125
const setSlotPolarity = (item: IGenericItemDatabase, slot: number, polarity: FocusSchool): void => {
126
item.Polarity ??= [];
127
const entry = item.Polarity.find(entry => entry.Slot == slot);
128
if (entry) {
129
entry.Value = polarity;
130
} else {
131
item.Polarity.push({ Slot: slot, Value: polarity });
132
}
133
};
@@ -97,10 +97,13 @@ pendingRecipeSchema.set("toJSON", {
97
97
}
98
98
});
99
99
100
const polaritySchema = new Schema<IPolarity>({
101
Slot: Number,
102
Value: String
103
});
100
const polaritySchema = new Schema<IPolarity>(
101
{
102
Slot: Number,
103
Value: String
104
},
105
{ _id: false }
106
);
104
107
105
108
const abilityOverrideSchema = new Schema<IAbilityOverride>({
106
109
Ability: String,
@@ -1,5 +1,5 @@
1
1
import { IOid } from "./commonTypes";
2
import { FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
2
import { IPolarity, FocusSchool } from "@/src/types/inventoryTypes/commonInventoryTypes";
3
3
import {
4
4
IBooster,
5
5
IChallengeProgress,
@@ -95,5 +95,5 @@ export interface IUpgradeOperation {
95
95
UpgradeRequirement: string; // uniqueName of item being consumed
96
96
PolarizeSlot: number;
97
97
PolarizeValue: FocusSchool;
98
PolarityRemap: object[];
98
PolarityRemap: IPolarity[];
99
99
}