diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index a2071b2c..4f6ca9d6 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -26,7 +26,8 @@ import { ILibraryDailyTaskInfo, ICalendarProgress, IDroneClient, - IUpgradeClient + IUpgradeClient, + ISlots } from "@/src/types/inventoryTypes/inventoryTypes"; import { IGenericUpdate } from "../types/genericUpdate"; import { @@ -159,10 +160,31 @@ export const getInventory = async ( return inventory; }; +const occupySlot = ( + inventory: TInventoryDatabaseDocument, + bin: InventorySlot, + premiumPurchase: boolean +): IInventoryChanges => { + const slotChanges = { + Slots: 0, + Extra: 0 + }; + if (premiumPurchase) { + slotChanges.Extra += 1; + } else { + slotChanges.Slots -= 1; + } + updateSlots(inventory, bin, slotChanges.Slots, slotChanges.Extra); + return { + [bin]: slotChanges satisfies ISlots + }; +}; + export const addItem = async ( inventory: TInventoryDatabaseDocument, typeName: string, - quantity: number = 1 + quantity: number = 1, + premiumPurchase: boolean = false ): Promise<{ InventoryChanges: IInventoryChanges }> => { // Bundles are technically StoreItems but a) they don't have a normal counterpart, and b) they are used in non-StoreItem contexts, e.g. email attachments. if (typeName in ExportBundles) { @@ -305,11 +327,10 @@ export const addItem = async ( combineInventoryChanges(inventoryChanges, await addItem(inventory, item, 1)); } } - updateSlots(inventory, InventorySlot.WEAPONS, 0, 1); return { InventoryChanges: { ...inventoryChanges, - WeaponBin: { count: 1, platinum: 0, Slots: -1 } + ...occupySlot(inventory, InventorySlot.WEAPONS, premiumPurchase) } }; } else { @@ -378,44 +399,26 @@ export const addItem = async ( case "Powersuits": switch (typeName.substr(1).split("/")[2]) { default: { - const inventoryChanges = addPowerSuit(inventory, typeName); - updateSlots(inventory, InventorySlot.SUITS, 0, 1); return { InventoryChanges: { - ...inventoryChanges, - SuitBin: { - count: 1, - platinum: 0, - Slots: -1 - } + ...addPowerSuit(inventory, typeName), + ...occupySlot(inventory, InventorySlot.SUITS, premiumPurchase) } }; } case "Archwing": { - const inventoryChanges = addSpaceSuit(inventory, typeName); - updateSlots(inventory, InventorySlot.SPACESUITS, 0, 1); return { InventoryChanges: { - ...inventoryChanges, - SpaceSuitBin: { - count: 1, - platinum: 0, - Slots: -1 - } + ...addSpaceSuit(inventory, typeName), + ...occupySlot(inventory, InventorySlot.SPACESUITS, premiumPurchase) } }; } case "EntratiMech": { - const inventoryChanges = addMechSuit(inventory, typeName); - updateSlots(inventory, InventorySlot.MECHSUITS, 0, 1); return { InventoryChanges: { - ...inventoryChanges, - MechBin: { - count: 1, - platinum: 0, - Slots: -1 - } + ...addMechSuit(inventory, typeName), + ...occupySlot(inventory, InventorySlot.MECHSUITS, premiumPurchase) } }; } @@ -446,12 +449,10 @@ export const addItem = async ( case "Types": switch (typeName.substr(1).split("/")[2]) { case "Sentinels": { - const inventoryChanges = addSentinel(inventory, typeName); - updateSlots(inventory, InventorySlot.SENTINELS, 0, 1); return { InventoryChanges: { - ...inventoryChanges, - SentinelBin: { count: 1, platinum: 0, Slots: -1 } + ...addSentinel(inventory, typeName), + ...occupySlot(inventory, InventorySlot.SENTINELS, premiumPurchase) } }; } diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index 76a6d111..cd6e7cad 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -251,7 +251,7 @@ export const handleStoreItemAcquisition = async ( } switch (storeCategory) { default: { - purchaseResponse = await addItem(inventory, internalName, quantity); + purchaseResponse = await addItem(inventory, internalName, quantity, true); break; } case "Types":