1. Welcome to the Brawl website! Feel free to look around our forums. Join our growing community by typing /register in-game!

Mathematics of PVP: Guide for Damage Calculations for Reworks

Discussion in 'Guides' started by 2002Tiki, Mar 3, 2017.

Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...
  1. 2002Tiki

    2002Tiki Member

    Joined:
    Jan 23, 2016
    Messages:
    28
    Ratings:
    +14
    This is a semi in-depth guide for calculating damage for anyone looking to find how much damage their reworked class or new class would give/receive. Some of this may seem like basic knowledge to more experienced players, but to some I hope it will be helpful.

    The Basics
    As you know, in Minecraft you have 10 hearts, and each of this hearts can be split into two half-hearts. These half-hearts are called health points. So, naturally, you have 20 health points.

    If you punch a player with your fist and they have no armor, it damages them by 1 health point. Hitting them with a normal item or block also just deals 1 health point.

    Of course, if you hit them with a sword, it will do more damage. This means it will add extra damage onto that one health point from your fist. Here's a chart for damage added by swords (Remember, an extra health point is added for your fist).

    Wooden/Golden Sword: +4 damage
    Stone Sword: +5 damage
    Iron Sword: +6 damage
    Diamond Sword: +7 damage

    As for axes, until 1.9 is implemented the damage added by an axe is the damage of the sword of the same material minus 1. For example, the diamond axe adds 6 instead of 7, and the gold axe adds 3 instead of 4.

    So, to calculate how much damage you will deal with a sword, use the formula below. Let D be total damage and X be added damage from sword.

    D=X+1

    ______________________________________________________________________________

    Sharpness, Armor, and Critical Hits

    Sharpness

    At the moment, 3 classes (Dwarf, Elf, and Ninja) have sharpness on their swords. Sharpness simply adds 1.25 health points dealt to your sword per level. For example, a sharpness II wooden sword will deal 6.5 health points instead of the normal 4.

    Here's the formula for damage with sharpness. Let D be the total, x be the level, and p be the damage added by the sword.

    D=X(1.25)+P+1

    Reminder: The 1 is added for your fist damage.

    Armor
    Armor is a little more complicated. Above your hearts at the bottom of the screen is your armor bar. It has 10 shirts that can be split into 20 half shirts called armor points.

    Naturally, the maximum number of armor points is 20. Each armor point added decreases the damage dealt by 4%, meaning each full shirt decreases damage dealt by 8%.

    Here's a chart of armor points:

    Helmet:
    Diamond: 3 armor points
    Iron: 2 armor points
    Chain mail: 2 armor points
    Gold: 2 armor points
    Leather: 1 armor point

    Chest plate:
    Diamond: 8 armor points
    Iron: 6 armor points
    Chain mail: 5 armor points
    Gold: 5 armor points
    Leather: 3 armor points

    Leggings:
    Diamond: 6 armor points
    Iron: 5 armor points
    Chain mail: 4 armor points
    Gold: 3 armor points
    Leather: 2 armor points

    Boots:
    Diamond: 3 armor points
    Iron: 2 armor points
    Chain mail: 1 armor point
    Gold: 1 armor point
    Leather: 1 armor point

    To calculate damage dealt with armor, use the formula below. Let D be total damage taken, p be the original damage of the weapon, and x be the total number of armor points.

    D=P(1-(x*.04))

    Critical Hits (Crits)

    Critical hits, also known as crits, occur when you hit a player while falling. Critical hits simply add 50% to the damage dealt, rounded down.

    Here's the formula. Let D be the damage with the crit and X be the damage of the sword without the crit.

    D=1.5*x

    ______________________________________________________________________________

    Final Damage Formulas

    This is the complete formula for finding damage dealt in a hit without a critical hit. Let D be the final damage, X be the swords starting added damage, S be the sharpness level, and A be the armor points.

    D=(X+1.25S+1)/(1+.08A)

    This is the complete formula for finding damage dealt in a hit with a critical hit.

    D=(1.5(X+1.25S+1))*(1-.04A)

    ______________________________________________________________________________

    This guide was made for CTF rework information, but obviously other gamemodes could use it for calculations. I also made a spreadsheet that does this calculations a lot quicker just by a few quick number inputs, PM me if you are interested in me sharing a copy to you and I will be happy to do so.

    If anyone notices any problems with this let me know in the comments and I'll fix it :smile:

    Tl;Dr

    Just read the final damage formulas at the end.
     
    • Like Like x 7
    • Informative Informative x 2
    • Useful Useful x 1
    • MVP Honor MVP Honor x 1
    #1 2002Tiki, Mar 3, 2017
    Last edited: Mar 7, 2017
  2. Magnificent

    Magnificent Dallas Fuel

    Joined:
    Jul 19, 2015
    Messages:
    1,409
    Ratings:
    +377
    I can left click and that's all that matters
     
    • Agree Agree x 2
    • Informative Informative x 2
  3. Phanta

    Phanta Well-Known Member

    Joined:
    Jan 1, 2014
    Messages:
    2,555
    Ratings:
    +997
    I had a copy of the source code handy so I figured I might as well take a look

    I'll provide some pseudocode snippets that show what's going on, but the real code is probably illegal to distribute, and my body isn't ready for the Mojang(tm) lawyers

    Code:
    if (player is invulnerable) or (player is in creative) or (health < 0):
        cancel damage
    
    Simple checks to make sure the player is able to take damage

    Code:
    if (player is sleeping):
        wake up player
    
    That's just rude.

    Code:
    if (damage amount is 0):
        cancel damage
    
    We don't care if the amount of damage to deal is zero, so we just kill the event to save cpu cycles.

    Code:
    if (damage is of fire type) and (player has fire resist potion effect):
        cancel damage
    
    Prevents fire damage if the player has fire resist.

    Code:
    if (damage is from a falling block) and (player is wearing a helmet):
        damage the helmet for `2d (2 + rand(0, 1))`
        multiply damage amount by 0.75
    
    If the player has a helmet and you drop an anvil on them, the helmet takes damage equal to that formula, where d is the amount of damage dealt and the rand(x, y) function generates a random number from x, inclusively, to y, exclusively. Then, the total damage is reduced by 25%. Essentially, the helmet is taking some of the damage for the player.

    Code:
    if (player was hit recently):
        if (damage amount <= previous damage amount):
            cancel damage
        deal damage
    else:
        deal damage
        grant invincibility frames
    
    This part is kind of strange. We all know about the invincibility frames you receive after taking a hit, but apparently the invincibility only applies if the amount of damage taken in the second hit is greater than the amount in the first hit. What's even weirder is that this applies after the anvil thing, so getting an anvil dropped on you while you have invincibility frames might negate the damage to you but still damage your helmet. Furthermore, you don't get additional invincibility frames if you take damage from this second hit, which is just weird.

    Now let's take a look at that "deal damage" bit. If we expand it into pseudocode, it look something like this:
    Code:
    if (damage source is affected by armour):
        damage armour for `d(25 - a)`
        set damage to `d(25 - a) / 25`
    
    First, we check to make sure the damage can be blocked by armour; potion damage, for example, bypasses armour. Then we damage the armour and reduce the total damage by those formulae above. The d stands for the damage amount, and the a stands for the player's armour. Since the maximum armor value is 20, damage can be reduced by 80% at most. Essentially, each point of armour reduces the damage by 4%.

    Code:
    if (player has resistance) and (damage is affected by potions):
        set damage to `d(25 - 5(r + 1)) / 25`
        if (damage < 0):
            set damage to 0
    
    Nullifies some damage based on resistance. r here represents the potion effect level, starting at 0 for Resistance I, 1 for Resistance II, and so on. It would appear to cap at 4, or Resistance V, since the multiplier becomes 0 at that point. Essentially, damage is reduced by 20% for each level of resistance.

    Code:
    for each armour item:
        if (item has protection):
            add `0.75(6 + p^2) / 3` to the total protection
        else if (item has fire protection) and (damage source is of fire type):
            add `1.25(6 + p^2) / 3` to the total protection
        else if (item has feather falling) and (damage source is of falling type):
            add `2.5(6 + p^2) / 3` to the total protection
        else if (item has blast protection) and (damage source is of explosive type):
            add `1.5(6 + p^2) / 3` to the total protection
        else if (item has projectile protection) and (damage source is of projectile type):
            add `1.5(6 + p^2) / 3` to the total protection
    clamp the total protection between 0 and 25
    set total protection to `((p + 1) / 2) + (rand(0, 1 + p / 2))`
    set damage to `d(25 - p) / 25`
    
    Wow, what a mess. We'll just ignore all protection types except general protection, which is at the top of this massive if-else chain. For each protection item, we add an amount to the total protection based on the formula above, where p represents the level of the enchantment, starting at 0 for Protection I. Since p is squared, higher levels of the enchantment offer more additional protection than lower levels. After summing up all the protection, we do some weird math on it and reduce the damage respectively. I think I can reduce it to this formula here:
    Code:
    M = 0.98 - ((4.5n + 0.75(p1^2 + p2^2 + ...)) / 150)
    
    Where M is the multiplier for damage, n is the total number of armour pieces with protection, and p1, p2, etc. are the various levels of protection on armour. Not a very nice looking formula.

    Code:
    subtract damage from health
    
    Finally, the important bit! There's also some logic involving absorption before this, but we don't really care about that.

    If we take all the damage modifiers and combine them into a massive formula, here's what it looks like (assuming the damage source is someone hitting you):
    Code:
    Df = Di * (1 - a / 25) * (1 - (r + 1) / 5) * (0.98 - ((4.5n + 0.75(p1^2 + p2^2 + ... + pn^2)) / 150))
    
    ew.

    also i did this all at 11:30 so there might be some wrong stuff
     
    • Like Like x 3
    #3 Phanta, Mar 4, 2017
    Last edited: Mar 4, 2017
  4. THECOMMANDER5643

    THECOMMANDER5643 Well-Known Member

    Joined:
    May 18, 2015
    Messages:
    192
    Ratings:
    +97
    Nice Job Tiki.
     
    • Like Like x 1
  5. Salty_Ivan

    Salty_Ivan Well-Known Member

    Joined:
    Aug 26, 2015
    Messages:
    535
    Ratings:
    +92
    Discord:
    Whale#7514
    D=X(P+1)
    This implies Dwarf's diamond sword with Sharpness XI deals 88 health points of damage, or 44 hearts.
    Psssst... It doesn't.
     
  6. 2002Tiki

    2002Tiki Member

    Joined:
    Jan 23, 2016
    Messages:
    28
    Ratings:
    +14
    Edited xD
     
  7. lnformative

    lnformative Well-Known Member

    Joined:
    Jun 10, 2015
    Messages:
    568
    Ratings:
    +193
    You are a ****ing legend
     
Loading...
Similar Threads Forum Date
Other The Mathematics of a Rock Literature Jan 31, 2016
Advanced Chemist Guide Guides Nov 2, 2021
rsugars guide to getting rich on raid Raid Jan 29, 2021
The Ultimate Party Map Making Guide Map Submissions Jan 16, 2021
MCCTF Special Gamemodes & misc Guide (Offical?) Guides Mar 19, 2020
Thread Status:
Please be aware that this thread is more than 30 days old. Do not post unless the topic can still be discussed. Read more...