summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp37
-rw-r--r--src/Entities/Entity.h4
2 files changed, 24 insertions, 17 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);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 563db7b9e..a6404a128 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -357,10 +357,10 @@ public:
virtual bool ArmorCoversAgainst(eDamageType a_DamageType);
/** Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover */
- virtual int GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage);
+ virtual float GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage);
/** Returns the hitpoints that the currently equipped armor's enchantments would cover */
- virtual int GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage);
+ virtual float GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage);
/** Returns explosion knock back reduction percent from blast protection level
@return knock back reduce percent */