From e577ed976c45162b2f72fa39d7f77ab7d47c1c69 Mon Sep 17 00:00:00 2001 From: panw Date: Wed, 19 Nov 2025 15:39:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8A=80=E8=83=BD=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=AE=E6=A0=87=E6=95=B0=E9=87=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=B9=B6=E4=BC=98=E5=8C=96=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 - 在SkillSet枚举中添加t_num字段用于配置技能目标数量 - 修改sTargets方法,根据技能配置中的t_num确定最大目标数量 - 重构findNearbyEnemies方法,实现基于距离和位置偏差的目标排序 - 添加对技能范围配置的灵活处理,支持range和dis字段 --- assets/script/game/common/config/SkillSet.ts | 1 + assets/script/game/hero/SACastSystem.ts | 43 +++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/assets/script/game/common/config/SkillSet.ts b/assets/script/game/common/config/SkillSet.ts index ba8ae751..d14f2d68 100644 --- a/assets/script/game/common/config/SkillSet.ts +++ b/assets/script/game/common/config/SkillSet.ts @@ -107,6 +107,7 @@ export enum EType { - ap: 攻击力百分比 - cd: 冷却时间 - hit_num: 范围攻击 伤害敌人数量 + - t_num: 目标数量 - hit: 穿刺个数 - hitcd: 持续伤害的伤害间隔 - speed: 移动速度 diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 0f9454b5..86c5d4ba 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -153,7 +153,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat } // 获取目标位置 - let targets = this.sTargets(heroView); + let targets = this.sTargets(heroView, s_uuid); if (targets.length === 0) { console.warn("[SACastSystem] 没有找到有效目标"); return false; @@ -172,7 +172,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat }, delay); if(isDSill){ - targets = this.sTargets(heroView); + targets = this.sTargets(heroView, s_uuid); if (targets.length === 0) { console.warn("[SACastSystem] 没有找到有效目标"); return false; @@ -225,11 +225,13 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat /** * 选择目标位置 */ - private sTargets(caster: HeroViewComp): Vec3[] { - // 简化版:选择最前方的敌人 - let heroAttrs = caster.ent.get(HeroAttrsComp); + private sTargets(caster: HeroViewComp, s_uuid: number): Vec3[] { + const heroAttrs = caster.ent.get(HeroAttrsComp); if (!heroAttrs) return []; - let targets=this.sDamageTargets(caster, config, maxTargets); + const config = SkillSet[s_uuid]; + if (!config) return this.sDefaultTargets(caster, heroAttrs.fac); + const maxTargets = Math.max(1, Number((config as any).t_num ?? 1)); + const targets = this.sDamageTargets(caster, config, maxTargets); if (targets.length === 0) { targets.push(...this.sDefaultTargets(caster, heroAttrs.fac)); } @@ -244,8 +246,8 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat const heroAttrs = caster.ent.get(HeroAttrsComp); if (!heroAttrs) return targets; - // 寻找最近的敌人 - const enemyPositions = this.findNearbyEnemies(caster, heroAttrs.fac, config.range || 300); + const range = Number((config as any).range ?? config.dis ?? 300); + const enemyPositions = this.findNearbyEnemies(caster, heroAttrs.fac, range); // 选择最多maxTargets个目标 for (let i = 0; i < Math.min(maxTargets, enemyPositions.length); i++) { @@ -278,9 +280,28 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat */ private findNearbyEnemies(caster: HeroViewComp, fac: number, range: number): Vec3[] { const enemies: Vec3[] = []; - - - + if (!caster || !caster.node) return enemies; + const currentPos = caster.node.position; + const results: { pos: Vec3; dist: number; laneBias: number }[] = []; + ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)).some(e => { + const model = e.get(HeroAttrsComp); + const view = e.get(HeroViewComp); + if (!model || !view || !view.node) return false; + if (model.is_dead) return false; + if (model.fac === fac) return false; + const pos = view.node.position; + const dist = Math.abs(currentPos.x - pos.x); + if (dist <= range) { + const laneBias = Math.abs(currentPos.y - pos.y); + results.push({ pos: pos.clone(), dist, laneBias }); + } + return false; + }); + results.sort((a, b) => { + if (a.laneBias !== b.laneBias) return a.laneBias - b.laneBias; + return a.dist - b.dist; + }); + for (const r of results) enemies.push(r.pos); return enemies; }