From 0b29d336527949edf354602a38700d30224b40db Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 18 Feb 2025 00:43:48 +0100 Subject: [PATCH 1/2] fix: add missing quest keys at updateQuestKey it's possible the quest key was not in already in the inventory but the quest was still available due to unlockAllQuests --- src/services/questService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/questService.ts b/src/services/questService.ts index e53126c5..1916ca0c 100644 --- a/src/services/questService.ts +++ b/src/services/questService.ts @@ -22,10 +22,10 @@ export const updateQuestKey = ( throw new Error("more than 1 quest key not supported"); } - const questKeyIndex = inventory.QuestKeys.findIndex(questKey => questKey.ItemType === questKeyUpdate[0].ItemType); - + let questKeyIndex = inventory.QuestKeys.findIndex(questKey => questKey.ItemType === questKeyUpdate[0].ItemType); if (questKeyIndex === -1) { - throw new Error(`quest key ${questKeyUpdate[0].ItemType} not found`); + // it's possible the quest key was not in already in the inventory but the quest was still available due to unlockAllQuests + questKeyIndex = inventory.QuestKeys.push({ ItemType: questKeyUpdate[0].ItemType }) - 1; } inventory.QuestKeys[questKeyIndex] = questKeyUpdate[0]; -- 2.47.2 From cbc1d2942a85545b7ba2e15dbae6eb9bf7eed9c5 Mon Sep 17 00:00:00 2001 From: Sainan Date: Tue, 18 Feb 2025 20:09:39 +0100 Subject: [PATCH 2/2] error when quest key is missing & unlockAllQuests is false --- src/services/questService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/questService.ts b/src/services/questService.ts index 1916ca0c..ae7c8133 100644 --- a/src/services/questService.ts +++ b/src/services/questService.ts @@ -3,6 +3,7 @@ import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/invento import { IInventoryDatabase, IQuestKeyDatabase, IQuestStage } from "@/src/types/inventoryTypes/inventoryTypes"; import { logger } from "@/src/utils/logger"; import { HydratedDocument } from "mongoose"; +import { config } from "@/src/services/configService"; export interface IUpdateQuestRequest { QuestKeys: Omit[]; @@ -24,7 +25,7 @@ export const updateQuestKey = ( let questKeyIndex = inventory.QuestKeys.findIndex(questKey => questKey.ItemType === questKeyUpdate[0].ItemType); if (questKeyIndex === -1) { - // it's possible the quest key was not in already in the inventory but the quest was still available due to unlockAllQuests + if (!config.unlockAllQuests) throw new Error(`quest key ${questKeyUpdate[0].ItemType} not found`); questKeyIndex = inventory.QuestKeys.push({ ItemType: questKeyUpdate[0].ItemType }) - 1; } -- 2.47.2