From 11afc8f24045930fbb292049ae976c30adfaa40f Mon Sep 17 00:00:00 2001 From: CWX Date: Thu, 16 Jan 2025 10:56:29 +0000 Subject: [PATCH] implement ProbabilityHelper --- Core/Helpers/ProbabilityHelper.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/Helpers/ProbabilityHelper.cs b/Core/Helpers/ProbabilityHelper.cs index 8c356340..7a5a275d 100644 --- a/Core/Helpers/ProbabilityHelper.cs +++ b/Core/Helpers/ProbabilityHelper.cs @@ -1,10 +1,26 @@ using Core.Annotations; +using Core.Models.Utils; +using Core.Utils; namespace Core.Helpers; [Injectable] public class ProbabilityHelper { + private readonly ISptLogger _logger; + private readonly RandomUtil _randomUtil; + + public ProbabilityHelper + ( + ISptLogger logger, + RandomUtil randomUtil + ) + { + _logger = logger; + _randomUtil = randomUtil; + } + + /// /// Chance to roll a number out of 100 /// @@ -13,6 +29,6 @@ public class ProbabilityHelper /// true if success public bool RollChance(double chance, double scale = 1) { - throw new NotImplementedException(); + return _randomUtil.GetInt(1, (int)(100 * scale)) / (1 * scale) <= chance; } }