From e7813b48dd8245d85e850f4022ff98b8f448eb27 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 12 Dec 2024 22:24:15 +0000 Subject: [PATCH] Added code to reduce the accuracy of values deemed too accurate --- Generator/Helpers/Gear/GearHelpers.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Generator/Helpers/Gear/GearHelpers.cs b/Generator/Helpers/Gear/GearHelpers.cs index 0b8d7cf..585f84a 100644 --- a/Generator/Helpers/Gear/GearHelpers.cs +++ b/Generator/Helpers/Gear/GearHelpers.cs @@ -296,7 +296,13 @@ namespace Generator.Helpers.Gear foreach (var cartridge in botToUpdate.inventory.Ammo.Keys) { var cartridgeWithWeights = botToUpdate.inventory.Ammo[cartridge]; + foreach (var cartridgeKvP in cartridgeWithWeights) + { + cartridgeWithWeights[cartridgeKvP.Key] = ReduceValueAccuracy(cartridgeKvP.Value); + } + var weights = cartridgeWithWeights.Values.Select(x => x).ToList(); + var commonAmmoDivisor = CommonDivisor(weights); foreach (var cartridgeWeightKvP in cartridgeWithWeights) @@ -341,6 +347,11 @@ namespace Generator.Helpers.Gear return; } + foreach (var itemWeightKvp in equipmentDict) + { + equipmentDict[itemWeightKvp.Key] = ReduceValueAccuracy(itemWeightKvp.Value, 4); + } + var weights = equipmentDict.Values.Select(x => x).ToList(); var commonAmmoDivisor = CommonDivisor(weights); @@ -355,5 +366,13 @@ namespace Generator.Helpers.Gear equipmentDict[itemTplWithWeight.Key] /= commonAmmoDivisor; } } + + private static int ReduceValueAccuracy(long x, int digits = 3) + { + int i = (int)Math.Log10(x); + i = Math.Max(0, i - (digits - 1)); + i = (int)Math.Pow(10, i); + return (int)(x / i * i); + } } }