From a79ca46b3dea805614edf90955f66ec003b60fc9 Mon Sep 17 00:00:00 2001 From: panw Date: Thu, 19 Mar 2026 09:57:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8A=80=E8=83=BD=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=8C=E6=96=B9=E6=8A=80=E8=83=BD=E6=96=BD?= =?UTF-8?q?=E6=94=BE=E7=9B=AE=E6=A0=87=E4=BD=8D=E7=BD=AE=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加目标节点存在性检查,防止空引用 重构敌方目标位置计算逻辑,确保在施放范围内 --- assets/script/game/hero/SCastSystem.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/assets/script/game/hero/SCastSystem.ts b/assets/script/game/hero/SCastSystem.ts index f38e5e25..ad204684 100644 --- a/assets/script/game/hero/SCastSystem.ts +++ b/assets/script/game/hero/SCastSystem.ts @@ -69,8 +69,9 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate if (typeof selfEid !== "number") continue; return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] }; } - if (!target) continue; - return { skillId: s_uuid, isFriendly: false, targetPos: target.node.position.clone(), targetEids: [] }; + if (!target || !heroView.node || !target.node) continue; + const targetPos = this.buildEnemyCastTargetPos(heroView, target, maxRange); + return { skillId: s_uuid, isFriendly: false, targetPos, targetEids: [] }; } return this.emptyCastPlan; } @@ -212,4 +213,11 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate if (type === HType.Mid) return 360; return this.meleeCastRange; } + + private buildEnemyCastTargetPos(caster: HeroViewComp, target: HeroViewComp, castRange: number): Vec3 { + const casterPos = caster.node.position; + const targetPos = target.node.position; + const direction = targetPos.x >= casterPos.x ? 1 : -1; + return new Vec3(casterPos.x + direction * castRange, casterPos.y, casterPos.z); + } }