To Hit
Contents |
Introduction
Here I detail the process of determining the result of an attack, as learned from reading the source. The primary function involved is MOB::receiveAttack(), in creature.cpp. This applies to not only melee or missile attacks, but wand rays and many spells.
The Attack Roll
We start with a "multiplier bonus". This defaults to 1, but becomes 2 for a Charge attack, and can be altered later in the calculation.
Up front, we figure noise for attacker's weapon (or if none, their base noise level), and defender shield, (or whatever they've got in their off-hand). This is primarily important for characters' relationship with Quizar, but can also affect whether you hear a monster (perhaps fighting your pet).
We start with a hitroll 1d20.
If attacker is Off Balance, or if their hitroll was 1, the melee or thrown attack will "Completely miss!" ("forced miss", and end here). If the hitroll was 20, the attacker gets get a "forced hit", with special processing ("critical threat") later. If the attacker is properly using True Aim (and didn't get a "forced miss" above), they likewise get a forced hit.
Otherwise, continue checking if they hit:
We find a maximum bonus, which is the sum of:
- Attacker level:
- Physical Dice for melee or thrown attacks
- Magical dice for spell attacks
- the sum of both Physical+Magical dice for wand attacks,
- 0 for improvised or "non-creature" attacks (poison, traps, etc).
- The weapon's (or monster attack's) "natural" bonus, such as a Rapier's "+2 to hit, or various penalties for throwing melee weapons.
- The weapon's magical bonuses (for Bow and Arrow, both their bonuses are added).
- Skill Level (0..3): Monsters and non-sourced attacks have skill level 2 for any attack. The avatar gets one level for each of the following:
- Having the skill for the Attack Type (Edged, Pointed, Blunt). If you are throwing a melee weapon, meleeing with a missile weapon, or attacking with a non-weapon, that would be Improvised Weapons.
- Having the Large/Medium/Small skill for a melee attack, or Ranged Weapons for a missile attack. Spells, wands, and any other attack styles automatically get this point.
- Having the "special" skill for the weapon, if used correctly (thrown vs. melee)
We then get the actual modifier as follows:
- Rolling from 1 to the maximum bonus. For each level of skill, we get an extra roll, and we keep the highest roll we got.
- If the attacker cannot sense the target, subtract 4.
- If the attacker is using a missile weapon from atop a tree, and the target is not also in a tree, add 4.
- If the target is the Natural Enemy of the attacker, add 4.
Add this to the hitroll, and subtract 10, ("so that AC 0 represents a 50% hit chance") to get the "Attack roll".
The AC Roll
Now AC is calculated, resulting in an "AC roll":
- Choose a body part to be attacked: head, neck, body, feet. If the target doesn't have that equipment slot, it goes to "body", whether or not they have a "body armor" slot. Body always has a 55% chance, the others will depend on the relative size of attacker and target:
- attacker is smaller: 39% feet, 1% neck, 5% head
- attacker is larger: 5% feet, 5% neck, 35% head
- similar sizes: 20% feet 5% neck, 20% head.
- Non-creature attacks are considered "same size".
- Find the AC (including enchantment) of the armor for that body part, and add the target's skill level for that armor:
- If there is no armor, the AC is 0 and skill is irrelevant.
- As usual, monsters always have skill 2
- Amulets don't have an "armor type" skill, but you do get credit for "armor material" skills.
- Roll from 1 to this armor AC, rerolling according to skill level, to get the "Worn AC roll"
- If skill is 0, roll twice and pick the lowest.
- If skill is 1, do not reroll.
- If skill is 2, roll twice and pick the highest.
- If the target is wearing a shield, check for a "parry" according to their skill with the shield: 25%, 50%, or 75% for skill 0, 1, or 2 respectively.
- If they parried, add their skill to the shield's AC, then roll against that, same as for the worn armor. Add the result into the "Worn AC roll".
- Roll from 1 to the target's natural ac. ("Natural AC roll") If the natural AC is 0 (as for humans), this will be 0.
- Whichever of the Worn or Natural AC rolls is lower, divide it by 3 (round fractions up), then add that to the other Roll. (Most likely, one or the other will be 0, but this allows a monster to get some benefit from wearing armor.)
- The result is the final "AC roll" against this attack.
If the attack roll >= the AC roll, or if we had a "forced hit" above, we hit. Otherwise, we have missed, and exit.
If the original hitroll was 20 ("critical threat"), we also have a chance to do more damage:
- We make a fresh d20 roll ("threat roll"), but reuse the modifier and AC roll from above.
- If the threat roll is 20, or if it is not 1 and (threat roll+modifier-10) >= AC roll from above, we add one to the damage multiplier.
- Otherwise, we get no extra damage.
At this point, there is still a chance for the target to avoid the attack with special skills, unless they cannot move, or it was a "forced hit":
- Dodging has a 10% chance to avoid the attack.
- Moving Target, if target moved last turn, has a 20% chance to avoid missile, wand, or spell attacks.
- Parrying with an appropriate weapon has a 10% chance to block the attack.
Damage Calculation
At this point, we have hit, but we're not quite finished -- we still need to calculate damage. If the AC roll was over 10, we subtract 10 from it for a "damage reduction" value (otherwise 0), and go on to receiveDamage():
- The "damage reduction" is randomly reduced: Roll twice, from 0 to its prior value, and keep the lesser value. (Before Version 115, this applied only to the first damage type from this attack, usually physical damage.)
For each damage type from this attack:
- Consider Resistances and Vulnerabilities: A resistance sets the "multiplier" to 0, mooting Charges and critical hits. Each vulnerability (including gold, silver, and Earth Elementals meleed by someone with Can Dig) then raises the multiplier by one.
- damage is initially (multiplier) times the basic dice for the attack. Note that the "number of dice" are multiplied before rolling, so "2d6+1" would become "4d6+2", not "(2d6+1)×2". (This will reduce the "spread" of the roll, pushing it toward the average.)
- If there is a weapon enchantment (or two), we figure an "enchant bonus" equal to (enchantment)×(multiplier), and then roll from 1 to that. If the multiplier is above 1, we roll (multiplier) times, keeping the highest value. This gets added into the damage. (This can be negative, if the weapon had a minus.)
If damage is above 0, we subtract the "damage reduction", but the minimum damage is then 1. Otherwise, minimum damage is 0.
At this point, check for explosions, figure side-effects (waking up, or blindness, etc.), and apply any intrinsics linked to the attack.
Finally, we actually apply the damage, then handle the victim's possible death and aftereffects thereof.
Back in receiveAttack(), if the target lived we go on to apply any poison from the weapon, and handle Ripostes and reflex ("hitback") attacks.
Take-Home Lessons
From the above, we can get some general advice:
- Both weapon and armor skills count for a lot!
- Not only do they increase your armor above its base AC, but they (or their lack) affect your AC roll quite a bit.
- Similarly, multiple skills push your attack rolls hard toward the maximum!
- Note, however, that for missile attacks, "Ranged Weapons" skill replaces the "weapon size" skills.
- All that said, skills don't do anything for damage.
- Weapon and armor enchantments are useful (especially backed with skill), but they don't give you a constant base damage, nor fixed protection for armor skills.
- Regardless of skills or enchantments, no weapon does "at least X points" damage, and no armor will always fend off even weak attacks.
- Either high weapon damage or weapon "to hit" bonuses do help, but generally not as much as appropriate skill(s). (It doesn't matter how much damage you do if you almost never hit!)
- Similarly, wearing heavy armor, or a shield isn't nearly as much help if you don't have skills for them.
- Wands are easy to hit with, especially if your levels are split between physical and magic.
Examples
To make some sense of this, let's try some examples. Suppose we've got a character ("Fred") with Physical level 8 and Magical Level 5, facing off against a Troll. To simplify, I'll introduce equipment only as it becomes relevant, and I'm not going to track their actual hit points. Numbers in [brackets] indicate a a die roll, while computed numbers get no bracket. I'm also not bothering to link dice expressions.
- To start the fight, Fred charges the troll with his +2 Flaming Sword in hand. He has Medium and Edged weapon skills.
- His hitroll is [16], a promising start.
- His maximum bonus is 8 (hit dice) +2 (weapon magic) +2 (skill level) = 12
- For the actual bonus, he gets 3 rolls from 1..12: [8] [2] [7], and takes the highest: 8
- His Attack roll is 16+8-10 = 14
- Now the troll figures his AC roll.
- First, where did he get hit? Turns out to be [his head]
- He's not wearing a helmet or a shield. so his Worn AC is 0.
- His Natural AC is 8, so he rolls 1..8, just once because skill doesn't apply here. He gets [5].
- The troll's total AC roll is 5 + (0/3)=5
- Since the Attack roll of 14 is higher than the AC roll of 5, Fred hits. The troll has no defensive skills, so that stands. Time to figure damage!
- There's no damage reduction for an AC roll of 10 or less, and it was only 5.
- The flaming sword first does 1d8 physical damage.
- The multiplier was 2 for a charge, and the troll has no resistance or vulnerability, so initial damage is 2d8, yielding [6]
- The maximum enchant bonus is 2×2=4. Fred rolls 1..4 twice (that multiplier again) for [3] [1], and gets 3 extra points.
- Accordingly, the troll takes 9 points of physical damage.
- Now the sword does another 1d3 points of fire damage.
- With the multiplier, initial damage is 2d3, and the result is [4].
- Fred rolls again for the enchant bonus, and this time he gets [1] [4], for 4 extra points.
- The troll takes 8 points of fire damage.
This isn't enough to kill him, so on to the troll's counterattack.
- The troll has the usual Club, doing 1d4+1 damage
- The troll's hitroll is 12.
- his maximum bonus is 6 (hit dice) +2 (monster skill) = 8
- For actual bonus, he gets 3 rolls from 1..8: [3] [1] [7], so it's 7
- His attack roll is 8+7-10=5
- Now Fred takes his AC roll
- Where did he get hit? Turns out to be [his body].
- Fred is wearing chainmail +1, which has AC 5, but he also has Metal Armour skill, for a total of 6
- he has a round shield, but he missed his 50% parry chance, so that doesn't help.
- He rolls 1..6 (once), and gets [5]
- His natural AC is the usual 0, so his AC roll is 5+(0/3)=5
- The troll hits. How much damage?
- The club does 1d4+1... [4]
- No enchantment, so no enchant bonus. No damage reduction either, since AC roll<= 10
- Fred takes 4 points of damage.
(to be continued...?)