移动 技能方向基本完善
This commit is contained in:
@@ -6,6 +6,7 @@ import { FacSet } from "../../config/BoxSet";
|
||||
import { oops } from "db://oops-framework/core/Oops";
|
||||
import { GameEvent } from "../../config/GameEvent";
|
||||
import { FightSet } from "../../config/Mission";
|
||||
import { HType } from "../../config/heroSet";
|
||||
|
||||
@ecs.register('BattleMoveSystem')
|
||||
export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
|
||||
@@ -40,14 +41,13 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
return;
|
||||
}
|
||||
|
||||
// 英雄阵营特殊逻辑:检查是否有敌人存在
|
||||
// 英雄阵营特殊逻辑:根据职业区分行为
|
||||
if (view.fac == FacSet.HERO) {
|
||||
const hasEnemies = this.checkEnemiesExist(e);
|
||||
const inAttackRange = view.is_atking;
|
||||
const isWarrior = view.type === HType.warrior;
|
||||
|
||||
// 如果有敌人,继续前进
|
||||
if (hasEnemies) {
|
||||
// 找到最近的敌人,调整移动方向
|
||||
// 战士职业:有敌人就向敌人前进
|
||||
if (isWarrior && hasEnemies) {
|
||||
const nearestEnemy = this.findNearestEnemy(e);
|
||||
if (nearestEnemy) {
|
||||
const enemyX = nearestEnemy.node.position.x;
|
||||
@@ -66,7 +66,7 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
const delta = ((view.speed-view.DEBUFF_SLOW)/3) * this.dt * move.direction;
|
||||
const newX = view.node.position.x + delta;
|
||||
|
||||
// 对于英雄,允许更自由的移动范围
|
||||
// 对于战士,允许更自由的移动范围
|
||||
if (newX >= -420 && newX <= 420) { // 使用地图边界
|
||||
view.status_change("move");
|
||||
view.node.setPosition(newX, view.node.position.y, 0);
|
||||
@@ -78,43 +78,46 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果没有敌人,回到targetX
|
||||
if (!hasEnemies) {
|
||||
const currentX = view.node.position.x;
|
||||
const targetX = move.targetX;
|
||||
|
||||
// 如果不在目标位置,移动到目标位置
|
||||
if (Math.abs(currentX - targetX) > 1) {
|
||||
// 确定移动方向:如果当前位置在目标位置右侧,向左移动;否则向右移动
|
||||
const direction = currentX > targetX ? -1 : 1;
|
||||
const delta = ((view.speed-view.DEBUFF_SLOW)/3) * this.dt * direction;
|
||||
const newX = view.node.position.x + delta;
|
||||
|
||||
// 设置朝向
|
||||
if (direction === 1) {
|
||||
view.node.setScale(1, 1, 1); // 面向右侧
|
||||
} else {
|
||||
view.node.setScale(-1, 1, 1); // 面向左侧
|
||||
}
|
||||
|
||||
// 确保不会超过目标位置
|
||||
if (direction === 1 && newX > targetX) {
|
||||
view.node.setPosition(targetX, view.node.position.y, 0);
|
||||
} else if (direction === -1 && newX < targetX) {
|
||||
view.node.setPosition(targetX, view.node.position.y, 0);
|
||||
} else {
|
||||
view.node.setPosition(newX, view.node.position.y, 0);
|
||||
}
|
||||
view.status_change("move");
|
||||
} else {
|
||||
view.status_change("idle");
|
||||
// 回到targetX后,面向右侧
|
||||
move.direction = 1;
|
||||
view.node.setScale(1, 1, 1); // 面向右侧
|
||||
}
|
||||
this.checkEnemiesInBase(e);
|
||||
return;
|
||||
// 其他职业或战士无敌人时:回到预定点
|
||||
const currentX = view.node.position.x;
|
||||
let finalTargetX = move.targetX;
|
||||
|
||||
// 检查预定点是否已被占用
|
||||
if (this.isPositionOccupied(finalTargetX, e)) {
|
||||
finalTargetX = move.targetX - 50; // 往前50的位置
|
||||
}
|
||||
|
||||
// 如果不在目标位置,移动到目标位置
|
||||
if (Math.abs(currentX - finalTargetX) > 1) {
|
||||
// 确定移动方向
|
||||
const direction = currentX > finalTargetX ? -1 : 1;
|
||||
const delta = ((view.speed-view.DEBUFF_SLOW)/3) * this.dt * direction;
|
||||
const newX = view.node.position.x + delta;
|
||||
|
||||
// 设置朝向
|
||||
if (direction === 1) {
|
||||
view.node.setScale(1, 1, 1); // 面向右侧
|
||||
} else {
|
||||
view.node.setScale(-1, 1, 1); // 面向左侧
|
||||
}
|
||||
|
||||
// 确保不会超过目标位置
|
||||
if (direction === 1 && newX > finalTargetX) {
|
||||
view.node.setPosition(finalTargetX, view.node.position.y, 0);
|
||||
} else if (direction === -1 && newX < finalTargetX) {
|
||||
view.node.setPosition(finalTargetX, view.node.position.y, 0);
|
||||
} else {
|
||||
view.node.setPosition(newX, view.node.position.y, 0);
|
||||
}
|
||||
view.status_change("move");
|
||||
} else {
|
||||
view.status_change("idle");
|
||||
// 到达目标位置后,面向右侧(敌人方向)
|
||||
move.direction = 1;
|
||||
view.node.setScale(1, 1, 1); // 面向右侧
|
||||
}
|
||||
this.checkEnemiesInBase(e);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算移动量
|
||||
@@ -249,17 +252,34 @@ export class BattleMoveSystem extends ecs.ComblockSystem implements ecs.ISystemU
|
||||
})
|
||||
.map(e => e);
|
||||
|
||||
// 按y坐标从小到大排序(y坐标越小显示在上层)
|
||||
// 按x坐标排序:x坐标越大(越前面)的显示在上层
|
||||
const sortedUnits = allUnits.sort((a, b) => {
|
||||
const posA = a.get(HeroViewComp).node.position.y;
|
||||
const posB = b.get(HeroViewComp).node.position.y;
|
||||
return posA - posB; // 修改排序顺序
|
||||
const posA = a.get(HeroViewComp).node.position.x;
|
||||
const posB = b.get(HeroViewComp).node.position.x;
|
||||
return posA - posB; // x坐标从小到大排序
|
||||
});
|
||||
|
||||
// 设置渲染顺序,y坐标越小的显示在上层(索引越大)
|
||||
// 设置渲染顺序:x坐标越大的显示在上层(index越大,层级越高)
|
||||
sortedUnits.forEach((unit, index) => {
|
||||
const view = unit.get(HeroViewComp);
|
||||
view.node.setSiblingIndex(sortedUnits.length - index - 1);
|
||||
view.node.setSiblingIndex(index); // 直接使用index,x坐标大的index大,层级高
|
||||
});
|
||||
}
|
||||
|
||||
/** 检查指定位置是否已被占用 */
|
||||
private isPositionOccupied(targetX: number, currentEntity: ecs.Entity): boolean {
|
||||
const currentView = currentEntity.get(HeroViewComp);
|
||||
const occupationRange = 30; // 定义占用范围为30像素
|
||||
|
||||
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 distance = Math.abs(view.node.position.x - targetX);
|
||||
return distance < occupationRange; // 如果距离小于占用范围,认为被占用
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { _decorator, Component, Node, v3, Vec3 } from 'cc';
|
||||
import { HeroViewComp } from './HeroViewComp';
|
||||
import { SkillSet, TGroup, TType } from '../common/config/SkillSet';
|
||||
import { DTType, SkillSet, SType, TGroup, TType } from '../common/config/SkillSet';
|
||||
import { Skill } from '../skills/Skill';
|
||||
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
@@ -52,8 +52,10 @@ export class SkillConComp extends CCComp {
|
||||
this.HeroView.vmHero.cd += dt
|
||||
}
|
||||
if(this.HeroView.vmHero.cd > this.HeroView.vmHero.cd_max){
|
||||
|
||||
let sc=SkillSet[this.HeroView.skills[1]]
|
||||
if(!sc) return
|
||||
if(sc.SType==SType.damage&&!this.HeroView.is_atking) return
|
||||
this.castSkill(sc,false,0)
|
||||
this.HeroView.vmHero.cd = 0
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { BoxSet, FacSet } from "../common/config/BoxSet";
|
||||
import { HType } from "../common/config/heroSet";
|
||||
import { SkillSet } from "../common/config/SkillSet";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
import { HeroViewComp } from "../hero/HeroViewComp";
|
||||
@@ -57,6 +58,12 @@ export class Skill extends ecs.Entity {
|
||||
node.setPosition(startPos);
|
||||
if(caster.fac==FacSet.MON){
|
||||
node.scale=v3(node.scale.x*-1,1,1)
|
||||
}else{
|
||||
if(caster.type==HType.warrior){
|
||||
if(caster.node.scale.x<0){
|
||||
node.scale=v3(node.scale.x*-1,node.scale.y,1)
|
||||
}
|
||||
}
|
||||
}
|
||||
node.angle+=angle
|
||||
// 添加技能组件
|
||||
|
||||
Reference in New Issue
Block a user