2024-03-25 21:14:06 -07:00
|
|
|
using Godot;
|
2024-06-04 22:12:01 -07:00
|
|
|
using SupaLidlGame.Extensions;
|
2024-03-25 21:14:06 -07:00
|
|
|
|
|
|
|
namespace SupaLidlGame.Utils;
|
|
|
|
|
|
|
|
public partial class CharacterStats : Node
|
|
|
|
{
|
|
|
|
public DoubleValue StaggerDamage { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public double StaggerCoefficient { get; set; } = 0.5;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public double StaggerDecayVelocity { get; set; } = 5;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public double MaxStagger { get; set; } = 25;
|
|
|
|
|
|
|
|
[Signal]
|
2024-03-29 16:17:19 -07:00
|
|
|
public delegate void StaggerEventHandler(double time, float damage);
|
2024-03-25 21:14:06 -07:00
|
|
|
|
|
|
|
public bool ShouldStagger => StaggerDamage.Value >= MaxStagger;
|
|
|
|
|
|
|
|
protected bool _shouldDecayStagger;
|
|
|
|
|
|
|
|
protected Timer _staggerDecayTimer;
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
StaggerDamage = GetNode<DoubleValue>("StaggerDamage");
|
|
|
|
|
|
|
|
if (StaggerDamage is null)
|
|
|
|
{
|
|
|
|
StaggerDamage = new DoubleValue();
|
|
|
|
AddChild(StaggerDamage);
|
|
|
|
}
|
|
|
|
|
|
|
|
_staggerDecayTimer = new Timer();
|
|
|
|
_staggerDecayTimer.Timeout += () => _shouldDecayStagger = true;
|
|
|
|
_staggerDecayTimer.Stop();
|
|
|
|
AddChild(_staggerDecayTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddStaggerDamage(float damage)
|
|
|
|
{
|
2024-03-29 16:17:19 -07:00
|
|
|
float delta = damage * (float)StaggerCoefficient;
|
|
|
|
StaggerDamage.Value += delta;
|
2024-03-25 21:14:06 -07:00
|
|
|
if (StaggerDamage.Value >= MaxStagger)
|
|
|
|
{
|
2024-03-29 16:17:19 -07:00
|
|
|
EmitSignal(SignalName.Stagger, 1, delta);
|
|
|
|
StaggerDamage.Value = 0;
|
2024-03-25 21:14:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_shouldDecayStagger = false;
|
2024-06-04 22:12:01 -07:00
|
|
|
_staggerDecayTimer.Restart(1);
|
2024-03-25 21:14:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void _Process(double delta)
|
|
|
|
{
|
|
|
|
if (_shouldDecayStagger)
|
|
|
|
{
|
|
|
|
StaggerDamage.Value = Mathf.MoveToward(
|
|
|
|
StaggerDamage.Value, 0, StaggerDecayVelocity * delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|