refactor: 合并英雄与怪物移动组件为通用 MoveComp
重构移动系统,将 HeroMoveComp 和 MonMoveComp 合并为通用的 MoveComp 组件,统一移动逻辑。 - 移除 HeroMasterComp 相关代码,简化实体查询 - 统一战斗范围计算和阵型回归逻辑 - 调整移动边界和撤退范围配置 - 优化敌人查找算法,提高性能
This commit is contained in:
@@ -77,8 +77,9 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
// 战斗状态:根据职业类型和rangeType执行智能战术
|
||||
this.processCombatLogic(e, move, view, model, nearestEnemy);
|
||||
} else {
|
||||
// 非战斗状态:向目标移动
|
||||
this.processMarchLogic(e, move, view, model);
|
||||
// 非战斗状态:回归阵型
|
||||
move.targetY = 0;
|
||||
this.processReturnFormation(e, move, view, model);
|
||||
model.is_atking = false;
|
||||
}
|
||||
}
|
||||
@@ -204,8 +205,7 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
/** 执行后撤逻辑 */
|
||||
private performRetreat(view: HeroViewComp, move: MonMoveComp, model: HeroAttrsComp, currentX: number) {
|
||||
const safeRetreatX = currentX - move.direction * 50;
|
||||
// 怪物活动范围通常宽一些
|
||||
if (safeRetreatX >= -450 && safeRetreatX <= 450) {
|
||||
if (safeRetreatX >= -300 && safeRetreatX <= 300) {
|
||||
const retreatSpeed = (model.speed / 3) * 0.8;
|
||||
this.moveEntity(view, -move.direction, retreatSpeed);
|
||||
model.is_atking = false;
|
||||
@@ -216,11 +216,8 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 进军逻辑 (无敌人时)
|
||||
* 策略:向目标X移动 (通常是屏幕左侧)
|
||||
*/
|
||||
private processMarchLogic(e: ecs.Entity, move: MonMoveComp, view: HeroViewComp, model: HeroAttrsComp) {
|
||||
/** 回归阵型逻辑 */
|
||||
private processReturnFormation(e: ecs.Entity, move: MonMoveComp, view: HeroViewComp, model: HeroAttrsComp) {
|
||||
const currentX = view.node.position.x;
|
||||
const targetX = move.targetX;
|
||||
|
||||
@@ -228,7 +225,6 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
const dir = targetX > currentX ? 1 : -1;
|
||||
const speed = model.speed / 3;
|
||||
|
||||
// 修正朝向
|
||||
move.direction = dir;
|
||||
|
||||
this.moveEntity(view, dir, speed);
|
||||
@@ -255,7 +251,7 @@ export class MonMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpda
|
||||
}
|
||||
|
||||
// 地图边界限制
|
||||
if (newX >= -450 && newX <= 450) {
|
||||
if (newX >= -320 && newX <= 320) {
|
||||
view.node.setPosition(newX, newY, 0);
|
||||
view.status_change("move");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user