From 8bdec80dafc705aaed0f6fa87f78ff099279358f Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 19 Jan 2025 23:53:50 +0000 Subject: [PATCH] Implemented AdjustWeighting --- .../Services/BotEquipmentFilterService.cs | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Libraries/Core/Services/BotEquipmentFilterService.cs b/Libraries/Core/Services/BotEquipmentFilterService.cs index 1f41006a..4bcf5bfb 100644 --- a/Libraries/Core/Services/BotEquipmentFilterService.cs +++ b/Libraries/Core/Services/BotEquipmentFilterService.cs @@ -347,6 +347,8 @@ public class BotEquipmentFilterService Dictionary> botItemPool, bool showEditWarnings = true) { + //TODO, bad typing by key with method below due to, EquipmentSlots + // MAKE CONSISTENT BEFORE IMPLEMENTING throw new NotImplementedException(); } @@ -355,12 +357,51 @@ public class BotEquipmentFilterService /// /// Weighting change to apply to bot /// Bot item dictionary to adjust + /// protected void AdjustWeighting( - AdjustmentDetails weightingAdjustments, + AdjustmentDetails? weightingAdjustments, Dictionary> botItemPool, bool showEditWarnings = true) { - throw new NotImplementedException(); + if (weightingAdjustments is null) + { + return; + } + + if (weightingAdjustments.Add?.Count > 0) + { + foreach (var poolAdjustmentKvP in weightingAdjustments.Add) + { + var locationToUpdate = botItemPool[poolAdjustmentKvP.Key]; + foreach (var itemToAddKvP in poolAdjustmentKvP.Value) + { + locationToUpdate[itemToAddKvP.Key] = poolAdjustmentKvP.Value[itemToAddKvP.Key]; + } + } + } + + if (weightingAdjustments.Edit?.Count > 0) + { + foreach (var poolAdjustmentKvP in weightingAdjustments.Edit) + { + var locationToUpdate = botItemPool[poolAdjustmentKvP.Key]; + foreach (var itemToEditKvP in poolAdjustmentKvP.Value) + { + // Only make change if item exists as we're editing, not adding + if (locationToUpdate[itemToEditKvP.Key] != null || locationToUpdate[itemToEditKvP.Key] == 0) + { + locationToUpdate[itemToEditKvP.Key] = poolAdjustmentKvP.Value[itemToEditKvP.Key]; + } + else + { + if (showEditWarnings) + { + _logger.Debug($"Tried to edit a non - existent item for slot: {poolAdjustmentKvP} {itemToEditKvP}"); + } + } + } + } + } } ///