feat(英雄技能): 添加AI检测计时器并优化技能目标选择逻辑
为HeroSkillsComp添加ai_timer属性用于AI行为降频处理,每0.2秒执行一次技能检测 优化SACastSystem中技能目标选择逻辑,移除冗余的类型转换并明确SkillConfig类型
This commit is contained in:
@@ -39,6 +39,9 @@ export class HeroSkillsComp extends ecs.Comp {
|
|||||||
skills: Record<number, SkillSlot> = {};
|
skills: Record<number, SkillSlot> = {};
|
||||||
max_auto: boolean = true;
|
max_auto: boolean = true;
|
||||||
|
|
||||||
|
/** AI 检测计时器 */
|
||||||
|
ai_timer: number = 0;
|
||||||
|
|
||||||
// ==================== 辅助方法 ====================
|
// ==================== 辅助方法 ====================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
|
|||||||
import { Vec3, v3 } from "cc";
|
import { Vec3, v3 } from "cc";
|
||||||
import { HeroAttrsComp } from "./HeroAttrsComp";
|
import { HeroAttrsComp } from "./HeroAttrsComp";
|
||||||
import { HeroViewComp } from "./HeroViewComp";
|
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 { HeroSkillsComp, SkillSlot } from "./HeroSkills";
|
||||||
import { Skill } from "../skill/Skill";
|
import { Skill } from "../skill/Skill";
|
||||||
import { smc } from "../common/SingletonModuleComp";
|
import { smc } from "../common/SingletonModuleComp";
|
||||||
@@ -36,9 +36,16 @@ export class SACastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdat
|
|||||||
update(e: ecs.Entity): void {
|
update(e: ecs.Entity): void {
|
||||||
if(!smc.mission.play || smc.mission.pause) return;
|
if(!smc.mission.play || smc.mission.pause) return;
|
||||||
const skills = e.get(HeroSkillsComp);
|
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 heroAttrs = e.get(HeroAttrsComp);
|
||||||
const heroView = e.get(HeroViewComp);
|
const heroView = e.get(HeroViewComp);
|
||||||
if (!skills || !heroAttrs || !heroView) return;
|
if (!heroAttrs || !heroView) return;
|
||||||
|
|
||||||
// 检查基本条件
|
// 检查基本条件
|
||||||
if (heroAttrs.is_dead || heroAttrs.isStun() || heroAttrs.isFrost()) 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 [];
|
if (!heroAttrs) return [];
|
||||||
const config = SkillSet[s_uuid];
|
const config = SkillSet[s_uuid];
|
||||||
if (!config) return this.sDefaultTargets(caster, heroAttrs.fac);
|
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);
|
const targets = this.sDamageTargets(caster, config, maxTargets);
|
||||||
if (targets.length === 0) {
|
if (targets.length === 0) {
|
||||||
targets.push(...this.sDefaultTargets(caster, heroAttrs.fac));
|
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 targets: Vec3[] = [];
|
||||||
const heroAttrs = caster.ent.get(HeroAttrsComp);
|
const heroAttrs = caster.ent.get(HeroAttrsComp);
|
||||||
if (!heroAttrs) return targets;
|
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);
|
const enemyPositions = this.findNearbyEnemies(caster, heroAttrs.fac, range);
|
||||||
|
|
||||||
// 选择最多maxTargets个目标
|
// 选择最多maxTargets个目标
|
||||||
|
|||||||
Reference in New Issue
Block a user