From 9b7c31e36f221c32c157d66800b93f4deb7b108a Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 3 Dec 2024 16:50:54 +0000 Subject: [PATCH] Added nullgaurd to `getQuestRewardItems()` to protect against invalid custom quests --- project/src/helpers/QuestHelper.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index c1292ba1..c03f0cbf 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -358,9 +358,16 @@ export class QuestHelper { * @returns array of items with the correct maxStack */ public getQuestRewardItems(quest: IQuest, status: QuestStatus, gameVersion: string): IItem[] { + if (!quest.rewards[QuestStatus[status]]) { + this.logger.warning(`Unable to find: ${status} reward for quest: ${quest.QuestName}`); + return []; + } + // Iterate over all rewards with the desired status, flatten out items that have a type of Item const questRewards = quest.rewards[QuestStatus[status]].flatMap((reward: IQuestReward) => - reward.type === "Item" && this.questRewardIsForGameEdition(reward, gameVersion) ? this.processReward(reward) : [], + reward.type === "Item" && this.questRewardIsForGameEdition(reward, gameVersion) + ? this.processReward(reward) + : [], ); return questRewards;