Wednesday, August 25, 2021

Why 100% Protection Doesn't Protect 100% of the Time

Update 2021-09-16: In Build 41.54 this has been fixed.  Holes are put in clothing AFTER protection is determined.

Every once in a while I'll hear (read) about someone complaining that they had 100% protection on a body part and still got hit by a zombie.

Should 100% protection protect you 100% of the time?  Maybe.  Maybe not.  But it doesn't.  Why?

Sometimes you get a hole in your clothing from an attack shortly before Project Zomboid calculates whether your clothing protects you from that attack.

The Code

The BodyDamage class is where damage (to your body) is determined.

Before we get to this part of the code, Project Zomboid has already randomly determined which body part is being attacked.

Right before the roll to see if you are hit, it checks to see if you will get a hole because of the attack

        bl = false;
        bl = this.getParentChar().addHoleFromZombieAttacks(BloodBodyPartType.FromIndex(n3));
        if (Rand.Next(100) > n4) {

addHoleFromZombieAttacks is in the IsoGameCharacter class and randomly determines if this zombie attack put a hole in a piece of clothing on the body part being attacked.  This is really important, because if there is a new hole, the protection on that part of your body goes down.

After it checks to see if you got a hole, it checks to see if you've been hit.  So it is possible to get a hole in your clothes and not get hit.

After Project Zomboid determines you've been hit, it figures out if it is a scratch or laceration or bite.  Here is code from what happens if you are scratched.  The code for lacerations and bites is almost identical to this part:

                Float f2 = Float.valueOf(this.getParentChar().getBodyPartClothingDefense(n3, false, false));
                if (this.getHealth() > 0.0f) {
                    this.getParentChar().getEmitter().playSound("ZombieScratch");
                }
                if ((float)Rand.Next(100) < f2.floatValue()) {
                    return false;
                }

getBodyPartClothingDefense adds up the clothing protection from the body part being attacked, with a maximum of 100.  Remember, though, that if you acquired a hole right before this, your protection is lower than it was right before the attack.

If a random 0-99 roll is less than defense value of your clothes, the protection holds and nothing else happens.

If the protection doesn't hold, then the code continues and you take the damage (and possibly get the zombie infection).

Some Thoughts

If you are wearing magical longjohns with 100% protection to your upper torso, a single attack can put a hole in it and reduce that protection to 0%.  

If you are wearing layers, a single hole will not reduce your protection by as much, and if your layers gives you more than 100% protection, you may still have 100% protection!

Some items, like the Hard Hat, can't have holes.  Unless a Hard Hat gets knocked off, you will never take damage to the head while wearing it.


Thanks for reading!  If you see a mistake or want me to answer a question about the code, please let me know!


Update:  Project Zomboid developer lemmy101 posted that this is unintentional and will be fixed.  I'll be sure to follow up on this topic when that happens!

No comments:

Post a Comment

Do Gloves Protect You From Broken Glass?

Yes, gloves protect you from handling broken glass - any pair of gloves.  But gloves are not needed when removing broken glass from a smashe...