NewVipInfo.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ---@class NewVipInfo
  2. NewVipInfo = class()
  3. local this = NewVipInfo
  4. this.vipLevel = 0
  5. this.vipBoughtGifts = {}
  6. this.allVIPRedPoint = {}
  7. this.AllPlayerVip = {}
  8. function this:Init()
  9. self:RegistMessages()
  10. self:Reset()
  11. end
  12. function this:Reset()
  13. end
  14. function this:RegistMessages()
  15. SL:RegisterLUAEvent(LUA_EVENT_ROLE_LOGIN, self.EnterGame, self)
  16. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_ACTION, self.RES_RECHARGE_ACTION, self)
  17. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PLAYER_ENTER_VIEW_INFO, self.RES_PLAYER_ENTER_VIEW_INFO, self)
  18. SL:RegisterLUAEvent(LUA_EVENT_CREATE_PLAYER_SUCCESS, self.LUA_EVENT_CREATE_PLAYER_SUCCESS, self)
  19. end
  20. function this:RES_RECHARGE_ACTION(_, message)
  21. if message.type == "8" then
  22. this.vipLevel = message.data.lv or 0
  23. self:GetAllRedPoint()
  24. SL:onLUAEvent(LUA_EVENT_VIP_CHANGE)
  25. local userid = SL:GetMetaValue("USER_ID")
  26. if not userid then
  27. return
  28. end
  29. local level_str = ""
  30. if this.vipLevel > 0 then
  31. level_str = "v" .. tostring(this.vipLevel)
  32. end
  33. self:SetPlayerHeadVipLevel(userid,level_str)
  34. end
  35. end
  36. function this:GetAllRedPoint()
  37. self.allVIPRedPoint = {}
  38. local allTable = SL:GetConfigTable("cfg_VIP");
  39. for key, value in pairs(allTable) do
  40. if value.grade <= self.vipLevel then
  41. local expackCfg = SL:GetConfig("cfg_VIP_Pack", value.expack)
  42. local count ,totalCount = InfoManager.countInfo:GetLimitAndTotalCountByKey(expackCfg.Limitedid)
  43. self.allVIPRedPoint[value.grade] = count>0
  44. end
  45. end
  46. SL:RefreshPanelALLRedStateKmlByCondition("checkVIPRedDot")
  47. end
  48. function this:EnterGame()
  49. -- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_FirstChargeGift_Info)
  50. end
  51. function this:LUA_EVENT_CREATE_PLAYER_SUCCESS(_id,message)
  52. local uid = tostring(message)
  53. local userid = SL:GetMetaValue("USER_ID")
  54. if uid == userid then
  55. local level_str = ""
  56. if this.vipLevel > 0 then
  57. level_str = "v" .. tostring(this.vipLevel)
  58. end
  59. self:SetPlayerHeadVipLevel(uid,level_str)
  60. else
  61. if this.AllPlayerVip[uid] then
  62. self:SetPlayerHeadVipLevel(uid,this.AllPlayerVip[uid])
  63. end
  64. end
  65. end
  66. function this:RES_PLAYER_ENTER_VIEW_INFO(_id,message)
  67. if not message.vipLv then
  68. return
  69. end
  70. --SL:LogTable(message,true)
  71. local level_str = ""
  72. if message.vipLv > 0 then
  73. level_str = "v" .. tostring(message.vipLv)
  74. end
  75. local uid = tostring(message.rid)
  76. self:SetPlayerHeadVipLevel(uid,level_str)
  77. end
  78. function this:SetPlayerHeadVipLevel(id,level_str)
  79. local is_success = SL:SetHeadVipName(tonumber(id),"Font/Vip_Font",level_str,0,5,-7)
  80. if is_success then
  81. this.AllPlayerVip[id] = nil
  82. else
  83. this.AllPlayerVip[id] = level_str
  84. end
  85. end