From 0038e19489d8821d3ad0ff1c247daea68dce6a04 Mon Sep 17 00:00:00 2001 From: Archangel Date: Thu, 23 Oct 2025 18:23:19 +0200 Subject: [PATCH] Add new migration --- .../4.0/BuyRestrictionMaxStringToInt.cs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Libraries/SPTarkov.Server.Core/Migration/Migrations/4.0/BuyRestrictionMaxStringToInt.cs diff --git a/Libraries/SPTarkov.Server.Core/Migration/Migrations/4.0/BuyRestrictionMaxStringToInt.cs b/Libraries/SPTarkov.Server.Core/Migration/Migrations/4.0/BuyRestrictionMaxStringToInt.cs new file mode 100644 index 00000000..8dfb4e5f --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/Migration/Migrations/4.0/BuyRestrictionMaxStringToInt.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Nodes; +using System.Threading.Tasks; +using SPTarkov.DI.Annotations; + +namespace SPTarkov.Server.Core.Migration.Migrations; + +[Injectable] +public class BuyRestrictionMaxStringToInt : AbstractProfileMigration +{ + public override string FromVersion + { + get { return "~4.0"; } + } + + public override string ToVersion + { + get { return "~4.0"; } + } + + public override string MigrationName + { + get { return "BuyRestrictionMaxStringToInt400"; } + } + + public override IEnumerable PrerequisiteMigrations + { + get { return [typeof(ThreeElevenToFourZero)]; } + } + + public override bool CanMigrate(JsonObject profile, IEnumerable previouslyRanMigrations) + { + if (profile?["characters"]?["pmc"]?["Inventory"]?["items"] is JsonArray items) + { + foreach (var itemNode in items) + { + if (itemNode is not JsonObject itemObj) + { + continue; + } + + if (itemObj["upd"] is JsonObject updObj) + { + if (updObj.TryGetPropertyValue("BuyRestrictionMax", out var buyRestrictionMaxNode)) + { + if (buyRestrictionMaxNode is JsonValue value && value.TryGetValue(out string? _)) + { + return true; + } + } + } + } + } + + return false; + } + + public override JsonObject? Migrate(JsonObject profile) + { + if (profile["characters"]?["pmc"]?["Inventory"]?["items"] is JsonArray items) + { + foreach (var itemNode in items) + { + if (itemNode is not JsonObject itemObj) + { + continue; + } + + if (itemObj["upd"] is JsonObject updObj && + updObj.TryGetPropertyValue("BuyRestrictionMax", out var buyRestrictionMaxNode)) + { + if (buyRestrictionMaxNode is JsonValue value && + value.TryGetValue(out string? strValue)) + { + if (int.TryParse(strValue, out var intValue)) + { + updObj["BuyRestrictionMax"] = intValue; + } + else + { + updObj.Remove("BuyRestrictionMax"); + } + } + } + } + } + + return base.Migrate(profile); + } +}