class UsingCoverPSMPrereqState extends PlayerStateMachinePrereqState
{
	var bValue : Bool;

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

}

class UsingCoverPSMPrereq extends PlayerStateMachinePrereq
{
	default m_skipWhenApplied = true;

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

	protected export const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var castedState : UsingCoverPSMPrereqState;
		var bb : IBlackboard;
		castedState = ( ( UsingCoverPSMPrereqState )( state ) );
		if( castedState )
		{
			bb = GameInstance.GetBlackboardSystem( game ).Get( GetAllBlackboardDefs().PlayerStateMachine );
			if( bb )
			{
				bb.UnregisterListenerBool( GetAllBlackboardDefs().PlayerStateMachine.UsingCover, castedState.m_listenerInt );
			}
		}
	}

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

	protected const override function GetCurrentPSMStateIndex( bb : IBlackboard ) : Int32
	{
		var b : Bool;
		b = bb.GetBool( GetAllBlackboardDefs().PlayerStateMachine.UsingCover );
		if( b )
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

	protected export override function Initialize( recordID : TweakDBID )
	{
		var b : Bool;
		b = TweakDBInterface.GetBool( recordID + T".isInState", true );
		if( b )
		{
			m_valueToListen = 1;
		}
		else
		{
			m_valueToListen = 0;
		}
	}

	public const function Evaluate( owner : GameObject, value : Bool ) : Bool
	{
		var checkPassed : Bool;
		var b : Bool;
		b = ( ( m_valueToListen == 0 ) ? ( false ) : ( true ) );
		checkPassed = value == b;
		return checkPassed;
	}

}

