class HighLevelNPCStatePrereqState extends NPCStatePrereqState
{
}

class HighLevelNPCStatePrereq extends NPCStatePrereq
{
	var m_valueToListen : gamedataNPCHighLevelState;

	protected export const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var castedState : HighLevelNPCStatePrereqState;
		bb = ( ( ScriptedPuppet )( context ) ).GetPuppetStateBlackboard();
		castedState = ( ( HighLevelNPCStatePrereqState )( state ) );
		castedState.m_owner = ( ( GameObject )( context ) );
		castedState.m_prevValue = bb.GetInt( GetAllBlackboardDefs().PuppetState.HighLevel );
		castedState.m_listenerInt = bb.RegisterListenerInt( GetAllBlackboardDefs().PuppetState.HighLevel, castedState, 'OnStateUpdate' );
		return false;
	}

	protected export const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var castedState : HighLevelNPCStatePrereqState;
		castedState = ( ( HighLevelNPCStatePrereqState )( state ) );
		( ( ScriptedPuppet )( context ) ).GetPuppetStateBlackboard().UnregisterListenerInt( GetAllBlackboardDefs().PuppetState.HighLevel, castedState.m_listenerInt );
	}

	public export const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var owner : ScriptedPuppet;
		var bb : IBlackboard;
		var currentState : Int32;
		owner = ( ( ScriptedPuppet )( context ) );
		bb = owner.GetPuppetStateBlackboard();
		currentState = bb.GetInt( GetAllBlackboardDefs().PuppetState.HighLevel );
		return Evaluate( owner, currentState, currentState );
	}

	protected export override function Initialize( recordID : TweakDBID )
	{
		super.Initialize( recordID );
		m_valueToListen = ( ( gamedataNPCHighLevelState )( ( ( Int32 )( EnumValueFromString( "gamedataNPCHighLevelState", GetStateName( recordID ) ) ) ) ) );
	}

	protected const override function GetStateToCheck() : Int32
	{
		return ( ( Int32 )( m_valueToListen ) );
	}

}

class CurrentHighLevelNPCStatePrereq extends IScriptablePrereq
{
	var m_valueToCheck : gamedataNPCHighLevelState;
	var m_invert : Bool;

	protected export override function Initialize( record : TweakDBID )
	{
		var stateName : String;
		stateName = TweakDBInterface.GetString( record + T".stateName", "" );
		m_valueToCheck = ( ( gamedataNPCHighLevelState )( ( ( Int32 )( EnumValueFromString( "gamedataNPCHighLevelState", stateName ) ) ) ) );
		m_invert = TweakDBInterface.GetBool( record + T".invert", false );
	}

	protected const override function OnApplied( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		state.OnChanged( IsFulfilled( game, context ) );
	}

	public export const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var bb : IBlackboard;
		var puppet : weak< ScriptedPuppet >;
		var currentPuppetState : gamedataNPCHighLevelState;
		puppet = ( ( ScriptedPuppet )( context ) );
		if( !( puppet ) )
		{
			return false;
		}
		bb = puppet.GetPuppetStateBlackboard();
		currentPuppetState = ( ( gamedataNPCHighLevelState )( ( ( Int32 )( bb.GetInt( GetAllBlackboardDefs().PuppetState.HighLevel ) ) ) ) );
		if( currentPuppetState != m_valueToCheck )
		{
			return ( ( m_invert ) ? ( true ) : ( false ) );
		}
		return ( ( m_invert ) ? ( false ) : ( true ) );
	}

}

