FriendData.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 = math.floor(offlineTime/3600)
  63. return string.formatbykey("FriendsOfflineHour",hours)
  64. elseif offlineTime < 259200 then
  65. return string.formatbykey("FriendsOfflineDay",1)
  66. else
  67. return string.formatbykey("FriendsOfflineDay",3)
  68. end
  69. end
  70. function FriendData:StatusStr()
  71. if self.status == 0 then
  72. return ""
  73. elseif self.status == Enum.FriendStatusType.MyInterest then
  74. return "关注"
  75. elseif self.status == Enum.FriendStatusType.MyFans then
  76. return "被关"
  77. elseif self.status == Enum.FriendStatusType.All then
  78. return "互关"
  79. end
  80. return ""
  81. end
  82. function FriendData:StatusImage()
  83. if self.status == 0 then
  84. return "ic_follow_0"
  85. elseif self.status == Enum.FriendStatusType.MyInterest then
  86. return "ic_follow_1"
  87. elseif self.status == Enum.FriendStatusType.MyFans then
  88. return "ic_follow_2"
  89. elseif self.status == Enum.FriendStatusType.All then
  90. return "ic_follow_3"
  91. end
  92. return "ic_follow_0"
  93. end
  94. function FriendData:IsNew()
  95. return self.isNew
  96. end
  97. function FriendData:SetNewState(val)
  98. self.isNew = val
  99. end
  100. return FriendData