aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Scripting/ScriptMgr.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-08-20 15:49:59 +0200
committerShauren <shauren.trinity@gmail.com>2020-08-20 15:49:59 +0200
commit75a6a7a0ad48874e75dd71f766dad3707341bb32 (patch)
tree056b66435bd15404bfc2b100d823209734642acb /src/server/game/Scripting/ScriptMgr.h
parent84a87d87bfd569192ff1564e3d8b2e68d5fff4bc (diff)
Core/Scripts: Unify RegisterSpellScript and RegisterAuraScript macros to do the same thing and implemented passing custom arguments to spell script classes
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.h')
-rw-r--r--src/server/game/Scripting/ScriptMgr.h61
1 files changed, 40 insertions, 21 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index be35f14448e..f2cacb5d892 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -20,6 +20,8 @@
#include "Common.h"
#include "ObjectGuid.h"
+#include "Tuples.h"
+#include "Types.h"
#include <vector>
class AccountMgr;
@@ -1093,33 +1095,50 @@ class TC_GAME_API ScriptMgr
std::string _currentContext;
};
-template <class S>
-class GenericSpellScriptLoader : public SpellScriptLoader
+namespace Trinity::SpellScripts
{
- public:
- GenericSpellScriptLoader(char const* name) : SpellScriptLoader(name) { }
- SpellScript* GetSpellScript() const override { return new S(); }
-};
-#define RegisterSpellScript(spell_script) new GenericSpellScriptLoader<spell_script>(#spell_script)
+ template<typename T>
+ using is_SpellScript = std::is_base_of<SpellScript, T>;
-template <class A>
-class GenericAuraScriptLoader : public SpellScriptLoader
-{
- public:
- GenericAuraScriptLoader(char const* name) : SpellScriptLoader(name) { }
- AuraScript* GetAuraScript() const override { return new A(); }
-};
-#define RegisterAuraScript(aura_script) new GenericAuraScriptLoader<aura_script>(#aura_script)
+ template<typename T>
+ using is_AuraScript = std::is_base_of<AuraScript, T>;
+}
-template <class S, class A>
+template <typename... Ts>
class GenericSpellAndAuraScriptLoader : public SpellScriptLoader
{
- public:
- GenericSpellAndAuraScriptLoader(char const* name) : SpellScriptLoader(name) { }
- SpellScript* GetSpellScript() const override { return new S(); }
- AuraScript* GetAuraScript() const override { return new A(); }
+ using SpellScriptType = typename Trinity::find_type_if_t<Trinity::SpellScripts::is_SpellScript, Ts...>;
+ using AuraScriptType = typename Trinity::find_type_if_t<Trinity::SpellScripts::is_AuraScript, Ts...>;
+ using ArgsType = typename Trinity::find_type_if_t<Trinity::is_tuple, Ts...>;
+
+public:
+ GenericSpellAndAuraScriptLoader(char const* name, ArgsType&& args) : SpellScriptLoader(name), _args(std::move(args)) { }
+
+private:
+ SpellScript* GetSpellScript() const override
+ {
+ if constexpr (!std::is_same_v<SpellScriptType, Trinity::find_type_end>)
+ return Trinity::new_from_tuple<SpellScriptType>(_args);
+ else
+ return nullptr;
+ }
+
+ AuraScript* GetAuraScript() const override
+ {
+ if constexpr (!std::is_same_v<AuraScriptType, Trinity::find_type_end>)
+ return Trinity::new_from_tuple<AuraScriptType>(_args);
+ else
+ return nullptr;
+ }
+
+ ArgsType _args;
};
-#define RegisterSpellAndAuraScriptPair(spell_script, aura_script) new GenericSpellAndAuraScriptLoader<spell_script, aura_script>(#spell_script)
+
+#define RegisterSpellScriptWithArgs(spell_script, script_name, ...) new GenericSpellAndAuraScriptLoader<spell_script, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
+#define RegisterSpellScript(spell_script) RegisterSpellScriptWithArgs(spell_script, #spell_script)
+#define RegisterAuraScript(aura_script) RegisterSpellScriptWithArgs(aura_script, #aura_script)
+#define RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, script_name, ...) new GenericSpellAndAuraScriptLoader<script_1, script_2, decltype(std::make_tuple(__VA_ARGS__))>(script_name, std::make_tuple(__VA_ARGS__))
+#define RegisterSpellAndAuraScriptPair(script_1, script_2) RegisterSpellAndAuraScriptPairWithArgs(script_1, script_2, #script_1)
template <class AI>
class GenericCreatureScript : public CreatureScript