From 4b2620093e3012f6cb0c247ae6eedaea3f58bc42 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 12 Dec 2024 13:23:52 +0000 Subject: [PATCH] Moved profile quest management code into its own function --- .../controllers/RepeatableQuestController.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/project/src/controllers/RepeatableQuestController.ts b/project/src/controllers/RepeatableQuestController.ts index 208b40e1..7d6c0138 100644 --- a/project/src/controllers/RepeatableQuestController.ts +++ b/project/src/controllers/RepeatableQuestController.ts @@ -560,14 +560,7 @@ export class RepeatableQuestController { `Removing: ${repeatableConfig.name} quest: ${questToReplace._id} from trader: ${questToReplace.traderId} as its been replaced`, ); - // Find quest we're replacing in pmc profile quests array and remove it - this.questHelper.findAndRemoveQuestFromArrayIfExists(questToReplace._id, pmcData.Quests); - - // Find quest we're replacing in scav profile quests array and remove it - this.questHelper.findAndRemoveQuestFromArrayIfExists( - questToReplace._id, - fullProfile.characters.scav?.Quests ?? [], - ); + this.removeQuestFromProfile(fullProfile, questToReplace._id); // Add new quests replacement cost to profile repeatablesOfTypeInProfile.changeRequirement[newRepeatableQuest._id] = { @@ -612,6 +605,21 @@ export class RepeatableQuestController { return output; } + /** + * Remove the provided quest from pmc and scav character profiles + * @param fullProfile Profile to remove quest from + * @param questToReplaceId Quest id to remove from profile + */ + protected removeQuestFromProfile(fullProfile: ISptProfile, questToReplaceId: string): void { + // Find quest we're replacing in pmc profile quests array and remove it + this.questHelper.findAndRemoveQuestFromArrayIfExists(questToReplaceId, fullProfile.characters.pmc.Quests); + + // Find quest we're replacing in scav profile quests array and remove it + if (fullProfile.characters.scav) { + this.questHelper.findAndRemoveQuestFromArrayIfExists(questToReplaceId, fullProfile.characters.scav.Quests); + } + } + /** * Find a repeatable (daily/weekly/scav) from a players profile by its id * @param questId Id of quest to find