refactor(monster&hero): 重构三路分层逻辑与渲染排序
1. 移除飞行怪特殊判定,统一按Y轴高度处理三路渲染 2. 重命名飞行层相关变量为更准确的路次命名 3. 新增英雄自动分路均衡分配逻辑 4. 调整渲染排序规则,按Y轴高度决定上下层显示顺序 5. 修复怪物入场动画与刷怪分路逻辑
This commit is contained in:
@@ -57,8 +57,8 @@ export class MissionMonCompComp extends CCComp {
|
||||
private static readonly MON_SPAWN_GAP_X = 50;
|
||||
/** 怪物出生掉落高度 */
|
||||
private static readonly MON_DROP_HEIGHT = 280;
|
||||
/** 飞行层高度偏移(地面, 空中1, 空中2) */
|
||||
private static readonly FLY_LANE_Y_OFFSETS = [0, 120, 240];
|
||||
/** 三路高度偏移(上路, 中路, 下路) */
|
||||
private static readonly LANE_Y_OFFSETS = [100, 0, -100];
|
||||
|
||||
// ======================== 编辑器属性 ========================
|
||||
|
||||
@@ -172,9 +172,22 @@ export class MissionMonCompComp extends CCComp {
|
||||
|
||||
// ======================== 插队刷怪 ========================
|
||||
|
||||
/** 选取当前排数最少的路(均衡分配) */
|
||||
private pickBalancedLane(): number {
|
||||
let min = this.laneIndices[0];
|
||||
let lane = 0;
|
||||
for (let i = 1; i < 3; i++) {
|
||||
if (this.laneIndices[i] < min) {
|
||||
min = this.laneIndices[i];
|
||||
lane = i;
|
||||
}
|
||||
}
|
||||
return lane;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理插队刷怪队列(每 0.15 秒尝试消费一个):
|
||||
* 1. 根据飞行层排号。
|
||||
* 1. 根据指定路或均衡分路。
|
||||
* 2. 找到后从队列中移除并生成怪物。
|
||||
*/
|
||||
private updateSpecialQueue(dt: number) {
|
||||
@@ -190,7 +203,7 @@ export class MissionMonCompComp extends CCComp {
|
||||
(MonList[MonType.FlyBoss] && MonList[MonType.FlyBoss].includes(item.uuid));
|
||||
|
||||
const upType = this.getRandomUpType();
|
||||
const lane = item.flyLane >= 0 && item.flyLane <= 2 ? item.flyLane : 0;
|
||||
const lane = item.flyLane !== undefined && item.flyLane >= 0 && item.flyLane <= 2 ? item.flyLane : this.pickBalancedLane();
|
||||
|
||||
this.addMonsterAt(lane, this.laneIndices[lane], item.uuid, isBoss, upType, Math.max(1, Number(item.level ?? 1)));
|
||||
this.laneIndices[lane]++;
|
||||
@@ -305,24 +318,27 @@ export class MissionMonCompComp extends CCComp {
|
||||
// 解析配置
|
||||
for (const slot of config) {
|
||||
const isBoss = slot.type === MonType.MeleeBoss || slot.type === MonType.LongBoss || slot.type === MonType.FlyBoss;
|
||||
// 判断分配到的飞行层
|
||||
let lane: number = slot.flyLane !== undefined ? slot.flyLane : 0;
|
||||
if (slot.type === MonType.Fly || slot.type === MonType.FlyBoss) {
|
||||
lane = slot.flyLane !== undefined ? slot.flyLane : 1; // 飞行怪默认在第一层
|
||||
}
|
||||
lane = Math.max(0, Math.min(2, lane)); // 约束在 0,1,2
|
||||
|
||||
for (let i = 0; i < slot.count; i++) {
|
||||
const uuid = this.getRandomUuidByType(slot.type);
|
||||
const upType = this.getRandomUpType();
|
||||
// 优先使用配置的 lane,否则均衡分配
|
||||
let lane = slot.flyLane !== undefined ? slot.flyLane : this.pickBalancedLane();
|
||||
lane = Math.max(0, Math.min(2, lane));
|
||||
|
||||
const req = { uuid, isBoss, upType, monLv: wave, lane };
|
||||
allMons.push(req);
|
||||
// 提前累加 laneIndices,以便本波内的均衡分配能正确计算
|
||||
this.laneIndices[lane]++;
|
||||
}
|
||||
}
|
||||
|
||||
this.waveTargetCount = allMons.length;
|
||||
this.waveSpawnedCount = 0;
|
||||
|
||||
// 由于上面循环中已经累加了 laneIndices,这里需要重置,以便下面真正生成时再累加(或者直接利用 allMons 生成)
|
||||
this.laneIndices = [0, 0, 0];
|
||||
|
||||
// 4. 立即生成本波所有怪物
|
||||
for (const req of allMons) {
|
||||
this.addMonsterAt(req.lane, this.laneIndices[req.lane], req.uuid, req.isBoss, req.upType, req.monLv);
|
||||
@@ -335,8 +351,8 @@ export class MissionMonCompComp extends CCComp {
|
||||
/**
|
||||
* 在指定层级、指定索引处生成一个怪物:
|
||||
*
|
||||
* @param laneIndex 飞行层索引 (0, 1, 2)
|
||||
* @param monIndex 该层级的第几个怪 (0, 1, 2...)
|
||||
* @param laneIndex 三路索引 (0 上, 1 中, 2 下)
|
||||
* @param monIndex 该路级的第几个怪 (0, 1, 2...)
|
||||
* @param uuid 怪物 UUID
|
||||
* @param isBoss 是否为 Boss
|
||||
* @param upType 属性成长类型
|
||||
@@ -355,7 +371,7 @@ export class MissionMonCompComp extends CCComp {
|
||||
|
||||
// 计算坐标
|
||||
const spawnX = MissionMonCompComp.MON_SPAWN_START_X + monIndex * MissionMonCompComp.MON_SPAWN_GAP_X;
|
||||
const landingY = BoxSet.GAME_LINE + MissionMonCompComp.FLY_LANE_Y_OFFSETS[laneIndex] + (isBoss ? 6 : 0);
|
||||
const landingY = BoxSet.GAME_LINE + MissionMonCompComp.LANE_Y_OFFSETS[laneIndex] + (isBoss ? 6 : 0);
|
||||
const spawnPos: Vec3 = v3(spawnX, landingY + MissionMonCompComp.MON_DROP_HEIGHT, 0);
|
||||
this.globalSpawnOrder = (this.globalSpawnOrder + 1) % 999;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user