From 0aaf45d20dd1909081629189c023e2c4458c93a4 Mon Sep 17 00:00:00 2001 From: panw Date: Tue, 8 Jul 2025 14:35:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8D=E5=BE=AE=E4=BC=98=E5=8C=96=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E7=9B=AE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script/game/hero/SkillConComp.ts | 64 +++++++++++-------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/assets/script/game/hero/SkillConComp.ts b/assets/script/game/hero/SkillConComp.ts index 0390dcd0..5734e0eb 100644 --- a/assets/script/game/hero/SkillConComp.ts +++ b/assets/script/game/hero/SkillConComp.ts @@ -135,55 +135,49 @@ export class SkillConComp extends CCComp { return false } - - + check_target(){ + if(this.HeroView.fac==FacSet.HERO){ + return ecs.query(ecs.allOf(MonModelComp)) + }else{ + return ecs.query(ecs.allOf(HeroModelComp)) + } + } + get_front(entities:any){ + 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 keyPos + } /** 筛选最前排单位 */ 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) - } + let entities=this.check_target() if(entities.length==0){ - console.log("filterFrontRow 目标不存在",pos.x,pos.y) - return pos - + if(this.HeroView.fac==FacSet.HERO){ + return v3(400,0) + }else{ + return v3(-400,0) + } } - 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,0) - console.log("filterFrontRow 目标存在",pos.x,pos.y) + pos=v3(this.get_front(entities),0) return pos } private selectAllyTargets( ): Vec3 { // 敌方最前排是x坐标最大的+50,我方最前排是x坐标最小的+50,若目标不存在,敌人 取320/2,我方取-320/2 - let entities:any=null - let kp=50 + let kp=0 let pos=v3(0,0) - if(this.HeroView.fac==FacSet.HERO){ - entities = ecs.query(ecs.allOf(MonModelComp)) - pos=v3(320/2+kp,0) - }else{ - entities = ecs.query(ecs.allOf(HeroModelComp)) - pos=v3(-320/2-kp,0) - kp=-50 - } + let entities=this.check_target() if(entities.length==0){ - console.log("selectAllyTargets 目标不存在",pos) - return pos + if(this.HeroView.fac==FacSet.HERO){ + return v3(320/2+kp,0) + }else{ + return v3(-320/2-kp,0) + } } - 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) + pos=v3(this.get_front(entities)+kp,0) return pos }