class NPCAttitudeTowardsPlayerPrereqState extends PrereqState
{
	var attitudeListener : gameScriptedPrereqAttitudeListenerWrapper;

	protected export function OnAttitudeStateChanged()
	{
		var prereq : NPCAttitudeTowardsPlayerPrereq;
		prereq = ( ( NPCAttitudeTowardsPlayerPrereq )( GetPrereq() ) );
		OnChanged( prereq.IsFulfilled( GetGameInstance(), GetContext() ) );
	}

}

class NPCAttitudeTowardsPlayerPrereq extends IScriptablePrereq
{
	var m_attitude : EAIAttitude;

	protected export override function Initialize( recordID : TweakDBID )
	{
		var str : String;
		str = TweakDBInterface.GetString( recordID + T".attitude", "" );
		m_attitude = ( ( EAIAttitude )( ( ( Int32 )( EnumValueFromString( "EAIAttitude", str ) ) ) ) );
	}

	public export const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var npc : NPCPuppet;
		var player : PlayerPuppet;
		var attitude : EAIAttitude;
		npc = ( ( NPCPuppet )( context ) );
		player = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( game ).GetLocalPlayerMainGameObject() ) );
		attitude = GameObject.GetAttitudeTowards( npc, player );
		if( attitude == m_attitude )
		{
			return true;
		}
		return false;
	}

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

	protected export const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var castedState : NPCAttitudeTowardsPlayerPrereqState;
		var player : PlayerPuppet;
		var puppet : NPCPuppet;
		puppet = ( ( NPCPuppet )( context ) );
		player = ( ( PlayerPuppet )( GameInstance.GetPlayerSystem( game ).GetLocalPlayerMainGameObject() ) );
		castedState = ( ( NPCAttitudeTowardsPlayerPrereqState )( state ) );
		if( puppet && player )
		{
			castedState.attitudeListener = gameScriptedPrereqAttitudeListenerWrapper.CreateListener( game, puppet.GetAttitudeAgent(), player.GetAttitudeAgent(), castedState );
			return false;
		}
		return false;
	}

	protected export const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var castedState : NPCAttitudeTowardsPlayerPrereqState;
		castedState = ( ( NPCAttitudeTowardsPlayerPrereqState )( state ) );
		castedState.attitudeListener = NULL;
	}

}

