返回提交历史
Modified
src/controllers/api/claimCompletedRecipeController.ts
+7
-6
Modified
src/controllers/api/focusController.ts
+5
-2
Modified
src/controllers/api/inventorySlotsController.ts
+5
-3
Modified
src/controllers/api/modularWeaponCraftingController.ts
+2
-2
Modified
src/controllers/custom/addItemController.ts
+9
-5
Modified
src/services/inventoryService.ts
+137
-133
Modified
src/services/purchaseService.ts
+17
-6
XFEstudio/SpaceNinjaServer
chore: do addItem on inventory document, not accountId (#699)
74ed0986
代码差异
7 个文件
+182
-157
@@ -80,11 +80,12 @@ export const claimCompletedRecipeController: RequestHandler = async (req, res) =
80
80
...(await updateCurrencyByAccountId(recipe.skipBuildTimePrice, true, accountId))
81
81
};
82
82
}
83
res.json({
84
InventoryChanges: {
85
...InventoryChanges,
86
...(await addItem(accountId, recipe.resultType, recipe.num)).InventoryChanges
87
}
88
});
83
const inventory = await getInventory(accountId);
84
InventoryChanges = {
85
...InventoryChanges,
86
...(await addItem(inventory, recipe.resultType, recipe.num)).InventoryChanges
87
};
88
await inventory.save();
89
res.json({ InventoryChanges });
89
90
}
90
91
};
@@ -4,6 +4,7 @@ import { getInventory, addMiscItems, addEquipment } from "@/src/services/invento
4
4
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
5
5
import { logger } from "@/src/utils/logger";
6
6
import { ExportFocusUpgrades } from "warframe-public-export-plus";
7
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
7
8
8
9
export const focusController: RequestHandler = async (req, res) => {
9
10
const accountId = await getAccountIdForRequest(req);
@@ -102,8 +103,10 @@ export const focusController: RequestHandler = async (req, res) => {
102
103
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingChassis",
103
104
"/Lotus/Weapons/Sentients/OperatorAmplifiers/SentTrainingAmplifier/SentAmpTrainingBarrel"
104
105
];
105
const result = await addEquipment("OperatorAmps", request.StartingWeaponType, accountId, parts);
106
res.json(result);
106
const inventory = await getInventory(accountId);
107
const inventoryChanges = addEquipment(inventory, "OperatorAmps", request.StartingWeaponType, parts);
108
await inventory.save();
109
res.json((inventoryChanges.OperatorAmps as IEquipmentClient[])[0]);
107
110
break;
108
111
}
109
112
case FocusOperation.UnbindUpgrade: {
@@ -1,5 +1,5 @@
1
1
import { getAccountIdForRequest } from "@/src/services/loginService";
2
import { updateCurrencyByAccountId } from "@/src/services/inventoryService";
2
import { getInventory, updateCurrency } from "@/src/services/inventoryService";
3
3
import { RequestHandler } from "express";
4
4
import { updateSlots } from "@/src/services/inventoryService";
5
5
import { InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
@@ -26,8 +26,10 @@ export const inventorySlotsController: RequestHandler = async (req, res) => {
26
26
27
27
//TODO: check which slot was purchased because pvpBonus is also possible
28
28
29
const currencyChanges = await updateCurrencyByAccountId(20, true, accountId);
30
await updateSlots(accountId, InventorySlot.PVE_LOADOUTS, 1, 1);
29
const inventory = await getInventory(accountId);
30
const currencyChanges = updateCurrency(inventory, 20, true);
31
updateSlots(inventory, InventorySlot.PVE_LOADOUTS, 1, 1);
32
await inventory.save();
31
33
32
34
//console.log({ InventoryChanges: currencyChanges }, " added loadout changes:");
33
35
@@ -34,9 +34,10 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
34
34
throw new Error(`unknown modular weapon type: ${data.WeaponType}`);
35
35
}
36
36
const category = modularWeaponTypes[data.WeaponType];
37
const inventory = await getInventory(accountId);
37
38
38
39
// Give weapon
39
const weapon = await addEquipment(category, data.WeaponType, accountId, data.Parts);
40
const weapon = addEquipment(inventory, category, data.WeaponType, data.Parts);
40
41
41
42
// Remove credits & parts
42
43
const miscItemChanges = [];
@@ -46,7 +47,6 @@ export const modularWeaponCraftingController: RequestHandler = async (req, res)
46
47
ItemCount: -1
47
48
});
48
49
}
49
const inventory = await getInventory(accountId);
50
50
const currencyChanges = updateCurrency(
51
51
inventory,
52
52
category == "Hoverboards" || category == "MoaPets" ? 5000 : 4000,
@@ -1,7 +1,7 @@
1
1
import { getAccountIdForRequest } from "@/src/services/loginService";
2
2
import { ItemType, toAddItemRequest } from "@/src/helpers/customHelpers/addItemHelpers";
3
3
import { getWeaponType } from "@/src/services/itemDataService";
4
import { addPowerSuit, addEquipment } from "@/src/services/inventoryService";
4
import { addPowerSuit, addEquipment, getInventory } from "@/src/services/inventoryService";
5
5
import { RequestHandler } from "express";
6
6
7
7
const addItemController: RequestHandler = async (req, res) => {
@@ -10,14 +10,18 @@ const addItemController: RequestHandler = async (req, res) => {
10
10
11
11
switch (request.type) {
12
12
case ItemType.Powersuit: {
13
const powersuit = await addPowerSuit(request.InternalName, accountId);
14
res.json(powersuit);
13
const inventory = await getInventory(accountId);
14
const inventoryChanges = addPowerSuit(inventory, request.InternalName);
15
await inventory.save();
16
res.json(inventoryChanges);
15
17
return;
16
18
}
17
19
case ItemType.Weapon: {
20
const inventory = await getInventory(accountId);
18
21
const weaponType = getWeaponType(request.InternalName);
19
const weapon = await addEquipment(weaponType, request.InternalName, accountId);
20
res.json(weapon);
22
const inventoryChanges = addEquipment(inventory, weaponType, request.InternalName);
23
await inventory.save();
24
res.json(inventoryChanges);
21
25
break;
22
26
}
23
27
default:
@@ -105,13 +105,12 @@ export const getInventory = async (accountOwnerId: string): Promise<TInventoryDa
105
105
};
106
106
107
107
export const addItem = async (
108
accountId: string,
108
inventory: TInventoryDatabaseDocument,
109
109
typeName: string,
110
110
quantity: number = 1
111
111
): Promise<{ InventoryChanges: IInventoryChanges }> => {
112
112
// Strict typing
113
113
if (typeName in ExportRecipes) {
114
const inventory = await getInventory(accountId);
115
114
const recipeChanges = [
116
115
{
117
116
ItemType: typeName,
@@ -119,7 +118,6 @@ export const addItem = async (
119
118
} satisfies ITypeCount
120
119
];
121
120
addRecipes(inventory, recipeChanges);
122
await inventory.save();
123
121
return {
124
122
InventoryChanges: {
125
123
Recipes: recipeChanges
@@ -127,11 +125,9 @@ export const addItem = async (
127
125
};
128
126
}
129
127
if (typeName in ExportResources) {
130
const inventory = await getInventory(accountId);
131
128
if (ExportResources[typeName].productCategory == "Ships") {
132
const oid = await createShip(new Types.ObjectId(accountId), typeName);
129
const oid = await createShip(inventory.accountOwnerId, typeName);
133
130
inventory.Ships.push(oid);
134
await inventory.save();
135
131
return {
136
132
InventoryChanges: {
137
133
Ships: [
@@ -143,11 +139,8 @@ export const addItem = async (
143
139
}
144
140
};
145
141
} else if (ExportResources[typeName].productCategory == "CrewShips") {
146
return {
147
InventoryChanges: {
148
CrewShips: [await addCrewShip(typeName, accountId)]
149
}
150
};
142
const inventoryChanges = addCrewShip(inventory, typeName);
143
return { InventoryChanges: inventoryChanges };
151
144
} else {
152
145
const miscItemChanges = [
153
146
{
@@ -156,7 +149,6 @@ export const addItem = async (
156
149
} satisfies IMiscItem
157
150
];
158
151
addMiscItems(inventory, miscItemChanges);
159
await inventory.save();
160
152
return {
161
153
InventoryChanges: {
162
154
MiscItems: miscItemChanges
@@ -165,21 +157,14 @@ export const addItem = async (
165
157
}
166
158
}
167
159
if (typeName in ExportCustoms) {
168
return {
169
InventoryChanges: {
170
WeaponSkins: [await addSkin(typeName, accountId)]
171
}
172
};
160
const inventoryChanges = addSkin(inventory, typeName);
161
return { InventoryChanges: inventoryChanges };
173
162
}
174
163
if (typeName in ExportFlavour) {
175
return {
176
InventoryChanges: {
177
FlavourItems: [await addCustomization(typeName, accountId)]
178
}
179
};
164
const inventoryChanges = addCustomization(inventory, typeName);
165
return { InventoryChanges: inventoryChanges };
180
166
}
181
167
if (typeName in ExportUpgrades || typeName in ExportArcanes) {
182
const inventory = await getInventory(accountId);
183
168
const changes = [
184
169
{
185
170
ItemType: typeName,
@@ -187,7 +172,6 @@ export const addItem = async (
187
172
}
188
173
];
189
174
addMods(inventory, changes);
190
await inventory.save();
191
175
return {
192
176
InventoryChanges: {
193
177
RawUpgrades: changes
@@ -195,7 +179,6 @@ export const addItem = async (
195
179
};
196
180
}
197
181
if (typeName in ExportGear) {
198
const inventory = await getInventory(accountId);
199
182
const consumablesChanges = [
200
183
{
201
184
ItemType: typeName,
@@ -203,7 +186,6 @@ export const addItem = async (
203
186
} satisfies IConsumable
204
187
];
205
188
addConsumables(inventory, consumablesChanges);
206
await inventory.save();
207
189
return {
208
190
InventoryChanges: {
209
191
Consumables: consumablesChanges
@@ -216,8 +198,8 @@ export const addItem = async (
216
198
case "Powersuits":
217
199
switch (typeName.substr(1).split("/")[2]) {
218
200
default: {
219
const inventoryChanges = await addPowerSuit(typeName, accountId);
220
await updateSlots(accountId, InventorySlot.SUITS, 0, 1);
201
const inventoryChanges = addPowerSuit(inventory, typeName);
202
updateSlots(inventory, InventorySlot.SUITS, 0, 1);
221
203
return {
222
204
InventoryChanges: {
223
205
...inventoryChanges,
@@ -230,22 +212,22 @@ export const addItem = async (
230
212
};
231
213
}
232
214
case "Archwing": {
233
const spaceSuit = await addSpaceSuit(typeName, accountId);
234
await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1);
215
const inventoryChanges = addSpaceSuit(inventory, typeName);
216
updateSlots(inventory, InventorySlot.SPACESUITS, 0, 1);
235
217
return {
236
218
InventoryChanges: {
219
...inventoryChanges,
237
220
SpaceSuitBin: {
238
221
count: 1,
239
222
platinum: 0,
240
223
Slots: -1
241
},
242
SpaceSuits: [spaceSuit]
224
}
243
225
}
244
226
};
245
227
}
246
228
case "EntratiMech": {
247
const inventoryChanges = await addMechSuit(typeName, accountId);
248
await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1);
229
const inventoryChanges = addMechSuit(inventory, typeName);
230
updateSlots(inventory, InventorySlot.MECHSUITS, 0, 1);
249
231
return {
250
232
InventoryChanges: {
251
233
...inventoryChanges,
@@ -261,18 +243,17 @@ export const addItem = async (
261
243
break;
262
244
case "Weapons": {
263
245
const weaponType = getWeaponType(typeName);
264
const weapon = await addEquipment(weaponType, typeName, accountId);
265
await updateSlots(accountId, InventorySlot.WEAPONS, 0, 1);
246
const inventoryChanges = addEquipment(inventory, weaponType, typeName);
247
updateSlots(inventory, InventorySlot.WEAPONS, 0, 1);
266
248
return {
267
249
InventoryChanges: {
268
WeaponBin: { count: 1, platinum: 0, Slots: -1 },
269
[weaponType]: [weapon]
250
...inventoryChanges,
251
WeaponBin: { count: 1, platinum: 0, Slots: -1 }
270
252
}
271
253
};
272
254
}
273
255
case "Objects": {
274
256
// /Lotus/Objects/Tenno/Props/TnoLisetTextProjector (Note Beacon)
275
const inventory = await getInventory(accountId);
276
257
const changes = [
277
258
{
278
259
ItemType: typeName,
@@ -280,7 +261,6 @@ export const addItem = async (
280
261
} satisfies IMiscItem
281
262
];
282
263
addShipDecorations(inventory, changes);
283
await inventory.save();
284
264
return {
285
265
InventoryChanges: {
286
266
ShipDecorations: changes
@@ -290,8 +270,8 @@ export const addItem = async (
290
270
case "Types":
291
271
switch (typeName.substr(1).split("/")[2]) {
292
272
case "Sentinels": {
293
const inventoryChanges = await addSentinel(typeName, accountId);
294
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
273
const inventoryChanges = addSentinel(inventory, typeName);
274
updateSlots(inventory, InventorySlot.SENTINELS, 0, 1);
295
275
return {
296
276
InventoryChanges: {
297
277
...inventoryChanges,
@@ -302,7 +282,6 @@ export const addItem = async (
302
282
case "Items": {
303
283
switch (typeName.substr(1).split("/")[3]) {
304
284
case "ShipDecos": {
305
const inventory = await getInventory(accountId);
306
285
const changes = [
307
286
{
308
287
ItemType: typeName,
@@ -310,7 +289,6 @@ export const addItem = async (
310
289
} satisfies IMiscItem
311
290
];
312
291
addShipDecorations(inventory, changes);
313
await inventory.save();
314
292
return {
315
293
InventoryChanges: {
316
294
ShipDecorations: changes
@@ -318,7 +296,6 @@ export const addItem = async (
318
296
};
319
297
}
320
298
default: {
321
const inventory = await getInventory(accountId);
322
299
const miscItemChanges = [
323
300
{
324
301
ItemType: typeName,
@@ -326,7 +303,6 @@ export const addItem = async (
326
303
} satisfies IMiscItem
327
304
];
328
305
addMiscItems(inventory, miscItemChanges);
329
await inventory.save();
330
306
return {
331
307
InventoryChanges: {
332
308
MiscItems: miscItemChanges
@@ -338,7 +314,6 @@ export const addItem = async (
338
314
case "Game":
339
315
if (typeName.substr(1).split("/")[3] == "Projections") {
340
316
// Void Relics, e.g. /Lotus/Types/Game/Projections/T2VoidProjectionGaussPrimeDBronze
341
const inventory = await getInventory(accountId);
342
317
const miscItemChanges = [
343
318
{
344
319
ItemType: typeName,
@@ -346,7 +321,6 @@ export const addItem = async (
346
321
} satisfies IMiscItem
347
322
];
348
323
addMiscItems(inventory, miscItemChanges);
349
await inventory.save();
350
324
return {
351
325
InventoryChanges: {
352
326
MiscItems: miscItemChanges
@@ -363,13 +337,13 @@ export const addItem = async (
363
337
};
364
338
365
339
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
366
export const addSentinel = async (sentinelName: string, accountId: string): Promise<IInventoryChanges> => {
367
const inventoryChanges: IInventoryChanges = {};
368
340
export const addSentinel = (
341
inventory: TInventoryDatabaseDocument,
342
sentinelName: string,
343
inventoryChanges: IInventoryChanges = {}
344
): IInventoryChanges => {
369
345
if (ExportSentinels[sentinelName]?.defaultWeapon) {
370
inventoryChanges.SentinelWeapons = [
371
await addSentinelWeapon(ExportSentinels[sentinelName].defaultWeapon, accountId)
372
];
346
addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
373
347
}
374
348
375
349
const modsToGive: IRawUpgrade[] = [];
@@ -387,96 +361,109 @@ export const addSentinel = async (sentinelName: string, accountId: string): Prom
387
361
}
388
362
}
389
363
390
const inventory = await getInventory(accountId);
391
364
addMods(inventory, modsToGive);
392
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 });
393
const changedInventory = await inventory.save();
394
inventoryChanges.Sentinels = [changedInventory.Sentinels[sentinelIndex - 1].toJSON()];
365
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 }) - 1;
366
inventoryChanges.Sentinels ??= [];
367
(inventoryChanges.Sentinels as IEquipmentClient[]).push(
368
inventory.Sentinels[sentinelIndex].toJSON<IEquipmentClient>()
369
);
395
370
396
371
return inventoryChanges;
397
372
};
398
373
399
export const addSentinelWeapon = async (typeName: string, accountId: string): Promise<IEquipmentClient> => {
400
const inventory = await getInventory(accountId);
401
const sentinelIndex = inventory.SentinelWeapons.push({ ItemType: typeName });
402
const changedInventory = await inventory.save();
403
return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON<IEquipmentClient>();
374
export const addSentinelWeapon = (
375
inventory: TInventoryDatabaseDocument,
376
typeName: string,
377
inventoryChanges: IInventoryChanges
378
): void => {
379
const index = inventory.SentinelWeapons.push({ ItemType: typeName }) - 1;
380
inventoryChanges.SentinelWeapons ??= [];
381
(inventoryChanges.SentinelWeapons as IEquipmentClient[]).push(
382
inventory.SentinelWeapons[index].toJSON<IEquipmentClient>()
383
);
404
384
};
405
385
406
export const addPowerSuit = async (powersuitName: string, accountId: string): Promise<IInventoryChanges> => {
407
const inventoryChanges: IInventoryChanges = {};
386
export const addPowerSuit = (
387
inventory: TInventoryDatabaseDocument,
388
powersuitName: string,
389
inventoryChanges: IInventoryChanges = {}
390
): IInventoryChanges => {
408
391
const specialItems = getExalted(powersuitName);
409
392
if (specialItems) {
410
for await (const specialItem of specialItems) {
411
await addSpecialItem(specialItem, accountId, inventoryChanges);
393
for (const specialItem of specialItems) {
394
addSpecialItem(inventory, specialItem, inventoryChanges);
412
395
}
413
396
}
414
const inventory = await getInventory(accountId);
415
const suitIndex = inventory.Suits.push({ ItemType: powersuitName, Configs: [], UpgradeVer: 101, XP: 0 });
416
const changedInventory = await inventory.save();
417
inventoryChanges.Suits = [changedInventory.Suits[suitIndex - 1].toJSON()];
397
const suitIndex = inventory.Suits.push({ ItemType: powersuitName, Configs: [], UpgradeVer: 101, XP: 0 }) - 1;
398
inventoryChanges.Suits ??= [];
399
(inventoryChanges.Suits as IEquipmentClient[]).push(inventory.Suits[suitIndex].toJSON<IEquipmentClient>());
418
400
return inventoryChanges;
419
401
};
420
402
421
export const addMechSuit = async (mechsuitName: string, accountId: string): Promise<IInventoryChanges> => {
422
const inventoryChanges: IInventoryChanges = {};
403
export const addMechSuit = (
404
inventory: TInventoryDatabaseDocument,
405
mechsuitName: string,
406
inventoryChanges: IInventoryChanges = {}
407
): IInventoryChanges => {
423
408
const specialItems = getExalted(mechsuitName);
424
409
if (specialItems) {
425
for await (const specialItem of specialItems) {
426
await addSpecialItem(specialItem, accountId, inventoryChanges);
410
for (const specialItem of specialItems) {
411
addSpecialItem(inventory, specialItem, inventoryChanges);
427
412
}
428
413
}
429
const inventory = await getInventory(accountId);
430
const suitIndex = inventory.MechSuits.push({ ItemType: mechsuitName, Configs: [], UpgradeVer: 101, XP: 0 });
431
const changedInventory = await inventory.save();
432
inventoryChanges.MechSuits = [changedInventory.MechSuits[suitIndex - 1].toJSON()];
414
const suitIndex = inventory.MechSuits.push({ ItemType: mechsuitName, Configs: [], UpgradeVer: 101, XP: 0 }) - 1;
415
inventoryChanges.MechSuits ??= [];
416
(inventoryChanges.MechSuits as IEquipmentClient[]).push(inventory.MechSuits[suitIndex].toJSON<IEquipmentClient>());
433
417
return inventoryChanges;
434
418
};
435
419
436
export const addSpecialItem = async (
420
export const addSpecialItem = (
421
inventory: TInventoryDatabaseDocument,
437
422
itemName: string,
438
accountId: string,
439
423
inventoryChanges: IInventoryChanges
440
): Promise<void> => {
441
const inventory = await getInventory(accountId);
424
): void => {
442
425
if (inventory.SpecialItems.find(x => x.ItemType == itemName)) {
443
426
return;
444
427
}
445
const specialItemIndex = inventory.SpecialItems.push({
446
ItemType: itemName,
447
Configs: [],
448
Features: 1,
449
UpgradeVer: 101,
450
XP: 0
451
});
452
const changedInventory = await inventory.save();
428
const specialItemIndex =
429
inventory.SpecialItems.push({
430
ItemType: itemName,
431
Configs: [],
432
Features: 1,
433
UpgradeVer: 101,
434
XP: 0
435
}) - 1;
453
436
inventoryChanges.SpecialItems ??= [];
454
(inventoryChanges.SpecialItems as object[]).push(changedInventory.SpecialItems[specialItemIndex - 1].toJSON());
437
(inventoryChanges.SpecialItems as IEquipmentClient[]).push(
438
inventory.SpecialItems[specialItemIndex].toJSON<IEquipmentClient>()
439
);
455
440
};
456
441
457
export const addSpaceSuit = async (spacesuitName: string, accountId: string): Promise<IEquipmentClient> => {
458
const inventory = await getInventory(accountId);
459
const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 });
460
const changedInventory = await inventory.save();
461
return changedInventory.SpaceSuits[suitIndex - 1].toJSON<IEquipmentClient>();
442
export const addSpaceSuit = (
443
inventory: TInventoryDatabaseDocument,
444
spacesuitName: string,
445
inventoryChanges: IInventoryChanges = {}
446
): IInventoryChanges => {
447
const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 }) - 1;
448
inventoryChanges.SpaceSuits ??= [];
449
(inventoryChanges.SpaceSuits as IEquipmentClient[]).push(
450
inventory.SpaceSuits[suitIndex].toJSON<IEquipmentClient>()
451
);
452
return inventoryChanges;
462
453
};
463
454
464
export const updateSlots = async (
465
accountId: string,
455
export const updateSlots = (
456
inventory: TInventoryDatabaseDocument,
466
457
slotName: SlotNames,
467
458
slotAmount: number,
468
459
extraAmount: number
469
): Promise<void> => {
470
const inventory = await getInventory(accountId);
471
460
): void => {
472
461
inventory[slotName].Slots += slotAmount;
473
462
if (inventory[slotName].Extra === undefined) {
474
463
inventory[slotName].Extra = extraAmount;
475
464
} else {
476
465
inventory[slotName].Extra += extraAmount;
477
466
}
478
479
await inventory.save();
480
467
};
481
468
482
469
const isCurrencyTracked = (usePremium: boolean): boolean => {
@@ -548,44 +535,61 @@ export const updateTheme = async (data: IThemeUpdateRequest, accountId: string):
548
535
await inventory.save();
549
536
};
550
537
551
export const addEquipment = async (
538
export const addEquipment = (
539
inventory: TInventoryDatabaseDocument,
552
540
category: TEquipmentKey,
553
541
type: string,
554
accountId: string,
555
modularParts: string[] | undefined = undefined
556
): Promise<IEquipmentClient> => {
557
const inventory = await getInventory(accountId);
558
559
const index = inventory[category].push({
560
ItemType: type,
561
Configs: [],
562
XP: 0,
563
ModularParts: modularParts
564
});
565
566
const changedInventory = await inventory.save();
567
return changedInventory[category][index - 1].toJSON() as object as IEquipmentClient;
542
modularParts: string[] | undefined = undefined,
543
inventoryChanges: IInventoryChanges = {}
544
): IInventoryChanges => {
545
const index =
546
inventory[category].push({
547
ItemType: type,
548
Configs: [],
549
XP: 0,
550
ModularParts: modularParts
551
}) - 1;
552
553
inventoryChanges[category] ??= [];
554
(inventoryChanges[category] as IEquipmentClient[]).push(inventory[category][index].toJSON<IEquipmentClient>());
555
return inventoryChanges;
568
556
};
569
557
570
export const addCustomization = async (customizatonName: string, accountId: string): Promise<IFlavourItem> => {
571
const inventory = await getInventory(accountId);
572
const flavourItemIndex = inventory.FlavourItems.push({ ItemType: customizatonName }) - 1;
573
const changedInventory = await inventory.save();
574
return changedInventory.FlavourItems[flavourItemIndex].toJSON();
558
export const addCustomization = (
559
inventory: TInventoryDatabaseDocument,
560
customizationName: string,
561
inventoryChanges: IInventoryChanges = {}
562
): IInventoryChanges => {
563
const flavourItemIndex = inventory.FlavourItems.push({ ItemType: customizationName }) - 1;
564
inventoryChanges.FlavourItems ??= [];
565
(inventoryChanges.FlavourItems as IFlavourItem[]).push(
566
inventory.FlavourItems[flavourItemIndex].toJSON<IFlavourItem>()
567
);
568
return inventoryChanges;
575
569
};
576
570
577
export const addSkin = async (typeName: string, accountId: string): Promise<IWeaponSkinClient> => {
578
const inventory = await getInventory(accountId);
571
export const addSkin = (
572
inventory: TInventoryDatabaseDocument,
573
typeName: string,
574
inventoryChanges: IInventoryChanges = {}
575
): IInventoryChanges => {
579
576
const index = inventory.WeaponSkins.push({ ItemType: typeName }) - 1;
580
const changedInventory = await inventory.save();
581
return changedInventory.WeaponSkins[index].toJSON() as object as IWeaponSkinClient;
577
inventoryChanges.WeaponSkins ??= [];
578
(inventoryChanges.WeaponSkins as IWeaponSkinClient[]).push(
579
inventory.WeaponSkins[index].toJSON<IWeaponSkinClient>()
580
);
581
return inventoryChanges;
582
582
};
583
583
584
const addCrewShip = async (typeName: string, accountId: string) => {
585
const inventory = await getInventory(accountId);
584
const addCrewShip = (
585
inventory: TInventoryDatabaseDocument,
586
typeName: string,
587
inventoryChanges: IInventoryChanges = {}
588
): IInventoryChanges => {
586
589
const index = inventory.CrewShips.push({ ItemType: typeName }) - 1;
587
const changedInventory = await inventory.save();
588
return changedInventory.CrewShips[index].toJSON();
590
inventoryChanges.CrewShips ??= [];
591
(inventoryChanges.CrewShips as object[]).push(inventory.CrewShips[index].toJSON());
592
return inventoryChanges;
589
593
};
590
594
591
595
const addGearExpByCategory = (
@@ -864,7 +868,7 @@ export const addBooster = async (ItemType: string, time: number, accountId: stri
864
868
existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time;
865
869
inventory.markModified(`Boosters.${itemIndex}.ExpiryDate`);
866
870
} else {
867
Boosters.push({ ItemType, ExpiryDate: currentTime + time }) - 1;
871
Boosters.push({ ItemType, ExpiryDate: currentTime + time });
868
872
}
869
873
870
874
await inventory.save();
@@ -204,9 +204,12 @@ export const handleStoreItemAcquisition = async (
204
204
}
205
205
}
206
206
switch (storeCategory) {
207
default:
208
purchaseResponse = await addItem(accountId, internalName, quantity);
207
default: {
208
const inventory = await getInventory(accountId);
209
purchaseResponse = await addItem(inventory, internalName, quantity);
210
await inventory.save();
209
211
break;
212
}
210
213
case "Types":
211
214
purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
212
215
break;
@@ -248,7 +251,9 @@ const handleSlotPurchase = async (
248
251
const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
249
252
const slotsPerPurchase = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase;
250
253
251
await updateSlots(accountId, slotName, slotsPerPurchase, slotsPerPurchase);
254
const inventory = await getInventory(accountId);
255
updateSlots(inventory, slotName, slotsPerPurchase, slotsPerPurchase);
256
await inventory.save();
252
257
253
258
logger.debug(`added ${slotsPerPurchase} slot ${slotName}`);
254
259
@@ -277,6 +282,7 @@ const handleBoosterPackPurchase = async (
277
282
BoosterPackItems: "",
278
283
InventoryChanges: {}
279
284
};
285
const inventory = await getInventory(accountId);
280
286
for (let i = 0; i != quantity; ++i) {
281
287
for (const weights of pack.rarityWeightsPerRoll) {
282
288
const result = getRandomWeightedReward(pack.components, weights);
@@ -286,11 +292,12 @@ const handleBoosterPackPurchase = async (
286
292
result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};';
287
293
combineInventoryChanges(
288
294
purchaseResponse.InventoryChanges,
289
(await addItem(accountId, result.type, result.itemCount)).InventoryChanges
295
(await addItem(inventory, result.type, result.itemCount)).InventoryChanges
290
296
);
291
297
}
292
298
}
293
299
}
300
await inventory.save();
294
301
return purchaseResponse;
295
302
};
296
303
@@ -303,8 +310,12 @@ const handleTypesPurchase = async (
303
310
const typeCategory = getStoreItemTypesCategory(typesName);
304
311
logger.debug(`type category ${typeCategory}`);
305
312
switch (typeCategory) {
306
default:
307
return await addItem(accountId, typesName, quantity);
313
default: {
314
const inventory = await getInventory(accountId);
315
const resp = await addItem(inventory, typesName, quantity);
316
await inventory.save();
317
return resp;
318
}
308
319
case "BoosterPacks":
309
320
return await handleBoosterPackPurchase(typesName, accountId, quantity);
310
321
case "SlotItems":