aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-08-20 15:49:59 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-03 00:25:03 +0100
commite81b5838a6780a73946047c627583cdb837df58d (patch)
tree08f1285dccc6e8ef50d840a9432dcab389849605
parent4064b22dd7bb01e759a9b48942bcda3455376cc9 (diff)
Core/Scripts: Unify RegisterSpellScript and RegisterAuraScript macros to do the same thing and implemented passing custom arguments to spell script classes
(cherry picked from commit 75a6a7a0ad48874e75dd71f766dad3707341bb32)
-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 5f25655d2bc..0e2c48f4e06 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;
@@ -1195,33 +1197,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