Example #1
0
        public static BaseGame StartPVPGame(int roomId, List <IGamePlayer> red, List <IGamePlayer> blue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            BaseGame result;

            try
            {
                int totalLevel = 0;
                foreach (IGamePlayer player in red)
                {
                    totalLevel += player.PlayerCharacter.Grade;
                }
                foreach (IGamePlayer player in blue)
                {
                    totalLevel += player.PlayerCharacter.Grade;
                }
                int averageLevel = totalLevel / (red.Count + blue.Count);
                int mapId        = MapMgr.GetMapIndex(averageLevel, GameMgr.m_serverId);
                if (mapIndex == 0)
                {
                    mapIndex = mapId;
                }
                Map map = MapMgr.AllocateMapInstance(mapIndex);
                if (map != null)
                {
                    PVPGame game = new PVPGame(GameMgr.m_gameId++, roomId, red, blue, map, roomType, gameType, timeType, 0);
                    //game.GameOverLog += new BaseGame.GameOverLogEventHandle(LogMgr.LogFightAdd);
                    List <BaseGame> games;
                    Monitor.Enter(games = GameMgr.m_games);
                    try
                    {
                        GameMgr.m_games.Add(game);
                    }
                    finally
                    {
                        Monitor.Exit(games);
                    }
                    game.Prepare();
                    result = game;
                }
                else
                {
                    result = null;
                }
            }
            catch (Exception e)
            {
                GameMgr.log.Error("Create game error:", e);
                result = null;
            }
            return(result);
        }
Example #2
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);
        }