Files
SPT-Server-Build/Core/Helpers/ProbabilityHelper.cs
T
2025-01-16 10:56:29 +00:00

35 lines
881 B
C#

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>
/// <param name="chance">Percentage chance roll should success</param>
/// <param name="scale">scale of chance to allow support of numbers > 1-100</param>
/// <returns>true if success</returns>
public bool RollChance(double chance, double scale = 1)
{
return _randomUtil.GetInt(1, (int)(100 * scale)) / (1 * scale) <= chance;
}
}