Add wait/delay for Doc to exit when attacking

pull/43/head
John Montagu, the 4th Earl of Sandvich 2024-09-16 12:23:32 -07:00
parent abf6316146
commit f5444dd55f
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
2 changed files with 20 additions and 11 deletions

View File

@ -804,14 +804,8 @@ script = ExtResource("8_r8ejq")
Hotbar = [] Hotbar = []
Items = [] Items = []
[node name="DocLance" parent="Inventory" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "ParryParticles", "StateMachine", "Anchor", "HandAnchor") instance=ExtResource("24_2es2r")] [node name="DocLance" parent="Inventory" instance=ExtResource("24_2es2r")]
unique_name_in_owner = true unique_name_in_owner = true
Hitbox = NodePath("Hitbox")
AnimationPlayer = NodePath("AnimationPlayer")
ParryParticles = NodePath("Anchor/Node2D/Sprite2D/ParryParticles")
StateMachine = NodePath("State")
Anchor = NodePath("Anchor")
HandAnchor = NodePath("Anchor/Node2D/Sprite2D/Hand")
[node name="InteractionTrigger" parent="." instance=ExtResource("33_08dyq")] [node name="InteractionTrigger" parent="." instance=ExtResource("33_08dyq")]

View File

@ -15,24 +15,39 @@ public partial class DocExitState : NPCState
private double _currentDuration = 0; private double _currentDuration = 0;
private bool _hasPlayedExitAnim = false;
private bool _previouslyCouldAttack = false;
public override NPCState Enter(IState<NPCState> previousState) public override NPCState Enter(IState<NPCState> previousState)
{ {
_currentDuration = Duration; _currentDuration = Duration;
TelegraphAnimationPlayer.Play("exit_out");
NPC.ShouldMove = false; NPC.ShouldMove = false;
_hasPlayedExitAnim = false;
return null; return null;
} }
public override void Exit(IState<NPCState> nextState) public override void Exit(IState<NPCState> nextState)
{ {
NPC.CanAttack = _previouslyCouldAttack;
} }
public override NPCState Process(double delta) public override NPCState Process(double delta)
{ {
if ((_currentDuration -= delta) <= 0) if (!NPC.Inventory.IsUsingItem)
{ {
return TelegraphState; if (!_hasPlayedExitAnim)
{
_hasPlayedExitAnim = true;
_previouslyCouldAttack = NPC.CanAttack;
NPC.CanAttack = false;
TelegraphAnimationPlayer.Play("exit_out");
}
if ((_currentDuration -= delta) <= 0)
{
return TelegraphState;
}
} }
return null; return null;
} }