From f95ed922a4290a8737f13173b574ad4e2174625b Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Sat, 9 Mar 2024 08:49:26 +0000 Subject: [PATCH] Fix quest statusTimers ending up with named keys (!254) - Don't depend on status being non-numeric to fix statusTimers - Cleaner tracking of fix counts in `updateProfileQuestDataValues` - Better number checking for quest status, since `0` is a valid status, but fails the `!Number()` check - Cleanup of quest status setting in `processAlteredQuests` Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/254 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/controllers/InraidController.ts | 2 +- project/src/helpers/InRaidHelper.ts | 4 +- project/src/services/ProfileFixerService.ts | 43 +++++++++++---------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 8f7236ac..e474ed12 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -433,7 +433,7 @@ export class InraidController pmcQuest.statusTimers = quest.statusTimers; for (const statusTimerKey in quest.statusTimers) { - if (!Number(statusTimerKey)) + if (Number.isNaN(parseInt(statusTimerKey))) { quest.statusTimers[QuestStatus[statusTimerKey]] = quest.statusTimers[statusTimerKey]; delete quest.statusTimers[statusTimerKey]; diff --git a/project/src/helpers/InRaidHelper.ts b/project/src/helpers/InRaidHelper.ts index ece393d8..1afb88e8 100644 --- a/project/src/helpers/InRaidHelper.ts +++ b/project/src/helpers/InRaidHelper.ts @@ -467,8 +467,8 @@ export class InRaidHelper // Set quest as AvailableAfter and set timer const timestamp = this.timeUtil.getTimestamp() + afsRequirement.availableAfter; lockedQuest.availableAfter = timestamp; - lockedQuest.statusTimers.AvailableAfter = timestamp; - lockedQuest.status = 9; + lockedQuest.statusTimers[QuestStatus.AvailableAfter] = this.timeUtil.getTimestamp(); + lockedQuest.status = QuestStatus.AvailableAfter; } } } diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index c5ce0cfa..2aa3e4d6 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -544,7 +544,8 @@ export class ProfileFixerService return; } - const fixes = new Map(); + const fixes: Record = {}; + const timerFixes: Record = {}; const questsToDelete: IQuestStatus[] = []; const fullProfile = this.profileHelper.getFullProfile(profile.sessionId); const isDevProfile = fullProfile?.info.edition.toLowerCase() === "spt developer"; @@ -559,28 +560,23 @@ export class ProfileFixerService continue; } - if (quest.status && !Number(quest.status)) + if (quest.status && Number.isNaN(parseInt(quest.status))) { - if (fixes.has(quest.status)) - { - fixes.set(quest.status, fixes.get(quest.status) + 1); - } - else - { - fixes.set(quest.status, 1); - } + fixes[quest.status] = (fixes[quest.status] ?? 0) + 1; const newQuestStatus = QuestStatus[quest.status]; quest.status = newQuestStatus; + } - for (const statusTimer in quest.statusTimers) + for (const statusTimer in quest.statusTimers) + { + if (Number.isNaN(parseInt(statusTimer))) { - if (!Number(statusTimer)) - { - const newKey = QuestStatus[statusTimer]; - quest.statusTimers[newKey] = quest.statusTimers[statusTimer]; - delete quest.statusTimers[statusTimer]; - } + timerFixes[statusTimer] = (timerFixes[statusTimer] ?? 0) + 1; + + const newKey = QuestStatus[statusTimer]; + quest.statusTimers[newKey] = quest.statusTimers[statusTimer]; + delete quest.statusTimers[statusTimer]; } } } @@ -590,11 +586,18 @@ export class ProfileFixerService profile.Quests.splice(profile.Quests.indexOf(questToDelete), 1); } - if (fixes.size > 0) + if (Object.keys(fixes).length > 0) { this.logger.debug( - `Updated quests values: ${ - Array.from(fixes.entries()).map(([k, v]) => `(${k}: ${v} times)`).join(", ") + `Updated quests values: ${Object.entries(fixes).map(([k, v]) => `(${k}: ${v} times)`).join(", ")}`, + ); + } + + if (Object.keys(timerFixes).length > 0) + { + this.logger.debug( + `Updated statusTimers values: ${ + Object.entries(timerFixes).map(([k, v]) => `(${k}: ${v} times)`).join(", ") }`, ); }