fix(hero.move): 修复战斗阶段英雄移动与攻击状态处理

添加战斗阶段移动限制逻辑,仅在非战斗时执行移动相关操作,修正战斗中的攻击状态与动画切换逻辑,避免异常行为。
This commit is contained in:
pan
2026-06-12 14:29:25 +08:00
parent 4026397cfe
commit 803e273187

View File

@@ -125,17 +125,22 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
move.baseY = slot.targetY; move.baseY = slot.targetY;
move.targetX = slot.targetX; move.targetX = slot.targetX;
// 战斗阶段不移动
const canMove = !smc.mission.in_fight;
// 2. 平滑 Y 轴换路 // 2. 平滑 Y 轴换路
let isChangingLane = false; let isChangingLane = false;
if (Math.abs(view.node.position.y - move.baseY) > 2) { if (canMove) {
const currentY = view.node.position.y; if (Math.abs(view.node.position.y - move.baseY) > 2) {
const deltaY = move.baseY - currentY; const currentY = view.node.position.y;
const step = 400 * this.dt; // 换路速度 const deltaY = move.baseY - currentY;
const newY = currentY + Math.sign(deltaY) * Math.min(Math.abs(deltaY), step); const step = 400 * this.dt; // 换路速度
view.node.setPosition(view.node.position.x, newY, 0); const newY = currentY + Math.sign(deltaY) * Math.min(Math.abs(deltaY), step);
isChangingLane = true; view.node.setPosition(view.node.position.x, newY, 0);
} else { isChangingLane = true;
view.node.setPosition(view.node.position.x, move.baseY, 0); } else {
view.node.setPosition(view.node.position.x, move.baseY, 0);
}
} }
// 渲染层级重排 // 渲染层级重排
@@ -144,18 +149,31 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const nearestEnemy = this.findNearestEnemy(e); const nearestEnemy = this.findNearestEnemy(e);
if (nearestEnemy) { if (nearestEnemy) {
/** 有敌人:进入战斗位移逻辑 */ /** 有敌人:进入战斗位移逻辑 */
this.processCombatLogic(e, move, view, model, nearestEnemy); if (canMove) {
this.processCombatLogic(e, move, view, model, nearestEnemy);
} else {
model.is_atking = true; // 战斗中不移动,但保持攻击状态
}
this.syncCombatTarget(model, view, nearestEnemy); this.syncCombatTarget(model, view, nearestEnemy);
} else { } else {
/** 无敌人:清目标并回归编队站位 */ /** 无敌人:清目标并回归编队站位 */
this.clearCombatTarget(model); this.clearCombatTarget(model);
this.moveToSlot(view, move, model, move.targetX); if (canMove) {
this.moveToSlot(view, move, model, move.targetX);
}
model.is_atking = false; model.is_atking = false;
} }
// 如果只在 Y 轴移动,也要播放 move 动画 if (canMove) {
if (isChangingLane && view.status !== "move" && view.status !== "atk") { // 如果只在 Y 轴移动,也要播放 move 动画
view.status_change("move"); if (isChangingLane && view.status !== "move" && view.status !== "atk") {
view.status_change("move");
}
} else {
// 战斗阶段如果不移动,确保不在攻击时恢复 idle 状态
if (!model.is_atking && view.status === "move") {
view.status_change("idle");
}
} }
} }