refactor(skill): 重构技能命中次数管理逻辑

- 在 SDataCom 组件中添加 max_hit_count 字段,用于存储最大可命中次数
- 移除 SkillView 中基于攻击帧的计数逻辑,改为使用 sData.max_hit_count 管理
- 在技能初始化时计算 max_hit_count(基础命中数 + 穿刺属性)
- 更新技能配置注释,将 hit_num 重命名为 hit_count 以保持命名一致性
This commit is contained in:
panw
2026-03-16 09:33:57 +08:00
parent 5634b49fee
commit 4e393b48b9
3 changed files with 32 additions and 25 deletions

View File

@@ -32,8 +32,6 @@ export class SkillView extends CCComp {
private collider: Collider2D = null; // 缓存碰撞体引用
private pendingDisableCollider: boolean = false;
private isDisposing: boolean = false;
private attackFrameCount: number = 0; // 攻击帧计数器
private maxAttackFrames: number = 1; // 最大攻击帧数,可配置
// 已命中目标追踪,防止重复伤害
init() {
this.SConf = SkillSet[this.s_uuid]
@@ -60,7 +58,12 @@ export class SkillView extends CCComp {
anim.play(anim.defaultClip.name);
}
}
this.attackFrameCount = 0; // 重置攻击帧计数
if (this.sData) {
this.sData.hit_count = 0;
const punctureCount = this.sData.Attrs?.[Attrs.puncture] ?? 0;
const baseHitCount = this.SConf?.hit ?? 0;
this.sData.max_hit_count = baseHitCount + punctureCount;
}
}
onBeginContact (seCol: Collider2D, oCol: Collider2D) {
if (!this.sData || !this.SConf) {
@@ -102,13 +105,12 @@ export class SkillView extends CCComp {
}
// //动画帧事件 atk 触发
public atk(args:any){
this.attackFrameCount++;
if (this.enable_collider_safely()) {
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] ${this.attackFrameCount}次攻击帧开启碰撞检测`);
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] 开启碰撞检测`);
this.scheduleOnce(() => {
if (!this.node || !this.node.isValid || this.isDisposing) return;
this.close_collider();
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] ${this.attackFrameCount}次攻击帧关闭碰撞检测`);
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf?.name}] 关闭碰撞检测`);
}, 0);
}
}
@@ -117,10 +119,10 @@ export class SkillView extends CCComp {
if(target == null) return;
// 安全检查:如果目标实体已不存在,直接返回
if (!target.ent) return;
if (!this.sData) return;
if (!this.SConf) return;
// 检查技能是否应该销毁
const max_hit_count=this.SConf.hit + this.sData.Attrs[Attrs.puncture]
if ( this.sData.hit_count >= max_hit_count ) {
if ( this.sData.hit_count >= this.sData.max_hit_count ) {
this.close_collider()
return
}
@@ -141,6 +143,9 @@ export class SkillView extends CCComp {
// 更新技能命中次数
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) &&