From b2c49d978af47ef2670587f56fa049f8481dc06d Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 8 Jul 2025 10:44:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=80=E8=83=BD=E7=9B=AE=E6=A0=87=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=20=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script/game/hero/SkillConComp.ts | 65 ++++++++++++++++--------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/assets/script/game/hero/SkillConComp.ts b/assets/script/game/hero/SkillConComp.ts index bf53e55d..0390dcd0 100644 --- a/assets/script/game/hero/SkillConComp.ts +++ b/assets/script/game/hero/SkillConComp.ts @@ -1,4 +1,4 @@ -import { _decorator, Component, Node, Vec3 } from 'cc'; +import { _decorator, Component, Node, v3, Vec3 } from 'cc'; import { HeroViewComp } from './HeroViewComp'; import { SkillSet, TGroup, TType } from '../common/config/SkillSet'; import { Skill } from '../skills/Skill'; @@ -75,16 +75,16 @@ export class SkillConComp extends CCComp { if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) { return; } - let targets:any=null + let target:any=null switch(config.TGroup){ case TGroup.Enemy: //单个敌人 - targets = this.filterFrontRow(); + target = this.filterFrontRow() break case TGroup.Ally: //所有敌人 - targets = this.selectAllyTargets(); + target = this.selectAllyTargets() break case TGroup.Self: //自身 - targets = this.HeroView.ent + target = this.node.position break case TGroup.Team: //所有友方 @@ -96,25 +96,20 @@ export class SkillConComp extends CCComp { this.HeroView.playSkillEffect(config.uuid) const skillEntity = ecs.getEntity(Skill); - if (targets.length === 0) return; - + + const timerId = setTimeout(() => { // 再次检查节点有效性 if (!this.node || !this.node.isValid || !this.HeroView || !this.HeroView.node || !this.HeroView.node.isValid) { return; } - // 检查目标有效性 - if (targets.length <= 0 || !targets[0]) return; - const targetView = targets[0].get(HeroViewComp); - if (!targetView || !targetView.node || !targetView.node.isValid) return; - skillEntity.load( new Vec3(this.HeroView.node.position.x + BoxSet.ATK_X * this.HeroView.scale, this.HeroView.node.position.y + BoxSet.ATK_Y, 0), this.node.parent, config.uuid, - new Vec3(targetView.node.position.x, targetView.node.position.y, 0), + new Vec3(target.x, target.y, 0), this.HeroView, 0, dmg @@ -143,31 +138,53 @@ export class SkillConComp extends CCComp { /** 筛选最前排单位 */ - private filterFrontRow(): ecs.Entity[] { - // 敌方最前排是x坐标最大的,我方最前排是x坐标最小的 + private filterFrontRow(): Vec3{ + // 敌方最前排是x坐标最大的,我方最前排是x坐标最小的,若目标不存在,敌人 取400,我方取-400 let entities:any=null + let pos=v3(0,0) if(this.HeroView.fac==FacSet.HERO){ entities = ecs.query(ecs.allOf(MonModelComp)) + pos=v3(400,0) }else{ entities = ecs.query(ecs.allOf(HeroModelComp)) + pos=v3(-400,0) + } + if(entities.length==0){ + console.log("filterFrontRow 目标不存在",pos.x,pos.y) + return pos + } - let keyPos = this.HeroView.fac==FacSet.HERO ? Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) : Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x)); - - return entities.filter(e => - Math.abs(e.get(HeroViewComp).node.position.x - keyPos) < 10 - ) + pos=v3(keyPos,0) + console.log("filterFrontRow 目标存在",pos.x,pos.y) + return pos } - private selectAllyTargets( ): ecs.Entity[] { + private selectAllyTargets( ): Vec3 { + // 敌方最前排是x坐标最大的+50,我方最前排是x坐标最小的+50,若目标不存在,敌人 取320/2,我方取-320/2 + let entities:any=null + let kp=50 + let pos=v3(0,0) if(this.HeroView.fac==FacSet.HERO){ - return ecs.query(ecs.allOf(MonModelComp)) + entities = ecs.query(ecs.allOf(MonModelComp)) + pos=v3(320/2+kp,0) }else{ - return ecs.query(ecs.allOf(MonModelComp)) - + entities = ecs.query(ecs.allOf(HeroModelComp)) + pos=v3(-320/2-kp,0) + kp=-50 } + if(entities.length==0){ + console.log("selectAllyTargets 目标不存在",pos) + return pos + } + let keyPos = this.HeroView.fac==FacSet.HERO ? + Math.min(...entities.map(e => e.get(HeroViewComp).node.position.x)) : + Math.max(...entities.map(e => e.get(HeroViewComp).node.position.x)); + pos=v3(keyPos+kp,0) + console.log("selectAllyTargets 目标存在",pos) + return pos } /** 随机选择目标 */