class IsPlayerOnGroundPrereqState extends PrereqState
{
	var m_bbValue : Bool;
	var m_isOnGroundListener : CallbackHandle;
	var m_owner : weak< GameObject >;

	protected event OnStateUpdateBool( value : Bool )
	{
		var checkPassed : Bool;
		const var prereq : IsPlayerOnGroundPrereq;
		prereq = ( ( IsPlayerOnGroundPrereq )( GetPrereq() ) );
		if( m_bbValue != value )
		{
			checkPassed = prereq.Evaluate( m_owner, value );
			OnChanged( checkPassed );
		}
		m_bbValue = value;
	}

}

class IsPlayerOnGroundPrereq extends IScriptablePrereq
{
	var m_invert : Bool;

	protected export override function Initialize( recordID : TweakDBID )
	{
		m_invert = TweakDBInterface.GetBool( recordID + T".invert", false );
	}

	protected const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var castedState : IsPlayerOnGroundPrereqState;
		bb = GameInstance.GetBlackboardSystem( game ).GetLocalInstanced( ( ( ScriptedPuppet )( context ) ).GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		castedState = ( ( IsPlayerOnGroundPrereqState )( state ) );
		castedState.m_owner = ( ( GameObject )( context ) );
		castedState.m_isOnGroundListener = bb.RegisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsOnGround, castedState, 'OnStateUpdateBool' );
		return false;
	}

	protected const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var bb : IBlackboard;
		var castedState : IsPlayerOnGroundPrereqState;
		castedState = ( ( IsPlayerOnGroundPrereqState )( state ) );
		bb = GameInstance.GetBlackboardSystem( game ).GetLocalInstanced( ( ( ScriptedPuppet )( context ) ).GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		bb.UnregisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsOnGround, castedState.m_isOnGroundListener );
	}

	public const function Evaluate( owner : GameObject, value : Bool ) : Bool
	{
		return m_invert ^ value;
	}

}

