fix(技能): 修复瞬时技能碰撞检测关闭时机
移除基于 pendingClose 的延迟关闭逻辑,改为在攻击帧中立即调度关闭碰撞检测。 这避免了同一帧内对同一目标造成多次伤害的问题,并简化了时间类型技能的处理逻辑。
This commit is contained in:
@@ -9,7 +9,6 @@ export class StimeDataComp extends ecs.Comp {
|
|||||||
elapsedTime: number = 0;
|
elapsedTime: number = 0;
|
||||||
hitInterval: number = 0;
|
hitInterval: number = 0;
|
||||||
hitElapsed: number = 0;
|
hitElapsed: number = 0;
|
||||||
pendingClose: boolean = false;
|
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.s_uuid = 0;
|
this.s_uuid = 0;
|
||||||
@@ -17,7 +16,6 @@ export class StimeDataComp extends ecs.Comp {
|
|||||||
this.elapsedTime = 0;
|
this.elapsedTime = 0;
|
||||||
this.hitInterval = 0;
|
this.hitInterval = 0;
|
||||||
this.hitElapsed = 0;
|
this.hitElapsed = 0;
|
||||||
this.pendingClose = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,10 +33,6 @@ export class STimeSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
if (!timeComp || !skillView) return;
|
if (!timeComp || !skillView) return;
|
||||||
const conf = SkillSet[timeComp.s_uuid];
|
const conf = SkillSet[timeComp.s_uuid];
|
||||||
if (!conf || conf.EType !== EType.timeEnd) return;
|
if (!conf || conf.EType !== EType.timeEnd) return;
|
||||||
if (timeComp.pendingClose) {
|
|
||||||
skillView.close_collider();
|
|
||||||
timeComp.pendingClose = false;
|
|
||||||
}
|
|
||||||
if (timeComp.totalTime <= 0) {
|
if (timeComp.totalTime <= 0) {
|
||||||
skillView.close_collider();
|
skillView.close_collider();
|
||||||
entity.destroy();
|
entity.destroy();
|
||||||
@@ -46,10 +40,9 @@ export class STimeSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
|||||||
}
|
}
|
||||||
timeComp.elapsedTime += this.dt;
|
timeComp.elapsedTime += this.dt;
|
||||||
timeComp.hitElapsed += this.dt;
|
timeComp.hitElapsed += this.dt;
|
||||||
if (timeComp.hitInterval > 0 && timeComp.hitElapsed >= timeComp.hitInterval && !timeComp.pendingClose) {
|
if (timeComp.hitInterval > 0 && timeComp.hitElapsed >= timeComp.hitInterval) {
|
||||||
timeComp.hitElapsed -= timeComp.hitInterval;
|
timeComp.hitElapsed -= timeComp.hitInterval;
|
||||||
skillView.atk(null);
|
skillView.atk(null);
|
||||||
timeComp.pendingClose = true;
|
|
||||||
}
|
}
|
||||||
if (timeComp.elapsedTime >= timeComp.totalTime) {
|
if (timeComp.elapsedTime >= timeComp.totalTime) {
|
||||||
skillView.close_collider();
|
skillView.close_collider();
|
||||||
|
|||||||
@@ -105,8 +105,12 @@ export class SkillView extends CCComp {
|
|||||||
this.attackFrameCount++;
|
this.attackFrameCount++;
|
||||||
if (this.enable_collider_safely()) {
|
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.attackFrameCount}次攻击帧开启碰撞检测`);
|
||||||
|
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}次攻击帧关闭碰撞检测`);
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//伤害应用
|
//伤害应用
|
||||||
apply_damage(target:HeroViewComp,is_range:boolean=false){
|
apply_damage(target:HeroViewComp,is_range:boolean=false){
|
||||||
@@ -120,13 +124,6 @@ export class SkillView extends CCComp {
|
|||||||
this.close_collider()
|
this.close_collider()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 对于非持续碰撞类型的技能,在造成伤害后立即关闭碰撞检测
|
|
||||||
// 这样可以避免同一帧内的重复伤害
|
|
||||||
if(this.SConf.EType !== EType.collision && this.collider) {
|
|
||||||
this.close_collider();
|
|
||||||
mLogger.log(this.debugMode, 'SkillView', `[SkillView] [${this.SConf.name}] 伤害后关闭碰撞检测`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 安全获取名称,防止实体销毁导致的空指针异常
|
// 安全获取名称,防止实体销毁导致的空指针异常
|
||||||
const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? "未知施法者";
|
const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? "未知施法者";
|
||||||
const targetName = target.ent.get(HeroAttrsComp)?.hero_name ?? "未知目标";
|
const targetName = target.ent.get(HeroAttrsComp)?.hero_name ?? "未知目标";
|
||||||
|
|||||||
Reference in New Issue
Block a user