ProtoHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ET.Server
  4. {
  5. /// <summary>
  6. /// Proto工具类
  7. /// </summary>
  8. public static class ProtoHelper
  9. {
  10. /// <summary>
  11. /// 玩家信息转proto
  12. /// </summary>
  13. /// <param name="player"></param>
  14. /// <returns></returns>
  15. public static PlayerInfo PlayerToProto(Player player)
  16. {
  17. return new PlayerInfo()
  18. {
  19. id = player.Id,
  20. name = player.Name,
  21. sex = player.Sex,
  22. exp = player.Exp,
  23. level = player.Level,
  24. vip = 0
  25. };
  26. }
  27. /// <summary>
  28. /// 房间信息转proto
  29. /// </summary>
  30. /// <param name="room"></param>
  31. /// <returns></returns>
  32. public static RoomInfo RoomToProto(Room room)
  33. {
  34. RoomInfo info = new RoomInfo();
  35. info.RoomId = room.RoomId;
  36. info.Type = room.Type;
  37. info.OwnerId = room.OwnerId;
  38. info.PlayerList = new List<PlayerInfo>();
  39. foreach (Player p in room.Players.Where(p => p != null))
  40. {
  41. info.PlayerList.Add(ProtoHelper.PlayerToProto(p));
  42. }
  43. return info;
  44. }
  45. }
  46. }