Ejemplo n.º 1
0
        static void Say(object o, CommandEventArgs e)
        {
            if (e.Length == 0)
            {
                Utils.NewSuccessText("Syntax: /{0} <message>", e[-1]);
                return;
            }

            if (Main.netMode == 1)
            {
                NetMessage.SendData(25, -1, -1, e.Eol(0));
            }
            else
            {
                Main.NewText(String.Format("<{0}> {1}", Main.player[Main.myPlayer].name, e.Eol(0)));
            }
        }
Ejemplo n.º 2
0
        static void Set(object o, CommandEventArgs e)
        {
            if (e.Length == 0 || String.Equals(e[0], "list", StringComparison.OrdinalIgnoreCase))
            {
                Utils.NewSuccessText("Config options:");
                foreach (FieldInfo fi in typeof(Config).GetFields(BindingFlags.Instance | BindingFlags.Public))
                {
                    Type t = fi.FieldType;
                    if (t != typeof(bool) && t != typeof(int) && t != typeof(string))
                    {
                        continue;
                    }

                    Utils.NewInfoText("{0}: {1} ({2})",
                                      fi.Name, fi.GetValue(Raptor.Config), ((DescriptionAttribute)fi.GetCustomAttributes(false)[0]).Description);
                }
            }
            else
            {
                FieldInfo fi = typeof(Config).GetField(e[0], BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);

                if (fi == null)
                {
                    Utils.NewErrorText("Invalid option \"{0}\".", e[0]);
                    return;
                }

                Type t = fi.FieldType;
                if (t != typeof(bool) && t != typeof(int) && t != typeof(string))
                {
                    Utils.NewErrorText("Invalid option \"{0}\".", e[0]);
                    return;
                }

                if (e.Length == 1)
                {
                    if (t == typeof(bool))
                    {
                        Utils.NewErrorText("Syntax: /{0} {1} <boolean>", e[-1], fi.Name);
                    }
                    else if (t == typeof(int))
                    {
                        Utils.NewErrorText("Syntax: /{0} {1} <integer>", e[-1], fi.Name);
                    }
                    else
                    {
                        Utils.NewErrorText("Syntax: /{0} {1} <string>", e[-1], fi.Name);
                    }
                    return;
                }

                if (t == typeof(bool))
                {
                    bool value;
                    if (!bool.TryParse(e[1], out value))
                    {
                        Utils.NewErrorText("Invalid value for option \"{0}\".", fi.Name);
                        return;
                    }

                    fi.SetValue(Raptor.Config, value);
                    Utils.NewSuccessText("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }
                else if (t == typeof(int))
                {
                    int value;
                    if (!int.TryParse(e[1], out value) || value <= 0)
                    {
                        Utils.NewErrorText("Invalid value for option \"{0}\".", fi.Name);
                        return;
                    }

                    fi.SetValue(Raptor.Config, value);
                    Utils.NewSuccessText("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }
                else
                {
                    string value = e.Eol(1);
                    fi.SetValue(Raptor.Config, value);
                    Utils.NewSuccessText("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }

                string configPath = "raptor.config";
                File.WriteAllText(configPath, JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
            }
        }
Ejemplo n.º 3
0
        static void Keybind(object o, CommandEventArgs e)
        {
            string subcommand = e.Length > 0 ? e[0].ToLowerInvariant() : "help";

            switch (subcommand)
            {
            case "add":
            {
                if (e.Length < 3)
                {
                    Utils.NewErrorText("Syntax: /{0} {1} <key> <command>", e[-1], e[0]);
                    return;
                }

                Keys key;
                if (!Enum.TryParse <Keys>(e[1], true, out key))
                {
                    Utils.NewErrorText("Invalid key \"{0}\".", e[1]);
                    return;
                }

                if (Raptor.Config.KeyBindings.ContainsKey(key))
                {
                    Utils.NewErrorText("The key \"{0}\" is already bound.", key);
                    return;
                }

                Raptor.Config.KeyBindings.Add(key, e.Eol(2));
                string configPath = "raptor.config";
                File.WriteAllText(configPath, JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                Utils.NewSuccessText("Bound the key \"{0}\" to \"{1}\".", key, e.Eol(2));
            }
                return;

            case "clr":
            case "clear":
            {
                Raptor.Config.KeyBindings.Clear();
                string configPath = "raptor.config";
                File.WriteAllText(configPath, JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                Utils.NewSuccessText("Cleared all key bindings.");
            }
                return;

            case "del":
            case "delete":
            case "remove":
            {
                if (e.Length == 1)
                {
                    Utils.NewErrorText("Syntax: /{0} {1} <key>", e[-1], e[0]);
                    return;
                }

                Keys key;
                if (!Enum.TryParse <Keys>(e[1], true, out key))
                {
                    Utils.NewErrorText("Invalid key \"{0}\".", e[1]);
                    return;
                }
                if (!Raptor.Config.KeyBindings.ContainsKey(key))
                {
                    Utils.NewErrorText("The key \"{0}\" is not bound.", key);
                    return;
                }
                Raptor.Config.KeyBindings.Remove(key);
                string configPath = "raptor.config";
                File.WriteAllText(configPath, JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                Utils.NewSuccessText("Unbound the key \"{0}\".", key);
            }
                return;

            case "list":
                Utils.NewSuccessText("Key Bindings:");
                foreach (KeyValuePair <Keys, string> kv in Raptor.Config.KeyBindings)
                {
                    Utils.NewInfoText("Key \"{0}\": {1}", kv.Key, kv.Value);
                }
                return;

            case "help":
            default:
                Utils.NewSuccessText("/{0} help:", e[-1]);
                Utils.NewInfoText("/{0} add <key> <command> - Adds a key binding.", e[-1]);
                Utils.NewInfoText("/{0} clr/clear - Clears all key bindings.", e[-1]);
                Utils.NewInfoText("/{0} del/delete/remove <key> - Deletes a key binding.", e[-1]);
                Utils.NewInfoText("/{0} list - Lists all key bindings.", e[-1]);
                return;
            }
        }
Ejemplo n.º 4
0
        static void Set(object o, CommandEventArgs e)
        {
            if (e.Length == 0 || String.Equals(e[0], "list", StringComparison.OrdinalIgnoreCase))
            {
                Utils.SuccessMessage("Config options:");
                foreach (FieldInfo fi in typeof(Config).GetFields(BindingFlags.Instance | BindingFlags.Public))
                {
                    Type t = fi.FieldType;
                    if (t != typeof(bool) && t != typeof(int) && t != typeof(string))
                        continue;

                    Utils.InfoMessage("{0}: {1} ({2})",
                        fi.Name, fi.GetValue(Raptor.Config), ((DescriptionAttribute)fi.GetCustomAttributes(false)[0]).Description);
                }
            }
            else
            {
                FieldInfo fi = typeof(Config).GetField(e[0], BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);

                if (fi == null)
                {
                    Utils.ErrorMessage("Invalid option \"{0}\".", e[0]);
                    return;
                }

                Type t = fi.FieldType;
                if (t != typeof(bool) && t != typeof(int) && t != typeof(string))
                {
                    Utils.ErrorMessage("Invalid option \"{0}\".", e[0]);
                    return;
                }

                if (e.Length == 1)
                {
                    if (t == typeof(bool))
                        Utils.ErrorMessage("Syntax: .{0} {1} <boolean>", e[-1], fi.Name);
                    else if (t == typeof(int))
                        Utils.ErrorMessage("Syntax: .{0} {1} <integer>", e[-1], fi.Name);
                    else
                        Utils.ErrorMessage("Syntax: .{0} {1} <string>", e[-1], fi.Name);
                    return;
                }

                if (t == typeof(bool))
                {
                    bool value;
                    if (!bool.TryParse(e[1], out value))
                    {
                        Utils.ErrorMessage("Invalid value for option \"{0}\".", fi.Name);
                        return;
                    }

                    fi.SetValue(Raptor.Config, value);
                    Utils.SuccessMessage("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }
                else if (t == typeof(int))
                {
                    int value;
                    if (!int.TryParse(e[1], out value) || value <= 0)
                    {
                        Utils.ErrorMessage("Invalid value for option \"{0}\".", fi.Name);
                        return;
                    }

                    fi.SetValue(Raptor.Config, value);
                    Utils.SuccessMessage("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }
                else
                {
                    string value = e.Eol(1);
                    fi.SetValue(Raptor.Config, value);
                    Utils.SuccessMessage("Set option \"{0}\" to value \"{1}\".", fi.Name, value);
                }

                File.WriteAllText("raptor.config", JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
            }
        }
Ejemplo n.º 5
0
        static void Say(object o, CommandEventArgs e)
        {
            if (e.Length == 0)
            {
                Utils.SuccessMessage("Syntax: .{0} <message>", e[-1]);
                return;
            }

            if (Main.netMode == 1)
                NetMessage.SendData(25, -1, -1, e.Eol(0));
            else
                Main.NewText(String.Format("<{0}> {1}", Main.player[Main.myPlayer].name, e.Eol(0)));
        }
Ejemplo n.º 6
0
        static void Keybind(object o, CommandEventArgs e)
        {
            string subcommand = e.Length > 0 ? e[0].ToLowerInvariant() : "help";

            switch (subcommand)
            {
                case "add":
                    {
                        if (e.Length < 3)
                        {
                            Utils.ErrorMessage("Syntax: .{0} {1} <keybind> <command>", e[-1], e[0]);
                            return;
                        }

                        string key = e[1];
                        var keybind = new Input.Keybind();
                        while (!Utils.TryParseXNAKey(key, out keybind.Key))
                        {
                            if (String.IsNullOrEmpty(key))
                            {
                                Utils.ErrorMessage("Invalid keybind '{0}'!", e[0]);
                                return;
                            }

                            switch (key[0])
                            {
                                case '!':
                                    break;
                                case '^':
                                    break;
                                case '+':
                                    break;
                                default:
                                    Utils.ErrorMessage("Invalid keybind modifier '{0}'!", key[0]);
                                    return;
                            }
                            key = key.Substring(1);
                        }

                        string keyString = e[1].ToLower();
                        if (Raptor.Config.Keybinds.ContainsKey(keyString))
                            Raptor.Config.Keybinds[keyString].Add(e.Eol(2));
                        else
                            Raptor.Config.Keybinds.Add(keyString, new List<string> { e.Eol(2) });

                        File.WriteAllText("raptor.config", JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                        Utils.SuccessMessage("Bound the key '{0}' to '{1}'.", e.Eol(2), e[1]);
                    }
                    return;
                case "clr":
                case "clear":
                    {
                        Raptor.Config.Keybinds.Clear();
                        string configPath = "raptor.config";
                        File.WriteAllText(configPath, JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                        Utils.SuccessMessage("Cleared all key bindings.");
                    }
                    return;
                case "del":
                case "delete":
                case "remove":
                    {
                        if (e.Length == 1)
                        {
                            Utils.ErrorMessage("Syntax: .{0} {1} <keybind>", e[-1], e[0]);
                            return;
                        }

                        string key = e[1];
                        var keybind = new Input.Keybind();
                        while (!Utils.TryParseXNAKey(key, out keybind.Key))
                        {
                            switch (key[0])
                            {
                                case '!':
                                    break;
                                case '^':
                                    break;
                                case '+':
                                    break;
                                default:
                                    Utils.ErrorMessage("Invalid keybind modifier '{0}'!", key[0]);
                                    return;
                            }
                            key = key.Substring(1);
                        }

                        Raptor.Config.Keybinds.Remove(e[1].ToLower());
                        File.WriteAllText("raptor.config", JsonConvert.SerializeObject(Raptor.Config, Formatting.Indented));
                        Utils.SuccessMessage("Removed keybind '{0}'.", e[1]);
                    }
                    return;
                case "list":
                    Utils.SuccessMessage("Key Bindings:");
                    foreach (var kv in Raptor.Config.Keybinds)
                    {
                        Utils.InfoMessage("Keybind '{0}':", kv.Key);
                        foreach (var command in kv.Value)
                            Utils.InfoMessage("  {0}", command);
                    }
                    return;
                case "help":
                default:
                    Utils.SuccessMessage(".{0} help:", e[-1]);
                    Utils.InfoMessage(".{0} add <key combination> <command> - Adds to a keybind.", e[-1]);
                    Utils.InfoMessage(".{0} clr/clear - Clears all keybinds.", e[-1]);
                    Utils.InfoMessage(".{0} del/delete/remove <key combination> - Deletes a keybind.", e[-1]);
                    Utils.InfoMessage(".{0} list - Lists all keybinds.", e[-1]);
                    return;
            }
        }