feat(技能系统): 添加目标数量配置并优化目标选择逻辑
- 在SkillSet枚举中添加t_num字段用于配置技能目标数量 - 修改sTargets方法,根据技能配置中的t_num确定最大目标数量 - 重构findNearbyEnemies方法,实现基于距离和位置偏差的目标排序 - 添加对技能范围配置的灵活处理,支持range和dis字段
This commit is contained in:
@@ -107,6 +107,7 @@ export enum EType {
|
||||
- ap: 攻击力百分比
|
||||
- cd: 冷却时间
|
||||
- hit_num: 范围攻击 伤害敌人数量
|
||||
- t_num: 目标数量
|
||||
- hit: 穿刺个数
|
||||
- hitcd: 持续伤害的伤害间隔
|
||||
- speed: 移动速度
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user