private static void ENTER_ROOM_REPLY(byte[] bytes) { EnterRoomReply input = EnterRoomReply.Parser.ParseFrom(bytes); if (!input.Ret) { string msg = "进入战场失败:" + input.ErrMsg; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("MSG: ENTER_ROOM_REPLY - " + msg); if (ClientManager.Instance) { ClientManager.Instance.StateMachine.TriggerTransition( ConnectionFSMStateEnum.StateEnum.DISCONNECTED_ROOM); } return; } // 请求地图数据 DownloadMap output = new DownloadMap() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadMap, output.ToByteArray()); // 请求地图上的资源变化数据 DownloadResCell output2 = new DownloadResCell() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadResCell, output2.ToByteArray()); { string msg = "成功进入战场!"; GameRoomManager.Instance.Log($"MSG: ENTER_ROOM_REPLY OK - " + msg); } }
private static void DOWNLOAD_RESCELL(byte[] bytes) { DownloadResCell input = DownloadResCell.Parser.ParseFrom(bytes); RoomLogic roomLogic = ServerRoomManager.Instance.GetRoomLogic(input.RoomId); string msg = null; if (roomLogic != null) { const int PACKAGE_SIZE = 24; int packageCount = Mathf.CeilToInt(roomLogic.ResManager.AllRes.Count * ResInfo.GetSaveSize() / (float)PACKAGE_SIZE); int infoCountForEachPakcage = PACKAGE_SIZE / ResInfo.GetSaveSize(); int packageIndex = 0; NetResCellInfo [] netResInfos = new NetResCellInfo[infoCountForEachPakcage]; int index = 0; foreach (var keyValue in roomLogic.ResManager.AllRes) { var info = new NetResCellInfo() { CellIndex = keyValue.Key, ResType = (int)keyValue.Value.ResType, ResAmount = keyValue.Value.GetAmount(keyValue.Value.ResType), }; netResInfos[index++] = info; if (index == infoCountForEachPakcage) { // 凑够一批就发送 DownloadResCellReply output = new DownloadResCellReply() { RoomId = input.RoomId, Ret = true, PackageCount = packageCount, PackageIndex = packageIndex, InfoCount = index, ResInfo = { netResInfos }, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadResCellReply, output.ToByteArray()); ServerRoomManager.Instance.Log($"MSG: DOWNLOAD_RES - Package:{packageIndex}/{packageCount} - InfoCount:{index}"); packageIndex++; index = 0; } } if (index > 0) { // 最后一段 NetResCellInfo [] netResInfosLast = new NetResCellInfo[index]; Array.Copy(netResInfos, 0, netResInfosLast, 0, index); DownloadResCellReply output = new DownloadResCellReply() { RoomId = input.RoomId, Ret = true, PackageCount = packageCount, PackageIndex = packageIndex, InfoCount = index, ResInfo = { netResInfosLast }, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadResCellReply, output.ToByteArray()); ServerRoomManager.Instance.Log($"MSG: DOWNLOAD_RES OK - Package:{packageIndex}/{packageCount} - InfoCount:{index} - TotalCount:{roomLogic.ResManager.AllRes.Count}"); } return; } else { msg = $"Battlfield is not found! RoomId:{input.RoomId}"; // 战场没有找到! ServerRoomManager.Instance.Log("MSG: DOWNLOAD_RES Error - " + msg); } { DownloadResCellReply output = new DownloadResCellReply() { RoomId = input.RoomId, Ret = false, ErrMsg = msg, }; ServerRoomManager.Instance.SendMsg(_args, ROOM_REPLY.DownloadResCellReply, output.ToByteArray()); } }