From d8bdfb9cb0495620eea73b418b827f38d643ae0b Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 21 Apr 2025 23:36:10 +0100 Subject: [PATCH] Fix botgen filtering issues --- .../Generators/BotGenerator.cs | 11 +++++--- .../Services/SeasonalEventService.cs | 26 ++++--------------- 2 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs index 5bb9788a..113df077 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs @@ -441,14 +441,19 @@ public class BotGenerator( } List tplsToRemove = []; - foreach (var (key, _) in propValue) + foreach (var value in propValue) { - if (_itemFilterService.IsLootableItemBlacklisted(key)) + if (_itemFilterService.IsLootableItemBlacklisted(value.Key)) { - tplsToRemove.Add(key); + tplsToRemove.Add(value.Key); } } + if (tplsToRemove.Count > 0) + { + Console.WriteLine($"Removing {tplsToRemove.Count} blacklisted loot from {lootContainerKey}"); + } + foreach (var blacklistedTplToRemove in tplsToRemove) { propValue.Remove(blacklistedTplToRemove); diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 2b4f614c..5a87b05d 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -80,6 +80,9 @@ public class SeasonalEventService( protected SeasonalEventConfig _seasonalEventConfig = _configServer.GetConfig(); protected WeatherConfig _weatherConfig = _configServer.GetConfig(); + protected HashSet _equipmentSlotsToFilter = [EquipmentSlots.FaceCover, EquipmentSlots.Headwear, EquipmentSlots.Backpack, EquipmentSlots.TacticalVest]; + protected HashSet _lootContainersToFilter = ["Backpack", "Pockets", "TacticalVest"]; + /// /// Get an array of christmas items found in bots inventories as loot /// @@ -352,11 +355,9 @@ public class SeasonalEventService( public void RemoveChristmasItemsFromBotInventory(BotTypeInventory botInventory, string botRole) { var christmasItems = GetChristmasEventItems(); - HashSet equipmentSlotsToFilter = [EquipmentSlots.FaceCover, EquipmentSlots.Headwear, EquipmentSlots.Backpack, EquipmentSlots.TacticalVest]; - HashSet lootContainersToFilter = ["Backpack", "Pockets", "TacticalVest"]; // Remove christmas related equipment - foreach (var equipmentSlotKey in equipmentSlotsToFilter) + foreach (var equipmentSlotKey in _equipmentSlotsToFilter) { if (botInventory.Equipment[equipmentSlotKey] is null) { @@ -378,7 +379,7 @@ public class SeasonalEventService( // Remove christmas related loot from loot containers var props = botInventory.Items.GetType().GetProperties(); - foreach (var lootContainerKey in lootContainersToFilter) + foreach (var lootContainerKey in _lootContainersToFilter) { var prop = (Dictionary?) props .FirstOrDefault(p => string.Equals(p.Name.ToLower(), lootContainerKey.ToLower(), StringComparison.OrdinalIgnoreCase)) @@ -411,23 +412,6 @@ public class SeasonalEventService( { prop.Remove(tplToRemove); } - - // Get non-christmas items - var nonChristmasTpls = prop.Where(tpl => !christmasItems.Contains(tpl.Key)); - if (!nonChristmasTpls.Any()) - { - continue; - } - - Dictionary intermediaryDict = new(); - - foreach (var tpl in nonChristmasTpls) - { - intermediaryDict[tpl.Key] = prop[tpl.Key]; - } - - // Replace the original containerItems with the updated one - prop = intermediaryDict; } }