Weapons/MeleeStateController.cs
namespace Opium;
/// <summary>
/// A controller for a weapon attack. This is shit and should be deleted.
/// </summary>
public partial class MeleeStateController : Component
{
public MeleeWeapon Weapon => Components.Get<MeleeWeapon>( FindMode.EverythingInSelfAndParent );
public float WindupReturnTime => 0.45f;
public bool WantsHeavyAttack = false;
public virtual void Update( MeleeWeaponAttack attack )
{
var state = attack.State;
if ( state == AttackState.Hit && Input.Down( "Attack1" ) )
{
attack.State = AttackState.Windup;
}
if ( state == AttackState.ReadyToAttack && ( !Input.Down( "Attack1" ) || ( Weapon.Actor.GetMechanic<StaminaMechanic>()?.Stamina <= 0 ) ) )
{
attack.State = WantsHeavyAttack ? AttackState.SwingingHeavyAttack : AttackState.Swinging;
attack.OnAttackReleased();
}
// Deciding on heavy attack vs light attack
if ( state == AttackState.Windup && !Input.Down( "Attack1" ) )
{
WantsHeavyAttack = false;
}
else
{
WantsHeavyAttack = true;
}
}
internal void OnStateChanged( AttackState before, AttackState after )
{
if ( after == AttackState.Inactive )
{
Weapon.TimeSinceShoot = 0;
}
}
}