ZumaUI.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /** @format */
  2. import {UI} from '../enums/UI'
  3. import {BaseUI} from './BaseUI'
  4. import {Data, Mgr} from '../GameControl'
  5. import {observer, render, node, label, editBox, list} from '../mobx/observer'
  6. import {msgCmd} from '../proto/msg_cmd'
  7. import {ZumaRole} from '../zuma/ZumaRole'
  8. import FightCore from '../zuma/FightCore'
  9. import {GAME_TYPE, PREFAB_TYPE} from '../enums/Enum'
  10. import {adventureEnd, adventureEndRsp} from '../proto/game'
  11. import {ccUtils} from '../utils/ccUtils'
  12. import {SkillOptCell} from '../cell/SkillOptCell'
  13. import ZumaCore from '../zuma/ZumaCore'
  14. import {IGameResult, IRewardNty, ItemUICfg} from '../interface/UIInterface'
  15. import {EliteInfoConfig} from '../config/EliteInfoConfig'
  16. import {IZumaConfig} from '../config/ZumaConfig'
  17. import {RoleQualityConfig} from '../config/RoleQualityConfig'
  18. import {IZumabuffConfig, ZumabuffConfig} from '../config/ZumabuffConfig'
  19. const {ccclass, property} = cc._decorator
  20. @ccclass
  21. @observer
  22. export class ZumaUI extends BaseUI {
  23. private _curBalls: number = 0
  24. get curBalls(): number {
  25. return this._curBalls
  26. }
  27. set curBalls(value: number) {
  28. this._curBalls = value
  29. this.fightCore.setBallNum(this._curBalls)
  30. this.zumaCore.setBallNum(this._curBalls)
  31. }
  32. @node('zuma')
  33. zumaNode: cc.Node
  34. @node('fight')
  35. fightNode: cc.Node
  36. @node('pausePop')
  37. pausePop: cc.Node
  38. zumaCore: ZumaCore
  39. fightCore: FightCore
  40. roundID: number
  41. activeBuff: number[] = []
  42. fightReadyTime: number = 2
  43. endGameTime: number = 2
  44. isWin: boolean
  45. onLoad() {
  46. this.zumaCore = this.zumaNode.getComponent(ZumaCore)
  47. this.fightCore = this.fightNode.getComponent(FightCore)
  48. }
  49. onShow(args, fromUI: number) {
  50. Mgr.net.add(msgCmd.cmd_adventure_end_rsp, this, this.onStageEndRsp)
  51. Data.game.stageRound = 101
  52. this.curBalls = 100
  53. //this.activeBuff.length = 0
  54. let zumaRole = cc.find('role', this.zumaNode).getComponent(ZumaRole)
  55. this.zumaCore.init(zumaRole, this)
  56. this.fightCore.init(this)
  57. this.zumaNode.active = false
  58. this.startFightRound()
  59. }
  60. onHide(): any {
  61. Mgr.event.removeAll(this)
  62. }
  63. //UI或者其他函数=======================================
  64. startFightRound() {
  65. this.fightCore.resetGameWorld()
  66. //resetGameWorld需要一帧清理数据
  67. this.scheduleOnce(() => {
  68. this.fightCore.startStageGame()
  69. })
  70. }
  71. endFightRound(isWin: boolean) {
  72. this.scheduleOnce(() => {
  73. this.fightCore.isStop = true
  74. }, this.fightReadyTime)
  75. if (isWin) {
  76. let hasNext = this.fightCore.getRoundCfg(true)
  77. if (!hasNext) {
  78. this.endGame(true)
  79. } else {
  80. this.startZuma()
  81. }
  82. } else {
  83. this.endGame(false)
  84. }
  85. }
  86. startZuma() {
  87. this.fightCore.changeBagShow(false)
  88. this.zumaNode.active = true
  89. this.zumaCore.initData()
  90. this.changeZumaShow(true)
  91. this.scheduleOnce(() => {
  92. this.zumaCore.startGame()
  93. }, this.fightReadyTime)
  94. }
  95. endZuma() {
  96. this.fightCore.changeBagShow(true)
  97. this.changeZumaShow(false)
  98. this.scheduleOnce(() => {
  99. this.zumaNode.active = false
  100. this.fightCore.startNextRound()
  101. }, this.fightReadyTime)
  102. }
  103. changeZumaShow(isShow: boolean) {
  104. this.zumaNode.stopAllActions()
  105. let targetY = -328
  106. this.zumaNode.y = targetY - (isShow ? this.zumaNode.height : 0)
  107. cc.tween(this.zumaNode)
  108. .to(this.fightReadyTime, {y: targetY - (isShow ? 0 : this.zumaNode.height)})
  109. .start()
  110. }
  111. addZumaBuff(buffID: number) {
  112. let index = this.activeBuff.indexOf(buffID)
  113. if (index < 0) {
  114. this.activeBuff.push(buffID)
  115. this.fightCore.addTeamBuff(buffID)
  116. } else {
  117. //当前直接BUFFID+1做升级处理
  118. this.activeBuff[index] += 1
  119. this.fightCore.addTeamBuff(this.activeBuff[index])
  120. }
  121. this.zumaCore.setBuffNum()
  122. }
  123. endGame(isWin) {
  124. if (this.fightCore.gameOver) return
  125. this.fightCore.gameOver = true
  126. this.isWin = isWin
  127. if (this.fightCore.isTestScene) {
  128. this.onStageEndRsp({errno: 0}, null)
  129. }
  130. if (Data.game.gameType == GAME_TYPE.normal || Data.game.gameType == GAME_TYPE.elite) {
  131. let data = adventureEnd.create()
  132. data.win = isWin
  133. data.bossNum = this.fightCore.bossNum
  134. data.monsterNum = this.fightCore.monsterNum
  135. data.eliteNum = this.fightCore.eliteNum
  136. Mgr.net.send(msgCmd.cmd_adventure_end, data, true, true)
  137. }
  138. }
  139. showGameResult(result: IGameResult) {
  140. this.scheduleOnce(() => {
  141. Mgr.ui.show(UI.GameResultUI, result)
  142. }, this.endGameTime)
  143. }
  144. initZumaBuffItem(buffID: number, node: cc.Node) {
  145. let zumaBuffCfg = ZumabuffConfig[buffID]
  146. ccUtils.setLabel(`lv.${zumaBuffCfg.ID % 100}`, node, 'lv')
  147. this.loadNotRefTexImg(`Public/goodsQuality/item_frame${zumaBuffCfg.quality}`, node, 'item_frame')
  148. this.loadNotRefTexImg(`Public/card/icon/${zumaBuffCfg.icon}`, node, 'icon')
  149. }
  150. //网络事件=======================================
  151. onStageEndRsp(data: adventureEndRsp, rewardsNty: IRewardNty) {
  152. let result: IGameResult = {
  153. isWin: this.isWin,
  154. startTime: this.fightCore.startTime,
  155. rewardsNty,
  156. }
  157. if (Data.game.gameType == GAME_TYPE.normal && this.isWin) {
  158. Data.user.adventureId = Data.game.stageID + 1
  159. }
  160. this.showGameResult(result)
  161. }
  162. //触发事件=======================================
  163. // @render
  164. // showRender() {}
  165. // 点击事件=======================================
  166. onBackClick() {
  167. this.hide()
  168. Mgr.ui.show(UI.MainUI)
  169. }
  170. onPauseClick() {
  171. this.fightCore.isStop = true
  172. this.pausePop.active = true
  173. //防止暂停UI多语言没有切换
  174. // this.scheduleOnce(() => {
  175. // cc.director.pause()
  176. // })
  177. }
  178. onContinueClick() {
  179. this.fightCore.isStop = false
  180. //cc.director.resume()
  181. this.pausePop.active = false
  182. }
  183. onQuitClick() {
  184. //cc.director.resume()
  185. this.pausePop.active = false
  186. Mgr.event.removeAll(this)
  187. this.endGame(false)
  188. Mgr.game.exitGame()
  189. }
  190. }