refactor(monster): 重构怪物分层显示与战斗逻辑
1. 重构怪物挂载逻辑,按Boss/小怪分别挂载到对应场景层 2. 调整怪物出生落点逻辑,移除额外Y轴偏移 3. 优化场景节点清理范围,新增MON/BOSS层清理 4. 重构渲染排序逻辑,分层管理怪物渲染层级 5. 新增5套攻击技能预制体与动画资源 6. 修复技能配置参数冗余注释与类型错误
This commit is contained in:
@@ -145,7 +145,9 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
const enemyX = enemy.node.position.x;
|
||||
const dist = Math.abs(selfX - enemyX);
|
||||
const attackRange = model.dis;
|
||||
const inRange = dist <= attackRange;
|
||||
/** 近战贴身作战:攻击距离 dis(100) 大于技能范围(60),推进到与敌人相隔 60 才停下,保证技能可命中且不过度贴身 */
|
||||
const stopRange = model.type === 0 ? 60 : attackRange;
|
||||
const inRange = dist <= stopRange;
|
||||
|
||||
if (inRange) {
|
||||
/** 进入攻击范围:停止移动,进入攻击状态,由 SCastSystem 负责技能释放 */
|
||||
@@ -216,13 +218,19 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
|
||||
private updateRenderOrder() {
|
||||
const scene = smc.map?.MapView?.scene;
|
||||
const actorRoot = scene?.entityLayer?.node?.getChildByName("HERO");
|
||||
if (!actorRoot) return;
|
||||
const layerNode = scene?.entityLayer?.node;
|
||||
if (!layerNode) return;
|
||||
|
||||
const now = Date.now() / 1000;
|
||||
if (now - this.lastRenderSortAt < this.renderSortInterval) return;
|
||||
this.lastRenderSortAt = now;
|
||||
|
||||
const heroRoot = layerNode.getChildByName("HERO");
|
||||
const monRoot = layerNode.getChildByName("MON");
|
||||
const bossRoot = layerNode.getChildByName("BOSS");
|
||||
|
||||
/** 分层重排同层节点:各阵营层内按 Y 轴路次 -> 前后位置 -> 出生序 -> eid 排序
|
||||
* (Boss 已有独立 BOSS 层固定在最底,无需 bossPriority 参与排序) */
|
||||
this.renderEntryCount = 0;
|
||||
ecs.query(this.getHeroViewMatcher()).forEach(e => {
|
||||
const attrs = e.get(HeroAttrsComp);
|
||||
@@ -230,8 +238,16 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (!attrs || !actorView?.node || attrs.is_dead) return;
|
||||
if (attrs.fac !== FacSet.HERO && attrs.fac !== FacSet.MON) return;
|
||||
|
||||
if (actorView.node.parent !== actorRoot) {
|
||||
actorView.node.parent = actorRoot;
|
||||
/** 按阵营/身份归位到对应显示层 */
|
||||
let targetRoot: Node | null | undefined;
|
||||
if (attrs.fac === FacSet.HERO) {
|
||||
targetRoot = heroRoot;
|
||||
} else {
|
||||
targetRoot = attrs.is_boss ? (bossRoot ?? monRoot ?? heroRoot) : (monRoot ?? heroRoot);
|
||||
}
|
||||
if (!targetRoot) return;
|
||||
if (actorView.node.parent !== targetRoot) {
|
||||
actorView.node.parent = targetRoot;
|
||||
}
|
||||
|
||||
/** 统一从 MoveComp 获取 spawnOrder */
|
||||
@@ -250,7 +266,6 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
this.renderEntries.push(entry);
|
||||
}
|
||||
entry.node = actorView.node;
|
||||
entry.bossPriority = attrs.is_boss ? 1 : 0;
|
||||
entry.laneScore = laneScore;
|
||||
entry.frontScore = frontScore;
|
||||
entry.spawnOrder = spawnOrder;
|
||||
@@ -259,9 +274,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
});
|
||||
this.renderEntries.length = this.renderEntryCount;
|
||||
|
||||
/** 定时重排同层节点: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;
|
||||
@@ -269,8 +282,14 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return a.eid - b.eid;
|
||||
});
|
||||
|
||||
this.renderEntries.forEach((item, index) => {
|
||||
/** 分层应用 siblingIndex:各层内部从 0 递增 */
|
||||
const layerCounters = new Map<Node, number>();
|
||||
this.renderEntries.forEach((item) => {
|
||||
const parent = item.node.parent;
|
||||
if (!parent) return;
|
||||
const index = layerCounters.get(parent) ?? 0;
|
||||
item.node.setSiblingIndex(index);
|
||||
layerCounters.set(parent, index + 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user