Core/Creatures: optimized sparring checks by handling them via variable instead of map lookups and expose its value to helpers to allow manipulation during runtime

This commit is contained in:
Ovahlord committed 2021-07-26 15:48:16 +02:00
1 parent ae13da2159
commit 0dfa919f09
4 files changed
+22 -40

No files matched your search

+9 -23
View File
@@ -763,15 +763,13 @@ uint32 Unit::DealDamage(Unit* victim, uint32 damage, CleanDamage const* cleanDam
// Sparring Checks
if (Creature* target = victim->ToCreature())
{
if (GetTypeId() == TYPEID_UNIT && !IsCharmedOwnedByPlayerOrPlayer())
if (IsCreature() && !IsCharmedOwnedByPlayerOrPlayer())
{
float sparringLimitPct = target->GetSparringHealthLimit();
if (sparringLimitPct != 0.0f)
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
{
if (damage >= target->GetHealth()) // First check: if we have a sparring limit we will never allow creatures to kill the sparring victim
damage = target->GetHealth() - 1;
else if (target->GetHealthPct() <= sparringLimitPct) // Second check: stop incomming damage when we have surpassed the health limit
else if (target->GetHealthPct() <= target->GetNoNpcDamageBelowPctHealthValue()) // Second check: stop incomming damage when we have surpassed the health limit
damage = 0;
}
}
@@ -1949,16 +1947,10 @@ void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
// Sparring Checks
if (Creature* target = damageInfo.GetVictim()->ToCreature())
{
if (caster->GetTypeId() == TYPEID_UNIT && !caster->IsCharmedOwnedByPlayerOrPlayer())
{
float sparringLimitPct = target->GetSparringHealthLimit();
if (sparringLimitPct != 0.0f)
if (target->GetHealthPct() <= sparringLimitPct)
if (IsCreature() && !IsCharmedOwnedByPlayerOrPlayer())
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
if (target->GetHealthPct() <= target->GetNoNpcDamageBelowPctHealthValue())
damageInfo.ModifyDamage(damageInfo.GetDamage() * -1);
}
}
SendSpellNonMeleeDamageLog(caster, (*itr)->GetSpellInfo()->Id, splitDamage, damageInfo.GetSchoolMask(), split_absorb, 0, false, 0, false);
@@ -2096,16 +2088,10 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr
// Sparring Checks
if (Creature* target = victim->ToCreature())
{
if (GetTypeId() == TYPEID_UNIT && !IsCharmedOwnedByPlayerOrPlayer())
{
float sparringLimitPct = target->GetSparringHealthLimit();
if (sparringLimitPct != 0.0f)
if (target->GetHealthPct() <= sparringLimitPct)
if (IsCreature() && !IsCharmedOwnedByPlayerOrPlayer())
if (target->GetNoNpcDamageBelowPctHealthValue() != 0.0f)
if (target->GetHealthPct() <= target->GetNoNpcDamageBelowPctHealthValue())
damageInfo.HitInfo |= HITINFO_FAKE_DAMAGE;
}
}
SendAttackStateUpdate(&damageInfo);