7 Commits

Author SHA1 Message Date
panw
3c4e1aad29 fix(ui): 调整多个英雄和地图的节点位置与缩放
- 调整 mo3, mo4, mo5, mo6, mud1, mud2, mud3 英雄的 Y 轴位置和缩放比例,使其视觉对齐更合理
- 调整 map_rpg 中特定节点的 Y 轴位置和底部边距,优化界面布局
- 移除 map_rpg 和 mo3.prefab 中未使用的属性字段以简化结构
2026-03-31 15:02:25 +08:00
panw
aa2bf8d6f6 refactor(game): 简化阵型移动逻辑并移除复杂碰撞处理
- 移除 `clampXByAllies` 及相关辅助方法,简化同排单位间的移动阻挡计算
- 重构 `getFormationSlotX` 方法,使用统一的战斗优先级和等级排序,不再按角色类型分层
- 新增 `moveToSlot` 方法集中处理向阵型位置移动的逻辑
- 引入 `isFormationParticipant` 方法,通过检查碰撞体启用状态更准确地筛选阵型参与者
- 删除多个未使用的移动调整参数,如 `meleeMinEnemyDistanceX`、`meleeOvertakeSpeedGap` 等
2026-03-31 15:00:07 +08:00
panw
67a59c9779 fix: 统一英雄预制体的局部位置Y坐标
将多个英雄预制体的局部位置Y坐标统一调整为-25,以解决视觉对齐问题。
调整部分英雄的缩放比例,确保模型显示一致。
2026-03-31 14:51:43 +08:00
panw
9c3ca2d967 refactor(map): 简化英雄出生位置计算逻辑
移除英雄出生时的横向间隔和占位检测机制,改为直接使用起始X坐标。这消除了不必要的循环和位置冲突检查,使出生逻辑更简洁高效。
2026-03-31 10:31:13 +08:00
panw
f0ae5aabef fix(移动系统): 调整同职业英雄的阵型位置计算逻辑
引入 resolveFormationTargetX 函数获取前排锚点坐标,根据英雄职业类型(近战、中程、远程)和场上存在的其他职业盟友,动态计算角色在阵型中的深度偏移,使同职业英雄在水平方向上正确排列,并确保目标位置在移动边界内。
2026-03-31 10:07:03 +08:00
panw
6a0304b265 refactor(game): 重构英雄阵型站位逻辑,移除硬编码使用动态计算
- 删除 `resolveFormationTargetX` 的导入和调用
- 将 `processRangedFormationCombat` 重命名为 `processFormationCombat`,使其适用于所有英雄类型
- 新增 `getFormationSlotX` 方法,根据同阵营、同Y轴单位的战斗优先级和生成顺序动态计算站位点
- 在撤退逻辑中,增加对战斗优先级的检查,防止低优先级单位阻挡高优先级单位
2026-03-31 09:54:53 +08:00
panw
44dbded217 fix(地图): 调整英雄出生点起始X坐标以解决重叠问题
将远程和近战英雄的起始出生X坐标统一调整为-280,避免因坐标差异导致英雄单位在地图上生成时出现重叠或间距异常。
2026-03-31 09:51:28 +08:00
32 changed files with 120 additions and 273 deletions

View File

@@ -114,7 +114,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -40.166, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -114,7 +114,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -31.014, "y": -15.476,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -114,7 +114,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -39.737, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -40.091, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -34.642, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.165, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.766, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.648, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -37.244, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.865, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -37.282, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.93, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.085, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.02, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.725, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.087, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.447, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -40.508, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -38.152, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -40.403, "y": -25,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -49.207, "y": -29.621,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1.1, "x": -1.2,
"y": 1.1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,
@@ -622,7 +622,7 @@
}, },
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 80, "width": 60,
"height": 100 "height": 100
}, },
"_anchorPoint": { "_anchorPoint": {
@@ -754,7 +754,6 @@
}, },
"fileId": "fdklpBwCBM/qJ4WFlQF3kT", "fileId": "fdklpBwCBM/qJ4WFlQF3kT",
"instance": null, "instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [ "nestedPrefabInstanceRoots": [
{ {
"__id__": 26 "__id__": 26

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -45.385, "y": -30.36,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1, "x": -1.2,
"y": 1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -41.284, "y": -30.55,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1, "x": -1.2,
"y": 1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,

View File

@@ -105,7 +105,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -0.129, "y": 4.003,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -117,8 +117,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 1, "x": 0.6,
"y": 1, "y": 0.9,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,
@@ -250,7 +250,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -44.121, "y": -40.734,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.928, "y": -30.802,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1, "x": -1.2,
"y": 1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -35.988, "y": -31.553,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1, "x": -1.2,
"y": 1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,

View File

@@ -111,7 +111,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.57, "y": -31.13,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -123,8 +123,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": -1, "x": -1.2,
"y": 1, "y": 1.2,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,

View File

@@ -105,7 +105,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -0.231, "y": 4.99,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -117,8 +117,8 @@
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0.9, "x": 0.6,
"y": 0.8, "y": 0.7,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,
@@ -250,7 +250,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -39.971, "y": -34.556,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -105,7 +105,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -0.736, "y": 4.897,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -118,7 +118,7 @@
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 1, "x": 1,
"y": 1, "y": 0.8,
"z": 1 "z": 1
}, },
"_mobility": 0, "_mobility": 0,
@@ -250,7 +250,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -36.343, "y": -30.533,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {

View File

@@ -1100,8 +1100,6 @@
"__id__": 0 "__id__": 0
}, },
"fileId": "afC1QRFbdIJrdpKczcbi3p", "fileId": "afC1QRFbdIJrdpKczcbi3p",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null "nestedPrefabInstanceRoots": null
}, },
{ {
@@ -1267,7 +1265,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -30, "y": -28,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -1383,7 +1381,7 @@
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": 0, "_top": 0,
"_bottom": 20, "_bottom": 22,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
"_isAbsLeft": true, "_isAbsLeft": true,

View File

@@ -4,7 +4,7 @@ import { HeroAttrsComp } from "./HeroAttrsComp";
import { smc } from "../common/SingletonModuleComp"; import { smc } from "../common/SingletonModuleComp";
import { FacSet } from "../common/config/GameSet"; import { FacSet } from "../common/config/GameSet";
import { HeroDisVal, HType, resolveFormationTargetX } from "../common/config/heroSet"; import { HeroDisVal, HType, resolveFormationTargetX } from "../common/config/heroSet";
import { Node } from "cc"; import { BoxCollider2D, Node } from "cc";
@ecs.register('MoveComp') @ecs.register('MoveComp')
export class MoveComp extends ecs.Comp { export class MoveComp extends ecs.Comp {
@@ -49,20 +49,8 @@ interface MoveFacConfig {
export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate { export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
/** 近战判定射程(来自 heroSet */ /** 近战判定射程(来自 heroSet */
private readonly meleeAttackRange = HeroDisVal[HType.Melee]; private readonly meleeAttackRange = HeroDisVal[HType.Melee];
/** 近战贴脸最小距离,避免完全重叠 */
private readonly meleeMinEnemyDistanceX = 60;
/** 同优先级近战允许“超车”时,至少要快这么多 */
private readonly meleeOvertakeSpeedGap = 20;
/** 常规同阵营横向最小间距 */ /** 常规同阵营横向最小间距 */
private readonly allySpacingX = 60; private readonly allySpacingX = 60;
/** 允许临时压缩站位时的最小间距 */
private readonly allyOverlapSpacingX = 14;
/** 友军偏离其目标点超过该值,可放宽让路 */
private readonly displacementReleaseX = 10;
/** 即将进入攻击位的锁定阈值 */
private readonly attackReadyLockX = 10;
/** 目标距离足够远才触发“借道前压” */
private readonly attackPassThresholdX = 60;
/** 纵向判定为同排的最大 Y 差 */ /** 纵向判定为同排的最大 Y 差 */
private readonly minSpacingY = 30; private readonly minSpacingY = 30;
/** 渲染层级重排节流,避免每帧排序 */ /** 渲染层级重排节流,避免每帧排序 */
@@ -200,83 +188,73 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
} }
private processMeleeLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) { private processMeleeLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) {
this.processRangedFormationCombat(move, view, model); this.processFormationCombat(e, move, view, model);
} }
private processMidLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) { private processMidLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) {
this.processRangedFormationCombat(move, view, model); this.processFormationCombat(e, move, view, model);
} }
private processLongLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) { private processLongLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) {
this.processRangedFormationCombat(move, view, model); this.processFormationCombat(e, move, view, model);
} }
private processRangedFormationCombat(move: MoveComp, view: HeroViewComp, model: HeroAttrsComp) { private processFormationCombat(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp) {
const currentX = view.node.position.x; const targetX = this.getFormationSlotX(e, model, move.baseY);
/** 中/远程不追人:强制回到自己职业站位点输出 */
const targetX = this.getFixedFormationX(model);
move.targetX = targetX; move.targetX = targetX;
const needMoveToFormation = Math.abs(currentX - targetX) > 5; this.moveToSlot(view, move, model, targetX);
if (needMoveToFormation) { model.is_atking = true;
const dir = targetX > currentX ? 1 : -1;
move.direction = dir;
const speed = model.speed / 3;
this.moveEntity(view, dir, speed);
model.is_atking = true;
} else {
view.status_change("idle");
model.is_atking = true;
}
}
private performRetreat(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, currentX: number) {
const cfg = this.facConfigs[model.fac] || this.facConfigs[FacSet.HERO];
const retreatMinX = Math.min(cfg.retreatBackX, cfg.retreatFrontX);
const retreatMaxX = Math.max(cfg.retreatBackX, cfg.retreatFrontX);
const safeRetreatX = currentX - move.direction * 50;
if (safeRetreatX >= retreatMinX && safeRetreatX <= retreatMaxX) {
const retreatSpeed = (model.speed / 3) * 0.8;
this.moveEntity(view, -move.direction, retreatSpeed);
model.is_atking = false;
} else {
view.status_change("idle");
model.is_atking = true;
}
} }
private processReturnFormation(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp) { private processReturnFormation(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp) {
const currentX = view.node.position.x; const targetX = this.getFormationSlotX(e, model, move.baseY);
/** 脱战时所有类型都回职业站位点,保证阵型稳定 */
const targetX = this.getFixedFormationX(model);
move.targetX = targetX; move.targetX = targetX;
this.moveToSlot(view, move, model, targetX);
if (Math.abs(currentX - targetX) > 5) {
const dir = targetX > currentX ? 1 : -1;
const speed = model.speed / 3;
move.direction = dir;
this.moveEntity(view, dir, speed);
const newX = view.node.position.x;
if ((dir === 1 && newX > targetX) || (dir === -1 && newX < targetX)) {
if (!this.hasAnyActorTooClose(e, targetX, view.node.position.y)) {
view.node.setPosition(targetX, view.node.position.y, 0);
}
}
} else {
view.status_change("idle");
}
} }
private getFixedFormationX(model: HeroAttrsComp): number { private getFormationSlotX(self: ecs.Entity, model: HeroAttrsComp, baseY: number): number {
/** const cfg = this.facConfigs[model.fac] || this.facConfigs[FacSet.HERO];
* 站位点来自 heroSet.resolveFormationTargetX const moveMinX = Math.min(cfg.moveBackX, cfg.moveFrontX);
* - 近战 HType.Melee: FormationPointX=0 const moveMaxX = Math.max(cfg.moveBackX, cfg.moveFrontX);
* - 中程 HType.Mid: FormationPointX=100 const forwardDir = model.fac === FacSet.MON ? -1 : 1;
* - 远程 HType.Long: FormationPointX=180 const laneAllies: ecs.Entity[] = [];
* 阵营镜像规则: ecs.query(this.getHeroMoveMatcher()).forEach(e => {
* - HERO(FacSet.HERO=0):乘 -1 => 近战0 / 中程-100 / 远程-180 if (!this.isFormationParticipant(e, model.fac, baseY)) return;
* - MON(FacSet.MON=1):乘 +1 => 近战0 / 中程100 / 远程180 laneAllies.push(e);
*/ });
return resolveFormationTargetX(model.fac, model.type as HType); laneAllies.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;
const lvA = attrsA?.lv ?? 1;
const lvB = attrsB?.lv ?? 1;
if (lvA !== lvB) return lvB - lvA;
const moveA = a.get(MoveComp);
const moveB = b.get(MoveComp);
const orderA = moveA?.spawnOrder ?? 0;
const orderB = moveB?.spawnOrder ?? 0;
if (orderA !== orderB) return orderA - orderB;
return a.eid - b.eid;
});
const slotIndex = Math.max(0, laneAllies.findIndex(entity => entity === self));
const frontAnchorX = resolveFormationTargetX(model.fac, HType.Melee);
const targetX = frontAnchorX - forwardDir * slotIndex * this.allySpacingX;
return Math.max(moveMinX, Math.min(moveMaxX, targetX));
}
private moveToSlot(view: HeroViewComp, move: MoveComp, model: HeroAttrsComp, targetX: number) {
const currentX = view.node.position.x;
if (Math.abs(currentX - targetX) <= 2) {
view.node.setPosition(targetX, move.baseY, 0);
view.status_change("idle");
return;
}
const dir = targetX > currentX ? 1 : -1;
move.direction = dir;
const speed = model.speed / 3;
this.moveEntity(view, dir, speed, targetX);
} }
private moveEntity(view: HeroViewComp, direction: number, speed: number, stopAtX?: number) { private moveEntity(view: HeroViewComp, direction: number, speed: number, stopAtX?: number) {
@@ -303,13 +281,6 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
/** 指定停止点时,限制不越过 stopAtX */ /** 指定停止点时,限制不越过 stopAtX */
newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX); newX = direction > 0 ? Math.min(newX, stopAtX) : Math.max(newX, stopAtX);
} }
/** 结合同排友军占位,做“让位/防重叠”裁剪 */
newX = this.clampXByAllies(view.ent, model.fac, move.baseY, currentX, newX, direction);
if (direction > 0) {
newX = Math.max(currentX, newX);
} else {
newX = Math.min(currentX, newX);
}
if (Math.abs(newX - currentX) < 0.01) { if (Math.abs(newX - currentX) < 0.01) {
view.status_change("idle"); view.status_change("idle");
return; return;
@@ -318,97 +289,6 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
view.status_change("move"); view.status_change("move");
} }
private clampXByAllies(self: ecs.Entity, fac: number, baseY: number, currentX: number, proposedX: number, direction: number): number {
const selfAttrs = self.get(HeroAttrsComp);
const selfMove = self.get(MoveComp);
const selfPriority = selfAttrs ? this.getCombatPriority(selfAttrs) : 0;
let clampedX = proposedX;
ecs.query(this.getHeroMoveMatcher()).forEach(e => {
if (e === self) return;
const attrs = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
const allyMove = e.get(MoveComp);
/** 只处理同阵营且同排Y 接近)的友军碰撞约束 */
if (!attrs || !view?.node || attrs.is_dead) return;
if (attrs.fac !== fac) return;
if (Math.abs(view.node.position.y - baseY) >= this.minSpacingY) return;
const allyPriority = this.getCombatPriority(attrs);
if (allyPriority < selfPriority) return;
const x = view.node.position.x;
/** 近战同优先级在满足条件时可超车,不做阻挡 */
if (this.shouldAllowMeleeOvertake(selfAttrs, selfMove, attrs, allyMove, currentX, x, direction, allyPriority, selfPriority)) return;
const spacing = this.resolveAllySpacing(selfAttrs, selfMove, currentX, direction, allyMove, x, allyPriority, selfPriority);
if (direction > 0 && x > currentX) {
clampedX = Math.min(clampedX, x - spacing);
}
if (direction < 0 && x < currentX) {
clampedX = Math.max(clampedX, x + spacing);
}
});
return clampedX;
}
private shouldAllowMeleeOvertake(
selfAttrs: HeroAttrsComp | null,
selfMove: MoveComp | null,
allyAttrs: HeroAttrsComp,
allyMove: MoveComp | null,
currentX: number,
allyX: number,
direction: number,
allyPriority: number,
selfPriority: number
): boolean {
if (!selfAttrs || !selfMove || !allyMove) return false;
/** 仅近战对近战、且同优先级才进入超车判定 */
if ((selfAttrs.type as HType) !== HType.Melee || (allyAttrs.type as HType) !== HType.Melee) return false;
if (allyPriority !== selfPriority) return false;
/** 我方更快,且双方都在前压且友军尚未到可攻击位,允许穿插 */
if (selfAttrs.speed <= allyAttrs.speed + this.meleeOvertakeSpeedGap) return false;
if (direction > 0 && allyX <= currentX) return false;
if (direction < 0 && allyX >= currentX) return false;
const selfTargetX = selfMove.targetX;
const allyTargetX = allyMove.targetX;
if (Math.abs(selfTargetX) <= 0.01 || Math.abs(allyTargetX) <= 0.01) return false;
const selfNeedAdvance = direction > 0 ? selfTargetX > currentX + 2 : selfTargetX < currentX - 2;
if (!selfNeedAdvance) return false;
const allyCanAttackNow = allyAttrs.enemy_in_cast_range || Math.abs(allyTargetX - allyX) <= this.attackReadyLockX;
if (allyCanAttackNow) return false;
const allyStillAdvancing = direction > 0 ? allyTargetX > allyX + 2 : allyTargetX < allyX - 2;
if (!allyStillAdvancing) return false;
return true;
}
private resolveAllySpacing(
selfAttrs: HeroAttrsComp | null,
selfMove: MoveComp | null,
currentX: number,
direction: number,
allyMove: MoveComp | null,
allyX: number,
allyPriority: number,
selfPriority: number
): number {
/** 默认保持标准间距,仅在“需要抢位输出”时放宽 */
if (!selfAttrs || !selfMove || !allyMove) return this.allySpacingX;
if ((selfAttrs.type as HType) !== HType.Melee) return this.allySpacingX;
if (allyPriority !== selfPriority) return this.allySpacingX;
const selfTargetX = selfMove.targetX;
const allyTargetX = allyMove.targetX;
const selfHasTarget = Math.abs(selfTargetX) > 0.01;
const allyHasTarget = Math.abs(allyTargetX) > 0.01;
if (!selfHasTarget || !allyHasTarget) return this.allySpacingX;
const selfDistToAttack = Math.abs(selfTargetX - currentX);
const canAttackNow = selfAttrs.enemy_in_cast_range || selfDistToAttack <= this.attackReadyLockX;
if (canAttackNow) return this.allySpacingX;
const targetTooFar = selfDistToAttack >= this.attackPassThresholdX;
if (!targetTooFar) return this.allySpacingX;
const allyDisplaced = Math.abs(allyX - allyTargetX) >= this.displacementReleaseX;
const selfNeedAdvance = direction > 0 ? selfTargetX > currentX + 2 : selfTargetX < currentX - 2;
if (allyDisplaced && selfNeedAdvance) return this.allyOverlapSpacingX;
return this.allySpacingX;
}
private getCombatPriority(model: HeroAttrsComp): number { private getCombatPriority(model: HeroAttrsComp): number {
/** 数值越大越靠前:近战 > 中程 > 远程 */ /** 数值越大越靠前:近战 > 中程 > 远程 */
const rangeType = model.type as HType.Melee | HType.Mid | HType.Long; const rangeType = model.type as HType.Melee | HType.Mid | HType.Long;
@@ -417,19 +297,18 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
return 1; return 1;
} }
private hasAnyActorTooClose(self: ecs.Entity, x: number, y: number): boolean { private isFormationParticipant(entity: ecs.Entity, fac: number, baseY: number): boolean {
const myAttrs = self.get(HeroAttrsComp); const attrs = entity.get(HeroAttrsComp);
if (!myAttrs) return false; const view = entity.get(HeroViewComp);
return ecs.query(this.getHeroViewMatcher()).some(e => { const move = entity.get(MoveComp);
if (e === self) return false; if (!attrs || !view?.node || !move) return false;
const attrs = e.get(HeroAttrsComp); if (attrs.is_dead || attrs.is_reviving) return false;
if (!attrs || attrs.is_dead) return false; if (attrs.fac !== fac) return false;
if (attrs.fac !== myAttrs.fac) return false; if (!move.moving) return false;
const view = e.get(HeroViewComp); if (Math.abs(view.node.position.y - baseY) >= this.minSpacingY) return false;
if (!view || !view.node) return false; const collider = view.node.getComponent(BoxCollider2D);
return Math.abs(view.node.position.x - x) < this.allySpacingX if (collider && !collider.enabled) return false;
&& Math.abs(view.node.position.y - y) < this.minSpacingY; return true;
});
} }
private resolveCombatRange(model: HeroAttrsComp, defaultMin: number, defaultMax: number): [number, number] { private resolveCombatRange(model: HeroAttrsComp, defaultMin: number, defaultMax: number): [number, number] {

View File

@@ -10,7 +10,6 @@ import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/O
import { HeroAttrsComp } from "../hero/HeroAttrsComp"; import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { FacSet } from "../common/config/GameSet"; import { FacSet } from "../common/config/GameSet";
import { oneCom } from "../skill/oncend"; import { oneCom } from "../skill/oncend";
import { HeroViewComp } from "../hero/HeroViewComp";
const { ccclass } = _decorator; const { ccclass } = _decorator;
/** 视图层对象 */ /** 视图层对象 */
@@ -19,14 +18,10 @@ const { ccclass } = _decorator;
export class MissionHeroCompComp extends CCComp { export class MissionHeroCompComp extends CCComp {
/** 英雄出生时的掉落高度,用于表现从空中落地 */ /** 英雄出生时的掉落高度,用于表现从空中落地 */
private static readonly HERO_DROP_HEIGHT = 260 private static readonly HERO_DROP_HEIGHT = 260
/** 出生点横向间隔 */
private static readonly HERO_SPAWN_STEP_X = -60
/** 近战起始出生 X */ /** 近战起始出生 X */
private static readonly HERO_SPAWN_START_MELEE_X = -50 private static readonly HERO_SPAWN_START_MELEE_X = -280
/** 远程(含中程)起始出生 X */ /** 远程(含中程)起始出生 X */
private static readonly HERO_SPAWN_START_RANGED_X = -150 private static readonly HERO_SPAWN_START_RANGED_X = -280
/** 占位判断容差 */
private static readonly HERO_SPAWN_OCCUPY_EPSILON_X = 10
/** 预留计时器 */ /** 预留计时器 */
timer:Timer=new Timer(2) timer:Timer=new Timer(2)
/** 预留状态:友方是否全部死亡 */ /** 预留状态:友方是否全部死亡 */
@@ -109,16 +104,7 @@ export class MissionHeroCompComp extends CCComp {
const hero_pos = 0; const hero_pos = 0;
const baseY = HeroPos[hero_pos].pos.y; const baseY = HeroPos[hero_pos].pos.y;
const startX = this.resolveSpawnStartX(uuid); const startX = this.resolveSpawnStartX(uuid);
let candidateX = startX; return v3(startX, baseY, 0);
let guard = 0;
while (guard < 50) {
if (!this.isSpawnXOccupied(candidateX, baseY)) {
break;
}
candidateX += MissionHeroCompComp.HERO_SPAWN_STEP_X;
guard += 1;
}
return v3(candidateX, baseY, 0);
} }
private resolveSpawnStartX(uuid: number): number { private resolveSpawnStartX(uuid: number): number {
@@ -128,21 +114,6 @@ export class MissionHeroCompComp extends CCComp {
: MissionHeroCompComp.HERO_SPAWN_START_RANGED_X; : MissionHeroCompComp.HERO_SPAWN_START_RANGED_X;
} }
private isSpawnXOccupied(targetX: number, baseY: number): boolean {
const aliveHeroes = this.getAliveHeroes();
for (let i = 0; i < aliveHeroes.length; i++) {
const view = aliveHeroes[i].get(HeroViewComp);
const node = view?.node;
if (!node || !node.isValid) continue;
const pos = node.getPosition();
if (Math.abs(pos.y - baseY) > 80) continue;
if (Math.abs(pos.x - targetX) <= MissionHeroCompComp.HERO_SPAWN_OCCUPY_EPSILON_X) {
return true;
}
}
return false;
}
/** 添加合成后的新英雄,并覆盖为聚合后的属性 */ /** 添加合成后的新英雄,并覆盖为聚合后的属性 */
private addMergedHero(uuid:number, hero_lv:number, ap:number, hp_max:number): number { private addMergedHero(uuid:number, hero_lv:number, ap:number, hp_max:number): number {
const hero = this.addHero(uuid, hero_lv); const hero = this.addHero(uuid, hero_lv);