Talk:Armor class

From NetHackWiki
Jump to: navigation, search

The section discussing how armor class works is well intentioned, but wrong. For armor class values between 0 and 10, the game mechanics are as described in the text. However, for armor class values below 0, the mechanics are different. If your armor class is -N, then each time you are attacked, the game randomly chooses a value x between 0 and N, and your armor class for the purposes of that attack is set to -x. For example, if your armor class is -20, then each time you are attacked by a monster, the game randomly chooses a number out of the interval 0, -1, -2, -3, -4, ..., -20 and sets your armor class equal to that number. This is done independently for each attack. The other omission in the text is that an armor class of -x for that attack not only reduces the monster's to-hit value by x, but it also reduces the amount of damage that the attack inflicts by x.

Disclaimer: My knowledge of the mechanics of armor class is not from reading the source code, but rather from playing the game way too much. Djao 05:55, 24 January 2007 (UTC)

The game randomly changing your armor class is exactly the same as the game randomly changing the monter's to-hit roll. I don't know the exact mechanics, but either way it is the same thing. I don't know how AC factors into damage taken, which is why that was left out. I was just basing the information on how it was done in Dungeons & Dragons, which is the easiest way to program it in the game. Randomly changing armor class for any negative value just seems too clunky for me. --MadDawg2552 02:28, 25 January 2007 (UTC)
Randomly changing the to-hit roll is not the same thing as randomly changing the armor class, because the game changes the monster's to-hit roll by the amount of your randomly altered armor class, not by the amount of your original armor class. An easy way to see the difference is to set your armor class to -127. Going by your method, no monster would ever hit your character at all (since no monster in the game has to-hit bonus large enough to overcome -127 AC). But, if you test in wizard mode, you will find that an armor class of -127 does NOT in fact make you completely invulnerable to every monster in the game. Monsters do sometimes hit you, because one out of every 127 attacks, your armor class is effectively 0 for the purposes of that attack. Djao 02:59, 25 January 2007 (UTC)
What you describe is what Dungeons & Dragons calls a "natural 20", meaning a 20 on the attack die is always a hit. In other words, one in 20 attacks will always be a hit, no matter what your AC is. It just happens less frequently in NetHack. --MadDawg2552 03:15, 25 January 2007 (UTC)
Well, I was about to dig through the source code to find the relevant portions, but someone has already done this below. The line below from hack.h implies that in Nethack (unlike AD&D), AC is randomly adjusted each time. This is in addition to the effects of natural 20, AC reductions to to-hit chances, damage reductions, etc. Djao 23:23, 25 January 2007 (UTC)
After looking at the source code (starting at line mhitu.c#line1560) it does seem that negative AC reduces damage done. I can't, however, find where it determines if the monster hits or not. It's got to be in there somewhere, but I can't find it. --MadDawg2552 02:54, 25 January 2007 (UTC)
That part of the code assumes the monster has already hit. See mhitu.c#line462 for the beginning of the AC code and line 563 onward for the rest of the formula. Here is a brief explanation:
(From hack.h) #define AC_VALUE(AC) ((AC) >= 0 ? (AC) : -rnd(-(AC)))

(the rest is from mhitu.c)
tmp = AC_VALUE(u.uac) + 10;		/* tmp ~= 0 - 20 */
tmp += mtmp->m_lev;
if(multi < 0) tmp += 4;
if((Invis && !perceives(mdat)) || !mtmp->mcansee)
	tmp -= 2;
	if(mtmp->mtrapped) tmp -= 2;
	if(tmp <= 0) tmp = 1;
for(i = 0; i < NATTK; i++)
	if(tmp > (j = rnd(20+i))) //then hit, else miss
  • If your AC is >= 0, then it is used as your AC value, otherwise a value between 0 and your AC value is used.
  • Add 10.
  • Add the monster's level.
  • Subtract 2 if the monster can't see you.
  • Subtract 2 if the monster is trapped.
  • If the result is less than 0, it is now 1.
  • Compare the result to a number between 0 and (20+attack number). In other words, a monster with multiple attacks is slightly less likely to hit on later attacks.
So it looks like there is no to-hit stat; only the monster's level affects its ability to hit you.

Whew! I'm glad we got that all sorted out. --MadDawg2552 04:49, 25 January 2007 (UTC)

Right, thanks for the correction. --Mogri 05:57, 25 January 2007 (UTC)

I read the code and can't figure how there is always a chance to be hit in combat (the key operator looks like a > and not a >=), but that seems to be what everybody says, so I stuck with that narrative in my rewrite; this necessitated reversing the meaning of one of the examples (the one where the target number turns out to be 1 and the monster rolls a 1 on the attack). --Tehks 21:30, September 18, 2009 (UTC)

That looks like a worthwhile thing to sort out. Unfortunately, I don't have the time to do that myself. Tjr 10:39, September 19, 2009 (UTC)

Deflection?

So how does deflection work, as in the message, "Your plate mail deflects the bat's attack." I have always been under the assumption that more armor pieces are better because it seems like I have a better chance of taking no damage. --Ageddyn 20:28, 5 June 2011 (UTC)

That's a SLASH'EM specific message. To my knowledge is simply means "You would have gotten hit by this attack if not for x piece of armor". I believe it's purely cosmetic. -- Qazmlpok 21:53, 5 June 2011 (UTC)
Basically - it runs through, in order, the shirt, the body armor, with a 1/10 chance the boots, a 1/10 chance the gloves, a 1/5 chance the helm, then the cloak, and finally the shield. It adds up the AC each provided, and when it reaches the number that let you dodge the attack, it says that piece of armor 'deflected' or 'blocked' the attack. This means it has a chance of not saying that at all (because without the AC from gloves, helm and boots it may not get high enough), and that it much less frequently says that about gloves, helm and boots, which makes sense physically. And I agree, it definitely seems purely cosmetic. I suppose it's a way of addressing without changing anything the fact that more armor should make you easier to hit, not harder. -Ion frigate 10:32, 6 June 2011 (UTC)
Ah, perfect! I've been playing SLASH'EM for four years and roguelikes for over 20, and it's still amazing how much I suck at them. --Ageddyn 00:45, 13 June 2011 (UTC)