From 916c82e936c99b2b866d0c3f5c19c3e06c0c965a Mon Sep 17 00:00:00 2001 From: walkpan Date: Thu, 19 Mar 2026 20:01:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8A=80=E8=83=BD):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E5=8F=8B=E6=96=B9=E6=8A=80=E8=83=BD=E7=9B=AE=E6=A0=87=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正 TGroup.Ally 枚举的注释描述,明确包含自身 - 将 Self 目标类型从友方技能判断中分离,新增 isSelfSkill 方法 - 为 Ally 类型添加 collectFriendlyTargetEids 方法以正确收集友方目标(可选包含自身) - 修复之前 Ally 技能错误地仅以自身为目标的问题 --- assets/script/game/common/config/SkillSet.ts | 2 +- assets/script/game/hero/SCastSystem.ts | 31 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/assets/script/game/common/config/SkillSet.ts b/assets/script/game/common/config/SkillSet.ts index 1947a3e1..ddf9bd1a 100644 --- a/assets/script/game/common/config/SkillSet.ts +++ b/assets/script/game/common/config/SkillSet.ts @@ -9,7 +9,7 @@ export enum HSSet { export enum TGroup { Self = 0, // 自身 - Ally = 1, // 所有敌人 + Ally = 1, // 所有友方,包括自己 Team = 2, // 所有友方 Enemy = 3, // 敌方单位 All = 4 // 所有单位 diff --git a/assets/script/game/hero/SCastSystem.ts b/assets/script/game/hero/SCastSystem.ts index 48318eb7..580d95b2 100644 --- a/assets/script/game/hero/SCastSystem.ts +++ b/assets/script/game/hero/SCastSystem.ts @@ -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 {