/** @format */ import {UI} from '../enums/UI' import {BaseUI} from './BaseUI' import {Data, Mgr} from '../GameControl' import {observer, render, node, label, editBox, list} from '../mobx/observer' import {msgCmd} from '../proto/msg_cmd' import {ZumaRole} from '../zuma/ZumaRole' import FightCore from '../zuma/FightCore' import {GAME_TYPE, PREFAB_TYPE} from '../enums/Enum' import {adventureEnd, adventureEndRsp} from '../proto/game' import {ccUtils} from '../utils/ccUtils' import {SkillOptCell} from '../cell/SkillOptCell' import ZumaCore from '../zuma/ZumaCore' import {IGameResult, IRewardNty, ItemUICfg} from '../interface/UIInterface' import {EliteInfoConfig} from '../config/EliteInfoConfig' import {IZumaConfig} from '../config/ZumaConfig' import {RoleQualityConfig} from '../config/RoleQualityConfig' import {IZumabuffConfig, ZumabuffConfig} from '../config/ZumabuffConfig' const {ccclass, property} = cc._decorator @ccclass @observer export class ZumaUI extends BaseUI { private _curBalls: number = 0 get curBalls(): number { return this._curBalls } set curBalls(value: number) { this._curBalls = value this.fightCore.setBallNum(this._curBalls) this.zumaCore.setBallNum(this._curBalls) } @node('zuma') zumaNode: cc.Node @node('fight') fightNode: cc.Node @node('pausePop') pausePop: cc.Node zumaCore: ZumaCore fightCore: FightCore roundID: number activeBuff: number[] = [] fightReadyTime: number = 2 endGameTime: number = 2 isWin: boolean onLoad() { this.zumaCore = this.zumaNode.getComponent(ZumaCore) this.fightCore = this.fightNode.getComponent(FightCore) } onShow(args, fromUI: number) { Mgr.net.add(msgCmd.cmd_adventure_end_rsp, this, this.onStageEndRsp) Data.game.stageRound = 101 this.curBalls = 100 //this.activeBuff.length = 0 let zumaRole = cc.find('role', this.zumaNode).getComponent(ZumaRole) this.zumaCore.init(zumaRole, this) this.fightCore.init(this) this.zumaNode.active = false this.startFightRound() } onHide(): any { Mgr.event.removeAll(this) } //UI或者其他函数======================================= startFightRound() { this.fightCore.resetGameWorld() //resetGameWorld需要一帧清理数据 this.scheduleOnce(() => { this.fightCore.startStageGame() }) } endFightRound(isWin: boolean) { this.scheduleOnce(() => { this.fightCore.isStop = true }, this.fightReadyTime) if (isWin) { let hasNext = this.fightCore.getRoundCfg(true) if (!hasNext) { this.endGame(true) } else { this.startZuma() } } else { this.endGame(false) } } startZuma() { this.fightCore.changeBagShow(false) this.zumaNode.active = true this.zumaCore.initData() this.changeZumaShow(true) this.scheduleOnce(() => { this.zumaCore.startGame() }, this.fightReadyTime) } endZuma() { this.fightCore.changeBagShow(true) this.changeZumaShow(false) this.scheduleOnce(() => { this.zumaNode.active = false this.fightCore.startNextRound() }, this.fightReadyTime) } changeZumaShow(isShow: boolean) { this.zumaNode.stopAllActions() let targetY = -328 this.zumaNode.y = targetY - (isShow ? this.zumaNode.height : 0) cc.tween(this.zumaNode) .to(this.fightReadyTime, {y: targetY - (isShow ? 0 : this.zumaNode.height)}) .start() } addZumaBuff(buffID: number) { let index = this.activeBuff.indexOf(buffID) if (index < 0) { this.activeBuff.push(buffID) this.fightCore.addTeamBuff(buffID) } else { //当前直接BUFFID+1做升级处理 this.activeBuff[index] += 1 this.fightCore.addTeamBuff(this.activeBuff[index]) } this.zumaCore.setBuffNum() } endGame(isWin) { if (this.fightCore.gameOver) return this.fightCore.gameOver = true this.isWin = isWin if (this.fightCore.isTestScene) { this.onStageEndRsp({errno: 0}, null) } if (Data.game.gameType == GAME_TYPE.normal || Data.game.gameType == GAME_TYPE.elite) { let data = adventureEnd.create() data.win = isWin data.bossNum = this.fightCore.bossNum data.monsterNum = this.fightCore.monsterNum data.eliteNum = this.fightCore.eliteNum Mgr.net.send(msgCmd.cmd_adventure_end, data, true, true) } } showGameResult(result: IGameResult) { this.scheduleOnce(() => { Mgr.ui.show(UI.GameResultUI, result) }, this.endGameTime) } initZumaBuffItem(buffID: number, node: cc.Node) { let zumaBuffCfg = ZumabuffConfig[buffID] ccUtils.setLabel(`lv.${zumaBuffCfg.ID % 100}`, node, 'lv') this.loadNotRefTexImg(`Public/goodsQuality/item_frame${zumaBuffCfg.quality}`, node, 'item_frame') this.loadNotRefTexImg(`Public/card/icon/${zumaBuffCfg.icon}`, node, 'icon') } //网络事件======================================= onStageEndRsp(data: adventureEndRsp, rewardsNty: IRewardNty) { let result: IGameResult = { isWin: this.isWin, startTime: this.fightCore.startTime, rewardsNty, } if (Data.game.gameType == GAME_TYPE.normal && this.isWin) { Data.user.adventureId = Data.game.stageID + 1 } this.showGameResult(result) } //触发事件======================================= // @render // showRender() {} // 点击事件======================================= onBackClick() { this.hide() Mgr.ui.show(UI.MainUI) } onPauseClick() { this.fightCore.isStop = true this.pausePop.active = true //防止暂停UI多语言没有切换 // this.scheduleOnce(() => { // cc.director.pause() // }) } onContinueClick() { this.fightCore.isStop = false //cc.director.resume() this.pausePop.active = false } onQuitClick() { //cc.director.resume() this.pausePop.active = false Mgr.event.removeAll(this) this.endGame(false) Mgr.game.exitGame() } }