# Damage Calculation

When one unit attacks another unit, the amount of HP lost can be determined through **Damage Calculation**. Typically this process is very straightforward and can be found simply by subtracting the attacked units shields or armor from the damage dealt. However, certain spells and abilities such as Corruption and Hardened Shield can significantly complicate matters.

## Input parameters[edit]

To see how is different factors can interact, consider the case where the attacker is a Marauder with +2 attack and the defender is an Immortal with +3 armor, +1 shields, 2/100 Shield Points, and 200/200 HP. The Immortal is also under the effect of Guardian Shield and Corruption. After one attack, how many Shield Points and HP remain?

### Basic parameters[edit]

**Base attack**: This is the how much damage the attack does without any bonus damage or upgrades.

- 10 ---
*The Marauder does 10 damage per shot by default*

**Bonus damage**: This is how much extra damage the attack does due to the defender having a certain attribute.

- 10 ---
*The Marauder does +10 damage to Armored units and the Immortal is Armored*

**Attack upgrades**: This is how much extra damage the attack does due to upgrades such as Infantry Weapons.

- 4 ---
*For each attack upgrade, the Marauder does +1 damage plus an additional 1 damage to Armored targets. With 2 attack upgrades, this is a total of +4 damage*

**Shield Defense**: For Protoss units, this is level of shield upgrades that the defender has. Otherwise, this is equal to 0.

- 1 ---
*The Immortal has +1 shields*

**Armor Defense**: This is the defender's base armor plus any armor upgrades such as Ground Armor or Chitinous Plating.

- 4 ---
*The Immortal has a base armor of 1 plus +3 armor upgrades for a total of 4*

### Modifier parameters[edit]

**Corrupted**: If the defender is affected by Corruption, then this equals 1.2; otherwise, this equals 1.

- 1.2 ---
*The Immortal is Corrupted*

**Splash**: If the defender is receiving the damage through splash damage, then this equals the % of the damage for the defender's location; otherwise this equals 1.^{[1]}

- 1 ---
*The Immortal is not receiving splash damage*

**Hallucinated**: If the defender is a Hallucination, then this equals 2; otherwise, this equals 1.

- 1 ---
*The Immortal is not Hallucinated*

**Prismatic**: If the attacker is a Void Ray and the defender is a Massive unit, then this equals 1.2; otherwise, this equals 1.^{[2]}

- 1 ---
*The Immortal is not Massive (nor is the Marauder a Void Ray)*

**Bypass**: If the attacker is a Baneling and the defender is a Structure, this equals 0; otherwise, this equals 1.^{[3]}

- 1 ---
*The Immortal is not a Structure (nor is the Marauder a Baneling)*

**Spell**: If the attacker's damage comes from a spell, this equals 0; otherwise, this equals 1.^{[4]}

- 1 ---
*The Marauder is not dealing damage via a spell*

**Hardened**: If the defender is an Immortal with Shield Points remaining (and thus Hardened Shield), then this equals 10; otherwise, this equals 900.^{[5]}

- 10 ---
*The defender is an Immortal with Shield Points remaining*

**Guardian**: If the defender is protected by Guardian Shield, then this equals 2; otherwise, this equals 0.

- 2 ---
*The Immortal is under the effect of Guardian Shield*

## Performing the Calculations[edit]

**Damage Dealt**: This is equal to (Base attack + Bonus damage + Attack upgrades)*Corrupted*Splash*Hallucinated*Prismatic.

- 28.8 ---
*(10 + 10 + 4)*1.2*1*1*1=28.8*

**Defense Available**: If the defender is a Protoss unit with Shield Points, this equals Shield Defense. Otherwise, this equals Armor Defense.

- 1 ---
*The defender is a Protoss unit with Shield Points remaining*

**Defense Applied**: This is equal to Defense Available*Bypass*Spell*(2-Hallucinated)

- 1 ---
*1*1*1*(2-1)=1*

**Damage Received**: This is equal to the Damage Dealt - Defense Applied.

- 27.8 ---
*28.8-1=27.8*

**Damage Capped**: This is equal to whichever is less, Damage Received or Hardened*Corrupted*Hallucinated+900*(1-Spell).

- 12 ---
*27.8 > 10*1.2*1+900*(1-1), so the Damage Capped is 10*1.2*1+0=12*

**Damage Inflicted**: This is equal to whichever is greater, Damage Capped - Guardian*Spell or 0.5^{[6]}.

- 10 ---
*12-2*1 > 0.5, so Damage Inflicted is 12-2*1=10*

**Total Damage**: If the defender is a Protoss unit with Shield Points, and the Damage Inflicted is greater than Shield Points + Armor Defense, then the damage spills over to the HP and this equals Damage Inflicted - Armor Defense^{[7]}. Otherwise, this equals the Damage Inflicted.

- 6 ---
*The defender is a Protoss unit with Shield Points, and the Damage Inflicted is greater than Shield Points + Armor Defense (10 > 3+4), so this equals 10-4=6*

## Applying the Damage[edit]

If the defender is a Protoss unit with Shield Points remaining, apply the Total Damage first to the Shield Points and then to the HP, if any of the Total Damage remains.

*The defender is a Protoss unit with Shield Points remaining, so the damage first reduces the shields from 2/100 to 0/200, with the remaining 4 damage being applied to HP. The Immortal's final Shield Points and HP are 0/100 and 196/200, respectively.*

For all other units, reduce the defender's HP by the Total Damage.

For units with attacks that do multiple hits (e.g. Zealot does 2 hits per attack), perform the whole process for each of hits.

## Notes[edit]

- ↑ E.g. a Marine caught within the swathe of an Ultralisk attack (but not the primary target) takes 33% of the damage dealt, so in this case splash equals 0.33.
- ↑ The Void Ray's Prismatic Beams does an additional 20% to Massive units.
- ↑ The Baneling's building attack bypasses defenses.
- ↑ All damage-dealing spells (e.g. Snipe, Nuke, Psionic Storm) not only ignore armor and shield upgrades, but also ignore Guardian Shield and Hardened Shield.
- ↑ This could be any suitably high number. Its sole purpose is to always be greater than the Damage Received so the damage is not capped.
- ↑ All attacks must do at least 0.5 damage.
- ↑ When an attack does damage to both Shield Points and HP, both the Shield Defense and Armor Defense are applied. See Plasma Shield for more details.