From c04b4bad959fa53231e069377b2f2644fac6ee8a Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 27 Jun 2025 23:35:44 +0100 Subject: [PATCH] Improved `GetFilteredDynamicModsForItem` --- .../Generators/BotInventoryGenerator.cs | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs index 0cc570ee..409d4c7b 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs @@ -648,27 +648,36 @@ public class BotInventoryGenerator( ) { var modPool = _botEquipmentModPoolService.GetModsForGearSlot(itemTpl); - foreach (var (modSlot, modsForSlot) in modPool) - { - // Get blacklist - if (!equipmentBlacklist.TryGetValue(modSlot, out var blacklistedMods)) + + return modPool.ToDictionary( + kvp => kvp.Key, + kvp => { - blacklistedMods = []; + var (modSlot, modsForSlot) = kvp; + + if (!equipmentBlacklist.TryGetValue(modSlot, out var blacklistedMods)) + { + // No blacklist for slot, return all mods + return modsForSlot; + } + + var filteredMods = modsForSlot + .Where(mod => !blacklistedMods.Contains(mod)) + .ToHashSet(); + if (filteredMods.Any()) + { + // There's at least one tpl remaining, send it + return filteredMods; + } + + _logger.Warning( + $"Filtering: '{modSlot}' resulted in 0 mods. Reverting to original set for slot" + ); + + // Return original + return modsForSlot; } - - // Get mods not on blacklist - var filteredMods = modsForSlot.Where(slotName => !blacklistedMods.Contains(slotName)); - if (!filteredMods.Any()) - { - _logger.Warning($"Filtering {modSlot} pool resulting in 0 items, skipping filter"); - continue; - } - - modsForSlot.Clear(); - modsForSlot.UnionWith(filteredMods); - } - - return modPool.ToDictionary(); + ); } ///