实现 英雄不在动一个x点,和 伤害队列显示
This commit is contained in:
@@ -2,11 +2,13 @@ import { HeroViewComp } from "../../../hero/HeroViewComp";
|
||||
import { BattleMoveComp } from "./BattleMoveComp";
|
||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { smc } from "../../SingletonModuleComp";
|
||||
import { BoxSet } from "../../config/BoxSet";
|
||||
|
||||
@ecs.register('BattleMoveSystem')
|
||||
export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
filter(): ecs.IMatcher {
|
||||
return ecs.allOf(BattleMoveComp, HeroViewComp);
|
||||
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
@@ -16,9 +18,13 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
|
||||
if (!move.moving) return;
|
||||
// 检测攻击范围内是否有敌人
|
||||
const shouldStop = this.checkEnemiesInRange(e, view.dis);
|
||||
// 检测友方碰撞和敌方攻击范围
|
||||
const alliesStop = this.checkAlliesInProximity(e);
|
||||
const enemiesStop = this.checkEnemiesInRange(e, view.dis);
|
||||
const shouldStop = alliesStop || enemiesStop;
|
||||
view.is_atking = shouldStop;
|
||||
// 同步攻击状态
|
||||
|
||||
// 同步状态
|
||||
if (!shouldStop) {
|
||||
if(view.is_stop||view.is_dead) return //停止移动或者死亡不移动
|
||||
// 计算移动量
|
||||
@@ -51,6 +57,60 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
newX >= move.targetX;
|
||||
}
|
||||
|
||||
/** 检测友方单位碰撞 */
|
||||
private checkAlliesInProximity(entity: ecs.Entity): boolean {
|
||||
const current = entity.get(HeroViewComp);
|
||||
const currentPos = current.node.position;
|
||||
const SAFE_DISTANCE = 30; // 安全距离
|
||||
|
||||
// 查找同阵营同类型的所有友军(包括当前单位)
|
||||
const allAllies = ecs.query(ecs.allOf(HeroViewComp)).filter(e => {
|
||||
const other = e.get(HeroViewComp);
|
||||
return (e === entity || (
|
||||
other.fac === current.fac &&
|
||||
other.type === current.type
|
||||
));
|
||||
});
|
||||
|
||||
// 按uuid从小到大排序
|
||||
const sortedAllies = allAllies.sort((a, b) => {
|
||||
return a.get(HeroViewComp).hero_uuid - b.get(HeroViewComp).hero_uuid;
|
||||
});
|
||||
|
||||
// 找到当前单位在排序中的位置
|
||||
const currentIndex = sortedAllies.findIndex(e => e === entity);
|
||||
|
||||
// 设置渲染顺序
|
||||
if (current.is_boss) {
|
||||
// boss显示在最上层
|
||||
current.node.setSiblingIndex(999);
|
||||
} else {
|
||||
// 非boss单位,uuid越小的显示在下层(索引越小)
|
||||
current.node.setSiblingIndex(currentIndex);
|
||||
}
|
||||
|
||||
// 如果是uuid最小的单位,直接移动
|
||||
if (currentIndex === 0) {
|
||||
current.is_stop_temp = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取前一个单位(uuid比当前小的最近单位)
|
||||
const prevUnit = sortedAllies[currentIndex - 1];
|
||||
const prevView = prevUnit.get(HeroViewComp);
|
||||
const distToPrev = Math.abs(currentPos.x - prevView.node.position.x);
|
||||
|
||||
// 如果与前一个单位距离小于安全距离,则停止
|
||||
if (distToPrev < SAFE_DISTANCE) {
|
||||
current.is_stop_temp = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 如果与前一个单位距离大于安全距离,则移动
|
||||
current.is_stop_temp = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 检测攻击范围内敌人 */
|
||||
private checkEnemiesInRange(entity: ecs.Entity, range: number): boolean {
|
||||
const currentPos = entity.get(HeroViewComp).node.position;
|
||||
@@ -74,4 +134,4 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user