Exemple #1
0
        public void PokerGame_PlayerMadeDecision(PokerPlayer player)
        {
            if (Players.Peek() != player)
            {
                return;
            }

            if (player.Mobile == null)
            {
                return;
            }

            bool resetTurns = false;

            Steps++;

            var pobj = new PokerActionObject(PokerHand.PokerGameId, Steps,
                                             PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).PokerPlayerId, (int)State / 2,
                                             (int)player.Action, 0);

            switch (player.Action)
            {
            case PlayerAction.None:
                break;

            case PlayerAction.Bet:
            {
                NextRaise = player.Bet;
                CheckPot(player.Bet, player);
                PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Bet;
                PokerMessage(player.Mobile, String.Format("I bet {0}.", player.Bet));
                CurrentBet            = player.Bet;
                player.RoundBet       = player.Bet;
                player.Currency      -= player.Bet;
                player.RoundCurrency += player.Bet;
                CommunityCurrency    += player.Bet;
                resetTurns            = true;
                pobj.Amount           = player.Bet;

                break;
            }

            case PlayerAction.Raise:
            {
                PokerMessage(player.Mobile, String.Format("I raise by {0}.", player.Bet));

                NextRaise = player.Bet;

                CurrentBet += player.Bet;

                int diff = CurrentBet - player.RoundBet;

                CheckPot(diff, player);
                PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += diff;
                player.Currency      -= diff;
                player.RoundCurrency += diff;
                player.RoundBet      += diff;
                CommunityCurrency    += diff;
                player.Bet            = diff;
                resetTurns            = true;
                pobj.Amount           = diff;


                break;
            }

            case PlayerAction.Call:
            {
                PokerMessage(player.Mobile, "I call.");

                int diff = CurrentBet - player.RoundBet;     //how much they owe in the pot

                CheckPot(diff, player);
                player.Bet = diff;
                PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Bet;
                player.Currency      -= diff;
                player.RoundCurrency += diff;
                player.RoundBet      += diff;
                CommunityCurrency    += diff;

                pobj.Amount = player.Bet;


                break;
            }

            case PlayerAction.Check:
            {
                if (!player.LonePlayer)
                {
                    PokerMessage(player.Mobile, "Check.");
                }
                pobj.Amount = 0;
                break;
            }

            case PlayerAction.Fold:
            {
                PokerMessage(player.Mobile, "I fold.");
                pobj.Amount = 0;

                PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Folded = 1;

                if (Players.Round.Contains(player))
                {
                    Players.Round.Remove(player);
                }

                if (Players.Turn.Contains(player))
                {
                    Players.Turn.Remove(player);
                }

                if (Players.Round.Count == 1)
                {
                    DoShowdown(true);
                    return;
                }

                foreach (var pokerPot in PokerPots)
                {
                    pokerPot.ContributionToPot.Remove(player);
                }

                break;
            }

            case PlayerAction.AllIn:
            {
                if (!player.IsAllIn)
                {
                    PokerMessage(player.Mobile, player.Forced ? "I call: all-in." : "All in.");


                    int diff = player.Currency - CurrentBet;

                    if (diff > 0)
                    {
                        CurrentBet += diff;
                        NextRaise  += diff;
                    }

                    player.Bet = player.Currency;
                    CheckPot(player.Bet, player, true);
                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Currency;
                    player.RoundCurrency += player.Currency;
                    player.RoundBet      += player.Currency;
                    CommunityCurrency    += player.Currency;
                    pobj.Amount           = player.Currency;
                    player.Currency       = 0;


                    //We need to check to see if this is a follow up action, or a first call
                    //before we reset the turns
                    if (Players.Prev() != null)
                    {
                        resetTurns = (Players.Prev().Action == PlayerAction.Check);

                        PokerPlayer prev = Players.Prev();

                        if (prev.Action == PlayerAction.Check ||
                            (prev.Action == PlayerAction.Bet && prev.Bet < player.Bet) ||
                            (prev.Action == PlayerAction.AllIn && prev.Bet < player.Bet) ||
                            (prev.Action == PlayerAction.Call && prev.Bet < player.Bet) ||
                            (prev.Action == PlayerAction.Raise && prev.Bet < player.Bet))
                        {
                            resetTurns = true;
                        }
                    }
                    else
                    {
                        resetTurns = true;
                    }

                    PokerActions.Add(pobj);
                    player.IsAllIn = true;

                    player.Forced = false;
                }

                break;
            }
            }

            PokerLogging.PokerPlayerAction(player, player.Action, Dealer.TableName, Dealer.IsDonation);

            if (!player.IsAllIn)
            {
                PokerActions.Add(pobj);
            }

            if (resetTurns)
            {
                Players.Turn.Clear();
                Players.Push(player);
            }

            Timer.m_LastPlayer = null;
            Timer.hasWarned    = false;

            if (Players.Turn.Count == Players.Round.Count)
            {
                State = (PokerGameState)((int)State + 1);
            }
            else
            {
                AssignNextTurn();
            }

            NeedsGumpUpdate = true;
        }
Exemple #2
0
        public void PokerGame_PlayerMadeDecision(PokerPlayer player)
        {
            if (Players.Peek() != player)
            {
                return;
            }

            if (player.Mobile == null)
            {
                return;
            }

            bool resetTurns = false;

            Steps++;

            var pobj = new PokerActionObject(PokerHand.PokerGameId, Steps,
                PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).PokerPlayerId, (int) State / 2,
                (int) player.Action, 0);

            switch (player.Action)
            {
                case PlayerAction.None:
                    break;
                case PlayerAction.Bet:
                {
                    NextRaise = player.Bet;
                    CheckPot(player.Bet, player);
                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Bet;
                    PokerMessage(player.Mobile, String.Format("I bet {0}.", player.Bet));
                    CurrentBet = player.Bet;
                    player.RoundBet = player.Bet;
                    player.Currency -= player.Bet;
                    player.RoundCurrency += player.Bet;
                    CommunityCurrency += player.Bet;
                    resetTurns = true;
                    pobj.Amount = player.Bet;

                    break;
                }
                case PlayerAction.Raise:
                {

                    PokerMessage(player.Mobile, String.Format("I raise by {0}.", player.Bet));

                    NextRaise = player.Bet;

                    CurrentBet += player.Bet;

                    int diff = CurrentBet - player.RoundBet;

                    CheckPot(diff, player);
                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += diff;
                    player.Currency -= diff;
                    player.RoundCurrency += diff;
                    player.RoundBet += diff;
                    CommunityCurrency += diff;
                    player.Bet = diff;
                    resetTurns = true;
                    pobj.Amount = diff;


                    break;
                }
                case PlayerAction.Call:
                {

                    PokerMessage(player.Mobile, "I call.");

                    int diff = CurrentBet - player.RoundBet; //how much they owe in the pot

                    CheckPot(diff, player);
                    player.Bet = diff;
                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Bet;
                    player.Currency -= diff;
                    player.RoundCurrency += diff;
                    player.RoundBet += diff;
                    CommunityCurrency += diff;

                    pobj.Amount = player.Bet;


                    break;
                }
                case PlayerAction.Check:
                {
                    if (!player.LonePlayer)
                    {
                        PokerMessage(player.Mobile, "Check.");
                    }
                    pobj.Amount = 0;
                    break;
                }
                case PlayerAction.Fold:
                {
                    PokerMessage(player.Mobile, "I fold.");
                    pobj.Amount = 0;

                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Folded = 1;

                    if (Players.Round.Contains(player))
                    {
                        Players.Round.Remove(player);
                    }

                    if (Players.Turn.Contains(player))
                    {
                        Players.Turn.Remove(player);
                    }

                    if (Players.Round.Count == 1)
                    {
                        DoShowdown(true);
                        return;
                    }

                    foreach (var pokerPot in PokerPots)
                    {
                        pokerPot.ContributionToPot.Remove(player);
                    }

                    break;
                }
                case PlayerAction.AllIn:
                {
                    if (!player.IsAllIn)
                    {
                        PokerMessage(player.Mobile, player.Forced ? "I call: all-in." : "All in.");


                        int diff = player.Currency - CurrentBet;

                        if (diff > 0)
                        {
                            CurrentBet += diff;
                            NextRaise += diff;
                        }

                        player.Bet = player.Currency;
                        CheckPot(player.Bet, player, true);
                        PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Debit += player.Currency;
                        player.RoundCurrency += player.Currency;
                        player.RoundBet += player.Currency;
                        CommunityCurrency += player.Currency;
                        pobj.Amount = player.Currency;
                        player.Currency = 0;


                        //We need to check to see if this is a follow up action, or a first call
                        //before we reset the turns
                        if (Players.Prev() != null)
                        {
                            resetTurns = (Players.Prev().Action == PlayerAction.Check);

                            PokerPlayer prev = Players.Prev();

                            if (prev.Action == PlayerAction.Check ||
                                (prev.Action == PlayerAction.Bet && prev.Bet < player.Bet) ||
                                (prev.Action == PlayerAction.AllIn && prev.Bet < player.Bet) ||
                                (prev.Action == PlayerAction.Call && prev.Bet < player.Bet) ||
                                (prev.Action == PlayerAction.Raise && prev.Bet < player.Bet))
                            {
                                resetTurns = true;
                            }
                        }
                        else
                        {
                            resetTurns = true;
                        }

                        PokerActions.Add(pobj);
                        player.IsAllIn = true;

                        player.Forced = false;
                    }

                    break;
                }
            }

            PokerLogging.PokerPlayerAction(player, player.Action, Dealer.TableName, Dealer.IsDonation);

            if (!player.IsAllIn)
            {
                PokerActions.Add(pobj);
            }

            if (resetTurns)
            {
                Players.Turn.Clear();
                Players.Push(player);
            }

            Timer.m_LastPlayer = null;
            Timer.hasWarned = false;

            if (Players.Turn.Count == Players.Round.Count)
            {
                State = (PokerGameState) ((int) State + 1);
            }
            else
            {
                AssignNextTurn();
            }

            NeedsGumpUpdate = true;
        }