Core/Auras: Improve aura interactions with immunities on spell effect level
* Effects that target is immune to will be suppressed instead of completely removed
This commit is contained in:
1 parent
0f4442c630
commit
c3b52fd29f
12 files changed
+147
-97
No files matched your search
@@ -3465,59 +3465,59 @@ void Unit::RemoveAura(Aura* aura, AuraRemoveFlags mode)
|
||||
RemoveAura(aurApp, mode);
|
||||
}
|
||||
|
||||
void Unit::RemoveAppliedAuras(std::function<bool(AuraApplication const*)> const& check)
|
||||
void Unit::RemoveAppliedAuras(std::function<bool(AuraApplication const*)> const& check, AuraRemoveFlags removeMode /* = AuraRemoveFlags::ByDefault*/)
|
||||
{
|
||||
for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end();)
|
||||
{
|
||||
if (check(iter->second))
|
||||
{
|
||||
RemoveAura(iter);
|
||||
RemoveAura(iter, removeMode);
|
||||
continue;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::RemoveOwnedAuras(std::function<bool(Aura const*)> const& check)
|
||||
void Unit::RemoveOwnedAuras(std::function<bool(Aura const*)> const& check, AuraRemoveFlags removeMode /* = AuraRemoveFlags::ByDefault*/)
|
||||
{
|
||||
for (AuraMap::iterator iter = m_ownedAuras.begin(); iter != m_ownedAuras.end();)
|
||||
{
|
||||
if (check(iter->second))
|
||||
{
|
||||
RemoveOwnedAura(iter);
|
||||
RemoveOwnedAura(iter, removeMode);
|
||||
continue;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::RemoveAppliedAuras(uint32 spellId, std::function<bool(AuraApplication const*)> const& check)
|
||||
void Unit::RemoveAppliedAuras(uint32 spellId, std::function<bool(AuraApplication const*)> const& check, AuraRemoveFlags removeMode /* = AuraRemoveFlags::ByDefault*/)
|
||||
{
|
||||
for (AuraApplicationMap::iterator iter = m_appliedAuras.lower_bound(spellId); iter != m_appliedAuras.upper_bound(spellId);)
|
||||
{
|
||||
if (check(iter->second))
|
||||
{
|
||||
RemoveAura(iter);
|
||||
RemoveAura(iter, removeMode);
|
||||
continue;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::RemoveOwnedAuras(uint32 spellId, std::function<bool(Aura const*)> const& check)
|
||||
void Unit::RemoveOwnedAuras(uint32 spellId, std::function<bool(Aura const*)> const& check, AuraRemoveFlags removeMode /* = AuraRemoveFlags::ByDefault*/)
|
||||
{
|
||||
for (AuraMap::iterator iter = m_ownedAuras.lower_bound(spellId); iter != m_ownedAuras.upper_bound(spellId);)
|
||||
{
|
||||
if (check(iter->second))
|
||||
{
|
||||
RemoveOwnedAura(iter);
|
||||
RemoveOwnedAura(iter, removeMode);
|
||||
continue;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::RemoveAurasByType(AuraType auraType, std::function<bool(AuraApplication const*)> const& check)
|
||||
void Unit::RemoveAurasByType(AuraType auraType, std::function<bool(AuraApplication const*)> const& check, AuraRemoveFlags removeMode /* = AuraRemoveFlags::ByDefault*/)
|
||||
{
|
||||
for (AuraEffectList::iterator iter = m_modAuras[auraType].begin(); iter != m_modAuras[auraType].end();)
|
||||
{
|
||||
@@ -3529,7 +3529,7 @@ void Unit::RemoveAurasByType(AuraType auraType, std::function<bool(AuraApplicati
|
||||
if (check(aurApp))
|
||||
{
|
||||
uint32 removedAuras = m_removedAurasCount;
|
||||
RemoveAura(aurApp);
|
||||
RemoveAura(aurApp, removeMode);
|
||||
if (m_removedAurasCount > removedAuras + 1)
|
||||
iter = m_modAuras[auraType].begin();
|
||||
}
|
||||
@@ -3856,42 +3856,31 @@ void Unit::RemoveAurasWithFamily(SpellFamilyNames family, uint32 familyFlag1, ui
|
||||
void Unit::RemoveMovementImpairingAuras(bool withRoot)
|
||||
{
|
||||
if (withRoot)
|
||||
RemoveAurasWithMechanic(1 << MECHANIC_ROOT);
|
||||
RemoveAurasWithMechanic(1 << MECHANIC_ROOT, AuraRemoveFlags::ByDefault, 0, true);
|
||||
|
||||
// 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;
|
||||
}
|
||||
RemoveAurasWithMechanic(1 << MECHANIC_ROOT, AuraRemoveFlags::ByDefault, 0, false);
|
||||
}
|
||||
|
||||
void Unit::RemoveAurasWithMechanic(uint32 mechanic_mask, AuraRemoveFlags removemode, uint32 except)
|
||||
void Unit::RemoveAurasWithMechanic(uint32 mechanicMaskToRemove, AuraRemoveFlags removeMode, uint32 exceptSpellId, bool withEffectMechanics)
|
||||
{
|
||||
for (AuraApplicationMap::iterator iter = m_appliedAuras.begin(); iter != m_appliedAuras.end();)
|
||||
RemoveAppliedAuras([=](AuraApplication const* aurApp)
|
||||
{
|
||||
Aura const* aura = iter->second->GetBase();
|
||||
if (!except || aura->GetId() != except)
|
||||
{
|
||||
if (aura->GetSpellInfo()->GetAllEffectsMechanicMask() & mechanic_mask)
|
||||
{
|
||||
RemoveAura(iter, removemode);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
Aura* aura = aurApp->GetBase();
|
||||
if (exceptSpellId && aura->GetId() == exceptSpellId)
|
||||
return false;
|
||||
|
||||
uint32 appliedMechanicMask = aura->GetSpellInfo()->GetSpellMechanicMaskByEffectMask(aurApp->GetEffectMask());
|
||||
if (!(appliedMechanicMask & mechanicMaskToRemove))
|
||||
return false;
|
||||
|
||||
// spell mechanic matches required mask for removal
|
||||
if ((1 << aura->GetSpellInfo()->Mechanic) & mechanicMaskToRemove || withEffectMechanics)
|
||||
return true;
|
||||
|
||||
// effect mechanic matches required mask for removal - don't remove, only update targets
|
||||
aura->UpdateTargetMap(aura->GetCaster());
|
||||
return false;
|
||||
}, removeMode);
|
||||
}
|
||||
|
||||
void Unit::RemoveAurasByShapeShift()
|
||||
@@ -7313,14 +7302,30 @@ bool Unit::IsImmunedToDamage(SpellInfo const* spellInfo) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caster) const
|
||||
bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caster, bool requireImmunityPurgesEffectAttribute /*= false*/) const
|
||||
{
|
||||
if (!spellInfo)
|
||||
return false;
|
||||
|
||||
auto hasImmunity = [requireImmunityPurgesEffectAttribute](SpellImmuneContainer const& container, uint32 key)
|
||||
{
|
||||
Trinity::IteratorPair<SpellImmuneContainer::const_iterator> range = Trinity::Containers::MapEqualRange(container, key);
|
||||
if (!requireImmunityPurgesEffectAttribute)
|
||||
return range.begin() != range.end();
|
||||
|
||||
return std::any_of(range.begin(), range.end(), [](SpellImmuneContainer::value_type const& entry)
|
||||
{
|
||||
if (SpellInfo const* immunitySourceSpell = sSpellMgr->GetSpellInfo(entry.second))
|
||||
if (immunitySourceSpell->HasAttribute(SPELL_ATTR1_IMMUNITY_PURGES_EFFECT))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
// Single spell immunity.
|
||||
SpellImmuneContainer const& idList = m_spellImmune[IMMUNITY_ID];
|
||||
if (idList.count(spellInfo->Id) > 0)
|
||||
if (hasImmunity(idList, spellInfo->Id))
|
||||
return true;
|
||||
|
||||
if (spellInfo->HasAttribute(SPELL_ATTR0_NO_IMMUNITIES))
|
||||
@@ -7329,7 +7334,7 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caste
|
||||
if (uint32 dispel = spellInfo->Dispel)
|
||||
{
|
||||
SpellImmuneContainer const& dispelList = m_spellImmune[IMMUNITY_DISPEL];
|
||||
if (dispelList.count(dispel) > 0)
|
||||
if (hasImmunity(dispelList, dispel))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7337,7 +7342,7 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caste
|
||||
if (uint32 mechanic = spellInfo->Mechanic)
|
||||
{
|
||||
SpellImmuneContainer const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
|
||||
if (mechanicList.count(mechanic) > 0)
|
||||
if (hasImmunity(mechanicList, mechanic))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7349,7 +7354,7 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caste
|
||||
if (!spellInfo->Effects[i].IsEffect())
|
||||
continue;
|
||||
|
||||
if (!IsImmunedToSpellEffect(spellInfo, i, caster))
|
||||
if (!IsImmunedToSpellEffect(spellInfo, i, caster, requireImmunityPurgesEffectAttribute))
|
||||
{
|
||||
immuneToAllEffects = false;
|
||||
break;
|
||||
@@ -7374,7 +7379,8 @@ bool Unit::IsImmunedToSpell(SpellInfo const* spellInfo, WorldObject const* caste
|
||||
|
||||
// Consider the school immune if any of these conditions are not satisfied.
|
||||
// In case of no immuneSpellInfo, ignore that condition and check only the other conditions
|
||||
if ((immuneSpellInfo && !immuneSpellInfo->IsPositive()) || !spellInfo->IsPositive() || !caster || !IsFriendlyTo(caster))
|
||||
if ((immuneSpellInfo && !immuneSpellInfo->IsPositive() && (!requireImmunityPurgesEffectAttribute || immuneSpellInfo->HasAttribute(SPELL_ATTR1_IMMUNITY_PURGES_EFFECT)))
|
||||
|| !spellInfo->IsPositive() || !caster || !IsFriendlyTo(caster))
|
||||
if (!spellInfo->CanPierceImmuneAura(immuneSpellInfo))
|
||||
schoolImmunityMask |= itr->first;
|
||||
}
|
||||
@@ -7416,7 +7422,8 @@ uint32 Unit::GetMechanicImmunityMask() const
|
||||
return mask;
|
||||
}
|
||||
|
||||
bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, WorldObject const* caster) const
|
||||
bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, WorldObject const* caster,
|
||||
bool requireImmunityPurgesEffectAttribute /*= false*/) const
|
||||
{
|
||||
if (!spellInfo || !spellInfo->Effects[index].IsEffect())
|
||||
return false;
|
||||
@@ -7424,16 +7431,33 @@ bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Worl
|
||||
if (spellInfo->HasAttribute(SPELL_ATTR0_NO_IMMUNITIES))
|
||||
return false;
|
||||
|
||||
auto hasImmunity = [requireImmunityPurgesEffectAttribute](SpellImmuneContainer const& container, uint32 key)
|
||||
{
|
||||
Trinity::IteratorPair<SpellImmuneContainer::const_iterator> range = Trinity::Containers::MapEqualRange(container, key);
|
||||
if (!requireImmunityPurgesEffectAttribute)
|
||||
return range.begin() != range.end();
|
||||
|
||||
return std::any_of(range.begin(), range.end(), [](SpellImmuneContainer::value_type const& entry)
|
||||
{
|
||||
if (SpellInfo const* immunitySourceSpell = sSpellMgr->GetSpellInfo(entry.second))
|
||||
if (immunitySourceSpell->HasAttribute(SPELL_ATTR1_IMMUNITY_PURGES_EFFECT))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// If m_immuneToEffect type contain this effect type, IMMUNE effect.
|
||||
uint32 effect = spellInfo->Effects[index].Effect;
|
||||
SpellImmuneContainer const& effectList = m_spellImmune[IMMUNITY_EFFECT];
|
||||
if (effectList.count(effect) > 0)
|
||||
if (hasImmunity(effectList, effect))
|
||||
return true;
|
||||
|
||||
if (uint32 mechanic = spellInfo->Effects[index].Mechanic)
|
||||
{
|
||||
SpellImmuneContainer const& mechanicList = m_spellImmune[IMMUNITY_MECHANIC];
|
||||
if (mechanicList.count(mechanic) > 0)
|
||||
if (hasImmunity(mechanicList, mechanic))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -7442,7 +7466,7 @@ bool Unit::IsImmunedToSpellEffect(SpellInfo const* spellInfo, uint32 index, Worl
|
||||
if (uint32 aura = spellInfo->Effects[index].ApplyAuraName)
|
||||
{
|
||||
SpellImmuneContainer const& list = m_spellImmune[IMMUNITY_STATE];
|
||||
if (list.count(aura) > 0)
|
||||
if (hasImmunity(list, aura))
|
||||
return true;
|
||||
|
||||
if (!spellInfo->HasAttribute(SPELL_ATTR2_NO_SCHOOL_IMMUNITIES))
|
||||
|
||||
Reference in new issue
Block a user