refactor(battle): 重构战斗目标查找与位置管理逻辑

新增全局位置网格系统,用于按索引存储敌我单位实体ID:
-  在SingletonModuleComp添加heroGrid与monGrid数组
-  为HeroAttrsComp新增posIndex字段记录位置索引并初始化

优化战斗核心流程:
-  重构MissionHeroComp的位置选择逻辑,拆分方法返回位置索引而非直接坐标,优化位置占用检测
-  重构SCastSystem的目标查找与收集逻辑,改用网格遍历替代全量实体查询,大幅提升性能
-  统一三路单位的查找优先级,简化代码提升可维护性
-  完善Hero与Monster的创建销毁流程,同步更新网格的单位注册与注销信息
This commit is contained in:
pan
2026-06-17 09:45:46 +08:00
parent 06a47842dd
commit b6b2dff986
7 changed files with 144 additions and 142 deletions

View File

@@ -113,6 +113,12 @@ export class Monster extends ecs.Entity {
Monster.putToPool(path, view.node);
}
if (model && model.posIndex >= 0) {
if (smc.mission.monGrid[model.posIndex] === this.eid) {
smc.mission.monGrid[model.posIndex] = -1;
}
}
// 手动移除组件,避免 ecs 引用滞留
this.remove(HeroViewComp);
this.remove(HeroAttrsComp);
@@ -170,6 +176,10 @@ export class Monster extends ecs.Entity {
model.type = hero.type;
model.fac = FacSet.MON;
model.dis = hero.dis ?? 720;
model.posIndex = laneIndex;
if (laneIndex >= 0) {
smc.mission.monGrid[laneIndex] = this.eid;
}
// 复制触发技能配置
model.call = hero.call;