refactor(战斗系统): 修改防御属性为百分比类型并优化伤害计算

- 将物理防御属性从数值型改为百分比型
- 使用 add_hp 方法替代直接修改 hp 以触发 UI 更新
- 重构伤害计算公式,明确防御减免和易伤的计算逻辑
- 调整测试英雄配置,统一使用远程攻击技能
This commit is contained in:
walkpan
2026-01-17 14:38:22 +08:00
parent d0f88708c6
commit b2c5ffa047
3 changed files with 37 additions and 28 deletions

View File

@@ -178,7 +178,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
}
if (damage <= 0) return reDate;
TAttrsComp.hp -= damage; // 应用伤害到数据层
// TAttrsComp.hp -= damage; // 应用伤害到数据层
TAttrsComp.add_hp(-damage, true); // 使用 add_hp 以触发 dirty_hp 和 UI 更新
// 受击者产生击退效果
// if (damage > 0 && targetView) {
@@ -257,7 +258,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
// 计算反伤伤害
let thornsDmg=Math.floor(thornsDamage*damage/100);
// 应用反伤伤害到数据层
CAttrs.hp -= thornsDmg;
// CAttrs.hp -= thornsDmg;
CAttrs.add_hp(-thornsDmg, true);
CAttrs.atked_count++;
let CView=caster.get(HeroViewComp);
// ✅ 触发视图层表现(伤害数字、受击动画、后退)
@@ -326,16 +328,23 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
let apBase = (sConf.ap||0)*(CAttrs[Attrs.AP]+damageEvent.ext_dmg)/100*damageEvent.dmg_ratio;
if (this.debugMode) console.log(`[HeroAtkSystem] 物理伤害基础值: ${apBase}, 技能ap=${sConf.ap},施法者物理攻击力: ${CAttrs[Attrs.AP]},}
额外伤害:${damageEvent.ext_dmg}, 额外伤害比例:${damageEvent.dmg_ratio}`);
//3.1 易伤
// 易伤
let DMG_INVUL = TAttrs[Attrs.DMG_INVUL]||0
//3.2 免伤 属性免伤+天赋免伤
let DMG_RED =TAttrs[Attrs.DEF]||0+TAttrsComp.useCountValTal(Attrs.DEF);
//4. 确保伤害值非负,返回最终伤害
let total = Math.max(0,apBase);
//5. 易伤减免 免伤属性免伤+天赋免伤
total = Math.floor(total * (1 + ((DMG_INVUL-DMG_RED)/100)));
if (this.debugMode) console.log(`[HeroAtkSystem] 易伤减免后: ${total}`);
return Math.max(0,total);
// 免伤 属性免伤+天赋免伤
let DMG_RED = (TAttrs[Attrs.DEF]||0) + TAttrsComp.useCountValTal(Attrs.DEF);
// 4. 确保伤害值非负
let total = Math.max(0, apBase);
// 5. 应用防御减免 (百分比型)
// 计算公式:基础伤害 * (1 + (易伤% - 免伤%) / 100)
// 易伤增加伤害,免伤减少伤害
let damageRatio = 1 + (DMG_INVUL - DMG_RED) / 100;
damageRatio = Math.max(0, damageRatio); // 确保伤害系数不为负即最多减免至0伤害
total = Math.floor(total * damageRatio);
if (this.debugMode) console.log(`[HeroAtkSystem] 最终伤害: ${total} (Base: ${apBase}, Def: ${DMG_RED}%, Invul: ${DMG_INVUL}%, Ratio: ${damageRatio})`);
return total;
}
/**