209 lines
7.7 KiB
TypeScript
209 lines
7.7 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 { FightSet } from "../common/config/Mission";
|
||
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";
|
||
import { GameEvent } from "../common/config/GameEvent";
|
||
import { oops } from "db://oops-framework/core/Oops";
|
||
// 导入肉鸽配置
|
||
import { getRogueWaveConfig, RogueConfig, RogueWaveType, AffixCountConfig, MonsterAffixConfig } from "./RogueConfig";
|
||
|
||
const { ccclass, property } = _decorator;
|
||
|
||
/** 视图层对象 */
|
||
@ccclass('MissionMonCompComp')
|
||
@ecs.register('MissionMonComp', false)
|
||
export class MissionMonCompComp extends CCComp {
|
||
timer:Timer=new Timer(1)
|
||
// 添加刷怪队列 - 扩展支持词条
|
||
private monsterQueue: Array<{
|
||
uuid: number,
|
||
position: number,
|
||
isBoss: boolean,
|
||
level: number,
|
||
affixes?: any[],
|
||
buffData?: any[] // 使用BuffAttr格式的buff数据
|
||
}> = [];
|
||
private isSpawning: boolean = false;// 是否正在生成怪物
|
||
private spawnInterval: number = 1; // 每个怪物生成间隔时间
|
||
private spawnTimer: number = 0; // 生成计时器
|
||
private is_fight:boolean = false;
|
||
|
||
|
||
onLoad(){
|
||
this.on(GameEvent.FightStart,this.to_fight,this)
|
||
}
|
||
/** 视图层逻辑代码分离演示 */
|
||
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.is_fight) {
|
||
if(this.timer.update(dt)){
|
||
this.do_mon_wave()
|
||
}
|
||
}
|
||
// 处理刷怪队列
|
||
if (this.monsterQueue.length > 0 && !this.isSpawning) {
|
||
this.spawnTimer += dt;
|
||
if (this.spawnTimer >= this.spawnInterval) {
|
||
this.spawnNextMonster();
|
||
this.spawnTimer = 0;
|
||
}
|
||
}
|
||
}
|
||
to_fight(){
|
||
console.log("[MissionMonComp]:to_fight")
|
||
this.is_fight=true
|
||
this.do_mon_wave()
|
||
this.timer=new Timer(FightSet.MON_WAVE_TIME)
|
||
}
|
||
test_call(){
|
||
this.addToSpawnQueue(5202, 0, true, 1);
|
||
}
|
||
|
||
do_mon_wave(){
|
||
oops.message.dispatchEvent(GameEvent.WaveUpdate)
|
||
console.log("[MissionMonComp]:怪物登场,当前波次 :",smc.vmdata.mission_data.current_wave)
|
||
const currentWave = smc.vmdata.mission_data.current_wave;
|
||
// 使用肉鸽模式配置
|
||
const rogueWaveConfig = getRogueWaveConfig(currentWave);
|
||
console.log(`[MissionMonComp]:肉鸽模式第${currentWave}波配置:`, rogueWaveConfig.description);
|
||
this.generateRogueMonstersFromConfig(rogueWaveConfig);
|
||
}
|
||
|
||
|
||
// 根据肉鸽配置生成怪物(肉鸽模式)
|
||
private generateRogueMonstersFromConfig(rogueWaveConfig: any) {
|
||
const { monsters, waveType } = rogueWaveConfig;
|
||
const currentWave = smc.vmdata.mission_data.current_wave;
|
||
const monsterLevel = RogueConfig.getMonsterLevel(currentWave);
|
||
|
||
// 处理非战斗波次
|
||
if (waveType === RogueWaveType.SHOP || waveType === RogueWaveType.REST) {
|
||
console.log(`[MissionMonComp]:${waveType}波次,无需生成怪物`);
|
||
// 可以在这里触发商店或休息事件
|
||
return;
|
||
}
|
||
|
||
if (!monsters || monsters.length === 0) {
|
||
console.warn(`[MissionMonComp]:肉鸽波次配置中没有怪物信息`);
|
||
return;
|
||
}
|
||
|
||
monsters.forEach((monsterGroup: any) => {
|
||
const { uuid, count, affixes, enhancedStats, buffData, isBoss } = monsterGroup;
|
||
|
||
// 为每个怪物组生成指定数量的怪物
|
||
for (let i = 0; i < count; i++) {
|
||
// 随机选择位置 (0-9)
|
||
let x=i%3 //0 1 2
|
||
this.addToSpawnQueueWithAffixes(
|
||
uuid,
|
||
x,
|
||
isBoss || false,
|
||
monsterLevel,
|
||
affixes,
|
||
buffData // 现在传递buffData而不是enhancedStats和specialEffects
|
||
);
|
||
}
|
||
});
|
||
|
||
const totalMonsters = monsters.reduce((total: number, group: any) => total + group.count, 0);
|
||
console.log(`[MissionMonComp]:肉鸽模式本波次将生成 ${totalMonsters} 只怪物,等级: ${monsterLevel}`);
|
||
|
||
// 输出词条信息
|
||
monsters.forEach((monsterGroup: any) => {
|
||
if (monsterGroup.buffData && monsterGroup.buffData.length > 0) {
|
||
console.log(`[MissionMonComp]:怪物 ${monsterGroup.uuid} 拥有词条:`, monsterGroup.buffData);
|
||
// 输出词条名称
|
||
monsterGroup.buffData.forEach((buff: any) => {
|
||
const config = MonsterAffixConfig[buff.buff_type];
|
||
if (config) {
|
||
console.log(`[MissionMonComp]: - ${config.name}: ${config.description}`);
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
// 新增:添加到刷怪队列 - 增加level参数(普通模式)
|
||
private addToSpawnQueue(uuid: number, position: number, isBoss: boolean = false, level: number = 1) {
|
||
this.monsterQueue.push({
|
||
uuid: uuid,
|
||
position: position,
|
||
isBoss: isBoss,
|
||
level: level
|
||
});
|
||
}
|
||
|
||
// 新增:添加到刷怪队列 - 支持词条(肉鸽模式)
|
||
private addToSpawnQueueWithAffixes(
|
||
uuid: number,
|
||
position: number,
|
||
isBoss: boolean = false,
|
||
level: number = 1,
|
||
affixes?: any[],
|
||
buffData?: any[]
|
||
) {
|
||
this.monsterQueue.push({
|
||
uuid: uuid,
|
||
position: position,
|
||
isBoss: isBoss,
|
||
level: level,
|
||
affixes: affixes,
|
||
buffData: buffData
|
||
});
|
||
}
|
||
|
||
// 新增:从队列中生成下一个怪物 - 传递词条参数
|
||
private spawnNextMonster() {
|
||
if (this.monsterQueue.length === 0) return;
|
||
|
||
const monsterData = this.monsterQueue.shift();
|
||
if (monsterData) {
|
||
this.addMonster(
|
||
monsterData.uuid,
|
||
monsterData.position,
|
||
monsterData.isBoss,
|
||
false,
|
||
monsterData.level,
|
||
monsterData.buffData
|
||
);
|
||
}
|
||
}
|
||
|
||
private addMonster(
|
||
uuid: number = 1001,
|
||
i: number = 0,
|
||
is_boss: boolean = false,
|
||
is_call: boolean = false,
|
||
lv: number = 1,
|
||
buffData?: any[]
|
||
) {
|
||
let x=RandomManager.instance.getRandomInt(0,2)
|
||
let mon = ecs.getEntity<Monster>(Monster);
|
||
let scale = -1;
|
||
let pos: Vec3 = v3(MonSet[x].pos);
|
||
|
||
// 生成怪物,传递词条buff数据
|
||
mon.load(pos, scale, uuid, is_boss, is_call, lv, buffData);
|
||
|
||
// 如果有词条buff数据,记录到控制台
|
||
if (buffData && buffData.length > 0) {
|
||
console.log(`[MissionMonComp]: 怪物 ${uuid} 获得肉鸽词条Buff:`, buffData);
|
||
}
|
||
}
|
||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||
reset() {
|
||
// this.node.destroy();
|
||
}
|
||
} |