diff --git a/assets/script/game/hero/HeroSkills.ts b/assets/script/game/hero/HeroSkills.ts index b1bc6579..db4f1826 100644 --- a/assets/script/game/hero/HeroSkills.ts +++ b/assets/script/game/hero/HeroSkills.ts @@ -39,6 +39,9 @@ export class HeroSkillsComp extends ecs.Comp { skills: Record = {}; max_auto: boolean = true; + /** AI 检测计时器 */ + ai_timer: number = 0; + // ==================== 辅助方法 ==================== /** diff --git a/assets/script/game/hero/SACastSystem.ts b/assets/script/game/hero/SACastSystem.ts index 453c31c5..8e2e2cef 100644 --- a/assets/script/game/hero/SACastSystem.ts +++ b/assets/script/game/hero/SACastSystem.ts @@ -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个目标