From 0a1913ab49c3cb3105d1147c665d321f47c2c860 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 25 Jul 2023 19:20:17 +0100 Subject: [PATCH] Fix issue with completing `Sadist` not failing `Colleagues Part 3` Added fail state to colleagues p3 Reworked loop inside `getQuestsFailedByCompletingQuest()` to use .some() instead Reworked `failQuests()` to check all fail conditions instead of just the first one --- project/assets/database/templates/quests.json | 17 ++++++++++++++++ project/src/controllers/QuestController.ts | 20 +++++++------------ .../src/models/eft/common/tables/IQuest.ts | 1 + 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/project/assets/database/templates/quests.json b/project/assets/database/templates/quests.json index 516b494f..925de1ab 100644 --- a/project/assets/database/templates/quests.json +++ b/project/assets/database/templates/quests.json @@ -52036,6 +52036,23 @@ "visibilityConditions": [] }, "dynamicLocale": false + }, + { + "_parent": "Quest", + "_props": { + "availableAfter": 0, + "dispersion": 0, + "dynamicLocale": false, + "id": "5edac4fb16d984318871ba2e", + "index": 1, + "parentId": "", + "status": [ + 4 + ], + "target": "5edab4b1218d181e29451435", + "visibilityConditions": [] + }, + "dynamicLocale": false } ] }, diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 6c62c70e..9556e92b 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -397,7 +397,7 @@ export class QuestController // Check if any of linked quest is failed, and that is unrestartable. const questsToFail = this.getQuestsFailedByCompletingQuest(completedQuestId); - if (questsToFail && questsToFail.length > 0) + if (questsToFail?.length > 0) { this.failQuests(sessionID, pmcData, questsToFail); } @@ -498,7 +498,8 @@ export class QuestController */ protected getQuestsFailedByCompletingQuest(completedQuestId: string): IQuest[] { - return this.questHelper.getQuestsFromDb().filter((x) => + const questsInDb = this.questHelper.getQuestsFromDb(); + return questsInDb.filter((x) => { // No fail conditions, exit early if (!x.conditions.Fail || x.conditions.Fail.length === 0) @@ -506,20 +507,12 @@ export class QuestController return false; } - for (const failCondition of x.conditions.Fail) - { - if (failCondition._props.target === completedQuestId) - { - return true; - } - } - - return false; + return x.conditions.Fail.some(y => y._props.target === completedQuestId); }); } /** - * Fail the quests provided + * Fail the provided quests * Update quest in profile, otherwise add fresh quest object with failed status * @param sessionID session id * @param pmcData player profile @@ -529,7 +522,8 @@ export class QuestController { for (const questToFail of questsToFail) { - if (questToFail.conditions.Fail[0]._props.status[0] !== QuestStatus.Success) + // Skip failing a quest that has a fail status of something other than success + if (questToFail.conditions.Fail?.some(x => x._props.status?.some(y => y !== QuestStatus.Success))) { continue; } diff --git a/project/src/models/eft/common/tables/IQuest.ts b/project/src/models/eft/common/tables/IQuest.ts index b5412b8d..e97b311d 100644 --- a/project/src/models/eft/common/tables/IQuest.ts +++ b/project/src/models/eft/common/tables/IQuest.ts @@ -77,6 +77,7 @@ export interface AvailableForProps zoneId?: string type?: boolean countInRaid?: boolean + globalQuestCounterId?: any } export interface AvailableForCounter