refactor(monster): 重构怪物生成与敌人选择逻辑
1. 统一调整敌人选取算法,加入Y轴权重实现同路优先攻击 2. 重构怪物出生点位配置,改用硬编码数组统一管理 3. 移除怪物生成时的Y轴随机偏移,固定站位避免逻辑冲突 4. 简化怪物生成接口参数,使用索引直接获取预设点位
This commit is contained in:
@@ -353,13 +353,15 @@ export class MoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
let nearest: HeroViewComp | null = null;
|
||||
let minDis = Infinity;
|
||||
|
||||
/** 一次遍历筛出最近敌人(仅比较 x 轴距离) */
|
||||
/** 遍历筛出最近敌人:以 X 轴距离为主,Y 轴距离作为同排的决胜权重,使角色优先攻击同路的敌人 */
|
||||
ecs.query(this.getHeroViewMatcher()).forEach(e => {
|
||||
const m = e.get(HeroAttrsComp);
|
||||
if (m.fac !== myFac && !m.is_dead) {
|
||||
const v = e.get(HeroViewComp);
|
||||
if (v?.node) {
|
||||
const d = Math.abs(currentPos.x - v.node.position.x);
|
||||
const dx = Math.abs(currentPos.x - v.node.position.x);
|
||||
const dy = Math.abs(currentPos.y - v.node.position.y);
|
||||
const d = dx + dy * 0.1; // Y轴权重较小,仅在 X 相近时起决定作用
|
||||
if (d < minDis) {
|
||||
minDis = d;
|
||||
nearest = v;
|
||||
|
||||
Reference in New Issue
Block a user