fix(战斗): 修正近战英雄的攻击逻辑和技能配置

- 将兽人召唤师、祭司、图腾师的类型从远程改为近战,以匹配其实际战斗行为
- 修复空挥技能的错误动画名称引用
- 重构SCastSystem的目标选择逻辑,移除冗余的combat_target处理
- 简化敌人查找逻辑,直接根据攻击范围寻找最近目标
This commit is contained in:
panw
2026-03-17 17:00:21 +08:00
parent 20aa067c9c
commit 5d25567b89
3 changed files with 10 additions and 42 deletions

View File

@@ -46,7 +46,9 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
}
private pickCastSkill(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): { skillId: number; targets: HeroViewComp[]; isFriendly: boolean } {
const { target, inRange } = this.resolveCastTarget(heroAttrs, heroView);
const type = heroAttrs.type as HType;
const maxRange = this.resolveMaxCastRange(heroAttrs, type);
const target = this.findNearestEnemyInRange(heroAttrs, heroView, maxRange);
const skillCandidates = [heroAttrs.skill_id, heroAttrs.atk_id];
for (const s_uuid of skillCandidates) {
if (!s_uuid) continue;
@@ -58,7 +60,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (this.isFriendlySkill(config.TGroup)) {
return { skillId: s_uuid, targets: [heroView], isFriendly: true };
}
if (!target || !inRange) continue;
if (!target) continue;
return { skillId: s_uuid, targets: [target], isFriendly: false };
}
return this.emptyCastPlan;
@@ -166,33 +168,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
return group === TGroup.Self || group === TGroup.Team || group === TGroup.Ally;
}
private resolveCombatTarget(heroAttrs: HeroAttrsComp): HeroViewComp | null {
if (heroAttrs.combat_target_eid <= 0) return null;
const targetEntity = ecs.getEntityByEid(heroAttrs.combat_target_eid);
if (!targetEntity) return null;
const targetAttrs = targetEntity.get(HeroAttrsComp);
const targetView = targetEntity.get(HeroViewComp);
if (!targetAttrs || !targetView || !targetView.node || !targetView.node.isValid) return null;
if (targetAttrs.is_dead || targetAttrs.is_reviving) return null;
if (targetAttrs.fac === heroAttrs.fac) return null;
return targetView;
}
private resolveCastTarget(heroAttrs: HeroAttrsComp, heroView: HeroViewComp): { target: HeroViewComp | null; inRange: boolean } {
const combatTarget = this.resolveCombatTarget(heroAttrs);
if (combatTarget && this.isEnemyInCastRange(heroAttrs, heroView, combatTarget)) {
return { target: combatTarget, inRange: true };
}
const nearestInRange = this.findNearestEnemy(heroAttrs, heroView, true);
if (nearestInRange) {
return { target: nearestInRange, inRange: true };
}
const fallback = combatTarget ?? this.findNearestEnemy(heroAttrs, heroView, false);
if (!fallback) return { target: null, inRange: false };
return { target: fallback, inRange: this.isEnemyInCastRange(heroAttrs, heroView, fallback) };
}
private findNearestEnemy(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, requireInRange: boolean): HeroViewComp | null {
private findNearestEnemyInRange(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, maxRange: number): HeroViewComp | null {
if (!heroView.node) return null;
const currentX = heroView.node.position.x;
let nearest: HeroViewComp | null = null;
@@ -204,7 +180,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (attrs.fac === heroAttrs.fac) return;
if (attrs.is_dead || attrs.is_reviving) return;
const dist = Math.abs(currentX - view.node.position.x);
if (requireInRange && !this.isEnemyInCastRange(heroAttrs, heroView, view)) return;
if (dist > maxRange) return;
if (dist >= minDist) return;
minDist = dist;
nearest = view;
@@ -212,14 +188,6 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
return nearest;
}
private isEnemyInCastRange(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, target: HeroViewComp): boolean {
if (!heroView.node || !target.node) return false;
const dist = Math.abs(heroView.node.position.x - target.node.position.x);
const type = heroAttrs.type as HType;
const maxRange = this.resolveMaxCastRange(heroAttrs, type);
return dist <= maxRange;
}
private resolveMaxCastRange(heroAttrs: HeroAttrsComp, type: HType): number {
const cached = heroAttrs.getCachedMaxSkillDistance();
if (cached > 0) return cached;