Пример #1
0
        private void OnSceneRemoved(SceneInterface scene)
        {
            scene.LoginControl.OnLoginsEnabled -= LoginControl_OnLoginsEnabled;
            m_KnownScenes.Remove(scene.ID);
            var removeList = new Dictionary <UUID, NpcAgent>();

            foreach (NpcAgent agent in m_NpcAgents.Values)
            {
                if (agent.CurrentScene == scene)
                {
                    try
                    {
                        agent.DetachAllAttachments();
                    }
                    catch
                    {
                        m_Log.WarnFormat("Failed to detach attachments of NPC {0} {1} ({2})", agent.NamedOwner.FirstName, agent.NamedOwner.LastName, agent.NamedOwner.ID);
                    }
                    removeList.Add(agent.ID, agent);
                }
            }

            foreach (KeyValuePair <UUID, NpcAgent> kvp in removeList)
            {
                /* we have to call the next two removes explicitly. We only want to act upon non-persisted data */
                m_NonpersistentInventoryService.Remove(kvp.Key);
                m_NonpersistentProfileService?.Remove(kvp.Key);
                NpcAgent npc          = kvp.Value;
                IObject  obj          = npc.SittingOnObject;
                var      presenceInfo = new NpcPresenceInfo
                {
                    Npc               = npc.NamedOwner,
                    Owner             = npc.NpcOwner,
                    Position          = npc.Position,
                    LookAt            = npc.LookAt,
                    Group             = npc.Group,
                    RegionID          = npc.SceneID,
                    SittingOnObjectID = obj != null ? obj.ID : UUID.Zero
                };
                kvp.Value.DisableListen();

                if (m_NpcAgents.Remove(kvp.Key))
                {
                    /* we do not distinguish persistent/non-persistent here since NpcAgent has a property for referencing it */
                    npc.NpcPresenceService.Store(presenceInfo);
                }
            }
        }
Пример #2
0
        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");
        }