Beispiel #1
0
        public int CreateLobby(Vector3 position, int maxPlayers)
        {
            int id = ++_lobbyCounter;

            _lobbies.Add(id, new PokerLobby(id, true, position, maxPlayers, API.createObject));

            _lobbies[id].OnLobbyRoundEnd += parameters => { if (OnLobbyRoundEnd != null)
                                                            {
                                                                OnLobbyRoundEnd.Invoke(id);
                                                            }
            };
            _lobbies[id].OnLobbyRoundStart += parameters => { if (OnLobbyRoundStart != null)
                                                              {
                                                                  OnLobbyRoundStart.Invoke(id);
                                                              }
            };
            _lobbies[id].OnPlayerLoseRound += parameters => { if (OnPlayerLoseRound != null)
                                                              {
                                                                  OnPlayerLoseRound.Invoke(id, parameters[0]);
                                                              }
            };                                                                                                                               // id, client
            _lobbies[id].OnPlayerWinRound += parameters => { if (OnPlayerWinRound != null)
                                                             {
                                                                 OnPlayerWinRound.Invoke(id, parameters[0], parameters[1], parameters[2]);
                                                             }
            };                                                                                                                                                          // id, client, take, handname
            _lobbies[id].OnPlayerMoneyChange += parameters => { if (OnPlayerMoneyChange != null)
                                                                {
                                                                    OnPlayerMoneyChange.Invoke(id, parameters[0], parameters[1]);
                                                                }
            };                                                                                                                                                    // id, client, newmoney

            return(id);
        }
        public void ProcessAClick(Brush activePanelColor)
        {
            if (_needColor == null)
            {
                return;
            }

            if (_needColor == activePanelColor)
            {
                EndGame();
                OnPlayerWinRound?.Invoke();
            }
            else
            {
                EndGame();
                _needColor = null;
                OnPlayerLoseRound?.Invoke();
            }
        }
Beispiel #3
0
        private void Advance()
        {
            do
            {
                CurrentBetter = (CurrentBetter + 1) % Players.Count;
                if (CurrentBetter == MaxBetter)
                {
                    // Advance
                    if (Table == null || Table.Length == 0)
                    {
                        Table = new Card[3];

                        for (int i = 0; i < 3; i++)
                        {
                            Table[i] = _deck.Pop();
                        }
                    }
                    else if (Table.Length == 3)
                    {
                        var tmp = new Card[4];
                        Array.Copy(Table, 0, tmp, 0, 3);
                        tmp[3] = _deck.Pop();
                        Table  = tmp;
                    }
                    else if (Table.Length == 4)
                    {
                        var tmp = new Card[5];
                        Array.Copy(Table, 0, tmp, 0, 4);
                        tmp[4] = _deck.Pop();
                        Table  = tmp;
                    }
                    else if (Table.Length == 5)
                    {
                        List <HandDescriptor> hands = new List <HandDescriptor>();

                        SendToPlayers("Revealing hands...");

                        // Get hands
                        foreach (Player player in Players.Where(p => p.State == PlayerState.Playing))
                        {
                            HandDescriptor hand = PokerEngine.GetHandResult(Table, player);

                            foreach (var player1 in Players.Where(p => p != player))
                            {
                                player1.Client.triggerEvent("SET_PLAYER_CARDS", player.Client.name,
                                                            player.Cards[0].ToJsCode(), player.Cards[1].ToJsCode());
                            }

                            hands.Add(hand);
                        }

                        API.shared.sleep(5000);

                        foreach (var hand in hands)
                        {
                            SendToPlayers("Player ~n~" + hand.Player.Client.name + "~n~ has " + hand.HandName);
                        }

                        int min = hands.Min(h => (int)h.Rank);
                        var potentialwinners = hands.Where(h => (int)h.Rank == min).ToList();
                        int tiebreakermax    = potentialwinners.Max(h => h.Tiebreaker);
                        var winners          = potentialwinners.Where(h => h.Tiebreaker >= tiebreakermax).ToArray();
                        int take             = Pot / winners.Length;
                        foreach (var winner in winners)
                        {
                            winner.Player.Money += take;
                            winner.Player.Client.triggerEvent("SHARD_CUSTOM", "winner", 5000);
                            SendToPlayers("Player ~n~" + winner.Player.Client.name + "~n~ has won the round with a ~g~" + winner.HandName);
                            if (OnPlayerWinRound != null)
                            {
                                OnPlayerWinRound.Invoke(winner.Player.Client, take, winner.HandName);
                            }
                        }

                        foreach (var losers in Players.Except(winners.Select(w => w.Player)))
                        {
                            losers.Client.triggerEvent("SHARD_CUSTOM", "loser", 5000);
                            if (OnPlayerLoseRound != null)
                            {
                                OnPlayerLoseRound.Invoke(losers.Client);
                            }
                        }

                        API.shared.sleep(5000);

                        EndRound();
                        return;
                    }

                    object[] newArgs = new object[Table.Length + 1];
                    newArgs[0] = Table.Length;
                    for (int i = 0; i < Table.Length; i++)
                    {
                        newArgs[i + 1] = Table[i].ToJsCode();
                    }

                    Players.ForEach(p => p.Client.triggerEvent("SET_TABLE_CARDS", newArgs));
                    API.shared.sleep(5000);
                }
            } while (Players[CurrentBetter].State == PlayerState.Folded);
            GiveTurn(Players[CurrentBetter]);
        }