源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
8.4 KiB

  1. BossHomeSceneRankItem = BossHomeSceneRankItem or BaseClass(BaseItem)
  2. local BossHomeSceneRankItem = BossHomeSceneRankItem
  3. function BossHomeSceneRankItem:__init(parent_wnd,prefab_asset,layer_name,tag)
  4. self.base_file = "boss"
  5. self.layout_file = "BossHomeSceneRankItem"
  6. self.tag = tag
  7. self.model = BossHomeModel:getInstance()
  8. self.enemy_list = {}
  9. self.show_data = false
  10. self.show_time = 0--显示的时间
  11. self:Load()
  12. end
  13. function BossHomeSceneRankItem:Load_callback()
  14. self.nodes = {
  15. "img_rank:img:obj","lb_rank:tmp","lb_name:tmp","lb_att:tmp",
  16. "con:obj","btn_team:img:obj","btn_att:img:obj","con/con_tip:obj",
  17. }
  18. self:GetChildren(self.nodes)
  19. self:AddEvents()
  20. if self.need_refreshData then
  21. self:UpdateView()
  22. end
  23. if self.tag == "boss_home" then
  24. lua_resM:setImageSprite(self, self.btn_att_img,'boss_asset',"boss_btn_29",true)
  25. lua_resM:setImageSprite(self, self.btn_team_img,'boss_asset',"boss_btn_30",true)
  26. end
  27. end
  28. function BossHomeSceneRankItem:AddEvents( )
  29. local function call_back( target )
  30. if target == self.btn_team_obj then
  31. if not self.data then return end
  32. local my_team_id = RoleManager.Instance.mainRoleInfo.team_id
  33. local other_team_id = 0
  34. if self.data.type == 0 then
  35. --无组队玩家
  36. else
  37. other_team_id = self.data.role_id
  38. end
  39. -------------------------
  40. if my_team_id == 0 and other_team_id ~= 0 then
  41. GlobalEventSystem:Fire(TeamModel.APPLY_JOIN_TEAM,other_team_id)
  42. elseif my_team_id == 0 and other_team_id == 0 then
  43. GlobalEventSystem:Fire(TeamModel.INVITE_PLAYER,{self.data.role_id})
  44. elseif my_team_id ~= 0 and other_team_id == 0 then
  45. GlobalEventSystem:Fire(TeamModel.INVITE_PLAYER,{self.data.role_id})
  46. elseif my_team_id ~= 0 and other_team_id ~= 0 then
  47. Message.show("双方均有队伍! 请退出队伍再操作!")
  48. end
  49. elseif target == self.btn_att_obj then
  50. if not self.data then return end
  51. local support_data = GuildModel:getInstance():GetCurSupportPlayerInfo()
  52. if self.data.type == 1 then
  53. --队伍的时候,先找到活着的队长,然后找到活着的队员,最后找死的队长
  54. local lead_info = false--队长
  55. local team_info = {}--队员信息
  56. local all_other_vo = SceneManager.Instance:GetAllRoleVos( )
  57. for a,vo in pairs(all_other_vo) do
  58. local temp = Scene:getInstance():GetRole(vo.role_id)
  59. if vo.team_id == self.data.role_id then
  60. if vo.team_job == 1 then
  61. lead_info = vo
  62. else
  63. table.insert( team_info, vo )
  64. end
  65. end
  66. end
  67. -------------------------
  68. local role_target = false
  69. if lead_info and lead_info.hp > 0 then
  70. --先找到活着的队长
  71. role_target = Scene.Instance:GetRole(lead_info.role_id)
  72. elseif team_info[1] then
  73. for k,v in pairs(team_info) do
  74. if v.hp > 0 then
  75. --然后找到活着的队员
  76. role_target = Scene.Instance:GetRole(v.role_id)
  77. break
  78. end
  79. end
  80. end
  81. if not role_target then
  82. --如果没有活的就找死的
  83. if lead_info then
  84. role_target = Scene.Instance:GetRole(lead_info.role_id)
  85. elseif team_info[1] then
  86. role_target = Scene.Instance:GetRole(team_info[1].role_id)
  87. end
  88. end
  89. -------------------------
  90. --对协助目标的判断
  91. local is_support = false
  92. if support_data then
  93. if lead_info and lead_info.role_id == support_data.role_id then
  94. is_support = true
  95. end
  96. if not is_support then
  97. for k,v in pairs(team_info) do
  98. if v.role_id == support_data.role_id then
  99. is_support = true
  100. break
  101. end
  102. end
  103. end
  104. end
  105. if is_support then
  106. --点到了协助目标
  107. Message.show("对方正在接收您的协助")
  108. return
  109. end
  110. -------------------------
  111. if role_target then
  112. Scene.Instance:SetClickTarget(role_target)
  113. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  114. end
  115. else
  116. if support_data and support_data.role_id == self.data.role_id then
  117. --点到了协助目标
  118. Message.show("对方正在接收您的协助")
  119. return
  120. end
  121. local role = Scene.Instance:GetRole(self.data.role_id)
  122. if role then
  123. Scene.Instance:SetClickTarget(role)
  124. GlobalEventSystem:Fire(EventName.STARTAUTOFIGHT)
  125. end
  126. end
  127. end
  128. end
  129. AddClickEvent(self.btn_team_obj,call_back,false)
  130. AddClickEvent(self.btn_att_obj,call_back,false)
  131. local function REFRESH_ENEMY_LIST( data )
  132. if not data then return end
  133. if not self.data then return end
  134. -------------------------
  135. local curTime = TimeUtil:getServerTime()
  136. if self.show_data and (curTime - self.show_data.time <= 5) then
  137. --强制闪烁5s,中间跳过过滤
  138. return
  139. end
  140. self.enemy_list = data
  141. self.show_data = false
  142. for k,v in pairs(self.enemy_list) do
  143. if self.data.type == 1 then
  144. --队伍的时候
  145. local all_other_vo = SceneManager.Instance:GetAllRoleVos( )
  146. for a,vo in pairs(all_other_vo) do
  147. local temp = Scene:getInstance():GetRole(vo.role_id)
  148. if vo.role_id == v.role_id and vo.team_id == self.data.role_id then
  149. self.show_data = v
  150. break
  151. end
  152. end
  153. elseif v.role_id == self.data.role_id then
  154. self.show_data = v
  155. break
  156. end
  157. end
  158. if not self.show_data then
  159. self:CleanAction()
  160. else
  161. self:ShowAction()
  162. end
  163. end
  164. self:BindEvent(self.model, BossHomeConst.REFRESH_ENEMY_LIST, REFRESH_ENEMY_LIST)
  165. end
  166. function BossHomeSceneRankItem:UpdateView( )
  167. if not self.data then return end
  168. self.data.server_num = 0
  169. if self.data.server_num ~= 0 then
  170. self.data.name = GetCSLongName(self.data.name, self.data.server_num)
  171. end
  172. if self.data.type == 1 then
  173. self.lb_name_tmp.text = self.model:GetShortNameStr(string.format( "%s队", self.data.name ))
  174. else
  175. self.lb_name_tmp.text = self.model:GetShortNameStr(self.data.name)
  176. end
  177. -------------------------
  178. local boss_id = self.model:GetCurFightBossId()
  179. if not boss_id then return end
  180. local boss_type = self.model:GetBossTypeByBossId( boss_id )
  181. -------------------------
  182. local boss_max_hp = boss_type and self.model:GetSceneBossHp(boss_type) or 0
  183. if boss_max_hp == 0 and boss_type ~= Config.ConfigBoss.ModuleId.BossHome and boss_type ~= Config.ConfigBoss.ModuleId.GuildBossHome then
  184. self.lb_att_tmp.text = "获取中"
  185. else
  186. self.lb_att_tmp.text = self.model:GetHurtNumStr(self.data.hurt)--string.format("%0.2f%%",self.data.hurt / boss_max_hp * 100)
  187. end
  188. self.img_rank_obj:SetActive(self.index <= 3)
  189. if self.index <= 3 then
  190. self.lb_rank_tmp.text = ""
  191. lua_resM:setImageSprite(self, self.img_rank_img, "common_asset", "com_rank_3_" .. self.index,true)
  192. else
  193. self.lb_rank_tmp.text = self.index
  194. end
  195. local is_me = false
  196. if self.data.type == 1 then
  197. is_me = RoleManager.Instance.mainRoleInfo.team_id == self.data.role_id
  198. else
  199. is_me = self.data.role_id == RoleManager.Instance.mainRoleInfo.role_id
  200. end
  201. self.btn_team_obj:SetActive((self.tag_str == "boss_home") and (not is_me))
  202. self.btn_att_obj:SetActive((self.tag_str == "boss_home") and (not is_me))
  203. end
  204. function BossHomeSceneRankItem:ShowAction( )
  205. --5s的闪现
  206. if (not self.is_loaded) or (not self.show_data) then return end
  207. self.show_time = 5
  208. local function clockFun()
  209. if self.show_time <= 0 then
  210. self:CleanAction()
  211. elseif self.show_time <= 2 then
  212. self.con_obj:SetActive(false)
  213. else
  214. self.con_obj:SetActive(true)
  215. self.con_tip.transform:GetComponent("CanvasGroup").alpha = 0
  216. local function right_action_move( percent )
  217. if percent <= 0.5 then
  218. self.con_tip.transform:GetComponent("CanvasGroup").alpha = percent * 2
  219. else
  220. self.con_tip.transform:GetComponent("CanvasGroup").alpha = 1 - ((percent-0.5) * 2)
  221. end
  222. end
  223. local action = cc.CustomUpdate.New(1,right_action_move)
  224. self:AddAction(action, self.con_tip.transform)
  225. self.show_time = self.show_time - 1
  226. end
  227. end
  228. if not self.close_time_id then
  229. clockFun()
  230. end
  231. self.close_time_id = self.close_time_id or GlobalTimerQuest:AddPeriodQuest(clockFun, 1, -1)
  232. end
  233. function BossHomeSceneRankItem:CleanAction( )
  234. self.show_time = 0
  235. self.con_obj:SetActive(false)
  236. self.show_data = false
  237. if self.close_time_id then
  238. GlobalTimerQuest:CancelQuest(self.close_time_id)
  239. self.close_time_id = nil
  240. end
  241. if self.con.transform then
  242. cc.ActionManager:getInstance():removeAllActionsFromTarget( self.con.transform )
  243. end
  244. end
  245. function BossHomeSceneRankItem:SetData( index, data, tag_str )
  246. self.index = index
  247. self.data = data
  248. self.tag_str = tag_str
  249. if self.is_loaded then
  250. self.need_refreshData = false
  251. self:UpdateView()
  252. else
  253. self.need_refreshData = true
  254. end
  255. end
  256. function BossHomeSceneRankItem:__delete( )
  257. self:CleanAction()
  258. end