Exemplo n.º 1
0
    private static void DOWNLOAD_RESCELL_REPLY(byte[] bytes)
    {
        DownloadResCellReply input = DownloadResCellReply.Parser.ParseFrom(bytes);

        if (!input.Ret)
        {
            string msg = "下载资源数据失败! - " + input.ErrMsg;
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY OK - " + msg);
            return;
        }
        List <HexGridChunk> chunkList = new List <HexGridChunk>();

        for (int i = 0; i < input.InfoCount; ++i)
        {
            HexCell     cell = GameRoomManager.Instance.HexmapHelper.GetCell(input.ResInfo[i].CellIndex);
            HexResource hr   = cell.Res;
            hr.ResType = (HexResource.RESOURCE_TYPE)input.ResInfo[i].ResType;
            hr.SetAmount(hr.ResType, input.ResInfo[i].ResAmount);
            cell.UpdateFeatureLevelFromRes();
            if (!chunkList.Contains(cell.chunk))
            {
                chunkList.Add(cell.chunk);
            }
        }
        // 刷新模型
        foreach (var chunk in chunkList)
        {
            chunk.Refresh();
        }

        if (input.PackageIndex == 0 && input.PackageIndex < input.PackageCount - 1)
        {
            resCount = input.InfoCount;
            string msg = "开始下载资源数据...";
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY - " + msg + $"PackageCount:{input.PackageCount}");
        }
        else if (input.PackageIndex == input.PackageCount - 1)
        {
            resCount += input.InfoCount;
            string msg = "下载资源数据成功!";
            GameRoomManager.Instance.Log($"MSG: DOWNLOAD_RES_REPLY OK - " + msg + $"PackageCount:{input.PackageCount} - Res Count:{resCount}");
        }
    }
Exemplo n.º 2
0
    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());
        }
    }