fix(技能): 确保技能持续时间至少为1帧并添加攻击间隔
将技能总时间的最小值从0改为1,避免除零错误。新增hitInterval字段控制攻击间隔,默认至少0.5秒。在STimeSystem中添加周期性攻击逻辑,通过pendingClose标志管理碰撞器状态。
This commit is contained in:
@@ -7,11 +7,17 @@ export class StimeDataComp extends ecs.Comp {
|
||||
s_uuid: number = 0;
|
||||
totalTime: number = 0;
|
||||
elapsedTime: number = 0;
|
||||
hitInterval: number = 0;
|
||||
hitElapsed: number = 0;
|
||||
pendingClose: boolean = false;
|
||||
|
||||
reset() {
|
||||
this.s_uuid = 0;
|
||||
this.totalTime = 0;
|
||||
this.elapsedTime = 0;
|
||||
this.hitInterval = 0;
|
||||
this.hitElapsed = 0;
|
||||
this.pendingClose = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +35,22 @@ export class STimeSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
|
||||
if (!timeComp || !skillView) return;
|
||||
const conf = SkillSet[timeComp.s_uuid];
|
||||
if (!conf || conf.EType !== EType.timeEnd) return;
|
||||
if (timeComp.pendingClose) {
|
||||
skillView.close_collider();
|
||||
timeComp.pendingClose = false;
|
||||
}
|
||||
if (timeComp.totalTime <= 0) {
|
||||
skillView.close_collider();
|
||||
entity.destroy();
|
||||
return;
|
||||
}
|
||||
timeComp.elapsedTime += this.dt;
|
||||
timeComp.hitElapsed += this.dt;
|
||||
if (timeComp.hitInterval > 0 && timeComp.hitElapsed >= timeComp.hitInterval && !timeComp.pendingClose) {
|
||||
timeComp.hitElapsed -= timeComp.hitInterval;
|
||||
skillView.atk(null);
|
||||
timeComp.pendingClose = true;
|
||||
}
|
||||
if (timeComp.elapsedTime >= timeComp.totalTime) {
|
||||
skillView.close_collider();
|
||||
entity.destroy();
|
||||
|
||||
@@ -150,7 +150,8 @@ export class Skill extends ecs.Entity {
|
||||
if (!sTimeCom) sTimeCom = this.add(StimeDataComp);
|
||||
sTimeCom.reset();
|
||||
sTimeCom.s_uuid = s_uuid;
|
||||
sTimeCom.totalTime = Math.max(0, config.time ?? 0);
|
||||
sTimeCom.totalTime = Math.max(1, config.time ?? 0);
|
||||
sTimeCom.hitInterval = Math.max(0.5, config.hitcd || 0);
|
||||
} else {
|
||||
const sTimeCom = this.get(StimeDataComp);
|
||||
if (sTimeCom) this.remove(StimeDataComp);
|
||||
|
||||
Reference in New Issue
Block a user