From 731682708f46a57abd11c36dc6e253132c2b54cb Mon Sep 17 00:00:00 2001 From: Foereaper Date: Wed, 10 Sep 2014 23:42:20 +0200 Subject: [PATCH] Added more BG hooks, fixed a few issues --- HookMgr.cpp | 35 +++++++++++++++++++++++++++++++++-- HookMgr.h | 6 ++++-- LuaEngine.cpp | 18 +++++++++--------- LuaEngine.h | 6 ++++-- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/HookMgr.cpp b/HookMgr.cpp index d3918ec..789763b 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -1935,10 +1935,41 @@ CreatureAI* Eluna::GetAI(Creature* creature) void Eluna::OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId) { - ENTRY_BEGIN(BGEventBindings, bg->GetTypeID(), BG_EVENT_ON_START, return); + EVENT_BEGIN(BGEventBindings, BG_EVENT_ON_START, return); Push(L, bg); Push(L, bgId); Push(L, instanceId); - ENTRY_EXECUTE(0); + 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(); } \ No newline at end of file diff --git a/HookMgr.h b/HookMgr.h index 519cbef..a76ebda 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -275,11 +275,13 @@ namespace HookMgr GOSSIP_EVENT_COUNT }; - // RegisterBGEvent(map_id/entry, EventId, function) + // 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, ???) - 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 }; }; diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 401d79c..6ffda49 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -96,6 +96,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)), @@ -104,7 +105,6 @@ 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 @@ -659,6 +659,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) { @@ -771,14 +779,6 @@ void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) return; } break; - - case HookMgr::REGTYPE_BG: - if (evt < HookMgr::BG_EVENT_COUNT) - { - 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 72dce6f..0ffdf5c 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -116,6 +116,7 @@ public: EventBind* GuildEventBindings; EventBind* GroupEventBindings; EventBind* VehicleEventBindings; + EventBind* BGEventBindings; EntryBind* PacketEventBindings; EntryBind* CreatureEventBindings; @@ -125,7 +126,6 @@ public: EntryBind* ItemEventBindings; EntryBind* ItemGossipBindings; EntryBind* playerGossipBindings; - EntryBind* BGEventBindings; Eluna(); ~Eluna(); @@ -349,7 +349,9 @@ public: /* Battle Ground */ void OnBGStart(BattleGround* bg, BattleGroundTypeId bgId, uint32 instanceId); - void OnBGEnd(BattleGround* bg); + 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);