class IsPuppetActivePrereqState extends PrereqState
{
	var psListener : gameScriptedPrereqPSChangeListenerWrapper;

	protected function OnPSStateChanged()
	{
		var prereq : IsPuppetActivePrereq;
		prereq = ( ( IsPuppetActivePrereq )( GetPrereq() ) );
		OnChanged( prereq.IsFulfilled( GetGameInstance(), GetContext() ) );
	}

}

class IsPuppetActivePrereq extends IScriptablePrereq
{
	var m_invert : Bool;

	protected export override function Initialize( recordID : TweakDBID )
	{
		m_invert = TweakDBInterface.GetBool( recordID + T".invert", false );
	}

	protected const override function OnApplied( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		var owner : weak< GameObject >;
		var castedState : CharacterDataPrereqState;
		owner = ( ( ScriptedPuppet )( context ) );
		if( owner )
		{
			castedState.OnChanged( IsFulfilled( game, context ) );
		}
	}

	protected const override function OnRegister( state : PrereqState, game : GameInstance, context : IScriptable ) : Bool
	{
		var castedState : IsPuppetActivePrereqState;
		var puppet : ScriptedPuppet;
		var persistentId : PersistentID;
		puppet = ( ( ScriptedPuppet )( context ) );
		castedState = ( ( IsPuppetActivePrereqState )( state ) );
		if( puppet )
		{
			persistentId = CreatePersistentID( puppet.GetEntityID(), puppet.GetPSClassName() );
			castedState.psListener = gameScriptedPrereqPSChangeListenerWrapper.CreateListener( game, persistentId, castedState );
			return false;
		}
		return false;
	}

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

	public const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var targetPuppet : ScriptedPuppet;
		var result : Bool;
		targetPuppet = ( ( ScriptedPuppet )( context ) );
		result = targetPuppet.IsActive();
		if( m_invert )
		{
			return !( result );
		}
		return result;
	}

}

