aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-10-27 01:01:41 +0200
committerShauren <shauren.trinity@gmail.com>2021-10-27 01:01:41 +0200
commit9fc8c86e9a47194a1b271fbcf7bf9e85cb3f0826 (patch)
treec852517d4f3f097781bf9b5963d4db258c23edcf /src
parent62e444e4b0ef7199e5ce40b216c13fb57a6e56ec (diff)
Scripts/Auras: Lookup aura scripts by their type, not name
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.cpp8
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.h7
-rw-r--r--src/server/scripts/Spells/spell_dh.cpp4
-rw-r--r--src/server/scripts/Spells/spell_priest.cpp7
-rw-r--r--src/server/scripts/Spells/spell_rogue.cpp9
-rw-r--r--src/server/scripts/Spells/spell_shaman.cpp12
-rw-r--r--src/server/scripts/Spells/spell_warlock.cpp11
7 files changed, 22 insertions, 36 deletions
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp
index 903d2e30798..b45f3e48c67 100644
--- a/src/server/game/Spells/Auras/SpellAuras.cpp
+++ b/src/server/game/Spells/Auras/SpellAuras.cpp
@@ -469,11 +469,11 @@ m_lastProcAttemptTime(std::chrono::steady_clock::now() - Seconds(10)), m_lastPro
// m_casterLevel = cast item level/caster level, caster level should be saved to db, confirmed with sniffs
}
-AuraScript* Aura::GetScriptByName(std::string const& scriptName) const
+AuraScript* Aura::GetScriptByType(std::type_info const& type) const
{
- for (auto itr = m_loadedScripts.begin(); itr != m_loadedScripts.end(); ++itr)
- if ((*itr)->_GetScriptName()->compare(scriptName) == 0)
- return *itr;
+ for (AuraScript* loadedScript : m_loadedScripts)
+ if (typeid(*loadedScript) == type)
+ return loadedScript;
return nullptr;
}
diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h
index ac99042d961..8f843d5ab95 100644
--- a/src/server/game/Spells/Auras/SpellAuras.h
+++ b/src/server/game/Spells/Auras/SpellAuras.h
@@ -20,6 +20,7 @@
#include "SpellAuraDefines.h"
#include "SpellInfo.h"
+#include <typeinfo>
class SpellInfo;
struct SpellModifier;
@@ -292,9 +293,9 @@ class TC_GAME_API Aura
DynObjAura const* ToDynObjAura() const { if (GetType() == DYNOBJ_AURA_TYPE) return reinterpret_cast<DynObjAura const*>(this); else return nullptr; }
template <class Script>
- Script* GetScript(std::string const& scriptName) const
+ Script* GetScript() const
{
- return dynamic_cast<Script*>(GetScriptByName(scriptName));
+ return static_cast<Script*>(GetScriptByType(typeid(Script)));
}
std::vector<AuraScript*> m_loadedScripts;
@@ -302,7 +303,7 @@ class TC_GAME_API Aura
AuraEffectVector const& GetAuraEffects() const { return _effects; }
private:
- AuraScript* GetScriptByName(std::string const& scriptName) const;
+ AuraScript* GetScriptByType(std::type_info const& type) const;
void _DeleteRemovedApplications();
protected:
diff --git a/src/server/scripts/Spells/spell_dh.cpp b/src/server/scripts/Spells/spell_dh.cpp
index 14e9a8543aa..490f6ac69a0 100644
--- a/src/server/scripts/Spells/spell_dh.cpp
+++ b/src/server/scripts/Spells/spell_dh.cpp
@@ -123,7 +123,7 @@ class spell_dh_blade_dance : public SpellScript
if (firstTargetGUID.IsEmpty())
firstTargetGUID = targetList.front()->GetGUID();
- if (spell_dh_first_blood* script = aura->GetScript<spell_dh_first_blood>(STRINGIZE(spell_dh_first_blood)))
+ if (spell_dh_first_blood* script = aura->GetScript<spell_dh_first_blood>())
script->SetFirstTarget(firstTargetGUID);
}
@@ -151,7 +151,7 @@ class spell_dh_blade_dance_damage : public SpellScript
int32 damage = GetHitDamage();
if (AuraEffect* aurEff = GetCaster()->GetAuraEffect(SPELL_DH_FIRST_BLOOD, EFFECT_0))
- if (spell_dh_first_blood* script = aurEff->GetBase()->GetScript<spell_dh_first_blood>(STRINGIZE(spell_dh_first_blood)))
+ if (spell_dh_first_blood* script = aurEff->GetBase()->GetScript<spell_dh_first_blood>())
if (GetHitUnit()->GetGUID() == script->GetFirstTarget())
AddPct(damage, aurEff->GetAmount());
diff --git a/src/server/scripts/Spells/spell_priest.cpp b/src/server/scripts/Spells/spell_priest.cpp
index 9178fc1532d..199901fe175 100644
--- a/src/server/scripts/Spells/spell_priest.cpp
+++ b/src/server/scripts/Spells/spell_priest.cpp
@@ -166,9 +166,7 @@ class spell_pri_aq_3p_bonus : public SpellScriptLoader
class spell_pri_atonement : public SpellScriptLoader
{
public:
- static char constexpr const ScriptName[] = "spell_pri_atonement";
-
- spell_pri_atonement() : SpellScriptLoader(ScriptName) { }
+ spell_pri_atonement() : SpellScriptLoader("spell_pri_atonement") { }
class spell_pri_atonement_AuraScript : public AuraScript
{
@@ -227,7 +225,6 @@ public:
return new spell_pri_atonement_AuraScript();
}
};
-char constexpr const spell_pri_atonement::ScriptName[];
// 194384, 214206 - Atonement
class spell_pri_atonement_triggered : public SpellScriptLoader
@@ -261,7 +258,7 @@ public:
{
if (Unit* caster = GetCaster())
if (Aura* atonement = caster->GetAura(SPELL_PRIEST_ATONEMENT))
- if (AtonementScript* script = atonement->GetScript<AtonementScript>(spell_pri_atonement::ScriptName))
+ if (AtonementScript* script = atonement->GetScript<AtonementScript>())
(script->*func)(GetTarget()->GetGUID());
}
diff --git a/src/server/scripts/Spells/spell_rogue.cpp b/src/server/scripts/Spells/spell_rogue.cpp
index 6141e0f1a41..f1871303adc 100644
--- a/src/server/scripts/Spells/spell_rogue.cpp
+++ b/src/server/scripts/Spells/spell_rogue.cpp
@@ -208,9 +208,7 @@ class spell_rog_deadly_poison : public SpellScriptLoader
class spell_rog_killing_spree : public SpellScriptLoader
{
public:
- static char constexpr const ScriptName[] = "spell_rog_killing_spree";
-
- spell_rog_killing_spree() : SpellScriptLoader(ScriptName) { }
+ spell_rog_killing_spree() : SpellScriptLoader("spell_rog_killing_spree") { }
class spell_rog_killing_spree_SpellScript : public SpellScript
{
@@ -225,7 +223,7 @@ class spell_rog_killing_spree : public SpellScriptLoader
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (Aura* aura = GetCaster()->GetAura(SPELL_ROGUE_KILLING_SPREE))
- if (spell_rog_killing_spree_AuraScript* script = aura->GetScript<spell_rog_killing_spree_AuraScript>(ScriptName))
+ if (spell_rog_killing_spree_AuraScript* script = aura->GetScript<spell_rog_killing_spree_AuraScript>())
script->AddTarget(GetHitUnit());
}
@@ -303,7 +301,6 @@ class spell_rog_killing_spree : public SpellScriptLoader
return new spell_rog_killing_spree_AuraScript();
}
};
-char constexpr const spell_rog_killing_spree::ScriptName[];
// 1943 - Rupture
class spell_rog_rupture : public SpellScriptLoader
@@ -528,7 +525,7 @@ class spell_rog_tricks_of_the_trade : public SpellScript
void DoAfterHit()
{
if (Aura* aura = GetHitAura())
- if (auto* script = aura->GetScript<spell_rog_tricks_of_the_trade_aura>("spell_rog_tricks_of_the_trade"))
+ if (spell_rog_tricks_of_the_trade_aura* script = aura->GetScript<spell_rog_tricks_of_the_trade_aura>())
{
if (Unit* explTarget = GetExplTargetUnit())
script->SetRedirectTarget(explTarget->GetGUID());
diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp
index 362e0ee04d6..24bc8a45b6c 100644
--- a/src/server/scripts/Spells/spell_shaman.cpp
+++ b/src/server/scripts/Spells/spell_shaman.cpp
@@ -314,9 +314,7 @@ class spell_sha_earth_shield : public SpellScriptLoader
class spell_sha_earthen_rage_passive : public SpellScriptLoader
{
public:
- static char constexpr const ScriptName[] = "spell_sha_earthen_rage_passive";
-
- spell_sha_earthen_rage_passive() : SpellScriptLoader(ScriptName) { }
+ spell_sha_earthen_rage_passive() : SpellScriptLoader("spell_sha_earthen_rage_passive") { }
class spell_sha_earthen_rage_passive_AuraScript : public AuraScript
{
@@ -353,7 +351,6 @@ public:
return new spell_sha_earthen_rage_passive_AuraScript();
}
};
-char constexpr const spell_sha_earthen_rage_passive::ScriptName[];
// 170377 - Earthen Rage (Proc Aura)
class spell_sha_earthen_rage_proc_aura : public SpellScriptLoader
@@ -376,7 +373,7 @@ public:
PreventDefaultAction();
if (Aura const* aura = GetCaster()->GetAura(SPELL_SHAMAN_EARTHEN_RAGE_PASSIVE))
- if (earthen_rage_script_t const* earthen_rage_script = aura->GetScript<earthen_rage_script_t>(spell_sha_earthen_rage_passive::ScriptName))
+ if (earthen_rage_script_t const* earthen_rage_script = aura->GetScript<earthen_rage_script_t>())
if (Unit* procTarget = ObjectAccessor::GetUnit(*GetCaster(), earthen_rage_script->GetProcTargetGuid()))
GetTarget()->CastSpell(procTarget, SPELL_SHAMAN_EARTHEN_RAGE_DAMAGE, true);
}
@@ -503,8 +500,6 @@ class spell_sha_flametongue_weapon_aura : public AuraScript
class spell_sha_healing_rain_aura : public AuraScript
{
public:
- static constexpr char const ScriptName[] = "spell_sha_healing_rain";
-
void SetVisualDummy(TempSummon* summon)
{
_visualDummy = summon->GetGUID();
@@ -534,7 +529,6 @@ private:
ObjectGuid _visualDummy;
Position _dest;
};
-constexpr char const spell_sha_healing_rain_aura::ScriptName[];
// 73920 - Healing Rain
class spell_sha_healing_rain : public SpellScript
@@ -554,7 +548,7 @@ class spell_sha_healing_rain : public SpellScript
summon->CastSpell(summon, SPELL_SHAMAN_HEALING_RAIN_VISUAL, true);
- if (spell_sha_healing_rain_aura* script = aura->GetScript<spell_sha_healing_rain_aura>(spell_sha_healing_rain_aura::ScriptName))
+ if (spell_sha_healing_rain_aura* script = aura->GetScript<spell_sha_healing_rain_aura>())
script->SetVisualDummy(summon);
}
}
diff --git a/src/server/scripts/Spells/spell_warlock.cpp b/src/server/scripts/Spells/spell_warlock.cpp
index 14b9befd46d..035262d0b4c 100644
--- a/src/server/scripts/Spells/spell_warlock.cpp
+++ b/src/server/scripts/Spells/spell_warlock.cpp
@@ -653,9 +653,7 @@ class spell_warl_soul_swap : public SpellScriptLoader
class spell_warl_soul_swap_override : public SpellScriptLoader
{
public:
- static char constexpr const ScriptName[] = "spell_warl_soul_swap_override";
-
- spell_warl_soul_swap_override() : SpellScriptLoader(ScriptName) { }
+ spell_warl_soul_swap_override() : SpellScriptLoader("spell_warl_soul_swap_override") { }
class spell_warl_soul_swap_override_AuraScript : public AuraScript
{
@@ -680,7 +678,6 @@ class spell_warl_soul_swap_override : public SpellScriptLoader
return new spell_warl_soul_swap_override_AuraScript();
}
};
-char constexpr const spell_warl_soul_swap_override::ScriptName[];
typedef spell_warl_soul_swap_override::spell_warl_soul_swap_override_AuraScript SoulSwapOverrideAuraScript;
@@ -704,7 +701,7 @@ class spell_warl_soul_swap_dot_marker : public SpellScriptLoader
Unit::AuraApplicationMap const& appliedAuras = swapVictim->GetAppliedAuras();
SoulSwapOverrideAuraScript* swapSpellScript = nullptr;
if (Aura* swapOverrideAura = warlock->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
- swapSpellScript = swapOverrideAura->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName);
+ swapSpellScript = swapOverrideAura->GetScript<SoulSwapOverrideAuraScript>();
if (!swapSpellScript)
return;
@@ -754,7 +751,7 @@ public:
Unit* currentTarget = GetExplTargetUnit();
Unit* swapTarget = nullptr;
if (Aura const* swapOverride = GetCaster()->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
- if (SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName))
+ if (SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>())
swapTarget = swapScript->GetOriginalSwapSource();
// Soul Swap Exhale can't be cast on the same target than Soul Swap
@@ -773,7 +770,7 @@ public:
Unit* swapSource = nullptr;
if (Aura const* swapOverride = GetCaster()->GetAura(SPELL_WARLOCK_SOUL_SWAP_OVERRIDE))
{
- SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>(spell_warl_soul_swap_override::ScriptName);
+ SoulSwapOverrideAuraScript* swapScript = swapOverride->GetScript<SoulSwapOverrideAuraScript>();
if (!swapScript)
return;
dotList = swapScript->GetDotList();