KLUIBossHpPanel.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. ---@class KLUIBossHpPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIBossHpPanelView
  3. local KLUIBossHpPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIBossHpPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:DataListInitData(self.view.drop_data_list,
  8. function()
  9. return #self.allDrop
  10. end,
  11. function(realIndex)
  12. return self:FastDataListItemGetFunc(realIndex)
  13. end,
  14. nil,
  15. function(realIndex, kmlcontrol)
  16. return self:FastDataListItemUpdateFunc(realIndex, kmlcontrol)
  17. end)
  18. self.drop_all_item = {}
  19. self.updateID = SL:Schedule(self.updateID, 0, 2, -1, function()
  20. self:Update()
  21. end)
  22. end
  23. local maxDixtance = 10
  24. function this:Update()
  25. if not self.parm or not self.parm.id then
  26. return
  27. end
  28. local role = SL:GetRoleById(self.parm.id)
  29. if not role then
  30. SL:CloseBossHp()
  31. return
  32. end
  33. local playerPos = SL:GetMetaValue(EMetaVarGetKey.MAP_PLAYER_POS)
  34. if not playerPos then
  35. return
  36. end
  37. local distance = SL:GetPointDistance(playerPos, role.data.OldCoord)
  38. if distance > maxDixtance then
  39. SL:CloseBossHp()
  40. return
  41. end
  42. end
  43. ---创建或者刷新界面数据时调用
  44. function this:Refresh()
  45. end
  46. function this:RefreshUI(parm)
  47. if self.parm and self.parm.id and self.parm.id == parm.id then
  48. self:CheckPKMode()
  49. return
  50. end
  51. self.parm = parm
  52. SL:onLUAEvent(LUA_EVENT_HIDE_RIGHT_BTN_VIEW)
  53. local is_player = SL:GetMetaValue(EMetaVarGetKey.ACTOR_IS_PLAYER, self.parm.id)
  54. local role = SL:GetRoleById(self.parm.id)
  55. local hp = SL:GetMetaValue(EMetaVarGetKey.ACTOR_HP, self.parm.id)
  56. if not hp then
  57. hp = 0
  58. end
  59. local maxhp = SL:GetMetaValue(EMetaVarGetKey.ACTOR_MAXHP, self.parm.id)
  60. if not maxhp then
  61. maxhp = 1
  62. end
  63. local value = Mathf.Ceil(hp / maxhp * 100)
  64. local is_att = ""
  65. if is_player then
  66. is_att = SL:GetMetaValue(EMetaVarGetKey.Check_PKMODE_IS_ATTACK_PLAYER, self.parm.id)
  67. end
  68. self.allDrop = {}
  69. self.ownerRid = InfoManager.monsterAffiliationInfo:GetMonsterAffiliationByRid(self.parm.id)
  70. self.maxHurt_Rid = InfoManager.monsterAffiliationInfo:GetMonsterMaxHurtByRid(self.parm.id)
  71. self:RefreshName()
  72. GUI:SetLoadingbar_startper(self.view.sliderHp, value)
  73. GUI:SetLoadingbar_startper(self.view.sliderHp2, value)
  74. GUI:SetLoadingbar_startper(self.view.sliderHp3, value)
  75. self:CheckHpColor()
  76. self:CheckQiangDuoBtn()
  77. if is_player then
  78. local baseCareer = role.data.career.baseCareer
  79. local src = "1" .. baseCareer
  80. GUI:Image_loadTexture(self.view.icon, src, "Atlas/MUIcon.spriteatlas")
  81. else
  82. local cdfId = role.data.serverData.cfgId
  83. local src = SL:GetConfig("cfg_monster", cdfId).icon
  84. GUI:Image_loadTexture(self.view.icon, src, "Atlas/Monster_icon.spriteatlas")
  85. end
  86. GUI:DataListUpdateData(self.view.drop_data_list)
  87. end
  88. function this:CheckPKMode()
  89. self:CheckQiangDuoBtn()
  90. self:CheckHpColor()
  91. self:RefreshName()
  92. end
  93. function this:CheckHpColor()
  94. local is_player = SL:GetMetaValue(EMetaVarGetKey.ACTOR_IS_PLAYER, self.parm.id)
  95. local is_att = ""
  96. if is_player then
  97. is_att = SL:GetMetaValue(EMetaVarGetKey.Check_PKMODE_IS_ATTACK_PLAYER, self.parm.id)
  98. end
  99. local is_owner = true
  100. local userid = SL:GetMetaValue("USER_ID")
  101. userid = tonumber(userid)
  102. local is_monster = SL:GetMetaValue(EMetaVarGetKey.ACTOR_IS_MONSTER, self.parm.id)
  103. ----怪物的血条显示规则和玩家的不一样
  104. if is_monster then
  105. if not self.ownerRid or self.ownerRid == 0 or self.ownerRid == userid then
  106. is_owner = true
  107. else
  108. is_owner = false
  109. end
  110. local role = SL:GetRoleById(self.parm.id)
  111. local cdfId = role.data.serverData.cfgId
  112. local mgroup = SL:GetConfig("cfg_monster", cdfId).mgroup
  113. local hate = 0
  114. if mgroup and #mgroup > 0 then
  115. hate = SL:GetConfig("cfg_boss_drop", mgroup[1], "mgroup").droptype
  116. end
  117. --SL:LogError("hate-----"..cdfId.. " "..hate)
  118. self.hate = hate
  119. if hate == 0 then
  120. GUI:setVisible(self.view.sliderHp, true)
  121. GUI:setVisible(self.view.sliderHp2, false)
  122. GUI:setVisible(self.view.sliderHp3, false)
  123. elseif hate == 1 then
  124. local hateId = self.maxHurt_Rid
  125. if hateId and hateId ~= 0 then
  126. if userid == hateId then
  127. GUI:setVisible(self.view.sliderHp, true)
  128. GUI:setVisible(self.view.sliderHp2, false)
  129. GUI:setVisible(self.view.sliderHp3, false)
  130. else
  131. GUI:setVisible(self.view.sliderHp, false)
  132. GUI:setVisible(self.view.sliderHp2, false)
  133. GUI:setVisible(self.view.sliderHp3, true)
  134. end
  135. else
  136. GUI:setVisible(self.view.sliderHp, true)
  137. GUI:setVisible(self.view.sliderHp2, false)
  138. GUI:setVisible(self.view.sliderHp3, false)
  139. end
  140. elseif hate == 2 then
  141. GUI:setVisible(self.view.sliderHp, true)
  142. GUI:setVisible(self.view.sliderHp2, false)
  143. GUI:setVisible(self.view.sliderHp3, false)
  144. elseif hate == 3 then
  145. local hateId = self.maxHurt_Rid
  146. if hateId and hateId ~= 0 then
  147. if userid == hateId then
  148. GUI:setVisible(self.view.sliderHp, true)
  149. GUI:setVisible(self.view.sliderHp2, false)
  150. GUI:setVisible(self.view.sliderHp3, false)
  151. else
  152. GUI:setVisible(self.view.sliderHp, false)
  153. GUI:setVisible(self.view.sliderHp2, false)
  154. GUI:setVisible(self.view.sliderHp3, true)
  155. end
  156. else
  157. GUI:setVisible(self.view.sliderHp, true)
  158. GUI:setVisible(self.view.sliderHp2, false)
  159. GUI:setVisible(self.view.sliderHp3, false)
  160. end
  161. elseif hate == 4 then
  162. GUI:setVisible(self.view.sliderHp, true)
  163. GUI:setVisible(self.view.sliderHp2, false)
  164. GUI:setVisible(self.view.sliderHp3, false)
  165. elseif hate == 5 then
  166. if is_owner then
  167. GUI:setVisible(self.view.sliderHp, true)
  168. GUI:setVisible(self.view.sliderHp2, false)
  169. GUI:setVisible(self.view.sliderHp3, false)
  170. else
  171. GUI:setVisible(self.view.sliderHp, false)
  172. GUI:setVisible(self.view.sliderHp2, false)
  173. GUI:setVisible(self.view.sliderHp3, true)
  174. end
  175. end
  176. else
  177. if string.isNullOrEmpty(is_att) then
  178. GUI:setVisible(self.view.sliderHp, true)
  179. GUI:setVisible(self.view.sliderHp2, false)
  180. GUI:setVisible(self.view.sliderHp3, false)
  181. else
  182. GUI:setVisible(self.view.sliderHp, false)
  183. GUI:setVisible(self.view.sliderHp2, true)
  184. GUI:setVisible(self.view.sliderHp3, false)
  185. end
  186. end
  187. end
  188. function this:CheckQiangDuoBtn(...)
  189. local rid = SL:GetMetaValue("MAIN_ACTOR_ID")
  190. rid = tonumber(rid)
  191. local is_monster = SL:GetMetaValue(EMetaVarGetKey.ACTOR_IS_MONSTER, self.parm.id)
  192. if not is_monster then
  193. GUI:setVisible(self.view.snatchBtn, false)
  194. return
  195. end
  196. local userid = SL:GetMetaValue("USER_ID")
  197. userid = tonumber(userid)
  198. local is_owner = true
  199. if not self.ownerRid or self.ownerRid == 0 or self.ownerRid == userid then
  200. is_owner = true
  201. else
  202. is_owner = false
  203. end
  204. local role = SL:GetRoleById(self.parm.id)
  205. local cdfId = role.data.serverData.cfgId
  206. local mgroup = SL:GetConfig("cfg_monster", cdfId).mgroup
  207. local hate = 0
  208. if mgroup and #mgroup > 0 then
  209. hate = SL:GetConfig("cfg_boss_drop", mgroup[1], "mgroup").droptype
  210. end
  211. if hate == 0 then
  212. GUI:setVisible(self.view.snatchBtn, false)
  213. elseif hate == 1 then
  214. local hateId = self.maxHurt_Rid
  215. if hateId and hateId ~= 0 then
  216. if userid == hateId then
  217. GUI:setVisible(self.view.snatchBtn, false)
  218. else
  219. GUI:setVisible(self.view.snatchBtn, true)
  220. end
  221. else
  222. GUI:setVisible(self.view.snatchBtn, false)
  223. end
  224. elseif hate == 2 then
  225. GUI:setVisible(self.view.snatchBtn, false)
  226. elseif hate == 3 then
  227. local hateId = self.maxHurt_Rid
  228. if hateId and hateId ~= 0 then
  229. if userid == hateId then
  230. GUI:setVisible(self.view.snatchBtn, false)
  231. else
  232. GUI:setVisible(self.view.snatchBtn, true)
  233. end
  234. else
  235. GUI:setVisible(self.view.snatchBtn, false)
  236. end
  237. elseif hate == 4 then
  238. GUI:setVisible(self.view.snatchBtn, false)
  239. elseif hate == 5 then
  240. if is_owner then
  241. GUI:setVisible(self.view.snatchBtn, false)
  242. else
  243. GUI:setVisible(self.view.snatchBtn, true)
  244. end
  245. end
  246. end
  247. ---注册UI事件和服务器消息
  248. function this:RegistEvents()
  249. SL:RegisterLUAEvent(LUA_EVENT_NET_PLAYER_DIE, self.PlayerDie, self) --玩家死亡
  250. SL:RegisterLUAEvent(LUA_EVENT_MONSTER_DIE, self.MonsterDie, self) --怪物死亡
  251. SL:RegisterLUAEvent(LUA_EVENT_ROLE_HP_CHANGE, self.HpChange, self) --角色血量变化
  252. SL:RegisterLUAEvent(LUA_EVENT_HIDE_BOSS_HP, self.HideBossHp, self) --隐藏boss血条
  253. SL:RegisterLUAEvent(LUA_EVENT_CANCEL_HIDE_BOSS_HP, self.CancelHideBossHp, self) --取消隐藏boss血条
  254. SL:RegisterLUAEvent(LUA_EVENT_MONSTER_TARGET_HATE, self.HeatChange, self) --怪物仇恨目标改变
  255. SL:RegisterLUAEvent(LUA_EVENT_MONSTER_AFFILIATION_CHANGE, self.LUA_EVENT_MONSTER_AFFILIATION_CHANGE, self) --归属改变
  256. GUI:AddOnClickEvent(self.view.KLUIBossHpButton, self, self.OnClickBossHp)
  257. GUI:AddOnClickEvent(self.view.snatchBtn, self, self.OnClickSnatchBtn)
  258. SL:RegisterLUAEvent(Event.CloseTeamTipsUI, self.CloseTeamTipsUI, self)
  259. end
  260. function this:CloseTeamTipsUI()
  261. self.isOnClick = false
  262. end
  263. function this:OnClickBossHp()
  264. if self.parm and self.parm.id then
  265. local role = SL:GetRoleById(self.parm.id)
  266. if role then
  267. if role.RoleType == ERoleType.Player then
  268. self.isOnClick = true
  269. GUI:UIPanel_Open("dev/ui/FriendSys/Panel/KLFriendOperate/KLFriendOperatePanel", nil, nil, { rid = role.data.id, name = role.data.name })
  270. return
  271. end
  272. end
  273. end
  274. end
  275. function this:OnClickSnatchBtn()
  276. if not self.hate then
  277. return
  278. end
  279. local rid = SL:GetMetaValue("MAIN_ACTOR_ID")
  280. rid = tonumber(rid)
  281. if self.hate == 5 then
  282. if rid ~= self.ownerRid and self.ownerRid ~= 0 then
  283. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.AllAttack)
  284. SL:SetHookAttackTargetId(self.ownerRid)
  285. SL:StartOnHook(true)
  286. end
  287. else
  288. local hateId = self.maxHurt_Rid
  289. if hateId and hateId ~= 0 and hateId ~= rid then
  290. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.AllAttack)
  291. SL:SetHookAttackTargetId(hateId)
  292. SL:StartOnHook(true)
  293. end
  294. end
  295. end
  296. function this:PlayerDie(_, message)
  297. if self.parm.id == message then
  298. self.parm = nil
  299. SL:CloseBossHp()
  300. end
  301. end
  302. function this:MonsterDie(_, message)
  303. if self.parm and self.parm.id == message then
  304. self.parm = nil
  305. SL:CloseBossHp()
  306. end
  307. end
  308. function this:HpChange(_, message)
  309. if self.parm and self.parm.id == message.id then
  310. local hp = message.hp
  311. local maxhp = message.maxhp
  312. local value = Mathf.Ceil(hp / maxhp * 100)
  313. GUI:SetLoadingbar_startper(self.view.sliderHp, value)
  314. GUI:SetLoadingbar_startper(self.view.sliderHp2, value)
  315. GUI:SetLoadingbar_startper(self.view.sliderHp3, value)
  316. end
  317. end
  318. function this:FastDataListItemGetFunc(realIndex)
  319. local data = self.allDrop[realIndex + 1]
  320. local message = { cfgId = data, itemIndex = realIndex + 1 }
  321. local item = GUI:UIPanel_Open("dev/ui/MainUI/Item/KLBossHp/KLBossHpItem", self.view.drop_data_list, self, message, true)
  322. self.drop_all_item[item.view.root] = item
  323. return item.view.root
  324. end
  325. function this:FastDataListItemUpdateFunc(realIndex, kmlcontrol)
  326. local data = self.allDrop[realIndex + 1]
  327. self.drop_all_item[kmlcontrol]:RefreshItem(data)
  328. end
  329. function this:HideBossHp()
  330. if self.isOnClick then
  331. GUI:UIPanel_Close("dev/ui/Team/Panel/KLUITeamTips/KLUITeamTipsPanel")
  332. end
  333. end
  334. function this:CancelHideBossHp()
  335. end
  336. function this:HeatChange(_, message)
  337. if self.parm and message.id == self.parm.id then
  338. self:CheckQiangDuoBtn()
  339. self:CheckHpColor()
  340. self:RefreshName()
  341. end
  342. end
  343. ---归属改变
  344. ---@param message RoleChangeData
  345. function this:LUA_EVENT_MONSTER_AFFILIATION_CHANGE(_, message)
  346. if message.rid == self.parm.id then
  347. self.ownerRid = message.ownerRid
  348. self.maxHurt_Rid = message.maxHurt
  349. self:CheckQiangDuoBtn()
  350. self:CheckHpColor()
  351. self:RefreshName()
  352. end
  353. end
  354. function this:RefreshName()
  355. local title = ""
  356. local color = "#FF3939"
  357. if self.parm then
  358. self.allDrop = {}
  359. local is_player = SL:GetMetaValue(EMetaVarGetKey.ACTOR_IS_PLAYER, self.parm.id)
  360. local name = SL:GetMetaValue(EMetaVarGetKey.ACTOR_NAME, self.parm.id)
  361. local role = SL:GetRoleById(self.parm.id)
  362. local userid = SL:GetMetaValue("USER_ID")
  363. userid = tonumber(userid)
  364. if is_player then
  365. local level = SL:GetMetaValue(EMetaVarGetKey.ACTOR_LEVEL, self.parm.id)
  366. title = "Lv." .. level .. " " .. name
  367. else
  368. local all_drop = SL:GetConfig('cfg_monster', role.data.serverData.cfgId, 'id').UIDrop
  369. if all_drop and #all_drop > 0 then
  370. local baseCareer = SL:GetMetaValue(EMetaVarGetKey.JOB)
  371. for _, one_reward in ipairs(all_drop) do
  372. if one_reward[1] == baseCareer then
  373. table.insert(self.allDrop, { cfgId = one_reward[2] })
  374. end
  375. end
  376. end
  377. local level = SL:GetConfig("cfg_monster", role.data.serverData.cfgId).level
  378. local bosstype = SL:GetConfig("cfg_monster", role.data.serverData.cfgId).type
  379. if bosstype == 2 then
  380. color = "#E6E600"
  381. end
  382. ----显示怪物的仇恨目标
  383. local hateId = self.maxHurt_Rid
  384. local hateName1 = ""
  385. if hateId and hateId ~= 0 then
  386. local hName = SL:GetMetaValue(EMetaVarGetKey.ACTOR_NAME, tonumber(hateId))
  387. if hName then
  388. hateName1 = "<color=#dce1e5>" .. hName .. "</color>"
  389. end
  390. end
  391. ----显示怪物的归属玩家
  392. local hateName2 = ""
  393. if self.ownerRid and self.ownerRid ~= 0 then
  394. local hName = SL:GetMetaValue(EMetaVarGetKey.ACTOR_NAME, tonumber(self.ownerRid))
  395. if hName then
  396. hateName2 = "<color=#dce1e5>" .. hName .. "</color>"
  397. end
  398. end
  399. local hateName = ""
  400. local cdfId = role.data.serverData.cfgId
  401. local mgroup = SL:GetConfig("cfg_monster", cdfId).mgroup
  402. local hate = 0
  403. if mgroup and #mgroup > 0 then
  404. hate = SL:GetConfig("cfg_boss_drop", mgroup[1], "mgroup").droptype
  405. end
  406. if hate == 0 then
  407. hateName = hateName1
  408. elseif hate == 1 then
  409. hateName = hateName1
  410. elseif hate == 2 then
  411. hateName = hateName1
  412. elseif hate == 3 then
  413. hateName = hateName1
  414. elseif hate == 4 then
  415. hateName = hateName1
  416. elseif hate == 5 then
  417. hateName = hateName2
  418. end
  419. title = "Lv." .. level .. " " .. name .. " " .. hateName
  420. end
  421. end
  422. GUI:Text_setString(self.view.name, title)
  423. GUI:Text_setTextColor(self.view.name, color)
  424. end
  425. function this:Close()
  426. self.ownerRid = 0
  427. self.parm = nil
  428. if self.updateID then
  429. SL:UnSchedule(self.updateID)
  430. self.updateID = nil
  431. end
  432. end
  433. return this