fix(移动系统): 调整同职业英雄的阵型位置计算逻辑
引入 resolveFormationTargetX 函数获取前排锚点坐标,根据英雄职业类型(近战、中程、远程)和场上存在的其他职业盟友,动态计算角色在阵型中的深度偏移,使同职业英雄在水平方向上正确排列,并确保目标位置在移动边界内。
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user