## Defending [Condition] Choosing the DEFEND command in the command menu more then doubles your character's defense attribute until your next turn. This means less damage inflicted by enemy attacks.

Note:
Even when a character's Defense is maxed out at 9999, Defending during battle still reduces damage. Defending is independent of Defense, so you still get the modifier regardless of what your Defense is.
This can be seen in the Damage Formula provided by Marcus of SideQuest Studios:

Damage Formula for Rainbow Moon:

The base values for calculating damage are attributes of both units, the attacker and the defender. I use the following identifiers:

Str(A) -> Strength of Attacker
Str(D) -> Strength of Defender
Bias(A) -> Bias of Attacker (0-8192, 4096 is balanced)
Bias(D) -> Bias of Defender (0-8192, 4096 is balanced)
Def(D) -> Defense of Defender
Lck(A) -> Luck of Attacker
SkillPower -> Specified hidden value for every skill. (1,0 for a standard attack)
DefenseMode -> 0,5 if defender is in defense mode, 1,0 otherwise.
InitialStrike -> 2,0 if this is an initial strike attack, 1,0 otherwise.

The game uses integer values only (fixed-point arithmetic), but to make the formula a little bit more readable I converted some values into floating point.

If a character is using the defend option, please note, that not only the DefenseMode variable will be modified. Actually, the defense attribute of the
defender will be increased too, so the overall effect of defending is higher than a 50% boost!

There are also some common math functions used:
MIN(A, C)/MAX(A, C) -> Minimal or maximal value from two given arguments
RANDOM(A) -> A random number from the range 0 - (A - 1)
SQRT(A) -> Square root of A
ABS(A) -> Absolute value of A

1.) Determining a critical hit: (2,0 if true / 1,0 if false)
Critical = (RANDOM(256) < (SQRT(MIN(Lck(A), 1024)) + (Lck(A) / 512)))

2.) Determining Weapon Affinity:
Affinity = 1,0 (if no affinity is active) (4096 / 4096)
Affinity = 1,375 (positive affinity) (4096 + (1024 + 512)) / 4096)
Affinity = 0,625 (negative affinity) (4096 - (1024 + 512)) / 4096)

3.) This is the main damage formula:
Damage = (MAX(0, ((Critical * Str(A)) * (4096 + ABS(Bias(A) - Bias(D)) / 8192) * Affinity) - ((Def(D) - Str(A)) / 2)) * SkillPower * DefenseMode * InitialStrike)

4.) A small random adjustment will be added after that:
Damage = (Damage + RANDOM((Damage / 8) + 3))