fix(技能): 修正友方技能目标选择逻辑

- 修正 TGroup.Ally 枚举的注释描述,明确包含自身
- 将 Self 目标类型从友方技能判断中分离,新增 isSelfSkill 方法
- 为 Ally 类型添加 collectFriendlyTargetEids 方法以正确收集友方目标(可选包含自身)
- 修复之前 Ally 技能错误地仅以自身为目标的问题
This commit is contained in:
walkpan
2026-03-19 20:01:27 +08:00
parent 4c29d6942a
commit 916c82e936
2 changed files with 29 additions and 4 deletions

View File

@@ -57,6 +57,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const maxRange = this.resolveMaxCastRange(heroAttrs, type);
const target = this.findNearestEnemyInRange(heroAttrs, heroView, maxRange);
const skillCandidates = [heroAttrs.skill_id, heroAttrs.atk_id];
const selfEid = heroView.ent?.eid;
for (const s_uuid of skillCandidates) {
if (!s_uuid) continue;
const config = SkillSet[s_uuid];
@@ -64,11 +65,16 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
const isMainSkill = s_uuid === heroAttrs.skill_id;
if (isMainSkill && !heroAttrs.can_skill) continue;
if (!isMainSkill && !heroAttrs.can_atk) continue;
if (this.isFriendlySkill(config.TGroup)) {
const selfEid = heroView.ent?.eid;
if (this.isSelfSkill(config.TGroup)) {
if (typeof selfEid !== "number") continue;
return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: [selfEid] };
}
if (this.isFriendlySkill(config.TGroup)) {
const includeSelf = config.TGroup === TGroup.Ally;
const friendlyEids = this.collectFriendlyTargetEids(heroAttrs.fac, selfEid, includeSelf);
if (friendlyEids.length === 0) continue;
return { skillId: s_uuid, isFriendly: true, targetPos: null, targetEids: friendlyEids };
}
if (!target || !heroView.node || !target.node) continue;
const targetPos = this.buildEnemyCastTargetPos(heroView, target, maxRange);
return { skillId: s_uuid, isFriendly: false, targetPos, targetEids: [] };
@@ -168,6 +174,21 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
return targets;
}
private collectFriendlyTargetEids(fac: number, selfEid: number | undefined, includeSelf: boolean): number[] {
const eids: number[] = [];
ecs.query(this.getHeroMatcher()).forEach(entity => {
const model = entity.get(HeroAttrsComp);
const view = entity.get(HeroViewComp);
if (!model || !view?.node || !view.ent) return;
if (model.fac !== fac) return;
if (model.is_dead || model.is_reviving) return;
const eid = view.ent.eid;
if (!includeSelf && typeof selfEid === "number" && eid === selfEid) return;
eids.push(eid);
});
return eids;
}
private hasCastTarget(castPlan: { skillId: number; isFriendly: boolean; targetPos: Vec3 | null; targetEids: number[] }): boolean {
if (castPlan.skillId === 0) return false;
if (castPlan.isFriendly) return castPlan.targetEids.length > 0;
@@ -175,7 +196,11 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
}
private isFriendlySkill(group: TGroup): boolean {
return group === TGroup.Self || group === TGroup.Team || group === TGroup.Ally;
return group === TGroup.Team || group === TGroup.Ally;
}
private isSelfSkill(group: TGroup): boolean {
return group === TGroup.Self;
}
private findNearestEnemyInRange(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, maxRange: number): HeroViewComp | null {