refactor: 合并英雄与怪物移动组件为通用 MoveComp

重构移动系统,将 HeroMoveComp 和 MonMoveComp 合并为通用的 MoveComp 组件,统一移动逻辑。
- 移除 HeroMasterComp 相关代码,简化实体查询
- 统一战斗范围计算和阵型回归逻辑
- 调整移动边界和撤退范围配置
- 优化敌人查找算法,提高性能
This commit is contained in:
walkpan
2026-03-13 15:54:12 +08:00
parent 5ab5a51752
commit b12b421823
7 changed files with 330 additions and 47 deletions

View File

@@ -8,20 +8,19 @@ import { BoxSet, FacSet, FightSet, IndexSet } from "../common/config/GameSet";
import { HeroInfo, HeroPos, HType } from "../common/config/heroSet";
import { GameEvent } from "../common/config/GameEvent";
import { Attrs} from "../common/config/HeroAttrs";
import { HeroMoveComp } from "./HeroMove";
import { MoveComp } from "./MoveComp";
import { mLogger } from "../common/Logger";
import { HeroMasterComp } from "./HeroMasterComp";
/** 角色实体 */
@ecs.register(`Hero`)
export class Hero extends ecs.Entity {
HeroModel!: HeroAttrsComp;
View!: HeroViewComp;
HeroMove!: HeroMoveComp;
HeroMove!: MoveComp;
debugMode: boolean = false; // 是否启用调试模式
protected init() {
this.addComponents<ecs.Comp>(
HeroMoveComp,
MoveComp,
HeroAttrsComp,
);
}
@@ -35,7 +34,6 @@ export class Hero extends ecs.Entity {
this.remove(HeroViewComp);
this.remove(HeroAttrsComp);
this.remove(HeroMasterComp)
super.destroy();
}
@@ -98,9 +96,10 @@ export class Hero extends ecs.Entity {
model.back_chance=FightSet.BACK_CHANCE
this.add(hv);
oops.message.dispatchEvent(GameEvent.MasterCalled,{uuid:uuid})
const move = this.get(HeroMoveComp);
const move = this.get(MoveComp);
move.direction = 1; // 向右移动
move.targetX = 0; // 右边界'
move.baseY = pos.y;
if(HeroInfo[uuid].type==HType.remote){
move.targetX = -100; // 右边界'
}
@@ -122,7 +121,7 @@ export class HeroLifecycleSystem extends ecs.ComblockSystem
implements ecs.IEntityEnterSystem, ecs.IEntityRemoveSystem {
filter() {
return ecs.allOf(HeroMoveComp);
return ecs.allOf(MoveComp);
}
entityEnter(e: ecs.Entity): void {