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);
            }
        }
Esempio n. 2
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 no active black jack game. Start another one with !bj <bet>");
                return;
            }

            if (!logic.IsSplitPossible(game.PlayerBoards[game.ActiveBoard].Board))
            {
                SendMessage(channel, command.User, "A split is not possible on the current hand.");
                return;
            }

            int bet = game.PlayerBoards[game.ActiveBoard].Bet;

            if (bet > playermodule.GetPlayerGold(game.PlayerID))
            {
                SendMessage(channel, command.User, "You don't have enough gold to split the hand.");
                return;
            }

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

            game.PlayerBoards.Add(new BlackJackBoard {
                Bet   = bet,
                Board = new Board(game.PlayerBoards[game.ActiveBoard].Board[1])
            });

            game.PlayerBoards[game.ActiveBoard].Board = game.PlayerBoards[game.ActiveBoard].Board.ChangeCard(1, game.Stack.Pop());

            RPGMessageBuilder message = messages.Create();

            message.User(game.PlayerID).Text(" current 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}). ");

            while (value == 21 || (game.ActiveBoard < game.PlayerBoards.Count && game.PlayerBoards[game.ActiveBoard].Board[0].Rank == CardRank.Ace))
            {
                ++game.ActiveBoard;
                if (game.ActiveBoard >= game.PlayerBoards.Count)
                {
                    message.Text(" All hands are played.");
                    logic.PlayoutDealer(game, message, playermodule, images);
                    value = 0;
                }
                else
                {
                    if (game.PlayerBoards[game.ActiveBoard].Board.Count == 0)
                    {
                        game.PlayerBoards[game.ActiveBoard].Board += game.Stack.Pop();
                    }

                    message.User(game.PlayerID).Text(" next hand is ");
                    foreach (Card card in game.PlayerBoards[0].Board)
                    {
                        message.Image(images.GetCardUrl(card), $"{card} ");
                    }
                    value = logic.Evaluate(game.PlayerBoards[game.ActiveBoard].Board);
                    message.Text($"({value}). ");
                }
            }

            if (value > 0)
            {
                logic.CheckSplit(game.PlayerBoards[game.ActiveBoard].Board, message);
            }

            message.Send();
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (command.Arguments.Length == 0)
            {
                ProvideHelp(channel, command.User);
                return;
            }

            int gold;

            try
            {
                gold = command.Arguments.Length < 2 ? 1 : int.Parse(command.Arguments[1]);
            }
            catch (Exception e)
            {
                Logger.Error(this, $"{command.Arguments[1]} is no valid bet amount", e);
                SendMessage(channel, command.User, $"{command.Arguments[1]} is no valid bet amount");
                return;
            }

            if (gold <= 0)
            {
                gold = 1;
            }

            if (playermodule.GetPlayerGold(playermodule.GetExistingPlayer(command.Service, command.User).UserID) < gold)
            {
                SendMessage(channel, command.User, $"You don't have {gold} gold");
                return;
            }

            if (command.Arguments[0].All(c => char.IsDigit(c)))
            {
                int field = int.Parse(command.Arguments[0]);
                if (field < 0 || field > 36)
                {
                    SendMessage(channel, command.User, $"Field {field} is not part of the board.");
                    return;
                }

                module.Bet(command.Service, command.User, gold, BetType.Plein, field);
                return;
            }

            switch (command.Arguments[0].ToLower())
            {
            case "r":
            case "red":
            case "rouge":
                module.Bet(command.Service, command.User, gold, BetType.Color, 0);
                SendMessage(channel, command.User, $"You bet {gold} on red for the next roulette round");
                break;

            case "b":
            case "black":
            case "noir":
                module.Bet(command.Service, command.User, gold, BetType.Color, 1);
                SendMessage(channel, command.User, $"You bet {gold} on black for the next roulette round");
                break;

            case "o":
            case "odd":
                module.Bet(command.Service, command.User, gold, BetType.OddEven, 1);
                SendMessage(channel, command.User, $"You bet {gold} on odds for the next roulette round");
                break;

            case "e":
            case "even":
                module.Bet(command.Service, command.User, gold, BetType.OddEven, 0);
                SendMessage(channel, command.User, $"You bet {gold} on evens for the next roulette round");
                break;

            case "dozen1":
                module.Bet(command.Service, command.User, gold, BetType.Douzaines, 0);
                SendMessage(channel, command.User, $"You bet {gold} on the first dozen for the next roulette round");
                break;

            case "row1":
                module.Bet(command.Service, command.User, gold, BetType.Colonnes, 0);
                SendMessage(channel, command.User, $"You bet {gold} on the first row for the next roulette round");
                break;

            case "dozen2":
                module.Bet(command.Service, command.User, gold, BetType.Douzaines, 1);
                SendMessage(channel, command.User, $"You bet {gold} on the second dozen for the next roulette round");
                break;

            case "row2":
                module.Bet(command.Service, command.User, gold, BetType.Colonnes, 1);
                SendMessage(channel, command.User, $"You bet {gold} on the second row for the next roulette round");
                break;

            case "dozen3":
                module.Bet(command.Service, command.User, gold, BetType.Douzaines, 2);
                SendMessage(channel, command.User, $"You bet {gold} on the third dozen for the next roulette round");
                break;

            case "row3":
                module.Bet(command.Service, command.User, gold, BetType.Colonnes, 2);
                SendMessage(channel, command.User, $"You bet {gold} on the third row for the next roulette round");
                break;

            case "half1":
                module.Bet(command.Service, command.User, gold, BetType.HalfBoard, 0);
                SendMessage(channel, command.User, $"You bet {gold} on 1-18 for the next roulette round");
                break;

            case "half2":
                module.Bet(command.Service, command.User, gold, BetType.HalfBoard, 1);
                SendMessage(channel, command.User, $"You bet {gold} on 19-36 for the next roulette round");
                break;

            case "history":
                SendMessage(channel, command.User, $"History of roulette fields: {string.Join(",", module.History)}");
                break;
            }
        }
Esempio n. 4
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();
        }
Esempio n. 5
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 have no active holdem game. Use !holdem to start a new game.");
                return;
            }

            int bet = Math.Min(playermodule.GetPlayerGold(userid), game.Bet);

            if (bet > 0)
            {
                playermodule.UpdateGold(userid, -bet);
                game.Pot += bet;
            }

            game.Muck.Push(game.Deck.Pop());
            game.Board += game.Deck.Pop();

            RPGMessageBuilder message = messagemodule.Create();

            if (game.Board.Count == 5)
            {
                // showdown
                message.Text("Showdown! ");
            }

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

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

            message.Text($" ({evaluation})");

            if (game.Board.Count == 5)
            {
                message.Text(". ").ShopKeeper().Text(" shows ");
                foreach (Card card in game.DealerHand)
                {
                    message.Image(cardimages.GetCardUrl(card), $"{card} ");
                }
                HandEvaluation dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand);
                message.Text($" ({dealerevaluation}). ");

                int multiplier = 0;

                if (dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four))
                {
                    message.ShopKeeper().Text(" isn't qualified for a showdown.");
                    multiplier = GetMultiplier(evaluation.Rank);
                }
                else if (dealerevaluation > evaluation)
                {
                    message.ShopKeeper().Text(" wins the hand and ").Gold(game.Pot).Text(" laughing at your face.");
                }
                else if (dealerevaluation == evaluation)
                {
                    message.ShopKeeper().Text(" Has the same hand as you.");
                    multiplier = 1;
                }
                else
                {
                    message.Text(" You win the hand.");
                    multiplier = GetMultiplier(evaluation.Rank);
                }

                if (multiplier > 0)
                {
                    message.Text(" Payout is ").Gold(game.Pot * multiplier);
                    playermodule.UpdateGold(userid, game.Pot * multiplier);
                }

                casino.RemoveGame(userid);
            }

            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();
        }