HeroTitleProxy.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. local RemoteProxy = requireProxy( "remote/RemoteProxy" )
  2. local HeroTitleProxy = class( "HeroTitleProxy", RemoteProxy )
  3. HeroTitleProxy.NAME = global.ProxyTable.HeroTitleProxy
  4. function HeroTitleProxy:ctor()
  5. self._activateTitle = nil --激活的称号
  6. self._titleData = {}
  7. self._titleList = {}
  8. HeroTitleProxy.super.ctor( self )
  9. end
  10. function HeroTitleProxy:onRegister()
  11. HeroTitleProxy.super.onRegister(self)
  12. end
  13. --获取已激活的称号id
  14. function HeroTitleProxy:getActivateTitle()
  15. return self._activateTitle
  16. end
  17. function HeroTitleProxy:getTitleList()
  18. return self._titleList
  19. end
  20. function HeroTitleProxy:getTitleIdByTypeId(id)
  21. local ItemConfigProxy = global.Facade:retrieveProxy(global.ProxyTable.ItemConfigProxy)
  22. return ItemConfigProxy:GetItemLooks(id)
  23. end
  24. function HeroTitleProxy:getTitleTime(id)
  25. if self._titleData[id] then
  26. return self._titleData[id].time
  27. end
  28. return nil
  29. end
  30. --称号界面 已激活的icon
  31. function HeroTitleProxy:getTitleActivateImage(id)
  32. local titleId = self:getTitleIdByTypeId(id)
  33. if global.isWinPlayMode then
  34. return string.format("%s%s%s.png", global.MMO.PATH_RES_PRIVATE, "title_icon/", titleId + 2)
  35. else
  36. return string.format("%s%s%s.png", global.MMO.PATH_RES_PRIVATE, "title_icon/", titleId + 3)
  37. end
  38. return nil
  39. end
  40. --称号列表的图片
  41. function HeroTitleProxy:getTitleListImage(id)
  42. local titleId = self:getTitleIdByTypeId(id)
  43. if global.isWinPlayMode then
  44. return string.format("%s%s%s.png", global.MMO.PATH_RES_PRIVATE, "title_icon/", titleId + 1)
  45. else
  46. return string.format("%s%s%s.png", global.MMO.PATH_RES_PRIVATE, "title_icon/", titleId + 2)
  47. end
  48. return nil
  49. end
  50. --场景中的图片
  51. function HeroTitleProxy:getSceneTitleImage(id)
  52. local titleId = self:getTitleIdByTypeId(id)
  53. return string.format("%s%s%s.png", global.MMO.PATH_RES_PRIVATE, "title_icon/", titleId)
  54. end
  55. --获取称号列表
  56. function HeroTitleProxy:ResquestTitleList()
  57. LuaSendMsg( global.MsgType.MSG_CS_TITLE_REQUEST_HERO, 1)
  58. end
  59. --激活称号
  60. function HeroTitleProxy:ResquestActivateTitle(id)
  61. LuaSendMsg( global.MsgType.MSG_CS_TITLE_REQUEST_HERO, 4, id)
  62. end
  63. --卸下称号
  64. function HeroTitleProxy:ResquestDisboardTitle()
  65. LuaSendMsg( global.MsgType.MSG_CS_TITLE_REQUEST_HERO, 5)
  66. end
  67. function HeroTitleProxy:handle_MSG_SC_TITLE_REPONSE( msg )
  68. local header = msg:GetHeader()
  69. if header.recog == 1 then
  70. local jsonData = ParseRawMsgToJson(msg)
  71. --称号列表
  72. self._activateTitle = {}
  73. self._titleList = {}
  74. if not jsonData then return end
  75. if jsonData.data then
  76. for i,v in pairs(jsonData.data) do
  77. local id = v[1]
  78. local time = v[2]
  79. local data = {id = id, time = time, index = i}
  80. self._titleData[id] = data
  81. self._titleList[i] = data
  82. end
  83. end
  84. self._activateTitle = jsonData.active
  85. elseif header.recog == 2 then
  86. --增加称号
  87. local id = header.param1
  88. if id and id > 0 then
  89. local time = header.param2
  90. if not self._titleData[id] then
  91. local index = #self._titleList + 1
  92. local data = {id = id, time = time, index = index}
  93. self._titleData[id] = data
  94. self._titleList[index] = data
  95. else
  96. self._titleData[id].time = time
  97. end
  98. end
  99. elseif header.recog == 3 then
  100. --删除称号
  101. local id = header.param1
  102. local config = self._titleData[id]
  103. if config then
  104. local index = config.index
  105. if index and self._titleList[index] then
  106. self._titleList[index] = nil
  107. end
  108. end
  109. self._titleData[id] = nil
  110. elseif header.recog == 4 then
  111. --激活
  112. if header.param1 and header.param1 > 0 then
  113. self._activateTitle = header.param1
  114. end
  115. elseif header.recog == 5 then
  116. --卸下
  117. self._activateTitle = nil
  118. elseif header.recog == 6 then
  119. --清理全部称号
  120. self._activateTitle = nil
  121. self._titleList = {}
  122. self._titleData = {}
  123. end
  124. global.Facade:sendNotification( global.NoticeTable.Layer_Title_Refresh_Hero )
  125. end
  126. function HeroTitleProxy:RegisterMsgHandler()
  127. HeroTitleProxy.super.RegisterMsgHandler(self)
  128. local msgType = global.MsgType
  129. LuaRegisterMsgHandler( msgType.MSG_SC_TITLE_REPONSE_HERO, handler( self, self.handle_MSG_SC_TITLE_REPONSE) )
  130. end
  131. return HeroTitleProxy