diff --git a/Libraries/Core/Helpers/RagfairServerHelper.cs b/Libraries/Core/Helpers/RagfairServerHelper.cs index 43355ef4..25d49f3f 100644 --- a/Libraries/Core/Helpers/RagfairServerHelper.cs +++ b/Libraries/Core/Helpers/RagfairServerHelper.cs @@ -150,21 +150,25 @@ public class RagfairServerHelper( // Item Types to return one of if (isWeaponPreset || itemHelper.IsOfBaseclasses(itemDetails.Value.Id, ragfairConfig.Dynamic.ShowAsSingleStack) - ) { + ) + { return 1; } - // Get max stack count - var maxStackCount = itemDetails.Value?.Properties?.StackMaxSize; + // Get max possible stack count + var maxStackSize = itemDetails.Value?.Properties?.StackMaxSize ?? 1; // non-stackable - use different values to calculate stack size - if (maxStackCount is null or 1) { - return randomUtil.GetInt((int) config.NonStackableCount.Min, (int) config.NonStackableCount.Max); + if (maxStackSize == 1) + { + return (int)randomUtil.GetDouble(config.NonStackableCount.Min.Value, config.NonStackableCount.Max.Value); } - var stackPercent = Math.Round(randomUtil.GetDouble((double) config.StackablePercent.Min, (double) config.StackablePercent.Max)); + // Get a % to get of stack size + var stackPercent = randomUtil.GetDouble(config.StackablePercent.Min.Value, config.StackablePercent.Max.Value); - return (int) ((maxStackCount / 100) * stackPercent); + // Min value to return should be no less than 1 + return Math.Max((int)randomUtil.GetPercentOfValue(stackPercent, maxStackSize, 0), 1); } /** diff --git a/Libraries/Core/Utils/RandomUtil.cs b/Libraries/Core/Utils/RandomUtil.cs index feb3338b..6255ec73 100644 --- a/Libraries/Core/Utils/RandomUtil.cs +++ b/Libraries/Core/Utils/RandomUtil.cs @@ -73,7 +73,7 @@ public class RandomUtil(ISptLogger _logger, ICloner _cloner) /// The calculated percentage of the given number, rounded to the specified number of decimal places. public double GetPercentOfValue(double percent, double number, int toFixed = 2) { - var num = percent * number / 100; + var num = percent * (number / 100); return Math.Round(num, toFixed); }