From f0ae5aabef7b48089e051afd25f04bb532f0426b Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 31 Mar 2026 10:07:03 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=A7=BB=E5=8A=A8=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8C=E8=81=8C=E4=B8=9A=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E7=9A=84=E9=98=B5=E5=9E=8B=E4=BD=8D=E7=BD=AE=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 引入 resolveFormationTargetX 函数获取前排锚点坐标,根据英雄职业类型(近战、中程、远程)和场上存在的其他职业盟友,动态计算角色在阵型中的深度偏移,使同职业英雄在水平方向上正确排列,并确保目标位置在移动边界内。 --- assets/script/game/hero/MoveComp.ts | 31 +++++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/assets/script/game/hero/MoveComp.ts b/assets/script/game/hero/MoveComp.ts index 7d6bedb0..85772797 100644 --- a/assets/script/game/hero/MoveComp.ts +++ b/assets/script/game/hero/MoveComp.ts @@ -3,7 +3,7 @@ import { HeroViewComp } from "./HeroViewComp"; import { HeroAttrsComp } from "./HeroAttrsComp"; import { smc } from "../common/SingletonModuleComp"; import { FacSet } from "../common/config/GameSet"; -import { HeroDisVal, HType } from "../common/config/heroSet"; +import { HeroDisVal, HType, resolveFormationTargetX } from "../common/config/heroSet"; import { Node } from "cc"; @ecs.register('MoveComp') @@ -269,7 +269,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX); const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX); const forwardDir = model.fac === FacSet.MON ? -1 : 1; - const sortedAllies: ecs.Entity[] = []; + const role = model.type as HType; + const sameRoleAllies: ecs.Entity[] = []; + let hasMeleeAlly = false; + let hasMidAlly = false; ecs.query(this.getHeroMoveMatcher()).forEach(e => { const attrs = e.get(HeroAttrsComp); const view = e.get(HeroViewComp); @@ -277,14 +280,13 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate if (attrs.is_dead || attrs.is_reviving) return; if (attrs.fac !== model.fac) return; if (Math.abs(view.node.position.y - baseY) >= this.minSpacingY) return; - sortedAllies.push(e); + const allyRole = attrs.type as HType; + if (allyRole === HType.Melee) hasMeleeAlly = true; + if (allyRole === HType.Mid) hasMidAlly = true; + if ((attrs.type as HType) !== role) return; + sameRoleAllies.push(e); }); - sortedAllies.sort((a, b) => { - const attrsA = a.get(HeroAttrsComp); - const attrsB = b.get(HeroAttrsComp); - const priorityA = attrsA ? this.getCombatPriority(attrsA) : 0; - const priorityB = attrsB ? this.getCombatPriority(attrsB) : 0; - if (priorityA !== priorityB) return priorityB - priorityA; + sameRoleAllies.sort((a, b) => { const moveA = a.get(MoveComp); const moveB = b.get(MoveComp); const orderA = moveA?.spawnOrder ?? 0; @@ -292,8 +294,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate if (orderA !== orderB) return orderA - orderB; return a.eid - b.eid; }); - const slotIndex = Math.max(0, sortedAllies.findIndex(entity => entity === self)); - const targetX = 0 - forwardDir * slotIndex * this.allySpacingX; + const slotIndex = Math.max(0, sameRoleAllies.findIndex(entity => entity === self)); + let roleDepth = 0; + if (role === HType.Mid) { + roleDepth = hasMeleeAlly ? 1 : 0; + } else if (role === HType.Long) { + roleDepth = (hasMeleeAlly ? 1 : 0) + (hasMidAlly ? 1 : 0); + } + const frontAnchorX = resolveFormationTargetX(model.fac, HType.Melee); + const targetX = frontAnchorX - forwardDir * (roleDepth + slotIndex) * this.allySpacingX; return Math.max(moveMinX, Math.min(moveMaxX, targetX)); }