GlobalLuaEventManager.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by PZM.
  4. --- DateTime: 2024/7/9 11:21
  5. ---@class GlobalEventManger
  6. GlobalLuaEventManager = {}
  7. local this = GlobalLuaEventManager
  8. function this.Init()
  9. this.RegistEvents()
  10. end
  11. function this.RegistEvents()
  12. SL:RegisterLUAEvent(LUA_EVENT_ENTER_MAP,this.LUA_EVENT_ENTER_MAP)
  13. SL:RegisterLuaNetMsg(LuaMessageIdToClient.TIPS,this.TIPS)
  14. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_CREATE, this.LUA_EVENT_PLAYER_CREATE)
  15. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_SEND_GET_REWARD_MSG,this.RES_SEND_GET_REWARD_MSG)
  16. -- SL:RegisterLuaNetMsg(LuaMessageIdToClient.AFTER_ENTER_SECRET_REALM,this.AFTER_ENTER_SECRET_REALM)
  17. SL:RegisterLUAEvent(LUA_EVENT_CAREER_CHANGED, this.LUA_EVENT_CAREER_CHANGED)
  18. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY,this.RES_ROLE_ATT_ADD_WAY)
  19. --跨服模式变化
  20. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_IN_OUT_CROSS_MAP,this.RES_IN_OUT_CROSS_MAP)
  21. SL:RegisterLuaNetMsg(MessageDef.ResViewUnionMessage,this.ResViewUnionMessage)
  22. SL:RegisterLuaNetMsg(MessageDef.ResQuitUnionMessage,this.ResQuitUnionMessage)
  23. SL:RegisterTrigger(LUA_TRIGGER_SET_STREAM,this.LUA_TRIGGER_SET_STREAM)
  24. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_RECHARGE_TRADE_INFO,this.RES_RECHARGE_TRADE_INFO)
  25. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_ENTER_MAP, this.LUA_EVENT_PLAYER_ENTER_MAP)
  26. SL:RegisterLUAEvent(LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER, this.LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER)
  27. SL:RegisterLUAEvent(LUA_EVENT_ROLE_LOGIN, this.LUA_EVENT_ROLE_LOGIN)
  28. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TASK_STATES_TO_FUNC_ON,this.RES_TASK_STATES_TO_FUNC_ON_MESSAGE)
  29. end
  30. function this:LUA_EVENT_ROLE_LOGIN()
  31. SL:SetLocalString("showMaxBagTips", "true")
  32. end
  33. function this.UnRegistEvents()
  34. SL:UnRegisterLUAEvent(LUA_EVENT_ENTER_MAP,this.LUA_EVENT_ENTER_MAP)
  35. SL:RegisterLUAEvent(LUA_EVENT_PLAYER_CREATE, this.LUA_EVENT_PLAYER_CREATE)
  36. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.RES_SEND_GET_REWARD_MSG,this.RES_SEND_GET_REWARD_MSG)
  37. SL:UnRegisterLUAEvent(LUA_EVENT_CAREER_CHANGED, this.LUA_EVENT_CAREER_CHANGED)
  38. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY,this.RES_ROLE_ATT_ADD_WAY)
  39. SL:UnRegisterLuaNetMsg(LuaMessageIdToClient.RES_IN_OUT_CROSS_MAP,this.RES_IN_OUT_CROSS_MAP)
  40. SL:UnRegisterLuaNetMsg(MessageDef.ResViewUnionMessage,this.ResViewUnionMessage)
  41. SL:UnRegisterLuaNetMsg(MessageDef.ResQuitUnionMessage,this.ResQuitUnionMessage)
  42. SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_ENTER_MAP, this.LUA_EVENT_PLAYER_ENTER_MAP)
  43. SL:UnRegisterLUAEvent(LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER, this.LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER)
  44. SL:UnRegisterLUAEvent(LUA_EVENT_EXIT_GAME, this.LUA_EVENT_EXIT_GAME)
  45. SL:UnRegisterLUAEvent(LuaMessageIdToClient.RES_TASK_STATES_TO_FUNC_ON,this.RES_TASK_STATES_TO_FUNC_ON_MESSAGE)
  46. end
  47. function this.Reset()
  48. this.UnRegistEvents()
  49. end
  50. function this.LUA_TRIGGER_SET_STREAM(_,go, roleId,itemCfgId,strengthLevel)
  51. if not SL:HasConfig('cfg_equip_strengthen',itemCfgId) then
  52. return
  53. end
  54. if not this.tempEqupInfo then
  55. this.tempEqupInfo = {}
  56. end
  57. this.tempEqupInfo.cfgId = itemCfgId
  58. local liuGuangId = EquipFunc.GetEquipLiuGuangId(this.tempEqupInfo,strengthLevel)
  59. if liuGuangId then
  60. SL:SetMetaValue(EMetaVarSetKey.EQUIP_STREAMER_REFRESH,go,liuGuangId)
  61. end
  62. end
  63. --进入地图 预显示界面
  64. function this.LUA_EVENT_ENTER_MAP(_, eventData)
  65. local isChangeMap = eventData
  66. GUI:UIPanel_Open("dev/outui/ExpMessage/Panel/KLUIExpMessage/KLUIExpMessagePanel")
  67. GUI:UIPanel_Open("dev/outui/Message/Panel/KLHorseRaceLamp/KLHorseRaceLampPanel")
  68. GUI:UIPanel_Open("dev/outui/Activity/Panel/KLActivityPreview/KLActivityPreviewPanel")
  69. Coroutine.Start(function()
  70. --预打开一下
  71. if not isChangeMap then
  72. Coroutine.WaitForEndOfFrame()
  73. GUI:UIPanel_Open("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", nil, nil, { x = -400, y = 0, relatePanel = "",isPreLoad = true })
  74. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  75. end
  76. end)
  77. GUI:UIPanel_Open("dev/ui/Common/Panel/KLTop/KLTopPanel")
  78. --this.PreLoad()
  79. end
  80. function this.PreLoad(...)
  81. if this.isHasPreLoad then
  82. return
  83. end
  84. this.isHasPreLoad = true
  85. local co = Coroutine.Start(function()
  86. --Coroutine.WaitForEndOfFrame()
  87. --GUI:PreLoadUI("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", 1)
  88. Coroutine.WaitForEndOfFrame()
  89. GUI:PreLoadUI("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel", 1)
  90. --Coroutine.WaitForEndOfFrame()
  91. --GUI:PreLoadUI("dev/ui/Common/Item/KLBagItem/KLBagItemItem",50)
  92. end
  93. )
  94. end
  95. function this:TIPS(message)
  96. SL:TipMessage(message, 1, NoticeType.NoticeMid)
  97. end
  98. ---@param data {player:Player}
  99. function this.LUA_EVENT_PLAYER_CREATE(_,data)
  100. end
  101. function this.RES_SEND_GET_REWARD_MSG(_,data)
  102. local reward = {}
  103. for k, v in pairs(data) do
  104. reward[tonumber(k)] = tonumber(v)
  105. end
  106. SL:OpenRewardTips(reward,0)
  107. end
  108. ---进入秘境副本成功回包
  109. function this.AFTER_ENTER_SECRET_REALM(_,data)
  110. local mapId = data.mapId
  111. GUI:UIPanel_Open("dev/outui/ChallengeBoss/Panel/KLChallengeBossPos/KLChallengeBossPosPanel",nil,nil,{mapId=mapId})
  112. end
  113. --职业改变
  114. function this.LUA_EVENT_CAREER_CHANGED(_, data)
  115. local preCareer = data.currentCareer
  116. local nextCareer = data.newCareer
  117. ---@type cfg_career_column
  118. local careerConfig = SL:GetConfig("cfg_career", nextCareer)
  119. if careerConfig.window == 1 then
  120. GUI:UIPanel_Open("dev/outui/Career/Panel/KLCareerChangePanel/KLCareerChangePanel", nil, nil, { currentCareer = nextCareer, originalCareer = preCareer })
  121. end
  122. end
  123. function this.RES_ROLE_ATT_ADD_WAY(_,data)
  124. local addWay = data
  125. SL:MeData_GetRoleExtInfo().attAddWay = addWay
  126. SL:onLUAEvent(LUA_EVENT_SURE_ATTR_PLAN, data)
  127. end
  128. function this.RES_IN_OUT_CROSS_MAP(id, message)
  129. this.isCrossServer = message.type
  130. if this.isCrossServer and this.isCrossServer == 1 then
  131. if not SL:MeData_GetUnionId() or SL:MeData_GetUnionId() == 0 then
  132. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, 0)
  133. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,0)
  134. else
  135. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, 5)
  136. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,5)
  137. end
  138. end
  139. end
  140. function this.ResViewUnionMessage(id, message)
  141. if message.unionInfo and message.unionInfo.unionId then
  142. if this.isCrossServer and this.isCrossServer == 1 then
  143. if not SL:MeData_GetUnionId() or SL:MeData_GetUnionId() == 0 then
  144. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, 0)
  145. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,0)
  146. else
  147. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, 5)
  148. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,5)
  149. end
  150. end
  151. end
  152. end
  153. function this.ResQuitUnionMessage(id, message)
  154. if message.isQuit then
  155. if this.isCrossServer and this.isCrossServer == 1 then
  156. SL:SetMetaValue(EMetaVarSetKey.SET_PKMODE, 0)
  157. SL:onLUAEvent(LUA_EVENT_CROSS_SERVER_PK_MODE,0)
  158. end
  159. end
  160. end
  161. function this.LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER(id, message)
  162. this.data_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER = message
  163. end
  164. function this.check_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER(message)
  165. if not this.data_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER then
  166. return
  167. end
  168. SL:ScheduleOnce(0.3, function()
  169. this.start_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER(message)
  170. end)
  171. end
  172. function this.start_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER(message)
  173. if not this.data_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER then
  174. return
  175. end
  176. local message = this.data_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER
  177. this.data_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER = nil
  178. local map_id = SL:GetMetaValue(EMetaVarGetKey.MAP_ID)
  179. local map_line = SL:GetMetaValue(EMetaVarGetKey.MAP_LINE)
  180. if message.mapCfgId ~= map_id or message.line ~= map_line then
  181. return
  182. end
  183. local me_x = SL:MeData_GetCoord().x
  184. local me_y = SL:MeData_GetCoord().z
  185. local all_monster = {}
  186. local all_status = SL:GetMapMonsterStatus()
  187. local one = 1
  188. for i, data in ipairs(all_status) do
  189. if data.configId == message.monsterCfgId and data.status == one then
  190. table.insert(all_monster,{configId=data.configId,x=data.pointX,y=data.pointY})
  191. end
  192. end
  193. local num = 0
  194. local index = 0
  195. --SL:OpenWaitingUI({ msg = "寻怪中"})
  196. local current_index = 1
  197. local is_end = false
  198. this.wait = SL:Schedule(this.wait,0,Time.deltaTime,-1, function()
  199. if is_end then
  200. return
  201. end
  202. local current_time = Time.GetServerTime()
  203. if current_index <= #all_monster then
  204. local data = all_monster[current_index]
  205. local arrive, path = SL:SearchPath({x=me_x,z=me_y}, {x=data.x,z=data.y})
  206. if arrive then
  207. data.num = path.n
  208. if num == 0 then
  209. num = data.num
  210. index = current_index
  211. else
  212. if num > data.num then
  213. num = data.num
  214. index = current_index
  215. end
  216. end
  217. end
  218. if current_index <= #all_monster then
  219. current_index = current_index+1
  220. return
  221. end
  222. end
  223. if index > 0 then
  224. local pos_data = all_monster[index]
  225. SL:StopOnHook(true)
  226. this.pos_monster_id = message.monsterCfgId
  227. this.map_data = {message.mapCfgId, message.line, pos_data.x, pos_data.y}
  228. SL:Pathfinding(message.mapCfgId, message.line, pos_data.x, pos_data.y,this.MonserPosEnd,this.pos_monster_id)
  229. --SL:HideWaitingUI()
  230. SL:UnSchedule(this.wait)
  231. end
  232. end)
  233. end
  234. function this.LUA_EVENT_PLAYER_ENTER_MAP(id, message)
  235. this.check_LUA_EVENT_CHALLENGE_BOSS_MONSTER_POS_AFTER(message)
  236. end
  237. function this.MonserPosEnd(pos)
  238. if pos and pos.x and pos.z then
  239. this.scheduleId = SL:ScheduleOnce(0.1, function()
  240. SL:Pathfinding( this.map_data[1], this.map_data[2], pos.x, pos.z,this.BossPointOnHook)
  241. end)
  242. else
  243. SL:StartOnHook(true,true,this.pos_monster_id)
  244. end
  245. end
  246. function this.BossPointOnHook()
  247. SL:StartOnHook(true,true,this.pos_monster_id)
  248. end
  249. ---@param message recharge
  250. function this.RES_RECHARGE_TRADE_INFO(_,message)
  251. --[[if message and message.bubble then
  252. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_ADD,{id=PopoverType.Tip_MonthCardQJQuota})
  253. else
  254. SL:onLUAEvent(LUA_EVENT_BUBBLETIPS_DEL,PopoverType.Tip_MonthCardQJQuota)
  255. end]]
  256. end
  257. function this.RES_TASK_STATES_TO_FUNC_ON_MESSAGE(_,message)
  258. if message then
  259. SL:ClearSystemFunctionState()
  260. local tempData = {}
  261. ---@type cfg_career_column
  262. local careerTbl = SL:GetMetaValue(EMetaVarGetKey.ME_CAREER_TAB_COLUMN)
  263. if careerTbl then
  264. for i, v in pairs(message) do
  265. local taskId = tonumber(i)
  266. local taskState = tonumber(v)
  267. ---@type cfg_system_switch_column[]
  268. --local tblList = cfg_system_switch_post.GetSystemBtnGetTaskInfo(careerTbl.id,taskId)
  269. local tblList = SL:CfgSystemSwitchPost_GetSystemBtnGetTaskInfo(careerTbl.id,taskId)
  270. if tblList then
  271. for j, k in pairs(tblList) do
  272. SL:SetMetaValue(EMetaVarSetKey.SET_SYSTEM_FUNCTION_TASK_STATE,k.systemName,taskState == TaskState.Accepted)
  273. tempData[k.btnPath] = k.btnPath
  274. end
  275. end
  276. ---@type cfg_system_switch_column[]
  277. --tblList = cfg_system_switch_post.GetSystemBtnFinishedTaskInfo(careerTbl.id,taskId)
  278. tblList = SL:CfgSystemSwitchPost_GetSystemBtnGetTaskInfo(careerTbl.id,taskId)
  279. if tblList then
  280. for j, k in pairs(tblList) do
  281. SL:SetMetaValue(EMetaVarSetKey.SET_SYSTEM_FUNCTION_TASK_STATE,k.systemName,SL:GetMetaValue(EMetaVarGetKey.GET_SYSTEM_FUNCTION_TASK_STATE,k.systemName) and true or taskState == TaskState.Completed)
  282. tempData[k.systemName] = k.btnPath
  283. end
  284. end
  285. end
  286. end
  287. for systemName, btnPath in pairs(tempData) do
  288. local isShow = SL:GetMetaValue(EMetaVarGetKey.IS_OPEN_SYSTEMFUNCTION, systemName)
  289. SL:ControlSystemPortalVisible(btnPath, isShow)
  290. end
  291. end
  292. end