예제 #1
0
 //玩家加入房间
 public static bool UserJoinRoom(this MatchRoom matchRoom, User user, long sessionActorId)
 {
     for (int i = 0; i < matchRoom.RoomConfig.GameNumber; i++)
     {
         if (!matchRoom.PlayerInfoDic.ContainsKey(i))
         {
             MatchPlayerInfo matchPlayerInfo = MatchPlayerInfoFactory.Create(user, sessionActorId, i);
             matchRoom.BroadcastActorMessage(new Actor_OtherJoinRoom()
             {
                 PlayerInfo = matchPlayerInfo
             });                                                                                         //广播其他玩家加入房间信息
             matchRoom.PlayerInfoDic[i] = matchPlayerInfo;
             return(true);
         }
     }
     return(false);
 }
 //检测能不能匹配成功
 public static void DetectionMatchCondition(this MatchRoomComponent matchRoomComponent, long matchRoomId)
 {
     try
     {
         MatchRoomConfig matchRoomConfig = Game.Scene.GetComponent <GameMatchRoomConfigComponent>().GetMatachRoomInfo(matchRoomId);
         while (matchRoomComponent.mAllQueueDics[matchRoomId].Count >= matchRoomConfig.GameNumber)
         {
             M2S_StartGame m2SStartGame = new M2S_StartGame();
             m2SStartGame.RoomConfig = matchRoomConfig;
             for (int i = 0; i < matchRoomConfig.GameNumber; i++)
             {
                 _TemporarayActorId = 0;
                 _IsAI = false;
                 if (matchRoomComponent.mAllQueueDics[matchRoomId][i].GetComponent <UserGateActorIdComponent>() != null)
                 {
                     _TemporarayActorId = matchRoomComponent.mAllQueueDics[matchRoomId][i].GetComponent <UserGateActorIdComponent>().ActorId;
                 }
                 else
                 {
                     _IsAI = true;
                 }
                 MatchPlayerInfo matchPlayer = MatchPlayerInfoFactory.Create(matchRoomComponent.mAllQueueDics[matchRoomId][i], _TemporarayActorId, i, _IsAI);
                 m2SStartGame.MatchPlayerInfos.Add(matchPlayer);
             }
             matchRoomComponent.PlayerStartGame(matchRoomId, matchRoomConfig.GameNumber);
             //随机分配一个游戏服务器并告知他开始一局游戏
             long toyGameId = Game.Scene.GetComponent <GameMatchRoomConfigComponent>().GetMatachRoomInfo(matchRoomId).ToyGameId;
             matchRoomComponent.RoomStartGame(toyGameId, m2SStartGame);
         }
     }
     catch (Exception e)
     {
         Log.Error(e);
         throw;
     }
 }
예제 #3
0
        public static void CheckMatchCondition(this MatchRoomComponent matchRoomComponent, long matchRoomId)
        {
            try
            {
                MatchRoomConfig matchRoomConfig = Game.Scene.GetComponent <MatchRoomConfigComponent>().GetMatchRoomInfo(matchRoomId);
                while (matchRoomComponent.mAllQueue[matchRoomId].Count >= matchRoomConfig.GameNumber)
                {
                    M2S_StartGame m2S_StartGame = new M2S_StartGame();
                    m2S_StartGame.RoomConfig = matchRoomConfig;
                    for (int i = 0; i < matchRoomConfig.GameNumber; i++)
                    {
                        _TempActorId = 0;
                        _IsAI        = false;
                        if (matchRoomComponent.mAllQueue[matchRoomId][i].GetComponent <UserGateActorIdComponent>() != null)
                        {
                            _TempActorId = matchRoomComponent.mAllQueue[matchRoomId][i].GetComponent <UserGateActorIdComponent>().ActorId;
                        }
                        else
                        {
                            _IsAI = true;
                        }
                        MatchPlayerInfo matchPlayerInfo = MatchPlayerInfoFactory.Create(matchRoomComponent.mAllQueue[matchRoomId][i], _TempActorId, i, _IsAI);;
                        m2S_StartGame.MatchPlayerInfos.Add(matchPlayerInfo);
                    }
                    matchRoomComponent.MatchStartGame(matchRoomId, matchRoomConfig.GameNumber);

                    long toyGameId = Game.Scene.GetComponent <MatchRoomConfigComponent>().GetMatchRoomInfo(matchRoomId).ToyGameId;
                    matchRoomComponent.RoomStartGame(toyGameId, m2S_StartGame);
                }
            }
            catch (System.Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }