fix(ASTS) 修复释放一技能时移动会造成本体移动的问题

This commit is contained in:
chicrobot committed 2026-01-31 00:54:03 +08:00
1 parent 8aa2a00cd1
commit 8f4616bbe7
1 file changed
+113 -94
+113 -94
View File
@@ -749,55 +749,65 @@ export default class AttackSkillTestScene extends Phaser.Scene {
this.castPuppetSkill3Second();
}
break;
case 4: // 技能4:傀儡快速移动并拉本体
case 4: // 技能4:傀儡快速移动并拉本体 / 切换到本体控制(当处于技能3控制状态时)
if (this.puppet && this.isControllingPuppet) {
// 使用轮盘相对方向计算目标位置
const maxDistance = 200;
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
// 检查是否处于3技能第二次按下后的控制期间
const isInSkill3Control = this.puppetSkill3State && this.puppetSkill3State.hasSecondCast;
// 计算归一化方向向量
let normalizedX = 0;
let normalizedY = 0;
if (distance > 0) {
normalizedX = directionX / distance;
normalizedY = directionY / distance;
}
// 计算目标位置:傀儡当前位置 + 归一化方向向量 * 最大距离
const targetX = this.puppet.x + normalizedX * maxDistance;
const targetY = this.puppet.y + normalizedY * maxDistance;
// 记录傀儡的初始位置
const initialPuppetX = this.puppet.x;
const initialPuppetY = this.puppet.y;
// 傀儡移动到目标位置
this.puppet.setPosition(targetX, targetY);
this.puppet.setVelocity(0, 0);
this.puppet.clearTarget();
// 计算傀儡位移的方向向量
const puppetDisplacementX = targetX - initialPuppetX;
const puppetDisplacementY = targetY - initialPuppetY;
const puppetDisplacementDistance = Math.sqrt(puppetDisplacementX * puppetDisplacementX + puppetDisplacementY * puppetDisplacementY);
// 计算本体应该移动的位置(在傀儡位移的直线上,距离傀儡一定距离)
if (puppetDisplacementDistance > 0) {
// 本体与傀儡之间的固定距离
const bodyDistance = 150;
// 计算本体移动的方向向量(与傀儡位移相同的方向)
const bodyMoveX = (puppetDisplacementX / puppetDisplacementDistance) * bodyDistance;
const bodyMoveY = (puppetDisplacementY / puppetDisplacementDistance) * bodyDistance;
// 本体沿着傀儡位移的直线移动
yuange.x = this.puppet.x - bodyMoveX;
yuange.y = this.puppet.y - bodyMoveY;
if (isInSkill3Control) {
// 处于3技能控制期间:只切换到本体控制,不执行移动和拉近逻辑
// 切换到本体控制(保持傀儡存在)
this.switchToYuange(false);
} else {
// 如果傀儡没有移动,保持本体位置不变
// 正常情况:执行傀儡快速移动并拉本体的逻辑
// 使用轮盘相对方向计算目标位置
const maxDistance = 200;
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
// 计算归一化方向向量
let normalizedX = 0;
let normalizedY = 0;
if (distance > 0) {
normalizedX = directionX / distance;
normalizedY = directionY / distance;
}
// 计算目标位置:傀儡当前位置 + 归一化方向向量 * 最大距离
const targetX = this.puppet.x + normalizedX * maxDistance;
const targetY = this.puppet.y + normalizedY * maxDistance;
// 记录傀儡的初始位置
const initialPuppetX = this.puppet.x;
const initialPuppetY = this.puppet.y;
// 傀儡移动到目标位置
this.puppet.setPosition(targetX, targetY);
this.puppet.setVelocity(0, 0);
this.puppet.clearTarget();
// 计算傀儡位移的方向向量
const puppetDisplacementX = targetX - initialPuppetX;
const puppetDisplacementY = targetY - initialPuppetY;
const puppetDisplacementDistance = Math.sqrt(puppetDisplacementX * puppetDisplacementX + puppetDisplacementY * puppetDisplacementY);
// 计算本体应该移动的位置(在傀儡位移的直线上,距离傀儡一定距离)
if (puppetDisplacementDistance > 0) {
// 本体与傀儡之间的固定距离
const bodyDistance = 150;
// 计算本体移动的方向向量(与傀儡位移相同的方向)
const bodyMoveX = (puppetDisplacementX / puppetDisplacementDistance) * bodyDistance;
const bodyMoveY = (puppetDisplacementY / puppetDisplacementDistance) * bodyDistance;
// 本体沿着傀儡位移的直线移动
yuange.x = this.puppet.x - bodyMoveX;
yuange.y = this.puppet.y - bodyMoveY;
} else {
// 如果傀儡没有移动,保持本体位置不变
}
yuange.setVelocity(0, 0);
}
yuange.setVelocity(0, 0);
}
break;
}
@@ -805,58 +815,67 @@ export default class AttackSkillTestScene extends Phaser.Scene {
// 控制本体时的技能
switch (skillIndex) {
case 1: // 技能1:扔出傀儡或收回傀儡
if (this.puppet) {
// 有傀儡存在:立即收回并销毁傀儡
this.switchToYuange();
} else {
// 没有傀儡:创建新傀儡
// 使用轮盘相对方向计算目标位置
const maxDistance = 200;
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
// 计算归一化方向向量
let normalizedX = 0;
let normalizedY = 0;
if (distance > 0) {
normalizedX = directionX / distance;
normalizedY = directionY / distance;
// 禁用移动能力
yuange.canMove = false;
// 停顿
yuange.setVelocity(0, 0);
// 延迟(0.2秒)后释放技能
this.time.delayedCall(200, () => {
if (this.puppet) {
// 有傀儡存在:收回并销毁傀儡
this.switchToYuange();
} else {
// 没有傀儡:创建新傀儡
// 使用轮盘相对方向计算目标位置
const maxDistance = 200;
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
// 计算归一化方向向量
let normalizedX = 0;
let normalizedY = 0;
if (distance > 0) {
normalizedX = directionX / distance;
normalizedY = directionY / distance;
}
// 计算目标位置:元歌当前位置 + 归一化方向向量 * 最大距离
const targetX = yuange.x + normalizedX * maxDistance;
const targetY = yuange.y + normalizedY * maxDistance;
// 创建傀儡直接在指定位置生成,不需要从本体位置开始移动
this.puppet = new Unit(this, targetX, targetY, 'player');
this.puppet.name = 'yuange-puppet';
this.puppet.type = 'yuange-puppet';
this.puppet.setScale(0.8);
this.puppet.tint = 0x00ffff; // 用蓝色区分傀儡
this.unitGroup.add(this.puppet);
// 切换控制到傀儡
this.isControllingPuppet = true;
yuange.setSelected(false);
this.currentlyControlled = this.puppet;
this.controlInfoText.setText('当前控制: 元歌傀儡');
// 更新技能轮盘显示为傀儡的技能
this.updateSkillWheelDisplay();
// 更新ControlMode的选中列表,确保虚拟摇杆能控制傀儡
import('../../systems/ControlMode.js').then(mod => {
mod.clearSelection();
mod.addToSelection(this.puppet);
mod.setActiveUnit(this.puppet);
// 自动锁定相机到傀儡
mod.setCameraLocked(true);
});
}
// 计算目标位置:元歌当前位置 + 归一化方向向量 * 最大距离
const targetX = yuange.x + normalizedX * maxDistance;
const targetY = yuange.y + normalizedY * maxDistance;
// 立即恢复透明度
yuange.alpha = 1;
// 创建傀儡直接在指定位置生成,不需要从本体位置开始移动
this.puppet = new Unit(this, targetX, targetY, 'player');
this.puppet.name = 'yuange-puppet';
this.puppet.type = 'yuange-puppet';
this.puppet.setScale(0.8);
this.puppet.tint = 0x00ffff; // 用蓝色区分傀儡
this.unitGroup.add(this.puppet);
// 切换控制到傀儡
this.isControllingPuppet = true;
yuange.setSelected(false);
this.currentlyControlled = this.puppet;
this.controlInfoText.setText('当前控制: 元歌傀儡');
// 更新技能轮盘显示为傀儡的技能
this.updateSkillWheelDisplay();
// 更新ControlMode的选中列表,确保虚拟摇杆能控制傀儡
import('../../systems/ControlMode.js').then(mod => {
mod.clearSelection();
mod.addToSelection(this.puppet);
mod.setActiveUnit(this.puppet);
// 自动锁定相机到傀儡
mod.setCameraLocked(true);
});
// 技能释放完成后,恢复移动能力
setTimeout(() => {
yuange.canMove = true;
}, 100);
}
}, [], this);
break;
case 2: // 技能2:扇形飞镖攻击
this.castFanDartSkill();