Added base BG methods and hooks

This has only been tested on Mangos Zero and will definitely need tweaking on Trinity

More methods will be added SHORTLY
This commit is contained in:
Foereaper
2014-09-10 22:38:21 +02:00
parent f2a591b87b
commit 0bfdf632e7
8 changed files with 308 additions and 2 deletions

221
BattleGroundMethods.h Normal file
View File

@@ -0,0 +1,221 @@
/*
* Copyright (C) 2010 - 2014 Eluna Lua Engine <http://emudevs.com/>
* 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<uint32>(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<uint32>(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<uint32>(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

View File

@@ -7,6 +7,7 @@
// Required // Required
#include "AccountMgr.h" #include "AccountMgr.h"
#include "AuctionHouseMgr.h" #include "AuctionHouseMgr.h"
#include "BattleGround/BattleGroundMgr.h"
#include "Cell.h" #include "Cell.h"
#include "CellImpl.h" #include "CellImpl.h"
#include "Chat.h" #include "Chat.h"

View File

@@ -601,6 +601,17 @@ namespace LuaGlobalFunctions
return 0; return 0;
} }
int RegisterBGEvent(lua_State* L)
{
uint32 ev = Eluna::CHECKVAL<uint32>(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*/) int ReloadEluna(lua_State* /*L*/)
{ {
Eluna::reload = true; Eluna::reload = true;

View File

@@ -1932,3 +1932,13 @@ CreatureAI* Eluna::GetAI(Creature* creature)
return NULL; return NULL;
return new ElunaCreatureAI(creature); 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();
}

View File

@@ -24,6 +24,7 @@ namespace HookMgr
REGTYPE_ITEM, REGTYPE_ITEM,
REGTYPE_ITEM_GOSSIP, REGTYPE_ITEM_GOSSIP,
REGTYPE_PLAYER_GOSSIP, REGTYPE_PLAYER_GOSSIP,
REGTYPE_BG,
REGTYPE_COUNT REGTYPE_COUNT
}; };
@@ -61,6 +62,7 @@ namespace HookMgr
// Eluna // Eluna
ELUNA_EVENT_ON_LUA_STATE_CLOSE = 16, // (event) 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
MAP_EVENT_ON_CREATE = 17, // (event, map) MAP_EVENT_ON_CREATE = 17, // (event, map)
@@ -89,8 +91,6 @@ namespace HookMgr
WORLD_EVENT_ON_DELETE_CREATURE = 31, // (event, creature) WORLD_EVENT_ON_DELETE_CREATURE = 31, // (event, creature)
WORLD_EVENT_ON_DELETE_GAMEOBJECT = 32, // (event, gameobject) 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 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_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 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 #endif

View File

@@ -104,6 +104,7 @@ GameObjectEventBindings(new EntryBind<HookMgr::GameObjectEvents>("GameObjectEven
GameObjectGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (gameobject)", *this)), GameObjectGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (gameobject)", *this)),
ItemEventBindings(new EntryBind<HookMgr::ItemEvents>("ItemEvents", *this)), ItemEventBindings(new EntryBind<HookMgr::ItemEvents>("ItemEvents", *this)),
ItemGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (item)", *this)), ItemGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (item)", *this)),
BGEventBindings(new EntryBind<HookMgr::BGEvents>("BGEvents", *this)),
playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)", *this)) playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)", *this))
{ {
// open base lua // open base lua
@@ -151,6 +152,7 @@ Eluna::~Eluna()
delete ItemEventBindings; delete ItemEventBindings;
delete ItemGossipBindings; delete ItemGossipBindings;
delete playerGossipBindings; delete playerGossipBindings;
delete BGEventBindings;
// Must close lua state after deleting stores and mgr // Must close lua state after deleting stores and mgr
lua_close(L); lua_close(L);
@@ -769,6 +771,21 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef)
return; return;
} }
break; 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_unref(L, LUA_REGISTRYINDEX, functionRef);
luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt); luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt);

View File

@@ -38,6 +38,7 @@ typedef int Difficulty;
struct AreaTriggerEntry; struct AreaTriggerEntry;
class AuctionHouseObject; class AuctionHouseObject;
class BattleGround;
class Channel; class Channel;
class Corpse; class Corpse;
class Creature; class Creature;
@@ -124,6 +125,7 @@ public:
EntryBind<HookMgr::ItemEvents>* ItemEventBindings; EntryBind<HookMgr::ItemEvents>* ItemEventBindings;
EntryBind<HookMgr::GossipEvents>* ItemGossipBindings; EntryBind<HookMgr::GossipEvents>* ItemGossipBindings;
EntryBind<HookMgr::GossipEvents>* playerGossipBindings; EntryBind<HookMgr::GossipEvents>* playerGossipBindings;
EntryBind<HookMgr::BGEvents>* BGEventBindings;
Eluna(); Eluna();
~Eluna(); ~Eluna();
@@ -344,6 +346,10 @@ public:
void OnUpdate(uint32 diff); void OnUpdate(uint32 diff);
void OnStartup(); void OnStartup();
void OnShutdown(); void OnShutdown();
/* Battle Ground */
void OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId);
void OnBGEnd(BattleGround* bg);
}; };
template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error); template<> Unit* Eluna::CHECKOBJ<Unit>(lua_State* L, int narg, bool error);
template<> Player* Eluna::CHECKOBJ<Player>(lua_State* L, int narg, bool error); template<> Player* Eluna::CHECKOBJ<Player>(lua_State* L, int narg, bool error);

View File

@@ -36,6 +36,7 @@ extern "C"
#include "CorpseMethods.h" #include "CorpseMethods.h"
#include "WeatherMethods.h" #include "WeatherMethods.h"
#include "VehicleMethods.h" #include "VehicleMethods.h"
#include "BattleGroundMethods.h"
void RegisterGlobals(lua_State* L) 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, "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent); // RegisterItemEvent(entry, event, function)
lua_register(L, "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent); // RegisterItemGossipEvent(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, "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent); // RegisterPlayerGossipEvent(menu_id, event, function)
lua_register(L, "RegisterBGEvent", &LuaGlobalFunctions::RegisterBGEvent); // RegisterBGEvent(event, function)
// Getters // Getters
lua_register(L, "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine); // GetLuaEngine() - Returns ElunaEngine lua_register(L, "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine); // GetLuaEngine() - Returns ElunaEngine
@@ -1204,6 +1206,33 @@ ElunaRegister<AuctionHouseObject> AuctionMethods[] =
{ NULL, NULL } { NULL, NULL }
}; };
ElunaRegister<BattleGround> 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<typename T> const char* ElunaTemplate<T>::tname = NULL; template<typename T> const char* ElunaTemplate<T>::tname = NULL;
template<typename T> bool ElunaTemplate<T>::manageMemory = false; template<typename T> bool ElunaTemplate<T>::manageMemory = false;
#if (!defined(TBC) && !defined(CLASSIC)) #if (!defined(TBC) && !defined(CLASSIC))
@@ -1297,4 +1326,7 @@ void RegisterFunctions(lua_State* L)
ElunaTemplate<QueryResult>::Register(L, "QueryResult", true); ElunaTemplate<QueryResult>::Register(L, "QueryResult", true);
ElunaTemplate<QueryResult>::SetMethods(L, QueryMethods); ElunaTemplate<QueryResult>::SetMethods(L, QueryMethods);
ElunaTemplate<BattleGround>::Register(L, "BattleGround");
ElunaTemplate<BattleGround>::SetMethods(L, BattleGroundMethods);
} }