KLWolfSoulFortressTaskPanel.lua 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. ---@class KLWolfSoulFortressTaskPanel:UIKmlLuaPanelBase
  2. ---@field view KLWolfSoulFortressTaskPanelView
  3. ---@field nextStateTime number @阶段时间
  4. ---@field nextStateTime_2 number @战斗阶段要变成退出按钮上的时间
  5. ---@field summonCount number @召唤了几个守护
  6. ---@field state number @哪个阶段
  7. ---@field lastHp number @上一次的血量
  8. local KLWolfSoulFortressTaskPanel = class(UIKmlLuaPanelBase)
  9. local this = KLWolfSoulFortressTaskPanel
  10. function this:AsyncLoadUI()
  11. end
  12. ---创建时调用一次
  13. function this:Init()
  14. self.position = 0
  15. --3秒延迟发消息
  16. self.nextPopTextTime = 0
  17. end
  18. function this:InitData(message)
  19. self.summonCount = message["1"]
  20. GUI:Text_setString(self.view.textSummonCount, self.summonCount)
  21. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.Union)
  22. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE,true)
  23. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,EPKMode.Union)
  24. end
  25. ---注册UI事件和服务器消息
  26. function this:RegistEvents()
  27. GUI:AddOnClickEvent(self.view.btnExit, self, self.BtnCloseOnClick)
  28. GUI:AddOnClickEvent(self.view.btnSummon, self, self.BtnSummonOnClick)
  29. GUI:AddOnClickEvent(self.view.btnHelp, self, self.BtnHelpOnClick)
  30. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WOLF_SOUL_STATE, self.RES_WOLF_SOUL_STATE, self)
  31. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WOLF_SOUL_FIGHT_PANEL, self.RES_WOLF_SOUL_FIGHT_PANEL, self)
  32. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WOLF_SOUL_PREPARE_PANEL, self.RES_WOLF_SOUL_PREPARE_PANEL, self)
  33. SL:RegisterLuaNetMsg(MessageDef.ResViewUnionMessage, this.ResViewUnionMessage, self)
  34. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_MAPPOS_CHANGE, self.LUA_EVENT_PLAYER_MAPPOS_CHANGE, self)
  35. end
  36. ---离雕像距离小于等于2格时打开召唤
  37. function this:LUA_EVENT_PLAYER_MAPPOS_CHANGE()
  38. if self.state == 1 and InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg and (self.position == 1 or self.position == 2) then
  39. local platformPosition = SL:GetNewDot(InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[1], InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[2])
  40. --Dot2(InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[1], InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[2])
  41. local mePos = SL:GetNewDot(SL:MeData_GetCoord().x, SL:MeData_GetCoord().z)--Dot2(SL:MeData_GetCoord().x, SL:MeData_GetCoord().z)
  42. if --[[Dot2.Distance(platformPosition, mePos)--]] SL:GetPointDistance(platformPosition, mePos) <= 2 then
  43. if not GUI:GetUI("dev/outui/Activity/Panel/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonPanel") then
  44. GUI:UIPanel_Open("dev/outui/Activity/Panel/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonPanel")
  45. end
  46. end
  47. end
  48. end
  49. ---@param message UnionProto.ViewUnionRes
  50. function this:ResViewUnionMessage(_, message)
  51. self.position = 0
  52. for k, v in pairs(message.unionInfo.unionMemberInfo) do
  53. if v.memberId == SL:GetMetaValue(EMetaVarGetKey.UID) then
  54. self.position = v.position
  55. break
  56. end
  57. end
  58. if self.position > 0 then
  59. if self.position <= 2 then
  60. GUI:SetActive(self.view.btnSummon, true)
  61. else
  62. GUI:SetActive(self.view.btnSummon, false)
  63. end
  64. end
  65. end
  66. -- 狼魂要塞准备阶段信息
  67. function this:RES_WOLF_SOUL_PREPARE_PANEL(_, message)
  68. InfoManager.wolfSoulFortressInfo.summonCount = message["1"]
  69. guardians = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardians
  70. GUI:Text_setString(self.view.textSummonCount, string.format("%s/%s", InfoManager.wolfSoulFortressInfo.summonCount, guardians))
  71. end
  72. -- 狼魂要塞战斗阶段面板信息
  73. ---@param message {hp:number, score:number,rank:number,left:number,nextGenTime:string}
  74. function this:RES_WOLF_SOUL_FIGHT_PANEL(_, message)
  75. ---雕像血量
  76. local wolfHp = message.hp
  77. if self.lastHp > wolfHp and self.nextPopTextTime < Time.GetServerTime() then
  78. local str = SL:GetConfig('cfg_string', 432).text
  79. SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, {
  80. message = str,
  81. channel = EChatChannelType.SYSTEM,
  82. })
  83. SL:TipMessage( str, 1, NoticeType.NoticeMid )
  84. self.nextPopTextTime = Time.GetServerTime() + 3000
  85. end
  86. self.lastHp = message.hp
  87. wolfHp = wolfHp / 10000 * 100 ---万分比
  88. GUI:Text_setString(self.view.textWolfHp, wolfHp .. "%")
  89. local score = message.score
  90. GUI:Text_setString(self.view.textScore, tostring(score))
  91. local rank = message.rank
  92. GUI:Text_setString(self.view.textRank, tostring(rank))
  93. local fightCount = message.left
  94. GUI:Text_setString(self.view.textFightCount, tostring(fightCount))
  95. self.nextStateTime = message.nextGenTime
  96. local nextTime = self.nextStateTime - Time.GetServerTime()
  97. GUI:Text_setString(self.view.timeText, Time.FormatTimeHMS(math.floor(nextTime)))
  98. GUI:Text_setString(self.view.timerTitle, "下一波倒计时")
  99. if fightCount == 0 then
  100. GUI:Text_setString(self.view.timerTitle, "副本结束倒计时")
  101. end
  102. if not self.timer_2 then
  103. ---self.timer_2 = Timer.StartLoopForever(1, self.RefreshTimeText_2, self)
  104. self.timer_2 = SL:StartLoopForever(1, self.RefreshTimeText_2, self)
  105. end
  106. end
  107. -- 狼魂要塞阶段信息
  108. ---@param message {"1":副本id, "2":哪个阶段,"3":下个阶段的时间}
  109. function this:RES_WOLF_SOUL_STATE(_, message)
  110. self.state = message["2"]
  111. if self.state == 1 then
  112. SL:TipMessage( SL:GetConfig('cfg_string', 434).text, 1, NoticeType.NoticeMid )
  113. self.nextStateTime = message["3"]
  114. elseif self.state == 2 then
  115. self.nextStateTime_2 = message["3"]
  116. else
  117. GUI:UIPanel_Open("dev/outui/Activity/Panel/KLWolfSoulFortress/KLWolfSoulFortressPanel", nil, nil, message["3"])
  118. end
  119. self:RefreshTimeUI()
  120. end
  121. function this:RefreshTimeUI()
  122. if not self.timer then
  123. ---self.timer = Timer.StartLoopForever(1, self.RefreshTimeText, self)
  124. self.timer = SL:StartLoopForever(1, self.RefreshTimeText, self)
  125. end
  126. if not self.timer_2 then
  127. ---self.timer_2 = Timer.StartLoopForever(1, self.RefreshTimeText_2, self)
  128. self.timer_2 = SL:StartLoopForever(1, self.RefreshTimeText_2, self)
  129. end
  130. self:RefreshTimeText()
  131. self:RefreshTimeText_2()
  132. if self.state == 1 then
  133. GUI:Text_setString(self.view.timerTitle, "准备倒计时")
  134. GUI:SetActive(self.view.textRoot, true)
  135. GUI:SetActive(self.view.textRoot_2, false)
  136. GUI:SetActive(self.view.timeText_2, false)
  137. else
  138. GUI:SetActive(self.view.textRoot, false)
  139. GUI:SetActive(self.view.textRoot_2, true)
  140. GUI:SetActive(self.view.timeText_2, true)
  141. end
  142. end
  143. ---界面显示时调用一次
  144. function this:Show()
  145. end
  146. ---创建或者刷新界面数据时调用
  147. function this:Refresh()
  148. self.lastHp = 0
  149. SL:ReqViewUnionMessage()
  150. GUI:SetActive(self.view.textRoot, true)
  151. GUI:SetActive(self.view.textRoot_2, false)
  152. if InfoManager.wolfSoulFortressInfo.summonCount then
  153. end
  154. self.nextStateTime = 0
  155. self.nextStateTime_2 = 0
  156. if InfoManager.wolfSoulFortressInfo.state then
  157. self.nextStateTime = InfoManager.wolfSoulFortressInfo.nextStateTime
  158. self.nextStateTime_2 = InfoManager.wolfSoulFortressInfo.nextStateTime_2
  159. self.state = InfoManager.wolfSoulFortressInfo.state
  160. self:RefreshTimeUI()
  161. end
  162. end
  163. function this:RefreshTimeText()
  164. local nextTime = self.nextStateTime - Time.GetServerTime()
  165. if nextTime > 0 then
  166. GUI:Text_setString(self.view.timeText, Time.FormatTimeHMS(math.floor(nextTime)))
  167. end
  168. end
  169. --退出按钮上的时间
  170. function this:RefreshTimeText_2()
  171. local nextTime = self.nextStateTime_2 - Time.GetServerTime()
  172. if nextTime > 0 then
  173. GUI:Text_setString(self.view.timeText_2, Time.FormatTimeHMS(math.floor(nextTime)))
  174. end
  175. end
  176. function this:BtnHelpOnClick()
  177. local helpCfg = SL:GetConfig("cfg_rule_text", 15001)
  178. if helpCfg then
  179. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  180. end
  181. end
  182. ---寻路到雕像
  183. function this:BtnSummonOnClick()
  184. ---召唤次数有限制
  185. if InfoManager.wolfSoulFortressInfo.summonCount == InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.guardians then
  186. SL:TipMessage( SL:GetConfig('cfg_string', 332).text, 1, NoticeType.NoticeMid )--"召唤次数已满!",
  187. return
  188. end
  189. if not InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg then
  190. return
  191. end
  192. local platformPosition =SL:GetNewDot(InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[1], InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[2])
  193. --Dot2(InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[1], InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[2])
  194. local mePos = SL:GetNewDot(SL:MeData_GetCoord().x, SL:MeData_GetCoord().z)--Dot2(SL:MeData_GetCoord().x, SL:MeData_GetCoord().z)
  195. if --[[Dot2.Distance(platformPosition, mePos)--]] SL:GetPointDistance(platformPosition, mePos) <= 2 then
  196. GUI:UIPanel_Open("dev/outui/Activity/Panel/KLWolfSoulFortressSummon/KLWolfSoulFortressSummonPanel")
  197. end
  198. local x = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[1]
  199. local y = InfoManager.wolfSoulFortressInfo.nowWolfSoulCfg.platformPosition[2]
  200. --RoleManager.me:PathMoveTo(Dot2.New(x, y), nil, 2, arriveFunc, true, nil, nil, 1)
  201. SL:PathMoveTo( --[[Dot2.New(x, y)--]] SL:GetNewDot(x,y), nil, 2, nil, true, nil, nil, 1)
  202. end
  203. function this:BtnCloseOnClick()
  204. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_QUIT_DUPLICATE)
  205. end
  206. function this:Close()
  207. if self.timer then
  208. ---Timer.Stop(self.timer)
  209. SL:UnSchedule(self.timer)
  210. self.timer = nil
  211. end
  212. if self.timer_2 then
  213. ---Timer.Stop(self.timer_2)
  214. SL:UnSchedule(self.timer_2)
  215. self.timer_2 = nil
  216. end
  217. InfoManager.copActivityInfo.hideTask = false
  218. ---@type KLUILeftUpPanel
  219. local panel = GUI:GetUI("dev/ui/MainUI/Panel/KLUILeftUp/KLUILeftUpPanel")
  220. if panel then
  221. panel:OnClickTaskToggle(nil, nil, { true })
  222. panel:SetTeamToogleEnabled(true)
  223. end
  224. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE, false)
  225. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLWolfSoulFortress/KLWolfSoulFortressPanel")
  226. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.Peace)
  227. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE,false)
  228. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,EPKMode.Peace)
  229. end
  230. return this