Further cleanup of acceptQuest

This commit is contained in:
Dev 2023-11-30 09:36:28 +00:00
parent a941a22305
commit 288b7cf654
2 changed files with 12 additions and 13 deletions

View File

@ -300,12 +300,15 @@ export class QuestController
const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID); const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID);
// Does quest exist in profile // 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) const existingQuestStatus = pmcData.Quests.find((x) => x.qid === acceptedQuest.qid)
if (existingQuestStatus) if (existingQuestStatus)
{ {
// Update existing // Update existing
this.questHelper.resetQuestState(pmcData, QuestStatus.Started, acceptedQuest.qid); 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 else
{ {
@ -324,7 +327,8 @@ export class QuestController
questFromDb.description, questFromDb.description,
); );
const startedQuestRewards = this.questHelper.applyQuestReward( // Apply non-item rewards to profile + return item rewards
const startedQuestRewardItems = this.questHelper.applyQuestReward(
pmcData, pmcData,
acceptedQuest.qid, acceptedQuest.qid,
QuestStatus.Started, QuestStatus.Started,
@ -332,24 +336,19 @@ export class QuestController
acceptQuestResponse, acceptQuestResponse,
); );
// Send started text + any starting reward items found above to player
this.mailSendService.sendLocalisedNpcMessageToPlayer( this.mailSendService.sendLocalisedNpcMessageToPlayer(
sessionID, sessionID,
this.traderHelper.getTraderById(questFromDb.traderId), this.traderHelper.getTraderById(questFromDb.traderId),
MessageType.QUEST_START, MessageType.QUEST_START,
messageId, messageId,
startedQuestRewards, startedQuestRewardItems,
this.timeUtil.getHoursAsSeconds(this.questConfig.redeemTime), this.timeUtil.getHoursAsSeconds(this.questConfig.redeemTime),
); );
acceptQuestResponse.profileChanges[sessionID].quests = this.questHelper // Having accepted new quest, look for newly unlocked quests and inform client of them
.getNewlyAccessibleQuestsWhenStartingQuest(acceptedQuest.qid, sessionID); acceptQuestResponse.profileChanges[sessionID].quests.push(...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 ];
}
return acceptQuestResponse; return acceptQuestResponse;
} }

View File

@ -747,7 +747,7 @@ export class QuestHelper
questToUpdate.status = newQuestState; questToUpdate.status = newQuestState;
questToUpdate.statusTimers[newQuestState] = this.timeUtil.getTimestamp(); 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) for (const statusKey in questToUpdate.statusTimers)
{ {
if (Number.parseInt(statusKey) > newQuestState) if (Number.parseInt(statusKey) > newQuestState)