import { _decorator, v3, Vec3 } from "cc"; import { mLogger } from "../common/Logger"; 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 { MonStart } from "../common/config/heroSet"; import { smc } from "../common/SingletonModuleComp"; import { GameEvent } from "../common/config/GameEvent"; // 导入新的肉鸽配置 import { BuffConf } from "../common/config/SkillSet"; import {BoxSet } from "../common/config/GameSet"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('MissionMonCompComp') @ecs.register('MissionMonComp', false) export class MissionMonCompComp extends CCComp { @property({ tooltip: "是否启用调试日志" }) private debugMode: boolean = false; // 刷怪队列 (主要用于特殊事件插队) private MonQueue: Array<{ uuid: number, level: number, }> = []; private spawnCount: number = 0; // 召唤计数器 /** 全局生成顺序计数器,用于层级管理 */ private globalSpawnOrder: number = 0; /** 游戏进行时间(秒) */ private gameTime: number = 0; /** 波次刷怪计时器 */ private waveTimer: number = 0; /** 队列处理计时器 */ private queueTimer: number = 0; onLoad(){ this.on(GameEvent.FightReady,this.fight_ready,this) this.on(GameEvent.NewWave,this.fight_ready,this) // 监听特殊刷怪事件 (精英/Boss) this.on("SpawnSpecialMonster", this.onSpawnSpecialMonster, this); } /** * 处理特殊刷怪事件 * @param event 事件名 * @param args 参数 { uuid, type, level, position?, buffs? } */ private onSpawnSpecialMonster(event: string, args: any) { if (!args) return; mLogger.log(this.debugMode, 'MissionMonComp', `[MissionMonComp] 收到特殊刷怪指令:`, args); // 插入队列 this.MonQueue.push({ uuid: args.uuid, level: args.level, }); // 立即触发一次队列检查 (可选,让 update 尽快处理) this.queueTimer = 1.0; } start() { } fight_ready(){ smc.vmdata.mission_data.mon_num=0 // 重置生成顺序计数器 this.globalSpawnOrder = 0 this.gameTime = 0 this.waveTimer = 0 this.queueTimer = 0 this.MonQueue = [] this.spawnCount = 0 mLogger.log(this.debugMode, 'MissionMonComp', "[MissionMonComp] Starting Wave System (15-min Cycle)"); } protected update(dt: number): void { if(!smc.mission.play) return if(smc.mission.pause) return // 如果英雄死亡(停止怪物行动标志为true),则停止刷怪逻辑 if(smc.mission.stop_mon_action) return; // 累加游戏时间 this.gameTime += dt; } private addMonster( uuid: number = 1001, i: number = 0, ) { let mon = ecs.getEntity(Monster); let scale = -1; const x = MonStart.START_X + Math.floor(i / 4) * MonStart.START_I; let y = BoxSet.GAME_LINE; let pos: Vec3 = v3(x, y, 0); // 递增全局生成顺序 - 溢出保护 this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999; // 生成怪物 mon.load(pos, scale, uuid, false); } /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */ reset() { // this.node.destroy(); } }