fix(hero.move): 修复战斗阶段英雄移动与攻击状态处理
添加战斗阶段移动限制逻辑,仅在非战斗时执行移动相关操作,修正战斗中的攻击状态与动画切换逻辑,避免异常行为。
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user