SupaLidlGame/State/Weapon/SwordBlockState.cs

93 lines
1.9 KiB
C#
Raw Normal View History

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; }
[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;
private float _oldBlockForce;
2023-08-08 00:54:00 -07:00
public override WeaponState Enter(IState<WeaponState> prevState)
{
Sword.EnableParry(ulong.MaxValue);
_oldBlockForce = Sword.BlockForce;
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)
{
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;
}
}