diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs index 113df077..999c87a7 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs @@ -431,35 +431,21 @@ public class BotGenerator( // Remove blacklisted loot from loot containers foreach (var lootContainerKey in lootContainersToFilter) { - var prop = props.FirstOrDefault(x => string.Equals(x.Name, lootContainerKey, StringComparison.CurrentCultureIgnoreCase)); - var propValue = (Dictionary) prop.GetValue(botInventory.Items); + var propInfo = props + .FirstOrDefault(x => string.Equals(x.Name, lootContainerKey, StringComparison.CurrentCultureIgnoreCase)); + var prop = (Dictionary?) propInfo.GetValue(botInventory.Items); // No container, skip - if (propValue?.Count == 0) + if (prop is null) { continue; } - List tplsToRemove = []; - foreach (var value in propValue) + var newProp = prop.Where(tpl => { - if (_itemFilterService.IsLootableItemBlacklisted(value.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); - } - - prop.SetValue(botInventory.Items, propValue); + return !_itemFilterService.IsLootableItemBlacklisted(tpl.Key); + }).ToDictionary(); + propInfo.SetValue(botInventory.Items, newProp); } } @@ -523,7 +509,7 @@ public class BotGenerator( Health = new CurrentMinMax { Current = _randomUtil.GetDouble(bodyParts.Head.Min, bodyParts.Head.Max), - Maximum = (double)Math.Round(bodyParts.Head.Max) + Maximum = (double) Math.Round(bodyParts.Head.Max) } } }, @@ -533,7 +519,7 @@ public class BotGenerator( Health = new CurrentMinMax { Current = _randomUtil.GetDouble(bodyParts.Chest.Min, bodyParts.Chest.Max), - Maximum = (double)Math.Round(bodyParts.Chest.Max) + Maximum = (double) Math.Round(bodyParts.Chest.Max) } } }, @@ -661,8 +647,8 @@ public class BotGenerator( return []; } - return skills.Select( - kvp => + return skills + .Select(kvp => { // Get skill from dict, skip if not found var skill = kvp.Value; diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index 5a87b05d..2a18365d 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -381,9 +381,9 @@ public class SeasonalEventService( var props = botInventory.Items.GetType().GetProperties(); foreach (var lootContainerKey in _lootContainersToFilter) { - var prop = (Dictionary?) props - .FirstOrDefault(p => string.Equals(p.Name.ToLower(), lootContainerKey.ToLower(), StringComparison.OrdinalIgnoreCase)) - .GetValue(botInventory.Items); + var propInfo = props + .FirstOrDefault(p => string.Equals(p.Name.ToLower(), lootContainerKey.ToLower(), StringComparison.OrdinalIgnoreCase)); + var prop = (Dictionary?) propInfo.GetValue(botInventory.Items); if (prop is null) { @@ -399,19 +399,8 @@ public class SeasonalEventService( ); } - List tplsToRemove = []; - foreach (var tplKey in prop) - { - if (christmasItems.Contains(tplKey.Key)) - { - tplsToRemove.Add(tplKey.Key); - } - } - - foreach (var tplToRemove in tplsToRemove) - { - prop.Remove(tplToRemove); - } + var newProp = prop.Where(tpl => !christmasItems.Contains(tpl.Key)).ToDictionary(); + propInfo.SetValue(botInventory.Items, newProp); } }