diff options
author | Mat <mail@mathias.is> | 2020-03-22 11:39:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-22 11:39:32 +0100 |
commit | c750c4e55fb103a99cc36ed76e247ae41a323581 (patch) | |
tree | a2d38f3a599ca4fdc9c9d06c5ca2486bc2eb189a /src/Entities/Entity.cpp | |
parent | Don't remove items twice (#4524) (diff) | |
download | cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar.gz cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar.bz2 cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar.lz cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar.xz cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.tar.zst cuberite-c750c4e55fb103a99cc36ed76e247ae41a323581.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Entities/Entity.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 87d385691..99f8b56b8 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -282,17 +282,12 @@ void cEntity::TakeDamage(cEntity & a_Attacker) void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, double a_KnockbackAmount) { - int ArmorCover = GetArmorCoverAgainst(a_Attacker, a_DamageType, a_RawDamage); - int EnchantmentCover = GetEnchantmentCoverAgainst(a_Attacker, a_DamageType, a_RawDamage); - int FinalDamage = a_RawDamage - ArmorCover - EnchantmentCover; - if ((FinalDamage == 0) && (a_RawDamage > 0)) - { - // Nobody's invincible - FinalDamage = 1; - } - ApplyArmorDamage(ArmorCover); + float FinalDamage = a_RawDamage; + float ArmorCover = GetArmorCoverAgainst(a_Attacker, a_DamageType, a_RawDamage); + + ApplyArmorDamage(static_cast<int>(ArmorCover)); - cEntity::TakeDamage(a_DamageType, a_Attacker, a_RawDamage, static_cast<float>(FinalDamage), a_KnockbackAmount); + cEntity::TakeDamage(a_DamageType, a_Attacker, a_RawDamage, FinalDamage, a_KnockbackAmount); } @@ -335,7 +330,19 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R { TDI.Attacker = nullptr; } + + if (a_RawDamage <= 0) + { + a_RawDamage = 0; + } + TDI.RawDamage = a_RawDamage; + + if (a_FinalDamage <= 0) + { + a_FinalDamage = 0; + } + TDI.FinalDamage = a_FinalDamage; Vector3d Heading(0, 0, 0); @@ -654,7 +661,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) -int cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +float cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) { int TotalEPF = 0; @@ -690,7 +697,7 @@ int cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType } } int CappedEPF = std::min(20, TotalEPF); - return static_cast<int>(a_Damage * CappedEPF / 25.0); + return (a_Damage * CappedEPF / 25.0f); } @@ -722,7 +729,7 @@ float cEntity::GetEnchantmentBlastKnockbackReduction() -int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) +float cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) { // Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover @@ -772,8 +779,8 @@ int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_Dama // TODO: Special armor cases, such as wool, saddles, dog's collar // Ref.: https://minecraft.gamepedia.com/Armor#Mob_armor as of 2012_12_20 - double Reduction = std::max(ArmorValue / 5.0, ArmorValue - a_Damage / (2 + Toughness / 4.0)); - return static_cast<int>(a_Damage * std::min(20.0, Reduction) / 25.0); + float Reduction = std::max(ArmorValue / 5.0f, ArmorValue - a_Damage / (2.0f + Toughness / 4.0f)); + return (a_Damage * std::min(20.0f, Reduction) / 25.0f); } |