Example #1
0
        private static void UpdateGames(long tick)
        {
            IList games = GameMgr.GetGames();

            if (games != null)
            {
                foreach (BaseGame baseGame in games)
                {
                    try
                    {
                        baseGame.Update(tick);
                    }
                    catch (Exception exception)
                    {
                        GameMgr.log.Error("Game  updated error:", exception);
                    }
                }
            }
        }
Example #2
0
        public static void SendStartMessage(BattleGame game)
        {
            GSPacketIn gSPacketIn = new GSPacketIn(3);

            gSPacketIn.WriteInt(2);
            if (game.GameType == eGameType.Free)
            {
                foreach (Player current in game.GetAllFightPlayers())
                {
                    (current.PlayerDetail as ProxyPlayer).m_antiAddictionRate = 1.0;
                    GSPacketIn pkg = GameMgr.SendBufferList(current, (current.PlayerDetail as ProxyPlayer).Buffers);
                    game.SendToAll(pkg);
                }
                gSPacketIn.WriteString("Tham chiến thành công, chúc bạn may mắn!");
            }
            else
            {
                gSPacketIn.WriteString("Kết nối thất bại!");
            }
            game.SendToAll(gSPacketIn, null);
        }
Example #3
0
        public static BattleGame StartBattleGame(List <IGamePlayer> red, ProxyRoom roomRed, List <IGamePlayer> blue, ProxyRoom roomBlue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            BattleGame result;

            try
            {
                int index = MapMgr.GetMapIndex(mapIndex, (byte)roomType, GameMgr.m_serverId);
                Map map   = MapMgr.AllocateMapInstance(index);
                if (map != null)
                {
                    BattleGame game = new BattleGame(GameMgr.m_gameId++, red, roomRed, blue, roomBlue, map, roomType, gameType, timeType, 0);
                    game.GameOverLog += new BaseGame.GameOverLogEventHandle(roomRed.LogFight);
                    Dictionary <int, BaseGame> games;
                    Monitor.Enter(games = GameMgr.m_games);
                    try
                    {
                        GameMgr.m_games.Add(game.Id, game);
                    }
                    finally
                    {
                        Monitor.Exit(games);
                    }
                    game.Prepare();
                    GameMgr.SendStartMessage(game);
                    GameMgr.SendBufferList(game);
                    GameMgr.UpdatePlayerGameId(game);
                    result = game;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception e)
            {
                GameMgr.log.Error("Create battle game error:", e);
                result = null;
            }
            return(result);
        }
Example #4
0
        private static void GameThread()
        {
            long balance = 0L;

            GameMgr.m_clearGamesTimer = TickHelper.GetTickCount();
            while (GameMgr.m_running)
            {
                long start = TickHelper.GetTickCount();
                try
                {
                    GameMgr.UpdateGames(start);
                    GameMgr.ClearStoppedGames(start);
                }
                catch (Exception ex)
                {
                    GameMgr.log.Error("Room Mgr Thread Error:", ex);
                }
                long end = TickHelper.GetTickCount();
                balance += GameMgr.THREAD_INTERVAL - (end - start);
                if (balance > 0L)
                {
                    Thread.Sleep((int)balance);
                    balance = 0L;
                }
                else
                {
                    if (balance < -1000L)
                    {
                        GameMgr.log.WarnFormat("Room Mgr is delay {0} ms!", balance);
                        balance += 1000L;
                    }
                }
                if (GameMgr.DELAY_TIME > 0)
                {
                    GameMgr.log.ErrorFormat("Delay for {0} ms!", GameMgr.DELAY_TIME);
                    Thread.Sleep(GameMgr.DELAY_TIME);
                }
            }
        }
Example #5
0
        public static BattleGame StartBattleGame(List <IGamePlayer> red, ProxyRoom roomRed, List <IGamePlayer> blue, ProxyRoom roomBlue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            BattleGame result;

            try
            {
                int mapIndex2 = MapMgr.GetMapIndex(mapIndex, (byte)roomType, GameMgr.m_serverId);
                Map map       = MapMgr.CloneMap(mapIndex2);
                List <PetSkillElementInfo> gameNeedPetSkill = PetMgr.GameNeedPetSkill();
                if (map != null)
                {
                    BattleGame battleGame = new BattleGame(GameMgr.m_gameId++, red, roomRed, blue, roomBlue, map, roomType, gameType, timeType, gameNeedPetSkill);
                    Dictionary <int, BaseGame> games;
                    Monitor.Enter(games = GameMgr.m_games);
                    try
                    {
                        GameMgr.m_games.Add(battleGame.Id, battleGame);
                    }
                    finally
                    {
                        Monitor.Exit(games);
                    }
                    battleGame.Prepare();
                    GameMgr.SendStartMessage(battleGame);
                    result = battleGame;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception exception)
            {
                GameMgr.log.Error("Create battle game error:", exception);
                result = null;
            }
            return(result);
        }