private void OnHarvestStopReply(byte[] bytes) { HarvestStopReply input = HarvestStopReply.Parser.ParseFrom(bytes); if (input.ActorId != ActorId) { return; // 不是自己,略过 } if (!input.Ret) { return; } HexResource.RESOURCE_TYPE resType = (HexResource.RESOURCE_TYPE)input.ResType; HexCell currentCell = HexUnit.Location; HexResource res = currentCell.Res; int level = res.GetLevel(resType); res.SetAmount(resType, input.ResRemain); int levelNew = res.GetLevel(resType); if (level != levelNew) { res.Refresh(currentCell); } string [] resTypes = { "木材", "粮食", "铁矿" }; string msg = $"获取了 {input.ResHarvest} 的 {resTypes[input.ResType]} 资源"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Success); GameRoomManager.Instance.Log("MSG: HarvestStop OK - " + msg + $" - 剩余资源{input.ResRemain}"); // 必要的时候, 刷新地面上的资源数字 PanelRoomMain.Instance.UpdateResInCell(currentCell.Index); }
private void OnHarvestStop(SocketAsyncEventArgs args, byte[] bytes) { HarvestStop input = HarvestStop.Parser.ParseFrom(bytes); if (input.RoomId != RoomId) { return; // 不是自己房间的消息,略过 } if (input.CellIndex == 0) { Debug.LogError("RoomLogic OnHarvestStop Error - Actor position is lost!"); } // 修改地图上的资源数据 var hr = ResManager.GetRes(input.CellIndex); if (hr == null) { hr = new ResInfo(); ResManager.AddRes(input.CellIndex, hr); } hr.SetAmount((ResInfo.RESOURCE_TYPE)input.ResType, input.ResRemain); // 修改玩家身上的资源数据 PlayerInfoInRoom piir = GetPlayerInRoom(input.OwnerId); if (piir == null) { ServerRoomManager.Instance.Log($"RoomLogic OnHarvestStop Error - player not found in server! Id:{input.OwnerId}"); return; } switch ((ResInfo.RESOURCE_TYPE)input.ResType) { case ResInfo.RESOURCE_TYPE.WOOD: piir.AddWood(input.ResHarvest); break; case ResInfo.RESOURCE_TYPE.FOOD: piir.AddFood(input.ResHarvest); break; case ResInfo.RESOURCE_TYPE.IRON: piir.AddIron(input.ResHarvest); break; } HarvestStopReply output = new HarvestStopReply() { RoomId = input.RoomId, OwnerId = input.OwnerId, ActorId = input.ActorId, CellIndex = input.CellIndex, ResType = input.ResType, ResRemain = input.ResRemain, ResHarvest = input.ResHarvest, Ret = true, }; BroadcastMsg(ROOM_REPLY.HarvestStopReply, output.ToByteArray()); // 发送给客户端刷新玩家身上的资源数量 UpdateResReply output2 = new UpdateResReply() { RoomId = input.RoomId, OwnerId = input.OwnerId, Ret = true, Wood = piir.Wood, Food = piir.Food, Iron = piir.Iron, }; ServerRoomManager.Instance.SendMsg(args, ROOM_REPLY.UpdateResReply, output2.ToByteArray()); }