From 3312a5f28cadd7c2de082615a07e31f1fe37b403 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 23 Aug 2025 10:14:04 +0100 Subject: [PATCH] Fixed Server serializing difficulty values incorrectly --- .../SPTarkov.Server.Core/Helpers/BotHelper.cs | 49 ------------------- .../Models/Eft/Common/Tables/BotType.cs | 29 +++++------ .../Services/SeasonalEventService.cs | 25 ++++++++-- 3 files changed, 37 insertions(+), 66 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs index ac0883b2..351abe29 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs @@ -69,55 +69,6 @@ public class BotHelper(ISptLogger logger, DatabaseService databaseSer return botRole.StartsWith("infected", StringComparison.CurrentCultureIgnoreCase); } - /// - /// Add a bot to the FRIENDLY_BOT_TYPES list - /// - /// bot settings to alter - /// bot type to add to friendly list - public void AddBotToFriendlyList(DifficultyCategories difficultySettings, string typeToAdd) - { - const string friendlyBotTypesKey = "FRIENDLY_BOT_TYPES"; - - // Null guard - if (!difficultySettings.Mind.ContainsKey(friendlyBotTypesKey)) - { - difficultySettings.Mind[friendlyBotTypesKey] = new List(); - } - - ((List)difficultySettings.Mind[friendlyBotTypesKey]).Add(typeToAdd); - } - - /// - /// Add a bot to the REVENGE_BOT_TYPES list - /// - /// bot settings to alter - /// bot type to add to revenge list - public void AddBotToRevengeList(DifficultyCategories difficultySettings, string[] typesToAdd) - { - const string revengePropKey = "REVENGE_BOT_TYPES"; - - // Nothing to add - if (typesToAdd.Length == 0) - { - return; - } - - // Null guard - if (!difficultySettings.Mind.ContainsKey(revengePropKey)) - { - difficultySettings.Mind[revengePropKey] = new List(); - } - - var revengeArray = (List)difficultySettings.Mind[revengePropKey]; - foreach (var botTypeToAdd in typesToAdd) - { - if (!revengeArray.Contains(botTypeToAdd)) - { - revengeArray.Add(botTypeToAdd); - } - } - } - /// /// Get randomization settings for bot from config/bot.json /// diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs index e2c947eb..a30665f3 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs @@ -1,3 +1,4 @@ +using System.Text.Json; using System.Text.Json.Serialization; using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Enums; @@ -240,33 +241,33 @@ public double? ModPistol_Grip { get; set; } public record DifficultyCategories { - public Dictionary? Aiming { get; set; } // TODO: string | number | boolean + public Dictionary? Aiming { get; set; } // TODO: string | number | boolean - public Dictionary? Boss { get; set; } // TODO: string | number | boolean + public Dictionary? Boss { get; set; } // TODO: string | number | boolean - public Dictionary? Change { get; set; } // TODO: string | number | boolean + public Dictionary? Change { get; set; } // TODO: string | number | boolean - public Dictionary? Core { get; set; } // TODO: string | number | boolean + public Dictionary? Core { get; set; } // TODO: string | number | boolean - public Dictionary? Cover { get; set; } // TODO: string | number | boolean + public Dictionary? Cover { get; set; } // TODO: string | number | boolean - public Dictionary? Grenade { get; set; } // TODO: string | number | boolean + public Dictionary? Grenade { get; set; } // TODO: string | number | boolean - public Dictionary? Hearing { get; set; } // TODO: string | number | boolean + public Dictionary? Hearing { get; set; } // TODO: string | number | boolean - public Dictionary? Lay { get; set; } // TODO: string | number | boolean + public Dictionary? Lay { get; set; } // TODO: string | number | boolean - public Dictionary? Look { get; set; } // TODO: string | number | boolean + public Dictionary? Look { get; set; } // TODO: string | number | boolean - public Dictionary? Mind { get; set; } // TODO: string | number | boolean | string[] + public Dictionary? Mind { get; set; } // TODO: string | number | boolean | string[] - public Dictionary? Move { get; set; } // TODO: string | number | boolean + public Dictionary? Move { get; set; } // TODO: string | number | boolean - public Dictionary? Patrol { get; set; } // TODO: string | number | boolean + public Dictionary? Patrol { get; set; } // TODO: string | number | boolean - public Dictionary? Scattering { get; set; } // TODO: string | number | boolean + public Dictionary? Scattering { get; set; } // TODO: string | number | boolean - public Dictionary? Shoot { get; set; } // TODO: string | number | boolean + public Dictionary? Shoot { get; set; } // TODO: string | number | boolean } public record Experience diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 4c325e34..8cc5f597 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -1,4 +1,5 @@ using System.Collections.Frozen; +using System.Text.Json; using SPTarkov.Common.Extensions; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Extensions; @@ -920,13 +921,31 @@ public class SeasonalEventService( protected void AddLootItemsToGifterDropItemsList() { var gifterBot = databaseService.GetBots().Types["gifter"]; - var itemsCSV = string.Join(",", gifterBot.BotInventory.Items.Backpack.Keys); string[] difficulties = ["easy", "normal", "hard", "impossible"]; foreach (var difficulty in difficulties) { - gifterBot.BotDifficulty[difficulty].Patrol.TryAdd("ITEMS_TO_DROP", ""); - gifterBot.BotDifficulty[difficulty].Patrol["ITEMS_TO_DROP"] = itemsCSV; + var gifterPatrolValues = gifterBot.BotDifficulty[difficulty].Patrol; + + // Read existing value from property + var existingItems = Enumerable.Empty(); + if (gifterPatrolValues.TryGetValue("ITEMS_TO_DROP", out var jsonElement) && jsonElement.ValueKind == JsonValueKind.String) + { + var existingCsv = jsonElement.GetString(); + if (!string.IsNullOrWhiteSpace(existingCsv)) + { + existingItems = existingCsv.Split(','); + } + } + + // Merge existing and new tpls we want + var combinedItems = new HashSet(existingItems); + combinedItems.UnionWith(gifterBot.BotInventory.Items.Backpack.Keys.Select(x => x.ToString())); + + // Turn set into a comma separated list ready for insertion + var finalItemsCsv = string.Join(",", combinedItems); + + gifterPatrolValues["ITEMS_TO_DROP"] = JsonDocument.Parse($"\"{finalItemsCsv}\"").RootElement.Clone(); } }