Damage Calculation
30-10-2022
In Devas, there are 4 basic stats:
In Devas, there are 4 basic stats:
Defense is calculated through a dilution formula:
\[D(x)=\frac{kx}{|x| + a}\]where \(x\) is the Defense stat, \(D(x)\) is the Damage Reduction, and:
\[a=n\left(\frac{k}{h} - 1\right)\]where \(n\) is a user-defined defense value, such that: \(D(n) = h\) and \[\lim_{x \to +\infty}D(x) = k\]
or simply put, the maximum damage reduction is defined as \(k\).
Evaluation Formula:
damage_calc:defense_evaluationDesmos Graph:
[Link]
Before we started planning the formula, we hoped that the maximum damage reduction that will ever occur would be at 60% Damage Reduction.
During the discussion, DoubleA had suggested when the player has 200 Defense, the Damage Reduction would be set to 50%. Therefore, we have agreed on three constants for this formula.
\[ \begin{cases} n := 200\\ h := 50\%\\ k := 60\%\\ D(0) = 0\\ D(n) = h\\ \end{cases} \]As we would require the horizontal asymptote to be on \(k\), we can determine that:
\[ \lim_{x \to +\infty}D(x) = k \hbox{        ...... [1]} \]We have found that \(
D(x) = k - \frac{k}{1+x}
\),
satisfies [1],
and \(D(0) = 0\).
However, \(D(n) = h\) is still not satisfied.
Therefore, we would need to scale \(x\) such that it satisfies this equation. We can do that by dividing \(x\) by \(a\), where \(a\) is a constant to be found.
To solve this, we can plug in \(D(n)=h\), to find \(a\).
\[D(n)=k-\frac{k}{1+\frac{n}{a}}\] \[h=k-\frac{k}{1+\frac{n}{a}}\] \[k-h=\frac{k}{1+\frac{n}{a}}\] \[1+\frac{n}{a}=\frac{k}{k-h}\] \[\frac{n}{a}=\frac{k}{k-h}-1\] \[a=\frac{n}{\frac{k}{k-h}-1}\] \[a=\frac{n}{\frac{k}{k-h}-\frac{k-h}{k-h}}\] \[a=\frac{n}{\frac{h}{k-h}}\] \[a=n\frac{k-h}{h}\] \[a=n\left(\frac{k}{h} - 1\right)\]Therefore, \(a\) is found.
Afterwards, we would need to change the formula such that the equation has rotational symmetry about the origin.
We can do this by first applying the absolute value to \(x\), and then multiplying the whole function by sign\((x)\).
\[D(x) = \hbox{sign}(x) \times \left( k-\frac{k}{1+\frac{|x|}{a}} \right)\] \[= \hbox{sign}(x) \times \left( k-\frac{k}{\frac{a + |x|}{a}} \right)\] \[= \hbox{sign}(x) \times \left( k-\frac{ak}{a + |x|} \right)\] \[= \hbox{sign}(x) \times \frac{ak + k|x| - ak}{a + |x|}\] \[= \hbox{sign}(x) \times \frac{k|x|}{a + |x|}\] \[= \frac{x}{|x|} \times \frac{k|x|}{a + |x|}\] \[\therefore    D(x) = \frac{kx}{|x| + a}\]As demonstrated, this is the formula which allows us to change the cap of the damage reduction formula.
When the damage calculation function is called, it takes in 3 parameters:
scoreboard players get #In.DMG DC.temp scoreboard players get #In.DEF DC.temp scoreboard players get #In.E_DEF DC.temp
scoreboard players get %Physical_Defense_Elemental_Effectiveness DC.Settings scoreboard players get %DEF_Eval.n DC.Settings scoreboard players get %DEF_Eval.h DC.Settings scoreboard players get %DEF_Eval.k DC.Settings scoreboard players get %DEF_Eval.a DC.Settings
To edit the constants, you may refer to stats:init/settings