fix(技能系统): 修复敌方技能施放目标位置计算

添加目标节点存在性检查,防止空引用
重构敌方目标位置计算逻辑,确保在施放范围内
This commit is contained in:
panw
2026-03-19 09:57:26 +08:00
parent 33d88b2884
commit a79ca46b3d

View File

@@ -69,8 +69,9 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (typeof selfEid !== "number") continue; if (typeof selfEid !== "number") continue;
return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] }; return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] };
} }
if (!target) continue; if (!target || !heroView.node || !target.node) continue;
return { skillId: s_uuid, isFriendly: false, targetPos: target.node.position.clone(), targetEids: [] }; const targetPos = this.buildEnemyCastTargetPos(heroView, target, maxRange);
return { skillId: s_uuid, isFriendly: false, targetPos, targetEids: [] };
} }
return this.emptyCastPlan; return this.emptyCastPlan;
} }
@@ -212,4 +213,11 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (type === HType.Mid) return 360; if (type === HType.Mid) return 360;
return this.meleeCastRange; 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);
}
} }