diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 06837c97..3fc6f3f2 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -304,15 +304,28 @@ export const addItem = async ( } if (typeName in ExportKeys) { - const changes = { - ItemType: typeName - }; - addKey(typeName, accountId); - return { - InventoryChanges: { - QuestKeys: [changes] - } - }; + if (typeName.toLocaleLowerCase().includes("quest")) { + const changes = { + ItemType: typeName + }; + addQuestKey(typeName, accountId); + return { + InventoryChanges: { + QuestKeys: [changes] + } + }; + } else { + const changes = { + ItemType: typeName, + ItemCount: quantity + }; + addLevelKey(typeName, quantity, accountId); + return { + InventoryChanges: { + LevelKeys: [changes] + } + }; + } } // Path-based duck typing @@ -549,13 +562,20 @@ export const addKubrowEgg = async ( return changedInventory.KubrowPetEggs[index - 1]; }; -export const addKey = async (typeName: string, accountId: string): Promise => { +export const addQuestKey = async (typeName: string, accountId: string): Promise => { const inventory = await getInventory(accountId); const index = inventory.QuestKeys.push({ ItemType: typeName }) - 1; const changedInventory = await inventory.save(); return changedInventory.QuestKeys[index].toJSON(); }; +export const addLevelKey = async (typeName: string, quantity: number, accountId: string): Promise => { + const inventory = await getInventory(accountId); + const index = inventory.LevelKeys.push({ ItemType: typeName, ItemCount: quantity }) - 1; + const changedInventory = await inventory.save(); + return changedInventory.LevelKeys[index]; +}; + const addGearExpByCategory = ( inventory: IInventoryDatabaseDocument, gearArray: IEquipmentClient[] | undefined,