2023-05-23 00:23:53 -07:00
|
|
|
using Godot;
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
namespace SupaLidlGame.State.Weapon;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public partial class SwordAttackState : WeaponState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public SupaLidlGame.Items.Weapons.Sword Sword { get; set; }
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public SwordAnticipateState AnticipateState { get; set; }
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
[Export]
|
|
|
|
public SwordIdleState IdleState { get; set; }
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
private double _attackDuration = 0;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
private double _useDuration = 0;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
private double _attackAnimDuration = 0;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
private bool _isAlternate = false;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
public override WeaponState Enter(IState<WeaponState> prevState)
|
|
|
|
{
|
2023-07-23 11:03:55 -07:00
|
|
|
Sword.EnableParry();
|
2023-06-03 18:21:46 -07:00
|
|
|
Sword.Attack();
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
if (_isAlternate)
|
|
|
|
{
|
|
|
|
Sword.AnimationPlayer.Play("attack_alternate");
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
else
|
2023-05-23 00:23:53 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
Sword.AnimationPlayer.Play("attack");
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
_attackDuration = Sword.AttackTime;
|
|
|
|
_useDuration = Sword.UseTime;
|
|
|
|
_attackAnimDuration = Sword.AttackAnimationDuration;
|
|
|
|
|
|
|
|
Sword.Visible = true;
|
|
|
|
Sword.UseDirection = Sword.Character.Target;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Exit(IState<WeaponState> nextState)
|
|
|
|
{
|
|
|
|
Sword.Deattack();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WeaponState Use()
|
|
|
|
{
|
|
|
|
if (_useDuration <= 0)
|
2023-05-23 00:23:53 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
// if we are still playing the current attack animation, we should alternate
|
|
|
|
if (_attackAnimDuration > 0)
|
2023-05-23 00:23:53 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
_isAlternate = !_isAlternate;
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
return IdleState;
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WeaponState Process(double delta)
|
|
|
|
{
|
|
|
|
if (_attackDuration > 0)
|
2023-05-23 00:23:53 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
if ((_attackDuration -= delta) <= 0)
|
2023-05-23 00:23:53 -07:00
|
|
|
{
|
2023-06-03 18:21:46 -07:00
|
|
|
Sword.Deattack();
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
2023-06-03 18:21:46 -07:00
|
|
|
}
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
if ((_attackAnimDuration -= delta) <= 0)
|
|
|
|
{
|
|
|
|
Sword.AnimationPlayer.Play("RESET");
|
|
|
|
_isAlternate = false;
|
|
|
|
return IdleState;
|
|
|
|
}
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
_useDuration -= delta;
|
2023-05-23 00:23:53 -07:00
|
|
|
|
2023-06-03 18:21:46 -07:00
|
|
|
return null;
|
2023-05-23 00:23:53 -07:00
|
|
|
}
|
|
|
|
}
|