private void OnReceiveReady(Session client, BroadPlayerReady recvData) { if (recvData == null || client == null) { return; } int readyCount = 0; for (int i = 0; i < mPlayerList.Count; ++i) { Player player = mPlayerList[i]; if (recvData.RoleId == player.Roleid && client == player.Client) { player.Position = ProtoTransfer.Get(recvData.Position); player.Direction = ProtoTransfer.Get(recvData.Direction); player.SetReady(); } //广播玩家准备(包括自己) if (mProtocol == Protocol.UDP) { player.SendUdp(MessageID.BroadRoomOperation, recvData); } else if (mProtocol == Protocol.KCP) { player.SendKcp(MessageID.BroadRoomOperation, recvData); } if (player.Ready) { readyCount++; } } if (mBegin == false) { //所有的玩家都准备好了,可以开始同步 if (readyCount >= mPlayerList.Count) { mFrameDic = new Dictionary <long, Dictionary <int, List <Command> > >(); BroadBattleGameStart sendData = new BroadBattleGameStart(); sendData.BattleID = mBattleId; sendData.RandSeed = mRandSeed; sendData.UdpPort = ServerConfig.UDP_PORT; sendData.FrameInterval = mFrameInterval; BroadCast(MessageID.BroadBattleStart, sendData, true); BeginGame(); } } else //断线重连 { Player user = GetPlayer(recvData.RoleId); if (user != null) { BroadBattleGameStart sendData = new BroadBattleGameStart(); sendData.BattleID = mBattleId; sendData.RandSeed = mRandSeed; sendData.UdpPort = ServerConfig.UDP_PORT; sendData.FrameInterval = mFrameInterval; //user.SendUdp(MessageID.GM_BEGIN_BC, sendData); /* * GM_Frame_BC frameData = new GM_Frame_BC(); * * //给他发送当前帧之前的数据 * for (long frame = 1; frame < mCurrentFrame - 1; ++frame) * { * if (mFrameDic.ContainsKey(frame)) * { * frameData.frame = frame; * frameData.frametime = 0; * var it = mFrameDic[frame].GetEnumerator(); * while (it.MoveNext()) * { * for (int i = 0, count = it.Current.Value.Count; i < count; ++i) * { * GMCommand cmd = ProtoTransfer.Get(it.Current.Value[i]); * * frameData.command.Add(cmd); * } * } * user.SendUdp(MessageID.GM_FRAME_BC, frameData); * } * } */ } } }