This contains in-depth mathematical analysis of the damage dealing system and functions, and breaks down the steps of the damage dealing process

This is sub-layout for documentation pages

The damage is calculated in several phases, all of them are going to be explained below,
but before we do so, let's start with some **definitions**

- Let \(A\), \(D\) be characters in the game.
- Let \(A\) be an attacker, and \(D\) be the defender.
- Let \(d\) be final damage that is dealt from attacker \(A\) to the defender \(D\)
- Let \(rand(a,b)\) be a function, which generates a random number from interval \(<a, b>\), using uniform probability distribution. \(a \in \mathbb{R}\)

Rolling phase is such a phase, where **attack rating** is determined for the attacker,
and **defence rating** be determined for the defender.

Attacker has some set of attack stats, from which the relevant attack stat is chosen
which respect to the **attack style**(magic / melee / blood / fire / ice / slash / stab etc.)

Let such a chosen number be \(Aa = 5\)

The same process is done for the defender, where defence stat \(Dd\) is chosen,
with respect to the **attacker's attack style**
Let \(Aa = 8\)

Then, we calculate roll for both participants.

- Let \(u\) be the chosen stat number. (eighter \(Aa\) or \(Dd\))

\((u \lt 0) \rightarrow f(u) = rand(u, 0)\)

\((u \geq 0) \rightarrow f(u) = rand(0, u)\)

Then, we calculate rolls \(r_a\) for attacker and \(r_b\) for defender

\(r_a = f(Aa)\)

\(r_d = f(Dd)\)

Then, damage is evaded completelly, if \(r_a < r_d\)

And damage is evaded with 50% chance, if \(r_a = r_d\)

Here is an example to support the theory above.

Let's imagine, that attacker is using **ice barrage** spell to attack.
Because of that, we choose **attack - ice** stat as \(Aa\). Let

\(Aa = 12\)

For defender, we choose **defence - ice** stat as \(Dd\). Let

\(Dd = -3\)

We calculate

\(r_a = rand(0, 12) = 3\)

\(r_d = rand(-3, 0) = -1\)

Because \(r_a \gt r_d\), damage will be dealt, and system proceeds to the next phase,

Damage calculation phase is such a phase, which takes place after
roll phase, if attacker was successfull in a roll.
Here, final damage \(d\) is calculated.

This phase takes previously calculated rolls \(r_a\) and \(r_d\) as an additional input.

The formula for final damage \(d\) is:

\(d = rand(1, d_{max})\)

Where \(d_{max}\) is the maximum possible damasge that can be dealt by
the attacker. It applies:

\(d_{max} = (1.7 * (rankMainW + dmgBonusForSpeed) + A_l * 0.3)
* (1 + 0.8 * rollDifference) \)

Where:

- \(rankMainW\) is the rank of the main weapon currently wielded by the attacker, or 0 if no weapon is wielded
- \(dmgBonusForSpeed = \frac{S_w - S_d}{1000} * 0.8 \)

Where- \(S_w\) is the main weapon attack speed
- \(S_d\) is the default attack speed, defined by system

- \(A_l\) is the level of the attacker
- \(rollDifference = min(1 - r_d / r_a, 1) \)

Then, that damage number is altered through series of modifier phases.

Damage modification phase, takes place always after
damage calculation phase.

Input - output specification

**Input**: the damage \(d\)

**Output**: the damage \(d1\), which can be whatever

Input - output specification

**Input**: the damage structure \(s\) containing damage \(d\)

**Output**: the damage structure \(s\) with modified damage or any values

This phase takes in consideration **attacker's** worn item sets, and it's
special effects.

For example, **The unholy robe set** has a chance of ignoring target's
protection prayers. That is calculated here, and the structure \(s\) is
changed in appropriate way for future phase.

Input - output specification

**Input**: the damage structure \(s\) containing damage \(d\)

**Output**: the damage structure \(s\) with modified damage or any values

This phase takes in consideration all **attacker's**
activated prayers, and also, all **defender's**
activated prayers.

This sorely depends on how the prayers are defined, but for example,
melee / magic protection prayer can nullyfy the damage, if the attack style matches

If, however, input damage structure \(s\) contains flag to skip protection prayers,
they are ommited

After effect phase is the last phase, and takes place after damage all modifier phases
were completed (and if any damage was dealt at all.)

It is responsible for **buff / debuff** modifiers, such
as poison / freeze / teleblock or healing (blood spells).