Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
0
        private void RemoveNpcData(NpcAgent npc)
        {
            UUID npcId = npc.ID;

            npc.InventoryService.Remove(npcId);
            try
            {
                npc.ProfileService.Remove(npcId);
            }
            catch
            {
                /* ignore exception here */
            }
            try
            {
                npc.NpcPresenceService.Remove(npcId);
            }
            catch
            {
                /* ignore exception here */
            }
        }
Ejemplo n.º 3
0
        private void CreateNpcCommand(List <string> args, Main.Common.CmdIO.TTY io, UUID limitedToScene)
        {
            UUID ncid;
            UGI  group = UGI.Unknown;

            if (args[0] == "help" || args.Count < 5)
            {
                io.Write("create npc <firstname> <lastname> <notecardid> [params...] - Remove NPC\n" +
                         "    owner <owner>\n" +
                         "    group <group>\n" +
                         "    position <position>\n" +
                         "    notecard <assetid>|(<primname>:<itemname>)\n" +
                         "    persistent\n" +
                         "    senseasagent");
                return;
            }

            UUID sceneId;

            if (limitedToScene != UUID.Zero)
            {
                sceneId = limitedToScene;
            }
            else if (io.SelectedScene == UUID.Zero)
            {
                io.Write("Please select a region first");
                return;
            }
            else
            {
                sceneId = io.SelectedScene;
            }

            var options  = NpcOptions.None;
            var position = new Vector3(128, 128, 23);

            SceneInterface scene;

            if (!m_KnownScenes.TryGetValue(sceneId, out scene))
            {
                io.Write("Scene not found");
                return;
            }

            if (!UUID.TryParse(args[4], out ncid))
            {
                string[]   parts = args[4].Split(new char[] { ':' }, 2);
                ObjectPart part;
                ObjectPartInventoryItem item;
                if (parts.Length >= 2 &&
                    scene.Primitives.TryGetValueByName(parts[0], out part) &&
                    part.Inventory.TryGetValue(parts[1], out item) &&
                    item.InventoryType == InventoryType.Notecard)
                {
                    ncid = item.AssetID;
                }
                else
                {
                    io.Write("Notecard not found by prim / item reference");
                    return;
                }
            }

            UGUI owner = scene.Owner;

            UUID groupid;

            for (int argi = 4; argi < args.Count; ++argi)
            {
                switch (args[argi])
                {
                case "owner":
                    if (!scene.AvatarNameService.TranslateToUUI(args[argi + 1], out owner))
                    {
                        io.WriteFormatted("{0} is not a valid owner.", args[argi + 1]);
                        return;
                    }
                    break;

                case "group":
                    if (scene.GroupsNameService == null)
                    {
                        io.WriteFormatted("Groups not enabled");
                        return;
                    }
                    else if (++argi >= args.Count)
                    {
                        io.WriteFormatted("Missing group id");
                        return;
                    }
                    else if (!UUID.TryParse(args[argi], out groupid))
                    {
                        io.WriteFormatted("Invalid group id {0}", args[argi]);
                        return;
                    }
                    else if (!scene.GroupsNameService.TryGetValue(groupid, out group))
                    {
                        io.WriteFormatted("Invalid group id {0}", groupid);
                        return;
                    }
                    break;

                case "position":
                    if (++argi < args.Count && !Vector3.TryParse(args[argi], out position))
                    {
                        position = new Vector3(128, 128, 23);
                    }
                    break;

                case "persistent":
                    options |= NpcOptions.Persistent;
                    break;

                case "senseasagent":
                    options |= NpcOptions.SenseAsAgent;
                    break;
                }
            }

            AssetData asset;

            if (!scene.AssetService.TryGetValue(ncid, out asset))
            {
                io.Write("Notecard not found");
                return;
            }
            if (asset.Type != AssetType.Notecard)
            {
                io.Write("Not a notecard");
                return;
            }

            Notecard nc;

            try
            {
                nc = new Notecard(asset);
            }
            catch
            {
                io.Write("Not a valid notecard");
                return;
            }

            NpcAgent agent = CreateNpc(sceneId, owner, group, args[2], args[3], position, nc, options);

            io.WriteFormatted("Npc {0} {1} ({2}) created", agent.FirstName, agent.LastName, agent.ID);
        }
Ejemplo n.º 4
0
 public bool TryGetNpc(UUID npcId, out NpcAgent agent)
 {
     return(m_NpcAgents.TryGetValue(npcId, out agent));
 }
Ejemplo n.º 5
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");
        }
Ejemplo n.º 6
0
        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());
                        }
                    }
                }
            }
        }