Merge branch 'master' of https://github.com/ElunaLuaEngine/Eluna into luaevents

This commit is contained in:
Rochet2
2014-09-13 16:05:30 +03:00
8 changed files with 335 additions and 0 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
#include "AccountMgr.h"
#include "AuctionHouseMgr.h"
#include "BattleGround/BattleGroundMgr.h"
#include "Cell.h"
#include "CellImpl.h"
#include "Chat.h"

View File

@@ -601,6 +601,17 @@ namespace LuaGlobalFunctions
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*/)
{
Eluna::reload = true;

View File

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

View File

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

View File

@@ -94,6 +94,7 @@ PlayerEventBindings(new EventBind<HookMgr::PlayerEvents>("PlayerEvents", *this))
GuildEventBindings(new EventBind<HookMgr::GuildEvents>("GuildEvents", *this)),
GroupEventBindings(new EventBind<HookMgr::GroupEvents>("GroupEvents", *this)),
VehicleEventBindings(new EventBind<HookMgr::VehicleEvents>("VehicleEvents", *this)),
BGEventBindings(new EventBind<HookMgr::BGEvents>("BGEvents", *this)),
PacketEventBindings(new EntryBind<HookMgr::PacketEvents>("PacketEvents", *this)),
CreatureEventBindings(new EntryBind<HookMgr::CreatureEvents>("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)
{

View File

@@ -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<HookMgr::GuildEvents>* GuildEventBindings;
EventBind<HookMgr::GroupEvents>* GroupEventBindings;
EventBind<HookMgr::VehicleEvents>* VehicleEventBindings;
EventBind<HookMgr::BGEvents>* BGEventBindings;
EntryBind<HookMgr::PacketEvents>* PacketEventBindings;
EntryBind<HookMgr::CreatureEvents>* 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<Unit>(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 "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<AuctionHouseObject> AuctionMethods[] =
{ 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> bool ElunaTemplate<T>::manageMemory = false;
#if (!defined(TBC) && !defined(CLASSIC))
@@ -1294,4 +1323,7 @@ void RegisterFunctions(lua_State* L)
ElunaTemplate<QueryResult>::Register(L, "QueryResult", true);
ElunaTemplate<QueryResult>::SetMethods(L, QueryMethods);
ElunaTemplate<BattleGround>::Register(L, "BattleGround");
ElunaTemplate<BattleGround>::SetMethods(L, BattleGroundMethods);
}