Ejemplo n.º 1
0
 public void DealHoleCards()
 {
     for (int i = 0; i < 2; ++i)
     //Simulate passing one card out at a time, going around the circle of players 2 times
     {
         foreach (PokerPlayer player in Players.Round)
         {
             Card card = Deck.Pop();
             player.AddCard(card);
             PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).HoleCards.Add(card);
         }
     }
 }
Ejemplo n.º 2
0
        public void AwardPotsToWinners(bool silent)
        {
            //** Casino Rake - Will take a percentage of each pot awarded and place it towards
            //**				the casino jackpot for the highest ranked hand.

            int totalrake = 0;

            if (!silent) //Only rake pots that have made it past the showdown.
            {
                foreach (PokerPot pokerPot in PokerPots)
                {
                    int rake = Math.Min((int)(pokerPot.PotCurrency * Dealer.Rake), Dealer.RakeMax);

                    if (rake > 0)
                    {
                        pokerPot.PotCurrency -= rake;
                        totalrake            += rake;
                    }
                }
            }

            Dealer.TotalRake += totalrake;
            PokerLogging.TotalRaked(Dealer.TableName, totalrake, Dealer.IsDonation);
            //**

            /*int lowestBet = 0;
             *
             * foreach (PokerPlayer player in winners.Where(player => player.RoundCurrency < lowestBet || lowestBet == 0))
             * {
             *  lowestBet = player.RoundCurrency;
             * }
             *
             * foreach (PokerPlayer player in Players.Round)
             * {
             *  int diff = player.RoundCurrency - lowestBet;
             *
             *  if (diff <= 0)
             *  {
             *      continue;
             *  }
             *
             *  PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Credit += diff;
             *  player.Currency += diff;
             *  CommunityCurrency -= diff;
             *  PokerMessage(
             *      Dealer,
             *      String.Format("{0:#,0} {1} has been returned to {2}.", diff, TypeOfCurrency.Name, player.Mobile.Name));
             * }*/

            Dictionary <PokerPlayer, int> winnerslog = new Dictionary <PokerPlayer, int>();

            foreach (PokerPot pokerpot in PokerPots)
            {
                if (pokerpot.winners.Count > 0)
                {
                    int splitPot = pokerpot.PotCurrency / pokerpot.winners.Count;
                    foreach (PokerPlayer player in pokerpot.winners)
                    {
                        PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Credit += splitPot;
                        player.Currency += splitPot;
                        if (winnerslog.ContainsKey(player))
                        {
                            winnerslog[player] += splitPot;
                        }
                        else
                        {
                            winnerslog.Add(player, splitPot);
                        }
                    }
                }
            }

            foreach (var winner in winnerslog)
            {
                PokerMessage(Dealer, String.Format("{0} has won {1:#,0} {2}.", winner.Key.Mobile.Name,
                                                   winner.Value,
                                                   (Dealer.IsDonation ? "donation coins" : "gold")));
                PokerLogging.HandWinnings(Dealer.TableName, winner.Key, winner.Value, Dealer.IsDonation);
            }

            foreach (var player in Players.Players)
            {
                PokerLogging.EndHandCurrency(Dealer.TableName, player, Dealer.IsDonation);
            }

            CommunityCurrency = 0;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
        public void RemovePlayer(PokerPlayer player)
        {
            Mobile from = player.Mobile;

            if (from is PlayerMobile)
            {
                var playermob = from as PlayerMobile;
                playermob.PokerJoinTimer = DateTime.UtcNow + TimeSpan.FromMinutes(1);

                playermob.Blessed = false;
            }

            if (from == null || !Players.Contains(player))
            {
                return;
            }

            Players.Players.Remove(player);

            if (Players.Peek() == player) //It is currently their turn, fold them.
            {
                player.CloseGump(typeof(PokerBetGump));
                Timer.m_LastPlayer = null;
                player.Action      = PlayerAction.Fold;
            }

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

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

            if (Players.Round.Count == 0)
            {
                if (PokerPlayers != null && PokerPlayers.Exists(x => x.Serial == player.Mobile.Serial))
                {
                    PokerPlayers.Find(x => x.Serial == player.Mobile.Serial).Credit += CommunityCurrency;
                }
                player.Currency  += CommunityCurrency;
                CommunityCurrency = 0;

                if (GameBackup.PokerGames.Contains(this))
                {
                    GameBackup.PokerGames.Remove(this);
                }
            }

            if (player.Currency > 0)
            {
                if (from.BankBox == null) //Should NEVER happen, but JUST IN CASE!
                {
                    Utility.PushColor(ConsoleColor.Red);
                    Console.WriteLine(
                        "WARNING: Player \"{0}\" with account \"{1}\" had null bank box while trying to deposit {2:#,0} {3}. Player will NOT recieve their gold.",
                        from.Name,
                        from.Account == null ? "(-null-)" : from.Account.Username,
                        player.Currency,
                        (Dealer.IsDonation ? "donation coins" : "gold"));
                    Utility.PopColor();

                    try
                    {
                        using (var op = new StreamWriter("poker_error.log", true))
                        {
                            op.WriteLine(
                                "WARNING: Player \"{0}\" with account \"{1}\" had null bankbox while poker script was trying to deposit {2:#,0} {3}. Player will NOT recieve their gold.",
                                from.Name,
                                from.Account == null ? "(-null-)" : from.Account.Username,
                                player.Currency,
                                (Dealer.IsDonation ? "donation coins" : "gold"));
                        }
                    }
                    catch
                    {}

                    from.SendMessage(
                        0x22,
                        "WARNING: Could not find your bank box. All of your poker money has been lost in this error. Please contact a Game Master to resolve this issue.");
                }
                else
                {
                    if (Banker.Deposit(from, TypeOfCurrency, player.Currency))
                    {
                        from.SendMessage(0x22, "{0:#,0} {1} has been deposited into your bank box.", player.Currency,
                                         (Dealer.IsDonation ? "donation coins" : "gold"));
                    }
                    else
                    {
                        BankCheck check;
                        if (Dealer.IsDonation)
                        {
                            check = new BankCheck(player.Currency, true);
                        }
                        else
                        {
                            check = new BankCheck(player.Currency);
                        }
                        from.Backpack.DropItem(check);
                        from.SendMessage(0x22, "{0:#,0} {1} has been placed in your bag.", player.Currency,
                                         (Dealer.IsDonation ? "donation coins" : "gold"));
                    }
                }
            }

            player.CloseAllGumps();
            ((PlayerMobile)from).PokerGame = null;
            from.Location = Dealer.ExitLocation;
            from.Map      = Dealer.ExitMap;
            from.SendMessage(0x22, "You have left the table");

            NeedsGumpUpdate = true;
        }