From d644b3a7f0f4b82cd7ac70c690d06c445bb97d6b Mon Sep 17 00:00:00 2001 From: Foereaper Date: Sun, 12 Nov 2017 12:31:24 +0100 Subject: [PATCH] Added game event related methods --- ElunaIncludes.h | 1 + GlobalMethods.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ LuaFunctions.cpp | 4 +++ 3 files changed, 79 insertions(+) diff --git a/ElunaIncludes.h b/ElunaIncludes.h index d505aa5..2dd2497 100644 --- a/ElunaIncludes.h +++ b/ElunaIncludes.h @@ -40,6 +40,7 @@ #ifdef TRINITY #include "Config.h" +#include "GameEventMgr.h" #include "GroupMgr.h" #include "ScriptedCreature.h" #include "SpellInfo.h" diff --git a/GlobalMethods.h b/GlobalMethods.h index 8629b76..4754ecb 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -460,6 +460,32 @@ namespace LuaGlobalFunctions return 1; } +#ifdef TRINITY + /** + * Returns the currently active game events. + * + * @return table activeEvents + */ + int GetActiveGameEvents(lua_State* L) + { + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 counter = 1; + GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList(); + + for (GameEventMgr::ActiveEvents::const_iterator i = activeEvents.begin(); i != activeEvents.end(); ++i) + { + Eluna::Push(L, *i); + lua_rawseti(L, tbl, counter); + + counter++; + } + + lua_settop(L, tbl); + return 1; + } +#endif + static int RegisterEntryHelper(lua_State* L, int regtype) { uint32 id = Eluna::CHECKVAL(L, 1); @@ -2349,6 +2375,22 @@ namespace LuaGlobalFunctions return 1; } +#ifdef TRINITY + /** + * Returns `true` if the event is currently active, otherwise `false`. + * + * @param uint16 eventId : the event id to check. + * @return bool isActive + */ + int IsGameEventActive(lua_State* L) + { + uint16 eventId = Eluna::CHECKVAL(L, 1); + + Eluna::Push(L, sGameEventMgr->IsActiveEvent(eventId)); + return 1; + } +#endif + /** * Returns the server's current time. * @@ -2419,6 +2461,38 @@ namespace LuaGlobalFunctions return 0; } +#ifdef TRINITY + /** + * Starts the event by eventId, if force is set, the event will force start regardless of previous event state. + * + * @param uint16 eventId : the event id to start. + * @param bool force = false : set `true` to force start the event. + */ + int StartGameEvent(lua_State* L) + { + uint16 eventId = Eluna::CHECKVAL(L, 1); + bool force = Eluna::CHECKVAL(L, 2, false); + + sGameEventMgr->StartEvent(eventId, force); + return 0; + } + + /** + * Stops the event by eventId, if force is set, the event will force stop regardless of previous event state. + * + * @param uint16 eventId : the event id to stop. + * @param bool force = false : set `true` to force stop the event. + */ + int StopGameEvent(lua_State* L) + { + uint16 eventId = Eluna::CHECKVAL(L, 1); + bool force = Eluna::CHECKVAL(L, 2, false); + + sGameEventMgr->StopEvent(eventId, force); + return 0; + } +#endif + /** * Returns an object representing a `long long` (64-bit) value. * diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp index 08b0ef2..f50bf25 100644 --- a/LuaFunctions.cpp +++ b/LuaFunctions.cpp @@ -108,12 +108,14 @@ luaL_Reg GlobalMethods[] = { "PrintInfo", &LuaGlobalFunctions::PrintInfo }, { "PrintError", &LuaGlobalFunctions::PrintError }, { "PrintDebug", &LuaGlobalFunctions::PrintDebug }, + { "GetActiveGameEvents", &LuaGlobalFunctions::GetActiveGameEvents }, // Boolean { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos }, { "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos }, { "IsBankPos", &LuaGlobalFunctions::IsBankPos }, { "IsBagPos", &LuaGlobalFunctions::IsBagPos }, + { "IsGameEventActive", &LuaGlobalFunctions::IsGameEventActive }, // Other { "ReloadEluna", &LuaGlobalFunctions::ReloadEluna }, @@ -139,6 +141,8 @@ luaL_Reg GlobalMethods[] = { "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath }, { "CreateInt64", &LuaGlobalFunctions::CreateLongLong }, { "CreateUint64", &LuaGlobalFunctions::CreateULongLong }, + { "StartGameEvent", &LuaGlobalFunctions::StartGameEvent }, + { "StopGameEvent", &LuaGlobalFunctions::StopGameEvent }, { NULL, NULL } };