KLUIChallengeBossLineItem.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. ---@class KLUIChallengeBossLineItem:UIKmlLuaPanelBase
  2. ---@field view KLUIChallengeBossLineItemView
  3. local KLUIChallengeBossLineItem = class(UIKmlLuaPanelBase)
  4. local this = KLUIChallengeBossLineItem
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:Text_setString(self.view.num,"")
  8. end
  9. ---创建或者刷新界面数据时调用
  10. function this:Refresh()
  11. end
  12. function this:RefreshItem(monsterid,map,move,panel,height,cfg_BOSS_challenge)
  13. self.isOpen = true
  14. self.panel = panel
  15. --SL:LogError(self.args.is_copy)
  16. ----@type cfg_BOSS_challenge_column
  17. self.cfg_BOSS_challenge = cfg_BOSS_challenge
  18. if self.args.is_copy and self.args.is_copy == 1 then
  19. self.mapId = monsterid
  20. self.data = map
  21. if height == 210 then
  22. else
  23. height = 230
  24. end
  25. self.monsterid = self.data[1]
  26. self.monster_num = self.data[2]
  27. self.x = self.data[3]
  28. self.y = self.data[4]
  29. self.range = self.data[5]
  30. local name = nil
  31. local level = nil
  32. local pos_tr = ""
  33. ----@type cfg_map_info_column
  34. local map_info = SL:GetConfig('cfg_map_info', self.mapId, 'id')
  35. if self.cfg_BOSS_challenge and self.cfg_BOSS_challenge.monsterType == EBossChallengeType.Sanctuary then
  36. ----@type cfg_mapMove_column
  37. local map_move = SL:GetConfig('cfg_mapMove',move, 'id')
  38. name = map_info.mapname
  39. level = map_move.level
  40. pos_tr = string.format("<color=#00FF00>[跨]</color>%s [%s线]",name, 1)
  41. self.line = 1
  42. self.monsterid = cfg_BOSS_challenge.monsterid
  43. self.monster_num = 1
  44. else
  45. local tab = SL:GetConfig('cfg_repfairyland', self.mapId, 'id')
  46. name = tab.name[1]
  47. level = tab.level
  48. pos_tr = string.format("%s(%s,%s)",name, self.x,self.y)
  49. end
  50. GUI:Text_setString(self.view.name,pos_tr)
  51. GUI:Text_setString(self.view.level,level.."级")
  52. local playerLevel = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  53. self.is_jion = false
  54. self.is_show_num = true
  55. if playerLevel < level then
  56. GUI:setVisible(self.view.level,true)
  57. GUI:setVisible(self.view.num,false)
  58. self.is_show_num = false
  59. else
  60. self.is_jion = true
  61. GUI:setVisible(self.view.level,false)
  62. GUI:setVisible(self.view.num,true)
  63. end
  64. GUI:Text_setString(self.view.num,"")
  65. local src = "button_interface_window17"
  66. if map_info.goldmap and map_info.goldmap == 1 then
  67. src = "img_boldboss_btn"
  68. GUI:setContentSize(self.view.btn,height,47)
  69. else
  70. GUI:setContentSize(self.view.btn,height,40)
  71. end
  72. GUI:Image_loadTexture(self.view.btn,src,"Atlas/UIChallengeBoss.spriteatlas")
  73. --self:GetCopyMonsterCount()
  74. else
  75. self.monsterid = monsterid
  76. self.mapId = map[1]
  77. self.line = map[2]
  78. self.moveId = move[1]
  79. local map_info = SL:GetConfig('cfg_map_info', self.mapId, 'id')
  80. local move_info = SL:GetConfig('cfg_mapMove', self.moveId, 'id')
  81. self.mapX = move_info.mapX
  82. self.mapY = move_info.mapY
  83. --local map_info = SL:FindConfigs("cfg_map_info","id",self.mapId)
  84. local name = map_info.mapname .. " ["..self.line.."线]"
  85. local level = move_info.level
  86. GUI:Text_setString(self.view.name,name)
  87. local level_str = level.."级"
  88. if self.args.is_copy and self.args.is_copy == 2 then
  89. local monster_level = SL:GetConfig('cfg_monster', self.monsterid, 'id').level
  90. level_str = monster_level.."级"
  91. end
  92. GUI:Text_setString(self.view.level,level_str)
  93. local playerLevel = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  94. self.is_jion = false
  95. self.is_show_num = true
  96. if playerLevel < level then
  97. GUI:setVisible(self.view.level,true)
  98. GUI:setVisible(self.view.num,false)
  99. self.is_show_num = false
  100. else
  101. self.is_jion = true
  102. GUI:setVisible(self.view.level,false)
  103. GUI:setVisible(self.view.num,true)
  104. end
  105. if height == 210 then
  106. else
  107. height = 230
  108. end
  109. GUI:Text_setString(self.view.num,"")
  110. GUI:Text_setString(self.view.num,"")
  111. local src = "button_interface_window17"
  112. if map_info.goldmap and map_info.goldmap == 1 then
  113. src = "img_boldboss_btn"
  114. GUI:setContentSize(self.view.btn,height,47)
  115. else
  116. GUI:setContentSize(self.view.btn,height,40)
  117. end
  118. GUI:Image_loadTexture(self.view.btn,src,"Atlas/UIChallengeBoss.spriteatlas")
  119. --self:GetMonsterCount()
  120. end
  121. end
  122. ---注册UI事件和服务器消息
  123. function this:RegistEvents()
  124. GUI:AddOnClickEvent(self.view.btn,self,self.OnclickIcon)
  125. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.MONSTER_COUNT_RESULT,self.MonserCount,self)
  126. -- SL:RegisterLuaNetMsg(LuaMessageIdToClient.SEND_SECRET_REALM_MONSTER_COUNT,self.MonserCopyCount,self)
  127. end
  128. function this:OnclickIcon()
  129. local map_id = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  130. local mapTab = SL:GetConfig("cfg_map_info",map_id)
  131. if mapTab.nopositionmove and mapTab.nopositionmove == 1 then
  132. SL:MessageTip({id=116})--"副本中无法传送",
  133. return
  134. end
  135. ---@type cfg_map_info_column
  136. local map_info = SL:GetConfig('cfg_map_info', self.mapId)
  137. if map_info.goldmap == 1 and InfoManager.newVipInfo.vipLevel <= 0 then
  138. SL:CommonTipsMessage({ stringTblID=228, ui = self, sureBtnText = "确定", cancelBtnText = "取消",
  139. callback = function()
  140. GUI:UIPanel_Close("dev/outui/ChallengeBoss/Panel/KLChallengeBoss/KLChallengeBossPanel")
  141. SL.HideMainPanel()
  142. GUI:UIPanel_Open("dev/outui/VIP/Panel/KLNewVIPMain/KLNewVIPMainPanel")
  143. end })
  144. return
  145. end
  146. if not self.is_jion then
  147. SL:TipMessage( SL:GetConfig('cfg_string',249).text, 1, NoticeType.NoticeMid )--"等级不足",
  148. return
  149. end
  150. if self.cfg_BOSS_challenge and self.cfg_BOSS_challenge.monsterType == EBossChallengeType.Sanctuary then
  151. local IsSatisfy ,tipsStr = InfoManager.sanctuaryBossInfo:GetIsSatisfy()
  152. if IsSatisfy then
  153. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_CROSS_MAP_TRANSFER_TO_NPC,{npcid = self.cfg_BOSS_challenge.npcInteraction})
  154. InfoManager.sanctuaryBossInfo.sanctuaryNpcId = self.cfg_BOSS_challenge.npcInteraction
  155. InfoManager.sanctuaryBossInfo.sanctuaryMapId= self.mapId
  156. GUI:UIPanel_Close("dev/outui/ChallengeBoss/Panel/KLChallengeBoss/KLChallengeBossPanel")
  157. SL.ShowMainPanel()
  158. else
  159. SL:TipMessage(tipsStr, 1, NoticeType.NoticeMid )--"次数不足",
  160. return
  161. end
  162. else
  163. if self.args.is_copy and self.args.is_copy == 1 then
  164. if not self.panel:isJoin() then
  165. SL:TipMessage( SL:GetConfig('cfg_string',256).text, 1, NoticeType.NoticeMid )--"次数不足",
  166. return
  167. end
  168. GUI:UIPanel_Close("dev/outui/ChallengeBoss/Panel/KLChallengeBoss/KLChallengeBossPanel")
  169. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ENTER_SECRET_REALM, {repId=self.mapId})
  170. else
  171. self:GetMonsterPos()
  172. end
  173. end
  174. --GUI:UIPanel_Open("dev/outui/ChallengeBoss/Panel/KLChallengeBossPos/KLChallengeBossPosPanel")
  175. end
  176. function this:GoldBossBtnDataListItemCountFunc()
  177. return #self.allGoldLevel
  178. end
  179. function this:GoldBossBtnDataListItemGetFunc(realIndex)
  180. local data = self.allGoldLevel[realIndex + 1]
  181. local item = GUI:UIPanel_Open("dev/ui/ChallengeBoss/Item/KLUIChallengeBossBtnItem/KLUIChallengeBossBtnItem",self.view.gold_boss_level,self,{},true)
  182. self.glod_boss_level_btn_all_item[item.view.root] = item
  183. return item.view.root
  184. end
  185. function this:GoldBossBtnDataListItemInitFunc(realIndex, kmlcontrol)
  186. end
  187. function this:GoldBossBtnDataListItemUpdateFunc(realIndex, kmlcontrol)
  188. local data = self.allGoldLevel[realIndex + 1]
  189. self.glod_boss_level_btn_all_item[kmlcontrol]:RefreshItem(data,self.select_gold_level,self)
  190. if data == self.select_gold_level then
  191. self.GoldBossLevelBtn = self.glod_boss_level_btn_all_item[kmlcontrol]
  192. end
  193. end
  194. function this:GetMonsterCount()
  195. GUI:setGrey(self.view.btn,false)
  196. GUI:Text_setString(self.view.num,"")
  197. if not self.is_show_num then
  198. return
  199. end
  200. if not self.mapId or not self.line or not self.monsterid then
  201. return
  202. end
  203. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_MOUNSTER_COUNT_BY_MAP, {mapCfgId=self.mapId,line=self.line,monsterCfgId=self.monsterid,state=1})
  204. end
  205. function this:MonserCount(id, message)
  206. --SL:LogError("MonserCount")
  207. if not message then
  208. return
  209. end
  210. if message.mapCfgId ~= self.mapId or message.line ~= self.line or message.monsterCfgId ~= self.monsterid then
  211. return
  212. end
  213. local monsterCount = message.monsterCount
  214. --SL:LogError(monsterCount)
  215. if not monsterCount then
  216. monsterCount = 0
  217. end
  218. if monsterCount <= 0 then
  219. GUI:setGrey(self.view.btn,true)
  220. GUI:Text_setString(self.view.num,"<color=#DCE1E5>"..monsterCount.."只".."</color>")
  221. else
  222. GUI:setGrey(self.view.btn,false)
  223. GUI:Text_setString(self.view.num,monsterCount.."只")
  224. end
  225. --GUI:Text_setString(self.view.num,monsterCount.."只")
  226. end
  227. --获得秘境副本怪物指定地图位置范围的怪物数量
  228. function this:GetCopyMonsterCount()
  229. if not self.isOpen then
  230. return
  231. end
  232. --SL:LogError("GetCopyMonsterCount")
  233. GUI:setGrey(self.view.btn,false)
  234. GUI:Text_setString(self.view.num,"")
  235. if not self.is_show_num then
  236. return
  237. end
  238. if not self.mapId or not self.monsterid then
  239. return
  240. end
  241. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_SECRET_REALM_MONSTER_COUNT, {repId=self.mapId,monsterId=self.monsterid,x=self.x,y=self.y,range=self.range})
  242. end
  243. function this:MonserCopyCount(id, message)
  244. if not message then
  245. return
  246. end
  247. if message.repId ~= self.mapId or message.x ~= self.x or message.y ~= self.y or message.range ~= self.range then
  248. return
  249. end
  250. local monsterCount = message.count
  251. --SL:LogError(monsterCount)
  252. if not monsterCount then
  253. monsterCount = 0
  254. end
  255. local timeStr = message.time
  256. if monsterCount <= 0 then
  257. timeStr = tonumber(timeStr)
  258. local current_time = Time.GetServerTime()
  259. timeStr = math.ceil((timeStr-current_time)/1000)
  260. if timeStr > 0 then
  261. -- SL:ScheduleOnce(timeStr+0.5,function ()
  262. -- self:GetCopyMonsterCount()
  263. -- end)
  264. GUI:setGrey(self.view.btn,true)
  265. GUI:setGrey(self.view.btn,false)
  266. GUI:Text_setString(self.view.num,"")
  267. GUI:setVisible(self.view.end_time,true)
  268. GUI:SetControl_time(self.view.end_time,timeStr)
  269. else
  270. GUI:setVisible(self.view.end_time,false)
  271. GUI:setGrey(self.view.btn,false)
  272. GUI:Text_setString(self.view.num,monsterCount.."只")
  273. end
  274. else
  275. GUI:setVisible(self.view.end_time,false)
  276. GUI:setGrey(self.view.btn,false)
  277. GUI:Text_setString(self.view.num,monsterCount.."只")
  278. end
  279. --GUI:Text_setString(self.view.num,monsterCount.."只")
  280. end
  281. function this:GetMonsterPos()
  282. if not self.is_show_num then
  283. return
  284. end
  285. if not self.mapId or not self.line or not self.monsterid then
  286. return
  287. end
  288. local map_line = SL:GetMetaValue(EMetaVarGetKey.MAP_LINE)
  289. local map_id = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  290. if map_id == self.mapId and self.line == map_line and SL:MeData_Check() then
  291. local me_x = SL:MeData_GetCoord().x
  292. local me_y = SL:MeData_GetCoord().z
  293. local all_monster = {}
  294. local all_status = SL:GetMapMonsterStatus()
  295. local one = 1
  296. for i, data in ipairs(all_status) do
  297. if data.configId == self.monsterid and data.status == one then
  298. table.insert(all_monster,{configId=data.configId,x=data.pointX,y=data.pointY})
  299. end
  300. end
  301. local num = 0
  302. local index = 0
  303. SL:OpenWaitingUI({ msg = "最佳线路寻怪中"})
  304. local current_index = 1
  305. local is_end = false
  306. self.wait = SL:Schedule(self.wait,0,Time.deltaTime,-1, function()
  307. if is_end then
  308. return
  309. end
  310. local current_time = Time.GetServerTime()
  311. if current_index <= #all_monster then
  312. local data = all_monster[current_index]
  313. local arrive, path = SL:SearchPath({x=me_x,z=me_y}, {x=data.x,z=data.y})
  314. if arrive then
  315. data.num = path.n
  316. if num == 0 then
  317. num = data.num
  318. index = current_index
  319. else
  320. if num > data.num then
  321. num = data.num
  322. index = current_index
  323. end
  324. end
  325. end
  326. if current_index <= #all_monster then
  327. current_index = current_index+1
  328. return
  329. end
  330. end
  331. if current_index >= #all_monster then
  332. is_end = true
  333. if index > 0 then
  334. local pos_data = all_monster[index]
  335. SL:onLUAEvent(LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS,{mapCfgId=self.mapId,line=self.line,x= pos_data.x,y= pos_data.y,monsterCfgId=self.monsterid})
  336. else
  337. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_NEAREST_MONSTER, {mapCfgId=self.mapId,line=self.line,monsterCfgId=self.monsterid,state=1,x=me_x,y=me_y})
  338. end
  339. SL:HideWaitingUI()
  340. SL:UnSchedule(self.wait)
  341. end
  342. end)
  343. else
  344. local msg = {mapCfgId=self.mapId,line=self.line,monsterCfgId=self.monsterid}
  345. local curMapId = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  346. ---@type cfg_map_info_column
  347. local mapInfo = SL:GetConfig("cfg_map_info",curMapId)
  348. if mapInfo.nopositionmove == 1 then
  349. SL:MessageTip({id=116})
  350. return
  351. end
  352. SL:onLUAEvent(LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER,msg)
  353. SL:MapTransfer(self.mapId, self.line)
  354. end
  355. end
  356. function this:Close()
  357. self:UnRegistEvents()
  358. self.isOpen = false
  359. end
  360. return this