LuaBossBattleMgr.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. local LuaBossBattleMgr = class("LuaBossBattleMgr")
  2. function LuaBossBattleMgr:ctor()
  3. self.battleMode = BattleSubMode.None
  4. self.isLoading = false
  5. self.isBattleEnd = false
  6. self.ShowSkip = false
  7. self:RegisterNetEvents();
  8. end
  9. function LuaBossBattleMgr:Destroy()
  10. self:UnRegisterNetEvents();
  11. if tolua.getpeer(self) ~= nil then
  12. tolua.setpeer(self, nil)
  13. end
  14. end
  15. function LuaBossBattleMgr:RegisterNetEvents()
  16. end
  17. function LuaBossBattleMgr:UnRegisterNetEvents()
  18. end
  19. function LuaBossBattleMgr:Enter(mode)
  20. if mode == nil then
  21. LogError("请设置Boss战的类型")
  22. return
  23. end
  24. self.isBattleEnd = false
  25. self.battleMode = mode
  26. if self.battleMode == BattleSubMode.WorldBoss then
  27. self:RegisterWorldBossEvents()
  28. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldBossBattle)
  29. end
  30. end
  31. function LuaBossBattleMgr:OpenNewbieBattleUI()
  32. if self.battleMode == BattleSubMode.NewbieBoss then
  33. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UINewbieBattle)
  34. end
  35. end
  36. function LuaBossBattleMgr:Exit()
  37. if self.battleMode == BattleSubMode.WorldBoss then
  38. self:UnRegisterWorldBossEvents()
  39. end
  40. self.battleMode = BattleSubMode.None
  41. self.isBattleEnd = true
  42. self.ShowSkip = false
  43. end
  44. --boss召唤出来
  45. function LuaBossBattleMgr:OnBossSpawned(bossName,life,maxLife,skillParam)
  46. self.bossName = bossName
  47. self.bossMaxLife = maxLife
  48. self.bossSkillParam = skillParam
  49. end
  50. --boss召唤出来显示warning
  51. function LuaBossBattleMgr:OnShowBossWarning()
  52. end
  53. --战斗失败
  54. function LuaBossBattleMgr:OnBattleFailed()
  55. -- LogError("LuaBossBattleMgr:OnBattleFailed")
  56. end
  57. --战斗胜利
  58. function LuaBossBattleMgr:OnBattleWin()
  59. -- LogError("LuaBossBattleMgr:OnBattleWin")
  60. end
  61. --- 战斗结束
  62. ---@param flag integer 1:boss死亡;2:自己死亡
  63. function LuaBossBattleMgr:OnBattleEnd(flag)
  64. -- LogError("LuaBossBattleMgr:OnBattleEnd " .. tostring(flag))
  65. if self.isBattleEnd then return end
  66. self.isBattleEnd = true
  67. if self.battleMode == BattleSubMode.WorldBoss then
  68. ManagerContainer.DataMgr.WorldBossData:SendLeaveChallengeBossRequest()
  69. self:ExitFromWorldBossBattle(flag)
  70. elseif self.battleMode == BattleSubMode.NewbieBoss then
  71. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ROLE_GUIDE_NTF, {guide_id = 1})
  72. local cb = function()
  73. ManagerContainer.LuaGameMgr:ShutDownBattle()
  74. ManagerContainer.LuaGameMgr:EnterBattle(false)
  75. end
  76. RegisterDelayStep(cb)
  77. end
  78. end
  79. --同步boss伤害
  80. function LuaBossBattleMgr:OnSyncBossDamage(damage)
  81. -- LogError("[wboy] CS_PLAYER_CHALLENGE_HP_REQ " .. Inspect(damage))
  82. if self.isBattleEnd then return end
  83. if self.battleMode == BattleSubMode.WorldBoss then
  84. ManagerContainer.DataMgr.WorldBossData:RecordBossDamage(damage)
  85. end
  86. end
  87. --剩余多长时间进入狂暴状态
  88. function LuaBossBattleMgr:OnShowBossRageLeftTime(leftTime)
  89. end
  90. --boss进入狂暴状态
  91. function LuaBossBattleMgr:OnBossInRage()
  92. end
  93. --开始进行加载
  94. function LuaBossBattleMgr:OnLoadBegin()
  95. self.isLoading = true
  96. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin);
  97. if self.battleMode == BattleSubMode.WorldBoss then
  98. ManagerContainer.DataMgr.WorldBossData:WorldBossBattleLoadBegin()
  99. end
  100. end
  101. --加载进度的刷新
  102. function LuaBossBattleMgr:OnLoadProgress(progress)
  103. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Progress,progress);
  104. end
  105. --加载完成
  106. function LuaBossBattleMgr:OnLoadComplete()
  107. self.isLoading = false
  108. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Complete);
  109. if self.battleMode == BattleSubMode.WorldBoss then
  110. ManagerContainer.DataMgr.WorldBossData:WorldBossBattleLoadComplete()
  111. end
  112. end
  113. function LuaBossBattleMgr:RegisterWorldBossEvents()
  114. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_HP_CHANGED, self, self.OnWorldBossHpChanged)
  115. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_PLAYER_CHANGED, self, self.OnWorldBossPlayerChanged)
  116. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_SERVER_KICKOUT_BATTLE, self, self.OnWorldBossServerKickoutBattle)
  117. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.WORLD_BOSS_ROLL_POINT_LIST_CHANGED, self, self.OnWorldBossRollPointList)
  118. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted)
  119. end
  120. function LuaBossBattleMgr:UnRegisterWorldBossEvents()
  121. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_HP_CHANGED, self, self.OnWorldBossHpChanged)
  122. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_PLAYER_CHANGED, self, self.OnWorldBossPlayerChanged)
  123. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_SERVER_KICKOUT_BATTLE, self, self.OnWorldBossServerKickoutBattle)
  124. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.WORLD_BOSS_ROLL_POINT_LIST_CHANGED, self, self.OnWorldBossRollPointList)
  125. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.UI_CLOSE_COMPELETED, self, self.OnUICloseCompleted)
  126. if self.playerChangeDeltaTimer and self.playerChangeDeltaTimer.running then
  127. self.playerChangeDeltaTimer:Stop()
  128. end
  129. self.playerChangeDeltaTimer = nil
  130. if self.waitRollTimer and self.waitRollTimer.running then
  131. self.waitRollTimer:Stop()
  132. end
  133. self.waitRollTimer = nil
  134. end
  135. function LuaBossBattleMgr:OnWorldBossHpChanged()
  136. local curHp = ManagerContainer.DataMgr.WorldBossData:GetCurHp()
  137. LuaBattleBridge.SyncWorldBossLife(curHp)
  138. end
  139. function LuaBossBattleMgr:OnWorldBossPlayerChanged(enters, exits)
  140. for i = 1, #exits do
  141. local uid = exits[i]
  142. LuaBattleBridge.SetActorDead(uid)
  143. end
  144. if not self.playerChangeDeltaTimer then
  145. self.playerChangeDeltaTimer = Timer.New(function()
  146. self:WorldBossPlayerChanged()
  147. end, 0.5, -1)
  148. end
  149. if self.playerChangeDeltaTimer.running then
  150. self:WorldBossPlayerChanged(true)
  151. end
  152. self.playerChangeDeltaTimer.time = 0.5
  153. self.playerChangeDeltaTimer.enters = enters
  154. self.playerChangeDeltaTimer.exits = exits
  155. self.playerChangeDeltaTimer:Start()
  156. end
  157. function LuaBossBattleMgr:WorldBossPlayerChanged(force)
  158. if not self.playerChangeDeltaTimer then
  159. return
  160. end
  161. local enters = self.playerChangeDeltaTimer.enters
  162. local exits = self.playerChangeDeltaTimer.exits
  163. for i = 1, #exits do
  164. local uid = exits[i]
  165. LuaBattleBridge.RemoveActorFromBattle(uid)
  166. end
  167. for i = 1, #enters do
  168. local enter = enters[i]
  169. local uid = enter.uid
  170. local actorSystem = enter.data
  171. if actorSystem then
  172. local actorParam = actorSystem:GetPlayerActorParam()
  173. if actorParam then
  174. if nil ~= actorSystem.userData.change_play_id and actorSystem.userData.change_play_id>0 then
  175. actorParam = actorSystem:CreatePetBossActor(actorSystem.userData.change_play_id)
  176. actorParam.ID = uid
  177. end
  178. LuaBattleBridge.AddActorToBattle(actorParam)
  179. end
  180. end
  181. end
  182. self.playerChangeDeltaTimer.enters = nil
  183. self.playerChangeDeltaTimer.exits = nil
  184. if not force then
  185. self.playerChangeDeltaTimer:Stop()
  186. end
  187. end
  188. --- 服务器强制踢出世界boss战斗
  189. ---@param result 1:胜利
  190. function LuaBossBattleMgr:OnWorldBossServerKickoutBattle(result)
  191. -- 设置boss血量为0,走战斗结束流程
  192. LuaBattleBridge.SyncWorldBossLife(0)
  193. end
  194. function LuaBossBattleMgr:ExitFromWorldBossBattle(flag)
  195. -- 不退出,等待Roll点界面
  196. if not self.waitRollTimer then
  197. -- 请求超时60秒,退出战斗
  198. self.waitRollTimer = Timer.New(function()
  199. self:ExitWorldBossBattle()
  200. end, 60, 1)
  201. end
  202. self.waitRollTimer:Start()
  203. return nil
  204. end
  205. function LuaBossBattleMgr:QuitFromWorldBossBattle()
  206. -- 不退出,等待Roll点界面
  207. if not self.waitRollTimer then
  208. -- 请求超时0秒,退出战斗
  209. self.waitRollTimer = Timer.New(function()
  210. self:ExitWorldBossBattle()
  211. end, 3, 1)
  212. end
  213. self.waitRollTimer:Start()
  214. return nil
  215. end
  216. function LuaBossBattleMgr:ExitWorldBossBattle()
  217. -- 清理数据,避免干扰其它战斗
  218. local actorSystemMap = ManagerContainer.DataMgr.WorldBossData:GetActorSystem()
  219. for uid,_ in pairs(actorSystemMap) do
  220. LuaBattleBridge.RemoveActorFromBattle(uid)
  221. end
  222. ManagerContainer.LuaGameMgr:ShutDownBattle()
  223. ManagerContainer.FSMMgr:ChangeState(Enum.StateEnum.IdleState.stateId)
  224. ManagerContainer.DataMgr.WorldBossData:ExitWorldBossBattle()
  225. local data = require('ExecuteSequenceData'):new()
  226. data:AppendFunc(false, ManagerContainer.LuaUIMgr, ManagerContainer.LuaUIMgr.Open, Enum.UIPageName.UIMain)
  227. data:AppendUIListener(Enum.UIPageName.UIMain, UIEventNames.UI_FILLCONTENT_COMPELETED, 5)
  228. data:AppendUIViewFunc(false, Enum.UIPageName.UIMain, 'ChangePageMsg', Enum.MainViewPageType.Town)
  229. data:AppendUIListener(Enum.UIPageName.UIMainCity1, UIEventNames.UI_FILLCONTENT_COMPELETED, 5)
  230. data:AppendUIViewFunc(false, Enum.UIPageName.UIMainCity1, 'OpenWorldBoss')
  231. ManagerContainer.ExecuteSequenceMgr:Execute(data)
  232. end
  233. function LuaBossBattleMgr:OnWorldBossRollPointList()
  234. local worldBossData = ManagerContainer.DataMgr.WorldBossData
  235. if not worldBossData:HasWorldBossPointInfo() then
  236. self:ExitWorldBossBattle()
  237. return
  238. end
  239. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIWorldBossReward) then
  240. return
  241. end
  242. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldBossReward)
  243. if self.waitRollTimer then
  244. self.waitRollTimer:Stop()
  245. end
  246. end
  247. function LuaBossBattleMgr:OnUICloseCompleted(owner)
  248. if owner.uiData.id ~= Enum.UIPageName.UIWorldBossReward then
  249. return
  250. end
  251. self:ExitWorldBossBattle()
  252. end
  253. --同步战斗内玩家信息
  254. function LuaBossBattleMgr:OnFighterLifeChanged(isBoss,actorId,life,maxLife)
  255. if isBoss then
  256. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Life,life,maxLife)
  257. else
  258. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Life,actorId,life,maxLife)
  259. end
  260. end
  261. function LuaBossBattleMgr:OnFighterEnergyChanged(actorId,sp,maxSp)
  262. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Sp,actorId,sp,maxSp)
  263. end
  264. function LuaBossBattleMgr:OnFighterCastSkill(skillParam)
  265. if skillParam.isBoss then
  266. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Skill,skillParam)
  267. else
  268. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Cast_Skill,skillParam)
  269. end
  270. end
  271. function LuaBossBattleMgr:OnShowBossBuff(actorId,isBoss,buffIcon,num,isPlayeRecord)
  272. if isBoss then
  273. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Buff,buffIcon,num)
  274. else
  275. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Player_Buff,actorId, buffIcon,num)
  276. end
  277. end
  278. function LuaBossBattleMgr:OnRemoveBossBuff(actorId,isBoss,buffIcon)
  279. if isBoss then
  280. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Remove_Buff,buffIcon)
  281. else
  282. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Remove_Player_Buff, actorId, buffIcon)
  283. end
  284. end
  285. function LuaBossBattleMgr:OnShowFighter(actorId)
  286. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Show_Fighter,actorId)
  287. end
  288. function LuaBossBattleMgr:ShowSkipBattle()
  289. self.ShowSkip = true
  290. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_SKIP_BATTLE)
  291. end
  292. function LuaBossBattleMgr:SetUINodeVis(nodePath)
  293. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Set_UINode_Vis,nodePath)
  294. end
  295. function LuaBossBattleMgr:HeroChangeProfessionSuccess()
  296. ManagerContainer.DataMgr.UserData:RoleChangeJobAttrSuccess()
  297. end
  298. return LuaBossBattleMgr