From 5a90a3ddded2ca5ace86d947ee4960387a3a2a8f Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 3 Nov 2021 12:31:46 -0400 Subject: [PATCH] Scripts/Auras: Lookup aura scripts by their type, not name Port From (https://github.com/TrinityCore/TrinityCore/commit/9fc8c86e9a47194a1b271fbcf7bf9e85cb3f0826) --- Source/Game/Spells/Auras/Aura.cs | 9 +++++---- Source/Scripts/Spells/DemonHunter.cs | 4 ++-- Source/Scripts/Spells/Priest.cs | 4 ++-- Source/Scripts/Spells/Rogue.cs | 2 +- Source/Scripts/Spells/Shaman.cs | 4 ++-- Source/Scripts/Spells/Warlock.cs | 6 +++--- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index 716488dd3..8283a4454 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -362,16 +362,17 @@ namespace Game.Spells // m_casterLevel = cast item level/caster level, caster level should be saved to db, confirmed with sniffs } - public T GetScript(string scriptName) where T : AuraScript + public T GetScript() where T : AuraScript { - return (T)GetScriptByName(scriptName); + return (T)GetScriptByType(typeof(T)); } - public AuraScript GetScriptByName(string scriptName) + public AuraScript GetScriptByType(Type type) { foreach (var auraScript in m_loadedScripts) - if (auraScript._GetScriptName().Equals(scriptName)) + if (auraScript.GetType() == type) return auraScript; + return null; } diff --git a/Source/Scripts/Spells/DemonHunter.cs b/Source/Scripts/Spells/DemonHunter.cs index 23fb92803..8ff43dc52 100644 --- a/Source/Scripts/Spells/DemonHunter.cs +++ b/Source/Scripts/Spells/DemonHunter.cs @@ -103,7 +103,7 @@ namespace Scripts.Spells.DemonHunter if (firstTargetGUID.IsEmpty()) firstTargetGUID = targetList[0].GetGUID(); - spell_dh_first_blood script = aura.GetScript(nameof(spell_dh_first_blood)); + spell_dh_first_blood script = aura.GetScript(); if (script != null) script.SetFirstTarget(firstTargetGUID); } @@ -132,7 +132,7 @@ namespace Scripts.Spells.DemonHunter AuraEffect aurEff = GetCaster().GetAuraEffect(SpellIds.FirstBlood, 0); if (aurEff != null) { - spell_dh_first_blood script = aurEff.GetBase().GetScript(nameof(spell_dh_first_blood)); + spell_dh_first_blood script = aurEff.GetBase().GetScript(); if (script != null) if (GetHitUnit().GetGUID() == script.GetFirstTarget()) MathFunctions.AddPct(ref damage, aurEff.GetAmount()); diff --git a/Source/Scripts/Spells/Priest.cs b/Source/Scripts/Spells/Priest.cs index 6cf8b31d7..6e3885849 100644 --- a/Source/Scripts/Spells/Priest.cs +++ b/Source/Scripts/Spells/Priest.cs @@ -175,7 +175,7 @@ namespace Scripts.Spells.Priest Aura atonement = caster.GetAura(SpellIds.Atonement); if (atonement != null) { - var script = atonement.GetScript("spell_pri_atonement"); + var script = atonement.GetScript(); if (script != null) script.AddAtonementTarget(GetTarget().GetGUID()); } @@ -190,7 +190,7 @@ namespace Scripts.Spells.Priest Aura atonement = caster.GetAura(SpellIds.Atonement); if (atonement != null) { - var script = atonement.GetScript("spell_pri_atonement"); + var script = atonement.GetScript(); if (script != null) script.RemoveAtonementTarget(GetTarget().GetGUID()); } diff --git a/Source/Scripts/Spells/Rogue.cs b/Source/Scripts/Spells/Rogue.cs index 0e84d3648..686ca80eb 100644 --- a/Source/Scripts/Spells/Rogue.cs +++ b/Source/Scripts/Spells/Rogue.cs @@ -49,7 +49,7 @@ namespace Scripts.Spells.Rogue Aura aura = GetCaster().GetAura(SpellIds.KillingSpree); if (aura != null) { - var script = aura.GetScript(nameof(spell_rog_killing_spree_AuraScript)); + var script = aura.GetScript(); if (script != null) script.AddTarget(GetHitUnit()); } diff --git a/Source/Scripts/Spells/Shaman.cs b/Source/Scripts/Spells/Shaman.cs index aea981cae..00e62f45b 100644 --- a/Source/Scripts/Spells/Shaman.cs +++ b/Source/Scripts/Spells/Shaman.cs @@ -273,7 +273,7 @@ namespace Scripts.Spells.Shaman Aura aura = GetCaster().GetAura(SpellIds.EarthenRagePassive); if (aura != null) { - var earthen_rage_script = aura.GetScript("spell_sha_earthen_rage_passive"); + var earthen_rage_script = aura.GetScript(); if (earthen_rage_script != null) { Unit procTarget = Global.ObjAccessor.GetUnit(GetCaster(), earthen_rage_script.GetProcTargetGuid()); @@ -393,7 +393,7 @@ namespace Scripts.Spells.Shaman summon.CastSpell(summon, SpellIds.HealingRainVisual, true); - var script = aura.GetScript("spell_sha_healing_rain"); + var script = aura.GetScript(); if (script != null) script.SetVisualDummy(summon); } diff --git a/Source/Scripts/Spells/Warlock.cs b/Source/Scripts/Spells/Warlock.cs index 9ffef416a..3fd4c9b42 100644 --- a/Source/Scripts/Spells/Warlock.cs +++ b/Source/Scripts/Spells/Warlock.cs @@ -491,7 +491,7 @@ namespace Scripts.Spells.Warlock spell_warl_soul_swap_override swapSpellScript = null; Aura swapOverrideAura = warlock.GetAura(SpellIds.SoulSwapOverride); if (swapOverrideAura != null) - swapSpellScript = swapOverrideAura.GetScript("spell_warl_soul_swap_override"); + swapSpellScript = swapOverrideAura.GetScript(); if (swapSpellScript == null) return; @@ -530,7 +530,7 @@ namespace Scripts.Spells.Warlock Aura swapOverride = GetCaster().GetAura(SpellIds.SoulSwapOverride); if (swapOverride != null) { - spell_warl_soul_swap_override swapScript = swapOverride.GetScript("spell_warl_soul_swap_override"); + spell_warl_soul_swap_override swapScript = swapOverride.GetScript(); if (swapScript != null) swapTarget = swapScript.GetOriginalSwapSource(); } @@ -552,7 +552,7 @@ namespace Scripts.Spells.Warlock Aura swapOverride = GetCaster().GetAura(SpellIds.SoulSwapOverride); if (swapOverride != null) { - spell_warl_soul_swap_override swapScript = swapOverride.GetScript("spell_warl_soul_swap_override"); + spell_warl_soul_swap_override swapScript = swapOverride.GetScript(); if (swapScript == null) return; dotList = swapScript.GetDotList();