From f76146dbe986e6f7abf689f5ab01eb6afa23dfcd Mon Sep 17 00:00:00 2001 From: Foereaper Date: Tue, 23 Jul 2024 19:14:28 +0200 Subject: [PATCH] Removal of Mangos wrappers Unfortunately mangos will not support multistate until larger fundamental changes are done to the emulator. Mangos will continue to use an old submodule for now. --- ElunaConfig.cpp | 4 +- ElunaCreatureAI.h | 9 +- ElunaIncludes.h | 82 +- ElunaUtility.cpp | 21 +- ElunaUtility.h | 2 +- LuaEngine.h | 9 - LuaValue.h | 5 + hooks/GossipHooks.cpp | 23 +- hooks/GuildHooks.cpp | 57 - hooks/PacketHooks.cpp | 12 +- hooks/PlayerHooks.cpp | 27 - lmarshal.h | 5 + methods/Mangos/AuraMethods.h | 206 -- methods/Mangos/BattleGroundMethods.h | 251 -- methods/Mangos/CorpseMethods.h | 91 - methods/Mangos/CreatureMethods.h | 1214 -------- methods/Mangos/ElunaQueryMethods.h | 345 --- methods/Mangos/GameObjectMethods.h | 345 --- methods/Mangos/GlobalMethods.h | 3047 -------------------- methods/Mangos/GroupMethods.h | 420 --- methods/Mangos/GuildMethods.h | 267 -- methods/Mangos/ItemMethods.h | 875 ------ methods/Mangos/MapMethods.h | 372 --- methods/Mangos/ObjectMethods.h | 498 ---- methods/Mangos/PlayerMethods.h | 3984 -------------------------- methods/Mangos/QuestMethods.h | 201 -- methods/Mangos/SpellMethods.h | 196 -- methods/Mangos/UnitMethods.h | 2624 ----------------- methods/Mangos/VehicleMethods.h | 116 - methods/Mangos/WorldObjectMethods.h | 1191 -------- methods/Mangos/WorldPacketMethods.h | 347 --- 31 files changed, 62 insertions(+), 16784 deletions(-) delete mode 100644 methods/Mangos/AuraMethods.h delete mode 100644 methods/Mangos/BattleGroundMethods.h delete mode 100644 methods/Mangos/CorpseMethods.h delete mode 100644 methods/Mangos/CreatureMethods.h delete mode 100644 methods/Mangos/ElunaQueryMethods.h delete mode 100644 methods/Mangos/GameObjectMethods.h delete mode 100644 methods/Mangos/GlobalMethods.h delete mode 100644 methods/Mangos/GroupMethods.h delete mode 100644 methods/Mangos/GuildMethods.h delete mode 100644 methods/Mangos/ItemMethods.h delete mode 100644 methods/Mangos/MapMethods.h delete mode 100644 methods/Mangos/ObjectMethods.h delete mode 100644 methods/Mangos/PlayerMethods.h delete mode 100644 methods/Mangos/QuestMethods.h delete mode 100644 methods/Mangos/SpellMethods.h delete mode 100644 methods/Mangos/UnitMethods.h delete mode 100644 methods/Mangos/VehicleMethods.h delete mode 100644 methods/Mangos/WorldObjectMethods.h delete mode 100644 methods/Mangos/WorldPacketMethods.h diff --git a/ElunaConfig.cpp b/ElunaConfig.cpp index e5657bdc0a..7fad4f2185 100644 --- a/ElunaConfig.cpp +++ b/ElunaConfig.cpp @@ -4,9 +4,9 @@ * Please see the included DOCS/LICENSE.md for more information */ -#if defined TRINITY || defined MANGOS +#if defined TRINITY #include "Config.h" -#elif defined CMANGOS || defined VMANGOS +#else #include "Config/Config.h" #endif #include "ElunaConfig.h" diff --git a/ElunaCreatureAI.h b/ElunaCreatureAI.h index a1623b5c2b..2b593a0acc 100644 --- a/ElunaCreatureAI.h +++ b/ElunaCreatureAI.h @@ -21,9 +21,6 @@ typedef CreatureAI NativeScriptedAI; #elif defined VMANGOS class BasicAI; typedef BasicAI NativeScriptedAI; -#else -class AggressorAI; -typedef AggressorAI NativeScriptedAI; #endif struct ElunaCreatureAI : NativeScriptedAI @@ -67,11 +64,7 @@ struct ElunaCreatureAI : NativeScriptedAI if (!me->GetEluna()->UpdateAI(me, diff)) { -#if defined MANGOS - if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)) -#else if (!me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_NPC)) -#endif NativeScriptedAI::UpdateAI(diff); } } @@ -202,7 +195,7 @@ struct ElunaCreatureAI : NativeScriptedAI NativeScriptedAI::CorpseRemoved(respawnDelay); } -#if !defined TRINITY && !defined VMANGOS +#if defined CMANGOS // Enables use of MoveInLineOfSight bool IsVisible(Unit* who) const override { diff --git a/ElunaIncludes.h b/ElunaIncludes.h index 00535c0045..e7549d80cb 100644 --- a/ElunaIncludes.h +++ b/ElunaIncludes.h @@ -11,6 +11,7 @@ #if !defined CMANGOS #include "AccountMgr.h" #include "AuctionHouseMgr.h" +#include "Bag.h" #include "Cell.h" #include "CellImpl.h" #include "Channel.h" @@ -39,7 +40,24 @@ #include "TemporarySummon.h" #include "WorldPacket.h" #include "WorldSession.h" +#if defined TRINITY +#include "Battleground.h" +#include "Config.h" +#include "DatabaseEnv.h" +#include "GitRevision.h" +#include "GroupMgr.h" +#include "MiscPackets.h" +#include "MotionMaster.h" +#include "ScriptedCreature.h" +#include "SpellHistory.h" +#include "SpellInfo.h" +#include "WeatherMgr.h" +#elif defined VMANGOS +#include "BasicAI.h" +#include "SQLStorages.h" +#endif #else +#include "AI/BaseAI/UnitAI.h" #include "Accounts/AccountMgr.h" #include "AuctionHouse/AuctionHouseMgr.h" #include "Chat/Channel.h" @@ -64,6 +82,7 @@ #include "Reputation/ReputationMgr.h" #include "Server/DBCStores.h" #include "Server/Opcodes.h" +#include "Server/SQLStorages.h" #include "Server/WorldPacket.h" #include "Server/WorldSession.h" #include "Spells/Spell.h" @@ -72,47 +91,11 @@ #include "Tools/Language.h" #endif -#if defined TRINITY -#include "Bag.h" -#include "Battleground.h" -#include "Config.h" -#include "DatabaseEnv.h" -#include "GameEventMgr.h" -#include "GitRevision.h" -#include "GroupMgr.h" -#include "MiscPackets.h" -#include "MotionMaster.h" -#include "ScriptedCreature.h" -#include "SpellHistory.h" -#include "SpellInfo.h" -#include "WeatherMgr.h" -#else -#include "Config/Config.h" -#if defined CMANGOS && defined CATA -#include "AI/BaseAI/AggressorAI.h" -#include "Server/SQLStorages.h" -#elif defined CMANGOS -#include "AI/BaseAI/UnitAI.h" -#include "Server/SQLStorages.h" -#elif defined VMANGOS -#include "BasicAI.h" -#include "Bag.h" -#else -#include "AggressorAI.h" -#include "SQLStorages.h" -#endif +#if !defined TRINITY #include "BattleGroundMgr.h" -#if !defined CMANGOS -#include "SQLStorages.h" -#else -#include "Server/SQLStorages.h" -#endif -#if defined MANGOS -#include "GitRevision.h" -#else +#include "Config/Config.h" #include "revision.h" #endif -#endif #if !defined TBC && !defined CLASSIC #if !defined CMANGOS @@ -135,20 +118,9 @@ typedef Opcodes OpcodesList; * Note: if you add or change a CORE_NAME or CORE_VERSION #define, * please update LuaGlobalFunctions::GetCoreName or LuaGlobalFunctions::GetCoreVersion documentation example string. */ -#if defined MANGOS -#define CORE_NAME "MaNGOS" -#define CORE_VERSION REVISION_NR -#if defined CATA -#define NUM_MSG_TYPES NUM_OPCODE_HANDLERS -#endif -#endif - #if defined CMANGOS #define CORE_NAME "cMaNGOS" #define CORE_VERSION REVISION_DATE " " REVISION_ID -#if defined CATA -#define NUM_MSG_TYPES MAX_OPCODE_TABLE_SIZE -#endif #endif #if defined VMANGOS @@ -186,12 +158,10 @@ typedef Opcodes OpcodesList; #define TOTAL_LOCALES MAX_LOCALE #define TARGETICONCOUNT TARGET_ICON_COUNT #define MAX_TALENT_SPECS MAX_TALENT_SPEC_COUNT -#if !defined VMANGOS -#define TEAM_NEUTRAL TEAM_INDEX_NEUTRAL -#endif - -#if (defined CATA && !defined MANGOS) || defined VMANGOS +#if defined CMANGOS +#define TEAM_NEUTRAL TEAM_INDEX_NEUTRAL +#elif defined VMANGOS #define PLAYER_FIELD_LIFETIME_HONORABLE_KILLS PLAYER_FIELD_LIFETIME_HONORBALE_KILLS #endif @@ -199,11 +169,11 @@ typedef Opcodes OpcodesList; #define SPELL_AURA_MOD_KILL_XP_PCT SPELL_AURA_MOD_XP_PCT #endif -#if defined CATA || defined MISTS || (defined WOTLK && !defined MANGOS) +#if defined WOTLK #define UNIT_BYTE2_FLAG_SANCTUARY UNIT_BYTE2_FLAG_SUPPORTABLE #endif -#if !defined CMANGOS +#if defined VMANGOS typedef TemporarySummon TempSummon; #else typedef TemporarySpawn TempSummon; diff --git a/ElunaUtility.cpp b/ElunaUtility.cpp index 1d0bc3a5e2..f2c7aec1e8 100644 --- a/ElunaUtility.cpp +++ b/ElunaUtility.cpp @@ -19,13 +19,10 @@ #include "Server/DBCStores.h" #include "Util/Timer.h" #endif -#if defined MANGOS -#include "Timer.h" -#endif uint32 ElunaUtil::GetCurrTime() { -#if !defined CMANGOS && !defined VMANGOS +#if defined TRINITY return getMSTime(); #else return WorldTimer::getMSTime(); @@ -34,7 +31,7 @@ uint32 ElunaUtil::GetCurrTime() uint32 ElunaUtil::GetTimeDiff(uint32 oldMSTime) { -#if !defined CMANGOS && !defined VMANGOS +#if defined TRINITY return GetMSTimeDiffToNow(oldMSTime); #else return WorldTimer::getMSTimeDiff(oldMSTime, WorldTimer::getMSTime()); @@ -67,10 +64,10 @@ ElunaUtil::WorldObjectInRangeCheck::WorldObjectInRangeCheck(bool nearest, WorldO if (GameObject const* go = i_obj->ToGameObject()) i_obj_unit = go->GetOwner(); if (!i_obj_unit) -#if !defined VMANGOS - i_obj_fact = sFactionTemplateStore.LookupEntry(14); -#else +#if defined VMANGOS i_obj_fact = sObjectMgr.GetFactionTemplateEntry(14); +#else + i_obj_fact = sFactionTemplateStore.LookupEntry(14); #endif } WorldObject const& ElunaUtil::WorldObjectInRangeCheck::GetFocusObject() const @@ -101,16 +98,8 @@ bool ElunaUtil::WorldObjectInRangeCheck::operator()(WorldObject* u) { if (i_obj_fact) { -#if (defined TRINITY || CMANGOS || VMANGOS) && !defined CATA if ((i_obj_fact->IsHostileTo(*target->GetFactionTemplateEntry())) != (i_hostile == 1)) return false; -#elif defined CATA && defined CMANGOS - if ((i_obj_fact->IsHostileTo(*target->GetFactionTemplateEntry())) != (i_hostile == 1)) - return false; -#else - if ((i_obj_fact->IsHostileTo(*target->getFactionTemplateEntry())) != (i_hostile == 1)) - return false; -#endif } else if (i_hostile == 1) return false; diff --git a/ElunaUtility.h b/ElunaUtility.h index 5f3d33d729..7c85c72121 100644 --- a/ElunaUtility.h +++ b/ElunaUtility.h @@ -33,7 +33,7 @@ #include #include -#if !defined MANGOS && !defined VMANGOS +#if !defined VMANGOS #define USING_BOOST #endif diff --git a/LuaEngine.h b/LuaEngine.h index 76cebfce4f..a8205d802e 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -489,9 +489,6 @@ class ELUNA_GAME_API Eluna void OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints); void OnTalentsReset(Player* pPlayer, bool noCost); void OnMoneyChanged(Player* pPlayer, int32& amount); -#if defined CATA - void OnMoneyChanged(Player* pPlayer, int64& amount); -#endif void OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim); void OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental); void OnDuelRequest(Player* pTarget, Player* pChallenger); @@ -546,13 +543,7 @@ class ELUNA_GAME_API Eluna void OnCreate(Guild* guild, Player* leader, const std::string& name); void OnDisband(Guild* guild); void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair); -#if defined CATA - void OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair); -#endif void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount); -#if defined CATA - void OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount); -#endif void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId); void OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank); void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId); diff --git a/LuaValue.h b/LuaValue.h index fdb654efe5..fcb15d1aab 100644 --- a/LuaValue.h +++ b/LuaValue.h @@ -27,6 +27,9 @@ // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#ifndef _LUA_VAL_H +#define _LUA_VAL_H + #pragma once #include // std::unordered_map @@ -151,3 +154,5 @@ class LuaVal LuaValVariant v; }; + +#endif diff --git a/hooks/GossipHooks.cpp b/hooks/GossipHooks.cpp index 361a77c22f..543f1c74c8 100644 --- a/hooks/GossipHooks.cpp +++ b/hooks/GossipHooks.cpp @@ -26,7 +26,7 @@ using namespace Hooks; bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject) { START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_HELLO, pGameObject->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -39,7 +39,7 @@ bool Eluna::OnGossipHello(Player* pPlayer, GameObject* pGameObject) bool Eluna::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) { START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -54,7 +54,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 send bool Eluna::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) { START_HOOK_WITH_RETVAL(GameObjectGossipBindings, GOSSIP_EVENT_ON_SELECT, pGameObject->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -70,7 +70,7 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, const std::string& code) { START_HOOK(PlayerGossipBindings, GOSSIP_EVENT_ON_SELECT, menuId); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -91,7 +91,7 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 send bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& /*targets*/) { START_HOOK_WITH_RETVAL(ItemGossipBindings, GOSSIP_EVENT_ON_HELLO, pItem->GetEntry(), true); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -104,12 +104,11 @@ bool Eluna::OnItemGossip(Player* pPlayer, Item* pItem, SpellCastTargets const& / void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* pItem, uint32 sender, uint32 action, const std::string& code) { START_HOOK(ItemGossipBindings, GOSSIP_EVENT_ON_SELECT, pItem->GetEntry()); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); #endif - HookPush(pPlayer); HookPush(pItem); HookPush(sender); @@ -125,7 +124,7 @@ void Eluna::HandleGossipSelectOption(Player* pPlayer, Item* pItem, uint32 sender bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature) { START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_HELLO, pCreature->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS pPlayer->GetPlayerMenu()->ClearMenus(); #else pPlayer->PlayerTalkClass->ClearMenus(); @@ -138,7 +137,7 @@ bool Eluna::OnGossipHello(Player* pPlayer, Creature* pCreature) bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) { START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS auto original_menu = *pPlayer->GetPlayerMenu(); pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -151,7 +150,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, HookPush(action); auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true); if (!preventDefault) { -#if defined CMANGOS && !defined CATA +#if defined CMANGOS *pPlayer->GetPlayerMenu() = original_menu; #else *pPlayer->PlayerTalkClass = original_menu; @@ -163,7 +162,7 @@ bool Eluna::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) { START_HOOK_WITH_RETVAL(CreatureGossipBindings, GOSSIP_EVENT_ON_SELECT, pCreature->GetEntry(), false); -#if defined CMANGOS && !defined CATA +#if defined CMANGOS auto original_menu = *pPlayer->GetPlayerMenu(); pPlayer->GetPlayerMenu()->ClearMenus(); #else @@ -177,7 +176,7 @@ bool Eluna::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 send HookPush(code); auto preventDefault = CallAllFunctionsBool(CreatureGossipBindings, key, true); if (!preventDefault) { -#if defined CMANGOS && !defined CATA +#if defined CMANGOS *pPlayer->GetPlayerMenu() = original_menu; #else *pPlayer->PlayerTalkClass = original_menu; diff --git a/hooks/GuildHooks.cpp b/hooks/GuildHooks.cpp index cf46ad46c9..6317a46223 100644 --- a/hooks/GuildHooks.cpp +++ b/hooks/GuildHooks.cpp @@ -94,35 +94,6 @@ void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, b CleanUpStack(4); } -#if defined CATA -void Eluna::OnMemberWitdrawMoney(Guild* guild, Player* player, uint64& amount, bool isRepair) -{ - START_HOOK(GUILD_EVENT_ON_MONEY_WITHDRAW); - HookPush(guild); - HookPush(player); - HookPush(amount); - HookPush(isRepair); // isRepair not a part of Mangos, implement? - int amountIndex = lua_gettop(L) - 1; - int n = SetupStack(GuildEventBindings, key, 4); - - while (n > 0) - { - int r = CallOneFunction(n--, 4, 1); - - if (lua_isnumber(L, r)) - { - amount = CHECKVAL(r); - // Update the stack for subsequent calls. - ReplaceArgument(amount, amountIndex); - } - - lua_pop(L, 1); - } - - CleanUpStack(4); -} -#endif - void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount) { START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT); @@ -149,34 +120,6 @@ void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount) CleanUpStack(3); } -#if defined CATA -void Eluna::OnMemberDepositMoney(Guild* guild, Player* player, uint64& amount) -{ - START_HOOK(GUILD_EVENT_ON_MONEY_DEPOSIT); - HookPush(guild); - HookPush(player); - HookPush(amount); - int amountIndex = lua_gettop(L); - int n = SetupStack(GuildEventBindings, key, 3); - - while (n > 0) - { - int r = CallOneFunction(n--, 3, 1); - - if (lua_isnumber(L, r)) - { - amount = CHECKVAL(r); - // Update the stack for subsequent calls. - ReplaceArgument(amount, amountIndex); - } - - lua_pop(L, 1); - } - - CleanUpStack(3); -} -#endif - void Eluna::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId) { diff --git a/hooks/PacketHooks.cpp b/hooks/PacketHooks.cpp index 59f323e854..d4e370e12c 100644 --- a/hooks/PacketHooks.cpp +++ b/hooks/PacketHooks.cpp @@ -101,10 +101,10 @@ void Eluna::OnPacketReceiveAny(Player* player, WorldPacket& packet, bool& result if (lua_isuserdata(L, r + 1)) if (WorldPacket* data = CHECKOBJ(r + 1, false)) { -#if defined TRINITY || defined VMANGOS - packet = std::move(*data); -#else +#if defined CMANGOS packet = *data; +#else + packet = std::move(*data); #endif } @@ -131,10 +131,10 @@ void Eluna::OnPacketReceiveOne(Player* player, WorldPacket& packet, bool& result if (lua_isuserdata(L, r + 1)) if (WorldPacket* data = CHECKOBJ(r + 1, false)) { -#if defined TRINITY || defined VMANGOS - packet = std::move(*data); -#else +#if defined CMANGOS packet = *data; +#else + packet = std::move(*data); #endif } diff --git a/hooks/PlayerHooks.cpp b/hooks/PlayerHooks.cpp index 4abb25c72b..297c8ac18f 100644 --- a/hooks/PlayerHooks.cpp +++ b/hooks/PlayerHooks.cpp @@ -280,33 +280,6 @@ void Eluna::OnMoneyChanged(Player* pPlayer, int32& amount) CleanUpStack(2); } -#if defined CATA -void Eluna::OnMoneyChanged(Player* pPlayer, int64& amount) -{ - START_HOOK(PLAYER_EVENT_ON_MONEY_CHANGE); - HookPush(pPlayer); - HookPush(amount); - int amountIndex = lua_gettop(L); - int n = SetupStack(PlayerEventBindings, key, 2); - - while (n > 0) - { - int r = CallOneFunction(n--, 2, 1); - - if (lua_isnumber(L, r)) - { - amount = CHECKVAL(r); - // Update the stack for subsequent calls. - ReplaceArgument(amount, amountIndex); - } - - lua_pop(L, 1); - } - - CleanUpStack(2); -} -#endif - void Eluna::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) { START_HOOK(PLAYER_EVENT_ON_GIVE_XP); diff --git a/lmarshal.h b/lmarshal.h index a56558fee2..1c8a83a0f4 100644 --- a/lmarshal.h +++ b/lmarshal.h @@ -4,9 +4,14 @@ * Please see the included DOCS/LICENSE.md for more information */ +#ifndef _LUA_MARSHAL_H +#define _LUA_MARSHAL_H + extern "C" { #include "lua.h" } int mar_encode(lua_State* L); int mar_decode(lua_State* L); + +#endif diff --git a/methods/Mangos/AuraMethods.h b/methods/Mangos/AuraMethods.h deleted file mode 100644 index 6e45a0e473..0000000000 --- a/methods/Mangos/AuraMethods.h +++ /dev/null @@ -1,206 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef AURAMETHODS_H -#define AURAMETHODS_H - -/*** - * The persistent effect of a [Spell] that remains on a [Unit] after the [Spell] - * has been cast. - * - * As an example, if you cast a damage-over-time spell on a target, an [Aura] is - * put on the target that deals damage continuously. - * - * [Aura]s on your player are displayed in-game as a series of icons to the left - * of the mini-map. - * - * Inherits all methods from: none - */ -namespace LuaAura -{ - /** - * Returns the [Unit] that casted the [Spell] that caused this [Aura] to be applied. - * - * @return [Unit] caster - */ - int GetCaster(Eluna* E, Aura* aura) - { - E->Push(aura->GetCaster()); - return 1; - } - - /** - * Returns the GUID of the [Unit] that casted the [Spell] that caused this [Aura] to be applied. - * - * @return string caster_guid : the GUID of the Unit as a decimal string - */ - int GetCasterGUID(Eluna* E, Aura* aura) - { - E->Push(aura->GetCasterGuid()); - return 1; - } - - /** - * Returns the level of the [Unit] that casted the [Spell] that caused this [Aura] to be applied. - * - * @return uint32 caster_level - */ - int GetCasterLevel(Eluna* E, Aura* aura) - { - E->Push(aura->GetCaster()->getLevel()); - return 1; - } - - /** - * Returns the amount of time left until the [Aura] expires. - * - * @return int32 duration : amount of time left in milliseconds - */ - int GetDuration(Eluna* E, Aura* aura) - { - E->Push(aura->GetAuraDuration()); - return 1; - } - - /** - * Returns the ID of the [Spell] that caused this [Aura] to be applied. - * - * @return uint32 aura_id - */ - int GetAuraId(Eluna* E, Aura* aura) - { - E->Push(aura->GetId()); - return 1; - } - - /** - * Returns the amount of time this [Aura] lasts when applied. - * - * To determine how much time has passed since this Aura was applied, - * subtract the result of [Aura]:GetDuration from the result of this method. - * - * @return int32 max_duration : the maximum duration of the Aura, in milliseconds - */ - int GetMaxDuration(Eluna* E, Aura* aura) - { - E->Push(aura->GetAuraMaxDuration()); - return 1; - } - - /** - * Returns the number of times the [Aura] has "stacked". - * - * This is the same as the number displayed on the [Aura]'s icon in-game. - * - * @return uint32 stack_amount - */ - int GetStackAmount(Eluna* E, Aura* aura) - { - E->Push(aura->GetStackAmount()); - return 1; - } - - /** - * Returns the [Unit] that the [Aura] has been applied to. - * - * @return [Unit] owner - */ - int GetOwner(Eluna* E, Aura* aura) - { - E->Push(aura->GetTarget()); - return 1; - } - - /** - * Change the amount of time before the [Aura] expires. - * - * @param int32 duration : the new duration of the Aura, in milliseconds - */ - int SetDuration(Eluna* E, Aura* aura) - { - int32 duration = E->CHECKVAL(2); - - aura->GetHolder()->SetAuraDuration(duration); -#if (defined(TBC) || defined(CLASSIC)) - aura->GetHolder()->UpdateAuraDuration(); -#else - aura->GetHolder()->SendAuraUpdate(false); -#endif - return 0; - } - - /** - * Change the maximum amount of time before the [Aura] expires. - * - * This does not affect the current duration of the [Aura], but if the [Aura] - * is reset to the maximum duration, it will instead change to `duration`. - * - * @param int32 duration : the new maximum duration of the Aura, in milliseconds - */ - int SetMaxDuration(Eluna* E, Aura* aura) - { - int32 duration = E->CHECKVAL(2); - - aura->GetHolder()->SetAuraMaxDuration(duration); -#if (defined(TBC) || defined(CLASSIC)) - aura->GetHolder()->UpdateAuraDuration(); -#else - aura->GetHolder()->SendAuraUpdate(false); -#endif - return 0; - } - - /** - * Change the amount of times the [Aura] has "stacked" on the [Unit]. - * - * If `amount` is greater than or equal to the current number of stacks, - * then the [Aura] has its duration reset to the maximum duration. - * - * @param uint32 amount - */ - int SetStackAmount(Eluna* E, Aura* aura) - { - uint8 amount = E->CHECKVAL(2); - - aura->GetHolder()->SetStackAmount(amount); - return 0; - } - - /** - * Remove this [Aura] from the [Unit] it is applied to. - */ - int Remove(Eluna* E, Aura* aura) - { - aura->GetTarget()->RemoveSpellAuraHolder(aura->GetHolder(), AURA_REMOVE_BY_CANCEL); - - E->CHECKOBJ(1)->Invalidate(); - return 0; - } - - ElunaRegister AuraMethods[] = - { - // Getters - { "GetCaster", &LuaAura::GetCaster }, - { "GetCasterGUID", &LuaAura::GetCasterGUID }, - { "GetCasterLevel", &LuaAura::GetCasterLevel }, - { "GetDuration", &LuaAura::GetDuration }, - { "GetMaxDuration", &LuaAura::GetMaxDuration }, - { "GetAuraId", &LuaAura::GetAuraId }, - { "GetStackAmount", &LuaAura::GetStackAmount }, - { "GetOwner", &LuaAura::GetOwner }, - - // Setters - { "SetDuration", &LuaAura::SetDuration }, - { "SetMaxDuration", &LuaAura::SetMaxDuration }, - { "SetStackAmount", &LuaAura::SetStackAmount }, - - // Other - { "Remove", &LuaAura::Remove }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/BattleGroundMethods.h b/methods/Mangos/BattleGroundMethods.h deleted file mode 100644 index d1bc8c049f..0000000000 --- a/methods/Mangos/BattleGroundMethods.h +++ /dev/null @@ -1,251 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef BATTLEGROUNDMETHODS_H -#define BATTLEGROUNDMETHODS_H - -/*** - * Contains the state of a battleground, e.g. Warsong Gulch, Arathi Basin, etc. - * - * Inherits all methods from: none - */ -namespace LuaBattleGround -{ - /** - * Returns the name of the [BattleGround]. - * - * @return string name - */ - int GetName(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetName()); - return 1; - } - - /** - * Returns the amount of alive players in the [BattleGround] by the team ID. - * - * @param [Team] team : team ID - * @return uint32 count - */ - int GetAlivePlayersCountByTeam(Eluna* E, BattleGround* bg) - { - uint32 team = E->CHECKVAL(2); - E->Push(bg->GetAlivePlayersCountByTeam((Team)team)); - return 1; - } - - /** - * Returns the [Map] of the [BattleGround]. - * - * @return [Map] map - */ - int GetMap(Eluna* E, BattleGround* bg) - { - E->Push(static_cast(bg->GetBgMap())); - return 1; - } - - /** - * Returns the bonus honor given by amount of kills in the specific [BattleGround]. - * - * @param uint32 kills : amount of kills - * @return uint32 bonusHonor - */ - int GetBonusHonorFromKillCount(Eluna* E, BattleGround* bg) - { - uint32 kills = E->CHECKVAL(2); - - E->Push(bg->GetBonusHonorFromKill(kills)); - return 1; - } - - /** - * Returns the bracket ID of the specific [BattleGround]. - * - * @return [BattleGroundBracketId] bracketId - */ - int GetBracketId(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetBracketId()); - return 1; - } - - /** - * Returns the end time of the [BattleGround]. - * - * @return uint32 endTime - */ - int GetEndTime(Eluna* E, BattleGround* bg) - { -#ifdef CATA - E->Push(bg->GetRemainingTime()); -#else - E->Push(bg->GetEndTime()); -#endif - return 1; - } - - /** - * Returns the amount of free slots for the selected team in the specific [BattleGround]. - * - * @param [Team] team : team ID - * @return uint32 freeSlots - */ - int GetFreeSlotsForTeam(Eluna* E, BattleGround* bg) - { - uint32 team = E->CHECKVAL(2); - E->Push(bg->GetFreeSlotsForTeam((Team)team)); - return 1; - } - - /** - * Returns the instance ID of the [BattleGround]. - * - * @return uint32 instanceId - */ - int GetInstanceId(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetInstanceID()); - return 1; - } - - /** - * Returns the map ID of the [BattleGround]. - * - * @return uint32 mapId - */ - int GetMapId(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMapId()); - return 1; - } - - /** - * Returns the type ID of the [BattleGround]. - * - * @return [BattleGroundTypeId] typeId - */ - int GetTypeId(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetTypeID()); - return 1; - } - - /** - * Returns the max allowed [Player] level of the specific [BattleGround]. - * - * @return uint32 maxLevel - */ - int GetMaxLevel(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMaxLevel()); - return 1; - } - - /** - * Returns the minimum allowed [Player] level of the specific [BattleGround]. - * - * @return uint32 minLevel - */ - int GetMinLevel(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMinLevel()); - return 1; - } - - /** - * Returns the maximum allowed [Player] count of the specific [BattleGround]. - * - * @return uint32 maxPlayerCount - */ - int GetMaxPlayers(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMaxPlayers()); - return 1; - } - - /** - * Returns the minimum allowed [Player] count of the specific [BattleGround]. - * - * @return uint32 minPlayerCount - */ - int GetMinPlayers(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMinPlayers()); - return 1; - } - - /** - * Returns the maximum allowed [Player] count per team of the specific [BattleGround]. - * - * @return uint32 maxTeamPlayerCount - */ - int GetMaxPlayersPerTeam(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMaxPlayersPerTeam()); - return 1; - } - - /** - * Returns the minimum allowed [Player] count per team of the specific [BattleGround]. - * - * @return uint32 minTeamPlayerCount - */ - int GetMinPlayersPerTeam(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetMinPlayersPerTeam()); - return 1; - } - - /** - * Returns the winning team of the specific [BattleGround]. - * - * @return [Team] team - */ - int GetWinner(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetWinner()); - return 1; - } - - /** - * Returns the status of the specific [BattleGround]. - * - * @return [BattleGroundStatus] status - */ - int GetStatus(Eluna* E, BattleGround* bg) - { - E->Push(bg->GetStatus()); - return 1; - } - - ElunaRegister BattleGroundMethods[] = - { - // Getters - { "GetName", &LuaBattleGround::GetName }, - { "GetAlivePlayersCountByTeam", &LuaBattleGround::GetAlivePlayersCountByTeam }, - { "GetMap", &LuaBattleGround::GetMap }, - { "GetBonusHonorFromKillCount", &LuaBattleGround::GetBonusHonorFromKillCount }, - { "GetBracketId", &LuaBattleGround::GetBracketId }, - { "GetEndTime", &LuaBattleGround::GetEndTime }, - { "GetFreeSlotsForTeam", &LuaBattleGround::GetFreeSlotsForTeam }, - { "GetInstanceId", &LuaBattleGround::GetInstanceId }, - { "GetMapId", &LuaBattleGround::GetMapId }, - { "GetTypeId", &LuaBattleGround::GetTypeId }, - { "GetMaxLevel", &LuaBattleGround::GetMaxLevel }, - { "GetMinLevel", &LuaBattleGround::GetMinLevel }, - { "GetMaxPlayers", &LuaBattleGround::GetMaxPlayers }, - { "GetMinPlayers", &LuaBattleGround::GetMinPlayers }, - { "GetMaxPlayersPerTeam", &LuaBattleGround::GetMaxPlayersPerTeam }, - { "GetMinPlayersPerTeam", &LuaBattleGround::GetMinPlayersPerTeam }, - { "GetWinner", &LuaBattleGround::GetWinner }, - { "GetStatus", &LuaBattleGround::GetStatus }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/CorpseMethods.h b/methods/Mangos/CorpseMethods.h deleted file mode 100644 index b4f4a94793..0000000000 --- a/methods/Mangos/CorpseMethods.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef CORPSEMETHODS_H -#define CORPSEMETHODS_H - -/*** - * The remains of a [Player] that has died. - * - * Inherits all methods from: [Object], [WorldObject] - */ -namespace LuaCorpse -{ - /** - * Returns the GUID of the [Player] that left the [Corpse] behind. - * - * @return ObjectGuid ownerGUID - */ - int GetOwnerGUID(Eluna* E, Corpse* corpse) - { - E->Push(corpse->GetOwnerGuid()); - return 1; - } - - /** - * Returns the time when the [Player] became a ghost and spawned this [Corpse]. - * - * @return uint32 ghostTime - */ - int GetGhostTime(Eluna* E, Corpse* corpse) - { - E->Push(corpse->GetGhostTime()); - return 1; - } - - /** - * Returns the [CorpseType] of a [Corpse]. - * - * enum CorpseType - * { - * CORPSE_BONES = 0, - * CORPSE_RESURRECTABLE_PVE = 1, - * CORPSE_RESURRECTABLE_PVP = 2 - * }; - * - * @return [CorpseType] corpseType - */ - int GetType(Eluna* E, Corpse* corpse) - { - E->Push(corpse->GetType()); - return 1; - } - - /** - * Sets the "ghost time" to the current time. - * - * See [Corpse:GetGhostTime]. - */ - int ResetGhostTime(Eluna* /*E*/, Corpse* corpse) - { - corpse->ResetGhostTime(); - return 0; - } - - /** - * Saves the [Corpse] to the database. - */ - int SaveToDB(Eluna* /*E*/, Corpse* corpse) - { - corpse->SaveToDB(); - return 0; - } - - ElunaRegister CorpseMethods[] = - { - // Getters - { "GetOwnerGUID", &LuaCorpse::GetOwnerGUID }, - { "GetGhostTime", &LuaCorpse::GetGhostTime }, - { "GetType", &LuaCorpse::GetType }, - - // Other - { "ResetGhostTime", &LuaCorpse::ResetGhostTime }, - { "SaveToDB", &LuaCorpse::SaveToDB }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/CreatureMethods.h b/methods/Mangos/CreatureMethods.h deleted file mode 100644 index 56c2973a4c..0000000000 --- a/methods/Mangos/CreatureMethods.h +++ /dev/null @@ -1,1214 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef CREATUREMETHODS_H -#define CREATUREMETHODS_H - -/*** - * Non-[Player] controlled [Unit]s (i.e. NPCs). - * - * Inherits all methods from: [Object], [WorldObject], [Unit] - */ -namespace LuaCreature -{ - /** - * Returns `true` if the [Creature] can regenerate health, - * and returns `false` otherwise. - * - * @return bool isRegenerating - */ - int IsRegeneratingHealth(Eluna* E, Creature* creature) - { - E->Push(creature->IsRegeneratingHealth()); - return 1; - } - - /** - * Returns `true` if the [Creature] is set to not give reputation when killed, - * and returns `false` otherwise. - * - * @return bool reputationDisabled - */ - int IsReputationGainDisabled(Eluna* E, Creature* creature) - { - E->Push(creature->IsReputationGainDisabled()); - return 1; - } - - /** - * Returns `true` if the [Creature] completes the [Quest] with the ID `questID`, - * and returns `false` otherwise. - * - * @param uint32 questID : the ID of a [Quest] - * @return bool completesQuest - */ - int CanCompleteQuest(Eluna* E, Creature* creature) - { - uint32 quest_id = E->CHECKVAL(2); - - E->Push(creature->HasInvolvedQuest(quest_id)); - return 1; - } - - /** - * Returns `true` if the [Creature] can be targeted for attack, - * and returns `false` otherwise. - * - * @param bool mustBeDead = false : if `true`, only returns `true` if the [Creature] is also dead. Otherwise, it must be alive. - * @return bool targetable - */ - int IsTargetableForAttack(Eluna* E, Creature* creature) - { - bool mustBeDead = E->CHECKVAL(2, false); - - E->Push(creature->IsTargetableForAttack(mustBeDead)); - return 1; - } - - /** - * Returns `true` if the [Creature] can assist `friend` in combat against `enemy`, - * and returns `false` otherwise. - * - * @param [Unit] friend : the Unit we will be assisting - * @param [Unit] enemy : the Unit that we would attack if we assist `friend` - * @param bool checkFaction = true : if `true`, the [Creature] must be the same faction as `friend` to assist - * @return bool canAssist - */ - int CanAssistTo(Eluna* E, Creature* creature) - { - Unit* u = E->CHECKOBJ(2); - Unit* enemy = E->CHECKOBJ(3); - bool checkfaction = E->CHECKVAL(4, true); - - E->Push(creature->CanAssistTo(u, enemy, checkfaction)); - return 1; - } - - /** - * Returns `true` if the [Creature] has searched for combat assistance already, - * and returns `false` otherwise. - * - * @return bool searchedForAssistance - */ - int HasSearchedAssistance(Eluna* E, Creature* creature) - { - E->Push(creature->HasSearchedAssistance()); - return 1; - } - - /** - * Returns `true` if the [Creature] will give its loot to `player`, - * and returns `false` otherwise. - * - * @return bool tapped - */ - int IsTappedBy(Eluna* E, Creature* creature) - { - Player* player = E->CHECKOBJ(2); - - E->Push(creature->IsTappedBy(player)); - return 1; - } - - /** - * Returns `true` if the [Creature] will give its loot to a [Player] or [Group], - * and returns `false` otherwise. - * - * @return bool hasLootRecipient - */ - int HasLootRecipient(Eluna* E, Creature* creature) - { - E->Push(creature->HasLootRecipient()); - return 1; - } - - /** - * Returns `true` if the [Creature] can start attacking nearby hostile [Unit]s, - * and returns `false` otherwise. - * - * @return bool canAggro - */ - int CanAggro(Eluna* E, Creature* creature) - { - E->Push(!creature->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE)); - return 1; - } - - /** - * Returns `true` if the [Creature] can move through deep water, - * and returns `false` otherwise. - * - * @return bool canSwim - */ - int CanSwim(Eluna* E, Creature* creature) - { - E->Push(creature->CanSwim()); - return 1; - } - - /** - * Returns `true` if the [Creature] can move on land, - * and returns `false` otherwise. - * - * @return bool canWalk - */ - int CanWalk(Eluna* E, Creature* creature) - { - E->Push(creature->CanWalk()); - return 1; - } - - /** - * Returns `true` if the [Creature] is returning to its spawn position from combat, - * and returns `false` otherwise. - * - * @return bool inEvadeMode - */ - int IsInEvadeMode(Eluna* E, Creature* creature) - { - E->Push(creature->IsInEvadeMode()); - return 1; - } - - /** - * Returns `true` if the [Creature]'s rank is Elite or Rare Elite, - * and returns `false` otherwise. - * - * @return bool isElite - */ - int IsElite(Eluna* E, Creature* creature) - { - E->Push(creature->IsElite()); - return 1; - } - - /** - * Returns `true` if the [Creature] is a city guard, - * and returns `false` otherwise. - * - * @return bool isGuard - */ - int IsGuard(Eluna* E, Creature* creature) - { - E->Push(creature->IsGuard()); - return 1; - } - - /** - * Returns `true` if the [Creature] is a civilian, - * and returns `false` otherwise. - * - * @return bool isCivilian - */ - int IsCivilian(Eluna* E, Creature* creature) - { - E->Push(creature->IsCivilian()); - return 1; - } - - /** - * Returns `true` if the [Creature] is the leader of a player faction, - * and returns `false` otherwise. - * - * @return bool isLeader - */ - int IsRacialLeader(Eluna* E, Creature* creature) - { - E->Push(creature->IsRacialLeader()); - return 1; - } - - /** - * Returns `true` if the [Creature]'s rank is Boss, - * and returns `false` otherwise. - * - * @return bool isWorldBoss - */ - int IsWorldBoss(Eluna* E, Creature* creature) - { - E->Push(creature->IsWorldBoss()); - return 1; - } - - /** - * Returns `true` if the [Creature] cannot cast `spellId` due to a category cooldown, - * and returns `false` otherwise. - * - * @param uint32 spellId : the ID of a [Spell] - * @return bool hasCooldown - */ - int HasCategoryCooldown(Eluna* E, Creature* creature) - { - uint32 spell = E->CHECKVAL(2); - - E->Push(creature->HasCategoryCooldown(spell)); - return 1; - } - - /** - * Returns `true` if the [Creature] can cast `spellId` when mind-controlled, - * and returns `false` otherwise. - * - * @param uint32 spellId : the ID of a [Spell] - * @return bool hasSpell - */ - int HasSpell(Eluna* E, Creature* creature) - { - uint32 id = E->CHECKVAL(2); - - E->Push(creature->HasSpell(id)); - return 1; - } - - /** - * Returns `true` if the [Creature] starts the [Quest] `questId`, - * and returns `false` otherwise. - * - * @param uint32 questId : the ID of a [Quest] - * @return bool hasQuest - */ - int HasQuest(Eluna* E, Creature* creature) - { - uint32 questId = E->CHECKVAL(2); - - E->Push(creature->HasQuest(questId)); - return 1; - } - - /** - * Returns `true` if the [Creature] has `spellId` on cooldown, - * and returns `false` otherwise. - * - * @param uint32 spellId : the ID of a [Spell] - * @return bool hasCooldown - */ - int HasSpellCooldown(Eluna* E, Creature* creature) - { - uint32 spellId = E->CHECKVAL(2); - - E->Push(creature->HasSpellCooldown(spellId)); - return 1; - } - - /** - * Returns `true` if the [Creature] can fly, - * and returns `false` otherwise. - * - * @return bool canFly - */ - int CanFly(Eluna* E, Creature* creature) - { - E->Push(creature->CanFly()); - return 1; - } - - /** - * Returns the time it takes for this [Creature] to respawn once killed. - * - * This value does not usually change over a [Creature]'s lifespan, - * but can be modified by [Creature:SetRespawnDelay]. - * - * @return uint32 respawnDelay : the respawn delay, in seconds - */ - int GetRespawnDelay(Eluna* E, Creature* creature) - { - E->Push(creature->GetRespawnDelay()); - return 1; - } - - /** - * Returns the radius the [Creature] is permitted to wander from its - * respawn point. - * - * @return float wanderRadius - */ - int GetWanderRadius(Eluna* E, Creature* creature) - { - E->Push(creature->GetRespawnRadius()); - return 1; - } - - /** - * Returns the current waypoint ID of the [Creature]. - * - * @return uint32 wpId - */ - int GetCurrentWaypointId(Eluna* E, Creature* creature) - { - E->Push(creature->GetMotionMaster()->getLastReachedWaypoint()); - return 1; - } - - /** - * Returns the default movement type for this [Creature]. - * - * @return [MovementGeneratorType] defaultMovementType - */ - int GetDefaultMovementType(Eluna* E, Creature* creature) - { - E->Push(creature->GetDefaultMovementType()); - return 1; - } - - /** - * Returns the aggro range of the [Creature] for `target`. - * - * @param [Unit] target - * @return float aggroRange - */ - int GetAggroRange(Eluna* E, Creature* creature) - { - Unit* target = E->CHECKOBJ(2); - - float AttackDist = creature->GetAttackDistance(target); - float ThreatRadius = sWorld.getConfig(CONFIG_FLOAT_THREAT_RADIUS); - E->Push(ThreatRadius > AttackDist ? ThreatRadius : AttackDist); - return 1; - } - - /** - * Returns the effective aggro range of the [Creature] for `target`. - * - * If this is smaller than the minimum aggro range set in the config file, - * that is used as the aggro range instead. - * - * @param [Unit] target - * @return float attackDistance - */ - int GetAttackDistance(Eluna* E, Creature* creature) - { - Unit* target = E->CHECKOBJ(2); - - E->Push(creature->GetAttackDistance(target)); - return 1; - } - - /** - * Returns the [Group] that can loot this [Creature]. - * - * @return [Group] lootRecipientGroup : the group or `nil` - */ - int GetLootRecipientGroup(Eluna* E, Creature* creature) - { - E->Push(creature->GetGroupLootRecipient()); - return 1; - } - - /** - * Returns the [Player] that can loot this [Creature]. - * - * @return [Player] lootRecipient : the player or `nil` - */ - int GetLootRecipient(Eluna* E, Creature* creature) - { - E->Push(creature->GetLootRecipient()); - return 1; - } - - /** - * Returns the [Creature]'s script name. - * - * This is used by the core to apply C++ scripts to the Creature. - * - * It is not used by Eluna. Eluna will override AI scripts. - * - * @return string scriptName - */ - int GetScriptName(Eluna* E, Creature* creature) - { - E->Push(creature->GetScriptName()); - return 1; - } - - /** - * Returns the [Creature]'s AI name. - * - * This is used by the core to assign the Creature's default AI. - * - * If the Creature is scripted by Eluna, the AI is overriden. - * - * @return string AIName - */ - int GetAIName(Eluna* E, Creature* creature) - { - E->Push(creature->GetAIName()); - return 1; - } - - /** - * Returns the [Creature]'s script ID. - * - * Every C++ script name is assigned a unique ID by the core. - * This returns the ID for this [Creature]'s script name. - * - * @return uint32 scriptID - */ - int GetScriptId(Eluna* E, Creature* creature) - { - E->Push(creature->GetScriptId()); - return 1; - } - - /** - * Returns the [Creature]'s cooldown for `spellID`. - * - * @param uint32 spellID - * @return uint32 cooldown : the cooldown, in milliseconds - */ - int GetCreatureSpellCooldownDelay(Eluna* E, Creature* creature) - { - uint32 spell = E->CHECKVAL(2); - - E->Push(creature->GetCreatureSpellCooldownDelay(spell)); - return 1; - } - - /** - * Returns the delay between when the [Creature] dies and when its body despawns. - * - * @return uint32 corpseDelay : the delay, in seconds - */ - int GetCorpseDelay(Eluna* E, Creature* creature) - { - E->Push(creature->GetCorpseDelay()); - return 1; - } - - /** - * Returns position the [Creature] returns to when evading from combat - * or respawning. - * - * @return float x - * @return float y - * @return float z - * @return float o - */ - int GetHomePosition(Eluna* E, Creature* creature) - { - float x, y, z, o; - creature->GetRespawnCoord(x, y, z, &o); - - E->Push(x); - E->Push(y); - E->Push(z); - E->Push(o); - return 4; - } - - /** - * Sets the position the [Creature] returns to when evading from combat - * or respawning. - * - * @param float x - * @param float y - * @param float z - * @param float o - */ - int SetHomePosition(Eluna* E, Creature* creature) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - float o = E->CHECKVAL(5); - - creature->SetRespawnCoord(x, y, z, o); - return 0; - } - - enum SelectAggroTarget - { - SELECT_TARGET_RANDOM = 0, // Just selects a random target - SELECT_TARGET_TOPAGGRO, // Selects targes from top aggro to bottom - SELECT_TARGET_BOTTOMAGGRO, // Selects targets from bottom aggro to top - SELECT_TARGET_NEAREST, - SELECT_TARGET_FARTHEST - }; - - /** - * Returns a target from the [Creature]'s threat list based on the - * supplied arguments. - * - * enum SelectAggroTarget - * { - * SELECT_TARGET_RANDOM = 0, //Just selects a random target - * SELECT_TARGET_TOPAGGRO, //Selects targets from top aggro to bottom - * SELECT_TARGET_BOTTOMAGGRO, //Selects targets from bottom aggro to top - * SELECT_TARGET_NEAREST, - * SELECT_TARGET_FARTHEST - * }; - * - * For example, if you wanted to select the third-farthest [Player] - * within 50 yards that has the [Aura] "Corrupted Blood" (ID 24328), - * you could use this function like so: - * - * target = creature:GetAITarget(4, true, 3, 50, 24328) - * - * @param [SelectAggroTarget] targetType : how the threat list should be sorted - * @param bool playerOnly = false : if `true`, skips targets that aren't [Player]s - * @param uint32 position = 0 : used as an offset into the threat list. If `targetType` is random, used as the number of players from top of aggro to choose from - * @param float distance = 0.0 : if positive, the maximum distance for the target. If negative, the minimum distance - * @param int32 aura = 0 : if positive, the target must have this [Aura]. If negative, the the target must not have this Aura - * @return [Unit] target : the target, or `nil` - */ - int GetAITarget(Eluna* E, Creature* creature) - { - uint32 targetType = E->CHECKVAL(2); - bool playerOnly = E->CHECKVAL(3, false); - uint32 position = E->CHECKVAL(4, 0); - float dist = E->CHECKVAL(5, 0.0f); - int32 aura = E->CHECKVAL(6, 0); - - ThreatList const& threatlist = creature->GetThreatManager().getThreatList(); - - if (threatlist.empty()) - return 1; - if (position >= threatlist.size()) - return 1; - - std::list targetList; - - for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) - { - Unit* target = (*itr)->getTarget(); - - if (!target) - continue; - if (playerOnly && target->GetTypeId() != TYPEID_PLAYER) - continue; - if (aura > 0 && !target->HasAura(aura)) - continue; - else if (aura < 0 && target->HasAura(-aura)) - continue; - if (dist > 0.0f && !creature->IsWithinDist(target, dist)) - continue; - else if (dist < 0.0f && creature->IsWithinDist(target, -dist)) - continue; - targetList.push_back(target); - } - - if (targetList.empty()) - return 1; - if (position >= targetList.size()) - return 1; - - if (targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) - targetList.sort(ElunaUtil::ObjectDistanceOrderPred(creature)); - - switch (targetType) - { - case SELECT_TARGET_NEAREST: - case SELECT_TARGET_TOPAGGRO: - { - std::list::const_iterator itr = targetList.begin(); - if (position) - std::advance(itr, position); - E->Push(*itr); - } - break; - case SELECT_TARGET_FARTHEST: - case SELECT_TARGET_BOTTOMAGGRO: - { - std::list::reverse_iterator ritr = targetList.rbegin(); - if (position) - std::advance(ritr, position); - E->Push(*ritr); - } - break; - case SELECT_TARGET_RANDOM: - { - std::list::const_iterator itr = targetList.begin(); - if (position) - std::advance(itr, urand(0, position)); - else - std::advance(itr, urand(0, targetList.size() - 1)); - E->Push(*itr); - } - break; - default: - luaL_argerror(E->L, 2, "SelectAggroTarget expected"); - break; - } - - return 1; - } - - /** - * Returns all [Unit]s in the [Creature]'s threat list. - * - * @return table targets - */ - int GetAITargets(Eluna* E, Creature* creature) - { - ThreatList const& threatlist = creature->GetThreatManager().getThreatList(); - - lua_createtable(E->L, threatlist.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (auto itr = threatlist.begin(); itr != threatlist.end(); ++itr) - { - Unit* target = (*itr)->getTarget(); - - if (!target) - continue; - E->Push(target); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns the number of [Unit]s in this [Creature]'s threat list. - * - * @return double targetsCount - */ - int GetAITargetsCount(Eluna* E, Creature* creature) - { - E->Push((double)creature->GetThreatManager().getThreatList().size()); - return 1; - } - - /** - * Returns the [Creature]'s NPC flags. - * - * These are used to control whether the NPC is a vendor, can repair items, - * can give quests, etc. - * - * @return [NPCFlags] npcFlags - */ - int GetNPCFlags(Eluna* E, Creature* creature) - { - E->Push(creature->GetUInt32Value(UNIT_NPC_FLAGS)); - return 1; - } - - /** - * Returns the [Creature]'s Extra flags. - * - * These are used to control whether the NPC is a civilian, uses pathfinding, - * if it's a guard, etc. - * - * @return [ExtraFlags] extraFlags - */ - int GetExtraFlags(Eluna* E, Creature* creature) - { - E->Push(creature->GetCreatureInfo()->ExtraFlags); - return 1; - } - -#if defined(CLASSIC) || defined(TBC) || defined(WOTLK) - /** - * Returns the [Creature]'s shield block value. - * - * @return uint32 shieldBlockValue - */ - int GetShieldBlockValue(Eluna* E, Creature* creature) - { - E->Push(creature->GetShieldBlockValue()); - return 1; - } -#endif - - /** - * Returns the guid of the [Creature] that is used as the ID in the database - * - * @return uint32 dbguid - */ - int GetDBTableGUIDLow(Eluna* E, Creature* creature) - { - // on mangos based this is same as lowguid - E->Push(creature->GetGUIDLow()); - return 1; - } - - /** - * Sets the [Creature]'s NPC flags to `flags`. - * - * @param [NPCFlags] flags - */ - int SetNPCFlags(Eluna* E, Creature* creature) - { - uint32 flags = E->CHECKVAL(2); - - creature->SetUInt32Value(UNIT_NPC_FLAGS, flags); - return 0; - } - - /** - * Makes the [Creature] able to fly if enabled. - * - * @param bool disable - */ - int SetDisableGravity(Eluna* E, Creature* creature) - { - bool disable = E->CHECKVAL(2); - - creature->SetLevitate(disable); - return 0; - } - - /** - * Sets the [Creature]'s death state to `deathState`. - * - * @param [DeathState] deathState - */ - int SetDeathState(Eluna* E, Creature* creature) - { - int32 state = E->CHECKVAL(2); - - creature->SetDeathState((DeathState)state); - return 0; - } - - /** - * Sets whether the [Creature] is currently walking or running. - * - * @param bool enable = true : `true` to enable walking, `false` for running - */ - int SetWalk(Eluna* E, Creature* creature) // TODO: Move same to Player ? - { - bool enable = E->CHECKVAL(2, true); - - creature->SetWalk(enable); - return 0; - } - - /** - * Equips given [Item]s to the [Unit]. Using 0 removes the equipped [Item] - * - * @param uint32 main_hand : main hand [Item]'s entry - * @param uint32 off_hand : off hand [Item]'s entry - * @param uint32 ranged : ranged [Item]'s entry - */ - int SetEquipmentSlots(Eluna* E, Creature* creature) - { - uint32 main_hand = E->CHECKVAL(2); - uint32 off_hand = E->CHECKVAL(3); - uint32 ranged = E->CHECKVAL(4); - - creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_0, main_hand); - creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_1, off_hand); - creature->SetVirtualItem(VIRTUAL_ITEM_SLOT_2, ranged); - return 0; - } - - /** - * Sets whether the [Creature] can be aggroed. - * - * @param bool allow = true : `true` to allow aggro, `false` to disable aggro - */ - int SetAggroEnabled(Eluna* E, Creature* creature) - { - bool allow = E->CHECKVAL(2, true); - - if (allow) - creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE); - else - creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PASSIVE); - - return 0; - } - - /** - * Sets whether the [Creature] gives reputation or not. - * - * @param bool disable = true : `true` to disable reputation, `false` to enable - */ - int SetDisableReputationGain(Eluna* E, Creature* creature) - { - bool disable = E->CHECKVAL(2, true); - - creature->SetDisableReputationGain(disable); - return 0; - } - - /** - * Sets the [Creature] as in combat with all [Player]s in the dungeon instance. - * - * This is used by raid bosses to prevent Players from using out-of-combat - * actions once the encounter has begun. - */ - int SetInCombatWithZone(Eluna* /*E*/, Creature* creature) - { - creature->SetInCombatWithZone(); - return 0; - } - - /** - * Sets the distance the [Creature] can wander from it's spawn point. - * - * @param float distance - */ - int SetWanderRadius(Eluna* E, Creature* creature) - { - float dist = E->CHECKVAL(2); - - creature->SetRespawnRadius(dist); - return 0; - } - - /** - * Sets the time it takes for the [Creature] to respawn when killed. - * - * @param uint32 delay : the delay, in seconds - */ - int SetRespawnDelay(Eluna* E, Creature* creature) - { - uint32 delay = E->CHECKVAL(2); - - creature->SetRespawnDelay(delay); - return 0; - } - - /** - * Sets the default movement type of the [Creature]. - * - * @param [MovementGeneratorType] type - */ - int SetDefaultMovementType(Eluna* E, Creature* creature) - { - int32 type = E->CHECKVAL(2); - - creature->SetDefaultMovementType((MovementGeneratorType)type); - return 0; - } - - /** - * Sets whether the [Creature] can search for assistance at low health or not. - * - * @param bool enable = true : `true` to disable searching, `false` to allow - */ - int SetNoSearchAssistance(Eluna* E, Creature* creature) - { - bool val = E->CHECKVAL(2, true); - - creature->SetNoSearchAssistance(val); - return 0; - } - - /** - * Sets whether the [Creature] can call nearby enemies for help in combat or not. - * - * @param bool enable = true : `true` to disable calling for help, `false` to enable - */ - int SetNoCallAssistance(Eluna* E, Creature* creature) - { - bool val = E->CHECKVAL(2, true); - - creature->SetNoCallAssistance(val); - return 0; - } - - /** - * Sets whether the creature is hovering / levitating or not. - * - * @param bool enable = true : `true` to enable hovering, `false` to disable - */ - int SetHover(Eluna* E, Creature* creature) - { - bool enable = E->CHECKVAL(2, true); - - // Copy paste from Aura::HandleAuraHover - // TODO: implement core side properly - WorldPacket data; - if (enable) - data.Initialize(SMSG_MOVE_SET_HOVER, 8 + 4); - else - data.Initialize(SMSG_MOVE_UNSET_HOVER, 8 + 4); - data << creature->GetPackGUID(); - data << uint32(0); - - creature->SendMessageToSet(&data, true); - return 0; - } - - /** - * Despawn this [Creature]. - * - * @param uint32 delay = 0 : dely to despawn in milliseconds - */ - int DespawnOrUnsummon(Eluna* E, Creature* creature) - { - uint32 msTimeToDespawn = E->CHECKVAL(2, 0); - - creature->ForcedDespawn(msTimeToDespawn); - return 0; - } - - /** - * Respawn this [Creature]. - */ - int Respawn(Eluna* /*E*/, Creature* creature) - { - creature->Respawn(); - return 0; - } - - /** - * Remove this [Creature]'s corpse. - */ - int RemoveCorpse(Eluna* /*E*/, Creature* creature) - { - creature->RemoveCorpse(); - return 0; - } - - /** - * Make the [Creature] start following its waypoint path. - */ - int MoveWaypoint(Eluna* /*E*/, Creature* creature) - { - creature->GetMotionMaster()->MoveWaypoint(); - return 0; - } - - /** - * Make the [Creature] call for assistance in combat from other nearby [Creature]s. - */ - int CallAssistance(Eluna* /*E*/, Creature* creature) - { - creature->CallAssistance(); - return 0; - } - - /** - * Make the [Creature] call for help in combat from friendly [Creature]s within `radius`. - * - * @param float radius - */ - int CallForHelp(Eluna* E, Creature* creature) - { - float radius = E->CHECKVAL(2); - - creature->CallForHelp(radius); - return 0; - } - - /** - * Make the [Creature] flee combat to get assistance from a nearby friendly [Creature]. - */ - int FleeToGetAssistance(Eluna* /*E*/, Creature* creature) - { - creature->DoFleeToGetAssistance(); - return 0; - } - - /** - * Make the [Creature] attack `target`. - * - * @param [Unit] target - */ - int AttackStart(Eluna* E, Creature* creature) - { - Unit* target = E->CHECKOBJ(2); - - creature->AI()->AttackStart(target); - return 0; - } - - /** - * Save the [Creature] in the database. - */ - int SaveToDB(Eluna* /*E*/, Creature* creature) - { - creature->SaveToDB(); - return 0; - } - - /** - * Make the [Creature] try to find a new target. - * - * This should be called every update cycle for the Creature's AI. - */ - int SelectVictim(Eluna* E, Creature* creature) - { - E->Push(creature->SelectHostileTarget()); - return 1; - } - - /** - * Transform the [Creature] into another Creature. - * - * @param uint32 entry : the Creature ID to transform into - * @param uint32 dataGUIDLow = 0 : use this Creature's model and equipment instead of the defaults - */ - int UpdateEntry(Eluna* E, Creature* creature) - { - uint32 entry = E->CHECKVAL(2); - uint32 dataGuidLow = E->CHECKVAL(3, 0); - - creature->UpdateEntry(entry, ALLIANCE, dataGuidLow ? eObjectMgr->GetCreatureData(dataGuidLow) : NULL); - return 0; - } - - /** - * Returns the [Creature]'s creature family ID (enumerated in CreatureFamily.dbc). - * - *
-     * enum CreatureFamily
-     * {
-     *     CREATURE_FAMILY_NONE                = 0,    // TrinityCore only
-     *     CREATURE_FAMILY_WOLF                = 1,
-     *     CREATURE_FAMILY_CAT                 = 2,
-     *     CREATURE_FAMILY_SPIDER              = 3,
-     *     CREATURE_FAMILY_BEAR                = 4,
-     *     CREATURE_FAMILY_BOAR                = 5,
-     *     CREATURE_FAMILY_CROCOLISK           = 6,
-     *     CREATURE_FAMILY_CARRION_BIRD        = 7,
-     *     CREATURE_FAMILY_CRAB                = 8,
-     *     CREATURE_FAMILY_GORILLA             = 9,
-     *     CREATURE_FAMILY_HORSE_CUSTOM        = 10,   // Does not exist in DBC but used for horse like beasts in DB
-     *     CREATURE_FAMILY_RAPTOR              = 11,
-     *     CREATURE_FAMILY_TALLSTRIDER         = 12,
-     *     CREATURE_FAMILY_FELHUNTER           = 15,
-     *     CREATURE_FAMILY_VOIDWALKER          = 16,
-     *     CREATURE_FAMILY_SUCCUBUS            = 17,
-     *     CREATURE_FAMILY_DOOMGUARD           = 19,
-     *     CREATURE_FAMILY_SCORPID             = 20,
-     *     CREATURE_FAMILY_TURTLE              = 21,
-     *     CREATURE_FAMILY_IMP                 = 23,
-     *     CREATURE_FAMILY_BAT                 = 24,
-     *     CREATURE_FAMILY_HYENA               = 25,
-     *     CREATURE_FAMILY_BIRD_OF_PREY        = 26,   // Named CREATURE_FAMILY_OWL in Mangos
-     *     CREATURE_FAMILY_WIND_SERPENT        = 27,
-     *     CREATURE_FAMILY_REMOTE_CONTROL      = 28,
-     *     CREATURE_FAMILY_FELGUARD            = 29,   // This and below is TBC+
-     *     CREATURE_FAMILY_DRAGONHAWK          = 30,
-     *     CREATURE_FAMILY_RAVAGER             = 31,
-     *     CREATURE_FAMILY_WARP_STALKER        = 32,
-     *     CREATURE_FAMILY_SPOREBAT            = 33,
-     *     CREATURE_FAMILY_NETHER_RAY          = 34,
-     *     CREATURE_FAMILY_SERPENT             = 35,
-     *     CREATURE_FAMILY_SEA_LION            = 36,   // TBC only
-     *     CREATURE_FAMILY_MOTH                = 37,   // This and below is WotLK+
-     *     CREATURE_FAMILY_CHIMAERA            = 38,
-     *     CREATURE_FAMILY_DEVILSAUR           = 39,
-     *     CREATURE_FAMILY_GHOUL               = 40,
-     *     CREATURE_FAMILY_SILITHID            = 41,
-     *     CREATURE_FAMILY_WORM                = 42,
-     *     CREATURE_FAMILY_RHINO               = 43,
-     *     CREATURE_FAMILY_WASP                = 44,
-     *     CREATURE_FAMILY_CORE_HOUND          = 45,
-     *     CREATURE_FAMILY_SPIRIT_BEAST        = 46
-     * };
-     * 
- * - * @return [CreatureFamily] creatureFamily - */ - int GetCreatureFamily(Eluna* E, Creature* creature) - { - uint32 entry = creature->GetEntry(); - - CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(entry); - if (cInfo) - E->Push(cInfo->Family); - - return 1; - } - - ElunaRegister CreatureMethods[] = - { - // Getters - { "GetAITarget", &LuaCreature::GetAITarget }, - { "GetAITargets", &LuaCreature::GetAITargets }, - { "GetAITargetsCount", &LuaCreature::GetAITargetsCount }, - { "GetHomePosition", &LuaCreature::GetHomePosition }, - { "GetCorpseDelay", &LuaCreature::GetCorpseDelay }, - { "GetCreatureSpellCooldownDelay", &LuaCreature::GetCreatureSpellCooldownDelay }, - { "GetScriptId", &LuaCreature::GetScriptId }, - { "GetAIName", &LuaCreature::GetAIName }, - { "GetScriptName", &LuaCreature::GetScriptName }, - { "GetAttackDistance", &LuaCreature::GetAttackDistance }, - { "GetAggroRange", &LuaCreature::GetAggroRange }, - { "GetDefaultMovementType", &LuaCreature::GetDefaultMovementType }, - { "GetRespawnDelay", &LuaCreature::GetRespawnDelay }, - { "GetWanderRadius", &LuaCreature::GetWanderRadius }, - { "GetCurrentWaypointId", &LuaCreature::GetCurrentWaypointId }, - { "GetLootRecipient", &LuaCreature::GetLootRecipient }, - { "GetLootRecipientGroup", &LuaCreature::GetLootRecipientGroup }, - { "GetNPCFlags", &LuaCreature::GetNPCFlags }, - { "GetExtraFlags", &LuaCreature::GetExtraFlags }, - { "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue }, - { "GetDBTableGUIDLow", &LuaCreature::GetDBTableGUIDLow }, - { "GetCreatureFamily", &LuaCreature::GetCreatureFamily }, - - // Setters - { "SetHover", &LuaCreature::SetHover }, - { "SetDisableGravity", &LuaCreature::SetDisableGravity }, - { "SetAggroEnabled", &LuaCreature::SetAggroEnabled }, - { "SetNoCallAssistance", &LuaCreature::SetNoCallAssistance }, - { "SetNoSearchAssistance", &LuaCreature::SetNoSearchAssistance }, - { "SetDefaultMovementType", &LuaCreature::SetDefaultMovementType }, - { "SetRespawnDelay", &LuaCreature::SetRespawnDelay }, - { "SetWanderRadius", &LuaCreature::SetWanderRadius }, - { "SetInCombatWithZone", &LuaCreature::SetInCombatWithZone }, - { "SetDisableReputationGain", &LuaCreature::SetDisableReputationGain }, - { "SetNPCFlags", &LuaCreature::SetNPCFlags }, - { "SetDeathState", &LuaCreature::SetDeathState }, - { "SetWalk", &LuaCreature::SetWalk }, - { "SetHomePosition", &LuaCreature::SetHomePosition }, - { "SetEquipmentSlots", &LuaCreature::SetEquipmentSlots }, - - // Boolean - { "IsRegeneratingHealth", &LuaCreature::IsRegeneratingHealth }, - { "IsWorldBoss", &LuaCreature::IsWorldBoss }, - { "IsRacialLeader", &LuaCreature::IsRacialLeader }, - { "IsCivilian", &LuaCreature::IsCivilian }, - { "IsGuard", &LuaCreature::IsGuard }, - { "IsElite", &LuaCreature::IsElite }, - { "IsInEvadeMode", &LuaCreature::IsInEvadeMode }, - { "HasCategoryCooldown", &LuaCreature::HasCategoryCooldown }, - { "CanWalk", &LuaCreature::CanWalk }, - { "CanSwim", &LuaCreature::CanSwim }, - { "CanAggro", &LuaCreature::CanAggro }, - { "HasSearchedAssistance", &LuaCreature::HasSearchedAssistance }, - { "IsTappedBy", &LuaCreature::IsTappedBy }, - { "HasLootRecipient", &LuaCreature::HasLootRecipient }, - { "CanAssistTo", &LuaCreature::CanAssistTo }, - { "IsTargetableForAttack", &LuaCreature::IsTargetableForAttack }, - { "CanCompleteQuest", &LuaCreature::CanCompleteQuest }, - { "IsReputationGainDisabled", &LuaCreature::IsReputationGainDisabled }, - { "HasSpell", &LuaCreature::HasSpell }, - { "HasQuest", &LuaCreature::HasQuest }, - { "HasSpellCooldown", &LuaCreature::HasSpellCooldown }, - { "CanFly", &LuaCreature::CanFly }, - - // Other - { "FleeToGetAssistance", &LuaCreature::FleeToGetAssistance }, - { "CallForHelp", &LuaCreature::CallForHelp }, - { "CallAssistance", &LuaCreature::CallAssistance }, - { "RemoveCorpse", &LuaCreature::RemoveCorpse }, - { "DespawnOrUnsummon", &LuaCreature::DespawnOrUnsummon }, - { "Respawn", &LuaCreature::Respawn }, - { "AttackStart", &LuaCreature::AttackStart }, - { "SaveToDB", &LuaCreature::SaveToDB }, - { "SelectVictim", &LuaCreature::SelectVictim }, - { "MoveWaypoint", &LuaCreature::MoveWaypoint }, - { "UpdateEntry", &LuaCreature::UpdateEntry }, - - // Not implemented methods - { "GetWaypointPath", nullptr, METHOD_REG_NONE }, // not implemented - { "GetLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "SetRegeneratingHealth", nullptr, METHOD_REG_NONE }, // not implemented - { "SetLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "SetReactState", nullptr, METHOD_REG_NONE }, // not implemented - { "IsDungeonBoss", nullptr, METHOD_REG_NONE }, // not implemented - { "IsTrigger", nullptr, METHOD_REG_NONE }, // not implemented - { "CanStartAttack", nullptr, METHOD_REG_NONE }, // not implemented - { "IsDamageEnoughForLootingAndReward", nullptr, METHOD_REG_NONE }, // not implemented - { "HasLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "AddLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "ResetLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveLootMode", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveFromWorld", nullptr, METHOD_REG_NONE }, // not implemented - { "GetRank", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/ElunaQueryMethods.h b/methods/Mangos/ElunaQueryMethods.h deleted file mode 100644 index 87ae0e5119..0000000000 --- a/methods/Mangos/ElunaQueryMethods.h +++ /dev/null @@ -1,345 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef QUERYMETHODS_H -#define QUERYMETHODS_H - -#define RESULT (*result) - -/*** - * The result of a database query. - * - * E.g. the return value of [Global:WorldDBQuery]. - * - * Inherits all methods from: none - */ -namespace LuaQuery -{ - static void CheckFields(Eluna* E, ElunaQuery* result) - { - uint32 field = E->CHECKVAL(2); - uint32 count = RESULT->GetFieldCount(); - if (field >= count) - { - char arr[256]; - sprintf(arr, "trying to access invalid field index %u. There are %u fields available and the indexes start from 0", field, count); - luaL_argerror(E->L, 2, arr); - } - } - - /** - * Returns `true` if the specified column of the current row is `NULL`, otherwise `false`. - * - * @param uint32 column - * @return bool isNull - */ - int IsNull(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - - E->Push(RESULT->Fetch()[col].IsNULL()); - return 1; - } - - /** - * Returns the number of columns in the result set. - * - * @return uint32 columnCount - */ - int GetColumnCount(Eluna* E, ElunaQuery* result) - { - E->Push(RESULT->GetFieldCount()); - return 1; - } - - /** - * Returns the number of rows in the result set. - * - * @return uint32 rowCount - */ - int GetRowCount(Eluna* E, ElunaQuery* result) - { - if (RESULT->GetRowCount() > (uint32)-1) - E->Push((uint32)-1); - else - E->Push((uint32)(RESULT->GetRowCount())); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a boolean. - * - * @param uint32 column - * @return bool data - */ - int GetBool(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetBool()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to an unsigned 8-bit integer. - * - * @param uint32 column - * @return uint8 data - */ - int GetUInt8(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetUInt8()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to an unsigned 16-bit integer. - * - * @param uint32 column - * @return uint16 data - */ - int GetUInt16(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetUInt16()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to an unsigned 32-bit integer. - * - * @param uint32 column - * @return uint32 data - */ - int GetUInt32(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetUInt32()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to an unsigned 64-bit integer. - * - * @param uint32 column - * @return uint64 data - */ - int GetUInt64(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetUInt64()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a signed 8-bit integer. - * - * @param uint32 column - * @return int8 data - */ - int GetInt8(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetInt8()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a signed 16-bit integer. - * - * @param uint32 column - * @return int16 data - */ - int GetInt16(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetInt16()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a signed 32-bit integer. - * - * @param uint32 column - * @return int32 data - */ - int GetInt32(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetInt32()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a signed 64-bit integer. - * - * @param uint32 column - * @return int64 data - */ - int GetInt64(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetInt64()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a 32-bit floating point value. - * - * @param uint32 column - * @return float data - */ - int GetFloat(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetFloat()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a 64-bit floating point value. - * - * @param uint32 column - * @return double data - */ - int GetDouble(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - E->Push(RESULT->Fetch()[col].GetDouble()); - return 1; - } - - /** - * Returns the data in the specified column of the current row, casted to a string. - * - * @param uint32 column - * @return string data - */ - int GetString(Eluna* E, ElunaQuery* result) - { - uint32 col = E->CHECKVAL(2); - CheckFields(E, result); - - E->Push(RESULT->Fetch()[col].GetString()); - return 1; - } - - /** - * Advances the [ElunaQuery] to the next row in the result set. - * - * *Do not* call this immediately after a query, or you'll skip the first row. - * - * Returns `false` if there was no new row, otherwise `true`. - * - * @return bool hadNextRow - */ - int NextRow(Eluna* E, ElunaQuery* result) - { - E->Push(RESULT->NextRow()); - return 1; - } - - /** - * Returns a table from the current row where keys are field names and values are the row's values. - * - * All numerical values will be numbers and everything else is returned as a string. - * - * **For example,** the query: - * - * SELECT entry, name FROM creature_template - * - * would result in a table like: - * - * { entry = 123, name = "some creature name" } - * - * To move to next row use [ElunaQuery:NextRow]. - * - * @return table rowData : table filled with row columns and data where `T[column] = data` - */ - int GetRow(Eluna* E, ElunaQuery* result) - { - uint32 col = RESULT->GetFieldCount(); - Field* row = RESULT->Fetch(); - - lua_createtable(E->L, 0, col); - int tbl = lua_gettop(E->L); - - const QueryFieldNames& names = RESULT->GetFieldNames(); - - for (uint32 i = 0; i < col; ++i) - { - E->Push(names[i]); - - const char* str = row[i].GetString(); - if (row[i].IsNULL() || !str) - E->Push(); - else - { - // MYSQL_TYPE_LONGLONG Interpreted as string for lua - switch (row[i].GetType()) - { - case MYSQL_TYPE_TINY: - case MYSQL_TYPE_SHORT: - case MYSQL_TYPE_INT24: - case MYSQL_TYPE_LONG: - case MYSQL_TYPE_FLOAT: - case MYSQL_TYPE_DOUBLE: - E->Push(strtod(str, NULL)); - break; - default: - E->Push(str); - break; - } - } - - lua_rawset(E->L, tbl); - } - - lua_settop(E->L, tbl); - return 1; - } - - ElunaRegister QueryMethods[] = - { - // Getters - { "GetColumnCount", &LuaQuery::GetColumnCount }, - { "GetRowCount", &LuaQuery::GetRowCount }, - { "GetRow", &LuaQuery::GetRow }, - { "GetBool", &LuaQuery::GetBool }, - { "GetUInt8", &LuaQuery::GetUInt8 }, - { "GetUInt16", &LuaQuery::GetUInt16 }, - { "GetUInt32", &LuaQuery::GetUInt32 }, - { "GetUInt64", &LuaQuery::GetUInt64 }, - { "GetInt8", &LuaQuery::GetInt8 }, - { "GetInt16", &LuaQuery::GetInt16 }, - { "GetInt32", &LuaQuery::GetInt32 }, - { "GetInt64", &LuaQuery::GetInt64 }, - { "GetFloat", &LuaQuery::GetFloat }, - { "GetDouble", &LuaQuery::GetDouble }, - { "GetString", &LuaQuery::GetString }, - - // Boolean - { "NextRow", &LuaQuery::NextRow }, - { "IsNull", &LuaQuery::IsNull }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#undef RESULT - -#endif diff --git a/methods/Mangos/GameObjectMethods.h b/methods/Mangos/GameObjectMethods.h deleted file mode 100644 index 503095a113..0000000000 --- a/methods/Mangos/GameObjectMethods.h +++ /dev/null @@ -1,345 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef GAMEOBJECTMETHODS_H -#define GAMEOBJECTMETHODS_H - -/*** - * Inherits all methods from: [Object], [WorldObject] - */ -namespace LuaGameObject -{ - /** - * Returns 'true' if the [GameObject] can give the specified [Quest] - * - * @param uint32 questId : quest entry Id to check - * @return bool hasQuest - */ - int HasQuest(Eluna* E, GameObject* go) - { - uint32 questId = E->CHECKVAL(2); - - E->Push(go->HasQuest(questId)); - return 1; - } - - /** - * Returns 'true' if the [GameObject] is spawned - * - * @return bool isSpawned - */ - int IsSpawned(Eluna* E, GameObject* go) - { - E->Push(go->isSpawned()); - return 1; - } - - /** - * Returns 'true' if the [GameObject] is a transport - * - * @return bool isTransport - */ - int IsTransport(Eluna* E, GameObject* go) - { - E->Push(go->IsTransport()); - return 1; - } - - /** - * Returns 'true' if the [GameObject] is active - * - * @return bool isActive - */ - int IsActive(Eluna* E, GameObject* go) - { - E->Push(go->isActiveObject()); - return 1; - } - - /*int IsDestructible(Eluna* E, GameObject* go) // TODO: Implementation core side - { - E->Push(go->IsDestructibleBuilding()); - return 1; - }*/ - - /** - * Returns display ID of the [GameObject] - * - * @return uint32 displayId - */ - int GetDisplayId(Eluna* E, GameObject* go) - { - E->Push(go->GetDisplayId()); - return 1; - } - - /** - * Returns the state of a [GameObject] - * Below are client side [GOState]s off of 3.3.5a - * - *
-     * enum GOState
-     * {
-     *     GO_STATE_ACTIVE             = 0,                        // show in world as used and not reset (closed door open)
-     *     GO_STATE_READY              = 1,                        // show in world as ready (closed door close)
-     *     GO_STATE_ACTIVE_ALTERNATIVE = 2                         // show in world as used in alt way and not reset (closed door open by cannon fire)
-     * };
-     * 
- * - * @return [GOState] goState - */ - int GetGoState(Eluna* E, GameObject* go) - { - E->Push(go->GetGoState()); - return 1; - } - - /** - * Returns the [LootState] of a [GameObject] - * Below are [LootState]s off of 3.3.5a - * - *
-     * enum LootState
-     * {
-     *     GO_NOT_READY = 0,
-     *     GO_READY,                                               // can be ready but despawned, and then not possible activate until spawn
-     *     GO_ACTIVATED,
-     *     GO_JUST_DEACTIVATED
-     * };
-     * 
- * - * @return [LootState] lootState - */ - int GetLootState(Eluna* E, GameObject* go) - { - E->Push(go->getLootState()); - return 1; - } - - /** - * Returns the [Player] that can loot the [GameObject] - * - * Not the original looter and may be nil. - * - * @return [Player] player - */ - int GetLootRecipient(Eluna* E, GameObject* go) - { - E->Push(go->GetLootRecipient()); - return 1; - } - - /** - * Returns the [Group] that can loot the [GameObject] - * - * Not the original looter and may be nil. - * - * @return [Group] group - */ - int GetLootRecipientGroup(Eluna* E, GameObject* go) - { - E->Push(go->GetGroupLootRecipient()); - return 1; - } - - /** - * Returns the guid of the [GameObject] that is used as the ID in the database - * - * @return uint32 dbguid - */ - int GetDBTableGUIDLow(Eluna* E, GameObject* go) - { - // on mangos based this is same as lowguid - E->Push(go->GetGUIDLow()); - return 1; - } - - /** - * Sets the state of a [GameObject] - * - *
-     * enum GOState
-     * {
-     *     GO_STATE_ACTIVE             = 0,                        // show in world as used and not reset (closed door open)
-     *     GO_STATE_READY              = 1,                        // show in world as ready (closed door close)
-     *     GO_STATE_ACTIVE_ALTERNATIVE = 2                         // show in world as used in alt way and not reset (closed door open by cannon fire)
-     * };
-     * 
- * - * @param [GOState] state : all available go states can be seen above - */ - int SetGoState(Eluna* E, GameObject* go) - { - uint32 state = E->CHECKVAL(2, 0); - - if (state == 0) - go->SetGoState(GO_STATE_ACTIVE); - else if (state == 1) - go->SetGoState(GO_STATE_READY); - else if (state == 2) - go->SetGoState(GO_STATE_ACTIVE_ALTERNATIVE); - - return 0; - } - - /** - * Sets the [LootState] of a [GameObject] - * Below are [LootState]s off of 3.3.5a - * - *
-     * enum LootState
-     * {
-     *     GO_NOT_READY = 0,
-     *     GO_READY,                                               // can be ready but despawned, and then not possible activate until spawn
-     *     GO_ACTIVATED,
-     *     GO_JUST_DEACTIVATED
-     * };
-     * 
- * - * @param [LootState] state : all available loot states can be seen above - */ - int SetLootState(Eluna* E, GameObject* go) - { - uint32 state = E->CHECKVAL(2, 0); - - if (state == 0) - go->SetLootState(GO_NOT_READY); - else if (state == 1) - go->SetLootState(GO_READY); - else if (state == 2) - go->SetLootState(GO_ACTIVATED); - else if (state == 3) - go->SetLootState(GO_JUST_DEACTIVATED); - - return 0; - } - - /** - * Saves [GameObject] to the database - * - */ - int SaveToDB(Eluna* /*E*/, GameObject* go) - { - go->SaveToDB(); - return 0; - } - - /** - * Removes [GameObject] from the world - * - * The object is no longer reachable after this and it is not respawned. - * - * @param bool deleteFromDB : if true, it will delete the [GameObject] from the database - */ - int RemoveFromWorld(Eluna* E, GameObject* go) - { - bool deldb = E->CHECKVAL(2, false); - - // cs_gobject.cpp copy paste - ObjectGuid ownerGuid = go->GetOwnerGuid(); - - if (ownerGuid) - { - Unit* owner = eObjectAccessor()GetUnit(*go, ownerGuid); - if (!owner || !ownerGuid.IsPlayer()) - return 0; - - owner->RemoveGameObject(go, false); - } - - if (deldb) - go->DeleteFromDB(); - - go->SetRespawnTime(0); - go->Delete(); - - E->CHECKOBJ(1)->Invalidate(); - return 0; - } - - /** - * Activates a door or a button/lever - * - * @param uint32 delay = 0 : cooldown time in seconds to restore the [GameObject] back to normal. 0 for infinite duration - */ - int UseDoorOrButton(Eluna* E, GameObject* go) - { - uint32 delay = E->CHECKVAL(2, 0); - - go->UseDoorOrButton(delay); - return 0; - } - - /** - * Despawns a [GameObject] - * - * The gameobject may be automatically respawned by the core - */ - int Despawn(Eluna* /*E*/, GameObject* go) - { - go->SetLootState(GO_JUST_DEACTIVATED); - return 0; - } - - /** - * Respawns a [GameObject] - */ - int Respawn(Eluna* /*E*/, GameObject* go) - { - go->Respawn(); - return 0; - } - - /** - * Sets the respawn or despawn time for the gameobject. - * - * Respawn time is also used as despawn time depending on gameobject settings - * - * @param int32 delay = 0 : cooldown time in seconds to respawn or despawn the object. 0 means never - */ - int SetRespawnTime(Eluna* E, GameObject* go) - { - int32 respawn = E->CHECKVAL(2); - - go->SetRespawnTime(respawn); - return 0; - } - - ElunaRegister GameObjectMethods[] = - { - // Getters - { "GetDisplayId", &LuaGameObject::GetDisplayId }, - { "GetGoState", &LuaGameObject::GetGoState }, - { "GetLootState", &LuaGameObject::GetLootState }, - { "GetLootRecipient", &LuaGameObject::GetLootRecipient }, - { "GetLootRecipientGroup", &LuaGameObject::GetLootRecipientGroup }, - { "GetDBTableGUIDLow", &LuaGameObject::GetDBTableGUIDLow }, - - // Setters - { "SetGoState", &LuaGameObject::SetGoState }, - { "SetLootState", &LuaGameObject::SetLootState }, - { "SetRespawnTime", &LuaGameObject::SetRespawnTime }, - - // Boolean - { "IsTransport", &LuaGameObject::IsTransport }, - { "IsActive", &LuaGameObject::IsActive }, - { "HasQuest", &LuaGameObject::HasQuest }, - { "IsSpawned", &LuaGameObject::IsSpawned }, - - // Other - { "RemoveFromWorld", &LuaGameObject::RemoveFromWorld }, - { "UseDoorOrButton", &LuaGameObject::UseDoorOrButton }, - { "Despawn", &LuaGameObject::Despawn }, - { "Respawn", &LuaGameObject::Respawn }, - { "SaveToDB", &LuaGameObject::SaveToDB }, - - // Not implemented methods - { "IsDestructible", nullptr, METHOD_REG_NONE }, // Not implemented - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/GlobalMethods.h b/methods/Mangos/GlobalMethods.h deleted file mode 100644 index 6271b66ba3..0000000000 --- a/methods/Mangos/GlobalMethods.h +++ /dev/null @@ -1,3047 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef GLOBALMETHODS_H -#define GLOBALMETHODS_H - -#include "BindingMap.h" - -/*** - * These functions can be used anywhere at any time, including at start-up. - */ -namespace LuaGlobalFunctions -{ - /** - * Returns Lua engine's name. - * - * Always returns "ElunaEngine" on Eluna. - * - * @return string engineName - */ - int GetLuaEngine(Eluna* E) - { - E->Push("ElunaEngine"); - return 1; - } - - /** - * Returns emulator's name. - * - * The result will be either `MaNGOS`, `cMaNGOS`, or `TrinityCore`. - * - * @return string coreName - */ - int GetCoreName(Eluna* E) - { - E->Push(CORE_NAME); - return 1; - } - - /** - * Returns emulator .conf RealmID - * - * - for MaNGOS returns the realmID as it is stored in the core. - * - for TrinityCore returns the realmID as it is in the conf file. - * @return uint32 realm ID - */ - - int GetRealmID(Eluna* E) - { - E->Push(realmID); - return 1; - } - - /** - * Returns emulator version - * - * - For TrinityCore returns the date of the last revision, e.g. `2015-08-26 22:53:12 +0300` - * - For cMaNGOS returns the date and time of the last revision, e.g. `2015-09-06 13:18:50` - * - for MaNGOS returns the version number as string, e.g. `21000` - * - * @return string version - */ - int GetCoreVersion(Eluna* E) - { - E->Push(GitRevision::GetProjectRevision()); - return 1; - } - - /** - * Returns emulator's supported expansion. - * - * Expansion is 0 for pre-TBC, 1 for TBC, 2 for WotLK, and 3 for Cataclysm. - * - * @return int32 expansion - */ - int GetCoreExpansion(Eluna* E) - { -#ifdef CLASSIC - E->Push(0); -#elif defined(TBC) - E->Push(1); -#elif defined(WOTLK) - E->Push(2); -#elif defined(CATA) - E->Push(3); -#endif - return 1; - } - - /** - * Returns the [Map] pointer of the Lua state. Returns null for the "World" state. - * - * @return [Map] map - */ - int GetStateMap(Eluna* E) - { - E->Push(E->GetBoundMap()); - return 1; - } - - /** - * Returns the map ID of the Lua state. Returns -1 for the "World" state. - * - * @return int32 mapId - */ - int GetStateMapId(Eluna* E) - { - E->Push(E->GetBoundMapId()); - return 1; - } - - /** - * Returns the instance ID of the Lua state. Returns 0 for continent maps and the world state. - * - * @return uint32 instanceId - */ - int GetStateInstanceId(Eluna* E) - { - E->Push(E->GetBoundInstanceId()); - return 1; - } - - /** - * Returns [Quest] template - * - * @param uint32 questId : [Quest] entry ID - * @return [Quest] quest - */ - int GetQuest(Eluna* E) - { - uint32 questId = E->CHECKVAL(1); - - E->Push(eObjectMgr->GetQuestTemplate(questId)); - return 1; - } - - /** - * Finds and Returns [Player] by guid if found - * - * @param ObjectGuid guid : guid of the [Player], you can get it with [Object:GetGUID] - * @return [Player] player - */ - int GetPlayerByGUID(Eluna* E) - { - ObjectGuid guid = E->CHECKVAL(1); - E->Push(eObjectAccessor()FindPlayer(guid)); - return 1; - } - - /** - * Finds and Returns [Player] by name if found - * - * @param string name : name of the [Player] - * @return [Player] player - */ - int GetPlayerByName(Eluna* E) - { - const char* name = E->CHECKVAL(1); - E->Push(eObjectAccessor()FindPlayerByName(name)); - return 1; - } - - /** - * Returns game time in seconds - * - * @return uint32 time - */ - int GetGameTime(Eluna* E) - { - E->Push(uint32(eWorld->GetGameTime())); - return 1; - } - - /** - * Returns a table with all the current [Player]s in the world - * - * Does not return players that may be teleporting or otherwise not on any map. - * - * enum TeamId - * { - * TEAM_ALLIANCE = 0, - * TEAM_HORDE = 1, - * TEAM_NEUTRAL = 2 - * }; - * - * @param [TeamId] team = TEAM_NEUTRAL : optional check team of the [Player], Alliance, Horde or Neutral (All) - * @param bool onlyGM = false : optional check if GM only - * @return table worldPlayers - */ - int GetPlayersInWorld(Eluna* E) - { - uint32 team = E->CHECKVAL(1, TEAM_NEUTRAL); - bool onlyGM = E->CHECKVAL(2, false); - - lua_newtable(E->L); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - eObjectAccessor()DoForAllPlayers([&](Player* player){ - if(player->IsInWorld()) - { - if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster())) - { - E->Push(player); - lua_rawseti(E->L, tbl, ++i); - } - } - }); - - lua_settop(E->L, tbl); // push table to top of stack - return 1; - } - - /** - * Returns a [Guild] by name. - * - * @param string name - * @return [Guild] guild : the Guild, or `nil` if it doesn't exist - */ - int GetGuildByName(Eluna* E) - { - const char* name = E->CHECKVAL(1); - E->Push(eGuildMgr->GetGuildByName(name)); - return 1; - } - - /** - * Returns a [Map] by ID. - * - * @param uint32 mapId : see [Map.dbc](https://github.com/cmangos/issues/wiki/Map.dbc) - * @param uint32 instanceId = 0 : required if the map is an instance, otherwise don't pass anything - * @return [Map] map : the Map, or `nil` if it doesn't exist - */ - int GetMapById(Eluna* E) - { - uint32 mapid = E->CHECKVAL(1); - uint32 instance = E->CHECKVAL(2, 0); - - E->Push(eMapMgr->FindMap(mapid, instance)); - return 1; - } - - /** - * Returns [Guild] by the leader's GUID - * - * @param ObjectGuid guid : the guid of a [Guild] leader - * @return [Guild] guild, or `nil` if it doesn't exist - */ - int GetGuildByLeaderGUID(Eluna* E) - { - ObjectGuid guid = E->CHECKVAL(1); - - E->Push(eGuildMgr->GetGuildByLeader(guid)); - return 1; - } - - /** - * Returns the amount of [Player]s in the world. - * - * @return uint32 count - */ - int GetPlayerCount(Eluna* E) - { - E->Push(eWorld->GetActiveSessionCount()); - return 1; - } - - /** - * Builds a [Player]'s GUID - * - * [Player] GUID consist of low GUID and type ID - * - * [Player] and [Creature] for example can have the same low GUID but not GUID. - * - * @param uint32 lowguid : low GUID of the [Player] - * @return ObjectGuid guid - */ - int GetPlayerGUID(Eluna* E) - { - uint32 lowguid = E->CHECKVAL(1); - E->Push(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); - return 1; - } - - /** - * Builds an [Item]'s GUID. - * - * [Item] GUID consist of low GUID and type ID - * [Player] and [Item] for example can have the same low GUID but not GUID. - * - * @param uint32 lowguid : low GUID of the [Item] - * @return ObjectGuid guid - */ - int GetItemGUID(Eluna* E) - { - uint32 lowguid = E->CHECKVAL(1); - E->Push(MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM)); - return 1; - } - - /** - * Builds a [GameObject]'s GUID. - * - * A GameObject's GUID consist of entry ID, low GUID and type ID - * - * A [Player] and GameObject for example can have the same low GUID but not GUID. - * - * @param uint32 lowguid : low GUID of the [GameObject] - * @param uint32 entry : entry ID of the [GameObject] - * @return ObjectGuid guid - */ - int GetObjectGUID(Eluna* E) - { - uint32 lowguid = E->CHECKVAL(1); - uint32 entry = E->CHECKVAL(2); - E->Push(MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); - return 1; - } - - /** - * Builds a [Creature]'s GUID. - * - * [Creature] GUID consist of entry ID, low GUID and type ID - * - * [Player] and [Creature] for example can have the same low GUID but not GUID. - * - * @param uint32 lowguid : low GUID of the [Creature] - * @param uint32 entry : entry ID of the [Creature] - * @return ObjectGuid guid - */ - int GetUnitGUID(Eluna* E) - { - uint32 lowguid = E->CHECKVAL(1); - uint32 entry = E->CHECKVAL(2); - E->Push(MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT)); - return 1; - } - - /** - * Returns the low GUID from a GUID. - * - * A GUID consists of a low GUID, type ID, and possibly an entry ID depending on the type ID. - * - * Low GUID is an ID to distinct the objects of the same type. - * - * [Player] and [Creature] for example can have the same low GUID but not GUID. - * - * On TrinityCore all low GUIDs are different for all objects of the same type. - * For example creatures in instances are assigned new GUIDs when the Map is created. - * - * On MaNGOS and cMaNGOS low GUIDs are unique only on the same map. - * For example creatures in instances use the same low GUID assigned for that spawn in the database. - * This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId] - * - * @param ObjectGuid guid : GUID of an [Object] - * @return uint32 lowguid : low GUID of the [Object] - */ - int GetGUIDLow(Eluna* E) - { - ObjectGuid guid = E->CHECKVAL(1); - - E->Push(guid.GetCounter()); - return 1; - } - - /** - * Returns an chat link for an [Item]. - * - * enum LocaleConstant - * { - * LOCALE_enUS = 0, - * LOCALE_koKR = 1, - * LOCALE_frFR = 2, - * LOCALE_deDE = 3, - * LOCALE_zhCN = 4, - * LOCALE_zhTW = 5, - * LOCALE_esES = 6, - * LOCALE_esMX = 7, - * LOCALE_ruRU = 8 - * }; - * - * @param uint32 entry : entry ID of an [Item] - * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Item] name in - * @return string itemLink - */ - int GetItemLink(Eluna* E) - { - uint32 entry = E->CHECKVAL(1); - uint8 locale = E->CHECKVAL(2, DEFAULT_LOCALE); - if (locale >= TOTAL_LOCALES) - return luaL_argerror(E->L, 2, "valid LocaleConstant expected"); - - const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry); - if (!temp) - return luaL_argerror(E->L, 1, "valid ItemEntry expected"); - - std::string name = temp->Name1; - if (ItemLocale const* il = eObjectMgr->GetItemLocale(entry)) - ObjectMgr::GetLocaleString(il->Name, static_cast(locale), name); - - std::ostringstream oss; - oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec << - "|Hitem:" << entry << ":0:" << -#ifndef CLASSIC - "0:0:0:0:" << -#endif - "0:0:0:0|h[" << name << "]|h|r"; - - E->Push(oss.str()); - return 1; - } - - /** - * Returns the type ID from a GUID. - * - * Type ID is different for each type ([Player], [Creature], [GameObject], etc.). - * - * GUID consist of entry ID, low GUID, and type ID. - * - * @param ObjectGuid guid : GUID of an [Object] - * @return int32 typeId : type ID of the [Object] - */ - int GetGUIDType(Eluna* E) - { - ObjectGuid guid = E->CHECKVAL(1); - E->Push(static_cast(guid.GetHigh())); - return 1; - } - - /** - * Returns the entry ID from a GUID. - * - * GUID consist of entry ID, low GUID, and type ID. - * - * @param ObjectGuid guid : GUID of an [Creature] or [GameObject] - * @return uint32 entry : entry ID, or `0` if `guid` is not a [Creature] or [GameObject] - */ - int GetGUIDEntry(Eluna* E) - { - ObjectGuid guid = E->CHECKVAL(1); - E->Push(guid.GetEntry()); - return 1; - } - - /** - * Returns the area or zone's name. - * - * enum LocaleConstant - * { - * LOCALE_enUS = 0, - * LOCALE_koKR = 1, - * LOCALE_frFR = 2, - * LOCALE_deDE = 3, - * LOCALE_zhCN = 4, - * LOCALE_zhTW = 5, - * LOCALE_esES = 6, - * LOCALE_esMX = 7, - * LOCALE_ruRU = 8 - * }; - * - * @param uint32 areaOrZoneId : area ID or zone ID - * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the name in - * @return string areaOrZoneName - */ - int GetAreaName(Eluna* E) - { - uint32 areaOrZoneId = E->CHECKVAL(1); - uint8 locale = E->CHECKVAL(2, DEFAULT_LOCALE); - if (locale >= TOTAL_LOCALES) - return luaL_argerror(E->L, 2, "valid LocaleConstant expected"); - - AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaOrZoneId); - if (!areaEntry) - return luaL_argerror(E->L, 1, "valid Area or Zone ID expected"); - - E->Push(areaEntry->area_name[locale]); - return 1; - } - - /** - * Returns the currently active game events. - * - * @return table activeEvents - */ - int GetActiveGameEvents(Eluna* E) - { - lua_newtable(E->L); - int tbl = lua_gettop(E->L); - uint32 counter = 1; - GameEventMgr::ActiveEvents const& activeEvents = eGameEventMgr->GetActiveEventList(); - - for (GameEventMgr::ActiveEvents::const_iterator i = activeEvents.begin(); i != activeEvents.end(); ++i) - { - E->Push(*i); - lua_rawseti(E->L, tbl, counter); - - counter++; - } - - lua_settop(E->L, tbl); - return 1; - } - - static int RegisterEntryHelper(Eluna* E, int regtype) - { - uint32 id = E->CHECKVAL(1); - uint32 ev = E->CHECKVAL(2); - luaL_checktype(E->L, 3, LUA_TFUNCTION); - uint32 shots = E->CHECKVAL(4, 0); - - lua_pushvalue(E->L, 3); - int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX); - if (functionRef >= 0) - return E->Register(regtype, id, ObjectGuid(), 0, ev, functionRef, shots); - else - luaL_argerror(E->L, 3, "unable to make a ref to function"); - return 0; - } - - static int RegisterEventHelper(Eluna* E, int regtype) - { - uint32 ev = E->CHECKVAL(1); - luaL_checktype(E->L, 2, LUA_TFUNCTION); - uint32 shots = E->CHECKVAL(3, 0); - - lua_pushvalue(E->L, 2); - int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX); - if (functionRef >= 0) - return E->Register(regtype, 0, ObjectGuid(), 0, ev, functionRef, shots); - else - luaL_argerror(E->L, 2, "unable to make a ref to function"); - return 0; - } - - static int RegisterUniqueHelper(Eluna* E, int regtype) - { - ObjectGuid guid = E->CHECKVAL(1); - uint32 instanceId = E->CHECKVAL(2); - uint32 ev = E->CHECKVAL(3); - luaL_checktype(E->L, 4, LUA_TFUNCTION); - uint32 shots = E->CHECKVAL(5, 0); - - lua_pushvalue(E->L, 4); - int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX); - if (functionRef >= 0) - return E->Register(regtype, 0, guid, instanceId, ev, functionRef, shots); - else - luaL_argerror(E->L, 4, "unable to make a ref to function"); - return 0; - } - - /** - * Registers a server event handler. - * - * enum ServerEvents - * { - * // Server - * SERVER_EVENT_ON_NETWORK_START = 1, // Not Implemented - * SERVER_EVENT_ON_NETWORK_STOP = 2, // Not Implemented - * SERVER_EVENT_ON_SOCKET_OPEN = 3, // Not Implemented - * SERVER_EVENT_ON_SOCKET_CLOSE = 4, // Not Implemented - * SERVER_EVENT_ON_PACKET_RECEIVE = 5, // (event, packet, player) - Player only if accessible. Can return false, newPacket - * SERVER_EVENT_ON_PACKET_RECEIVE_UNKNOWN = 6, // Not Implemented - * SERVER_EVENT_ON_PACKET_SEND = 7, // (event, packet, player) - Player only if accessible. Can return false - * - * // World - * WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) - Needs core support on Mangos - * WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload) - * // UNUSED = 10, - * WORLD_EVENT_ON_SHUTDOWN_INIT = 11, // (event, code, mask) - * WORLD_EVENT_ON_SHUTDOWN_CANCEL = 12, // (event) - * WORLD_EVENT_ON_UPDATE = 13, // (event, diff) - * WORLD_EVENT_ON_STARTUP = 14, // (event) - * WORLD_EVENT_ON_SHUTDOWN = 15, // (event) - * - * // Eluna - * ELUNA_EVENT_ON_LUA_STATE_CLOSE = 16, // (event) - triggers just before shutting down eluna (on shutdown and restart) - * - * // Map - * MAP_EVENT_ON_CREATE = 17, // (event, map) - * MAP_EVENT_ON_DESTROY = 18, // (event, map) - * MAP_EVENT_ON_GRID_LOAD = 19, // Not Implemented - * MAP_EVENT_ON_GRID_UNLOAD = 20, // Not Implemented - * MAP_EVENT_ON_PLAYER_ENTER = 21, // (event, map, player) - * MAP_EVENT_ON_PLAYER_LEAVE = 22, // (event, map, player) - * MAP_EVENT_ON_UPDATE = 23, // (event, map, diff) - * - * // Area trigger - * TRIGGER_EVENT_ON_TRIGGER = 24, // (event, player, triggerId) - Can return true - * - * // Weather - * WEATHER_EVENT_ON_CHANGE = 25, // (event, zoneId, state, grade) - * - * // Auction house - * AUCTION_EVENT_ON_ADD = 26, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow) - * AUCTION_EVENT_ON_REMOVE = 27, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow) - * AUCTION_EVENT_ON_SUCCESSFUL = 28, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow) - * AUCTION_EVENT_ON_EXPIRE = 29, // (event, auctionId, owner, item, expireTime, buyout, startBid, currentBid, bidderGUIDLow) - * - * // AddOns - * ADDON_EVENT_ON_MESSAGE = 30, // (event, sender, type, prefix, msg, target) - target can be nil/whisper_target/guild/group/channel. Can return false - * - * WORLD_EVENT_ON_DELETE_CREATURE = 31, // (event, creature) - * WORLD_EVENT_ON_DELETE_GAMEOBJECT = 32, // (event, gameobject) - * - * // Eluna - * ELUNA_EVENT_ON_LUA_STATE_OPEN = 33, // (event) - triggers after all scripts are loaded - * - * GAME_EVENT_START = 34, // (event, gameeventid) - * GAME_EVENT_STOP = 35, // (event, gameeventid) - * }; - * - * @proto cancel = (event, function) - * @proto cancel = (event, function, shots) - * - * @param uint32 event : server event ID, refer to ServerEvents above - * @param function function : function that will be called when the event occurs - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterServerEvent(Eluna* E) - { - return RegisterEventHelper(E, Hooks::REGTYPE_SERVER); - } - - /** - * Registers a [Player] event handler. - * - *
-     * enum PlayerEvents
-     * {
-     *     PLAYER_EVENT_ON_CHARACTER_CREATE        =     1,        // (event, player)
-     *     PLAYER_EVENT_ON_CHARACTER_DELETE        =     2,        // (event, guid)
-     *     PLAYER_EVENT_ON_LOGIN                   =     3,        // (event, player)
-     *     PLAYER_EVENT_ON_LOGOUT                  =     4,        // (event, player)
-     *     PLAYER_EVENT_ON_SPELL_CAST              =     5,        // (event, player, spell, skipCheck)
-     *     PLAYER_EVENT_ON_KILL_PLAYER             =     6,        // (event, killer, killed)
-     *     PLAYER_EVENT_ON_KILL_CREATURE           =     7,        // (event, killer, killed)
-     *     PLAYER_EVENT_ON_KILLED_BY_CREATURE      =     8,        // (event, killer, killed)
-     *     PLAYER_EVENT_ON_DUEL_REQUEST            =     9,        // (event, target, challenger)
-     *     PLAYER_EVENT_ON_DUEL_START              =     10,       // (event, player1, player2)
-     *     PLAYER_EVENT_ON_DUEL_END                =     11,       // (event, winner, loser, type)
-     *     PLAYER_EVENT_ON_GIVE_XP                 =     12,       // (event, player, amount, victim) - Can return new XP amount
-     *     PLAYER_EVENT_ON_LEVEL_CHANGE            =     13,       // (event, player, oldLevel)
-     *     PLAYER_EVENT_ON_MONEY_CHANGE            =     14,       // (event, player, amount) - Can return new money amount
-     *     PLAYER_EVENT_ON_REPUTATION_CHANGE       =     15,       // (event, player, factionId, standing, incremental) - Can return new standing
-     *     PLAYER_EVENT_ON_TALENTS_CHANGE          =     16,       // (event, player, points)
-     *     PLAYER_EVENT_ON_TALENTS_RESET           =     17,       // (event, player, noCost)
-     *     PLAYER_EVENT_ON_CHAT                    =     18,       // (event, player, msg, Type, lang) - Can return false, newMessage
-     *     PLAYER_EVENT_ON_WHISPER                 =     19,       // (event, player, msg, Type, lang, receiver) - Can return false, newMessage
-     *     PLAYER_EVENT_ON_GROUP_CHAT              =     20,       // (event, player, msg, Type, lang, group) - Can return false, newMessage
-     *     PLAYER_EVENT_ON_GUILD_CHAT              =     21,       // (event, player, msg, Type, lang, guild) - Can return false, newMessage
-     *     PLAYER_EVENT_ON_CHANNEL_CHAT            =     22,       // (event, player, msg, Type, lang, channel) - Can return false, newMessage
-     *     PLAYER_EVENT_ON_EMOTE                   =     23,       // (event, player, emote) - Not triggered on any known emote
-     *     PLAYER_EVENT_ON_TEXT_EMOTE              =     24,       // (event, player, textEmote, emoteNum, guid)
-     *     PLAYER_EVENT_ON_SAVE                    =     25,       // (event, player)
-     *     PLAYER_EVENT_ON_BIND_TO_INSTANCE        =     26,       // (event, player, difficulty, mapid, permanent)
-     *     PLAYER_EVENT_ON_UPDATE_ZONE             =     27,       // (event, player, newZone, newArea)
-     *     PLAYER_EVENT_ON_MAP_CHANGE              =     28,       // (event, player)
-     *
-     *     // Custom
-     *     PLAYER_EVENT_ON_EQUIP                   =     29,       // (event, player, item, bag, slot)
-     *     PLAYER_EVENT_ON_FIRST_LOGIN             =     30,       // (event, player)
-     *     PLAYER_EVENT_ON_CAN_USE_ITEM            =     31,       // (event, player, itemEntry) - Can return InventoryResult enum value
-     *     PLAYER_EVENT_ON_LOOT_ITEM               =     32,       // (event, player, item, count)
-     *     PLAYER_EVENT_ON_ENTER_COMBAT            =     33,       // (event, player, enemy)
-     *     PLAYER_EVENT_ON_LEAVE_COMBAT            =     34,       // (event, player)
-     *     PLAYER_EVENT_ON_REPOP                   =     35,       // (event, player)
-     *     PLAYER_EVENT_ON_RESURRECT               =     36,       // (event, player)
-     *     PLAYER_EVENT_ON_LOOT_MONEY              =     37,       // (event, player, amount)
-     *     PLAYER_EVENT_ON_QUEST_ABANDON           =     38,       // (event, player, questId)
-     *     PLAYER_EVENT_ON_LEARN_TALENTS           =     39,       // (event, player, talentId, talentRank, spellid)
-     *     // UNUSED                               =     40,       // (event, player)
-     *     // UNUSED                               =     41,       // (event, player)
-     *     PLAYER_EVENT_ON_COMMAND                 =     42,       // (event, player, command) - player is nil if command used from console. Can return false
-     * };
-     * 
- * - * @proto cancel = (event, function) - * @proto cancel = (event, function, shots) - * - * @param uint32 event : [Player] event Id, refer to PlayerEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterPlayerEvent(Eluna* E) - { - return RegisterEventHelper(E, Hooks::REGTYPE_PLAYER); - } - - /** - * Registers a [Guild] event handler. - * - *
-     * enum GuildEvents
-     * {
-     *     // Guild
-     *     GUILD_EVENT_ON_ADD_MEMBER               =     1,       // (event, guild, player, rank)
-     *     GUILD_EVENT_ON_REMOVE_MEMBER            =     2,       // (event, guild, player, isDisbanding)
-     *     GUILD_EVENT_ON_MOTD_CHANGE              =     3,       // (event, guild, newMotd)
-     *     GUILD_EVENT_ON_INFO_CHANGE              =     4,       // (event, guild, newInfo)
-     *     GUILD_EVENT_ON_CREATE                   =     5,       // (event, guild, leader, name)  // Not on TC
-     *     GUILD_EVENT_ON_DISBAND                  =     6,       // (event, guild)
-     *     GUILD_EVENT_ON_MONEY_WITHDRAW           =     7,       // (event, guild, player, amount, isRepair) - Can return new money amount
-     *     GUILD_EVENT_ON_MONEY_DEPOSIT            =     8,       // (event, guild, player, amount) - Can return new money amount
-     *     GUILD_EVENT_ON_ITEM_MOVE                =     9,       // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId)   // TODO
-     *     GUILD_EVENT_ON_EVENT                    =     10,      // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank)  // TODO
-     *     GUILD_EVENT_ON_BANK_EVENT               =     11,      // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId)
-     *
-     *     GUILD_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (event, function) - * @proto cancel = (event, function, shots) - * - * @param uint32 event : [Guild] event Id, refer to GuildEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterGuildEvent(Eluna* E) - { - return RegisterEventHelper(E, Hooks::REGTYPE_GUILD); - } - - /** - * Registers a [Group] event handler. - * - *
-     * enum GroupEvents
-     * {
-     *     // Group
-     *     GROUP_EVENT_ON_MEMBER_ADD               =     1,       // (event, group, guid)
-     *     GROUP_EVENT_ON_MEMBER_INVITE            =     2,       // (event, group, guid)
-     *     GROUP_EVENT_ON_MEMBER_REMOVE            =     3,       // (event, group, guid, method, kicker, reason)
-     *     GROUP_EVENT_ON_LEADER_CHANGE            =     4,       // (event, group, newLeaderGuid, oldLeaderGuid)
-     *     GROUP_EVENT_ON_DISBAND                  =     5,       // (event, group)
-     *     GROUP_EVENT_ON_CREATE                   =     6,       // (event, group, leaderGuid, groupType)
-     *
-     *     GROUP_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (event, function) - * @proto cancel = (event, function, shots) - * - * @param uint32 event : [Group] event Id, refer to GroupEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterGroupEvent(Eluna* E) - { - return RegisterEventHelper(E, Hooks::REGTYPE_GROUP); - } - - /** - * Registers a [BattleGround] event handler. - * - *
-     * enum BGEvents
-     * {
-     *     BG_EVENT_ON_START                               = 1,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_ON_END                                 = 2,    // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
-     *     BG_EVENT_ON_CREATE                              = 3,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_ON_PRE_DESTROY                         = 4,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (event, function) - * @proto cancel = (event, function, shots) - * - * @param uint32 event : [BattleGround] event Id, refer to BGEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterBGEvent(Eluna* E) - { - return RegisterEventHelper(E, Hooks::REGTYPE_BG); - } - - /** - * Registers a [WorldPacket] event handler. - * - *
-     * enum PacketEvents
-     * {
-     *     PACKET_EVENT_ON_PACKET_RECEIVE          =     5,       // (event, packet, player) - Player only if accessible. Can return false, newPacket
-     *     PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN  =     6,       // Not Implemented
-     *     PACKET_EVENT_ON_PACKET_SEND             =     7,       // (event, packet, player) - Player only if accessible. Can return false
-     *
-     *     PACKET_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : opcode - * @param uint32 event : packet event Id, refer to PacketEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterPacketEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_PACKET); - } - - /** - * Registers a [Creature] gossip event handler. - * - *
-     * enum GossipEvents
-     * {
-     *     GOSSIP_EVENT_ON_HELLO                           = 1,    // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
-     *     GOSSIP_EVENT_ON_SELECT                          = 2,    // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
-     *     GOSSIP_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : [Creature] entry Id - * @param uint32 event : [Creature] gossip event Id, refer to GossipEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterCreatureGossipEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_CREATURE_GOSSIP); - } - - /** - * Registers a [GameObject] gossip event handler. - * - *
-     * enum GossipEvents
-     * {
-     *     GOSSIP_EVENT_ON_HELLO                           = 1,    // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
-     *     GOSSIP_EVENT_ON_SELECT                          = 2,    // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
-     *     GOSSIP_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : [GameObject] entry Id - * @param uint32 event : [GameObject] gossip event Id, refer to GossipEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterGameObjectGossipEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_GAMEOBJECT_GOSSIP); - } - - /** - * Registers an [Item] event handler. - * - *
-     * enum ItemEvents
-     * {
-     *     ITEM_EVENT_ON_DUMMY_EFFECT                      = 1,    // (event, caster, spellid, effindex, item)
-     *     ITEM_EVENT_ON_USE                               = 2,    // (event, player, item, target) - Can return false to stop the spell casting
-     *     ITEM_EVENT_ON_QUEST_ACCEPT                      = 3,    // (event, player, item, quest) - Can return true
-     *     ITEM_EVENT_ON_EXPIRE                            = 4,    // (event, player, itemid) - Can return true
-     *     ITEM_EVENT_ON_REMOVE                            = 5,    // (event, player, item) - Can return true
-     *     ITEM_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : [Item] entry Id - * @param uint32 event : [Item] event Id, refer to ItemEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterItemEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_ITEM); - } - - /** - * Registers an [Item] gossip event handler. - * - *
-     * enum GossipEvents
-     * {
-     *     GOSSIP_EVENT_ON_HELLO                           = 1,    // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
-     *     GOSSIP_EVENT_ON_SELECT                          = 2,    // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
-     *     GOSSIP_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : [Item] entry Id - * @param uint32 event : [Item] gossip event Id, refer to GossipEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterItemGossipEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_ITEM_GOSSIP); - } - - /** - * Registers a [Map] event handler for all instance of a [Map]. - * - *
-     * enum InstanceEvents
-     * {
-     *     INSTANCE_EVENT_ON_INITIALIZE                    = 1,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_ON_LOAD                          = 2,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_ON_UPDATE                        = 3,    // (event, instance_data, map, diff)
-     *     INSTANCE_EVENT_ON_PLAYER_ENTER                  = 4,    // (event, instance_data, map, player)
-     *     INSTANCE_EVENT_ON_CREATURE_CREATE               = 5,    // (event, instance_data, map, creature)
-     *     INSTANCE_EVENT_ON_GAMEOBJECT_CREATE             = 6,    // (event, instance_data, map, go)
-     *     INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS   = 7,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_COUNT
-     * };
-     * 
- * - * @param uint32 map_id : ID of a [Map] - * @param uint32 event : [Map] event ID, refer to MapEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - */ - int RegisterMapEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_MAP); - } - - /** - * Registers a [Map] event handler for one instance of a [Map]. - * - *
-     * enum InstanceEvents
-     * {
-     *     INSTANCE_EVENT_ON_INITIALIZE                    = 1,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_ON_LOAD                          = 2,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_ON_UPDATE                        = 3,    // (event, instance_data, map, diff)
-     *     INSTANCE_EVENT_ON_PLAYER_ENTER                  = 4,    // (event, instance_data, map, player)
-     *     INSTANCE_EVENT_ON_CREATURE_CREATE               = 5,    // (event, instance_data, map, creature)
-     *     INSTANCE_EVENT_ON_GAMEOBJECT_CREATE             = 6,    // (event, instance_data, map, go)
-     *     INSTANCE_EVENT_ON_CHECK_ENCOUNTER_IN_PROGRESS   = 7,    // (event, instance_data, map)
-     *     INSTANCE_EVENT_COUNT
-     * };
-     * 
- * - * @param uint32 instance_id : ID of an instance of a [Map] - * @param uint32 event : [Map] event ID, refer to MapEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - */ - int RegisterInstanceEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_INSTANCE); - } - - /** - * Registers a [Player] gossip event handler. - * - * Note that you can not use `GOSSIP_EVENT_ON_HELLO` with this hook. It does nothing since players dont have an "on hello". - * - *
-     * enum GossipEvents
-     * {
-     *     GOSSIP_EVENT_ON_HELLO                           = 1,    // (event, player, object) - Object is the Creature/GameObject/Item. Can return false to do default action. For item gossip can return false to stop spell casting.
-     *     GOSSIP_EVENT_ON_SELECT                          = 2,    // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip. Can return false to do default action.
-     *     GOSSIP_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (menu_id, event, function) - * @proto cancel = (menu_id, event, function, shots) - * - * @param uint32 menu_id : [Player] gossip menu Id - * @param uint32 event : [Player] gossip event Id, refer to GossipEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterPlayerGossipEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_PLAYER_GOSSIP); - } - - /** - * Registers a [Creature] event handler. - * - *
-     * enum CreatureEvents
-     * {
-     *     CREATURE_EVENT_ON_ENTER_COMBAT                    = 1,  // (event, creature, target) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_LEAVE_COMBAT                    = 2,  // (event, creature) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_TARGET_DIED                     = 3,  // (event, creature, victim) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_DIED                            = 4,  // (event, creature, killer) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SPAWN                           = 5,  // (event, creature) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_REACH_WP                        = 6,  // (event, creature, type, id) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_AIUPDATE                        = 7,  // (event, creature, diff) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_RECEIVE_EMOTE                   = 8,  // (event, creature, player, emoteid) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_DAMAGE_TAKEN                    = 9,  // (event, creature, attacker, damage) - Can return true to stop normal action, can return new damage as second return value.
-     *     CREATURE_EVENT_ON_PRE_COMBAT                      = 10, // (event, creature, target) - Can return true to stop normal action
-     *     // UNUSED
-     *     CREATURE_EVENT_ON_OWNER_ATTACKED                  = 12, // (event, creature, target) - Can return true to stop normal action            // Not on mangos
-     *     CREATURE_EVENT_ON_OWNER_ATTACKED_AT               = 13, // (event, creature, attacker) - Can return true to stop normal action          // Not on mangos
-     *     CREATURE_EVENT_ON_HIT_BY_SPELL                    = 14, // (event, creature, caster, spellid) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SPELL_HIT_TARGET                = 15, // (event, creature, target, spellid) - Can return true to stop normal action
-     *     // UNUSED                                         = 16, // (event, creature)
-     *     // UNUSED                                         = 17, // (event, creature)
-     *     // UNUSED                                         = 18, // (event, creature)
-     *     CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE          = 19, // (event, creature, summon) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN       = 20, // (event, creature, summon) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED          = 21, // (event, creature, summon, killer) - Can return true to stop normal action    // Not on mangos
-     *     CREATURE_EVENT_ON_SUMMONED                        = 22, // (event, creature, summoner) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_RESET                           = 23, // (event, creature)
-     *     CREATURE_EVENT_ON_REACH_HOME                      = 24, // (event, creature) - Can return true to stop normal action
-     *     // UNUSED                                         = 25, // (event, creature)
-     *     CREATURE_EVENT_ON_CORPSE_REMOVED                  = 26, // (event, creature, respawndelay) - Can return true to stop normal action, can return new respawndelay as second return value
-     *     CREATURE_EVENT_ON_MOVE_IN_LOS                     = 27, // (event, creature, unit) - Can return true to stop normal action. Does not actually check LOS, just uses the sight range
-     *     // UNUSED                                         = 28, // (event, creature)
-     *     // UNUSED                                         = 29, // (event, creature)
-     *     CREATURE_EVENT_ON_DUMMY_EFFECT                    = 30, // (event, caster, spellid, effindex, creature)
-     *     CREATURE_EVENT_ON_QUEST_ACCEPT                    = 31, // (event, player, creature, quest) - Can return true
-     *     // UNUSED                                         = 32, // (event, creature)
-     *     // UNUSED                                         = 33, // (event, creature)
-     *     CREATURE_EVENT_ON_QUEST_REWARD                    = 34, // (event, player, creature, quest, opt) - Can return true
-     *     CREATURE_EVENT_ON_DIALOG_STATUS                   = 35, // (event, player, creature)
-     *     CREATURE_EVENT_ON_ADD                             = 36, // (event, creature)
-     *     CREATURE_EVENT_ON_REMOVE                          = 37, // (event, creature)
-     *     CREATURE_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : the ID of one or more [Creature]s - * @param uint32 event : refer to CreatureEvents above - * @param function function : function that will be called when the event occurs - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterCreatureEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_CREATURE); - } - - /** - * Registers a [Creature] event handler for a *single* [Creature]. - * - *
-     * enum CreatureEvents
-     * {
-     *     CREATURE_EVENT_ON_ENTER_COMBAT                    = 1,  // (event, creature, target) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_LEAVE_COMBAT                    = 2,  // (event, creature) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_TARGET_DIED                     = 3,  // (event, creature, victim) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_DIED                            = 4,  // (event, creature, killer) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SPAWN                           = 5,  // (event, creature) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_REACH_WP                        = 6,  // (event, creature, type, id) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_AIUPDATE                        = 7,  // (event, creature, diff) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_RECEIVE_EMOTE                   = 8,  // (event, creature, player, emoteid) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_DAMAGE_TAKEN                    = 9,  // (event, creature, attacker, damage) - Can return true to stop normal action, can return new damage as second return value.
-     *     CREATURE_EVENT_ON_PRE_COMBAT                      = 10, // (event, creature, target) - Can return true to stop normal action
-     *     // UNUSED
-     *     CREATURE_EVENT_ON_OWNER_ATTACKED                  = 12, // (event, creature, target) - Can return true to stop normal action            // Not on mangos
-     *     CREATURE_EVENT_ON_OWNER_ATTACKED_AT               = 13, // (event, creature, attacker) - Can return true to stop normal action          // Not on mangos
-     *     CREATURE_EVENT_ON_HIT_BY_SPELL                    = 14, // (event, creature, caster, spellid) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SPELL_HIT_TARGET                = 15, // (event, creature, target, spellid) - Can return true to stop normal action
-     *     // UNUSED                                         = 16, // (event, creature)
-     *     // UNUSED                                         = 17, // (event, creature)
-     *     // UNUSED                                         = 18, // (event, creature)
-     *     CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE          = 19, // (event, creature, summon) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN       = 20, // (event, creature, summon) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED          = 21, // (event, creature, summon, killer) - Can return true to stop normal action    // Not on mangos
-     *     CREATURE_EVENT_ON_SUMMONED                        = 22, // (event, creature, summoner) - Can return true to stop normal action
-     *     CREATURE_EVENT_ON_RESET                           = 23, // (event, creature)
-     *     CREATURE_EVENT_ON_REACH_HOME                      = 24, // (event, creature) - Can return true to stop normal action
-     *     // UNUSED                                         = 25, // (event, creature)
-     *     CREATURE_EVENT_ON_CORPSE_REMOVED                  = 26, // (event, creature, respawndelay) - Can return true to stop normal action, can return new respawndelay as second return value
-     *     CREATURE_EVENT_ON_MOVE_IN_LOS                     = 27, // (event, creature, unit) - Can return true to stop normal action. Does not actually check LOS, just uses the sight range
-     *     // UNUSED                                         = 28, // (event, creature)
-     *     // UNUSED                                         = 29, // (event, creature)
-     *     CREATURE_EVENT_ON_DUMMY_EFFECT                    = 30, // (event, caster, spellid, effindex, creature)
-     *     CREATURE_EVENT_ON_QUEST_ACCEPT                    = 31, // (event, player, creature, quest) - Can return true
-     *     // UNUSED                                         = 32, // (event, creature)
-     *     // UNUSED                                         = 33, // (event, creature)
-     *     CREATURE_EVENT_ON_QUEST_REWARD                    = 34, // (event, player, creature, quest, opt) - Can return true
-     *     CREATURE_EVENT_ON_DIALOG_STATUS                   = 35, // (event, player, creature)
-     *     CREATURE_EVENT_ON_ADD                             = 36, // (event, creature)
-     *     CREATURE_EVENT_ON_REMOVE                          = 37, // (event, creature)
-     *     CREATURE_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (guid, instance_id, event, function) - * @proto cancel = (guid, instance_id, event, function, shots) - * - * @param ObjectGuid guid : the GUID of a single [Creature] - * @param uint32 instance_id : the instance ID of a single [Creature] - * @param uint32 event : refer to CreatureEvents above - * @param function function : function that will be called when the event occurs - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterUniqueCreatureEvent(Eluna* E) - { - return RegisterUniqueHelper(E, Hooks::REGTYPE_CREATURE); - } - - /** - * Registers a [GameObject] event handler. - * - *
-     * enum GameObjectEvents
-     * {
-     *     GAMEOBJECT_EVENT_ON_AIUPDATE                    = 1,    // (event, go, diff)
-     *     GAMEOBJECT_EVENT_ON_SPAWN                       = 2,    // (event, go)
-     *     GAMEOBJECT_EVENT_ON_DUMMY_EFFECT                = 3,    // (event, caster, spellid, effindex, go) - Can return true to stop normal action
-     *     GAMEOBJECT_EVENT_ON_QUEST_ACCEPT                = 4,    // (event, player, go, quest) - Can return true to stop normal action
-     *     GAMEOBJECT_EVENT_ON_QUEST_REWARD                = 5,    // (event, player, go, quest, opt) - Can return true to stop normal action
-     *     GAMEOBJECT_EVENT_ON_DIALOG_STATUS               = 6,    // (event, player, go)
-     *     GAMEOBJECT_EVENT_ON_DESTROYED                   = 7,    // (event, go, attacker)
-     *     GAMEOBJECT_EVENT_ON_DAMAGED                     = 8,    // (event, go, attacker)
-     *     GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE           = 9,    // (event, go, state)
-     *     GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED            = 10,   // (event, go, state)
-     *     // UNUSED                                       = 11,   // (event, gameobject)
-     *     GAMEOBJECT_EVENT_ON_ADD                         = 12,   // (event, gameobject)
-     *     GAMEOBJECT_EVENT_ON_REMOVE                      = 13,   // (event, gameobject)
-     *     GAMEOBJECT_EVENT_ON_USE                         = 14,   // (event, go, player) - Can return true to stop normal action
-     *     GAMEOBJECT_EVENT_COUNT
-     * };
-     * 
- * - * @proto cancel = (entry, event, function) - * @proto cancel = (entry, event, function, shots) - * - * @param uint32 entry : [GameObject] entry Id - * @param uint32 event : [GameObject] event Id, refer to GameObjectEvents above - * @param function function : function to register - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * - * @return function cancel : a function that cancels the binding when called - */ - int RegisterGameObjectEvent(Eluna* E) - { - return RegisterEntryHelper(E, Hooks::REGTYPE_GAMEOBJECT); - } - - /** - * Reloads the Lua engine. - */ - int ReloadEluna(Eluna* E) - { - E->ReloadEluna(); - return 0; - } - - /** - * Runs a command. - * - * @param string command : the command to run - */ - int RunCommand(Eluna* E) - { - const char* command = E->CHECKVAL(1); - - eWorld->QueueCliCommand(new CliCommandHolder(0, SEC_CONSOLE, nullptr, command, nullptr, nullptr)); - return 0; - } - - /** - * Sends a message to all [Player]s online. - * - * @param string message : message to send - */ - int SendWorldMessage(Eluna* E) - { - const char* message = E->CHECKVAL(1); - eWorld->SendServerMessage(SERVER_MSG_STRING, message); - return 0; - } - - /** - * Executes a SQL query on the world database and returns an [ElunaQuery]. - * - * The query is always executed synchronously - * (i.e. execution halts until the query has finished and then results are returned). - * - * local Q = WorldDBQuery("SELECT entry, name FROM creature_template LIMIT 10") - * if Q then - * repeat - * local entry, name = Q:GetUInt32(0), Q:GetString(1) - * print(entry, name) - * until not Q:NextRow() - * end - * - * @param string sql : query to execute - * @return [ElunaQuery] results or nil if no rows found or nil if no rows found - */ - int WorldDBQuery(Eluna* E) - { - const char* query = E->CHECKVAL(1); - - QueryNamedResult* result = WorldDatabase.QueryNamed(query); - if (result) - { - ElunaQuery elunaQuery(result); - E->Push(&elunaQuery); - } - else - E->Push(); - - return 1; - } - - /** - * Executes a SQL query on the world database. - * - * The query may be executed *asynchronously* (at a later, unpredictable time). - * If you need to execute the query synchronously, use [Global:WorldDBQuery] instead. - * - * Any results produced are ignored. - * If you need results from the query, use [Global:WorldDBQuery] instead. - * - * WorldDBExecute("DELETE FROM my_table") - * - * @param string sql : query to execute - */ - int WorldDBExecute(Eluna* E) - { - const char* query = E->CHECKVAL(1); - WorldDatabase.Execute(query); - return 0; - } - - /** - * Executes a SQL query on the character database and returns an [ElunaQuery]. - * - * The query is always executed synchronously - * (i.e. execution halts until the query has finished and then results are returned). - * - * For an example see [Global:WorldDBQuery]. - * - * @param string sql : query to execute - * @return [ElunaQuery] results or nil if no rows found - */ - int CharDBQuery(Eluna* E) - { - const char* query = E->CHECKVAL(1); - - QueryNamedResult* result = CharacterDatabase.QueryNamed(query); - if (result) - { - ElunaQuery elunaQuery(result); - E->Push(&elunaQuery); - } - else - E->Push(); - - return 1; - } - - /** - * Executes a SQL query on the character database. - * - * The query may be executed *asynchronously* (at a later, unpredictable time). - * If you need to execute the query synchronously, use [Global:CharDBQuery] instead. - * - * Any results produced are ignored. - * If you need results from the query, use [Global:CharDBQuery] instead. - * - * CharDBExecute("DELETE FROM my_table") - * - * @param string sql : query to execute - */ - int CharDBExecute(Eluna* E) - { - const char* query = E->CHECKVAL(1); - CharacterDatabase.Execute(query); - return 0; - } - - /** - * Executes a SQL query on the login database and returns an [ElunaQuery]. - * - * The query is always executed synchronously - * (i.e. execution halts until the query has finished and then results are returned). - * - * For an example see [Global:WorldDBQuery]. - * - * @param string sql : query to execute - * @return [ElunaQuery] results or nil if no rows found - */ - int AuthDBQuery(Eluna* E) - { - const char* query = E->CHECKVAL(1); - - QueryNamedResult* result = LoginDatabase.QueryNamed(query); - if (result) - { - ElunaQuery elunaQuery(result); - E->Push(&elunaQuery); - } - else - E->Push(); - - return 1; - } - - /** - * Executes a SQL query on the login database. - * - * The query may be executed *asynchronously* (at a later, unpredictable time). - * If you need to execute the query synchronously, use [Global:AuthDBQuery] instead. - * - * Any results produced are ignored. - * If you need results from the query, use [Global:AuthDBQuery] instead. - * - * AuthDBExecute("DELETE FROM my_table") - * - * @param string sql : query to execute - */ - int AuthDBExecute(Eluna* E) - { - const char* query = E->CHECKVAL(1); - LoginDatabase.Execute(query); - return 0; - } - - /** - * Registers a global timed event. - * - * When the passed function is called, the parameters `(eventId, delay, repeats)` are passed to it. - * - * Repeats will decrease on each call if the event does not repeat indefinitely - * - * @proto eventId = (function, delay) - * @proto eventId = (function, delaytable) - * @proto eventId = (function, delay, repeats) - * @proto eventId = (function, delaytable, repeats) - * - * @param function function : function to trigger when the time has passed - * @param uint32 delay : set time in milliseconds for the event to trigger - * @param table delaytable : a table `{min, max}` containing the minimum and maximum delay time - * @param uint32 repeats = 1 : how many times for the event to repeat, 0 is infinite - * @return int eventId : unique ID for the timed event used to cancel it or nil - */ - int CreateLuaEvent(Eluna* E) - { - luaL_checktype(E->L, 1, LUA_TFUNCTION); - uint32 min, max; - if (lua_istable(E->L, 2)) - { - E->Push(1); - lua_gettable(E->L, 2); - min = E->CHECKVAL(-1); - E->Push(2); - lua_gettable(E->L, 2); - max = E->CHECKVAL(-1); - lua_pop(E->L, 2); - } - else - min = max = E->CHECKVAL(2); - uint32 repeats = E->CHECKVAL(3, 1); - - if (min > max) - return luaL_argerror(E->L, 2, "min is bigger than max delay"); - - lua_pushvalue(E->L, 1); - int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX); - if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF) - { - E->eventMgr->globalProcessor->AddEvent(functionRef, min, max, repeats); - E->Push(functionRef); - } - return 1; - } - - /** - * Removes a global timed event specified by ID. - * - * @param int eventId : event Id to remove - * @param bool all_Events = false : remove from all events, not just global - */ - int RemoveEventById(Eluna* E) - { - int eventId = E->CHECKVAL(1); - bool all_Events = E->CHECKVAL(1, false); - - // not thread safe - if (all_Events) - E->eventMgr->SetState(eventId, LUAEVENT_STATE_ABORT); - else - E->eventMgr->globalProcessor->SetState(eventId, LUAEVENT_STATE_ABORT); - return 0; - } - - /** - * Removes all global timed events. - * - * @param bool all_Events = false : remove all events, not just global - */ - int RemoveEvents(Eluna* E) - { - bool all_Events = E->CHECKVAL(1, false); - - // not thread safe - if (all_Events) - E->eventMgr->SetStates(LUAEVENT_STATE_ABORT); - else - E->eventMgr->globalProcessor->SetStates(LUAEVENT_STATE_ABORT); - return 0; - } - - /** - * Performs an in-game spawn and returns the [Creature] or [GameObject] spawned. - * - * @param int32 spawnType : type of object to spawn, 1 = [Creature], 2 = [GameObject] - * @param uint32 entry : entry ID of the [Creature] or [GameObject] - * @param uint32 mapId : map ID to spawn the [Creature] or [GameObject] in - * @param uint32 instanceId : instance ID to put the [Creature] or [GameObject] in. Non instance is 0 - * @param float x : x coordinate of the [Creature] or [GameObject] - * @param float y : y coordinate of the [Creature] or [GameObject] - * @param float z : z coordinate of the [Creature] or [GameObject] - * @param float o : o facing/orientation of the [Creature] or [GameObject] - * @param bool save = false : optional to save the [Creature] or [GameObject] to the database - * @param uint32 durorresptime = 0 : despawn time of the [Creature] if it's not saved or respawn time of [GameObject] - * @param uint32 phase = 1 : phase to put the [Creature] or [GameObject] in - * @return [WorldObject] worldObject : returns [Creature] or [GameObject] - */ - int PerformIngameSpawn(Eluna* E) - { - int spawntype = E->CHECKVAL(1); - uint32 entry = E->CHECKVAL(2); - uint32 mapID = E->CHECKVAL(3); - uint32 instanceID = E->CHECKVAL(4); - float x = E->CHECKVAL(5); - float y = E->CHECKVAL(6); - float z = E->CHECKVAL(7); - float o = E->CHECKVAL(8); - bool save = E->CHECKVAL(9, false); - uint32 durorresptime = E->CHECKVAL(10, 0); -#if (!defined(TBC) && !defined(CLASSIC)) - uint32 phase = E->CHECKVAL(11, PHASEMASK_NORMAL); - if (!phase) - { - E->Push(); - return 1; - } -#endif - - Map* map = eMapMgr->FindMap(mapID, instanceID); - if (!map) - { - E->Push(); - return 1; - } - - if (spawntype == 1) // spawn creature - { - if (save) - { - CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); - if (!cinfo) - { - E->Push(); - return 1; - } - -#if (defined(TBC) || defined(CLASSIC)) - CreatureCreatePos pos(map, x, y, z, o); -#else - CreatureCreatePos pos(map, x, y, z, o, phase); -#endif - Creature* pCreature = new Creature; - // used guids from specially reserved range (can be 0 if no free values) - uint32 lowguid = eObjectMgr->GenerateStaticCreatureLowGuid(); - if (!lowguid) - { - E->Push(); - return 1; - } - - if (!pCreature->Create(lowguid, pos, cinfo)) - { - delete pCreature; - E->Push(); - return 1; - } - -#ifdef TBC - pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode())); -#elif defined(CLASSIC) - pCreature->SaveToDB(map->GetId()); -#else - pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); -#endif - - uint32 db_guid = pCreature->GetGUIDLow(); - - // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); - pCreature->LoadFromDB(db_guid, map); - - map->Add(pCreature); - eObjectMgr->AddCreatureToGrid(db_guid, eObjectMgr->GetCreatureData(db_guid)); - if (durorresptime) - pCreature->ForcedDespawn(durorresptime); - - E->Push(pCreature); - } - else - { - CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); - if (!cinfo) - { - E->Push(); - return 1; - } - - TemporarySummon* pCreature = new TemporarySummon(ObjectGuid(uint64(0))); -#if (defined(TBC) || defined(CLASSIC)) - CreatureCreatePos pos(map, x, y, z, o); -#else - CreatureCreatePos pos(map, x, y, z, o, phase); -#endif - if (!pCreature->Create(map->GenerateLocalLowGuid(cinfo->GetHighGuid()), pos, cinfo, TEAM_NONE)) - { - delete pCreature; - { - E->Push(); - return 1; - } - } - - pCreature->SetRespawnCoord(pos); - - // Active state set before added to map - pCreature->SetActiveObjectState(false); - - // Also initializes the AI and MMGen - pCreature->Summon(durorresptime ? TEMPSPAWN_TIMED_OR_DEAD_DESPAWN : TEMPSPAWN_MANUAL_DESPAWN, durorresptime); - - // Creature Linking, Initial load is handled like respawn - if (pCreature->IsLinkingEventTrigger()) - map->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_RESPAWN, pCreature); - - E->Push(pCreature); - } - - return 1; - } - - if (spawntype == 2) // Spawn object - { - if (save) - { - const GameObjectInfo* gInfo = ObjectMgr::GetGameObjectInfo(entry); - if (!gInfo) - { - E->Push(); - return 1; - } - - // used guids from specially reserved range (can be 0 if no free values) - uint32 db_lowGUID = eObjectMgr->GenerateStaticGameObjectLowGuid(); - if (!db_lowGUID) - { - E->Push(); - return 1; - } - - GameObject* pGameObj = new GameObject; -#if ((defined(TBC) || defined(CLASSIC))) - if (!pGameObj->Create(db_lowGUID, gInfo->id, map, x, y, z, o)) -#else - if (!pGameObj->Create(db_lowGUID, gInfo->id, map, phase, x, y, z, o)) -#endif - { - delete pGameObj; - E->Push(); - return 1; - } - - if (durorresptime) - pGameObj->SetRespawnTime(durorresptime); - - // fill the gameobject data and save to the db -#ifdef TBC - pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode())); -#elif defined(CLASSIC) - pGameObj->SaveToDB(map->GetId()); -#else - pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); -#endif - - // this will generate a new guid if the object is in an instance - if (!pGameObj->LoadFromDB(db_lowGUID, map)) - { - delete pGameObj; - E->Push(); - return 1; - } - - // DEBUG_LOG(GetMangosString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o); - - map->Add(pGameObj); - pGameObj->AIM_Initialize(); - - eObjectMgr->AddGameobjectToGrid(db_lowGUID, eObjectMgr->GetGOData(db_lowGUID)); - - E->Push(pGameObj); - } - else - { - GameObject* pGameObj = new GameObject; - -#if ((defined(TBC) || defined(CLASSIC))) - if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), entry, map, x, y, z, o)) -#else - if (!pGameObj->Create(map->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), entry, map, phase, x, y, z, o)) -#endif - { - delete pGameObj; - E->Push(); - return 1; - } - - pGameObj->SetRespawnTime(durorresptime / IN_MILLISECONDS); - - map->Add(pGameObj); - pGameObj->AIM_Initialize(); - - E->Push(pGameObj); - } - return 1; - } - - E->Push(); - return 1; - } - - /** - * Creates a [WorldPacket]. - * - * @param [Opcodes] opcode : the opcode of the packet - * @param uint32 size : the size of the packet - * @return [WorldPacket] packet - */ - int CreatePacket(Eluna* E) - { - uint32 opcode = E->CHECKVAL(1); - size_t size = E->CHECKVAL(2); - if (opcode >= NUM_MSG_TYPES) - return luaL_argerror(E->L, 1, "valid opcode expected"); - -#if defined CMANGOS && defined CLASSIC - E->Push(new WorldPacket((Opcodes)opcode, size)); -#else - E->Push(new WorldPacket((OpcodesList)opcode, size)); -#endif - return 1; - } - - /** - * Adds an [Item] to a vendor and updates the world database. - * - * @param uint32 entry : [Creature] entry Id - * @param uint32 item : [Item] entry Id - * @param int32 maxcount : max [Item] stack count - * @param uint32 incrtime : combined with maxcount, incrtime tells how often (in seconds) the vendor list is refreshed and the limited [Item] copies are restocked - * @param uint32 extendedcost : unique cost of an [Item], such as conquest points for example - */ - int AddVendorItem(Eluna* E) - { - uint32 entry = E->CHECKVAL(1); - uint32 item = E->CHECKVAL(2); - int maxcount = E->CHECKVAL(3); - uint32 incrtime = E->CHECKVAL(4); - uint32 extendedcost = E->CHECKVAL(5); - - if (!eObjectMgr->IsVendorItemValid(false, "npc_vendor", entry, item, maxcount, incrtime, extendedcost, 0)) - return 0; -#ifndef CLASSIC - eObjectMgr->AddVendorItem(entry, item, maxcount, incrtime, extendedcost); -#else - eObjectMgr->AddVendorItem(entry, item, maxcount, incrtime); -#endif - return 0; - } - - /** - * Removes an [Item] from a vendor and updates the database. - * - * @param uint32 entry : [Creature] entry Id - * @param uint32 item : [Item] entry Id - */ - int VendorRemoveItem(Eluna* E) - { - uint32 entry = E->CHECKVAL(1); - uint32 item = E->CHECKVAL(2); - if (!eObjectMgr->GetCreatureTemplate(entry)) - return luaL_argerror(E->L, 1, "valid CreatureEntry expected"); - -#if defined(CATA) || defined(MISTS) - eObjectMgr->RemoveVendorItem(entry, item, 1); -#else - eObjectMgr->RemoveVendorItem(entry, item); -#endif - return 0; - } - - /** - * Removes all [Item]s from a vendor and updates the database. - * - * @param uint32 entry : [Creature] entry Id - */ - int VendorRemoveAllItems(Eluna* E) - { - uint32 entry = E->CHECKVAL(1); - - VendorItemData const* items = eObjectMgr->GetNpcVendorItemList(entry); - if (!items || items->Empty()) - return 0; - - auto const itemlist = items->m_items; - for (auto itr = itemlist.begin(); itr != itemlist.end(); ++itr) - eObjectMgr->RemoveVendorItem(entry, (*itr)->item); - - return 0; - } - - /** - * Kicks a [Player] from the server. - * - * @param [Player] player : [Player] to kick - */ - int Kick(Eluna* E) - { - Player* player = E->CHECKOBJ(1); - player->GetSession()->KickPlayer(); - - return 0; - } - - /** - * Ban's a [Player]'s account, character or IP - * - * enum BanMode - * { - * BAN_ACCOUNT = 0, - * BAN_CHARACTER = 1, - * BAN_IP = 2 - * }; - * - * @param [BanMode] banMode : method of ban, refer to BanMode above - * @param string nameOrIP : If BanMode is 0 then accountname, if 1 then charactername if 2 then ip - * @param uint32 duration : duration (in seconds) of the ban - * @param string reason = "" : ban reason, this is optional - * @param string whoBanned = "" : the [Player]'s name that banned the account, character or IP, this is optional - * @return int result : status of the ban. 0 if success, 1 if syntax error, 2 if target not found, 3 if a longer ban already exists, nil if unknown result - */ - int Ban(Eluna* E) - { - int banMode = E->CHECKVAL(1); - std::string nameOrIP = E->CHECKVAL(2); - uint32 duration = E->CHECKVAL(3); - const char* reason = E->CHECKVAL(4, ""); - const char* whoBanned = E->CHECKVAL(5, ""); - - const int BAN_ACCOUNT = 0; - const int BAN_CHARACTER = 1; - const int BAN_IP = 2; - - BanMode mode = BanMode::BAN_ACCOUNT; - - switch (banMode) - { - case BAN_ACCOUNT: - if (!Utf8ToUpperOnlyLatin(nameOrIP)) - return luaL_argerror(E->L, 2, "invalid account name"); - mode = BanMode::BAN_ACCOUNT; - break; - case BAN_CHARACTER: - if (!normalizePlayerName(nameOrIP)) - return luaL_argerror(E->L, 2, "invalid character name"); - mode = BanMode::BAN_CHARACTER; - break; - case BAN_IP: - if (!IsIPAddress(nameOrIP.c_str())) - return luaL_argerror(E->L, 2, "invalid ip"); - mode = BanMode::BAN_IP; - break; - default: - return luaL_argerror(E->L, 1, "unknown banmode"); - } - - BanReturn result; - result = eWorld->BanAccount(mode, nameOrIP, duration, reason, whoBanned); - switch (result) - { - case BanReturn::BAN_SUCCESS: - E->Push(0); - break; - case BanReturn::BAN_SYNTAX_ERROR: - E->Push(1); - break; - case BanReturn::BAN_NOTFOUND: - E->Push(2); - break; - } - return 1; - } - - /** - * Saves all [Player]s. - */ - int SaveAllPlayers(Eluna* /*E*/) - { - eObjectAccessor()SaveAllPlayers(); - return 0; - } - - /** - * Sends mail to a [Player]. - * - * There can be several item entry-amount pairs at the end of the function. - * There can be maximum of 12 different items. - * - * enum MailStationery - * { - * MAIL_STATIONERY_TEST = 1, - * MAIL_STATIONERY_DEFAULT = 41, - * MAIL_STATIONERY_GM = 61, - * MAIL_STATIONERY_AUCTION = 62, - * MAIL_STATIONERY_VAL = 64, // Valentine - * MAIL_STATIONERY_CHR = 65, // Christmas - * MAIL_STATIONERY_ORP = 67 // Orphan - * }; - * - * @param string subject : title (subject) of the mail - * @param string text : contents of the mail - * @param uint32 receiverGUIDLow : low GUID of the receiver - * @param uint32 senderGUIDLow = 0 : low GUID of the sender - * @param [MailStationery] stationary = MAIL_STATIONERY_DEFAULT : type of mail that is being sent as, refer to MailStationery above - * @param uint32 delay = 0 : mail send delay in milliseconds - * @param uint32 money = 0 : money to send - * @param uint32 cod = 0 : cod money amount - * @param uint32 entry = 0 : entry of an [Item] to send with mail - * @param uint32 amount = 0 : amount of the [Item] to send with mail - * @return uint32 itemGUIDlow : low GUID of the item. Up to 12 values returned, returns nil if no further items are sent - */ - int SendMail(Eluna* E) - { - int i = 0; - std::string subject = E->CHECKVAL(++i); - std::string text = E->CHECKVAL(++i); - uint32 receiverGUIDLow = E->CHECKVAL(++i); - uint32 senderGUIDLow = E->CHECKVAL(++i, 0); - uint32 stationary = E->CHECKVAL(++i, MAIL_STATIONERY_DEFAULT); - uint32 delay = E->CHECKVAL(++i, 0); - uint32 money = E->CHECKVAL(++i, 0); - uint32 cod = E->CHECKVAL(++i, 0); - int argAmount = lua_gettop(E->L); - - MailSender sender(MAIL_NORMAL, senderGUIDLow, (MailStationery)stationary); - MailDraft draft(subject, text); - - if (cod) - draft.SetCOD(cod); - if (money) - draft.SetMoney(money); - - uint8 addedItems = 0; - while (addedItems <= MAX_MAIL_ITEMS && i + 2 <= argAmount) - { - uint32 entry = E->CHECKVAL(++i); - uint32 amount = E->CHECKVAL(++i); - - ItemTemplate const* item_proto = ObjectMgr::GetItemPrototype(entry); - if (!item_proto) - { - luaL_error(E->L, "Item entry %d does not exist", entry); - continue; - } - if (amount < 1 || (item_proto->MaxCount > 0 && amount > uint32(item_proto->MaxCount))) - { - luaL_error(E->L, "Item entry %d has invalid amount %d", entry, amount); - continue; - } - if (Item* item = Item::CreateItem(entry, amount)) - { - item->SaveToDB(); - draft.AddItem(item); - - E->Push(item->GetGUIDLow()); - ++addedItems; - } - } - - Player* receiverPlayer = eObjectAccessor()FindPlayer(MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)); - draft.SendMailTo(MailReceiver(receiverPlayer, MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); - return addedItems; - } - - /** - * Performs a bitwise AND (a & b). - * - * @param uint32 a - * @param uint32 b - * @return uint32 result - */ - int bit_and(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - uint32 b = E->CHECKVAL(2); - E->Push(a & b); - return 1; - } - - /** - * Performs a bitwise OR (a | b). - * - * @param uint32 a - * @param uint32 b - * @return uint32 result - */ - int bit_or(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - uint32 b = E->CHECKVAL(2); - E->Push(a | b); - return 1; - } - - /** - * Performs a bitwise left-shift (a << b). - * - * @param uint32 a - * @param uint32 b - * @return uint32 result - */ - int bit_lshift(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - uint32 b = E->CHECKVAL(2); - E->Push(a << b); - return 1; - } - - /** - * Performs a bitwise right-shift (a >> b). - * - * @param uint32 a - * @param uint32 b - * @return uint32 result - */ - int bit_rshift(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - uint32 b = E->CHECKVAL(2); - E->Push(a >> b); - return 1; - } - - /** - * Performs a bitwise XOR (a ^ b). - * - * @param uint32 a - * @param uint32 b - * @return uint32 result - */ - int bit_xor(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - uint32 b = E->CHECKVAL(2); - E->Push(a ^ b); - return 1; - } - - /** - * Performs a bitwise NOT (~a). - * - * @param uint32 a - * @return uint32 result - */ - int bit_not(Eluna* E) - { - uint32 a = E->CHECKVAL(1); - E->Push(~a); - return 1; - } - - /** - * Adds a taxi path to a specified map, returns the used pathId. - * - * Note that the first taxi point needs to be near the player when he starts the taxi path. - * The function should also be used only **once** per path added so use it on server startup for example. - * - * Related function: [Player:StartTaxi] - * - * -- Execute on startup - * local pathTable = {{mapid, x, y, z}, {mapid, x, y, z}} - * local path = AddTaxiPath(pathTable, 28135, 28135) - * - * -- Execute when the player should fly - * player:StartTaxi(path) - * - * @param table waypoints : table containing waypoints: {map, x, y, z[, actionFlag, delay]} - * @param uint32 mountA : alliance [Creature] entry - * @param uint32 mountH : horde [Creature] entry - * @param uint32 price = 0 : price of the taxi path - * @param uint32 pathId = 0 : path Id of the taxi path - * @return uint32 actualPathId - */ - int AddTaxiPath(Eluna* E) - { - luaL_checktype(E->L, 1, LUA_TTABLE); - uint32 mountA = E->CHECKVAL(2); - uint32 mountH = E->CHECKVAL(3); - uint32 price = E->CHECKVAL(4, 0); - uint32 pathId = E->CHECKVAL(5, 0); - lua_pushvalue(E->L, 1); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes} - - std::list nodes; - - int start = lua_gettop(E->L); - int end = start; - - E->Push(); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, nil - while (lua_next(E->L, -2) != 0) - { - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value - luaL_checktype(E->L, -1, LUA_TTABLE); - E->Push(); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value, nil - while (lua_next(E->L, -2) != 0) - { - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value, key2, value2 - lua_insert(E->L, end++); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, value2, key, value, key2 - } - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, value2, key, value - if (start == end) - continue; - if (end - start < 4) // no mandatory args, dont add - return luaL_argerror(E->L, 1, "all waypoints do not have mandatory arguments"); - - while (end - start < 8) // fill optional args with 0 - { - E->Push(0); - lua_insert(E->L, end++); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, node, key, value - } - TaxiPathNodeEntry entry; - - // mandatory - entry.mapid = E->CHECKVAL(start); - entry.x = E->CHECKVAL(start + 1); - entry.y = E->CHECKVAL(start + 2); - entry.z = E->CHECKVAL(start + 3); - // optional - entry.actionFlag = E->CHECKVAL(start + 4, 0); - entry.delay = E->CHECKVAL(start + 5, 0); - - nodes.push_back(entry); - - while (end != start) // remove args - if (!lua_isnone(E->L, --end)) - lua_remove(E->L, end); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value - - lua_pop(E->L, 1); - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key - } - // Stack: {nodes}, mountA, mountH, price, pathid, {nodes} - lua_pop(E->L, 1); - // Stack: {nodes}, mountA, mountH, price, pathid - - if (nodes.size() < 2) - return 1; - if (!pathId) - pathId = sTaxiPathNodesByPath.size(); - if (sTaxiPathNodesByPath.size() <= pathId) - sTaxiPathNodesByPath.resize(pathId + 1); - sTaxiPathNodesByPath[pathId].clear(); - sTaxiPathNodesByPath[pathId].resize(nodes.size()); - static uint32 nodeId = 500; - uint32 startNode = nodeId; - uint32 index = 0; - for (std::list::iterator it = nodes.begin(); it != nodes.end(); ++it) - { - TaxiPathNodeEntry& entry = *it; - TaxiNodesEntry* nodeEntry = new TaxiNodesEntry(); - - entry.path = pathId; - entry.index = nodeId; - nodeEntry->ID = index; - nodeEntry->map_id = entry.mapid; - nodeEntry->x = entry.x; - nodeEntry->y = entry.y; - nodeEntry->z = entry.z; - nodeEntry->MountCreatureID[0] = mountH; - nodeEntry->MountCreatureID[1] = mountA; - - sTaxiNodesStore.SetEntry(nodeId++, nodeEntry); - sTaxiPathNodesByPath[pathId].set(index++, new TaxiPathNodeEntry(entry)); - } - if (startNode >= nodeId) - return 1; - - sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); - TaxiPathEntry* pathEntry = new TaxiPathEntry(); - pathEntry->from = startNode; - pathEntry->to = nodeId - 1; - pathEntry->price = price; - pathEntry->ID = pathId; - sTaxiPathStore.SetEntry(pathId, pathEntry); - - E->Push(pathId); - return 1; - } - - /** - * Returns `true` if the bag and slot is a valid inventory position, otherwise `false`. - * - * Some commonly used combinations: - * - * *Bag 255 (common character inventory)* - * - * - Slots 0-18: equipment - * - Slots 19-22: bag slots - * - Slots 23-38: backpack - * - Slots 39-66: bank main slots - * - Slots 67-74: bank bag slots - * - Slots 86-117: keyring - * - * *Bags 19-22 (equipped bags)* - * - * - Slots 0-35 - * - * *Bags 67-74 (bank bags)* - * - * - Slots 0-35 - * - * @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot] - * @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot] - * @return bool isInventoryPos - */ - int IsInventoryPos(Eluna* E) - { - uint8 bag = E->CHECKVAL(1); - uint8 slot = E->CHECKVAL(2); - - E->Push(Player::IsInventoryPos(bag, slot)); - return 1; - } - - /** - * Returns `true` if the bag and slot is a valid equipment position, otherwise `false`. - * - * See [Global:IsInventoryPos] for bag/slot combination examples. - * - * @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot] - * @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot] - * @return bool isEquipmentPosition - */ - int IsEquipmentPos(Eluna* E) - { - uint8 bag = E->CHECKVAL(1); - uint8 slot = E->CHECKVAL(2); - - E->Push(Player::IsEquipmentPos(bag, slot)); - return 1; - } - - /** - * Returns `true` if the bag and slot is a valid bank position, otherwise `false`. - * - * See [Global:IsInventoryPos] for bag/slot combination examples. - * - * @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot] - * @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot] - * @return bool isBankPosition - */ - int IsBankPos(Eluna* E) - { - uint8 bag = E->CHECKVAL(1); - uint8 slot = E->CHECKVAL(2); - - E->Push(Player::IsBankPos(bag, slot)); - return 1; - } - - /** - * Returns `true` if the bag and slot is a valid bag position, otherwise `false`. - * - * See [Global:IsInventoryPos] for bag/slot combination examples. - * - * @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot] - * @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot] - * @return bool isBagPosition - */ - int IsBagPos(Eluna* E) - { - uint8 bag = E->CHECKVAL(1); - uint8 slot = E->CHECKVAL(2); - - E->Push(Player::IsBagPos((bag << 8) + slot)); - return 1; - } - - /** - * Returns `true` if the event is currently active, otherwise `false`. - * - * @param uint16 eventId : the event id to check. - * @return bool isActive - */ - int IsGameEventActive(Eluna* E) - { - uint16 eventId = E->CHECKVAL(1); - - E->Push(eGameEventMgr->IsActiveEvent(eventId)); - return 1; - } - - /** - * Returns the server's current time. - * - * @return uint32 currTime : the current time, in milliseconds - */ - int GetCurrTime(Eluna* E) - { - E->Push(ElunaUtil::GetCurrTime()); - return 1; - } - - /** - * Returns the difference between an old timestamp and the current time. - * - * @param uint32 oldTime : an old timestamp, in milliseconds - * @return uint32 timeDiff : the difference, in milliseconds - */ - int GetTimeDiff(Eluna* E) - { - uint32 oldtimems = E->CHECKVAL(1); - - E->Push(ElunaUtil::GetTimeDiff(oldtimems)); - return 1; - } - - static std::string GetStackAsString(Eluna* E) - { - std::ostringstream oss; - int top = lua_gettop(E->L); - for (int i = 1; i <= top; ++i) - { - oss << luaL_tolstring(E->L, i, NULL); - lua_pop(E->L, 1); - } - return oss.str(); - } - - /** - * Prints given parameters to the info log. - * - * @param ... - */ - int PrintInfo(Eluna* E) - { - ELUNA_LOG_INFO("%s", GetStackAsString(E).c_str()); - return 0; - } - - /** - * Prints given parameters to the error log. - * - * @param ... - */ - int PrintError(Eluna* E) - { - ELUNA_LOG_ERROR("%s", GetStackAsString(E).c_str()); - return 0; - } - - /** - * Prints given parameters to the debug log. - * - * @param ... - */ - int PrintDebug(Eluna* E) - { - ELUNA_LOG_DEBUG("%s", GetStackAsString(E).c_str()); - return 0; - } - - /** - * Starts the event by eventId, if force is set, the event will force start regardless of previous event state. - * - * @param uint16 eventId : the event id to start. - * @param bool force = false : set `true` to force start the event. - */ - int StartGameEvent(Eluna* E) - { - uint16 eventId = E->CHECKVAL(1); - bool force = E->CHECKVAL(2, false); - - eGameEventMgr->StartEvent(eventId, force); - return 0; - } - - /** - * Stops the event by eventId, if force is set, the event will force stop regardless of previous event state. - * - * @param uint16 eventId : the event id to stop. - * @param bool force = false : set `true` to force stop the event. - */ - int StopGameEvent(Eluna* E) - { - uint16 eventId = E->CHECKVAL(1); - bool force = E->CHECKVAL(2, false); - - eGameEventMgr->StopEvent(eventId, force); - return 0; - } - - /** - * Returns an object representing a `long long` (64-bit) value. - * - * The value by default is 0, but can be initialized to a value by passing a number or long long as a string. - * - * @proto value = () - * @proto value = (n) - * @proto value = (n_ll) - * @proto value = (n_str) - * @param int32 n - * @param int64 n_ll - * @param string n_str - * @return int64 value - */ - int CreateLongLong(Eluna* E) - { - long long init = 0; - if (lua_isstring(E->L, 1)) - { - std::string str = E->CHECKVAL(1); - std::istringstream iss(str); - iss >> init; - if (iss.bad()) - return luaL_argerror(E->L, 1, "long long (as string) could not be converted"); - } - else if (!lua_isnoneornil(E->L, 1)) - init = E->CHECKVAL(1); - - E->Push(init); - return 1; - } - - /** - * Returns an object representing an `unsigned long long` (64-bit) value. - * - * The value by default is 0, but can be initialized to a value by passing a number or unsigned long long as a string. - * - * @proto value = () - * @proto value = (n) - * @proto value = (n_ull) - * @proto value = (n_str) - * @param uint32 n - * @param uint64 n_ull - * @param string n_str - * @return uint64 value - */ - int CreateULongLong(Eluna* E) - { - unsigned long long init = 0; - if (lua_isstring(E->L, 1)) - { - std::string str = E->CHECKVAL(1); - std::istringstream iss(str); - iss >> init; - if (iss.bad()) - return luaL_argerror(E->L, 1, "unsigned long long (as string) could not be converted"); - } - else if (!lua_isnoneornil(E->L, 1)) - init = E->CHECKVAL(1); - - E->Push(init); - return 1; - } - - /** - * Unbinds event handlers for either all [BattleGround] events, or one type of event. - * - * If `event_type` is `nil`, all [BattleGround] event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto () - * @proto (event_type) - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterBGEvent] - */ - int ClearBattleGroundEvents(Eluna* E) - { - typedef EventKey Key; - - if (lua_isnoneornil(E->L, 1)) - { - E->BGEventBindings->Clear(); - } - else - { - uint32 event_type = E->CHECKVAL(1); - E->BGEventBindings->Clear(Key((Hooks::BGEvents)event_type)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [Creature]'s events, or one type of event. - * - * If `event_type` is `nil`, all the [Creature]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [Creature], not just one. - * To bind and unbind events to a single [Creature], see [Global:RegisterUniqueCreatureEvent] and [Global:ClearUniqueCreatureEvents]. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of one or more [Creature]s whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterCreatureEvent] - */ - int ClearCreatureEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->CreatureEventBindings->Clear(Key((Hooks::CreatureEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [Creature]'s events, or one type of event. - * - * If `event_type` is `nil`, all the [Creature]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect only a single [Creature]. - * To bind and unbind events to all instances of a [Creature], see [Global:RegisterCreatureEvent] and [Global:ClearCreatureEvent]. - * - * @proto (entry) - * @proto (entry, event_type) - * @param ObjectGuid guid : the GUID of a single [Creature] whose handlers will be cleared - * @param uint32 instance_id : the instance ID of a single [Creature] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterCreatureEvent] - */ - int ClearUniqueCreatureEvents(Eluna* E) - { - typedef UniqueObjectKey Key; - - if (lua_isnoneornil(E->L, 3)) - { - ObjectGuid guid = E->CHECKVAL(1); - uint32 instanceId = E->CHECKVAL(2); - for (uint32 i = 1; i < Hooks::CREATURE_EVENT_COUNT; ++i) - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)i, guid, instanceId)); - } - else - { - ObjectGuid guid = E->CHECKVAL(1); - uint32 instanceId = E->CHECKVAL(2); - uint32 event_type = E->CHECKVAL(3); - E->CreatureUniqueBindings->Clear(Key((Hooks::CreatureEvents)event_type, guid, instanceId)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [Creature]'s gossip events, or one type of event. - * - * If `event_type` is `nil`, all the [Creature]'s gossip event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [Creature], not just one. - * To bind and unbind gossip events to a single [Creature], tell the Eluna developers to implement that. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of a [Creature] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterCreatureGossipEvent] - */ - int ClearCreatureGossipEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->CreatureGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [GameObject]'s events, or one type of event. - * - * If `event_type` is `nil`, all the [GameObject]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [GameObject], not just one. - * To bind and unbind events to a single [GameObject], tell the Eluna developers to implement that. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of a [GameObject] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterGameObjectEvent] - */ - int ClearGameObjectEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::GAMEOBJECT_EVENT_COUNT; ++i) - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->GameObjectEventBindings->Clear(Key((Hooks::GameObjectEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [GameObject]'s gossip events, or one type of event. - * - * If `event_type` is `nil`, all the [GameObject]'s gossip event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [GameObject], not just one. - * To bind and unbind gossip events to a single [GameObject], tell the Eluna developers to implement that. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of a [GameObject] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterGameObjectGossipEvent] - */ - int ClearGameObjectGossipEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->GameObjectGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all [Group] events, or one type of [Group] event. - * - * If `event_type` is `nil`, all [Group] event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto () - * @proto (event_type) - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterGroupEvent] - */ - int ClearGroupEvents(Eluna* E) - { - typedef EventKey Key; - - if (lua_isnoneornil(E->L, 1)) - { - E->GroupEventBindings->Clear(); - } - else - { - uint32 event_type = E->CHECKVAL(1); - E->GroupEventBindings->Clear(Key((Hooks::GroupEvents)event_type)); - } - return 0; - } - - /** - * Unbinds event handlers for either all [Guild] events, or one type of [Guild] event. - * - * If `event_type` is `nil`, all [Guild] event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto () - * @proto (event_type) - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterGuildEvent] - */ - int ClearGuildEvents(Eluna* E) - { - typedef EventKey Key; - - if (lua_isnoneornil(E->L, 1)) - { - E->GuildEventBindings->Clear(); - } - else - { - uint32 event_type = E->CHECKVAL(1); - E->GuildEventBindings->Clear(Key((Hooks::GuildEvents)event_type)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of an [Item]'s events, or one type of event. - * - * If `event_type` is `nil`, all the [Item]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [Item], not just one. - * To bind and unbind events to a single [Item], tell the Eluna developers to implement that. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of an [Item] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterItemEvent] - */ - int ClearItemEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::ITEM_EVENT_COUNT; ++i) - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->ItemEventBindings->Clear(Key((Hooks::ItemEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of an [Item]'s gossip events, or one type of event. - * - * If `event_type` is `nil`, all the [Item]'s gossip event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * **NOTE:** this will affect all instances of the [Item], not just one. - * To bind and unbind gossip events to a single [Item], tell the Eluna developers to implement that. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the ID of an [Item] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterItemGossipEvent] - */ - int ClearItemGossipEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->ItemGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [WorldPacket] opcode's events, or one type of event. - * - * If `event_type` is `nil`, all the [WorldPacket] opcode's event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto (opcode) - * @proto (opcode, event_type) - * @param uint32 opcode : the type of [WorldPacket] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterPacketEvent] - */ - int ClearPacketEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::PACKET_EVENT_COUNT; ++i) - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->PacketEventBindings->Clear(Key((Hooks::PacketEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all [Player] events, or one type of [Player] event. - * - * If `event_type` is `nil`, all [Player] event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto () - * @proto (event_type) - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterPlayerEvent] - */ - int ClearPlayerEvents(Eluna* E) - { - typedef EventKey Key; - - if (lua_isnoneornil(E->L, 1)) - { - E->PlayerEventBindings->Clear(); - } - else - { - uint32 event_type = E->CHECKVAL(1); - E->PlayerEventBindings->Clear(Key((Hooks::PlayerEvents)event_type)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a [Player]'s gossip events, or one type of event. - * - * If `event_type` is `nil`, all the [Player]'s gossip event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto (entry) - * @proto (entry, event_type) - * @param uint32 entry : the low GUID of a [Player] whose handlers will be cleared - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterPlayerGossipEvent] - */ - int ClearPlayerGossipEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::GOSSIP_EVENT_COUNT; ++i) - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->PlayerGossipBindings->Clear(Key((Hooks::GossipEvents)event_type, entry)); - } - return 0; - } - - /** - * Unbinds event handlers for either all server events, or one type of event. - * - * If `event_type` is `nil`, all server event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto () - * @proto (event_type) - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterServerEvent] - */ - int ClearServerEvents(Eluna* E) - { - typedef EventKey Key; - - if (lua_isnoneornil(E->L, 1)) - { - E->ServerEventBindings->Clear(); - } - else - { - uint32 event_type = E->CHECKVAL(1); - E->ServerEventBindings->Clear(Key((Hooks::ServerEvents)event_type)); - } - return 0; - } - - /** - * Unbinds event handlers for either all of a non-instanced [Map]'s events, or one type of event. - * - * If `event_type` is `nil`, all the non-instanced [Map]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto (map_id) - * @proto (map_id, event_type) - * @param uint32 map_id : the ID of a [Map] - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterPlayerGossipEvent] - */ - int ClearMapEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->MapEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); - } - - return 0; - } - - /** - * Unbinds event handlers for either all of an instanced [Map]'s events, or one type of event. - * - * If `event_type` is `nil`, all the instanced [Map]'s event handlers are cleared. - * - * Otherwise, only event handlers for `event_type` are cleared. - * - * @proto (instance_id) - * @proto (instance_id, event_type) - * @param uint32 entry : the ID of an instance of a [Map] - * @param uint32 event_type : the event whose handlers will be cleared, see [Global:RegisterInstanceEvent] - */ - int ClearInstanceEvents(Eluna* E) - { - typedef EntryKey Key; - - if (lua_isnoneornil(E->L, 2)) - { - uint32 entry = E->CHECKVAL(1); - for (uint32 i = 1; i < Hooks::INSTANCE_EVENT_COUNT; ++i) - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)i, entry)); - } - else - { - uint32 entry = E->CHECKVAL(1); - uint32 event_type = E->CHECKVAL(2); - E->InstanceEventBindings->Clear(Key((Hooks::InstanceEvents)event_type, entry)); - } - - return 0; - } - - ElunaGlobal::ElunaRegister GlobalMethods[] = - { - // Hooks - { "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent }, - { "RegisterServerEvent", &LuaGlobalFunctions::RegisterServerEvent }, - { "RegisterPlayerEvent", &LuaGlobalFunctions::RegisterPlayerEvent }, - { "RegisterGuildEvent", &LuaGlobalFunctions::RegisterGuildEvent }, - { "RegisterGroupEvent", &LuaGlobalFunctions::RegisterGroupEvent }, - { "RegisterCreatureEvent", &LuaGlobalFunctions::RegisterCreatureEvent }, - { "RegisterUniqueCreatureEvent", &LuaGlobalFunctions::RegisterUniqueCreatureEvent }, - { "RegisterCreatureGossipEvent", &LuaGlobalFunctions::RegisterCreatureGossipEvent }, - { "RegisterGameObjectEvent", &LuaGlobalFunctions::RegisterGameObjectEvent }, - { "RegisterGameObjectGossipEvent", &LuaGlobalFunctions::RegisterGameObjectGossipEvent }, - { "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent }, - { "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent }, - { "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent }, - { "RegisterBGEvent", &LuaGlobalFunctions::RegisterBGEvent }, - { "RegisterMapEvent", &LuaGlobalFunctions::RegisterMapEvent }, - { "RegisterInstanceEvent", &LuaGlobalFunctions::RegisterInstanceEvent }, - - { "ClearBattleGroundEvents", &LuaGlobalFunctions::ClearBattleGroundEvents }, - { "ClearCreatureEvents", &LuaGlobalFunctions::ClearCreatureEvents }, - { "ClearUniqueCreatureEvents", &LuaGlobalFunctions::ClearUniqueCreatureEvents }, - { "ClearCreatureGossipEvents", &LuaGlobalFunctions::ClearCreatureGossipEvents }, - { "ClearGameObjectEvents", &LuaGlobalFunctions::ClearGameObjectEvents }, - { "ClearGameObjectGossipEvents", &LuaGlobalFunctions::ClearGameObjectGossipEvents }, - { "ClearGroupEvents", &LuaGlobalFunctions::ClearGroupEvents }, - { "ClearGuildEvents", &LuaGlobalFunctions::ClearGuildEvents }, - { "ClearItemEvents", &LuaGlobalFunctions::ClearItemEvents }, - { "ClearItemGossipEvents", &LuaGlobalFunctions::ClearItemGossipEvents }, - { "ClearPacketEvents", &LuaGlobalFunctions::ClearPacketEvents }, - { "ClearPlayerEvents", &LuaGlobalFunctions::ClearPlayerEvents }, - { "ClearPlayerGossipEvents", &LuaGlobalFunctions::ClearPlayerGossipEvents }, - { "ClearServerEvents", &LuaGlobalFunctions::ClearServerEvents }, - { "ClearMapEvents", &LuaGlobalFunctions::ClearMapEvents }, - { "ClearInstanceEvents", &LuaGlobalFunctions::ClearInstanceEvents }, - - // Getters - { "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine }, - { "GetCoreName", &LuaGlobalFunctions::GetCoreName }, - { "GetRealmID", &LuaGlobalFunctions::GetRealmID }, - { "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion }, - { "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion }, - { "GetStateMap", &LuaGlobalFunctions::GetStateMap, METHOD_REG_MAP }, // Map state method only in multistate - { "GetStateMapId", &LuaGlobalFunctions::GetStateMapId }, - { "GetStateInstanceId", &LuaGlobalFunctions::GetStateInstanceId }, - { "GetQuest", &LuaGlobalFunctions::GetQuest }, - { "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID, METHOD_REG_WORLD }, // World state method only in multistate - { "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName, METHOD_REG_WORLD }, // World state method only in multistate - { "GetGameTime", &LuaGlobalFunctions::GetGameTime }, - { "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld, METHOD_REG_WORLD }, // World state method only in multistate - { "GetPlayersOnMap", nullptr, METHOD_REG_NONE }, // Map state method only in multistate TODO - { "GetGuildByName", &LuaGlobalFunctions::GetGuildByName }, - { "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID }, - { "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount }, - { "GetPlayerGUID", &LuaGlobalFunctions::GetPlayerGUID }, - { "GetItemGUID", &LuaGlobalFunctions::GetItemGUID }, - { "GetObjectGUID", &LuaGlobalFunctions::GetObjectGUID }, - { "GetUnitGUID", &LuaGlobalFunctions::GetUnitGUID }, - { "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow }, - { "GetGUIDType", &LuaGlobalFunctions::GetGUIDType }, - { "GetGUIDEntry", &LuaGlobalFunctions::GetGUIDEntry }, - { "GetAreaName", &LuaGlobalFunctions::GetAreaName }, - { "bit_not", &LuaGlobalFunctions::bit_not }, - { "bit_xor", &LuaGlobalFunctions::bit_xor }, - { "bit_rshift", &LuaGlobalFunctions::bit_rshift }, - { "bit_lshift", &LuaGlobalFunctions::bit_lshift }, - { "bit_or", &LuaGlobalFunctions::bit_or }, - { "bit_and", &LuaGlobalFunctions::bit_and }, - { "GetItemLink", &LuaGlobalFunctions::GetItemLink }, - { "GetMapById", &LuaGlobalFunctions::GetMapById }, - { "GetCurrTime", &LuaGlobalFunctions::GetCurrTime }, - { "GetTimeDiff", &LuaGlobalFunctions::GetTimeDiff }, - { "PrintInfo", &LuaGlobalFunctions::PrintInfo }, - { "PrintError", &LuaGlobalFunctions::PrintError }, - { "PrintDebug", &LuaGlobalFunctions::PrintDebug }, - { "GetActiveGameEvents", &LuaGlobalFunctions::GetActiveGameEvents }, - - // Boolean - { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos }, - { "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos }, - { "IsBankPos", &LuaGlobalFunctions::IsBankPos }, - { "IsBagPos", &LuaGlobalFunctions::IsBagPos }, - { "IsGameEventActive", &LuaGlobalFunctions::IsGameEventActive }, - - // Other - { "ReloadEluna", &LuaGlobalFunctions::ReloadEluna }, - { "RunCommand", &LuaGlobalFunctions::RunCommand }, - { "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage }, - { "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery }, - { "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute }, - { "CharDBQuery", &LuaGlobalFunctions::CharDBQuery }, - { "CharDBExecute", &LuaGlobalFunctions::CharDBExecute }, - { "AuthDBQuery", &LuaGlobalFunctions::AuthDBQuery }, - { "AuthDBExecute", &LuaGlobalFunctions::AuthDBExecute }, - { "CreateLuaEvent", &LuaGlobalFunctions::CreateLuaEvent }, - { "RemoveEventById", &LuaGlobalFunctions::RemoveEventById }, - { "RemoveEvents", &LuaGlobalFunctions::RemoveEvents }, - { "PerformIngameSpawn", &LuaGlobalFunctions::PerformIngameSpawn }, - { "CreatePacket", &LuaGlobalFunctions::CreatePacket }, - { "AddVendorItem", &LuaGlobalFunctions::AddVendorItem }, - { "VendorRemoveItem", &LuaGlobalFunctions::VendorRemoveItem }, - { "VendorRemoveAllItems", &LuaGlobalFunctions::VendorRemoveAllItems }, - { "Kick", &LuaGlobalFunctions::Kick }, - { "Ban", &LuaGlobalFunctions::Ban }, - { "SaveAllPlayers", &LuaGlobalFunctions::SaveAllPlayers }, - { "SendMail", &LuaGlobalFunctions::SendMail }, - { "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath }, - { "CreateInt64", &LuaGlobalFunctions::CreateLongLong }, - { "CreateUint64", &LuaGlobalFunctions::CreateULongLong }, - { "StartGameEvent", &LuaGlobalFunctions::StartGameEvent }, - { "StopGameEvent", &LuaGlobalFunctions::StopGameEvent }, - - // unimplemented - { "WorldDBQueryAsync", nullptr, METHOD_REG_NONE }, - { "CharDBQueryAsync", nullptr, METHOD_REG_NONE }, - { "AuthDBQueryAsync", nullptr, METHOD_REG_NONE }, - - { NULL, NULL, METHOD_REG_NONE } - }; -} -#endif diff --git a/methods/Mangos/GroupMethods.h b/methods/Mangos/GroupMethods.h deleted file mode 100644 index 86e25d0f94..0000000000 --- a/methods/Mangos/GroupMethods.h +++ /dev/null @@ -1,420 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef GROUPMETHODS_H -#define GROUPMETHODS_H - -/*** - * Inherits all methods from: none - */ -namespace LuaGroup -{ - /** - * Returns 'true' if the [Player] is the [Group] leader - * - * @param ObjectGuid guid : guid of a possible leader - * @return bool isLeader - */ - int IsLeader(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - E->Push(group->IsLeader(guid)); - return 1; - } - - /** - * Returns 'true' if the [Group] is full - * - * @return bool isFull - */ - int IsFull(Eluna* E, Group* group) - { - E->Push(group->IsFull()); - return 1; - } - -#if !(defined(CLASSIC) || defined(TBC)) - /** - * Returns 'true' if the [Group] is a LFG group - * - * @return bool isLFGGroup - */ - int IsLFGGroup(Eluna* E, Group* group) - { - E->Push(group->isLFGGroup()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Group] is a raid [Group] - * - * @return bool isRaid - */ - int IsRaidGroup(Eluna* E, Group* group) - { - E->Push(group->isRaidGroup()); - return 1; - } - - /** - * Returns 'true' if the [Group] is a battleground [Group] - * - * @return bool isBG - */ - int IsBGGroup(Eluna* E, Group* group) - { - E->Push(group->isBGGroup()); - return 1; - } - - /** - * Returns 'true' if the [Player] is a member of this [Group] - * - * @param ObjectGuid guid : guid of a player - * @return bool isMember - */ - int IsMember(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - E->Push(group->IsMember(guid)); - return 1; - } - - /** - * Returns 'true' if the [Player] is an assistant of this [Group] - * - * @param ObjectGuid guid : guid of a player - * @return bool isAssistant - */ - int IsAssistant(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - E->Push(group->IsAssistant(guid)); - return 1; - } - - /** - * Returns 'true' if the [Player]s are in the same subgroup in this [Group] - * - * @param [Player] player1 : first [Player] to check - * @param [Player] player2 : second [Player] to check - * @return bool sameSubGroup - */ - int SameSubGroup(Eluna* E, Group* group) - { - Player* player1 = E->CHECKOBJ(2); - Player* player2 = E->CHECKOBJ(3); - E->Push(group->SameSubGroup(player1, player2)); - return 1; - } - - /** - * Returns 'true' if the subgroup has free slots in this [Group] - * - * @param uint8 subGroup : subGroup ID to check - * @return bool hasFreeSlot - */ - int HasFreeSlotSubGroup(Eluna* E, Group* group) - { - uint8 subGroup = E->CHECKVAL(2); - - if (subGroup >= MAX_RAID_SUBGROUPS) - { - luaL_argerror(E->L, 2, "valid subGroup ID expected"); - return 0; - } - - E->Push(group->HasFreeSlotSubGroup(subGroup)); - return 1; - } - - /** - * Adds a new member to the [Group] - * - * @param [Player] player : [Player] to add to the group - * @return bool added : true if member was added - */ - int AddMember(Eluna* E, Group* group) - { - Player* player = E->CHECKOBJ(2); - - if (player->GetGroup() || !group->IsCreated() || group->IsFull()) - { - E->Push(false); - return 1; - } - - if (player->GetGroupInvite()) - player->UninviteFromGroup(); - - bool success = group->AddMember(player->GetObjectGuid(), player->GetName()); - - E->Push(success); - return 1; - } - - /** - * Returns a table with the [Player]s in this [Group] - * - * @return table groupPlayers : table of [Player]s - */ - int GetMembers(Eluna* E, Group* group) - { - lua_newtable(E->L); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next()) - { - Player* member = itr->getSource(); - - if (!member || !member->GetSession()) - continue; - - E->Push(member); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); // push table to top of stack - return 1; - } - - /** - * Returns [Group] leader GUID - * - * @return ObjectGuid leaderGUID - */ - int GetLeaderGUID(Eluna* E, Group* group) - { - E->Push(group->GetLeaderGuid()); - return 1; - } - - /** - * Returns the [Group]'s GUID - * - * @return ObjectGuid groupGUID - */ - int GetGUID(Eluna* E, Group* group) - { -#ifdef CLASSIC - E->Push(group->GetId()); -#else - E->Push(group->GET_GUID()); -#endif - return 1; - } - - /** - * Returns a [Group] member's GUID by their name - * - * @param string name : the [Player]'s name - * @return ObjectGuid memberGUID - */ - int GetMemberGUID(Eluna* E, Group* group) - { - const char* name = E->CHECKVAL(2); - - E->Push(group->GetMemberGuid(name)); - return 1; - } - - /** - * Returns the member count of this [Group] - * - * @return uint32 memberCount - */ - int GetMembersCount(Eluna* E, Group* group) - { - E->Push(group->GetMembersCount()); - return 1; - } - - /** - * Returns the [Player]'s subgroup ID of this [Group] - * - * @param ObjectGuid guid : guid of the player - * @return uint8 subGroupID : a valid subgroup ID or MAX_RAID_SUBGROUPS+1 - */ - int GetMemberGroup(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - E->Push(group->GetMemberGroup(guid)); - return 1; - } - - /** - * Sets the leader of this [Group] - * - * @param ObjectGuid guid : guid of the new leader - */ - int SetLeader(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - group->ChangeLeader(guid); - group->SendUpdate(); - return 0; - } - - /** - * Sends a specified [WorldPacket] to this [Group] - * - * @param [WorldPacket] packet : the [WorldPacket] to send - * @param bool ignorePlayersInBg : ignores [Player]s in a battleground - * @param ObjectGuid ignore : ignore a [Player] by their GUID - */ - int SendPacket(Eluna* E, Group* group) - { - WorldPacket* data = E->CHECKOBJ(2); - bool ignorePlayersInBg = E->CHECKVAL(3); - ObjectGuid ignore = E->CHECKVAL(4); - - group->BroadcastPacket(data, ignorePlayersInBg, -1, ignore); - return 0; - } - - /** - * Removes a [Player] from this [Group] and returns 'true' if successful - * - *
-     * enum RemoveMethod
-     * {
-     *     GROUP_REMOVEMETHOD_DEFAULT  = 0,
-     *     GROUP_REMOVEMETHOD_KICK     = 1,
-     *     GROUP_REMOVEMETHOD_LEAVE    = 2,
-     *     GROUP_REMOVEMETHOD_KICK_LFG = 3
-     * };
-     * 
- * - * @param ObjectGuid guid : guid of the player to remove - * @param [RemoveMethod] method : method used to remove the player - * @return bool removed - */ - int RemoveMember(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - uint32 method = E->CHECKVAL(3, 0); - - E->Push(group->RemoveMember(guid, method)); - return 1; - } - - /** - * Disbands this [Group] - * - */ - int Disband(Eluna* /*E*/, Group* group) - { - group->Disband(); - return 0; - } - - /** - * Converts this [Group] to a raid [Group] - * - */ - int ConvertToRaid(Eluna* /*E*/, Group* group) - { - group->ConvertToRaid(); - return 0; - } - - /** - * Sets the member's subGroup - * - * @param ObjectGuid guid : guid of the player to move - * @param uint8 groupID : the subGroup's ID - */ - int SetMembersGroup(Eluna* E, Group* group) - { - ObjectGuid guid = E->CHECKVAL(2); - uint8 subGroup = E->CHECKVAL(3); - - if (subGroup >= MAX_RAID_SUBGROUPS) - { - luaL_argerror(E->L, 3, "valid subGroup ID expected"); - return 0; - } - - if (!group->HasFreeSlotSubGroup(subGroup)) - return 0; - - group->ChangeMembersGroup(guid, subGroup); - return 0; - } - - /** - * Sets the target icon of an object for the [Group] - * - * @param uint8 icon : the icon (Skull, Square, etc) - * @param ObjectGuid target : GUID of the icon target, 0 is to clear the icon - * @param ObjectGuid setter : GUID of the icon setter - */ - int SetTargetIcon(Eluna* E, Group* group) - { - uint8 icon = E->CHECKVAL(2); - ObjectGuid target = E->CHECKVAL(3); - ObjectGuid setter = E->CHECKVAL(4, ObjectGuid()); - - if (icon >= TARGETICONCOUNT) - return luaL_argerror(E->L, 2, "valid target icon expected"); - -#if (defined(CLASSIC) || defined(TBC)) - group->SetTargetIcon(icon, target); -#else - group->SetTargetIcon(icon, setter, target); -#endif - return 0; - } - - ElunaRegister GroupMethods[] = - { - // Getters - { "GetMembers", &LuaGroup::GetMembers, METHOD_REG_WORLD }, // World state method only in multistate - { "GetLeaderGUID", &LuaGroup::GetLeaderGUID }, - { "GetGUID", &LuaGroup::GetGUID }, - { "GetMemberGroup", &LuaGroup::GetMemberGroup }, - { "GetMemberGUID", &LuaGroup::GetMemberGUID }, - { "GetMembersCount", &LuaGroup::GetMembersCount }, - - // Setters - { "SetLeader", &LuaGroup::SetLeader, METHOD_REG_WORLD }, // World state method only in multistate - { "SetMembersGroup", &LuaGroup::SetMembersGroup, METHOD_REG_WORLD }, // World state method only in multistate - { "SetTargetIcon", &LuaGroup::SetTargetIcon, METHOD_REG_WORLD }, // World state method only in multistate - - // Boolean - { "IsLeader", &LuaGroup::IsLeader }, - { "AddMember", &LuaGroup::AddMember, METHOD_REG_WORLD }, // World state method only in multistate - { "RemoveMember", &LuaGroup::RemoveMember, METHOD_REG_WORLD }, // World state method only in multistate - { "Disband", &LuaGroup::Disband, METHOD_REG_WORLD }, // World state method only in multistate - { "IsFull", &LuaGroup::IsFull }, - { "IsRaidGroup", &LuaGroup::IsRaidGroup }, - { "IsBGGroup", &LuaGroup::IsBGGroup }, - { "IsMember", &LuaGroup::IsMember }, - { "IsAssistant", &LuaGroup::IsAssistant }, - { "SameSubGroup", &LuaGroup::SameSubGroup }, - { "HasFreeSlotSubGroup", &LuaGroup::HasFreeSlotSubGroup }, -#if !(defined(CLASSIC) || defined(TBC)) - { "IsLFGGroup", &LuaGroup::IsLFGGroup }, -#else - { "IsLFGGroup", nullptr, METHOD_REG_NONE }, -#endif - // Other - { "SendPacket", &LuaGroup::SendPacket }, - { "ConvertToRaid", &LuaGroup::ConvertToRaid, METHOD_REG_WORLD }, // World state method only in multistate - - // Not implemented methods - { "IsBFGroup", nullptr, METHOD_REG_NONE }, // not implemented - { "ConvertToLFG", nullptr, METHOD_REG_NONE }, // not implemented - { "GetMemberFlags", nullptr, METHOD_REG_NONE }, // not implemented - { "SetMemberFlag", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL, METHOD_REG_NONE } - }; -}; - -#endif diff --git a/methods/Mangos/GuildMethods.h b/methods/Mangos/GuildMethods.h deleted file mode 100644 index 39c0421d83..0000000000 --- a/methods/Mangos/GuildMethods.h +++ /dev/null @@ -1,267 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef GUILDMETHODS_H -#define GUILDMETHODS_H - -/*** - * Inherits all methods from: none - */ -namespace LuaGuild -{ - /** - * Returns a table with the [Player]s in this [Guild] - * - * Only the players that are online and on some map. - * - * @return table guildPlayers : table of [Player]s - */ - int GetMembers(Eluna* E, Guild* guild) - { - lua_newtable(E->L); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - eObjectAccessor()DoForAllPlayers([&](Player* player) - { - if (player->IsInWorld() && player->GetGuildId() == guild->GetId()) - { - E->Push(player); - lua_rawseti(E->L, tbl, ++i); - } - }); - - lua_settop(E->L, tbl); // push table to top of stack - return 1; - } - - /** - * Returns the member count of this [Guild] - * - * @return uint32 memberCount - */ - int GetMemberCount(Eluna* E, Guild* guild) - { - E->Push(guild->GetMemberSize()); - return 1; - } - - /** - * Finds and returns the [Guild] leader by their GUID if logged in - * - * @return [Player] leader - */ - int GetLeader(Eluna* E, Guild* guild) - { - E->Push(eObjectAccessor()FindPlayer(guild->GetLeaderGuid())); - return 1; - } - - /** - * Returns [Guild] leader GUID - * - * @return ObjectGuid leaderGUID - */ - int GetLeaderGUID(Eluna* E, Guild* guild) - { - E->Push(guild->GetLeaderGuid()); - return 1; - } - - /** - * Returns the [Guild]s entry ID - * - * @return uint32 entryId - */ - int GetId(Eluna* E, Guild* guild) - { - E->Push(guild->GetId()); - return 1; - } - - /** - * Returns the [Guild]s name - * - * @return string guildName - */ - int GetName(Eluna* E, Guild* guild) - { - E->Push(guild->GetName()); - return 1; - } - - /** - * Returns the [Guild]s current Message Of The Day - * - * @return string guildMOTD - */ - int GetMOTD(Eluna* E, Guild* guild) - { - E->Push(guild->GetMOTD()); - return 1; - } - - /** - * Returns the [Guild]s current info - * - * @return string guildInfo - */ - int GetInfo(Eluna* E, Guild* guild) - { - E->Push(guild->GetGINFO()); - return 1; - } - -#if defined(CLASSIC) || defined(TBC) || defined(WOTLK) - /** - * Sets the leader of this [Guild] - * - * @param [Player] leader : the [Player] leader to change - */ - int SetLeader(Eluna* E, Guild* guild) - { - Player* player = E->CHECKOBJ(2); - - guild->SetLeader(player->GET_GUID()); - return 0; - } -#endif - -#ifndef CLASSIC - /** - * Sets the information of the bank tab specified - * - * @param uint8 tabId : the ID of the tab specified - * @param string info : the information to be set to the bank tab - */ - int SetBankTabText(Eluna* E, Guild* guild) - { - uint8 tabId = E->CHECKVAL(2); - const char* text = E->CHECKVAL(3); - - guild->SetGuildBankTabText(tabId, text); - return 0; - } -#endif - - // SendPacketToGuild(packet) - /** - * Sends a [WorldPacket] to all the [Player]s in the [Guild] - * - * @param [WorldPacket] packet : the [WorldPacket] to be sent to the [Player]s - */ - int SendPacket(Eluna* E, Guild* guild) - { - WorldPacket* data = E->CHECKOBJ(2); - - guild->BroadcastPacket(data); - return 0; - } - - // SendPacketToRankedInGuild(packet, rankId) - /** - * Sends a [WorldPacket] to all the [Player]s at the specified rank in the [Guild] - * - * @param [WorldPacket] packet : the [WorldPacket] to be sent to the [Player]s - * @param uint8 rankId : the rank ID - */ - int SendPacketToRanked(Eluna* E, Guild* guild) - { - WorldPacket* data = E->CHECKOBJ(2); - uint8 ranked = E->CHECKVAL(3); - - guild->BroadcastPacketToRank(data, ranked); - return 0; - } - - /** - * Disbands the [Guild] - */ - int Disband(Eluna* /*E*/, Guild* guild) - { - guild->Disband(); - return 0; - } - - /** - * Adds the specified [Player] to the [Guild] at the specified rank. - * - * If no rank is specified, defaults to none. - * - * @param [Player] player : the [Player] to be added to the guild - * @param uint8 rankId : the rank ID - */ - int AddMember(Eluna* E, Guild* guild) - { - Player* player = E->CHECKOBJ(2); - uint8 rankId = E->CHECKVAL(3, GUILD_RANK_NONE); - - guild->AddMember(player->GET_GUID(), rankId); - return 0; - } - - /** - * Removes the specified [Player] from the [Guild]. - * - * @param [Player] player : the [Player] to be removed from the guild - * @param bool isDisbanding : default 'false', should only be set to 'true' if the guild is triggered to disband - */ - int DeleteMember(Eluna* E, Guild* guild) - { - Player* player = E->CHECKOBJ(2); - bool isDisbanding = E->CHECKVAL(3, false); - - guild->DelMember(player->GET_GUID(), isDisbanding); - return 0; - } - - /** - * Promotes/demotes the [Player] to the specified rank. - * - * @param [Player] player : the [Player] to be promoted/demoted - * @param uint8 rankId : the rank ID - */ - int SetMemberRank(Eluna* E, Guild* guild) - { - Player* player = E->CHECKOBJ(2); - uint8 newRank = E->CHECKVAL(3); - - guild->ChangeMemberRank(player->GET_GUID(), newRank); - return 0; - } - - ElunaRegister GuildMethods[] = - { - // Getters - { "GetMembers", &LuaGuild::GetMembers, METHOD_REG_WORLD }, // World state method only in multistate - { "GetLeader", &LuaGuild::GetLeader, METHOD_REG_WORLD }, // World state method only in multistate - { "GetLeaderGUID", &LuaGuild::GetLeaderGUID }, - { "GetId", &LuaGuild::GetId }, - { "GetName", &LuaGuild::GetName }, - { "GetMOTD", &LuaGuild::GetMOTD }, - { "GetInfo", &LuaGuild::GetInfo }, - { "GetMemberCount", &LuaGuild::GetMemberCount }, - - // Setters - { "SetMemberRank", &LuaGuild::SetMemberRank, METHOD_REG_WORLD }, // World state method only in multistate - { "SetLeader", &LuaGuild::SetLeader, METHOD_REG_WORLD }, // World state method only in multistate -#ifndef CLASSIC - { "SetBankTabText", &LuaGuild::SetBankTabText, METHOD_REG_WORLD }, // World state method only in multistate -#else - { "SetBankTabText", nullptr, METHOD_REG_NONE}, -#endif - - // Other - { "SendPacket", &LuaGuild::SendPacket }, - { "SendPacketToRanked", &LuaGuild::SendPacketToRanked }, - { "Disband", &LuaGuild::Disband, METHOD_REG_WORLD }, // World state method only in multistate - { "AddMember", &LuaGuild::AddMember, METHOD_REG_WORLD }, // World state method only in multistate - { "DeleteMember", &LuaGuild::DeleteMember, METHOD_REG_WORLD }, // World state method only in multistate - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/ItemMethods.h b/methods/Mangos/ItemMethods.h deleted file mode 100644 index 5ec717d948..0000000000 --- a/methods/Mangos/ItemMethods.h +++ /dev/null @@ -1,875 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef ITEMMETHODS_H -#define ITEMMETHODS_H - -/*** - * Inherits all methods from: [Object] - */ -namespace LuaItem -{ - /** - * Returns 'true' if the [Item] is soulbound, 'false' otherwise - * - * @return bool isSoulBound - */ - int IsSoulBound(Eluna* E, Item* item) - { - E->Push(item->IsSoulBound()); - return 1; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns 'true' if the [Item] is account bound, 'false' otherwise - * - * @return bool isAccountBound - */ - int IsBoundAccountWide(Eluna* E, Item* item) - { - E->Push(item->IsBoundAccountWide()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Item] is bound to a [Player] by an enchant, 'false' otehrwise - * - * @return bool isBoundByEnchant - */ - int IsBoundByEnchant(Eluna* E, Item* item) - { - E->Push(item->IsBoundByEnchant()); - return 1; - } - - /** - * Returns 'true' if the [Item] is not bound to the [Player] specified, 'false' otherwise - * - * @param [Player] player : the [Player] object to check the item against - * @return bool isNotBound - */ - int IsNotBoundToPlayer(Eluna* E, Item* item) - { - Player* player = E->CHECKOBJ(2); - - E->Push(item->IsBindedNotWith(player)); - return 1; - } - - /** - * Returns 'true' if the [Item] is locked, 'false' otherwise - * - * @return bool isLocked - */ - int IsLocked(Eluna* E, Item* item) - { - E->Push(item->IsLocked()); - return 1; - } - - /** - * Returns 'true' if the [Item] is a bag, 'false' otherwise - * - * @return bool isBag - */ - int IsBag(Eluna* E, Item* item) - { - E->Push(item->IsBag()); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Item] is a currency token, 'false' otherwise - * - * @return bool isCurrencyToken - */ - int IsCurrencyToken(Eluna* E, Item* item) - { - E->Push(item->IsCurrencyToken()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Item] is a not an empty bag, 'false' otherwise - * - * @return bool isNotEmptyBag - */ - int IsNotEmptyBag(Eluna* E, Item* item) - { - E->Push(item->IsNotEmptyBag()); - return 1; - } - - /** - * Returns 'true' if the [Item] is broken, 'false' otherwise - * - * @return bool isBroken - */ - int IsBroken(Eluna* E, Item* item) - { - E->Push(item->IsBroken()); - return 1; - } - - /** - * Returns 'true' if the [Item] can be traded, 'false' otherwise - * - * @return bool isTradeable - */ - int CanBeTraded(Eluna* E, Item* item) - { -#if (defined(TBC) || defined(CLASSIC)) - E->Push(item->CanBeTraded()); -#else - bool mail = E->CHECKVAL(2, false); - E->Push(item->CanBeTraded(mail)); -#endif - return 1; - } - - /** - * Returns 'true' if the [Item] is currently in a trade window, 'false' otherwise - * - * @return bool isInTrade - */ - int IsInTrade(Eluna* E, Item* item) - { - E->Push(item->IsInTrade()); - return 1; - } - - /** - * Returns 'true' if the [Item] is currently in a bag, 'false' otherwise - * - * @return bool isInBag - */ - int IsInBag(Eluna* E, Item* item) - { - E->Push(item->IsInBag()); - return 1; - } - - /** - * Returns 'true' if the [Item] is currently equipped, 'false' otherwise - * - * @return bool isEquipped - */ - int IsEquipped(Eluna* E, Item* item) - { - E->Push(item->IsEquipped()); - return 1; - } - - /** - * Returns 'true' if the [Item] has the [Quest] specified tied to it, 'false' otherwise - * - * @param uint32 questId : the [Quest] id to be checked - * @return bool hasQuest - */ - int HasQuest(Eluna* E, Item* item) - { - uint32 quest = E->CHECKVAL(2); - - E->Push(item->HasQuest(quest)); - return 1; - } - - /** - * Returns 'true' if the [Item] is a potion, 'false' otherwise - * - * @return bool isPotion - */ - int IsPotion(Eluna* E, Item* item) - { - E->Push(item->IsPotion()); - return 1; - } - -#if defined(WOTLK) - /** - * Returns 'true' if the [Item] is a weapon vellum, 'false' otherwise - * - * @return bool isWeaponVellum - */ - int IsWeaponVellum(Eluna* E, Item* item) - { - E->Push(item->IsWeaponVellum()); - return 1; - } - - /** - * Returns 'true' if the [Item] is an armor vellum, 'false' otherwise - * - * @return bool isArmorVellum - */ - int IsArmorVellum(Eluna* E, Item* item) - { - E->Push(item->IsArmorVellum()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Item] is a conjured consumable, 'false' otherwise - * - * @return bool isConjuredConsumable - */ - int IsConjuredConsumable(Eluna* E, Item* item) - { - E->Push(item->IsConjuredConsumable()); - return 1; - } - - /** - * Returns the chat link of the [Item] - * - *
-     * enum LocaleConstant
-     * {
-     *     LOCALE_enUS = 0,
-     *     LOCALE_koKR = 1,
-     *     LOCALE_frFR = 2,
-     *     LOCALE_deDE = 3,
-     *     LOCALE_zhCN = 4,
-     *     LOCALE_zhTW = 5,
-     *     LOCALE_esES = 6,
-     *     LOCALE_esMX = 7,
-     *     LOCALE_ruRU = 8
-     * };
-     * 
- * - * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the [Item]'s name in - * @return string itemLink - */ - int GetItemLink(Eluna* E, Item* item) - { - uint8 locale = E->CHECKVAL(2, DEFAULT_LOCALE); - if (locale >= TOTAL_LOCALES) - return luaL_argerror(E->L, 2, "valid LocaleConstant expected"); - - const ItemTemplate* temp = item->GetTemplate(); - std::string name = temp->Name1; - if (ItemLocale const* il = eObjectMgr->GetItemLocale(temp->ItemId)) - ObjectMgr::GetLocaleString(il->Name, static_cast(locale), name); - -#ifndef CLASSIC - if (int32 itemRandPropId = item->GetItemRandomPropertyId()) - { -#if defined(CATA) || defined (MISTS) - char* suffix = NULL; -#else - char* const* suffix = NULL; -#endif - if (itemRandPropId < 0) - { - const ItemRandomSuffixEntry* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId()); - if (itemRandEntry) - suffix = itemRandEntry->nameSuffix; - } - else - { - const ItemRandomPropertiesEntry* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId()); - if (itemRandEntry) - suffix = itemRandEntry->nameSuffix; - } - if (suffix) - { - name += ' '; - name += suffix[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)]; - } - } -#endif - - std::ostringstream oss; - oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec << - "|Hitem:" << temp->ItemId << ":" << - item->GetEnchantmentId(PERM_ENCHANTMENT_SLOT) << ":" << -#ifndef CLASSIC - item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT) << ":" << - item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_2) << ":" << - item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_3) << ":" << - item->GetEnchantmentId(BONUS_ENCHANTMENT_SLOT) << ":" << -#endif - item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" << - (uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r"; - - E->Push(oss.str()); - return 1; - } - - int GetOwnerGUID(Eluna* E, Item* item) - { - E->Push(item->GetOwnerGuid()); - return 1; - } - - /** - * Returns the [Player] who currently owns the [Item] - * - * @return [Player] player : the [Player] who owns the [Item] - */ - int GetOwner(Eluna* E, Item* item) - { - E->Push(item->GetOwner()); - return 1; - } - - /** - * Returns the [Item]s stack count - * - * @return uint32 count - */ - int GetCount(Eluna* E, Item* item) - { - E->Push(item->GetCount()); - return 1; - } - - /** - * Returns the [Item]s max stack count - * - * @return uint32 maxCount - */ - int GetMaxStackCount(Eluna* E, Item* item) - { - E->Push(item->GetMaxStackCount()); - return 1; - } - - /** - * Returns the [Item]s current slot - * - * @return uint8 slot - */ - int GetSlot(Eluna* E, Item* item) - { - E->Push(item->GetSlot()); - return 1; - } - - /** - * Returns the [Item]s current bag slot - * - * @return uint8 bagSlot - */ - int GetBagSlot(Eluna* E, Item* item) - { - E->Push(item->GetBagSlot()); - return 1; - } - - /** - * Returns the [Item]s enchantment ID by enchant slot specified - * - * @param [EnchantmentSlot] enchantSlot : the enchant slot specified - * @return uint32 enchantId : the id of the enchant slot specified - */ - int GetEnchantmentId(Eluna* E, Item* item) - { - uint32 enchant_slot = E->CHECKVAL(2); - - if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) - return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected"); - - E->Push(item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); - return 1; - } - - /** - * Returns the spell ID tied to the [Item] by spell index - * - * @param uint32 spellIndex : the spell index specified - * @return uint32 spellId : the id of the spell - */ - int GetSpellId(Eluna* E, Item* item) - { - uint32 index = E->CHECKVAL(2); - if (index >= MAX_ITEM_PROTO_SPELLS) - return luaL_argerror(E->L, 2, "valid SpellIndex expected"); - - E->Push(item->GetTemplate()->Spells[index].SpellId); - return 1; - } - - /** - * Returns the spell trigger tied to the [Item] by spell index - * - * @param uint32 spellIndex : the spell index specified - * @return uint32 spellTrigger : the spell trigger of the specified index - */ - int GetSpellTrigger(Eluna* E, Item* item) - { - uint32 index = E->CHECKVAL(2); - if (index >= MAX_ITEM_PROTO_SPELLS) - return luaL_argerror(E->L, 2, "valid SpellIndex expected"); - - E->Push(item->GetTemplate()->Spells[index].SpellTrigger); - return 1; - } - - /** - * Returns class of the [Item] - * - * @return uint32 class - */ - int GetClass(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->Class); - return 1; - } - - /** - * Returns subclass of the [Item] - * - * @return uint32 subClass - */ - int GetSubClass(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->SubClass); - return 1; - } - - /** - * Returns the ID of the [Item] - * - * @return uint32 itemId - */ - int GetItemId(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->ItemId); - return 1; - } - - /** - * Returns the name of the [Item] - * - * @return string name - */ - int GetName(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->Name1); - return 1; - } - - /** - * Returns the display ID of the [Item] - * - * @return uint32 displayId - */ - int GetDisplayId(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->DisplayInfoID); - return 1; - } - - /** - * Returns the quality of the [Item] - * - * @return uint32 quality - */ - int GetQuality(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->Quality); - return 1; - } - - /** - * Returns the flags of the [Item] - * - * @return uint32 flags - */ - int GetFlags(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->Flags); - return 1; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns the flags2 of the [Item] - * - * @return uint32 flags2 - */ - int GetFlags2(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->Flags2); - return 1; - } -#endif - - /** - * Returns the extraFlags of the [Item] - * - * @return uint32 extraFlags - */ - int GetExtraFlags(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->ExtraFlags); - return 1; - } - - /** - * Returns the default purchase count of the [Item] - * - * @return uint32 count - */ - int GetBuyCount(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->BuyCount); - return 1; - } - - /** - * Returns the purchase price of the [Item] - * - * @return uint32 price - */ - int GetBuyPrice(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->BuyPrice); - return 1; - } - - /** - * Returns the sell price of the [Item] - * - * @return uint32 price - */ - int GetSellPrice(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->SellPrice); - return 1; - } - - /** - * Returns the inventory type of the [Item] - * - * @return uint32 inventoryType - */ - int GetInventoryType(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->InventoryType); - return 1; - } - - /** - * Returns the [Player] classes allowed to use this [Item] - * - * @return uint32 allowableClass - */ - int GetAllowableClass(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->AllowableClass); - return 1; - } - - /** - * Returns the [Player] races allowed to use this [Item] - * - * @return uint32 allowableRace - */ - int GetAllowableRace(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->AllowableRace); - return 1; - } - - /** - * Returns the [Item]s level - * - * @return uint32 itemLevel - */ - int GetItemLevel(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->ItemLevel); - return 1; - } - - /** - * Returns the minimum level required to use this [Item] - * - * @return uint32 requiredLevel - */ - int GetRequiredLevel(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->RequiredLevel); - return 1; - } - -#ifdef WOTLK - int GetStatsCount(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->StatsCount); - return 1; - } -#endif - - /** - * Returns the random property ID of this [Item] - * - * @return uint32 randomPropertyId - */ - int GetRandomProperty(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->RandomProperty); - return 1; - } - -#ifndef CLASSIC - int GetRandomSuffix(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->RandomSuffix); - return 1; - } -#endif - - /** - * Returns the item set ID of this [Item] - * - * @return uint32 itemSetId - */ - int GetItemSet(Eluna* E, Item* item) - { - E->Push(item->GetTemplate()->ItemSet); - return 1; - } - - /** - * Returns the bag size of this [Item], 0 if [Item] is not a bag - * - * @return uint32 bagSize - */ - int GetBagSize(Eluna* E, Item* item) - { - if (Bag* bag = item->ToBag()) - E->Push(bag->GetBagSize()); - else - E->Push(0); - return 1; - } - - /** - * Sets the [Player] specified as the owner of the [Item] - * - * @param [Player] player : the [Player] specified - */ - int SetOwner(Eluna* E, Item* item) - { - Player* player = E->CHECKOBJ(2); - - item->SetOwnerGuid(player->GET_GUID()); - return 0; - } - - /** - * Sets the binding of the [Item] to 'true' or 'false' - * - * @param bool setBinding - */ - int SetBinding(Eluna* E, Item* item) - { - bool soulbound = E->CHECKVAL(2); - - item->SetBinding(soulbound); - item->SetState(ITEM_CHANGED, item->GetOwner()); - - return 0; - } - - /** - * Sets the stack count of the [Item] - * - * @param uint32 count - */ - int SetCount(Eluna* E, Item* item) - { - uint32 count = E->CHECKVAL(2); - item->SetCount(count); - return 0; - } - - /** - * Sets the specified enchantment of the [Item] to the specified slot - * - * @param uint32 enchantId : the ID of the enchant to be applied - * @param uint32 enchantSlot : the slot for the enchant to be applied to - * @return bool enchantmentSuccess : if enchantment is successfully set to specified slot, returns 'true', otherwise 'false' - */ - int SetEnchantment(Eluna* E, Item* item) - { - Player* owner = item->GetOwner(); - if (!owner) - { - E->Push(false); - return 1; - } - - uint32 enchant = E->CHECKVAL(2); - if (!sSpellItemEnchantmentStore.LookupEntry(enchant)) - { - E->Push(false); - return 1; - } - - EnchantmentSlot slot = (EnchantmentSlot)E->CHECKVAL(3); - if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) - return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected"); - - owner->ApplyEnchantment(item, slot, false); - item->SetEnchantment(slot, enchant, 0, 0); - owner->ApplyEnchantment(item, slot, true); - E->Push(true); - return 1; - } - - /* OTHER */ - /** - * Removes an enchant from the [Item] by the specified slot - * - * @param uint32 enchantSlot : the slot for the enchant to be removed from - * @return bool enchantmentRemoved : if enchantment is successfully removed from specified slot, returns 'true', otherwise 'false' - */ - int ClearEnchantment(Eluna* E, Item* item) - { - Player* owner = item->GetOwner(); - if (!owner) - { - E->Push(false); - return 1; - } - - EnchantmentSlot slot = (EnchantmentSlot)E->CHECKVAL(2); - if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) - return luaL_argerror(E->L, 2, "valid EnchantmentSlot expected"); - - if (!item->GetEnchantmentId(slot)) - { - E->Push(false); - return 1; - } - - owner->ApplyEnchantment(item, slot, false); - item->ClearEnchantment(slot); - E->Push(true); - return 1; - } - - /** - * Saves the [Item] to the database - */ - int SaveToDB(Eluna* /*E*/, Item* item) - { -#if defined TRINITY || defined AZEROTHCORE - CharacterDatabaseTransaction trans = CharacterDatabaseTransaction(nullptr); - item->SaveToDB(trans); -#else - item->SaveToDB(); -#endif - return 0; - } - - ElunaRegister ItemMethods[] = - { - // Getters - { "GetOwnerGUID", &LuaItem::GetOwnerGUID }, - { "GetOwner", &LuaItem::GetOwner }, - { "GetCount", &LuaItem::GetCount }, - { "GetMaxStackCount", &LuaItem::GetMaxStackCount }, - { "GetSlot", &LuaItem::GetSlot }, - { "GetBagSlot", &LuaItem::GetBagSlot }, - { "GetEnchantmentId", &LuaItem::GetEnchantmentId }, - { "GetSpellId", &LuaItem::GetSpellId }, - { "GetSpellTrigger", &LuaItem::GetSpellTrigger }, - { "GetItemLink", &LuaItem::GetItemLink }, - { "GetClass", &LuaItem::GetClass }, - { "GetSubClass", &LuaItem::GetSubClass }, - { "GetItemId", &LuaItem::GetItemId }, - { "GetName", &LuaItem::GetName }, - { "GetDisplayId", &LuaItem::GetDisplayId }, - { "GetQuality", &LuaItem::GetQuality }, - { "GetFlags", &LuaItem::GetFlags }, -#if (!defined(TBC) && !defined(CLASSIC)) - { "GetFlags2", &LuaItem::GetFlags2 }, -#else - { "GetFlags2", nullptr, METHOD_REG_NONE }, -#endif - { "GetExtraFlags", &LuaItem::GetExtraFlags }, - { "GetBuyCount", &LuaItem::GetBuyCount }, - { "GetBuyPrice", &LuaItem::GetBuyPrice }, - { "GetSellPrice", &LuaItem::GetSellPrice }, - { "GetInventoryType", &LuaItem::GetInventoryType }, - { "GetAllowableClass", &LuaItem::GetAllowableClass }, - { "GetAllowableRace", &LuaItem::GetAllowableRace }, - { "GetItemLevel", &LuaItem::GetItemLevel }, - { "GetRequiredLevel", &LuaItem::GetRequiredLevel }, - { "GetRandomProperty", &LuaItem::GetRandomProperty }, - { "GetItemSet", &LuaItem::GetItemSet }, - { "GetBagSize", &LuaItem::GetBagSize }, -#ifndef CLASSIC - { "GetRandomSuffix", &LuaItem::GetRandomSuffix }, -#else - { "GetRandomSuffix", nullptr, METHOD_REG_NONE }, -#endif -#ifdef WOTLK - { "GetStatsCount", &LuaItem::GetStatsCount }, -#else - { "GetStatsCount", nullptr, METHOD_REG_NONE }, -#endif - - // Setters - { "SetOwner", &LuaItem::SetOwner }, - { "SetBinding", &LuaItem::SetBinding }, - { "SetCount", &LuaItem::SetCount }, - - // Boolean - { "IsSoulBound", &LuaItem::IsSoulBound }, - { "IsBoundByEnchant", &LuaItem::IsBoundByEnchant }, - { "IsNotBoundToPlayer", &LuaItem::IsNotBoundToPlayer }, - { "IsLocked", &LuaItem::IsLocked }, - { "IsBag", &LuaItem::IsBag }, - { "IsNotEmptyBag", &LuaItem::IsNotEmptyBag }, - { "IsBroken", &LuaItem::IsBroken }, - { "CanBeTraded", &LuaItem::CanBeTraded }, - { "IsInTrade", &LuaItem::IsInTrade }, - { "IsInBag", &LuaItem::IsInBag }, - { "IsEquipped", &LuaItem::IsEquipped }, - { "HasQuest", &LuaItem::HasQuest }, - { "IsPotion", &LuaItem::IsPotion }, - { "IsConjuredConsumable", &LuaItem::IsConjuredConsumable }, - { "SetEnchantment", &LuaItem::SetEnchantment }, - { "ClearEnchantment", &LuaItem::ClearEnchantment }, -#ifndef CLASSIC - { "IsCurrencyToken", &LuaItem::IsCurrencyToken }, -#else - { "IsCurrencyToken", nullptr, METHOD_REG_NONE }, -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - { "IsBoundAccountWide", &LuaItem::IsBoundAccountWide }, -#else - { "IsBoundAccountWide", nullptr, METHOD_REG_NONE }, -#endif -#if defined(WOTLK) - { "IsWeaponVellum", &LuaItem::IsWeaponVellum }, - { "IsArmorVellum", &LuaItem::IsArmorVellum }, -#else - { "IsWeaponVellum", nullptr, METHOD_REG_NONE }, - { "IsArmorVellum", nullptr, METHOD_REG_NONE }, -#endif - - // Other - { "SaveToDB", &LuaItem::SaveToDB }, - - // Not implemented methods - { "IsRefundExpired", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/MapMethods.h b/methods/Mangos/MapMethods.h deleted file mode 100644 index b463e32a18..0000000000 --- a/methods/Mangos/MapMethods.h +++ /dev/null @@ -1,372 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef MAPMETHODS_H -#define MAPMETHODS_H - -#include "ElunaInstanceAI.h" - -/*** - * A game map, e.g. Azeroth, Eastern Kingdoms, the Molten Core, etc. - * - * Inherits all methods from: none - */ -namespace LuaMap -{ - -#ifndef CLASSIC - /** - * Returns `true` if the [Map] is an arena [BattleGround], `false` otherwise. - * - * @return bool isArena - */ - int IsArena(Eluna* E, Map* map) - { - E->Push(map->IsBattleArena()); - return 1; - } -#endif - - /** - * Returns `true` if the [Map] is a non-arena [BattleGround], `false` otherwise. - * - * @return bool isBattleGround - */ - int IsBattleground(Eluna* E, Map* map) - { - E->Push(map->IsBattleGround()); - return 1; - } - - /** - * Returns `true` if the [Map] is a dungeon, `false` otherwise. - * - * @return bool isDungeon - */ - int IsDungeon(Eluna* E, Map* map) - { - E->Push(map->IsDungeon()); - return 1; - } - - /** - * Returns `true` if the [Map] has no [Player]s, `false` otherwise. - * - * @return bool isEmpty - */ - int IsEmpty(Eluna* E, Map* map) - { - E->Push(map->isEmpty()); - return 1; - } - -#ifndef CLASSIC - /** - * Returns `true` if the [Map] is a heroic, `false` otherwise. - * - * @return bool isHeroic - */ - int IsHeroic(Eluna* E, Map* map) - { - E->Push(map->IsHeroic()); - return 1; - } -#endif - - /** - * Returns `true` if the [Map] is a raid, `false` otherwise. - * - * @return bool isRaid - */ - int IsRaid(Eluna* E, Map* map) - { - E->Push(map->IsRaid()); - return 1; - } - - /** - * Returns the name of the [Map]. - * - * @return string mapName - */ - int GetName(Eluna* E, Map* map) - { - E->Push(map->GetMapName()); - return 1; - } - - /** - * Returns the height of the [Map] at the given X and Y coordinates. - * - * In case of no height found nil is returned - * - * @param float x - * @param float y - * @return float z - */ - int GetHeight(Eluna* E, Map* map) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); -#if (defined(TBC) || defined(CLASSIC)) - float z = map->GetHeight(x, y, MAX_HEIGHT); -#else - uint32 phasemask = E->CHECKVAL(4, 1); - float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT); -#endif - if (z != INVALID_HEIGHT) - E->Push(z); - return 1; - } - - /** - * Returns the difficulty of the [Map]. - * - * Always returns 0 if the expansion is pre-TBC. - * - * @return int32 difficulty - */ - int GetDifficulty(Eluna* E, Map* map) - { -#ifndef CLASSIC - E->Push(map->GetDifficulty()); -#else - E->Push((Difficulty)0); -#endif - return 1; - } - - /** - * Returns the instance ID of the [Map]. - * - * @return uint32 instanceId - */ - int GetInstanceId(Eluna* E, Map* map) - { - E->Push(map->GetInstanceId()); - return 1; - } - - /** - * Returns the player count currently on the [Map] (excluding GMs). - * - * @return uint32 playerCount - */ - int GetPlayerCount(Eluna* E, Map* map) - { - E->Push(map->GetPlayersCountExceptGMs()); - return 1; - } - - /** - * Returns the ID of the [Map]. - * - * @return uint32 mapId - */ - int GetMapId(Eluna* E, Map* map) - { - E->Push(map->GetId()); - return 1; - } - - /** - * Returns the area ID of the [Map] at the specified X, Y, and Z coordinates. - * - * @param float x - * @param float y - * @param float z - * @param uint32 phasemask = PHASEMASK_NORMAL - * @return uint32 areaId - */ - int GetAreaId(Eluna* E, Map* map) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - - E->Push(map->GetTerrain()->GetAreaId(x, y, z)); - return 1; - } - - /** - * Returns a [WorldObject] by its GUID from the map if it is spawned. - * - * @param ObjectGuid guid - * @return [WorldObject] object - */ - int GetWorldObject(Eluna* E, Map* map) - { - ObjectGuid guid = E->CHECKVAL(2); - - E->Push(map->GetWorldObject(guid)); - return 1; - } - - /** - * Sets the [Weather] type based on [WeatherType] and grade supplied. - * - * enum WeatherType - * { - * WEATHER_TYPE_FINE = 0, - * WEATHER_TYPE_RAIN = 1, - * WEATHER_TYPE_SNOW = 2, - * WEATHER_TYPE_STORM = 3, - * WEATHER_TYPE_THUNDERS = 86, - * WEATHER_TYPE_BLACKRAIN = 90 - * }; - * - * @param uint32 zone : id of the zone to set the weather for - * @param [WeatherType] type : the [WeatherType], see above available weather types - * @param float grade : the intensity/grade of the [Weather], ranges from 0 to 1 - */ - int SetWeather(Eluna* E, Map* map) - { - (void)map; // ensure that the variable is referenced in order to pass compiler checks - uint32 zoneId = E->CHECKVAL(2); - uint32 weatherType = E->CHECKVAL(3); - float grade = E->CHECKVAL(4); - - if (Weather::IsValidWeatherType(weatherType)) - map->SetWeather(zoneId, (WeatherType)weatherType, grade, false); - - return 0; - } - - /** - * Gets the instance data table for the [Map], if it exists. - * - * The instance must be scripted using Eluna for this to succeed. - * If the instance is scripted in C++ this will return `nil`. - * - * @return table instance_data : instance data table, or `nil` - */ - int GetInstanceData(Eluna* E, Map* map) - { - ElunaInstanceAI* iAI = dynamic_cast(map->GetInstanceData()); - - if (iAI) - E->PushInstanceData(iAI, false); - else - E->Push(); // nil - - return 1; - } - - /** - * Saves the [Map]'s instance data to the database. - */ - int SaveInstanceData(Eluna* /*E*/, Map* map) - { - ElunaInstanceAI* iAI = dynamic_cast(map->GetInstanceData()); - - if (iAI) - iAI->SaveToDB(); - - return 0; - } - - /** - * Returns a table with all the current [Player]s in the map - * - * enum TeamId - * { - * TEAM_ALLIANCE = 0, - * TEAM_HORDE = 1, - * TEAM_NEUTRAL = 2 - * }; - * - * @param [TeamId] team : optional check team of the [Player], Alliance, Horde or Neutral (All) - * @return table mapPlayers - */ - int GetPlayers(Eluna* E, Map* map) - { - uint32 team = E->CHECKVAL(2, TEAM_NEUTRAL); - - lua_newtable(E->L); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - Map::PlayerList const& players = map->GetPlayers(); - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - { - Player* player = itr->getSource(); - - if (!player) - continue; - if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team)) - { - E->Push(player); - lua_rawseti(E->L, tbl, ++i); - } - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns a runtime-persistent cache tied to the [Map]. - * This data will remain for as long as the [Map] exists, or until a server restart. - * - * A reload of the Lua state will NOT clear this cache. - * - * This cache can be added to and read from with the following sub-methods. - *
-     * -- Sets the key-value pair in the cache
-     * Map:Data():Set("key", val)
-     *
-     * -- Returns the value from the cache using the key
-     * local val = Map:Data():Get("key")
-     *
-     * -- Removes the key-value pair from the cache
-     * Map:Data():Set("key", nil)
-     *
-     * -- Returns all the key-value pairs as a Lua table indexed by the keys
-     * local table = Map:Data():AsTable()
-     * 
- */ - int Data(Eluna* E, Map* map) - { - return LuaVal::PushLuaVal(E->L, map->lua_data); - } - - ElunaRegister MapMethods[] = - { - // Getters - { "GetName", &LuaMap::GetName }, - { "GetDifficulty", &LuaMap::GetDifficulty }, - { "GetInstanceId", &LuaMap::GetInstanceId }, - { "GetInstanceData", &LuaMap::GetInstanceData }, - { "GetPlayerCount", &LuaMap::GetPlayerCount }, - { "GetPlayers", &LuaMap::GetPlayers }, - { "GetMapId", &LuaMap::GetMapId }, - { "GetAreaId", &LuaMap::GetAreaId }, - { "GetHeight", &LuaMap::GetHeight }, - { "GetWorldObject", &LuaMap::GetWorldObject }, - - // Setters - { "SetWeather", &LuaMap::SetWeather }, - - // Boolean - { "IsBattleground", &LuaMap::IsBattleground }, - { "IsDungeon", &LuaMap::IsDungeon }, - { "IsEmpty", &LuaMap::IsEmpty }, - { "IsRaid", &LuaMap::IsRaid }, -#ifndef CLASSIC - { "IsArena", &LuaMap::IsArena }, - { "IsHeroic", &LuaMap::IsHeroic }, -#else - { "IsArena", nullptr, METHOD_REG_NONE }, - { "IsHeroic", nullptr, METHOD_REG_NONE }, -#endif - // Other - { "SaveInstanceData", &LuaMap::SaveInstanceData }, - { "Data", &LuaMap::Data }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/ObjectMethods.h b/methods/Mangos/ObjectMethods.h deleted file mode 100644 index 7dec65cc78..0000000000 --- a/methods/Mangos/ObjectMethods.h +++ /dev/null @@ -1,498 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef OBJECTMETHODS_H -#define OBJECTMETHODS_H - -/*** - * A basic game object (either an [Item] or a [WorldObject]). - * - * Objects in MaNGOS/Trinity are stored an a giant block of "values". - * Subclasses of Object, like [WorldObject], extend the block with more data specific to that subclass. - * Further subclasses, like [Player], extend it even further. - * - * A detailed map of all the fields in this data block can be found in the UpdateFields.h file of your emulator - * (it varies depending on the expansion supported). - * - * The GetValue methods in this class (e.g. [Object:GetInt32Value]) provide low-level access to the data block. - * Other methods, like [Object:HasFlag] and [Object:GetScale], merely wrap the GetValue methods and provide a simpler interface. - * - * Inherits all methods from: none - */ -namespace LuaObject -{ - /** - * Returns `true` if the specified flag is set, otherwise `false`. - * - * @param uint16 index : the index of the flags data in the [Object] - * @param uint32 flag : the flag to check for in the flags data - * @return bool hasFlag - */ - int HasFlag(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint32 flag = E->CHECKVAL(3); - - E->Push(obj->HasFlag(index, flag)); - return 1; - } - - /** - * Returns `true` if the [Object] has been added to its [Map], otherwise `false`. - * - * @return bool inWorld - */ - int IsInWorld(Eluna* E, Object* obj) - { - E->Push(obj->IsInWorld()); - return 1; - } - - /** - * Returns the data at the specified index, casted to a signed 32-bit integer. - * - * @param uint16 index - * @return int32 value - */ - int GetInt32Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - E->Push(obj->GetInt32Value(index)); - return 1; - } - - /** - * Returns the data at the specified index, casted to a unsigned 32-bit integer. - * - * @param uint16 index - * @return uint32 value - */ - int GetUInt32Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - E->Push(obj->GetUInt32Value(index)); - return 1; - } - - /** - * Returns the data at the specified index, casted to a single-precision floating point value. - * - * @param uint16 index - * @return float value - */ - int GetFloatValue(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - E->Push(obj->GetFloatValue(index)); - return 1; - } - - /** - * Returns the data at the specified index and offset, casted to an unsigned 8-bit integer. - * - * E.g. if you want the second byte at index 10, you would pass in 1 as the offset. - * - * @param uint16 index - * @param uint8 offset : should be 0, 1, 2, or 3 - * @return uint8 value - */ - int GetByteValue(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint8 offset = E->CHECKVAL(3); - E->Push(obj->GetByteValue(index, offset)); - return 1; - } - - /** - * Returns the data at the specified index and offset, casted to a signed 16-bit integer. - * - * E.g. if you want the second half-word at index 10, you would pass in 1 as the offset. - * - * @param uint16 index - * @param uint8 offset : should be 0 or 1 - * @return uint16 value - */ - int GetUInt16Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint8 offset = E->CHECKVAL(3); - E->Push(obj->GetUInt16Value(index, offset)); - return 1; - } - - /** - * Returns the scale/size of the [Object]. - * - * This affects the size of a [WorldObject] in-game, but [Item]s don't have a "scale". - * - * @return float scale - */ - int GetScale(Eluna* E, Object* obj) - { - E->Push(obj->GetObjectScale()); - return 1; - } - - /** - * Returns the entry of the [Object]. - * - * [Player]s do not have an "entry". - * - * @return uint32 entry - */ - int GetEntry(Eluna* E, Object* obj) - { - E->Push(obj->GetEntry()); - return 1; - } - - /** - * Returns the GUID of the [Object]. - * - * GUID is an unique identifier for the object. - * - * However on MaNGOS and cMangos creatures and gameobjects inside different maps can share - * the same GUID but not on the same map. - * - * On TrinityCore this value is unique across all maps - * - * @return ObjectGuid guid - */ - int GetGUID(Eluna* E, Object* obj) - { - E->Push(obj->GET_GUID()); - return 1; - } - - /** - * Returns the low-part of the [Object]'s GUID. - * - * On TrinityCore all low GUIDs are different for all objects of the same type. - * For example creatures in instances are assigned new GUIDs when the Map is created. - * - * On MaNGOS and cMaNGOS low GUIDs are unique only on the same map. - * For example creatures in instances use the same low GUID assigned for that spawn in the database. - * This is why to identify a creature you have to know the instanceId and low GUID. See [Map:GetIntstanceId] - * - * @return uint32 guidLow - */ - int GetGUIDLow(Eluna* E, Object* obj) - { - E->Push(obj->GetGUIDLow()); - return 1; - } - - /** - * Returns the TypeId of the [Object]. - * - * enum TypeID - * { - * TYPEID_OBJECT = 0, - * TYPEID_ITEM = 1, - * TYPEID_CONTAINER = 2, - * TYPEID_UNIT = 3, - * TYPEID_PLAYER = 4, - * TYPEID_GAMEOBJECT = 5, - * TYPEID_DYNAMICOBJECT = 6, - * TYPEID_CORPSE = 7 - * }; - * - * @return uint8 typeID - */ - int GetTypeId(Eluna* E, Object* obj) - { - E->Push(obj->GetTypeId()); - return 1; - } - - /** - * Returns the data at the specified index, casted to an unsigned 64-bit integer. - * - * @param uint16 index - * @return uint64 value - */ - int GetUInt64Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - E->Push(obj->GetUInt64Value(index)); - return 1; - } - - /** - * Sets the specified flag in the data value at the specified index. - * - * If the flag was already set, it remains set. - * - * To remove a flag, use [Object:RemoveFlag]. - * - * @param uint16 index - * @param uint32 value - */ - int SetFlag(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint32 flag = E->CHECKVAL(3); - - obj->SetFlag(index, flag); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to a signed 32-bit integer. - * - * @param uint16 index - * @param int32 value - */ - int SetInt32Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - int32 value = E->CHECKVAL(3); - obj->SetInt32Value(index, value); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to an unsigned 32-bit integer. - * - * @param uint16 index - * @param uint32 value - */ - int SetUInt32Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint32 value = E->CHECKVAL(3); - obj->SetUInt32Value(index, value); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to an unsigned 32-bit integer. - * - * @param uint16 index - * @param uint32 value - */ - int UpdateUInt32Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint32 value = E->CHECKVAL(3); - obj->UpdateUInt32Value(index, value); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to a single-precision floating point value. - * - * @param uint16 index - * @param float value - */ - int SetFloatValue(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - float value = E->CHECKVAL(3); - - obj->SetFloatValue(index, value); - return 0; - } - - /** - * Sets the data at the specified index and offset to the given value, converted to an unsigned 8-bit integer. - * - * @param uint16 index - * @param uint8 offset : should be 0, 1, 2, or 3 - * @param uint8 value - */ - int SetByteValue(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint8 offset = E->CHECKVAL(3); - uint8 value = E->CHECKVAL(4); - obj->SetByteValue(index, offset, value); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to an unsigned 16-bit integer. - * - * @param uint16 index - * @param uint8 offset : should be 0 or 1 - * @param uint16 value - */ - int SetUInt16Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint8 offset = E->CHECKVAL(3); - uint16 value = E->CHECKVAL(4); - obj->SetUInt16Value(index, offset, value); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to a signed 16-bit integer. - * - * @param uint16 index - * @param uint8 offset : should be 0 or 1 - * @param int16 value - */ - int SetInt16Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint8 offset = E->CHECKVAL(3); - int16 value = E->CHECKVAL(4); - obj->SetInt16Value(index, offset, value); - return 0; - } - - /** - * Sets the [Object]'s scale/size to the given value. - * - * @param float scale - */ - int SetScale(Eluna* E, Object* obj) - { - float size = E->CHECKVAL(2); - - obj->SetObjectScale(size); - return 0; - } - - /** - * Sets the data at the specified index to the given value, converted to an unsigned 64-bit integer. - * - * @param uint16 index - * @param uint64 value - */ - int SetUInt64Value(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint64 value = E->CHECKVAL(3); - obj->SetUInt64Value(index, value); - return 0; - } - - /** - * Removes a flag from the value at the specified index. - * - * @param uint16 index - * @param uint32 flag - */ - int RemoveFlag(Eluna* E, Object* obj) - { - uint16 index = E->CHECKVAL(2); - uint32 flag = E->CHECKVAL(3); - - obj->RemoveFlag(index, flag); - return 0; - } - - /** - * Attempts to convert the [Object] to a [Corpse]. - * - * If the [Object] is not a [Corpse], returns `nil`. - * - * @return [Corpse] corpse : the [Object] as a [Corpse], or `nil` - */ - int ToCorpse(Eluna* E, Object* obj) - { - E->Push(obj->ToCorpse()); - return 1; - } - - /** - * Attempts to convert the [Object] to a [GameObject]. - * - * If the [Object] is not a [GameObject], returns `nil`. - * - * @return [GameObject] gameObject : the [Object] as a [GameObject], or `nil` - */ - int ToGameObject(Eluna* E, Object* obj) - { - E->Push(obj->ToGameObject()); - return 1; - } - - /** - * Attempts to convert the [Object] to a [Unit]. - * - * If the [Object] is not a [Unit], returns `nil`. - * - * @return [Unit] unit : the [Object] as a [Unit], or `nil` - */ - int ToUnit(Eluna* E, Object* obj) - { - E->Push(obj->ToUnit()); - return 1; - } - - /** - * Attempts to convert the [Object] to a [Creature]. - * - * If the [Object] is not a [Creature], returns `nil`. - * - * @return [Creature] creature : the [Object] as a [Creature], or `nil` - */ - int ToCreature(Eluna* E, Object* obj) - { - E->Push(obj->ToCreature()); - return 1; - } - - /** - * Attempts to convert the [Object] to a [Player]. - * - * If the [Object] is not a [Player], returns `nil`. - * - * @return [Player] player : the [Object] as a [Player], or `nil` - */ - int ToPlayer(Eluna* E, Object* obj) - { - E->Push(obj->ToPlayer()); - return 1; - } - - ElunaRegister ObjectMethods[] = - { - // Getters - { "GetEntry", &LuaObject::GetEntry }, - { "GetGUID", &LuaObject::GetGUID }, - { "GetGUIDLow", &LuaObject::GetGUIDLow }, - { "GetInt32Value", &LuaObject::GetInt32Value }, - { "GetUInt32Value", &LuaObject::GetUInt32Value }, - { "GetFloatValue", &LuaObject::GetFloatValue }, - { "GetByteValue", &LuaObject::GetByteValue }, - { "GetUInt16Value", &LuaObject::GetUInt16Value }, - { "GetUInt64Value", &LuaObject::GetUInt64Value }, - { "GetScale", &LuaObject::GetScale }, - { "GetTypeId", &LuaObject::GetTypeId }, - - // Setters - { "SetInt32Value", &LuaObject::SetInt32Value }, - { "SetUInt32Value", &LuaObject::SetUInt32Value }, - { "UpdateUInt32Value", &LuaObject::UpdateUInt32Value }, - { "SetFloatValue", &LuaObject::SetFloatValue }, - { "SetByteValue", &LuaObject::SetByteValue }, - { "SetUInt16Value", &LuaObject::SetUInt16Value }, - { "SetInt16Value", &LuaObject::SetInt16Value }, - { "SetUInt64Value", &LuaObject::SetUInt64Value }, - { "SetScale", &LuaObject::SetScale }, - { "SetFlag", &LuaObject::SetFlag }, - - // Boolean - { "IsInWorld", &LuaObject::IsInWorld }, - { "HasFlag", &LuaObject::HasFlag }, - - // Other - { "ToGameObject", &LuaObject::ToGameObject }, - { "ToUnit", &LuaObject::ToUnit }, - { "ToCreature", &LuaObject::ToCreature }, - { "ToPlayer", &LuaObject::ToPlayer }, - { "ToCorpse", &LuaObject::ToCorpse }, - { "RemoveFlag", &LuaObject::RemoveFlag }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/PlayerMethods.h b/methods/Mangos/PlayerMethods.h deleted file mode 100644 index 2280baaebe..0000000000 --- a/methods/Mangos/PlayerMethods.h +++ /dev/null @@ -1,3984 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef PLAYERMETHODS_H -#define PLAYERMETHODS_H - -/*** - * Inherits all methods from: [Object], [WorldObject], [Unit] - */ -namespace LuaPlayer -{ -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns 'true' if the [Player] can Titan Grip, 'false' otherwise. - * - * @return bool canTitanGrip - */ - int CanTitanGrip(Eluna* E, Player* player) - { - E->Push(player->CanTitanGrip()); - return 1; - } - - /** - * Returns 'true' if the [Player] has a talent by ID in specified spec, 'false' otherwise. - * - * @param uint32 spellId : talent spellId to check - * @param uint8 spec : specified spec. 0 for primary, 1 for secondary. - * @return bool hasTalent - */ - int HasTalent(Eluna* E, Player* player) - { - uint32 spellId = E->CHECKVAL(2); - uint8 maxSpecs = MAX_TALENT_SPEC_COUNT; - uint8 spec = E->CHECKVAL(3); - - if (spec >= maxSpecs) - return 1; - - E->Push(player->HasTalent(spellId, spec)); - return 1; - } - - /** - * Returns 'true' if the [Player] has completed the specified achievement, 'false' otherwise. - * - * @param uint32 achievementId - * @return bool hasAchieved - */ - int HasAchieved(Eluna* E, Player* player) - { - uint32 achievementId = E->CHECKVAL(2); - - E->Push(player->GetAchievementMgr().HasAchievement(achievementId)); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] has an active [Quest] by specific ID, 'false' otherwise. - * - * @param uint32 questId - * @return bool hasQuest - */ - int HasQuest(Eluna* E, Player* player) - { - uint32 quest = E->CHECKVAL(2); - - E->Push(player->IsActiveQuest(quest)); - return 1; - } - - /** - * Returns 'true' if the [Player] has a skill by specific ID, 'false' otherwise. - * - * @param uint32 skill - * @return bool hasSkill - */ - int HasSkill(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->HasSkill(skill)); - return 1; - } - - /** - * Returns 'true' if the [Player] has a [Spell] by specific ID, 'false' otherwise. - * - * @param uint32 spellId - * @return bool hasSpell - */ - int HasSpell(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - - E->Push(player->HasSpell(id)); - return 1; - } - - /** - * Returns true if [Player] has specified login flag - * - * @param uint32 flag - * @return bool hasLoginFlag - */ - int HasAtLoginFlag(Eluna* E, Player* player) - { - uint32 flag = E->CHECKVAL(2); - - E->Push(player->HasAtLoginFlag((AtLoginFlags)flag)); - return 1; - } - - /** - * Returns true if [Player] has [Quest] for [GameObject] - * - * @param int32 entry : entry of a [GameObject] - * @return bool hasQuest - */ - int HasQuestForGO(Eluna* E, Player* player) - { - int32 entry = E->CHECKVAL(2); - - E->Push(player->HasQuestForGO(entry)); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Player] has a title by specific ID, 'false' otherwise. - * - * @param uint32 titleId - * @return bool hasTitle - */ - int HasTitle(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); - if (titleInfo) - E->Push(player->HasTitle(titleInfo)); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] has the given amount of item entry specified, 'false' otherwise. - * - * @param uint32 itemId : entry of the item - * @param uint32 count = 1 : amount of items the player needs should have - * @param bool check_bank = false : determines if the item can be in player bank - * @return bool hasItem - */ - int HasItem(Eluna* E, Player* player) - { - uint32 itemId = E->CHECKVAL(2); - uint32 count = E->CHECKVAL(3, 1); - bool check_bank = E->CHECKVAL(4, false); - E->Push(player->HasItemCount(itemId, count, check_bank)); - return 1; - } - - /** - * Returns 'true' if the [Player] has a quest for the item entry specified, 'false' otherwise. - * - * @param uint32 entry : entry of the item - * @return bool hasQuest - */ - int HasQuestForItem(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - E->Push(player->HasQuestForItem(entry)); - return 1; - } - - /** - * Returns 'true' if the [Player] can use the item or item entry specified, 'false' otherwise. - * - * @proto canUse = (item) - * @proto canUse = (entry) - * @param [Item] item : an instance of an item - * @param uint32 entry : entry of the item - * @return bool canUse - */ - int CanUseItem(Eluna* E, Player* player) - { - Item* item = E->CHECKOBJ(2, false); - if (item) - E->Push(player->CanUseItem(item) == EQUIP_ERR_OK); - else - { - uint32 entry = E->CHECKVAL(2); - const ItemTemplate* temp = eObjectMgr->GetItemTemplate(entry); - if (temp) - E->Push(player->CanUseItem(temp) == EQUIP_ERR_OK); - else - E->Push(false); - } - return 1; - } - - /** - * Returns 'true' if the [Spell] specified by ID is currently on cooldown for the [Player], 'false' otherwise. - * - * @param uint32 spellId - * @return bool hasSpellCooldown - */ - int HasSpellCooldown(Eluna* E, Player* player) - { - uint32 spellId = E->CHECKVAL(2); - - E->Push(player->HasSpellCooldown(spellId)); - return 1; - } - - /** - * Returns 'true' if the [Player] can share [Quest] specified by ID, 'false' otherwise. - * - * @param uint32 entryId - * @return bool hasSpellCooldown - */ - int CanShareQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - E->Push(player->CanShareQuest(entry)); - return 1; - } - - /** - * Returns 'true' if the [Player] can currently communicate through chat, 'false' otherwise. - * - * @return bool canSpeak - */ - int CanSpeak(Eluna* E, Player* player) - { - E->Push(player->CanSpeak()); - return 1; - } - - /** - * Returns 'true' if the [Player] has permission to uninvite others from the current group, 'false' otherwise. - * - * @return bool canUninviteFromGroup - */ - int CanUninviteFromGroup(Eluna* E, Player* player) - { - E->Push(player->CanUninviteFromGroup() == ERR_PARTY_RESULT_OK); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Player] can fly, 'false' otherwise. - * - * @return bool canFly - */ - int CanFly(Eluna* E, Player* player) - { - E->Push(player->CanFly()); - return 1; - } -#endif - -#ifdef CLASSIC - /** - * Returns [Player] kills - * - * @param bool honorable = true : if victims are honorable - * @return uint32 kills - */ - int GetHonorStoredKills(Eluna* E, Player* player) - { - bool honorable = E->CHECKVAL(2, true); - - E->Push(player->GetHonorStoredKills(honorable)); - return 1; - } - - /** - * Returns rank points - * - * @return float rankPoints - */ - int GetRankPoints(Eluna* E, Player* player) - { - E->Push(player->GetRankPoints()); - return 1; - } - - /** - * Returns last week's standing position - * - * @return int32 standingPos - */ - int GetHonorLastWeekStandingPos(Eluna* E, Player* player) - { - E->Push(player->GetHonorLastWeekStandingPos()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] is currently in water, 'false' otherwise. - * - * @return bool isInWater - */ - int IsInWater(Eluna* E, Player* player) - { - E->Push(player->IsInWater()); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently moving, 'false' otherwise. - * - * @return bool isMoving - */ - int IsMoving(Eluna* E, Player* player) // enable for unit when mangos support it - { - E->Push(player->isMoving()); - return 1; - } - -#ifdef CLASSIC - /** - * Updates the [Player]s weekly honor status - */ - int UpdateHonor(Eluna* E, Player* player) - { - player->UpdateHonor(); - return 0; - } - - /** - * Resets the [Player]s weekly honor status - */ - int ResetHonor(Eluna* E, Player* player) - { - player->ResetHonor(); - return 0; - } - - /** - * Clears all of [Player]s weekly honor status - */ - int ClearHonorInfo(Eluna* E, Player* player) - { - player->ClearHonorInfo(); - return 0; - } -#endif - -#ifndef CLASSIC - /** - * Returns 'true' if the [Player] is currently flying, 'false' otherwise. - * - * @return bool isFlying - */ - int IsFlying(Eluna* E, Player* player) // enable for unit when mangos support it - { - E->Push(player->IsFlying()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] is in a [Group], 'false' otherwise. - * - * @return bool isInGroup - */ - int IsInGroup(Eluna* E, Player* player) - { - E->Push((player->GetGroup() != NULL)); - return 1; - } - - /** - * Returns 'true' if the [Player] is in a [Guild], 'false' otherwise. - * - * @return bool isInGuild - */ - int IsInGuild(Eluna* E, Player* player) - { - E->Push((player->GetGuildId() != 0)); - return 1; - } - - /** - * Returns 'true' if the [Player] is a Game Master, 'false' otherwise. - * - * Note: This is only true when GM tag is activated! For alternative see [Player:GetGMRank] - * - * @return bool isGM - */ - int IsGM(Eluna* E, Player* player) - { - E->Push(player->isGameMaster()); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Player] is in an arena team specified by type, 'false' otherwise. - * - * @param uint32 type - * @return bool isInArenaTeam - */ - int IsInArenaTeam(Eluna* E, Player* player) - { - uint32 type = E->CHECKVAL(2); - if (type < MAX_ARENA_SLOT && player->GetArenaTeamId(type)) - E->Push(true); - else - E->Push(false); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] is immune to everything. - * - * @return bool isImmune - */ - int IsImmuneToDamage(Eluna* E, Player* player) - { - E->Push(player->isTotalImmune()); - return 1; - } - - /** - * Returns 'true' if the [Player] satisfies all requirements to complete the quest entry. - * - * @param uint32 entry - * @return bool canComplete - */ - int CanCompleteQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - E->Push(player->CanCompleteQuest(entry)); - return 1; - } - - /** - * Returns 'true' if the [Player] is a part of the Horde faction, 'false' otherwise. - * - * @return bool isHorde - */ - int IsHorde(Eluna* E, Player* player) - { - E->Push((player->GetTeam() == HORDE)); - return 1; - } - - /** - * Returns 'true' if the [Player] is a part of the Alliance faction, 'false' otherwise. - * - * @return bool isAlliance - */ - int IsAlliance(Eluna* E, Player* player) - { - E->Push((player->GetTeam() == ALLIANCE)); - return 1; - } - - /** - * Returns 'true' if the [Player] is 'Do Not Disturb' flagged, 'false' otherwise. - * - * @return bool isDND - */ - int IsDND(Eluna* E, Player* player) - { - E->Push(player->isDND()); - return 1; - } - - /** - * Returns 'true' if the [Player] is 'Away From Keyboard' flagged, 'false' otherwise. - * - * @return bool isAFK - */ - int IsAFK(Eluna* E, Player* player) - { - E->Push(player->isAFK()); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently falling, 'false' otherwise. - * - * @return bool isFalling - */ - int IsFalling(Eluna* E, Player* player) - { - E->Push(player->IsFalling()); - return 1; - } - - int IsGroupVisibleFor(Eluna* E, Player* player) - { - Player* target = E->CHECKOBJ(2); - E->Push(player->IsGroupVisibleFor(target)); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently in the same raid as another [Player] by object, 'false' otherwise. - * - * @param [Player] player - * @return bool isInSameRaidWith - */ - int IsInSameRaidWith(Eluna* E, Player* player) - { - Player* target = E->CHECKOBJ(2); - E->Push(player->IsInSameRaidWith(target)); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently in the same [Group] as another [Player] by object, 'false' otherwise. - * - * @param [Player] player - * @return bool isInSameGroupWith - */ - int IsInSameGroupWith(Eluna* E, Player* player) - { - Player* target = E->CHECKOBJ(2); - E->Push(player->IsInSameGroupWith(target)); - return 1; - } - - /** - * Returns 'true' if the [Player] is eligible for Honor or XP gain by [Unit] specified, 'false' otherwise. - * - * @param [Unit] unit - * @return bool isHonorOrXPTarget - */ - int IsHonorOrXPTarget(Eluna* E, Player* player) - { - Unit* victim = E->CHECKOBJ(2); - - E->Push(player->isHonorOrXPTarget(victim)); - return 1; - } - - /** - * Returns 'true' if the [Player] can see anoter [Player] specified by object, 'false' otherwise. - * - * @param [Player] player - * @return bool isVisibleForPlayer - */ - int IsVisibleForPlayer(Eluna* E, Player* player) - { - Player* target = E->CHECKOBJ(2); - - E->Push(player->IsVisibleGloballyFor(target)); - return 1; - } - - int IsGMVisible(Eluna* E, Player* player) - { - E->Push(player->isGMVisible()); - return 1; - } - - /** - * Returns 'true' if the [Player] has taxi cheat activated, 'false' otherwise. - * - * @return bool isTaxiCheater - */ - int IsTaxiCheater(Eluna* E, Player* player) - { - E->Push(player->IsTaxiCheater()); - return 1; - } - - int IsGMChat(Eluna* E, Player* player) - { - E->Push(player->isGMChat()); - return 1; - } - - /** - * Returns 'true' if the [Player] is accepting whispers, 'false' otherwise. - * - * @return bool isAcceptingWhispers - */ - int IsAcceptingWhispers(Eluna* E, Player* player) - { - E->Push(player->isAcceptWhispers()); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently rested, 'false' otherwise. - * - * @return bool isRested - */ - int IsRested(Eluna* E, Player* player) - { - E->Push(player->GetRestBonus() > 0.0f); - return 1; - } - - /** - * Returns 'true' if the [Player] is currently in a [BattleGround] queue, 'false' otherwise. - * - * @return bool inBattlegroundQueue - */ - int InBattlegroundQueue(Eluna* E, Player* player) - { - E->Push(player->InBattleGroundQueue()); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Player] is currently in an arena, 'false' otherwise. - * - * @return bool inArena - */ - int InArena(Eluna* E, Player* player) - { - E->Push(player->InArena()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Player] is currently in a [BattleGround], 'false' otherwise. - * - * @return bool inBattleGround - */ - int InBattleground(Eluna* E, Player* player) - { - E->Push(player->InBattleGround()); - return 1; - } - - /** - * Returns 'true' if the [Player] can block incomming attacks, 'false' otherwise. - * - * @return bool canBlock - */ - int CanBlock(Eluna* E, Player* player) - { - E->Push(player->CanBlock()); - return 1; - } - - /** - * Returns 'true' if the [Player] can parry incomming attacks, 'false' otherwise. - * - * @return bool canParry - */ - int CanParry(Eluna* E, Player* player) - { - E->Push(player->CanParry()); - return 1; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns the amount of available specs the [Player] currently has - * - * @return uint8 specCount - */ - int GetSpecsCount(Eluna* E, Player* player) - { - E->Push(player->GetSpecsCount()); - return 1; - } - - /** - * Returns the [Player]s active spec ID - * - * @return uint32 specId - */ - int GetActiveSpec(Eluna* E, Player* player) - { - E->Push(player->GetActiveSpec()); - return 1; - } -#endif - -#ifdef WOTLK - /** - * Returns the normal phase of the player instead of the actual phase possibly containing GM phase - * - * @return uint32 phasemask - */ - int GetPhaseMaskForSpawn(Eluna* E, Player* player) - { - E->Push(player->GetPhaseMaskForSpawn()); - return 1; - } -#endif - -#if defined(TBC) || defined (WOTLK) - /** - * Returns the [Player]s current amount of Arena Points - * - * @return uint32 arenaPoints - */ - int GetArenaPoints(Eluna* E, Player* player) - { - E->Push(player->GetArenaPoints()); - return 1; - } - - /** - * Returns the [Player]s current amount of Honor Points - * - * @return uint32 honorPoints - */ - int GetHonorPoints(Eluna* E, Player* player) - { - E->Push(player->GetHonorPoints()); - return 1; - } -#endif -#if defined(CLASSIC) || defined(TBC) || defined (WOTLK) - /** - * Returns the [Player]s current shield block value - * - * @return uint32 blockValue - */ - int GetShieldBlockValue(Eluna* E, Player* player) - { - E->Push(player->GetShieldBlockValue()); - return 1; - } -#endif - - /** - * Returns the [Player]s cooldown delay by specified [Spell] ID - * - * @param uint32 spellId - * @return uint32 spellCooldownDelay - */ - int GetSpellCooldownDelay(Eluna* E, Player* player) - { - uint32 spellId = E->CHECKVAL(2); - - E->Push(uint32(player->GetSpellCooldownDelay(spellId))); - return 1; - } - - /** - * Returns the [Player]s current latency in MS - * - * @return uint32 latency - */ - int GetLatency(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetLatency()); - return 1; - } - - /** - * Returns [Player]s original sub group - * - * @return uint8 subGroup - */ - int GetOriginalSubGroup(Eluna* E, Player* player) - { - E->Push(player->GetOriginalSubGroup()); - return 1; - } - - /** - * Returns [Player]s original [Group] object - * - * @return [Group] group - */ - int GetOriginalGroup(Eluna* E, Player* player) - { - E->Push(player->GetOriginalGroup()); - return 1; - } - - /** - * Returns a random Raid Member [Player] object within radius specified of [Player] - * - * @param float radius - * @return [Player] player - */ - int GetNextRandomRaidMember(Eluna* E, Player* player) - { - float radius = E->CHECKVAL(2); - - E->Push(player->GetNextRandomRaidMember(radius)); - return 1; - } - - /** - * Returns [Player]s current sub group - * - * @return uint8 subGroup - */ - int GetSubGroup(Eluna* E, Player* player) - { - E->Push(player->GetSubGroup()); - return 1; - } - - /** - * Returns [Group] invitation - * - * @return [Group] group - */ - int GetGroupInvite(Eluna* E, Player* player) - { - E->Push(player->GetGroupInvite()); - return 1; - } - - /** - * Returns rested experience bonus - * - * @param uint32 xp - * @return uint32 xpBonus - */ - int GetXPRestBonus(Eluna* E, Player* player) - { - uint32 xp = E->CHECKVAL(2); - - E->Push(player->GetXPRestBonus(xp)); - return 1; - } - - /** - * Returns the [Player]s current [BattleGround] type ID - * - * @return [BattleGroundTypeId] typeId - */ - int GetBattlegroundTypeId(Eluna* E, Player* player) - { - E->Push(player->GetBattleGroundTypeId()); - return 1; - } - - /** - * Returns the [Player]s current [BattleGround] ID - * - * @return uint32 battleGroundId - */ - int GetBattlegroundId(Eluna* E, Player* player) - { - E->Push(player->GetBattleGroundId()); - return 1; - } - - /** - * Returns the [Player]s reputation rank of faction specified - * - * @param uint32 faction - * @return [ReputationRank] rank - */ - int GetReputationRank(Eluna* E, Player* player) - { - uint32 faction = E->CHECKVAL(2); - - E->Push(player->GetReputationRank(faction)); - return 1; - } - - /** - * Returns the [Player]s current level of intoxication - * - * @return uint16 drunkValue - */ - int GetDrunkValue(Eluna* E, Player* player) - { - E->Push(player->GetDrunkValue()); - return 1; - } - - /** - * Returns skill temporary bonus value - * - * @param uint32 skill - * @param int16 bonusVal - */ - int GetSkillTempBonusValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetSkillTempBonusValue(skill)); - return 1; - } - - /** - * Returns skill permanent bonus value - * - * @param uint32 skill - * @param int16 bonusVal - */ - int GetSkillPermBonusValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetSkillPermBonusValue(skill)); - return 1; - } - - /** - * Returns skill value without bonus' - * - * @param uint32 skill - * @return uint16 pureVal - */ - int GetPureSkillValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetPureSkillValue(skill)); - return 1; - } - - /** - * Returns base skill value - * - * @param uint32 skill - * @return uint16 baseVal - */ - int GetBaseSkillValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetBaseSkillValue(skill)); - return 1; - } - - /** - * Returns skill value - * - * @param uint32 skill - * @return uint16 val - */ - int GetSkillValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetSkillValue(skill)); - return 1; - } - - /** - * Returns max value of specified skill without bonus' - * - * @param uint32 skill - * @return uint16 pureVal - */ - int GetPureMaxSkillValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetPureMaxSkillValue(skill)); - return 1; - } - - /** - * Returns max value of specified skill - * - * @param uint32 skill - * @return uint16 val - */ - int GetMaxSkillValue(Eluna* E, Player* player) - { - uint32 skill = E->CHECKVAL(2); - - E->Push(player->GetMaxSkillValue(skill)); - return 1; - } - - /** - * Returns mana bonus from amount of intellect - * - * @return float bonus - */ - int GetManaBonusFromIntellect(Eluna* E, Player* player) - { - E->Push(player->GetManaBonusFromIntellect()); - return 1; - } - - /** - * Returns health bonus from amount of stamina - * - * @return float bonus - */ - int GetHealthBonusFromStamina(Eluna* E, Player* player) - { - E->Push(player->GetHealthBonusFromStamina()); - return 1; - } - - /** - * Returns raid or dungeon difficulty - * - * @param bool isRaid = true : argument is TrinityCore only - * @return int32 difficulty - */ - int GetDifficulty(Eluna* E, Player* player) - { -#ifdef TBC - E->Push(player->GetDifficulty()); -#elif defined(CLASSIC) - E->Push((Difficulty)0); -#else - bool isRaid = E->CHECKVAL(2, true); - E->Push(player->GetDifficulty(isRaid)); -#endif - return 1; - } - - /** - * Returns the [Player]s current guild rank - * - * @return uint32 guildRank - */ - int GetGuildRank(Eluna* E, Player* player) // TODO: Move to Guild Methods - { - E->Push(player->GetRank()); - return 1; - } - - /** - * Returns the [Player]s free talent point amount - * - * @return uint32 freeTalentPointAmt - */ - int GetFreeTalentPoints(Eluna* E, Player* player) - { - E->Push(player->GetFreeTalentPoints()); - return 1; - } - - /** - * Returns the name of the [Player]s current [Guild] - * - * @return string guildName - */ - int GetGuildName(Eluna* E, Player* player) - { - if (!player->GetGuildId()) - return 1; - E->Push(eGuildMgr->GetGuildNameById(player->GetGuildId())); - return 1; - } - - /** - * Returns the amount of reputation the [Player] has with the faction specified - * - * @param uint32 faction - * @return int32 reputationAmt - */ - int GetReputation(Eluna* E, Player* player) - { - uint32 faction = E->CHECKVAL(2); - - E->Push(player->GetReputationMgr().GetReputation(faction)); - return 1; - } - - /** - * Returns [Unit] target combo points are on - * - * @return [Unit] target - */ - int GetComboTarget(Eluna* E, Player* player) - { - E->Push(player->GetMap()->GetUnit(player->GetComboTargetGuid())); - return 1; - } - - /** - * Returns [Player]'s combo points - * - * @return uint8 comboPoints - */ - int GetComboPoints(Eluna* E, Player* player) - { - E->Push(player->GetComboPoints()); - return 1; - } - - /** - * Returns the amount of time the [Player] has spent ingame - * - * @return uint32 inGameTime - */ - int GetInGameTime(Eluna* E, Player* player) - { - E->Push(player->GetInGameTime()); - return 1; - } - - /** - * Returns the status of the [Player]s [Quest] specified by entry ID - * - * @param uint32 questId - * @return [QuestStatus] questStatus - */ - int GetQuestStatus(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - E->Push(player->GetQuestStatus(entry)); - return 1; - } - - /** - * Returns 'true' if the [Player]s [Quest] specified by entry ID has been rewarded, 'false' otherwise. - * - * @param uint32 questId - * @return bool questRewardStatus - */ - int GetQuestRewardStatus(Eluna* E, Player* player) - { - uint32 questId = E->CHECKVAL(2); - - E->Push(player->GetQuestRewardStatus(questId)); - return 1; - } - - /** - * Returns [Quest] required [Creature] or [GameObject] count - * - * @param uint32 quest : entry of a quest - * @param int32 entry : entry of required [Creature] - * @return uint16 count - */ - int GetReqKillOrCastCurrentCount(Eluna* E, Player* player) - { - uint32 questId = E->CHECKVAL(2); - int32 entry = E->CHECKVAL(3); - - E->Push(player->GetReqKillOrCastCurrentCount(questId, entry)); - return 1; - } - - /** - * Returns the quest level of the [Player]s [Quest] specified by object - * - * @param uint32 questId - * @return [QuestStatus] questRewardStatus - */ - int GetQuestLevel(Eluna* E, Player* player) - { - Quest* quest = E->CHECKOBJ(2); - - E->Push(player->GetQuestLevelForPlayer(quest)); - return 1; - } - - /** - * Returns a [Player]s [Item] object by gear slot specified - * - * @param uint8 slot - * @return [Item] item - */ - int GetEquippedItemBySlot(Eluna* E, Player* player) - { - uint8 slot = E->CHECKVAL(2); - if (slot >= EQUIPMENT_SLOT_END) - return 1; - - Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); - E->Push(item); - return 1; - } - - /** - * Returns the [Player]s current resting bonus - * - * @return float restBonus - */ - int GetRestBonus(Eluna* E, Player* player) - { - E->Push(player->GetRestBonus()); - return 1; - } - - /** - * Returns active GM chat tag - * - * @return uint8 tag - */ - int GetChatTag(Eluna* E, Player* player) - { - E->Push(player->GetChatTag()); - return 1; - } - - /** - * Returns an item in given bag on given slot. - * - *
-     * Possible and most commonly used combinations:
-     *
-     * bag = 255
-     * slots 0-18 equipment
-     * slots 19-22 equipped bag slots
-     * slots 23-38 backpack
-     * slots 39-66 bank main slots
-     * slots 67-74 bank bag slots
-     * slots 86-117 keyring
-     *
-     * bag = 19-22
-     * slots 0-35 for equipped bags
-     *
-     * bag = 67-74
-     * slots 0-35 for bank bags
-     * 
- * - * @param uint8 bag : the bag the [Item] is in, you can get this with [Item:GetBagSlot] - * @param uint8 slot : the slot the [Item] is in within the bag, you can get this with [Item:GetSlot] - * @return [Item] item : [Item] or nil - */ - int GetItemByPos(Eluna* E, Player* player) - { - uint8 bag = E->CHECKVAL(2); - uint8 slot = E->CHECKVAL(3); - - E->Push(player->GetItemByPos(bag, slot)); - return 1; - } - - /** - * Returns an [Item] from the player by guid. - * - * The item can be equipped, in bags or in bank. - * - * @param ObjectGuid guid : an item guid - * @return [Item] item - */ - int GetItemByGUID(Eluna* E, Player* player) - { - ObjectGuid guid = E->CHECKVAL(2); - - E->Push(player->GetItemByGuid(guid)); - return 1; - } - - /** - * Returns a mailed [Item] by guid. - * - * @param ObjectGuid guid : an item guid - * @return [Item] item - */ - int GetMailItem(Eluna* E, Player* player) - { - ObjectGuid guid = E->CHECKVAL(2); - - E->Push(player->GetMItem(guid.GetCounter())); - return 1; - } - - /** - * Returns an [Item] from the player by entry. - * - * The item can be equipped, in bags or in bank. - * - * @param uint32 entryId - * @return [Item] item - */ - int GetItemByEntry(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - E->Push(player->GetItemByEntry(entry)); - return 1; - } - - /** - * Returns the database textID of the [WorldObject]'s gossip header text for the [Player] - * - * @param [WorldObject] object - * @return uint32 textId : key to npc_text database table - */ - int GetGossipTextId(Eluna* E, Player* player) - { - WorldObject* obj = E->CHECKOBJ(2); - E->Push(player->GetGossipTextId(obj)); - return 1; - } - - /** - * Returns the [Player]s currently selected [Unit] object - * - * @return [Unit] unit - */ - int GetSelection(Eluna* E, Player* player) - { - E->Push(player->GetMap()->GetUnit(player->GetSelectionGuid())); - return 1; - } - - /** - * Returns the [Player]s GM Rank - * - * @return [AccountTypes] gmRank - */ - int GetGMRank(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetSecurity()); - return 1; - } - - /** - * Returns the [Player]s amount of money in copper - * - * @return uint32 coinage - */ - int GetCoinage(Eluna* E, Player* player) - { - E->Push(player->GetMoney()); - return 1; - } - - /** - * Returns the [Player]s current [Guild] ID - * - * @return uint32 guildId - */ - int GetGuildId(Eluna* E, Player* player) - { - E->Push(player->GetGuildId()); - return 1; - } - - /** - * Returns the [Player]s [TeamId] - * - * @return [TeamId] teamId - */ - int GetTeam(Eluna* E, Player* player) - { - E->Push(player->GetTeamId()); - return 1; - } - - /** - * Returns amount of the specified [Item] the [Player] has. - * - * @param uint32 entry : entry of the item - * @param bool checkinBank = false : also counts the items in player's bank if true - * @return uint32 itemamount - */ - int GetItemCount(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - bool checkinBank = E->CHECKVAL(3, false); - E->Push(player->GetItemCount(entry, checkinBank)); - return 1; - } - - /** - * Returns the [Player]s lifetime Honorable Kills - * - * @return uint32 lifeTimeKils - */ - int GetLifetimeKills(Eluna* E, Player* player) - { - E->Push(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)); - return 1; - } - - /** - * Returns the [Player]s IP address - * - * @return string ip - */ - int GetPlayerIP(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetRemoteAddress()); - return 1; - } - - /** - * Returns the [Player]s time played at current level - * - * @return uint32 currLevelPlayTime - */ - int GetLevelPlayedTime(Eluna* E, Player* player) - { - E->Push(player->GetLevelPlayedTime()); - return 1; - } - - /** - * Returns the [Player]s total time played - * - * @return uint32 totalPlayTime - */ - int GetTotalPlayedTime(Eluna* E, Player* player) - { - E->Push(player->GetTotalPlayedTime()); - return 1; - } - - /** - * Returns the [Player]s [Guild] object - * - * @return [Guild] guild - */ - int GetGuild(Eluna* E, Player* player) - { - E->Push(eGuildMgr->GetGuildById(player->GetGuildId())); - return 1; - } - - /** - * Returns the [Player]s [Group] object - * - * @return [Group] group - */ - int GetGroup(Eluna* E, Player* player) - { - E->Push(player->GetGroup()); - return 1; - } - - /** - * Returns the [Player]s account ID - * - * @return uint32 accountId - */ - int GetAccountId(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetAccountId()); - return 1; - } - - /** - * Returns the [Player]s account name - * - * @return string accountName - */ - int GetAccountName(Eluna* E, Player* player) - { - std::string accName; - if (eAccountMgr->GetName(player->GetSession()->GetAccountId(), accName)) - E->Push(accName); - - return 1; - } - - /** - * Returns the [Player]s [Corpse] object - * - * @return [Corpse] corpse - */ - int GetCorpse(Eluna* E, Player* player) - { - E->Push(player->GetCorpse()); - return 1; - } - - /** - * Returns the [Player]s database locale index - * - * @return int localeIndex - */ - int GetDbLocaleIndex(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetSessionDbLocaleIndex()); - return 1; - } - - /** - * Returns the [Player]s game client locale - * - * @return [LocaleConstant] locale - */ - int GetDbcLocale(Eluna* E, Player* player) - { - E->Push(player->GetSession()->GetSessionDbcLocale()); - return 1; - } - - /** - * Locks the player controls and disallows all movement and casting. - * - * @param bool apply = true : lock if true and unlock if false - */ - int SetPlayerLock(Eluna* E, Player* player) - { - bool apply = E->CHECKVAL(2, true); - - if (apply) - { - player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED | UNIT_FLAG_SILENCED); - player->SetClientControl(player, 0); - } - else - { - player->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_PACIFIED | UNIT_FLAG_SILENCED); - player->SetClientControl(player, 1); - } - return 0; - } - - /** - * Sets the [Player]s login flag to the flag specified - * - * @param uint32 flag - */ - int SetAtLoginFlag(Eluna* E, Player* player) - { - uint32 flag = E->CHECKVAL(2); - - player->SetAtLoginFlag((AtLoginFlags)flag); - return 0; - } - - /** - * Sets the [Player]s sheathe state to the state specified - * - * @param uint32 sheatheState - */ - int SetSheath(Eluna* E, Player* player) - { - uint32 sheathed = E->CHECKVAL(2); - if (sheathed >= MAX_SHEATH_STATE) - return 0; - - player->SetSheath((SheathState)sheathed); - return 0; - } - - /** - * Sets the [Player]s intoxication level to the level specified - * - * @param uint8 drunkValue - */ - int SetDrunkValue(Eluna* E, Player* player) - { - uint8 newDrunkValue = E->CHECKVAL(2); - - player->SetDrunkValue(newDrunkValue); - return 0; - } - - /** - * Sets the [Player]s faction standing to that of the race specified - * - * @param uint8 raceId - */ - int SetFactionForRace(Eluna* E, Player* player) - { - uint8 race = E->CHECKVAL(2); - - player->setFactionForRace(race); - return 0; - } - - /** - * Sets (increases) skill of the [Player] - * - * @param uint16 id - * @param uint16 step - * @param uint16 currVal - * @param uint16 maxVal - */ - int SetSkill(Eluna* E, Player* player) - { - uint16 id = E->CHECKVAL(2); - uint16 step = E->CHECKVAL(3); - uint16 currVal = E->CHECKVAL(4); - uint16 maxVal = E->CHECKVAL(5); - - player->SetSkill(id, currVal, maxVal, step); - return 0; - } - - /** - * Sets the [Player]s guild rank to the rank specified - * - * @param uint8 rank - */ - int SetGuildRank(Eluna* E, Player* player) // TODO: Move to Guild Methods - { - uint8 rank = E->CHECKVAL(2); - - if (!player->GetGuildId()) - return 0; - - player->SetRank(rank); - return 0; - } - - /** - * Sets the [Player]s free talent points to the amount specified for the current spec - * - * @param uint32 talentPointAmt - */ - int SetFreeTalentPoints(Eluna* E, Player* player) - { - uint32 points = E->CHECKVAL(2); - - player->SetFreeTalentPoints(points); -#if (!defined(TBC) && !defined(CLASSIC)) - player->SendTalentsInfoData(false); -#endif - return 0; - } - - /** - * Sets the [Player]s reputation amount for the faction specified - * - * @param uint32 factionId - * @param int32 reputationValue - */ - int SetReputation(Eluna* E, Player* player) - { - uint32 faction = E->CHECKVAL(2); - int32 value = E->CHECKVAL(3); - FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); - - player->GetReputationMgr().SetReputation(factionEntry, value); - return 0; - } - - /** - * Sets [Quest] state - * - * @param uint32 entry : entry of a quest - * @param uint32 status - */ - int SetQuestStatus(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - uint32 status = E->CHECKVAL(3); - if (status >= MAX_QUEST_STATUS) - return 0; - - player->SetQuestStatus(entry, (QuestStatus)status); - return 0; - } - - /** - * Sets the [Player]s rest bonus to the amount specified - * - * @param float restBonus - */ - int SetRestBonus(Eluna* E, Player* player) - { - float bonus = E->CHECKVAL(2); - - player->SetRestBonus(bonus); - return 0; - } - - /** - * Toggles whether the [Player] accepts whispers or not - * - * @param bool acceptWhispers = true - */ - int SetAcceptWhispers(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetAcceptWhispers(on); - return 0; - } - - /** - * Toggles PvP Death - * - * @param bool on = true - */ - int SetPvPDeath(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetPvPDeath(on); - return 0; - } - - /** - * Toggles whether the [Player] has GM visibility on or off - * - * @param bool gmVisible = true - */ - int SetGMVisible(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetGMVisible(on); - return 0; - } - - /** - * Toggles whether the [Player] has taxi cheat enabled or not - * - * @param bool taxiCheat = true - */ - int SetTaxiCheat(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetTaxiCheater(on); - return 0; - } - - /** - * Toggle Blizz (GM) tag - * - * @param bool on = true - */ - int SetGMChat(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetGMChat(on); - return 0; - } - - /** - * Toggles the [Player]s GM mode on or off - * - * @param bool setGmMode = true - */ - int SetGameMaster(Eluna* E, Player* player) - { - bool on = E->CHECKVAL(2, true); - - player->SetGameMaster(on); - return 0; - } - - /** - * Sets the [Player]s gender to gender specified - * - * - GENDER_MALE = 0 - * - GENDER_FEMALE = 1 - * - * @param [Gender] gender - */ - int SetGender(Eluna* E, Player* player) - { - uint32 _gender = E->CHECKVAL(2); - - Gender gender; - switch (_gender) - { - case 0: - gender = GENDER_MALE; - break; - case 1: - gender = GENDER_FEMALE; - break; - default: - return luaL_argerror(E->L, 2, "valid Gender expected"); - } - - player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender); - player->SetByteValue(PLAYER_BYTES_3, 0, gender); - player->InitDisplayIds(); - return 0; - } - -#if defined(TBC) || defined(WOTLK) - /** - * Sets the [Player]s Arena Points to the amount specified - * - * @param uint32 arenaPoints - */ - int SetArenaPoints(Eluna* E, Player* player) - { - uint32 arenaP = E->CHECKVAL(2); - player->SetArenaPoints(arenaP); - return 0; - } - - /** - * Sets the [Player]s Honor Points to the amount specified - * - * @param uint32 honorPoints - */ - int SetHonorPoints(Eluna* E, Player* player) - { - uint32 honorP = E->CHECKVAL(2); - player->SetHonorPoints(honorP); - return 0; - } -#endif - -#ifdef CLASSIC - /** - * Sets kills - * - * @param uint32 kills - * @param bool honorable = true : if victims were honorable - */ - int SetHonorStoredKills(Eluna* E, Player* player) - { - uint32 kills = E->CHECKVAL(2); - bool honorable = E->CHECKVAL(3, true); - - player->SetHonorStoredKills(kills, honorable); - return 0; - } - - /** - * Sets rank points - * - * @param float rankPoints - */ - int SetRankPoints(Eluna* E, Player* player) - { - float rankPoints = E->CHECKVAL(2); - - player->SetRankPoints(rankPoints); - return 0; - } - - /** - * Sets last week's honor standing position - * - * @param int32 standingPos - */ - int SetHonorLastWeekStandingPos(Eluna* E, Player* player) - { - int32 standingPos = E->CHECKVAL(2); - - player->SetHonorLastWeekStandingPos(standingPos); - return 0; - } -#endif - - /** - * Sets the [Player]s amount of Lifetime Honorable Kills to the value specified - * - * @param uint32 honorableKills - */ - int SetLifetimeKills(Eluna* E, Player* player) - { - uint32 val = E->CHECKVAL(2); - player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, val); - return 0; - } - - /** - * Sets the [Player]s amount of money to copper specified - * - * @param uint32 copperAmt - */ - int SetCoinage(Eluna* E, Player* player) - { - uint32 amt = E->CHECKVAL(2); - player->SetMoney(amt); - return 0; - } - - /** - * Sets the [Player]s home location to the location specified - * - * @param float x : X Coordinate - * @param float y : Y Coordinate - * @param float z : Z Coordinate - * @param uint32 mapId : Map ID - * @param uint32 areaId : Area ID - */ - int SetBindPoint(Eluna* E, Player* player) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - uint32 mapId = E->CHECKVAL(5); - uint32 areaId = E->CHECKVAL(6); - - WorldLocation loc(mapId, x, y, z); - player->SetHomebindToLocation(loc, areaId); - return 0; - } - -#ifndef CLASSIC - /** - * Adds the specified title to the [Player]s list of known titles - * - * @param uint32 titleId - */ - int SetKnownTitle(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); - if (t) - player->SetTitle(t, false); - return 0; - } -#endif - - /** - * Toggle the [Player]s FFA flag - * - * @param bool applyFFA = true - */ - int SetFFA(Eluna* E, Player* player) - { - bool apply = E->CHECKVAL(2, true); - - player->SetFFAPvP(apply); - return 0; - } - - /*int SetMovement(Eluna* E, Player* player) - { - int32 pType = E->CHECKVAL(2); - - player->SetMovement((PlayerMovementType)pType); - return 0; - }*/ - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Resets the [Player]s pets talent points - */ - int ResetPetTalents(Eluna* /*E*/, Player* player) - { - Pet* pet = player->GetPet(); - Pet::resetTalentsForAllPetsOf(player, pet); - - if (pet) - player->SendTalentsInfoData(true); - - return 0; - } - - /** - * Reset the [Player]s completed achievements - */ - int ResetAchievements(Eluna* /*E*/, Player* player) - { - player->GetAchievementMgr().Reset(); - return 0; - } -#endif - - /** - * Shows the mailbox window to the player from specified guid. - * - * @param ObjectGuid guid = playerguid : guid of the mailbox window sender - */ - int SendShowMailBox(Eluna* E, Player* player) - { - ObjectGuid guid = E->CHECKVAL(2, player->GET_GUID()); - -#if (defined(CLASSIC) || defined(TBC)) - WorldPacket data(CMSG_GET_MAIL_LIST, 8); - data << guid; - player->GetSession()->HandleGetMailList(data); -#else - player->GetSession()->SendShowMailBox(guid); -#endif - return 0; - } - -#if defined(TBC) || defined(WOTLK) - /** - * Adds or detracts from the [Player]s current Arena Points - * - * @param int32 amount - */ - int ModifyArenaPoints(Eluna* E, Player* player) - { - int32 amount = E->CHECKVAL(2); - - player->ModifyArenaPoints(amount); - return 0; - } - - /** - * Adds or detracts from the [Player]s current Honor Points - * - * @param int32 amount - */ - int ModifyHonorPoints(Eluna* E, Player* player) - { - int32 amount = E->CHECKVAL(2); - - player->ModifyHonorPoints(amount); - return 0; - } -#endif - - /** - * Saves the [Player] to the database - */ - int SaveToDB(Eluna* /*E*/, Player* player) - { - player->SaveToDB(); - return 0; - } - - /** - * Sends a summon request to the player from the given summoner - * - * @param [Unit] summoner - */ - int SummonPlayer(Eluna* E, Player* player) - { - Unit* summoner = E->CHECKOBJ(2); - - float x, y, z; - summoner->GetPosition(x,y,z); - player->SetSummonPoint(summoner->GetMapId(), x, y, z); - - WorldPacket data(SMSG_SUMMON_REQUEST, 8 + 4 + 4); - data << summoner->GET_GUID(); - data << uint32(summoner->GetZoneId()); - data << uint32(MAX_PLAYER_SUMMON_DELAY * IN_MILLISECONDS); - - player->GetSession()->SendPacket(&data); - return 0; - } - - /** - * Mutes the [Player] for the amount of seconds specified - * - * @param uint32 muteTime - */ - int Mute(Eluna* E, Player* player) - { - uint32 muteseconds = E->CHECKVAL(2); - /*const char* reason = luaL_checkstring(E, 2);*/ // Mangos does not have a reason field in database. - - time_t muteTime = time(NULL) + muteseconds; - player->GetSession()->m_muteTime = muteTime; - std::ostringstream oss; - oss << "UPDATE account SET mutetime = " << muteTime << " WHERE id = " << player->GetSession()->GetAccountId(); - LoginDatabase.PExecute("%s", oss.str().c_str()); - return 0; - } - - /** - * Rewards the given quest entry for the [Player] if he has completed it. - * - * @param uint32 entry : quest entry - */ - int RewardQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - Quest const* quest = eObjectMgr->GetQuestTemplate(entry); - - // If player doesn't have the quest - if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE) - return 0; - - player->RewardQuest(quest, 0, player); - return 0; - } - - /** - * Sends an auction house window to the [Player] from the [Unit] specified - * - * @param [Unit] sender - */ - int SendAuctionMenu(Eluna* E, Player* player) - { - Unit* unit = E->CHECKOBJ(2); - - AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit); - if (!ahEntry) - return 0; - - WorldPacket data(MSG_AUCTION_HELLO, 12); - data << unit->GET_GUID(); - data << uint32(ahEntry->houseId); - data << uint8(1); - - player->GetSession()->SendPacket(&data); - return 0; - } - - /** - * Sends a flightmaster window to the [Player] from the [Creature] specified - * - * @param [Creature] sender - */ - int SendTaxiMenu(Eluna* E, Player* player) - { - Creature* creature = E->CHECKOBJ(2); - - player->GetSession()->SendTaxiMenu(creature); - return 0; - } - - /** - * Sends a spirit resurrection request to the [Player] - */ - int SendSpiritResurrect(Eluna* /*E*/, Player* player) - { - player->GetSession()->SendSpiritResurrect(); - return 0; - } - - /** - * Sends a tabard vendor window to the [Player] from the [WorldObject] specified - * - * @param [WorldObject] sender - */ - int SendTabardVendorActivate(Eluna* E, Player* player) - { - WorldObject* obj = E->CHECKOBJ(2); - - player->GetSession()->SendTabardVendorActivate(obj->GET_GUID()); - return 0; - } - - /** - * Sends a bank window to the [Player] from the [WorldObject] specified. - * - * @param [WorldObject] sender - */ - int SendShowBank(Eluna* E, Player* player) - { - WorldObject* obj = E->CHECKOBJ(2); - - player->GetSession()->SendShowBank(obj->GET_GUID()); - return 0; - } - - /** - * Sends a vendor window to the [Player] from the [WorldObject] specified. - * - * @param [WorldObject] sender - */ - int SendListInventory(Eluna* E, Player* player) - { - WorldObject* obj = E->CHECKOBJ(2); - - player->GetSession()->SendListInventory(obj->GET_GUID()); - return 0; - } - - /** - * Sends a trainer window to the [Player] from the [Creature] specified - * - * @param [Creature] sender - */ - int SendTrainerList(Eluna* E, Player* player) - { - Creature* obj = E->CHECKOBJ(2); - - player->GetSession()->SendTrainerList(obj->GET_GUID()); - return 0; - } - - /** - * Sends a guild invitation from the [Player]s [Guild] to the [Player] object specified - * - * @param [Player] invitee - */ - int SendGuildInvite(Eluna* E, Player* player) - { - Player* plr = E->CHECKOBJ(2); - - player->GetSession()->SendGuildInvite(plr); - return 0; - } - - /** - * Sends an update for the world state to the [Player] - * - * @param uint32 field - * @param uint32 value - */ - int SendUpdateWorldState(Eluna* E, Player* player) - { - uint32 field = E->CHECKVAL(2); - uint32 value = E->CHECKVAL(3); - - player->SendUpdateWorldState(field, value); - return 0; - } - - /** - * Forces the [Player] to log out - * - * @param bool saveToDb = true - */ - int LogoutPlayer(Eluna* E, Player* player) - { - bool save = E->CHECKVAL(2, true); - - player->GetSession()->LogoutPlayer(save); - return 0; - } - - /** - * Forcefully removes the [Player] from a [BattleGround] raid group - */ - int RemoveFromBattlegroundRaid(Eluna* /*E*/, Player* player) - { - player->RemoveFromBattleGroundRaid(); - return 0; - } - - /** - * Unbinds the [Player] from his instances except the one he currently is in. - * - * Difficulty is not used on classic. - * - * @param uint32 map = true - * @param uint32 difficulty = 0 - */ - int UnbindInstance(Eluna* E, Player* player) - { - uint32 map = E->CHECKVAL(2); -#ifndef CLASSIC - uint32 difficulty = E->CHECKVAL(3, 0); - - if (difficulty < MAX_DIFFICULTY) - player->UnbindInstance(map, (Difficulty)difficulty); -#else//CLASSIC - player->UnbindInstance(map); -#endif - return 0; - } - - /** - * Unbinds the [Player] from his instances except the one he currently is in. - */ - int UnbindAllInstances(Eluna* /*E*/, Player* player) - { -#ifdef CLASSIC - Player::BoundInstancesMap& binds = player->GetBoundInstances(); - for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) - { - if (itr->first != player->GetMapId()) - player->UnbindInstance(itr); - else - ++itr; - } -#else - for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) - { - Player::BoundInstancesMap& binds = player->GetBoundInstances(Difficulty(i)); - for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();) - { - if (itr->first != player->GetMapId()) - player->UnbindInstance(itr, Difficulty(i)); - else - ++itr; - } - } -#endif - return 0; - } - - /** - * Forces the [Player] to leave a [BattleGround] - * - * @param bool teleToEntry = true - */ - int LeaveBattleground(Eluna* E, Player* player) - { - bool teleToEntryPoint = E->CHECKVAL(2, true); - - player->LeaveBattleground(teleToEntryPoint); - return 0; - } - - /** - * Repairs [Item] at specified position. - * - * @param uint16 position - * @param bool cost = true - * @param float discountMod = 1.0 - */ - int DurabilityRepair(Eluna* E, Player* player) - { - uint16 position = E->CHECKVAL(2); - bool takeCost = E->CHECKVAL(3, true); - float discountMod = E->CHECKVAL(4, 1.0f); - -#ifdef CLASSIC - player->DurabilityRepair(position, takeCost, discountMod); -#else - player->DurabilityRepair(position, takeCost, discountMod, false); -#endif - return 0; - } - - /** - * Repairs all [Item]s. - * - * @param bool takeCost = true - * @param float discountMod = 1.0 - * @param bool guidBank = false - */ - int DurabilityRepairAll(Eluna* E, Player* player) - { - bool takeCost = E->CHECKVAL(2, true); - float discountMod = E->CHECKVAL(3, 1.0f); - bool guildBank = E->CHECKVAL(4, false); - -#ifdef CLASSIC - player->DurabilityRepairAll(takeCost, discountMod); -#else - player->DurabilityRepairAll(takeCost, discountMod, guildBank); -#endif - return 0; - } - - /** - * Sets durability loss for an [Item] in the specified slot - * - * @param int32 slot - */ - int DurabilityPointLossForEquipSlot(Eluna* E, Player* player) - { - int32 slot = E->CHECKVAL(2); - - if (slot >= EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END) - player->DurabilityPointLossForEquipSlot((EquipmentSlots)slot); - return 0; - } - - /** - * Sets durability loss on all [Item]s equipped - * - * If inventory is true, sets durability loss for [Item]s in bags - * - * @param int32 points - * @param bool inventory = true - */ - int DurabilityPointsLossAll(Eluna* E, Player* player) - { - int32 points = E->CHECKVAL(2); - bool inventory = E->CHECKVAL(3, true); - - player->DurabilityPointsLossAll(points, inventory); - return 0; - } - - /** - * Sets durability loss for the specified [Item] - * - * @param [Item] item - * @param int32 points - */ - int DurabilityPointsLoss(Eluna* E, Player* player) - { - Item* item = E->CHECKOBJ(2); - int32 points = E->CHECKVAL(3); - - player->DurabilityPointsLoss(item, points); - return 0; - } - - /** - * Damages specified [Item] - * - * @param [Item] item - * @param double percent - */ - int DurabilityLoss(Eluna* E, Player* player) - { - Item* item = E->CHECKOBJ(2); - double percent = E->CHECKVAL(3); - - player->DurabilityLoss(item, percent); - return 0; - } - - /** - * Damages all [Item]s equipped. If inventory is true, damages [Item]s in bags - * - * @param double percent - * @param bool inventory = true - */ - int DurabilityLossAll(Eluna* E, Player* player) - { - double percent = E->CHECKVAL(2); - bool inventory = E->CHECKVAL(3, true); - - player->DurabilityLossAll(percent, inventory); - return 0; - } - - /** - * Kills the [Player] - */ - int KillPlayer(Eluna* /*E*/, Player* player) - { - player->KillPlayer(); - return 0; - } - - /** - * Forces the [Player] to leave a [Group] - */ - int RemoveFromGroup(Eluna* /*E*/, Player* player) - { - if (!player->GetGroup()) - return 0; - - player->RemoveFromGroup(); - return 0; - } - - /** - * Returns the [Player]s accumulated talent reset cost - * - * @return uint32 resetCost - */ - int ResetTalentsCost(Eluna* E, Player* player) - { -#ifdef CATA - E->Push(player->GetNextResetTalentsCost()); -#else - E->Push(player->resetTalentsCost()); -#endif - return 1; - } - - /** - * Resets the [Player]s talents - * - * @param bool noCost = true - */ - int ResetTalents(Eluna* E, Player* player) - { - bool no_cost = E->CHECKVAL(2, true); - -#ifdef CATA - player->ResetTalents(no_cost); -#else - player->resetTalents(no_cost); -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - player->SendTalentsInfoData(false); -#endif - return 0; - } - - /** - * Removes the [Spell] from the [Player] - * - * @param uint32 entry : entry of a [Spell] - */ - int RemoveSpell(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - player->removeSpell(entry); - return 0; - } - - /** - * Clears the [Player]s combo points - */ - int ClearComboPoints(Eluna* /*E*/, Player* player) - { - player->ClearComboPoints(); - return 0; - } - - /** - * Adds combo points to the [Player] - * - * @param [Unit] target - * @param int8 count - */ - int AddComboPoints(Eluna* E, Player* player) - { - Unit* target = E->CHECKOBJ(2); - int8 count = E->CHECKVAL(3); - - player->AddComboPoints(target, count); - return 0; - } - - /** - * Gives [Quest] monster talked to credit - * - * @param uint32 entry : entry of a [Creature] - * @param [Creature] creature - */ - int TalkedToCreature(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - Creature* creature = E->CHECKOBJ(3); - - player->TalkedToCreature(entry, creature->GET_GUID()); - return 0; - } - - /** - * Gives [Quest] monster killed credit - * - * @param uint32 entry : entry of a [Creature] - */ - int KilledMonsterCredit(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - player->KilledMonsterCredit(entry, player->GET_GUID()); - return 0; - } - - /** - * Completes a [Quest] if in a [Group] - * - * @param uint32 quest : entry of a quest - * @param [WorldObject] obj - */ - int GroupEventHappens(Eluna* E, Player* player) - { - uint32 questId = E->CHECKVAL(2); - WorldObject* obj = E->CHECKOBJ(3); - - player->GroupEventHappens(questId, obj); - return 0; - } - - /** - * Completes the [Quest] if a [Quest] area is explored, or completes the [Quest] - * - * @param uint32 quest : entry of a [Quest] - */ - int AreaExploredOrEventHappens(Eluna* E, Player* player) - { - uint32 questId = E->CHECKVAL(2); - - player->AreaExploredOrEventHappens(questId); - return 0; - } - - /** - * Sets the given [Quest] entry failed for the [Player]. - * - * @param uint32 entry : entry of a [Quest] - */ - int FailQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - player->FailQuest(entry); - return 0; - } - - /** - * Sets the given quest entry incomplete for the [Player]. - * - * @param uint32 entry : quest entry - */ - int IncompleteQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - player->IncompleteQuest(entry); - return 0; - } - - /** - * Completes the given quest entry for the [Player] and tries to satisfy all quest requirements. - * - * The player should have the quest to complete it. - * - * @param uint32 entry : quest entry - */ - int CompleteQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - Quest const* quest = eObjectMgr->GetQuestTemplate(entry); - - // If player doesn't have the quest - if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE) - return 0; - - // Add quest items for quests that require items - for (uint8 x = 0; x < QUEST_ITEM_OBJECTIVES_COUNT; ++x) - { - uint32 id = quest->ReqItemId[x]; - uint32 count = quest->ReqItemCount[x]; - - if (!id || !count) - continue; - - uint32 curItemCount = player->GetItemCount(id, true); - - ItemPosCountVec dest; - uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, id, count - curItemCount); - if (msg == EQUIP_ERR_OK) - { - Item* item = player->StoreNewItem(dest, id, true); - player->SendNewItem(item, count - curItemCount, true, false); - } - } - - // All creature/GO slain/cast (not required, but otherwise it will display "Creature slain 0/10") - for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i) - { - int32 creature = quest->ReqCreatureOrGOId[i]; - uint32 creaturecount = quest->ReqCreatureOrGOCount[i]; - - if (uint32 spell_id = quest->ReqSpell[i]) - { - for (uint16 z = 0; z < creaturecount; ++z) - player->CastedCreatureOrGO(creature, ObjectGuid(), spell_id); - } - else if (creature > 0) - { - if (CreatureInfo const* cInfo = ObjectMgr::GetCreatureTemplate(creature)) - for (uint16 z = 0; z < creaturecount; ++z) - player->KilledMonster(cInfo, ObjectGuid()); - } - else if (creature < 0) - { - for (uint16 z = 0; z < creaturecount; ++z) - player->CastedCreatureOrGO(-creature, ObjectGuid(), 0); - } - } - - // If the quest requires reputation to complete - if (uint32 repFaction = quest->GetRepObjectiveFaction()) - { - uint32 repValue = quest->GetRepObjectiveValue(); - uint32 curRep = player->GetReputationMgr().GetReputation(repFaction); - if (curRep < repValue) - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction)) - player->GetReputationMgr().SetReputation(factionEntry, repValue); - } - - // If the quest requires money - int32 ReqOrRewMoney = quest->GetRewOrReqMoney(); - if (ReqOrRewMoney < 0) - player->ModifyMoney(-ReqOrRewMoney); - - player->CompleteQuest(entry); - return 0; - } - - /** - * Tries to add the given quest entry for the [Player]. - * - * @param uint32 entry : quest entry - */ - int AddQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - Quest const* quest = eObjectMgr->GetQuestTemplate(entry); - - if (!quest) - return 0; - - // check item starting quest (it can work incorrectly if added without item in inventory) - for (uint32 id = 0; id < sItemStorage.GetMaxEntry(); ++id) - { - ItemPrototype const* pProto = sItemStorage.LookupEntry(id); - if (!pProto) - continue; - - if (pProto->StartQuest == entry) - return 0; - } - - // ok, normal (creature/GO starting) quest - if (player->CanAddQuest(quest, true)) - { - player->AddQuest(quest, NULL); - - if (player->CanCompleteQuest(entry)) - player->CompleteQuest(entry); - } - - return 0; - } - - /** - * Removes the given quest entry from the [Player]. - * - * @param uint32 entry : quest entry - */ - int RemoveQuest(Eluna* E, Player* player) - { - uint32 entry = E->CHECKVAL(2); - - Quest const* quest = eObjectMgr->GetQuestTemplate(entry); - - if (!quest) - return 0; - - // remove all quest entries for 'entry' from quest log - for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot) - { - uint32 logQuest = player->GetQuestSlotQuestId(slot); - if (logQuest == entry) - { - player->SetQuestSlot(slot, 0); - - // we ignore unequippable quest items in this case, its' still be equipped - player->TakeQuestSourceItem(logQuest, false); - } - } - - // set quest status to not started (will updated in DB at next save) - player->SetQuestStatus(entry, QUEST_STATUS_NONE); - - // reset rewarded for restart repeatable quest - player->getQuestStatusMap()[entry].m_rewarded = false; - - return 0; - } - - /** - * Sends whisper text from the [Player] - * - * @param string text - * @param uint32 lang : language the [Player] will speak - * @param [Player] receiver : is the [Player] that will receive the whisper, if TrinityCore - * @param ObjectGuid guid : is the GUID of a [Player] that will receive the whisper, not TrinityCore - */ - int Whisper(Eluna* E, Player* player) - { - std::string text = E->CHECKVAL(2); - uint32 lang = E->CHECKVAL(3); - ObjectGuid guid = E->CHECKVAL(4); - - player->Whisper(text, lang, guid); - return 0; - } - - /** - * Sends a text emote from the [Player] - * - * @param string emoteText - */ - int TextEmote(Eluna* E, Player* player) - { - std::string text = E->CHECKVAL(2); - - player->TextEmote(text); - return 0; - } - - /** - * Sends yell text from the [Player] - * - * @param string text : text for the [Player] to yells - * @param uint32 lang : language the [Player] will speak - */ - int Yell(Eluna* E, Player* player) - { - std::string text = E->CHECKVAL(2); - uint32 lang = E->CHECKVAL(3); - - player->Yell(text, lang); - return 0; - } - - /** - * Sends say text from the [Player] - * - * @param string text : text for the [Player] to say - * @param uint32 lang : language the [Player] will speak - */ - int Say(Eluna* E, Player* player) - { - std::string text = E->CHECKVAL(2); - uint32 lang = E->CHECKVAL(3); - - player->Say(text, lang); - return 0; - } - - /** - * Gives the [Player] experience - * - * @param uint32 xp : experience to give - * @param [Unit] victim = nil - */ - int GiveXP(Eluna* E, Player* player) - { - uint32 xp = E->CHECKVAL(2); - Unit* victim = E->CHECKOBJ(3, false); - - player->GiveXP(xp, victim); - return 0; - } - - /** - * Toggle the [Player]s 'Do Not Disturb' flag - */ - int ToggleDND(Eluna* /*E*/, Player* player) - { - player->ToggleDND(); - return 0; - } - - /** - * Toggle the [Player]s 'Away From Keyboard' flag - */ - int ToggleAFK(Eluna* /*E*/, Player* player) - { - player->ToggleAFK(); - return 0; - } - - /** - * Equips the given item or item entry to the given slot. Returns the equipped item or nil. - * - * enum EquipmentSlots // 19 slots - * { - * EQUIPMENT_SLOT_START = 0, - * EQUIPMENT_SLOT_HEAD = 0, - * EQUIPMENT_SLOT_NECK = 1, - * EQUIPMENT_SLOT_SHOULDERS = 2, - * EQUIPMENT_SLOT_BODY = 3, - * EQUIPMENT_SLOT_CHEST = 4, - * EQUIPMENT_SLOT_WAIST = 5, - * EQUIPMENT_SLOT_LEGS = 6, - * EQUIPMENT_SLOT_FEET = 7, - * EQUIPMENT_SLOT_WRISTS = 8, - * EQUIPMENT_SLOT_HANDS = 9, - * EQUIPMENT_SLOT_FINGER1 = 10, - * EQUIPMENT_SLOT_FINGER2 = 11, - * EQUIPMENT_SLOT_TRINKET1 = 12, - * EQUIPMENT_SLOT_TRINKET2 = 13, - * EQUIPMENT_SLOT_BACK = 14, - * EQUIPMENT_SLOT_MAINHAND = 15, - * EQUIPMENT_SLOT_OFFHAND = 16, - * EQUIPMENT_SLOT_RANGED = 17, - * EQUIPMENT_SLOT_TABARD = 18, - * EQUIPMENT_SLOT_END = 19 - * }; - * - * enum InventorySlots // 4 slots - * { - * INVENTORY_SLOT_BAG_START = 19, - * INVENTORY_SLOT_BAG_END = 23 - * }; - * - * @proto equippedItem = (item, slot) - * @proto equippedItem = (entry, slot) - * @param [Item] item : item to equip - * @param uint32 entry : entry of the item to equip - * @param uint32 slot : equipment slot to equip the item to The slot can be [EquipmentSlots] or [InventorySlots] - * @return [Item] equippedItem : item or nil if equipping failed - */ - int EquipItem(Eluna* E, Player* player) - { - uint16 dest = 0; - Item* item = E->CHECKOBJ(2, false); - uint32 slot = E->CHECKVAL(3); - - if (slot >= INVENTORY_SLOT_BAG_END) - return 1; - - if (!item) - { - uint32 entry = E->CHECKVAL(2); - item = Item::CreateItem(entry, 1, player); - if (!item) - return 1; - - InventoryResult result = player->CanEquipItem(slot, dest, item, false); - if (result != EQUIP_ERR_OK) - { - delete item; - return 1; - } - player->ItemAddedQuestCheck(entry, 1); -#if (!defined(TBC) && !defined(CLASSIC)) - player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, entry, 1); -#endif - } - else - { - InventoryResult result = player->CanEquipItem(slot, dest, item, false); - if (result != EQUIP_ERR_OK) - return 1; - player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true); - } - - E->Push(player->EquipItem(dest, item, true)); - player->AutoUnequipOffhandIfNeed(); - return 1; - } - - /** - * Returns true if the player can equip the given [Item] or item entry to the given slot, false otherwise. - * - * @proto canEquip = (item, slot) - * @proto canEquip = (entry, slot) - * @param [Item] item : item to equip - * @param uint32 entry : entry of the item to equip - * @param uint32 slot : equipment slot to test - * @return bool canEquip - */ - int CanEquipItem(Eluna* E, Player* player) - { - Item* item = E->CHECKOBJ(2, false); - uint32 slot = E->CHECKVAL(3); - if (slot >= EQUIPMENT_SLOT_END) - { - E->Push(false); - return 1; - } - - if (!item) - { - uint32 entry = E->CHECKVAL(2); - uint16 dest; - InventoryResult msg = player->CanEquipNewItem(slot, dest, entry, false); - if (msg != EQUIP_ERR_OK) - { - E->Push(false); - return 1; - } - } - else - { - uint16 dest; - InventoryResult msg = player->CanEquipItem(slot, dest, item, false); - if (msg != EQUIP_ERR_OK) - { - E->Push(false); - return 1; - } - } - E->Push(true); - return 1; - } - -#ifndef CLASSIC - /** - * Removes a title by ID from the [Player]s list of known titles - * - * @param uint32 titleId - */ - int UnsetKnownTitle(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); - if (t) - player->SetTitle(t, true); - return 0; - } -#endif - - /** - * Advances all of the [Player]s weapon skills to the maximum amount available - */ - int AdvanceSkillsToMax(Eluna* /*E*/, Player* player) - { - player->UpdateSkillsToMaxSkillsForLevel(); - return 0; - } - - /** - * Advances all of the [Player]s skills to the amount specified - * - * @param uint32 skillStep - */ - int AdvanceAllSkills(Eluna* E, Player* player) - { - uint32 step = E->CHECKVAL(2); - - if (!step) - return 0; - - for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i) - { - if (SkillLineEntry const* entry = sSkillLineStore.LookupEntry(i)) - { - if (entry->categoryId == SKILL_CATEGORY_LANGUAGES || entry->categoryId == SKILL_CATEGORY_GENERIC) - continue; - - if (player->HasSkill(entry->id)) - player->UpdateSkill(entry->id, step); - } - } - - return 0; - } - - /** - * Advances a [Player]s specific skill to the amount specified - * - * @param uint32 skillId - * @param uint32 skillStep - */ - int AdvanceSkill(Eluna* E, Player* player) - { - uint32 _skillId = E->CHECKVAL(2); - uint32 _step = E->CHECKVAL(3); - if (_skillId && _step) - { - if (player->HasSkill(_skillId)) - player->UpdateSkill(_skillId, _step); - } - return 0; - } - - /** - * Teleports a [Player] to the location specified - * - * @param uint32 mappId - * @param float xCoord - * @param float yCoord - * @param float zCoord - * @param float orientation - */ - int Teleport(Eluna* E, Player* player) - { - uint32 mapId = E->CHECKVAL(2); - float x = E->CHECKVAL(3); - float y = E->CHECKVAL(4); - float z = E->CHECKVAL(5); - float o = E->CHECKVAL(6); - - if (player->IsTaxiFlying()) - { - player->GetMotionMaster()->MovementExpired(); - player->m_taxi.ClearTaxiDestinations(); - } - - E->Push(player->TeleportTo(mapId, x, y, z, o)); - return 1; - } - - int AddLifetimeKills(Eluna* E, Player* player) - { - uint32 val = E->CHECKVAL(2); - uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS); - player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills + val); - return 0; - } - - /** - * Adds the given amount of the specified item entry to the player. - * - * @param uint32 entry : entry of the item to add - * @param uint32 itemCount = 1 : amount of the item to add - * @return [Item] item : the item that was added or nil - */ - int AddItem(Eluna* E, Player* player) - { - uint32 itemId = E->CHECKVAL(2); - uint32 itemCount = E->CHECKVAL(3, 1); - - E->Push(player->StoreNewItemInInventorySlot(itemId, itemCount)); - return 1; - } - - /** - * Removes the given amount of the specified [Item] from the player. - * - * @proto (item, itemCount) - * @proto (entry, itemCount) - * @param [Item] item : item to remove - * @param uint32 entry : entry of the item to remove - * @param uint32 itemCount = 1 : amount of the item to remove - */ - int RemoveItem(Eluna* E, Player* player) - { - Item* item = E->CHECKOBJ(2, false); - uint32 itemCount = E->CHECKVAL(3); - if (!item) - { - uint32 itemId = E->CHECKVAL(2); - player->DestroyItemCount(itemId, itemCount, true); - } - else - { - bool all = itemCount >= item->GetCount(); - player->DestroyItemCount(item, itemCount, true); - if (all) - E->CHECKOBJ(2)->Invalidate(); - } - return 0; - } - - /** - * Removes specified amount of lifetime kills - * - * @param uint32 val : kills to remove - */ - int RemoveLifetimeKills(Eluna* E, Player* player) - { - uint32 val = E->CHECKVAL(2); - uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS); - if (val > currentKills) - val = currentKills; - player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills - val); - return 0; - } - - /** - * Resets cooldown of the specified spell - * - * @param uint32 spellId - * @param bool update = true - */ - int ResetSpellCooldown(Eluna* E, Player* player) - { - uint32 spellId = E->CHECKVAL(2); - bool update = E->CHECKVAL(3, true); - - player->RemoveSpellCooldown(spellId, update); - return 0; - } - - /** - * Resets cooldown of the specified category - * - * @param uint32 category - * @param bool update = true - */ - int ResetTypeCooldowns(Eluna* E, Player* player) - { - uint32 category = E->CHECKVAL(2); - bool update = E->CHECKVAL(3, true); - (void)update; // ensure that the variable is referenced in order to pass compiler checks - - player->RemoveSpellCategoryCooldown(category, update); - return 0; - } - - /** - * Resets all of the [Player]'s cooldowns - */ - int ResetAllCooldowns(Eluna* /*E*/, Player* player) - { - player->RemoveAllSpellCooldown(); - return 0; - } - - /** - * Sends a Broadcast Message to the [Player] - * - * @param string message - */ - int SendBroadcastMessage(Eluna* E, Player* player) - { - const char* message = E->CHECKVAL(2); - if (std::string(message).length() > 0) - ChatHandler(player->GetSession()).SendSysMessage(message); - return 0; - } - - /** - * Sends an Area Trigger Message to the [Player] - * - * @param string message - */ - int SendAreaTriggerMessage(Eluna* E, Player* player) - { - std::string msg = E->CHECKVAL(2); - if (msg.length() > 0) - player->GetSession()->SendAreaTriggerMessage("%s", msg.c_str()); - return 0; - } - - /** - * Sends a Notification to the [Player] - * - * @param string message - */ - int SendNotification(Eluna* E, Player* player) - { - std::string msg = E->CHECKVAL(2); - if (msg.length() > 0) - player->GetSession()->SendNotification("%s", msg.c_str()); - return 0; - } - - /** - * Sends a [WorldPacket] to the [Player] - * - * @param [WorldPacket] packet - * @param bool selfOnly = true - */ - int SendPacket(Eluna* E, Player* player) - { - WorldPacket* data = E->CHECKOBJ(2); - bool selfOnly = E->CHECKVAL(3, true); - - if (selfOnly) - player->GetSession()->SendPacket(data); - else - player->SendMessageToSet(data, true); - - return 0; - } - - /** - * Sends addon message to the [Player] receiver - * - * @param string prefix - * @param string message - * @param [ChatMsg] channel - * @param [Player] receiver - * - */ - int SendAddonMessage(Eluna* E, Player* player) - { - std::string prefix = E->CHECKVAL(2); - std::string message = E->CHECKVAL(3); - uint8 channel = E->CHECKVAL(4); - Player* receiver = E->CHECKOBJ(5); - - std::string fullmsg = prefix + "\t" + message; - - WorldPacket data(SMSG_MESSAGECHAT, 100); - data << uint8(channel); - data << int32(LANG_ADDON); - data << player->GET_GUID(); -#ifndef CLASSIC - data << uint32(0); - data << receiver->GET_GUID(); -#endif - data << uint32(fullmsg.length() + 1); - data << fullmsg; - data << uint8(0); - - receiver->GetSession()->SendPacket(&data); - return 0; - } - - /** - * Kicks the [Player] from the server - */ - int KickPlayer(Eluna* /*E*/, Player* player) - { - player->GetSession()->KickPlayer(); - return 0; - } - - /** - * Adds or subtracts from the [Player]s money in copper - * - * @param int32 copperAmt : negative to remove, positive to add - */ - int ModifyMoney(Eluna* E, Player* player) - { - int32 amt = E->CHECKVAL(2); - - player->ModifyMoney(amt); - return 1; - } - - /** - * Teaches the [Player] the [Spell] specified by entry ID - * - * @param uint32 spellId - */ - int LearnSpell(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - - player->learnSpell(id, false); - return 0; - } - - /** - * Learn the [Player] the talent specified by talent_id and talentRank - * - * @param uint32 talent_id - * @param uint32 talentRank - */ - int LearnTalent(Eluna* E, Player* player) - { - uint32 id = E->CHECKVAL(2); - uint32 rank = E->CHECKVAL(3); - - player->LearnTalent(id, rank); -#if (!defined(TBC) && !defined(CLASSIC)) - player->SendTalentsInfoData(false); -#endif - - // if player has a pet, update owner talent auras - if (player->GetPet()) - player->GetPet()->CastOwnerTalentAuras(); - return 0; - } - -#if !defined(CLASSIC) - /** - * Remove cooldowns on spells that have less than 10 minutes of cooldown from the [Player], similarly to when you enter an arena. - */ - int RemoveArenaSpellCooldowns(Eluna* /*E*/, Player* player) - { - player->RemoveArenaSpellCooldowns(); - return 0; - } -#endif - - /** - * Resurrects the [Player]. - * - * @param float healthPercent = 100.0f - * @param bool ressSickness = false - */ - int ResurrectPlayer(Eluna* E, Player* player) - { - float percent = E->CHECKVAL(2, 100.0f); - bool sickness = E->CHECKVAL(3, false); - player->ResurrectPlayer(percent, sickness); - player->SpawnCorpseBones(); - return 0; - } - - /** - * Adds a new item to the gossip menu shown to the [Player] on next call to [Player:GossipSendMenu]. - * - * sender and intid are numbers which are passed directly to the gossip selection handler. Internally they are partly used for the database gossip handling. - * code specifies whether to show a box to insert text to. The player inserted text is passed to the gossip selection handler. - * money specifies an amount of money the player needs to have to click the option. An error message is shown if the player doesn't have enough money. - * Note that the money amount is only checked client side and is not removed from the player either. You will need to check again in your code before taking action. - * - * See also: [Player:GossipSendMenu], [Player:GossipAddQuests], [Player:GossipComplete], [Player:GossipClearMenu] - * - * @param uint32 icon : number that specifies used icon - * @param string msg : label on the gossip item - * @param uint32 sender : number passed to gossip handlers - * @param uint32 intid : number passed to gossip handlers - * @param bool code = false : show text input on click if true - * @param string popup = nil : if non empty string, a popup with given text shown on click - * @param uint32 money = 0 : required money in copper - */ - int GossipMenuAddItem(Eluna* E, Player* player) - { - uint32 _icon = E->CHECKVAL(2); - const char* msg = E->CHECKVAL(3); - uint32 _sender = E->CHECKVAL(4); - uint32 _intid = E->CHECKVAL(5); - bool _code = E->CHECKVAL(6, false); - const char* _promptMsg = E->CHECKVAL(7, ""); - uint32 _money = E->CHECKVAL(8, 0); -#if !defined(CLASSIC) - player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _money, _code); -#else - player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _code); -#endif - return 0; - } - - /** - * Closes the [Player]s currently open Gossip Menu. - * - * See also: [Player:GossipMenuAddItem], [Player:GossipAddQuests], [Player:GossipSendMenu], [Player:GossipClearMenu] - */ - int GossipComplete(Eluna* /*E*/, Player* player) - { - player->PlayerTalkClass->CloseGossip(); - return 0; - } - - /** - * Sends the current gossip items of the player to him as a gossip menu with header text from the given textId. - * - * If sender is a [Player] then menu_id is mandatory, otherwise it is not used for anything. - * menu_id is the ID used to trigger the OnGossipSelect registered for players. See [Global:RegisterPlayerGossipEvent] - * - * See also: [Player:GossipMenuAddItem], [Player:GossipAddQuests], [Player:GossipComplete], [Player:GossipClearMenu] - * - * @proto (npc_text, sender) - * @proto (npc_text, sender, menu_id) - * @param uint32 npc_text : entry ID of a header text in npc_text database table, common default is 100 - * @param [Object] sender : object acting as the source of the sent gossip menu - * @param uint32 menu_id : if sender is a [Player] then menu_id is mandatory - */ - int GossipSendMenu(Eluna* E, Player* player) - { - uint32 npc_text = E->CHECKVAL(2); - Object* sender = E->CHECKOBJ(3); - if (sender->GetTypeId() == TYPEID_PLAYER) - { - uint32 menu_id = E->CHECKVAL(4); - player->PlayerTalkClass->GetGossipMenu().SetMenuId(menu_id); - } - - player->PlayerTalkClass->SendGossipMenu(npc_text, sender->GET_GUID()); - return 0; - } - - /** - * Clears the [Player]s current gossip item list. - * - * See also: [Player:GossipMenuAddItem], [Player:GossipSendMenu], [Player:GossipAddQuests], [Player:GossipComplete] - * - * Note: This is needed when you show a gossip menu without using gossip hello or select hooks which do this automatically. - * Usually this is needed when using [Player] is the sender of a Gossip Menu. - */ - int GossipClearMenu(Eluna* /*E*/, Player* player) - { - player->PlayerTalkClass->ClearMenus(); - return 0; - } - - /** - * Attempts to start the taxi/flying to the given pathID - * - * @param uint32 pathId : pathId from DBC or [Global:AddTaxiPath] - */ - int StartTaxi(Eluna* E, Player* player) - { - uint32 pathId = E->CHECKVAL(2); - - player->ActivateTaxiPathTo(pathId); - return 0; - } - - /** - * Sends POI to the location on your map - * - * @param float x - * @param float y - * @param uint32 icon : map icon to show - * @param uint32 flags - * @param uint32 data - * @param string iconText - */ - int GossipSendPOI(Eluna* E, Player* player) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - uint32 icon = E->CHECKVAL(4); - uint32 flags = E->CHECKVAL(5); - uint32 data = E->CHECKVAL(6); - std::string iconText = E->CHECKVAL(7); - - WorldPacket packet(SMSG_GOSSIP_POI, 4 + 4 + 4 + 4 + 4 + 10); - packet << flags; - packet << x; - packet << y; - packet << icon; - packet << data; - packet << iconText; - - player->GetSession()->SendPacket(&packet); - return 0; - } - - /** - * Adds the gossip items to the [Player]'s gossip for the quests the given [WorldObject] can offer to the player. - * - * @param [WorldObject] source : a questgiver with quests - */ - int GossipAddQuests(Eluna* E, Player* player) - { - WorldObject* source = E->CHECKOBJ(2); - - if (source->GetTypeId() == TYPEID_UNIT) - { - if (source->GetUInt32Value(UNIT_NPC_FLAGS) & UNIT_NPC_FLAG_QUESTGIVER) - player->PrepareQuestMenu(source->GET_GUID()); - } - else if (source->GetTypeId() == TYPEID_GAMEOBJECT) - { - if (source->ToGameObject()->GetGoType() == GAMEOBJECT_TYPE_QUESTGIVER) - player->PrepareQuestMenu(source->GET_GUID()); - } - return 0; - } - - /** - * Shows a quest accepting window to the [Player] for the given quest. - * - * @param uint32 questId : entry of a quest - * @param bool activateAccept = true : auto finish the quest - */ - int SendQuestTemplate(Eluna* E, Player* player) - { - uint32 questId = E->CHECKVAL(2); - bool activateAccept = E->CHECKVAL(3, true); - - Quest const* quest = eObjectMgr->GetQuestTemplate(questId); - if (!quest) - return 0; - - player->PlayerTalkClass->SendQuestGiverQuestDetails(quest, player->GET_GUID(), activateAccept); - return 0; - } - - /** - * Converts [Player]'s corpse to bones - */ - int SpawnBones(Eluna* /*E*/, Player* player) - { - player->SpawnCorpseBones(); - return 0; - } - - /** - * Loots [Player]'s bones for insignia - * - * @param [Player] looter - */ - int RemovedInsignia(Eluna* E, Player* player) - { - Player* looter = E->CHECKOBJ(2); - player->RemovedInsignia(looter); - return 0; - } - - /** - * Makes the [Player] invite another player to a group. - * - * @param [Player] invited : player to invite to group - * @return bool success : true if the player was invited to a group - */ - int GroupInvite(Eluna* E, Player* player) - { - Player* invited = E->CHECKOBJ(2); - - if (invited->GetGroup() || invited->GetGroupInvite()) - { - E->Push(false); - return 1; - } - - // Get correct existing group if any - Group* group = player->GetGroup(); - if (group && group->isBGGroup()) - group = player->GetOriginalGroup(); - - bool success = false; - - // Try invite if group found - if (group) - success = !group->IsFull() && group->AddInvite(invited); - else - { - // Create new group if one not found - group = new Group; - success = group->AddLeaderInvite(player) && group->AddInvite(invited); - if (!success) - delete group; - } - - if (success) - { -#if defined(CLASSIC) || defined(TBC) - WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size - data << player->GetName(); - invited->GetSession()->SendPacket(&data); -#else - WorldPacket data(SMSG_GROUP_INVITE, 10); // guess size - data << uint8(1); // invited/already in group flag - data << player->GetName(); // max len 48 - data << uint32(0); // unk - data << uint8(0); // count - data << uint32(0); // unk - invited->GetSession()->SendPacket(&data); -#endif - } - - E->Push(success); - return 1; - } - - /** - * Creates a new [Group] with the creator [Player] as leader. - * - * @param [Player] invited : player to add to group - * @return [Group] createdGroup : the created group or nil - */ - int GroupCreate(Eluna* E, Player* player) - { - Player* invited = E->CHECKOBJ(2); - - if (player->GetGroup() || invited->GetGroup()) - return 0; - - if (player->GetGroupInvite()) - player->UninviteFromGroup(); - if (invited->GetGroupInvite()) - invited->UninviteFromGroup(); - - // Try create new group - Group* group = new Group; - if (!group->AddLeaderInvite(player)) - { - delete group; - return 0; - } - - // Forming a new group, create it - if (!group->IsCreated()) - { - group->RemoveInvite(player); - if (!group->Create(group->GetLeaderGuid(), group->GetLeaderName())) - return 0; - - } - - if (!group->AddMember(invited->GetObjectGuid(), invited->GetName())) - return 0; - - E->Push(group); - return 1; - } - - /** - * Starts a cinematic for the [Player] - * - * @param uint32 CinematicSequenceId : entry of a cinematic - */ - int SendCinematicStart(Eluna* E, Player* player) - { - uint32 CinematicSequenceId = E->CHECKVAL(2); - - player->SendCinematicStart(CinematicSequenceId); - return 0; - } - -#if !defined(CLASSIC) && !defined(TBC) - /** - * Starts a movie for the [Player] - * - * @param uint32 MovieId : entry of a movie - */ - int SendMovieStart(Eluna* E, Player* player) - { - uint32 MovieId = E->CHECKVAL(2); - - player->SendMovieStart(MovieId); - return 0; - } -#endif - - ElunaRegister PlayerMethods[] = - { - // Getters - { "GetSelection", &LuaPlayer::GetSelection }, - { "GetGMRank", &LuaPlayer::GetGMRank }, - { "GetGuildId", &LuaPlayer::GetGuildId }, - { "GetCoinage", &LuaPlayer::GetCoinage }, - { "GetTeam", &LuaPlayer::GetTeam }, - { "GetItemCount", &LuaPlayer::GetItemCount }, - { "GetGroup", &LuaPlayer::GetGroup }, - { "GetGuild", &LuaPlayer::GetGuild }, - { "GetAccountId", &LuaPlayer::GetAccountId }, - { "GetAccountName", &LuaPlayer::GetAccountName }, - { "GetLifetimeKills", &LuaPlayer::GetLifetimeKills }, - { "GetPlayerIP", &LuaPlayer::GetPlayerIP }, - { "GetLevelPlayedTime", &LuaPlayer::GetLevelPlayedTime }, - { "GetTotalPlayedTime", &LuaPlayer::GetTotalPlayedTime }, - { "GetItemByPos", &LuaPlayer::GetItemByPos }, - { "GetItemByEntry", &LuaPlayer::GetItemByEntry }, - { "GetItemByGUID", &LuaPlayer::GetItemByGUID }, - { "GetMailItem", &LuaPlayer::GetMailItem }, - { "GetReputation", &LuaPlayer::GetReputation }, - { "GetEquippedItemBySlot", &LuaPlayer::GetEquippedItemBySlot }, - { "GetQuestLevel", &LuaPlayer::GetQuestLevel }, - { "GetChatTag", &LuaPlayer::GetChatTag }, - { "GetRestBonus", &LuaPlayer::GetRestBonus }, - { "GetReqKillOrCastCurrentCount", &LuaPlayer::GetReqKillOrCastCurrentCount }, - { "GetQuestStatus", &LuaPlayer::GetQuestStatus }, - { "GetInGameTime", &LuaPlayer::GetInGameTime }, - { "GetComboPoints", &LuaPlayer::GetComboPoints }, - { "GetComboTarget", &LuaPlayer::GetComboTarget }, - { "GetGuildName", &LuaPlayer::GetGuildName }, - { "GetFreeTalentPoints", &LuaPlayer::GetFreeTalentPoints }, - { "GetSpellCooldownDelay", &LuaPlayer::GetSpellCooldownDelay }, - { "GetGuildRank", &LuaPlayer::GetGuildRank }, - { "GetDifficulty", &LuaPlayer::GetDifficulty }, - { "GetHealthBonusFromStamina", &LuaPlayer::GetHealthBonusFromStamina }, - { "GetManaBonusFromIntellect", &LuaPlayer::GetManaBonusFromIntellect }, - { "GetMaxSkillValue", &LuaPlayer::GetMaxSkillValue }, - { "GetPureMaxSkillValue", &LuaPlayer::GetPureMaxSkillValue }, - { "GetSkillValue", &LuaPlayer::GetSkillValue }, - { "GetBaseSkillValue", &LuaPlayer::GetBaseSkillValue }, - { "GetPureSkillValue", &LuaPlayer::GetPureSkillValue }, - { "GetSkillPermBonusValue", &LuaPlayer::GetSkillPermBonusValue }, - { "GetSkillTempBonusValue", &LuaPlayer::GetSkillTempBonusValue }, - { "GetReputationRank", &LuaPlayer::GetReputationRank }, - { "GetDrunkValue", &LuaPlayer::GetDrunkValue }, - { "GetBattlegroundId", &LuaPlayer::GetBattlegroundId }, - { "GetBattlegroundTypeId", &LuaPlayer::GetBattlegroundTypeId }, - { "GetXPRestBonus", &LuaPlayer::GetXPRestBonus }, - { "GetGroupInvite", &LuaPlayer::GetGroupInvite }, - { "GetSubGroup", &LuaPlayer::GetSubGroup }, - { "GetNextRandomRaidMember", &LuaPlayer::GetNextRandomRaidMember }, - { "GetOriginalGroup", &LuaPlayer::GetOriginalGroup }, - { "GetOriginalSubGroup", &LuaPlayer::GetOriginalSubGroup }, - { "GetLatency", &LuaPlayer::GetLatency }, - { "GetDbLocaleIndex", &LuaPlayer::GetDbLocaleIndex }, - { "GetDbcLocale", &LuaPlayer::GetDbcLocale }, - { "GetCorpse", &LuaPlayer::GetCorpse }, - { "GetGossipTextId", &LuaPlayer::GetGossipTextId }, - { "GetQuestRewardStatus", &LuaPlayer::GetQuestRewardStatus }, - { "GetShieldBlockValue", &LuaPlayer::GetShieldBlockValue }, -#if defined(CLASSIC) - { "GetHonorStoredKills", &LuaPlayer::GetHonorStoredKills }, - { "GetRankPoints", &LuaPlayer::GetRankPoints }, - { "GetHonorLastWeekStandingPos", &LuaPlayer::GetHonorLastWeekStandingPos }, -#else - { "GetHonorStoredKills", nullptr, METHOD_REG_NONE }, - { "GetRankPoints", nullptr, METHOD_REG_NONE }, - { "GetHonorLastWeekStandingPos", nullptr, METHOD_REG_NONE }, -#endif -#if defined(TBC) || defined (WOTLK) - { "GetArenaPoints", &LuaPlayer::GetArenaPoints }, - { "GetHonorPoints", &LuaPlayer::GetHonorPoints }, -#else - { "GetArenaPoints", nullptr, METHOD_REG_NONE }, - { "GetHonorPoints", nullptr, METHOD_REG_NONE }, -#endif -#ifdef WOTLK - { "GetPhaseMaskForSpawn", &LuaPlayer::GetPhaseMaskForSpawn }, -#else - { "GetPhaseMaskForSpawn", nullptr, METHOD_REG_NONE }, -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - { "GetActiveSpec", &LuaPlayer::GetActiveSpec }, - { "GetSpecsCount", &LuaPlayer::GetSpecsCount }, -#else - { "GetActiveSpec", nullptr, METHOD_REG_NONE }, - { "GetSpecsCount", nullptr, METHOD_REG_NONE }, -#endif - - // Setters - { "AdvanceSkillsToMax", &LuaPlayer::AdvanceSkillsToMax }, - { "AdvanceSkill", &LuaPlayer::AdvanceSkill }, - { "AdvanceAllSkills", &LuaPlayer::AdvanceAllSkills }, - { "AddLifetimeKills", &LuaPlayer::AddLifetimeKills }, - { "SetCoinage", &LuaPlayer::SetCoinage }, - { "SetBindPoint", &LuaPlayer::SetBindPoint }, - { "SetLifetimeKills", &LuaPlayer::SetLifetimeKills }, - { "SetGameMaster", &LuaPlayer::SetGameMaster }, - { "SetGMChat", &LuaPlayer::SetGMChat }, - { "SetTaxiCheat", &LuaPlayer::SetTaxiCheat }, - { "SetGMVisible", &LuaPlayer::SetGMVisible }, - { "SetPvPDeath", &LuaPlayer::SetPvPDeath }, - { "SetAcceptWhispers", &LuaPlayer::SetAcceptWhispers }, - { "SetRestBonus", &LuaPlayer::SetRestBonus }, - { "SetQuestStatus", &LuaPlayer::SetQuestStatus }, - { "SetReputation", &LuaPlayer::SetReputation }, - { "SetFreeTalentPoints", &LuaPlayer::SetFreeTalentPoints }, - { "SetGuildRank", &LuaPlayer::SetGuildRank }, - { "SetSkill", &LuaPlayer::SetSkill }, - { "SetFactionForRace", &LuaPlayer::SetFactionForRace }, - { "SetDrunkValue", &LuaPlayer::SetDrunkValue }, - { "SetAtLoginFlag", &LuaPlayer::SetAtLoginFlag }, - { "SetPlayerLock", &LuaPlayer::SetPlayerLock }, - { "SetGender", &LuaPlayer::SetGender }, - { "SetSheath", &LuaPlayer::SetSheath }, -#if defined(CLASSIC) - { "SetKnownTitle", nullptr, METHOD_REG_NONE }, - { "UnsetKnownTitle", nullptr, METHOD_REG_NONE }, - { "SetHonorStoredKills", &LuaPlayer::SetHonorStoredKills }, - { "SetRankPoints", &LuaPlayer::SetRankPoints }, - { "SetHonorLastWeekStandingPos", &LuaPlayer::SetHonorLastWeekStandingPos }, -#else - { "SetKnownTitle", &LuaPlayer::SetKnownTitle }, - { "UnsetKnownTitle", &LuaPlayer::UnsetKnownTitle }, - { "SetHonorStoredKills", nullptr, METHOD_REG_NONE }, - { "SetRankPoints", nullptr, METHOD_REG_NONE }, - { "SetHonorLastWeekStandingPos", nullptr, METHOD_REG_NONE }, -#endif -#if defined(TBC) || defined(WOTLK) - { "SetArenaPoints", &LuaPlayer::SetArenaPoints }, - { "SetHonorPoints", &LuaPlayer::SetHonorPoints }, -#else - { "SetArenaPoints", nullptr, METHOD_REG_NONE }, - { "SetHonorPoints", nullptr, METHOD_REG_NONE }, -#endif - - // Boolean - { "IsInGroup", &LuaPlayer::IsInGroup }, - { "IsInGuild", &LuaPlayer::IsInGuild }, - { "IsGM", &LuaPlayer::IsGM }, - { "IsImmuneToDamage", &LuaPlayer::IsImmuneToDamage }, - { "IsAlliance", &LuaPlayer::IsAlliance }, - { "IsHorde", &LuaPlayer::IsHorde }, - { "HasItem", &LuaPlayer::HasItem }, - { "Teleport", &LuaPlayer::Teleport }, - { "AddItem", &LuaPlayer::AddItem }, - { "CanCompleteQuest", &LuaPlayer::CanCompleteQuest }, - { "CanEquipItem", &LuaPlayer::CanEquipItem }, - { "IsFalling", &LuaPlayer::IsFalling }, - { "ToggleAFK", &LuaPlayer::ToggleAFK }, - { "ToggleDND", &LuaPlayer::ToggleDND }, - { "IsAFK", &LuaPlayer::IsAFK }, - { "IsDND", &LuaPlayer::IsDND }, - { "IsAcceptingWhispers", &LuaPlayer::IsAcceptingWhispers }, - { "IsGMChat", &LuaPlayer::IsGMChat }, - { "IsTaxiCheater", &LuaPlayer::IsTaxiCheater }, - { "IsGMVisible", &LuaPlayer::IsGMVisible }, - { "HasQuest", &LuaPlayer::HasQuest }, - { "InBattlegroundQueue", &LuaPlayer::InBattlegroundQueue }, - { "CanSpeak", &LuaPlayer::CanSpeak }, - { "HasAtLoginFlag", &LuaPlayer::HasAtLoginFlag }, - { "CanUninviteFromGroup", &LuaPlayer::CanUninviteFromGroup }, - { "IsRested", &LuaPlayer::IsRested }, - { "IsVisibleForPlayer", &LuaPlayer::IsVisibleForPlayer }, - { "HasQuestForItem", &LuaPlayer::HasQuestForItem }, - { "HasQuestForGO", &LuaPlayer::HasQuestForGO }, - { "CanShareQuest", &LuaPlayer::CanShareQuest }, - { "IsInSameGroupWith", &LuaPlayer::IsInSameGroupWith }, - { "IsInSameRaidWith", &LuaPlayer::IsInSameRaidWith }, - { "IsGroupVisibleFor", &LuaPlayer::IsGroupVisibleFor }, - { "HasSkill", &LuaPlayer::HasSkill }, - { "IsHonorOrXPTarget", &LuaPlayer::IsHonorOrXPTarget }, - { "CanParry", &LuaPlayer::CanParry }, - { "CanBlock", &LuaPlayer::CanBlock }, - { "InBattleground", &LuaPlayer::InBattleground }, - { "CanUseItem", &LuaPlayer::CanUseItem }, - { "HasSpell", &LuaPlayer::HasSpell }, - { "HasSpellCooldown", &LuaPlayer::HasSpellCooldown }, - { "IsInWater", &LuaPlayer::IsInWater }, - { "IsMoving", &LuaPlayer::IsMoving }, -#ifndef CLASSIC - { "HasTitle", &LuaPlayer::HasTitle }, - { "IsInArenaTeam", &LuaPlayer::IsInArenaTeam }, - { "InArena", &LuaPlayer::InArena }, - { "CanFly", &LuaPlayer::CanFly }, - { "IsFlying", &LuaPlayer::IsFlying }, -#else - { "HasTitle", nullptr, METHOD_REG_NONE }, - { "IsInArenaTeam", nullptr, METHOD_REG_NONE }, - { "InArena", nullptr, METHOD_REG_NONE }, - { "CanFly", nullptr, METHOD_REG_NONE }, - { "IsFlying",nullptr, METHOD_REG_NONE }, -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - { "HasAchieved", &LuaPlayer::HasAchieved }, - { "HasTalent", &LuaPlayer::HasTalent }, - { "CanTitanGrip", &LuaPlayer::CanTitanGrip }, -#else - { "HasAchieved", nullptr, METHOD_REG_NONE }, - { "HasTalent", nullptr, METHOD_REG_NONE }, - { "CanTitanGrip", nullptr, METHOD_REG_NONE }, -#endif - - // Gossip - { "GossipMenuAddItem", &LuaPlayer::GossipMenuAddItem }, - { "GossipSendMenu", &LuaPlayer::GossipSendMenu }, - { "GossipComplete", &LuaPlayer::GossipComplete }, - { "GossipClearMenu", &LuaPlayer::GossipClearMenu }, - - // Other - { "SendBroadcastMessage", &LuaPlayer::SendBroadcastMessage }, - { "SendAreaTriggerMessage", &LuaPlayer::SendAreaTriggerMessage }, - { "SendNotification", &LuaPlayer::SendNotification }, - { "SendPacket", &LuaPlayer::SendPacket }, - { "SendAddonMessage", &LuaPlayer::SendAddonMessage }, - { "ModifyMoney", &LuaPlayer::ModifyMoney }, - { "LearnSpell", &LuaPlayer::LearnSpell }, - { "LearnTalent", &LuaPlayer::LearnTalent }, - { "RemoveItem", &LuaPlayer::RemoveItem }, - { "RemoveLifetimeKills", &LuaPlayer::RemoveLifetimeKills }, - { "ResurrectPlayer", &LuaPlayer::ResurrectPlayer }, - { "EquipItem", &LuaPlayer::EquipItem }, - { "ResetSpellCooldown", &LuaPlayer::ResetSpellCooldown }, - { "ResetTypeCooldowns", &LuaPlayer::ResetTypeCooldowns }, - { "ResetAllCooldowns", &LuaPlayer::ResetAllCooldowns }, - { "GiveXP", &LuaPlayer::GiveXP }, - { "Say", &LuaPlayer::Say }, - { "Yell", &LuaPlayer::Yell }, - { "TextEmote", &LuaPlayer::TextEmote }, - { "Whisper", &LuaPlayer::Whisper }, - { "CompleteQuest", &LuaPlayer::CompleteQuest }, - { "IncompleteQuest", &LuaPlayer::IncompleteQuest }, - { "FailQuest", &LuaPlayer::FailQuest }, - { "AddQuest", &LuaPlayer::AddQuest }, - { "RemoveQuest", &LuaPlayer::RemoveQuest }, - { "AreaExploredOrEventHappens", &LuaPlayer::AreaExploredOrEventHappens }, - { "GroupEventHappens", &LuaPlayer::GroupEventHappens }, - { "KilledMonsterCredit", &LuaPlayer::KilledMonsterCredit }, - { "TalkedToCreature", &LuaPlayer::TalkedToCreature }, - { "AddComboPoints", &LuaPlayer::AddComboPoints }, - { "ClearComboPoints", &LuaPlayer::ClearComboPoints }, - { "RemoveSpell", &LuaPlayer::RemoveSpell }, - { "ResetTalents", &LuaPlayer::ResetTalents }, - { "ResetTalentsCost", &LuaPlayer::ResetTalentsCost }, - { "RemoveFromGroup", &LuaPlayer::RemoveFromGroup }, - { "KillPlayer", &LuaPlayer::KillPlayer }, - { "DurabilityLossAll", &LuaPlayer::DurabilityLossAll }, - { "DurabilityLoss", &LuaPlayer::DurabilityLoss }, - { "DurabilityPointsLoss", &LuaPlayer::DurabilityPointsLoss }, - { "DurabilityPointsLossAll", &LuaPlayer::DurabilityPointsLossAll }, - { "DurabilityPointLossForEquipSlot", &LuaPlayer::DurabilityPointLossForEquipSlot }, - { "DurabilityRepairAll", &LuaPlayer::DurabilityRepairAll }, - { "DurabilityRepair", &LuaPlayer::DurabilityRepair }, - { "LeaveBattleground", &LuaPlayer::LeaveBattleground }, - { "UnbindInstance", &LuaPlayer::UnbindInstance }, - { "UnbindAllInstances", &LuaPlayer::UnbindAllInstances }, - { "RemoveFromBattlegroundRaid", &LuaPlayer::RemoveFromBattlegroundRaid }, - { "KickPlayer", &LuaPlayer::KickPlayer }, - { "LogoutPlayer", &LuaPlayer::LogoutPlayer }, - { "SendTrainerList", &LuaPlayer::SendTrainerList }, - { "SendListInventory", &LuaPlayer::SendListInventory }, - { "SendShowBank", &LuaPlayer::SendShowBank }, - { "SendTabardVendorActivate", &LuaPlayer::SendTabardVendorActivate }, - { "SendSpiritResurrect", &LuaPlayer::SendSpiritResurrect }, - { "SendTaxiMenu", &LuaPlayer::SendTaxiMenu }, - { "SendUpdateWorldState", &LuaPlayer::SendUpdateWorldState }, - { "RewardQuest", &LuaPlayer::RewardQuest }, - { "SendAuctionMenu", &LuaPlayer::SendAuctionMenu }, - { "SendShowMailBox", &LuaPlayer::SendShowMailBox }, - { "StartTaxi", &LuaPlayer::StartTaxi }, - { "GossipSendPOI", &LuaPlayer::GossipSendPOI }, - { "GossipAddQuests", &LuaPlayer::GossipAddQuests }, - { "SendQuestTemplate", &LuaPlayer::SendQuestTemplate }, - { "SpawnBones", &LuaPlayer::SpawnBones }, - { "RemovedInsignia", &LuaPlayer::RemovedInsignia }, - { "SendGuildInvite", &LuaPlayer::SendGuildInvite }, - { "Mute", &LuaPlayer::Mute }, - { "SummonPlayer", &LuaPlayer::SummonPlayer }, - { "SaveToDB", &LuaPlayer::SaveToDB }, - { "GroupInvite", &LuaPlayer::GroupInvite, METHOD_REG_WORLD }, // World state method only in multistate - { "GroupCreate", &LuaPlayer::GroupCreate, METHOD_REG_WORLD }, // World state method only in multistate - { "SendCinematicStart", &LuaPlayer::SendCinematicStart }, -#if defined(CLASSIC) - { "UpdateHonor", &LuaPlayer::UpdateHonor }, - { "ResetHonor", &LuaPlayer::ResetHonor }, - { "ClearHonorInfo", &LuaPlayer::ClearHonorInfo }, - { "RemoveArenaSpellCooldowns", nullptr, METHOD_REG_NONE }, -#else - { "UpdateHonor", nullptr, METHOD_REG_NONE }, - { "ResetHonor", nullptr, METHOD_REG_NONE }, - { "ClearHonorInfo", nullptr, METHOD_REG_NONE }, - { "RemoveArenaSpellCooldowns", &LuaPlayer::RemoveArenaSpellCooldowns }, -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - { "ResetPetTalents", &LuaPlayer::ResetPetTalents }, - { "ResetAchievements", &LuaPlayer::ResetAchievements }, - { "SendMovieStart", &LuaPlayer::SendMovieStart }, -#else - { "ResetPetTalents", nullptr, METHOD_REG_NONE }, - { "ResetAchievements", nullptr, METHOD_REG_NONE }, - { "SendMovieStart", nullptr, METHOD_REG_NONE }, -#endif -#if defined(TBC) || defined(WOTLK) - { "ModifyHonorPoints", &LuaPlayer::ModifyHonorPoints }, - { "ModifyArenaPoints", &LuaPlayer::ModifyArenaPoints }, -#else - { "ModifyHonorPoints", nullptr, METHOD_REG_NONE }, - { "ModifyArenaPoints", nullptr, METHOD_REG_NONE }, -#endif - - // Not implemented methods - { "GetChampioningFaction", nullptr, METHOD_REG_NONE }, // not implemented - { "GetRecruiterId", nullptr, METHOD_REG_NONE }, // not implemented - { "SetMovement", nullptr, METHOD_REG_NONE }, // not implemented - { "SetFFA", nullptr, METHOD_REG_NONE }, // not implemented - { "IsImmuneToEnvironmentalDamage", nullptr, METHOD_REG_NONE }, // not implemented - { "InRandomLfgDungeon", nullptr, METHOD_REG_NONE }, // not implemented - { "HasPendingBind", nullptr, METHOD_REG_NONE }, // not implemented - { "CanFlyInZone", nullptr, METHOD_REG_NONE }, // not implemented - { "IsNeverVisible", nullptr, METHOD_REG_NONE }, // not implemented, - { "IsUsingLfg", nullptr, METHOD_REG_NONE }, // not implemented, - { "HasReceivedQuestReward", nullptr, METHOD_REG_NONE }, // not implemented, - { "IsOutdoorPvPActive", nullptr, METHOD_REG_NONE }, // not implemented, - { "IsARecruiter", nullptr, METHOD_REG_NONE }, // not implemented, - { "RemovePet", nullptr, METHOD_REG_NONE }, // not implemented - { "SummonPet", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveActiveQuest", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveRewardedQuest", nullptr, METHOD_REG_NONE }, // not implemented - { "KilledPlayerCredit", nullptr, METHOD_REG_NONE }, // not implemented - { "KillGOCredit", nullptr, METHOD_REG_NONE }, // not implemented - { "GainSpellComboPoints", nullptr, METHOD_REG_NONE }, // not implemented - { "AddTalent", nullptr, METHOD_REG_NONE }, // not implemented - { "BindToInstance", nullptr, METHOD_REG_NONE }, // not implemented - { "SetAchievement", nullptr, METHOD_REG_NONE }, // not implemented - { "GetMailCount", nullptr, METHOD_REG_NONE }, // not implemented - { "GetXP", nullptr, METHOD_REG_NONE }, // not implemented - { "GetXPForNextLevel", nullptr, METHOD_REG_NONE }, // not implemented - { "CanCompleteRepeatableQuest", nullptr, METHOD_REG_NONE }, // not implemented - { "CanRewardQuest", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL } - }; -}; -#endif diff --git a/methods/Mangos/QuestMethods.h b/methods/Mangos/QuestMethods.h deleted file mode 100644 index 3fa05cae67..0000000000 --- a/methods/Mangos/QuestMethods.h +++ /dev/null @@ -1,201 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef QUESTMETHODS_H -#define QUESTMETHODS_H - -/*** - * Inherits all methods from: none - */ -namespace LuaQuest -{ - /** - * Returns 'true' if the [Quest] has the specified flag, false otherwise. - * Below flags are based off of 3.3.5a. Subject to change. - * - *
-     * enum QuestFlags
-     * {
-     *     // Flags used at server and sent to client
-     *     QUEST_FLAGS_NONE                    = 0x0,
-     *     QUEST_FLAGS_STAY_ALIVE              = 0x1,       // Not used currently
-     *     QUEST_FLAGS_PARTY_ACCEPT            = 0x2,       // Not used currently. If player in party, all players that can accept this quest will receive confirmation box to accept quest CMSG_QUEST_CONFIRM_ACCEPT/SMSG_QUEST_CONFIRM_ACCEPT
-     *     QUEST_FLAGS_EXPLORATION             = 0x4,       // Not used currently
-     *     QUEST_FLAGS_SHARABLE                = 0x8,       // Can be shared: Player::CanShareQuest()
-     *     QUEST_FLAGS_HAS_CONDITION           = 0x10,      // Not used currently
-     *     QUEST_FLAGS_HIDE_REWARD_POI         = 0x20,      // Not used currently: Unsure of content
-     *     QUEST_FLAGS_RAID                    = 0x40,      // Not used currently
-     *     QUEST_FLAGS_TBC                     = 0x80,      // Not used currently: Available if TBC expansion enabled only
-     *     QUEST_FLAGS_NO_MONEY_FROM_XP        = 0x100,     // Not used currently: Experience is not converted to gold at max level
-     *     QUEST_FLAGS_HIDDEN_REWARDS          = 0x200,     // Items and money rewarded only sent in SMSG_QUESTGIVER_OFFER_REWARD (not in SMSG_QUESTGIVER_QUEST_DETAILS or in client quest log(SMSG_QUEST_QUERY_RESPONSE))
-     *     QUEST_FLAGS_TRACKING                = 0x400,     // These quests are automatically rewarded on quest complete and they will never appear in quest log client side.
-     *     QUEST_FLAGS_DEPRECATE_REPUTATION    = 0x800,     // Not used currently
-     *     QUEST_FLAGS_DAILY                   = 0x1000,    // Used to know quest is Daily one
-     *     QUEST_FLAGS_FLAGS_PVP               = 0x2000,    // Having this quest in log forces PvP flag
-     *     QUEST_FLAGS_UNAVAILABLE             = 0x4000,    // Used on quests that are not generically available
-     *     QUEST_FLAGS_WEEKLY                  = 0x8000,
-     *     QUEST_FLAGS_AUTOCOMPLETE            = 0x10000,   // auto complete
-     *     QUEST_FLAGS_DISPLAY_ITEM_IN_TRACKER = 0x20000,   // Displays usable item in quest tracker
-     *     QUEST_FLAGS_OBJ_TEXT                = 0x40000,   // use Objective text as Complete text
-     *     QUEST_FLAGS_AUTO_ACCEPT             = 0x80000,   // The client recognizes this flag as auto-accept. However, NONE of the current quests (3.3.5a) have this flag. Maybe blizz used to use it, or will use it in the future.
-     *
-     *     // ... 4.x added flags up to 0x80000000 - all unknown for now
-     * };
-     * 
- * - * @param [QuestFlags] flag : all available flags can be seen above - * @return bool hasFlag - */ - int HasFlag(Eluna* E, Quest* quest) - { - uint32 flag = E->CHECKVAL(2); - - E->Push(quest->HasQuestFlag((QuestFlags)flag)); - return 1; - } - -#ifndef CLASSIC - /** - * Returns 'true' if the [Quest] is a daily quest, false otherwise. - * - * @return bool isDaily - */ - int IsDaily(Eluna* E, Quest* quest) - { - E->Push(quest->IsDaily()); - return 1; - } -#endif - - /** - * Returns 'true' if the [Quest] is repeatable, false otherwise. - * - * @return bool isRepeatable - */ - int IsRepeatable(Eluna* E, Quest* quest) - { - E->Push(quest->IsRepeatable()); - return 1; - } - - /** - * Returns entry ID of the [Quest]. - * - * @return uint32 entryId - */ - int GetId(Eluna* E, Quest* quest) - { - E->Push(quest->GetQuestId()); - return 1; - } - - /** - * Returns the [Quest]'s level. - * - * @return uint32 level - */ - int GetLevel(Eluna* E, Quest* quest) - { - E->Push(quest->GetQuestLevel()); - return 1; - } - - /** - * Returns the minimum level required to pick up the [Quest]. - * - * @return uint32 minLevel - */ - int GetMinLevel(Eluna* E, Quest* quest) - { - E->Push(quest->GetMinLevel()); - return 1; - } - - /** - * Returns the next [Quest] entry ID. - * - * @return int32 entryId - */ - int GetNextQuestId(Eluna* E, Quest* quest) - { - E->Push(quest->GetNextQuestId()); - return 1; - } - - /** - * Returns the previous [Quest] entry ID. - * - * @return int32 entryId - */ - int GetPrevQuestId(Eluna* E, Quest* quest) - { - E->Push(quest->GetPrevQuestId()); - return 1; - } - - /** - * Returns the next [Quest] entry ID in the specific [Quest] chain. - * - * @return int32 entryId - */ - int GetNextQuestInChain(Eluna* E, Quest* quest) - { - E->Push(quest->GetNextQuestInChain()); - return 1; - } - - /** - * Returns the [Quest]'s flags. - * - * @return [QuestFlags] flags - */ - int GetFlags(Eluna* E, Quest* quest) - { - E->Push(quest->GetQuestFlags()); - return 1; - } - - /** - * Returns the [Quest]'s type. - * - * TODO: Document types available. - * - * @return uint32 type - */ - int GetType(Eluna* E, Quest* quest) - { - E->Push(quest->GetType()); - return 1; - } - - ElunaRegister QuestMethods[] = - { - // Getters - { "GetId", &LuaQuest::GetId }, - { "GetLevel", &LuaQuest::GetLevel }, - { "GetMinLevel", &LuaQuest::GetMinLevel }, - { "GetNextQuestId", &LuaQuest::GetNextQuestId }, - { "GetPrevQuestId", &LuaQuest::GetPrevQuestId }, - { "GetNextQuestInChain", &LuaQuest::GetNextQuestInChain }, - { "GetFlags", &LuaQuest::GetFlags }, - { "GetType", &LuaQuest::GetType }, - - // Boolean - { "HasFlag", &LuaQuest::HasFlag }, - { "IsRepeatable", &LuaQuest::IsRepeatable }, -#ifndef CLASSIC - { "IsDaily", &LuaQuest::IsDaily }, -#else - { "IsDaily", nullptr, METHOD_REG_NONE }, -#endif - - // Not implemented methods - { "GetMaxLevel", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/SpellMethods.h b/methods/Mangos/SpellMethods.h deleted file mode 100644 index d6c1983d9a..0000000000 --- a/methods/Mangos/SpellMethods.h +++ /dev/null @@ -1,196 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef SPELLMETHODS_H -#define SPELLMETHODS_H - -/*** - * An instance of a spell, created when the spell is cast by a [Unit]. - * - * Inherits all methods from: none - */ -namespace LuaSpell -{ - /** - * Returns `true` if the [Spell] is automatically repeating, `false` otherwise. - * - * @return bool isAutoRepeating - */ - int IsAutoRepeat(Eluna* E, Spell* spell) - { - E->Push(spell->IsAutoRepeat()); - return 1; - } - - /** - * Returns the [Unit] that casted the [Spell]. - * - * @return [Unit] caster - */ - int GetCaster(Eluna* E, Spell* spell) - { - E->Push(spell->GetCaster()); - return 1; - } - - /** - * Returns the cast time of the [Spell]. - * - * @return int32 castTime - */ - int GetCastTime(Eluna* E, Spell* spell) - { - E->Push(spell->GetCastTime()); - return 1; - } - - /** - * Returns the entry ID of the [Spell]. - * - * @return uint32 entryId - */ - int GetEntry(Eluna* E, Spell* spell) - { - E->Push(spell->m_spellInfo->Id); - return 1; - } - - /** - * Returns the power cost of the [Spell]. - * - * @return uint32 powerCost - */ - int GetPowerCost(Eluna* E, Spell* spell) - { - E->Push(spell->GetPowerCost()); - return 1; - } - - /** - * Returns the spell duration of the [Spell]. - * - * @return int32 duration - */ - int GetDuration(Eluna* E, Spell* spell) - { - E->Push(GetSpellDuration(spell->m_spellInfo)); - return 1; - } - - /** - * Returns the target destination coordinates of the [Spell]. - * - * @return float x : x coordinate of the [Spell] - * @return float y : y coordinate of the [Spell] - * @return float z : z coordinate of the [Spell] - */ - int GetTargetDest(Eluna* E, Spell* spell) - { - if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)) - return 3; - float x, y, z; - spell->m_targets.getDestination(x, y, z); - - E->Push(x); - E->Push(y); - E->Push(z); - return 3; - } - - /** - * Returns the target [Object] of the [Spell]. - * - * The target can be any of the following [Object] types: - * - [Player] - * - [Creature] - * - [GameObject] - * - [Item] - * - [Corpse] - * - * @return [Object] target - */ - int GetTarget(Eluna* E, Spell* spell) - { - if (GameObject* target = spell->m_targets.getGOTarget()) - E->Push(target); - else if (Item* target = spell->m_targets.getItemTarget()) - E->Push(target); - else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid())) - E->Push(target); - else if (Unit* target = spell->m_targets.getUnitTarget()) - E->Push(target); - - return 1; - } - - /** - * Sets the [Spell] to automatically repeat. - * - * @param bool repeat : set variable to 'true' for spell to automatically repeat - */ - int SetAutoRepeat(Eluna* E, Spell* spell) - { - bool repeat = E->CHECKVAL(2); - spell->SetAutoRepeat(repeat); - return 0; - } - - /** - * Casts the [Spell]. - * - * @param bool skipCheck = false : skips initial checks to see if the [Spell] can be casted or not, this is optional - */ - int Cast(Eluna* E, Spell* spell) - { - bool skipCheck = E->CHECKVAL(2, false); - spell->cast(skipCheck); - return 0; - } - - /** - * Cancels the [Spell]. - */ - int Cancel(Eluna* /*E*/, Spell* spell) - { - spell->cancel(); - return 0; - } - - /** - * Finishes the [Spell]. - */ - int Finish(Eluna* /*E*/, Spell* spell) - { - spell->finish(); - return 0; - } - - ElunaRegister SpellMethods[] = - { - // Getters - { "GetCaster", &LuaSpell::GetCaster }, - { "GetCastTime", &LuaSpell::GetCastTime }, - { "GetEntry", &LuaSpell::GetEntry }, - { "GetDuration", &LuaSpell::GetDuration }, - { "GetPowerCost", &LuaSpell::GetPowerCost }, - { "GetTargetDest", &LuaSpell::GetTargetDest }, - { "GetTarget", &LuaSpell::GetTarget }, - - // Setters - { "SetAutoRepeat", &LuaSpell::SetAutoRepeat }, - - // Boolean - { "IsAutoRepeat", &LuaSpell::IsAutoRepeat }, - - // Other - { "Cancel", &LuaSpell::Cancel }, - { "Cast", &LuaSpell::Cast }, - { "Finish", &LuaSpell::Finish }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/UnitMethods.h b/methods/Mangos/UnitMethods.h deleted file mode 100644 index 2485d17bb7..0000000000 --- a/methods/Mangos/UnitMethods.h +++ /dev/null @@ -1,2624 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef UNITMETHODS_H -#define UNITMETHODS_H - -/*** - * Inherits all methods from: [Object], [WorldObject] - */ -namespace LuaUnit -{ - /** - * The [Unit] tries to attack a given target - * - * @param [Unit] who : [Unit] to attack - * @param bool meleeAttack = false: attack with melee or not - * @return didAttack : if the [Unit] did not attack - */ - int Attack(Eluna* E, Unit* unit) - { - Unit* who = E->CHECKOBJ(2); - bool meleeAttack = E->CHECKVAL(3, false); - - E->Push(unit->Attack(who, meleeAttack)); - return 1; - } - - /** - * The [Unit] stops attacking its target - * - * @return bool isAttacking : if the [Unit] wasn't attacking already - */ - int AttackStop(Eluna* E, Unit* unit) - { - E->Push(unit->AttackStop()); - return 1; - } - - /** - * Returns true if the [Unit] is standing. - * - * @return bool isStanding - */ - int IsStandState(Eluna* E, Unit* unit) - { - E->Push(unit->IsStandState()); - return 1; - } - - /** - * Returns true if the [Unit] is mounted. - * - * @return bool isMounted - */ - int IsMounted(Eluna* E, Unit* unit) - { - E->Push(unit->IsMounted()); - return 1; - } - - /** - * Returns true if the [Unit] is rooted. - * - * @return bool isRooted - */ - int IsRooted(Eluna* E, Unit* unit) - { - E->Push(unit->IsInRoots() || unit->IsRooted()); - return 1; - } - - /** - * Returns true if the [Unit] has full health. - * - * @return bool hasFullHealth - */ - int IsFullHealth(Eluna* E, Unit* unit) - { - E->Push(unit->IsFullHealth()); - return 1; - } - - /** - * Returns true if the [Unit] is in an accessible place for the given [Creature]. - * - * @param [WorldObject] obj - * @param float radius - * @return bool isAccessible - */ - int IsInAccessiblePlaceFor(Eluna* E, Unit* unit) - { - Creature* creature = E->CHECKOBJ(2); - - E->Push(unit->isInAccessablePlaceFor(creature)); - return 1; - } - - /** - * Returns true if the [Unit] an auctioneer. - * - * @return bool isAuctioneer - */ - int IsAuctioneer(Eluna* E, Unit* unit) - { - E->Push(unit->isAuctioner()); - return 1; - } - - /** - * Returns true if the [Unit] a guild master. - * - * @return bool isGuildMaster - */ - int IsGuildMaster(Eluna* E, Unit* unit) - { - E->Push(unit->IsGuildMaster()); - return 1; - } - - /** - * Returns true if the [Unit] an innkeeper. - * - * @return bool isInnkeeper - */ - int IsInnkeeper(Eluna* E, Unit* unit) - { - E->Push(unit->IsInnkeeper()); - return 1; - } - - /** - * Returns true if the [Unit] a trainer. - * - * @return bool isTrainer - */ - int IsTrainer(Eluna* E, Unit* unit) - { - E->Push(unit->IsTrainer()); - return 1; - } - - /** - * Returns true if the [Unit] is able to show a gossip window. - * - * @return bool hasGossip - */ - int IsGossip(Eluna* E, Unit* unit) - { - E->Push(unit->IsGossip()); - return 1; - } - - /** - * Returns true if the [Unit] is a taxi master. - * - * @return bool isTaxi - */ - int IsTaxi(Eluna* E, Unit* unit) - { - E->Push(unit->IsTaxi()); - return 1; - } - - /** - * Returns true if the [Unit] is a spirit healer. - * - * @return bool isSpiritHealer - */ - int IsSpiritHealer(Eluna* E, Unit* unit) - { - E->Push(unit->IsSpiritHealer()); - return 1; - } - - /** - * Returns true if the [Unit] is a spirit guide. - * - * @return bool isSpiritGuide - */ - int IsSpiritGuide(Eluna* E, Unit* unit) - { - E->Push(unit->IsSpiritGuide()); - return 1; - } - - /** - * Returns true if the [Unit] is a tabard designer. - * - * @return bool isTabardDesigner - */ - int IsTabardDesigner(Eluna* E, Unit* unit) - { - E->Push(unit->IsTabardDesigner()); - return 1; - } - - /** - * Returns true if the [Unit] provides services like vendor, training and auction. - * - * @return bool isTabardDesigner - */ - int IsServiceProvider(Eluna* E, Unit* unit) - { - E->Push(unit->IsServiceProvider()); - return 1; - } - - /** - * Returns true if the [Unit] is a spirit guide or spirit healer. - * - * @return bool isSpiritService - */ - int IsSpiritService(Eluna* E, Unit* unit) - { - E->Push(unit->IsSpiritService()); - return 1; - } - - /** - * Returns true if the [Unit] is alive. - * - * @return bool isAlive - */ - int IsAlive(Eluna* E, Unit* unit) - { - E->Push(unit->IsAlive()); - return 1; - } - - /** - * Returns true if the [Unit] is dead. - * - * @return bool isDead - */ - int IsDead(Eluna* E, Unit* unit) - { - E->Push(unit->IsDead()); - return 1; - } - - /** - * Returns true if the [Unit] is dying. - * - * @return bool isDying - */ - int IsDying(Eluna* E, Unit* unit) - { - E->Push(unit->IsDying()); - return 1; - } - - /** - * Returns true if the [Unit] is a banker. - * - * @return bool isBanker - */ - int IsBanker(Eluna* E, Unit* unit) - { - E->Push(unit->IsBanker()); - return 1; - } - - /** - * Returns true if the [Unit] is a vendor. - * - * @return bool isVendor - */ - int IsVendor(Eluna* E, Unit* unit) - { - E->Push(unit->IsVendor()); - return 1; - } - - /** - * Returns true if the [Unit] is a battle master. - * - * @return bool isBattleMaster - */ - int IsBattleMaster(Eluna* E, Unit* unit) - { - E->Push(unit->IsBattleMaster()); - return 1; - } - - /** - * Returns true if the [Unit] is a charmed. - * - * @return bool isCharmed - */ - int IsCharmed(Eluna* E, Unit* unit) - { - E->Push(unit->IsCharmed()); - return 1; - } - - /** - * Returns true if the [Unit] is an armorer and can repair equipment. - * - * @return bool isArmorer - */ - int IsArmorer(Eluna* E, Unit* unit) - { - E->Push(unit->IsArmorer()); - return 1; - } - - /** - * Returns true if the [Unit] is attacking a player. - * - * @return bool isAttackingPlayer - */ - int IsAttackingPlayer(Eluna* E, Unit* unit) - { - E->Push(unit->isAttackingPlayer()); - return 1; - } - - /** - * Returns true if the [Unit] flagged for PvP. - * - * @return bool isPvP - */ - int IsPvPFlagged(Eluna* E, Unit* unit) - { - E->Push(unit->IsPvP()); - return 1; - } - -#ifndef CLASSIC - /** - * Returns true if the [Unit] is on a [Vehicle]. - * - * @return bool isOnVehicle - */ - int IsOnVehicle(Eluna* E, Unit* unit) - { - E->Push(unit->IsBoarded()); - return 1; - } -#endif - - /** - * Returns true if the [Unit] is in combat. - * - * @return bool inCombat - */ - int IsInCombat(Eluna* E, Unit* unit) - { - E->Push(unit->IsInCombat()); - return 1; - } - - /** - * Returns true if the [Unit] is under water. - * - * @return bool underWater - */ - int IsUnderWater(Eluna* E, Unit* unit) - { - E->Push(unit->IsUnderWater()); - return 1; - } - - /** - * Returns true if the [Unit] is in water. - * - * @return bool inWater - */ - int IsInWater(Eluna* E, Unit* unit) - { - E->Push(unit->IsInWater()); - return 1; - } - - /** - * Returns true if the [Unit] is not moving. - * - * @return bool notMoving - */ - int IsStopped(Eluna* E, Unit* unit) - { - E->Push(unit->IsStopped()); - return 1; - } - - /** - * Returns true if the [Unit] is a quest giver. - * - * @return bool questGiver - */ - int IsQuestGiver(Eluna* E, Unit* unit) - { - E->Push(unit->IsQuestGiver()); - return 1; - } - - /** - * Returns true if the [Unit]'s health is below the given percentage. - * - * @param int32 healthpct : percentage in integer from - * @return bool isBelow - */ - int HealthBelowPct(Eluna* E, Unit* unit) - { - E->Push(unit->HealthBelowPct(E->CHECKVAL(2))); - return 1; - } - - /** - * Returns true if the [Unit]'s health is above the given percentage. - * - * @param int32 healthpct : percentage in integer from - * @return bool isAbove - */ - int HealthAbovePct(Eluna* E, Unit* unit) - { - E->Push(unit->HealthAbovePct(E->CHECKVAL(2))); - return 1; - } - - /** - * Returns true if the [Unit] has an aura from the given spell entry. - * - * @param uint32 spell : entry of the aura spell - * @return bool hasAura - */ - int HasAura(Eluna* E, Unit* unit) - { - uint32 spell = E->CHECKVAL(2); - - E->Push(unit->HasAura(spell)); - return 1; - } - - /** - * Returns true if the [Unit] is casting a spell - * - * @return bool isCasting - */ - int IsCasting(Eluna* E, Unit* unit) - { - E->Push(unit->IsNonMeleeSpellCasted(false)); - return 1; - } - - /** - * Returns true if the [Unit] has the given unit state. - * - * @param [UnitState] state : an unit state - * @return bool hasState - */ - int HasUnitState(Eluna* E, Unit* unit) - { - uint32 state = E->CHECKVAL(2); - - E->Push(unit->hasUnitState(state)); - return 1; - } - - /** - * Returns the [Unit]'s owner. - * - * @return [Unit] owner - */ - int GetOwner(Eluna* E, Unit* unit) - { - E->Push(unit->GetOwner()); - return 1; - } - - /** - * Returns the [Unit]'s owner's GUID. - * - * @return ObjectGuid ownerGUID - */ - int GetOwnerGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetOwnerGuid()); - return 1; - } - - /** - * Returns the [Unit]'s mount's modelID. - * - * @return uint32 mountId : displayId of the mount - */ - int GetMountId(Eluna* E, Unit* unit) - { - E->Push(unit->GetMountID()); - return 1; - } - - /** - * Returns the [Unit]'s creator's GUID. - * - * @return ObjectGuid creatorGUID - */ - int GetCreatorGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetCreatorGuid()); - return 1; - } - - /** - * Returns the [Unit]'s charmer's GUID. - * - * @return ObjectGuid charmerGUID - */ - int GetCharmerGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetCharmerGuid()); - return 1; - } - - /** - * Returns the GUID of the [Unit]'s charmed entity. - * - * @return ObjectGuid charmedGUID - */ - int GetCharmGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetCharmGuid()); - return 1; - } - - /** - * Returns the GUID of the [Unit]'s pet. - * - * @return ObjectGuid petGUID - */ - int GetPetGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetPetGuid()); - return 1; - } - - /** - * Returns the GUID of the [Unit]'s charmer or owner. - * - * @return ObjectGuid controllerGUID - */ - int GetControllerGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetCharmerOrOwnerGuid()); - return 1; - } - - /** - * Returns the GUID of the [Unit]'s charmer or owner or its own GUID. - * - * @return ObjectGuid controllerGUID - */ - int GetControllerGUIDS(Eluna* E, Unit* unit) - { - E->Push(unit->GetCharmerOrOwnerOrOwnGuid()); - return 1; - } - - /** - * Returns [Unit]'s specified stat - * - * @param uint32 statType - * @return float stat - */ - int GetStat(Eluna* E, Unit* unit) - { - uint32 stat = E->CHECKVAL(2); - - if (stat >= MAX_STATS) - return 1; - - E->Push(unit->GetStat((Stats)stat)); - return 1; - } - - /** - * Returns the [Unit]'s base spell power - * - * @param uint32 spellSchool - * @return uint32 spellPower - */ - int GetBaseSpellPower(Eluna* E, Unit* unit) - { - uint32 spellschool = E->CHECKVAL(2); - - if (spellschool >= MAX_SPELL_SCHOOL) - return 1; - - E->Push(unit->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + spellschool)); - return 1; - } - - /** - * Returns the [Unit]'s current victim target or nil. - * - * @return [Unit] victim - */ - int GetVictim(Eluna* E, Unit* unit) - { - E->Push(unit->getVictim()); - return 1; - } - - /** - * Returns the currently casted [Spell] of given type or nil. - * - *
-     * enum CurrentSpellTypes
-     * {
-     *     CURRENT_MELEE_SPELL             = 0,
-     *     CURRENT_GENERIC_SPELL           = 1,
-     *     CURRENT_CHANNELED_SPELL         = 2,
-     *     CURRENT_AUTOREPEAT_SPELL        = 3
-     * };
-     * 
- * - * @param [CurrentSpellTypes] spellType - * @return [Spell] castedSpell - */ - int GetCurrentSpell(Eluna* E, Unit* unit) - { - uint32 type = E->CHECKVAL(2); - if (type >= CURRENT_MAX_SPELL) - return luaL_argerror(E->L, 2, "valid CurrentSpellTypes expected"); - - E->Push(unit->GetCurrentSpell(type)); - return 1; - } - - /** - * Returns the [Unit]'s current stand state. - * - * @return uint8 standState - */ - int GetStandState(Eluna* E, Unit* unit) - { - E->Push(unit->getStandState()); - return 1; - } - - /** - * Returns the [Unit]'s current display ID. - * - * @return uint32 displayId - */ - int GetDisplayId(Eluna* E, Unit* unit) - { - E->Push(unit->GetDisplayId()); - return 1; - } - - /** - * Returns the [Unit]'s native/original display ID. - * - * @return uint32 displayId - */ - int GetNativeDisplayId(Eluna* E, Unit* unit) - { - E->Push(unit->GetNativeDisplayId()); - return 1; - } - - /** - * Returns the [Unit]'s level. - * - * @return uint8 level - */ - int GetLevel(Eluna* E, Unit* unit) - { - E->Push(unit->getLevel()); - return 1; - } - - /** - * Returns the [Unit]'s health amount. - * - * @return uint32 healthAmount - */ - int GetHealth(Eluna* E, Unit* unit) - { - E->Push(unit->GetHealth()); - return 1; - } - - Powers PowerSelectorHelper(Eluna* E, Unit* unit, int powerType = -1) - { - if (powerType == -1) - return unit->GetPowerType(); - - if (powerType < 0 || powerType >= int(MAX_POWERS)) - luaL_argerror(E->L, 2, "valid Powers expected"); - - return (Powers)powerType; - } - - /** - * Returns the [Unit]'s power amount for given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - * @return uint32 powerAmount - */ - int GetPower(Eluna* E, Unit* unit) - { - int type = E->CHECKVAL(2, -1); - Powers power = PowerSelectorHelper(E, unit, type); - - E->Push(unit->GetPower(power)); - return 1; - } - - /** - * Returns the [Unit]'s max power amount for given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - * @return uint32 maxPowerAmount - */ - int GetMaxPower(Eluna* E, Unit* unit) - { - int type = E->CHECKVAL(2, -1); - Powers power = PowerSelectorHelper(E, unit, type); - - E->Push(unit->GetMaxPower(power)); - return 1; - } - - /** - * Returns the [Unit]'s power percent for given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - * @return float powerPct - */ - int GetPowerPct(Eluna* E, Unit* unit) - { - int type = E->CHECKVAL(2, -1); - - Powers power = PowerSelectorHelper(E, unit, type); - float percent = ((float)unit->GetPower(power) / (float)unit->GetMaxPower(power)) * 100.0f; - - E->Push(percent); - return 1; - } - - /** - * Returns the [Unit]'s current power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @return [Powers] powerType - */ - int GetPowerType(Eluna* E, Unit* unit) - { - E->Push(unit->GetPowerType()); - return 1; - } - - /** - * Returns the [Unit]'s max health. - * - * @return uint32 maxHealth - */ - int GetMaxHealth(Eluna* E, Unit* unit) - { - E->Push(unit->GetMaxHealth()); - return 1; - } - - /** - * Returns the [Unit]'s health percent. - * - * @return float healthPct - */ - int GetHealthPct(Eluna* E, Unit* unit) - { - E->Push(unit->GetHealthPercent()); - return 1; - } - - /** - * Returns the [Unit]'s gender. - * - * @return uint8 gender : 0 for male, 1 for female and 2 for none - */ - int GetGender(Eluna* E, Unit* unit) - { - E->Push(unit->getGender()); - return 1; - } - - /** - * Returns the [Unit]'s race ID. - * - * @return [Races] race - */ - int GetRace(Eluna* E, Unit* unit) - { - E->Push(unit->getRace()); - return 1; - } - - /** - * Returns the [Unit]'s class ID. - * - * @return [Classes] class - */ - int GetClass(Eluna* E, Unit* unit) - { - E->Push(unit->getClass()); - return 1; - } - - /** - * Returns the race mask - * - * @return uint32 racemask - */ - int GetRaceMask(Eluna* E, Unit* unit) - { - E->Push(unit->getRaceMask()); - return 1; - } - - /** - * Returns the class mask - * - * @return uint32 classmask - */ - int GetClassMask(Eluna* E, Unit* unit) - { - E->Push(unit->getClassMask()); - return 1; - } - - /** - * Returns the [Unit]'s creature type ID (enumerated in CreatureType.dbc). - * - *
-     * enum CreatureType
-     * {
-     *     CREATURE_TYPE_BEAST            = 1,
-     *     CREATURE_TYPE_DRAGONKIN        = 2,
-     *     CREATURE_TYPE_DEMON            = 3,
-     *     CREATURE_TYPE_ELEMENTAL        = 4,
-     *     CREATURE_TYPE_GIANT            = 5,
-     *     CREATURE_TYPE_UNDEAD           = 6,
-     *     CREATURE_TYPE_HUMANOID         = 7,
-     *     CREATURE_TYPE_CRITTER          = 8,
-     *     CREATURE_TYPE_MECHANICAL       = 9,
-     *     CREATURE_TYPE_NOT_SPECIFIED    = 10,
-     *     CREATURE_TYPE_TOTEM            = 11,
-     *     CREATURE_TYPE_NON_COMBAT_PET   = 12,     // This and below is TBC+
-     *     CREATURE_TYPE_GAS_CLOUD        = 13
-     * };
-     * 
- * - * @return [CreatureType] creatureType - */ - int GetCreatureType(Eluna* E, Unit* unit) - { - E->Push(unit->GetCreatureType()); - return 1; - } - - /** - * Returns the [Unit]'s class' name in given or default locale or nil. - * - *
-     * enum LocaleConstant
-     * {
-     *     LOCALE_enUS = 0,
-     *     LOCALE_koKR = 1,
-     *     LOCALE_frFR = 2,
-     *     LOCALE_deDE = 3,
-     *     LOCALE_zhCN = 4,
-     *     LOCALE_zhTW = 5,
-     *     LOCALE_esES = 6,
-     *     LOCALE_esMX = 7,
-     *     LOCALE_ruRU = 8
-     * };
-     * 
- * - * @param [LocaleConstant] locale = DEFAULT_LOCALE - * @return string className : class name or nil - */ - int GetClassAsString(Eluna* E, Unit* unit) - { - uint8 locale = E->CHECKVAL(2, DEFAULT_LOCALE); - if (locale >= TOTAL_LOCALES) - return luaL_argerror(E->L, 2, "valid LocaleConstant expected"); - - const ChrClassesEntry* entry = sChrClassesStore.LookupEntry(unit->getClass()); - if (!entry) - return 1; - - E->Push(entry->name[locale]); - return 1; - } - - /** - * Returns the [Unit]'s race's name in given or default locale or nil. - * - *
-     * enum LocaleConstant
-     * {
-     *     LOCALE_enUS = 0,
-     *     LOCALE_koKR = 1,
-     *     LOCALE_frFR = 2,
-     *     LOCALE_deDE = 3,
-     *     LOCALE_zhCN = 4,
-     *     LOCALE_zhTW = 5,
-     *     LOCALE_esES = 6,
-     *     LOCALE_esMX = 7,
-     *     LOCALE_ruRU = 8
-     * };
-     * 
- * - * @param [LocaleConstant] locale = DEFAULT_LOCALE : locale to return the race name in - * @return string raceName : race name or nil - */ - int GetRaceAsString(Eluna* E, Unit* unit) - { - uint8 locale = E->CHECKVAL(2, DEFAULT_LOCALE); - if (locale >= TOTAL_LOCALES) - return luaL_argerror(E->L, 2, "valid LocaleConstant expected"); - - const ChrRacesEntry* entry = sChrRacesStore.LookupEntry(unit->getRace()); - if (!entry) - return 1; - - E->Push(entry->name[locale]); - return 1; - } - - /** - * Returns the [Unit]'s faction ID. - * - * @return uint32 faction - */ - int GetFaction(Eluna* E, Unit* unit) - { - E->Push(unit->getFaction()); - return 1; - } - - /** - * Returns the [Aura] of the given spell entry on the [Unit] or nil. - * - * @param uint32 spellID : entry of the aura spell - * @return [Aura] aura : aura object or nil - */ - int GetAura(Eluna* E, Unit* unit) - { - uint32 spellID = E->CHECKVAL(2); - - E->Push(unit->GetAura(spellID, EFFECT_INDEX_0)); - return 1; - } - - /** - * Returns a table containing friendly [Unit]'s within given range of the [Unit]. - * - * @param float range = 533.333 : search radius - * @return table friendyUnits : table filled with friendly units - */ - int GetFriendlyUnitsInRange(Eluna* E, Unit* unit) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - - std::list list; - MaNGOS::AnyFriendlyUnitInObjectRangeCheck checker(unit, range); - MaNGOS::UnitListSearcher searcher(list, checker); - Cell::VisitGridObjects(unit, searcher, range); - - ElunaUtil::ObjectGUIDCheck guidCheck(unit->GET_GUID()); - list.remove_if(guidCheck); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns a table containing unfriendly [Unit]'s within given range of the [Unit]. - * - * @param float range = 533.333 : search radius - * @return table unfriendyUnits : table filled with unfriendly units - */ - int GetUnfriendlyUnitsInRange(Eluna* E, Unit* unit) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - - std::list list; - MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck checker(unit, range); - MaNGOS::UnitListSearcher searcher(list, checker); - Cell::VisitGridObjects(unit, searcher, range); - - ElunaUtil::ObjectGUIDCheck guidCheck(unit->GET_GUID()); - list.remove_if(guidCheck); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns [Unit]'s [Vehicle] methods - * - * @return [Vehicle] vehicle - */ - int GetVehicleKit(Eluna* E, Unit* unit) - { - E->Push(unit->GetVehicleInfo()); - return 1; - } - - /* - int GetVehicle(Eluna* E, Unit* unit) - { - E->Push(unit->GetVehicle()); - return 1; - } - */ - - /** - * Returns the Critter Guid - * - * @return ObjectGuid critterGuid - */ - int GetCritterGUID(Eluna* E, Unit* unit) - { - E->Push(unit->GetCritterGuid()); - return 1; - } -#endif - - /** - * Returns the [Unit]'s speed of given [UnitMoveType]. - * - *
-     * enum UnitMoveType
-     * {
-     *     MOVE_WALK           = 0,
-     *     MOVE_RUN            = 1,
-     *     MOVE_RUN_BACK       = 2,
-     *     MOVE_SWIM           = 3,
-     *     MOVE_SWIM_BACK      = 4,
-     *     MOVE_TURN_RATE      = 5,
-     *     MOVE_FLIGHT         = 6,
-     *     MOVE_FLIGHT_BACK    = 7,
-     *     MOVE_PITCH_RATE     = 8
-     * };
-     * 
- * - * @param [UnitMoveType] type - * @return float speed - */ - int GetSpeed(Eluna* E, Unit* unit) - { - uint32 type = E->CHECKVAL(2); - if (type >= MAX_MOVE_TYPE) - return luaL_argerror(E->L, 2, "valid UnitMoveType expected"); - - E->Push(unit->GetSpeedRate((UnitMoveType)type)); - return 1; - } - - /** - * Returns the current movement type for this [Unit]. - * - *
-     * enum MovementGeneratorType
-     * {
-     *     IDLE_MOTION_TYPE                = 0,
-     *     RANDOM_MOTION_TYPE              = 1,
-     *     WAYPOINT_MOTION_TYPE            = 2,
-     *     MAX_DB_MOTION_TYPE              = 3,
-     *     ANIMAL_RANDOM_MOTION_TYPE       = 3, // TC
-     *
-     *     CONFUSED_MOTION_TYPE            = 4,
-     *     CHASE_MOTION_TYPE               = 5,
-     *     HOME_MOTION_TYPE                = 6,
-     *     FLIGHT_MOTION_TYPE              = 7,
-     *     POINT_MOTION_TYPE               = 8,
-     *     FLEEING_MOTION_TYPE             = 9,
-     *     DISTRACT_MOTION_TYPE            = 10,
-     *     ASSISTANCE_MOTION_TYPE          = 11,
-     *     ASSISTANCE_DISTRACT_MOTION_TYPE = 12,
-     *     TIMED_FLEEING_MOTION_TYPE       = 13,
-     *     FOLLOW_MOTION_TYPE              = 14,
-     *     EFFECT_MOTION_TYPE              = 15, // mangos
-     *     ROTATE_MOTION_TYPE              = 15, // TC
-     *     EFFECT_MOTION_TYPE              = 16, // TC
-     *     NULL_MOTION_TYPE                = 17, // TC
-     * };
-     * 
- * - * @return [MovementGeneratorType] movementType - */ - int GetMovementType(Eluna* E, Unit* unit) - { - E->Push(unit->GetMotionMaster()->GetCurrentMovementGeneratorType()); - return 1; - } - - /** - * Sets the [Unit]'s owner GUID to given GUID. - * - * @param ObjectGuid guid : new owner guid - */ - int SetOwnerGUID(Eluna* E, Unit* unit) - { - ObjectGuid guid = E->CHECKVAL(2); - - unit->SetOwnerGuid(guid); - return 0; - } - - /** - * Sets the [Unit]'s PvP on or off. - * - * @param bool apply = true : true if set on, false if off - */ - int SetPvP(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - unit->SetPvP(apply); - return 0; - } - - /** - * Sets the [Unit]'s sheath state. - * - * enum SheathState - * { - * SHEATH_STATE_UNARMED = 0, // non prepared weapon - * SHEATH_STATE_MELEE = 1, // prepared melee weapon - * SHEATH_STATE_RANGED = 2 // prepared ranged weapon - * }; - * - * @param [SheathState] sheathState : valid SheathState - */ - int SetSheath(Eluna* E, Unit* unit) - { - uint32 sheathed = E->CHECKVAL(2); - if (sheathed >= MAX_SHEATH_STATE) - return luaL_argerror(E->L, 2, "valid SheathState expected"); - - unit->SetSheath((SheathState)sheathed); - return 0; - } - - /** - * Sets the [Unit]'s name internally. - * - * @param string name : new name - */ - int SetName(Eluna* E, Unit* unit) - { - const char* name = E->CHECKVAL(2); - if (std::string(name).length() > 0) - unit->SetName(name); - return 0; - } - - /** - * Sets the [Unit]'s speed of given [UnitMoveType] to given rate. - * If forced, packets sent to clients forcing the visual change. - * - *
-     * enum UnitMoveType
-     * {
-     *     MOVE_WALK           = 0,
-     *     MOVE_RUN            = 1,
-     *     MOVE_RUN_BACK       = 2,
-     *     MOVE_SWIM           = 3,
-     *     MOVE_SWIM_BACK      = 4,
-     *     MOVE_TURN_RATE      = 5,
-     *     MOVE_FLIGHT         = 6,
-     *     MOVE_FLIGHT_BACK    = 7,
-     *     MOVE_PITCH_RATE     = 8
-     * };
-     * 
- * - * @param [UnitMoveType] type - * @param float rate - * @param bool forced = false - */ - int SetSpeed(Eluna* E, Unit* unit) - { - uint32 type = E->CHECKVAL(2); - float rate = E->CHECKVAL(3); - bool forced = E->CHECKVAL(4, false); - (void)forced; // ensure that the variable is referenced in order to pass compiler checks - if (type >= MAX_MOVE_TYPE) - return luaL_argerror(E->L, 2, "valid UnitMoveType expected"); - - unit->SetSpeedRate((UnitMoveType)type, rate, forced); - return 0; - } - - /** - * Sets the [Unit]'s faction. - * - * @param uint32 faction : new faction ID - */ - int SetFaction(Eluna* E, Unit* unit) - { - uint32 factionId = E->CHECKVAL(2); - - unit->setFaction(factionId); - return 0; - } - - /** - * Sets the [Unit]'s level. - * - * @param uint8 level : new level - */ - int SetLevel(Eluna* E, Unit* unit) - { - uint8 newlevel = E->CHECKVAL(2); - - if (newlevel < 1) - return luaL_argerror(E->L, 2, "level cannot be below 1"); - - if (Player* player = unit->ToPlayer()) - { - player->GiveLevel(newlevel); - player->InitTalentForLevel(); - player->SetUInt32Value(PLAYER_XP, 0); - } - else - unit->SetLevel(newlevel); - - return 0; - } - - /** - * Sets the [Unit]'s health. - * - * @param uint32 health : new health - */ - int SetHealth(Eluna* E, Unit* unit) - { - uint32 amt = E->CHECKVAL(2); - unit->SetHealth(amt); - return 0; - } - - /** - * Sets the [Unit]'s max health. - * - * @param uint32 maxHealth : new max health - */ - int SetMaxHealth(Eluna* E, Unit* unit) - { - uint32 amt = E->CHECKVAL(2); - unit->SetMaxHealth(amt); - return 0; - } - - /** - * Sets the [Unit]'s power amount for the given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param uint32 amount : new power amount - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - */ - int SetPower(Eluna* E, Unit* unit) - { - uint32 amt = E->CHECKVAL(2); - int type = E->CHECKVAL(3, -1); - Powers power = PowerSelectorHelper(E, unit, type); - - unit->SetPower(power, amt); - return 0; - } - - /** - * modifies the [Unit]'s power amount for the given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param int32 amount : amount to modify - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - */ - int ModifyPower(Eluna* E, Unit* unit) - { - int32 amt = E->CHECKVAL(2); - int type = E->CHECKVAL(3, -1); - Powers power = PowerSelectorHelper(E, unit, type); - - unit->ModifyPower(power, amt); - return 0; - } - - /** - * Sets the [Unit]'s max power amount for the given power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param int type = -1 : a valid power type from [Powers] or -1 for the [Unit]'s current power type - * @param uint32 maxPower : new max power amount - */ - int SetMaxPower(Eluna* E, Unit* unit) - { - int type = E->CHECKVAL(2, -1); - uint32 amt = E->CHECKVAL(3); - Powers power = PowerSelectorHelper(E, unit, type); - - unit->SetMaxPower(power, amt); - return 0; - } - - /** - * Sets the [Unit]'s power type. - * - * enum Powers - * { - * POWER_MANA = 0, - * POWER_RAGE = 1, - * POWER_FOCUS = 2, - * POWER_ENERGY = 3, - * POWER_HAPPINESS = 4, - * POWER_RUNE = 5, - * POWER_RUNIC_POWER = 6, - * MAX_POWERS = 7, - * POWER_ALL = 127, // default for class? - * POWER_HEALTH = 0xFFFFFFFE // (-2 as signed value) - * }; - * - * @param [Powers] type : a valid power type - */ - int SetPowerType(Eluna* E, Unit* unit) - { - uint32 type = E->CHECKVAL(2); - if (type >= int(MAX_POWERS)) - return luaL_argerror(E->L, 2, "valid Powers expected"); - - unit->SetPowerType((Powers)type); - return 0; - } - - /** - * Sets the [Unit]'s modelID. - * - * @param uint32 displayId - */ - int SetDisplayId(Eluna* E, Unit* unit) - { - uint32 model = E->CHECKVAL(2); - unit->SetDisplayId(model); - return 0; - } - - /** - * Sets the [Unit]'s native/default modelID. - * - * @param uint32 displayId - */ - int SetNativeDisplayId(Eluna* E, Unit* unit) - { - uint32 model = E->CHECKVAL(2); - unit->SetNativeDisplayId(model); - return 0; - } - - /** - * Sets the [Unit]'s facing/orientation. - * - * @param uint32 orientation - */ - int SetFacing(Eluna* E, Unit* unit) - { - float o = E->CHECKVAL(2); - unit->SetFacingTo(o); - return 0; - } - - /** - * Sets the [Unit] to face the given [WorldObject]'s direction. - * - * @param [WorldObject] target - */ - int SetFacingToObject(Eluna* E, Unit* unit) - { - WorldObject* obj = E->CHECKOBJ(2); - unit->SetFacingToObject(obj); - return 0; - } - - /** - * Sets creator GUID - * - * @param ObjectGuid guid - */ - int SetCreatorGUID(Eluna* E, Unit* unit) - { - ObjectGuid guid = E->CHECKVAL(2); - - unit->SetCreatorGuid(guid); - return 0; - } - - /** - * Sets pet GUID - * - * @param ObjectGuid guid - */ - int SetPetGUID(Eluna* E, Unit* unit) - { - ObjectGuid guid = E->CHECKVAL(2); - - unit->SetPetGuid(guid); - return 0; - } - - /** - * Toggles (Sets) [Unit]'s water walking - * - * @param bool enable = true - */ - int SetWaterWalk(Eluna* E, Unit* unit) - { - bool enable = E->CHECKVAL(2, true); - - unit->SetWaterWalk(enable); - return 0; - } - - /** - * Sets the [Unit]'s stand state - * - * @param uint8 state : stand state - */ - int SetStandState(Eluna* E, Unit* unit) - { - uint8 state = E->CHECKVAL(2); - - unit->SetStandState(state); - return 0; - } - - /** - * Sets the [Unit] in combat with the `enemy` [Unit]. - * - * @param [Unit] enemy : the [Unit] to start combat with - */ - int SetInCombatWith(Eluna* E, Unit* unit) - { - Unit* enemy = E->CHECKOBJ(2); - unit->SetInCombatWith(enemy); - return 0; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Sets the [Unit]'s FFA flag on or off. - * - * @param bool apply = true - */ - int SetFFA(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - unit->SetFFAPvP(apply); - return 0; - } - - /** - * Sets the [Unit]'s sanctuary flag on or off. - * - * @param bool apply = true - */ - int SetSanctuary(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - if (apply) - { - unit->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY); - unit->CombatStop(); - unit->CombatStopWithPets(); - } - else - unit->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY); - - return 0; - } - - int SetCritterGUID(Eluna* E, Unit* unit) - { - ObjectGuid guid = E->CHECKVAL(2); - - unit->SetCritterGuid(guid); - return 0; - } -#endif - - /*int SetStunned(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - unit->SetControlled(apply, UNIT_STATE_STUNNED); - return 0; - }*/ - - /** - * Roots the [Unit] to the ground, if 'false' specified, unroots the [Unit]. - * - * @param bool apply = true - */ - int SetRooted(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - unit->SetRoot(apply); - return 0; - } - - /** - * Confuses the [Unit], if 'false' specified, the [Unit] is no longer confused. - * - * @param bool apply = true - */ - int SetConfused(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - unit->SetConfused(apply); - return 0; - } - - /** - * Fears the [Unit], if 'false' specified, the [Unit] is no longer feared. - * - * @param bool apply = true - */ - int SetFeared(Eluna* E, Unit* unit) - { - bool apply = E->CHECKVAL(2, true); - - unit->SetFeared(apply); - return 0; - } - - /** - * Clears the [Unit]'s threat list. - */ - int ClearThreatList(Eluna* /*E*/, Unit* unit) - { - unit->GetThreatManager().clearReferences(); - return 0; - } - - /** - * Mounts the [Unit] on the given displayID/modelID. - * - * @param uint32 displayId - */ - int Mount(Eluna* E, Unit* unit) - { - uint32 displayId = E->CHECKVAL(2); - - unit->Mount(displayId); - return 0; - } - - /** - * Dismounts the [Unit]. - */ - int Dismount(Eluna* /*E*/, Unit* unit) - { - if (unit->IsMounted()) - { - unit->Unmount(); - unit->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); - } - - return 0; - } - - /** - * Makes the [Unit] perform the given emote. - * - * @param uint32 emoteId - */ - int PerformEmote(Eluna* E, Unit* unit) - { - unit->HandleEmoteCommand(E->CHECKVAL(2)); - return 0; - } - - /** - * Makes the [Unit] perform the given emote continuously. - * - * @param uint32 emoteId - */ - int EmoteState(Eluna* E, Unit* unit) - { - uint32 emoteId = E->CHECKVAL(2); - - unit->SetUInt32Value(UNIT_NPC_EMOTESTATE, emoteId); - return 0; - } - - /** - * Returns calculated percentage from Health - * - * @return int32 percentage - */ - int CountPctFromCurHealth(Eluna* E, Unit* unit) - { - E->Push(unit->CountPctFromCurHealth(E->CHECKVAL(2))); - return 1; - } - - /** - * Returns calculated percentage from Max Health - * - * @return int32 percentage - */ - int CountPctFromMaxHealth(Eluna* E, Unit* unit) - { - E->Push(unit->CountPctFromMaxHealth(E->CHECKVAL(2))); - return 1; - } - - /** - * Sends chat message to [Player] - * - * @param uint8 type : chat, whisper, etc - * @param uint32 lang : language to speak - * @param string msg - * @param [Player] target - */ - int SendChatMessageToPlayer(Eluna* E, Unit* unit) - { - uint8 type = E->CHECKVAL(2); - uint32 lang = E->CHECKVAL(3); - std::string msg = E->CHECKVAL(4); - Player* target = E->CHECKOBJ(5); - - if (type >= MAX_CHAT_MSG_TYPE) - return luaL_argerror(E->L, 2, "valid ChatMsg expected"); - if (lang >= LANGUAGES_COUNT) - return luaL_argerror(E->L, 3, "valid Language expected"); - - WorldPacket data; - ChatHandler::BuildChatPacket(data, ChatMsg(type), msg.c_str(), Language(lang), 0, unit->GET_GUID(), unit->GetName(), target->GET_GUID(), target->GetName()); - - target->GetSession()->SendPacket(&data); - return 0; - } - - /*static void PrepareMove(Unit* unit) - { - unit->GetMotionMaster()->MovementExpired(); // Chase - unit->StopMoving(); // Some - unit->GetMotionMaster()->Clear(); // all - }*/ - - /** - * Stops the [Unit]'s movement - */ - int MoveStop(Eluna* /*E*/, Unit* unit) - { - unit->StopMoving(); - return 0; - } - - /** - * The [Unit]'s movement expires and clears movement - * - * @param bool reset = true : cleans movement - */ - int MoveExpire(Eluna* E, Unit* unit) - { - bool reset = E->CHECKVAL(2, true); - unit->GetMotionMaster()->MovementExpired(reset); - - return 0; - } - - /** - * Clears the [Unit]'s movement - * - * @param bool reset = true : clean movement - */ - int MoveClear(Eluna* E, Unit* unit) - { - bool reset = E->CHECKVAL(2, true); - unit->GetMotionMaster()->Clear(reset); - return 0; - } - - /** - * The [Unit] will be idle - */ - int MoveIdle(Eluna* /*E*/, Unit* unit) - { - unit->GetMotionMaster()->MoveIdle(); - return 0; - } - - /** - * The [Unit] will move at random - * - * @param float radius : limit on how far the [Unit] will move at random - */ - int MoveRandom(Eluna* E, Unit* unit) - { - float radius = E->CHECKVAL(2); - float x, y, z; - unit->GetPosition(x, y, z); - - unit->GetMotionMaster()->MoveRandomAroundPoint(x, y, z, radius); - return 0; - } - - /** - * The [Unit] will move to its set home location - */ - int MoveHome(Eluna* /*E*/, Unit* unit) - { - unit->GetMotionMaster()->MoveTargetedHome(); - return 0; - } - - /** - * The [Unit] will follow the target - * - * @param [Unit] target : target to follow - * @param float dist = 0 : distance to start following - * @param float angle = 0 - */ - int MoveFollow(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - float dist = E->CHECKVAL(3, 0.0f); - float angle = E->CHECKVAL(4, 0.0f); - unit->GetMotionMaster()->MoveFollow(target, dist, angle); - return 0; - } - - /** - * The [Unit] will chase the target - * - * @param [Unit] target : target to chase - * @param float dist = 0 : distance start chasing - * @param float angle = 0 - */ - int MoveChase(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - float dist = E->CHECKVAL(3, 0.0f); - float angle = E->CHECKVAL(4, 0.0f); - unit->GetMotionMaster()->MoveChase(target, dist, angle); - return 0; - } - - /** - * The [Unit] will move confused - */ - int MoveConfused(Eluna* /*E*/, Unit* unit) - { - unit->GetMotionMaster()->MoveConfused(); - return 0; - } - - /** - * The [Unit] will flee - * - * @param [Unit] target - * @param uint32 time = 0 : flee delay - */ - int MoveFleeing(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - uint32 time = E->CHECKVAL(3, 0); - unit->GetMotionMaster()->MoveFleeing(target, time); - return 0; - } - - /** - * The [Unit] will move to the coordinates - * - * @param uint32 id : unique waypoint Id - * @param float x - * @param float y - * @param float z - * @param bool genPath = true : if true, generates path - */ - int MoveTo(Eluna* E, Unit* unit) - { - uint32 id = E->CHECKVAL(2); - float x = E->CHECKVAL(3); - float y = E->CHECKVAL(4); - float z = E->CHECKVAL(5); - bool genPath = E->CHECKVAL(6, true); - - unit->GetMotionMaster()->MovePoint(id, x, y, z, genPath); - return 0; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Makes the [Unit] jump to the coordinates - * - * @param float x - * @param float y - * @param float z - * @param float zSpeed : start velocity - * @param float maxHeight : maximum height - * @param uint32 id = 0 : unique movement Id - */ - int MoveJump(Eluna* E, Unit* unit) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - float zSpeed = E->CHECKVAL(5); - float maxHeight = E->CHECKVAL(6); - uint32 id = E->CHECKVAL(7, 0); - -#if WOTLK - unit->GetMotionMaster()->MoveJump(x, y, z, zSpeed, maxHeight, id); -#else - Position pos(x, y, z); - unit->GetMotionMaster()->MoveJump(pos, zSpeed, maxHeight, id); -#endif - return 0; - } -#endif - - /** - * The [Unit] will whisper the message to a [Player] - * - * @param string msg : message for the [Unit] to emote - * @param uint32 lang : language for the [Unit] to speak - * @param [Player] receiver : specific [Unit] to receive the message - * @param bool bossWhisper = false : is a boss whisper - */ - int SendUnitWhisper(Eluna* E, Unit* unit) - { - const char* msg = E->CHECKVAL(2); - uint32 lang = E->CHECKVAL(3); - (void)lang; // ensure that the variable is referenced in order to pass compiler checks - Player* receiver = E->CHECKOBJ(4); - bool bossWhisper = E->CHECKVAL(5, false); - - if (std::string(msg).length() > 0) - unit->MonsterWhisper(msg, receiver, bossWhisper); - - return 0; - } - - /** - * The [Unit] will emote the message - * - * @param string msg : message for the [Unit] to emote - * @param [Unit] receiver = nil : specific [Unit] to receive the message - * @param bool bossEmote = false : is a boss emote - */ - int SendUnitEmote(Eluna* E, Unit* unit) - { - const char* msg = E->CHECKVAL(2); - Unit* receiver = E->CHECKOBJ(3, false); - bool bossEmote = E->CHECKVAL(4, false); - - if (std::string(msg).length() > 0) - unit->MonsterTextEmote(msg, receiver, bossEmote); - - return 0; - } - - /** - * The [Unit] will say the message - * - * @param string msg : message for the [Unit] to say - * @param uint32 language : language for the [Unit] to speak - */ - int SendUnitSay(Eluna* E, Unit* unit) - { - const char* msg = E->CHECKVAL(2); - uint32 language = E->CHECKVAL(3); - if (std::string(msg).length() > 0) - unit->MonsterSay(msg, language, unit); - - return 0; - } - - /** - * The [Unit] will yell the message - * - * @param string msg : message for the [Unit] to yell - * @param uint32 language : language for the [Unit] to speak - */ - int SendUnitYell(Eluna* E, Unit* unit) - { - const char* msg = E->CHECKVAL(2); - uint32 language = E->CHECKVAL(3); - if (std::string(msg).length() > 0) - unit->MonsterYell(msg, language, unit); - - return 0; - } - - /** - * Unmorphs the [Unit] setting it's display ID back to the native display ID. - */ - int DeMorph(Eluna* /*E*/, Unit* unit) - { - unit->DeMorph(); - return 0; - } - - /** - * Makes the [Unit] cast the spell on the target. - * - * @param [Unit] target = nil : can be self or another unit - * @param uint32 spell : entry of a spell - * @param bool triggered = false : if true the spell is instant and has no cost - */ - int CastSpell(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2, false); - uint32 spell = E->CHECKVAL(3); - bool triggered = E->CHECKVAL(4, false); - - SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); - if (!spellEntry) - return 0; - - unit->CastSpell(target, spell, triggered); - return 0; - } - - /** - * Casts the [Spell] at target [Unit] with custom basepoints or casters. - * See also [Unit:CastSpell]. - * - * @param [Unit] target = nil - * @param uint32 spell - * @param bool triggered = false - * @param int32 bp0 = nil : custom basepoints for [Spell] effect 1. If nil, no change is made - * @param int32 bp1 = nil : custom basepoints for [Spell] effect 2. If nil, no change is made - * @param int32 bp2 = nil : custom basepoints for [Spell] effect 3. If nil, no change is made - * @param [Item] castItem = nil - * @param ObjectGuid originalCaster = ObjectGuid() - */ - int CastCustomSpell(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2, false); - uint32 spell = E->CHECKVAL(3); - bool triggered = E->CHECKVAL(4, false); - bool has_bp0 = !lua_isnoneornil(E->L, 5); - int32 bp0 = E->CHECKVAL(5, 0); - bool has_bp1 = !lua_isnoneornil(E->L, 6); - int32 bp1 = E->CHECKVAL(6, 0); - bool has_bp2 = !lua_isnoneornil(E->L, 7); - int32 bp2 = E->CHECKVAL(7, 0); - Item* castItem = E->CHECKOBJ(8, false); - ObjectGuid originalCaster = E->CHECKVAL(9, ObjectGuid()); - - unit->CastCustomSpell(target, spell, has_bp0 ? &bp0 : NULL, has_bp1 ? &bp1 : NULL, has_bp2 ? &bp2 : NULL, triggered, castItem, NULL, ObjectGuid(originalCaster)); - return 0; - } - - /** - * Makes the [Unit] cast the spell to the given coordinates, used for area effect spells. - * - * @param float x - * @param float y - * @param float z - * @param uint32 spell : entry of a spell - * @param bool triggered = true : if true the spell is instant and has no cost - */ - int CastSpellAoF(Eluna* E, Unit* unit) - { - float _x = E->CHECKVAL(2); - float _y = E->CHECKVAL(3); - float _z = E->CHECKVAL(4); - uint32 spell = E->CHECKVAL(5); - bool triggered = E->CHECKVAL(6, true); - - unit->CastSpell(_x, _y, _z, spell, triggered); - return 0; - } - - /** - * Clears the [Unit]'s combat - */ - int ClearInCombat(Eluna* /*E*/, Unit* unit) - { - unit->ClearInCombat(); - return 0; - } - - /** - * Stops the [Unit]'s current spell cast - * - * @param uint32 spell = 0 : entry of a spell - */ - int StopSpellCast(Eluna* E, Unit* unit) - { - uint32 spellId = E->CHECKVAL(2, 0); - unit->CastStop(spellId); - return 0; - } - - /** - * Interrupts [Unit]'s spell state, casting, etc. - * - * if spell is not interruptible, it will return - * - * @param int32 spellType : type of spell to interrupt - * @param bool delayed = true : skips if the spell is delayed - */ - int InterruptSpell(Eluna* E, Unit* unit) - { - int spellType = E->CHECKVAL(2); - bool delayed = E->CHECKVAL(3, true); - switch (spellType) - { - case 0: - spellType = CURRENT_MELEE_SPELL; - break; - case 1: - spellType = CURRENT_GENERIC_SPELL; - break; - case 2: - spellType = CURRENT_CHANNELED_SPELL; - break; - case 3: - spellType = CURRENT_AUTOREPEAT_SPELL; - break; - default: - return luaL_argerror(E->L, 2, "valid CurrentSpellTypes expected"); - } - - unit->InterruptSpell((CurrentSpellTypes)spellType, delayed); - return 0; - } - - /** - * Adds the [Aura] of the given spell entry on the given target from the [Unit]. - * - * @param uint32 spell : entry of a spell - * @param [Unit] target : aura will be applied on the target - * @return [Aura] aura - */ - int AddAura(Eluna* E, Unit* unit) - { - uint32 spell = E->CHECKVAL(2); - Unit* target = E->CHECKOBJ(3); - - SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); - if (!spellEntry) - return 1; - - if (!IsSpellAppliesAura(spellEntry) && !IsSpellHaveEffect(spellEntry, SPELL_EFFECT_PERSISTENT_AREA_AURA)) - return 1; - - SpellAuraHolder* holder = CreateSpellAuraHolder(spellEntry, target, unit); - - for (uint32 i = 0; i < MAX_EFFECT_INDEX; ++i) - { - uint8 eff = spellEntry->Effect[i]; - if (eff >= TOTAL_SPELL_EFFECTS) - continue; - - if (IsAreaAuraEffect(eff) || - eff == SPELL_EFFECT_APPLY_AURA || - eff == SPELL_EFFECT_PERSISTENT_AREA_AURA) - { - Aura* aur = CreateAura(spellEntry, SpellEffIndex(i), NULL, holder, target); - holder->AddAura(aur, SpellEffIndex(i)); - } - } - - E->Push(target->AddSpellAuraHolder(holder)); - return 1; - } - - /** - * Removes [Aura] of the given spell entry from the [Unit]. - * - * @param uint32 spell : entry of a spell - */ - int RemoveAura(Eluna* E, Unit* unit) - { - uint32 spellId = E->CHECKVAL(2); - unit->RemoveAurasDueToSpell(spellId); - return 0; - } - - /** - * Removes all [Aura]'s from the [Unit]. - * - * Note: talents and racials are also auras, use with caution - */ - int RemoveAllAuras(Eluna* /*E*/, Unit* unit) - { - unit->RemoveAllAuras(); - return 0; - } - -#if !defined(CLASSIC) - /** - * Removes all positive visible [Aura]'s from the [Unit]. - */ - int RemoveArenaAuras(Eluna* /*E*/, Unit* unit) - { - unit->RemoveArenaAuras(); - return 0; - } -#endif - - /** - * Adds the given unit state for the [Unit]. - * - * @param [UnitState] state - */ - int AddUnitState(Eluna* E, Unit* unit) - { - uint32 state = E->CHECKVAL(2); - - unit->addUnitState(state); - return 0; - } - - /** - * Removes the given unit state from the [Unit]. - * - * @param [UnitState] state - */ - int ClearUnitState(Eluna* E, Unit* unit) - { - uint32 state = E->CHECKVAL(2); - - unit->clearUnitState(state); - return 0; - } - - /** - * Makes the [Unit] teleport to given coordinates within same map. - * - * @param float x - * @param float y - * @param float z - * @param float o : orientation - */ - int NearTeleport(Eluna* E, Unit* unit) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - float o = E->CHECKVAL(5); - - unit->NearTeleportTo(x, y, z, o); - return 0; - } - - /** - * Makes the [Unit] damage the target [Unit] - * - *
-     * enum SpellSchools
-     * {
-     *     SPELL_SCHOOL_NORMAL  = 0,
-     *     SPELL_SCHOOL_HOLY    = 1,
-     *     SPELL_SCHOOL_FIRE    = 2,
-     *     SPELL_SCHOOL_NATURE  = 3,
-     *     SPELL_SCHOOL_FROST   = 4,
-     *     SPELL_SCHOOL_SHADOW  = 5,
-     *     SPELL_SCHOOL_ARCANE  = 6,
-     *     MAX_SPELL_SCHOOL     = 7
-     * };
-     * 
- * - * @param [Unit] target : [Unit] to damage - * @param uint32 damage : amount to damage - * @param bool durabilityloss = true : if false, the damage does not do durability damage - * @param [SpellSchools] school = MAX_SPELL_SCHOOL : school the damage is done in or MAX_SPELL_SCHOOL for direct damage - * @param uint32 spell = 0 : spell that inflicts the damage - */ - int DealDamage(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - uint32 damage = E->CHECKVAL(3); - bool durabilityloss = E->CHECKVAL(4, true); - uint32 school = E->CHECKVAL(5, MAX_SPELL_SCHOOL); - uint32 spell = E->CHECKVAL(6, 0); - if (school > MAX_SPELL_SCHOOL) - return luaL_argerror(E->L, 6, "valid SpellSchool expected"); - - // flat melee damage without resistence/etc reduction - if (school == MAX_SPELL_SCHOOL) - { - unit->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, durabilityloss); - unit->SendAttackStateUpdate(HITINFO_NORMALSWING2, target, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0); - return 0; - } - - SpellSchoolMask schoolmask = SpellSchoolMask(1 << school); - - if (schoolmask & SPELL_SCHOOL_MASK_NORMAL) - damage = unit->CalcArmorReducedDamage(target, damage); - - // melee damage by specific school - if (!spell) - { - uint32 absorb = 0; - uint32 resist = 0; - - target->CalculateDamageAbsorbAndResist(unit, schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist); - - if (damage <= absorb + resist) - damage = 0; - else - damage -= absorb + resist; - - unit->DealDamageMods(target, damage, &absorb); - unit->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false); - unit->SendAttackStateUpdate(HITINFO_NORMALSWING2, target, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0); - return 0; - } - - // non-melee damage - unit->SpellNonMeleeDamageLog(target, spell, damage); - return 0; - } - - /** - * Makes the [Unit] heal the target [Unit] with given spell - * - * @param [Unit] target : [Unit] to heal - * @param uint32 spell : spell that causes the healing - * @param uint32 amount : amount to heal - * @param bool critical = false : if true, heal is logged as critical - */ - int DealHeal(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - uint32 spell = E->CHECKVAL(3); - uint32 amount = E->CHECKVAL(4); - bool critical = E->CHECKVAL(5, false); - - SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); - if (spellEntry) - unit->DealHeal(target, amount, spellEntry, critical); - - return 0; - } - - /** - * Makes the [Unit] kill the target [Unit] - * - * @param [Unit] target : [Unit] to kill - * @param bool durLoss = true : when true, the target's items suffer durability loss - */ - int Kill(Eluna* E, Unit* unit) - { - Unit* target = E->CHECKOBJ(2); - bool durLoss = E->CHECKVAL(3, true); - - unit->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, durLoss); - return 0; - } - - /** - * Adds threat to the [Unit] from the victim. - * - *
-     * enum SpellSchoolMask
-     * {
-     *     SPELL_SCHOOL_MASK_NONE    = 0,
-     *     SPELL_SCHOOL_MASK_NORMAL  = 1,
-     *     SPELL_SCHOOL_MASK_HOLY    = 2,
-     *     SPELL_SCHOOL_MASK_FIRE    = 4,
-     *     SPELL_SCHOOL_MASK_NATURE  = 8,
-     *     SPELL_SCHOOL_MASK_FROST   = 16,
-     *     SPELL_SCHOOL_MASK_SHADOW  = 32,
-     *     SPELL_SCHOOL_MASK_ARCANE  = 64,
-     * }
-     * 
- * - * @param [Unit] victim : [Unit] that caused the threat - * @param float threat : threat amount - * @param [SpellSchoolMask] schoolMask = 0 : [SpellSchoolMask] of the threat causer - * @param uint32 spell = 0 : spell entry used for threat - */ - int AddThreat(Eluna* E, Unit* unit) - { - Unit* victim = E->CHECKOBJ(2); - float threat = E->CHECKVAL(3, true); - uint32 spell = E->CHECKVAL(4, 0); - - SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); -#ifdef CLASSIC - unit->AddThreat(victim, threat, false, spellEntry ? GetSchoolMask(spellEntry->School) : SPELL_SCHOOL_MASK_NONE, spellEntry); -#else - unit->AddThreat(victim, threat, false, spellEntry ? static_cast(spellEntry->SchoolMask) : SPELL_SCHOOL_MASK_NONE, spellEntry); -#endif - return 0; - } - - ElunaRegister UnitMethods[] = - { - // Getters - { "GetLevel", &LuaUnit::GetLevel }, - { "GetHealth", &LuaUnit::GetHealth }, - { "GetDisplayId", &LuaUnit::GetDisplayId }, - { "GetNativeDisplayId", &LuaUnit::GetNativeDisplayId }, - { "GetPower", &LuaUnit::GetPower }, - { "GetMaxPower", &LuaUnit::GetMaxPower }, - { "GetPowerType", &LuaUnit::GetPowerType }, - { "GetMaxHealth", &LuaUnit::GetMaxHealth }, - { "GetHealthPct", &LuaUnit::GetHealthPct }, - { "GetPowerPct", &LuaUnit::GetPowerPct }, - { "GetGender", &LuaUnit::GetGender }, - { "GetRace", &LuaUnit::GetRace }, - { "GetClass", &LuaUnit::GetClass }, - { "GetRaceMask", &LuaUnit::GetRaceMask }, - { "GetClassMask", &LuaUnit::GetClassMask }, - { "GetRaceAsString", &LuaUnit::GetRaceAsString }, - { "GetClassAsString", &LuaUnit::GetClassAsString }, - { "GetAura", &LuaUnit::GetAura }, - { "GetFaction", &LuaUnit::GetFaction }, - { "GetCurrentSpell", &LuaUnit::GetCurrentSpell }, - { "GetCreatureType", &LuaUnit::GetCreatureType }, - { "GetMountId", &LuaUnit::GetMountId }, - { "GetOwner", &LuaUnit::GetOwner }, - { "GetFriendlyUnitsInRange", &LuaUnit::GetFriendlyUnitsInRange }, - { "GetUnfriendlyUnitsInRange", &LuaUnit::GetUnfriendlyUnitsInRange }, - { "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, - { "GetCreatorGUID", &LuaUnit::GetCreatorGUID }, - { "GetMinionGUID", &LuaUnit::GetPetGUID }, - { "GetCharmerGUID", &LuaUnit::GetCharmerGUID }, - { "GetCharmGUID", &LuaUnit::GetCharmGUID }, - { "GetPetGUID", &LuaUnit::GetPetGUID }, - { "GetControllerGUID", &LuaUnit::GetControllerGUID }, - { "GetControllerGUIDS", &LuaUnit::GetControllerGUIDS }, - { "GetStandState", &LuaUnit::GetStandState }, - { "GetVictim", &LuaUnit::GetVictim }, - { "GetSpeed", &LuaUnit::GetSpeed }, - { "GetStat", &LuaUnit::GetStat }, - { "GetBaseSpellPower", &LuaUnit::GetBaseSpellPower }, - { "GetMovementType", &LuaUnit::GetMovementType }, -#if (!defined(TBC) && !defined(CLASSIC)) - { "GetVehicleKit", &LuaUnit::GetVehicleKit }, - { "GetCritterGUID", &LuaUnit::GetCritterGUID }, -#else - { "GetVehicleKit", nullptr, METHOD_REG_NONE }, - { "GetCritterGUID", nullptr, METHOD_REG_NONE }, -#endif - - // Setters - { "SetFaction", &LuaUnit::SetFaction }, - { "SetLevel", &LuaUnit::SetLevel }, - { "SetHealth", &LuaUnit::SetHealth }, - { "SetMaxHealth", &LuaUnit::SetMaxHealth }, - { "SetPower", &LuaUnit::SetPower }, - { "SetMaxPower", &LuaUnit::SetMaxPower }, - { "SetPowerType", &LuaUnit::SetPowerType }, - { "SetDisplayId", &LuaUnit::SetDisplayId }, - { "SetNativeDisplayId", &LuaUnit::SetNativeDisplayId }, - { "SetFacing", &LuaUnit::SetFacing }, - { "SetFacingToObject", &LuaUnit::SetFacingToObject }, - { "SetSpeed", &LuaUnit::SetSpeed }, - { "SetRooted", &LuaUnit::SetRooted}, - { "SetConfused", &LuaUnit::SetConfused}, - { "SetFeared", &LuaUnit::SetFeared}, - { "SetPvP", &LuaUnit::SetPvP }, - { "SetOwnerGUID", &LuaUnit::SetOwnerGUID }, - { "SetName", &LuaUnit::SetName }, - { "SetSheath", &LuaUnit::SetSheath }, - { "SetCreatorGUID", &LuaUnit::SetCreatorGUID }, - { "SetMinionGUID", &LuaUnit::SetPetGUID }, - { "SetPetGUID", &LuaUnit::SetPetGUID }, - { "SetWaterWalk", &LuaUnit::SetWaterWalk }, - { "SetStandState", &LuaUnit::SetStandState }, - { "SetInCombatWith", &LuaUnit::SetInCombatWith }, - { "ModifyPower", &LuaUnit::ModifyPower }, -#if (!defined(TBC) && !defined(CLASSIC)) - { "SetFFA", &LuaUnit::SetFFA }, - { "SetSanctuary", &LuaUnit::SetSanctuary }, - { "SetCritterGUID", &LuaUnit::SetCritterGUID }, -#else - { "SetFFA", nullptr, METHOD_REG_NONE }, - { "SetSanctuary", nullptr, METHOD_REG_NONE }, - { "SetCritterGUID", nullptr, METHOD_REG_NONE }, -#endif - - // Boolean - { "IsAlive", &LuaUnit::IsAlive }, - { "IsDead", &LuaUnit::IsDead }, - { "IsDying", &LuaUnit::IsDying }, - { "IsPvPFlagged", &LuaUnit::IsPvPFlagged }, - { "IsInCombat", &LuaUnit::IsInCombat }, - { "IsBanker", &LuaUnit::IsBanker }, - { "IsBattleMaster", &LuaUnit::IsBattleMaster }, - { "IsCharmed", &LuaUnit::IsCharmed }, - { "IsArmorer", &LuaUnit::IsArmorer }, - { "IsAttackingPlayer", &LuaUnit::IsAttackingPlayer }, - { "IsInWater", &LuaUnit::IsInWater }, - { "IsUnderWater", &LuaUnit::IsUnderWater }, - { "IsAuctioneer", &LuaUnit::IsAuctioneer }, - { "IsGuildMaster", &LuaUnit::IsGuildMaster }, - { "IsInnkeeper", &LuaUnit::IsInnkeeper }, - { "IsTrainer", &LuaUnit::IsTrainer }, - { "IsGossip", &LuaUnit::IsGossip }, - { "IsTaxi", &LuaUnit::IsTaxi }, - { "IsSpiritHealer", &LuaUnit::IsSpiritHealer }, - { "IsSpiritGuide", &LuaUnit::IsSpiritGuide }, - { "IsTabardDesigner", &LuaUnit::IsTabardDesigner }, - { "IsServiceProvider", &LuaUnit::IsServiceProvider }, - { "IsSpiritService", &LuaUnit::IsSpiritService }, - { "HealthBelowPct", &LuaUnit::HealthBelowPct }, - { "HealthAbovePct", &LuaUnit::HealthAbovePct }, - { "IsMounted", &LuaUnit::IsMounted }, - { "AttackStop", &LuaUnit::AttackStop }, - { "Attack", &LuaUnit::Attack }, - { "IsStopped", &LuaUnit::IsStopped }, - { "HasUnitState", &LuaUnit::HasUnitState }, - { "IsQuestGiver", &LuaUnit::IsQuestGiver }, - { "IsInAccessiblePlaceFor", &LuaUnit::IsInAccessiblePlaceFor }, - { "IsVendor", &LuaUnit::IsVendor }, - { "IsRooted", &LuaUnit::IsRooted }, - { "IsFullHealth", &LuaUnit::IsFullHealth }, - { "HasAura", &LuaUnit::HasAura }, - { "IsCasting", &LuaUnit::IsCasting }, - { "IsStandState", &LuaUnit::IsStandState }, -#if !defined(CLASSIC) - { "IsOnVehicle", &LuaUnit::IsOnVehicle }, -#else - { "IsOnVehicle", nullptr, METHOD_REG_NONE }, -#endif - - // Other - { "AddAura", &LuaUnit::AddAura }, - { "RemoveAura", &LuaUnit::RemoveAura }, - { "RemoveAllAuras", &LuaUnit::RemoveAllAuras }, - { "ClearInCombat", &LuaUnit::ClearInCombat }, - { "DeMorph", &LuaUnit::DeMorph }, - { "SendUnitWhisper", &LuaUnit::SendUnitWhisper }, - { "SendUnitEmote", &LuaUnit::SendUnitEmote }, - { "SendUnitSay", &LuaUnit::SendUnitSay }, - { "SendUnitYell", &LuaUnit::SendUnitYell }, - { "CastSpell", &LuaUnit::CastSpell }, - { "CastCustomSpell", &LuaUnit::CastCustomSpell }, - { "CastSpellAoF", &LuaUnit::CastSpellAoF }, - { "Kill", &LuaUnit::Kill }, - { "StopSpellCast", &LuaUnit::StopSpellCast }, - { "InterruptSpell", &LuaUnit::InterruptSpell }, - { "SendChatMessageToPlayer", &LuaUnit::SendChatMessageToPlayer }, - { "PerformEmote", &LuaUnit::PerformEmote }, - { "EmoteState", &LuaUnit::EmoteState }, - { "CountPctFromCurHealth", &LuaUnit::CountPctFromCurHealth }, - { "CountPctFromMaxHealth", &LuaUnit::CountPctFromMaxHealth }, - { "Dismount", &LuaUnit::Dismount }, - { "Mount", &LuaUnit::Mount }, - { "ClearThreatList", &LuaUnit::ClearThreatList }, - { "ClearUnitState", &LuaUnit::ClearUnitState }, - { "AddUnitState", &LuaUnit::AddUnitState }, - { "NearTeleport", &LuaUnit::NearTeleport }, - { "MoveIdle", &LuaUnit::MoveIdle }, - { "MoveRandom", &LuaUnit::MoveRandom }, - { "MoveHome", &LuaUnit::MoveHome }, - { "MoveFollow", &LuaUnit::MoveFollow }, - { "MoveChase", &LuaUnit::MoveChase }, - { "MoveConfused", &LuaUnit::MoveConfused }, - { "MoveFleeing", &LuaUnit::MoveFleeing }, - { "MoveTo", &LuaUnit::MoveTo }, - { "MoveStop", &LuaUnit::MoveStop }, - { "MoveExpire", &LuaUnit::MoveExpire }, - { "MoveClear", &LuaUnit::MoveClear }, - { "DealDamage", &LuaUnit::DealDamage }, - { "DealHeal", &LuaUnit::DealHeal }, - { "AddThreat", &LuaUnit::AddThreat }, -#if !defined(CLASSIC) - { "RemoveArenaAuras", &LuaUnit::RemoveArenaAuras }, -#else - { "RemoveArenaAuras", nullptr, METHOD_REG_NONE }, -#endif -#if (!defined(TBC) && !defined(CLASSIC)) - { "MoveJump", &LuaUnit::MoveJump }, -#else - { "MoveJump", nullptr, METHOD_REG_NONE }, -#endif - - // Not implemented mehtods - { "GetVehicle", nullptr, METHOD_REG_NONE }, // not implemented - { "SetStunned", nullptr, METHOD_REG_NONE }, // not implemented - { "SetCanFly", nullptr, METHOD_REG_NONE }, // not implemented - { "SetVisible", nullptr, METHOD_REG_NONE }, // not implemented - { "IsVisible", nullptr, METHOD_REG_NONE }, // not implemented, - { "IsMoving", nullptr, METHOD_REG_NONE }, // not implemented - { "IsFlying", nullptr, METHOD_REG_NONE }, // not implemented - { "RestoreDisplayId", nullptr, METHOD_REG_NONE }, // not implemented - { "RestoreFaction", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveBindSightAuras", nullptr, METHOD_REG_NONE }, // not implemented - { "RemoveCharmAuras", nullptr, METHOD_REG_NONE }, // not implemented - { "DisableMelee", nullptr, METHOD_REG_NONE }, // not implemented - { "SummonGuardian", nullptr, METHOD_REG_NONE }, // not implemented - { "SetImmuneTo", nullptr, METHOD_REG_NONE }, // not implemented - - { NULL, NULL } - }; -}; -#endif diff --git a/methods/Mangos/VehicleMethods.h b/methods/Mangos/VehicleMethods.h deleted file mode 100644 index b630ceac2a..0000000000 --- a/methods/Mangos/VehicleMethods.h +++ /dev/null @@ -1,116 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef VEHICLEMETHODS_H -#define VEHICLEMETHODS_H -#ifndef CLASSIC -#ifndef TBC - -/*** - * Inherits all methods from: none - */ -namespace LuaVehicle -{ - /** - * Returns true if the [Unit] passenger is on board - * - * @param [Unit] passenger - * @return bool isOnBoard - */ - int IsOnBoard(Eluna* E, Vehicle* vehicle) - { - Unit* passenger = E->CHECKOBJ(2); - - E->Push(vehicle->HasOnBoard(passenger)); - return 1; - } - - /** - * Returns the [Vehicle]'s owner - * - * @return [Unit] owner - */ - int GetOwner(Eluna* E, Vehicle* vehicle) - { - E->Push(vehicle->GetOwner()); - return 1; - } - - /** - * Returns the [Vehicle]'s entry - * - * @return uint32 entry - */ - int GetEntry(Eluna* E, Vehicle* vehicle) - { - E->Push(vehicle->GetVehicleEntry()->m_ID); - return 1; - } - - /** - * Returns the [Vehicle]'s passenger in the specified seat - * - * @param int8 seat - * @return [Unit] passenger - */ - int GetPassenger(Eluna* E, Vehicle* vehicle) - { - int8 seatId = E->CHECKVAL(2); - E->Push(vehicle->GetPassenger(seatId)); - return 1; - } - - /** - * Adds [Unit] passenger to a specified seat in the [Vehicle] - * - * @param [Unit] passenger - * @param int8 seat - */ - int AddPassenger(Eluna* E, Vehicle* vehicle) - { - Unit* passenger = E->CHECKOBJ(2); - int8 seatId = E->CHECKVAL(3); - - if (vehicle->CanBoard(passenger)) - vehicle->Board(passenger, seatId); - - return 0; - } - - /** - * Removes [Unit] passenger from the [Vehicle] - * - * @param [Unit] passenger - */ - int RemovePassenger(Eluna* E, Vehicle* vehicle) - { - Unit* passenger = E->CHECKOBJ(2); - - vehicle->UnBoard(passenger, false); - return 0; - } - - ElunaRegister VehicleMethods[] = - { - // Getters - { "GetOwner", &LuaVehicle::GetOwner }, - { "GetEntry", &LuaVehicle::GetEntry }, - { "GetPassenger", &LuaVehicle::GetPassenger }, - - // Boolean - { "IsOnBoard", &LuaVehicle::IsOnBoard }, - - // Other - { "AddPassenger", &LuaVehicle::AddPassenger }, - { "RemovePassenger", &LuaVehicle::RemovePassenger }, - - { NULL, NULL, METHOD_REG_NONE } - }; -} - -#endif // CLASSIC -#endif // TBC -#endif // VEHICLEMETHODS_H diff --git a/methods/Mangos/WorldObjectMethods.h b/methods/Mangos/WorldObjectMethods.h deleted file mode 100644 index 935340a885..0000000000 --- a/methods/Mangos/WorldObjectMethods.h +++ /dev/null @@ -1,1191 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef WORLDOBJECTMETHODS_H -#define WORLDOBJECTMETHODS_H - -/*** - * Inherits all methods from: [Object] - */ -namespace LuaWorldObject -{ - /** - * Returns the name of the [WorldObject] - * - * @return string name - */ - int GetName(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetName()); - return 1; - } - - /** - * Returns the current [Map] object of the [WorldObject] - * - * @return [Map] mapObject - */ - int GetMap(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetMap()); - return 1; - } - -#if (!defined(TBC) && !defined(CLASSIC)) - /** - * Returns the current phase of the [WorldObject] - * - * @return uint32 phase - */ - int GetPhaseMask(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetPhaseMask()); - return 1; - } - - /** - * Sets the [WorldObject]'s phase mask. - * - * @param uint32 phaseMask - * @param bool update = true : update visibility to nearby objects - */ - int SetPhaseMask(Eluna* E, WorldObject* obj) - { - uint32 phaseMask = E->CHECKVAL(2); - bool update = E->CHECKVAL(3, true); - obj->SetPhaseMask(phaseMask, update); - return 0; - } -#endif - - /** - * Returns the current instance ID of the [WorldObject] - * - * @return uint32 instanceId - */ - int GetInstanceId(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetInstanceId()); - return 1; - } - - /** - * Returns the current area ID of the [WorldObject] - * - * @return uint32 areaId - */ - int GetAreaId(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetAreaId()); - return 1; - } - - /** - * Returns the current zone ID of the [WorldObject] - * - * @return uint32 zoneId - */ - int GetZoneId(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetZoneId()); - return 1; - } - - /** - * Returns the current map ID of the [WorldObject] - * - * @return uint32 mapId - */ - int GetMapId(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetMapId()); - return 1; - } - - /** - * Returns the current X coordinate of the [WorldObject] - * - * @return float x - */ - int GetX(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetPositionX()); - return 1; - } - - /** - * Returns the current Y coordinate of the [WorldObject] - * - * @return float y - */ - int GetY(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetPositionY()); - return 1; - } - - /** - * Returns the current Z coordinate of the [WorldObject] - * - * @return float z - */ - int GetZ(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetPositionZ()); - return 1; - } - - /** - * Returns the current orientation of the [WorldObject] - * - * @return float orientation / facing - */ - int GetO(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetOrientation()); - return 1; - } - - /** - * Returns the coordinates and orientation of the [WorldObject] - * - * @return float x : x coordinate of the [WorldObject] - * @return float y : y coordinate of the [WorldObject] - * @return float z : z coordinate (height) of the [WorldObject] - * @return float o : facing / orientation of the [WorldObject] - */ - int GetLocation(Eluna* E, WorldObject* obj) - { - E->Push(obj->GetPositionX()); - E->Push(obj->GetPositionY()); - E->Push(obj->GetPositionZ()); - E->Push(obj->GetOrientation()); - return 4; - } - - /** - * Returns the nearest [Player] object in sight of the [WorldObject] or within the given range - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return [Player] nearestPlayer - */ - int GetNearestPlayer(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 hostile = E->CHECKVAL(3, 0); - uint32 dead = E->CHECKVAL(4, 1); - - Unit* target = NULL; - ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER, 0, hostile, dead); - MaNGOS::UnitLastSearcher searcher(target, checker); - Cell::VisitWorldObjects(obj, searcher, range); - - E->Push(target); - return 1; - } - - /** - * Returns the nearest [GameObject] object in sight of the [WorldObject] or within the given range and/or with a specific entry ID - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 entryId = 0 : optionally set entry ID of game object to find - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * - * @return [GameObject] nearestGameObject - */ - int GetNearestGameObject(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 entry = E->CHECKVAL(3, 0); - uint32 hostile = E->CHECKVAL(4, 0); - - GameObject* target = NULL; - ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_GAMEOBJECT, entry, hostile); - MaNGOS::GameObjectLastSearcher searcher(target, checker); - Cell::VisitGridObjects(obj, searcher, range); - - E->Push(target); - return 1; - } - - /** - * Returns the nearest [Creature] object in sight of the [WorldObject] or within the given range and/or with a specific entry ID - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 entryId = 0 : optionally set entry ID of creature to find - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return [Creature] nearestCreature - */ - int GetNearestCreature(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 entry = E->CHECKVAL(3, 0); - uint32 hostile = E->CHECKVAL(4, 0); - uint32 dead = E->CHECKVAL(5, 1); - - Creature* target = NULL; - ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry, hostile, dead); - MaNGOS::CreatureLastSearcher searcher(target, checker); - Cell::VisitGridObjects(obj, searcher, range); - - E->Push(target); - return 1; - } - - /** - * Returns a table of [Player] objects in sight of the [WorldObject] or within the given range - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return table playersInRange : table of [Player]s - */ - int GetPlayersInRange(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 hostile = E->CHECKVAL(3, 0); - uint32 dead = E->CHECKVAL(4, 1); - - std::list list; - ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER, 0, hostile, dead); - MaNGOS::PlayerListSearcher searcher(list, checker); - Cell::VisitWorldObjects(obj, searcher, range); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns a table of [Creature] objects in sight of the [WorldObject] or within the given range and/or with a specific entry ID - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 entryId = 0 : optionally set entry ID of creatures to find - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return table creaturesInRange : table of [Creature]s - */ - int GetCreaturesInRange(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 entry = E->CHECKVAL(3, 0); - uint32 hostile = E->CHECKVAL(4, 0); - uint32 dead = E->CHECKVAL(5, 1); - - std::list list; - ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry, hostile, dead); - MaNGOS::CreatureListSearcher searcher(list, checker); - Cell::VisitGridObjects(obj, searcher, range); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns a table of [GameObject] objects in sight of the [WorldObject] or within the given range and/or with a specific entry ID - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param uint32 entryId = 0 : optionally set entry ID of game objects to find - * @param uint32 hostile = 0 : 0 both, 1 hostile, 2 friendly - * - * @return table gameObjectsInRange : table of [GameObject]s - */ - int GetGameObjectsInRange(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint32 entry = E->CHECKVAL(3, 0); - uint32 hostile = E->CHECKVAL(4, 0); - - std::list list; - ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_GAMEOBJECT, entry, hostile); - MaNGOS::GameObjectListSearcher searcher(list, checker); - Cell::VisitGridObjects(obj, searcher, range); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns nearest [WorldObject] in sight of the [WorldObject]. - * The distance, type, entry and hostility requirements the [WorldObject] must match can be passed. - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored - * @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored - * @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return [WorldObject] worldObject - */ - int GetNearObject(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint16 type = E->CHECKVAL(3, 0); // TypeMask - uint32 entry = E->CHECKVAL(4, 0); - uint32 hostile = E->CHECKVAL(5, 0); // 0 none, 1 hostile, 2 friendly - uint32 dead = E->CHECKVAL(6, 1); // 0 both, 1 alive, 2 dead - - float x, y, z; - obj->GetPosition(x, y, z); - ElunaUtil::WorldObjectInRangeCheck checker(true, obj, range, type, entry, hostile, dead); - - WorldObject* target = NULL; - MaNGOS::WorldObjectLastSearcher searcher(target, checker); - Cell::VisitAllObjects(obj, searcher, range); - - E->Push(target); - return 1; - } - - /** - * Returns a table of [WorldObject]s in sight of the [WorldObject]. - * The distance, type, entry and hostility requirements the [WorldObject] must match can be passed. - * - * @param float range = 533.33333 : optionally set range. Default range is grid size - * @param [TypeMask] type = 0 : the [TypeMask] that the [WorldObject] must be. This can contain multiple types. 0 will be ingored - * @param uint32 entry = 0 : the entry of the [WorldObject], 0 will be ingored - * @param uint32 hostile = 0 : specifies whether the [WorldObject] needs to be 1 hostile, 2 friendly or 0 either - * @param uint32 dead = 1 : 0 both, 1 alive, 2 dead - * - * @return table worldObjectList : table of [WorldObject]s - */ - int GetNearObjects(Eluna* E, WorldObject* obj) - { - float range = E->CHECKVAL(2, SIZE_OF_GRIDS); - uint16 type = E->CHECKVAL(3, 0); // TypeMask - uint32 entry = E->CHECKVAL(4, 0); - uint32 hostile = E->CHECKVAL(5, 0); // 0 none, 1 hostile, 2 friendly - uint32 dead = E->CHECKVAL(6, 1); // 0 both, 1 alive, 2 dead - - float x, y, z; - obj->GetPosition(x, y, z); - ElunaUtil::WorldObjectInRangeCheck checker(false, obj, range, type, entry, hostile, dead); - - std::list list; - MaNGOS::WorldObjectListSearcher searcher(list, checker); - Cell::VisitAllObjects(obj, searcher, range); - - lua_createtable(E->L, list.size(), 0); - int tbl = lua_gettop(E->L); - uint32 i = 0; - - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - { - E->Push(*it); - lua_rawseti(E->L, tbl, ++i); - } - - lua_settop(E->L, tbl); - return 1; - } - - /** - * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space. - * - * The function takes into account the given object sizes. See also [WorldObject:GetExactDistance], [WorldObject:GetDistance2d] - * - * @proto dist = (obj) - * @proto dist = (x, y, z) - * - * @param [WorldObject] obj - * @param float x : the X-coordinate of the point - * @param float y : the Y-coordinate of the point - * @param float z : the Z-coordinate of the point - * - * @return float dist : the distance in yards - */ - int GetDistance(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, false); - if (target) - E->Push(obj->GetDistance(target)); - else - { - float X = E->CHECKVAL(2); - float Y = E->CHECKVAL(3); - float Z = E->CHECKVAL(4); - E->Push(obj->GetDistance(X, Y, Z)); - } - return 1; - } - - /** - * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 3d space. - * - * The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d] - * - * @proto dist = (obj) - * @proto dist = (x, y, z) - * - * @param [WorldObject] obj - * @param float x : the X-coordinate of the point - * @param float y : the Y-coordinate of the point - * @param float z : the Z-coordinate of the point - * - * @return float dist : the distance in yards - */ - int GetExactDistance(Eluna* E, WorldObject* obj) - { - float x, y, z; - obj->GetPosition(x, y, z); - WorldObject* target = E->CHECKOBJ(2, false); - if (target) - { - float x2, y2, z2; - target->GetPosition(x2, y2, z2); - x -= x2; - y -= y2; - z -= z2; - } - else - { - x -= E->CHECKVAL(2); - y -= E->CHECKVAL(3); - z -= E->CHECKVAL(4); - } - - E->Push(std::sqrt(x*x + y*y + z*z)); - return 1; - } - - /** - * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space. - * - * The function takes into account the given object sizes. See also [WorldObject:GetDistance], [WorldObject:GetExactDistance2d] - * - * @proto dist = (obj) - * @proto dist = (x, y) - * - * @param [WorldObject] obj - * @param float x : the X-coordinate of the point - * @param float y : the Y-coordinate of the point - * - * @return float dist : the distance in yards - */ - int GetDistance2d(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, false); - if (target) - E->Push(obj->GetDistance2d(target)); - else - { - float X = E->CHECKVAL(2); - float Y = E->CHECKVAL(3); - E->Push(obj->GetDistance2d(X, Y)); - } - return 1; - } - - /** - * Returns the distance from this [WorldObject] to another [WorldObject], or from this [WorldObject] to a point in 2d space. - * - * The function does not take into account the given object sizes, which means only the object coordinates are compared. See also [WorldObject:GetDistance], [WorldObject:GetDistance2d] - * - * @proto dist = (obj) - * @proto dist = (x, y) - * - * @param [WorldObject] obj - * @param float x : the X-coordinate of the point - * @param float y : the Y-coordinate of the point - * - * @return float dist : the distance in yards - */ - int GetExactDistance2d(Eluna* E, WorldObject* obj) - { - float x, y, z; - obj->GetPosition(x, y, z); - WorldObject* target = E->CHECKOBJ(2, false); - if (target) - { - float x2, y2, z2; - target->GetPosition(x2, y2, z2); - x -= x2; - y -= y2; - } - else - { - x -= E->CHECKVAL(2); - y -= E->CHECKVAL(3); - } - - E->Push(std::sqrt(x*x + y*y)); - return 1; - } - - /** - * Returns the x, y and z of a point dist away from the [WorldObject]. - * - * @param float distance : specifies the distance of the point from the [WorldObject] in yards - * @param float angle : specifies the angle of the point relative to the orientation / facing of the [WorldObject] in radians - * - * @return float x - * @return float y - * @return float z - */ - int GetRelativePoint(Eluna* E, WorldObject* obj) - { - float dist = E->CHECKVAL(2); - float rad = E->CHECKVAL(3); - - float x, y, z; - obj->GetClosePoint(x, y, z, 0.0f, dist, rad); - - E->Push(x); - E->Push(y); - E->Push(z); - return 3; - } - - /** - * Returns the angle between this [WorldObject] and another [WorldObject] or a point. - * - * The angle is the angle between two points and orientation will be ignored. - * - * @proto dist = (obj) - * @proto dist = (x, y) - * - * @param [WorldObject] object - * @param float x - * @param float y - * - * @return float angle : angle in radians in range 0..2*pi - */ - int GetAngle(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, false); - if (target) - E->Push(obj->GetAngle(target)); - else - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - E->Push(obj->GetAngle(x, y)); - } - - return 1; - } - - /** - * Sends a [WorldPacket] to [Player]s in sight of the [WorldObject]. - * - * @param [WorldPacket] packet - */ - int SendPacket(Eluna* E, WorldObject* obj) - { - WorldPacket* data = E->CHECKOBJ(2); - - obj->SendMessageToSet(data, true); - return 0; - } - - /** - * Spawns a [GameObject] at specified location. - * - * @param uint32 entry : [GameObject] entry ID - * @param float x - * @param float y - * @param float z - * @param float o - * @param uint32 respawnDelay = 30 : respawn time in seconds - * @return [GameObject] gameObject - */ - int SummonGameObject(Eluna* E, WorldObject* obj) - { - uint32 entry = E->CHECKVAL(2); - float x = E->CHECKVAL(3); - float y = E->CHECKVAL(4); - float z = E->CHECKVAL(5); - float o = E->CHECKVAL(6); - uint32 respawnDelay = E->CHECKVAL(7, 30); - - E->Push(obj->SummonGameObject(entry, x, y, z, o, respawnDelay)); - return 1; - } - - /** - * Spawns the creature at specified location. - * - * enum TempSummonType - * { - * TEMPSUMMON_TIMED_OR_DEAD_DESPAWN = 1, // despawns after a specified time OR when the creature disappears - * TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN = 2, // despawns after a specified time OR when the creature dies - * TEMPSUMMON_TIMED_DESPAWN = 3, // despawns after a specified time - * TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT = 4, // despawns after a specified time after the creature is out of combat - * TEMPSUMMON_CORPSE_DESPAWN = 5, // despawns instantly after death - * TEMPSUMMON_CORPSE_TIMED_DESPAWN = 6, // despawns after a specified time after death - * TEMPSUMMON_DEAD_DESPAWN = 7, // despawns when the creature disappears - * TEMPSUMMON_MANUAL_DESPAWN = 8, // despawns when UnSummon() is called - * TEMPSUMMON_TIMED_OOC_OR_CORPSE_DESPAWN = 9, // despawns after a specified time (OOC) OR when the creature dies - * TEMPSUMMON_TIMED_OOC_OR_DEAD_DESPAWN = 10 // despawns after a specified time (OOC) OR when the creature disappears - * }; - * - * @param uint32 entry : [Creature]'s entry ID - * @param float x - * @param float y - * @param float z - * @param float o - * @param [TempSummonType] spawnType = MANUAL_DESPAWN : defines how and when the creature despawns - * @param uint32 despawnTimer = 0 : despawn time in milliseconds - * @return [Creature] spawnedCreature - */ - int SpawnCreature(Eluna* E, WorldObject* obj) - { - uint32 entry = E->CHECKVAL(2); - float x = E->CHECKVAL(3); - float y = E->CHECKVAL(4); - float z = E->CHECKVAL(5); - float o = E->CHECKVAL(6); - uint32 spawnType = E->CHECKVAL(7, 8); - uint32 despawnTimer = E->CHECKVAL(8, 0); - - TempSpawnType type; - switch (spawnType) - { - case 1: - type = TEMPSPAWN_TIMED_OR_DEAD_DESPAWN; - break; - case 2: - type = TEMPSPAWN_TIMED_OR_CORPSE_DESPAWN; - break; - case 3: - type = TEMPSPAWN_TIMED_DESPAWN; - break; - case 4: - type = TEMPSPAWN_TIMED_OOC_DESPAWN; - break; - case 5: - type = TEMPSPAWN_CORPSE_DESPAWN; - break; - case 6: - type = TEMPSPAWN_CORPSE_TIMED_DESPAWN; - break; - case 7: - type = TEMPSPAWN_DEAD_DESPAWN; - break; - case 8: - type = TEMPSPAWN_MANUAL_DESPAWN; - break; - case 9: - type = TEMPSPAWN_TIMED_OOC_OR_CORPSE_DESPAWN; - break; - case 10: - type = TEMPSPAWN_TIMED_OOC_OR_DEAD_DESPAWN; - break; - default: - return luaL_argerror(E->L, 7, "valid SpawnType expected"); - } - - E->Push(obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); - return 1; - } - - /** - * Registers a timed event to the [WorldObject] - * When the passed function is called, the parameters `(eventId, delay, repeats, worldobject)` are passed to it. - * Repeats will decrease on each call if the event does not repeat indefinitely - * - * Note that for [Creature] and [GameObject] the timed event timer ticks only if the creature is in sight of someone - * For all [WorldObject]s the timed events are removed when the object is destoryed. This means that for example a [Player]'s events are removed on logout. - * - * local function Timed(eventid, delay, repeats, worldobject) - * print(worldobject:GetName()) - * end - * worldobject:RegisterEvent(Timed, 1000, 5) -- do it after 1 second 5 times - * worldobject:RegisterEvent(Timed, {1000, 10000}, 0) -- do it after 1 to 10 seconds forever - * - * @proto eventId = (function, delay) - * @proto eventId = (function, delaytable) - * @proto eventId = (function, delay, repeats) - * @proto eventId = (function, delaytable, repeats) - * - * @param function function : function to trigger when the time has passed - * @param uint32 delay : set time in milliseconds for the event to trigger - * @param table delaytable : a table `{min, max}` containing the minimum and maximum delay time - * @param uint32 repeats = 1 : how many times for the event to repeat, 0 is infinite - * @return int eventId : unique ID for the timed event used to cancel it or nil - */ - int RegisterEvent(Eluna* E, WorldObject* obj) - { - luaL_checktype(E->L, 2, LUA_TFUNCTION); - uint32 min, max; - if (lua_istable(E->L, 3)) - { - E->Push(1); - lua_gettable(E->L, 3); - min = E->CHECKVAL(-1); - E->Push(2); - lua_gettable(E->L, 3); - max = E->CHECKVAL(-1); - lua_pop(E->L, 2); - } - else - min = max = E->CHECKVAL(3); - uint32 repeats = E->CHECKVAL(4, 1); - - if (min > max) - return luaL_argerror(E->L, 3, "min is bigger than max delay"); - - lua_pushvalue(E->L, 2); - int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX); - if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF) - { - obj->elunaEvents->AddEvent(functionRef, min, max, repeats); - E->Push(functionRef); - } - return 1; - } - - /** - * Removes the timed event from a [WorldObject] by the specified event ID - * - * @param int eventId : event Id to remove - */ - int RemoveEventById(Eluna* E, WorldObject* obj) - { - int eventId = E->CHECKVAL(2); - obj->elunaEvents->SetState(eventId, LUAEVENT_STATE_ABORT); - return 0; - } - - /** - * Removes all timed events from a [WorldObject] - * - */ - int RemoveEvents(Eluna* /*E*/, WorldObject* obj) - { - obj->elunaEvents->SetStates(LUAEVENT_STATE_ABORT); - return 0; - } - - /** - * Returns true if the given [WorldObject] or coordinates are in the [WorldObject]'s line of sight - * - * @proto isInLoS = (worldobject) - * @proto isInLoS = (x, y, z) - * - * @param [WorldObject] worldobject - * @param float x - * @param float y - * @param float z - * @return bool isInLoS - */ - int IsWithinLoS(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, false); - - if (target) - E->Push(obj->IsWithinLOSInMap(target)); - else - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - E->Push(obj->IsWithinLOS(x, y, z)); - } - - return 1; - } - - /** - * Returns true if the [WorldObject]s are on the same map - * - * @param [WorldObject] worldobject - * @return bool isInMap - */ - int IsInMap(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, true); - E->Push(obj->IsInMap(target)); - return 1; - } - - /** - * Returns true if the point is in the given distance of the [WorldObject] - * - * Notice that the distance is measured from the edge of the [WorldObject]. - * - * @param float x - * @param float y - * @param float z - * @param float distance - * @return bool isInDistance - */ - int IsWithinDist3d(Eluna* E, WorldObject* obj) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - float dist = E->CHECKVAL(5); - E->Push(obj->IsWithinDist3d(x, y, z, dist)); - return 1; - } - - /** - * Returns true if the point is in the given distance of the [WorldObject] - * - * The distance is measured only in x,y coordinates. - * Notice that the distance is measured from the edge of the [WorldObject]. - * - * @param float x - * @param float y - * @param float distance - * @return bool isInDistance - */ - int IsWithinDist2d(Eluna* E, WorldObject* obj) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float dist = E->CHECKVAL(4); - E->Push(obj->IsWithinDist2d(x, y, dist)); - return 1; - } - - /** - * Returns true if the target is in the given distance of the [WorldObject] - * - * Notice that the distance is measured from the edge of the [WorldObject]s. - * - * @param [WorldObject] target - * @param float distance - * @param bool is3D = true : if false, only x,y coordinates used for checking - * @return bool isInDistance - */ - int IsWithinDist(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2, true); - float distance = E->CHECKVAL(3); - bool is3D = E->CHECKVAL(4, true); - E->Push(obj->IsWithinDist(target, distance, is3D)); - return 1; - } - - /** - * Returns true if the [WorldObject] is on the same map and within given distance - * - * Notice that the distance is measured from the edge of the [WorldObject]s. - * - * @param [WorldObject] target - * @param float distance - * @param bool is3D = true : if false, only x,y coordinates used for checking - * @return bool isInDistance - */ - int IsWithinDistInMap(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2); - float distance = E->CHECKVAL(3); - bool is3D = E->CHECKVAL(4, true); - - E->Push(obj->IsWithinDistInMap(target, distance, is3D)); - return 1; - } - - /** - * Returns true if the target is within given range - * - * Notice that the distance is measured from the edge of the [WorldObject]s. - * - * @param [WorldObject] target - * @param float minrange - * @param float maxrange - * @param bool is3D = true : if false, only x,y coordinates used for checking - * @return bool isInDistance - */ - int IsInRange(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2); - float minrange = E->CHECKVAL(3); - float maxrange = E->CHECKVAL(4); - bool is3D = E->CHECKVAL(5, true); - - E->Push(obj->IsInRange(target, minrange, maxrange, is3D)); - return 1; - } - - /** - * Returns true if the point is within given range - * - * Notice that the distance is measured from the edge of the [WorldObject]. - * - * @param float x - * @param float y - * @param float minrange - * @param float maxrange - * @return bool isInDistance - */ - int IsInRange2d(Eluna* E, WorldObject* obj) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float minrange = E->CHECKVAL(4); - float maxrange = E->CHECKVAL(5); - - E->Push(obj->IsInRange2d(x, y, minrange, maxrange)); - return 1; - } - - /** - * Returns true if the point is within given range - * - * Notice that the distance is measured from the edge of the [WorldObject]. - * - * @param float x - * @param float y - * @param float z - * @param float minrange - * @param float maxrange - * @return bool isInDistance - */ - int IsInRange3d(Eluna* E, WorldObject* obj) - { - float x = E->CHECKVAL(2); - float y = E->CHECKVAL(3); - float z = E->CHECKVAL(4); - float minrange = E->CHECKVAL(5); - float maxrange = E->CHECKVAL(6); - - E->Push(obj->IsInRange3d(x, y, z, minrange, maxrange)); - return 1; - } - - /** - * Returns true if the target is in the given arc in front of the [WorldObject] - * - * @param [WorldObject] target - * @param float arc = pi - * @return bool isInFront - */ - int IsInFront(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2); - float arc = E->CHECKVAL(3, static_cast(M_PI)); - - E->Push(obj->IsInFront(target, arc)); - return 1; - } - - /** - * Returns true if the target is in the given arc behind the [WorldObject] - * - * @param [WorldObject] target - * @param float arc = pi - * @return bool isInBack - */ - int IsInBack(Eluna* E, WorldObject* obj) - { - WorldObject* target = E->CHECKOBJ(2); - float arc = E->CHECKVAL(3, static_cast(M_PI)); - - E->Push(obj->IsInBack(target, arc)); - return 1; - } - - /** - * The [WorldObject] plays music to a [Player] - * - * If no [Player] provided it will play the music to everyone near. - * This method does not interrupt previously played music. - * - * See also [WorldObject:PlayDistanceSound], [WorldObject:PlayDirectSound] - * - * @param uint32 music : entry of a music - * @param [Player] player = nil : [Player] to play the music to - */ - int PlayMusic(Eluna* E, WorldObject* obj) - { - uint32 musicid = E->CHECKVAL(2); - Player* player = E->CHECKOBJ(3, false); - - WorldPacket data(SMSG_PLAY_MUSIC, 4); - data << uint32(musicid); - - if (player) - player->SendDirectMessage(&data); - else - obj->SendMessageToSet(&data, true); - - return 0; - } - - /** - * The [WorldObject] plays a sound to a [Player] - * - * If no [Player] provided it will play the sound to everyone near. - * This method will play sound and does not interrupt prvious sound. - * - * See also [WorldObject:PlayDistanceSound], [WorldObject:PlayMusic] - * - * @param uint32 sound : entry of a sound - * @param [Player] player = nil : [Player] to play the sound to - */ - int PlayDirectSound(Eluna* E, WorldObject* obj) - { - uint32 soundId = E->CHECKVAL(2); - Player* player = E->CHECKOBJ(3, false); - if (!sSoundEntriesStore.LookupEntry(soundId)) - return 0; - - if (player) - obj->PlayDirectSound(soundId, player); - else - obj->PlayDirectSound(soundId); - - return 0; - } - - /** - * The [WorldObject] plays a sound to a [Player] - * - * If no [Player] it will play the sound to everyone near. - * Sound will fade the further you are from the [WorldObject]. - * This method interrupts previously playing sound. - * - * See also [WorldObject:PlayDirectSound], [WorldObject:PlayMusic] - * - * @param uint32 sound : entry of a sound - * @param [Player] player = nil : [Player] to play the sound to - */ - int PlayDistanceSound(Eluna* E, WorldObject* obj) - { - uint32 soundId = E->CHECKVAL(2); - Player* player = E->CHECKOBJ(3, false); - if (!sSoundEntriesStore.LookupEntry(soundId)) - return 0; - - if (player) - obj->PlayDistanceSound(soundId, player); - else - obj->PlayDistanceSound(soundId); - - return 0; - } - - /** - * Returns a runtime-persistent cache tied to the [WorldObject]. - * This data will remain for as long as the [WorldObject] exists, or until a server restart. - * - * A reload of the Lua state will NOT clear this cache. - * - * This cache can be added to and read from with the following sub-methods. - *
-     * -- Sets the key-value pair in the cache
-     * WorldObject:Data():Set("key", val)
-     *
-     * -- Returns the value from the cache using the key
-     * local val = WorldObject:Data():Get("key")
-     *
-     * -- Removes the key-value pair from the cache
-     * WorldObject:Data():Set("key", nil)
-     *
-     * -- Returns all the key-value pairs as a Lua table indexed by the keys
-     * local table = WorldObject:Data():AsTable()
-     * 
- */ - int Data(Eluna* E, WorldObject* obj) - { - return LuaVal::PushLuaVal(E->L, obj->lua_data); - } - - ElunaRegister WorldObjectMethods[] = - { - // Getters - { "GetName", &LuaWorldObject::GetName }, - { "GetMap", &LuaWorldObject::GetMap }, -#if (!defined(TBC) && !defined(CLASSIC)) - { "GetPhaseMask", &LuaWorldObject::GetPhaseMask }, - { "SetPhaseMask", &LuaWorldObject::SetPhaseMask }, -#else - { "GetPhaseMask", nullptr, METHOD_REG_NONE }, - { "SetPhaseMask", nullptr, METHOD_REG_NONE }, -#endif - { "GetInstanceId", &LuaWorldObject::GetInstanceId }, - { "GetAreaId", &LuaWorldObject::GetAreaId }, - { "GetZoneId", &LuaWorldObject::GetZoneId }, - { "GetMapId", &LuaWorldObject::GetMapId }, - { "GetX", &LuaWorldObject::GetX }, - { "GetY", &LuaWorldObject::GetY }, - { "GetZ", &LuaWorldObject::GetZ }, - { "GetO", &LuaWorldObject::GetO }, - { "GetLocation", &LuaWorldObject::GetLocation }, - { "GetPlayersInRange", &LuaWorldObject::GetPlayersInRange }, - { "GetCreaturesInRange", &LuaWorldObject::GetCreaturesInRange }, - { "GetGameObjectsInRange", &LuaWorldObject::GetGameObjectsInRange }, - { "GetNearestPlayer", &LuaWorldObject::GetNearestPlayer }, - { "GetNearestGameObject", &LuaWorldObject::GetNearestGameObject }, - { "GetNearestCreature", &LuaWorldObject::GetNearestCreature }, - { "GetNearObject", &LuaWorldObject::GetNearObject }, - { "GetNearObjects", &LuaWorldObject::GetNearObjects }, - { "GetDistance", &LuaWorldObject::GetDistance }, - { "GetExactDistance", &LuaWorldObject::GetExactDistance }, - { "GetDistance2d", &LuaWorldObject::GetDistance2d }, - { "GetExactDistance2d", &LuaWorldObject::GetExactDistance2d }, - { "GetRelativePoint", &LuaWorldObject::GetRelativePoint }, - { "GetAngle", &LuaWorldObject::GetAngle }, - - // Boolean - { "IsWithinLoS", &LuaWorldObject::IsWithinLoS }, - { "IsInMap", &LuaWorldObject::IsInMap }, - { "IsWithinDist3d", &LuaWorldObject::IsWithinDist3d }, - { "IsWithinDist2d", &LuaWorldObject::IsWithinDist2d }, - { "IsWithinDist", &LuaWorldObject::IsWithinDist }, - { "IsWithinDistInMap", &LuaWorldObject::IsWithinDistInMap }, - { "IsInRange", &LuaWorldObject::IsInRange }, - { "IsInRange2d", &LuaWorldObject::IsInRange2d }, - { "IsInRange3d", &LuaWorldObject::IsInRange3d }, - { "IsInFront", &LuaWorldObject::IsInFront }, - { "IsInBack", &LuaWorldObject::IsInBack }, - - // Other - { "SummonGameObject", &LuaWorldObject::SummonGameObject }, - { "SpawnCreature", &LuaWorldObject::SpawnCreature }, - { "SendPacket", &LuaWorldObject::SendPacket }, - { "RegisterEvent", &LuaWorldObject::RegisterEvent, METHOD_REG_MAP }, // Map state method only in multistate - { "RemoveEventById", &LuaWorldObject::RemoveEventById, METHOD_REG_MAP }, // Map state method only in multistate - { "RemoveEvents", &LuaWorldObject::RemoveEvents, METHOD_REG_MAP }, // Map state method only in multistate - { "PlayMusic", &LuaWorldObject::PlayMusic }, - { "PlayDirectSound", &LuaWorldObject::PlayDirectSound }, - { "PlayDistanceSound", &LuaWorldObject::PlayDistanceSound }, - { "Data", &LuaWorldObject::Data }, - - { NULL, NULL, METHOD_REG_NONE } - }; -}; -#endif diff --git a/methods/Mangos/WorldPacketMethods.h b/methods/Mangos/WorldPacketMethods.h deleted file mode 100644 index 1468a04cf4..0000000000 --- a/methods/Mangos/WorldPacketMethods.h +++ /dev/null @@ -1,347 +0,0 @@ -/* -* Copyright (C) 2010 - 2024 Eluna Lua Engine -* This program is free software licensed under GPL version 3 -* Please see the included DOCS/LICENSE.md for more information -*/ - -#ifndef WORLDPACKETMETHODS_H -#define WORLDPACKETMETHODS_H - -/*** - * A packet used to pass messages between the server and a client. - * - * Each packet has an opcode that determines the type of message being sent, - * e.g. if a CMSG_LOGOUT_REQUEST packet is sent to the server, - * the client has sent a message that its [Player] wants to logout. - * - * The packet can contain further data, the format of which depends on the opcode. - * - * Inherits all methods from: none - */ -namespace LuaPacket -{ - /** - * Returns the opcode of the [WorldPacket]. - * - * @return uint16 opcode - */ - int GetOpcode(Eluna* E, WorldPacket* packet) - { - E->Push(packet->GetOpcode()); - return 1; - } - - /** - * Returns the size of the [WorldPacket]. - * - * @return uint32 size - */ - int GetSize(Eluna* E, WorldPacket* packet) - { - E->Push(packet->size()); - return 1; - } - - /** - * Sets the opcode of the [WorldPacket] to the specified opcode. - * - * @param [Opcodes] opcode : see Opcodes.h for all known opcodes - */ - int SetOpcode(Eluna* E, WorldPacket* packet) - { - uint32 opcode = E->CHECKVAL(2); - if (opcode >= NUM_MSG_TYPES) - return luaL_argerror(E->L, 2, "valid opcode expected"); - - packet->SetOpcode((OpcodesList)opcode); - return 0; - } - - /** - * Reads and returns a signed 8-bit integer value from the [WorldPacket]. - * - * @return int8 value - */ - int ReadByte(Eluna* E, WorldPacket* packet) - { - int8 _byte; - (*packet) >> _byte; - E->Push(_byte); - return 1; - } - - /** - * Reads and returns an unsigned 8-bit integer value from the [WorldPacket]. - * - * @return uint8 value - */ - int ReadUByte(Eluna* E, WorldPacket* packet) - { - uint8 _ubyte; - (*packet) >> _ubyte; - E->Push(_ubyte); - return 1; - } - - /** - * Reads and returns a signed 16-bit integer value from the [WorldPacket]. - * - * @return int16 value - */ - int ReadShort(Eluna* E, WorldPacket* packet) - { - int16 _short; - (*packet) >> _short; - E->Push(_short); - return 1; - } - - /** - * Reads and returns an unsigned 16-bit integer value from the [WorldPacket]. - * - * @return uint16 value - */ - int ReadUShort(Eluna* E, WorldPacket* packet) - { - uint16 _ushort; - (*packet) >> _ushort; - E->Push(_ushort); - return 1; - } - - /** - * Reads and returns a signed 32-bit integer value from the [WorldPacket]. - * - * @return int32 value - */ - int ReadLong(Eluna* E, WorldPacket* packet) - { - int32 _long; - (*packet) >> _long; - E->Push(_long); - return 1; - } - - /** - * Reads and returns an unsigned 32-bit integer value from the [WorldPacket]. - * - * @return uint32 value - */ - int ReadULong(Eluna* E, WorldPacket* packet) - { - uint32 _ulong; - (*packet) >> _ulong; - E->Push(_ulong); - return 1; - } - - /** - * Reads and returns a single-precision floating-point value from the [WorldPacket]. - * - * @return float value - */ - int ReadFloat(Eluna* E, WorldPacket* packet) - { - float _val; - (*packet) >> _val; - E->Push(_val); - return 1; - } - - /** - * Reads and returns a double-precision floating-point value from the [WorldPacket]. - * - * @return double value - */ - int ReadDouble(Eluna* E, WorldPacket* packet) - { - double _val; - (*packet) >> _val; - E->Push(_val); - return 1; - } - - /** - * Reads and returns an unsigned 64-bit integer value from the [WorldPacket]. - * - * @return ObjectGuid value : value returned as string - */ - int ReadGUID(Eluna* E, WorldPacket* packet) - { - ObjectGuid guid; - (*packet) >> guid; - E->Push(guid); - return 1; - } - - /** - * Reads and returns a string value from the [WorldPacket]. - * - * @return string value - */ - int ReadString(Eluna* E, WorldPacket* packet) - { - std::string _val; - (*packet) >> _val; - E->Push(_val); - return 1; - } - - /** - * Writes an unsigned 64-bit integer value to the [WorldPacket]. - * - * @param ObjectGuid value : the value to be written to the [WorldPacket] - */ - int WriteGUID(Eluna* E, WorldPacket* packet) - { - ObjectGuid guid = E->CHECKVAL(2); - (*packet) << guid; - return 0; - } - - /** - * Writes a string to the [WorldPacket]. - * - * @param string value : the string to be written to the [WorldPacket] - */ - int WriteString(Eluna* E, WorldPacket* packet) - { - std::string _val = E->CHECKVAL(2); - (*packet) << _val; - return 0; - } - - /** - * Writes a signed 8-bit integer value to the [WorldPacket]. - * - * @param int8 value : the int8 value to be written to the [WorldPacket] - */ - int WriteByte(Eluna* E, WorldPacket* packet) - { - int8 byte = E->CHECKVAL(2); - (*packet) << byte; - return 0; - } - - /** - * Writes an unsigned 8-bit integer value to the [WorldPacket]. - * - * @param uint8 value : the uint8 value to be written to the [WorldPacket] - */ - int WriteUByte(Eluna* E, WorldPacket* packet) - { - uint8 byte = E->CHECKVAL(2); - (*packet) << byte; - return 0; - } - - /** - * Writes a signed 16-bit integer value to the [WorldPacket]. - * - * @param int16 value : the int16 value to be written to the [WorldPacket] - */ - int WriteShort(Eluna* E, WorldPacket* packet) - { - int16 _short = E->CHECKVAL(2); - (*packet) << _short; - return 0; - } - - /** - * Writes an unsigned 16-bit integer value to the [WorldPacket]. - * - * @param uint16 value : the uint16 value to be written to the [WorldPacket] - */ - int WriteUShort(Eluna* E, WorldPacket* packet) - { - uint16 _ushort = E->CHECKVAL(2); - (*packet) << _ushort; - return 0; - } - - /** - * Writes a signed 32-bit integer value to the [WorldPacket]. - * - * @param int32 value : the int32 value to be written to the [WorldPacket] - */ - int WriteLong(Eluna* E, WorldPacket* packet) - { - int32 _long = E->CHECKVAL(2); - (*packet) << _long; - return 0; - } - - /** - * Writes an unsigned 32-bit integer value to the [WorldPacket]. - * - * @param uint32 value : the uint32 value to be written to the [WorldPacket] - */ - int WriteULong(Eluna* E, WorldPacket* packet) - { - uint32 _ulong = E->CHECKVAL(2); - (*packet) << _ulong; - return 0; - } - - /** - * Writes a 32-bit floating-point value to the [WorldPacket]. - * - * @param float value : the float value to be written to the [WorldPacket] - */ - int WriteFloat(Eluna* E, WorldPacket* packet) - { - float _val = E->CHECKVAL(2); - (*packet) << _val; - return 0; - } - - /** - * Writes a 64-bit floating-point value to the [WorldPacket]. - * - * @param double value : the double value to be written to the [WorldPacket] - */ - int WriteDouble(Eluna* E, WorldPacket* packet) - { - double _val = E->CHECKVAL(2); - (*packet) << _val; - return 0; - } - - ElunaRegister PacketMethods[] = - { - // Getters - { "GetOpcode", &LuaPacket::GetOpcode }, - { "GetSize", &LuaPacket::GetSize }, - - // Setters - { "SetOpcode", &LuaPacket::SetOpcode }, - - // Readers - { "ReadByte", &LuaPacket::ReadByte }, - { "ReadUByte", &LuaPacket::ReadUByte }, - { "ReadShort", &LuaPacket::ReadShort }, - { "ReadUShort", &LuaPacket::ReadUShort }, - { "ReadLong", &LuaPacket::ReadLong }, - { "ReadULong", &LuaPacket::ReadULong }, - { "ReadGUID", &LuaPacket::ReadGUID }, - { "ReadString", &LuaPacket::ReadString }, - { "ReadFloat", &LuaPacket::ReadFloat }, - { "ReadDouble", &LuaPacket::ReadDouble }, - - // Writers - { "WriteByte", &LuaPacket::WriteByte }, - { "WriteUByte", &LuaPacket::WriteUByte }, - { "WriteShort", &LuaPacket::WriteShort }, - { "WriteUShort", &LuaPacket::WriteUShort }, - { "WriteLong", &LuaPacket::WriteLong }, - { "WriteULong", &LuaPacket::WriteULong }, - { "WriteGUID", &LuaPacket::WriteGUID }, - { "WriteString", &LuaPacket::WriteString }, - { "WriteFloat", &LuaPacket::WriteFloat }, - { "WriteDouble", &LuaPacket::WriteDouble }, - - { NULL, NULL } - }; -}; - -#endif