60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
|
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)
|
||
|
{
|
||
|
// UmLog.warn("checkWinAfterKilledEnemy => ", enemy);
|
||
|
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");
|
||
|
if (killedData.boss >= stageData.boss) {
|
||
|
LayoutManager.instance.GameUI.showGameWin();
|
||
|
}
|
||
|
else {
|
||
|
UmClientEvent.dispatchEvent(GameDefine.EVENT_INIT_MAP, GameDefine.ENEMY_BOSS);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|