fix(技能系统): 修复敌方技能施放目标位置计算
添加目标节点存在性检查,防止空引用 重构敌方目标位置计算逻辑,确保在施放范围内
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user