Exemple #1
0
        internal int HasMiner(List <TSPlayer> team)
        {
            int MinerCount = 0;

            foreach (TSPlayer p in team)
            {
                if (Classes.GetClass(Players.GetClassPlaying(p.Name)).category == "Miner")
                {
                    MinerCount++;
                }
            }
            return(MinerCount);
        }
Exemple #2
0
        private void ClassMod(CommandArgs args)
        {
            TSPlayer player = args.Player;

            #region help
            if (args.Parameters.Count == 0 || args.Parameters[0] == "help")
            {
                player.SendErrorMessage("Aliases: /cwmod, /cwm");
                player.SendErrorMessage("/cwm select [class name]");
                player.SendErrorMessage("/cwm add [class name]");
                player.SendErrorMessage("/cwm del");
                player.SendErrorMessage("/cwm set {inv | stats}");
                player.SendErrorMessage("/cwm buff {add | del | clear} [buff name/id] [duration] <itemHeld>");
                player.SendErrorMessage("/cwm itemgen {add | del | clear} [refresh] [maxQuantity]");
                player.SendErrorMessage("/cwm link {set | clear}");
                player.SendErrorMessage("/cwm desc {get | set} [line] [description text]");
                player.SendErrorMessage("/cwm category {get | set | list} [category]");
                return;
            }
            #endregion

            /*wheeee, first command is done, on to the other three. But first, have some command syntax before i forget to write this down anywhere outside of the source code.*/

            #region select
            if (args.Parameters[0] == "select")
            {
                if (args.Parameters.Count == 1)
                {
                    player.SendErrorMessage("Usage: /cwm select [class name]");
                    player.SendErrorMessage("This selects a class for other class modifying commands to reference");
                    return;
                }
                int resultType = 0;
                args.Parameters.RemoveAt(0);
                string search  = string.Join(" ", args.Parameters);
                string results = CUtil.ClassExists(search, ref resultType);
                switch (resultType)
                {
                case -1:
                    player.SendErrorMessage(results);
                    break;

                case 0:
                case 1:
                    PInfo.SelectClass(player.Name, results);
                    player.SendSuccessMessage("Class " + results + " selected.");
                    break;

                case 2:
                    player.SendErrorMessage("Multiple classes found: ");
                    player.SendErrorMessage(results);
                    break;
                }
                return;
            }
            #endregion

            #region add
            if (args.Parameters[0] == "add")
            {
                if (args.Parameters.Count == 0)
                {
                    player.SendErrorMessage("Usage: /cwm add [class name]");
                    player.SendErrorMessage("This adds a new class with the given name, using your current inventory and stats");
                    return;
                }
                int resultType = 0;
                args.Parameters.RemoveAt(0);
                string name    = string.Join(" ", args.Parameters);
                string results = CUtil.ClassExists(name, ref resultType);
                if (resultType == 0)
                {
                    player.SendErrorMessage("There is already a class named " + name);
                    return;
                }
                CUtil.AddClass(player, name);
                player.SendSuccessMessage("Class " + name + " successfully added.");
                PInfo.SelectClass(player.Name, name);
                player.SendSuccessMessage("Class " + name + " has been automatically selected.");
                return;
            }
            #endregion

            #region checkSelected
            string selectedClass = PInfo.GetClassEdit(player.Name);
            if (selectedClass == "none")
            {
                player.SendErrorMessage("Please select a class using \"/cwm select\"before using this command.");
                return;
            }
            CWClass c = CUtil.GetClass(selectedClass);
            #endregion

            #region del
            if (args.Parameters[0].ToLower() == "del")
            {
                if (CUtil.DelClass(c.name))
                {
                    player.SendSuccessMessage("Class " + c.name + " successfully deleted.");
                }
                else
                {
                    player.SendErrorMessage("Warning: Unknown class selected: " + c.name);
                    player.SendErrorMessage("Deselecting unknown class.");
                }
                PInfo.SelectClass(player.Name, "none");
                return;
            }
            #endregion

            #region set
            if (args.Parameters[0].ToLower() == "set")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "inv" && args.Parameters[1].ToLower() != "stats" && args.Parameters[1].ToLower() != "stat"))
                {
                    player.SendErrorMessage("Usage: /cwm set {inv | stats}");
                    player.SendErrorMessage("This sets the inventory or health/mana of a class to that of your current player.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "inv")
                {
                    c.inventory = player.PlayerData.inventory;
                }
                if (args.Parameters[1].ToLower() == "stat" || args.Parameters[1].ToLower() == "stats")
                {
                    c.maxHealth = player.PlayerData.maxHealth;
                    c.maxMana   = player.PlayerData.maxMana;
                    c.extraSlot = player.PlayerData.extraSlot;
                }
                CUtil.UpdateClass(c);
                player.SendSuccessMessage("Successfully updated " + c.name);
                return;
            }
            #endregion

            #region buff
            if (args.Parameters[0].ToLower() == "buff")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "del" && args.Parameters[1].ToLower() != "add" && args.Parameters[1].ToLower() != "clear"))
                {
                    player.SendErrorMessage("Usage: /cwm buff {add | del | clear} [buff name/id] [duration] <itemHeld>");
                    player.SendErrorMessage("This allows modifications of a class's buffs and itembuffs.");
                    player.SendErrorMessage("<itemHeld> should be 0 or empty for permanent buffs, 1 for buffs while holding an item, and 2 for buffs while not holding an item.");
                    player.SendErrorMessage("if <itemheld> is not 0, the currently item you are currently holding is used.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "clear")
                {
                    c.buffs = new List <Buff>();
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage("All buffs cleared from class " + c.name);
                    return;
                }
                if (args.Parameters[1].ToLower() == "add")
                {
                    if (args.Parameters.Count < 4)
                    {
                        player.SendErrorMessage("Usage: /cwm buff add [buff name/id] [duration] <itemHeld>");
                        player.SendErrorMessage("<itemHeld> should be 0 or empty for permanent buffs, 1 for buffs while holding an item, and 2 for buffs while not holding an item.");
                        player.SendErrorMessage("if <itemheld> is not 0, the currently item you are currently holding is used.");
                        return;
                    }
                    int buffID;
                    if (!int.TryParse(args.Parameters[2].ToLower(), out buffID))
                    {
                        List <int> t = TShock.Utils.GetBuffByName(args.Parameters[2].ToLower());
                        if (t.Count > 1)
                        {
                            player.SendErrorMessage("Multiple buff IDs found: " + string.Join(", ", t));
                            return;
                        }
                        else if (t.Count == 1)
                        {
                            buffID = t[0];
                        }
                        else if (t.Count == 0)
                        {
                            player.SendErrorMessage("Buff " + args.Parameters[2] + " not found.");
                            return;
                        }
                    }
                    float duration;
                    if (!float.TryParse(args.Parameters[3].ToLower(), out duration))
                    {
                        player.SendErrorMessage("Please only use numerical durations.");
                        return;
                    }
                    if (args.Parameters.Count == 5 && args.Parameters[4].ToLower() != "0" && args.Parameters[4].ToLower() != "no")
                    {
                        Item tempItem = player.TPlayer.HeldItem;
                        switch (args.Parameters[4].ToLower())
                        {
                        case "1":
                            c.buffs.Add(new Buff(buffID, (int)duration * 10, tempItem.netID, 1));
                            CUtil.UpdateClass(c);
                            player.SendSuccessMessage("Buff " + TShock.Utils.GetBuffName(buffID) + " has been added to " + c.name + " with a duration of " + duration + " seconds, while holding " + tempItem.Name);
                            return;

                        case "2":
                            c.buffs.Add(new Buff(buffID, (int)duration * 10, tempItem.netID, 0));
                            CUtil.UpdateClass(c);
                            player.SendSuccessMessage("Buff " + TShock.Utils.GetBuffName(buffID) + " has been added to " + c.name + " with a duration of " + duration + " seconds, while not holding " + tempItem.Name);
                            return;
                        }
                    }
                    c.buffs.Add(new Buff(buffID, (int)duration * 10));
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage("Buff " + TShock.Utils.GetBuffName(buffID) + " has been added to " + c.name + " with a duration of " + duration + " seconds.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "del")
                {
                    int buffID;
                    if (!int.TryParse(args.Parameters[2].ToLower(), out buffID))
                    {
                        List <int> t = TShock.Utils.GetBuffByName(args.Parameters[2].ToLower());
                        if (t.Count > 1)
                        {
                            player.SendErrorMessage("Multiple buff IDs found: " + string.Join(", ", t));
                            return;
                        }
                        else if (t.Count == 1)
                        {
                            buffID = t[0];
                        }
                        else if (t.Count == 0)
                        {
                            player.SendErrorMessage("Buff " + args.Parameters[2] + " not found.");
                            return;
                        }
                    }
                    c.buffs.RemoveAll(b => b.id == buffID);
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage("All instances of " + TShock.Utils.GetBuffName(buffID) + " have been removed from " + c.name + ".");
                    return;
                }
                return;
            }
            #endregion

            #region itemgen
            if (args.Parameters[0].ToLower() == "itemGen")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "del" && args.Parameters[1].ToLower() != "add" && args.Parameters[1].ToLower() != "clear"))
                {
                    player.SendErrorMessage("Usage: /cwm itemgen {add | del | clear} [refresh] [maxQuantity]");
                    player.SendErrorMessage("This allows modification of a class's regenerating items.");
                    player.SendErrorMessage("'/cwm itemgen add' utilizes the prefix, quantity, and item id of the player's currently selected item.");
                    player.SendErrorMessage("The stack size of the currently held item determines the number of items given at one time.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "clear")
                {
                    c.items = new List <ItemRestock>();
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage("Class " + c.name + " has been cleared of itemgens.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "add")
                {
                    if (args.Parameters.Count < 4)
                    {
                        player.SendErrorMessage("Usage: /cwm itemgen add [refresh] [maxQuantity]");
                        return;
                    }
                    float refresh;
                    if (!float.TryParse(args.Parameters[2], out refresh))
                    {
                        player.SendErrorMessage("Please use numerals for the refresh time.");
                        return;
                    }
                    int maxCount;
                    if (!int.TryParse(args.Parameters[3], out maxCount))
                    {
                        player.SendErrorMessage("Please use numerals for the maximum item count.");
                        return;
                    }
                    Item tempItem = player.TPlayer.HeldItem;
                    c.items.Add(new ItemRestock((int)refresh * 10, tempItem.netID, tempItem.stack, maxCount, tempItem.prefix));
                    CUtil.UpdateClass(c);
                    if (tempItem.prefix == 0)
                    {
                        player.SendSuccessMessage(c.name + " will now receive " + tempItem.stack + " " + tempItem.Name + " every " + (float)refresh / 10 + " seconds.");
                    }
                    else
                    {
                        player.SendSuccessMessage(c.name + " will now receive " + tempItem.stack + " " + TShock.Utils.GetPrefixById(tempItem.prefix) + " " + tempItem.Name + " every " + (float)refresh / 10 + " seconds.");
                    }
                    return;
                }
                if (args.Parameters[1].ToLower() == "del")
                {
                    Item tempItem = player.TPlayer.HeldItem;
                    player.SendSuccessMessage(c.items.RemoveAll(i => i.item == tempItem.netID) + " itemgen(s) removed from " + c.name + ".");
                    CUtil.UpdateClass(c);
                    return;
                }
                return;
            }
            #endregion

            #region link
            if (args.Parameters[0].ToLower() == "link")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "set" && args.Parameters[1].ToLower() != "clear"))
                {
                    player.SendErrorMessage("Usage: /cwm link {set | clear}");
                    player.SendErrorMessage("This command allows you set and remove locations that will cause a player to automatically preview a class.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "clear")
                {
                    c.locations = new List <LocationLink>();
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage("All location links removed from " + c.name);
                    return;
                }
                if (args.Parameters[1].ToLower() == "set")
                {
                    c.locations.Add(new LocationLink(player.TileX, player.TileY));
                    player.SendSuccessMessage("New location link set at your current location for " + c.name);
                    CUtil.UpdateClass(c);
                    return;
                }
            }
            #endregion

            #region description
            if (args.Parameters[0].ToLower() == "desc" || args.Parameters[0].ToLower() == "description")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "get" && args.Parameters[1].ToLower() != "set"))
                {
                    player.SendErrorMessage("Usage: /cwm desc {get | set} [line] [description text]");
                    player.SendErrorMessage("This command allows you to check and set the description of a class, one line at a time.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "get")
                {
                    if (c.description.Count == 0)
                    {
                        player.SendErrorMessage(c.name + " does not have a description.");
                        return;
                    }
                    foreach (string s in c.description)
                    {
                        player.SendSuccessMessage(s);
                    }
                    return;
                }
                if (args.Parameters[1].ToLower() == "set")
                {
                    if (args.Parameters.Count < 4)
                    {
                        player.SendErrorMessage("Usage: /cwm desc set [line] [description text]");
                        return;
                    }
                    int line;
                    if (!int.TryParse(args.Parameters[2], out line))
                    {
                        player.SendErrorMessage("Unable to parse line number.");
                        return;
                    }
                    args.Parameters.RemoveAt(0);
                    args.Parameters.RemoveAt(0);
                    args.Parameters.RemoveAt(0);
                    c.description[line - 1] = string.Join(" ", args.Parameters);
                    player.SendSuccessMessage("Description line " + line + " of " + c.name + " set.");
                    player.SendSuccessMessage("Current description for " + c.name + " is now:");
                    foreach (string s in c.description)
                    {
                        player.SendSuccessMessage(s);
                    }
                    return;
                }
            }
            #endregion

            #region category
            if (args.Parameters[0] == "cat" || args.Parameters[0] == "category")
            {
                if (args.Parameters.Count == 1 || (args.Parameters[1].ToLower() != "get" && args.Parameters[1].ToLower() != "set" && args.Parameters[1].ToLower() != "list"))
                {
                    player.SendErrorMessage("Usage: /cwm category {get | set | list} [category]");
                    player.SendErrorMessage("This command allows you to retrieve or specify the category of a class.");
                    player.SendErrorMessage("Categories should be a single word, and cannot consist entirely of numbers.");
                    return;
                }
                if (args.Parameters[1].ToLower() == "get")
                {
                    if (c.category == "none")
                    {
                        player.SendErrorMessage(c.name + " does not have a category yet.");
                    }
                    else
                    {
                        player.SendSuccessMessage(c.name + " is in the \"" + c.category + "\" category.");
                    }
                    return;
                }
                if (args.Parameters[1].ToLower() == "set")
                {
                    if (args.Parameters.Count == 2)
                    {
                        player.SendErrorMessage("Usage: /cwm category set [category]");
                        player.SendErrorMessage("This specifies the category of the currently selected class.");
                        return;
                    }
                    float YouMotherFucker;
                    if (float.TryParse(args.Parameters[2], out YouMotherFucker))
                    {
                        player.SendErrorMessage("Didn't you read the help text? What kind of category is " + args.Parameters[2] + " anyways?");
                        TShockAPI.Commands.HandleCommand(TSPlayer.Server, "/slap " + player.Name + " 5");
                        return;
                    }
                    TextInfo TI = new CultureInfo("en-US", false).TextInfo;
                    c.category = TI.ToTitleCase(args.Parameters[2]);
                    CUtil.UpdateClass(c);
                    player.SendSuccessMessage(c.name + " is now categorized under \"" + c.category + "\"");
                    return;
                }
                if (args.Parameters[1].ToLower() == "list")
                {
                    List <string> categories = new List <string>();
                    foreach (CWClass x in CUtil.classes)
                    {
                        categories.Add(x.category);
                    }
                    categories = categories.Distinct().ToList();
                    player.SendSuccessMessage("Categories: ");
                    player.SendSuccessMessage(string.Join(", ", categories));
                    return;
                }
            }

            #endregion
        }