223 lines
8.1 KiB
TypeScript
223 lines
8.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 { MonSet } from "../common/config/heroSet";
|
||
import { smc } from "../common/SingletonModuleComp";
|
||
import { GameEvent } from "../common/config/GameEvent";
|
||
// 导入肉鸽配置
|
||
import {
|
||
generateStageConfig,
|
||
getStageMonsterConfigs,
|
||
getStageAllMultipliers,
|
||
MonsterType,
|
||
StageType,
|
||
getStageType
|
||
} from "./RogueConfig";
|
||
import { MonModelComp } from "../hero/MonModelComp";
|
||
|
||
const { ccclass, property } = _decorator;
|
||
|
||
/** 视图层对象 */
|
||
@ccclass('MissionMonCompComp')
|
||
@ecs.register('MissionMonComp', false)
|
||
export class MissionMonCompComp extends CCComp { // 添加刷怪队列 - 使用新的RogueConfig格式
|
||
private monsterQueue: Array<{
|
||
uuid: number,
|
||
position: number,
|
||
type: MonsterType,
|
||
level: number,
|
||
enhancement?: any, // 增强属性配置
|
||
stageMultipliers?: any // 关卡倍数配置
|
||
}> = [];
|
||
private isSpawning: boolean = false;// 是否正在生成怪物
|
||
private spawnInterval: number = 0.1; // 每个怪物生成间隔时间
|
||
private spawnTimer: number = 0; // 生成计时器
|
||
private spawnCount: number = 0; // 召唤计数器
|
||
private pauseInterval: number = 5.0; // 暂停间隔时间(5秒)
|
||
private isPausing: boolean = false; // 是否正在暂停
|
||
|
||
|
||
onLoad(){
|
||
this.on(GameEvent.FightReady,this.fight_ready,this)
|
||
this.on(GameEvent.NewWave,this.fight_ready,this)
|
||
|
||
}
|
||
/** 视图层逻辑代码分离演示 */
|
||
start() {
|
||
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
|
||
// this.on(ModuleEvent.Cmd, this.onHandler, this);
|
||
}
|
||
|
||
fight_ready(){
|
||
// console.log("[MissionMonComp]:fight_ready")
|
||
smc.vmdata.mission_data.mon_num=0
|
||
this.do_mon_wave()
|
||
}
|
||
|
||
|
||
protected update(dt: number): void {
|
||
if(!smc.mission.play||smc.mission.pause) return
|
||
|
||
// 处理刷怪队列
|
||
if (this.monsterQueue.length > 0 && !this.isSpawning) {
|
||
this.spawnTimer += dt;
|
||
|
||
// 检查是否需要暂停(每召唤5次后暂停5秒)
|
||
if (this.isPausing) {
|
||
if (this.spawnTimer >= this.pauseInterval) {
|
||
// 暂停结束,重置状态
|
||
this.isPausing = false;
|
||
this.spawnCount = 0;
|
||
this.spawnTimer = 0;
|
||
// console.log("[MissionMonComp]: 暂停结束,继续召唤怪物");
|
||
}
|
||
return; // 暂停期间不召唤怪物
|
||
}
|
||
|
||
// 正常召唤间隔
|
||
if (this.spawnTimer >= this.spawnInterval) {
|
||
this.spawnNextMonster();
|
||
this.spawnTimer = 0;
|
||
|
||
// 检查是否需要进入暂停状态
|
||
if (this.spawnCount >= 5) {
|
||
this.isPausing = true;
|
||
this.spawnTimer = 0; // 重置计时器用于暂停计时
|
||
// console.log("[MissionMonComp]: 已召唤5只怪物,开始暂停5秒");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
do_mon_wave(){
|
||
// 重置召唤相关状态
|
||
this.spawnCount = 0;
|
||
this.isPausing = false;
|
||
this.spawnTimer = 0;
|
||
|
||
const currentStage = smc.data.mission;
|
||
// 使用新的肉鸽关卡配置
|
||
let level=smc.vmdata.mission_data.level
|
||
const stageType = getStageType(currentStage,level);
|
||
const monsterConfigs = getStageMonsterConfigs(currentStage,level);
|
||
// console.log(`[MissionMonComp]:第${currentStage}关 - ${stageType}类型,怪物数量: ${monsterConfigs.length}`);
|
||
this.generateMonstersFromStageConfig(monsterConfigs);
|
||
}
|
||
|
||
|
||
// 根据新的关卡配置生成怪物
|
||
private generateMonstersFromStageConfig(monsterConfigs: any[]) {
|
||
const currentStage = smc.data.mission;
|
||
|
||
// 设置怪物总数
|
||
// console.log("[MissionMonComp] generateMonstersFromStageConfig",monsterConfigs)
|
||
if (!monsterConfigs || monsterConfigs.length === 0) {
|
||
console.warn(`[MissionMonComp]:关卡${currentStage}配置中没有怪物信息`);
|
||
return;
|
||
}
|
||
|
||
// 为每个怪物配置生成怪物
|
||
monsterConfigs.forEach((monsterConfig: any, index: number) => {
|
||
const { uuid, type, enhancement, stageMultipliers } = monsterConfig;
|
||
|
||
// 位置循环使用 (0-4)
|
||
const position = index % 5;
|
||
|
||
this.addToStageSpawnQueue(
|
||
uuid,
|
||
position,
|
||
type,
|
||
1, // 默认等级1
|
||
enhancement,
|
||
stageMultipliers
|
||
);
|
||
});
|
||
|
||
// console.log(`[MissionMonComp]:关卡${currentStage}将生成 ${monsterConfigs.length} 只怪物`);
|
||
|
||
// 输出增强属性信息
|
||
monsterConfigs.forEach((monsterConfig: any) => {
|
||
if (monsterConfig.enhancement && monsterConfig.enhancement.buffList.length > 0) {
|
||
// console.log(`[MissionMonComp]:怪物 ${monsterConfig.uuid} (${monsterConfig.type}) 拥有增强属性:`,
|
||
// monsterConfig.enhancement.buffList.map((buff: any) => `${buff.name}:+${buff.value}`));
|
||
}
|
||
});
|
||
}
|
||
|
||
// 添加到关卡刷怪队列 - 使用新的配置格式
|
||
private addToStageSpawnQueue(
|
||
uuid: number,
|
||
position: number,
|
||
type: MonsterType,
|
||
level: number = 1,
|
||
enhancement?: any,
|
||
stageMultipliers?: any
|
||
) {
|
||
this.monsterQueue.push({
|
||
uuid: uuid,
|
||
position: position,
|
||
type: type,
|
||
level: level,
|
||
enhancement: enhancement,
|
||
stageMultipliers: stageMultipliers
|
||
});
|
||
}
|
||
|
||
// 从队列中生成下一个怪物 - 使用新的配置格式
|
||
private spawnNextMonster() {
|
||
if (this.monsterQueue.length === 0) return;
|
||
|
||
const monsterData = this.monsterQueue.shift();
|
||
if (monsterData) {
|
||
const isBoss = monsterData.type === MonsterType.BOSS;
|
||
|
||
this.addMonster(
|
||
monsterData.uuid,
|
||
monsterData.position,
|
||
isBoss,
|
||
false,
|
||
monsterData.level,
|
||
monsterData.enhancement,
|
||
monsterData.stageMultipliers
|
||
);
|
||
|
||
// 增加召唤计数
|
||
this.spawnCount++;
|
||
// console.log(`[MissionMonComp]: 召唤第${this.spawnCount}只${monsterData.type}怪物,剩余队列: ${this.monsterQueue.length}`);
|
||
}
|
||
}
|
||
|
||
private addMonster(
|
||
uuid: number = 1001,
|
||
i: number = 0,
|
||
is_boss: boolean = false,
|
||
is_call: boolean = false,
|
||
lv: number = 1,
|
||
enhancement?: any,
|
||
stageMultipliers?: any
|
||
) {
|
||
let mon = ecs.getEntity<Monster>(Monster);
|
||
let scale = -1;
|
||
let pos: Vec3 = v3(MonSet[i].pos);
|
||
|
||
// 生成怪物,传递增强属性和关卡倍数
|
||
mon.load(pos,scale,uuid,is_boss,is_call,enhancement, stageMultipliers);
|
||
|
||
// 如果有增强属性,记录到控制台
|
||
if (enhancement && enhancement.buffList && enhancement.buffList.length > 0) {
|
||
// console.log(`[MissionMonComp]: 怪物 ${uuid} 获得增强属性:`,
|
||
// enhancement.buffList.map((buff: any) => `${buff.name}:+${buff.value}`));
|
||
}
|
||
|
||
// 如果有关卡倍数,记录到控制台
|
||
if (stageMultipliers) {
|
||
// console.log(`[MissionMonComp]: 怪物 ${uuid} 关卡倍数 - HP: x${stageMultipliers.hp.toFixed(2)}, 攻击: x${stageMultipliers.attack.toFixed(2)}`);
|
||
}
|
||
}
|
||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||
reset() {
|
||
// this.node.destroy();
|
||
}
|
||
} |