返回提交历史
Modified
src/services/inventoryService.ts
+65
-13
XFEstudio/SpaceNinjaServer
feat: purchase shop decorations (#299)
f216d522
代码差异
1 个文件
+65
-13
@@ -116,6 +116,23 @@ export const addItem = async (
116
116
FlavourItems: [await addCustomization(typeName, accountId)]
117
117
}
118
118
};
119
case "Objects": {
120
// /Lotus/Objects/Tenno/Props/TnoLisetTextProjector (Note Beacon)
121
const inventory = await getInventory(accountId);
122
const changes = [
123
{
124
ItemType: typeName,
125
ItemCount: quantity
126
} satisfies IMiscItem
127
];
128
addShipDecorations(inventory, changes);
129
await inventory.save();
130
return {
131
InventoryChanges: {
132
ShipDecorations: changes
133
}
134
};
135
}
119
136
case "Types":
120
137
switch (typeName.substr(1).split("/")[2]) {
121
138
case "AvatarImages":
@@ -136,20 +153,40 @@ export const addItem = async (
136
153
}
137
154
};
138
155
case "Items": {
139
const inventory = await getInventory(accountId);
140
const miscItemChanges = [
141
{
142
ItemType: typeName,
143
ItemCount: quantity
144
} satisfies IMiscItem
145
];
146
addMiscItems(inventory, miscItemChanges);
147
await inventory.save();
148
return {
149
InventoryChanges: {
150
MiscItems: miscItemChanges
156
switch (typeName.substr(1).split("/")[3]) {
157
case "ShipDecos": {
158
const inventory = await getInventory(accountId);
159
const changes = [
160
{
161
ItemType: typeName,
162
ItemCount: quantity
163
} satisfies IMiscItem
164
];
165
addShipDecorations(inventory, changes);
166
await inventory.save();
167
return {
168
InventoryChanges: {
169
ShipDecorations: changes
170
}
171
};
151
172
}
152
};
173
default: {
174
const inventory = await getInventory(accountId);
175
const miscItemChanges = [
176
{
177
ItemType: typeName,
178
ItemCount: quantity
179
} satisfies IMiscItem
180
];
181
addMiscItems(inventory, miscItemChanges);
182
await inventory.save();
183
return {
184
InventoryChanges: {
185
MiscItems: miscItemChanges
186
}
187
};
188
}
189
}
153
190
}
154
191
case "Recipes":
155
192
case "Consumables": {
@@ -427,6 +464,21 @@ export const addMiscItems = (inventory: IInventoryDatabaseDocument, itemsArray:
427
464
});
428
465
};
429
466
467
export const addShipDecorations = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
468
const { ShipDecorations } = inventory;
469
470
itemsArray?.forEach(({ ItemCount, ItemType }) => {
471
const itemIndex = ShipDecorations.findIndex(miscItem => miscItem.ItemType === ItemType);
472
473
if (itemIndex !== -1) {
474
ShipDecorations[itemIndex].ItemCount += ItemCount;
475
inventory.markModified(`ShipDecorations.${itemIndex}.ItemCount`);
476
} else {
477
ShipDecorations.push({ ItemCount, ItemType });
478
}
479
});
480
};
481
430
482
export const addConsumables = (inventory: IInventoryDatabaseDocument, itemsArray: IConsumable[] | undefined) => {
431
483
const { Consumables } = inventory;
432
484