refactor(monster&hero): 重构三路分层逻辑与渲染排序

1. 移除飞行怪特殊判定,统一按Y轴高度处理三路渲染
2. 重命名飞行层相关变量为更准确的路次命名
3. 新增英雄自动分路均衡分配逻辑
4. 调整渲染排序规则,按Y轴高度决定上下层显示顺序
5. 修复怪物入场动画与刷怪分路逻辑
This commit is contained in:
panw
2026-05-12 16:32:25 +08:00
parent 86363f50b0
commit 20e9b1d484
5 changed files with 147 additions and 52 deletions

View File

@@ -65,7 +65,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
private lastRenderSortAt = 0;
private heroMoveMatcher: ecs.IMatcher | null = null;
private heroViewMatcher: ecs.IMatcher | null = null;
private readonly renderEntries: { node: Node; bossPriority: number; frontScore: number; spawnOrder: number; eid: number }[] = [];
private readonly renderEntries: { node: Node; bossPriority: number; frontScore: number; spawnOrder: number; eid: number; laneScore: number }[] = [];
private renderEntryCount = 0;
/**
@@ -391,18 +391,21 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
}
}
const isFly = actorView.node.position.y > 50;
// 飞行怪在最前,其次是地面的 X 坐标
const frontScore = isFly ? 999999 - actorView.node.position.x : (attrs.fac === FacSet.HERO ? actorView.node.position.x : -actorView.node.position.x);
// 按 Y 轴计算渲染层级权重Y 越小,说明越靠近屏幕下方,应该渲染在越前面)
// 之前的 isFly 逻辑已被移除,统一按 Y 轴处理三路渲染
const laneScore = -actorView.node.position.y;
// X 轴权重:站在前排的(交战处)优先渲染
const frontScore = attrs.fac === FacSet.HERO ? actorView.node.position.x : -actorView.node.position.x;
const entryIndex = this.renderEntryCount;
let entry = this.renderEntries[entryIndex];
if (!entry) {
entry = { node: actorView.node, bossPriority: 0, frontScore: 0, spawnOrder: 0, eid: 0 };
entry = { node: actorView.node, bossPriority: 0, frontScore: 0, spawnOrder: 0, eid: 0, laneScore: 0 };
this.renderEntries.push(entry);
}
entry.node = actorView.node;
entry.bossPriority = attrs.is_boss ? 1 : 0;
entry.laneScore = laneScore;
entry.frontScore = frontScore;
entry.spawnOrder = spawnOrder;
entry.eid = e.eid;
@@ -410,9 +413,11 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
});
this.renderEntries.length = this.renderEntryCount;
/** 定时重排同层节点Boss 优先级 -> 前后位置 -> 出生序 -> eid */
/** 定时重排同层节点Boss 优先级 -> Y 轴路次 -> 前后位置 -> 出生序 -> eid */
this.renderEntries.sort((a, b) => {
if (a.bossPriority !== b.bossPriority) return a.bossPriority - b.bossPriority;
// Y轴靠下的laneScore 较大)应该在后面,从而渲染在上面
if (Math.abs(a.laneScore - b.laneScore) > 10) return a.laneScore - b.laneScore;
if (a.frontScore !== b.frontScore) return a.frontScore - b.frontScore;
if (a.spawnOrder !== b.spawnOrder) return a.spawnOrder - b.spawnOrder;
return a.eid - b.eid;