namespace GamePort.Game; /// Jimmy424E80 timed Invisible device; material state and source /// targetable55D are distinct from raw control and authored visibility. public sealed class InvisibleGadget { public const float Duration = 7; public bool Equipped { get; private set; } public float Remaining { get; private set; } public float Recharge { get; private set; } public bool Targetable { get; private set; } = true; public float Opacity { get; private set; } = 1; public bool ConventionalBlend { get; private set; } public bool MeterVisible { get; private set; } public bool MeterReady { get; private set; } public float MeterPercent { get; private set; } public int Activations { get; private set; } public bool Active => Equipped && !Targetable; public event Action? EquippedChanged; public event Action? AlphaRequested; public event Action? BlendRequested; public bool Equip(float energy, bool energyOverride) { if (!float.IsFinite(energy)) throw new ArgumentOutOfRangeException(nameof(energy)); if (energy <= 0 && !energyOverride) return false; Equipped = true; Remaining = Recharge = 0; Targetable = true; Opacity = 1; ConventionalBlend = false; MeterReady = false; MeterVisible = true; EquippedChanged?.Invoke(true); return true; } public void Release() { BlendRequested?.Invoke(true); AlphaRequested?.Invoke(0); Equipped = false; Remaining = Duration; Recharge = 0; Targetable = true; Opacity = 1; ConventionalBlend = false; MeterVisible = false; MeterReady = false; EquippedChanged?.Invoke(false); } public void Reset() { Release(); Remaining = MeterPercent = 0; Activations = 0; } public void Step(float seconds, bool anyControlled, bool primary, bool jump, float energy, bool energyOverride, Action adjustEnergy, bool suppressed = false) { if (!float.IsFinite(seconds) || seconds < 0 || seconds >= 1) throw new ArgumentOutOfRangeException(nameof(seconds)); if (!float.IsFinite(energy)) throw new ArgumentOutOfRangeException(nameof(energy)); ArgumentNullException.ThrowIfNull(adjustEnergy); //Any controlled pointer, not necessarily Jimmy's identity. A NULL //owner freezes timers and hides both meter sprites without cleanup. if (!anyControlled) { MeterVisible = false; return; } if (!Equipped) return; MeterVisible = true; if (primary && !jump) { if (suppressed) return; if (Remaining == 0 && Recharge == Duration) { if (energy <= 2 && !energyOverride) return; adjustEnergy(-2); Remaining = Duration; Recharge = 0; Activations++; ConventionalBlend = false; Opacity = .7f; Targetable = false; BlendRequested?.Invoke(false); AlphaRequested?.Invoke(.7f); } } if (Remaining == 0 && (energy > 0 || energyOverride)) { var sum = (double)Recharge + seconds; Recharge = (float)sum; MeterPercent = (float)(sum * (1f / 7) * 100); if (Recharge >= Duration) { Recharge = Duration; MeterReady = true; } } if (Remaining <= 0) return; var remaining = (double)Remaining - seconds; Remaining = (float)remaining; MeterPercent = (float)Math.Max(remaining * (1f / 7) * 100, 0); if (Remaining <= 0) { Remaining = 0; Opacity = 1; Targetable = true; ConventionalBlend = false; MeterReady = false; BlendRequested?.Invoke(true); AlphaRequested?.Invoke(0); return; } if (Remaining <= 3) { ConventionalBlend = ((int)((double)Remaining * 5) & 1) != 0; BlendRequested?.Invoke(ConventionalBlend); } } }