fix(SkillView): 提前检查命中次数并立即关闭碰撞器
在碰撞检测开始时立即检查命中次数,达到上限后立即关闭碰撞器并返回,避免后续不必要的逻辑执行。同时移除后续重复的命中次数检查和关闭碰撞器逻辑,简化代码结构。
This commit is contained in:
@@ -74,6 +74,14 @@ export class SkillView extends CCComp {
|
||||
mLogger.log(this.debugMode, 'SkillView', `[skillView] 碰撞1 [${this.sData.caster.box_group}][${casterName}][${casterEid}]的[${seCol.group}]:[${this.SConf.name}][${this.ent.eid}]碰撞了 [${oCol.group}]:[ ${targetName}][${targetEid}]`);
|
||||
if (oCol.group === seCol.group) return;
|
||||
if (this.pendingDisableCollider) return;
|
||||
if (this.sData.hit_count >= this.sData.max_hit_count) {
|
||||
this.close_collider();
|
||||
return;
|
||||
}
|
||||
this.sData.hit_count++;
|
||||
if (this.sData.hit_count >= this.sData.max_hit_count) {
|
||||
this.close_collider();
|
||||
}
|
||||
// 不是 HeroViewComp,直接忽略
|
||||
if (!targetView) return;
|
||||
// 🔥 方案A:防御性检查 - 在获取model前强制检查ent是否存在
|
||||
@@ -116,11 +124,6 @@ export class SkillView extends CCComp {
|
||||
if (!target.ent) return;
|
||||
if (!this.sData) return;
|
||||
if (!this.SConf) return;
|
||||
// 检查技能是否应该销毁
|
||||
if ( this.sData.hit_count >= this.sData.max_hit_count ) {
|
||||
this.close_collider()
|
||||
return
|
||||
}
|
||||
// 安全获取名称,防止实体销毁导致的空指针异常
|
||||
const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? "未知施法者";
|
||||
const targetName = target.ent.get(HeroAttrsComp)?.hero_name ?? "未知目标";
|
||||
@@ -135,12 +138,6 @@ export class SkillView extends CCComp {
|
||||
this.sData.ext_dmg,
|
||||
this.sData.dmg_ratio,
|
||||
);
|
||||
|
||||
// 更新技能命中次数
|
||||
this.sData.hit_count++
|
||||
if (this.sData.hit_count >= this.sData.max_hit_count) {
|
||||
this.close_collider();
|
||||
}
|
||||
if (
|
||||
(this.SConf.DTType != DTType.range) &&
|
||||
(this.SConf.EType != EType.animationEnd) &&
|
||||
|
||||
Reference in New Issue
Block a user