示例#1
0
        private async Task BankTransferAsync(IUser user = null, float amount = 0)
        {
            await Context.Message.DeleteAsync();

            BotConfig conf  = BotConfig.Load();
            var       gconf = conf.GetConfig(Context.Guild.Id);

            if (user == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Incorrect Command Usage", $"Correct Usage: `{gconf.Prefix}bank transfer <@user> <amount>`", false);

                return;
            }

            if (amount <= 0)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"The amount must be greater than 0.");

                return;
            }

            LoriUser profile = ProfileDatabase.GetUser(Context.User.Id);

            if (profile == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find your bank account.");

                return;
            }

            LoriUser profile2 = ProfileDatabase.GetUser(user.Id);

            if (profile2 == null)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", $"We could not find {user.Username}'s bank account.");

                return;
            }

            if (profile.GetCurrency() >= amount)
            {
                await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "Transfer Error", "You can not afford this transfer.");

                return;
            }

            ProfileDatabase.AddCurrency(Context.User.Id, -amount);
            ProfileDatabase.AddCurrency(user.Id, amount);

            float newAmt = profile.GetCurrency();

            EmbedBuilder embed = new EmbedBuilder()
            {
                Color       = Color.DarkPurple,
                Title       = "Transfer successful",
                Description = $"Successfully transferred ${amount} to {user.Username}.\nNew balance: ${newAmt}"
            };

            await Context.Channel.SendMessageAsync(null, false, embed.Build());
        }
示例#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);
            }
        }
示例#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);
            }
        }