Core/Spells: Scrolls should not be consumed, when they fail to apply.

(cherry picked from commit 8d87c834e7)
This commit is contained in:
FAQ
2020-04-15 22:06:14 +03:00
committed by Shauren
parent 6300b096ac
commit 88afe180b4

View File

@@ -3408,21 +3408,21 @@ void Spell::_cast(bool skipCheck)
CallScriptBeforeCastHandlers();
auto cleanupSpell = [this, modOwner](SpellCastResult res, int32* p1 = nullptr, int32* p2 = nullptr)
{
SendCastResult(res, p1, p2);
SendInterrupted(0);
if (modOwner)
modOwner->SetSpellModTakingSpell(this, false);
finish(false);
SetExecutedCurrently(false);
};
// skip check if done already (for instant cast spells for example)
if (!skipCheck)
{
auto cleanupSpell = [this, modOwner](SpellCastResult res, int32* p1 = nullptr, int32* p2 = nullptr)
{
SendCastResult(res, p1, p2);
SendInterrupted(0);
if (modOwner)
modOwner->SetSpellModTakingSpell(this, false);
finish(false);
SetExecutedCurrently(false);
};
int32 param1 = 0, param2 = 0;
SpellCastResult castResult = CheckCast(false, &param1, &param2);
if (castResult != SPELL_CAST_OK)
@@ -3479,6 +3479,40 @@ void Spell::_cast(bool skipCheck)
}
}
// check if target already has the same type, but more powerful aura
if (modOwner)
{
for (SpellEffectInfo const& spellEffectInfo : GetSpellInfo()->GetEffects())
{
if (!spellEffectInfo.IsAura())
continue;
Unit::AuraEffectList const& auras = modOwner->GetAuraEffectsByType(SPELL_AURA_MOD_STAT);
for (Unit::AuraEffectList::const_iterator auraIt = auras.begin(); auraIt != auras.end(); ++auraIt)
{
// check if both spells are in same SpellGroups
if (sSpellMgr->CheckSpellGroupStackRules(GetSpellInfo(), (*auraIt)->GetSpellInfo()) == SPELL_GROUP_STACK_RULE_EXCLUSIVE_HIGHEST)
{
// compare new aura vs existing aura
if (abs(spellEffectInfo.CalcBaseValue(m_caster, nullptr, m_castItemEntry, m_castItemLevel)) < abs((*auraIt)->GetSpellEffectInfo().CalcBaseValue(m_caster, nullptr, m_castItemEntry, m_castItemLevel)))
{
cleanupSpell(SPELL_FAILED_AURA_BOUNCED);
return;
}
else if (abs(spellEffectInfo.BasePoints) == abs((*auraIt)->GetSpellEffectInfo().BasePoints))
{
// in case when baseboints match and to avoid false positive, example, spell 8097 vs 8116
if (abs(spellEffectInfo.MiscValue) == abs((*auraIt)->GetSpellEffectInfo().MiscValue))
{
cleanupSpell(SPELL_FAILED_AURA_BOUNCED);
return;
}
}
}
}
}
}
// if the spell allows the creature to turn while casting, then adjust server-side orientation to face the target now
// client-side orientation is handled by the client itself, as the cast target is targeted due to Creature::SetSpellFocusTarget
if (m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->ToUnit()->HasUnitFlag(UNIT_FLAG_POSSESSED))