Resolve issue with failQuest() breaking when no quest or repeatable quest is found and it attempts to send a mail message to player

This commit is contained in:
Dev 2024-03-12 21:24:46 +00:00
parent d18fafad01
commit 378bb7fdae

View File

@ -686,7 +686,7 @@ export class QuestHelper
output: IItemEventRouterResponse = null, output: IItemEventRouterResponse = null,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
// Prepare response to send back client // Prepare response to send back to client
if (!output) if (!output)
{ {
output = this.eventOutputHolder.getOutput(sessionID); output = this.eventOutputHolder.getOutput(sessionID);
@ -698,14 +698,16 @@ export class QuestHelper
// Create a dialog message for completing the quest. // Create a dialog message for completing the quest.
const quest = this.getQuestFromDb(failRequest.qid, pmcData); const quest = this.getQuestFromDb(failRequest.qid, pmcData);
const matchingRepeatable = pmcData.RepeatableQuests.flatMap((repeatableType) => repeatableType.activeQuests) // Merge all daily/weekly/scav daily quests into one array and look for the matching quest by id
.find((activeQuest) => activeQuest._id === failRequest.qid); const matchingRepeatableQuest = pmcData.RepeatableQuests.flatMap((repeatableType) =>
repeatableType.activeQuests
).find((activeQuest) => activeQuest._id === failRequest.qid);
if (!(matchingRepeatable || quest)) if (matchingRepeatableQuest || quest)
{ {
this.mailSendService.sendLocalisedNpcMessageToPlayer( this.mailSendService.sendLocalisedNpcMessageToPlayer(
sessionID, sessionID,
this.traderHelper.getTraderById(quest?.traderId ?? matchingRepeatable.traderId), // can be null when repeatable quest has been moved to inactiveQuests this.traderHelper.getTraderById(quest?.traderId ?? matchingRepeatableQuest?.traderId), // Can be null when repeatable quest has been moved to inactiveQuests
MessageType.QUEST_FAIL, MessageType.QUEST_FAIL,
quest.failMessageText, quest.failMessageText,
questRewards, questRewards,