From 0bada5c20cac032e847e4b1d22590a052739b83e Mon Sep 17 00:00:00 2001 From: Archangel Date: Mon, 22 Dec 2025 20:48:50 +0100 Subject: [PATCH] Add migration to fix invalid repeatable quests --- .../Fixes/InvalidRepeatableQuestFix.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Libraries/SPTarkov.Server.Core/Migration/Migrations/Fixes/InvalidRepeatableQuestFix.cs diff --git a/Libraries/SPTarkov.Server.Core/Migration/Migrations/Fixes/InvalidRepeatableQuestFix.cs b/Libraries/SPTarkov.Server.Core/Migration/Migrations/Fixes/InvalidRepeatableQuestFix.cs new file mode 100644 index 00000000..b829cf25 --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/Migration/Migrations/Fixes/InvalidRepeatableQuestFix.cs @@ -0,0 +1,70 @@ +using System.Text.Json.Nodes; +using SPTarkov.DI.Annotations; + +namespace SPTarkov.Server.Core.Migration.Migrations.Fixes; + +[Injectable] +public sealed class InvalidRepeatableQuestFix : AbstractProfileMigration +{ + public override string FromVersion + { + get { return "~4.0"; } + } + + public override string ToVersion + { + get { return "~4.0"; } + } + + public override string MigrationName + { + get { return "InvalidRepeatableQuestFix"; } + } + + public override bool CanMigrate(JsonObject profile, IEnumerable previouslyRanMigrations) + { + if (profile["characters"]?["pmc"]?["RepeatableQuests"] is JsonArray repeatables) + { + foreach (var node in repeatables) + { + if (node is not JsonObject quest) + { + continue; + } + + var endTimeNode = quest["endTime"]; + var endTime = endTimeNode?.GetValue() ?? 0; + + if (endTime != 0 && quest["changeRequirement"] is null) + { + return true; + } + } + } + + return false; + } + + public override JsonObject? Migrate(JsonObject profile) + { + if (profile["characters"]?["pmc"]?["RepeatableQuests"] is JsonArray repeatables) + { + foreach (var node in repeatables) + { + if (node is not JsonObject quest) + { + continue; + } + + var endTime = quest["endTime"]?.GetValue() ?? 0; + + if (endTime != 0 && quest["changeRequirement"] is null) + { + quest["endTime"] = 0; + } + } + } + + return base.Migrate(profile); + } +}