重构了 技能系统,还需要完善

This commit is contained in:
2025-10-30 15:12:49 +08:00
parent 1281cbd32d
commit 55646c3a11
27 changed files with 1022 additions and 595 deletions

View File

@@ -5,6 +5,7 @@ import { smc } from "../../SingletonModuleComp";
import { FacSet } from "../../config/BoxSet";
import { HType } from "../../config/heroSet";
import { Attrs } from "../../config/HeroAttrs";
import { HeroAttrsComp } from "../../../hero/HeroAttrsComp";
@ecs.register('BattleMoveSystem')
export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
@@ -16,20 +17,21 @@ 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 model = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
if (!move.moving) return;
const shouldStop = this.checkEnemiesInFace(e);
view.is_atking = this.checkEnemiesInRange(e, view.Attrs[Attrs.DIS]);
model.is_atking = this.checkEnemiesInRange(e, model.Attrs[Attrs.DIS]);
// 更新渲染层级
this.updateRenderOrder(e);
// 同步状态
if (!shouldStop) { //在攻击范围内停止移动
// if(view.fac==1){
if(view.is_stop||view.is_dead||view.isStun()||view.isFrost()) {
// if(model.fac==1){
if(model.is_stop||model.is_dead||model.isStun()||model.isFrost()) {
view.status_change("idle");
return; //停止移动或者死亡不移动
}
@@ -39,9 +41,9 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
return;
}
// 英雄阵营特殊逻辑:根据职业区分行为
if (view.fac == FacSet.HERO) {
if (model.fac == FacSet.HERO) {
const hasEnemies = this.checkEnemiesExist(e);
const isWarrior = view.type === HType.warrior;
const isWarrior = model.type === HType.warrior;
// 战士职业:有敌人就向敌人前进
if (isWarrior && hasEnemies) {
@@ -62,7 +64,7 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
}
// 继续向敌人方向移动
const delta = (view.Attrs[Attrs.SPEED]/3) * this.dt * move.direction;
const delta = (model.Attrs[Attrs.SPEED]/3) * this.dt * move.direction;
const newX = view.node.position.x + delta;
// 对于战士,允许更自由的移动范围
@@ -89,7 +91,7 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
if (Math.abs(currentX - finalTargetX) > 1) {
// 确定移动方向
const direction = currentX > finalTargetX ? -1 : 1;
const delta = (view.Attrs[Attrs.SPEED]/3) * this.dt * direction;
const delta = (model.Attrs[Attrs.SPEED]/3) * this.dt * direction;
const newX = view.node.position.x + delta;
// 设置朝向
@@ -121,7 +123,7 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
}
// 计算移动量
const delta =(view.Attrs[Attrs.SPEED]/3) * this.dt * move.direction;
const delta =(model.Attrs[Attrs.SPEED]/3) * this.dt * move.direction;
const newX = view.node.position.x + delta;
// 限制移动范围
@@ -140,16 +142,16 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
// 因为敌人在面前而暂时停止不设置moving为false保持检查状态
}
// console.log(`[${view.hero_name}] 类型:${view.type} 是否停止:${shouldStop} 方向:${move.direction} 位置:${view.node.position.x.toFixed(1)}`);
// console.log(`[${model.hero_name}] 类型:${model.type} 是否停止:${shouldStop} 方向:${move.direction} 位置:${model.node.position.x.toFixed(1)}`);
}
/** 检查是否存在敌人 */
private checkEnemiesExist(entity: ecs.Entity): boolean {
const team = entity.get(HeroViewComp).fac;
const team = entity.get(HeroAttrsComp).fac;
let hasEnemies = false;
ecs.query(ecs.allOf(HeroViewComp)).some(e => {
const view = e.get(HeroViewComp);
if (view.fac !== team && !view.is_dead) {
ecs.query(ecs.allOf(HeroAttrsComp)).some(e => {
const model = e.get(HeroAttrsComp);
if (model.fac !== team && !model.is_dead) {
hasEnemies = true;
return true;
}
@@ -160,17 +162,18 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
/** 找到最近的敌人 */
private findNearestEnemy(entity: ecs.Entity): HeroViewComp | null {
const currentPos = entity.get(HeroViewComp).node.position;
const team = entity.get(HeroViewComp).fac;
let nearestEnemy: HeroViewComp | null = null;
const team = entity.get(HeroAttrsComp).fac;
let nearestEnemy: HeroAttrsComp | null = null;
let minDistance = Infinity;
ecs.query(ecs.allOf(HeroViewComp)).forEach(e => {
ecs.query(ecs.allOf(HeroAttrsComp)).forEach(e => {
const model = e.get(HeroAttrsComp);
const view = e.get(HeroViewComp);
if (view.fac !== team && !view.is_dead) {
if (model.fac !== team && !model.is_dead) {
const distance = Math.abs(currentPos.x - view.node.position.x);
if (distance < minDistance) {
minDistance = distance;
nearestEnemy = view;
nearestEnemy = model;
}
}
});
@@ -188,8 +191,8 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
/** 检测是否在墓地 */
private checkInGrave(entity: ecs.Entity): boolean {
const view = entity.get(HeroViewComp);
return view.node.position.x === -1000 || view.node.position.x === 1000;
const model = entity.get(HeroViewComp);
return model.node.position.x === -1000 || model.node.position.x === 1000;
}
/** 检测攻击范围内敌人 */
@@ -198,9 +201,9 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
const team = entity.get(HeroViewComp).fac;
let found = false;
ecs.query(ecs.allOf(HeroViewComp)).some(e => {
const view = e.get(HeroViewComp);
const distance = Math.abs(currentPos.x - view.node.position.x);
if (view.fac !== team) {
const model = e.get(HeroViewComp);
const distance = Math.abs(currentPos.x - model.node.position.x);
if (model.fac !== team) {
if (distance <= range) {
found = true;
return true;
@@ -215,9 +218,9 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
const team = entity.get(HeroViewComp).fac;
let found = false;
ecs.query(ecs.allOf(HeroViewComp)).some(e => {
const view = e.get(HeroViewComp);
const distance = Math.abs(currentPos.x - view.node.position.x);
if (view.fac !== team) {
const model = e.get(HeroViewComp);
const distance = Math.abs(currentPos.x - model.node.position.x);
if (model.fac !== team) {
if (distance <= 75) {
found = true;
return true;
@@ -247,8 +250,8 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
// 设置渲染顺序x坐标越大的显示在上层index越大层级越高
sortedUnits.forEach((unit, index) => {
const view = unit.get(HeroViewComp);
view.node.setSiblingIndex(index); // 直接使用indexx坐标大的index大层级高
const model = unit.get(HeroViewComp);
model.node.setSiblingIndex(index); // 直接使用indexx坐标大的index大层级高
});
}
@@ -260,11 +263,11 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
return ecs.query(ecs.allOf(HeroViewComp)).some(e => {
if (e === currentEntity) return false; // 排除自己
const view = e.get(HeroViewComp);
if (view.fac !== currentView.fac) return false; // 只检查同阵营
if (view.is_dead) return false; // 排除死亡单位
const model = e.get(HeroViewComp);
if (model.fac !== currentView.fac) return false; // 只检查同阵营
if (model.is_dead) return false; // 排除死亡单位
const distance = Math.abs(view.node.position.x - targetX);
const distance = Math.abs(model.node.position.x - targetX);
return distance < occupationRange; // 如果距离小于占用范围,认为被占用
});
}