2024-04-19 03:49:41 -07:00
|
|
|
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() {
|
2024-04-23 19:17:24 -07:00
|
|
|
// this.changeState(EGAME_STATE.PLAY);
|
2024-04-19 03:49:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
changeState(state: EGAME_STATE) {
|
|
|
|
GameGlobalData.Instance.changeState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
getHero(): HeroBase {
|
|
|
|
return this.hero;
|
|
|
|
}
|
|
|
|
|
2024-04-23 19:17:24 -07:00
|
|
|
checkWinAfterKilledEnemy(enemy: string, expCollect: number)
|
2024-04-19 03:49:41 -07:00
|
|
|
{
|
2024-04-23 19:17:24 -07:00
|
|
|
UmLog.warn("checkWinAfterKilledEnemy => ", enemy, expCollect);
|
|
|
|
|
|
|
|
if (!Number.isNaN(expCollect))
|
|
|
|
{
|
|
|
|
|
|
|
|
GameGlobalData.Instance.expCollected += expCollect;
|
|
|
|
LayoutManager.instance.GameUI.updateExpProgressBar(GameGlobalData.Instance.expCollected);
|
|
|
|
}
|
|
|
|
|
2024-04-19 03:49:41 -07:00
|
|
|
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) {
|
2024-04-23 19:17:24 -07:00
|
|
|
GameGlobalData.Instance.changeState(EGAME_STATE.FINISH);
|
|
|
|
setTimeout(() => {
|
|
|
|
LayoutManager.instance.GameUI.showGameWin(this.getRewardData());
|
|
|
|
}, 2000);
|
2024-04-19 03:49:41 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UmClientEvent.dispatchEvent(GameDefine.EVENT_INIT_MAP, GameDefine.ENEMY_BOSS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-23 19:17:24 -07:00
|
|
|
|
|
|
|
getRewardData()
|
|
|
|
{
|
|
|
|
var levelDataConfig = GameGlobalData.Instance.getLevelDesignConfigData();
|
|
|
|
return { exp: GameGlobalData.Instance.expCollected, gold: levelDataConfig.goldcollect, reward: levelDataConfig.reward };
|
|
|
|
}
|
2024-04-19 03:49:41 -07:00
|
|
|
}
|
|
|
|
|