ZumaUI.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {ccUtils} from '../utils/ccUtils'
  6. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  7. import {msgCmd} from '../proto/msg_cmd'
  8. import {ZumaConfig} from '../config/ZumaConfig'
  9. import {ZumaCore} from '../zuma/ZumaCore'
  10. import {ZumaRole} from '../zuma/ZumaRole'
  11. import FightCore from '../zuma/FightCore'
  12. import {GAME_PREFAB_TYPE, GAME_ROLE_TIP, GAME_TYPE, RELIC_EVENT_NTY} from '../enums/Enum'
  13. import {adventureEnd, dailyDungeonsEnd, relicEventSelect} from '../proto/game'
  14. import {IStageInfoConfig, StageInfoConfig} from '../config/StageInfoConfig'
  15. import {EliteInfoConfig, IEliteInfoConfig} from '../config/EliteInfoConfig'
  16. import {IReliclevelsConfig, ReliclevelsConfig} from '../config/ReliclevelsConfig'
  17. import {DailyConfig, IDailyConfig} from '../config/DailyConfig'
  18. import {IStageConfig, StageConfig} from '../config/StageConfig'
  19. import {EliteStageConfig, IEliteStageConfig} from '../config/EliteStageConfig'
  20. import {ChallengeConfig, IChallengeConfig} from '../config/ChallengeConfig'
  21. import {ICard} from '../interface/GlobalInterface'
  22. const {ccclass, property} = cc._decorator
  23. @ccclass
  24. @observer
  25. export class ZumaUI extends BaseUI {
  26. @node('zuma')
  27. zumaNode: cc.Node
  28. @node('fight')
  29. fightNode: cc.Node
  30. @node('pausePop')
  31. private pausePop: cc.Node
  32. zumaCore: ZumaCore
  33. fightCore: FightCore
  34. roundID: number
  35. activeBuff: number[] = []
  36. onLoad() {
  37. this.zumaCore = this.zumaNode.getComponent(ZumaCore)
  38. this.fightCore = this.fightNode.getComponent(FightCore)
  39. }
  40. onShow(args, fromUI: number) {
  41. //Mgr.net.add(msgCmd.xxx, this, this.onXXXRsp)
  42. this.activeBuff.length = 0
  43. let zumaRole = cc.find('role', this.zumaNode).getComponent(ZumaRole)
  44. this.zumaCore.init(zumaRole, this)
  45. this.fightCore.init(this)
  46. this.startFightRound()
  47. }
  48. onHide(): any {
  49. Mgr.event.removeAll(this)
  50. }
  51. //UI或者其他函数=======================================
  52. startFightRound() {
  53. Data.game.stageRound = 101
  54. this.fightCore.resetGameWorld()
  55. //resetGameWorld需要一帧清理数据
  56. this.scheduleOnce(() => {
  57. this.fightCore.startStageGame()
  58. })
  59. }
  60. endFightRound(isWin: boolean) {
  61. this.fightCore.isStop = true
  62. if (isWin) {
  63. let hasNext = this.fightCore.getRoundCfg(true)
  64. if (!hasNext) {
  65. this.endGame(true)
  66. } else {
  67. this.startZuma()
  68. }
  69. } else {
  70. this.endGame(false)
  71. }
  72. }
  73. startZuma() {
  74. this.zumaCore.startGame()
  75. }
  76. endZuma() {
  77. this.fightCore.startNextRound()
  78. }
  79. addZumaBuff(buffID: number) {
  80. let index = this.activeBuff.indexOf(buffID)
  81. if (index < 0) {
  82. this.activeBuff.push(buffID)
  83. this.fightCore.addTeamBuff(buffID)
  84. } else {
  85. //当前直接BUFFID+1做升级处理
  86. this.activeBuff[index] += 1
  87. this.fightCore.addTeamBuff(this.activeBuff[index])
  88. }
  89. }
  90. endGame(isWin) {
  91. if (this.fightCore.gameOver) return
  92. this.fightCore.gameOver = true
  93. if (this.fightCore.isTestScene) {
  94. this.startFightRound()
  95. }
  96. if (Data.game.gameType == GAME_TYPE.normal || Data.game.gameType == GAME_TYPE.elite) {
  97. let data = adventureEnd.create()
  98. data.win = isWin
  99. data.bossNum = this.fightCore.bossNum
  100. data.monsterNum = this.fightCore.monsterNum
  101. data.eliteNum = this.fightCore.eliteNum
  102. Mgr.net.send(msgCmd.cmd_adventure_end, data, true, true)
  103. }
  104. }
  105. //网络事件=======================================
  106. // onXXXRsp() {}
  107. //触发事件=======================================
  108. // @render
  109. // showRender() {}
  110. // 点击事件=======================================
  111. onBackClick() {
  112. this.hide()
  113. Mgr.ui.show(UI.MainUI)
  114. }
  115. onPauseClick() {
  116. this.fightCore.isStop = true
  117. this.pausePop.active = true
  118. //防止暂停UI多语言没有切换
  119. // this.scheduleOnce(() => {
  120. // cc.director.pause()
  121. // })
  122. }
  123. onContinueClick() {
  124. this.fightCore.isStop = false
  125. //cc.director.resume()
  126. this.pausePop.active = false
  127. }
  128. onQuitClick() {
  129. //cc.director.resume()
  130. this.pausePop.active = false
  131. Mgr.event.removeAll(this)
  132. this.endGame(false)
  133. Mgr.game.exitGame()
  134. }
  135. }