Battle System

''Note: these formulas are pulled from the source code for the js version of larn running at larn.org. ularn/xlarn/other variants might have different formulas''

Monster Attacks Player
When a monster attacks a player, there is a process to determine what happens next:
 * 1) Check Protections
 * 2) Determine Bias
 * 3) Check Invisible & Charm
 * 4) Damage Calculation
 * 5) Special Attack Calculation
 * 6) Attack Roll
 * 7) Damage Application

Check Protections
Explanation
 * If the player is holding a scarab of negate spirit or currently has spirit protection scroll active, they are immune to attacks from poltergeist and spirit naga
 * If the player is holding a cube of undead control or currently has undead protection scroll active, they are immune to attacks from vampire, wraith, and zombie
 * If any of the above options are true, the entire damage application process is cancelled

Determine Bias
Explanation
 * The bias factor is set as the game difficulty +1
 * Example: if the game difficulty is 0, then the bias is equal to 1
 * This bias factor will be relevant when monster rolls for attack. Generally the higher the bias factor, the more likely you are to be hit by monster attacks

Check Invisible & Charm
Explanation
 * If player is invisible, the monster has a 19 in 33 (57.57%) chance of missing, otherwise they land the hit
 * If player uses the charm monster spell, the monster has a variable chance of being charmed and missing, based on monster level and player charisma level
 * Example: If monster level is 3 and player charisma is 12 and the charm spell is active, the monster has a rnd(30) + 3 < 30 (90.90%) chance of missing

Damage Calculation
When struck by a monster, the following formula is used to determine how much damage is taken Explanation
 * If the attacking monster is a bat, damage is always 1
 * Otherwise, calculated damage is set as monster base damage + monster level + random number between 1 and monster damage
 * Example: if monster base damage is 2 and monster level is 1, then calculated damage could be between 4 and 5 inclusively 
 * If calculated damage - player AC is less than 0, no damage is taken
 * Example: If monster damage is 3 and player AC is 3, no damage is taken\
 * Otherwise, player loses HP equal to calculated damage

Special Attack Calculation
Explanation
 * This is only calculated if the monster has a special attack, signified by ATT > 0 (see table in Monsters)
 * The special attack will land if either of these conditions is met:
 * calculated damage + bias + 8 is greater than player AC
 * Example: If bias is 1 (game difficulty is 0) and calculated damage is 4, the player must have an armor class of 13 or higher to avoid this condition
 * The generated random number between 1 and player AC is equal to 1
 * Example: If player AC is 12, there is a 1 in 12 chance of this condition being met, therefore, the higher your AC, the less likely it is for special attacks to land
 * Also Note: if player AC is 0, there is a 100% chance that special attacks will land
 * If the special attack was a theft, the monster will disappear without applying damage
 * Otherwise, the bias will be decreased by 2, and an attack roll will be performed.

Attack Roll
When struck by a monster, the following formula is used to determine whether the attack is hit or missed:

Explanation Observations on hit-or-miss formula
 * If calculated damage + bias is higher than player AC (armor class), the hit lands
 * Example: if calculated damage is 3 and bias is 1, player must have armor class of 4 or higher for monster to miss
 * A random number is generated using a range of 1 - player AC. If the random number is equal to 1, or if the player's AC is 0, the hit lands
 * Example: if player AC is 3, they have a one in 3 chance of being hit 
 * The addition of bias to the hit-or-miss formula means that a player's AC must always be higher than the attacking monster's calculated damage in order for the attack to miss. The amount of required AC for an attack to miss depends on difficulty level (at difficulty 0, you only need  calculated damage  AC)
 * Even if player armor class is greater than calculated damage + bias, you still have a one-in-AC chance of being hit
 * When player AC is 0, all attacks to the player will hit

Damage Application
When struck by a monster, the following formula is used to determine how much damage is taken Explanation
 * If calculated damage is less than 0, no damage is taken
 * Example: If calculated damage is 3 and player AC is 3, no damage is taken
 * Otherwise, player loses HP equal to calculated damage