示例#1
0
        private void RemoveNpcCommand(List <string> args, Main.Common.CmdIO.TTY io, UUID limitedToScene)
        {
            UUID npcId;

            if (args[0] == "help" || args.Count < 3 || !UUID.TryParse(args[2], out npcId))
            {
                io.Write("remove npc <uuid> - Remove NPC");
                return;
            }

            UUID selectedScene = io.SelectedScene;

            if (limitedToScene != UUID.Zero)
            {
                selectedScene = limitedToScene;
            }

            SceneInterface scene;

            if (!m_KnownScenes.TryGetValue(selectedScene, out scene))
            {
                scene = null;
            }

            NpcAgent npc;

            if (!m_NpcAgents.TryGetValue(npcId, out npc))
            {
                io.Write("Npc does not exist");
            }
            else if (scene != null && npc.CurrentScene != scene)
            {
                io.Write("Npc is not in the region");
            }
            else if (!m_NpcAgents.Remove(npcId, out npc))
            {
                io.Write("Npc does not exist");
            }
            else
            {
                npc.CurrentScene.Remove(npc);
                RemoveNpcData(npc);
                io.Write("Npc removed");
            }
        }
示例#2
0
        private void ShowNpcsCommand(List <string> args, Main.Common.CmdIO.TTY io, UUID limitedToScene)
        {
            if (args[0] == "help")
            {
                io.Write("show npcs - Shows all NPCs in region");
                return;
            }
            UUID selectedScene = io.SelectedScene;

            if (limitedToScene != UUID.Zero)
            {
                selectedScene = limitedToScene;
            }

            SceneInterface scene;

            if (!m_KnownScenes.TryGetValue(selectedScene, out scene))
            {
                io.Write("No region selected");
            }
            else
            {
                var sb = new StringBuilder("NPCs:\n----------------------------------------------\n");
                foreach (NpcAgent agent in m_NpcAgents.Values)
                {
                    if (agent.CurrentScene != scene)
                    {
                        continue;
                    }
                    UGUIWithName npcOwner = m_AdminWebIF.ResolveName(agent.NpcOwner);
                    sb.AppendFormat("Npc {0} {1} ({2})\n- Owner: {3}\n", agent.NamedOwner.FirstName, agent.NamedOwner.LastName, agent.NamedOwner.ID.ToString(), npcOwner.FullName);
                    if (m_NpcPresenceService != null && m_NpcPresenceService[agent.Owner.ID].Count != 0)
                    {
                        sb.AppendFormat("- Persistent NPC\n");
                    }
                }
                io.Write(sb.ToString());
            }
        }
示例#3
0
        private void RemoveAllNpcsCommand(List <string> args, Main.Common.CmdIO.TTY io, UUID limitedToScene)
        {
            if (args[0] == "help" || args.Count < 3)
            {
                io.Write("remove all npcs - Remove all NPCs\n" +
                         "remove all npcs persistentonly - Remove all persistent npcs\n" +
                         "remove all npcs nonpersistentonly - Remove all non-persistent npcs");
                return;
            }

            bool persistentonly    = (args.Count > 3 && args[3] == "persistentonly");
            bool nonpersistentonly = (args.Count > 3 && args[3] == "nonpersistentonly");

            UUID selectedScene = io.SelectedScene;

            if (limitedToScene != UUID.Zero)
            {
                selectedScene = limitedToScene;
            }

            SceneInterface scene;

            if (!m_KnownScenes.TryGetValue(selectedScene, out scene))
            {
                scene = null;
            }

            if (scene == null)
            {
                io.Write("No scene selected");
                return;
            }

            NpcAgent npc;
            var      npcs = new List <UUID>();

            foreach (IAgent agent in scene.Agents)
            {
                if (agent.IsNpc)
                {
                    npcs.Add(agent.ID);
                }
            }

            var formattedListBuilder = new FormattedListBuilder();

            formattedListBuilder.AddColumn("NPC", 40);
            formattedListBuilder.AddColumn("Status", 20);
            formattedListBuilder.AddHeader();
            formattedListBuilder.AddSeparator();
            foreach (UUID id in npcs)
            {
                if (!m_NpcAgents.TryGetValue(id, out npc))
                {
                    formattedListBuilder.AddData(id, "Not found");
                }
                else if (scene != null && npc.CurrentScene != scene)
                {
                    formattedListBuilder.AddData(id, "Not in region");
                }
                else if (!m_NpcAgents.Remove(id, out npc))
                {
                    formattedListBuilder.AddData(id, "Skipped");
                }
                else if ((persistentonly && npc.NpcPresenceService != m_NpcPresenceService) ||
                         (nonpersistentonly && npc.NpcPresenceService == m_NpcPresenceService))
                {
                    /* skip non-persistent */
                }
                else
                {
                    try
                    {
                        npc.CurrentScene.Remove(npc);
                        RemoveNpcData(npc);
                        formattedListBuilder.AddData(id, "Removed");
                    }
                    catch
                    {
                        formattedListBuilder.AddData(id, "Failed to remove");
                    }
                }
            }
            io.Write(formattedListBuilder.ToString());
        }
示例#4
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);
        }