From 8fdd9e2c983b0d80bf4ab548e0a439d361991467 Mon Sep 17 00:00:00 2001 From: walkpan Date: Sun, 2 Nov 2025 00:23:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(skill):=20=E6=B7=BB=E5=8A=A0=E5=91=BD?= =?UTF-8?q?=E4=B8=AD=E7=9B=AE=E6=A0=87=E8=BF=BD=E8=B8=AA=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E4=BC=A4=E5=AE=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 hitTargets Set 来追踪已命中目标,避免技能对同一目标造成多次伤害。同时优化碰撞检测逻辑,移除不必要的条件检查。 --- assets/script/game/skill/SkillView.ts | 32 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index 5cb7c7d4..72b496b8 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -29,6 +29,8 @@ export class SkillView extends CCComp { SConf:SkillConfig=null; sData:SDataCom=null; s_uuid:number=1001 + // 已命中目标追踪,防止重复伤害 + private hitTargets: Set = new Set(); start() { this.SConf = SkillSet[this.s_uuid] this.sData=this.ent.get(SDataCom) @@ -47,15 +49,23 @@ export class SkillView extends CCComp { } onBeginContact (seCol: Collider2D, oCol: Collider2D) { - if(oCol.group==this.group) return - if (!this.SConf) return; - if(this.SConf.EType!=EType.collision) return + const targetId = oCol.uuid; + if(this.hitTargets.has(targetId)) return; // 已经命中过,跳过 + // 记录命中目标 + + // if (!this.SConf) return; + // if(this.SConf.EType!=EType.collision) return + if(oCol.group == seCol.group) return let target = oCol.getComponent(HeroViewComp) if(target == null) return; let model=target.ent.get(HeroAttrsComp) - if(!model) return + console.log(`[skillView] 碰撞3`,oCol.group,seCol.group,model); + if(model == null) return if(model.is_dead) return - // console.log(`[skillView] 碰撞5[${this.sData.caster.box_group}][${this.sData.caster.ent.get(HeroAttrsComp).hero_name}][${this.sData.caster.ent.eid}]的[${this.group}] [${this.SConf.name}]碰撞了 [${oCol.group}][ ${oCol.getComponent(HeroViewComp).ent.get(HeroAttrsComp).hero_name}][${oCol.getComponent(HeroViewComp).ent.eid}]`); + if(this.sData.fac == model.fac) return; + // 检查是否已经命中过这个目标 + console.log(`[skillView] 碰撞5[${this.sData.caster.box_group}][${this.sData.caster.ent.get(HeroAttrsComp).hero_name}][${this.sData.caster.ent.eid}]的[${this.group}] [${this.SConf.name}]碰撞了 [${oCol.group}][ ${oCol.getComponent(HeroViewComp).ent.get(HeroAttrsComp).hero_name}][${oCol.getComponent(HeroViewComp).ent.eid}]`); + this.hitTargets.add(targetId); this.apply_damage(target) } @@ -115,6 +125,18 @@ export class SkillView extends CCComp { apply_damage(target:HeroViewComp,is_range:boolean=false){ if(target == null) return; if (!this.SConf) return; + + // 检查是否已经命中过这个目标(除非是范围伤害) + const targetId = target.node.uuid; + if(!is_range && this.hitTargets.has(targetId)) { + return; // 已经命中过,跳过 + } + + // 记录命中目标(除非是范围伤害) + if(!is_range) { + this.hitTargets.add(targetId); + } + console.log(`[skillView] 伤害 [${this.group}][${this.sData.caster.ent.get(HeroAttrsComp).hero_name}][${this.sData.caster.ent.eid}]的 [${this.SConf.name}]对 [${target.box_group}][ ${target.ent.get(HeroAttrsComp).hero_name}][${target.ent.eid}]`); // if(this.sData.hit_count > this.SConf.hit_num) return 不能超出 最大伤害数量 // 使用伤害队列系统处理伤害