Scripts/Auras: Lookup aura scripts by their type, not name

Port From (https://github.com/TrinityCore/TrinityCore/commit/9fc8c86e9a47194a1b271fbcf7bf9e85cb3f0826)
This commit is contained in:
hondacrx
2021-11-03 12:31:46 -04:00
parent b1e6aabee7
commit 5a90a3ddde
6 changed files with 15 additions and 14 deletions
+5 -4
View File
@@ -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<T>(string scriptName) where T : AuraScript
public T GetScript<T>() 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;
}
+2 -2
View File
@@ -103,7 +103,7 @@ namespace Scripts.Spells.DemonHunter
if (firstTargetGUID.IsEmpty())
firstTargetGUID = targetList[0].GetGUID();
spell_dh_first_blood script = aura.GetScript<spell_dh_first_blood>(nameof(spell_dh_first_blood));
spell_dh_first_blood script = aura.GetScript<spell_dh_first_blood>();
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<spell_dh_first_blood>(nameof(spell_dh_first_blood));
spell_dh_first_blood script = aurEff.GetBase().GetScript<spell_dh_first_blood>();
if (script != null)
if (GetHitUnit().GetGUID() == script.GetFirstTarget())
MathFunctions.AddPct(ref damage, aurEff.GetAmount());
+2 -2
View File
@@ -175,7 +175,7 @@ namespace Scripts.Spells.Priest
Aura atonement = caster.GetAura(SpellIds.Atonement);
if (atonement != null)
{
var script = atonement.GetScript<spell_pri_atonement>("spell_pri_atonement");
var script = atonement.GetScript<spell_pri_atonement>();
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>("spell_pri_atonement");
var script = atonement.GetScript<spell_pri_atonement>();
if (script != null)
script.RemoveAtonementTarget(GetTarget().GetGUID());
}
+1 -1
View File
@@ -49,7 +49,7 @@ namespace Scripts.Spells.Rogue
Aura aura = GetCaster().GetAura(SpellIds.KillingSpree);
if (aura != null)
{
var script = aura.GetScript<spell_rog_killing_spree_AuraScript>(nameof(spell_rog_killing_spree_AuraScript));
var script = aura.GetScript<spell_rog_killing_spree_AuraScript>();
if (script != null)
script.AddTarget(GetHitUnit());
}
+2 -2
View File
@@ -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>("spell_sha_earthen_rage_passive");
var earthen_rage_script = aura.GetScript<spell_sha_earthen_rage_passive>();
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_AuraScript>("spell_sha_healing_rain");
var script = aura.GetScript<spell_sha_healing_rain_AuraScript>();
if (script != null)
script.SetVisualDummy(summon);
}
+3 -3
View File
@@ -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>("spell_warl_soul_swap_override");
swapSpellScript = swapOverrideAura.GetScript<spell_warl_soul_swap_override>();
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");
spell_warl_soul_swap_override swapScript = swapOverride.GetScript<spell_warl_soul_swap_override>();
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");
spell_warl_soul_swap_override swapScript = swapOverride.GetScript<spell_warl_soul_swap_override>();
if (swapScript == null)
return;
dotList = swapScript.GetDotList();