Example #1
0
        /// <summary>
        /// Removes the player from their game
        /// </summary>
        public static void RemovePlayer(int UserId)
        {
            try
            {
                TexasHoldEm Game = GetGameForUser(UserId);

                if (Game != null)
                {
                    Game.RemovePlayerFromGame(UserId);
                }
            }
            catch (Exception e)
            {
                Logging.LogRPGamesError("Error in RemovePlayer() void: " + e);
            }
        }
Example #2
0
        /// <summary>
        /// Gets the player id based on the Dice Furni
        /// </summary>
        public static int GetPlayerByDice(Item Item, out TexasHoldEm RealGame)
        {
            RealGame = null;
            int Number = 0;

            if (Item == null || Item.TexasHoldEmData == null)
            {
                return(Number);
            }

            if (GameList == null || GameList.Count <= 0)
            {
                return(Number);
            }

            lock (GameList)
            {
                foreach (TexasHoldEm Game in GameList.Values)
                {
                    if (Game == null)
                    {
                        continue;
                    }

                    if (Game.Banker.Values.Where(x => x.Furni != null && x.Furni == Item).ToList().Count > 0)
                    {
                        RealGame = Game;
                        Number   = 0;
                        break;
                    }

                    if (Game.Player1.Values.Where(x => x.Furni != null && x.Furni == Item).ToList().Count > 0)
                    {
                        RealGame = Game;
                        Number   = 1;
                        break;
                    }

                    if (Game.Player2.Values.Where(x => x.Furni != null && x.Furni == Item).ToList().Count > 0)
                    {
                        RealGame = Game;
                        Number   = 2;
                        break;
                    }

                    if (Game.Player3.Values.Where(x => x.Furni != null && x.Furni == Item).ToList().Count > 0)
                    {
                        RealGame = Game;
                        Number   = 3;
                        break;
                    }
                }
            }

            if (RealGame == null || Number == 0 || RealGame.PlayerList == null || !RealGame.PlayerList.ContainsKey(Number))
            {
                return(0);
            }

            return(RealGame.PlayerList[Number].UserId);
        }
Example #3
0
        /// <summary>
        /// Generates the Texas Hold 'Em Games dictionary from the database.
        /// </summary>
        public static void Initialize()
        {
            ClearOldData();

            using (var dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.SetQuery("SELECT * FROM `rp_gambling`");
                DataTable Table = dbClient.getTable();

                if (Table != null)
                {
                    foreach (DataRow Row in Table.Rows)
                    {
                        int GameId = Convert.ToInt32(Row["id"]);

                        if (GameList.ContainsKey(GameId))
                        {
                            continue;
                        }

                        int      RoomId      = Convert.ToInt32(Row["room_id"]);
                        string[] Player1Data = Row["player_1"].ToString().Split(';');
                        string[] Player2Data = Row["player_2"].ToString().Split(';');
                        string[] Player3Data = Row["player_3"].ToString().Split(';');

                        ConcurrentDictionary <int, int>             PlayerList = new ConcurrentDictionary <int, int>();
                        ConcurrentDictionary <int, TexasHoldEmItem> Player1    = GeneratePlayer(GameId, 1);
                        ConcurrentDictionary <int, TexasHoldEmItem> Player2    = GeneratePlayer(GameId, 2);
                        ConcurrentDictionary <int, TexasHoldEmItem> Player3    = GeneratePlayer(GameId, 3);
                        ConcurrentDictionary <int, TexasHoldEmItem> Banker     = GeneratePlayer(GameId, 0);

                        TexasHoldEmItem JoinGate  = GenerateJoinGate(Row);
                        TexasHoldEmItem PotSquare = GeneratePotSquare(Row);

                        int JoinCost = Convert.ToInt32(Row["join_cost"]);

                        TexasHoldEm Game = new TexasHoldEm(GameId, RoomId, Player1, Player2, Player3, Banker, PotSquare, JoinGate, Player1Data, Player2Data, Player3Data, JoinCost);

                        GameList.TryAdd(GameId, Game);

                        #region Spawn Furni
                        Room Room = RoleplayManager.GenerateRoom(RoomId);
                        if (Room != null && Room.GetRoomItemHandler() != null)
                        {
                            if (Game.PotSquare.Furni == null)
                            {
                                Game.PotSquare.SpawnDice();
                            }

                            if (Game.JoinGate.Furni == null)
                            {
                                Game.JoinGate.SpawnDice();
                            }

                            foreach (TexasHoldEmItem Item in Game.Player1.Values)
                            {
                                if (Item != null && Item.Furni == null)
                                {
                                    Item.SpawnDice();
                                }
                            }

                            foreach (TexasHoldEmItem Item in Game.Player2.Values)
                            {
                                if (Item != null && Item.Furni == null)
                                {
                                    Item.SpawnDice();
                                }
                            }

                            foreach (TexasHoldEmItem Item in Game.Player3.Values)
                            {
                                if (Item != null && Item.Furni == null)
                                {
                                    Item.SpawnDice();
                                }
                            }

                            foreach (TexasHoldEmItem Item in Game.Banker.Values)
                            {
                                if (Item != null && Item.Furni == null)
                                {
                                    Item.SpawnDice();
                                }
                            }
                        }
                        #endregion
                    }
                }
            }

            //log.Info("Carregado " + GameList.Count + " Jogos de Texas Hold!");
        }