Ejemplo n.º 1
0
        public static async Task GameTimeout(SocketUser user, BlackjackGame game)
        {
            {
                EmbedBuilder eb  = new EmbedBuilder();
                var          bot = game.Message.Author.Id;

                game.Stand();

                if (game.SumHand(game.Hand) > 21)
                {
                    await BalanceDb.AddToasties(bot, game.Toasties, game.Channel.Guild.Id);

                    eb.WithAuthor(user.Username + " | Timeout", user.GetAvatarUrl());
                    eb.WithDescription("Your hand is a bust. You lose `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                       "New balance `" + BalanceDb.GetToasties(user.Id, game.Channel.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                    eb.WithColor(Color.DarkRed);
                }

                else if (game.SumHand(game.Hand) > game.SumHand(game.Dealer) || game.SumHand(game.Dealer) > 21)
                {
                    await BalanceDb.AddToasties(user.Id, game.Toasties * 2, game.Channel.Guild.Id);

                    await BalanceDb.AddToasties(bot, -game.Toasties, game.Channel.Guild.Id);

                    eb.WithAuthor(user.Username + " | Timeout", user.GetAvatarUrl());
                    eb.WithDescription("Your score is higher than Namiko's. You win `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                       "New balance `" + BalanceDb.GetToasties(user.Id, game.Channel.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                    eb.WithColor(Color.Gold);
                }

                else if (game.SumHand(game.Hand) == game.SumHand(game.Dealer))
                {
                    await BalanceDb.AddToasties(user.Id, game.Toasties, game.Channel.Guild.Id);

                    eb.WithAuthor(user.Username + " | Timeout", user.GetAvatarUrl());
                    eb.WithDescription("Your score is tied with Namiko's. You get your " + ToastieUtil.RandomEmote() + " back!\n" +
                                       "Your balance `" + BalanceDb.GetToasties(user.Id, game.Channel.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                    eb.WithColor(Color.DarkGreen);
                }

                else
                {
                    await BalanceDb.AddToasties(bot, game.Toasties, game.Channel.Guild.Id);

                    eb.WithAuthor(user.Username + " | Timeout", user.GetAvatarUrl());
                    eb.WithDescription("Namiko's score is higher. You lose `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                       "New balance `" + BalanceDb.GetToasties(user.Id, game.Channel.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                    eb.WithColor(Color.DarkRed);
                }

                eb.AddField("Your hand (" + game.SumHand(game.Hand) + ")", HandToString(game.Hand, false), true);
                eb.AddField("Namiko's hand (" + game.SumHand(game.Dealer) + ")", HandToString(game.Dealer, false), true);

                await Send(game, eb);

                games.Remove(user);
            }
        }
Ejemplo n.º 2
0
        public async Task BlackjackCommand(string sAmount, [Remainder] string str = "")
        {
            var user = (SocketGuildUser)Context.User;
            var ch   = (SocketTextChannel)Context.Channel;

            if (Blackjack.games.ContainsKey(Context.User))
            {
                await Context.Channel.SendMessageAsync("You are already in a game of blackjack. #" + Blackjack.games[user].Channel.Name);

                return;
            }

            int amount = ToastieUtil.ParseAmount(sAmount, user);

            if (amount < 0)
            {
                await Context.Channel.SendMessageAsync("Pick an amount! number, all, half, or x/y.");

                return;
            }
            if (amount == 0)
            {
                await Context.Channel.SendMessageAsync("You have no toasties...");

                return;
            }

            try
            {
                await BalanceDb.AddToasties(user.Id, -amount, Context.Guild.Id);
            }
            catch (Exception e)
            {
                await ch.SendMessageAsync(e.Message);

                return;
            }

            if (BalanceDb.GetToasties(Context.Client.CurrentUser.Id, Context.Guild.Id) < amount)
            {
                string prefix = Program.GetPrefix(Context);
                await Context.Channel.SendMessageAsync("Tch, I don't have enough toasties... I will recover eventually by stealing toasties from all of you. :fox:" +
                                                       $"But if you want to speed up the process you can give me some using the `{prefix}give` or `{prefix}at` commands.");

                await BalanceDb.AddToasties(user.Id, amount, Context.Guild.Id);

                return;
            }

            BlackjackGame game = new BlackjackGame(amount, ch);

            Blackjack.games[user] = game;
            await Blackjack.GameContinue(Context, game);
        }
Ejemplo n.º 3
0
 public static async Task Send(BlackjackGame game, EmbedBuilder eb)
 {
     if (game.Message == null)
     {
         game.Message = await game.Channel.SendMessageAsync("", false, eb.Build());
     }
     else
     {
         await game.Message.ModifyAsync(msg => msg.Embed = eb.Build());
     }
 }
Ejemplo n.º 4
0
        public static async Task GameEnd(SocketCommandContext Context, BlackjackGame game)
        {
            EmbedBuilder eb   = new EmbedBuilder();
            var          user = Context.User;

            if (game.SumHand(game.Hand) > 21)
            {
                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, game.Toasties, Context.Guild.Id);

                eb.WithAuthor(user.Username + " | You Lose", user.GetAvatarUrl());
                eb.WithDescription("Your hand is a bust. You lose `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                   "New balance `" + BalanceDb.GetToasties(user.Id, Context.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                eb.WithColor(Color.DarkRed);
            }

            else if (game.SumHand(game.Hand) > game.SumHand(game.Dealer) || game.SumHand(game.Dealer) > 21)
            {
                await BalanceDb.AddToasties(user.Id, game.Toasties * 2, Context.Guild.Id);

                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, -game.Toasties, Context.Guild.Id);

                eb.WithAuthor(user.Username + " | You Win", user.GetAvatarUrl());
                eb.WithDescription("Your score is higher than Namiko's. You win `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                   "New balance `" + BalanceDb.GetToasties(user.Id, Context.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                eb.WithColor(Color.Gold);
            }

            else if (game.SumHand(game.Hand) == game.SumHand(game.Dealer))
            {
                await BalanceDb.AddToasties(user.Id, game.Toasties, Context.Guild.Id);

                eb.WithAuthor(user.Username + " | Tie", user.GetAvatarUrl());
                eb.WithDescription("Your score is tied with Namiko's. You get your " + ToastieUtil.RandomEmote() + " back!\n" +
                                   "Your balance `" + BalanceDb.GetToasties(user.Id, Context.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                eb.WithColor(Color.DarkGreen);
            }

            else
            {
                await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, game.Toasties, Context.Guild.Id);

                eb.WithAuthor(user.Username + " | You Lose", user.GetAvatarUrl());
                eb.WithDescription("Namiko's score is higher. You lose `" + game.Toasties + "` " + ToastieUtil.RandomEmote() + "\n" +
                                   "New balance `" + BalanceDb.GetToasties(user.Id, Context.Guild.Id) + "` " + ToastieUtil.RandomEmote());
                eb.WithColor(Color.DarkRed);
            }

            eb.AddField("Your hand (" + game.SumHand(game.Hand) + ")", HandToString(game.Hand, false), true);
            eb.AddField("Namiko's hand (" + game.SumHand(game.Dealer) + ")", HandToString(game.Dealer, false), true);

            await Send(game, eb);

            games.Remove(user);
        }
Ejemplo n.º 5
0
        public static async Task Hit(SocketCommandContext Context, BlackjackGame game)
        {
            int value = game.Hit();

            if (value < 22)
            {
                await GameContinue(Context, game);
            }

            else
            {
                await GameEnd(Context, game);
            }
        }
Ejemplo n.º 6
0
        public static async Task DoubleDown(SocketCommandContext Context, BlackjackGame game)
        {
            try
            {
                await BalanceDb.AddToasties(Context.User.Id, -game.Toasties, Context.Guild.Id);

                game.Toasties *= 2;
                game.Hit();
                await Stand(Context, game);
            }
            catch (Exception e)
            {
                await Context.Channel.SendMessageAsync(e.Message);
            }
        }
Ejemplo n.º 7
0
        public static async Task GameContinue(SocketCommandContext Context, BlackjackGame game)
        {
            EmbedBuilder eb   = new EmbedBuilder();
            var          user = Context.User;

            eb.WithAuthor(user.Username + " | Blackjack", user.GetAvatarUrl());
            eb.WithDescription("You started a game of blackjack against Namiko! The one closest to 21 wins!\n" +
                               String.Format("{0,10} - to draw another card.\n", "**hit**") +
                               String.Format("{0,10} - to finalize and let Namiko draw.\n", "**stand**") +
                               String.Format("{0,10} - to double your bet and draw only 1 card.\n", "**double**") +
                               String.Format("{0,10} - to forfeit and get half your toasties back.", "**forfeit**"));
            eb.AddField("Your hand (" + game.SumHand(game.Hand) + ")", HandToString(game.Hand, false), true);
            eb.AddField("Namiko's hand (" + game.CardValue(game.Dealer[0]) + ")", HandToString(game.Dealer, true), true);
            eb.WithColor(Color.Green);

            game.Refresh = DateTime.Now;
            await Send(game, eb);
        }
Ejemplo n.º 8
0
        public static async Task Forfeit(SocketCommandContext Context, BlackjackGame game)
        {
            var user = Context.User;

            await BalanceDb.AddToasties(user.Id, game.Toasties / 2, Context.Guild.Id);

            await BalanceDb.AddToasties(Context.Client.CurrentUser.Id, game.Toasties / 2, Context.Guild.Id);

            EmbedBuilder eb = new EmbedBuilder();

            eb.WithAuthor(user.Username + " | You Lose", null, user.GetAvatarUrl());
            eb.WithDescription("You forfeit. You get half your toasties back. Lost `" + game.Toasties / 2 + "`" + ToastieUtil.RandomEmote() + "\n" +
                               "New balance `" + BalanceDb.GetToasties(user.Id, Context.Guild.Id) + "`" + ToastieUtil.RandomEmote());
            eb.AddField("Your hand (" + game.SumHand(game.Hand) + ")", HandToString(game.Hand, false), true);
            eb.AddField("Namiko's hand (" + game.SumHand(game.Dealer) + ")", HandToString(game.Dealer, false), true);
            eb.WithColor(Color.DarkBlue);

            await Send(game, eb);

            games.Remove(user);
        }
Ejemplo n.º 9
0
 public static async Task Stand(SocketCommandContext Context, BlackjackGame game)
 {
     game.Stand();
     await GameEnd(Context, game);
 }