Fixed AdjustWeighting not correctly ignoring items in the edit list not found at the destination
Added nullguards Added missing comment Simplified if statement
This commit is contained in:
@@ -70,8 +70,9 @@ public class BotEquipmentFilterService
|
||||
{
|
||||
AdjustWeighting(botWeightingAdjustments.Equipment, baseBotNode.BotInventory.Equipment);
|
||||
AdjustWeighting(botWeightingAdjustments.Ammo, baseBotNode.BotInventory.Ammo);
|
||||
// Don't warn when edited item not found, we're editing usec/bear clothing and they dont have each others clothing
|
||||
AdjustWeighting(botWeightingAdjustments?.Clothing, baseBotNode.BotAppearance, false);
|
||||
|
||||
// Don't warn when edited item not found, we're editing usec/bear clothing and they don't have each others clothing
|
||||
AdjustWeighting(botWeightingAdjustments.Clothing, baseBotNode.BotAppearance, false);
|
||||
}
|
||||
|
||||
if (botWeightingAdjustmentsByPlayerLevel is not null)
|
||||
@@ -455,8 +456,9 @@ public class BotEquipmentFilterService
|
||||
/// </summary>
|
||||
/// <param name="weightingAdjustments">Weighting change to apply to bot</param>
|
||||
/// <param name="botItemPool">Bot item dictionary to adjust</param>
|
||||
/// <param name="showEditWarnings">When item being adjusted cannot be found at source, show warning message</param>
|
||||
protected void AdjustWeighting(
|
||||
AdjustmentDetails weightingAdjustments,
|
||||
AdjustmentDetails? weightingAdjustments,
|
||||
Appearance botItemPool,
|
||||
bool showEditWarnings = true)
|
||||
{
|
||||
@@ -470,6 +472,11 @@ public class BotEquipmentFilterService
|
||||
foreach (var poolAdjustmentKvP in weightingAdjustments.Add)
|
||||
{
|
||||
var locationToUpdate = botItemPool.GetByJsonProp<Dictionary<string, double>>(poolAdjustmentKvP.Key);
|
||||
if (locationToUpdate is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var itemToAddKvP in poolAdjustmentKvP.Value)
|
||||
{
|
||||
locationToUpdate[itemToAddKvP.Key] = itemToAddKvP.Value;
|
||||
@@ -482,21 +489,27 @@ public class BotEquipmentFilterService
|
||||
foreach (var poolAdjustmentKvP in weightingAdjustments.Edit)
|
||||
{
|
||||
var locationToUpdate = botItemPool.GetByJsonProp<Dictionary<string, double>>(poolAdjustmentKvP.Key);
|
||||
if (locationToUpdate is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var itemToEditKvP in poolAdjustmentKvP.Value)
|
||||
// Only make change if item exists as we're editing, not adding
|
||||
{
|
||||
if (locationToUpdate.GetValueOrDefault(itemToEditKvP.Key) != null || locationToUpdate.GetValueOrDefault(itemToEditKvP.Key) == 0)
|
||||
if (locationToUpdate.ContainsKey(itemToEditKvP.Key))
|
||||
{
|
||||
locationToUpdate[itemToEditKvP.Key] = itemToEditKvP.Value;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
||||
// We tried to add an item flagged as edit only
|
||||
if (showEditWarnings)
|
||||
{
|
||||
if (showEditWarnings)
|
||||
if (_logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
if (_logger.IsLogEnabled(LogLevel.Debug))
|
||||
{
|
||||
_logger.Debug($"Tried to edit a non - existent item for slot: {poolAdjustmentKvP} {itemToEditKvP}");
|
||||
}
|
||||
_logger.Debug($"Tried to edit a non - existent item for slot: {poolAdjustmentKvP} {itemToEditKvP}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user