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 b6311d7..af84882 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 be623ea..d3a9677 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 6921a11..8c431cc 100644
--- a/HookMgr.cpp
+++ b/HookMgr.cpp
@@ -1934,3 +1934,44 @@ CreatureAI* Eluna::GetAI(Creature* creature)
return NULL;
return new ElunaCreatureAI(creature);
}
+
+void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
+{
+ EVENT_BEGIN(BGEventBindings, BG_EVENT_ON_START, return);
+ Push(L, bg);
+ Push(L, bgId);
+ Push(L, instanceId);
+ EVENT_EXECUTE(0);
+ ENDCALL();
+}
+
+void Eluna::OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId, Team winner)
+{
+ EVENT_BEGIN(BGEventBindings, BG_EVENT_ON_END, return);
+ Push(L, bg);
+ Push(L, bgId);
+ Push(L, instanceId);
+ Push(L, winner);
+ EVENT_EXECUTE(0);
+ ENDCALL();
+}
+
+void Eluna::OnBGCreate(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
+{
+ EVENT_BEGIN(BGEventBindings, BG_EVENT_ON_CREATE, return);
+ Push(L, bg);
+ Push(L, bgId);
+ Push(L, instanceId);
+ EVENT_EXECUTE(0);
+ ENDCALL();
+}
+
+void Eluna::OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId)
+{
+ EVENT_BEGIN(BGEventBindings, BG_EVENT_ON_PRE_DESTROY, return);
+ Push(L, bg);
+ Push(L, bgId);
+ Push(L, instanceId);
+ EVENT_EXECUTE(0);
+ ENDCALL();
+}
diff --git a/HookMgr.h b/HookMgr.h
index 1008fcb..a76ebda 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
};
@@ -273,5 +274,15 @@ 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(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, bg, bgId, instanceId, winner) - Needs to be added to TC
+ BG_EVENT_ON_CREATE = 3, // (event, bg, bgId, instanceId) - Needs to be added to TC
+ BG_EVENT_ON_PRE_DESTROY = 4, // (event, bg, bgId, instanceId) - Needs to be added to TC
+ BG_EVENT_COUNT
+ };
};
#endif
diff --git a/LuaEngine.cpp b/LuaEngine.cpp
index 2491cc1..d3a5e27 100644
--- a/LuaEngine.cpp
+++ b/LuaEngine.cpp
@@ -94,6 +94,7 @@ PlayerEventBindings(new EventBind("PlayerEvents", *this))
GuildEventBindings(new EventBind("GuildEvents", *this)),
GroupEventBindings(new EventBind("GroupEvents", *this)),
VehicleEventBindings(new EventBind("VehicleEvents", *this)),
+BGEventBindings(new EventBind("BGEvents", *this)),
PacketEventBindings(new EntryBind("PacketEvents", *this)),
CreatureEventBindings(new EntryBind("CreatureEvents", *this)),
@@ -153,6 +154,7 @@ Eluna::~Eluna()
delete ItemEventBindings;
delete ItemGossipBindings;
delete playerGossipBindings;
+ delete BGEventBindings;
// Must close lua state after deleting stores and mgr
lua_close(L);
@@ -659,6 +661,14 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef)
}
break;
+ case HookMgr::REGTYPE_BG:
+ if (evt < HookMgr::BG_EVENT_COUNT)
+ {
+ BGEventBindings->Insert(evt, functionRef);
+ return;
+ }
+ break;
+
case HookMgr::REGTYPE_PACKET:
if (evt < HookMgr::PACKET_EVENT_COUNT)
{
diff --git a/LuaEngine.h b/LuaEngine.h
index 5ba385b..bcbd557 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;
@@ -115,6 +116,7 @@ public:
EventBind* GuildEventBindings;
EventBind* GroupEventBindings;
EventBind* VehicleEventBindings;
+ EventBind* BGEventBindings;
EntryBind* PacketEventBindings;
EntryBind* CreatureEventBindings;
@@ -344,6 +346,12 @@ public:
void OnUpdate(uint32 diff);
void OnStartup();
void OnShutdown();
+
+ /* Battle Ground */
+ void OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
+ void OnBGEnd(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId, Team winner);
+ void OnBGCreate(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
+ void OnBGDestroy(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
};
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 d20e015..753614f 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
@@ -1201,6 +1203,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))
@@ -1294,4 +1323,7 @@ void RegisterFunctions(lua_State* L)
ElunaTemplate::Register(L, "QueryResult", true);
ElunaTemplate::SetMethods(L, QueryMethods);
+
+ ElunaTemplate::Register(L, "BattleGround");
+ ElunaTemplate::SetMethods(L, BattleGroundMethods);
}