feat(Core/Scripts): Optimize GameEventScript (#18711)

* Add files via upload

* Update GameEventScript.h
This commit is contained in:
天鹿
2024-04-12 21:56:46 +08:00
committed by GitHub
parent a2c867fcf2
commit 170817e66d
2 changed files with 21 additions and 16 deletions

View File

@@ -21,32 +21,28 @@
void ScriptMgr::OnGameEventStart(uint16 EventID)
{
ExecuteScript<GameEventScript>([&](GameEventScript* script)
{
script->OnStart(EventID);
});
CALL_ENABLED_HOOKS(GameEventScript, GAMEEVENTHOOK_ON_START, script->OnStart(EventID));
}
void ScriptMgr::OnGameEventStop(uint16 EventID)
{
ExecuteScript<GameEventScript>([&](GameEventScript* script)
{
script->OnStop(EventID);
});
CALL_ENABLED_HOOKS(GameEventScript, GAMEEVENTHOOK_ON_STOP, script->OnStop(EventID));
}
void ScriptMgr::OnGameEventCheck(uint16 EventID)
{
ExecuteScript<GameEventScript>([&](GameEventScript* script)
{
script->OnEventCheck(EventID);
});
CALL_ENABLED_HOOKS(GameEventScript, GAMEEVENTHOOK_ON_EVENT_CHECK, script->OnEventCheck(EventID));
}
GameEventScript::GameEventScript(const char* name)
: ScriptObject(name)
GameEventScript::GameEventScript(const char* name, std::vector<uint16> enabledHooks)
: ScriptObject(name, GAMEEVENTHOOK_END)
{
ScriptRegistry<GameEventScript>::AddScript(this);
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < GAMEEVENTHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<GameEventScript>::AddScript(this, std::move(enabledHooks));
}
template class AC_GAME_API ScriptRegistry<GameEventScript>;

View File

@@ -19,11 +19,20 @@
#define SCRIPT_OBJECT_GAME_EVENT_SCRIPT_H_
#include "ScriptObject.h"
#include <vector>
enum GameEventHook
{
GAMEEVENTHOOK_ON_START,
GAMEEVENTHOOK_ON_STOP,
GAMEEVENTHOOK_ON_EVENT_CHECK,
GAMEEVENTHOOK_END
};
class GameEventScript : public ScriptObject
{
protected:
GameEventScript(const char* name);
GameEventScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
public:
// Runs on start event