From 803e273187874f8774f75802e1b0189fc418d63c Mon Sep 17 00:00:00 2001 From: pan Date: Fri, 12 Jun 2026 14:29:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(hero.move):=20=E4=BF=AE=E5=A4=8D=E6=88=98?= =?UTF-8?q?=E6=96=97=E9=98=B6=E6=AE=B5=E8=8B=B1=E9=9B=84=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E4=B8=8E=E6=94=BB=E5=87=BB=E7=8A=B6=E6=80=81=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加战斗阶段移动限制逻辑,仅在非战斗时执行移动相关操作,修正战斗中的攻击状态与动画切换逻辑,避免异常行为。 --- assets/script/game/hero/MoveComp.ts | 46 ++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/assets/script/game/hero/MoveComp.ts b/assets/script/game/hero/MoveComp.ts index 60e827a4..d4d94fca 100644 --- a/assets/script/game/hero/MoveComp.ts +++ b/assets/script/game/hero/MoveComp.ts @@ -125,17 +125,22 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate move.baseY = slot.targetY; move.targetX = slot.targetX; + // 战斗阶段不移动 + const canMove = !smc.mission.in_fight; + // 2. 平滑 Y 轴换路 let isChangingLane = false; - if (Math.abs(view.node.position.y - move.baseY) > 2) { - const currentY = view.node.position.y; - const deltaY = move.baseY - currentY; - const step = 400 * this.dt; // 换路速度 - const newY = currentY + Math.sign(deltaY) * Math.min(Math.abs(deltaY), step); - view.node.setPosition(view.node.position.x, newY, 0); - isChangingLane = true; - } else { - view.node.setPosition(view.node.position.x, move.baseY, 0); + if (canMove) { + if (Math.abs(view.node.position.y - move.baseY) > 2) { + const currentY = view.node.position.y; + const deltaY = move.baseY - currentY; + const step = 400 * this.dt; // 换路速度 + const newY = currentY + Math.sign(deltaY) * Math.min(Math.abs(deltaY), step); + view.node.setPosition(view.node.position.x, newY, 0); + isChangingLane = true; + } 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); 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); } else { /** 无敌人:清目标并回归编队站位 */ this.clearCombatTarget(model); - this.moveToSlot(view, move, model, move.targetX); + if (canMove) { + this.moveToSlot(view, move, model, move.targetX); + } model.is_atking = false; } - // 如果只在 Y 轴移动,也要播放 move 动画 - if (isChangingLane && view.status !== "move" && view.status !== "atk") { - view.status_change("move"); + if (canMove) { + // 如果只在 Y 轴移动,也要播放 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"); + } } }