feat(怪物系统): 重构怪物生成逻辑并添加多种怪物类型

重构怪物生成系统,使用MonType枚举替代原有布尔标记
添加6种怪物类型配置和属性计算规则
修改关卡配置生成逻辑,支持精英/Boss波次
新增多种怪物配置并调整原有怪物属性
This commit is contained in:
2025-10-29 16:41:08 +08:00
parent 68b9c1924b
commit 9dc1126dfe
4 changed files with 161 additions and 215 deletions

View File

@@ -6,11 +6,9 @@ import { MonSet } from "../common/config/heroSet";
import { smc } from "../common/SingletonModuleComp";
import { GameEvent } from "../common/config/GameEvent";
// 导入肉鸽配置
import {
MonsterType,
EventType,
} from "./RogueConfig";
import { MonType, EventType, getStageMonConfigs} from "./RogueConfig";
import { MonModelComp } from "../hero/MonModelComp";
import { BuffConf } from "../common/config/SkillSet";
const { ccclass, property } = _decorator;
@@ -19,12 +17,12 @@ const { ccclass, property } = _decorator;
@ecs.register('MissionMonComp', false)
export class MissionMonCompComp extends CCComp {
// 添加刷怪队列 - 使用新的RogueConfig格式
private monsterQueue: Array<{
private MonQueue: Array<{
uuid: number,
position: number,
type: MonsterType,
type: MonType
level: number,
strengthMultiplier: number
buffs: BuffConf[]
}> = [];
private isSpawning: boolean = false;// 是否正在生成怪物
private spawnInterval: number = 0.1; // 每个怪物生成间隔时间
@@ -58,12 +56,12 @@ export class MissionMonCompComp extends CCComp {
// 处理随机事件
if (this.currentEvent && !this.eventProcessed) {
this.processRandomEvent();
this.eventProcessed = true;
}
// 处理刷怪队列
if (this.monsterQueue.length > 0 && !this.isSpawning) {
if (this.MonQueue.length > 0 && !this.isSpawning) {
this.spawnTimer += dt;
// 检查是否需要暂停每召唤5次后暂停5秒
@@ -100,64 +98,31 @@ export class MissionMonCompComp extends CCComp {
this.spawnTimer = 0;
this.eventProcessed = false;
const currentStage = smc.data.mission;
const cStage = smc.data.mission;
// 使用新的肉鸽关卡配置
let level=smc.vmdata.mission_data.level
const stageType = getStageType(currentStage,level);
// 检查是否为事件关卡
if (stageType === "event") {
this.currentEvent = getRandomEvent();
} else {
this.currentEvent = null;
}
const monsterConfigs = getStageMonsterConfigs(currentStage,level);
// console.log(`[MissionMonComp]:第${currentStage}关 - ${stageType}类型,怪物数量: ${monsterConfigs.length}`);
this.generateMonstersFromStageConfig(monsterConfigs);
const monsConf = getStageMonConfigs(cStage);
// console.log(`[MissionMonComp]:第${cStage}关 - ${stageType}类型,怪物数量: ${monsConf.length}`);
this.generateMonsters(monsConf);
}
// 处理随机事件
private processRandomEvent() {
if (!this.currentEvent) return;
switch (this.currentEvent) {
case EventType.TREASURE:
// 发送获得奖励事件
smc.vmdata.mission_data.gold += 50; // 增加50金币
// 可以触发UI提示
// oops.message.dispatchEvent("event_treasure");
break;
case EventType.TRAP:
// 对玩家造成伤害
// 这里可以实现对玩家英雄造成伤害的逻辑
// oops.message.dispatchEvent("event_trap");
break;
case EventType.BUFF:
// 给玩家增加临时增益效果
// oops.message.dispatchEvent("event_buff");
break;
case EventType.DEBUFF:
// 给玩家增加临时减益效果
// oops.message.dispatchEvent("event_debuff");
break;
}
}
// 根据新的关卡配置生成怪物
private generateMonstersFromStageConfig(monsterConfigs: any[]) {
const currentStage = smc.data.mission;
private generateMonsters(monsConf: any[]) {
const cStage = smc.data.mission;
// 设置怪物总数
// console.log("[MissionMonComp] generateMonstersFromStageConfig",monsterConfigs)
if (!monsterConfigs || monsterConfigs.length === 0) {
console.warn(`[MissionMonComp]:关卡${currentStage}配置中没有怪物信息`);
// console.log("[MissionMonComp] generateMonsters",monsConf)
if (!monsConf || monsConf.length === 0) {
console.warn(`[MissionMonComp]:关卡${cStage}配置中没有怪物信息`);
return;
}
// 为每个怪物配置生成怪物
monsterConfigs.forEach((monsterConfig: any, index: number) => {
const { uuid, type, strengthMultiplier } = monsterConfig;
monsConf.forEach((mon: any, index: number) => {
const { uuid, type,level, buffs } = mon;
// 位置循环使用 (0-4)
const position = index % 5;
@@ -166,70 +131,68 @@ export class MissionMonCompComp extends CCComp {
uuid,
position,
type,
1, // 默认等级1
strengthMultiplier // 强度倍率
level, // 默认等级1
buffs // 强度倍率
);
});
// console.log(`[MissionMonComp]:关卡${currentStage}将生成 ${monsterConfigs.length} 只怪物`);
// console.log(`[MissionMonComp]:关卡${cStage}将生成 ${monsConf.length} 只怪物`);
}
// 添加到关卡刷怪队列 - 使用新的配置格式
private addToStageSpawnQueue(
uuid: number,
position: number,
type: MonsterType,
type: MonType,
level: number = 1,
strengthMultiplier: number = 1.0
buffs: BuffConf[] = []
) {
this.monsterQueue.push({
this.MonQueue.push({
uuid: uuid,
position: position,
type: type,
level: level,
strengthMultiplier: strengthMultiplier
buffs: buffs
});
}
// 从队列中生成下一个怪物 - 使用新的配置格式
private spawnNextMonster() {
if (this.monsterQueue.length === 0) return;
if (this.MonQueue.length === 0) return;
const monsterData = this.monsterQueue.shift();
const monsterData = this.MonQueue.shift();
if (monsterData) {
const isBoss = monsterData.type === MonsterType.BOSS;
this.addMonster(
monsterData.uuid,
monsterData.position,
isBoss,
false,
monsterData.type,
monsterData.level,
monsterData.strengthMultiplier
monsterData.buffs
);
// 增加召唤计数
this.spawnCount++;
// console.log(`[MissionMonComp]: 召唤第${this.spawnCount}只${monsterData.type}怪物,剩余队列: ${this.monsterQueue.length}`);
// console.log(`[MissionMonComp]: 召唤第${this.spawnCount}只${monsterData.type}怪物,剩余队列: ${this.MonQueue.length}`);
}
}
private addMonster(
uuid: number = 1001,
i: number = 0,
is_boss: boolean = false,
is_call: boolean = false,
monType: MonType = MonType.NORMAL,
lv: number = 1,
strengthMultiplier: number = 1.0
buffs: BuffConf[] = []
) {
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,strengthMultiplier);
mon.load(pos,scale,uuid,lv,monType,buffs);
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
// this.node.destroy();