From 288b7cf654515c56fbc4cc37969a5145604f9014 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 30 Nov 2023 09:36:28 +0000 Subject: [PATCH] Further cleanup of `acceptQuest` --- project/src/controllers/QuestController.ts | 23 +++++++++++----------- project/src/helpers/QuestHelper.ts | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 51d5c403..d9f6ae3f 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -300,12 +300,15 @@ export class QuestController const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID); // Does quest exist in profile - // Restarting a quest can mean quest exists in profile + // Restarting a failed quest can mean quest exists in profile const existingQuestStatus = pmcData.Quests.find((x) => x.qid === acceptedQuest.qid) if (existingQuestStatus) { // Update existing this.questHelper.resetQuestState(pmcData, QuestStatus.Started, acceptedQuest.qid); + + // Need to send client an empty list of completedConditions (Unsure if this does anything) + acceptQuestResponse.profileChanges[sessionID].questsStatus.push(existingQuestStatus); } else { @@ -324,7 +327,8 @@ export class QuestController questFromDb.description, ); - const startedQuestRewards = this.questHelper.applyQuestReward( + // Apply non-item rewards to profile + return item rewards + const startedQuestRewardItems = this.questHelper.applyQuestReward( pmcData, acceptedQuest.qid, QuestStatus.Started, @@ -332,24 +336,19 @@ export class QuestController acceptQuestResponse, ); + // Send started text + any starting reward items found above to player this.mailSendService.sendLocalisedNpcMessageToPlayer( sessionID, this.traderHelper.getTraderById(questFromDb.traderId), MessageType.QUEST_START, messageId, - startedQuestRewards, + startedQuestRewardItems, this.timeUtil.getHoursAsSeconds(this.questConfig.redeemTime), ); - acceptQuestResponse.profileChanges[sessionID].quests = this.questHelper - .getNewlyAccessibleQuestsWhenStartingQuest(acceptedQuest.qid, sessionID); - - // Quest already existed, probably a fail/restart - // Need to send client an empty list of completedConditions - if (existingQuestStatus) - { - acceptQuestResponse.profileChanges[sessionID].questsStatus = [ existingQuestStatus ]; - } + // Having accepted new quest, look for newly unlocked quests and inform client of them + acceptQuestResponse.profileChanges[sessionID].quests.push(...this.questHelper + .getNewlyAccessibleQuestsWhenStartingQuest(acceptedQuest.qid, sessionID)); return acceptQuestResponse; } diff --git a/project/src/helpers/QuestHelper.ts b/project/src/helpers/QuestHelper.ts index d13798a0..8bd43e65 100644 --- a/project/src/helpers/QuestHelper.ts +++ b/project/src/helpers/QuestHelper.ts @@ -747,7 +747,7 @@ export class QuestHelper questToUpdate.status = newQuestState; questToUpdate.statusTimers[newQuestState] = this.timeUtil.getTimestamp(); - // Delete all status timers after the new status + // Delete all status timers after applying new status for (const statusKey in questToUpdate.statusTimers) { if (Number.parseInt(statusKey) > newQuestState)