fix(技能): 修正友方技能目标选择逻辑
- 修正 TGroup.Ally 枚举的注释描述,明确包含自身 - 将 Self 目标类型从友方技能判断中分离,新增 isSelfSkill 方法 - 为 Ally 类型添加 collectFriendlyTargetEids 方法以正确收集友方目标(可选包含自身) - 修复之前 Ally 技能错误地仅以自身为目标的问题
This commit is contained in:
@@ -9,7 +9,7 @@ export enum HSSet {
|
||||
|
||||
export enum TGroup {
|
||||
Self = 0, // 自身
|
||||
Ally = 1, // 所有敌人
|
||||
Ally = 1, // 所有友方,包括自己
|
||||
Team = 2, // 所有友方
|
||||
Enemy = 3, // 敌方单位
|
||||
All = 4 // 所有单位
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user