feat(skill): 优化技能碰撞检测逻辑并添加攻击帧计数

- 在SkillView中缓存碰撞体引用并添加攻击帧计数器
- 实现攻击帧事件中动态开启碰撞检测
- 非持续碰撞类型技能在造成伤害后立即关闭碰撞检测
- 清理资源时取消所有定时器
- 调整技能预制体碰撞体位置和大小
- 注释掉Main.ts中的物理调试绘制代码
This commit is contained in:
2025-11-03 14:47:53 +08:00
parent 2d5653e0e4
commit 1a45e91f1a
3 changed files with 237 additions and 44 deletions

View File

@@ -3,13 +3,9 @@ import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ec
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { HeroViewComp } from "../hero/HeroViewComp";
import { DTType, EType, RType, SkillConfig, SkillSet } from "../common/config/SkillSet";
import { BoxSet, FacSet } from "../common/config/GameSet";
import { SDataCom } from "./SDataCom";
import { SMoveDataComp } from "./SMoveComp";
import { Attrs } from "../common/config/HeroAttrs";
import { MonMoveComp } from "../hero/MonMove";
import { HeroAttrsComp } from "../hero/HeroAttrsComp";
import { HeroMoveComp } from "../hero/HeroMove";
import { DamageQueueHelper } from "../hero/DamageQueueComp";
const { ccclass, property } = _decorator;
@@ -29,16 +25,19 @@ export class SkillView extends CCComp {
SConf:SkillConfig=null;
sData:SDataCom=null;
s_uuid:number=1001
private collider: Collider2D = null; // 缓存碰撞体引用
private attackFrameCount: number = 0; // 攻击帧计数器
private maxAttackFrames: number = 1; // 最大攻击帧数,可配置
// 已命中目标追踪,防止重复伤害
start() {
this.SConf = SkillSet[this.s_uuid]
this.sData=this.ent.get(SDataCom)
this.anim=this.node.getComponent(Animation)
this.node.active = true;
let collider = this.getComponent(Collider2D);
if(collider) {
collider.group = this.group;
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
this.collider = this.getComponent(Collider2D);
if(this.collider) {
this.collider.group = this.group;
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
}
if(this.node.getComponent(Animation)){
let anim = this.node.getComponent(Animation);
@@ -78,7 +77,15 @@ export class SkillView extends CCComp {
}
}
// //动画帧事件 atk 触发
// public atk(args:any){
public atk(args:any){
this.attackFrameCount++;
// 开启碰撞检测
if(this.collider) {
this.collider.enabled = true;
console.log(`[SkillView] [${this.SConf?.name}] 第${this.attackFrameCount}次攻击帧开启碰撞检测`);
}
// let dis=this.node.getComponent(UITransform).width/2
// let enemys:any=[]
// if( this.sData.fac==FacSet.HERO){
@@ -123,12 +130,18 @@ export class SkillView extends CCComp {
// });
// }
// }
// }
}
//伤害应用
apply_damage(target:HeroViewComp,is_range:boolean=false){
if(target == null) return;
if (!this.SConf) return;
// 对于非持续碰撞类型的技能,在造成伤害后立即关闭碰撞检测
// 这样可以避免同一帧内的重复伤害
if(this.SConf.EType !== EType.collision && this.collider) {
this.collider.enabled = false;
console.log(`[SkillView] [${this.SConf.name}] 伤害后关闭碰撞检测`);
}
// 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 不能超出 最大伤害数量
// 使用伤害队列系统处理伤害
@@ -152,10 +165,12 @@ export class SkillView extends CCComp {
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
const collider = this.getComponent(Collider2D);
if (collider) {
collider.off(Contact2DType.BEGIN_CONTACT);
}
// 清理碰撞体事件监听
if (this.collider) {
this.collider.off(Contact2DType.BEGIN_CONTACT);
}
// 取消所有定时器
this.unscheduleAllCallbacks();
this.node.destroy();
}
}