using System; namespace ProjectI.Builds { public sealed class UltimateChargeState { public const float Maximum = 100; public float Charge { get; private set; } public double ActiveUntil { get; private set; } private double lastTick = double.NaN; private bool wasEligible; public void Tick(double now, bool eligible) { if (!Finite(now) || (!double.IsNaN(lastTick) && now < lastTick)) return; if (!double.IsNaN(lastTick) && eligible && wasEligible) Add((float)(Math.Max(0, now - Math.Max(lastTick, ActiveUntil)) * .5)); lastTick = now; wasEligible = eligible; } public void AddDamage(float applied, bool ultimate) { if (!ultimate && applied > 0 && !float.IsNaN(applied) && !float.IsInfinity(applied)) Add(applied * .01f); } public void AddKill(bool elite, bool boss, bool ultimate) { if (!ultimate) Add(boss ? 10 : elite ? 5 : 2); } public bool TryConsume(double now, double duration) { if (!Finite(now) || !Finite(duration) || double.IsInfinity(now + duration) || Charge < Maximum || now < ActiveUntil) return false; Charge = 0; ActiveUntil = now + duration; return true; } public void Reset() { Charge = 0; ActiveUntil = 0; lastTick = double.NaN; wasEligible = false; } private void Add(float amount) => Charge = Math.Min(Maximum, Charge + amount); private static bool Finite(double n) => n >= 0 && !double.IsNaN(n) && !double.IsInfinity(n); } }