feat(战斗系统): 实现基于技能距离的智能移动和攻击逻辑

重构英雄和怪物移动系统,引入技能距离缓存机制
在HeroAttrsComp中添加技能距离缓存管理
修改HeroSkillsComp以支持技能距离计算
更新移动系统使用技能距离判断攻击时机和停止位置
调整怪物配置统一使用水球技能
This commit is contained in:
2025-11-03 22:59:56 +08:00
parent 914ab0e8b9
commit 8152523e10
9 changed files with 333 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import { smc } from "../common/SingletonModuleComp";
import { Attrs, AttrsType, BType, NeAttrs } from "../common/config/HeroAttrs";
import { BuffConf, SkillSet } from "../common/config/SkillSet";
import { HeroInfo, AttrSet, HeroUpSet } from "../common/config/heroSet";
import { HeroSkillsComp } from "./HeroSkills";
@ecs.register('HeroAttrs')
@@ -33,6 +34,10 @@ export class HeroAttrsComp extends ecs.Comp {
Attrs: any = []; // 最终属性数组经过Buff计算后
NeAttrs: any = []; // 负面状态数组
// ==================== 技能距离缓存 ====================
maxSkillDistance: number = 0; // 最远技能攻击距离缓存受MP影响
minSkillDistance: number = 0; // 最近技能攻击距离缓存不受MP影响用于停止位置判断
// ==================== Buff/Debuff 系统 ====================
/** 持久型buff数组 - 不会自动过期 */
BUFFS: Record<number, Array<{value: number, BType: BType}>> = {};
@@ -347,6 +352,41 @@ export class HeroAttrsComp extends ecs.Comp {
return this.NeAttrs[NeAttrs.IN_FROST]?.time > 0;
}
// ==================== 技能距离缓存管理 ====================
/**
* 更新技能距离缓存
* 在技能初始化、新增技能、MP变化时调用
* @param skillsComp 技能组件
*/
public updateSkillDistanceCache(skillsComp: HeroSkillsComp): void {
if (!skillsComp) {
this.maxSkillDistance = 0;
this.minSkillDistance = 0;
return;
}
// 最远距离使用当前MP可施放的技能
this.maxSkillDistance = skillsComp.getMaxSkillDistance(this.mp);
// 最近距离使用所有技能中的最小距离不考虑MP限制用于停止位置判断
this.minSkillDistance = skillsComp.getAbsoluteMinSkillDistance();
}
/**
* 获取缓存的最远技能攻击距离
* @returns 最远攻击距离
*/
public getCachedMaxSkillDistance(): number {
return this.maxSkillDistance;
}
/**
* 获取缓存的最近技能攻击距离
* @returns 最近攻击距离
*/
public getCachedMinSkillDistance(): number {
return this.minSkillDistance;
}
reset() {
@@ -370,6 +410,9 @@ export class HeroAttrsComp extends ecs.Comp {
this.NeAttrs = [];
this.BUFFS = {};
this.BUFFS_TEMP = {};
// 重置技能距离缓存
this.maxSkillDistance = 0;
this.minSkillDistance = 0;
this.is_dead = false;
this.is_count_dead = false;
this.is_atking = false;
@@ -457,6 +500,9 @@ export class HeroAttrSystem extends ecs.ComblockSystem
// 1. 更新临时 Buff/Debuff时间递减过期自动移除
model.updateTemporaryBuffsDebuffs(this.dt);
// 记录MP变化前的值
const oldMp = model.mp;
if(this.timer.update(this.dt)){
// 2. HP/MP 自然回复(业务规则)
model.mp += HeroUpSet.MP
@@ -471,6 +517,14 @@ export class HeroAttrSystem extends ecs.ComblockSystem
model.hp = model.Attrs[Attrs.HP_MAX];
}
// 4. 如果MP发生变化更新最大技能距离缓存最小距离不受MP影响
if (model.mp !== oldMp) {
const skillsComp = e.get(HeroSkillsComp);
if (skillsComp) {
model.updateSkillDistanceCache(skillsComp);
}
}
// 每 60 帧输出一次统计
this.frameCount++;
if (this.frameCount % 60 === 0 && this.entityCount === 1) {