refactor(missionMon): 扩展为6路刷怪并优化中路判定逻辑

1.  将原3路刷怪扩展为6路,调整刷怪线Y轴偏移配置
2.  优化怪物中路判定,使用常量BoxSet.GAME_LINE替代硬编码30阈值
3.  改进均衡选路逻辑,支持多候选路随机选择
4.  为怪物出生位置增加Y轴随机偏移实现多路线进军
This commit is contained in:
panw
2026-05-21 16:58:29 +08:00
parent 52b24668c7
commit 7c54f58be1
2 changed files with 19 additions and 16 deletions

View File

@@ -561,7 +561,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
}
} else {
// 怪物:优先找中路目标
const isMidLane = Math.abs(view.node.position.y) < 30; // 0 是中路
const isMidLane = Math.abs(view.node.position.y - BoxSet.GAME_LINE) < 30; // BoxSet.GAME_LINE(100) 是中路
if (foundPreferredLane && !isMidLane) return;
@@ -619,7 +619,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
frontEnemy = view;
} else {
// 怪物:优先找中路最前排的
const isMidLane = Math.abs(view.node.position.y) < 30;
const isMidLane = Math.abs(view.node.position.y - BoxSet.GAME_LINE) < 30; // BoxSet.GAME_LINE(100) 是中路
if (foundPreferredLane && !isMidLane) return;

View File

@@ -9,7 +9,7 @@
*
* 关键设计:
* - 突破 5 槽限制,怪物按刷怪顺序依次从 X=280 开始向右(每隔 50排布。
* - 3 条刷怪线:地面、+120、+240
* - 6 条刷怪线:在三路 Y 轴范围内随机偏移,实现 6 路进军
* - resetSlotSpawnData(wave) 在每波开始时读取配置,分配并立即生成所有怪物。
* - 去除跨波 HP 继承,上一波残留怪在波次结束/开始时销毁。
*
@@ -57,8 +57,8 @@ export class MissionMonCompComp extends CCComp {
private static readonly MON_SPAWN_GAP_X = 50;
/** 怪物出生掉落高度 */
private static readonly MON_DROP_HEIGHT = 280;
/** 路高度偏移(上路, 中路, 下路 */
private static readonly LANE_Y_OFFSETS = [100, 0, -100];
/** 6路高度偏移(在三路的y轴范围内实现 6路 进军 */
private static readonly LANE_Y_OFFSETS = [100, 60, 20, -20, -60, -100];
// ======================== 编辑器属性 ========================
@@ -83,7 +83,7 @@ export class MissionMonCompComp extends CCComp {
// ======================== 运行时状态 ========================
/** 记录每条线当前排到的索引 */
private laneIndices: number[] = [0, 0, 0];
private laneIndices: number[] = [0, 0, 0, 0, 0, 0];
/** 全局生成顺序计数器(用于渲染层级排序) */
private globalSpawnOrder: number = 0;
/** 插队刷怪处理计时器 */
@@ -230,7 +230,7 @@ export class MissionMonCompComp extends CCComp {
this.MonQueue = []
this.pendingMonsters = []
this.spawnTimer = 0
this.laneIndices = [0, 0, 0];
this.laneIndices = [0, 0, 0, 0, 0, 0];
// 预生成第一波数据以获取数量和 Boss 信息
const monsters = spawningEngine.generateWave(this.currentWave);
@@ -241,17 +241,19 @@ export class MissionMonCompComp extends CCComp {
// ======================== 插队刷怪 ========================
/** 选取当前排数最少的路(均衡分配) */
/** 选取当前排数最少的路(均衡分配,数量相同时随机选一个 */
private pickBalancedLane(): number {
let min = this.laneIndices[0];
let lane = 0;
for (let i = 1; i < 3; i++) {
let candidates = [0];
for (let i = 1; i < 6; i++) {
if (this.laneIndices[i] < min) {
min = this.laneIndices[i];
lane = i;
candidates = [i];
} else if (this.laneIndices[i] === min) {
candidates.push(i);
}
}
return lane;
return candidates[Math.floor(Math.random() * candidates.length)];
}
/**
@@ -270,7 +272,7 @@ export class MissionMonCompComp extends CCComp {
const isBoss = MonList[MonType.MeleeBoss].includes(item.uuid) ||
MonList[MonType.LongBoss].includes(item.uuid);
const lane = item.flyLane !== undefined && item.flyLane >= 0 && item.flyLane <= 2 ? item.flyLane : this.pickBalancedLane();
const lane = item.flyLane !== undefined && item.flyLane >= 0 && item.flyLane <= 5 ? item.flyLane : this.pickBalancedLane();
// 构造一个模拟的 GeneratedMonster 数据传递给 addMonsterAt
const base = HeroInfo[item.uuid];
@@ -326,7 +328,7 @@ export class MissionMonCompComp extends CCComp {
});
// 2. 重置排号索引
this.laneIndices = [0, 0, 0];
this.laneIndices = [0, 0, 0, 0, 0, 0];
this.waveSpawnedCount = 0;
}
@@ -335,7 +337,7 @@ export class MissionMonCompComp extends CCComp {
/**
* 在指定层级、指定索引处生成一个怪物:
*
* @param laneIndex 三路索引 (0 上, 1 中, 2 下)
* @param laneIndex 三路索引 (0 上, 1 中, 2 下) - 已扩展为6路
* @param monIndex 该路级的第几个怪 (0, 1, 2...)
* @param monData 新引擎生成的怪物数据 (含 uuid, hp, ap, affixes 等)
* @param monLv 怪物等级 (仅对旧有的 level 参数做兼容,实际属性由 monData 决定)
@@ -351,7 +353,8 @@ export class MissionMonCompComp extends CCComp {
// 计算坐标
const spawnX = MissionMonCompComp.MON_SPAWN_START_X + monIndex * MissionMonCompComp.MON_SPAWN_GAP_X;
const landingY = BoxSet.GAME_LINE + MissionMonCompComp.LANE_Y_OFFSETS[laneIndex] + (monData.isBoss ? 6 : 0);
const randomY = Math.random() * 20 - 10; // -10 到 10 的随机Y轴偏移
const landingY = BoxSet.GAME_LINE + MissionMonCompComp.LANE_Y_OFFSETS[laneIndex] + randomY + (monData.isBoss ? 6 : 0);
const spawnPos: Vec3 = v3(spawnX, landingY + MissionMonCompComp.MON_DROP_HEIGHT, 0);
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999;