Home

calculateDamage

calculateDamage is a function used in video games and simulations to determine the amount of health an attack will remove from a target. It combines factors from the attacker, the weapon, any active buffs or skills, and the target’s defenses to produce a single damage value.

Common inputs include attackerStats (attack power, critical chance, elemental or type bonuses), weapon properties (base damage,

A typical calculation follows a sequence. First, compute raw damage by combining weapon damage with attacker

Edge cases include situations where defenses exceed raw damage, resulting in zero damage, or when penetration

See also: damage calculation, armor, resistance, critical hit, armor penetration.

type,
flat
bonuses),
skillModifiers
(multipliers
and
duration),
and
targetStats
(armor,
resistances,
shields,
absorb
effects).
Some
implementations
also
include
randomness,
damage
type,
and
penetration
factors.
bonuses
and
any
flat
additions.
Next,
apply
multipliers
from
skills
or
buffs.
Then
determine
critical
hits
using
the
attacker’s
critical
chance
and
apply
the
critical
multiplier
if
triggered.
After
that,
apply
target
mitigation,
usually
through
armor
and
resistances.
Armor
often
reduces
damage
by
a
factor
such
as
a
divisor
or
percentage,
while
resistances
lower
specific
damage
types.
Some
systems
include
armor
penetration
or
shield
absorption
before
final
mitigation.
Finally,
apply
a
small
random
variance
to
avoid
determinism
and
clamp
the
result
at
zero
to
prevent
negative
damage.
and
resistances
interact
in
unusual
ways.
Different
games
handle
damage
types
separately
(physical,
elemental,
magical)
and
may
exclude
certain
modifiers
from
certain
types.