From 868c67c8f0aaf09275ae27f86c850ddf3e36218f Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sun, 13 May 2018 20:21:52 -0400 Subject: [PATCH] Core/Spells: Implement aura 428 (SPELL_AURA_LINKED_SUMMON) --- .../Constants/Spells/SpellAuraConst.cs | 2 +- Source/Game/Spells/Auras/AuraEffect.cs | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Source/Framework/Constants/Spells/SpellAuraConst.cs b/Source/Framework/Constants/Spells/SpellAuraConst.cs index 0151772ac..ba6cef24c 100644 --- a/Source/Framework/Constants/Spells/SpellAuraConst.cs +++ b/Source/Framework/Constants/Spells/SpellAuraConst.cs @@ -449,7 +449,7 @@ namespace Framework.Constants Unk425 = 425, Unk426 = 426, ScalePlayerLevel = 427, // NYI - Unk428 = 428, + LinkedSummon = 428, Unk429 = 429, PlayScene = 430, ModOverrideZonePvpType = 431, // NYI diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 192e21f60..255bea8aa 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -6024,6 +6024,67 @@ namespace Game.Spells target.TogglePvpTalents(false); } } + + [AuraEffectHandler(AuraType.LinkedSummon)] + void HandleLinkedSummon(AuraApplication aurApp, AuraEffectHandleModes mode, bool apply) + { + if (!mode.HasAnyFlag(AuraEffectHandleModes.Real)) + return; + + Unit target = aurApp.GetTarget(); + SpellInfo triggerSpellInfo = Global.SpellMgr.GetSpellInfo(GetSpellEffectInfo().TriggerSpell); + if (triggerSpellInfo == null) + return; + + // on apply cast summon spell + if (apply) + target.CastSpell(target, triggerSpellInfo, true, null, this); + // on unapply we need to search for and remove the summoned creature + else + { + List summonedEntries = new List(); + foreach (var spellEffect in triggerSpellInfo.GetEffectsForDifficulty(target.GetMap().GetDifficultyID())) + { + if (spellEffect != null && spellEffect.Effect == SpellEffectName.Summon) + { + uint summonEntry = (uint)spellEffect.MiscValue; + if (summonEntry != 0) + { + if (!summonedEntries.Contains(summonEntry)) + summonedEntries.Add(summonEntry); + } + } + } + + // we don't know if there can be multiple summons for the same effect, so consider only 1 summon for each effect + // most of the spells have multiple effects with the same summon spell id for multiple spawns, so right now it's safe to assume there's only 1 spawn per effect + foreach (uint summonEntry in summonedEntries) + { + List nearbyEntries = new List(); + target.GetCreatureListWithEntryInGrid(nearbyEntries, summonEntry); + foreach (var creature in nearbyEntries) + { + if (creature.GetOwner() == target) + { + creature.DespawnOrUnsummon(); + break; + } + else + { + TempSummon tempSummon = creature.ToTempSummon(); + if (tempSummon) + { + if (tempSummon.GetSummoner() == target) + { + tempSummon.DespawnOrUnsummon(); + break; + } + } + } + } + } + } + } #endregion }