Core/Spells: Allow spell scripts to access other scripts attached to a spell

This commit is contained in:
Shauren
2025-09-19 00:35:14 +02:00
parent 7f43815c98
commit 4c66c09e38
2 changed files with 12 additions and 0 deletions

View File

@@ -9167,6 +9167,14 @@ bool Spell::CheckScriptEffectImplicitTargets(uint32 effIndex, uint32 effIndexToC
return true;
}
SpellScript* Spell::GetScriptByType(std::type_info const& type) const
{
auto itr = std::ranges::find(m_loadedScripts, type, [](SpellScript* script) -> std::type_info const& { return typeid(*script); });
if (itr != m_loadedScripts.end())
return *itr;
return nullptr;
}
bool Spell::CanExecuteTriggersOnHit(Unit* unit, SpellInfo const* triggeredByAura /*= nullptr*/) const
{
bool onlyOnTarget = (triggeredByAura && (triggeredByAura->HasAttribute(SPELL_ATTR4_CLASS_TRIGGER_ONLY_ON_TARGET)));

View File

@@ -31,6 +31,7 @@
#include "Types.h"
#include "UniqueTrackablePtr.h"
#include <memory>
#include <typeinfo>
namespace WorldPackets::Spells
{
@@ -920,6 +921,8 @@ class TC_GAME_API Spell
void CallScriptCalcCritChanceHandlers(Unit const* victim, float& chance);
void CallScriptCalcDamageHandlers(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& damage, int32& flatMod, float& pctMod);
void CallScriptCalcHealingHandlers(SpellEffectInfo const& spellEffectInfo, Unit* victim, int32& healing, int32& flatMod, float& pctMod);
template <class Script>
Script* GetScript() const { return static_cast<Script*>(GetScriptByType(typeid(Script))); }
protected:
void CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& targets, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
void CallScriptObjectTargetSelectHandlers(WorldObject*& target, SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType);
@@ -927,6 +930,7 @@ class TC_GAME_API Spell
void CallScriptEmpowerStageCompletedHandlers(int32 completedStagesCount);
void CallScriptEmpowerCompletedHandlers(int32 completedStagesCount);
bool CheckScriptEffectImplicitTargets(uint32 effIndex, uint32 effIndexToCheck);
SpellScript* GetScriptByType(std::type_info const& type) const;
std::vector<SpellScript*> m_loadedScripts;
struct HitTriggerSpell