feat(技能): 增加基于目标类型的智能排序逻辑
扩展技能目标选择系统,支持根据 TType 配置选择不同优先级的目标。 新增 HighestAP(最高攻击力)目标类型,并在 SCastSystem 中实现排序算法: - Frontline(默认):最近距离优先 - Backline:最远距离优先 - LowestHP:最低血量优先 - HighestHP:最高血量优先 - HighestAP:最高攻击力优先 同时更新所有技能配置,补充缺失的 TType 字段。
This commit is contained in:
@@ -2,7 +2,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
|
||||
import { Vec3 } from "cc";
|
||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||
import { HeroViewComp } from "./HeroViewComp";
|
||||
import { BuffsList, SkillConfig, SkillSet, SType, TGroup } from "../common/config/SkillSet";
|
||||
import { BuffsList, SkillConfig, SkillSet, SType, TGroup, TType } from "../common/config/SkillSet";
|
||||
import { Skill } from "../skill/Skill";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { GameConst } from "../common/config/GameConst";
|
||||
@@ -132,7 +132,7 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
const isAll = config.TGroup === TGroup.All;
|
||||
if (isSelf) return [caster];
|
||||
const currentPos = caster.node.position;
|
||||
const list: { view: HeroViewComp; dis: number; lane: number }[] = [];
|
||||
const list: { view: HeroViewComp; attrs: HeroAttrsComp; dis: number; lane: number }[] = [];
|
||||
ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)).forEach(ent => {
|
||||
const targetAttrs = ent.get(HeroAttrsComp);
|
||||
const targetView = ent.get(HeroViewComp);
|
||||
@@ -145,12 +145,41 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
const dis = Math.abs(currentPos.x - targetView.node.position.x);
|
||||
if (dis > range) return;
|
||||
const lane = Math.abs(currentPos.y - targetView.node.position.y);
|
||||
list.push({ view: targetView, dis, lane });
|
||||
list.push({ view: targetView, attrs: targetAttrs, dis, lane });
|
||||
});
|
||||
|
||||
list.sort((a, b) => {
|
||||
if (a.lane !== b.lane) return a.lane - b.lane;
|
||||
return a.dis - b.dis;
|
||||
// 优先检查是否在同一行 (除了特殊目标类型)
|
||||
// 如果是寻找特殊目标(如最低血量),通常忽略行优先,但在范围内全搜索
|
||||
// 但如果设计要求"最近的优先",则通常还是先看行。
|
||||
// 这里假设 TType 优先级高于 Lane 优先级,或者在 TType 相同情况下比较 Lane
|
||||
|
||||
const type = config.TType ?? TType.Frontline;
|
||||
switch (type) {
|
||||
case TType.Backline:
|
||||
// 后排:距离最远优先
|
||||
if (a.lane !== b.lane) return a.lane - b.lane; // 先同行
|
||||
return b.dis - a.dis;
|
||||
case TType.LowestHP:
|
||||
// 最低血量
|
||||
if (a.attrs.hp !== b.attrs.hp) return a.attrs.hp - b.attrs.hp;
|
||||
return a.dis - b.dis; // 血量相同选最近
|
||||
case TType.HighestHP:
|
||||
// 最高血量
|
||||
if (a.attrs.hp !== b.attrs.hp) return b.attrs.hp - a.attrs.hp;
|
||||
return a.dis - b.dis;
|
||||
case TType.HighestAP:
|
||||
// 最高攻击
|
||||
if (a.attrs.ap !== b.attrs.ap) return b.attrs.ap - a.attrs.ap;
|
||||
return a.dis - b.dis;
|
||||
case TType.Frontline:
|
||||
default:
|
||||
// 前排:距离最近优先 (默认)
|
||||
if (a.lane !== b.lane) return a.lane - b.lane;
|
||||
return a.dis - b.dis;
|
||||
}
|
||||
});
|
||||
|
||||
const maxTargets = Math.max(GameConst.Skill.MIN_TARGET_COUNT, 1);
|
||||
return list.slice(0, maxTargets).map(item => item.view);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user