1
0

Fix armor protection (#4506)

* Fix armor protection

* Check min damage

* Check min damage

* Commit missing changes

* Convert to int

* Use float

* Float some more
This commit is contained in:
Mat 2020-03-22 12:39:32 +02:00 committed by GitHub
parent 49dd645aa6
commit c750c4e55f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 17 deletions

View File

@ -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);
cEntity::TakeDamage(a_DamageType, a_Attacker, a_RawDamage, static_cast<float>(FinalDamage), a_KnockbackAmount);
ApplyArmorDamage(static_cast<int>(ArmorCover));
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);
}

View File

@ -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 */