chore(Core/AllMapScript) Update structure (#19979)

* fix(Core/AllMapScript) Update structure to use CALL_ENABLED_HOOKS

* fatal error: no template named 'vector' in namespace 'std'

* fix build

Co-authored-by: Anton Popovichenko <anton.popovichenko@mendix.com>

---------

Co-authored-by: Anton Popovichenko <anton.popovichenko@mendix.com>
This commit is contained in:
Walter Pagani
2024-09-21 17:25:22 -03:00
committed by GitHub
parent b364e00238
commit cfd7bf4162
3 changed files with 29 additions and 32 deletions

View File

@@ -88,10 +88,7 @@ void ScriptMgr::OnCreateMap(Map* map)
{
ASSERT(map);
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnCreateMap(map);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_CREATE_MAP, script->OnCreateMap(map));
ForeachMaps<WorldMapScript>(map,
[&](WorldMapScript* script)
@@ -116,10 +113,7 @@ void ScriptMgr::OnDestroyMap(Map* map)
{
ASSERT(map);
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnDestroyMap(map);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_DESTROY_MAP, script->OnDestroyMap(map));
ForeachMaps<WorldMapScript>(map,
[&](WorldMapScript* script)
@@ -193,10 +187,7 @@ void ScriptMgr::OnPlayerEnterMap(Map* map, Player* player)
ASSERT(map);
ASSERT(player);
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnPlayerEnterAll(map, player);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_PLAYER_ENTER_ALL, script->OnPlayerEnterAll(map, player));
ExecuteScript<PlayerScript>([=](PlayerScript* script)
{
@@ -227,10 +218,7 @@ void ScriptMgr::OnPlayerLeaveMap(Map* map, Player* player)
ASSERT(map);
ASSERT(player);
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnPlayerLeaveAll(map, player);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_PLAYER_LEAVE_ALL, script->OnPlayerLeaveAll(map, player));
ForeachMaps<WorldMapScript>(map,
[&](WorldMapScript* script)
@@ -255,10 +243,7 @@ void ScriptMgr::OnMapUpdate(Map* map, uint32 diff)
{
ASSERT(map);
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnMapUpdate(map, diff);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_MAP_UPDATE, script->OnMapUpdate(map, diff));
ForeachMaps<WorldMapScript>(map,
[&](WorldMapScript* script)
@@ -281,24 +266,22 @@ void ScriptMgr::OnMapUpdate(Map* map, uint32 diff)
void ScriptMgr::OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript** instanceData, bool load, std::string data, uint32 completedEncounterMask)
{
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnBeforeCreateInstanceScript(instanceMap, instanceData, load, data, completedEncounterMask);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_BEFORE_CREATE_INSTANCE_SCRIPT, script->OnBeforeCreateInstanceScript(instanceMap, instanceData, load, data, completedEncounterMask));
}
void ScriptMgr::OnDestroyInstance(MapInstanced* mapInstanced, Map* map)
{
ExecuteScript<AllMapScript>([&](AllMapScript* script)
{
script->OnDestroyInstance(mapInstanced, map);
});
CALL_ENABLED_HOOKS(AllMapScript, ALLMAPHOOK_ON_DESTROY_INSTANCE, script->OnDestroyInstance(mapInstanced, map));
}
AllMapScript::AllMapScript(const char* name) :
ScriptObject(name)
AllMapScript::AllMapScript(const char* name, std::vector<uint16> enabledHooks) : ScriptObject(name, ALLMAPHOOK_END)
{
ScriptRegistry<AllMapScript>::AddScript(this);
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < ALLMAPHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<AllMapScript>::AddScript(this, std::move(enabledHooks));
}
template class AC_GAME_API ScriptRegistry<AllMapScript>;

View File

@@ -19,11 +19,24 @@
#define SCRIPT_OBJECT_ALL_MAP_SCRIPT_H_
#include "ScriptObject.h"
#include <vector>
enum AllMapHook
{
ALLMAPHOOK_ON_PLAYER_ENTER_ALL,
ALLMAPHOOK_ON_PLAYER_LEAVE_ALL,
ALLMAPHOOK_ON_BEFORE_CREATE_INSTANCE_SCRIPT,
ALLMAPHOOK_ON_DESTROY_INSTANCE,
ALLMAPHOOK_ON_CREATE_MAP,
ALLMAPHOOK_ON_DESTROY_MAP,
ALLMAPHOOK_ON_MAP_UPDATE,
ALLMAPHOOK_END
};
class AllMapScript : public ScriptObject
{
protected:
AllMapScript(const char* name);
AllMapScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
public:
/**

View File

@@ -102,6 +102,7 @@ void ScriptMgr::Initialize()
ScriptRegistry<UnitScript>::InitEnabledHooksIfNeeded(UNITHOOK_END);
ScriptRegistry<WorldObjectScript>::InitEnabledHooksIfNeeded(WORLDOBJECTHOOK_END);
ScriptRegistry<WorldScript>::InitEnabledHooksIfNeeded(WORLDHOOK_END);
ScriptRegistry<AllMapScript>::InitEnabledHooksIfNeeded(ALLMAPHOOK_END);
}
void ScriptMgr::Unload()