@@ -100,7 +100,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
* - CRITICAL_DMG: 暴击伤害加成
* - BACK_CHANCE: 击退概率
* - HIT: 命中率(用于闪避计算)
* - AP/MAP: 攻击力(基础伤害计算)
* - AP 攻击力(基础伤害计算)
*
* ✅ 正确使用被攻击者属性( TAttrsComp - 实时):
* - DODGE: 闪避率(用于闪避计算)
@@ -147,8 +147,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
return reDate ;
}
// 暴击判定
// 使用施法者的暴击率属性( damageEvent.Attrs 快照),- 被攻击者的暴击抗性属性TAttrsComp.Attrs[Attrs.CRITICAL_RESIST ]
const isCrit = this . checkChance ( damageEvent . Attrs [ Attrs . CRITICAL ] - TAttrsComp . Attrs [ Attrs . CRITICAL_RESIST ] ) ;
// 使用施法者的暴击率属性( damageEvent.Attrs 快照),- 被攻击者的暴击抗性属性TAttrsComp.Attrs[Attrs.CRITICAL_RES]
const isCrit = this . checkChance ( damageEvent . Attrs [ Attrs . CRITICAL ] - TAttrsComp . Attrs [ Attrs . CRITICAL_RES ] ) ;
// 计算基础伤害
let damage = this . dmgCount ( damageEvent , TAttrsComp ) ;
if ( this . debugMode ) console . log ( "[HeroAtkSystem] dmgCount" , damage )
@@ -237,18 +237,12 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
/**
* 详细伤害计算核心方法
*
* 这是整个战斗系统中最核心的伤害计算方法,负责根据施法者属性、目标属性和技能配置
* 计算最终的基础伤害值。该方法采用多阶段的伤害计算公式,综合考虑了物理和魔法伤害
* 以及各种属性加成和抗性减免。
*
* 计算流程:
* 1. 获取技能配置
* 2. 计算原始物理伤害和魔法伤害
* 3. 应用防御 减免
* 4. 应用物理/魔法攻击力和抗性修正
* 5. 应用元素属性加成和抗性修正
* 6. 应用最终伤害减免
* 7. 确保伤害值非负
* 2. 计算原始物理伤害
* 3. 应用最终伤害 减免
* 4. 确保伤害值非负
*
* @param CAttrs 施法者属性快照对象,包含所有攻击力、属性加成等战斗属性
* @param TAttrs 目标属性对象,包含所有防御力、抗性等防御属性
@@ -256,9 +250,7 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
* @returns 经过完整计算后的最终伤害值(未考虑暴击)
*
* @important 注意事项:
* - 此方法计算的是基础伤害,暴击计算在外部处理
* - 所有除法和乘法计算后都进行取整操作,确保游戏中的伤害值为整数
* - 元素伤害只应用于魔法伤害部分
*/
private dmgCount ( damageEvent :DamageEvent , TAttrsComp :HeroAttrsComp ) {
// 1. 获取技能配置 - 如果技能不存在, 直接返回0伤害
@@ -270,58 +262,15 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
// 2. 计算原始物理伤害和魔法伤害
// 物理伤害基础值 = 技能物理倍率 * (施法者物理攻击力 + 额外伤害) / 100 * 额外伤害比例
let apBase = ( sConf . ap || 0 ) * ( CAttrs [ Attrs . AP ] + damageEvent . ext_dmg ) / 100 * damageEvent . dmg_ratio ;
// 魔法伤害基础值 = 技能魔法倍率 * ( 施法者魔法 攻击力 + 额外伤害) / 100 * 额外伤害比例
let mapBase = ( sConf . map || 0 ) * ( CAttrs [ Attrs . MAP ] + damageEvent . ext_dmg ) / 100 * damageEvent . dmg_ratio ;
if ( this . debugMode ) console . log ( ` [HeroAtkSystem] 物理伤害基础值: ${ apBase } , 技能ap= ${ sConf . ap } ,施法者物理攻击力: ${ CAttrs [ Attrs . AP ] } , 魔法伤害基础值: ${ mapBase } 技能map= ${ sConf . map }
if ( this . debugMode ) console . log ( ` [HeroAtkSystem] 物理伤害基础值: ${ apBase } , 技能ap= ${ sConf . ap } , 施法者物理 攻击力: ${ CAttrs [ Attrs . AP ] } ,}
额外伤害: ${ damageEvent . ext_dmg } , 额外伤害比例: ${ damageEvent . dmg_ratio } ` ) ;
// 3. 获取目标防御属性
const def = ( TAttrs [ Attrs . DEF ] || 0 ) ; // 目标物理防御
const mdef = ( TAttrs [ Attrs . MDEF ] || 0 ) ; // 目标魔法防御
// 4. 计算防御减免系数(采用公式:防御/(防御+常数), 确保防御值不会导致伤害减到0)
const apRed = def / ( def + FightSet . DEF_C ) ; // 物理防御减免系数
const mapRed = mdef / ( mdef + FightSet . MDEF_C ) ; // 魔法防御减免系数
// 5. 应用防御减免到基础伤害,向下取整
let apAfter = Math . floor ( apBase * ( 1 - apRed ) ) ; // 物理伤害 - 防御减免
let mapAfter = Math . floor ( mapBase * ( 1 - mapRed ) ) ; // 魔法伤害 - 防御减免
if ( this . debugMode ) console . log ( ` [HeroAtkSystem] 物理伤害基础值: ${ apBase } , 物理伤害 - 防御减免: ${ apAfter } 魔法伤害基础值: ${ mapBase } , 魔法伤害 - 防御减免: ${ mapAfter } ` ) ;
// 6. 应用物理/魔法攻击力和抗性修正
// 物理伤害修正:基础伤害 * (1 + 物理攻击力加成%) * (1 - 目标物理抗性%)
apAfter = this . applyPR ( apAfter , CAttrs [ Attrs . PHYS_POWER ] || 0 , TAttrs [ Attrs . PHYS_RES ] || 0 ) ;
// 魔法伤害修正:基础伤害 * (1 + 魔法攻击力加成%) * (1 - 目标魔法抗性%)
mapAfter = this . applyPR ( mapAfter , CAttrs [ Attrs . MAGIC_POWER ] || 0 , TAttrs [ Attrs . MAGIC_RES ] || 0 ) ;
if ( this . debugMode ) console . log ( ` [HeroAtkSystem] 物理伤害修正后: ${ apAfter } 魔法伤害修正后: ${ mapAfter } ` ) ;
// 7. 根据技能元素类型,应用元素属性加成和抗性修正
switch ( sConf . DType ) {
case DType . ICE :
// 冰系伤害修正:魔法伤害 * (1 + 冰系攻击力加成%) * (1 - 目标冰系抗性%)
mapAfter = this . applyPR ( mapAfter , CAttrs [ Attrs . ICE_POWER ] || 0 , TAttrs [ Attrs . ICE_RES ] || 0 ) ;
break ;
case DType . FIRE :
// 火系伤害修正:魔法伤害 * (1 + 火系攻击力加成%) * (1 - 目标火系抗性%)
mapAfter = this . applyPR ( mapAfter , CAttrs [ Attrs . FIRE_POWER ] || 0 , TAttrs [ Attrs . FIRE_RES ] || 0 ) ;
break ;
case DType . WIND :
// 风系伤害修正:魔法伤害 * (1 + 风系攻击力加成%) * (1 - 目标风系抗性%)
mapAfter = this . applyPR ( mapAfter , CAttrs [ Attrs . WIND_POWER ] || 0 , TAttrs [ Attrs . WIND_RES ] || 0 ) ;
break ;
}
if ( this . debugMode ) console . log ( ` [HeroAtkSystem] 物理伤害修正后: ${ apAfter } 元素伤害修正后: ${ mapAfter } ` ) ;
// 8. 计算最终总伤害(物理伤害 + 魔法伤害)
let total = apAfter + mapAfter ;
//9.1 易伤
//3.1 易伤
let DMG_INVUL = TAttrs [ Attrs . DMG_INVUL ] || 0
//9 .2 免伤 属性免伤+天赋免伤
let DMG_RED = TAttrs [ Attrs . DMG_RED ] || 0 + TAttrsComp . useCountValTal ( Attrs . DMG_RED ) ;
// 10 . 确保伤害值非负,返回最终伤害
total = Math . max ( 0 , total ) ;
//11 . 易伤减免 免伤属性免伤+天赋免伤
//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 ) ;