From 8fc0bb95477fdc96a5cefc53af317b497c2acd46 Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 27 Jan 2025 19:41:04 +0000 Subject: [PATCH] Improved durability value generation --- .../Core/Generators/BotInventoryGenerator.cs | 2 +- Libraries/Core/Helpers/BotGeneratorHelper.cs | 14 ++++----- .../Core/Helpers/DurabilityLimitsHelper.cs | 29 ++++++++++--------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/Libraries/Core/Generators/BotInventoryGenerator.cs b/Libraries/Core/Generators/BotInventoryGenerator.cs index 5cbfd79b..50e4c608 100644 --- a/Libraries/Core/Generators/BotInventoryGenerator.cs +++ b/Libraries/Core/Generators/BotInventoryGenerator.cs @@ -405,7 +405,7 @@ public class BotInventoryGenerator( var found = false; // Limit attempts to find a compatible item as it's expensive to check them all - var maxAttempts = Math.Round(settings.RootEquipmentPool.Count() * 0.75); // Roughly 75% of pool size + var maxAttempts = Math.Round(settings.RootEquipmentPool.Count * 0.75); // Roughly 75% of pool size var attempts = 0; while (!found) { diff --git a/Libraries/Core/Helpers/BotGeneratorHelper.cs b/Libraries/Core/Helpers/BotGeneratorHelper.cs index 86946a61..c2c7eb9a 100644 --- a/Libraries/Core/Helpers/BotGeneratorHelper.cs +++ b/Libraries/Core/Helpers/BotGeneratorHelper.cs @@ -256,7 +256,7 @@ public class BotGeneratorHelper( maxDurability ); - return new UpdRepairable { Durability = (int)currentDurability, MaxDurability = (int)maxDurability }; + return new UpdRepairable { Durability = Math.Round(currentDurability, 5), MaxDurability = Math.Round(maxDurability, 5) }; } /// @@ -267,12 +267,12 @@ public class BotGeneratorHelper( /// Repairable object private UpdRepairable GenerateArmorRepairableProperties(TemplateItem itemTemplate, string? botRole = null) { - double? maxDurability; - double? currentDurability; + double maxDurability; + double currentDurability; if (itemTemplate.Properties?.ArmorClass == 0) { - maxDurability = itemTemplate.Properties.MaxDurability; - currentDurability = itemTemplate.Properties.MaxDurability; + maxDurability = itemTemplate.Properties.MaxDurability.Value; + currentDurability = itemTemplate.Properties.MaxDurability.Value; } else { @@ -280,11 +280,11 @@ public class BotGeneratorHelper( currentDurability = _durabilityLimitsHelper.GetRandomizedArmorDurability( itemTemplate, botRole, - maxDurability.Value + maxDurability ); } - return new UpdRepairable { Durability = (int)currentDurability!, MaxDurability = (int)maxDurability! }; + return new UpdRepairable { Durability = Math.Round(currentDurability, 5), MaxDurability = Math.Round(maxDurability, 5) }; } /// diff --git a/Libraries/Core/Helpers/DurabilityLimitsHelper.cs b/Libraries/Core/Helpers/DurabilityLimitsHelper.cs index c75f0bfc..34955ea3 100644 --- a/Libraries/Core/Helpers/DurabilityLimitsHelper.cs +++ b/Libraries/Core/Helpers/DurabilityLimitsHelper.cs @@ -39,23 +39,24 @@ public class DurabilityLimitsHelper( public double GetRandomizedMaxArmorDurability(TemplateItem? itemTemplate, string? botRole = null) { var itemMaxDurability = itemTemplate.Properties.MaxDurability.Value; - - if (botRole is not null) + if (botRole is null) { - if (_botHelper.IsBotPmc(botRole)) - { - return GenerateMaxPmcArmorDurability(itemMaxDurability); - } + return itemMaxDurability; + } - if (_botHelper.IsBotBoss(botRole)) - { - return itemMaxDurability; - } + if (_botHelper.IsBotPmc(botRole)) + { + return GenerateMaxPmcArmorDurability(itemMaxDurability); + } - if (_botHelper.IsBotFollower(botRole)) - { - return itemMaxDurability; - } + if (_botHelper.IsBotBoss(botRole)) + { + return itemMaxDurability; + } + + if (_botHelper.IsBotFollower(botRole)) + { + return itemMaxDurability; } return itemMaxDurability;