62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace KernelPanic.Combat
|
|
{
|
|
/// <summary>
|
|
/// Carries source data for combat rolls so later passives can bias the result.
|
|
/// </summary>
|
|
public readonly struct RollContext
|
|
{
|
|
public RollContext(CombatantState source)
|
|
{
|
|
Source = source;
|
|
}
|
|
|
|
public static RollContext None => new(null);
|
|
public CombatantState Source { get; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Single combat randomness chokepoint. Seeded from RunConfig.RunSeed during boot for reproducible runs.
|
|
/// </summary>
|
|
public static class RandomRoll
|
|
{
|
|
private static Random _random = new(0);
|
|
public static int CurrentSeed { get; private set; }
|
|
public static int DrawCount { get; private set; }
|
|
|
|
public static void Seed(int seed)
|
|
{
|
|
_random = new Random(seed);
|
|
CurrentSeed = seed;
|
|
DrawCount = 0;
|
|
}
|
|
|
|
public static void Restore(int seed, int draws)
|
|
{
|
|
if (draws < 0 || draws > 10000000) throw new ArgumentOutOfRangeException(nameof(draws));
|
|
Seed(seed);
|
|
for (int i = 0; i < draws; i++) _random.Next();
|
|
DrawCount = draws;
|
|
}
|
|
|
|
public static int RollRange(int min, int max, RollContext context)
|
|
{
|
|
if (min > max)
|
|
{
|
|
(min, max) = (max, min);
|
|
}
|
|
|
|
// Mint's passive will flip this bool; no passive sets it in this scaffold.
|
|
if (context.Source != null && context.Source.ForceMaxRolls)
|
|
{
|
|
return max;
|
|
}
|
|
|
|
int value = _random.Next(min, max + 1);
|
|
DrawCount += (long)max + 1 - min > int.MaxValue ? 2 : 1;
|
|
return value;
|
|
}
|
|
}
|
|
}
|