feat(skill&shield): 实现护盾持续时间功能,调整魔法盾冷却

1.  为护盾技能添加duration配置,支持永久/限时护盾
2.  新增护盾倒计时逻辑,到期自动清空护盾
3.  调整英雄6301魔法盾的冷却时间为10秒,新增7秒持续时长配置
4.  重构HeroAttrsComp,新增护盾持续时间字段与清空护盾方法
This commit is contained in:
panFD
2026-09-13 14:04:00 +08:00
parent 4f749c9a81
commit ed9232cf0b
5 changed files with 46 additions and 10 deletions

View File

@@ -28,18 +28,34 @@ const TICK_STEP = 0.1;
export class BuffSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate {
private timer = new Timer(TICK_STEP);
// HeroAttrsComp 可选,用于 DoT/HoT 的血量结算与护盾倒计时
private processShieldTimer(attrsComp: HeroAttrsComp | null): void {
if (!attrsComp) return;
// 永久护盾(duration<=0)不参与倒计时
if (attrsComp.shield_duration <= 0) return;
attrsComp.shield_duration -= TICK_STEP;
if (attrsComp.shield_duration <= 0) {
attrsComp.clear_shield();
mLogger.log(DEBUG, "BuffSystem", `护盾到期: ${attrsComp.hero_name}(eid:${attrsComp.ent?.eid ?? "-"}) 护盾已清空`);
}
}
// filter 改为 allOf(HeroAttrsComp):护盾倒计时挂在 HeroAttrsComp 上,
// 若按 BuffComp 过滤,无 buff 的实体不会被遍历,护盾到期清空会失效
filter(): ecs.IMatcher {
return ecs.allOf(BuffComp);
return ecs.allOf(HeroAttrsComp);
}
update(e: ecs.Entity): void {
if (!this.timer.update(this.dt)) return;
const buffComp = e.get(BuffComp);
if (!buffComp) return;
// HeroAttrsComp 必有(filter 保证),用于 DoT/HoT 血量结算与护盾倒计时
const attrsComp = e.get(HeroAttrsComp);
this.processShieldTimer(attrsComp);
// HeroAttrsComp 可选,用于 DoT/HoT 的血量结算
const attrsComp = e.has(HeroAttrsComp) ? e.get(HeroAttrsComp) : null;
// BuffComp 可选:无 buff 时仅做护盾倒计时
const buffComp = e.has(BuffComp) ? e.get(BuffComp) : null;
if (!buffComp) return;
// ---- 处理所有 buff 层 ----
let anyChanged = false;

View File

@@ -42,6 +42,8 @@ export class HeroAttrsComp extends ecs.Comp {
shield: number = 0; // 当前护盾
/** 护盾获得时的快照值,作为护盾进度条分母(护盾为覆盖语义,分母不能随扣盾变化) */
shield_max: number = 0;
/** 护盾剩余持续时间(秒),<=0 表示永久护盾;由 BuffSystem 定时递减,归零时清空护盾 */
shield_duration: number = 0;
defense: number = 0; // 防御(除法递减模型减伤,见 getFinalDefense)
// ==================== 攻击属性 (补充) ====================
@@ -168,13 +170,27 @@ export class HeroAttrsComp extends ecs.Comp {
*
* Why 覆盖而非累加:新护盾直接替换旧护盾,避免多源护盾无限叠加导致数值膨胀。
* @param value 新的护盾值(<=0 时视为清空护盾)
* @param duration 护盾持续时间(秒),<=0 或不传表示永久护盾;到期由 BuffSystem 清空
*/
add_shield(value: number) {
add_shield(value: number, duration: number = 0) {
this.shield = Math.max(0, Math.floor(value));
// 覆盖为新护盾时刷新快照分母;清空护盾时分母归零
this.shield_max = this.shield;
this.shield_duration = Math.max(0, duration);
this.dirty_shield = true; // 标记护盾需要更新
}
/**
* 清空护盾(护盾到期或外部强制驱散时调用)。
* 直接置零并打脏标记,视图层据此隐藏护盾条与特效。
*/
clear_shield() {
if (this.shield <= 0) return;
this.shield = 0;
this.shield_max = 0;
this.shield_duration = 0;
this.dirty_shield = true;
}
add_hp_max(value: number) {
this.hp_max += value
this.hp += value
@@ -701,6 +717,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.dis = 100;
this.shield = 0;
this.shield_max = 0;
this.shield_duration = 0;
this.defense = 0;
// 重置新增属性

View File

@@ -575,7 +575,8 @@ export class SCastSystem extends ecs.ComblockSystem implements ecs.ISystemUpdate
} else if (kind === SkillKind.Shield && sAp !== 0) {
// 护盾值 = ap% × 施法者最终最大生命(getFinalHpMax 含驻场光环与计时 buff 加成)
const addShield = Math.max(0, Math.floor(_cAttrsComp.getFinalHpMax() * sAp / 100));
model.add_shield(addShield);
// shield_duration 缺省/<=0 表示永久护盾
model.add_shield(addShield, config.shield_duration ?? 0);
}
if (config.buff_type !== undefined) {