feat(英雄技能): 添加AI检测计时器并优化技能目标选择逻辑

为HeroSkillsComp添加ai_timer属性用于AI行为降频处理,每0.2秒执行一次技能检测
优化SACastSystem中技能目标选择逻辑,移除冗余的类型转换并明确SkillConfig类型
This commit is contained in:
walkpan
2026-01-03 08:28:49 +08:00
parent a9884cf020
commit c948c3e0bd
2 changed files with 15 additions and 5 deletions

View File

@@ -39,6 +39,9 @@ export class HeroSkillsComp extends ecs.Comp {
skills: Record<number, SkillSlot> = {};
max_auto: boolean = true;
/** AI 检测计时器 */
ai_timer: number = 0;
// ==================== 辅助方法 ====================
/**

View File

@@ -2,7 +2,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { Vec3, v3 } from "cc";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroViewComp } from "./HeroViewComp";
import { HSSet, SkillSet, SType, TGroup } from "../common/config/SkillSet";
import { HSSet, SkillSet, SType, TGroup, SkillConfig } from "../common/config/SkillSet";
import { HeroSkillsComp, SkillSlot } from "./HeroSkills";
import { Skill } from "../skill/Skill";
import { smc } from "../common/SingletonModuleComp";
@@ -36,9 +36,16 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
update(e: ecs.Entity): void {
if(!smc.mission.play || smc.mission.pause) return;
const skills = e.get(HeroSkillsComp);
if (!skills) return;
// AI 降频每0.2秒执行一次
skills.ai_timer += this.dt;
if (skills.ai_timer < 0.2) return;
skills.ai_timer = 0;
const heroAttrs = e.get(HeroAttrsComp);
const heroView = e.get(HeroViewComp);
if (!skills || !heroAttrs || !heroView) return;
if (!heroAttrs || !heroView) return;
// 检查基本条件
if (heroAttrs.is_dead || heroAttrs.isStun() || heroAttrs.isFrost()) return;
@@ -268,7 +275,7 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
if (!heroAttrs) return [];
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 maxTargets = Math.max(1, config.t_num ?? 1);
const targets = this.sDamageTargets(caster, config, maxTargets);
if (targets.length === 0) {
targets.push(...this.sDefaultTargets(caster, heroAttrs.fac));
@@ -279,12 +286,12 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
/**
* 选择伤害技能目标
*/
private sDamageTargets(caster: HeroViewComp, config: any, maxTargets: number): Vec3[] {
private sDamageTargets(caster: HeroViewComp, config: SkillConfig, maxTargets: number): Vec3[] {
const targets: Vec3[] = [];
const heroAttrs = caster.ent.get(HeroAttrsComp);
if (!heroAttrs) return targets;
const range = Number((config as any).range ?? config.dis ?? 300);
const range = Number(config.dis ?? 300);
const enemyPositions = this.findNearbyEnemies(caster, heroAttrs.fac, range);
// 选择最多maxTargets个目标