From cf6868b3b91f4af102bbdda035c49cbbeed289a3 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 12 Dec 2024 14:46:55 +0000 Subject: [PATCH] Added code to handle cleaning up of repeatable change requirements --- .../controllers/RepeatableQuestController.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/project/src/controllers/RepeatableQuestController.ts b/project/src/controllers/RepeatableQuestController.ts index 7d6c0138..f98d679c 100644 --- a/project/src/controllers/RepeatableQuestController.ts +++ b/project/src/controllers/RepeatableQuestController.ts @@ -562,7 +562,10 @@ export class RepeatableQuestController { this.removeQuestFromProfile(fullProfile, questToReplace._id); - // Add new quests replacement cost to profile + // Delete the replaced quest change requirement from profile + this.cleanUpRepeatableChangeRequirements(repeatablesOfTypeInProfile, questToReplace._id); + + // Add replacement quests change requirement data to profile repeatablesOfTypeInProfile.changeRequirement[newRepeatableQuest._id] = { changeCost: newRepeatableQuest.changeCost, changeStandingCost: this.randomUtil.getArrayValue([0, 0.01]), @@ -620,6 +623,25 @@ export class RepeatableQuestController { } } + /** + * Clean up the repeatables `changeRequirement` dictionary of expired data + * @param repeatablesOfTypeInProfile The repeatables that have the replaced and new quest + * @param replacedQuestId Id of the replaced quest + */ + protected cleanUpRepeatableChangeRequirements( + repeatablesOfTypeInProfile: IPmcDataRepeatableQuest, + replacedQuestId: string, + ): void { + if (repeatablesOfTypeInProfile.activeQuests.length === 1) { + // Only one repeatable quest being replaced (e.g. scav_daily), remove everything ready for new quest requirement to be added + // Will assist in cleanup of existing profiles data + repeatablesOfTypeInProfile.changeRequirement = {}; + } else { + // Multiple active quests of this type (e.g. daily or weekly) are active, just remove the single replaced quest + delete repeatablesOfTypeInProfile.changeRequirement[replacedQuestId]; + } + } + /** * Find a repeatable (daily/weekly/scav) from a players profile by its id * @param questId Id of quest to find