Пример #1
0
        public void OnInitialize()
        {
            SetupConfig();

            for (int i = 0; i < SSConfig.BuyRatePermissions.Length; i++)
            {
                BuyRatePermissions.Add(SSConfig.BuyRatePermissions[i]);
                BuyRates.Add(SSConfig.BuyRates[i]);
            }

            if (!Directory.Exists(ShopLogs))
            {
                Directory.CreateDirectory(ShopLogs);
            }

            if (!File.Exists(ShopLogSavePath))
            {
                File.Create(ShopLogSavePath).Close();
            }

            bool serverbuy = false;
            bool seehiddenprices = false;
            bool buy = false;
            bool buyrate = false;
            foreach (Group group in TShock.Groups.groups)
            {
                if (group.Name != "superadmin")
                {
                    if (group.HasPermission("serverbuy"))
                        serverbuy = true;
                    if (group.HasPermission("seehiddenprices"))
                        seehiddenprices = true;
                    if (group.HasPermission("buy"))
                        buy = true;
                    if (group.HasPermission("buyrate"))
                        buyrate = true;
                }
            }

            List<string> permlist = new List<string>();
            if (!serverbuy)
                permlist.Add("serverbuy");
            if (!seehiddenprices)
                permlist.Add("seehiddenprices");
            if (!buy)
                permlist.Add("buy");
            if (!buyrate)
                permlist.Add("buyrate");

            bool setshop = false;
            foreach (Group group in TShock.Groups.groups)
            {
                if (group.Name != "superadmin")
                {
                    if (group.HasPermission("setshop"))
                        setshop = true;
                }
            }
            if (!setshop)
                permlist.Add("setshop");

            TShock.Groups.AddPermissions("trustedadmin", permlist);
            Commands.ChatCommands.Add(new Command("buy", Buy, "buy"));
            Commands.ChatCommands.Add(new Command("serverbuy", Servershop, "servershop"));
            Commands.ChatCommands.Add(new Command("serverbuy", Servershop, "ss"));
            Commands.ChatCommands.Add(new Command("setshop", Setshop, "setshop"));
            Commands.ChatCommands.Add(new Command("buyrate", BuyRate, "buyrate"));
            SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            var table = new SqlTable("ServerShopCatalogue",
                new SqlColumn("ID", MySqlDbType.Int32) { Primary = true },
                new SqlColumn("Name", MySqlDbType.String, 255) { Unique = true },
                new SqlColumn("Price", MySqlDbType.Int32),
                new SqlColumn("MaxStack", MySqlDbType.Int32),
                new SqlColumn("InStock", MySqlDbType.Int32),
                new SqlColumn("ShopName", MySqlDbType.String, 255),
                new SqlColumn("Hidden", MySqlDbType.Int32),
                new SqlColumn("Permission", MySqlDbType.String, 255)
            );
            SQLWriter.EnsureExists(table);
            string alpha = "abcdefghijklmnopqrstuvwkyz";
            if (SQLEditor.ReadColumn("ServerShopCatalogue", "ID", new List<SqlValue>()).Count < 1)
            {
                Console.WriteLine("Creating Item Price List...");
                foreach (char letter in alpha)
                //for (Int32 i = 1; i < 364; i++ )
                {
                    string firstletter = "" + letter + "";
                    for (int k = 0; k < TShockAPI.TShock.Utils.GetItemByName(firstletter).Count; k++)
                    //for (Int32 k = 0; k < TShockAPI.TShock.Utils.GetItemByIdOrName(i.ToString()).Count; k++)
                    {
                        Item item = TShockAPI.TShock.Utils.GetItemByName(firstletter)[k];
                        int price = item.value / 5;
                        int i = item.type;
                        string space = " ";
                        string itemID = i.ToString();
                        string itemname = item.name;
                        string apostrophe = "'";
                        char[] apostrophetochar = apostrophe.ToCharArray();
                        itemname = itemname.Replace(apostrophetochar[0], ' ');
                        int itemmaxstack = item.maxStack;
                        List<SqlValue> list = new List<SqlValue>();
                        list.Add(new SqlValue("ID", i));
                        list.Add(new SqlValue("Name", "'" + itemname + "'"));
                        list.Add(new SqlValue("Price", price));
                        list.Add(new SqlValue("MaxStack", itemmaxstack));
                        list.Add(new SqlValue("InStock", 1));
                        list.Add(new SqlValue("ShopName", "'" + space + "'"));
                        list.Add(new SqlValue("Hidden", 0));
                        try
                        {
                            SQLEditor.InsertValues("ServerShopCatalogue", list);
                        }
                        catch (Exception) { }

                    }
                }
            }
            if (SQLEditor.ReadColumn("ServerShopCatalogue", "ID", new List<SqlValue>()).Count > 0)
            {
                Console.WriteLine("Loading Item Price List...");
                for (int i = 0; i < SQLEditor.ReadColumn("ServerShopCatalogue", "ID", new List<SqlValue>()).Count; i++)
                {
                    int id = Int32.Parse(SQLEditor.ReadColumn("ServerShopCatalogue", "ID", new List<SqlValue>())[i].ToString());
                    List<SqlValue> where = new List<SqlValue>();
                    where.Add(new SqlValue("ID", id));
                    string name = SQLEditor.ReadColumn("ServerShopCatalogue", "Name", where)[0].ToString();
                    int price = Int32.Parse(SQLEditor.ReadColumn("ServerShopCatalogue", "Price", where)[0].ToString());
                    bool instock = Int32.Parse(SQLEditor.ReadColumn("ServerShopCatalogue", "InStock", where)[0].ToString()) == 0 ? false : true;
                    string shopname = SQLEditor.ReadColumn("ServerShopCatalogue", "ShopName", where)[0].ToString();
                    bool hidden = Int32.Parse(SQLEditor.ReadColumn("ServerShopCatalogue", "Hidden", where)[0].ToString()) == 0 ? false : true;
                    string permission;
                    try
                    {
                        permission = SQLEditor.ReadColumn("ServerShopCatalogue", "Permission", where)[0].ToString();
                    }
                    catch (NullReferenceException)
                    {
                        permission = null;
                    }
                    SSCatalogue.Add(new ServerShopCatalogueItem(id, name, price, instock, shopname, permission, hidden));
                    if (!ShopList.Contains(shopname))
                        ShopList.Add(shopname);
                }
                for (int i = 0; i < ShopList.Count; i++ )
                {
                    if (ShopList[i] == " ")
                        ShopList.RemoveAt(i);
                }
            }
            SSCatalogueInStock = GetItemsInStock();
        }
Пример #2
0
        public void OnInitialize()
        {
            SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            bool setcost = false;
            bool freewarp = false;
            bool freetp = false;
            bool freeheal = false;
            bool freebuff = false;
            bool checkcommandcost = false;

            foreach (Group group in TShock.Groups.groups)
            {
                if (group.Name != "superadmin")
                {
                    if (group.HasPermission("setcost"))
                        setcost = true;
                    if (group.HasPermission("freewarp"))
                        freewarp = true;
                    if (group.HasPermission("freetp"))
                        freetp = true;
                    if (group.HasPermission("freeheal"))
                        freeheal = true;
                    if (group.HasPermission("freebuff"))
                        setcost = true;
                    if (group.HasPermission("checkcommandcost"))
                        checkcommandcost = true;
                }
            }

            List<string> permlist = new List<string>();
            if (!setcost)
                permlist.Add("setcost");
            if (!freewarp)
                permlist.Add("freewarp");
            if (!freetp)
                permlist.Add("freetp");
            if (!freeheal)
                permlist.Add("freeheal");
            if (!freebuff)
                permlist.Add("freebuff");
            if (!checkcommandcost)
                permlist.Add("checkcommandcost");
            TShock.Groups.AddPermissions("trustedadmin", permlist);

            Commands.ChatCommands.Add(new Command("setcost", SetCost, "setcost"));
            Commands.ChatCommands.Add(new Command("setcost", SetWarpCost, "setwarpcost"));
            Commands.ChatCommands.Add(new Command("checkcommandcost", CheckCommandCost, "checkcommandcost"));
            Commands.ChatCommands.Add(new Command("checkcommandcost", CheckWarpCost, "checkwarpcost"));
            var table = new SqlTable("CommandCosts",
                new SqlColumn("Command", MySqlDbType.String, 255) { Unique = true },
                new SqlColumn("Cost", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);
            if (SQLEditor.ReadColumn("CommandCosts", "Command", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> tp = new List<SqlValue>();
                tp.Add(new SqlValue("Command", "'" + "tp" + "'"));
                tp.Add(new SqlValue("Cost", 100));
                SQLEditor.InsertValues("CommandCosts", tp);
                List<SqlValue> heal = new List<SqlValue>();
                heal.Add(new SqlValue("Command", "'" + "heal" + "'"));
                heal.Add(new SqlValue("Cost", 100));
                SQLEditor.InsertValues("CommandCosts", heal);
                List<SqlValue> buff = new List<SqlValue>();
                buff.Add(new SqlValue("Command", "'" + "buff" + "'"));
                buff.Add(new SqlValue("Cost", 100));
                SQLEditor.InsertValues("CommandCosts", buff);
                List<SqlValue> warp = new List<SqlValue>();
                warp.Add(new SqlValue("Command", "'" + "warp" + "'"));
                warp.Add(new SqlValue("Cost", 100));
                SQLEditor.InsertValues("CommandCosts", warp);
            }
            List<SqlValue> where1 = new List<SqlValue>();
            where1.Add(new SqlValue("Command", "'" + "warp" + "'"));
            warpcost = Int32.Parse(SQLEditor.ReadColumn("CommandCosts", "Cost", where1)[0].ToString());
            List<SqlValue> where2 = new List<SqlValue>();
            where2.Add(new SqlValue("Command", "'" + "tp" + "'"));
            tpcost = Int32.Parse(SQLEditor.ReadColumn("CommandCosts", "Cost", where1)[0].ToString());
            List<SqlValue> where3 = new List<SqlValue>();
            where3.Add(new SqlValue("Command", "'" + "heal" + "'"));
            healcost = Int32.Parse(SQLEditor.ReadColumn("CommandCosts", "Cost", where1)[0].ToString());
            List<SqlValue> where4 = new List<SqlValue>();
            where4.Add(new SqlValue("Command", "'" + "buff" + "'"));
            buffcost = Int32.Parse(SQLEditor.ReadColumn("CommandCosts", "Cost", where1)[0].ToString());
        }
Пример #3
0
        internal void OnInitialize(EventArgs args)
        {
            if (C3Config.TeamColor1 < 1 || C3Config.TeamColor1 > 4 || C3Config.TeamColor1 == C3Config.TeamColor2 || C3Config.TeamColor2 > 4 || C3Config.TeamColor2 < 1)
                throw new Exception("Team Colours are inccorectly set up. Check c3config.json");

            SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());

            ApocalypseMonsters.AddNPCs();
            int ArenaCount;

            #region TestPerms
            //Checks to see if permissions have been moved around
            bool vote = false;
            bool joinvote = false;
            bool setflags = false;
            bool setspawns = false;
            bool managec3settings = false;
            bool cvote = false;
            bool duel = false;
            foreach (Group group in TShock.Groups.groups)
            {
                if (group.Name != "superadmin")
                {
                    if (group.HasPermission("vote"))
                        vote = true;
                    if (group.HasPermission("joinvote"))
                        joinvote = true;
                    if (group.HasPermission("setflags"))
                        setflags = true;
                    if (group.HasPermission("managec3settings"))
                        managec3settings = true;
                    if (group.HasPermission("cvote"))
                        cvote = true;
                    if (group.HasPermission("duel"))
                        duel = true;
                    if (group.HasPermission("setspawns"))
                        setspawns = true;
                }
            }
            List<string> perm = new List<string>();
            if (!vote)
                perm.Add("vote");
            if (!joinvote)
                perm.Add("joinvote");
            if (!duel)
                perm.Add("duel");
            TShock.Groups.AddPermissions("default", perm);

            perm.Clear();
            if (!setflags)
                perm.Add("setflags");
            if (!setflags)
                perm.Add("setspawns");
            if (!managec3settings)
                perm.Add("managec3settings");
            if (!cvote)
                perm.Add("cvote");
            if (!setspawns)
                perm.Add("setspawns");
            TShock.Groups.AddPermissions("trustedadmin", perm);
            #endregion
            //Converted v2.2
            #region AddCommands
            if (C3Mod.C3Config.TeamColor1 == 1)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Flag, "setctfredflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Spawn, "setctfredspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam1Spawn, "setoneflagredspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam1Spawn, "setduelredspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam1Spawn, "settdmredspawn"));
            }
            else if (C3Mod.C3Config.TeamColor1 == 2)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Flag, "setctfgreenflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Spawn, "setctfgreenspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam1Spawn, "setoneflaggreenspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam1Spawn, "setduelgreenspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam1Spawn, "settdmgreenspawn"));
            }
            else if (C3Mod.C3Config.TeamColor1 == 3)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Flag, "setctfblueflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Spawn, "setctfbluespawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam1Spawn, "setoneflagbluespawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam1Spawn, "setduelbluespawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam1Spawn, "settdmbluespawn"));
            }
            else if (C3Mod.C3Config.TeamColor1 == 4)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Flag, "setctfyellowflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam1Spawn, "setctfyellowspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam1Spawn, "setoneflagyellowspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam1Spawn, "setduelyellowspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam1Spawn, "settdmyellowspawn"));
            }
            if (C3Mod.C3Config.TeamColor2 == 1)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Flag, "setctfredflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Spawn, "setctfredspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam2Spawn, "setoneflagredspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam2Spawn, "setduelredspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam2Spawn, "settdmredspawn"));
            }
            else if (C3Mod.C3Config.TeamColor2 == 2)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Flag, "setctfgreenflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Spawn, "setctfgreenspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam2Spawn, "setoneflaggreenspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam2Spawn, "setduelgreenspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam2Spawn, "settdmgreenspawn"));
            }
            else if (C3Mod.C3Config.TeamColor2 == 3)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Flag, "setctfblueflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Spawn, "setctfbluespawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam2Spawn, "setoneflagbluespawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam2Spawn, "setduelbluespawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam2Spawn, "settdmbluespawn"));
            }
            else if (C3Mod.C3Config.TeamColor2 == 4)
            {
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Flag, "setctfyellowflag"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFTeam2Spawn, "setctfyellowspawn"));
                Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagTeam2Spawn, "setoneflagyellowspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelTeam2Spawn, "setduelyellowspawn"));
                Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMTeam2Spawn, "settdmyellowspawn"));
            }

            Commands.ChatCommands.Add(new Command("setflags", C3Commands.AddCTFArena, "addctfarena"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlag, "setoneflag"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.AddOneFlagArena, "addoneflagarena"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.AddDuelArena, "addduelarena"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.AddTDMArena, "addtdmarena"));

            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetFFASpawn, "setffaspawn"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.AddFFAArena, "addffaarena"));

            Commands.ChatCommands.Add(new Command("vote", C3Commands.StartVote, "vote"));
            Commands.ChatCommands.Add(new Command("joinvote", C3Commands.JoinVote, "join"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.Stop, "stop"));
            Commands.ChatCommands.Add(new Command(C3Commands.Quit, "quit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetCTFLimit, "setctflimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetOneFlagLimit, "setoneflaglimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetDuelLimit, "setduellimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetTDMLimit, "settdmlimit"));

            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetFFALimit, "setffalimit"));

            Commands.ChatCommands.Add(new Command("cvote", C3Commands.CancelVote, "cvote"));
            Commands.ChatCommands.Add(new Command("duel", C3Commands.ChallengePlayer, "duel"));
            Commands.ChatCommands.Add(new Command(C3Commands.AcceptChallenge, "accept"));

            Commands.ChatCommands.Add(new Command(C3Commands.ListArenaID, "list"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocPlayerSpawn, "setapocplayerspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocMonsterSpawn, "setapocmonsterspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocSpectatorSpawn, "setapocspectatorspawn"));
            #endregion

            #region FlagPoints

            var table = new SqlTable("FlagPoints",
                new SqlColumn("Name", MySqlDbType.Text),
                new SqlColumn("RedX", MySqlDbType.Int32),
                new SqlColumn("RedY", MySqlDbType.Int32),
                new SqlColumn("BlueX", MySqlDbType.Int32),
                new SqlColumn("BlueY", MySqlDbType.Int32),
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if ((ArenaCount = SQLEditor.ReadColumn("FlagPoints", "Name", new List<SqlValue>()).Count) != 0)
            {
                for (int i = 0; i < ArenaCount; i++)
                {
                    string name = SQLEditor.ReadColumn("FlagPoints", "Name", new List<SqlValue>())[i].ToString();
                    int redx = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "RedX", new List<SqlValue>())[i].ToString());
                    int redy = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "RedY", new List<SqlValue>())[i].ToString());
                    int bluex = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueX", new List<SqlValue>())[i].ToString());
                    int bluey = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueY", new List<SqlValue>())[i].ToString());
                    int redspawnx = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "RedSpawnX", new List<SqlValue>())[i].ToString());
                    int redspawny = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "RedSpawnY", new List<SqlValue>())[i].ToString());
                    int bluespawnx = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueSpawnX", new List<SqlValue>())[i].ToString());
                    int bluespawny = Int32.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueSpawnY", new List<SqlValue>())[i].ToString());

                    CTF.Arenas.Add(new CTFArena(new Vector2(redx, redy), new Vector2(bluex, bluey), new Vector2(redspawnx, redspawny), new Vector2(bluespawnx, bluespawny), name));
                }
            }

            #endregion

            #region DuelSpawns

            table = new SqlTable("DuelSpawns",
                new SqlColumn("Name", MySqlDbType.Text),
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if ((ArenaCount = SQLEditor.ReadColumn("DuelSpawns", "Name", new List<SqlValue>()).Count) != 0)
            {
                for (int i = 0; i < ArenaCount; i++)
                {
                    string name = SQLEditor.ReadColumn("DuelSpawns", "Name", new List<SqlValue>())[0].ToString();
                    int redx = Int32.Parse(SQLEditor.ReadColumn("DuelSpawns", "RedSpawnX", new List<SqlValue>())[0].ToString());
                    int redy = Int32.Parse(SQLEditor.ReadColumn("DuelSpawns", "RedSpawnY", new List<SqlValue>())[0].ToString());
                    int bluex = Int32.Parse(SQLEditor.ReadColumn("DuelSpawns", "BlueSpawnX", new List<SqlValue>())[0].ToString());
                    int bluey = Int32.Parse(SQLEditor.ReadColumn("DuelSpawns", "BlueSpawnY", new List<SqlValue>())[0].ToString());

                    Duel.Arenas.Add(new DuelArena(new Vector2(redx, redy), new Vector2(bluex, bluey), name));
                }
            }

            #endregion

            #region OneFlagPoints

            table = new SqlTable("OneFlagPoints",
                new SqlColumn("Name", MySqlDbType.Text),
                new SqlColumn("FlagX", MySqlDbType.Int32),
                new SqlColumn("FlagY", MySqlDbType.Int32),
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if ((ArenaCount = SQLEditor.ReadColumn("OneFlagPoints", "Name", new List<SqlValue>()).Count) != 0)
            {
                for (int i = 0; i < ArenaCount; i++)
                {
                    string name = SQLEditor.ReadColumn("OneFlagPoints", "Name", new List<SqlValue>())[i].ToString();
                    int flagx = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "FlagX", new List<SqlValue>())[i].ToString());
                    int flagy = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "FlagY", new List<SqlValue>())[i].ToString());
                    int redspawnx = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "RedSpawnX", new List<SqlValue>())[i].ToString());
                    int redspawny = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "RedSpawnY", new List<SqlValue>())[i].ToString());
                    int bluespawnx = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "BlueSpawnX", new List<SqlValue>())[i].ToString());
                    int bluespawny = Int32.Parse(SQLEditor.ReadColumn("OneFlagPoints", "BlueSpawnY", new List<SqlValue>())[i].ToString());

                    OneFlagCTF.Arenas.Add(new OneFlagArena(new Vector2(flagx, flagy), new Vector2(redspawnx, redspawny), new Vector2(bluespawnx, bluespawny), name));
                }
            }

            #endregion

            #region TDMSpawns

            table = new SqlTable("TDMSpawns",
                new SqlColumn("Name", MySqlDbType.Text),
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter.EnsureExists(table);

            if ((ArenaCount = SQLEditor.ReadColumn("TDMSpawns", "Name", new List<SqlValue>()).Count) != 0)
            {
                for (int i = 0; i < ArenaCount; i++)
                {
                    string name = SQLEditor.ReadColumn("TDMSpawns", "Name", new List<SqlValue>())[i].ToString();
                    int redx = Int32.Parse(SQLEditor.ReadColumn("TDMSpawns", "RedSpawnX", new List<SqlValue>())[i].ToString());
                    int redy = Int32.Parse(SQLEditor.ReadColumn("TDMSpawns", "RedSpawnY", new List<SqlValue>())[i].ToString());
                    int bluex = Int32.Parse(SQLEditor.ReadColumn("TDMSpawns", "BlueSpawnX", new List<SqlValue>())[i].ToString());
                    int bluey = Int32.Parse(SQLEditor.ReadColumn("TDMSpawns", "BlueSpawnY", new List<SqlValue>())[i].ToString());

                    TDM.Arenas.Add(new TDMArena(new Vector2(redx, redy), new Vector2(bluex, bluey), name));
                }
            }

            #endregion

            #region FFASpawns

            table = new SqlTable("FFASpawns",
                new SqlColumn("Name", MySqlDbType.Text),
                new SqlColumn("SpawnX", MySqlDbType.Int32),
                new SqlColumn("SpawnY", MySqlDbType.Int32)
            );
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter.EnsureExists(table);

            if ((ArenaCount = SQLEditor.ReadColumn("FFASpawns", "Name", new List<SqlValue>()).Count) != 0)
            {
                for (int i = 0; i < ArenaCount; i++)
                {
                    string name = SQLEditor.ReadColumn("FFASpawns", "Name", new List<SqlValue>())[i].ToString();
                    int x = Int32.Parse(SQLEditor.ReadColumn("FFASpawns", "SpawnX", new List<SqlValue>())[i].ToString());
                    int y = Int32.Parse(SQLEditor.ReadColumn("FFASpawns", "SpawnY", new List<SqlValue>())[i].ToString());

                    FFA.Arenas.Add(new FFAArena(new Vector2(x, y), name));
                }
            }

            #endregion

            #region Apocalypse

            table = new SqlTable("Apocalypse",
                new SqlColumn("SpawnX", MySqlDbType.Int32),
                new SqlColumn("SpawnY", MySqlDbType.Int32),
                new SqlColumn("MonsterSpawnX", MySqlDbType.Int32),
                new SqlColumn("MonsterSpawnY", MySqlDbType.Int32),
                new SqlColumn("SpectatorSpawnX", MySqlDbType.Int32),
                new SqlColumn("SpectatorSpawnY", MySqlDbType.Int32)
            );
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("Apocalypse", "SpawnX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("SpawnX", 0));
                list.Add(new SqlValue("SpawnY", 0));
                list.Add(new SqlValue("MonsterSpawnX", 0));
                list.Add(new SqlValue("MonsterSpawnY", 0));
                list.Add(new SqlValue("SpectatorSpawnX", 0));
                list.Add(new SqlValue("SpectatorSpawnY", 0));
                SQLEditor.InsertValues("Apocalypse", list);
            }
            else
            {
                Apocalypse.PlayerSpawn.X = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "SpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.PlayerSpawn.Y = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "SpawnY", new List<SqlValue>())[0].ToString());
                Apocalypse.MonsterSpawn.X = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "MonsterSpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.MonsterSpawn.Y = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "MonsterSpawnY", new List<SqlValue>())[0].ToString());
                Apocalypse.SpectatorArea.X = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "SpectatorSpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.SpectatorArea.Y = Int32.Parse(SQLEditor.ReadColumn("Apocalypse", "SpectatorSpawnY", new List<SqlValue>())[0].ToString());
            }

            #endregion
        }
Пример #4
0
        public void OnInitialize()
        {
            SQLEditor = new SqlTableEditor(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());

            ApocalypseMonsters.AddNPCs();

            #region TestPerms
            //Checks to see if permissions have been moved around
            bool vote = false;
            bool joinvote = false;
            bool setflags = false;
            bool setspawns = false;
            bool managec3settings = false;
            bool cvote = false;
            bool duel = false;
            foreach (Group group in TShock.Groups.groups)
            {
                if (group.Name != "superadmin")
                {
                    if (group.HasPermission("vote"))
                        vote = true;
                    if (group.HasPermission("joinvote"))
                        joinvote = true;
                    if (group.HasPermission("setflags"))
                        setflags = true;
                    if (group.HasPermission("managec3settings"))
                        managec3settings = true;
                    if (group.HasPermission("cvote"))
                        cvote = true;
                    if (group.HasPermission("duel"))
                        duel = true;
                    if (group.HasPermission("setspawns"))
                        setspawns = true;
                }
            }
            List<string> perm = new List<string>();
            if (!vote)
                perm.Add("vote");
            if (!joinvote)
                perm.Add("joinvote");
            if (!duel)
                perm.Add("duel");
            TShock.Groups.AddPermissions("default", perm);

            perm.Clear();
            if (!setflags)
                perm.Add("setflags");
            if (!setflags)
                perm.Add("setspawns");
            if (!managec3settings)
                perm.Add("managec3settings");
            if (!cvote)
                perm.Add("cvote");
            if (!setspawns)
                perm.Add("setspawns");
            TShock.Groups.AddPermissions("trustedadmin", perm);
            #endregion

            #region AddCommands
            //Adds C3Commands
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFRedFlag, "setctfredflag"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetCTFBlueFlag, "setctfblueflag"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlag, "setoneflag"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagRedSpawn, "setoneflagredspawn"));
            Commands.ChatCommands.Add(new Command("setflags", C3Commands.SetOneFlagBlueSpawn, "setoneflagbluespawn"));
            Commands.ChatCommands.Add(new Command("vote", C3Commands.StartVote, "vote"));
            Commands.ChatCommands.Add(new Command("joinvote", C3Commands.JoinVote, "join"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetCTFLimit, "setctflimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetOneFlagLimit, "setoneflaglimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetDuelLimit, "setduellimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.SetTDMLimit, "settdmlimit"));
            Commands.ChatCommands.Add(new Command("managec3settings", C3Commands.Stop, "stop"));
            Commands.ChatCommands.Add(new Command("cvote", C3Commands.CancelVote, "cvote"));
            Commands.ChatCommands.Add(new Command("duel", C3Commands.ChallengePlayer, "duel"));
            Commands.ChatCommands.Add(new Command(C3Commands.AcceptChallenge, "accept"));
            Commands.ChatCommands.Add(new Command(C3Commands.Quit, "quit"));
            Commands.ChatCommands.Add(new Command(C3Commands.Teams, "teams"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelBlueSpawn, "setduelbluespawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetDuelRedSpawn, "setduelredspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMBlueSpawn, "settdmbluespawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetTDMRedSpawn, "settdmredspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocPlayerSpawn, "setapocplayerspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocMonsterSpawn, "setapocmonsterspawn"));
            Commands.ChatCommands.Add(new Command("setspawns", C3Commands.SetApocSpectatorSpawn, "setapocspectatorspawn"));
            #endregion

            #region FlagPoints

            var table = new SqlTable("FlagPoints",
                new SqlColumn("RedX", MySqlDbType.Int32),
                new SqlColumn("RedY", MySqlDbType.Int32),
                new SqlColumn("BlueX", MySqlDbType.Int32),
                new SqlColumn("BlueY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("FlagPoints", "RedX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("RedX", 0));
                list.Add(new SqlValue("RedY", 0));
                list.Add(new SqlValue("BlueX", 0));
                list.Add(new SqlValue("BlueY", 0));
                SQLEditor.InsertValues("FlagPoints", list);
            }
            else
            {
                CTF.flagPoints[0].X = float.Parse(SQLEditor.ReadColumn("FlagPoints", "RedX", new List<SqlValue>())[0].ToString());
                CTF.flagPoints[0].Y = float.Parse(SQLEditor.ReadColumn("FlagPoints", "RedY", new List<SqlValue>())[0].ToString());
                CTF.flagPoints[1].X = float.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueX", new List<SqlValue>())[0].ToString());
                CTF.flagPoints[1].Y = float.Parse(SQLEditor.ReadColumn("FlagPoints", "BlueY", new List<SqlValue>())[0].ToString());
            }

            #endregion

            #region DuelSpawns

            table = new SqlTable("DuelSpawns",
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("DuelSpawns", "RedSpawnX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("RedSpawnX", 0));
                list.Add(new SqlValue("RedSpawnY", 0));
                list.Add(new SqlValue("BlueSpawnX", 0));
                list.Add(new SqlValue("BlueSpawnY", 0));
                SQLEditor.InsertValues("DuelSpawns", list);
            }
            else
            {
                Duel.DuelSpawns[0].X = float.Parse(SQLEditor.ReadColumn("DuelSpawns", "RedSpawnX", new List<SqlValue>())[0].ToString());
                Duel.DuelSpawns[0].Y = float.Parse(SQLEditor.ReadColumn("DuelSpawns", "RedSpawnY", new List<SqlValue>())[0].ToString());
                Duel.DuelSpawns[1].X = float.Parse(SQLEditor.ReadColumn("DuelSpawns", "BlueSpawnX", new List<SqlValue>())[0].ToString());
                Duel.DuelSpawns[1].Y = float.Parse(SQLEditor.ReadColumn("DuelSpawns", "BlueSpawnY", new List<SqlValue>())[0].ToString());
            }

            #endregion

            #region OneFlagPoints

            table = new SqlTable("OneFlagPoints",
                new SqlColumn("FlagX", MySqlDbType.Int32),
                new SqlColumn("FlagY", MySqlDbType.Int32),
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("OneFlagPoints", "RedSpawnX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("FlagX", 0));
                list.Add(new SqlValue("FlagY", 0));
                list.Add(new SqlValue("RedSpawnX",0));
                list.Add(new SqlValue("RedSpawnY", 0));
                list.Add(new SqlValue("BlueSpawnX", 0));
                list.Add(new SqlValue("BlueSpawnY", 0));
                SQLEditor.InsertValues("OneFlagPoints", list);
            }
            else
            {
                OneFlagCTF.FlagPoint.X = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "FlagX", new List<SqlValue>())[0].ToString());
                OneFlagCTF.FlagPoint.Y = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "FlagY", new List<SqlValue>())[0].ToString());
                OneFlagCTF.SpawnPoint[0].X = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "RedSpawnX", new List<SqlValue>())[0].ToString());
                OneFlagCTF.SpawnPoint[0].Y = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "RedSpawnY", new List<SqlValue>())[0].ToString());
                OneFlagCTF.SpawnPoint[1].X = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "BlueSpawnX", new List<SqlValue>())[0].ToString());
                OneFlagCTF.SpawnPoint[1].Y = float.Parse(SQLEditor.ReadColumn("OneFlagPoints", "BlueSpawnY", new List<SqlValue>())[0].ToString());
            }

            #endregion

            #region TDMSpawns

            table = new SqlTable("TDMSpawns",
                new SqlColumn("RedSpawnX", MySqlDbType.Int32),
                new SqlColumn("RedSpawnY", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnX", MySqlDbType.Int32),
                new SqlColumn("BlueSpawnY", MySqlDbType.Int32)
            );
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("TDMSpawns", "RedSpawnX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("RedSpawnX",0));
                list.Add(new SqlValue("RedSpawnY", 0));
                list.Add(new SqlValue("BlueSpawnX", 0));
                list.Add(new SqlValue("BlueSpawnY", 0));
                SQLEditor.InsertValues("TDMSpawns", list);
            }
            else
            {
                TDM.TDMSpawns[0].X = float.Parse(SQLEditor.ReadColumn("TDMSpawns", "RedSpawnX", new List<SqlValue>())[0].ToString());
                TDM.TDMSpawns[0].Y = float.Parse(SQLEditor.ReadColumn("TDMSpawns", "RedSpawnY", new List<SqlValue>())[0].ToString());
                TDM.TDMSpawns[1].X = float.Parse(SQLEditor.ReadColumn("TDMSpawns", "BlueSpawnX", new List<SqlValue>())[0].ToString());
                TDM.TDMSpawns[1].Y = float.Parse(SQLEditor.ReadColumn("TDMSpawns", "BlueSpawnY", new List<SqlValue>())[0].ToString());
            }

            #endregion

            #region Apocalypse

            table = new SqlTable("Apocalypse",
                new SqlColumn("SpawnX", MySqlDbType.Int32),
                new SqlColumn("SpawnY", MySqlDbType.Int32),
                new SqlColumn("MonsterSpawnX", MySqlDbType.Int32),
                new SqlColumn("MonsterSpawnY", MySqlDbType.Int32),
                new SqlColumn("SpectatorSpawnX", MySqlDbType.Int32),
                new SqlColumn("SpectatorSpawnY", MySqlDbType.Int32)
            );
            SQLWriter = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
            SQLWriter.EnsureExists(table);

            if (SQLEditor.ReadColumn("Apocalypse", "SpawnX", new List<SqlValue>()).Count == 0)
            {
                List<SqlValue> list = new List<SqlValue>();
                list.Add(new SqlValue("SpawnX", 0));
                list.Add(new SqlValue("SpawnY", 0));
                list.Add(new SqlValue("MonsterSpawnX", 0));
                list.Add(new SqlValue("MonsterSpawnY", 0));
                list.Add(new SqlValue("SpectatorSpawnX", 0));
                list.Add(new SqlValue("SpectatorSpawnY", 0));
                SQLEditor.InsertValues("Apocalypse", list);
            }
            else
            {
                Apocalypse.PlayerSpawn.X = float.Parse(SQLEditor.ReadColumn("Apocalypse", "SpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.PlayerSpawn.Y = float.Parse(SQLEditor.ReadColumn("Apocalypse", "SpawnY", new List<SqlValue>())[0].ToString());
                Apocalypse.MonsterSpawn.X = float.Parse(SQLEditor.ReadColumn("Apocalypse", "MonsterSpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.MonsterSpawn.Y = float.Parse(SQLEditor.ReadColumn("Apocalypse", "MonsterSpawnY", new List<SqlValue>())[0].ToString());
                Apocalypse.SpectatorArea.X = float.Parse(SQLEditor.ReadColumn("Apocalypse", "SpectatorSpawnX", new List<SqlValue>())[0].ToString());
                Apocalypse.SpectatorArea.Y = float.Parse(SQLEditor.ReadColumn("Apocalypse", "SpectatorSpawnY", new List<SqlValue>())[0].ToString());
            }

            #endregion
        }