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

This commit is contained in:
Shauren
2021-10-27 01:01:41 +02:00
parent 62e444e4b0
commit 9fc8c86e9a
7 changed files with 22 additions and 36 deletions
+4 -4
View File
@@ -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;
}
+4 -3
View File
@@ -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:
+2 -2
View File
@@ -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());
+2 -5
View File
@@ -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());
}
+3 -6
View File
@@ -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());
+3 -9
View File
@@ -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);
}
}
+4 -7
View File
@@ -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();