From c7ea51d1ddaff63e2459141a9810d01adda3dfe4 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 1 Jun 2022 13:51:21 -0400 Subject: [PATCH] Core/Auras: Added support for SPELL_ATTR5_LIMIT_N limit to other number than just 1 Port From (https://github.com/TrinityCore/TrinityCore/commit/d818add0e20fcf2c86ef46b5cd94f942488511a0) --- .../Framework/Constants/Spells/SpellConst.cs | 2 +- Source/Game/Entities/Unit/Unit.Spells.cs | 18 +++++++++++------- Source/Game/Spells/SpellManager.cs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Source/Framework/Constants/Spells/SpellConst.cs b/Source/Framework/Constants/Spells/SpellConst.cs index 4a55aa770..5d4dfdc04 100644 --- a/Source/Framework/Constants/Spells/SpellConst.cs +++ b/Source/Framework/Constants/Spells/SpellConst.cs @@ -1762,7 +1762,7 @@ namespace Framework.Constants RemoveEnteringArena = 0x04, // Remove Entering Arena Description Force This Aura To Be Removed On Entering Arena, Regardless Of Other Properties AllowWhileStunned = 0x08, // Allow While Stunned TriggersChanneling = 0x10, // Triggers Channeling - LimitN = 0x20, /*Incomplete Impl*/ // Limit N Description Remove Previous Application To Another Unit If Applied + LimitN = 0x20, // Limit N Description Remove Previous Application To Another Unit If Applied IgnoreAreaEffectPvpCheck = 0x40, /*Nyi*/ // Ignore Area Effect Pvp Check NotOnPlayer = 0x80, /*Nyi*/ // Not On Player NotOnPlayerControlledNpc = 0x100, /*Nyi*/ // Not On Player Controlled Npc diff --git a/Source/Game/Entities/Unit/Unit.Spells.cs b/Source/Game/Entities/Unit/Unit.Spells.cs index c469b43a1..4f7160e40 100644 --- a/Source/Game/Entities/Unit/Unit.Spells.cs +++ b/Source/Game/Entities/Unit/Unit.Spells.cs @@ -3934,14 +3934,18 @@ namespace Game.Entities // register single target aura caster.m_scAuras.Add(aura); - // remove other single target auras - var scAuras = caster.GetSingleCastAuras(); - for (var i = 0; i < scAuras.Count; ++i) - { - var aur = scAuras[i]; - if (aur != aura && aur.IsSingleTargetWith(aura)) - aur.Remove(); + Queue aurasSharingLimit = new(); + // remove other single target auras + foreach (Aura scAura in caster.GetSingleCastAuras()) + if (scAura != aura && scAura.IsSingleTargetWith(aura)) + aurasSharingLimit.Enqueue(scAura); + + uint maxOtherAuras = aura.GetSpellInfo().MaxAffectedTargets - 1; + while (aurasSharingLimit.Count > maxOtherAuras) + { + aurasSharingLimit.Peek().Remove(); + aurasSharingLimit.Dequeue(); } } } diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index d960f8ec7..3ea9533d2 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -4379,7 +4379,7 @@ namespace Game.Entities if (spellInfo.ActiveIconFileDataId == 135754) // flight spellInfo.Attributes |= SpellAttr0.Passive; - if (spellInfo.IsSingleTarget()) + if (spellInfo.IsSingleTarget() && spellInfo.MaxAffectedTargets == 0) spellInfo.MaxAffectedTargets = 1; }