Example #1
0
        private async Task LeaderboardAsync([Remainder] string lb = "")
        {
            await Context.Message.DeleteAsync();

            if (lb.Equals(""))
            {
                BotConfig conf  = BotConfig.Load();
                var       gconf = conf.GetConfig(Context.Guild.Id);
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Incorrect Command Usage", $"Correct Usage: `{gconf.Prefix}leaderboard <game name>`", false);

                return;
            }

            string leaderboard = "";

            if (lb.ToLower().Equals("connect 4") || lb.ToLower().Equals("connect4") || lb.ToLower().Equals("c4"))
            {
                leaderboard = "Connect 4";
            }
            else if (lb.ToLower().Equals("tic tac toe") || lb.ToLower().Equals("tictactoe") || lb.ToLower().Equals("ttt"))
            {
                leaderboard = "Tic Tac Toe";
            }
            else
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Leaderboard Error", $"Leaderboard with name '{lb}' could not be found.");

                return;
            }

            LoriLeaderboard fullLb = await LeaderboardDatabase.GetLeaderboardAsync(leaderboard, 10);

            var    top10 = fullLb.GetTop(10);
            string board = $"`{"pos", 5} {"Name", 30}   {"score",5}`";

            for (int i = 0; i < top10.Count; i++)
            {
                board += $"\n`[{i+1,3}] {top10[i].Name,30} - {top10[i].Score,5}`";
            }

            EmbedBuilder embed = new EmbedBuilder()
            {
                Title       = $"{leaderboard} - Top 10",
                Color       = Color.DarkPurple,
                Description = board,
                Footer      = new EmbedFooterBuilder()
                {
                    Text = fullLb.GetPositionAsString(Context.User.Id)
                }
            };

            await Context.Channel.SendMessageAsync(null, false, embed.Build());
        }
Example #2
0
        private async Task ConnectTurnAsunc(int column = -1)
        {
            await Context.Message.DeleteAsync();

            if (column < 1 || column > 7)
            {
                BotConfig conf  = BotConfig.Load();
                var       gconf = conf.GetConfig(Context.Guild.Id);
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Incorrect Command Usage", $"Correct Usage: `{gconf.Prefix}c4 <column>` - Column must be 1 - 7", false);

                return;
            }

            if (!GameHandler.DoesGameExist(Context.Guild.Id, GameType.CONNECT))
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "There is not a game in this guild.", false);

                return;
            }

            ConnectGame game = (ConnectGame)GameHandler.GetGame(Context.Guild.Id, GameType.CONNECT);

            if (game == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "The game could not be found.", false);

                return;
            }

            if (game.Players[0] != Context.User.Id && game.Players[1] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "You are not part of this game...");

                return;
            }

            if (game.Players[game.Turn] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Connect4 Error", "It is not your turn...");

                return;
            }

            GameHandler.TakeTurn(Context.Guild.Id, GameType.CONNECT, Context.User.Id, column);
            ulong winner = GameHandler.CheckForWinner(Context.Guild.Id, GameType.CONNECT);
            bool  draw   = GameHandler.CheckForDraw(Context.Guild.Id, GameType.CONNECT);

            IMessage oldMsg = await Context.Channel.GetMessageAsync(game.RenderId);

            await oldMsg.DeleteAsync();

            if (winner == 0L)
            {
                if (!draw)
                {
                    var nextUp = await Context.Guild.GetUserAsync(game.Players[game.Turn]);

                    string render = game.RenderGame();
                    var    msg    = await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                                        $"Next Up: {nextUp.Mention}\n" +
                                                                        $"`{CommandHandler.GetPrefix(Context.Guild.Id)}c4 <column>` to take your turn\n`{CommandHandler.GetPrefix(Context.Guild.Id)}c4 end` to end the game");

                    game.RenderId = msg.Id;
                }
                else
                {
                    string render = game.RenderGame();
                    await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                        $"DRAW ({(await Context.Guild.GetUserAsync(game.Players[0])).Mention} v {(await Context.Guild.GetUserAsync(game.Players[1])).Mention})");

                    if (ProfileDatabase.GetUser(game.Players[0]) != null)
                    {
                        ProfileDatabase.AddCurrency(game.Players[0], 100);
                    }
                    if (ProfileDatabase.GetUser(game.Players[1]) != null)
                    {
                        ProfileDatabase.AddCurrency(game.Players[1], 100);
                    }
                    GameHandler.EndGame(game);
                }
            }
            else
            {
                string render = game.RenderGame();
                await Context.Channel.SendFileAsync(render, $"**Connect 4**\n" +
                                                    $"Game Won by " + (await Context.Guild.GetUserAsync(winner)).Mention);

                var winwin = ProfileDatabase.GetUser(winner);
                if (winwin != null)
                {
                    ProfileDatabase.AddCurrency(winner, 250);
                    await LeaderboardDatabase.CheckAsync(winner, winwin.Name, "Connect 4");

                    await LeaderboardDatabase.AddScoreAsync(winner, "Connect 4");
                }
                GameHandler.EndGame(game);
            }
        }
Example #3
0
        private async Task TicTacToeTurnAsync(int x = -1, int y = -1)
        {
            await Context.Message.DeleteAsync();

            if (!GameHandler.DoesGameExist(Context.Guild.Id, GameType.TICTACTOE))
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...");

                return;
            }

            TicTacToeGame game = (TicTacToeGame)GameHandler.GetGame(Context.Guild.Id, GameType.TICTACTOE);

            if (game == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...");

                return;
            }

            if (game.Players[0] != Context.User.Id && game.Players[1] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "You are not part of this game...");

                return;
            }

            if (game.Players[game.Turn] != Context.User.Id)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "It is not your turn...");

                return;
            }

            if (x <= 0 || y <= 0 || x > 3 || y > 3)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "You need to choose and x and y between of 1, 2 or 3...");

                return;
            }

            GameHandler.TakeTurn(Context.Guild.Id, GameType.TICTACTOE, Context.User.Id, x, y);
            ulong winner = GameHandler.CheckForWinner(Context.Guild.Id, GameType.TICTACTOE);

            if (winner == 0L)
            {
                var oldMsg = await Context.Channel.GetMessageAsync(game.RenderId);

                await oldMsg.DeleteAsync();

                var nextUp = await Context.Guild.GetUserAsync(game.Players[game.Turn]);

                string render = game.RenderGame();
                var    msg    = await Context.Channel.SendFileAsync(render, $"**TicTacToe**\n" +
                                                                    $"Next Up: {nextUp.Mention}\n" +
                                                                    $"`{CommandHandler.GetPrefix(Context.Guild.Id)}t <x> <y>` to take your turn\n`{CommandHandler.GetPrefix(Context.Guild.Id)}t end` to end the game");

                game.RenderId = msg.Id;
            }
            else
            {
                IMessage msg = await Context.Channel.GetMessageAsync(game.RenderId);

                await msg.DeleteAsync();

                string render = game.RenderGame();
                await Context.Channel.SendFileAsync(render, $"**TicTacToe**\n" +
                                                    $"Game Won by " + (await Context.Guild.GetUserAsync(winner)).Mention);

                var winwin = ProfileDatabase.GetUser(winner);
                if (winwin != null)
                {
                    ProfileDatabase.AddCurrency(winner, 100);
                    await LeaderboardDatabase.CheckAsync(winner, winwin.Name, "Tic Tac Toe");

                    await LeaderboardDatabase.AddScoreAsync(winner, "Tic Tac Toe");
                }
                GameHandler.EndGame(game);
            }
        }