From ce5b592d8bb4cdf744e43572c0e967b766bb4760 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 18 Feb 2022 13:44:18 -0500 Subject: [PATCH] Core/Spells: Scrolls should not be consumed, when they fail to apply. Port From (https://github.com/TrinityCore/TrinityCore/commit/88afe180b404324b3c1a5bfc31fa37c8ded48a78) --- Source/Game/Spells/Spell.cs | 59 +++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index 5ac2a7dbb..c7860eb75 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -2605,22 +2605,21 @@ namespace Game.Spells CallScriptBeforeCastHandlers(); + void cleanupSpell(SpellCastResult result, int? param1 = null, int? param2 = null) + { + SendCastResult(result, param1, param2); + 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) { - void cleanupSpell(SpellCastResult result, int? param1 = null, int? param2 = null) - { - SendCastResult(result, param1, param2); - SendInterrupted(0); - - if (modOwner) - modOwner.SetSpellModTakingSpell(this, false); - - Finish(false); - SetExecutedCurrently(false); - } - - int param1 = 0, param2 = 0; SpellCastResult castResult = CheckCast(false, ref param1, ref param2); if (castResult != SpellCastResult.SpellCastOk) @@ -2680,6 +2679,40 @@ namespace Game.Spells } } + // check if target already has the same type, but more powerful aura + if (modOwner) + { + foreach (SpellEffectInfo spellEffectInfo in GetSpellInfo().GetEffects()) + { + if (!spellEffectInfo.IsAura()) + continue; + + var auras = modOwner.GetAuraEffectsByType(AuraType.ModStat); + foreach (var auraIt in auras) + { + // check if both spells are in same SpellGroups + if (Global.SpellMgr.CheckSpellGroupStackRules(GetSpellInfo(), auraIt.GetSpellInfo()) == SpellGroupStackRule.ExclusiveHighest) + { + // compare new aura vs existing aura + if (Math.Abs(spellEffectInfo.CalcBaseValue(m_caster, null, m_castItemEntry, m_castItemLevel)) < Math.Abs(auraIt.GetSpellEffectInfo().CalcBaseValue(m_caster, null, m_castItemEntry, m_castItemLevel))) + { + cleanupSpell(SpellCastResult.AuraBounced); + return; + } + else if (Math.Abs(spellEffectInfo.BasePoints) == Math.Abs(auraIt.GetSpellEffectInfo().BasePoints)) + { + // in case when baseboints match and to avoid false positive, example, spell 8097 vs 8116 + if (Math.Abs(spellEffectInfo.MiscValue) == Math.Abs(auraIt.GetSpellEffectInfo().MiscValue)) + { + cleanupSpell(SpellCastResult.AuraBounced); + 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::FocusTarget if (m_caster.IsTypeId(TypeId.Unit) && !m_caster.ToUnit().HasUnitFlag(UnitFlags.Possessed))