157 lines
5.1 KiB
TypeScript
157 lines
5.1 KiB
TypeScript
import { _decorator, Component, Node } from 'cc';
|
|
import { StageInfo } from '../../global/GameInterface';
|
|
import { Prefab } from 'cc';
|
|
import { instantiate } from 'cc';
|
|
import { GameAssets } from '../../global/GameAssets';
|
|
import { UmClientEvent } from '../../../../cc-common/cc-util/UmOneToMultiListener';
|
|
import { EGAME_STATE, GameDefine } from '../../config/GameDefine';
|
|
import { GameGlobalData } from '../../global/GameGlobalData';
|
|
import { UmUtil } from '../../../../cc-common/cc-util/UmUtil';
|
|
import { HeroBase } from '../hero/HeroBase';
|
|
import { CreepBase } from '../creep/CreepBase';
|
|
import { Vec3 } from 'cc';
|
|
import { UmLog } from '../../../../cc-common/cc-util/UmLog';
|
|
import { EnemyBase } from '../enemy/EnemyBase';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('MapManager')
|
|
export class MapManager extends Component {
|
|
@property(Node) gameplaySpaceLayout: Node = null!;
|
|
@property(Node) environment: Node = null!;
|
|
private stageInfo: StageInfo = null;
|
|
|
|
protected onLoad(): void {
|
|
UmClientEvent.on(GameDefine.EVENT_START_GAME, this.onGameStart.bind(this));
|
|
UmClientEvent.on(GameDefine.EVENT_INIT_MAP, this.initObjectMap.bind(this));
|
|
|
|
this.environment?.setNodeActive(false);
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
UmClientEvent.off(GameDefine.EVENT_START_GAME, this.onGameStart.bind(this));
|
|
}
|
|
|
|
onGameStart()
|
|
{
|
|
GameGlobalData.Instance.prepareDataOnStartNewStage();
|
|
this.initMapAtStartStage();
|
|
}
|
|
|
|
public initMapAtStartStage()
|
|
{
|
|
this.addEnvironment();
|
|
this.initObjectMap(GameDefine.ENEMY_CREEP);
|
|
// this.initObjectMap(GameDefine.ENEMY_BOSS);
|
|
|
|
this.gameplaySpaceLayout?.getComponentInChildren(HeroBase)?.node.setSiblingIndex(Number.MAX_SAFE_INTEGER);
|
|
|
|
UmUtil.delay(this.node, 1, () => {
|
|
GameGlobalData.Instance.changeState(EGAME_STATE.PLAY);
|
|
});
|
|
}
|
|
|
|
public initObjectMap(objectRequest: string)
|
|
{
|
|
UmLog.log("initObjectMap => ", objectRequest);
|
|
if (objectRequest == GameDefine.ENEMY_CREEP)
|
|
{
|
|
this.addCreepEnemy();
|
|
return;
|
|
}
|
|
|
|
if (objectRequest == GameDefine.ENEMY_BOSS) {
|
|
this.initBoss();
|
|
return;
|
|
}
|
|
|
|
if (objectRequest == GameDefine.HERO) {
|
|
this.initHero();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private initHero()
|
|
{
|
|
var hero = instantiate(GameAssets.instance.heroPrefab);
|
|
hero.parent = this.gameplaySpaceLayout;
|
|
}
|
|
|
|
|
|
bossIndex = 0;
|
|
getBossIndex()
|
|
{
|
|
return 2;
|
|
this.bossIndex++;
|
|
this.bossIndex = Math.min(2, this.bossIndex);
|
|
this.bossIndex = Math.max(1, this.bossIndex);
|
|
}
|
|
|
|
private initBoss() {
|
|
var bossIndex = `B${this.getBossIndex()}`;
|
|
var boss = instantiate(GameAssets.instance.getBossPrefabById(bossIndex));
|
|
boss.parent = this.gameplaySpaceLayout;
|
|
|
|
var data = GameGlobalData.Instance.getBossDataConfigAfterRaitoById(bossIndex);
|
|
boss.getComponent(EnemyBase)?.setEnemyData(data);
|
|
}
|
|
|
|
private addEnvironment()
|
|
{
|
|
this.environment?.setNodeActive(true);
|
|
}
|
|
|
|
private addCreepEnemy() {
|
|
|
|
// this.enemyType = data?.enemyType || this.enemyType;
|
|
// this.attackType = data?.attackType || this.attackType;
|
|
|
|
// this.dmg = data?.dmg || this.dmg;
|
|
// this.moveSpeed = data?.moveSpeed || this.moveSpeed;
|
|
// this.range = data?.range || this.range;
|
|
var count = 1;
|
|
|
|
{
|
|
var creep = instantiate(GameAssets.instance.creepPrefab);
|
|
creep.parent = this.gameplaySpaceLayout;
|
|
// var data = { enemyType: 0, attackType: 0, hp: 75, dmg: 20 };
|
|
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(1,3)}`);
|
|
creep.getComponent(CreepBase)?.setEnemyData(data);
|
|
creep.name = data.Name_Id + "_" + (count++).toString();
|
|
creep.position = new Vec3(-233, 104, 0);
|
|
}
|
|
|
|
{
|
|
var creep = instantiate(GameAssets.instance.creepPrefab);
|
|
creep.parent = this.gameplaySpaceLayout;
|
|
// var data = { enemyType: 1, attackType: 1, hp: 50, dmg: 5 };
|
|
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(4, 6)}`);
|
|
creep.getComponent(CreepBase)?.setEnemyData(data);
|
|
creep.position = new Vec3(290, 310, 0);
|
|
creep.name = data.Name_Id + "_" + (count++).toString();
|
|
}
|
|
|
|
{
|
|
var creep = instantiate(GameAssets.instance.creepPrefab);
|
|
creep.parent = this.gameplaySpaceLayout;
|
|
// var data = { enemyType: 0, attackType: 0, hp: 75, dmg: 20 };
|
|
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(1, 3)}`);
|
|
creep.getComponent(CreepBase)?.setEnemyData(data);
|
|
creep.position = new Vec3(-211, 480, 0);
|
|
creep.name = data.Name_Id + "_" + (count++).toString();
|
|
}
|
|
|
|
}
|
|
|
|
get StageInfo(): StageInfo
|
|
{
|
|
if (this.stageInfo)
|
|
return this.stageInfo;
|
|
|
|
|
|
return { stageId: 1, stageName: "Stage 1" };
|
|
}
|
|
|
|
|
|
}
|
|
|