simplify blacklist filtering
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -381,9 +381,9 @@ public class SeasonalEventService(
|
||||
var props = botInventory.Items.GetType().GetProperties();
|
||||
foreach (var lootContainerKey in _lootContainersToFilter)
|
||||
{
|
||||
var prop = (Dictionary<string, double>?) 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<string, double>?) propInfo.GetValue(botInventory.Items);
|
||||
|
||||
if (prop is null)
|
||||
{
|
||||
@@ -399,19 +399,8 @@ public class SeasonalEventService(
|
||||
);
|
||||
}
|
||||
|
||||
List<string> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user