super-hero/assets/cc-game/scripts/game_play/map/MapManager.ts

157 lines
5.1 KiB
TypeScript
Raw Normal View History

2024-04-19 03:49:41 -07:00
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()
{
2024-04-23 19:17:24 -07:00
GameGlobalData.Instance.prepareDataOnStartNewStage();
2024-04-19 03:49:41 -07:00
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;
}
2024-05-08 02:31:19 -07:00
bossIndex = 0;
getBossIndex()
{
return 2;
this.bossIndex++;
this.bossIndex = Math.min(2, this.bossIndex);
this.bossIndex = Math.max(1, this.bossIndex);
}
2024-04-19 03:49:41 -07:00
private initBoss() {
2024-05-08 02:31:19 -07:00
var bossIndex = `B${this.getBossIndex()}`;
var boss = instantiate(GameAssets.instance.getBossPrefabById(bossIndex));
2024-04-19 03:49:41 -07:00
boss.parent = this.gameplaySpaceLayout;
2024-04-22 01:32:16 -07:00
2024-05-08 02:31:19 -07:00
var data = GameGlobalData.Instance.getBossDataConfigAfterRaitoById(bossIndex);
2024-04-19 03:49:41 -07:00
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;
2024-04-22 01:32:16 -07:00
var count = 1;
2024-04-19 03:49:41 -07:00
{
var creep = instantiate(GameAssets.instance.creepPrefab);
creep.parent = this.gameplaySpaceLayout;
2024-04-22 01:32:16 -07:00
// var data = { enemyType: 0, attackType: 0, hp: 75, dmg: 20 };
2024-04-23 19:17:24 -07:00
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(1,3)}`);
2024-04-19 03:49:41 -07:00
creep.getComponent(CreepBase)?.setEnemyData(data);
2024-04-22 01:32:16 -07:00
creep.name = data.Name_Id + "_" + (count++).toString();
2024-04-19 03:49:41 -07:00
creep.position = new Vec3(-233, 104, 0);
}
{
var creep = instantiate(GameAssets.instance.creepPrefab);
creep.parent = this.gameplaySpaceLayout;
2024-04-22 01:32:16 -07:00
// var data = { enemyType: 1, attackType: 1, hp: 50, dmg: 5 };
2024-04-23 19:17:24 -07:00
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(4, 6)}`);
2024-04-19 03:49:41 -07:00
creep.getComponent(CreepBase)?.setEnemyData(data);
creep.position = new Vec3(290, 310, 0);
2024-04-22 01:32:16 -07:00
creep.name = data.Name_Id + "_" + (count++).toString();
2024-04-19 03:49:41 -07:00
}
{
var creep = instantiate(GameAssets.instance.creepPrefab);
creep.parent = this.gameplaySpaceLayout;
2024-04-22 01:32:16 -07:00
// var data = { enemyType: 0, attackType: 0, hp: 75, dmg: 20 };
2024-04-23 19:17:24 -07:00
var data = GameGlobalData.Instance.getEnemyDataConfigAfterRatioById(`E${UmUtil.getRandomInt(1, 3)}`);
2024-04-19 03:49:41 -07:00
creep.getComponent(CreepBase)?.setEnemyData(data);
creep.position = new Vec3(-211, 480, 0);
2024-04-22 01:32:16 -07:00
creep.name = data.Name_Id + "_" + (count++).toString();
2024-04-19 03:49:41 -07:00
}
}
get StageInfo(): StageInfo
{
if (this.stageInfo)
return this.stageInfo;
return { stageId: 1, stageName: "Stage 1" };
}
}