KLRedFortTaskPanel.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. ---@class KLRedFortTaskPanel:UIKmlLuaPanelBase
  2. ---@field view KLRedFortTaskPanelView
  3. ---@field joinCount number
  4. ---@field nextStateTime number
  5. ---@field nowState number
  6. ---@field alertAreaSize {v1:{},v2:{}}
  7. ---@field nowShrinkingState number
  8. local KLRedFortTaskPanel = class(UIKmlLuaPanelBase)
  9. local this = KLRedFortTaskPanel
  10. ---创建时调用一次
  11. function this:Init()
  12. SL:KeepOpenPanel("KLRedFortTaskPanelKml", true)
  13. end
  14. function this:InitData(message)
  15. self:RES_RED_FORTRESS_STATE_UPDATE(nil, message)
  16. end
  17. ---注册UI事件和服务器消息
  18. function this:RegistEvents()
  19. GUI:AddOnClickEvent(self.view.exitBtn, self, self.BtnCloseOnClick)
  20. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RED_FORTRESS_STATE_UPDATE, self.RES_RED_FORTRESS_STATE_UPDATE, self)
  21. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RED_FORTRESS_PREPARE_COUNT, self.RES_RED_FORTRESS_PREPARE_COUNT, self)
  22. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RED_FORTRESS_TASK_INFO, self.RES_RED_FORTRESS_TASK_INFO, self)
  23. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RED_FORTRESS_SHRINKING_STAGE, self.RES_RED_FORTRESS_SHRINKING_STAGE, self)
  24. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_QUIT_DUPLICATE, self.RES_QUIT_DUPLICATE, self)
  25. end
  26. ---赤色要塞阶段
  27. function this:RES_RED_FORTRESS_STATE_UPDATE(_, message)
  28. if self.timer then
  29. --Timer.Stop(self.timer)
  30. SL:UnSchedule(self.timer)
  31. self.timer = nil
  32. end
  33. self.nowState = message["1"]
  34. self.nextStateTime = message["2"]
  35. self:RefreshTimeText()
  36. if message["1"] == ERedFortstage.Wait then
  37. GUI:SetActive(self.view.textSetout, true)
  38. GUI:SetActive(self.view.textJoin, true)
  39. GUI:SetActive(self.view.textSetoutTime, true)
  40. if self.joinCount and self.joinCount > 0 then
  41. GUI:Text_setString(self.view.textJoinCoun, tostring(self.joinCount))
  42. else
  43. GUI:Text_setString(self.view.textJoinCoun, "0")
  44. end
  45. SL:SetAllViewPlayerToMonster(true, InfoManager.redFortInfo.cfg_repRedfortress.transfiguration)
  46. SL:RefreshHead(SL:GetMetaValue(EMetaVarGetKey.UID))
  47. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.Peace)
  48. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE, true)
  49. if not self.timer then
  50. self.timer = SL:StartLoopForever(1, self.RefreshTimeText, self) ---Timer.StartLoopForever(1, self.RefreshTimeText, self)
  51. end
  52. elseif message["1"] == ERedFortstage.Fight then
  53. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE, false)
  54. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, EPKMode.AllAttack)
  55. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE, true)
  56. --战斗阶段显示裁剪过的地块并且增加阻挡点
  57. ---字段后端要用来生成怪物,这里写死偏移量
  58. local x1 = InfoManager.redFortInfo.cfg_repRedfortress.start[1] - 4
  59. local x2 = InfoManager.redFortInfo.cfg_repRedfortress.start[2] + 5
  60. local y1 = InfoManager.redFortInfo.cfg_repRedfortress.start[3] - 3
  61. local y2 = InfoManager.redFortInfo.cfg_repRedfortress.start[4] + 6
  62. local v1 = Vector2(x1, y1)
  63. local v2 = Vector2(x2, y2)
  64. ---裁切地块有偏移
  65. SL.MapMaskMgr:SetRect(v1, v2)
  66. --local str = "10000152 预警区域 左下:x-%s y-%s,右上:x-%s y-%s"
  67. --logError(string.format(str, v1.x, v1.y, v2.x, v2.y))
  68. SL.MapMaskMgr:SetAlertRect(v1, v2)
  69. ---阻挡点
  70. --Scene.SetCustomResistanceData(Dot2(x1 - 1,y1 - 1), Dot2(x2 + 1,y2 + 1))
  71. SL:SetAllViewPlayerToMonster(true, InfoManager.redFortInfo.cfg_repRedfortress.transfiguration)
  72. SL:RefreshHead(SL:GetMetaValue(EMetaVarGetKey.UID))
  73. if not self.timer then
  74. self.timer =SL:StartLoopForever(1, self.RefreshTimeText, self) ---Timer.StartLoopForever(1, self.RefreshTimeText, self)
  75. end
  76. else
  77. end
  78. end
  79. ---赤色要塞准备阶段人数
  80. function this:RES_RED_FORTRESS_PREPARE_COUNT(_, message)
  81. GUI:SetActive(self.view.textJoin, true)
  82. if message and message > 0 then
  83. GUI:Text_setString(self.view.textJoinCoun, tostring(message))
  84. else
  85. GUI:Text_setString(self.view.textJoinCoun, "0")
  86. end
  87. end
  88. ---赤色要塞任务面板信息
  89. function this:RES_RED_FORTRESS_TASK_INFO(_, message)
  90. GUI:SetActive(self.view.textTarget, true)
  91. GUI:SetActive(self.view.textPlayer, true)
  92. GUI:SetActive(self.view.textRevive, true)
  93. GUI:SetActive(self.view.textFightTime, true)
  94. GUI:SetActive(self.view.textSetout, false)
  95. GUI:SetActive(self.view.textJoin, false)
  96. GUI:SetActive(self.view.textSetoutTime, false)
  97. GUI:Text_setString(self.view.textPlayerCount, tostring(message["1"]))
  98. GUI:Text_setString(self.view.textReviveCount, tostring(message["2"]))
  99. if message["2"] > 0 then
  100. GUI:Text_setTextColor(self.view.textReviveCount, EColor[EGradColor.green])
  101. else
  102. GUI:Text_setTextColor(self.view.textReviveCount, EColor[EGradColor.red])
  103. end
  104. end
  105. ---赤色要塞缩圈数据
  106. function this:RES_RED_FORTRESS_SHRINKING_STAGE(_, message)
  107. self.nowShrinkingState = message["1"]
  108. local v1, v2 = self:GetLeftAndRight(message)
  109. if self.alertAlphaTimer then
  110. ---Timer.Stop(self.alertAlphaTimer)
  111. SL:UnSchedule(self.alertAlphaTimer)
  112. self.alertAlphaTimer = nil
  113. if self.alertAreaSize[self.nowShrinkingState - 1] then
  114. local tempV1, tempV2 = self.alertAreaSize[self.nowShrinkingState - 1].v1, self.alertAreaSize[self.nowShrinkingState - 1].v2
  115. SL.MapMaskMgr:SetAlertRect(tempV1, tempV2)
  116. ---Scene.SetCustomResistanceData(Dot2(tempV1.x - 1,tempV1.y), Dot2(tempV2.x,tempV2.y))
  117. SL.Scene:SetCustomResistanceData(Dot2(tempV1.x - 1,tempV1.y), Dot2(tempV2.x,tempV2.y))
  118. end
  119. if self.nowShrinkingState == #InfoManager.redFortInfo.cfg_repRedfortress.warning then
  120. SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, {
  121. message = "最终决战开始,扣除所有复活次数",
  122. channel = EChatChannelType.SYSTEM,
  123. })
  124. end
  125. end
  126. ---裁切地块有偏移
  127. SL.MapMaskMgr:SetRect(v1, v2)
  128. --local str = "10000152 安全区域 左下:x-%s y-%s,右上:x-%s y-%s"
  129. --logError(string.format(str, v1.x, v1.y, v2.x, v2.y))
  130. self.alertTime = InfoManager.redFortInfo.cfg_repRedfortress.warning[self.nowShrinkingState]
  131. SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, {
  132. message = "平台边缘即将塌陷,请马上远离",
  133. channel = EChatChannelType.SYSTEM,
  134. })
  135. SL:TipMessage( SL:GetConfig('cfg_string',252).text, self.alertTime, NoticeType.NoticeMid )--"平台边缘即将塌陷,请马上远离!",
  136. self.alertAlpha = 0.5
  137. self:SetAlertAlpha()
  138. if not self.alertAlphaTimer then
  139. self.alertAlphaTimer =SL:StartLoopForever(1, self.SetAlertAlpha, self) ---Timer.StartLoopForever(1, self.SetAlertAlpha, self)
  140. end
  141. table.insert(self.alertAreaSize, { v1 = v1, v2 = v2 })
  142. end
  143. function this:SetAlertAlpha()
  144. if self.alertTime <= 0 then
  145. if self.alertAlphaTimer then
  146. ---Timer.Stop(self.alertAlphaTimer)
  147. SL:UnSchedule(self.alertAlphaTimer)
  148. self.alertAlphaTimer = nil
  149. end
  150. if self.alertAreaSize[self.nowShrinkingState] then
  151. local tempV1 = self.alertAreaSize[self.nowShrinkingState].v1
  152. local tempV2 = self.alertAreaSize[self.nowShrinkingState].v2
  153. SL.MapMaskMgr:SetAlertRect(tempV1, tempV2)
  154. ---Scene.SetCustomResistanceData(Dot2(tempV1.x - 1,tempV1.y), Dot2(tempV2.x,tempV2.y))
  155. SL.Scene:SetCustomResistanceData(Dot2(tempV1.x - 1,tempV1.y), Dot2(tempV2.x,tempV2.y))
  156. end
  157. if self.nowShrinkingState == #InfoManager.redFortInfo.cfg_repRedfortress.warning then
  158. SL:onLUAEvent(LUA_EVENT_CHAT_RECEIVE_NOTICE, {
  159. message = "最终决战开始,扣除所有复活次数",
  160. channel = EChatChannelType.SYSTEM,
  161. })
  162. end
  163. end
  164. SL.MapMaskMgr:SetAlertAlpha(self.alertAlpha)
  165. self.alertTime = self.alertTime - 1
  166. if self.alertAlpha == 1 then
  167. self.alertAlpha = 0.5
  168. else
  169. self.alertAlpha = 1
  170. end
  171. end
  172. ---@param message {"1":number,"2":{"1":number,"2":number,"3":number,"4":number}}
  173. ---@return table {v1:{},v2:{}}
  174. function this:GetLeftAndRight(message)
  175. local cut = 1
  176. for i = 1, message["1"] do
  177. cut = cut - InfoManager.redFortInfo.cfg_repRedfortress.mapCut[i][2] / 100
  178. end
  179. ---字段后端要用来生成怪物,这里写死偏移量
  180. local x1 = message["2"]["1"]
  181. local x2 = message["2"]["2"]
  182. local y1 = message["2"]["3"]
  183. local y2 = message["2"]["4"]
  184. ---裁切地块有偏移
  185. --local length = x2 - x1
  186. --local width = y2 - y1
  187. --length = length - length * cut
  188. --width = width - width * cut
  189. --local v1 = Vector2(math.floor(x1 + length / 2), math.floor(y1 + width / 2))
  190. --local v2 = Vector2(math.floor(x2 - length / 2), math.floor(y2 - width / 2))
  191. local v1 = Vector2(x1, y1)
  192. local v2 = Vector2(x2, y2)
  193. return v1, v2
  194. end
  195. ---退出副本
  196. function this:RES_QUIT_DUPLICATE(_, message)
  197. ---@type cfg_rep_column
  198. local tbl = SL:GetConfig("cfg_rep", message, "id")
  199. if tbl.type == EActivityType.RedFort then
  200. GUI:UIPanel_Close("dev/outui/Activity/Panel/KLRedFortTask/KLRedFortTaskPanel")
  201. end
  202. end
  203. function this:BtnCloseOnClick()
  204. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_QUIT_DUPLICATE)
  205. end
  206. ---创建或者刷新界面数据时调用
  207. function this:Refresh()
  208. self.alertAreaSize = {}
  209. self:RefreshUI()
  210. self:ShowActivity(false)
  211. end
  212. function this:RefreshUI()
  213. ---先调用一次防止大退重进没数据
  214. InfoManager.redFortInfo:GetCfgByLevel()
  215. self:HideAllText()
  216. end
  217. function this:HideAllText()
  218. GUI:SetActive(self.view.textSetout, false)
  219. GUI:SetActive(self.view.textTarget, false)
  220. GUI:SetActive(self.view.textPlayer, false)
  221. GUI:SetActive(self.view.textRevive, false)
  222. GUI:SetActive(self.view.textSetoutTime, false)
  223. GUI:SetActive(self.view.textFightTime, false)
  224. end
  225. function this:RefreshTimeText()
  226. local nextTime = self.nextStateTime - Time.GetServerTime()
  227. if nextTime < 0 then
  228. if self.timer then
  229. ---Timer.Stop(self.timer)
  230. SL:UnSchedule(self.timer)
  231. self.timer = nil
  232. end
  233. return
  234. end
  235. if self.nowState == ERedFortstage.Wait then
  236. GUI:Text_setString(self.view.textTime, Time.FormatTimeHMS(math.floor(nextTime)))
  237. else
  238. GUI:Text_setString(self.view.textFightTime, Time.FormatTimeHMS(math.floor(nextTime)))
  239. end
  240. end
  241. function this:ShowActivity(isShow)
  242. ---@type KLActivityPreviewPanel
  243. local uiPanel = GUI:GetUI("dev/outui/Activity/Panel/KLActivityPreview/KLActivityPreviewPanel")
  244. if uiPanel then
  245. if not isShow then
  246. uiPanel:HideActivity()
  247. else
  248. uiPanel:ShowActivity()
  249. end
  250. end
  251. end
  252. function this:Close()
  253. if self.timer then
  254. ---Timer.Stop(self.timer)
  255. SL:UnSchedule(self.timer)
  256. self.timer = nil
  257. end
  258. if self.alertAlphaTimer then
  259. ---Timer.Stop(self.alertAlphaTimer)
  260. SL:UnSchedule(self.alertAlphaTimer)
  261. self.alertAlphaTimer = nil
  262. end
  263. InfoManager.copActivityInfo.hideTask = false
  264. ---@type KLUILeftUpPanel
  265. local panel = GUI:GetUI("dev/ui/MainUI/Panel/KLUILeftUp/KLUILeftUpPanel")
  266. if panel then
  267. panel:OnClickTaskToggle(nil, nil, { true })
  268. panel:SetTeamToogleEnabled(true)
  269. end
  270. SL:SetAllViewPlayerToMonster()
  271. if SL:MeData_Check() then
  272. SL:RefreshHead(SL:GetMetaValue(EMetaVarGetKey.UID))
  273. end
  274. SL.MapMaskMgr:DestroyEntity()
  275. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE, false)
  276. self:ShowActivity(true)
  277. end
  278. return this