class IsPlayerMovingPrereqState extends PrereqState
{
	var m_owner : weak< GameObject >;
	var m_isMovingVertically : Bool;
	var m_listenerVertical : CallbackHandle;
	var m_isMovingHorizontally : Bool;
	var m_listenerHorizontal : CallbackHandle;

	protected event OnVerticalUpdate( isMovingVertically : Bool )
	{
		var checkPassed : Bool;
		const var prereq : IsPlayerMovingPrereq;
		prereq = ( ( IsPlayerMovingPrereq )( GetPrereq() ) );
		if( m_isMovingVertically != isMovingVertically )
		{
			checkPassed = prereq.Evaluate( m_owner, isMovingVertically || m_isMovingHorizontally );
			OnChanged( checkPassed );
		}
		m_isMovingVertically = isMovingVertically;
	}

	protected event OnHorizontalUpdate( isMovingHorizontally : Bool )
	{
		var checkPassed : Bool;
		const var prereq : IsPlayerMovingPrereq;
		prereq = ( ( IsPlayerMovingPrereq )( GetPrereq() ) );
		if( m_isMovingHorizontally != isMovingHorizontally )
		{
			checkPassed = prereq.Evaluate( m_owner, isMovingHorizontally || m_isMovingVertically );
			OnChanged( checkPassed );
		}
		m_isMovingHorizontally = isMovingHorizontally;
	}

}

class IsPlayerMovingPrereq extends PlayerStateMachinePrereq
{
	default m_skipWhenApplied = true;

	protected const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var castedState : IsPlayerMovingPrereqState;
		bb = GameInstance.GetBlackboardSystem( game ).GetLocalInstanced( ( ( ScriptedPuppet )( context ) ).GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		castedState = ( ( IsPlayerMovingPrereqState )( state ) );
		castedState.m_owner = ( ( GameObject )( context ) );
		castedState.m_listenerHorizontal = bb.RegisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingHorizontally, castedState, 'OnHorizontalUpdate' );
		castedState.m_listenerVertical = bb.RegisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingVertically, castedState, 'OnVerticalUpdate' );
		return false;
	}

	protected const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var bb : IBlackboard;
		var castedState : IsPlayerMovingPrereqState;
		castedState = ( ( IsPlayerMovingPrereqState )( state ) );
		bb = GameInstance.GetBlackboardSystem( game ).GetLocalInstanced( ( ( ScriptedPuppet )( context ) ).GetEntityID(), GetAllBlackboardDefs().PlayerStateMachine );
		bb.UnregisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingHorizontally, castedState.m_listenerHorizontal );
		bb.UnregisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingVertically, castedState.m_listenerVertical );
	}

	protected const override function GetStateMachineEnum() : String
	{
		return "";
	}

	protected const override function GetCurrentPSMStateIndex( bb : IBlackboard ) : Int32
	{
		if( bb.GetBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingHorizontally ) || bb.GetBool( GetAllBlackboardDefs().PlayerStateMachine.IsMovingVertically ) )
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

	protected override function Initialize( recordID : TweakDBID )
	{
		super.Initialize( recordID );
		m_valueToListen = ( ( TweakDBInterface.GetBool( recordID + T".isMoving", true ) ) ? ( 1 ) : ( 0 ) );
	}

	public const function Evaluate( owner : GameObject, value : Bool ) : Bool
	{
		if( m_valueToListen == 0 )
		{
			return value == false;
		}
		else if( m_valueToListen == 1 )
		{
			return value == true;
		}
		else
		{
			return false;
		}
	}

}

