diff --git a/BattleGroundMethods.h b/BattleGroundMethods.h
new file mode 100644
index 0000000..b71902e
--- /dev/null
+++ b/BattleGroundMethods.h
@@ -0,0 +1,221 @@
+/*
+* Copyright (C) 2010 - 2014 Eluna Lua Engine
+* This program is free software licensed under GPL version 3
+* Please see the included DOCS/LICENSE.md for more information
+*/
+
+#ifndef BATTLEGROUNDMETHODS_H
+#define BATTLEGROUNDMETHODS_H
+
+namespace LuaBattleGround
+{
+#ifdef MANGOS // Currently only tested on Mangos. May need tweaking for TC
+ /**
+ * Returns the name of the [Battleground]
+ *
+ * @return string name
+ */
+ int GetName(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetName());
+ return 1;
+ }
+
+ /**
+ * Returns the amount of alive players in the [Battleground] by the team ID.
+ *
+ * @param uint32 team : team ID
+ * @return uint32 count
+ */
+ int GetAlivePlayersCountByTeam(lua_State* L, BattleGround* bg)
+ {
+ uint32 team = Eluna::CHECKVAL(L, 2);
+
+ Eluna::Push(L, bg->GetAlivePlayersCountByTeam((Team)team));
+ return 1;
+ }
+
+ /**
+ * Returns the [Map] of the [Battleground].
+ *
+ * @return [Map] map
+ */
+ int GetMap(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetBgMap());
+ return 1;
+ }
+
+ /**
+ * Returns the bonus honor given by amount of kills in the specific [Battleground].
+ *
+ * @param uint32 kills : amount of kills
+ * @return uint32 bonusHonor
+ */
+ int GetBonusHonorFromKillCount(lua_State* L, BattleGround* bg)
+ {
+ uint32 kills = Eluna::CHECKVAL(L, 2);
+
+ Eluna::Push(L, bg->GetBonusHonorFromKill(kills));
+ return 1;
+ }
+
+ /**
+ * Returns the bracket ID of the specific [Battleground].
+ *
+ * @return BattleGroundBracketId bracketId
+ */
+ int GetBracketId(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetBracketId());
+ return 1;
+ }
+
+ /**
+ * Returns the end time of the [Battleground].
+ *
+ * @return uint32 endTime
+ */
+ int GetEndTime(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetEndTime());
+ return 1;
+ }
+
+ /**
+ * Returns the amount of free slots for the selected team in the specific [Battleground].
+ *
+ * @param uint32 team : team ID
+ * @return uint32 freeSlots
+ */
+ int GetFreeSlotsForTeam(lua_State* L, BattleGround* bg)
+ {
+ uint32 team = Eluna::CHECKVAL(L, 2);
+
+ Eluna::Push(L, bg->GetFreeSlotsForTeam((Team)team));
+ return 1;
+ }
+
+ /**
+ * Returns the instance ID of the [Battleground].
+ *
+ * @return uint32 instanceId
+ */
+ int GetInstanceId(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetInstanceID());
+ return 1;
+ }
+
+ /**
+ * Returns the map ID of the [Battleground].
+ *
+ * @return uint32 mapId
+ */
+ int GetMapId(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMapId());
+ return 1;
+ }
+
+ /**
+ * Returns the type ID of the [Battleground].
+ *
+ * @return BattleGroundTypeId typeId
+ */
+ int GetTypeId(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetTypeID());
+ return 1;
+ }
+
+ /**
+ * Returns the max allowed [Player] level of the specific [Battleground].
+ *
+ * @return uint32 maxLevel
+ */
+ int GetMaxLevel(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMaxLevel());
+ return 1;
+ }
+
+ /**
+ * Returns the minimum allowed [Player] level of the specific [Battleground].
+ *
+ * @return uint32 minLevel
+ */
+ int GetMinLevel(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMinLevel());
+ return 1;
+ }
+
+ /**
+ * Returns the maximum allowed [Player] count of the specific [Battleground].
+ *
+ * @return uint32 maxPlayerCount
+ */
+ int GetMaxPlayers(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMaxPlayers());
+ return 1;
+ }
+
+ /**
+ * Returns the minimum allowed [Player] count of the specific [Battleground].
+ *
+ * @return uint32 minPlayerCount
+ */
+ int GetMinPlayers(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMinPlayers());
+ return 1;
+ }
+
+ /**
+ * Returns the maximum allowed [Player] count per team of the specific [Battleground].
+ *
+ * @return uint32 maxTeamPlayerCount
+ */
+ int GetMaxPlayersPerTeam(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMaxPlayersPerTeam());
+ return 1;
+ }
+
+ /**
+ * Returns the minimum allowed [Player] count per team of the specific [Battleground].
+ *
+ * @return uint32 minTeamPlayerCount
+ */
+ int GetMinPlayersPerTeam(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetMinPlayersPerTeam());
+ return 1;
+ }
+
+ /**
+ * Returns the winning team of the specific [Battleground].
+ *
+ * @return Team team
+ */
+ int GetWinner(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetWinner());
+ return 1;
+ }
+
+ /**
+ * Returns the status of the specific [Battleground].
+ *
+ * @return BattleGroundStatus status
+ */
+ int GetStatus(lua_State* L, BattleGround* bg)
+ {
+ Eluna::Push(L, bg->GetStatus());
+ return 1;
+ }
+#endif
+};
+#endif
\ No newline at end of file
diff --git a/ElunaIncludes.h b/ElunaIncludes.h
index 61d17b3..0fac616 100644
--- a/ElunaIncludes.h
+++ b/ElunaIncludes.h
@@ -7,6 +7,7 @@
// Required
#include "AccountMgr.h"
#include "AuctionHouseMgr.h"
+#include "BattleGround/BattleGroundMgr.h"
#include "Cell.h"
#include "CellImpl.h"
#include "Chat.h"
diff --git a/GlobalMethods.h b/GlobalMethods.h
index b7f404a..d87018d 100644
--- a/GlobalMethods.h
+++ b/GlobalMethods.h
@@ -601,6 +601,17 @@ namespace LuaGlobalFunctions
return 0;
}
+ int RegisterBGEvent(lua_State* L)
+ {
+ uint32 ev = Eluna::CHECKVAL(L, 1);
+ luaL_checktype(L, 2, LUA_TFUNCTION);
+ lua_pushvalue(L, 2);
+ int functionRef = luaL_ref(L, LUA_REGISTRYINDEX);
+ if (functionRef > 0)
+ sEluna->Register(HookMgr::REGTYPE_BG, 0, ev, functionRef);
+ return 0;
+ }
+
int ReloadEluna(lua_State* /*L*/)
{
Eluna::reload = true;
diff --git a/HookMgr.cpp b/HookMgr.cpp
index 4a9ea3d..d3918ec 100644
--- a/HookMgr.cpp
+++ b/HookMgr.cpp
@@ -1932,3 +1932,13 @@ CreatureAI* Eluna::GetAI(Creature* creature)
return NULL;
return new ElunaCreatureAI(creature);
}
+
+void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
+{
+ ENTRY_BEGIN(BGEventBindings, bg->GetTypeID(), BG_EVENT_ON_START, return);
+ Push(L, bg);
+ Push(L, bgId);
+ Push(L, instanceId);
+ ENTRY_EXECUTE(0);
+ ENDCALL();
+}
\ No newline at end of file
diff --git a/HookMgr.h b/HookMgr.h
index c81b1f4..519cbef 100644
--- a/HookMgr.h
+++ b/HookMgr.h
@@ -24,6 +24,7 @@ namespace HookMgr
REGTYPE_ITEM,
REGTYPE_ITEM_GOSSIP,
REGTYPE_PLAYER_GOSSIP,
+ REGTYPE_BG,
REGTYPE_COUNT
};
@@ -61,6 +62,7 @@ namespace HookMgr
// Eluna
ELUNA_EVENT_ON_LUA_STATE_CLOSE = 16, // (event)
+ ELUNA_EVENT_ON_LUA_STATE_OPEN = 33, // (event) - Possibly change hook ID for increments? Not implemented on TC/Cmangos
// Map
MAP_EVENT_ON_CREATE = 17, // (event, map)
@@ -88,8 +90,6 @@ namespace HookMgr
WORLD_EVENT_ON_DELETE_CREATURE = 31, // (event, creature)
WORLD_EVENT_ON_DELETE_GAMEOBJECT = 32, // (event, gameobject)
-
- ELUNA_EVENT_ON_LUA_STATE_OPEN = 33, // (event) - Possibly change hook ID for increments? Not implemented on TC/Cmangos
SERVER_EVENT_COUNT
};
@@ -274,5 +274,13 @@ namespace HookMgr
GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip
GOSSIP_EVENT_COUNT
};
+
+ // RegisterBGEvent(map_id/entry, EventId, function)
+ enum BGEvents
+ {
+ BG_EVENT_ON_START = 1, // (event, bg, bgId, instanceId) - Needs to be added to TC
+ BG_EVENT_ON_END = 2, // (event, ???) - Needs to be added to TC
+ BG_EVENT_COUNT
+ };
};
#endif
diff --git a/LuaEngine.cpp b/LuaEngine.cpp
index fbe8f77..163dcf3 100644
--- a/LuaEngine.cpp
+++ b/LuaEngine.cpp
@@ -104,6 +104,7 @@ GameObjectEventBindings(new EntryBind("GameObjectEven
GameObjectGossipBindings(new EntryBind("GossipEvents (gameobject)", *this)),
ItemEventBindings(new EntryBind("ItemEvents", *this)),
ItemGossipBindings(new EntryBind("GossipEvents (item)", *this)),
+BGEventBindings(new EntryBind("BGEvents", *this)),
playerGossipBindings(new EntryBind("GossipEvents (player)", *this))
{
// open base lua
@@ -151,6 +152,7 @@ Eluna::~Eluna()
delete ItemEventBindings;
delete ItemGossipBindings;
delete playerGossipBindings;
+ delete BGEventBindings;
// Must close lua state after deleting stores and mgr
lua_close(L);
@@ -769,6 +771,21 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef)
return;
}
break;
+
+ case HookMgr::REGTYPE_BG:
+ if (evt < HookMgr::BG_EVENT_COUNT)
+ {
+ if (!BattleGroundTypeId(id))
+ {
+ luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
+ luaL_error(L, "Couldn't find battleground with type (ID: %d)!", id);
+ return;
+ }
+
+ BGEventBindings->Insert(id, evt, functionRef);
+ return;
+ }
+ break;
}
luaL_unref(L, LUA_REGISTRYINDEX, functionRef);
luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt);
diff --git a/LuaEngine.h b/LuaEngine.h
index 0cece17..72dce6f 100644
--- a/LuaEngine.h
+++ b/LuaEngine.h
@@ -38,6 +38,7 @@ typedef int Difficulty;
struct AreaTriggerEntry;
class AuctionHouseObject;
+class BattleGround;
class Channel;
class Corpse;
class Creature;
@@ -124,6 +125,7 @@ public:
EntryBind* ItemEventBindings;
EntryBind* ItemGossipBindings;
EntryBind* playerGossipBindings;
+ EntryBind* BGEventBindings;
Eluna();
~Eluna();
@@ -344,6 +346,10 @@ public:
void OnUpdate(uint32 diff);
void OnStartup();
void OnShutdown();
+
+ /* Battle Ground */
+ void OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
+ void OnBGEnd(BattleGround* bg);
};
template<> Unit* Eluna::CHECKOBJ(lua_State* L, int narg, bool error);
template<> Player* Eluna::CHECKOBJ(lua_State* L, int narg, bool error);
diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp
index 19091a9..bbe913e 100644
--- a/LuaFunctions.cpp
+++ b/LuaFunctions.cpp
@@ -36,6 +36,7 @@ extern "C"
#include "CorpseMethods.h"
#include "WeatherMethods.h"
#include "VehicleMethods.h"
+#include "BattleGroundMethods.h"
void RegisterGlobals(lua_State* L)
{
@@ -52,6 +53,7 @@ void RegisterGlobals(lua_State* L)
lua_register(L, "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent); // RegisterItemEvent(entry, event, function)
lua_register(L, "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent); // RegisterItemGossipEvent(entry, event, function)
lua_register(L, "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent); // RegisterPlayerGossipEvent(menu_id, event, function)
+ lua_register(L, "RegisterBGEvent", &LuaGlobalFunctions::RegisterBGEvent); // RegisterBGEvent(event, function)
// Getters
lua_register(L, "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine); // GetLuaEngine() - Returns ElunaEngine
@@ -1204,6 +1206,33 @@ ElunaRegister AuctionMethods[] =
{ NULL, NULL }
};
+ElunaRegister BattleGroundMethods[] =
+{
+ // Getters
+ { "GetName", &LuaBattleGround::GetName },
+ { "GetAlivePlayersCountByTeam", &LuaBattleGround::GetAlivePlayersCountByTeam },
+ { "GetMap", &LuaBattleGround::GetMap },
+ { "GetBonusHonorFromKillCount", &LuaBattleGround::GetBonusHonorFromKillCount },
+ { "GetBracketId", &LuaBattleGround::GetBracketId },
+ { "GetEndTime", &LuaBattleGround::GetEndTime },
+ { "GetFreeSlotsForTeam", &LuaBattleGround::GetFreeSlotsForTeam },
+ { "GetInstanceId", &LuaBattleGround::GetInstanceId },
+ { "GetMapId", &LuaBattleGround::GetMapId },
+ { "GetTypeId", &LuaBattleGround::GetTypeId },
+ { "GetMaxLevel", &LuaBattleGround::GetMaxLevel },
+ { "GetMinLevel", &LuaBattleGround::GetMinLevel },
+ { "GetMaxPlayers", &LuaBattleGround::GetMaxPlayers },
+ { "GetMinPlayers", &LuaBattleGround::GetMinPlayers },
+ { "GetMaxPlayersPerTeam", &LuaBattleGround::GetMaxPlayersPerTeam },
+ { "GetMinPlayersPerTeam", &LuaBattleGround::GetMinPlayersPerTeam },
+ { "GetWinner", &LuaBattleGround::GetWinner },
+ { "GetStatus", &LuaBattleGround::GetStatus },
+
+ // Setters
+
+ { NULL, NULL }
+};
+
template const char* ElunaTemplate::tname = NULL;
template bool ElunaTemplate::manageMemory = false;
#if (!defined(TBC) && !defined(CLASSIC))
@@ -1297,4 +1326,7 @@ void RegisterFunctions(lua_State* L)
ElunaTemplate::Register(L, "QueryResult", true);
ElunaTemplate::SetMethods(L, QueryMethods);
+
+ ElunaTemplate::Register(L, "BattleGround");
+ ElunaTemplate::SetMethods(L, BattleGroundMethods);
}