From 191f9ab768b072a054b4914f68e8fc45aa227e86 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Fri, 28 Mar 2014 14:53:22 +0200 Subject: [PATCH] Eluna reimplement lock and improve hook handling --- HookMgr.cpp | 2746 +++++++++++++++++++++++++------------------------ HookMgr.h | 2 +- LuaEngine.cpp | 8 +- LuaEngine.h | 56 +- 4 files changed, 1474 insertions(+), 1338 deletions(-) diff --git a/HookMgr.cpp b/HookMgr.cpp index 5f4ba38..5fe018b 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -7,190 +7,316 @@ #include "LuaEngine.h" #include "HookMgr.h" -extern bool StartEluna(); -bool HookMgr::OnCommand(Player* player, const char* text) +void HookMgr::OnEngineRestart() { - std::string fullcmd(text); - char* creload = strtok((char*)text, " "); - char* celuna = strtok(NULL, ""); - if (creload && celuna) - { - std::string reload(creload); - std::string eluna(celuna); - std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower); - if (reload == "reload") - { - std::transform(eluna.begin(), eluna.end(), eluna.begin(), ::tolower); - if (std::string("eluna").find(eluna) == 0) - { - sWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna..."); - StartEluna(); - return false; - } - } - } + if (!sEluna->ServerEventBindings.HasEvents(ELUNA_EVENT_ON_RESTART)) + return; ELUNA_GUARD(); - bool result = true; - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_COMMAND)) - return result; - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, fullcmd); - sEluna->PlayerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - result = sEluna->CHECKVAL(sEluna->L, i, result); - } - sEluna->PlayerEventBindings.EndCall(); - return result; + sEluna->ServerEventBindings.BeginCall(ELUNA_EVENT_ON_RESTART); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } void HookMgr::OnWorldUpdate(uint32 diff) { - ELUNA_GUARD(); sEluna->m_EventMgr.Update(diff); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE)) + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_UPDATE)) return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE); sEluna->Push(sEluna->L, diff); sEluna->ServerEventBindings.ExecuteCall(); sEluna->ServerEventBindings.EndCall(); } -void HookMgr::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid) +// areatrigger +bool HookMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) { + if (!sEluna->ServerEventBindings.HasEvents(TRIGGER_EVENT_ON_TRIGGER)) + return false; ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_ITEM)) - return; + sEluna->ServerEventBindings.BeginCall(TRIGGER_EVENT_ON_TRIGGER); sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, count); - sEluna->Push(sEluna->L, guid); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->Push(sEluna->L, pTrigger->id); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + return false; } - -void HookMgr::OnLootMoney(Player* pPlayer, uint32 amount) +// weather +void HookMgr::OnChange(Weather* weather, WeatherState state, float grade) { + if (!sEluna->ServerEventBindings.HasEvents(WEATHER_EVENT_ON_CHANGE)) + return; ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_MONEY)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, amount); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.BeginCall(WEATHER_EVENT_ON_CHANGE); + sEluna->Push(sEluna->L, (weather->GetZone())); + sEluna->Push(sEluna->L, state); + sEluna->Push(sEluna->L, grade); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } - -void HookMgr::OnFirstLogin(Player* pPlayer) +// transport +void HookMgr::OnAddPassenger(Transport* transport, Player* player) { +} +void HookMgr::OnAddCreaturePassenger(Transport* transport, Creature* creature) +{ +} +void HookMgr::OnRemovePassenger(Transport* transport, Player* player) +{ +} +void HookMgr::OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z) +{ +} +// Auction House +void HookMgr::OnAdd(AuctionHouseObject* ah) +{ + if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_ADD)) + return; ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_FIRST_LOGIN)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_ADD); + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } -void HookMgr::OnRepop(Player* pPlayer) +void HookMgr::OnRemove(AuctionHouseObject* ah) { + if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_REMOVE)) + return; ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPOP)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_REMOVE); + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } -void HookMgr::OnResurrect(Player* pPlayer) +void HookMgr::OnSuccessful(AuctionHouseObject* ah) { + if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_SUCCESSFUL)) + return; ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_RESURRECT)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_SUCCESSFUL); + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } -void HookMgr::OnQuestAbandon(Player* pPlayer, uint32 questId) +void HookMgr::OnExpire(AuctionHouseObject* ah) { - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_QUEST_ABANDON)) + if (!sEluna->ServerEventBindings.HasEvents(AUCTION_EVENT_ON_EXPIRE)) return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, questId); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnGmTicketCreate(Player* pPlayer, std::string& ticketText) -{ - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_CREATE)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, ticketText); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnGmTicketUpdate(Player* pPlayer, std::string& ticketText) -{ - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_UPDATE)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, ticketText); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnGmTicketDelete(Player* pPlayer) -{ - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_DELETE)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); -} - -void HookMgr::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) -{ ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EQUIP)) - return; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pItem); - sEluna->Push(sEluna->L, bag); - sEluna->Push(sEluna->L, slot); - sEluna->PlayerEventBindings.ExecuteCall(); - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_EXPIRE); + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); } -InventoryResult HookMgr::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) +// Packet +bool HookMgr::OnPacketSend(WorldSession* session, WorldPacket& packet) { - ELUNA_GUARD(); - InventoryResult result = EQUIP_ERR_OK; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CAN_USE_ITEM)) + bool result = true; + Player* player = NULL; + if (session) + player = session->GetPlayer(); + if (sEluna->ServerEventBindings.HasEvents(SERVER_EVENT_ON_PACKET_SEND)) { - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, itemEntry); - sEluna->PlayerEventBindings.ExecuteCall(); + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_SEND); + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->ServerEventBindings.ExecuteCall(); for (int i = 1; i <= lua_gettop(sEluna->L); ++i) { if (lua_isnoneornil(sEluna->L, i)) continue; - uint32 res = lua_tounsigned(sEluna->L, i); - if (res != EQUIP_ERR_OK) - result = (InventoryResult)res; + if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) + packet = *data; + if (!sEluna->CHECKVAL(sEluna->L, i, true)) + { + result = false; + break; + } } - sEluna->PlayerEventBindings.EndCall(); + sEluna->ServerEventBindings.EndCall(); + } + if (sEluna->PacketEventBindings.HasEvents(Opcodes(packet.GetOpcode()))) + { + ELUNA_GUARD(); + sEluna->PacketEventBindings.BeginCall(Opcodes(packet.GetOpcode())); + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->PacketEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) + packet = *data; + if (!sEluna->CHECKVAL(sEluna->L, i, true)) + { + result = false; + break; + } + } + sEluna->PacketEventBindings.EndCall(); + } + return result; +} +bool HookMgr::OnPacketReceive(WorldSession* session, WorldPacket& packet) +{ + bool result = true; + Player* player = NULL; + if (session) + player = session->GetPlayer(); + if (sEluna->ServerEventBindings.HasEvents(SERVER_EVENT_ON_PACKET_RECEIVE)) + { + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_RECEIVE); + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->ServerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) + packet = *data; + if (!sEluna->CHECKVAL(sEluna->L, i, true)) + { + result = false; + break; + } + } + sEluna->ServerEventBindings.EndCall(); + } + if (sEluna->PacketEventBindings.HasEvents(Opcodes(packet.GetOpcode()))) + { + ELUNA_GUARD(); + sEluna->PacketEventBindings.BeginCall(Opcodes(packet.GetOpcode())); + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->PacketEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) + packet = *data; + if (!sEluna->CHECKVAL(sEluna->L, i, true)) + { + result = false; + break; + } + } + sEluna->PacketEventBindings.EndCall(); } return result; } +#ifndef MANGOS +class ElunaWorldAI : public WorldScript +{ +public: + ElunaWorldAI() : WorldScript("ElunaWorldAI") {} + ~ElunaWorldAI() {} + + void OnOpenStateChange(bool open) override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_OPEN_STATE_CHANGE)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_OPEN_STATE_CHANGE); + sEluna->Push(sEluna->L, open); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnConfigLoad(bool reload) override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_CONFIG_LOAD)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_CONFIG_LOAD); + sEluna->Push(sEluna->L, reload); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnMotdChange(std::string& newMotd) override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_MOTD_CHANGE)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_MOTD_CHANGE); + sEluna->Push(sEluna->L, newMotd); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN_INIT)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_INIT); + sEluna->Push(sEluna->L, code); + sEluna->Push(sEluna->L, mask); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdownCancel() override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN_CANCEL)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_CANCEL); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnUpdate(uint32 diff) override + { + sEluna->m_EventMgr.Update(diff); + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_UPDATE)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE); + sEluna->Push(sEluna->L, diff); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnStartup() override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_STARTUP)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_STARTUP); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdown() override + { + if (!sEluna->ServerEventBindings.HasEvents(WORLD_EVENT_ON_SHUTDOWN)) + return; + ELUNA_GUARD(); + sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } +}; +#endif + void HookMgr::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code) { - ELUNA_GUARD(); int bind = sEluna->ItemGossipBindings.GetBind(item->GetEntry(), GOSSIP_EVENT_ON_SELECT); if (bind) { + ELUNA_GUARD(); pPlayer->PlayerTalkClass->ClearMenus(); sEluna->BeginCall(bind); sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); @@ -208,10 +334,10 @@ void HookMgr::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sende void HookMgr::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code) { - ELUNA_GUARD(); int bind = sEluna->playerGossipBindings.GetBind(menuId, GOSSIP_EVENT_ON_SELECT); if (bind) { + ELUNA_GUARD(); pPlayer->PlayerTalkClass->ClearMenus(); sEluna->BeginCall(bind); sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); @@ -228,22 +354,13 @@ void HookMgr::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 se } } -void HookMgr::OnEngineRestart() -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(ELUNA_EVENT_ON_RESTART)) - return; - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} - // item bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget) { - ELUNA_GUARD(); int bind = sEluna->ItemEventBindings.GetBind(pTarget->GetEntry(), ITEM_EVENT_ON_DUMMY_EFFECT); if (!bind) return false; + ELUNA_GUARD(); sEluna->BeginCall(bind); sEluna->Push(sEluna->L, ITEM_EVENT_ON_DUMMY_EFFECT); sEluna->Push(sEluna->L, pCaster); @@ -256,10 +373,10 @@ bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effInde bool HookMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) { - ELUNA_GUARD(); int bind = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_QUEST_ACCEPT); if (!bind) return false; + ELUNA_GUARD(); sEluna->BeginCall(bind); sEluna->Push(sEluna->L, ITEM_EVENT_ON_QUEST_ACCEPT); sEluna->Push(sEluna->L, pPlayer); @@ -271,11 +388,11 @@ bool HookMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) bool HookMgr::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) { - ELUNA_GUARD(); int bind1 = sEluna->ItemGossipBindings.GetBind(pItem->GetEntry(), GOSSIP_EVENT_ON_HELLO); int bind2 = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_USE); if (!bind1 && !bind2) return false; + ELUNA_GUARD(); if (bind1) { pPlayer->PlayerTalkClass->ClearMenus(); @@ -324,10 +441,10 @@ bool HookMgr::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& target bool HookMgr::OnExpire(Player* pPlayer, ItemTemplate const* pProto) { - ELUNA_GUARD(); int bind = sEluna->ItemEventBindings.GetBind(pProto->ItemId, ITEM_EVENT_ON_EXPIRE); if (!bind) return false; + ELUNA_GUARD(); sEluna->BeginCall(bind); sEluna->Push(sEluna->L, ITEM_EVENT_ON_EXPIRE); sEluna->Push(sEluna->L, pPlayer); @@ -335,343 +452,196 @@ bool HookMgr::OnExpire(Player* pPlayer, ItemTemplate const* pProto) sEluna->ExecuteCall(3, 0); return true; } -// creature -bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pTarget->GetEntry(), CREATURE_EVENT_ON_DUMMY_EFFECT); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DUMMY_EFFECT); - sEluna->Push(sEluna->L, pCaster); - sEluna->Push(sEluna->L, spellId); - sEluna->Push(sEluna->L, effIndex); - sEluna->Push(sEluna->L, pTarget); - sEluna->ExecuteCall(5, 0); - return true; -} -bool HookMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_HELLO); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->ExecuteCall(3, 0); - return true; -} - -bool HookMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->ExecuteCall(5, 0); - return true; -} - -bool HookMgr::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->Push(sEluna->L, code); - sEluna->ExecuteCall(6, 0); - return true; -} - -bool HookMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_ACCEPT); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_ACCEPT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -bool HookMgr::OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_SELECT); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -bool HookMgr::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_COMPLETE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -bool HookMgr::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_REWARD); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_REWARD); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -uint32 HookMgr::GetDialogStatus(Player* pPlayer, Creature* pCreature) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_DIALOG_STATUS); - if (!bind) - return 0; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIALOG_STATUS); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pCreature); - sEluna->ExecuteCall(3, 0); - return DIALOG_STATUS_SCRIPTED_NO_STATUS; -} - -void HookMgr::OnSummoned(Creature* pCreature, Unit* pSummoner) -{ - int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED); - sEluna->Push(sEluna->L, pCreature); - sEluna->Push(sEluna->L, pSummoner); - sEluna->ExecuteCall(3, 0); -} - -// gameobject -bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pTarget->GetEntry(), GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); - sEluna->Push(sEluna->L, pCaster); - sEluna->Push(sEluna->L, spellId); - sEluna->Push(sEluna->L, effIndex); - sEluna->Push(sEluna->L, pTarget); - sEluna->ExecuteCall(5, 0); - return true; -} - -bool HookMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_HELLO); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->ExecuteCall(3, 0); - return true; -} - -bool HookMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->ExecuteCall(5, 0); - return true; -} - -bool HookMgr::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); - if (!bind) - return false; - pPlayer->PlayerTalkClass->ClearMenus(); - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, sender); - sEluna->Push(sEluna->L, action); - sEluna->Push(sEluna->L, code); - sEluna->ExecuteCall(6, 0); - return true; -} - -bool HookMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -bool HookMgr::OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->CreatureEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -bool HookMgr::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_REWARD); - if (!bind) - return false; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_REWARD); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pQuest); - sEluna->ExecuteCall(4, 0); - return true; -} - -uint32 HookMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DIALOG_STATUS); - if (!bind) - return 0; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DIALOG_STATUS); - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pGameObject); - sEluna->ExecuteCall(3, 0); - return DIALOG_STATUS_SCRIPTED_NO_STATUS; // DIALOG_STATUS_UNDEFINED -} - -void HookMgr::OnDestroyed(GameObject* pGameObject, Player* pPlayer) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DESTROYED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DESTROYED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pPlayer); - sEluna->ExecuteCall(3, 0); -} - -void HookMgr::OnDamaged(GameObject* pGameObject, Player* pPlayer) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DAMAGED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DAMAGED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, pPlayer); - sEluna->ExecuteCall(3, 0); -} - -void HookMgr::OnLootStateChanged(GameObject* pGameObject, uint32 state, Unit* pUnit) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, state); - sEluna->Push(sEluna->L, pUnit); - sEluna->ExecuteCall(4, 0); -} - -void HookMgr::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, state); - sEluna->ExecuteCall(3, 0); -} // Player +extern bool StartEluna(); +bool HookMgr::OnCommand(Player* player, const char* text) +{ + std::string fullcmd(text); + char* creload = strtok((char*)text, " "); + char* celuna = strtok(NULL, ""); + if (creload && celuna) + { + std::string reload(creload); + std::string eluna(celuna); + std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower); + if (reload == "reload") + { + std::transform(eluna.begin(), eluna.end(), eluna.begin(), ::tolower); + if (std::string("eluna").find(eluna) == 0) + { + sWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna..."); + StartEluna(); + return false; + } + } + } + bool result = true; + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_COMMAND)) + return result; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_COMMAND); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, fullcmd); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + result = sEluna->CHECKVAL(sEluna->L, i, result); + } + sEluna->PlayerEventBindings.EndCall(); + return result; +} + +void HookMgr::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOOT_ITEM)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_ITEM); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, count); + sEluna->Push(sEluna->L, guid); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnLootMoney(Player* pPlayer, uint32 amount) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOOT_MONEY)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_MONEY); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, amount); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnFirstLogin(Player* pPlayer) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_FIRST_LOGIN)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_FIRST_LOGIN); + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnRepop(Player* pPlayer) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_REPOP)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPOP); + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnResurrect(Player* pPlayer) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_RESURRECT)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_RESURRECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnQuestAbandon(Player* pPlayer, uint32 questId) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_QUEST_ABANDON)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_QUEST_ABANDON); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, questId); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketCreate(Player* pPlayer, std::string& ticketText) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_CREATE)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_CREATE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, ticketText); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketUpdate(Player* pPlayer, std::string& ticketText) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_UPDATE)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_UPDATE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, ticketText); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketDelete(Player* pPlayer) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GM_TICKET_DELETE)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_DELETE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) +{ + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_EQUIP)) + return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EQUIP); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, bag); + sEluna->Push(sEluna->L, slot); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +InventoryResult HookMgr::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) +{ + InventoryResult result = EQUIP_ERR_OK; + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CAN_USE_ITEM)) + { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CAN_USE_ITEM); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, itemEntry); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + uint32 res = lua_tounsigned(sEluna->L, i); + if (res != EQUIP_ERR_OK) + result = (InventoryResult)res; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} void HookMgr::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_ENTER_COMBAT)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_ENTER_COMBAT)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_ENTER_COMBAT); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, pEnemy); sEluna->PlayerEventBindings.ExecuteCall(); @@ -680,9 +650,10 @@ void HookMgr::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) void HookMgr::OnPlayerLeaveCombat(Player* pPlayer) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEAVE_COMBAT)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LEAVE_COMBAT)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEAVE_COMBAT); sEluna->Push(sEluna->L, pPlayer); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -690,9 +661,10 @@ void HookMgr::OnPlayerLeaveCombat(Player* pPlayer) void HookMgr::OnPVPKill(Player* pKiller, Player* pKilled) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_PLAYER)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILL_PLAYER)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_PLAYER); sEluna->Push(sEluna->L, pKiller); sEluna->Push(sEluna->L, pKilled); sEluna->PlayerEventBindings.ExecuteCall(); @@ -701,9 +673,10 @@ void HookMgr::OnPVPKill(Player* pKiller, Player* pKilled) void HookMgr::OnCreatureKill(Player* pKiller, Creature* pKilled) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_CREATURE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILL_CREATURE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_CREATURE); sEluna->Push(sEluna->L, pKiller); sEluna->Push(sEluna->L, pKilled); sEluna->PlayerEventBindings.ExecuteCall(); @@ -712,9 +685,10 @@ void HookMgr::OnCreatureKill(Player* pKiller, Creature* pKilled) void HookMgr::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILLED_BY_CREATURE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_KILLED_BY_CREATURE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILLED_BY_CREATURE); sEluna->Push(sEluna->L, pKiller); sEluna->Push(sEluna->L, pKilled); sEluna->PlayerEventBindings.ExecuteCall(); @@ -723,9 +697,10 @@ void HookMgr::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) void HookMgr::OnLevelChanged(Player* pPlayer, uint8 oldLevel) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEVEL_CHANGE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LEVEL_CHANGE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEVEL_CHANGE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, oldLevel); sEluna->PlayerEventBindings.ExecuteCall(); @@ -734,9 +709,10 @@ void HookMgr::OnLevelChanged(Player* pPlayer, uint8 oldLevel) void HookMgr::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_CHANGE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TALENTS_CHANGE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_CHANGE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, newPoints); sEluna->PlayerEventBindings.ExecuteCall(); @@ -745,9 +721,10 @@ void HookMgr::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) void HookMgr::OnTalentsReset(Player* pPlayer, bool noCost) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_RESET)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TALENTS_RESET)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_RESET); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, noCost); sEluna->PlayerEventBindings.ExecuteCall(); @@ -756,9 +733,10 @@ void HookMgr::OnTalentsReset(Player* pPlayer, bool noCost) void HookMgr::OnMoneyChanged(Player* pPlayer, int32& amount) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MONEY_CHANGE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_MONEY_CHANGE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MONEY_CHANGE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, amount); sEluna->PlayerEventBindings.ExecuteCall(); @@ -767,9 +745,10 @@ void HookMgr::OnMoneyChanged(Player* pPlayer, int32& amount) void HookMgr::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GIVE_XP)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GIVE_XP)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GIVE_XP); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, amount); sEluna->Push(sEluna->L, pVictim); @@ -785,9 +764,10 @@ void HookMgr::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) void HookMgr::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPUTATION_CHANGE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_REPUTATION_CHANGE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPUTATION_CHANGE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, factionID); sEluna->Push(sEluna->L, standing); @@ -804,9 +784,10 @@ void HookMgr::OnReputationChange(Player* pPlayer, uint32 factionID, int32& stand void HookMgr::OnDuelRequest(Player* pTarget, Player* pChallenger) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_REQUEST)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_REQUEST)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_REQUEST); sEluna->Push(sEluna->L, pTarget); sEluna->Push(sEluna->L, pChallenger); sEluna->PlayerEventBindings.ExecuteCall(); @@ -815,9 +796,10 @@ void HookMgr::OnDuelRequest(Player* pTarget, Player* pChallenger) void HookMgr::OnDuelStart(Player* pStarter, Player* pChallenger) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_START)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_START)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_START); sEluna->Push(sEluna->L, pStarter); sEluna->Push(sEluna->L, pChallenger); sEluna->PlayerEventBindings.ExecuteCall(); @@ -826,9 +808,10 @@ void HookMgr::OnDuelStart(Player* pStarter, Player* pChallenger) void HookMgr::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_END)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_DUEL_END)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_END); sEluna->Push(sEluna->L, pWinner); sEluna->Push(sEluna->L, pLoser); sEluna->Push(sEluna->L, type); @@ -838,9 +821,10 @@ void HookMgr::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) void HookMgr::OnEmote(Player* pPlayer, uint32 emote) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EMOTE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_EMOTE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EMOTE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, emote); sEluna->PlayerEventBindings.ExecuteCall(); @@ -849,9 +833,10 @@ void HookMgr::OnEmote(Player* pPlayer, uint32 emote) void HookMgr::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TEXT_EMOTE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_TEXT_EMOTE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TEXT_EMOTE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, textEmote); sEluna->Push(sEluna->L, emoteNum); @@ -862,9 +847,10 @@ void HookMgr::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, ui void HookMgr::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SPELL_CAST)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_SPELL_CAST)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SPELL_CAST); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, pSpell); sEluna->Push(sEluna->L, skipCheck); @@ -874,9 +860,10 @@ void HookMgr::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) void HookMgr::OnLogin(Player* pPlayer) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGIN)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOGIN)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGIN); sEluna->Push(sEluna->L, pPlayer); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -884,9 +871,10 @@ void HookMgr::OnLogin(Player* pPlayer) void HookMgr::OnLogout(Player* pPlayer) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGOUT)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_LOGOUT)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGOUT); sEluna->Push(sEluna->L, pPlayer); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -894,9 +882,10 @@ void HookMgr::OnLogout(Player* pPlayer) void HookMgr::OnCreate(Player* pPlayer) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_CREATE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHARACTER_CREATE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_CREATE); sEluna->Push(sEluna->L, pPlayer); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -904,9 +893,10 @@ void HookMgr::OnCreate(Player* pPlayer) void HookMgr::OnDelete(uint32 guidlow) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_DELETE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHARACTER_DELETE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_DELETE); sEluna->Push(sEluna->L, guidlow); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -914,9 +904,10 @@ void HookMgr::OnDelete(uint32 guidlow) void HookMgr::OnSave(Player* pPlayer) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SAVE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_SAVE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SAVE); sEluna->Push(sEluna->L, pPlayer); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -924,9 +915,10 @@ void HookMgr::OnSave(Player* pPlayer) void HookMgr::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_BIND_TO_INSTANCE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_BIND_TO_INSTANCE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_BIND_TO_INSTANCE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, difficulty); sEluna->Push(sEluna->L, mapid); @@ -937,9 +929,10 @@ void HookMgr::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 ma void HookMgr::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_UPDATE_ZONE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_UPDATE_ZONE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_UPDATE_ZONE); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, newZone); sEluna->Push(sEluna->L, newArea); @@ -949,9 +942,10 @@ void HookMgr::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) void HookMgr::OnMapChanged(Player* player) { - ELUNA_GUARD(); - if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MAP_CHANGE)) + if (!sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_MAP_CHANGE)) return; + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MAP_CHANGE); sEluna->Push(sEluna->L, player); sEluna->PlayerEventBindings.ExecuteCall(); sEluna->PlayerEventBindings.EndCall(); @@ -959,10 +953,11 @@ void HookMgr::OnMapChanged(Player* player) bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) { - ELUNA_GUARD(); bool result = true; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHAT)) + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHAT)) { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHAT); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, msg); sEluna->Push(sEluna->L, type); @@ -987,10 +982,11 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup) { - ELUNA_GUARD(); bool result = true; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GROUP_CHAT)) + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GROUP_CHAT)) { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GROUP_CHAT); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, msg); sEluna->Push(sEluna->L, type); @@ -1016,10 +1012,11 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild) { - ELUNA_GUARD(); bool result = true; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GUILD_CHAT)) + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_GUILD_CHAT)) { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GUILD_CHAT); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, msg); sEluna->Push(sEluna->L, type); @@ -1045,10 +1042,11 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel) { - ELUNA_GUARD(); bool result = true; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHANNEL_CHAT)) + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_CHANNEL_CHAT)) { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHANNEL_CHAT); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, msg); sEluna->Push(sEluna->L, type); @@ -1074,10 +1072,11 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver) { - ELUNA_GUARD(); bool result = true; - if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_WHISPER)) + if (sEluna->PlayerEventBindings.HasEvents(PLAYER_EVENT_ON_WHISPER)) { + ELUNA_GUARD(); + sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_WHISPER); sEluna->Push(sEluna->L, pPlayer); sEluna->Push(sEluna->L, msg); sEluna->Push(sEluna->L, type); @@ -1105,9 +1104,10 @@ bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg // Vehicle void HookMgr::OnInstall(Vehicle* vehicle) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_INSTALL)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL); sEluna->Push(sEluna->L, vehicle); sEluna->VehicleEventBindings.ExecuteCall(); sEluna->VehicleEventBindings.EndCall(); @@ -1115,9 +1115,10 @@ void HookMgr::OnInstall(Vehicle* vehicle) void HookMgr::OnUninstall(Vehicle* vehicle) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_UNINSTALL)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_UNINSTALL)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_UNINSTALL); sEluna->Push(sEluna->L, vehicle); sEluna->VehicleEventBindings.ExecuteCall(); sEluna->VehicleEventBindings.EndCall(); @@ -1125,9 +1126,10 @@ void HookMgr::OnUninstall(Vehicle* vehicle) void HookMgr::OnReset(Vehicle* vehicle) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_RESET)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_RESET)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_RESET); sEluna->Push(sEluna->L, vehicle); sEluna->VehicleEventBindings.ExecuteCall(); sEluna->VehicleEventBindings.EndCall(); @@ -1135,9 +1137,10 @@ void HookMgr::OnReset(Vehicle* vehicle) void HookMgr::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL_ACCESSORY)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_INSTALL_ACCESSORY)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL_ACCESSORY); sEluna->Push(sEluna->L, vehicle); sEluna->Push(sEluna->L, accessory); sEluna->VehicleEventBindings.ExecuteCall(); @@ -1146,9 +1149,10 @@ void HookMgr::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) void HookMgr::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_ADD_PASSENGER)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_ADD_PASSENGER)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_ADD_PASSENGER); sEluna->Push(sEluna->L, vehicle); sEluna->Push(sEluna->L, passenger); sEluna->Push(sEluna->L, seatId); @@ -1158,9 +1162,10 @@ void HookMgr::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) void HookMgr::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) { - ELUNA_GUARD(); - if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_REMOVE_PASSENGER)) + if (!sEluna->VehicleEventBindings.HasEvents(VEHICLE_EVENT_ON_REMOVE_PASSENGER)) return; + ELUNA_GUARD(); + sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_REMOVE_PASSENGER); sEluna->Push(sEluna->L, vehicle); sEluna->Push(sEluna->L, passenger); sEluna->VehicleEventBindings.ExecuteCall(); @@ -1168,757 +1173,12 @@ void HookMgr::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) } #endif -// areatrigger -bool HookMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(TRIGGER_EVENT_ON_TRIGGER)) - return false; - sEluna->Push(sEluna->L, pPlayer); - sEluna->Push(sEluna->L, pTrigger->id); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - return false; -} -// weather -void HookMgr::OnChange(Weather* weather, WeatherState state, float grade) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WEATHER_EVENT_ON_CHANGE)) - return; - sEluna->Push(sEluna->L, (weather->GetZone())); - sEluna->Push(sEluna->L, state); - sEluna->Push(sEluna->L, grade); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} -// transport -void HookMgr::OnAddPassenger(Transport* transport, Player* player) -{ - ELUNA_GUARD(); -} -void HookMgr::OnAddCreaturePassenger(Transport* transport, Creature* creature) -{ - ELUNA_GUARD(); -} -void HookMgr::OnRemovePassenger(Transport* transport, Player* player) -{ - ELUNA_GUARD(); -} -void HookMgr::OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z) -{ - ELUNA_GUARD(); -} -// Auction House -void HookMgr::OnAdd(AuctionHouseObject* ah) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_ADD)) - return; - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} - -void HookMgr::OnRemove(AuctionHouseObject* ah) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_REMOVE)) - return; - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} - -void HookMgr::OnSuccessful(AuctionHouseObject* ah) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_SUCCESSFUL)) - return; - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} - -void HookMgr::OnExpire(AuctionHouseObject* ah) -{ - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_EXPIRE)) - return; - sEluna->Push(sEluna->L, (ah)); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); -} - -// Packet -bool HookMgr::OnPacketSend(WorldSession* session, WorldPacket& packet) -{ - ELUNA_GUARD(); - bool result = true; - Player* player = NULL; - if (session) - player = session->GetPlayer(); - if (sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_SEND)) - { - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->ServerEventBindings.EndCall(); - } - if (sEluna->PacketEventBindings.BeginCall(packet.GetOpcode())) - { - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->PacketEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->PacketEventBindings.EndCall(); - } - return result; -} -bool HookMgr::OnPacketReceive(WorldSession* session, WorldPacket& packet) -{ - ELUNA_GUARD(); - bool result = true; - Player* player = NULL; - if (session) - player = session->GetPlayer(); - if (sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_RECEIVE)) - { - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->ServerEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->ServerEventBindings.EndCall(); - } - if (sEluna->PacketEventBindings.BeginCall(packet.GetOpcode())) - { - sEluna->Push(sEluna->L, new WorldPacket(packet)); - sEluna->Push(sEluna->L, player); - sEluna->PacketEventBindings.ExecuteCall(); - for (int i = 1; i <= lua_gettop(sEluna->L); ++i) - { - if (lua_isnoneornil(sEluna->L, i)) - continue; - if (WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false)) - packet = *data; - if (!sEluna->CHECKVAL(sEluna->L, i, true)) - { - result = false; - break; - } - } - sEluna->PacketEventBindings.EndCall(); - } - return result; -} - -#ifndef MANGOS -class ElunaWorldAI : public WorldScript -{ -public: - ElunaWorldAI() : WorldScript("ElunaWorldAI") { } - ~ElunaWorldAI() { } - - void OnOpenStateChange(bool open) OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_OPEN_STATE_CHANGE)) - return; - sEluna->Push(sEluna->L, open); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnConfigLoad(bool reload) OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_CONFIG_LOAD)) - return; - sEluna->Push(sEluna->L, reload); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnMotdChange(std::string& newMotd) OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_MOTD_CHANGE)) - return; - sEluna->Push(sEluna->L, newMotd); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_INIT)) - return; - sEluna->Push(sEluna->L, code); - sEluna->Push(sEluna->L, mask); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdownCancel() OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_CANCEL)) - return; - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnUpdate(uint32 diff) OVERRIDE - { - ELUNA_GUARD(); - sEluna->m_EventMgr.Update(diff); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE)) - return; - sEluna->Push(sEluna->L, diff); - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnStartup() OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_STARTUP)) - return; - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } - - void OnShutdown() OVERRIDE - { - ELUNA_GUARD(); - if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN)) - return; - sEluna->ServerEventBindings.ExecuteCall(); - sEluna->ServerEventBindings.EndCall(); - } -}; -#endif - -struct ElunaCreatureAI : ScriptedAI -{ - ElunaCreatureAI(Creature* creature) : ScriptedAI(creature) { } - ~ElunaCreatureAI() { } - -#ifdef MANGOS -#define me m_creature -#endif - - //Called at World update tick -#ifdef MANGOS - void UpdateAI( const uint32 diff) OVERRIDE -#else - void UpdateAI(uint32 diff) OVERRIDE -#endif - { - ELUNA_GUARD(); - ScriptedAI::UpdateAI(diff); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_AIUPDATE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, diff); - sEluna->ExecuteCall(3, 0); - } - - //Called for reaction at enter to combat if not in combat yet (enemy can be NULL) - //Called at creature aggro either by MoveInLOS or Attack Start - void EnterCombat(Unit* target) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::EnterCombat(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ENTER_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); - } - - // Called at any Damage from any attacker (before damage apply) - void DamageTaken(Unit* attacker, uint32& damage) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::DamageTaken(attacker, damage); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DAMAGE_TAKEN); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->Push(sEluna->L, damage); - sEluna->ExecuteCall(4, 0); - } - - //Called at creature death - void JustDied(Unit* killer) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::JustDied(killer); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DIED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, killer); - sEluna->ExecuteCall(3, 0); - } - - //Called at creature killing another unit - void KilledUnit(Unit* victim) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::KilledUnit(victim); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_TARGET_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, victim); - sEluna->ExecuteCall(3, 0); - } - - // Called when the creature summon successfully other creature - void JustSummoned(Creature* summon) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::JustSummoned(summon); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->ExecuteCall(3, 0); - } - - // Called when a summoned creature is despawned - void SummonedCreatureDespawn(Creature* summon) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::SummonedCreatureDespawn(summon); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->ExecuteCall(3, 0); - } - - //Called at waypoint reached or PointMovement end - void MovementInform(uint32 type, uint32 id) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::MovementInform(type, id); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_WP); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_WP); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, type); - sEluna->Push(sEluna->L, id); - sEluna->ExecuteCall(4, 0); - } - - // Called before EnterCombat even before the creature is in combat. - void AttackStart(Unit* target) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::AttackStart(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PRE_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); - } - - // Called for reaction at stopping attack at no attackers or targets - void EnterEvadeMode() OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::EnterEvadeMode(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_LEAVE_COMBAT); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); - } - - // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) - void AttackedBy(Unit* attacker) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::AttackedBy(attacker); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ATTACKED_AT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->ExecuteCall(3, 0); - } - - // Called when creature is spawned or respawned (for reseting variables) - void JustRespawned() OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::JustRespawned(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPAWN); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPAWN); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); - } - - // Called at reaching home after evade - void JustReachedHome() OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::JustReachedHome(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_HOME); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); - } - - // Called at text emote receive from player - void ReceiveEmote(Player* player, uint32 emoteId) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::ReceiveEmote(player, emoteId); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RECEIVE_EMOTE); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, player); - sEluna->Push(sEluna->L, emoteId); - sEluna->ExecuteCall(4, 0); - } - - // called when the corpse of this creature gets removed - void CorpseRemoved(uint32& respawnDelay) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::CorpseRemoved(respawnDelay); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CORPSE_REMOVED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, respawnDelay); - sEluna->ExecuteCall(3, 0); - } - - void MoveInLineOfSight(Unit* who) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::MoveInLineOfSight(who); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_MOVE_IN_LOS); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, who); - sEluna->ExecuteCall(3, 0); - } - -#ifndef MANGOS - // Called when hit by a spell - void SpellHit(Unit* caster, SpellInfo const* spell) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::SpellHit(caster, spell); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_HIT_BY_SPELL); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, caster); - sEluna->Push(sEluna->L, spell->Id); // Pass spell object? - sEluna->ExecuteCall(4, 0); - } - - // Called when spell hits a target - void SpellHitTarget(Unit* target, SpellInfo const* spell) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::SpellHitTarget(target, spell); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_HIT_TARGET); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->Push(sEluna->L, spell->Id); // Pass spell object? - sEluna->ExecuteCall(4, 0); - } - - // Called when AI is temporarily replaced or put back when possess is applied or removed - void OnPossess(bool apply) - { - ELUNA_GUARD(); - ScriptedAI::OnPossess(apply); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_POSSESS); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_POSSESS); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, apply); - sEluna->ExecuteCall(3, 0); - } - - //Called at creature reset either by death or evade - void Reset() OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::Reset(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RESET); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RESET); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); - } - - // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events. - bool CanRespawn() OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::CanRespawn(); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CAN_RESPAWN); - if (!bind) - return true; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CAN_RESPAWN); - sEluna->Push(sEluna->L, me); - sEluna->ExecuteCall(2, 0); - return true; - } - - // Called when the creature is summoned successfully by other creature - void IsSummonedBy(Unit* summoner) OVERRIDE - { - ScriptedAI::IsSummonedBy(summoner); - sHookMgr->OnSummoned(me, summoner); - } - - void SummonedCreatureDies(Creature* summon, Unit* killer) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::SummonedCreatureDies(summon, killer); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, summon); - sEluna->Push(sEluna->L, killer); - sEluna->ExecuteCall(4, 0); - } - - void OnCharmed(bool apply) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::OnCharmed(apply); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CHARMED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CHARMED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, apply); - sEluna->ExecuteCall(3, 0); - } - - // Called when owner takes damage - void OwnerAttackedBy(Unit* attacker) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::OwnerAttackedBy(attacker); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED_AT); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, attacker); - sEluna->ExecuteCall(3, 0); - } - - // Called when owner attacks something - void OwnerAttacked(Unit* target) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::OwnerAttacked(target); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, target); - sEluna->ExecuteCall(3, 0); - } - - void PassengerBoarded(Unit* passenger, int8 seatId, bool apply) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::PassengerBoarded(passenger, seatId, apply); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PASSANGER_BOARDED); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PASSANGER_BOARDED); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, passenger); - sEluna->Push(sEluna->L, seatId); - sEluna->Push(sEluna->L, apply); - sEluna->ExecuteCall(5, 0); - } - - void OnSpellClick(Unit* clicker, bool& result) OVERRIDE - { - ELUNA_GUARD(); - ScriptedAI::OnSpellClick(clicker, result); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_CLICK); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_CLICK); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, clicker); - sEluna->Push(sEluna->L, result); - sEluna->ExecuteCall(4, 0); - } - - // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter - void MoveInLineOfSight_Safe(Unit* who) - { - ELUNA_GUARD(); - ScriptedAI::MoveInLineOfSight_Safe(who); - int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); - sEluna->Push(sEluna->L, me); - sEluna->Push(sEluna->L, who); - sEluna->ExecuteCall(3, 0); - } -#endif - -#ifdef MANGOS -#undef me -#endif -}; - -void HookMgr::UpdateAI(GameObject* pGameObject, uint32 diff) -{ - ELUNA_GUARD(); - int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_AIUPDATE); - if (!bind) - return; - sEluna->BeginCall(bind); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_AIUPDATE); - sEluna->Push(sEluna->L, pGameObject); - sEluna->Push(sEluna->L, diff); - sEluna->ExecuteCall(3, 0); -} - -#ifndef MANGOS -struct ElunaGameObjectAI : public GameObjectAI -{ - ElunaGameObjectAI(GameObject* _go) : GameObjectAI(_go) { } - ~ElunaGameObjectAI() - { - } - - void Reset() OVERRIDE - { - ELUNA_GUARD(); - sEluna->BeginCall(sEluna->GameObjectEventBindings.GetBind(go->GetEntry(), GAMEOBJECT_EVENT_ON_RESET)); - sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_RESET); - sEluna->Push(sEluna->L, go); - sEluna->ExecuteCall(2, 0); - } -}; -#endif - void HookMgr::OnAddMember(Guild* guild, Player* player, uint32 plRank) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ADD_MEMBER)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_ADD_MEMBER)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ADD_MEMBER); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, player); sEluna->Push(sEluna->L, plRank); @@ -1928,9 +1188,10 @@ void HookMgr::OnAddMember(Guild* guild, Player* player, uint32 plRank) void HookMgr::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_REMOVE_MEMBER)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_REMOVE_MEMBER)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_REMOVE_MEMBER); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, player); sEluna->Push(sEluna->L, isDisbanding); @@ -1940,9 +1201,10 @@ void HookMgr::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) void HookMgr::OnMOTDChanged(Guild* guild, const std::string& newMotd) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MOTD_CHANGE)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MOTD_CHANGE)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MOTD_CHANGE); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, newMotd); sEluna->GuildEventBindings.ExecuteCall(); @@ -1951,9 +1213,10 @@ void HookMgr::OnMOTDChanged(Guild* guild, const std::string& newMotd) void HookMgr::OnInfoChanged(Guild* guild, const std::string& newInfo) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_INFO_CHANGE)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_INFO_CHANGE)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_INFO_CHANGE); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, newInfo); sEluna->GuildEventBindings.ExecuteCall(); @@ -1962,9 +1225,10 @@ void HookMgr::OnInfoChanged(Guild* guild, const std::string& newInfo) void HookMgr::OnCreate(Guild* guild, Player* leader, const std::string& name) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_CREATE)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_CREATE)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_CREATE); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, leader); sEluna->Push(sEluna->L, name); @@ -1974,9 +1238,10 @@ void HookMgr::OnCreate(Guild* guild, Player* leader, const std::string& name) void HookMgr::OnDisband(Guild* guild) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_DISBAND)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_DISBAND)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_DISBAND); sEluna->Push(sEluna->L, guild); sEluna->GuildEventBindings.ExecuteCall(); sEluna->GuildEventBindings.EndCall(); @@ -1984,9 +1249,10 @@ void HookMgr::OnDisband(Guild* guild) void HookMgr::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair) // isRepair not a part of Mangos, implement? { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_WITHDRAW)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MONEY_WITHDRAW)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_WITHDRAW); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, player); sEluna->Push(sEluna->L, amount); @@ -1997,9 +1263,10 @@ void HookMgr::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, void HookMgr::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_DEPOSIT)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_MONEY_DEPOSIT)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_DEPOSIT); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, player); sEluna->Push(sEluna->L, amount); @@ -2010,9 +1277,10 @@ void HookMgr::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) void HookMgr::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ITEM_MOVE)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_ITEM_MOVE)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ITEM_MOVE); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, player); sEluna->Push(sEluna->L, pItem); @@ -2028,9 +1296,10 @@ void HookMgr::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBa void HookMgr::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_EVENT)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_EVENT)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_EVENT); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, eventType); sEluna->Push(sEluna->L, playerGuid1); @@ -2042,9 +1311,10 @@ void HookMgr::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 void HookMgr::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) { - ELUNA_GUARD(); - if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_BANK_EVENT)) + if (!sEluna->GuildEventBindings.HasEvents(GUILD_EVENT_ON_BANK_EVENT)) return; + ELUNA_GUARD(); + sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_BANK_EVENT); sEluna->Push(sEluna->L, guild); sEluna->Push(sEluna->L, eventType); sEluna->Push(sEluna->L, tabId); @@ -2058,9 +1328,10 @@ void HookMgr::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 pla // Group void HookMgr::OnAddMember(Group* group, uint64 guid) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_ADD)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_ADD)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_ADD); sEluna->Push(sEluna->L, group); sEluna->Push(sEluna->L, guid); sEluna->GroupEventBindings.ExecuteCall(); @@ -2069,9 +1340,10 @@ void HookMgr::OnAddMember(Group* group, uint64 guid) void HookMgr::OnInviteMember(Group* group, uint64 guid) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_INVITE)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_INVITE)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_INVITE); sEluna->Push(sEluna->L, group); sEluna->Push(sEluna->L, guid); sEluna->GroupEventBindings.ExecuteCall(); @@ -2080,9 +1352,10 @@ void HookMgr::OnInviteMember(Group* group, uint64 guid) void HookMgr::OnRemoveMember(Group* group, uint64 guid, uint8 method) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_REMOVE)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_MEMBER_REMOVE)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_REMOVE); sEluna->Push(sEluna->L, group); sEluna->Push(sEluna->L, guid); sEluna->Push(sEluna->L, method); @@ -2092,9 +1365,10 @@ void HookMgr::OnRemoveMember(Group* group, uint64 guid, uint8 method) void HookMgr::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_LEADER_CHANGE)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_LEADER_CHANGE)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_LEADER_CHANGE); sEluna->Push(sEluna->L, group); sEluna->Push(sEluna->L, newLeaderGuid); sEluna->Push(sEluna->L, oldLeaderGuid); @@ -2104,9 +1378,10 @@ void HookMgr::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeade void HookMgr::OnDisband(Group* group) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_DISBAND)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_DISBAND)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_DISBAND); sEluna->Push(sEluna->L, group); sEluna->GroupEventBindings.ExecuteCall(); sEluna->GroupEventBindings.EndCall(); @@ -2114,9 +1389,10 @@ void HookMgr::OnDisband(Group* group) void HookMgr::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType) { - ELUNA_GUARD(); - if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_CREATE)) + if (!sEluna->GroupEventBindings.HasEvents(GROUP_EVENT_ON_CREATE)) return; + ELUNA_GUARD(); + sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_CREATE); sEluna->Push(sEluna->L, group); sEluna->Push(sEluna->L, leaderGuid); sEluna->Push(sEluna->L, groupType); @@ -2124,6 +1400,822 @@ void HookMgr::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType) sEluna->GroupEventBindings.EndCall(); } +// creature +bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pTarget->GetEntry(), CREATURE_EVENT_ON_DUMMY_EFFECT); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DUMMY_EFFECT); + sEluna->Push(sEluna->L, pCaster); + sEluna->Push(sEluna->L, spellId); + sEluna->Push(sEluna->L, effIndex); + sEluna->Push(sEluna->L, pTarget); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) +{ + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_HELLO); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->ExecuteCall(3, 0); + return true; +} + +bool HookMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) +{ + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) +{ + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->Push(sEluna->L, code); + sEluna->ExecuteCall(6, 0); + return true; +} + +bool HookMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_ACCEPT); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_ACCEPT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_SELECT); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_COMPLETE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_REWARD); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_REWARD); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +uint32 HookMgr::GetDialogStatus(Player* pPlayer, Creature* pCreature) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_DIALOG_STATUS); + if (!bind) + return 0; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIALOG_STATUS); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->ExecuteCall(3, 0); + return DIALOG_STATUS_SCRIPTED_NO_STATUS; +} + +void HookMgr::OnSummoned(Creature* pCreature, Unit* pSummoner) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pSummoner); + sEluna->ExecuteCall(3, 0); +} + +struct ElunaCreatureAI : ScriptedAI +{ + ElunaCreatureAI(Creature* creature) : ScriptedAI(creature) {} + ~ElunaCreatureAI() {} + +#ifdef MANGOS +#define me m_creature +#endif + + //Called at World update tick +#ifdef MANGOS + void UpdateAI(const uint32 diff) override +#else + void UpdateAI(uint32 diff) override +#endif + { + ScriptedAI::UpdateAI(diff); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_AIUPDATE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, diff); + sEluna->ExecuteCall(3, 0); + } + + //Called for reaction at enter to combat if not in combat yet (enemy can be NULL) + //Called at creature aggro either by MoveInLOS or Attack Start + void EnterCombat(Unit* target) override + { + ScriptedAI::EnterCombat(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ENTER_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + // Called at any Damage from any attacker (before damage apply) + void DamageTaken(Unit* attacker, uint32& damage) override + { + ScriptedAI::DamageTaken(attacker, damage); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DAMAGE_TAKEN); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->Push(sEluna->L, damage); + sEluna->ExecuteCall(4, 0); + } + + //Called at creature death + void JustDied(Unit* killer) override + { + ScriptedAI::JustDied(killer); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DIED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, killer); + sEluna->ExecuteCall(3, 0); + } + + //Called at creature killing another unit + void KilledUnit(Unit* victim) override + { + ScriptedAI::KilledUnit(victim); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_TARGET_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, victim); + sEluna->ExecuteCall(3, 0); + } + + // Called when the creature summon successfully other creature + void JustSummoned(Creature* summon) override + { + ScriptedAI::JustSummoned(summon); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->ExecuteCall(3, 0); + } + + // Called when a summoned creature is despawned + void SummonedCreatureDespawn(Creature* summon) override + { + ScriptedAI::SummonedCreatureDespawn(summon); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->ExecuteCall(3, 0); + } + + //Called at waypoint reached or PointMovement end + void MovementInform(uint32 type, uint32 id) override + { + ScriptedAI::MovementInform(type, id); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_WP); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_WP); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, id); + sEluna->ExecuteCall(4, 0); + } + + // Called before EnterCombat even before the creature is in combat. + void AttackStart(Unit* target) override + { + ScriptedAI::AttackStart(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PRE_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + // Called for reaction at stopping attack at no attackers or targets + void EnterEvadeMode() override + { + ScriptedAI::EnterEvadeMode(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_LEAVE_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) + void AttackedBy(Unit* attacker) override + { + ScriptedAI::AttackedBy(attacker); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ATTACKED_AT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->ExecuteCall(3, 0); + } + + // Called when creature is spawned or respawned (for reseting variables) + void JustRespawned() override + { + ScriptedAI::JustRespawned(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPAWN); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPAWN); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called at reaching home after evade + void JustReachedHome() override + { + ScriptedAI::JustReachedHome(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_HOME); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called at text emote receive from player + void ReceiveEmote(Player* player, uint32 emoteId) override + { + ScriptedAI::ReceiveEmote(player, emoteId); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RECEIVE_EMOTE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, emoteId); + sEluna->ExecuteCall(4, 0); + } + + // called when the corpse of this creature gets removed + void CorpseRemoved(uint32& respawnDelay) override + { + ScriptedAI::CorpseRemoved(respawnDelay); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CORPSE_REMOVED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, respawnDelay); + sEluna->ExecuteCall(3, 0); + } + + void MoveInLineOfSight(Unit* who) override + { + ScriptedAI::MoveInLineOfSight(who); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_MOVE_IN_LOS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, who); + sEluna->ExecuteCall(3, 0); + } + +#ifndef MANGOS + // Called when hit by a spell + void SpellHit(Unit* caster, SpellInfo const* spell) override + { + ScriptedAI::SpellHit(caster, spell); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_HIT_BY_SPELL); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, caster); + sEluna->Push(sEluna->L, spell->Id); // Pass spell object? + sEluna->ExecuteCall(4, 0); + } + + // Called when spell hits a target + void SpellHitTarget(Unit* target, SpellInfo const* spell) override + { + ScriptedAI::SpellHitTarget(target, spell); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_HIT_TARGET); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->Push(sEluna->L, spell->Id); // Pass spell object? + sEluna->ExecuteCall(4, 0); + } + + // Called when AI is temporarily replaced or put back when possess is applied or removed + void OnPossess(bool apply) + { + ScriptedAI::OnPossess(apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_POSSESS); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_POSSESS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(3, 0); + } + + //Called at creature reset either by death or evade + void Reset() override + { + ELUNA_GUARD(); + ScriptedAI::Reset(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RESET); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RESET); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events. + bool CanRespawn() override + { + ScriptedAI::CanRespawn(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CAN_RESPAWN); + if (!bind) + return true; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CAN_RESPAWN); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + return true; + } + + // Called when the creature is summoned successfully by other creature + void IsSummonedBy(Unit* summoner) override + { + ScriptedAI::IsSummonedBy(summoner); + sHookMgr->OnSummoned(me, summoner); + } + + void SummonedCreatureDies(Creature* summon, Unit* killer) override + { + ScriptedAI::SummonedCreatureDies(summon, killer); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->Push(sEluna->L, killer); + sEluna->ExecuteCall(4, 0); + } + + void OnCharmed(bool apply) override + { + ScriptedAI::OnCharmed(apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CHARMED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CHARMED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(3, 0); + } + + // Called when owner takes damage + void OwnerAttackedBy(Unit* attacker) override + { + ScriptedAI::OwnerAttackedBy(attacker); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED_AT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->ExecuteCall(3, 0); + } + + // Called when owner attacks something + void OwnerAttacked(Unit* target) override + { + ScriptedAI::OwnerAttacked(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + void PassengerBoarded(Unit* passenger, int8 seatId, bool apply) override + { + ScriptedAI::PassengerBoarded(passenger, seatId, apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PASSANGER_BOARDED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PASSANGER_BOARDED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, passenger); + sEluna->Push(sEluna->L, seatId); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(5, 0); + } + + void OnSpellClick(Unit* clicker, bool& result) override + { + ScriptedAI::OnSpellClick(clicker, result); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_CLICK); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_CLICK); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, clicker); + sEluna->Push(sEluna->L, result); + sEluna->ExecuteCall(4, 0); + } + + // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter + void MoveInLineOfSight_Safe(Unit* who) + { + ScriptedAI::MoveInLineOfSight_Safe(who); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, who); + sEluna->ExecuteCall(3, 0); + } +#endif + +#ifdef MANGOS +#undef me +#endif +}; + +// gameobject +bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pTarget->GetEntry(), GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); + sEluna->Push(sEluna->L, pCaster); + sEluna->Push(sEluna->L, spellId); + sEluna->Push(sEluna->L, effIndex); + sEluna->Push(sEluna->L, pTarget); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) +{ + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_HELLO); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->ExecuteCall(3, 0); + return true; +} + +bool HookMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) +{ + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) +{ + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + ELUNA_GUARD(); + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->Push(sEluna->L, code); + sEluna->ExecuteCall(6, 0); + return true; +} + +bool HookMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +void HookMgr::UpdateAI(GameObject* pGameObject, uint32 diff) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_AIUPDATE); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_AIUPDATE); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, diff); + sEluna->ExecuteCall(3, 0); +} + +#ifndef MANGOS +struct ElunaGameObjectAI : public GameObjectAI +{ + ElunaGameObjectAI(GameObject* _go) : GameObjectAI(_go) {} + ~ElunaGameObjectAI() + { + } + + void Reset() override + { + int bind = sEluna->GameObjectEventBindings.GetBind(go->GetEntry(), GAMEOBJECT_EVENT_ON_RESET); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_RESET); + sEluna->Push(sEluna->L, go); + sEluna->ExecuteCall(2, 0); + } +}; +#endif + +bool HookMgr::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_REWARD); + if (!bind) + return false; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_REWARD); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +uint32 HookMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DIALOG_STATUS); + if (!bind) + return 0; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DIALOG_STATUS); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->ExecuteCall(3, 0); + return DIALOG_STATUS_SCRIPTED_NO_STATUS; // DIALOG_STATUS_UNDEFINED +} + +void HookMgr::OnDestroyed(GameObject* pGameObject, Player* pPlayer) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DESTROYED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DESTROYED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pPlayer); + sEluna->ExecuteCall(3, 0); +} + +void HookMgr::OnDamaged(GameObject* pGameObject, Player* pPlayer) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DAMAGED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DAMAGED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pPlayer); + sEluna->ExecuteCall(3, 0); +} + +void HookMgr::OnLootStateChanged(GameObject* pGameObject, uint32 state, Unit* pUnit) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, state); + sEluna->Push(sEluna->L, pUnit); + sEluna->ExecuteCall(4, 0); +} + +void HookMgr::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) +{ + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); + if (!bind) + return; + ELUNA_GUARD(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, state); + sEluna->ExecuteCall(3, 0); +} + CreatureAI* HookMgr::GetAI(Creature* creature) { if (!sEluna->CreatureEventBindings.GetBindMap(creature->GetEntry())) diff --git a/HookMgr.h b/HookMgr.h index 99be767..e207f74 100644 --- a/HookMgr.h +++ b/HookMgr.h @@ -456,7 +456,7 @@ public: #ifdef MANGOS #define sHookMgr (&MaNGOS::Singleton::Instance()) #else -#define sHookMgr ACE_Singleton::instance() +#define sHookMgr ACE_Singleton::instance() #endif #endif diff --git a/LuaEngine.cpp b/LuaEngine.cpp index f1a906a..0da95a4 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -750,15 +750,19 @@ void Eluna::EventBind::Insert(int eventId, int funcRef) Bindings[eventId].push_back(funcRef); } -bool Eluna::EventBind::BeginCall(int eventId) const +bool Eluna::EventBind::HasEvents(int eventId) const { if (Bindings.empty()) return false; if (Bindings.find(eventId) == Bindings.end()) return false; + return true; +} + +void Eluna::EventBind::BeginCall(int eventId) const +{ lua_settop(sEluna->L, 0); // stack should be empty sEluna->Push(sEluna->L, eventId); - return true; } void Eluna::EventBind::ExecuteCall() diff --git a/LuaEngine.h b/LuaEngine.h index 2aa3c01..24b7937 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -65,9 +65,6 @@ extern "C" typedef std::set LoadedScripts; -#define ELUNA_GUARD() { } - // ACE_Guard< ACE_Thread_Mutex > ELUNA_GUARD_OBJECT (sEluna->lock); - #ifdef MANGOS #undef sWorld #undef sMapMgr @@ -451,11 +448,11 @@ class Eluna { public: friend class ScriptMgr; - friend class ACE_Singleton; + friend class ACE_Singleton; lua_State* L; EventMgr m_EventMgr; - // ACE_Thread_Mutex lock; + ACE_Recursive_Thread_Mutex lock; Eluna() { @@ -491,8 +488,10 @@ public: return &itr->second; } - // Checks if there are events for ID, if so, cleans stack and pushes eventId - bool BeginCall(int eventId) const; + // Checks if there are events for ID + bool HasEvents(int eventId) const; + // Cleans stack and pushes eventId + void BeginCall(int eventId) const; // Loops through all registered events for the eventId at stack index 1 // Copies the whole stack as arguments for the called function. Before Executing, push all params to stack! // Leaves return values from all functions in order to the stack. @@ -687,9 +686,50 @@ template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); #ifdef MANGOS #define sEluna (&MaNGOS::Singleton::Instance()) #else -#define sEluna ACE_Singleton::instance() +#define sEluna ACE_Singleton::instance() #endif +/* +class FakeLock +{ +public: +static bool locked; +FakeLock() +{ +if (locked) +printf("ELUNA_GUARD CREATE\n"); +locked = true; +} +~FakeLock() +{ +if (!locked) +printf("ELUNA_GUARD DELETE\n"); +locked = false; +} +}; +class FakeRecursiveLock +{ +public: +static uint32 locked; +FakeRecursiveLock() +{ +++locked; +if (locked > 1) +printf("GUARD LOCK %u\n", locked); +} +~FakeRecursiveLock() +{ +if (!locked) +printf("GUARD FAULTY\n"); +else if (locked > 1) +printf("GUARD RELE %u\n", locked); +--locked; +} +}; +*/ +#define ELUNA_GUARD() \ + ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); + class LuaTaxiMgr { private: