SupaLidlGame/State/NPC/Doc/DocExitState.cs

55 lines
1.3 KiB
C#
Raw Normal View History

2023-07-13 23:46:58 -07:00
using Godot;
namespace SupaLidlGame.State.NPC.Doc;
public partial class DocExitState : NPCState
{
[Export]
public AnimationPlayer TelegraphAnimationPlayer { get; set; }
[Export]
public DocTelegraphState TelegraphState { get; set; }
[Export]
public double Duration { get; set; } = 1;
private double _currentDuration = 0;
private bool _hasPlayedExitAnim = false;
private bool _previouslyCouldAttack = false;
2023-07-13 23:46:58 -07:00
public override NPCState Enter(IState<NPCState> previousState)
{
_currentDuration = Duration;
2023-07-24 21:29:14 -07:00
NPC.ShouldMove = false;
_hasPlayedExitAnim = false;
2023-07-13 23:46:58 -07:00
return null;
}
public override void Exit(IState<NPCState> nextState)
{
NPC.CanAttack = _previouslyCouldAttack;
2023-07-13 23:46:58 -07:00
}
public override NPCState Process(double delta)
{
if (!NPC.Inventory.IsUsingItem)
2023-07-13 23:46:58 -07:00
{
if (!_hasPlayedExitAnim)
{
_hasPlayedExitAnim = true;
_previouslyCouldAttack = NPC.CanAttack;
NPC.CanAttack = false;
TelegraphAnimationPlayer.Play("exit_out");
}
if ((_currentDuration -= delta) <= 0)
{
return TelegraphState;
}
2023-07-13 23:46:58 -07:00
}
return null;
}
}