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

@@ -1,6 +1,7 @@
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { HeroViewComp } from "./HeroViewComp";
import { HeroAttrsComp } from "./HeroAttrsComp";
import { HeroSkillsComp } from "./HeroSkills";
import { smc } from "../common/SingletonModuleComp";
import { FacSet, IndexSet } from "../common/config/GameSet";
import { Attrs } from "../common/config/HeroAttrs";
@@ -32,7 +33,7 @@ export class MonMoveComp extends ecs.Comp {
@ecs.register('MonMoveSystem')
export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
filter(): ecs.IMatcher {
return ecs.allOf(MonMoveComp, HeroViewComp, HeroAttrsComp);
return ecs.allOf(MonMoveComp, HeroViewComp, HeroAttrsComp, HeroSkillsComp);
}
update(e: ecs.Entity) {
@@ -46,8 +47,10 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
if (model.fac !== FacSet.MON) return;
if (!move.moving) return;
const shouldStop = this.checkEnemiesInFace(e);
model.is_atking = this.checkEnemiesInRange(e, model.Attrs[Attrs.DIS]);
const shouldStopInFace = this.checkEnemiesInFace(e);
const shouldStopAtMinRange = this.shouldStopAtMinSkillRange(e);
const shouldStop = shouldStopInFace || shouldStopAtMinRange;
model.is_atking = this.checkEnemiesInSkillRange(e);
// 🔥 移除渲染层级更新:各线路固定,后召唤的天然层级更高,无需动态调整
@@ -110,6 +113,36 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
return found;
}
/** 检测技能攻击范围内敌人 */
private checkEnemiesInSkillRange(entity: ecs.Entity): boolean {
const currentView = entity.get(HeroViewComp);
const heroAttrs = entity.get(HeroAttrsComp);
if (!currentView || !currentView.node || !heroAttrs) return false;
const currentPos = currentView.node.position;
const team = heroAttrs.fac;
// 使用缓存的最远技能攻击距离判断攻击时机
const maxSkillDistance = heroAttrs.getCachedMaxSkillDistance();
if (maxSkillDistance === 0) return false;
let found = false;
ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)).some(e => {
const model = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
if (!view || !view.node) return false;
const distance = Math.abs(currentPos.x - view.node.position.x);
if (model.fac !== team && !model.is_dead) {
if (distance <= maxSkillDistance) {
found = true;
return true;
}
}
});
return found;
}
/** 检测面前是否有敌人 */
private checkEnemiesInFace(entity: ecs.Entity): boolean {
const currentView = entity.get(HeroViewComp);
@@ -132,4 +165,31 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
});
return found;
}
/** 检查是否应该基于最近技能距离停止移动 */
private shouldStopAtMinSkillRange(entity: ecs.Entity): boolean {
const currentView = entity.get(HeroViewComp);
const heroAttrs = entity.get(HeroAttrsComp);
if (!currentView || !currentView.node || !heroAttrs) return false;
const currentPos = currentView.node.position;
const team = heroAttrs.fac;
// 使用缓存的最近技能攻击距离
const minSkillDistance = heroAttrs.getCachedMinSkillDistance();
if (minSkillDistance === 0) return false;
// 检查是否有敌人在最近技能距离内
return ecs.query(ecs.allOf(HeroAttrsComp, HeroViewComp)).some(e => {
const model = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
if (!view || !view.node) return false;
const distance = Math.abs(currentPos.x - view.node.position.x);
if (model.fac !== team && !model.is_dead) {
return distance <= minSkillDistance;
}
return false;
});
}
}