This commit is contained in:
chicrobot committed 2026-02-03 13:46:45 +08:00
commit 4205af8413
1 file changed
+131 -106
+131 -106
View File
@@ -749,55 +749,65 @@ export default class AttackSkillTestScene extends Phaser.Scene {
this.castPuppetSkill3Second(); this.castPuppetSkill3Second();
} }
break; break;
case 4: // 技能4:傀儡快速移动并拉本体 case 4: // 技能4:傀儡快速移动并拉本体 / 切换到本体控制(当处于技能3控制状态时)
if (this.puppet && this.isControllingPuppet) { if (this.puppet && this.isControllingPuppet) {
// 使用轮盘相对方向计算目标位置 // 检查是否处于3技能第二次按下后的控制期间
const maxDistance = 200; const isInSkill3Control = this.puppetSkill3State && this.puppetSkill3State.hasSecondCast;
const distance = Math.sqrt(directionX * directionX + directionY * directionY);
// 计算归一化方向向量 if (isInSkill3Control) {
let normalizedX = 0; // 处于3技能控制期间:只切换到本体控制,不执行移动和拉近逻辑
let normalizedY = 0; // 切换到本体控制(保持傀儡存在)
if (distance > 0) { this.switchToYuange(false);
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 { } 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; break;
} }
@@ -805,58 +815,67 @@ export default class AttackSkillTestScene extends Phaser.Scene {
// 控制本体时的技能 // 控制本体时的技能
switch (skillIndex) { switch (skillIndex) {
case 1: // 技能1:扔出傀儡或收回傀儡 case 1: // 技能1:扔出傀儡或收回傀儡
if (this.puppet) {
// 有傀儡存在:立即收回并销毁傀儡 // 禁用移动能力
this.switchToYuange(); yuange.canMove = false;
} else { // 停顿
// 没有傀儡:创建新傀儡 yuange.setVelocity(0, 0);
// 使用轮盘相对方向计算目标位置
const maxDistance = 200; // 延迟(0.2秒)后释放技能
const distance = Math.sqrt(directionX * directionX + directionY * directionY); this.time.delayedCall(200, () => {
if (this.puppet) {
// 计算归一化方向向量 // 有傀儡存在:收回并销毁傀儡
let normalizedX = 0; this.switchToYuange();
let normalizedY = 0; } else {
if (distance > 0) { // 没有傀儡:创建新傀儡
normalizedX = directionX / distance; // 使用轮盘相对方向计算目标位置
normalizedY = directionY / distance; 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; yuange.alpha = 1;
const targetY = yuange.y + normalizedY * maxDistance;
// 创建傀儡直接在指定位置生成,不需要从本体位置开始移动
this.puppet = new Unit(this, targetX, targetY, 'player'); }, [], this);
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);
}
break; break;
case 2: // 技能2:扇形飞镖攻击 case 2: // 技能2:扇形飞镖攻击
this.castFanDartSkill(); this.castFanDartSkill();
@@ -1108,7 +1127,7 @@ export default class AttackSkillTestScene extends Phaser.Scene {
this.puppet.clearTarget(); this.puppet.clearTarget();
// 一段时间后自动销毁傀儡,切换到本体控制 // 一段时间后自动销毁傀儡,切换到本体控制
this.time.delayedCall(3000, () => { this.puppetDestructionTimer = this.time.delayedCall(3000, () => {
if (this.puppet) { if (this.puppet) {
// 销毁眩晕特效 // 销毁眩晕特效
if (this.stunEffect) { if (this.stunEffect) {
@@ -1128,17 +1147,14 @@ export default class AttackSkillTestScene extends Phaser.Scene {
yuange.setSelected(true); yuange.setSelected(true);
// 更新UI提示 // 更新UI提示
this.controlInfoText.setText('当前控制: 元歌'); this.controlInfoText.setText('当前控制: 元歌');
// 恢复本体的移动能力 // 恢复本体的移动能力
const yuange = this.currentlyControlled; yuange.canMove = true;
if (yuange) { yuange.setVelocity(0, 0);
yuange.canMove = true;
yuange.setVelocity(0, 0); // 更新技能轮盘显示为元歌本体的技能
} this.updateSkillWheelDisplay();
// 更新技能轮盘显示为元歌本体的技能
this.updateSkillWheelDisplay();
// 更新选择系统并锁定相机到本体 // 更新选择系统并锁定相机到本体
import('../../systems/ControlMode.js').then(mod => { import('../../systems/ControlMode.js').then(mod => {
@@ -1157,6 +1173,9 @@ export default class AttackSkillTestScene extends Phaser.Scene {
firstCastTime: 0, firstCastTime: 0,
secondCastTime: 0 secondCastTime: 0
}; };
// 清除计时器引用
this.puppetDestructionTimer = null;
} }
}); });
@@ -1518,6 +1537,12 @@ export default class AttackSkillTestScene extends Phaser.Scene {
*/ */
switchToYuange(destroyPuppet = true) { switchToYuange(destroyPuppet = true) {
if (destroyPuppet && this.puppet) { if (destroyPuppet && this.puppet) {
// 清除定时销毁任务
if (this.puppetDestructionTimer) {
this.puppetDestructionTimer.remove();
this.puppetDestructionTimer = null;
}
// 删除傀儡 // 删除傀儡
this.puppet.destroy(); this.puppet.destroy();
this.puppet = null; this.puppet = null;