feat(Scripts): Implement generic script loader and registry macros (#8976)
* cherry-pick commit (https://github.com/TrinityCore/TrinityCore/commit/fb87ac8e8da3d215d4988b8c2fa25d7a98cf9ee0) * cherry-pick commit (https://github.com/TrinityCore/TrinityCore/commit/7d4fbf706ae19481468901ccd65c497fcabe56bf#diff-ea1c86c26019127a4e99686cd9029f9ec3e8193f2761b262c2475668edc06764) * cherry-pick commit (https://github.com/TrinityCore/TrinityCore/commit/75a6a7a0ad48874e75dd71f766dad3707341bb32#diff-ea1c86c26019127a4e99686cd9029f9ec3e8193f2761b262c2475668edc06764) Co-Authored-By: Treeston <14020072+Treeston@users.noreply.github.com> Co-Authored-By: Shauren <shauren.trinity@gmail.com> Co-authored-by: Treeston <14020072+Treeston@users.noreply.github.com> Co-authored-by: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
#include "PetDefines.h"
|
#include "PetDefines.h"
|
||||||
#include "QuestDef.h"
|
#include "QuestDef.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
|
#include "Tuples.h"
|
||||||
|
#include "Types.h"
|
||||||
#include "Weather.h"
|
#include "Weather.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
@@ -1964,6 +1966,85 @@ private:
|
|||||||
ScriptLoaderCallbackType _script_loader_callback;
|
ScriptLoaderCallbackType _script_loader_callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace Acore::SpellScripts
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
using is_SpellScript = std::is_base_of<SpellScript, T>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
using is_AuraScript = std::is_base_of<AuraScript, T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename... Ts>
|
||||||
|
class GenericSpellAndAuraScriptLoader : public SpellScriptLoader
|
||||||
|
{
|
||||||
|
using SpellScriptType = typename Acore::find_type_if_t<Acore::SpellScripts::is_SpellScript, Ts...>;
|
||||||
|
using AuraScriptType = typename Acore::find_type_if_t<Acore::SpellScripts::is_AuraScript, Ts...>;
|
||||||
|
using ArgsType = typename Acore::find_type_if_t<Acore::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, Acore::find_type_end>)
|
||||||
|
{
|
||||||
|
return Acore::new_from_tuple<SpellScriptType>(_args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AuraScript* GetAuraScript() const override
|
||||||
|
{
|
||||||
|
if constexpr (!std::is_same_v<AuraScriptType, Acore::find_type_end>)
|
||||||
|
{
|
||||||
|
return Acore::new_from_tuple<AuraScriptType>(_args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArgsType _args;
|
||||||
|
};
|
||||||
|
|
||||||
|
#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 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
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GenericCreatureScript(char const* name) : CreatureScript(name) { }
|
||||||
|
CreatureAI* GetAI(Creature* me) const override { return new AI(me); }
|
||||||
|
};
|
||||||
|
#define RegisterCreatureAI(ai_name) new GenericCreatureScript<ai_name>(#ai_name)
|
||||||
|
|
||||||
|
template <class AI, AI*(*AIFactory)(Creature*)>
|
||||||
|
class FactoryCreatureScript : public CreatureScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FactoryCreatureScript(char const* name) : CreatureScript(name) { }
|
||||||
|
CreatureAI* GetAI(Creature* me) const override { return AIFactory(me); }
|
||||||
|
};
|
||||||
|
#define RegisterCreatureAIWithFactory(ai_name, factory_fn) new FactoryCreatureScript<ai_name, &factory_fn>(#ai_name)
|
||||||
|
|
||||||
|
template <class AI>
|
||||||
|
class GenericGameObjectScript : public GameObjectScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GenericGameObjectScript(char const* name) : GameObjectScript(name) { }
|
||||||
|
GameObjectAI* GetAI(GameObject* go) const override { return new AI(go); }
|
||||||
|
};
|
||||||
|
#define RegisterGameObjectAI(ai_name) new GenericGameObjectScript<ai_name>(#ai_name)
|
||||||
|
|
||||||
#define sScriptMgr ScriptMgr::instance()
|
#define sScriptMgr ScriptMgr::instance()
|
||||||
|
|
||||||
template<class TScript>
|
template<class TScript>
|
||||||
|
|||||||
@@ -96,14 +96,10 @@ private:
|
|||||||
Creature const* _source;
|
Creature const* _source;
|
||||||
};
|
};
|
||||||
|
|
||||||
class boss_lord_marrowgar : public CreatureScript
|
struct boss_lord_marrowgar : public BossAI
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
boss_lord_marrowgar() : CreatureScript("boss_lord_marrowgar") { }
|
boss_lord_marrowgar(Creature* creature) : BossAI(creature, DATA_LORD_MARROWGAR)
|
||||||
|
|
||||||
struct boss_lord_marrowgarAI : public BossAI
|
|
||||||
{
|
|
||||||
boss_lord_marrowgarAI(Creature* creature) : BossAI(creature, DATA_LORD_MARROWGAR)
|
|
||||||
{
|
{
|
||||||
_introDone = false;
|
_introDone = false;
|
||||||
_boneSlice = false;
|
_boneSlice = false;
|
||||||
@@ -307,12 +303,6 @@ public:
|
|||||||
{
|
{
|
||||||
return target->GetPositionX() < -337.0f; // main gate
|
return target->GetPositionX() < -337.0f; // main gate
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
CreatureAI* GetAI(Creature* creature) const override
|
|
||||||
{
|
|
||||||
return GetIcecrownCitadelAI<boss_lord_marrowgarAI>(creature);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class npc_coldflame : public CreatureScript
|
class npc_coldflame : public CreatureScript
|
||||||
@@ -704,7 +694,7 @@ public:
|
|||||||
|
|
||||||
void AddSC_boss_lord_marrowgar()
|
void AddSC_boss_lord_marrowgar()
|
||||||
{
|
{
|
||||||
new boss_lord_marrowgar();
|
RegisterIcecrownCitadelCreatureAI(boss_lord_marrowgar);
|
||||||
new npc_coldflame();
|
new npc_coldflame();
|
||||||
new npc_bone_spike();
|
new npc_bone_spike();
|
||||||
new spell_marrowgar_coldflame();
|
new spell_marrowgar_coldflame();
|
||||||
|
|||||||
@@ -626,4 +626,6 @@ inline AI* GetIcecrownCitadelAI(T* obj)
|
|||||||
return GetInstanceAI<AI>(obj, ICCScriptName);
|
return GetInstanceAI<AI>(obj, ICCScriptName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define RegisterIcecrownCitadelCreatureAI(ai_name) RegisterCreatureAIWithFactory(ai_name, GetIcecrownCitadelAI)
|
||||||
|
|
||||||
#endif // ICECROWN_CITADEL_H_
|
#endif // ICECROWN_CITADEL_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user