From a46e26725fb9f750d18599e8cf981d017b5aec18 Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 24 Oct 2025 21:59:04 +0100 Subject: [PATCH] Hardened `GetRandomizedResourceValue` when `GetPercentOfValue`returns values below 1 --- .../Helpers/BotGeneratorHelper.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs index abd4bf89..8d7d9e20 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs @@ -171,7 +171,7 @@ public class BotGeneratorHelper( } /// - /// Randomize the HpResource for bots e.g (245/400 resources) + /// Choose a random value between a min and max for a resource to be /// /// Max resource value of medical items /// Value provided from config @@ -188,12 +188,11 @@ public class BotGeneratorHelper( return 1; } - var min = randomUtil.GetPercentOfValue(randomizationValues.ResourcePercent, maxResource, 0); + // Generate a randomised min value the resource could have + var min = Math.Max(1, randomUtil.GetPercentOfValue(randomizationValues.ResourcePercent, maxResource, 0)); - // Using food at 0 causes client to error - var clampedMin = Math.Clamp(min, 1, min); - - return randomUtil.GetDouble(clampedMin, maxResource); + // Choose value from randomised min and resource max possible + return randomUtil.GetDouble(min, maxResource); } ///