diff --git a/src/BadDay.Core/PainBox.cs b/src/BadDay.Core/PainBox.cs index d9eccce..c624472 100644 --- a/src/BadDay.Core/PainBox.cs +++ b/src/BadDay.Core/PainBox.cs @@ -17,13 +17,19 @@ public sealed class PainBox { _p = parameters; _rng = rng; - DisableTick = parameters.BoxDisableAtSeconds is { } d - ? (long)Math.Round(d / parameters.TickSeconds) - : long.MaxValue; + Level = parameters.BoxIntensity; + DisableTick = long.MaxValue; + if (parameters.BoxDisableAtSeconds is { } d) SwitchOff((long)Math.Round(d / parameters.TickSeconds)); } /// The first tick the box is off; when it is never disabled. - public long DisableTick { get; } + public long DisableTick { get; private set; } + + /// The intensity the ramp scales: the parameters' BoxIntensity until a caller sets it. + public double Level { get; set; } + + /// Switches the box off from ; an earlier switch-off stands. + public void SwitchOff(long tick) => DisableTick = Math.Min(DisableTick, tick); /// Writes this tick's intensity. Always draws the jitter, so the stream does not depend on state. public void Write(long tick, ref BoxStimulus box) @@ -31,7 +37,7 @@ public sealed class PainBox double jitter = _rng.NextSigned(); double ramp = Math.Min(1.0, tick * _p.TickSeconds / _p.BoxRampSeconds); box.Intensity = tick < DisableTick - ? Math.Max(0.0, _p.BoxIntensity * ramp * (1.0 + _p.BoxNoise * jitter)) + ? Math.Max(0.0, Level * ramp * (1.0 + _p.BoxNoise * jitter)) : 0.0; } } diff --git a/src/BadDay.Core/PainBoxSession.cs b/src/BadDay.Core/PainBoxSession.cs index 0e8c259..889e723 100644 --- a/src/BadDay.Core/PainBoxSession.cs +++ b/src/BadDay.Core/PainBoxSession.cs @@ -62,6 +62,12 @@ public sealed class PainBoxSession /// True from the tick the deliberate withdrawal begins. public bool Withdrew { get; private set; } + /// Sets the box intensity the ramp scales; it takes effect on the next . + public void SetIntensity(double level) => _box.Level = level; + + /// Switches the box off from the next tick; the check then ends the run if the will still holds. + public void SwitchOff() => _box.SwitchOff(TickIndex); + /// /// The disable check, before ticking: if the box switches off now while the will still holds, the run ends /// with the will intact and this returns true. A will already broken is not given back by the box going off.