From 78aaecbb7db1304bbb80ecd4cbc68068940923a7 Mon Sep 17 00:00:00 2001 From: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Date: Sun, 1 Dec 2024 08:43:49 +0100 Subject: [PATCH] separate quest and level keys --- src/services/inventoryService.ts | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) 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,