NPCs/Implementation/Crackhead/AttackStunState.cs
namespace Opium.AI;
[Title( "Attack Stun" ), Description( "The attack state." )]
public partial class AttackStunState : StateMachine.State
{
/// <summary>
/// Should we be forcing into this state? Not super happy with this but it's event based.
/// </summary>
private bool forceStun = false;
bool isBlockStun = false;
public override FullBodyState? GetFullBodyState()
{
return isBlockStun ? FullBodyState.BlockStun : FullBodyState.AttackStun;
}
public override void OnStateEnter( StateMachine.State prev )
{
forceStun = false;
Agent.GetMechanic<AttackStunMechanic>()?.Activate();
// Hack
if ( Agent.Weapon is MeleeWeapon melee && melee.IsValid() && (melee.CurrentAttack?.IsActive ?? false) )
{
melee.CurrentAttack.State = AttackState.Inactive;
}
}
public override void OnEvent( string eventName, params object[] obj )
{
if ( eventName == "block_react" )
{
forceStun = true;
isBlockStun = true;
}
if ( eventName == "damage" )
{
forceStun = true;
isBlockStun = false;
}
}
public override void OnStateExit( StateMachine.State next )
{
Agent.GetMechanic<AttackStunMechanic>()?.Deactivate();
}
public override bool ShouldEnterState( StateMachine machine )
{
return forceStun;
}
}