伤害算法详解

录入:EvilP 作者: 翻译:
录入时间:2026-10-21 23:33:21 最后修改时间:2026-10-27 12:11:07
报错页面:传送门

可以下载同本站资料里的翻译版本的 汉化文件 配合使用。

如果因为网站带宽原因经常卡页面加载,可以尝试用 速查模式并开启缓存。


取整算法:

  • 银行家取整:既四舍六入五取偶法(Round-half-to-even),尾数小于五则舍去,尾数大于五则进位,尾数等于五时看前一位,前一位是奇数则进位,前一位是偶数则舍去,使结果末位为偶数。
  • 向下取整:取不大于该数的最大整数,即直接去掉小数部分。
  • 向上取整:取不小于该数的最小整数,即只要有小数部分就进位。
  • 如果不是精细计算,可以忽略取整部分,基本只有少量结果会在取随机伤害前的最终取整时会有 1 点的误差。

攻防修正值

  • 差值 = 攻击 − 防御
  • 每点差值提供递减的百分比:
    • 第 1 点 +4.00%;
    • 第 2 点 +3.96%;
    • 第 3 点 +3.92%……
    • 每点递减 0.04%,直到 0;
    • 差值超过 100 后不再影响伤害。
  • 系数 = 1 + 0.0002*差值*(201-差值);
  • 差值为 100 时,系数最大值 = 202%,也就是 2.02;
  • 差值 > 0 时:倍率 = 1 + 系数 | 差值 < 0 时:倍率 = 1 / (1 + 系数)
  • 对应到倍率:1 + 2.02 = 3.02x 和 1 ÷ (1 + 2.02) ≈ 0.331x;

攻防修正值模拟计算器

Δ Delta = ATK − DEF 0 系数 / Coefficient: 0.00%
伤害倍率 / A/D Modifier 1.00x
旧版倍率 (20 + ATK) / (20 + DEF) 1.0000

兵种的攻击、防御、伤害

  • 兵种的攻击、防御、基础伤害除了 statDmgMult 参数以外的计算过程不在此论述

基础伤害计算流程:

  • DMG = 基础伤害
  • DMG = DMG × 基础伤害倍数,相关参数:statDmgMult
  • DMG = DMG × 兵种数量
  • DMG = DMG + 能量相关伤害,魅魔的「无尽苦难 」
  • DMG = DMG × 攻击方的全类增伤,相关参数:outAllDmgMod
  • DMG = 向下取整(DMG)

攻击方标签增伤计算流程:

  • DMG = DMG × ( 1 + 标签增伤 )
  • DMG = 银行家取整(DMG),带标签的增伤,同标签相加,异标签相乘。参数范例:
    • outDmgMods-normal_damage
    • outDmgMods-basic_attack
    • outDmgMods-melee_attack
    • outDmgMods-shoot_attack
    • outDmgMods-range_attack

目标相关附加和修正流程:

  • DMG = DMG × ( 1 + 兵种阶级差修正 ),相关参数:
    • 寄体「推翻强者!」:damagePerDeltaLevel
    • 虫巢女王「碾碎弱者!」:damagePerDeltaLevelLower
  • DMG = DMG × ( 1 + 召唤物伤害加成 ),如果被攻击目标是召唤生物
    • 相关参数:summonDamagePercent
  • DMG = DMG × ( 1 + 城墙远程射击减伤 ),如果满足城防射击条件
  • DMG = DMG × ( 1 + 标签减伤 ),带标签的减伤,同标签相加,异标签相乘,至少为 10%。参数范例:
    • inDmgMods-normal_damage
    • inDmgMods-basic_attack
    • inDmgMods-melee_attack
    • inDmgMods-shoot_attack
    • inDmgMods-range_attack
  • DMG = DMG × ( 1 + 顶级掠食者的 50% )
  • DMG = DMG × 攻防修正值
  • DMG = DMG × 射程影响
  • DMG = DMG × (1 + 移动格数 × 每格增伤),骑兵「马术加成 」
  • DMG = DMG × 防御方的全类减伤,相关参数:inAllDmgMod
  • DMG = 银行家取整(DMG)

获取伤害范围:

  • 分别计算最小伤害(DMG.Min)和最大伤害(DMG.Max),计算结果向下取整

伤害范围内随机取值流程:

  • 像基础伤害的最大值和最小值相同的兵种,以及受只造成最小伤害(alwaysMinDmg )或者只造成最大伤害(alwaysMaxDmg )效果影响的不进行随机取值
  • 生成一个带正态倾向的随机数 r,用它均匀地落在区间 [DMG.Min, DMG.Max] 上选一个整数 DMG.K,具体流程:
    • 1、生成 r(最多尝试10次)
      • u1,u2 = 随机源的两次 NextDouble(),从随机源取两个双精度浮点数:u1、u2
      • 用 Box-Muller 变换算出一个标准正态随机数 z:z = sqrt(-2 × log(u1)) × cos(u2 × 2π)
      • 把 z 缩放平移成 r:r = z × 0.23 + 0.5。也就是均值 0.5、标准差 0.23 的正态分布
      • 检查 r 是否落在 [0,1) 内:是就采用并停止;否则丢弃,重新尝试
      • 如果 10 次都没得到合格的 r,就退回用一次普通 NextDouble() 作为 r
    • 2、用 r 选整数 DMG.K
      • 计算区间宽度:DMG.Max + 1 - DMG.Min(注意是 DMG.Max + 1,因为 DMG.K 的取值是 DMG.Min 到 DMG.Max 闭区间,DMG.Max - DMG.Min + 1 个整数)
      • 用 r 乘宽度,得到 [0, 宽度) 内的一个浮点数
      • 向下取整,得到一个 0 到 宽度 -1 的整数偏移
      • 加上 DMG.Min,得到 DMG.K,即 DMG.Min 到 DMG.Max 之间的整数
      • 最后用原生边界钳制把 DMG.K 限制在 [DMG.Min, DMG.Max + 1) 内,确保不越界

幸运判定伤害:

  • DMG = DMG.K × 幸运修正
  • DMG = 向上取整(DMG)
  • DMG = max(1, DMG),即 DMG 最低为 1

Rounding Methods:

  • Banker's Rounding: also known as round-half-to-even. If the fractional part is less than five, round down; if greater than five, round up; if exactly five, look at the preceding digit — round up if it is odd, round down if it is even, so that the final digit of the result is even.
  • Round Down (Floor): take the largest integer not greater than the number, i.e., simply discard the fractional part.
  • Round Up (Ceiling): take the smallest integer not less than the number, i.e., round up whenever there is any fractional part.
  • If you are not doing precise calculations, the rounding steps can be ignored. In practice, only a small number of results will differ by 1 point, at the final rounding before random damage is rolled.

Attack/Defense Modifier

  • Delta = Attack − Defense
  • Each point of Delta provides a diminishing percentage:
    • 1st point: +4.00%;
    • 2nd point: +3.96%;
    • 3rd point: +3.92%…
    • Each point decreases by 0.04% until it reaches 0;
    • Once Delta exceeds 100, it no longer affects damage.
  • When Delta is 100, the maximum coefficient = 202%;
  • When Delta > 0: Multiplier = 1 + Coefficient | When Delta < 0: Multiplier = 1 / (1 + Coefficient)
  • Corresponding multipliers: 1 + 2.02 = 3.02x and 1 ÷ (1 + 2.02) ≈ 0.331x;
  • Attack/Defense Modifier Simulator

Creature Attack, Defense, and Damage

  • The calculation process for creature Attack, Defense, and Base Damage (except for the statDmgMult parameter) is not covered here.

Base Damage Calculation Flow:

  • DMG = Base Damage
  • DMG = DMG × Base Damage Multiplier; related parameter: statDmgMult
  • DMG = DMG × Creature Count
  • DMG = DMG + Energy-related damage, e.g., the Concubus's "Ceaseless Suffering"
  • DMG = DMG × Attacker's All-type Damage Increase; related parameter: outAllDmgMod
  • DMG = Floor(DMG)

Attacker Tag-Based Damage Increase Flow:

  • DMG = DMG × (1 + Tag-Based Damage Increase)
  • DMG = Banker's Rounding(DMG). For tag-based damage increases, same tags add, different tags multiply. Example parameters:
    • outDmgMods-normal_damage
    • outDmgMods-basic_attack
    • outDmgMods-melee_attack
    • outDmgMods-shoot_attack
    • outDmgMods-range_attack

Target-Related Additions and Modifiers Flow:

  • DMG = DMG × (1 + Creature Tier Difference Modifier); related parameters:
    • Parasite's "Topple the Strong!": damagePerDeltaLevel
    • Hive Queen's "Squash the Weak!": damagePerDeltaLevelLower
  • DMG = DMG × (1 + Summoned Creature Damage Bonus), if the target is a summoned creature
    • Related parameter: summonDamagePercent
  • DMG = DMG × (1 + Wall Ranged Shot Damage Reduction), if the fortification shot condition is met
  • DMG = DMG × (1 + Tag-Based Damage Reduction). For tag-based damage reduction, same tags add, different tags multiply, with a minimum of 10%. Example parameters:
    • inDmgMods-normal_damage
    • inDmgMods-basic_attack
    • inDmgMods-melee_attack
    • inDmgMods-shoot_attack
    • inDmgMods-range_attack
  • DMG = DMG × (1 + Apex Predator's 50%)
  • DMG = DMG × ATK/DEF Modifier
  • DMG = DMG × Range Influence
  • DMG = DMG × (1 + Hexes Moved × Damage Bonus per Hex), e.g., Cavalry's "Jousting Bonus"
  • DMG = DMG × Defender's All-type Damage Reduction; related parameter: inAllDmgMod
  • DMG = Banker's Rounding(DMG)

Obtaining the Damage Range:

  • Calculate the minimum damage (DMG.Min) and maximum damage (DMG.Max) separately, rounding the results down.

Random Value Selection Within the Damage Range:

  • Creatures whose base damage minimum and maximum are equal, as well as those affected by effects that always deal minimum damage (alwaysMinDmg) or always deal maximum damage (alwaysMaxDmg), do not undergo random value selection.
  • Generate a normally-biased random number r, and use it to uniformly pick an integer DMG.K within the interval [DMG.Min, DMG.Max]. The specific process:
    • 1. Generate r (up to 10 attempts)
      • u1, u2 = two NextDouble() calls from the random source, taking two double-precision floating-point numbers: u1, u2
      • Use the Box-Muller transform to compute a standard normal random number z: z = sqrt(-2 × log(u1)) × cos(u2 × 2π)
      • Scale and shift z into r: r = z × 0.23 + 0.5. That is, a normal distribution with mean 0.5 and standard deviation 0.23
      • Check whether r falls within [0,1): if yes, accept it and stop; otherwise discard it and try again
      • If no valid r is obtained after 10 attempts, fall back to a single ordinary NextDouble() as r
    • 2. Use r to select the integer DMG.K
      • Compute the interval width: DMG.Max + 1 - DMG.Min (note the DMG.Max + 1, because DMG.K ranges over the closed interval from DMG.Min to DMG.Max, i.e., DMG.Max - DMG.Min + 1 integers)
      • Multiply r by the width to get a floating-point number within [0, width)
      • Round down to get an integer offset from 0 to width - 1
      • Add DMG.Min to get DMG.K, i.e., an integer between DMG.Min and DMG.Max
      • Finally, use native boundary clamping to restrict DMG.K to [DMG.Min, DMG.Max + 1), ensuring it does not go out of bounds

Luck Damage Determination:

  • DMG = DMG.K × Luck Modifier
  • DMG = Ceiling(DMG)
  • DMG = max(1, DMG), i.e., DMG is at least 1