Core/Spells: ported resistance and immunity updates from 3.3.5 branch

This commit is contained in:
Ovahlord committed 2021-06-12 14:10:44 +02:00
1 parent eef9796dd3
commit 8011d2de29
11 files changed
+378 -82

No files matched your search

+182 -70
View File
@@ -1140,8 +1140,12 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage* damageInfo, int32 dama
// Physical Damage
if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL)
{
// Get blocked status
blocked = isSpellBlocked(victim, spellInfo);
// Spells with this attribute were already calculated in MeleeSpellHitResult
if (spellInfo->HasAttribute(SPELL_ATTR8_CANT_BLOCK))
{
// Get blocked status
blocked = isSpellBlocked(victim, spellInfo);
}
}
if (crit)
@@ -1606,7 +1610,7 @@ bool Unit::IsDamageReducedByArmor(SpellSchoolMask schoolMask, SpellInfo const* s
return true;
}
uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType /*attackType*/)
uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo const* spellInfo, WeaponAttackType /*attackType*/) const
{
float armor = float(victim->GetArmor());
@@ -1652,52 +1656,32 @@ uint32 Unit::CalcArmorReducedDamage(Unit* victim, const uint32 damage, SpellInfo
return std::max<uint32>(damage * (1.0f - tmpvalue), 1);
}
uint32 Unit::CalcSpellResistance(Unit* victim, SpellSchoolMask schoolMask, SpellInfo const* spellInfo) const
uint32 Unit::CalcSpellResistedDamage(Unit* victim, uint32 damage, SpellSchoolMask schoolMask, SpellInfo const* spellInfo) const
{
// Magic damage, check for resists
if (!(schoolMask & SPELL_SCHOOL_MASK_SPELL))
if (!(schoolMask & SPELL_SCHOOL_MASK_MAGIC))
return 0;
// Npcs can have holy resistance
if ((schoolMask & SPELL_SCHOOL_MASK_HOLY) && victim->GetTypeId() != TYPEID_UNIT)
return 0;
// Ignore spells that can't be resisted
if (spellInfo && spellInfo->HasAttribute(SPELL_ATTR4_IGNORE_RESISTANCES))
return 0;
uint8 const bossLevel = 83;
uint32 const bossResistanceConstant = 510;
uint32 resistanceConstant = 0;
uint8 level = victim->getLevel();
if (level == bossLevel)
resistanceConstant = bossResistanceConstant;
else
resistanceConstant = level * 5;
int32 baseVictimResistance = victim->GetResistance(schoolMask);
baseVictimResistance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask);
if (Player const* player = ToPlayer())
baseVictimResistance -= player->GetSpellPenetrationItemMod();
// Resistance can't be lower then 0
int32 victimResistance = std::max<int32>(baseVictimResistance, 0);
if (victimResistance > 0)
// Ignore spells that can't be resisted
if (spellInfo)
{
int32 ignoredResistance = 0;
if (spellInfo->HasAttribute(SPELL_ATTR4_IGNORE_RESISTANCES))
return 0;
AuraEffectList const& ResIgnoreAuras = GetAuraEffectsByType(SPELL_AURA_MOD_IGNORE_TARGET_RESIST);
for (AuraEffectList::const_iterator itr = ResIgnoreAuras.begin(); itr != ResIgnoreAuras.end(); ++itr)
if ((*itr)->GetMiscValue() & schoolMask)
ignoredResistance += (*itr)->GetAmount();
ignoredResistance = std::min<int32>(ignoredResistance, 100);
ApplyPct(victimResistance, 100 - ignoredResistance);
// Binary spells can't have damage part resisted
if (spellInfo->HasAttribute(SPELL_ATTR0_CU_BINARY_SPELL))
return 0;
}
if (victimResistance <= 0)
return 0;
float averageResist = float(victimResistance) / float(victimResistance + resistanceConstant);
float averageResist = Unit::GetEffectiveResistChance(this, schoolMask, victim, spellInfo);
float discreteResistProbability[11];
for (uint32 i = 0; i < 11; ++i)
@@ -1721,7 +1705,66 @@ uint32 Unit::CalcSpellResistance(Unit* victim, SpellSchoolMask schoolMask, Spell
while (r >= probabilitySum && resistance < 10)
probabilitySum += discreteResistProbability[++resistance];
return resistance * 10;
float damageResisted = float(damage * resistance / 10);
if (damageResisted > 0.0f) // if any damage was resisted
{
int32 ignoredResistance = GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_IGNORE_TARGET_RESIST, schoolMask);
ignoredResistance = std::min<int32>(ignoredResistance, 100);
ApplyPct(damageResisted, 100 - ignoredResistance);
// Spells with melee and magic school mask, decide whether resistance or armor absorb is higher
if (spellInfo && spellInfo->HasAttribute(SPELL_ATTR0_CU_SCHOOLMASK_NORMAL_WITH_MAGIC))
{
uint32 damageAfterArmor = CalcArmorReducedDamage(victim, damage, spellInfo, BASE_ATTACK);
uint32 armorReduction = damage - damageAfterArmor;
if (armorReduction < damageResisted) // pick the lower one, the weakest resistance counts
damageResisted = armorReduction;
}
}
return damageResisted;
}
float Unit::GetEffectiveResistChance(Unit const* owner, SpellSchoolMask schoolMask, Unit const* victim, SpellInfo const* spellInfo)
{
float victimResistance = float(victim->GetResistance(schoolMask));
if (owner)
{
// pets inherit 100% of masters penetration
// excluding traps
Player const* player = owner->GetSpellModOwner();
if (player && owner->GetEntry() != WORLD_TRIGGER)
{
victimResistance += float(player->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
victimResistance -= float(player->GetSpellPenetrationItemMod());
}
else
victimResistance += float(owner->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_RESISTANCE, schoolMask));
}
// holy resistance exists in pve and comes from level difference, ignore template values
if (schoolMask & SPELL_SCHOOL_MASK_HOLY)
victimResistance = 0.0f;
// Chaos Bolt exception, ignore all target resistances (unknown attribute?)
if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARLOCK && spellInfo->SpellIconID == 3178)
victimResistance = 0.0f;
victimResistance = std::max(victimResistance, 0.0f);
if (owner)
victimResistance += std::max((float(victim->getLevelForTarget(owner)) - float(owner->getLevelForTarget(victim))) * 5.0f, 0.0f);
static uint32 const BOSS_LEVEL = 83;
static float const BOSS_RESISTANCE_CONSTANT = 510.0f;
uint32 level = victim->getLevel();
float resistanceConstant = 0.0f;
if (level == BOSS_LEVEL)
resistanceConstant = BOSS_RESISTANCE_CONSTANT;
else
resistanceConstant = level * 5.0f;
return victimResistance / (victimResistance + resistanceConstant);
}
void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
@@ -1729,8 +1772,8 @@ void Unit::CalcAbsorbResist(DamageInfo& damageInfo)
if (!damageInfo.GetVictim() || !damageInfo.GetVictim()->IsAlive() || !damageInfo.GetDamage())
return;
uint32 spellResistance = CalcSpellResistance(damageInfo.GetVictim(), damageInfo.GetSchoolMask(), damageInfo.GetSpellInfo());
damageInfo.ResistDamage(CalculatePct(damageInfo.GetDamage(), spellResistance));
uint32 resistedDamage = CalcSpellResistedDamage(damageInfo.GetVictim(), damageInfo.GetDamage(), damageInfo.GetSchoolMask(), damageInfo.GetSpellInfo());
damageInfo.ResistDamage(resistedDamage);
// Ignore Absorption Auras
float auraAbsorbMod(GetMaxPositiveAuraModifierByMiscMask(SPELL_AURA_MOD_TARGET_ABSORB_SCHOOL, damageInfo.GetSchoolMask()));
@@ -2584,8 +2627,19 @@ SpellMissInfo Unit::MagicSpellHitResult(Unit* victim, SpellInfo const* spellInfo
// Chance resist mechanic (select max value from every mechanic spell effect)
int32 resist_chance = victim->GetMechanicResistChance(spellInfo) * 100;
tmp += resist_chance;
// Chance resist debuff
if (!spellInfo->IsPositive() && !spellInfo->HasAttribute(SPELL_ATTR4_IGNORE_RESISTANCES))
{
// resistance for binary spells
if (spellInfo->HasAttribute(SPELL_ATTR0_CU_BINARY_SPELL) && (spellInfo->GetSchoolMask() & SPELL_SCHOOL_MASK_NORMAL) == 0)
if ((spellInfo->GetSchoolMask() & SPELL_SCHOOL_MASK_HOLY) == 0 || victim->GetTypeId() == TYPEID_UNIT)
tmp += int32(Unit::GetEffectiveResistChance(this, spellInfo->GetSchoolMask(), victim, spellInfo) * 10000.0f); // 100 for spell calculations, and 100 for return value percentage
}
// Roll chance
if (resist_chance > 0 && rand < (tmp += resist_chance))
if (rand < tmp)
return SPELL_MISS_RESIST;
// cast by caster in front of victim
@@ -4082,9 +4136,28 @@ void Unit::RemoveAurasWithFamily(SpellFamilyNames family, uint32 familyFlag1, ui
}
}
void Unit::RemoveMovementImpairingAuras()
void Unit::RemoveMovementImpairingAuras(bool withRoot)
{
RemoveAurasWithMechanic((1<<MECHANIC_SNARE)|(1<<MECHANIC_ROOT));
if (withRoot)
RemoveAurasWithMechanic(1 << MECHANIC_ROOT);
// Snares
for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end();)
{
Aura const* aura = iter->second->GetBase();
if (aura->GetSpellInfo()->Mechanic == MECHANIC_SNARE)
{
RemoveAura(iter);
continue;
}
// turn off snare auras by setting amount to 0
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
if (((1 << i) & iter->second->GetEffectMask()) && aura->GetSpellInfo()->Effects[i].Mechanic == MECHANIC_SNARE)
aura->GetEffect(i)->ChangeAmount(0);
++iter;
}
}
void Unit::RemoveAurasWithMechanic(uint32 mechanic_mask, AuraRemoveFlags removemode, uint32 except)
@@ -4104,6 +4177,21 @@ void Unit::RemoveAurasWithMechanic(uint32 mechanic_mask, AuraRemoveFlags removem
}
}
void Unit::RemoveAurasByShapeShift()
{
uint32 mechanic_mask = (1 << MECHANIC_SNARE) | (1 << MECHANIC_ROOT);
for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end();)
{
Aura const* aura = iter->second->GetBase();
if ((aura->GetSpellInfo()->GetAllEffectsMechanicMask() & mechanic_mask) && !aura->GetSpellInfo()->HasAttribute(SPELL_ATTR0_CU_AURA_CC))
{
RemoveAura(iter);
continue;
}
++iter;
}
}
void Unit::RemoveAreaAurasDueToLeaveWorld()
{
// make sure that all area auras not applied on self are removed - prevent access to deleted pointer later
@@ -7628,17 +7716,18 @@ int32 Unit::SpellBaseHealingBonusTaken(SpellSchoolMask schoolMask) const
bool Unit::IsImmunedToDamage(SpellSchoolMask schoolMask) const
{
if (schoolMask == SPELL_SCHOOL_MASK_NONE)
return false;
// If m_immuneToSchool type contain this school type, IMMUNE damage.
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
if ((itr->first & schoolMask) != 0)
return true;
uint32 schoolImmunityMask = GetSchoolImmunityMask();
if ((schoolImmunityMask & schoolMask) == schoolMask) // We need to be immune to all types
return true;
// If m_immuneToDamage type contain magic, IMMUNE damage.
SpellImmuneContainer const& damageList = m_spellImmune[IMMUNITY_DAMAGE];
for (auto itr = damageList.begin(); itr != damageList.end(); ++itr)
if ((itr->first & schoolMask) != 0)
return true;
uint32 damageImmunityMask = GetDamageImmunityMask();
if ((damageImmunityMask & schoolMask) == schoolMask) // We need to be immune to all types
return true;
return false;
}
@@ -7655,18 +7744,24 @@ bool Unit::IsImmunedToDamage(SpellInfo const* spellInfo) const
if (spellInfo->HasAttribute(SPELL_ATTR1_UNAFFECTED_BY_SCHOOL_IMMUNE) || spellInfo->HasAttribute(SPELL_ATTR2_UNAFFECTED_BY_AURA_SCHOOL_IMMUNE))
return false;
uint32 schoolMask = spellInfo->GetSchoolMask();
// If m_immuneToSchool type contain this school type, IMMUNE damage.
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
if ((itr->first & schoolMask) && !spellInfo->CanPierceImmuneAura(sSpellMgr->GetSpellInfo(itr->second)))
if (uint32 schoolMask = spellInfo->GetSchoolMask())
{
// If m_immuneToSchool type contain this school type, IMMUNE damage.
uint32 schoolImmunityMask = 0;
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
if ((itr->first & schoolMask) && !spellInfo->CanPierceImmuneAura(sSpellMgr->GetSpellInfo(itr->second)))
schoolImmunityMask |= itr->first;
// // We need to be immune to all types
if ((schoolImmunityMask & schoolMask) == schoolMask)
return true;
// If m_immuneToDamage type contain magic, IMMUNE damage.
SpellImmuneContainer const& damageList = m_spellImmune[IMMUNITY_DAMAGE];
for (auto itr = damageList.begin(); itr != damageList.end(); ++itr)
if ((itr->first & schoolMask) != 0)
// If m_immuneToDamage type contain magic, IMMUNE damage.
uint32 damageImmunityMask = GetDamageImmunityMask();
if ((damageImmunityMask & schoolMask) == schoolMask) // We need to be immune to all types
return true;
}
return false;
}
@@ -7720,16 +7815,23 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster, Optional<u
if (immuneToAllEffects) //Return immune only if the target is immune to all spell effects.
return true;
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
if (uint32 schoolMask = spellInfo->GetSchoolMask())
{
if (!(itr->first & spellInfo->GetSchoolMask()))
continue;
uint32 schoolImmunityMask = 0;
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
{
if ((itr->first & schoolMask) == 0)
continue;
SpellInfo const* immuneSpellInfo = sSpellMgr->GetSpellInfo(itr->second);
if (!(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive() && caster && IsFriendlyTo(caster)))
if (!spellInfo->CanPierceImmuneAura(immuneSpellInfo))
return true;
SpellInfo const* immuneSpellInfo = sSpellMgr->GetSpellInfo(itr->second);
if (!(immuneSpellInfo && immuneSpellInfo->IsPositive() && spellInfo->IsPositive() && caster && IsFriendlyTo(caster)))
if (!spellInfo->CanPierceImmuneAura(immuneSpellInfo))
schoolImmunityMask |= itr->first;
}
if ((schoolImmunityMask & schoolMask) == schoolMask)
return true;
}
return false;
@@ -7738,8 +7840,18 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, Unit* caster, Optional<u
uint32 Unit::GetSchoolImmunityMask() const
{
uint32 mask = 0;
SpellImmuneContainer const& mechanicList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = mechanicList.begin(); itr != mechanicList.end(); ++itr)
SpellImmuneContainer const& schoolList = m_spellImmune[IMMUNITY_SCHOOL];
for (auto itr = schoolList.begin(); itr != schoolList.end(); ++itr)
mask |= itr->first;
return mask;
}
uint32 Unit::GetDamageImmunityMask() const
{
uint32 mask = 0;
SpellImmuneContainer const& damageList = m_spellImmune[IMMUNITY_DAMAGE];
for (auto itr = damageList.begin(); itr != damageList.end(); ++itr)
mask |= itr->first;
return mask;