refactor(hero): 重构护盾数值逻辑,使用快照最大值作为进度分母

1. 新增shield_max字段存储护盾获得时的快照值,作为护盾进度条固定分母
2. 修改add_shield方法为覆盖式设置护盾,新增注释说明设计原因
3. 移除HeroTopBarComp中冗余的NumberFormatter导入和动态创建的护盾数值标签
4. 重构护盾进度条更新逻辑,使用快照值计算进度,修复原进度条异常问题
This commit is contained in:
panFD
2026-09-13 13:40:32 +08:00
parent 3b744fc3f2
commit 4f749c9a81
2 changed files with 19 additions and 31 deletions

View File

@@ -40,6 +40,8 @@ export class HeroAttrsComp extends ecs.Comp {
speed: number = 100; // 基础移动速度
dis: number = 100; // 基础距离
shield: number = 0; // 当前护盾
/** 护盾获得时的快照值,作为护盾进度条分母(护盾为覆盖语义,分母不能随扣盾变化) */
shield_max: number = 0;
defense: number = 0; // 防御(除法递减模型减伤,见 getFinalDefense)
// ==================== 攻击属性 (补充) ====================
@@ -161,12 +163,16 @@ export class HeroAttrsComp extends ecs.Comp {
}
return addValue;
}
/**
* 设置护盾值(覆盖语义,不累加)。
*
* Why 覆盖而非累加:新护盾直接替换旧护盾,避免多源护盾无限叠加导致数值膨胀。
* @param value 新的护盾值(<=0 时视为清空护盾)
*/
add_shield(value: number) {
const oldShield = this.shield;
const addValue = Math.max(0, Math.floor(value));
if (addValue <= 0) return;
this.shield += addValue;
if (this.shield < 0) this.shield = 0;
this.shield = Math.max(0, Math.floor(value));
// 覆盖为新护盾时刷新快照分母;清空护盾时分母归零
this.shield_max = this.shield;
this.dirty_shield = true; // 标记护盾需要更新
}
add_hp_max(value: number) {
@@ -694,6 +700,7 @@ export class HeroAttrsComp extends ecs.Comp {
this.speed = 100;
this.dis = 100;
this.shield = 0;
this.shield_max = 0;
this.defense = 0;
// 重置新增属性