2023-08-08 00:54:00 -07:00
|
|
|
using Godot;
|
|
|
|
using SupaLidlGame.Extensions;
|
|
|
|
|
|
|
|
namespace SupaLidlGame.State.Weapon;
|
|
|
|
|
|
|
|
public partial class SwordBlockState : WeaponState
|
|
|
|
{
|
|
|
|
[Export]
|
|
|
|
public SupaLidlGame.Items.Weapons.Sword Sword { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public SwordIdleState IdleState { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public WeaponState UseState { get; set; }
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public string BlockAnimKey { get; set; }
|
|
|
|
|
2024-03-30 01:59:45 -07:00
|
|
|
[Export]
|
|
|
|
public float BlockForceMultiplier { get; set; } = 4;
|
|
|
|
|
2023-08-08 00:54:00 -07:00
|
|
|
public bool HasBlocked { get; set; }
|
|
|
|
|
|
|
|
private double _attackDuration = 0;
|
|
|
|
|
|
|
|
private double _useDuration = 0;
|
|
|
|
|
|
|
|
private bool _isAlternate = false;
|
|
|
|
|
2024-03-29 16:17:19 -07:00
|
|
|
private float _oldBlockForce;
|
|
|
|
|
2023-08-08 00:54:00 -07:00
|
|
|
public override WeaponState Enter(IState<WeaponState> prevState)
|
|
|
|
{
|
|
|
|
Sword.EnableParry(ulong.MaxValue);
|
2024-03-29 16:17:19 -07:00
|
|
|
_oldBlockForce = Sword.BlockForce;
|
2024-03-30 01:59:45 -07:00
|
|
|
Sword.BlockForce *= BlockForceMultiplier;
|
2023-08-08 00:54:00 -07:00
|
|
|
|
|
|
|
_useDuration = Sword.UseAltTime;
|
|
|
|
_attackDuration = Sword.AttackAltTime;
|
|
|
|
|
|
|
|
Sword.UseDirection = Sword.Character.Target;
|
|
|
|
|
|
|
|
Sword.AnimationPlayer.TryPlay(BlockAnimKey);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WeaponState Use()
|
|
|
|
{
|
|
|
|
if (_attackDuration <= 0 && HasBlocked)
|
|
|
|
{
|
|
|
|
return UseState;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Deattack()
|
|
|
|
{
|
|
|
|
Sword.DisableParry();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Exit(IState<WeaponState> nextState)
|
|
|
|
{
|
2024-03-29 16:17:19 -07:00
|
|
|
if (nextState == IdleState)
|
|
|
|
{
|
|
|
|
Sword.AnimationPlayer.Play("RESET");
|
|
|
|
}
|
|
|
|
|
|
|
|
Sword.BlockForce = _oldBlockForce;
|
2023-08-08 00:54:00 -07:00
|
|
|
Deattack();
|
|
|
|
HasBlocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WeaponState Process(double delta)
|
|
|
|
{
|
|
|
|
if (_attackDuration > 0)
|
|
|
|
{
|
|
|
|
if ((_attackDuration -= delta) <= 0)
|
|
|
|
{
|
|
|
|
Deattack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((_useDuration -= delta) <= 0)
|
|
|
|
{
|
|
|
|
return IdleState;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|