Exemplo n.º 1
0
        public void AddBindTool(BindTool NewBT, bool Database)
        {
            List <BindTool> Removed = new List <BindTool>();

            foreach (BindTool PT in bindTools)
            {
                if ((PT.item == NewBT.item) &&
                    ((PT.slot == NewBT.slot) ||
                     ((PT.slot != -1) && (NewBT.slot == -1)) ||
                     ((PT.slot == -1) && (NewBT.slot != -1))) &&
                    ((PT.prefix == NewBT.prefix) ||
                     ((PT.prefix != -1) && (NewBT.prefix == -1)) ||
                     ((PT.prefix == -1) && (NewBT.prefix != -1))))
                {
                    Removed.Add(PT);
                    if (Database && tsPlayer.IsLoggedIn)
                    {
                        BTDatabase.BTDelete(tsPlayer.Account.ID, PT.item, PT.slot, PT.prefix);
                    }
                }
            }
            bindTools = (from BindTool b in bindTools
                         where !Removed.Contains(b)
                         select b).ToList();
            bindTools.Add(NewBT);
            if (Database && tsPlayer.IsLoggedIn)
            {
                BTDatabase.BTAdd(tsPlayer.Account.ID, NewBT);
            }
        }
Exemplo n.º 2
0
 public void AddBindTool(BindTool NewBT)
 {
     foreach (BindTool PT in BindTools)
     {
         if (PT.item == NewBT.item)
         {
             BindTools.Remove(PT);
             break;
         }
     }
     BindTools.Add(NewBT);
 }
Exemplo n.º 3
0
 public static bool AnyGBMatch(BindTool BindTool)
 {
     foreach (BTGlobalBind GlobalBind in GlobalBinds)
     {
         if ((GlobalBind.ItemID == BindTool.item) &&
             ((GlobalBind.Slot == BindTool.slot) ||
              ((GlobalBind.Slot != -1) && (BindTool.slot == -1)) ||
              ((GlobalBind.Slot == -1) && (BindTool.slot != -1))) &&
             ((GlobalBind.Prefix == BindTool.prefix) ||
              ((GlobalBind.Prefix != -1) && (BindTool.prefix == -1)) ||
              ((GlobalBind.Prefix == -1) && (BindTool.prefix != -1))))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
 public static void BTAdd(int UserID, BindTool BTItem)
 {
     db.Query("INSERT INTO BindTools (UserID, ItemID, Commands, Awaiting, Looping, Slot, Prefix) " +
              "VALUES (@0, @1, @2, @3, @4, @5, @6);", UserID, BTItem.item, string.Join("~;*;~", BTItem.commands),
              (BTItem.awaiting ? 1 : 0), (BTItem.looping ? 1 : 0), BTItem.slot, BTItem.prefix);
 }
Exemplo n.º 5
0
        private void BindToolCMD(CommandArgs args)
        {
            var player = BTPlayers[args.Player.Index];

            if ((player == null) || (player.tsPlayer == null))
            {
                return;
            }

            if (args.Parameters.Count == 0)
            {
                args.Player.SendMessage("BindTool usage:", Color.LightSalmon);
                args.Player.SendMessage(string.Format("{0}bindtool [-flags] commands; separated; by semicolon", TShock.Config.CommandSpecifier), Color.BurlyWood);
                args.Player.SendMessage("This will bind those commands to the current item in hand.", Color.BurlyWood);
                args.Player.SendMessage(string.Format("Type {0}bt help for flag info.", TShock.Config.CommandSpecifier), Color.BurlyWood);
                args.Player.SendMessage(string.Format("Type {0}bt list for current bind list.", TShock.Config.CommandSpecifier), Color.BurlyWood);
                return;
            }

            if (args.Parameters[0].ToLower() == "help")
            {
                List <string> Help = new List <string>
                {
                    "-l will loop trough commands in order",
                    "[c/aaaa00:-s will bind item only at certain slot]",
                    "-p will bind item only with certain prefix",
                    "[c/aaaa00:-d will add bind to database, so it will be saved and can be used after rejoin]",
                    "You can combine flags: -spd = slot + prefix + database",
                    string.Format("[c/aaaa00:-w instead of execution will add command to queue, so you could add parameters later] (write {0}bt help wait for more info)", TShock.Config.CommandSpecifier),
                    "-c will clear all commands from the item at certain slot with certain prefix",
                    "[c/aaaa00:-csp = clear any bind on item; -cs = clear binds on item with certain prefix, but any slot; -cp = clear binds on item with certain slot, but any prefix]"
                };
                int page = 1;
                if ((args.Parameters.Count > 1) && (!int.TryParse(args.Parameters[1], out page)))
                {
                    if (args.Parameters[1].ToLower() == "wait")
                    {
                        page = 1;
                        Help = new List <string>
                        {
                            "Text format uses {Num} syntax. Parameters start from 0.",
                            string.Format("[c/aaaa00:For example ' {0}bt {0}region allow ", TShock.Config.CommandSpecifier) + "\"{0}\" " + string.Format("\"Region Name\" ' will allow you to use {0}bw Player1, {0}bw \"Player 2\", etc.]", TShock.Config.CommandSpecifier),
                            "You need to fill all {Num} fields used in your bind command."
                        };
                    }
                    else
                    {
                        args.Player.SendErrorMessage("\"{0}\" is not a valid page number.", args.Parameters[1]); return;
                    }
                }
                PaginationTools.SendPage(args.Player, page, Help,
                                         new PaginationTools.Settings
                {
                    HeaderFormat = "Bindtools help ({0}/{1}):",
                    FooterFormat = "Type {0}bt help {{0}} for more info.".SFormat(TShock.Config.CommandSpecifier)
                }
                                         );
                return;
            }
            else if (args.Parameters[0].ToLower() == "list")
            {
                int page = 1;
                if ((args.Parameters.Count > 1) &&
                    (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out page)))
                {
                    return;
                }
                var Normal = BTPlayers[args.Player.Index].bindTools.Select
                             (
                    b => (string.Format("Item: [i:{0}]. Commands: {1}. Awaiting: {2}. Looping: {3}. Slot: {4}. Prefix: {5}. Database: {6}.",
                                        b.item,
                                        string.Join("; ", b.commands),
                                        b.awaiting,
                                        b.looping,
                                        ((b.slot == -1) ? "Any" : (b.slot == 58) ? "Cursor" : "Hotbar-" + (b.slot + 1)),
                                        ((b.prefix == -1) ? "Any" : (b.prefix == 0) ? "None" : Lang.prefix[b.prefix].Value),
                                        b.database))
                             ).ToList();
                PaginationTools.SendPage(args.Player, page, Normal,
                                         new PaginationTools.Settings
                {
                    HeaderFormat           = "Current binds ({0}/{1}):",
                    FooterFormat           = "Type {0}bt list {{0}} for more info.".SFormat(TShock.Config.CommandSpecifier),
                    NothingToDisplayString = "You do not have any binds."
                }
                                         );
                return;
            }

            if ((args.Player.TPlayer.selectedItem > 9) && (args.Player.TPlayer.selectedItem != 58))
            {
                args.Player.SendMessage("Please select an item from your hotbar or cursor", Color.Red);
                return;
            }

            byte flagmod = 0;
            bool awaiting = false, looping = false, slot = false, clear = false;
            bool prefix = false, database = false;

            if (args.Parameters[0].StartsWith("-"))
            {
                flagmod = 1;
                for (int i = 1; i < args.Parameters[0].Length; i++)
                {
                    if ((args.Parameters[0][i] == 'w') || ((args.Parameters[0][i] == 'W')))
                    {
                        awaiting = true;
                    }
                    else if ((args.Parameters[0][i] == 'l') || ((args.Parameters[0][i] == 'L')))
                    {
                        looping = true;
                    }
                    else if ((args.Parameters[0][i] == 's') || ((args.Parameters[0][i] == 'S')))
                    {
                        slot = true;
                    }
                    else if ((args.Parameters[0][i] == 'c') || ((args.Parameters[0][i] == 'C')))
                    {
                        clear = true;
                    }
                    else if ((args.Parameters[0][i] == 'p') || ((args.Parameters[0][i] == 'P')))
                    {
                        prefix = true;
                    }
                    else if ((args.Parameters[0][i] == 'd') || ((args.Parameters[0][i] == 'D')))
                    {
                        database = true;
                    }
                    else
                    {
                        args.Player.SendMessage("Invalid BindTool flag.", Color.LightSalmon);
                        args.Player.SendMessage("Valid flags are 'w' [awaiting], 'l' [looping], 's' [slot], 'p' [prefix], " +
                                                "'d' [database], 'c' [clear], 'ca' [clear any], 'ce' [clear everything]", Color.BurlyWood);
                        args.Player.SendMessage("You can combine flags: -spd = slot + prefix + database, -csp = clear any bind on item; -cs = clear binds on item with certain prefix, but any slot", Color.BurlyWood);
                        return;
                    }
                }
            }

            var item = args.Player.TPlayer.inventory[args.Player.TPlayer.selectedItem];

            if (clear)
            {
                string _prefix = Lang.prefix[item.prefix].Value;
                player.RemoveBindTool(item.netID, ((slot) ? -1 : args.Player.TPlayer.selectedItem), ((prefix) ? -1 : item.prefix));
                args.Player.SendMessage(string.Format("All commands have been removed from [i:{0}]{1}{2}", item.netID,
                                                      ((slot) ? "" : " at " + ((args.Player.TPlayer.selectedItem > 9) ? "cursor" : "hotbar-" + (args.Player.TPlayer.selectedItem + 1)) + " slot"),
                                                      ((prefix) ? "" : (" with " + (_prefix == "" ? "no" : _prefix) + " prefix"))), Color.BurlyWood);
                return;
            }

            else if (args.Parameters.Count < 1)
            {
                args.Player.SendMessage("Missing commands", Color.LightSalmon); return;
            }

            string        NewMsg  = string.Join(" ", args.Message.Replace("\"", "\\\"").Split(' ').Skip(1));
            List <string> NewArgs = BTExtensions.ParseParameters(NewMsg);

            var           cmdstring = string.Join(" ", NewArgs.GetRange(flagmod, NewArgs.Count - flagmod));
            List <string> cmdlist   = cmdstring.Split(';').ToList();

            for (int i = 0; i < cmdlist.Count; i++)
            {
                cmdlist[i] = cmdlist[i].TrimStart(' ');
            }

            BindTool BindTool = new BindTool(item.netID, (slot ? args.Player.TPlayer.selectedItem : -1), cmdlist, awaiting, looping, (prefix ? item.prefix : -1), database);

            if (BTExtensions.AnyGBMatch(BindTool) && !args.Player.HasPermission(BTPermissions.Overwrite))
            {
                args.Player.SendErrorMessage("You can't overwrite global binds!");
                return;
            }

            player.AddBindTool(BindTool, database);

            string Prefix = Lang.prefix[item.prefix].Value;

            StringBuilder builder = new StringBuilder();

            builder.Append("Bound");
            foreach (string cmd in cmdlist)
            {
                builder.AppendFormat(" '{0}'", cmd);
            }
            builder.AppendFormat(" to {0}{1}{2} (Database: {3})", item.Name,
                                 (slot ? (" at " + ((args.Player.TPlayer.selectedItem > 9) ? "cursor" : "hotbar-" + (args.Player.TPlayer.selectedItem + 1)) + " slot") : ""),
                                 (prefix ? (" with " + ((Prefix == "") ? "no" : Prefix) + " prefix") : ""), database);

            args.Player.SendMessage(builder.ToString(), Color.BurlyWood);
        }