Example #1
0
        private static void ModPvP(CommandArgs args)
        {
            var      player   = args.Player;
            var      input    = args.Parameters;
            int      id       = -1;
            DbObject dbObject = null;

            if (input.Count < 1 || !StringConsts.TryGetSectionFromString(input[0], out var section))
            {
                player.SendErrorMessage(HelpModPvP);
                return;
            }

            if (section == StringConsts.Help)
            {
                if (input.Count > 1)
                {
                    StringConsts.TryGetSectionFromString(input[1], out var helpsection);

                    switch (helpsection)
                    {
                    case StringConsts.Database:
                        player.SendMessage(DatabaseAttributes, Color.Yellow);
                        return;

                    case StringConsts.Config:
                        player.SendMessage(ConfigAttributes, Color.Yellow);
                        return;

                    default:
                        player.SendErrorMessage(InvalidSyntax + AttributesHelp);
                        return;
                    }
                }

                player.SendErrorMessage(AttributesHelp);
                return;
            }

            if (section != StringConsts.Config)
            {
                if (input.Count < 3)
                {
                    player.SendErrorMessage(HelpModPvP);
                    return;
                }

                if (!int.TryParse(input[1], out id))
                {
                    var foundItems = TShock.Utils.GetIdFromInput(section, input[1]);
                    if (foundItems.Count == 1)
                    {
                        id = foundItems[0];
                    }
                    else if (foundItems.Count > 1)
                    {
                        player.SendErrorMessage("Found Multiple items");
                        foreach (int item in foundItems)
                        {
                            player.SendMessage($"({item}) {MiscUtils.GetNameFromInput(section, item)}", Color.Yellow);
                        }
                        return;
                    }
                    else
                    {
                        player.SendErrorMessage(NothingFoundError);
                        return;
                    }
                }

                dbObject = Cache.GetSection(section, id);
                if (dbObject == null)
                {
                    player.SendErrorMessage(NothingFoundError);
                    return;
                }

                if (input.Count < 4)
                {
                    player.SendErrorMessage(InvalidSyntax + "Please enter value(s) for the attribute(s).");
                    return;
                }
            }
            else
            {
                if (input.Count < 3)
                {
                    player.SendErrorMessage(HelpModPvP);
                    return;
                }
            }

            var pairedInputs = MiscUtils.SplitIntoPairs(input.Skip((section != StringConsts.Config).ToInt() + 1).ToArray());

            foreach (var pair in pairedInputs)
            {
                var attribute = "";
                if (section != StringConsts.Config)
                {
                    StringConsts.TryGetDatabaseAttributeFromString(pair[0], out attribute);
                }
                else
                {
                    StringConsts.TryGetConfigValueFromString(pair[0], out attribute);
                }

                pair[0] = attribute;
            }

            switch (section)
            {
            case DbTables.ItemTable:
            case DbTables.ProjectileTable:
            case DbTables.BuffTable:
                string name = MiscUtils.GetNameFromInput(section, id);
                player.SendMessage($"Modifying {name} ({id})", Color.Green);

                foreach (var pair in pairedInputs)
                {
                    if (dbObject.TrySetValue(pair[0], pair[1]))
                    {
                        player.SendMessage($"Set {pair[0]} to {pair[1]}", Color.YellowGreen);
                        if (args.Silent)
                        {
                            PvPModifier.Webhook.Send(player.Account.Name, section, name, pair[0], pair[1]);
                        }
                    }
                    else
                    {
                        player.SendErrorMessage(InvalidValue(pair[0], section));
                    }
                }

                if (dbObject is DbItem)
                {
                    foreach (var pvper in PvPModifier.ActivePlayers)
                    {
                        if (!pvper.TPlayer.hostile)
                        {
                            continue;
                        }

                        int itemindex = pvper.TPlayer.FindItem(id);
                        if (itemindex != -1)
                        {
                            SSCUtils.FillInventoryToIndex(pvper, 0, Constants.JunkItem, itemindex);
                            var item = pvper.TPlayer.inventory[itemindex];
                            SSCUtils.SetItem(pvper, (byte)itemindex, 0);
                            pvper.InvTracker.AddItem(PvPUtils.GetCustomWeapon(pvper, id, item.prefix, (short)item.stack));
                        }
                        pvper.InvTracker.StartDroppingItems();
                    }
                }

                break;

            case StringConsts.Config:
                foreach (var pair in pairedInputs)
                {
                    if (MiscUtils.SetValueWithString(PvPModifier.Config, pair[0], pair[1]))
                    {
                        player.SendSuccessMessage($"Set {pair[0]} to {pair[1]}");
                    }
                    else
                    {
                        player.SendErrorMessage(ConfigValueFail(pair[0], pair[1]));
                    }
                }

                PvPModifier.Config.Write(Config.ConfigPath);
                break;

            default:
                player.SendErrorMessage(HelpModPvP);
                return;
            }
        }
Example #2
0
        private static void ResetPvP(CommandArgs args)
        {
            Console.WriteLine("Enter Cms");
            Console.WriteLine("MaxAI: " + Terraria.Projectile.maxAI);
            args.Player.SendErrorMessage("" + Terraria.Projectile.maxAI);

            var player = args.Player;
            var input  = args.Parameters;

            if (input.Count < 1 || !StringConsts.TryGetSectionFromString(input[0], out var section))
            {
                player.SendErrorMessage(InvalidSyntax + ResetList);
                return;
            }

            switch (section)
            {
            case StringConsts.Database:
                Database.InitDefaultTables();
                Database.LoadDatabase();
                foreach (var pvper in PvPModifier.ActivePlayers)
                {
                    PvPUtils.RefreshInventory(pvper);
                }
                player.SendSuccessMessage("Reset database to default.");
                return;

            case StringConsts.Config:
                PvPModifier.Config.ResetConfigValues();
                PvPModifier.Config.Write(Config.ConfigPath);
                player.SendSuccessMessage("Reset config values to default.");
                return;

            case DbTables.ItemTable:
            case DbTables.ProjectileTable:
            case DbTables.BuffTable:
                if (input.Count < 2)
                {
                    player.SendErrorMessage("Please provide a valid id or name.");
                    return;
                }
                if (!int.TryParse(input[1], out int id))
                {
                    var foundList = TShock.Utils.GetIdFromInput(section, input[1]);
                    id = foundList[0];
                    if (foundList.Count == 0)
                    {
                        player.SendErrorMessage("Please provide a valid id or name.");
                        return;
                    }

                    if (foundList.Count > 1)
                    {
                        player.SendErrorMessage("Found multiple of input");
                        foreach (int items in foundList)
                        {
                            player.SendMessage($"({items}) {MiscUtils.GetNameFromInput(section, items)}", Color.Yellow);
                        }
                        return;
                    }
                }

                /*
                 * if (!int.TryParse(input[1], out int id))
                 * {
                 *  var foundList = TShock.Utils.GetIdFromInput(section, input[1]);
                 *  id = foundList[0];
                 * }
                 */

                Database.DeleteRow(section, id);
                Database.Query(Database.GetDefaultValueSqlString(section, id));

                string log = "Reset the values of {0}".SFormat(MiscUtils.GetNameFromInput(section, id));
                if (section == DbTables.ItemTable)
                {
                    foreach (var pvper in PvPModifier.ActivePlayers)
                    {
                        PvPUtils.RefreshItem(pvper, id);
                    }
                }
                player.SendSuccessMessage(log);
                Database.LoadDatabase();
                PvPModifier.Config.LogChange($"[{player.Name} ({DateTime.Now})] {log}");
                break;

            default:
                player.SendErrorMessage("Invalid parameters. " + ResetList);
                return;
            }
        }
Example #3
0
        private static void CheckStat(CommandArgs args)
        {
            var player = args.Player;
            var input  = args.Parameters;

            if (input.Count != 2 || !StringConsts.TryGetSectionFromString(input[0], out string section))
            {
                player.SendErrorMessage(InvalidCheckStat);
                return;
            }

            if (!int.TryParse(input[1], out int id))
            {
                var foundItems = TShock.Utils.GetIdFromInput(section, input[1]);
                if (foundItems.Count == 1)
                {
                    id = foundItems[0];
                }
                else if (foundItems.Count > 1)
                {
                    player.SendErrorMessage("Found Multiple items");
                    foreach (int item in foundItems)
                    {
                        player.SendMessage($"({item}) {MiscUtils.GetNameFromInput(section, item)}", Color.Yellow);
                    }
                    return;
                }
                else
                {
                    player.SendErrorMessage(NothingFoundError);
                    return;
                }
            }

            switch (section)
            {
            case DbTables.ItemTable:
                if (id > 0 && id < Terraria.Main.maxItemTypes)
                {
                    player.SendMessage(Cache.Items[id].ToString(), Color.YellowGreen);
                    player.SendMessage(ScrollUp + "\n" + NegativeExplanation, Color.Yellow);
                }
                return;

            case DbTables.ProjectileTable:
                if (id > 0 && id < Terraria.Main.maxProjectileTypes)
                {
                    player.SendMessage(Cache.Projectiles[id].ToString(), Color.YellowGreen);
                    player.SendMessage(ScrollUp + "\n" + NegativeExplanation, Color.Yellow);
                }
                return;

            case DbTables.BuffTable:
                if (id > 0 && id < Terraria.Main.maxBuffTypes)
                {
                    player.SendMessage(Cache.Buffs[id].ToString(), Color.YellowGreen);
                    player.SendMessage(ScrollUp + "\n" + NegativeExplanation, Color.Yellow);
                }
                return;

            case StringConsts.Config:
                player.SendErrorMessage(InvalidCheckStat);
                return;
            }

            player.SendErrorMessage(OverflowID);
        }