public NpcAgent CreateNpc(UUID sceneid, UGUI owner, UGI group, string firstName, string lastName, Vector3 position, Notecard nc, NpcOptions options = NpcOptions.None) { SceneInterface scene; AgentServiceList agentServiceList = m_NonpersistentAgentServices; if ((options & NpcOptions.Persistent) != NpcOptions.None) { if (m_NpcPresenceService == null) { throw new InvalidOperationException("Persistence of NPCs not configured"); } agentServiceList = m_PersistentAgentServices; } NpcPresenceServiceInterface presenceService = agentServiceList.Get <NpcPresenceServiceInterface>(); InventoryServiceInterface inventoryService = agentServiceList.Get <InventoryServiceInterface>(); var npcId = new UGUIWithName { ID = UUID.Random, FirstName = firstName, LastName = lastName }; if (m_KnownScenes.TryGetValue(sceneid, out scene)) { var agent = new NpcAgent(npcId, agentServiceList, sceneid) { NpcOwner = owner, Group = group }; try { m_NpcAgents.Add(agent.ID, agent); var npcInfo = new NpcPresenceInfo { RegionID = sceneid, Npc = agent.NamedOwner, Owner = agent.NpcOwner, Group = agent.Group, }; inventoryService.CheckInventory(npcInfo.Npc.ID); presenceService.Store(npcInfo); agent.CurrentScene = scene; agent.Position = position; scene.Add(agent); } catch { if (m_NpcPresenceService != null) { presenceService.Remove(agent.ID); } inventoryService.Remove(agent.ID); m_NpcAgents.Remove(agent.ID); throw; } agent.EnableListen(); scene.SendAgentObjectToAllAgents(agent); agent.SendAnimations(); ThreadPool.QueueUserWorkItem(LoadAppearanceFromNotecardJob, new RebakeJob { Notecard = nc, Agent = agent }); return(agent); } throw new KeyNotFoundException("Scene not found"); }
private void LoginControl_OnLoginsEnabled(UUID sceneID, bool obj) { SceneInterface scene; bool notrezzedbefore = true; if (m_NpcPresenceService != null && m_KnownScenes.TryGetValue(sceneID, out scene)) { foreach (NpcPresenceInfo npcInfo in m_NpcPresenceService[scene.ID]) { NpcAgent agent; IAgent d; if (!scene.Agents.TryGetValue(npcInfo.Npc.ID, out d)) { if (notrezzedbefore) { m_Log.Info("Rezzing persistent NPCs"); notrezzedbefore = false; } /* only rez if not rezzed before */ m_Log.InfoFormat("Rezzing persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID); try { agent = new NpcAgent(npcInfo.Npc, m_PersistentAgentServices, sceneID) { GlobalPosition = npcInfo.Position, LookAt = npcInfo.LookAt, NpcOwner = npcInfo.Owner, Group = npcInfo.Group, CurrentScene = scene }; m_NpcAgents.Add(npcInfo.Npc.ID, agent); scene.Add(agent); agent.EnableListen(); try { if (npcInfo.SittingOnObjectID != UUID.Zero) { agent.DoSit(npcInfo.SittingOnObjectID); } } catch { m_Log.WarnFormat("Failed to sit persistent NPC {0} {1} ({2}) on object id {3}", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString(), npcInfo.SittingOnObjectID.ToString()); } } catch { m_Log.WarnFormat("Failed to instantiate persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString()); continue; } try { agent.RebakeAppearance(); } catch { m_Log.WarnFormat("Failed to rebake persistent NPC {0} {1} ({2})", npcInfo.Npc.FirstName, npcInfo.Npc.LastName, npcInfo.Npc.ID.ToString()); } } } } }