Implement timed Invisible gadget and shared energy warnings
This commit is contained in:
1 parent
3527d33810
commit
1897dd2b90
44 files changed
+2466
-39
No files matched your search
@@ -0,0 +1,87 @@
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>Jimmy424E80 timed Invisible device; material state and source
|
||||
/// targetable55D are distinct from raw control and authored visibility.</summary>
|
||||
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<bool>? EquippedChanged;
|
||||
|
||||
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()
|
||||
{
|
||||
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<float> 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;
|
||||
}
|
||||
}
|
||||
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;
|
||||
return;
|
||||
}
|
||||
if (Remaining <= 3)
|
||||
ConventionalBlend = ((int)((double)Remaining * 5) & 1) != 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user