From b010ff87c2e88c6cd4e5f62367e5150455ba1e40 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 3 Jun 2024 16:20:16 +0100 Subject: [PATCH] Pulled code out of `acceptRepeatableQuest()` into new function `createAcceptedQuestClientResponse()` --- project/src/controllers/QuestController.ts | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 4c8892cb..2bf2e576 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -363,8 +363,6 @@ export class QuestController sessionID: string, ): IItemEventRouterResponse { - const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID); - // Create and store quest status object inside player profile const newRepeatableQuest = this.questHelper.getQuestReadyForProfile( pmcData, @@ -402,16 +400,27 @@ export class QuestController fullProfile.characters.scav.Quests.push(newRepeatableQuest); } - const repeatableSettings = pmcData.RepeatableQuests.find( - (x) => x.name === repeatableQuestProfile.sptRepatableGroupName, - ); + const response = this.createAcceptedQuestClientResponse(sessionID, pmcData, repeatableQuestProfile); + + return response; + } + + protected createAcceptedQuestClientResponse( + sessionID: string, + pmcData: IPmcData, + repeatableQuestProfile: IRepeatableQuest): IItemEventRouterResponse + { + const repeatableSettings = pmcData.RepeatableQuests + .find((quest) => quest.name === repeatableQuestProfile.sptRepatableGroupName); const change = {}; - change[repeatableQuestProfile._id] = repeatableSettings.changeRequirement[repeatableQuestProfile._id]; - const responseData: IPmcDataRepeatableQuest = { + change[repeatableQuestProfile._id] = repeatableSettings!.changeRequirement[repeatableQuestProfile._id]; + + const repeatableData: IPmcDataRepeatableQuest = { id: repeatableSettings.id - ?? this.questConfig.repeatableQuests.find((x) => x.name === repeatableQuestProfile.sptRepatableGroupName) + ?? this.questConfig.repeatableQuests + .find((repeatableQuest) => repeatableQuest.name === repeatableQuestProfile.sptRepatableGroupName) .id, name: repeatableSettings.name, endTime: repeatableSettings.endTime, @@ -422,11 +431,15 @@ export class QuestController freeChangesAvailable: repeatableSettings.freeChangesAvailable, }; + // Nullguard + const acceptQuestResponse = this.eventOutputHolder.getOutput(sessionID); if (!acceptQuestResponse.profileChanges[sessionID].repeatableQuests) { acceptQuestResponse.profileChanges[sessionID].repeatableQuests = []; } - acceptQuestResponse.profileChanges[sessionID].repeatableQuests.push(responseData); + + // Add constructed objet into response + acceptQuestResponse.profileChanges[sessionID].repeatableQuests.push(repeatableData); return acceptQuestResponse; }