fix(skill): 添加命中目标追踪防止重复伤害
添加 hitTargets Set 来追踪已命中目标,避免技能对同一目标造成多次伤害。同时优化碰撞检测逻辑,移除不必要的条件检查。
This commit is contained in:
@@ -29,6 +29,8 @@ export class SkillView extends CCComp {
|
||||
SConf:SkillConfig=null;
|
||||
sData:SDataCom=null;
|
||||
s_uuid:number=1001
|
||||
// 已命中目标追踪,防止重复伤害
|
||||
private hitTargets: Set<string> = 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 不能超出 最大伤害数量
|
||||
// 使用伤害队列系统处理伤害
|
||||
|
||||
Reference in New Issue
Block a user