예제 #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 have no active holdem game. Use !holdem to start a new game.");
                return;
            }

            casino.RemoveGame(userid);

            RPGMessageBuilder message          = messagemodule.Create().User(userid).Text(" folds the hand. ");
            HandEvaluation    dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand);
            HandEvaluation    playerevaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand);

            if (dealerevaluation < playerevaluation || dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four))
            {
                message.ShopKeeper().Text(" laughs and shows ");
                foreach (Card card in game.DealerHand)
                {
                    message.Image(cardimages.GetCardUrl(card), $"{card} ");
                }
                message.Text("while grabbing ").Gold(game.Pot);
            }
            else
            {
                message.ShopKeeper().Text(" gladly rakes in ").Gold(game.Pot);
            }
            message.Send();
        }
예제 #2
0
        public void TestCardUrl([ValueSource("Codes")] Tuple <Card, byte> data)
        {
            CardImageModule module = new CardImageModule(null);
            string          url    = module.GetCardUrl(data.Item1);
            Match           match  = Regex.Match(url, "code=(?<code>[0-9]+)$");

            Assert.That(match.Success);
            Assert.AreEqual(data.Item2, byte.Parse(match.Groups["code"].Value));
        }
예제 #3
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();
        }
예제 #4
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;
            }

            ++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();
        }
예제 #5
0
        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);
            }
        }
예제 #6
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();
        }
예제 #7
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();
        }
예제 #8
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();
        }
예제 #9
0
        public void PlayoutDealer(BlackJackGame game, RPGMessageBuilder messages, PlayerModule playermodule, CardImageModule images)
        {
            messages.ShopKeeper().Text(" is drawing his hand to ");

            int value = 0;

            do
            {
                game.DealerBoard += game.Stack.Pop();
                value             = Evaluate(game.DealerBoard);
            }while(value < 17);

            foreach (Card card in game.DealerBoard)
            {
                messages.Image(images.GetCardUrl(card), $"{card} ");
            }

            if (value > 21)
            {
                messages.Text(" Bust!");
            }
            else
            {
                messages.Text($"({value}) ");
            }

            int payout = 0;

            if (value > 21)
            {
                foreach (BlackJackBoard board in game.PlayerBoards)
                {
                    payout = board.Bet * 2;
                }
            }
            else
            {
                foreach (BlackJackBoard board in game.PlayerBoards)
                {
                    int boardvalue = Evaluate(board.Board);
                    if (boardvalue > value)
                    {
                        payout = board.Bet * 2;
                    }
                    else if (boardvalue == value)
                    {
                        payout = board.Bet;
                    }
                }
            }

            if (payout > 0)
            {
                messages.Text("Payout is ").Gold(payout);
                playermodule.UpdateGold(game.PlayerID, payout);
            }
            else
            {
                messages.ShopKeeper().Text(" laughs at you.");
            }
        }
        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();
        }