当前位置: 首页>>代码示例>>C#>>正文


C# ArgumentList.TryGetInt方法代码示例

本文整理汇总了C#中ArgumentList.TryGetInt方法的典型用法代码示例。如果您正苦于以下问题:C# ArgumentList.TryGetInt方法的具体用法?C# ArgumentList.TryGetInt怎么用?C# ArgumentList.TryGetInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArgumentList的用法示例。


在下文中一共展示了ArgumentList.TryGetInt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MaxPlayersCommand

        internal static void MaxPlayersCommand(ISender sender, ArgumentList args)
        {
            if (MaxPlayersDisabled)
            {
                sender.Message (255, "This command has been disabled.");
                return;
            }

            int maxp = -1;
            int overl = -1;

            if (args.TryGetInt (0, out maxp) && (maxp < 1 || maxp > MAX_SLOTS))
            {
                sender.Message (255, "Max numbers of players must be in range 1 .. {0}", MAX_SLOTS);
                return;
            }

            if (args.Count > 1)
            {
                overl = args.GetInt (1);
                if (overl < 0 || overl > maxp)
                {
                    sender.Message (255, "Number of overlimit slots must be in range 0 .. <max player count>");
                    return;
                }
            }

            int oldmax = maxSlots;
            int oldover = overlimitSlots;

            int result = maxSlots;
            if (maxp >= 0 || overl >= 0)
            {
                result = ChangeLimits (maxp < 0 ? maxSlots : maxp, overl < 0 ? overlimitSlots : overl);
                Server.notifyOps(
                    String.Format("Max player slots changed to {0}+{1}. [{2}]", result, overlimitSlots, sender.Name)
                );
            }

            sender.Message (255, ChatColor.SteelBlue, "Max player slots: {0}, overlimit slots: {1}", result, overlimitSlots);

            if (oldmax != maxSlots || oldover != overlimitSlots)
            {
                Program.properties.MaxPlayers = maxSlots;
                Program.properties.OverlimitSlots = overlimitSlots;
                Program.properties.Save (true);
            }
        }
开发者ID:emreuyls,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:48,代码来源:SlotManager.cs

示例2: Invasion

        public void Invasion(ISender sender, ArgumentList args)
        {
            if (Main.invasionType == 0)
            {
                var custom = args.TryPop("-custom");
                if (custom)
                {
                    if (args.Count > 0)
                    {
                        var npcIds = new List<Int32>();
                        while (args.Count > 0)
                        {
                            int npcType;
                            string npc;

                            if (args.TryGetInt(0, out npcType))
                            {
                                npcIds.Add(npcType);
                            }
                            else if (args.TryGetString(0, out npc))
                            {
                                var match = Definitions.DefinitionManager.FindNPC(npc);
                                if (match.Length == 1)
                                {
                                    npcIds.Add(match[0].Id);
                                }
                                else if (match.Length == 0)
                                {
                                    sender.Message("Cannot find a NPC by `{0}`", npc);
                                    return;
                                }
                                else
                                {
                                    sender.Message("Found too many NPC's containing `{0}`", npc);
                                    return;
                                }
                            }
                            else
                            {
                                throw new CommandError("Expected a NPC id or name.");
                            }
                        }

                        //Schedule...
                        //if (!_customInvasion.IsEmpty()) _customInvasion.Enabled = false;
                        //_customInvasion = new Task()
                        //{
                        //    Trigger = 10,
                        //    Data = npcIds,
                        //    Method = (task) =>
                        //    {
                        //        var ids = task.Data as List<Int32>;
                        //        for (var x = 0; x < 5; x++)
                        //        {
                        //            var ix = Main.rand.Next(0, ids.Count - 1);
                        //            var pos = FindPositionOutOfSight();

                        //            if (pos.HasValue)
                        //            {

                        //            }
                        //        }
                        //    }
                        //};

                        if (_invasion != null) lock (_invasion) _invasion = npcIds;
                        else _invasion = npcIds;

                        Main.StartInvasion(_assignedInvasionType);
                    }
                    else throw new CommandError("Expected npc type or name");
                }
                else
                {
                    var txt = args.GetString(0).ToLower();
                    var vals = Enum.GetValues(typeof(InvasionType));
                    foreach (InvasionType it in vals)
                    {
                        if (it.ToString().ToLower() == txt)
                        {
                            Main.StartInvasion((int)it);
                            sender.Message("A {0} invasion has begun.", it);
                            return;
                        }
                    }

                    sender.Message("No such invasion of type {0}", txt);
                }
            }
            else
            {
                if (args.TryPop("end") || args.TryPop("stop") || args.TryPop("cancel"))
                {
                    //if (!_customInvasion.IsEmpty()) _customInvasion.Enabled = false;
                    Main.invasionType = 0;
                    if (_invasion != null) lock (_invasion) _invasion.Clear();
                    sender.Message("The invasion has now been stopped.");
                }
                else sender.Message("An invasion is already under way.");
            }
//.........这里部分代码省略.........
开发者ID:VanixxGraphix,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:101,代码来源:Invasion.cs

示例3: ShowHelp

        /// <summary>
        /// Shows the help.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        public static void ShowHelp(ISender sender, ArgumentList args)
        {
            var commands = sender.GetAvailableCommands();
            if (commands != null && commands.Count > 0)
            {
                int page = 0;
                if (!args.TryGetInt(0, out page))
                {
                    if (args.Count > 0)
                    {
                        var command = args.GetString(0);
                        if (commands.ContainsKey(command))
                        {
                            sender.SendMessage(commands[command].description);
                            commands[command].ShowHelp(sender, true);
                            return;
                        }
                        else
                            throw new CommandError("No such command: " + command);
                    }
                }
                else
                    page--;

                //				const Int32 MaxLines = 5;
                var maxLines = sender is Player ? 5 : 15;
                var lineOffset = page * maxLines;
                var maxPages = (int)Math.Ceiling(commands.Count / (double)maxLines);

                if (page >= 0 && page < maxPages)
                {
                    var cmds = new List<CommandInfo>();
                    var sorted = commands
                        .OrderBy(x => x.Key.ToLower())
                        .Select(x => x.Value)
                        .ToArray();
                    for (var i = lineOffset; i < lineOffset + maxLines; i++)
                    {
                        if (i < sorted.Length)
                            cmds.Add(sorted[i]);
                    }

                    var prefixMax = cmds
                        .Select(x => x.Prefix.Length)
                        .OrderByDescending(x => x)
                        .First();
                    foreach (var cmd in cmds)
                        cmd.ShowDescription(sender, prefixMax);

                    sender.SendMessage(String.Format("[Page {0} / {1}]", page + 1, maxPages));
                }
                else
                {
                    sender.SendMessage("Usage:");
                    sender.SendMessage("    help <command> - Get help for a command.");
                    sender.SendMessage("    help <page> - View a list of commands. Valid page numbers are 1 to " + maxPages + ".");
                    sender.SendMessage("Examples:");
                    sender.SendMessage("    help oplogin");
                    sender.SendMessage("    help 1");
                }
            }
            else
                sender.SendMessage("You have no available commands.");
        }
开发者ID:claudiofreda,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:69,代码来源:DefaultCommands.cs

示例4: house


//.........这里部分代码省略.........
                        if (player.Op)
                        {
                            houseName = House.plugin.GetHouseNameImInside(player);
                            if (houseName == null)
                                player.sendMessage("You're not inside any houses", House.plugin.chatColor);
                            else
                                player.sendMessage("You're inside " + houseName, House.plugin.chatColor);
                        }
                        break;

                    // PROPERTIES
                    case "P":
                    case "PROPERTIES":
                        player.sendMessage("Max Area: " + House.plugin.maxArea, House.plugin.chatColor);
                        player.sendMessage("Max Houses: " + House.plugin.maxHouses, House.plugin.chatColor);
                        player.sendMessage("Min Height: " + House.plugin.minHeight, House.plugin.chatColor);
                        player.sendMessage("Max Height: " + House.plugin.maxHeight, House.plugin.chatColor);
                        player.sendMessage("Players Can Make Houses: " + House.plugin.playersCanMakeHouses.ToString(), House.plugin.chatColor);
                        player.sendMessage("Players Can Teleport: " + House.plugin.playersCanTeleport.ToString(), House.plugin.chatColor);
                        break;

                    // SET
                    case "S":
                    case "SET":
                        if (!player.Op)
                            player.sendMessage("Only ops can use this command!", House.plugin.chatColor);
                        else
                        {
                            if (args.TryGetString(1, out param))
                            {
                                switch (param.ToUpper())
                                {
                                    case "MAXAREA":
                                        if (args.TryGetInt(2, out value))
                                        {
                                            House.plugin.properties.MaxArea = value;
                                            House.plugin.maxArea = value;
                                            House.plugin.properties.Save(true);
                                            player.sendMessage("You updated MaxArea to " + value, House.plugin.chatColor);
                                        }
                                        else
                                            player.sendMessage("Must specify an integer value for MaxArea!", House.plugin.chatColor);
                                        break;

                                    case "MAXHOUSES":
                                        if (args.TryGetInt(2, out value))
                                        {
                                            House.plugin.properties.MaxHouses = value;
                                            House.plugin.maxHouses = value;
                                            House.plugin.properties.Save(true);
                                            player.sendMessage("You updated MaxHouses to " + value, House.plugin.chatColor);
                                        }
                                        else
                                            player.sendMessage("Must specify an integer value for MaxHouses!", House.plugin.chatColor);
                                        break;

                                    case "MINHEIGHT":
                                        if (args.TryGetInt(2, out value))
                                        {
                                            House.plugin.properties.MinHeight = value;
                                            House.plugin.minHeight = value;
                                            House.plugin.properties.Save(true);
                                            player.sendMessage("You updated MinHeight to " + value, House.plugin.chatColor);
                                        }
                                        else
                                            player.sendMessage("Must specify an integer value for MinHeight!", House.plugin.chatColor);
开发者ID:amarriner,项目名称:House,代码行数:67,代码来源:Commands.cs


注:本文中的ArgumentList.TryGetInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。