implement ProbabilityHelper

This commit is contained in:
CWX
2025-01-16 10:56:29 +00:00
parent e21515f02a
commit 11afc8f240
+17 -1
View File
@@ -1,10 +1,26 @@
using Core.Annotations;
using Core.Models.Utils;
using Core.Utils;
namespace Core.Helpers;
[Injectable]
public class ProbabilityHelper
{
private readonly ISptLogger<ProbabilityHelper> _logger;
private readonly RandomUtil _randomUtil;
public ProbabilityHelper
(
ISptLogger<ProbabilityHelper> logger,
RandomUtil randomUtil
)
{
_logger = logger;
_randomUtil = randomUtil;
}
/// <summary>
/// Chance to roll a number out of 100
/// </summary>
@@ -13,6 +29,6 @@ public class ProbabilityHelper
/// <returns>true if success</returns>
public bool RollChance(double chance, double scale = 1)
{
throw new NotImplementedException();
return _randomUtil.GetInt(1, (int)(100 * scale)) / (1 * scale) <= chance;
}
}