Example #1
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            BlackJackGame game = blackjack.GetGame(command.Service, command.User);

            if (game == null)
            {
                SendMessage(channel, command.User, "There is active black jack game. Start another one with !bj <bet>");
                return;
            }

            game.PlayerBoards[game.ActiveBoard].Board += game.Stack.Pop();

            int value = logic.Evaluate(game.PlayerBoards[game.ActiveBoard].Board);

            RPGMessageBuilder message = messages.Create();

            message.User(game.PlayerID).Text(" has ");
            foreach (Card card in game.PlayerBoards[game.ActiveBoard].Board)
            {
                message.Image(images.GetCardUrl(card), $"{card} ");
            }
            message.Text(". ");

            if (value > 21)
            {
                message.Text("Bust!");
                game.PlayerBoards.RemoveAt(game.ActiveBoard);
            }
            else
            {
                message.Text($"({value}). ");
                if (value == 21)
                {
                    ++game.ActiveBoard;
                }
            }


            if (game.PlayerBoards.Count == 0)
            {
                message.Text(" All hands are busted.").ShopKeeper().Text(" laughs at you.");
                blackjack.RemoveGame(game.PlayerID);
            }
            else
            {
                if (game.ActiveBoard >= game.PlayerBoards.Count)
                {
                    message.Text(" All hands have been played.");
                    logic.PlayoutDealer(game, message, playermodule, images);
                    blackjack.RemoveGame(game.PlayerID);
                }
            }
            message.Send();
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            BlackJackGame game = blackjack.GetGame(command.Service, command.User);

            if (game == null)
            {
                SendMessage(channel, command.User, "There is no active black jack game. Start another one with !bj <bet>");
                return;
            }

            ++game.ActiveBoard;

            RPGMessageBuilder message = messages.Create();

            message.User(game.PlayerID).Text(" is satisfied.");
            if (game.ActiveBoard >= game.PlayerBoards.Count)
            {
                message.Text(" All hands have been played.");
                logic.PlayoutDealer(game, message, playermodule, images);
                blackjack.RemoveGame(game.PlayerID);
            }
            else
            {
                if (game.PlayerBoards[game.ActiveBoard].Board.Count == 1)
                {
                    game.PlayerBoards[game.ActiveBoard].Board += game.Stack.Pop();
                }

                message.Text(" Next hand is ");
                foreach (Card card in game.PlayerBoards[game.ActiveBoard].Board)
                {
                    message.Image(images.GetCardUrl(card), $"{card} ");
                }

                int value = logic.Evaluate(game.PlayerBoards[game.ActiveBoard].Board);
                message.Text($"({value}). ");
                logic.CheckSplit(game.PlayerBoards[game.ActiveBoard].Board, message);
            }
            message.Send();
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command) {
            BlackJackGame existing = blackjack.GetGame(command.Service, command.User);
            if(existing != null) {
                SendMessage(channel, command.User, "There is already a game running for you.");
                return;
            }

            if(command.Arguments.Length == 0) {
                SendMessage(channel, command.User, "You have to specify a bet amount");
                return;
            }

            long userid = playermodule.GetPlayer(command.Service, command.User).UserID;

            int bet;
            int.TryParse(command.Arguments[0], out bet);
            if (bet <= 0)
            {
                SendMessage(channel, command.User, $"{command.Arguments[0]} is no valid bet");
                return;
            }

            if (bet > playermodule.GetPlayerGold(userid))
            {
                SendMessage(channel, command.User, "You can't bet more than you have.");
                return;
            }

            int maxbet = playermodule.GetLevel(userid) * 40;
            if (bet > maxbet)
            {
                SendMessage(channel, command.User, $"On your level you're only allowed to bet up to {maxbet} gold.");
                return;
            }

            BlackJackGame game = blackjack.StartGame(command.Service, command.User);
            game.Stack.Shuffle();

            game.DealerBoard += game.Stack.Pop();

            game.PlayerBoards = new List<BlackJackBoard>();
            game.PlayerBoards.Add(new BlackJackBoard() {
                Bet = bet
            });
            game.PlayerBoards[0].Board += game.Stack.Pop();
            game.PlayerBoards[0].Board += game.Stack.Pop();

            playermodule.UpdateGold(game.PlayerID, -bet);

            RPGMessageBuilder message = messages.Create();
            message.User(userid).Text(" has ");
            foreach(Card card in game.PlayerBoards[0].Board)
                message.Image(images.GetCardUrl(card), $"{card} ");
            message.Text(".");

            int value = logic.Evaluate(game.PlayerBoards[0].Board);
            if(value == 21) {
                message.Text("Black Jack!");
                int winnings = (int)(game.PlayerBoards[0].Bet * 2.5);
                message.Text("Winnings: ").Gold(winnings);
                playermodule.UpdateGold(userid, winnings);
                blackjack.RemoveGame(userid);
            }
            else {
                message.Text($"({value}). ");
                message.ShopKeeper().Text(" shows ");
                foreach (Card card in game.DealerBoard)
                    message.Image(images.GetCardUrl(card), $"{card} ");
                message.Text($"({logic.Evaluate(game.DealerBoard)}). ");

                logic.CheckSplit(game.PlayerBoards[0].Board, message);
            }

            message.Send();
        }