KLLoranSiegeCopyTaskPanel.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. ---@class KLLoranSiegeCopyTaskPanel:UIKmlLuaPanelBase
  2. ---@field view KLLoranSiegeCopyTaskPanelView
  3. local KLLoranSiegeCopyTaskPanel = class(UIKmlLuaPanelBase)
  4. local this =KLLoranSiegeCopyTaskPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. InfoManager.loranSiegeInfo.isInCopy = true
  10. SL:KeepOpenPanel("KLLoranSiegeCopyTaskPanel",true)
  11. self.nowCount = nil
  12. self.loadingCount = nil
  13. self.nowUnion = nil
  14. end
  15. function this:UnScheduleTimer()
  16. if self.countDown then
  17. SL:UnSchedule(self.countDown)
  18. end
  19. self.countDown = nil
  20. end
  21. ---注册UI事件和服务器消息
  22. function this:RegistEvents()
  23. GUI:AddOnClickEvent(self.view.exitBtn,self,self.Exit)
  24. GUI:AddOnClickEvent(self.view.TaskButton,self,self.TaskButtonOnClick)
  25. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_QUIT_DUPLICATE,self.RES_QUIT_SUCCESS,self)
  26. GUI:AddOnClickEvent(self.view.HelpButton, self, self.OnClickHelpButton)
  27. SL:RegisterLUAEvent(LUA_EVENT_LOGIN_MAP, self.LUA_EVENT_LOGIN_MAP, self) --登录进入地图
  28. SL:RegisterLUAEvent(LUA_EVENT_ROLAND_SIEGE_STATE_INFO_CHANGE, self.LUA_EVENT_ROLAND_SIEGE_STATE_INFO_CHANGE , self)
  29. SL:RegisterLUAEvent(LUA_EVENT_ROLAND_SIEGE_TASK_INFO_CHANGE, self.LUA_EVENT_ROLAND_SIEGE_TASK_INFO_CHANGE , self)
  30. SL:RegisterLUAEvent(LUA_EVENT_ROLAND_SIEGE_ROLAND_PROGRESS_INFO_CHANGE, self.LUA_EVENT_ROLAND_SIEGE_ROLAND_PROGRESS_INFO_CHANGE , self)
  31. SL:RegisterLUAEvent(LUA_EVENT_ROLAND_SIEGE_ROLAND_MONSTER_LIST_CHANGE, self.LUA_EVENT_ROLAND_SIEGE_ROLAND_MONSTER_LIST_CHANGE , self)
  32. end
  33. ---任务按钮点击寻路
  34. function this:TaskButtonOnClick()
  35. if self.repTaskConfig then
  36. this.pos_monster_id = self.repTaskConfig.param[1]
  37. local x = self.repTaskConfig.moveTo[1]
  38. local y = self.repTaskConfig.moveTo[2]
  39. this.map_id = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  40. this.map_line = SL:GetMetaValue(EMetaVarGetKey.MAP_LINE)
  41. SL:Pathfinding(this.map_id, this.map_line, x, y,this.MonserPosEnd,this.pos_monster_id)
  42. end
  43. end
  44. function this:MonserPosEnd(pos)
  45. if pos and pos.x and pos.z then
  46. this.scheduleId = SL:ScheduleOnce(0.1, function()
  47. SL:Pathfinding(this.map_id, this.map_line, pos.x, pos.z,this.BossPointOnHook)
  48. end)
  49. else
  50. SL:StartOnHook(true,true,this.pos_monster_id)
  51. end
  52. end
  53. function this:BossPointOnHook()
  54. SL:StartOnHook(true,true,this.pos_monster_id)
  55. end
  56. function this:Exit()
  57. SL:CommonTipsMessage({ stringTblID=211, ui = self, sureBtnText = "确定", cancelBtnText = "取消",
  58. callback = self.ExitSure})
  59. end
  60. function this:ExitSure()
  61. InfoManager.copActivityInfo.hideTask = false
  62. SL:onLUAEvent(LUA_EVENT_SHOW_TASK)
  63. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_QUIT_DUPLICATE,self.configId)
  64. GUI:UIPanel_Close("dev/outui/LoranSiege/Panel/KLLoranSiegeCopyTask/KLLoranSiegeCopyTaskPanel")
  65. end
  66. function this:RES_QUIT_SUCCESS(id,message)
  67. ---@type cfg_rep_column
  68. local tbl = SL:GetConfig("cfg_rep",message,"id")
  69. if tbl.type == self.configId then
  70. InfoManager.copActivityInfo.hideTask = false
  71. GUI:UIPanel_Close("dev/outui/LoranSiege/Panel/KLLoranSiegeCopyTask/KLLoranSiegeCopyTaskPanel")
  72. SL.ShowMainPanel()
  73. end
  74. end
  75. --帮助页面
  76. function this:OnClickHelpButton()
  77. local helpCfg=SL:GetConfig("cfg_rule_text",16005)
  78. if helpCfg then
  79. SL:CommonStrTipsMessage({title =helpCfg.menutxt,str=helpCfg.location})
  80. end
  81. end
  82. function this:LUA_EVENT_LOGIN_MAP()
  83. local map_id = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  84. local is_has = SL:HasConfigTwoKeys("cfg_rep",map_id,"type","mapId")
  85. if not is_has then
  86. self:ExitSure()
  87. end
  88. end
  89. ---罗兰攻城战副本状态改变
  90. function this:LUA_EVENT_ROLAND_SIEGE_STATE_INFO_CHANGE()
  91. local stateInfo = InfoManager.loranSiegeInfo.siegeStateInfo
  92. if not stateInfo then
  93. return
  94. end
  95. local state = stateInfo["2"]
  96. ---是否是准备阶段
  97. local ifPrepare = state == EDuplicateState.PREPARE
  98. if ifPrepare then
  99. GUI:Text_setString(self.view.openDesTxt,"")
  100. else
  101. GUI:Text_setString(self.view.end_time,"")
  102. end
  103. GUI:setVisible(self.view.task_root,not ifPrepare)
  104. GUI:setVisible(self.view.begin_root,ifPrepare)
  105. GUI:setVisible(self.view.text_countdown_tips, state == EDuplicateState.FINISH)
  106. self.configId = tonumber(stateInfo["1"])
  107. local name_str = SL:GetConfig("cfg_rep",self.configId).name[1]
  108. GUI:Text_setString(self.view.ActivityName,name_str)
  109. self:UnScheduleTimer()
  110. if state ~= EDuplicateState.CLOSED then
  111. local time = tonumber(stateInfo["3"])
  112. local count = (time - tonumber(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))) * 0.001 + 1
  113. local func = function()
  114. local now = tonumber(SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME))
  115. local deltaTime = time - now
  116. if state == EDuplicateState.PREPARE then
  117. GUI:Text_setString(self.view.openDesTxt,Time.ShowFormatTimeMS(deltaTime).."后开启副本")
  118. elseif state == EDuplicateState.FINISH then
  119. GUI:Text_setString(self.view.text_countdown_tips_text,Time.ShowFormatTimeMS(deltaTime).."秒")
  120. else
  121. GUI:Text_setString(self.view.end_time,Time.ShowFormatTimeMS(deltaTime))
  122. end
  123. if deltaTime <= 0 then
  124. if state == EDuplicateState.PREPARE then
  125. GUI:Text_setString(self.view.openDesTxt,"")
  126. elseif state == EDuplicateState.FINISH then
  127. GUI:setVisible(self.view.text_countdown_tips, false)
  128. else
  129. GUI:Text_setString(self.view.end_time,"")
  130. end
  131. self:UnScheduleTimer()
  132. end
  133. end
  134. func()
  135. self.countDown = SL:Schedule(self.countDown, 0, 1, count, func)
  136. end
  137. end
  138. ---罗兰攻城战任务信息改变
  139. function this:LUA_EVENT_ROLAND_SIEGE_TASK_INFO_CHANGE()
  140. GUI:setVisible(self.view.loading,false)
  141. local taskInfo = InfoManager.loranSiegeInfo.siegeTaskInfo
  142. if not taskInfo or not taskInfo.taskId then
  143. return
  144. end
  145. local iconStr = taskInfo.camp == 1 and "icon_attack" or "icon_guard"
  146. local color = taskInfo.nowCount >= taskInfo.totalCount and "#1add1f" or "#ff2323"
  147. local title = "(血量<color="..color..">"..tostring(taskInfo.nowCount).."</color>/"..tostring(taskInfo.totalCount)..")"
  148. ---@type cfg_repTask_column
  149. self.repTaskConfig = SL:GetConfig("cfg_repTask",taskInfo.taskId)
  150. --最后一阶段
  151. if not self.repTaskConfig.nextID or self.repTaskConfig.nextID == 0 then
  152. self:LUA_EVENT_ROLAND_SIEGE_ROLAND_PROGRESS_INFO_CHANGE()
  153. title = "(<color="..color..">"..tostring(taskInfo.nowCount).."</color>/"..tostring(taskInfo.totalCount)..")"
  154. --防守方最后一阶段任务不显示进度
  155. if taskInfo.camp == 2 then
  156. title = ""
  157. end
  158. else
  159. --守方提示
  160. if taskInfo.camp == 2 and not self.timer1 then
  161. if not self.nowCount then
  162. self.nowCount = taskInfo.nowCount
  163. end
  164. --血量变化了
  165. if taskInfo.nowCount < taskInfo.totalCount then
  166. if self.nowCount ~= taskInfo.nowCount then
  167. self.nowCount = taskInfo.nowCount
  168. ---@type cfg_monster_column
  169. local monsterCfg = SL:GetConfig("cfg_monster",self.repTaskConfig.param[1])
  170. ---@type cfg_string_column
  171. local tbl = SL:GetConfig("cfg_string", 16010, "id")
  172. local HorseRaceLampData = {
  173. id = 16010,
  174. content = string.format(tbl.text,monsterCfg.name),
  175. }
  176. SL:MessageTip(HorseRaceLampData)
  177. self.timer1 = SL:Schedule(self.timer1,10,10,-1,function()
  178. if self.timer1 then
  179. SL:UnSchedule(self.timer1)
  180. end
  181. self.timer1 = nil
  182. end)
  183. end
  184. end
  185. end
  186. end
  187. local unionName = "无"
  188. local unionRank = "0"
  189. local selfRank = "0"
  190. local selfScore = "0"
  191. if taskInfo.unionName then
  192. unionName = taskInfo.unionName
  193. end
  194. if taskInfo.unionRank then
  195. unionRank = taskInfo.unionRank
  196. end
  197. if taskInfo.selfRank then
  198. selfRank = taskInfo.selfRank
  199. end
  200. if taskInfo.selfScore then
  201. selfScore = taskInfo.selfScore
  202. end
  203. GUI:Text_setString(self.view.nowOccupyingPartyName,tostring(unionName))
  204. GUI:Text_setString(self.view.unionRankText,tostring(unionRank))
  205. GUI:Text_setString(self.view.myRankText,tostring(selfRank))
  206. GUI:Text_setString(self.view.myPointsText,tostring(selfScore))
  207. GUI:Image_loadTexture(self.view.taskIcon,iconStr,"Atlas/KLSiegePanel.spriteatlas")
  208. GUI:Text_setString(self.view.stateName,tostring(self.repTaskConfig.name))
  209. GUI:Text_setString(self.view.taskName,tostring(self.repTaskConfig.UItext))
  210. GUI:Text_setString(self.view.taskProgress,title)
  211. end
  212. ---攻城战进度信息变动
  213. function this:LUA_EVENT_ROLAND_SIEGE_ROLAND_PROGRESS_INFO_CHANGE()
  214. GUI:setVisible(self.view.loading,false)
  215. local info = InfoManager.loranSiegeInfo.rolandProgressInfo
  216. local unionName = ""
  217. local loadNum = 0
  218. local now = 0
  219. local max = 0
  220. if info and info.unionName then
  221. unionName = "<color=#1ADE1FFF>"..info.unionName.."</color>占领中"
  222. end
  223. if unionName ~= "" then
  224. GUI:setVisible(self.view.loading,true)
  225. self.loadingCount = info.now
  226. if self.nowUnion ~= info.unionId and self.loadingCount == info.max and not self.timer2 then
  227. self.nowUnion = info.unionId
  228. local id = 16011
  229. local content = ""
  230. if info.unionId == SL:MeData_GetUnionId() then
  231. ---@type cfg_string_column
  232. local tbl = SL:GetConfig("cfg_string", 16011, "id")
  233. content = string.format(tbl.text,info.unionName)
  234. else
  235. id = 16012
  236. ---@type cfg_string_column
  237. local tbl = SL:GetConfig("cfg_string", 16012, "id")
  238. content = string.format(tbl.text,info.unionName)
  239. end
  240. local HorseRaceLampData = {
  241. id = id,
  242. content = content,
  243. }
  244. SL:MessageTip(HorseRaceLampData)
  245. self.timer2 = SL:Schedule(self.timer2,10,10,-1,function()
  246. if self.timer2 then
  247. SL:UnSchedule(self.timer2)
  248. end
  249. self.timer2 = nil
  250. end)
  251. end
  252. else
  253. return
  254. end
  255. if info and info.now then
  256. now = info.now
  257. end
  258. if info and info.max then
  259. max = info.max
  260. end
  261. loadNum = Mathf.Ceil(now/max*100)
  262. GUI:Text_setString(self.view.loadingText,unionName)
  263. GUI:SetLoadingbar_startper(self.view.loading,loadNum)
  264. GUI:Text_setString(self.view.loadingNumText,now.."/"..max)
  265. end
  266. ---攻城战怪物信息变动
  267. function this:LUA_EVENT_ROLAND_SIEGE_ROLAND_MONSTER_LIST_CHANGE()
  268. self:SetResistancePoint()
  269. end
  270. ---设置阻挡点
  271. function this:SetResistancePoint()
  272. local taskInfo = InfoManager.loranSiegeInfo.siegeTaskInfo
  273. if taskInfo.camp == 1 then
  274. ---@type cfg_repGlobal_column
  275. local tbl = SL:GetConfig("cfg_repGlobal",16001009,"id")
  276. local strList = string.split(tbl.value,"|")
  277. for i, v in pairs(strList) do
  278. local strs = string.split(v,"#")
  279. local index = 1
  280. local isAdd = self:IsMonsterLive(strs[1],strs[2])
  281. for z = 1, table.count(strs) / 2 do
  282. if strs[index] then
  283. SL:SetResistancePoint(tonumber(strs[index]),tonumber(strs[index+1]),isAdd)
  284. end
  285. index = index + 2
  286. end
  287. end
  288. end
  289. end
  290. ---怪物是否存活
  291. function this:IsMonsterLive(x,y)
  292. local monsterInfo = InfoManager.loranSiegeInfo.monsterList
  293. for i, v in pairs(monsterInfo) do
  294. if v.x == tonumber(x) and v.y == tonumber(y) then
  295. return true
  296. end
  297. end
  298. return false
  299. end
  300. ---取消所有阻挡点
  301. function this:CancelAllResistancePoint()
  302. ---@type cfg_repGlobal_column
  303. local tbl = SL:GetConfig("cfg_repGlobal",16001009,"id")
  304. local strList = string.split(tbl.value,"|")
  305. for i, v in pairs(strList) do
  306. local strs = string.split(v,"#")
  307. local index = 1
  308. for z = 1, table.count(strs) / 2 do
  309. if strs[index] then
  310. SL:SetResistancePoint(tonumber(strs[index]),tonumber(strs[index+1]),false)
  311. end
  312. index = index + 2
  313. end
  314. end
  315. end
  316. function this:CreateModel()
  317. ---@type cfg_repGlobal_column
  318. local cfg = SL:GetConfig("cfg_repGlobal",16001011)
  319. local strList = string.split(cfg.value,'|')
  320. local pos = string.split(strList[2],'#')
  321. SL:CreateSceneItemModel(strList[1],function(res)
  322. self.Model = res
  323. if not IsNil(res) then
  324. res:SetLocalEulerAngles(0, 0, 0)
  325. res.localScale = Vector3 (tonumber(pos[4]),tonumber(pos[4]),tonumber(pos[4]))
  326. res:SetLocalPosition(tonumber(pos[1]),tonumber(pos[2]),tonumber(pos[3]))
  327. end
  328. end)
  329. end
  330. ---界面显示时调用一次
  331. function this:Show()
  332. end
  333. ---创建或者刷新界面数据时调用
  334. function this:Refresh()
  335. self:LUA_EVENT_ROLAND_SIEGE_STATE_INFO_CHANGE()
  336. self:LUA_EVENT_ROLAND_SIEGE_TASK_INFO_CHANGE()
  337. self:CreateModel()
  338. end
  339. function this:SetVisible(isVisible)
  340. GUI:setVisible(self.view.root,isVisible)
  341. end
  342. function this:Hide()
  343. end
  344. function this:Close()
  345. self:UnScheduleTimer()
  346. if this.scheduleId then
  347. SL:UnSchedule(this.scheduleId)
  348. end
  349. this.scheduleId = nil
  350. if self.timer1 then
  351. SL:UnSchedule(self.timer1)
  352. end
  353. self.timer1 = nil
  354. if self.timer2 then
  355. SL:UnSchedule(self.timer2)
  356. end
  357. self.timer2 = nil
  358. if SL:MeData_Check() then
  359. InfoManager.loranSiegeInfo:SetRoleHeadIcon(SL:MeData_GetId(),nil,SL:MeData_GetRoleExtInfo().roleInfoExtData.position)
  360. end
  361. if self.Model then
  362. SL:RecycleSceneItemModel(self.Model)
  363. end
  364. self.Model = nil
  365. self:CancelAllResistancePoint()
  366. SL:SetMetaValue(EMetaVarSetKey.SET_ISNOTCHANGEPKMODE,false)
  367. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE,EPKMode.Union)
  368. InfoManager.loranSiegeInfo.isInCopy = false
  369. end
  370. return this