去掉物理碰撞组件,英雄的移动改由系统逻辑统一处理
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "196aaacb-556c-4bb2-925c-9a70dc3e56fc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HeroViewComp } from "../../../hero/HeroViewComp";
|
||||
import { BattleMoveComp } from "./BattleMoveComp";
|
||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { smc } from "../../SingletonModuleComp";
|
||||
|
||||
@ecs.register('BattleMoveSystem')
|
||||
export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
@@ -9,24 +10,29 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
}
|
||||
|
||||
update(e: ecs.Entity) {
|
||||
if(!smc.mission.play||smc.mission.pause) return
|
||||
const move = e.get(BattleMoveComp);
|
||||
const view = e.get(HeroViewComp);
|
||||
|
||||
if (!move.moving) return;
|
||||
|
||||
// 检测攻击范围内是否有敌人
|
||||
const hasEnemy = this.checkEnemiesInRange(e, view.dis);
|
||||
|
||||
if (!hasEnemy) {
|
||||
const shouldStop = this.checkEnemiesInRange(e, view.dis);
|
||||
view.is_atking = shouldStop;
|
||||
// 同步攻击状态
|
||||
if (!shouldStop) {
|
||||
if(view.is_stop||view.is_dead) return //停止移动或者死亡不移动
|
||||
// 计算移动量
|
||||
const delta = view.speed * this.dt * move.direction;
|
||||
const newX = view.node.position.x + delta;
|
||||
|
||||
|
||||
// 限制移动范围
|
||||
if (this.validatePosition(newX, move)) {
|
||||
view.node.setPosition(newX, view.node.position.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(`[${view.hero_name}] 类型:${view.type} 是否停止:${shouldStop} 方向:${move.direction} 位置:${view.node.position.x.toFixed(1)}`);
|
||||
}
|
||||
|
||||
/** 验证目标位置有效性 */
|
||||
@@ -41,11 +47,23 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
private checkEnemiesInRange(entity: ecs.Entity, range: number): boolean {
|
||||
const currentPos = entity.get(HeroViewComp).node.position;
|
||||
const team = entity.get(HeroViewComp).fac;
|
||||
const view = entity.get(HeroViewComp);
|
||||
const isMelee = view.type === 0;
|
||||
|
||||
return ecs.query(ecs.allOf(HeroViewComp)).some(e => {
|
||||
const view = e.get(HeroViewComp);
|
||||
return view.fac !== team &&
|
||||
Math.abs(currentPos.x - view.node.position.x) <= range;
|
||||
const distance = Math.abs(currentPos.x - view.node.position.x);
|
||||
|
||||
if (isMelee) {
|
||||
// 近战需要满足:在攻击范围内且距离<=75才停止
|
||||
const inAttackRange = distance <= range;
|
||||
const closeEnough = distance <= 75; // 近战停止距离
|
||||
return view.fac !== team && inAttackRange && closeEnough;
|
||||
}
|
||||
else {
|
||||
// 远程/辅助:在攻击范围内即停止
|
||||
return view.fac !== team && distance <= range;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9f62614b-42c3-4f21-a3d6-68c9190082e8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -5,11 +5,13 @@
|
||||
* @LastEditTime: 2022-07-25 17:05:02
|
||||
*/
|
||||
import { ecs } from "../../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BattleMoveSystem } from "./BattleMoveSystem";
|
||||
import { MoveToSystem } from "./MoveTo";
|
||||
|
||||
export class EcsPositionSystem extends ecs.System {
|
||||
constructor() {
|
||||
super();
|
||||
this.add(new MoveToSystem());
|
||||
this.add(new BattleMoveSystem());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user