返回提交历史
Modified
src/services/inventoryService.ts
+42
-8
XFEstudio/XFESpaceNinjaServer
fix: give respective weapons & mods when acquiring sentinel (#623)
42f11b2d
代码差异
1 个文件
+42
-8
@@ -30,7 +30,7 @@ import { logger } from "@/src/utils/logger";
30
30
import { getWeaponType, getExalted } from "@/src/services/itemDataService";
31
31
import { getRandomWeightedReward } from "@/src/services/rngService";
32
32
import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
33
import { IEquipmentClient } from "../types/inventoryTypes/commonInventoryTypes";
33
import { IEquipmentClient, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
34
34
import {
35
35
ExportArcanes,
36
36
ExportBoosterPacks,
@@ -39,6 +39,7 @@ import {
39
39
ExportGear,
40
40
ExportRecipes,
41
41
ExportResources,
42
ExportSentinels,
42
43
ExportUpgrades
43
44
} from "warframe-public-export-plus";
44
45
import { createShip } from "./shipService";
@@ -299,16 +300,16 @@ export const addItem = async (
299
300
}
300
301
case "Types":
301
302
switch (typeName.substr(1).split("/")[2]) {
302
case "Sentinels":
303
// TOOD: Sentinels should also grant their DefaultUpgrades & SentinelWeapon.
304
const sentinel = await addSentinel(typeName, accountId);
303
case "Sentinels": {
304
const inventoryChanges = await addSentinel(typeName, accountId);
305
305
await updateSlots(accountId, InventorySlot.SENTINELS, 0, 1);
306
306
return {
307
307
InventoryChanges: {
308
SentinelBin: { count: 1, platinum: 0, Slots: -1 },
309
Sentinels: [sentinel]
308
...inventoryChanges,
309
SentinelBin: { count: 1, platinum: 0, Slots: -1 }
310
310
}
311
311
};
312
}
312
313
case "Items": {
313
314
switch (typeName.substr(1).split("/")[3]) {
314
315
case "ShipDecos": {
@@ -374,10 +375,43 @@ export const addItem = async (
374
375
375
376
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
376
377
export const addSentinel = async (sentinelName: string, accountId: string) => {
378
const inventoryChanges: IInventoryChanges = {};
379
380
if (ExportSentinels[sentinelName]?.defaultWeapon) {
381
inventoryChanges.SentinelWeapons = [
382
await addSentinelWeapon(ExportSentinels[sentinelName].defaultWeapon, accountId)
383
];
384
}
385
386
const modsToGive: IRawUpgrade[] = [];
387
const configs: IItemConfig[] = [];
388
if (ExportSentinels[sentinelName]?.defaultUpgrades) {
389
const upgrades = [];
390
for (const defaultUpgrade of ExportSentinels[sentinelName].defaultUpgrades) {
391
modsToGive.push({ ItemType: defaultUpgrade.ItemType, ItemCount: 1 });
392
if (defaultUpgrade.Slot != -1) {
393
upgrades[defaultUpgrade.Slot] = defaultUpgrade.ItemType;
394
}
395
}
396
if (upgrades.length != 0) {
397
configs.push({ Upgrades: upgrades });
398
}
399
}
400
401
const inventory = await getInventory(accountId);
402
addMods(inventory, modsToGive);
403
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0 });
404
const changedInventory = await inventory.save();
405
inventoryChanges.Sentinels = [changedInventory.Sentinels[sentinelIndex - 1].toJSON()];
406
407
return inventoryChanges;
408
};
409
410
export const addSentinelWeapon = async (typeName: string, accountId: string) => {
377
411
const inventory = await getInventory(accountId);
378
const sentinelIndex = inventory.Sentinels.push({ ItemType: sentinelName, Configs: [], XP: 0 });
412
const sentinelIndex = inventory.SentinelWeapons.push({ ItemType: typeName });
379
413
const changedInventory = await inventory.save();
380
return changedInventory.Sentinels[sentinelIndex - 1].toJSON();
414
return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON();
381
415
};
382
416
383
417
export const addPowerSuit = async (powersuitName: string, accountId: string): Promise<IEquipmentClient> => {