From b00ac48cfa9cf54546ae9ba1a3a545563ae37f32 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Tue, 1 Jun 2021 13:55:51 +0200 Subject: [PATCH] feat(Core/Script): Allow spell script ValidateSpellInfo to work with any container type (#6078) * Cherry-pick https://github.com/TrinityCore/TrinityCore/commit/f2f0aeb562dfc1a78b04d13a14e3c37a58367619 Co-authored-by: Shauren --- src/server/game/Spells/SpellScript.cpp | 19 +++++++------------ src/server/game/Spells/SpellScript.h | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index 2962028a1..79f1701df 100644 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -14,26 +14,21 @@ bool _SpellScript::_Validate(SpellInfo const* entry) { if (!Validate(entry)) { - LOG_ERROR("server", "_SpellScript::_Validate: Spell `%u` did not pass Validate() function of script `%s` - script will not be added to the spell", entry->Id, m_scriptName->c_str()); + LOG_ERROR("scripts.spells", "_SpellScript::_Validate: Spell `%u` did not pass Validate() function of script `%s` - script will not be added to the spell", entry->Id, m_scriptName->c_str()); return false; } return true; } -bool _SpellScript::_ValidateSpellInfo(uint32 const* begin, uint32 const* end) +bool _SpellScript::_ValidateSpellInfo(uint32 spellId) { - bool allValid = true; - while (begin != end) + if (!sSpellMgr->GetSpellInfo(spellId)) { - if (!sSpellMgr->GetSpellInfo(*begin)) - { - LOG_ERROR("server", "_SpellScript::_ValidateSpellInfo: Spell %u does not exist.", *begin); - allValid = false; - } - - ++begin; + LOG_ERROR("scripts.spells", "_SpellScript::ValidateSpellInfo: Spell %u does not exist.", spellId); + return false; } - return allValid; + + return true; } void _SpellScript::_Register() diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index 1652460f1..97fa2acc6 100644 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -123,7 +123,23 @@ public: } private: - static bool _ValidateSpellInfo(uint32 const* begin, uint32 const* end); + template + static bool _ValidateSpellInfo(Iterator begin, Iterator end) + { + bool allValid = true; + while (begin != end) + { + if (!_ValidateSpellInfo(*begin)) + { + allValid = false; + } + + ++begin; + } + return allValid; + } + + static bool _ValidateSpellInfo(uint32 spellId); }; // SpellScript interface - enum used for runtime checks of script function calls