返回提交历史
Modified
src/services/inventoryService.ts
+14
-14
XFEstudio/SpaceNinjaServer
fix: occupy a sentinel slot for sentinel weapons (#1156)
Fixes #1155 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1156
7acb5492
代码差异
1 个文件
+14
-14
@@ -518,15 +518,7 @@ export const addItem = async (
518
518
switch (typeName.substr(1).split("/")[2]) {
519
519
case "Sentinels": {
520
520
return {
521
InventoryChanges: {
522
...addSentinel(
523
inventory,
524
typeName,
525
{},
526
premiumPurchase ? EquipmentFeatures.DOUBLE_CAPACITY : undefined
527
),
528
...occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase)
529
}
521
InventoryChanges: addSentinel(inventory, typeName, premiumPurchase)
530
522
};
531
523
}
532
524
case "Game": {
@@ -622,20 +614,24 @@ export const applyDefaultUpgrades = (
622
614
};
623
615
624
616
//TODO: maybe genericMethod for all the add methods, they share a lot of logic
625
export const addSentinel = (
617
const addSentinel = (
626
618
inventory: TInventoryDatabaseDocument,
627
619
sentinelName: string,
628
inventoryChanges: IInventoryChanges = {},
629
features: number | undefined = undefined
620
premiumPurchase: boolean,
621
inventoryChanges: IInventoryChanges = {}
630
622
): IInventoryChanges => {
623
// Sentinel itself occupies a slot in the sentinels bin
624
combineInventoryChanges(inventoryChanges, occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase));
625
631
626
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
632
627
if (ExportSentinels[sentinelName]?.defaultWeapon) {
633
addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, inventoryChanges);
628
addSentinelWeapon(inventory, ExportSentinels[sentinelName].defaultWeapon, premiumPurchase, inventoryChanges);
634
629
}
635
630
636
631
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
637
632
const configs: IItemConfig[] = applyDefaultUpgrades(inventory, ExportSentinels[sentinelName]?.defaultUpgrades);
638
633
634
const features = premiumPurchase ? EquipmentFeatures.DOUBLE_CAPACITY : undefined;
639
635
const sentinelIndex =
640
636
inventory.Sentinels.push({ ItemType: sentinelName, Configs: configs, XP: 0, Features: features }) - 1;
641
637
inventoryChanges.Sentinels ??= [];
@@ -644,11 +640,15 @@ export const addSentinel = (
644
640
return inventoryChanges;
645
641
};
646
642
647
export const addSentinelWeapon = (
643
const addSentinelWeapon = (
648
644
inventory: TInventoryDatabaseDocument,
649
645
typeName: string,
646
premiumPurchase: boolean,
650
647
inventoryChanges: IInventoryChanges
651
648
): void => {
649
// Sentinel weapons also occupy a slot in the sentinels bin
650
combineInventoryChanges(inventoryChanges, occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase));
651
652
652
const index = inventory.SentinelWeapons.push({ ItemType: typeName, XP: 0 }) - 1;
653
653
inventoryChanges.SentinelWeapons ??= [];
654
654
inventoryChanges.SentinelWeapons.push(inventory.SentinelWeapons[index].toJSON<IEquipmentClient>());