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