mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
namespace Nadeko.Econ.Gambling;
|
|
|
|
public sealed class BetrollGame
|
|
{
|
|
private readonly (int WhenAbove, decimal MultiplyBy)[] _thresholdPairs;
|
|
private readonly NadekoRandom _rng;
|
|
|
|
public BetrollGame(IReadOnlyList<(int WhenAbove, decimal MultiplyBy)> pairs)
|
|
{
|
|
_thresholdPairs = pairs.OrderByDescending(x => x.WhenAbove).ToArray();
|
|
_rng = new();
|
|
}
|
|
|
|
public BetrollResult Roll(decimal amount = 0)
|
|
{
|
|
var roll = _rng.Next(1, 101);
|
|
|
|
for (var i = 0; i < _thresholdPairs.Length; i++)
|
|
{
|
|
ref var pair = ref _thresholdPairs[i];
|
|
|
|
if (pair.WhenAbove < roll)
|
|
{
|
|
return new()
|
|
{
|
|
Multiplier = pair.MultiplyBy,
|
|
Roll = roll,
|
|
Threshold = pair.WhenAbove,
|
|
Won = amount * pair.MultiplyBy
|
|
};
|
|
}
|
|
}
|
|
|
|
return new()
|
|
{
|
|
Multiplier = 0,
|
|
Roll = roll,
|
|
Threshold = -1,
|
|
Won = 0,
|
|
};
|
|
}
|
|
} |