struct ActivatedDeviceNPCSetup
{
	instanceeditable var npcSpawnerNodeRef : NodeRef;
	var m_npcSpawned : weak< NPCPuppet >;
}

class ActivatedDeviceNPCController extends ScriptableDeviceComponent
{

	public const override function GetPS() : ActivatedDeviceNPCControllerPS
	{
		return ( ( ActivatedDeviceNPCControllerPS )( GetBasePS() ) );
	}

}

class ActivatedDeviceNPCControllerPS extends ActivatedDeviceControllerPS
{
	private instanceeditable persistent var m_activatedDeviceNPCSetup : ActivatedDeviceNPCSetup;

	public function GetSpawnedNPC() : NPCPuppet
	{
		return m_activatedDeviceNPCSetup.m_npcSpawned;
	}

	protected override function GameAttached()
	{
		var globalNodeRef : GlobalNodeRef;
		globalNodeRef = ResolveNodeRefWithEntityID( m_activatedDeviceNPCSetup.npcSpawnerNodeRef, GetOwnerEntityWeak().GetEntityID() );
		if( GlobalNodeRef.IsDefined( globalNodeRef ) )
		{
			GameInstance.GetEntitySpawnerEventsBroadcaster( GetGameInstance() ).RegisterSpawnerEventPSListener( ( ( EntityID )( globalNodeRef ) ), '', GetID(), GetClassName() );
		}
		super.GameAttached();
	}

	public function OnGameEntitySpawnerEvent( evt : gameEntitySpawnerEvent ) : EntityNotificationType
	{
		if( evt.eventType == gameEntitySpawnerEventType.Spawn )
		{
			m_activatedDeviceNPCSetup.m_npcSpawned = ( ( NPCPuppet )( GameInstance.FindEntityByID( GetGameInstance(), evt.spawnedEntityId ) ) );
			return EntityNotificationType.SendThisEventToEntity;
		}
		return EntityNotificationType.DoNotNotifyEntity;
	}

}

