From 239dd45243b6a11745ceffd23828a1d5fc5fe056 Mon Sep 17 00:00:00 2001 From: Sainan Date: Sun, 29 Dec 2024 03:00:45 +0100 Subject: [PATCH] fix: purchase response doesn't include exalted weapons when applicable --- src/services/inventoryService.ts | 37 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 78f4f219..423be170 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -219,16 +219,16 @@ export const addItem = async ( case "Powersuits": switch (typeName.substr(1).split("/")[2]) { default: { - const suit = await addPowerSuit(typeName, accountId); + const inventoryChanges = await addPowerSuit(typeName, accountId); await updateSlots(accountId, InventorySlot.SUITS, 0, 1); return { InventoryChanges: { + ...inventoryChanges, SuitBin: { count: 1, platinum: 0, Slots: -1 - }, - Suits: [suit] + } } }; } @@ -247,16 +247,16 @@ export const addItem = async ( }; } case "EntratiMech": { - const mechSuit = await addMechSuit(typeName, accountId); + const inventoryChanges = await addMechSuit(typeName, accountId); await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1); return { InventoryChanges: { + ...inventoryChanges, MechBin: { count: 1, platinum: 0, Slots: -1 - }, - MechSuits: [mechSuit] + } } }; } @@ -405,33 +405,41 @@ export const addSentinelWeapon = async (typeName: string, accountId: string) => return changedInventory.SentinelWeapons[sentinelIndex - 1].toJSON(); }; -export const addPowerSuit = async (powersuitName: string, accountId: string): Promise => { +export const addPowerSuit = async (powersuitName: string, accountId: string): Promise => { + const inventoryChanges: IInventoryChanges = {}; const specialItems = getExalted(powersuitName); if (specialItems) { for await (const specialItem of specialItems) { - await addSpecialItem(specialItem, accountId); + await addSpecialItem(specialItem, accountId, inventoryChanges); } } const inventory = await getInventory(accountId); const suitIndex = inventory.Suits.push({ ItemType: powersuitName, Configs: [], UpgradeVer: 101, XP: 0 }); const changedInventory = await inventory.save(); - return changedInventory.Suits[suitIndex - 1].toJSON() as object as IEquipmentClient; + inventoryChanges.Suits = [changedInventory.Suits[suitIndex - 1].toJSON()]; + return inventoryChanges; }; -export const addMechSuit = async (mechsuitName: string, accountId: string) => { +export const addMechSuit = async (mechsuitName: string, accountId: string): Promise => { + const inventoryChanges: IInventoryChanges = {}; const specialItems = getExalted(mechsuitName); if (specialItems) { for await (const specialItem of specialItems) { - await addSpecialItem(specialItem, accountId); + await addSpecialItem(specialItem, accountId, inventoryChanges); } } const inventory = await getInventory(accountId); const suitIndex = inventory.MechSuits.push({ ItemType: mechsuitName, Configs: [], UpgradeVer: 101, XP: 0 }); const changedInventory = await inventory.save(); - return changedInventory.MechSuits[suitIndex - 1].toJSON(); + inventoryChanges.MechSuits = [changedInventory.MechSuits[suitIndex - 1].toJSON()]; + return inventoryChanges; }; -export const addSpecialItem = async (itemName: string, accountId: string): Promise => { +export const addSpecialItem = async ( + itemName: string, + accountId: string, + inventoryChanges: IInventoryChanges +): Promise => { const inventory = await getInventory(accountId); if (inventory.SpecialItems.find(x => x.ItemType == itemName)) { return; @@ -444,7 +452,8 @@ export const addSpecialItem = async (itemName: string, accountId: string): Promi XP: 0 }); const changedInventory = await inventory.save(); - return changedInventory.SpecialItems[specialItemIndex - 1].toJSON(); + inventoryChanges.SpecialItems ??= []; + (inventoryChanges.SpecialItems as object[]).push(changedInventory.SpecialItems[specialItemIndex - 1].toJSON()); }; export const addSpaceSuit = async (spacesuitName: string, accountId: string) => {