32 lines
976 B
C#
32 lines
976 B
C#
namespace AcDream.App.Net;
|
|
|
|
/// <summary>
|
|
/// Tracks retail's stamina-exhaustion notification edge for one live-session
|
|
/// generation.
|
|
/// </summary>
|
|
internal sealed class StaminaExhaustionEdgeTracker
|
|
{
|
|
private bool? _wasExhausted;
|
|
|
|
/// <summary>
|
|
/// Observes the current stamina value and returns <see langword="true"/>
|
|
/// only when a previously initialized state changes between exhausted and
|
|
/// non-exhausted.
|
|
/// </summary>
|
|
public bool Observe(int currentStamina)
|
|
{
|
|
bool exhausted = currentStamina == 0;
|
|
if (_wasExhausted == exhausted)
|
|
return false;
|
|
|
|
bool isEdge = _wasExhausted.HasValue;
|
|
_wasExhausted = exhausted;
|
|
return isEdge;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Forgets the retiring character/session sample. The first sample in the
|
|
/// next generation establishes a baseline and must not synthesize an edge.
|
|
/// </summary>
|
|
public void Reset() => _wasExhausted = null;
|
|
}
|