FriendData.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. local FriendData = class("FriendData")
  2. function FriendData:ctor(id)
  3. self.uid = id
  4. self.head = 0
  5. self.job = 0
  6. self.level = 1
  7. self.fightPower = 0
  8. self.sex = 0
  9. self.status = 0
  10. self.onlineStatus = false
  11. self.lastOnlineTime = 0
  12. self.isNew = false
  13. self.param = nil
  14. end
  15. -- message CommonPlayerBriefInfo {
  16. -- uint64 uid = 1; //玩家唯一ID
  17. -- string nick_name = 2; //玩家nickname
  18. -- int32 img_id = 3; //头像ID
  19. -- int32 gender = 4; //性別
  20. -- int32 level = 5; //等级
  21. -- int32 config_id = 6; //职业ID
  22. -- int32 fight_power = 7; //战斗力(历史最高战力)
  23. -- bool online_state = 8; //玩家在线状态
  24. -- uint64 online_time = 9; //玩家最后在线时间
  25. -- }
  26. -- //0无状态 1关注该玩家 2该玩家关注自己 3互相关注
  27. function FriendData:SetData(brief_info)
  28. if brief_info == nil or brief_info.uid ~= self.uid then
  29. return
  30. end
  31. self.head = CommonUtil.GetPlayerHeadIcon(brief_info)
  32. self.job = brief_info.config_id
  33. self.level = brief_info.level
  34. self.sex = brief_info.gender
  35. self.name = CommonUtil.GetVaildNickName(brief_info.nick_name)
  36. self.fightPower = brief_info.fight_power
  37. self.onlineStatus = brief_info.online_state --在线状态
  38. self.lastOnlineTime = brief_info.online_time --玩家最后在线时间
  39. self.headFrameId = brief_info.head_frame_id --头像框id
  40. end
  41. function FriendData:SetStatus(status)
  42. self.status = status --关注状态 0无状态 1关注该玩家 2该玩家关注自己 3互相关注
  43. end
  44. function FriendData:GetOnlineStatus()
  45. if self.onlineStatus then
  46. return string.formatbykey("FriendsOnline")
  47. else
  48. return self:GetOfflineTimeStr()
  49. end
  50. end
  51. function FriendData:GetOfflineTime()
  52. if self.onlineStatus then
  53. return 0
  54. end
  55. return (ManagerContainer.LuaTimerMgr:CurLuaServerTime() - self.lastOnlineTime)/1000
  56. end
  57. function FriendData:GetOfflineTimeStr()
  58. local offlineTime = self:GetOfflineTime()
  59. if offlineTime < 3600 then
  60. return string.formatbykey("FriendsOffline")
  61. elseif offlineTime < 86400 then
  62. local hours = 0
  63. if IsNewLuadll then
  64. hours = math.floor(offlineTime/3600)
  65. else
  66. hours = math.floor(#offlineTime/3600)
  67. end
  68. return string.formatbykey("FriendsOfflineHour",hours)
  69. elseif offlineTime < 259200 then
  70. return string.formatbykey("FriendsOfflineDay",1)
  71. else
  72. return string.formatbykey("FriendsOfflineDay",3)
  73. end
  74. end
  75. function FriendData:StatusStr()
  76. if self.status == 0 then
  77. return ""
  78. elseif self.status == Enum.FriendStatusType.MyInterest then
  79. return "关注"
  80. elseif self.status == Enum.FriendStatusType.MyFans then
  81. return "被关"
  82. elseif self.status == Enum.FriendStatusType.All then
  83. return "互关"
  84. end
  85. return ""
  86. end
  87. function FriendData:StatusImage()
  88. if self.status == 0 then
  89. return "ic_follow_0"
  90. elseif self.status == Enum.FriendStatusType.MyInterest then
  91. return "ic_follow_1"
  92. elseif self.status == Enum.FriendStatusType.MyFans then
  93. return "ic_follow_2"
  94. elseif self.status == Enum.FriendStatusType.All then
  95. return "ic_follow_3"
  96. end
  97. return "ic_follow_0"
  98. end
  99. function FriendData:IsNew()
  100. return self.isNew
  101. end
  102. function FriendData:SetNewState(val)
  103. self.isNew = val
  104. end
  105. return FriendData