/// <summary> /// 账号在房间内发起准备 /// </summary> /// <param name="accountId"></param> /// <returns></returns> public bool ReadyInRoom(int accountId) { bool isSuccess = false; for (int i = 0; i < MemberInfoArray.Length; ++i) { if (MemberInfoArray[i].playerId == accountId) { MemberInfoArray[i].isReady = true; isSuccess = true; } } if (!isSuccess) { return(false); } if (IsAllMemberReady()) { bool isNotFind = false; LBPlayerEnterSceneInfo[] playerInfos = new LBPlayerEnterSceneInfo[MemberInfoArray.Length]; for (int i = 0; i < MemberInfoArray.Length; ++i) { LBPlayer curPlayer = LBPlayerManager.Instance.GetPlayerByPlayerId(MemberInfoArray[i].playerId); if (null == curPlayer) { //异常情况,应该是bug LBLogger.Error(LogTag, "准备进入场景时找不到对应的玩家 " + MemberInfoArray[i].playerId); isNotFind = true; break; } playerInfos[i] = new LBPlayerEnterSceneInfo(); playerInfos[i].playerId = curPlayer.PlayerId; playerInfos[i].playerName = curPlayer.PlayerName; playerInfos[i].connectionId = curPlayer.ConnectionId; } if (isNotFind) { //异常处理情况 } else { if (LBSceneManager.Instance.PlayersEnterScene(RoomId, playerInfos)) { IsPlaying = true; } else { LBLogger.Error(LogTag, "进入场景失败,房间ID:" + RoomId); } } } else { BroadcastEvent(RpId.RoomAccountInfo, RpRoomMemberInfo.Serialization(RqCommonFunc.CreateRoomPlayerList(RoomId))); } return(true); }
/// <summary> /// 账号进入房间 /// </summary> /// <param name="playerId"></param> /// <returns></returns> public bool EnterRoom(int playerId) { LBLogger.Error(LogTag, "请求进入房间 " + playerId); int emptyIndex = FindEmptyMemberIndex(); if (emptyIndex < 0) { return(false); } MemberInfoArray[emptyIndex].playerId = playerId; LBPlayer curPlayer = LBPlayerManager.Instance.GetPlayerByPlayerId(playerId); if (null != curPlayer) { LBLogger.Error(LogTag, "发起进入房间消息 " + playerId + " " + curPlayer.ConnectionId); LBPeerManager.Instance.SendMessage(curPlayer.ConnectionId, RpId.EnterRoom, RpEnterRoom.Serialization(true, RoomId, RoomName)); } BroadcastEvent(RpId.RoomAccountInfo, RpRoomMemberInfo.Serialization(RqCommonFunc.CreateRoomPlayerList(RoomId))); return(true); }