refactor(hero): 统一英雄攻击射程配置并优化射程判断

1.  将MoveSystem和MonMoveSystem中的硬编码射程常量替换为HeroDisVal统一配置
2.  调整近战英雄默认攻击射程为120,修正原硬编码数值不一致问题
3.  优化施法射程计算逻辑,复用HeroDisVal配置
4.  为敌人查找逻辑添加同路优先筛选逻辑
5.  修正部分英雄技能的弹道类型为贝塞尔曲线
6.  移除冗余的射程常量定义,统一配置管理
This commit is contained in:
panw
2026-05-12 16:32:38 +08:00
parent 20e9b1d484
commit 9b35482b3c
5 changed files with 53 additions and 28 deletions

View File

@@ -30,10 +30,6 @@ export class MonMoveComp extends ecs.Comp {
@ecs.register('MonMoveSystem')
export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
/** 近战判定射程 */
private readonly meleeAttackRange = 250;
/** 远程判定射程 */
private readonly longAttackRange = 600;
/** 渲染层级重排节流,避免每帧排序 */
private readonly renderSortInterval = 0.05;
private lastRenderSortAt = 0;
@@ -128,8 +124,8 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
private isEnemyInAttackRange(model: HeroAttrsComp, selfX: number, enemyX: number): boolean {
const dist = Math.abs(selfX - enemyX);
const rangeType = model.type as HType.Melee | HType.Mid | HType.Long;
if (rangeType === HType.Melee) return dist <= this.meleeAttackRange;
return dist <= this.longAttackRange;
const attackRange = HeroDisVal[rangeType];
return dist <= attackRange;
}
private processCombatLogic(e: ecs.Entity, move: MonMoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) {

View File

@@ -48,10 +48,6 @@ interface MoveFacConfig {
@ecs.register('MoveSystem')
export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
/** 近战判定射程 */
private readonly meleeAttackRange = 250;
/** 远程判定射程 */
private readonly longAttackRange = 600;
private readonly heroFrontAnchorX = -100;
private readonly monFrontAnchorX = 0;
/** 常规同阵营横向最小间距(英雄) */
@@ -166,8 +162,8 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
private isEnemyInAttackRange(model: HeroAttrsComp, selfX: number, enemyX: number): boolean {
const dist = Math.abs(selfX - enemyX);
const rangeType = model.type as HType.Melee | HType.Mid | HType.Long;
if (rangeType === HType.Melee) return dist <= this.meleeAttackRange;
return dist <= this.longAttackRange;
const attackRange = HeroDisVal[rangeType];
return dist <= attackRange;
}
private processCombatLogic(e: ecs.Entity, move: MoveComp, view: HeroViewComp, model: HeroAttrsComp, enemy: HeroViewComp) {

View File

@@ -5,7 +5,7 @@ import { HeroViewComp } from "./HeroViewComp";
import { DTType, RType, SkillConfig, SkillKind, SkillSet, SkillUpList, TGroup } from "../common/config/SkillSet";
import { Skill } from "../skill/Skill";
import { smc } from "../common/SingletonModuleComp";
import { HeroInfo, HType } from "../common/config/heroSet";
import { HeroDisVal, HeroInfo, HType } from "../common/config/heroSet";
import { Attrs } from "../common/config/HeroAttrs";
import { BoxSet, FacSet, FightSet } from "../common/config/GameSet";
import { oops } from "db://oops-framework/core/Oops";
@@ -140,8 +140,6 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
}
/** 空施法计划:用于“当前无可施法技能”时的统一返回 */
private readonly emptyCastPlan = { skillId: 0, skillLv: 1, isFriendly: false, targetPos: null as Vec3 | null, targetEids: [] as number[] };
/** 近战英雄默认施法射程 */
private readonly meleeCastRange = 64;
/** 查询缓存:避免每帧重复创建 matcher */
private heroMatcher: ecs.IMatcher | null = null;
@@ -543,12 +541,16 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
/**
* 在施法距离内查找最近敌人。
* 用于单体技能与基础目标参考。
* 考虑三路设计同路Y差较小优先如果同路没有目标再考虑跨路
*/
private findNearestEnemyInRange(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, maxRange: number): HeroViewComp | null {
if (!heroView.node) return null;
const currentX = heroView.node.position.x;
const currentY = heroView.node.position.y;
let nearest: HeroViewComp | null = null;
let minDist = Infinity;
let foundSameLane = false;
ecs.query(this.getHeroMatcher()).forEach(entity => {
const attrs = entity.get(HeroAttrsComp);
const view = entity.get(HeroViewComp);
@@ -556,10 +558,26 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (attrs.fac === heroAttrs.fac) return;
if (attrs.is_dead || attrs.is_reviving) return;
if (this.isOutOfBattleBounds(view.node.position.x)) return;
const dist = Math.abs(currentX - view.node.position.x);
if (dist > maxRange) return;
if (dist >= minDist) return;
minDist = dist;
const distX = Math.abs(currentX - view.node.position.x);
if (distX > maxRange) return;
const isSameLane = Math.abs(currentY - view.node.position.y) < 30; // 30为容差
// 如果之前找到了同路目标,且当前不是同路,直接跳过
if (foundSameLane && !isSameLane) return;
// 如果当前是同路,且之前没找到同路,则强制替换(同路优先)
if (isSameLane && !foundSameLane) {
foundSameLane = true;
minDist = distX;
nearest = view;
return;
}
// 同等路况下比较距离
if (distX >= minDist) return;
minDist = distX;
nearest = view;
});
return nearest;
@@ -568,13 +586,17 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
/**
* 在施法距离内查找“最前排”敌人。
* 依据施法者面向方向选择 x 轴上更前的目标。
* 考虑三路设计:同路优先
*/
private findFrontEnemyInRange(heroAttrs: HeroAttrsComp, heroView: HeroViewComp, maxRange: number, nearestEnemy: HeroViewComp): HeroViewComp | null {
if (!heroView.node || !nearestEnemy.node) return null;
const currentX = heroView.node.position.x;
const currentY = heroView.node.position.y;
const direction = nearestEnemy.node.position.x >= currentX ? 1 : -1;
let frontEnemy: HeroViewComp | null = null;
let edgeX = direction > 0 ? Infinity : -Infinity;
let foundSameLane = false;
ecs.query(this.getHeroMatcher()).forEach(entity => {
const attrs = entity.get(HeroAttrsComp);
const view = entity.get(HeroViewComp);
@@ -583,8 +605,20 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
if (attrs.is_dead || attrs.is_reviving) return;
const enemyX = view.node.position.x;
if (this.isOutOfBattleBounds(enemyX)) return;
const dist = Math.abs(currentX - enemyX);
if (dist > maxRange) return;
const isSameLane = Math.abs(currentY - view.node.position.y) < 30;
if (foundSameLane && !isSameLane) return;
if (isSameLane && !foundSameLane) {
foundSameLane = true;
edgeX = enemyX;
frontEnemy = view;
return;
}
if (direction > 0) {
if (enemyX >= edgeX) return;
edgeX = enemyX;
@@ -618,9 +652,8 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
private resolveMaxCastRange(heroAttrs: HeroAttrsComp, type: HType): number {
const cached = heroAttrs.getCachedMaxSkillDistance();
if (cached > 0) return cached;
if (type === HType.Long) return 720;
if (type === HType.Mid) return 360;
return this.meleeCastRange;
const rangeType = type as HType.Melee | HType.Mid | HType.Long;
return HeroDisVal[rangeType];
}
/** 生成沿目标方向的施法目标坐标 */