fix(移动): 增加角色间最小间距并调整技能距离数值
- 将相同位置检测阈值改为最小间距要求,防止角色重叠 - 当无法找到合适位置时返回null并停止移动 - 调整近战和中程技能的标准距离数值 - 移动目标位置时增加间距检查
This commit is contained in:
@@ -68,8 +68,8 @@ export enum SkillRange {
|
||||
|
||||
/** 距离类型的标准数值定义 */
|
||||
export const SkillDisVal: Record<SkillRange, number> = {
|
||||
[SkillRange.Melee]: 120,
|
||||
[SkillRange.Mid]: 360,
|
||||
[SkillRange.Melee]: 150,
|
||||
[SkillRange.Mid]: 400,
|
||||
[SkillRange.Long]: 720
|
||||
};
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
{ offset: -30, lineName: "LINE3" },
|
||||
// { offset: 30, lineName: "LINE4" },
|
||||
];
|
||||
private readonly samePointXThreshold = 12;
|
||||
private readonly samePointYThreshold = 3;
|
||||
private readonly minSpacingX = 50;
|
||||
private readonly minSpacingY = 30;
|
||||
|
||||
private readonly facConfigs: Record<number, MoveFacConfig> = {
|
||||
[FacSet.HERO]: {
|
||||
@@ -81,7 +81,10 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return;
|
||||
}
|
||||
|
||||
this.applyLineAndY(e, view, move, view.node.position.x);
|
||||
const snappedY = this.applyLineAndY(e, view, move, view.node.position.x);
|
||||
if (snappedY !== null && view.node.position.y !== snappedY) {
|
||||
view.node.setPosition(view.node.position.x, snappedY, 0);
|
||||
}
|
||||
this.updateRenderOrder(e);
|
||||
const nearestEnemy = this.findNearestEnemy(e);
|
||||
if (nearestEnemy) {
|
||||
@@ -212,7 +215,9 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
this.moveEntity(view, dir, speed);
|
||||
const newX = view.node.position.x;
|
||||
if ((dir === 1 && newX > targetX) || (dir === -1 && newX < targetX)) {
|
||||
view.node.setPosition(targetX, view.node.position.y, 0);
|
||||
if (!this.hasAnyActorTooClose(e, targetX, view.node.position.y)) {
|
||||
view.node.setPosition(targetX, view.node.position.y, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
view.status_change("idle");
|
||||
@@ -260,16 +265,20 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
}
|
||||
newX = Math.max(moveMinX, Math.min(moveMaxX, newX));
|
||||
const newY = this.applyLineAndY(view.ent, view, move, newX);
|
||||
if (newY === null) {
|
||||
view.status_change("idle");
|
||||
return;
|
||||
}
|
||||
view.node.setPosition(newX, newY, 0);
|
||||
view.status_change("move");
|
||||
}
|
||||
|
||||
private applyLineAndY(entity: ecs.Entity, view: HeroViewComp, move: MoveComp, x: number): number {
|
||||
private applyLineAndY(entity: ecs.Entity, view: HeroViewComp, move: MoveComp, x: number): number | null {
|
||||
if (!view.node) return 0;
|
||||
const baseY = move.baseY;
|
||||
for (const slot of this.ySlots) {
|
||||
const y = baseY + slot.offset;
|
||||
if (!this.hasTeammateAtPoint(entity, x, y)) {
|
||||
if (!this.hasAnyActorTooClose(entity, x, y)) {
|
||||
const lineNode = this.getLineNode(slot.lineName);
|
||||
if (lineNode && view.node.parent !== lineNode) {
|
||||
view.node.parent = lineNode;
|
||||
@@ -277,12 +286,7 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return y;
|
||||
}
|
||||
}
|
||||
const fallback = this.ySlots[0];
|
||||
const fallbackNode = this.getLineNode(fallback.lineName);
|
||||
if (fallbackNode && view.node.parent !== fallbackNode) {
|
||||
view.node.parent = fallbackNode;
|
||||
}
|
||||
return baseY + fallback.offset;
|
||||
return null;
|
||||
}
|
||||
|
||||
private getLineNode(lineName: string) {
|
||||
@@ -292,17 +296,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
return layerRoot.getChildByName(lineName);
|
||||
}
|
||||
|
||||
private hasTeammateAtPoint(self: ecs.Entity, x: number, y: number): boolean {
|
||||
const myAttrs = self.get(HeroAttrsComp);
|
||||
if (!myAttrs) return false;
|
||||
private hasAnyActorTooClose(self: ecs.Entity, x: number, y: number): boolean {
|
||||
return ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)).some(e => {
|
||||
if (e === self) return false;
|
||||
const attrs = e.get(HeroAttrsComp);
|
||||
if (!attrs || attrs.fac !== myAttrs.fac || attrs.is_dead) return false;
|
||||
if (!attrs || attrs.is_dead) return false;
|
||||
const view = e.get(HeroViewComp);
|
||||
if (!view || !view.node) return false;
|
||||
return Math.abs(view.node.position.x - x) <= this.samePointXThreshold
|
||||
&& Math.abs(view.node.position.y - y) <= this.samePointYThreshold;
|
||||
return Math.abs(view.node.position.x - x) < this.minSpacingX
|
||||
&& Math.abs(view.node.position.y - y) < this.minSpacingY;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user