88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
import { _decorator, v3, Vec3 } from "cc";
|
|
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
|
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
|
|
import { Monster } from "../hero/Mon";
|
|
import { BoxSet } from "../common/config/BoxSet";
|
|
import { HeroSet, MonSet } from "../common/config/heroSet";
|
|
import { Missions } from "../common/config/MissionSet";
|
|
import { RandomManager } from "db://oops-framework/core/common/random/RandomManager";
|
|
import { Timer } from "db://oops-framework/core/common/timer/Timer";
|
|
import { smc } from "../common/SingletonModuleComp";
|
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
/** 视图层对象 */
|
|
@ccclass('MissionMonCompComp')
|
|
@ecs.register('MissionMonComp', false)
|
|
export class MissionMonCompComp extends CCComp {
|
|
timer:Timer=new Timer(10)
|
|
// 添加刷怪队列
|
|
private monsterQueue: Array<{uuid: number, position: number, isBoss: boolean}> = [];
|
|
private isSpawning: boolean = false;
|
|
private spawnInterval: number = 0.5; // 每个怪物生成间隔时间
|
|
private spawnTimer: number = 0;
|
|
|
|
/** 视图层逻辑代码分离演示 */
|
|
start() {
|
|
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
|
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
|
// this.test_call()
|
|
}
|
|
protected update(dt: number): void {
|
|
if(!smc.mission.play||smc.mission.pause) return
|
|
if(this.timer.update(dt)){
|
|
this.mon_refresh()
|
|
}
|
|
|
|
// 处理刷怪队列
|
|
if (this.monsterQueue.length > 0 && !this.isSpawning) {
|
|
this.spawnTimer += dt;
|
|
if (this.spawnTimer >= this.spawnInterval) {
|
|
this.spawnNextMonster();
|
|
this.spawnTimer = 0;
|
|
}
|
|
}
|
|
}
|
|
test_call(){
|
|
this.addToSpawnQueue(5202, 0, true);
|
|
}
|
|
|
|
|
|
mon_refresh(){
|
|
let positions = [0, 1, 2, 3];
|
|
positions.forEach(pos => {
|
|
let x = RandomManager.instance.getRandomInt(0, Missions[0].length, 1);
|
|
this.addToSpawnQueue(Missions[0][x], pos, false);
|
|
});
|
|
}
|
|
|
|
// 新增:添加到刷怪队列
|
|
private addToSpawnQueue(uuid: number, position: number, isBoss: boolean = false) {
|
|
this.monsterQueue.push({
|
|
uuid: uuid,
|
|
position: position,
|
|
isBoss: isBoss
|
|
});
|
|
}
|
|
|
|
// 新增:从队列中生成下一个怪物
|
|
private spawnNextMonster() {
|
|
if (this.monsterQueue.length === 0) return;
|
|
|
|
const monsterData = this.monsterQueue.shift();
|
|
if (monsterData) {
|
|
this.addMonster(monsterData.uuid, monsterData.position, monsterData.isBoss);
|
|
}
|
|
}
|
|
|
|
private addMonster(uuid:number=1001,i:number=0,is_boss:boolean=false) {
|
|
let mon = ecs.getEntity<Monster>(Monster);
|
|
let scale = -1
|
|
let pos:Vec3 = v3(MonSet[i].pos);
|
|
mon.load(pos,scale,uuid,is_boss);
|
|
}
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
// this.node.destroy();
|
|
}
|
|
} |