import { _decorator, Component, Node } from 'cc'; import { EGAME_STATE, GameDefine } from '../config/GameDefine'; import { GameGlobalData } from '../global/GameGlobalData'; import { HeroBase } from './hero/HeroBase'; import { UmLog } from '../../../cc-common/cc-util/UmLog'; import { LayoutManager } from './LayoutManager'; import { UmClientEvent } from '../../../cc-common/cc-util/UmOneToMultiListener'; const { ccclass, property } = _decorator; @ccclass('GamePlayManager') export class GamePlayManager extends Component { hero: HeroBase = null!; protected onLoad(): void { UmClientEvent.on(GameDefine.EVENT_CHECK_WIN, this.checkWinAfterKilledEnemy.bind(this)); } protected onDestroy(): void { UmClientEvent.off(GameDefine.EVENT_CHECK_WIN, this.checkWinAfterKilledEnemy.bind(this)); } start() { // this.changeState(EGAME_STATE.PLAY); } changeState(state: EGAME_STATE) { GameGlobalData.Instance.changeState(state); } getHero(): HeroBase { return this.hero; } checkWinAfterKilledEnemy(enemy: string, expCollect: number) { UmLog.warn("checkWinAfterKilledEnemy => ", enemy, expCollect); if (!Number.isNaN(expCollect)) { GameGlobalData.Instance.expCollected += expCollect; LayoutManager.instance.GameUI.updateExpProgressBar(GameGlobalData.Instance.expCollected); LayoutManager.instance.GameUI.checkLevelUp(); } var killedData = GameGlobalData.Instance.killedData; if (enemy == GameDefine.ENEMY_CREEP) killedData.creep++; else killedData.boss++; GameGlobalData.Instance.killedData = killedData; var stageData = GameGlobalData.Instance.gameDataConfig.stageInfo; if (killedData.creep >= stageData.creep) { // UmLog.log("checkWinAfterKilledEnemy => ", "CHECK BOSS");s if (killedData.boss >= stageData.boss) { GameGlobalData.Instance.killedData = killedData = { creep: 0, boss: 0 }; UmClientEvent.dispatchEvent(GameDefine.EVENT_INIT_MAP, GameDefine.ENEMY_CREEP); } else { UmClientEvent.dispatchEvent(GameDefine.EVENT_INIT_MAP, GameDefine.ENEMY_BOSS); } } } getRewardData() { var levelDataConfig = GameGlobalData.Instance.getLevelDesignConfigData(); return { exp: GameGlobalData.Instance.expCollected, gold: levelDataConfig.goldcollect, reward: levelDataConfig.reward }; } }