SupaLidlGame/State/Character/PlayerHealState.cs

77 lines
1.9 KiB
C#
Raw Normal View History

2023-09-09 22:33:57 -07:00
using Godot;
namespace SupaLidlGame.State.Character;
public partial class PlayerHealState : PlayerState
{
[Export]
public double TimeToHeal { get; set; }
[Export]
public float HealAmount { get; set; }
private double _timeLeftToHeal = 0;
private bool _hasHealed = false;
public override IState<CharacterState> Enter(IState<CharacterState> prevState)
{
if (_player.Stats.Level.Value < 1)
{
return IdleState;
}
_timeLeftToHeal = TimeToHeal;
GD.Print("Heal anim");
2023-09-10 17:08:14 -07:00
_player.MovementAnimation.Stop();
2023-09-09 22:33:57 -07:00
_player.AttackAnimation.Play("heal_start");
_player.AttackAnimation.Queue("heal");
_hasHealed = false;
return base.Enter(prevState);
}
public override void Exit(IState<CharacterState> nextState)
{
if (_hasHealed)
{
_player.AttackAnimation.Play("heal_end");
}
else
{
_player.AttackAnimation.Play("heal_cancel");
}
2023-09-17 22:35:27 -07:00
base.Exit(nextState);
2023-09-09 22:33:57 -07:00
}
public override CharacterState Process(double delta)
{
// lock player - no base.Process(delta)
// if somehow the player's level decreased mid-heal and is not enough
// then we return to idle
if (_player.Stats.Level.Value < 1)
{
return IdleState;
}
if ((_timeLeftToHeal -= delta) <= 0)
{
// heal player
_player.Stats.Level.Value--;
_player.Health = Mathf.Min(_player.Health + HealAmount, 100);
_hasHealed = true;
return IdleState;
}
return null;
}
public override CharacterState Input(InputEvent @event)
{
if (@event.IsActionReleased("ability"))
{
_player.AttackAnimation.Play("heal_cancel");
return IdleState;
}
return null;
}
}