Ejemplo n.º 1
0
 //玩家退出房间
 public static bool UserOutRoom(this MatchRoom matchRoom, long userId)
 {
     if (matchRoom.RoomType == RoomType.Match)
     {
         return(true);//随机匹配房间无法退出 只能等待游戏结束 回复成功让玩家回到大厅
     }
     //如果正在游戏接发起投票解散房间
     if (matchRoom.IsGameBeing)
     {
         matchRoom.RommEnterVoteDissolve(userId);//开始投票
         return(false);
     }
     matchRoom.intData = -1;
     //如果是房卡 并且还没开始 就退出房间
     foreach (var player in matchRoom.PlayerInfoDic)
     {
         if (player.Value.User.UserId == userId)
         {
             matchRoom.intData = player.Key;
             matchRoom.PlayerInfoDic.Remove(player.Key);
             matchRoom.BroadcastActorMessage(new Actor_OtherOutRoom()
             {
                 UserId = userId
             });
             break;
         }
     }
     //如果是房主退出房间 直接移除房间
     if (matchRoom.intData == 0)
     {
         Game.Scene.GetComponent <MatchRoomComponent>().RemoveRoom(matchRoom.RoomId);
     }
     else if (matchRoom.intData == -1)
     {
         Log.Error("退出房间玩家不在房间中");
     }
     return(true);
 }