private static void AddAndWaitUntilAgentIsAdded(IScene scene, BotClientAPI m_character) { bool done = false; scene.AddNewClient(m_character, delegate { done = true; }); while (!done) { Thread.Sleep(3); } }
/// <summary> /// Creates a new bot inworld /// </summary> /// <param name = "FirstName"></param> /// <param name = "LastName"></param> /// <param name = "cloneAppearanceFrom">UUID of the avatar whos appearance will be copied to give this bot an appearance</param> /// <returns>ID of the bot</returns> public UUID CreateAvatar(string FirstName, string LastName, IScene scene, UUID cloneAppearanceFrom, UUID creatorID, Vector3 startPos) { AgentCircuitData m_aCircuitData = new AgentCircuitData { child = false, circuitcode = (uint) Util.RandomClass.Next(), Appearance = GetAppearance(cloneAppearanceFrom, scene) }; //Add the circuit data so they can login //Sets up appearance if (m_aCircuitData.Appearance == null) { m_aCircuitData.Appearance = new AvatarAppearance {Wearables = AvatarWearable.DefaultWearables}; } //Create the new bot data BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData) { FirstName = FirstName, LastName = LastName }; m_aCircuitData.AgentID = m_character.AgentId; m_aCircuitData.Appearance.Owner = m_character.AgentId; List<AvatarAttachment> attachments = m_aCircuitData.Appearance.GetAttachments(); m_aCircuitData.Appearance.ClearAttachments(); foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(new InventoryItemBase(t.ItemID)); if (item != null) { item.ID = UUID.Random(); item.Owner = m_character.AgentId; item.Folder = UUID.Zero; scene.InventoryService.AddItemAsync(item, null); //Now fix the ItemID m_aCircuitData.Appearance.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData); //This adds them to the scene and sets them inworld AddAndWaitUntilAgentIsAdded(scene, m_character); IScenePresence SP = scene.GetScenePresence(m_character.AgentId); if (SP == null) return UUID.Zero; //Failed! Bot bot = new Bot(); bot.Initialize(SP, creatorID); SP.MakeRootAgent(startPos, false, true); //Move them SP.Teleport(startPos); foreach(var presence in scene.GetScenePresences()) presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate); IAttachmentsModule attModule = SP.Scene.RequestModuleInterface<IAttachmentsModule>(); if (attModule != null) foreach (AvatarAttachment att in attachments) attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true); IAvatarAppearanceModule appearance = SP.RequestModuleInterface<IAvatarAppearanceModule>(); appearance.InitialHasWearablesBeenSent = true; //Save them in the bots list m_bots.Add(m_character.AgentId, bot); AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID); MainConsole.Instance.Info("[RexBotManager]: Added bot " + m_character.Name + " to scene."); //Return their UUID return m_character.AgentId; }
private static void AddAndWaitUntilAgentIsAdded(IScene scene, BotClientAPI m_character) { bool done = false; scene.AddNewClient(m_character, delegate { done = true; }); while (!done) Thread.Sleep(3); }
/// <summary> /// Creates a new bot inworld /// </summary> /// <param name = "FirstName"></param> /// <param name = "LastName"></param> /// <param name = "cloneAppearanceFrom">UUID of the avatar whos appearance will be copied to give this bot an appearance</param> /// <returns>ID of the bot</returns> public UUID CreateAvatar(string FirstName, string LastName, IScene scene, UUID cloneAppearanceFrom, UUID creatorID, Vector3 startPos) { AgentCircuitData m_aCircuitData = new AgentCircuitData { child = false, circuitcode = (uint)Util.RandomClass.Next(), Appearance = GetAppearance(cloneAppearanceFrom, scene) }; //Add the circuit data so they can login //Sets up appearance if (m_aCircuitData.Appearance == null) { m_aCircuitData.Appearance = new AvatarAppearance { Wearables = AvatarWearable.DefaultWearables }; } //Create the new bot data BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData) { FirstName = FirstName, LastName = LastName }; m_aCircuitData.AgentID = m_character.AgentId; m_aCircuitData.Appearance.Owner = m_character.AgentId; List <AvatarAttachment> attachments = m_aCircuitData.Appearance.GetAttachments(); m_aCircuitData.Appearance.ClearAttachments(); foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(new InventoryItemBase(t.ItemID)); if (item != null) { item.ID = UUID.Random(); item.Owner = m_character.AgentId; item.Folder = UUID.Zero; scene.InventoryService.AddItemAsync(item, null); //Now fix the ItemID m_aCircuitData.Appearance.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData); //This adds them to the scene and sets them inworld AddAndWaitUntilAgentIsAdded(scene, m_character); IScenePresence SP = scene.GetScenePresence(m_character.AgentId); if (SP == null) { return(UUID.Zero); //Failed! } Bot bot = new Bot(); bot.Initialize(SP, creatorID); SP.MakeRootAgent(startPos, false, true); //Move them SP.Teleport(startPos); foreach (var presence in scene.GetScenePresences()) { presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate); } IAttachmentsModule attModule = SP.Scene.RequestModuleInterface <IAttachmentsModule>(); if (attModule != null) { foreach (AvatarAttachment att in attachments) { attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true); } } IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>(); appearance.InitialHasWearablesBeenSent = true; //Save them in the bots list m_bots.Add(m_character.AgentId, bot); AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID); MainConsole.Instance.Info("[RexBotManager]: Added bot " + m_character.Name + " to scene."); //Return their UUID return(m_character.AgentId); }
public UUID CreateAvatar(string firstName, string lastName, IScene scene, AvatarAppearance avatarApp, UUID creatorID, Vector3 startPos) { //Add the circuit data so they can login AgentCircuitData m_aCircuitData = new AgentCircuitData { IsChildAgent = false, CircuitCode = (uint)Util.RandomClass.Next() }; //Create the new bot data BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData); m_character.Name = firstName + " " + lastName; m_aCircuitData.AgentID = m_character.AgentId; //Set up appearance var origOwner = avatarApp.Owner; avatarApp.Owner = m_character.AgentId; List <AvatarAttachment> attachments = avatarApp.GetAttachments(); avatarApp.ClearAttachments(); // get original attachments foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID); if (item != null) { item.ID = UUID.Random(); item.Owner = m_character.AgentId; item.Folder = UUID.Zero; scene.InventoryService.AddCacheItemAsync(item); //Now fix the ItemID avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData); //This adds them to the scene and sets them in world AddAndWaitUntilAgentIsAdded(scene, m_character); IScenePresence SP = scene.GetScenePresence(m_character.AgentId); if (SP == null) { return(UUID.Zero); //Failed! } // set this as a NPC character SP.IsNpcAgent = true; IAvatarAppearanceModule appearance = SP.RequestModuleInterface <IAvatarAppearanceModule>(); appearance.Appearance = avatarApp; appearance.InitialHasWearablesBeenSent = true; Bot bot = new Bot(); bot.Initialize(SP, creatorID); try { SP.MakeRootAgent(startPos, false, true); } catch { MainConsole.Instance.ErrorFormat("[BotManager]: Error creating bot {0} as root agent!", m_character.AgentId); } //Move them SP.Teleport(startPos); foreach (var presence in scene.GetScenePresences()) { presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate); } IAttachmentsModule attModule = SP.Scene.RequestModuleInterface <IAttachmentsModule>(); if (attModule != null) { foreach (AvatarAttachment att in attachments) { attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true); } } //Save them in the bots list m_bots.Add(m_character.AgentId, bot); AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID); MainConsole.Instance.InfoFormat("[BotManager]: Added bot {0} to region {1}", m_character.Name, scene.RegionInfo.RegionName); //Return their UUID return(m_character.AgentId); }
public UUID CreateAvatar(string firstName, string lastName, IScene scene, AvatarAppearance avatarApp, UUID creatorID, Vector3 startPos) { //Add the circuit data so they can login AgentCircuitData m_aCircuitData = new AgentCircuitData { IsChildAgent = false, CircuitCode = (uint) Util.RandomClass.Next() }; //Create the new bot data BotClientAPI m_character = new BotClientAPI(scene, m_aCircuitData); m_character.Name = firstName + " " + lastName; m_aCircuitData.AgentID = m_character.AgentId; //Set up appearance var origOwner = avatarApp.Owner; avatarApp.Owner = m_character.AgentId; List<AvatarAttachment> attachments = avatarApp.GetAttachments(); avatarApp.ClearAttachments(); // get original attachments foreach (AvatarAttachment t in attachments) { InventoryItemBase item = scene.InventoryService.GetItem(origOwner, t.ItemID); if (item != null) { item.ID = UUID.Random(); item.Owner = m_character.AgentId; item.Folder = UUID.Zero; scene.InventoryService.AddCacheItemAsync(item); //Now fix the ItemID avatarApp.SetAttachment(t.AttachPoint, item.ID, t.AssetID); } } scene.AuthenticateHandler.AgentCircuits.Add(m_character.CircuitCode, m_aCircuitData); //This adds them to the scene and sets them in world AddAndWaitUntilAgentIsAdded(scene, m_character); IScenePresence SP = scene.GetScenePresence(m_character.AgentId); if (SP == null) return UUID.Zero; //Failed! IAvatarAppearanceModule appearance = SP.RequestModuleInterface<IAvatarAppearanceModule>(); appearance.Appearance = avatarApp; appearance.InitialHasWearablesBeenSent = true; Bot bot = new Bot(); bot.Initialize(SP, creatorID); SP.MakeRootAgent(startPos, false, true); //Move them SP.Teleport(startPos); foreach (var presence in scene.GetScenePresences()) presence.SceneViewer.QueuePresenceForUpdate(SP, PrimUpdateFlags.ForcedFullUpdate); IAttachmentsModule attModule = SP.Scene.RequestModuleInterface<IAttachmentsModule>(); if (attModule != null) foreach (AvatarAttachment att in attachments) attModule.RezSingleAttachmentFromInventory(SP.ControllingClient, att.ItemID, att.AssetID, 0, true); //Save them in the bots list m_bots.Add(m_character.AgentId, bot); AddTagToBot(m_character.AgentId, "AllBots", bot.AvatarCreatorID); MainConsole.Instance.InfoFormat("[BotManager]: Added bot {0} to region {1}", m_character.Name, scene.RegionInfo.RegionName); //Return their UUID return m_character.AgentId; }