PlayerTitleProxy.lua 5.0 KB

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