simplify blacklist filtering

This commit is contained in:
CWX
2025-04-22 13:08:39 +01:00
parent d8bdfb9cb0
commit 7726df0ee1
2 changed files with 17 additions and 42 deletions
@@ -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<string, double>) prop.GetValue(botInventory.Items);
var propInfo = props
.FirstOrDefault(x => string.Equals(x.Name, lootContainerKey, StringComparison.CurrentCultureIgnoreCase));
var prop = (Dictionary<string, double>?) propInfo.GetValue(botInventory.Items);
// No container, skip
if (propValue?.Count == 0)
if (prop is null)
{
continue;
}
List<string> 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;