class NPCHitSourcePrereqState extends PrereqState
{
	var m_listener : PuppetListener;
}

class NPCHitSourcePrereq extends IScriptablePrereq
{
	var m_hitSource : EAIHitSource;
	var m_invert : Bool;

	protected export override function Initialize( recordID : TweakDBID )
	{
		var str : String;
		str = TweakDBInterface.GetString( recordID + T".hitSource", "" );
		m_hitSource = ( ( EAIHitSource )( ( ( Int32 )( EnumValueFromString( "EAIHitSource", str ) ) ) ) );
		m_invert = TweakDBInterface.GetBool( recordID + T".invert", false );
	}

	protected export const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var puppet : ScriptedPuppet;
		var castedState : NPCHitSourcePrereqState;
		puppet = ( ( ScriptedPuppet )( context ) );
		if( puppet )
		{
			castedState = ( ( NPCHitSourcePrereqState )( state ) );
			castedState.m_listener = new PuppetListener;
			castedState.m_listener.RegisterOwner( castedState );
			ScriptedPuppet.AddListener( puppet, castedState.m_listener );
			return false;
		}
		return false;
	}

	protected export const override function OnUnregister( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var puppet : ScriptedPuppet;
		var castedState : NPCHitSourcePrereqState;
		puppet = ( ( ScriptedPuppet )( context ) );
		castedState = ( ( NPCHitSourcePrereqState )( state ) );
		if( puppet && castedState.m_listener )
		{
			ScriptedPuppet.RemoveListener( puppet, castedState.m_listener );
		}
		castedState.m_listener = NULL;
	}

	public export const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var owner : GameObject;
		var targetPuppet : ScriptedPuppet;
		var hitReactionComponent : HitReactionComponent;
		owner = ( ( GameObject )( context ) );
		targetPuppet = ( ( ScriptedPuppet )( owner ) );
		hitReactionComponent = targetPuppet.GetHitReactionComponent();
		if( !( targetPuppet ) )
		{
			return false;
		}
		return EvaluateCondition( hitReactionComponent.GetHitReactionData().hitSource );
	}

	public const function EvaluateCondition( hitSource : Int32 ) : Bool
	{
		if( hitSource != ( ( Int32 )( m_hitSource ) ) )
		{
			return ( ( m_invert ) ? ( true ) : ( false ) );
		}
		return ( ( m_invert ) ? ( false ) : ( true ) );
	}

}

