Esempio n. 1
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            long       userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HoldemGame game   = casino.GetGame(userid);

            if (game != null)
            {
                SendMessage(channel, command.User, "You are already active in a holdem game. Use !fold to fold your hand or !call to stay active in the game.");
                return;
            }

            int bet;

            if (command.Arguments.Length == 0)
            {
                bet = 1;
            }
            else
            {
                int.TryParse(command.Arguments[0], out bet);
            }

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

            int gold = playermodule.GetPlayerGold(userid);

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

            int maxbet = playermodule.GetLevel(userid) * 10;

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

            // allow the player to play for one gold even if he has no gold
            if (gold > 0)
            {
                playermodule.UpdateGold(userid, -bet);
            }

            game = casino.CreateGame(userid, bet);

            game.Deck.Shuffle();

            game.PlayerHand += game.Deck.Pop();
            game.DealerHand += game.Deck.Pop();
            game.PlayerHand += game.Deck.Pop();
            game.DealerHand += game.Deck.Pop();

            game.Muck.Push(game.Deck.Pop());
            for (int i = 0; i < 3; ++i)
            {
                game.Board += game.Deck.Pop();
            }

            RPGMessageBuilder message = messagemodule.Create();

            message.Text("You have ");
            foreach (Card card in game.PlayerHand)
            {
                message.Image(imagemodule.GetCardUrl(card), $"{card} ");
            }
            message.Text(". The board shows ");
            foreach (Card card in game.Board)
            {
                message.Image(imagemodule.GetCardUrl(card), $"{card} ");
            }

            HandEvaluation evaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            message.Text($" ({evaluation})").Send();
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command) {
            VideoPokerGame game = pokermodule.GetGame(command.Service, command.User);
            long userid = playermodule.GetPlayer(command.Service, command.User).UserID;
            HandEvaluation evaluation;

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

                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) * 10;
                if (bet > maxbet) {
                    SendMessage(channel, command.User, $"On your level you're only allowed to bet up to {maxbet} gold.");
                    return;
                }

                game = pokermodule.CreateGame(command.Service, command.User, bet);
                game.IsMaxBet = bet == maxbet;
                game.Deck.Shuffle();
                for(int i = 0; i < 5; ++i)
                    game.Hand += game.Deck.Pop();

                RPGMessageBuilder message = messagemodule.Create();
                message.User(userid).Text(" has ");
                foreach(Card card in game.Hand)
                    message.Image(imagemodule.GetCardUrl(card), $"{card} ");

                evaluation = HandEvaluator.Evaluate(game.Hand);
                message.Text($"({evaluation})").Send();
            }
            else {
                RPGMessageBuilder message = messagemodule.Create();

                if(command.Arguments.Length > 0) {
                    int redraw = 0;
                    foreach(string argument in command.Arguments) {
                        if(argument.All(c => char.IsDigit(c))) {
                            int index = int.Parse(argument);
                            if(index < 1 || index > 5) {
                                SendMessage(channel, command.User, $"{index} is not a valid slot to redraw");
                                return;
                            }
                            redraw |= 1 << (index - 1);
                        }
                        else if(argument.ToLower() == "all") {
                            redraw |= 31;
                        }
                        else {
                            int index = game.Hand.IndexOf(c => c.ToString().ToLower() == argument.ToLower());
                            if(index == -1) {
                                SendMessage(channel, command.User, $"{argument} points not to a card in your hand");
                                return;
                            }
                            redraw |= 1 << index;
                        }
                    }

                    int cards = 0;
                    for(int i = 0; i < 5; ++i) {
                        if((redraw & (1 << i)) != 0) {
                            game.Hand = game.Hand.ChangeCard(i, game.Deck.Pop());
                            ++cards;
                        }
                    }
                    message.User(userid).Text($" is redrawing {cards} cards. ");
                    foreach (Card card in game.Hand)
                        message.Image(imagemodule.GetCardUrl(card), $"{card} ");

                    evaluation = HandEvaluator.Evaluate(game.Hand);
                    message.Text($"({evaluation}).");
                }
                else {
                    evaluation = HandEvaluator.Evaluate(game.Hand);
                    message.User(userid).Text(" is satisfied with the hand.");
                }

                int multiplicator = GetMultiplicator(evaluation, game.IsMaxBet);
                if(multiplicator == 0)
                    message.Text(" ").ShopKeeper().Text(" laughs about that shitty hand.");
                else {
                    int payout = game.Bet * multiplicator;
                    playermodule.UpdateGold(userid, payout);
                    message.Text(" Payout is ").Gold(payout);
                }

                message.Send();
                pokermodule.RemoveGame(command.Service, command.User);
            }
        }
        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();
        }