private static void CHANGE_AI_RIGHTS_REPLY(byte[] bytes) { ChangeAiRightsReply input = ChangeAiRightsReply.Parser.ParseFrom(bytes); if (input.OwnerId != GameRoomManager.Instance.CurrentPlayer.TokenId) { // 校验, 此内容测试完毕以后, 可以去掉 GameRoomManager.Instance.Log($"RoomMsgReply CHANGE_AI_RIGHTS_REPLY Error - Id is not the same! - {input.OwnerId} : {GameRoomManager.Instance.CurrentPlayer.TokenId}"); return; } if (!input.Ret) { string msg = "AI代理权设置失败! - 实际代码永远不可能走到这里! 如果发现这个错误, 就让服务器去查吧! "; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log($"MSG: CHANGE_AI_RIGHTS_REPLY Error - " + msg); return; } { string msg = ""; if (input.ControlByMe) { msg = $"AI代理权修改: {input.AiAccount} 被我控制!"; GameRoomManager.Instance.AddAiPlayer(input.AiPlayerId, input.AiAccount); // AI-代理权 4-刷新AI玩家身上的资源 UpdateRes output3 = new UpdateRes() { RoomId = input.RoomId, OwnerId = input.AiPlayerId, }; GameRoomManager.Instance.SendMsg(ROOM.UpdateRes, output3.ToByteArray()); } else { msg = $"AI代理权修改: {input.AiAccount} 解除被我的控制!"; GameRoomManager.Instance.RemoveAiPlayer(input.AiPlayerId); } GameRoomManager.Instance.Log($"MSG: CHANGE_AI_RIGHTS_REPLY OK - " + msg); } }
private static void DOWNLOAD_MAP_REPLY(byte[] bytes) { DownloadMapReply input = DownloadMapReply.Parser.ParseFrom(bytes); if (!input.Ret) { string msg = "下载地图失败!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("MSG: DOWNLOAD_MAP_REPLY Error - " + msg); return; } if (input.PackageIndex == 0) {// 第一条此类消息 mapDataBuffers.Clear(); GameRoomManager.Instance.Log($"MSG: DOWNLOAD_MAP_REPLY - 开始下载地图!地图名:{input.RoomName}"); } mapDataBuffers.Add(input.MapData.ToByteArray()); bool ret = false; if (input.IsLastPackage) {// 最后一条此类消息了 int totalSize = 0; foreach (var package in mapDataBuffers) { totalSize += package.Length; } // 同时确保文件名的唯一性和可读性 string mapName = $"{input.RoomName}_{input.RoomId}"; // 把服务器传过来的地图数据写入本地文件 BinaryWriter writer = GameRoomManager.Instance.HexmapHelper.BeginSaveBuffer(mapName); if (writer == null) { return; } foreach (var package in mapDataBuffers) { GameRoomManager.Instance.HexmapHelper.SaveBuffer(writer, package); } GameRoomManager.Instance.HexmapHelper.EndSaveBuffer(ref writer); GameRoomManager.Instance.Log($"MSG: DOWNLOAD_MAP_REPLY - 下载地图成功!地图名:{mapName} - Total Map Size:{totalSize}"); // 从本地文件读取地图,并显示出来 GameRoomManager.Instance.HexmapHelper.Load(mapName); GameRoomManager.Instance.Log($"MSG: DOWNLOAD_MAP_REPLY - 显示地图!地图名:{mapName}"); // 设置房间ID和名字 GameRoomManager.Instance.RoomId = input.RoomId; GameRoomManager.Instance.RoomName = input.RoomName; string msg = $"进入战场 - {input.RoomName}"; GameRoomManager.Instance.Log("MSG: DOWNLOAD_MAP_REPLY OK - " + msg); UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Success); // 2-补充内容,获取城市信息 DownloadCities output = new DownloadCities() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadCities, output.ToByteArray()); // 3-补充内容,获取单位信息 DownloadActors output2 = new DownloadActors() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.DownloadActors, output2.ToByteArray()); // 4-刷新玩家身上的资源 UpdateRes output3 = new UpdateRes() { RoomId = input.RoomId, OwnerId = GameRoomManager.Instance.CurrentPlayer.TokenId, }; GameRoomManager.Instance.SendMsg(ROOM.UpdateRes, output3.ToByteArray()); // 5-刷新玩家身上的行动点 UpdateActionPoint output4 = new UpdateActionPoint() { RoomId = input.RoomId, OwnerId = GameRoomManager.Instance.CurrentPlayer.TokenId, }; GameRoomManager.Instance.SendMsg(ROOM.UpdateActionPoint, output4.ToByteArray()); } }