Added game event related methods

This commit is contained in:
Foereaper
2017-11-12 12:31:24 +01:00
parent e2054785d0
commit d644b3a7f0
3 changed files with 79 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
#ifdef TRINITY
#include "Config.h"
#include "GameEventMgr.h"
#include "GroupMgr.h"
#include "ScriptedCreature.h"
#include "SpellInfo.h"

View File

@@ -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<uint32>(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<uint16>(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<uint16>(L, 1);
bool force = Eluna::CHECKVAL<bool>(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<uint16>(L, 1);
bool force = Eluna::CHECKVAL<bool>(L, 2, false);
sGameEventMgr->StopEvent(eventId, force);
return 0;
}
#endif
/**
* Returns an object representing a `long long` (64-bit) value.
*

View File

@@ -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 }
};