From a04de5b1940853ee34e0dedc2b00faaca0ae8935 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Sun, 29 Jun 2014 21:27:59 +0200 Subject: [PATCH] Truncating history --- AuraMethods.h | 127 +++ CMakeLists.txt | 134 +++ CorpseMethods.h | 58 ++ CreatureMethods.h | 679 ++++++++++++ GameObjectMethods.h | 207 ++++ GlobalMethods.h | 1167 +++++++++++++++++++++ GroupMethods.h | 227 ++++ GuildMethods.h | 205 ++++ HookMgr.cpp | 2093 +++++++++++++++++++++++++++++++++++++ HookMgr.h | 467 +++++++++ ItemMethods.h | 498 +++++++++ LuaEngine.cpp | 895 ++++++++++++++++ LuaEngine.h | 689 +++++++++++++ LuaFunctions.cpp | 1215 ++++++++++++++++++++++ MapMethods.h | 114 +++ ObjectMethods.h | 214 ++++ PlayerMethods.h | 2328 ++++++++++++++++++++++++++++++++++++++++++ QueryMethods.h | 188 ++++ QuestMethods.h | 103 ++ README.md | 36 + SpellMethods.h | 131 +++ UnitMethods.h | 1710 +++++++++++++++++++++++++++++++ VehicleMethods.h | 80 ++ WeatherMethods.h | 51 + WorldObjectMethods.h | 432 ++++++++ WorldPacketMethods.h | 207 ++++ docs/INSTALL.md | 33 + docs/LICENSE.md | 220 ++++ 28 files changed, 14508 insertions(+) create mode 100644 AuraMethods.h create mode 100644 CMakeLists.txt create mode 100644 CorpseMethods.h create mode 100644 CreatureMethods.h create mode 100644 GameObjectMethods.h create mode 100644 GlobalMethods.h create mode 100644 GroupMethods.h create mode 100644 GuildMethods.h create mode 100644 HookMgr.cpp create mode 100644 HookMgr.h create mode 100644 ItemMethods.h create mode 100644 LuaEngine.cpp create mode 100644 LuaEngine.h create mode 100644 LuaFunctions.cpp create mode 100644 MapMethods.h create mode 100644 ObjectMethods.h create mode 100644 PlayerMethods.h create mode 100644 QueryMethods.h create mode 100644 QuestMethods.h create mode 100644 README.md create mode 100644 SpellMethods.h create mode 100644 UnitMethods.h create mode 100644 VehicleMethods.h create mode 100644 WeatherMethods.h create mode 100644 WorldObjectMethods.h create mode 100644 WorldPacketMethods.h create mode 100644 docs/INSTALL.md create mode 100644 docs/LICENSE.md diff --git a/AuraMethods.h b/AuraMethods.h new file mode 100644 index 0000000..f72c422 --- /dev/null +++ b/AuraMethods.h @@ -0,0 +1,127 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaAura +{ + int GetCaster(lua_State* L, Aura* aura) + { + sEluna->Push(L, aura->GetCaster()); + return 1; + } + + int GetCasterGUID(lua_State* L, Aura* aura) + { +#ifdef MANGOS + sEluna->Push(L, aura->GetCasterGuid()); +#else + sEluna->Push(L, aura->GetCasterGUID()); +#endif + return 1; + } + + int GetCasterLevel(lua_State* L, Aura* aura) + { + sEluna->Push(L, aura->GetCaster()->getLevel()); + return 1; + } + + int GetDuration(lua_State* L, Aura* aura) + { +#ifdef MANGOS + sEluna->Push(L, aura->GetAuraDuration()); +#else + sEluna->Push(L, aura->GetDuration()); +#endif + return 1; + } + + int GetCharges(lua_State* L, Aura* aura) + { + sEluna->Push(L, aura->GetStackAmount()); + return 1; + } + + int GetAuraId(lua_State* L, Aura* aura) + { + sEluna->Push(L, aura->GetId()); + return 1; + } + + int GetMaxDuration(lua_State* L, Aura* aura) + { +#ifdef MANGOS + sEluna->Push(L, aura->GetAuraMaxDuration()); +#else + sEluna->Push(L, aura->GetMaxDuration()); +#endif + return 1; + } + + int GetStackAmount(lua_State* L, Aura* aura) + { + sEluna->Push(L, aura->GetStackAmount()); + return 1; + } + + int GetOwner(lua_State* L, Aura* aura) + { +#ifdef MANGOS + sEluna->Push(L, aura->GetTarget()); +#else + sEluna->Push(L, aura->GetOwner()); +#endif + return 1; + } + + int SetDuration(lua_State* L, Aura* aura) + { + int duration = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + aura->GetHolder()->SetAuraDuration(duration); +#else + aura->SetDuration(duration); +#endif + return 0; + } + + int SetMaxDuration(lua_State* L, Aura* aura) + { + int duration = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + aura->GetHolder()->SetAuraMaxDuration(duration); +#else + aura->SetMaxDuration(duration); +#endif + return 0; + } + + int SetStackAmount(lua_State* L, Aura* aura) + { + int amount = sEluna->CHECKVAL(L, 2); + int duration = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + aura->GetHolder()->SetStackAmount(amount); +#else + aura->SetStackAmount(amount); +#endif + return 0; + } + + int Remove(lua_State* L, Aura* aura) + { + int duration = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + aura->GetHolder()->RemoveAura(aura->GetEffIndex()); +#else + aura->Remove(); +#endif + return 0; + } +}; +#endif diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..4ec483a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,134 @@ +# +# Copyright (C) 2010 - 2014 Eluna Lua Engine +# This program is free software licensed under GPL version 3 +# Please see the included DOCS/LICENSE.md for more information +# + +if ( USE_COREPCH ) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) + include_directories(${CMAKE_SOURCE_DIR}) +endif () + +file(GLOB sources_localdir *.cpp *.h) + +set(LuaEngine_STAT_SRCS + ${LuaEngine_STAT_SRCS} + ${sources_localdir} +) + +include_directories( + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/dep/recastnavigation/Detour + ${CMAKE_SOURCE_DIR}/dep/recastnavigation/Recast + ${CMAKE_SOURCE_DIR}/dep/g3dlite/include + ${CMAKE_SOURCE_DIR}/dep/SFMT + ${CMAKE_SOURCE_DIR}/dep/mersennetwister + ${CMAKE_SOURCE_DIR}/dep/zlib + ${CMAKE_SOURCE_DIR}/dep/lualib + ${CMAKE_SOURCE_DIR}/src/server/shared + ${CMAKE_SOURCE_DIR}/src/server/shared/Configuration + ${CMAKE_SOURCE_DIR}/src/server/shared/Cryptography + ${CMAKE_SOURCE_DIR}/src/server/shared/Cryptography/Authentication + ${CMAKE_SOURCE_DIR}/src/server/shared/Database + ${CMAKE_SOURCE_DIR}/src/server/shared/DataStores + ${CMAKE_SOURCE_DIR}/src/server/shared/Debugging + ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic/CountedReference + ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic/LinkedReference + ${CMAKE_SOURCE_DIR}/src/server/shared/Dynamic + ${CMAKE_SOURCE_DIR}/src/server/shared/Logging + ${CMAKE_SOURCE_DIR}/src/server/shared/Packets + ${CMAKE_SOURCE_DIR}/src/server/shared/Policies + ${CMAKE_SOURCE_DIR}/src/server/shared/Threading + ${CMAKE_SOURCE_DIR}/src/server/shared/Utilities + ${CMAKE_SOURCE_DIR}/src/server/collision + ${CMAKE_SOURCE_DIR}/src/server/collision/Management + ${CMAKE_SOURCE_DIR}/src/server/collision/Models + ${CMAKE_SOURCE_DIR}/src/server/collision/Maps + ${CMAKE_SOURCE_DIR}/src/server/shared + ${CMAKE_SOURCE_DIR}/src/server/shared/Database + ${CMAKE_SOURCE_DIR}/src/server/game/Accounts + ${CMAKE_SOURCE_DIR}/src/server/game/Achievements + ${CMAKE_SOURCE_DIR}/src/server/game/Addons + ${CMAKE_SOURCE_DIR}/src/server/game/Handlers + ${CMAKE_SOURCE_DIR}/src/server/game/AI + ${CMAKE_SOURCE_DIR}/src/server/game/AI/CoreAI + ${CMAKE_SOURCE_DIR}/src/server/game/AI/EventAI + ${CMAKE_SOURCE_DIR}/src/server/game/AI/ScriptedAI + ${CMAKE_SOURCE_DIR}/src/server/game/AI/SmartScripts + ${CMAKE_SOURCE_DIR}/src/server/game/AuctionHouse + ${CMAKE_SOURCE_DIR}/src/server/game/Battlegrounds + ${CMAKE_SOURCE_DIR}/src/server/game/Battlegrounds/Zones + ${CMAKE_SOURCE_DIR}/src/server/game/Calendar + ${CMAKE_SOURCE_DIR}/src/server/game/Chat + ${CMAKE_SOURCE_DIR}/src/server/game/Chat/Channels + ${CMAKE_SOURCE_DIR}/src/server/game/Conditions + ${CMAKE_SOURCE_DIR}/src/server/shared/Configuration + ${CMAKE_SOURCE_DIR}/src/server/game/Combat + ${CMAKE_SOURCE_DIR}/src/server/game/DataStores + ${CMAKE_SOURCE_DIR}/src/server/game/DungeonFinding + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/AreaTrigger + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Corpse + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Creature + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/DynamicObject + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Item + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Item/Container + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/GameObject + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Object + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Object/Updates + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Pet + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Player + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Transport + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Unit + ${CMAKE_SOURCE_DIR}/src/server/game/Entities/Vehicle + ${CMAKE_SOURCE_DIR}/src/server/game/Events + ${CMAKE_SOURCE_DIR}/src/server/game/Globals + ${CMAKE_SOURCE_DIR}/src/server/game/Grids + ${CMAKE_SOURCE_DIR}/src/server/game/Grids/Cells + ${CMAKE_SOURCE_DIR}/src/server/game/Grids/Notifiers + ${CMAKE_SOURCE_DIR}/src/server/game/Groups + ${CMAKE_SOURCE_DIR}/src/server/game/Guilds + ${CMAKE_SOURCE_DIR}/src/server/game/Instances + ${CMAKE_SOURCE_DIR}/src/server/game/LookingForGroup + ${CMAKE_SOURCE_DIR}/src/server/game/Loot + ${CMAKE_SOURCE_DIR}/src/server/game/Mails + ${CMAKE_SOURCE_DIR}/src/server/game/Miscellaneous + ${CMAKE_SOURCE_DIR}/src/server/game/Maps + ${CMAKE_SOURCE_DIR}/src/server/game/Movement + ${CMAKE_SOURCE_DIR}/src/server/game/Movement/MovementGenerators + ${CMAKE_SOURCE_DIR}/src/server/game/Movement/Waypoints + ${CMAKE_SOURCE_DIR}/src/server/game/Movement/Spline + ${CMAKE_SOURCE_DIR}/src/server/game/Opcodes + ${CMAKE_SOURCE_DIR}/src/server/game/OutdoorPvP + ${CMAKE_SOURCE_DIR}/src/server/game/Pools + ${CMAKE_SOURCE_DIR}/src/server/game/PrecompiledHeaders + ${CMAKE_SOURCE_DIR}/src/server/game/Quests + ${CMAKE_SOURCE_DIR}/src/server/game/Reputation + ${CMAKE_SOURCE_DIR}/src/server/game/Scripting + ${CMAKE_SOURCE_DIR}/src/server/game/Server + ${CMAKE_SOURCE_DIR}/src/server/game/Server/Protocol + ${CMAKE_SOURCE_DIR}/src/server/game/Server/Protocol/Handlers + ${CMAKE_SOURCE_DIR}/src/server/game/Skills + ${CMAKE_SOURCE_DIR}/src/server/game/Spells + ${CMAKE_SOURCE_DIR}/src/server/game/Spells/Auras + ${CMAKE_SOURCE_DIR}/src/server/game/Texts + ${CMAKE_SOURCE_DIR}/src/server/game/Tickets + ${CMAKE_SOURCE_DIR}/src/server/game/Tools + ${CMAKE_SOURCE_DIR}/src/server/game/Weather + ${CMAKE_SOURCE_DIR}/src/server/game/World + ${CMAKE_SOURCE_DIR}/src/server/scripts/PrecompiledHeaders + ${ACE_INCLUDE_DIR} + ${MYSQL_INCLUDE_DIR} + ${OPENSSL_INCLUDE_DIR} +) + +add_library(LuaEngine STATIC + ${LuaEngine_STAT_SRCS} + ${game_STAT_SRCS} + ${game_STAT_PCH_SRC} +) + +target_link_libraries(LuaEngine + game +) + +add_dependencies(LuaEngine game) \ No newline at end of file diff --git a/CorpseMethods.h b/CorpseMethods.h new file mode 100644 index 0000000..1de01bc --- /dev/null +++ b/CorpseMethods.h @@ -0,0 +1,58 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaCorpse +{ + // GetOwnerGUID() + int GetOwnerGUID(lua_State* L, Corpse* corpse) + { +#ifdef MANGOS + sEluna->Push(L, corpse->GetOwnerGuid()); +#else + sEluna->Push(L, corpse->GetOwnerGUID()); +#endif + return 1; + } + + // GetGhostTime() + int GetGhostTime(lua_State* L, Corpse* corpse) + { + sEluna->Push(L, uint32(corpse->GetGhostTime())); + return 1; + } + + // GetType() + int GetType(lua_State* L, Corpse* corpse) + { + sEluna->Push(L, corpse->GetType()); + return 1; + } + + // ResetGhostTime() + int ResetGhostTime(lua_State* L, Corpse* corpse) + { + corpse->ResetGhostTime(); + return 0; + } + + // SaveToDB() + int SaveToDB(lua_State* L, Corpse* corpse) + { + corpse->SaveToDB(); + return 0; + } + + // DeleteBonesFromWorld() + int DeleteBonesFromWorld(lua_State* L, Corpse* corpse) + { + corpse->DeleteBonesFromWorld(); + return 0; + } +}; +#endif diff --git a/CreatureMethods.h b/CreatureMethods.h new file mode 100644 index 0000000..5eb6177 --- /dev/null +++ b/CreatureMethods.h @@ -0,0 +1,679 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaCreature +{ + /* BOOLEAN */ + int IsReputationGainDisabled(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsReputationGainDisabled()); + return 1; + } + + int IsRegeneratingHealth(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->IsRegeneratingHealth()); +#else + sEluna->Push(L, creature->isRegeneratingHealth()); +#endif + return 1; + } + + int HasInvolvedQuest(lua_State* L, Creature* creature) + { + uint32 quest_id = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + sEluna->Push(L, creature->HasInvolvedQuest(quest_id)); +#else + sEluna->Push(L, creature->hasInvolvedQuest(quest_id)); +#endif + return 1; + } + + int IsTargetAcceptable(lua_State* L, Creature* creature) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, creature->isTargetableForAttack(target)); + return 1; + } + + int CanAssistTo(lua_State* L, Creature* creature) + { + Unit* u = sEluna->CHECKOBJ(L, 2); + Unit* enemy = sEluna->CHECKOBJ(L, 3); + bool checkfaction = sEluna->CHECKVAL(L, 4, true); + + sEluna->Push(L, creature->CanAssistTo(u, enemy, checkfaction)); + return 1; + } + + int HasSearchedAssistance(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->HasSearchedAssistance()); + return 1; + } + + int IsTappedBy(lua_State* L, Creature* creature) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, creature->isTappedBy(player)); + return 1; + } + + int HasLootRecipient(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->HasLootRecipient()); +#else + sEluna->Push(L, creature->hasLootRecipient()); +#endif + return 1; + } + + int HasReactState(lua_State* L, Creature* creature) + { + int32 state = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + sEluna->Push(L, creature->GetCharmInfo()->HasReactState((ReactStates)state)); +#else + sEluna->Push(L, creature->HasReactState((ReactStates)state)); +#endif + return 1; + } + + int CanSwim(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->CanSwim()); + return 1; + } + + int CanWalk(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->CanWalk()); + return 1; + } + + int IsInEvadeMode(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsInEvadeMode()); + return 1; + } + + int IsElite(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->IsElite()); +#else + sEluna->Push(L, creature->isElite()); +#endif + return 1; + } + + int IsGuard(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsGuard()); + return 1; + } + + int IsCivilian(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsCivilian()); + return 1; + } + + int IsRacialLeader(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsRacialLeader()); + return 1; + } + + int IsWorldBoss(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->IsWorldBoss()); +#else + sEluna->Push(L, creature->isWorldBoss()); +#endif + return 1; + } + + int HasCategoryCooldown(lua_State* L, Creature* creature) + { + uint32 spell = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, creature->HasCategoryCooldown(spell)); + return 1; + } + + int HasSpell(lua_State* L, Creature* creature) + { + uint32 id = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, creature->HasSpell(id)); + return 1; + } + + int HasQuest(lua_State* L, Creature* creature) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + sEluna->Push(L, creature->HasQuest(questId)); +#else + sEluna->Push(L, creature->hasQuest(questId)); +#endif + return 1; + } + + int HasSpellCooldown(lua_State* L, Creature* creature) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, creature->HasSpellCooldown(spellId)); + return 1; + } + + int CanFly(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->CanFly()); + return 1; + } + + /*int IsTrigger(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsTrigger()); + return 1; + }*/ + + /*int IsDamageEnoughForLootingAndReward(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->IsDamageEnoughForLootingAndReward()); + return 1; + }*/ + + /*int CanStartAttack(lua_State* L, Creature* creature) // TODO: Implement core side + { + Unit* target = sEluna->CHECKOBJ(L, 2); + bool force = sEluna->CHECKVAL(L, 3, true); + + sEluna->Push(L, creature->CanStartAttack(target, force)); + return 1; + }*/ + + /*int HasLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + uint16 lootMode = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, creature->HasLootMode(lootMode)); + return 1; + }*/ + + /* GETTERS */ + int GetRespawnDelay(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetRespawnDelay()); + return 1; + } + + int GetRespawnRadius(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetRespawnRadius()); + return 1; + } + + int GetDefaultMovementType(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetDefaultMovementType()); + return 1; + } + + int GetAggroRange(lua_State* L, Creature* creature) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, creature->GetAttackDistance(target)); + return 1; + } + + int GetAttackDistance(lua_State* L, Creature* creature) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, creature->GetAttackDistance(target)); + return 1; + } + + int GetLootRecipientGroup(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->GetGroupLootRecipient()); +#else + sEluna->Push(L, creature->GetLootRecipientGroup()); +#endif + return 1; + } + + int GetLootRecipient(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetLootRecipient()); + return 1; + } + + int GetReactState(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->GetCharmInfo()->GetReactState()); +#else + sEluna->Push(L, creature->GetReactState()); +#endif + return 1; + } + + int GetScriptName(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetScriptName()); + return 1; + } + + int GetAIName(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetAIName()); + return 1; + } + + int GetScriptId(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetScriptId()); + return 1; + } + + int GetCreatureSpellCooldownDelay(lua_State* L, Creature* creature) + { + uint32 spell = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, creature->GetCreatureSpellCooldownDelay(spell)); + return 1; + } + + int GetCorpseDelay(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetCorpseDelay()); + return 1; + } + + int GetHomePosition(lua_State* L, Creature* creature) + { + float x, y, z, o; +#ifdef MANGOS + creature->GetRespawnCoord(x, y, z, &o); +#else + creature->GetHomePosition(x, y, z, o); +#endif + + sEluna->Push(L, x); + sEluna->Push(L, y); + sEluna->Push(L, z); + sEluna->Push(L, o); + return 4; + } + + int GetAITarget(lua_State* L, Creature* creature) + { + uint32 targetType = sEluna->CHECKVAL(L, 2); + bool playerOnly = sEluna->CHECKVAL(L, 3, false); + uint32 position = sEluna->CHECKVAL(L, 4, 0); + float dist = sEluna->CHECKVAL(L, 5, 0.0f); + int32 aura = sEluna->CHECKVAL(L, 6, 0); + + ThreatList const& threatlist = creature->getThreatManager().getThreatList(); + if (position >= threatlist.size()) + { + sEluna->Push(L); + return 1; + } + + std::list targetList; + for (ThreatList::const_iterator 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; + targetList.push_back(target); + } + + if (position >= targetList.size()) + { + sEluna->Push(L); + return 1; + } + + if (targetType == SELECT_TARGET_NEAREST || targetType == SELECT_TARGET_FARTHEST) + targetList.sort(Eluna::ObjectDistanceOrderPred(creature)); + + switch (targetType) + { + case SELECT_TARGET_NEAREST: + case SELECT_TARGET_TOPAGGRO: + { + std::list::const_iterator itr = targetList.begin(); + std::advance(itr, position); + sEluna->Push(L, *itr); + return 1; + } + case SELECT_TARGET_FARTHEST: + case SELECT_TARGET_BOTTOMAGGRO: + { + std::list::reverse_iterator ritr = targetList.rbegin(); + std::advance(ritr, position); + sEluna->Push(L, *ritr); + return 1; + } + case SELECT_TARGET_RANDOM: + { + std::list::const_iterator itr = targetList.begin(); + std::advance(itr, urand(position, targetList.size() - 1)); + sEluna->Push(L, *itr); + return 1; + } + default: + luaL_argerror(L, 2, "SelectAggroTarget expected"); + } + + sEluna->Push(L); + return 1; + } + + int GetAITargets(lua_State* L, Creature* creature) + { + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + ThreatList const& threatList = creature->getThreatManager().getThreatList(); + ThreatList::const_iterator itr; + for (itr = threatList.begin(); itr != threatList.end(); ++itr) + { + Unit* target = (*itr)->getTarget(); + if (!target) + continue; + ++i; + sEluna->Push(L, i); + sEluna->Push(L, target); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetAITargetsCount(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->getThreatManager().getThreatList().size()); + return 1; + } + + int GetNPCFlags(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetUInt32Value(UNIT_NPC_FLAGS)); + return 1; + } + +#ifndef CATA + int GetShieldBlockValue(lua_State* L, Creature* creature) + { + sEluna->Push(L, creature->GetShieldBlockValue()); + return 1; + } +#endif + + /*int GetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + sEluna->Push(L, creature->GetLootMode()); + return 1; + }*/ + + /* SETTERS */ + int SetNPCFlags(lua_State* L, Creature* creature) + { + uint32 flags = sEluna->CHECKVAL(L, 2); + + creature->SetUInt32Value(UNIT_NPC_FLAGS, flags); + return 0; + } + + int SetDeathState(lua_State* L, Creature* creature) + { + int32 state = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + creature->SetDeathState((DeathState)state); +#else + creature->setDeathState((DeathState)state); +#endif + return 0; + } + + int SetWalk(lua_State* L, Creature* creature) // TODO: Move same to Player ? + { + bool enable = sEluna->CHECKVAL(L, 2, true); + + creature->SetWalk(enable); + return 0; + } + + int SetReactState(lua_State* L, Creature* creature) + { + int32 state = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + creature->GetCharmInfo()->SetReactState((ReactStates)state); +#else + creature->SetReactState((ReactStates)state); +#endif + return 0; + } + + int SetDisableReputationGain(lua_State* L, Creature* creature) + { + bool disable = sEluna->CHECKVAL(L, 2, true); + + creature->SetDisableReputationGain(disable); + return 0; + } + + int SetInCombatWithZone(lua_State* L, Creature* creature) + { + creature->SetInCombatWithZone(); + return 0; + } + + int SetRespawnRadius(lua_State* L, Creature* creature) + { + float dist = sEluna->CHECKVAL(L, 2); + + creature->SetRespawnRadius(dist); + return 0; + } + + int SetRespawnDelay(lua_State* L, Creature* creature) + { + uint32 delay = sEluna->CHECKVAL(L, 2); + + creature->SetRespawnDelay(delay); + return 0; + } + + int SetDefaultMovementType(lua_State* L, Creature* creature) + { + int32 type = sEluna->CHECKVAL(L, 2); + + creature->SetDefaultMovementType((MovementGeneratorType)type); + return 0; + } + + int SetNoSearchAssistance(lua_State* L, Creature* creature) + { + bool val = sEluna->CHECKVAL(L, 2, true); + + creature->SetNoSearchAssistance(val); + return 0; + } + + int SetNoCallAssistance(lua_State* L, Creature* creature) + { + bool val = sEluna->CHECKVAL(L, 2, true); + + creature->SetNoCallAssistance(val); + return 0; + } + + int SetHover(lua_State* L, Creature* creature) + { + bool enable = sEluna->CHECKVAL(L, 2, true); + +#ifdef MANGOS + creature->SetLevitate(enable); +#else + creature->SetHover(enable); +#endif + return 0; + } + + /*int SetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + uint16 lootMode = sEluna->CHECKVAL(L, 2); + + creature->SetLootMode(lootMode); + return 0; + }*/ + + /*int SetDisableGravity(lua_State* L, Creature* creature) + { + bool disable = sEluna->CHECKVAL(L, 2, true); + bool packetOnly = sEluna->CHECKVAL(L, 3, false); + + sEluna->Push(L, creature->SetDisableGravity(disable, packetOnly)); + return 1; + }*/ + + /* OTHER */ + int DespawnOrUnsummon(lua_State* L, Creature* creature) + { + uint32 msTimeToDespawn = sEluna->CHECKVAL(L, 2, 0); + +#ifdef MANGOS + creature->ForcedDespawn(msTimeToDespawn); +#else + creature->DespawnOrUnsummon(msTimeToDespawn); +#endif + return 0; + } + + int Respawn(lua_State* L, Creature* creature) + { + creature->Respawn(); + return 0; + } + + int RemoveCorpse(lua_State* L, Creature* creature) + { + creature->RemoveCorpse(); + return 0; + } + + int MoveWaypoint(lua_State* L, Creature* creature) + { +#ifdef MANGOS + creature->GetMotionMaster()->MoveWaypoint(); +#else + creature->GetMotionMaster()->MovePath(creature->GetWaypointPath(), true); +#endif + return 0; + } + + int CallAssistance(lua_State* L, Creature* creature) + { + creature->CallAssistance(); + return 0; + } + + int CallForHelp(lua_State* L, Creature* creature) + { + float radius = sEluna->CHECKVAL(L, 2); + + creature->CallForHelp(radius); + return 0; + } + + int FleeToGetAssistance(lua_State* L, Creature* creature) + { + creature->DoFleeToGetAssistance(); + return 0; + } + + int AttackStart(lua_State* L, Creature* creature) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + + creature->AI()->AttackStart(target); + return 0; + } + + int SaveToDB(lua_State* L, Creature* creature) + { + creature->SaveToDB(); + return 0; + } + + int SelectVictim(lua_State* L, Creature* creature) + { +#ifdef MANGOS + sEluna->Push(L, creature->SelectHostileTarget()); +#else + sEluna->Push(L, creature->SelectVictim()); +#endif + return 1; + } + + /*int ResetLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + creature->ResetLootMode(); + return 0; + }*/ + + /*int RemoveLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + uint16 lootMode = sEluna->CHECKVAL(L, 2); + + creature->RemoveLootMode(lootMode); + return 0; + }*/ + + /*int AddLootMode(lua_State* L, Creature* creature) // TODO: Implement LootMode features + { + uint16 lootMode = sEluna->CHECKVAL(L, 2); + + creature->AddLootMode(lootMode); + return 0; + }*/ +}; +#endif diff --git a/GameObjectMethods.h b/GameObjectMethods.h new file mode 100644 index 0000000..0cecd60 --- /dev/null +++ b/GameObjectMethods.h @@ -0,0 +1,207 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaGameObject +{ + /* BOOLEAN */ + int HasQuest(lua_State* L, GameObject* go) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + sEluna->Push(L, go->HasQuest(questId)); +#else + sEluna->Push(L, go->hasQuest(questId)); +#endif + return 1; + } + + int IsSpawned(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + sEluna->Push(L, false); + else + sEluna->Push(L, go->isSpawned()); + return 1; + } + + int IsTransport(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + sEluna->Push(L, false); + else + sEluna->Push(L, go->IsTransport()); + return 1; + } + + int IsActive(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + sEluna->Push(L, false); + else + sEluna->Push(L, go->isActiveObject()); + return 1; + } + + /*int IsDestructible(lua_State* L, GameObject* go) // TODO: Implementation core side + { + if (!go || !go->IsInWorld()) + sEluna->Push(L, false); + else + sEluna->Push(L, go->IsDestructibleBuilding()); + return 1; + }*/ + + /* GETTERS */ + int GetDisplayId(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + sEluna->Push(L, go->GetDisplayId()); + return 1; + } + + int GetGoState(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + sEluna->Push(L, go->GetGoState()); + return 1; + } + + int GetLootState(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + sEluna->Push(L, go->getLootState()); + return 1; + } + + /* SETTERS */ + int SetGoState(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + uint32 state = sEluna->CHECKVAL(L, 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; + } + + int SetLootState(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + uint32 state = sEluna->CHECKVAL(L, 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; + } + + /* OTHER */ + int SaveToDB(lua_State* L, GameObject* go) + { + go->SaveToDB(); + return 0; + } + + int RemoveFromWorld(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + bool del = sEluna->CHECKVAL(L, 2, false); + if (del) + go->DeleteFromDB(); + go->RemoveFromWorld(); + return 0; + } + + int RegisterEvent(lua_State* L, GameObject* go) + { + luaL_checktype(L, 2, LUA_TFUNCTION); + uint32 delay = sEluna->CHECKVAL(L, 3); + uint32 repeats = sEluna->CHECKVAL(L, 4); + + lua_settop(L, 2); + int functionRef = lua_ref(L, true); + functionRef = sEluna->m_EventMgr.AddEvent(&go->m_Events, functionRef, delay, repeats, go); + if (functionRef) + sEluna->Push(L, functionRef); + else + sEluna->Push(L); + return 1; + } + + int RemoveEventById(lua_State* L, GameObject* go) + { + int eventId = sEluna->CHECKVAL(L, 2); + sEluna->m_EventMgr.RemoveEvent(&go->m_Events, eventId); + return 0; + } + + int RemoveEvents(lua_State* L, GameObject* go) + { + sEluna->m_EventMgr.RemoveEvents(&go->m_Events); + return 0; + } + + int UseDoorOrButton(lua_State* L, GameObject* go) + { + if (!go || !go->IsInWorld()) + return 0; + + uint32 delay = sEluna->CHECKVAL(L, 2, 0); + + go->UseDoorOrButton(delay); + return 0; + } + + int Despawn(lua_State* L, GameObject* go) + { + uint32 delay = sEluna->CHECKVAL(L, 2, 1); + if (!delay) + delay = 1; + + go->SetSpawnedByDefault(false); + go->SetRespawnTime(delay); + return 0; + } + + int Respawn(lua_State* L, GameObject* go) + { + uint32 delay = sEluna->CHECKVAL(L, 2, 1); + if (!delay) + delay = 1; + + go->SetSpawnedByDefault(true); + go->SetRespawnTime(delay); + return 0; + } +}; +#endif diff --git a/GlobalMethods.h b/GlobalMethods.h new file mode 100644 index 0000000..fd91afe --- /dev/null +++ b/GlobalMethods.h @@ -0,0 +1,1167 @@ +/* +* Copyright (C) 2010 - 2014 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 + +extern bool StartEluna(); + +namespace LuaGlobalFunctions +{ + /* GETTERS */ + int GetLuaEngine(lua_State* L) + { + sEluna->Push(L, "ElunaEngine"); + return 1; + } + + int GetCoreName(lua_State* L) + { + sEluna->Push(L, CORE_NAME); + return 1; + } + + int GetCoreVersion(lua_State* L) + { + sEluna->Push(L, CORE_VERSION); + return 1; + } + + int GetQuest(lua_State* L) + { + uint32 questId = sEluna->CHECKVAL(L, 1); + + sEluna->Push(L, sObjectMgr->GetQuestTemplate(questId)); + return 1; + } + + int GetPlayerByGUID(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, sObjectAccessor->FindPlayer(GUID_TYPE(guid))); + return 1; + } + + int GetPlayerByName(lua_State* L) + { + const char* message = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, sObjectAccessor->FindPlayerByName(message)); + return 1; + } + + int GetGameTime(lua_State* L) + { + time_t time = sWorld->GetGameTime(); + if (time < 0) + sEluna->Push(L, int32(time)); + else + sEluna->Push(L, uint32(time)); + return 1; + } + + int GetPlayersInWorld(lua_State* L) + { + uint32 team = sEluna->CHECKVAL(L, 1, TEAM_NEUTRAL); + bool onlyGM = sEluna->CHECKVAL(L, 2, false); + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + SessionMap const& sessions = sWorld->GetAllSessions(); + for (SessionMap::const_iterator it = sessions.begin(); it != sessions.end(); ++it) + { + if (Player* player = it->second->GetPlayer()) + { +#ifdef MANGOS + if (player->GetSession() && ((team >= TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->isGameMaster()))) +#else + if (player->GetSession() && ((team >= TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGameMaster()))) +#endif + { + ++i; + sEluna->Push(L, i); + sEluna->Push(L, player); + lua_settable(L, tbl); + } + } + } + + lua_settop(L, tbl); // push table to top of stack + return 1; + } + + int GetPlayersInMap(lua_State* L) + { + uint32 mapID = sEluna->CHECKVAL(L, 1); + uint32 instanceID = sEluna->CHECKVAL(L, 2, 0); + uint32 team = sEluna->CHECKVAL(L, 3, TEAM_NEUTRAL); + + Map* map = sMapMgr->FindMap(mapID, instanceID); + if (!map) + return 0; + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + Map::PlayerList const& players = map->GetPlayers(); + for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) + { +#ifdef MANGOS + Player* player = itr->getSource(); +#else + Player* player = itr->GetSource(); +#endif + if (!player) + continue; + if (player->GetSession() && (team >= TEAM_NEUTRAL || player->GetTeamId() == team)) + { + ++i; + sEluna->Push(L, i); + sEluna->Push(L, player); + lua_settable(L, tbl); + } + } + + lua_settop(L, tbl); + return 1; + } + + int GetGuildByName(lua_State* L) + { + const char* name = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, sGuildMgr->GetGuildByName(name)); + return 1; + } + + int GetMapById(lua_State* L) + { + uint32 mapid = sEluna->CHECKVAL(L, 1); + uint32 instance = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, sMapMgr->FindMap(mapid, instance)); + return 1; + } + + int GetGuildByLeaderGUID(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + + sEluna->Push(L, sGuildMgr->GetGuildByLeader(GUID_TYPE(guid))); + return 1; + } + + int GetPlayerCount(lua_State* L) + { + sEluna->Push(L, sWorld->GetActiveSessionCount()); + return 1; + } + + int GetPlayerGUID(lua_State* L) + { + uint32 lowguid = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_PLAYER)); + return 1; + } + + int GetItemGUID(lua_State* L) + { + uint32 lowguid = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, MAKE_NEW_GUID(lowguid, 0, HIGHGUID_ITEM)); + return 1; + } + + int GetObjectGUID(lua_State* L) + { + uint32 lowguid = sEluna->CHECKVAL(L, 1); + uint32 entry = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_GAMEOBJECT)); + return 1; + } + + int GetUnitGUID(lua_State* L) + { + uint32 lowguid = sEluna->CHECKVAL(L, 1); + uint32 entry = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, MAKE_NEW_GUID(lowguid, entry, HIGHGUID_UNIT)); + return 1; + } + + int GetGUIDLow(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + + sEluna->Push(L, GUID_LOPART(guid)); + return 1; + } + + int GetItemLink(lua_State* L) + { + /* + 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 + */ + uint32 entry = sEluna->CHECKVAL(L, 1); + int loc_idx = sEluna->CHECKVAL(L, 2, DEFAULT_LOCALE); + if (loc_idx < 0 || loc_idx >= MAX_LOCALES) + return luaL_argerror(L, 2, "valid LocaleConstant expected"); + + const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry); + if (!temp) + return luaL_argerror(L, 1, "valid ItemEntry expected"); + + std::string name = temp->Name1; + if (ItemLocale const* il = sObjectMgr->GetItemLocale(entry)) + ObjectMgr::GetLocaleString(il->Name, loc_idx, name); + + std::ostringstream oss; + oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec << + "|Hitem:" << entry << ":0:0:0:0:0:0:0:0:0|h[" << name << "]|h|r"; + + sEluna->Push(L, oss.str()); + return 1; + } + + int GetGUIDType(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, GUID_HIPART(guid)); + return 1; + } + + int GetGUIDEntry(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, GUID_ENPART(guid)); + return 1; + } + + /* OTHER */ + int RegisterPacketEvent(lua_State* L) + { + lua_settop(L, 2); + uint32 ev = sEluna->CHECKVAL(L, 1); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_PACKET, 0, ev, functionRef); + return 0; + } + + int RegisterServerEvent(lua_State* L) + { + lua_settop(L, 2); + uint32 ev = sEluna->CHECKVAL(L, 1); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_SERVER, 0, ev, functionRef); + return 0; + } + + int RegisterPlayerEvent(lua_State* L) + { + lua_settop(L, 2); + uint32 ev = sEluna->CHECKVAL(L, 1); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_PLAYER, 0, ev, functionRef); + return 0; + } + + int RegisterGuildEvent(lua_State* L) + { + lua_settop(L, 2); + uint32 ev = sEluna->CHECKVAL(L, 1); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_GUILD, 0, ev, functionRef); + return 0; + } + + int RegisterGroupEvent(lua_State* L) + { + lua_settop(L, 2); + uint32 ev = sEluna->CHECKVAL(L, 1); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_GROUP, 0, ev, functionRef); + return 0; + } + + int RegisterCreatureGossipEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_CREATURE_GOSSIP, entry, ev, functionRef); + return 0; + } + + int RegisterGameObjectGossipEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_GAMEOBJECT_GOSSIP, entry, ev, functionRef); + return 0; + } + + int RegisterItemEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_ITEM, entry, ev, functionRef); + return 0; + } + + int RegisterItemGossipEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_ITEM_GOSSIP, entry, ev, functionRef); + return 0; + } + + int RegisterPlayerGossipEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 menu_id = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_PLAYER_GOSSIP, menu_id, ev, functionRef); + return 0; + } + + int RegisterCreatureEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_CREATURE, entry, ev, functionRef); + return 0; + } + + int RegisterGameObjectEvent(lua_State* L) + { + lua_settop(L, 3); + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 ev = sEluna->CHECKVAL(L, 2); + luaL_checktype(L, lua_gettop(L), LUA_TFUNCTION); + int functionRef = lua_ref(L, true); + if (functionRef > 0) + sEluna->Register(REGTYPE_GAMEOBJECT, entry, ev, functionRef); + return 0; + } + + int ReloadEluna(lua_State* L) + { + sEluna->Push(L, StartEluna()); + return 1; + } + + int SendWorldMessage(lua_State* L) + { + const char* message = sEluna->CHECKVAL(L, 1); + sWorld->SendServerMessage(SERVER_MSG_STRING, message); + return 0; + } + + int WorldDBQuery(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + if (!query) + return 0; + + QueryResult* result = NULL; +#ifdef MANGOS + result = WorldDatabase.Query(query); +#else + QueryResult res = WorldDatabase.Query(query); + if (res) + result = new QueryResult(res); +#endif + if (!result) + return 0; + + sEluna->Push(L, result); + return 1; + } + + int WorldDBExecute(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + WorldDatabase.Execute(query); + return 0; + } + + int CharDBQuery(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + + QueryResult* result = NULL; +#ifdef MANGOS + result = CharacterDatabase.Query(query); +#else + QueryResult res = CharacterDatabase.Query(query); + if (res) + result = new QueryResult(res); +#endif + if (!result) + return 0; + + sEluna->Push(L, result); + return 1; + } + + int CharDBExecute(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + CharacterDatabase.Execute(query); + return 0; + } + + int AuthDBQuery(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + + QueryResult* result = NULL; +#ifdef MANGOS + result = LoginDatabase.Query(query); +#else + QueryResult res = LoginDatabase.Query(query); + if (res) + result = new QueryResult(res); +#endif + if (!result) + return 0; + + sEluna->Push(L, result); + return 1; + } + + int AuthDBExecute(lua_State* L) + { + const char* query = sEluna->CHECKVAL(L, 1); + LoginDatabase.Execute(query); + return 0; + } + + int CreateLuaEvent(lua_State* L) + { + luaL_checktype(L, 1, LUA_TFUNCTION); + uint32 delay = sEluna->CHECKVAL(L, 2); + uint32 repeats = sEluna->CHECKVAL(L, 3); + + lua_settop(L, 1); + int functionRef = lua_ref(L, true); + functionRef = sEluna->m_EventMgr.AddEvent(&sEluna->m_EventMgr.GlobalEvents, functionRef, delay, repeats); + if (functionRef) + sEluna->Push(L, functionRef); + else + sEluna->Push(L); + return 1; + } + + int RemoveEventById(lua_State* L) + { + int eventId = sEluna->CHECKVAL(L, 1); + bool all_Events = sEluna->CHECKVAL(L, 1, false); + + if (all_Events) + sEluna->m_EventMgr.RemoveEvent(eventId); + else + sEluna->m_EventMgr.RemoveEvent(&sEluna->m_EventMgr.GlobalEvents, eventId); + return 0; + } + + int RemoveEvents(lua_State* L) + { + bool all_Events = sEluna->CHECKVAL(L, 1, false); + + if (all_Events) + sEluna->m_EventMgr.RemoveEvents(); + else + sEluna->m_EventMgr.GlobalEvents.KillAllEvents(true); + return 0; + } + + int PerformIngameSpawn(lua_State* L) + { + int spawntype = sEluna->CHECKVAL(L, 1); + uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 mapID = sEluna->CHECKVAL(L, 3); + uint32 instanceID = sEluna->CHECKVAL(L, 4); + float x = sEluna->CHECKVAL(L, 5); + float y = sEluna->CHECKVAL(L, 6); + float z = sEluna->CHECKVAL(L, 7); + float o = sEluna->CHECKVAL(L, 8); + bool save = sEluna->CHECKVAL(L, 9, false); + uint32 durorresptime = sEluna->CHECKVAL(L, 10, 0); +#ifndef TBC + uint32 phase = sEluna->CHECKVAL(L, 11, PHASEMASK_NORMAL); + if (!phase) + return 0; +#endif + +#ifdef MANGOS + Map* map = sMapMgr->FindMap(mapID, instanceID); + if (!map) + return 0; + + if (spawntype == 1) // spawn creature + { + if (save) + { + CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); + if (!cinfo) + return 0; + +#ifdef TBC + 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 = sObjectMgr->GenerateStaticCreatureLowGuid(); + if (!lowguid) + return 0; + + if (!pCreature->Create(lowguid, pos, cinfo)) + { + delete pCreature; + return 0; + } + +#ifdef TBC + pCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode())); +#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); + sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid)); + if (durorresptime) + pCreature->ForcedDespawn(durorresptime); + + sEluna->Push(L, pCreature); + } + else + { + CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); + if (!cinfo) + return 0; + + TemporarySummon* pCreature = new TemporarySummon(GUID_TYPE(uint64(0))); +#ifdef TBC + 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; + return NULL; + } + + pCreature->SetRespawnCoord(pos); + + // Active state set before added to map + pCreature->SetActiveObjectState(false); + + // Also initializes the AI and MMGen + pCreature->Summon(durorresptime ? TEMPSUMMON_TIMED_OR_DEAD_DESPAWN : TEMPSUMMON_MANUAL_DESPAWN, durorresptime); + + // Creature Linking, Initial load is handled like respawn + if (pCreature->IsLinkingEventTrigger()) + map->GetCreatureLinkingHolder()->DoCreatureLinkingEvent(LINKING_EVENT_RESPAWN, pCreature); + + sEluna->Push(L, pCreature); + } + + return 1; + } + + if (spawntype == 2) // Spawn object + { + if (save) + { + const GameObjectInfo* gInfo = ObjectMgr::GetGameObjectInfo(entry); + if (!gInfo) + return 0; + + // used guids from specially reserved range (can be 0 if no free values) + uint32 db_lowGUID = sObjectMgr->GenerateStaticGameObjectLowGuid(); + if (!db_lowGUID) + return 0; + + GameObject* pGameObj = new GameObject; +#ifdef TBC + 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; + return 0; + } + + if (durorresptime) + pGameObj->SetRespawnTime(durorresptime); + + // fill the gameobject data and save to the db +#ifdef TBC + pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode())); +#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; + return false; + } + + // DEBUG_LOG(GetMangosString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o); + + map->Add(pGameObj); + + sObjectMgr->AddGameobjectToGrid(db_lowGUID, sObjectMgr->GetGOData(db_lowGUID)); + + sEluna->Push(L, pGameObj); + } + else + { + GameObject* pGameObj = new GameObject; + +#ifdef TBC + 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; + return NULL; + } + + pGameObj->SetRespawnTime(durorresptime / IN_MILLISECONDS); + + map->Add(pGameObj); + + sEluna->Push(L, pGameObj); + } + return 1; + } +#else + Map* map = sMapMgr->FindMap(mapID, instanceID); + if (!map) + return 0; + + Position pos = { x, y, z, o }; + + if (spawntype == 1) // spawn creature + { + if (save) + { + Creature* creature = new Creature(); + if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, phase, entry, 0, 0, x, y, z, o)) + { + delete creature; + return 0; + } + + creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); + + uint32 db_lowguid = creature->GetDBTableGUIDLow(); + if (!creature->LoadCreatureFromDB(db_lowguid, map)) + { + delete creature; + return 0; + } + + sObjectMgr->AddCreatureToGrid(db_lowguid, sObjectMgr->GetCreatureData(db_lowguid)); + sEluna->Push(L, creature); + } + else + { + TempSummon* creature = map->SummonCreature(entry, pos, NULL, durorresptime); + if (!creature) + return 0; + + if (durorresptime) + creature->SetTempSummonType(TEMPSUMMON_TIMED_OR_DEAD_DESPAWN); + else + creature->SetTempSummonType(TEMPSUMMON_MANUAL_DESPAWN); + + sEluna->Push(L, creature); + } + + return 1; + } + + if (spawntype == 2) // Spawn object + { + const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(entry); + if (!objectInfo) + return 0; + + if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId)) + return 0; + + GameObject* object = new GameObject; + uint32 lowguid = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT); + + if (!object->Create(lowguid, objectInfo->entry, map, phase, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY)) + { + delete object; + return 0; + } + + if (durorresptime) + object->SetRespawnTime(durorresptime); + + if (save) + { + // fill the gameobject data and save to the db + object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), phase); + + // this will generate a new lowguid if the object is in an instance + if (!object->LoadGameObjectFromDB(lowguid, map)) + { + delete object; + return false; + } + + sObjectMgr->AddGameobjectToGrid(lowguid, sObjectMgr->GetGOData(lowguid)); + } + else + map->AddToMap(object); + sEluna->Push(L, object); + return 1; + } +#endif + return 0; + } + + // CreatePacket(opcode, size) + int CreatePacket(lua_State* L) + { + uint32 opcode = sEluna->CHECKVAL(L, 1); + uint32 size = sEluna->CHECKVAL(L, 2); + if (opcode >= NUM_MSG_TYPES) + return luaL_argerror(L, 1, "valid opcode expected"); + + sEluna->Push(L, new WorldPacket((Opcodes)opcode, size)); + return 1; + } + + int AddVendorItem(lua_State* L) + { + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 item = sEluna->CHECKVAL(L, 2); + int maxcount = sEluna->CHECKVAL(L, 3); + uint32 incrtime = sEluna->CHECKVAL(L, 4); + uint32 extendedcost = sEluna->CHECKVAL(L, 5); + +#ifdef MANGOS + if (!sObjectMgr->IsVendorItemValid(false, "npc_vendor", entry, item, maxcount, incrtime, extendedcost, 0)) + return 0; + sObjectMgr->AddVendorItem(entry, item, maxcount, incrtime, extendedcost); +#else +#ifdef CATA + if (!sObjectMgr->IsVendorItemValid(entry, item, maxcount, incrtime, extendedcost, 1)) + return 0; + sObjectMgr->AddVendorItem(entry, item, maxcount, incrtime, extendedcost, 1); +#else + if (!sObjectMgr->IsVendorItemValid(entry, item, maxcount, incrtime, extendedcost)) + return 0; + sObjectMgr->AddVendorItem(entry, item, maxcount, incrtime, extendedcost); +#endif +#endif + return 0; + } + + int VendorRemoveItem(lua_State* L) + { + uint32 entry = sEluna->CHECKVAL(L, 1); + uint32 item = sEluna->CHECKVAL(L, 2); + if (!sObjectMgr->GetCreatureTemplate(entry)) + return luaL_argerror(L, 1, "valid CreatureEntry expected"); + +#ifdef CATA + sObjectMgr->RemoveVendorItem(entry, item, 1); +#else + sObjectMgr->RemoveVendorItem(entry, item); +#endif + return 0; + } + + int VendorRemoveAllItems(lua_State* L) + { + uint32 entry = sEluna->CHECKVAL(L, 1); + + VendorItemData const* items = sObjectMgr->GetNpcVendorItemList(entry); + if (!items || items->Empty()) + return 0; + + VendorItemList const itemlist = items->m_items; + for (VendorItemList::const_iterator itr = itemlist.begin(); itr != itemlist.end(); ++itr) +#ifdef CATA + sObjectMgr->RemoveVendorItem(entry, (*itr)->item, 1); +#else + sObjectMgr->RemoveVendorItem(entry, (*itr)->item); +#endif + return 0; + } + + int Kick(lua_State* L) + { + Player* player = sEluna->CHECKOBJ(L, 1); + player->GetSession()->KickPlayer(); + return 0; + } + + int Ban(lua_State* L) + { + int banMode = sEluna->CHECKVAL(L, 1); + const char* nameOrIP_cstr = sEluna->CHECKVAL(L, 2); + uint32 duration = sEluna->CHECKVAL(L, 3); + const char* reason = sEluna->CHECKVAL(L, 4); + Player* whoBanned = sEluna->CHECKOBJ(L, 5); + std::string nameOrIP(nameOrIP_cstr); + + switch (banMode) + { + case BAN_ACCOUNT: + if (!AccountMgr::normalizeString(nameOrIP)) + return 0; + break; + case BAN_CHARACTER: + if (!normalizePlayerName(nameOrIP)) + return 0; + break; + case BAN_IP: + if (!IsIPAddress(nameOrIP.c_str())) + return 0; + break; + default: + return 0; + } + + switch (sWorld->BanAccount((BanMode)banMode, nameOrIP, duration, reason, whoBanned->GetSession() ? whoBanned->GetName() : "")) + { + case BAN_SUCCESS: + if (duration > 0) + ChatHandler(whoBanned->GetSession()).PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(duration, true).c_str(), reason); + else + ChatHandler(whoBanned->GetSession()).PSendSysMessage(LANG_BAN_YOUPERMBANNED, nameOrIP.c_str(), reason); + break; + case BAN_SYNTAX_ERROR: + return 0; + case BAN_NOTFOUND: + return 0; + } + return 0; + } + + int SaveAllPlayers(lua_State* L) + { + sObjectAccessor->SaveAllPlayers(); + return 0; + } + + int SendMail(lua_State* L) + { + int i = 0; + std::string subject = luaL_checkstring(L, ++i); + std::string text = luaL_checkstring(L, ++i); + uint32 receiverGUIDLow = luaL_checkunsigned(L, ++i); + Player* senderPlayer = sEluna->CHECKOBJ(L, ++i); + uint32 stationary = luaL_optunsigned(L, ++i, MAIL_STATIONERY_DEFAULT); + uint32 delay = luaL_optunsigned(L, ++i, 0); + int32 argAmount = lua_gettop(L); + + MailSender sender(MAIL_NORMAL, senderPlayer ? senderPlayer->GetGUIDLow() : 0, (MailStationery)stationary); + MailDraft draft(subject, text); + +#ifndef MANGOS + SQLTransaction trans = CharacterDatabase.BeginTransaction(); +#endif + uint8 addedItems = 0; + while (addedItems <= MAX_MAIL_ITEMS && i + 2 <= argAmount) + { + uint32 entry = luaL_checkunsigned(L, ++i); + uint32 amount = luaL_checkunsigned(L, ++i); + +#ifdef MANGOS + ItemTemplate const* item_proto = ObjectMgr::GetItemPrototype(entry); +#else + ItemTemplate const* item_proto = sObjectMgr->GetItemTemplate(entry); +#endif + if (!item_proto) + { + luaL_error(L, "Item entry %d does not exist", entry); + continue; + } + if (amount < 1 || (item_proto->MaxCount > 0 && amount > uint32(item_proto->MaxCount))) + { + luaL_error(L, "Item entry %d has invalid amount %d", entry, amount); + continue; + } + if (Item* item = Item::CreateItem(entry, amount, senderPlayer ? senderPlayer : 0)) + { +#ifdef MANGOS + item->SaveToDB(); +#else + item->SaveToDB(trans); + SQLTransaction trans = CharacterDatabase.BeginTransaction(); +#endif + draft.AddItem(item); + ++addedItems; + } + } + +#ifdef MANGOS + draft.SendMailTo(MailReceiver(MAKE_NEW_GUID(receiverGUIDLow, 0, HIGHGUID_PLAYER)), sender); +#else + draft.SendMailTo(trans, MailReceiver(receiverGUIDLow), sender, MAIL_CHECK_MASK_NONE, delay); + CharacterDatabase.CommitTransaction(trans); +#endif + return 0; + } + + // bit_and(a, b) + int bit_and(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + uint32 b = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, a & b); + return 1; + } + + // bit_or(a, b) + int bit_or(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + uint32 b = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, a | b); + return 1; + } + + // bit_lshift(a, b) + int bit_lshift(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + uint32 b = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, a << b); + return 1; + } + + // bit_rshift(a, b) + int bit_rshift(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + uint32 b = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, a >> b); + return 1; + } + + // bit_xor(a, b) + int bit_xor(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + uint32 b = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, a ^ b); + return 1; + } + + // bit_not(a) + int bit_not(lua_State* L) + { + uint32 a = sEluna->CHECKVAL(L, 1); + sEluna->Push(L, ~a); + return 1; + } + + // AddTaxiPath(pathTable, mountA, mountH[, price, pathId]) + int AddTaxiPath(lua_State* L) + { + luaL_checktype(L, 1, LUA_TTABLE); + uint32 mountA = sEluna->CHECKVAL(L, 2); + uint32 mountH = sEluna->CHECKVAL(L, 3); + uint32 price = sEluna->CHECKVAL(L, 4, 0); + uint32 pathId = sEluna->CHECKVAL(L, 5, 0); + lua_settop(L, 1); + + std::list nodes; + + int start = lua_gettop(L); + int end = start; + + sEluna->Push(L); + while (lua_next(L, -2) != 0) + { + luaL_checktype(L, -1, LUA_TTABLE); + sEluna->Push(L); + while (lua_next(L, -2) != 0) + { + lua_insert(L, end++); + } + if (start == end) + continue; + if (end - start < 4) // no mandatory args, dont add + { + while (end != start) + if (!lua_isnone(L, --end)) + lua_remove(L, end); + continue; + } + + while (end - start < 8) // fill optional args with 0 + { + sEluna->Push(L, 0); + lua_insert(L, end++); + } + TaxiPathNodeEntry* entry = new TaxiPathNodeEntry(); + // mandatory + entry->mapid = sEluna->CHECKVAL(L, start); + entry->x = sEluna->CHECKVAL(L, start + 1); + entry->y = sEluna->CHECKVAL(L, start + 2); + entry->z = sEluna->CHECKVAL(L, start + 3); + // optional + entry->actionFlag = sEluna->CHECKVAL(L, start + 4); + entry->delay = sEluna->CHECKVAL(L, start + 5); + entry->arrivalEventID = sEluna->CHECKVAL(L, start + 6); + entry->departureEventID = sEluna->CHECKVAL(L, start + 7); + + nodes.push_back(*entry); + + while (end != start) // remove args + if (!lua_isnone(L, --end)) + lua_remove(L, end); + + lua_pop(L, 1); + } + + sEluna->Push(L, LuaTaxiMgr::AddPath(nodes, mountA, mountH, price, pathId)); + return 1; + } + + int AddCorpse(lua_State* L) + { + Corpse* corpse = sEluna->CHECKOBJ(L, 1); + + sObjectAccessor->AddCorpse(corpse); + return 0; + } + + int RemoveCorpse(lua_State* L) + { + Corpse* corpse = sEluna->CHECKOBJ(L, 1); + sObjectAccessor->RemoveCorpse(corpse); + return 1; + } + + int ConvertCorpseForPlayer(lua_State* L) + { + uint64 guid = sEluna->CHECKVAL(L, 1); + bool insignia = sEluna->CHECKVAL(L, 2, false); + + sEluna->Push(L, sObjectAccessor->ConvertCorpseForPlayer(GUID_TYPE(guid), insignia)); + return 0; + } + + int RemoveOldCorpses(lua_State* L) + { + sObjectAccessor->RemoveOldCorpses(); + return 0; + } + + int FindWeather(lua_State* L) + { + uint32 zoneId = sEluna->CHECKVAL(L, 1); +#ifdef MANGOS + Weather* weather = sWorld->FindWeather(zoneId); +#else + Weather* weather = WeatherMgr::FindWeather(zoneId); +#endif + sEluna->Push(L, weather); + return 1; + } + + int AddWeather(lua_State* L) + { + uint32 zoneId = sEluna->CHECKVAL(L, 1); +#ifdef MANGOS + Weather* weather = sWorld->AddWeather(zoneId); +#else + Weather* weather = WeatherMgr::AddWeather(zoneId); +#endif + sEluna->Push(L, weather); + return 1; + } + + int RemoveWeather(lua_State* L) + { + uint32 zoneId = sEluna->CHECKVAL(L, 1); +#ifdef MANGOS + sWorld->RemoveWeather(zoneId); +#else + WeatherMgr::RemoveWeather(zoneId); +#endif + return 0; + } + + int SendFineWeatherToPlayer(lua_State* L) + { + Player* player = sEluna->CHECKOBJ(L, 1); +#ifdef MANGOS + Weather::SendFineWeatherUpdateToPlayer(player); +#else + WeatherMgr::SendFineWeatherUpdateToPlayer(player); +#endif + return 0; + } +} +#endif diff --git a/GroupMethods.h b/GroupMethods.h new file mode 100644 index 0000000..3a531bb --- /dev/null +++ b/GroupMethods.h @@ -0,0 +1,227 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaGroup +{ + /* BOOLEAN */ + int IsLeader(lua_State* L, Group* group) + { + uint64 guid = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, group->IsLeader(GUID_TYPE(guid))); + return 1; + } + + int IsFull(lua_State* L, Group* group) + { + sEluna->Push(L, group->IsFull()); + return 1; + } + + int isRaidGroup(lua_State* L, Group* group) + { + sEluna->Push(L, group->isRaidGroup()); + return 1; + } + + int isBGGroup(lua_State* L, Group* group) + { + sEluna->Push(L, group->isBGGroup()); + return 1; + } + + int IsMember(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + sEluna->Push(L, group->IsMember(player->GET_GUID())); + return 1; + } + + int IsAssistant(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, group->IsAssistant(player->GET_GUID())); + return 1; + } + + int SameSubGroup(lua_State* L, Group* group) + { + Player* player1 = sEluna->CHECKOBJ(L, 2); + Player* player2 = sEluna->CHECKOBJ(L, 3); + sEluna->Push(L, group->SameSubGroup(player1, player2)); + return 1; + } + + int HasFreeSlotSubGroup(lua_State* L, Group* group) + { + uint8 subGroup = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, group->HasFreeSlotSubGroup(subGroup)); + return 1; + } + + int AddInvite(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, group->AddInvite(player)); + return 1; + } + + /*int isLFGGroup(lua_State* L, Group* group) // TODO: Implementation + { + sEluna->Push(L, group->isLFGGroup()); + return 1; + }*/ + + /*int isBFGroup(lua_State* L, Group* group) // TODO: Implementation + { + sEluna->Push(L, group->isBFGroup()); + return 1; + }*/ + + /* GETTERS */ + int GetMembers(lua_State* L, Group* group) + { + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next()) + { +#ifdef MANGOS + Player* member = itr->getSource(); +#else + Player* member = itr->GetSource(); +#endif + + if (!member || !member->GetSession()) + continue; + + ++i; + sEluna->Push(L, i); + sEluna->Push(L, member); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); // push table to top of stack + return 1; + } + + int GetLeaderGUID(lua_State* L, Group* group) + { +#ifdef MANGOS + sEluna->Push(L, group->GetLeaderGuid()); +#else + sEluna->Push(L, group->GetLeaderGUID()); +#endif + return 1; + } + + int GetLeader(lua_State* L, Group* group) + { +#ifdef MANGOS + sEluna->Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGuid())); +#else + sEluna->Push(L, sObjectAccessor->FindPlayer(group->GetLeaderGUID())); +#endif + return 1; + } + + int GetGUID(lua_State* L, Group* group) + { + sEluna->Push(L, group->GET_GUID()); + return 1; + } + + int GetMemberGUID(lua_State* L, Group* group) + { + const char* name = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, group->GetMemberGuid(name)); +#else + sEluna->Push(L, group->GetMemberGUID(name)); +#endif + return 1; + } + + int GetMembersCount(lua_State* L, Group* group) + { + sEluna->Push(L, group->GetMembersCount()); + return 1; + } + + int GetMemberGroup(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, group->GetMemberGroup(player->GET_GUID())); + return 1; + } + + /* OTHER */ + int ChangeLeader(lua_State* L, Group* group) + { + Player* leader = sEluna->CHECKOBJ(L, 2); + + group->ChangeLeader(leader->GET_GUID()); + return 0; + } + + // SendPacket(packet, sendToPlayersInBattleground[, ignoreguid]) + int SendPacket(lua_State* L, Group* group) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + bool ignorePlayersInBg = sEluna->CHECKVAL(L, 3); + uint64 ignore = sEluna->CHECKVAL(L, 4); + + group->BroadcastPacket(data, ignorePlayersInBg, -1, (GUID_TYPE)ignore); + return 0; + } + + int RemoveMember(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint32 method = sEluna->CHECKVAL(L, 3, 0); + +#ifdef MANGOS + sEluna->Push(L, group->RemoveMember(player->GET_GUID(), method)); +#else + sEluna->Push(L, group->RemoveMember(player->GET_GUID(), (RemoveMethod)method)); +#endif + return 1; + } + + int Disband(lua_State* L, Group* group) + { + group->Disband(); + return 0; + } + + int ConvertToRaid(lua_State* L, Group* group) + { + group->ConvertToRaid(); + return 0; + } + + int ChangeMembersGroup(lua_State* L, Group* group) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint8 groupID = sEluna->CHECKVAL(L, 3); + + group->ChangeMembersGroup(player->GET_GUID(), groupID); + return 0; + } + + /*int ConvertToLFG(lua_State* L, Group* group) // TODO: Implementation + { + group->ConvertToLFG(); + return 0; + }*/ +}; +#endif diff --git a/GuildMethods.h b/GuildMethods.h new file mode 100644 index 0000000..8575414 --- /dev/null +++ b/GuildMethods.h @@ -0,0 +1,205 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaGuild +{ + /* GETTERS */ + int GetMembers(lua_State* L, Guild* guild) + { + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + SessionMap const& sessions = sWorld->GetAllSessions(); + for (SessionMap::const_iterator it = sessions.begin(); it != sessions.end(); ++it) + { + if (Player* player = it->second->GetPlayer()) + { + if (player->GetSession() && (player->GetGuildId() == guild->GetId())) + { + ++i; + sEluna->Push(L, i); + sEluna->Push(L, player); + lua_settable(L, tbl); + } + } + } + + lua_settop(L, tbl); // push table to top of stack + return 1; + } + + int GetMemberCount(lua_State* L, Guild* guild) + { + sEluna->Push(L, guild->GetMemberSize()); + return 1; + } + + int GetLeader(lua_State* L, Guild* guild) + { +#ifdef MANGOS + sEluna->Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGuid())); +#else + sEluna->Push(L, sObjectAccessor->FindPlayer(guild->GetLeaderGUID())); +#endif + return 1; + } + + int GetLeaderGUID(lua_State* L, Guild* guild) + { +#ifdef MANGOS + sEluna->Push(L, guild->GetLeaderGuid()); +#else + sEluna->Push(L, guild->GetLeaderGUID()); +#endif + return 1; + } + + int GetId(lua_State* L, Guild* guild) + { + sEluna->Push(L, guild->GetId()); + return 1; + } + + int GetName(lua_State* L, Guild* guild) + { + sEluna->Push(L, guild->GetName()); + return 1; + } + + int GetMOTD(lua_State* L, Guild* guild) + { + sEluna->Push(L, guild->GetMOTD()); + return 1; + } + + int GetInfo(lua_State* L, Guild* guild) + { +#ifdef MANGOS + sEluna->Push(L, guild->GetGINFO()); +#else + sEluna->Push(L, guild->GetInfo()); +#endif + return 1; + } + + /* SETTERS */ +#ifndef CATA + int SetLeader(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + +#ifdef MANGOS + guild->SetLeader(player->GET_GUID()); +#else + guild->HandleSetLeader(player->GetSession(), player->GetName()); +#endif + return 0; + } +#endif + + int SetBankTabText(lua_State* L, Guild* guild) + { + uint8 tabId = sEluna->CHECKVAL(L, 2); + const char* text = sEluna->CHECKVAL(L, 3); +#ifdef MANGOS + guild->SetGuildBankTabText(tabId, text); +#else + guild->SetBankTabText(tabId, text); +#endif + return 0; + } + + /* OTHER */ + // SendPacketToGuild(packet) + int SendPacket(lua_State* L, Guild* guild) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + + guild->BroadcastPacket(data); + return 0; + } + + // SendPacketToRankedInGuild(packet, rankId) + int SendPacketToRanked(lua_State* L, Guild* guild) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + uint8 ranked = sEluna->CHECKVAL(L, 3); + + guild->BroadcastPacketToRank(data, ranked); + return 0; + } + + int Disband(lua_State* L, Guild* guild) + { + guild->Disband(); + return 0; + } + + int AddMember(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint8 rankId = sEluna->CHECKVAL(L, 3, GUILD_RANK_NONE); + + guild->AddMember(player->GET_GUID(), rankId); + return 0; + } + + int DeleteMember(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + bool isDisbanding = sEluna->CHECKVAL(L, 3, false); + +#ifdef MANGOS + guild->DelMember(player->GET_GUID(), isDisbanding); +#else + guild->DeleteMember(player->GET_GUID(), isDisbanding); +#endif + return 0; + } + + int ChangeMemberRank(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint8 newRank = sEluna->CHECKVAL(L, 3); + + guild->ChangeMemberRank(player->GET_GUID(), newRank); + return 0; + } + + // Move to Player methods + int WithdrawBankMoney(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint32 money = sEluna->CHECKVAL(L, 3); +#ifdef MANGOS + if (guild->GetGuildBankMoney() < money) + return 0; + guild->SetBankMoney(guild->GetGuildBankMoney() - money); +#else + guild->HandleMemberWithdrawMoney(player->GetSession(), money); +#endif + return 0; + } + + // Move to Player methods + int DepositBankMoney(lua_State* L, Guild* guild) + { + Player* player = sEluna->CHECKOBJ(L, 2); + uint32 money = sEluna->CHECKVAL(L, 3); + +#ifdef MANGOS + guild->SetBankMoney(guild->GetGuildBankMoney() + money); +#else + guild->HandleMemberDepositMoney(player->GetSession(), money); +#endif + return 0; + } +}; +#endif diff --git a/HookMgr.cpp b/HookMgr.cpp new file mode 100644 index 0000000..10cd33b --- /dev/null +++ b/HookMgr.cpp @@ -0,0 +1,2093 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#include "LuaEngine.h" +#include "HookMgr.h" + +extern bool StartEluna(); +bool HookMgr::OnCommand(Player* player, const char* text) +{ + std::string fullcmd(text); + char* creload = strtok((char*)text, " "); + char* celuna = strtok(NULL, ""); + if (creload && celuna) + { + std::string reload(creload); + std::string eluna(celuna); + std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower); + if (reload == "reload") + { + std::transform(eluna.begin(), eluna.end(), eluna.begin(), ::tolower); + if (std::string("eluna").find(eluna) == 0) + { + sWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna..."); + StartEluna(); + return false; + } + } + } + ELUNA_GUARD(); + bool result = true; + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_COMMAND)) + return result; + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, fullcmd); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + result = sEluna->CHECKVAL(sEluna->L, i, result); + } + sEluna->PlayerEventBindings.EndCall(); + return result; +} + +void HookMgr::OnWorldUpdate(uint32 diff) +{ + ELUNA_GUARD(); + sEluna->m_EventMgr.Update(diff); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE)) + return; + sEluna->Push(sEluna->L, diff); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +void HookMgr::OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_ITEM)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, count); + sEluna->Push(sEluna->L, guid); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnLootMoney(Player* pPlayer, uint32 amount) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOOT_MONEY)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, amount); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnFirstLogin(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_FIRST_LOGIN)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnRepop(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPOP)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnResurrect(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_RESURRECT)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnQuestAbandon(Player* pPlayer, uint32 questId) +{ + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_QUEST_ABANDON)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, questId); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketCreate(Player* pPlayer, std::string& ticketText) +{ + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_CREATE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, ticketText); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketUpdate(Player* pPlayer, std::string& ticketText) +{ + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_UPDATE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, ticketText); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGmTicketDelete(Player* pPlayer) +{ + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GM_TICKET_DELETE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EQUIP)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, bag); + sEluna->Push(sEluna->L, slot); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +InventoryResult HookMgr::OnCanUseItem(const Player* pPlayer, uint32 itemEntry) +{ + ELUNA_GUARD(); + InventoryResult result = EQUIP_ERR_OK; + if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CAN_USE_ITEM)) + { + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, itemEntry); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + uint32 res = lua_tounsigned(sEluna->L, i); + if (res != EQUIP_ERR_OK) + result = (InventoryResult)res; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} + +void HookMgr::HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code) +{ + ELUNA_GUARD(); + int bind = sEluna->ItemGossipBindings.GetBind(item->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (bind) + { + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, item); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + if (code.empty()) + lua_pushnil(sEluna->L); + else + sEluna->Push(sEluna->L, code); + sEluna->ExecuteCall(6, 0); + } +} + +void HookMgr::HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code) +{ + ELUNA_GUARD(); + int bind = sEluna->playerGossipBindings.GetBind(menuId, GOSSIP_EVENT_ON_SELECT); + if (bind) + { + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); // receiver + sEluna->Push(sEluna->L, pPlayer); // sender, just not to mess up the amount of args. + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + if (code.empty()) + lua_pushnil(sEluna->L); + else + sEluna->Push(sEluna->L, code); + sEluna->Push(sEluna->L, menuId); + sEluna->ExecuteCall(7, 0); + } +} + +void HookMgr::OnEngineRestart() +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(ELUNA_EVENT_ON_RESTART)) + return; + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +// item +bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget) +{ + ELUNA_GUARD(); + int bind = sEluna->ItemEventBindings.GetBind(pTarget->GetEntry(), ITEM_EVENT_ON_DUMMY_EFFECT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, ITEM_EVENT_ON_DUMMY_EFFECT); + sEluna->Push(sEluna->L, pCaster); + sEluna->Push(sEluna->L, spellId); + sEluna->Push(sEluna->L, effIndex); + sEluna->Push(sEluna->L, pTarget); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_QUEST_ACCEPT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, ITEM_EVENT_ON_QUEST_ACCEPT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets) +{ + ELUNA_GUARD(); + int bind1 = sEluna->ItemGossipBindings.GetBind(pItem->GetEntry(), GOSSIP_EVENT_ON_HELLO); + int bind2 = sEluna->ItemEventBindings.GetBind(pItem->GetEntry(), ITEM_EVENT_ON_USE); + if (!bind1 && !bind2) + return false; + if (bind1) + { + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind1); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); + sEluna->ExecuteCall(3, 0); + } + if (bind2) + { + sEluna->BeginCall(bind2); + sEluna->Push(sEluna->L, ITEM_EVENT_ON_USE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pItem); +#ifdef MANGOS + if (GameObject* target = targets.getGOTarget()) + sEluna->Push(sEluna->L, target); + else if (Item* target = targets.getItemTarget()) + sEluna->Push(sEluna->L, target); + else if (Corpse* target = pPlayer->GetMap()->GetCorpse(targets.getCorpseTargetGuid())) + sEluna->Push(sEluna->L, target); + else if (Unit* target = targets.getUnitTarget()) + sEluna->Push(sEluna->L, target); + else + sEluna->Push(sEluna->L); +#else + if (GameObject* target = targets.GetGOTarget()) + sEluna->Push(sEluna->L, target); + else if (Item* target = targets.GetItemTarget()) + sEluna->Push(sEluna->L, target); + else if (Corpse* target = targets.GetCorpseTarget()) + sEluna->Push(sEluna->L, target); + else if (Unit* target = targets.GetUnitTarget()) + sEluna->Push(sEluna->L, target); + else if (WorldObject* target = targets.GetObjectTarget()) + sEluna->Push(sEluna->L, target); + else + sEluna->Push(sEluna->L); +#endif + sEluna->ExecuteCall(4, 0); + } + // pPlayer->SendEquipError((InventoryResult)83, pItem, NULL); + return false; +} + +bool HookMgr::OnExpire(Player* pPlayer, ItemTemplate const* pProto) +{ + ELUNA_GUARD(); + int bind = sEluna->ItemEventBindings.GetBind(pProto->ItemId, ITEM_EVENT_ON_EXPIRE); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, ITEM_EVENT_ON_EXPIRE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pProto->ItemId); + sEluna->ExecuteCall(3, 0); + return true; +} +// creature +bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pTarget->GetEntry(), CREATURE_EVENT_ON_DUMMY_EFFECT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DUMMY_EFFECT); + sEluna->Push(sEluna->L, pCaster); + sEluna->Push(sEluna->L, spellId); + sEluna->Push(sEluna->L, effIndex); + sEluna->Push(sEluna->L, pTarget); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipHello(Player* pPlayer, Creature* pCreature) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_HELLO); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->ExecuteCall(3, 0); + return true; +} + +bool HookMgr::OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureGossipBindings.GetBind(pCreature->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->Push(sEluna->L, code); + sEluna->ExecuteCall(6, 0); + return true; +} + +bool HookMgr::OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_ACCEPT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_ACCEPT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_SELECT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_COMPLETE); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_COMPLETE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_QUEST_REWARD); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_QUEST_REWARD); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +uint32 HookMgr::GetDialogStatus(Player* pPlayer, Creature* pCreature) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_DIALOG_STATUS); + if (!bind) + return 0; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIALOG_STATUS); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pCreature); + sEluna->ExecuteCall(3, 0); + return DIALOG_STATUS_SCRIPTED_NO_STATUS; +} + +void HookMgr::OnSummoned(Creature* pCreature, Unit* pSummoner) +{ + int bind = sEluna->CreatureEventBindings.GetBind(pCreature->GetEntry(), CREATURE_EVENT_ON_SUMMONED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED); + sEluna->Push(sEluna->L, pCreature); + sEluna->Push(sEluna->L, pSummoner); + sEluna->ExecuteCall(3, 0); +} + +// gameobject +bool HookMgr::OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pTarget->GetEntry(), GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DUMMY_EFFECT); + sEluna->Push(sEluna->L, pCaster); + sEluna->Push(sEluna->L, spellId); + sEluna->Push(sEluna->L, effIndex); + sEluna->Push(sEluna->L, pTarget); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipHello(Player* pPlayer, GameObject* pGameObject) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_HELLO); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_HELLO); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->ExecuteCall(3, 0); + return true; +} + +bool HookMgr::OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->ExecuteCall(5, 0); + return true; +} + +bool HookMgr::OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectGossipBindings.GetBind(pGameObject->GetEntry(), GOSSIP_EVENT_ON_SELECT); + if (!bind) + return false; + pPlayer->PlayerTalkClass->ClearMenus(); + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GOSSIP_EVENT_ON_SELECT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, sender); + sEluna->Push(sEluna->L, action); + sEluna->Push(sEluna->L, code); + sEluna->ExecuteCall(6, 0); + return true; +} + +bool HookMgr::OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_ACCEPT); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->CreatureEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_COMPLETE); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +bool HookMgr::OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_QUEST_REWARD); + if (!bind) + return false; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_QUEST_REWARD); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pQuest); + sEluna->ExecuteCall(4, 0); + return true; +} + +uint32 HookMgr::GetDialogStatus(Player* pPlayer, GameObject* pGameObject) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DIALOG_STATUS); + if (!bind) + return 0; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DIALOG_STATUS); + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pGameObject); + sEluna->ExecuteCall(3, 0); + return DIALOG_STATUS_SCRIPTED_NO_STATUS; // DIALOG_STATUS_UNDEFINED +} + +void HookMgr::OnDestroyed(GameObject* pGameObject, Player* pPlayer) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DESTROYED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DESTROYED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pPlayer); + sEluna->ExecuteCall(3, 0); +} + +void HookMgr::OnDamaged(GameObject* pGameObject, Player* pPlayer) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_DAMAGED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_DAMAGED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, pPlayer); + sEluna->ExecuteCall(3, 0); +} + +void HookMgr::OnLootStateChanged(GameObject* pGameObject, uint32 state, Unit* pUnit) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, state); + sEluna->Push(sEluna->L, pUnit); + sEluna->ExecuteCall(4, 0); +} + +void HookMgr::OnGameObjectStateChanged(GameObject* pGameObject, uint32 state) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, state); + sEluna->ExecuteCall(3, 0); +} +// Player +void HookMgr::OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_ENTER_COMBAT)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pEnemy); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnPlayerLeaveCombat(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEAVE_COMBAT)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnPVPKill(Player* pKiller, Player* pKilled) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_PLAYER)) + return; + sEluna->Push(sEluna->L, pKiller); + sEluna->Push(sEluna->L, pKilled); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnCreatureKill(Player* pKiller, Creature* pKilled) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILL_CREATURE)) + return; + sEluna->Push(sEluna->L, pKiller); + sEluna->Push(sEluna->L, pKilled); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_KILLED_BY_CREATURE)) + return; + sEluna->Push(sEluna->L, pKiller); + sEluna->Push(sEluna->L, pKilled); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnLevelChanged(Player* pPlayer, uint8 oldLevel) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LEVEL_CHANGE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, oldLevel); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_CHANGE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, newPoints); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnTalentsReset(Player* pPlayer, bool noCost) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TALENTS_RESET)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, noCost); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnMoneyChanged(Player* pPlayer, int32& amount) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MONEY_CHANGE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, amount); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GIVE_XP)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, amount); + sEluna->Push(sEluna->L, pVictim); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_REPUTATION_CHANGE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, factionID); + sEluna->Push(sEluna->L, standing); + sEluna->Push(sEluna->L, incremental); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnDuelRequest(Player* pTarget, Player* pChallenger) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_REQUEST)) + return; + sEluna->Push(sEluna->L, pTarget); + sEluna->Push(sEluna->L, pChallenger); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnDuelStart(Player* pStarter, Player* pChallenger) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_START)) + return; + sEluna->Push(sEluna->L, pStarter); + sEluna->Push(sEluna->L, pChallenger); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_DUEL_END)) + return; + sEluna->Push(sEluna->L, pWinner); + sEluna->Push(sEluna->L, pLoser); + sEluna->Push(sEluna->L, type); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_WHISPER)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, msg); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, lang); + sEluna->Push(sEluna->L, pReceiver); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnEmote(Player* pPlayer, uint32 emote) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_EMOTE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, emote); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_TEXT_EMOTE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, textEmote); + sEluna->Push(sEluna->L, emoteNum); + sEluna->Push(sEluna->L, guid); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SPELL_CAST)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pSpell); + sEluna->Push(sEluna->L, skipCheck); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnLogin(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGIN)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnLogout(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_LOGOUT)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnCreate(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_CREATE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnDelete(uint32 guidlow) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHARACTER_DELETE)) + return; + sEluna->Push(sEluna->L, guidlow); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnSave(Player* pPlayer) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_SAVE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_BIND_TO_INSTANCE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, difficulty); + sEluna->Push(sEluna->L, mapid); + sEluna->Push(sEluna->L, permanent); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_UPDATE_ZONE)) + return; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, newZone); + sEluna->Push(sEluna->L, newArea); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +void HookMgr::OnMapChanged(Player* player) +{ + ELUNA_GUARD(); + if (!sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_MAP_CHANGE)) + return; + sEluna->Push(sEluna->L, player); + sEluna->PlayerEventBindings.ExecuteCall(); + sEluna->PlayerEventBindings.EndCall(); +} + +bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg) +{ + ELUNA_GUARD(); + bool result = true; + if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHAT)) + { + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, msg); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, lang); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (!lua_toboolean(sEluna->L, i)) + result = false; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} + +bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup) +{ + ELUNA_GUARD(); + bool result = true; + if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GROUP_CHAT)) + { + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, msg); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, lang); + sEluna->Push(sEluna->L, pGroup); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (!lua_toboolean(sEluna->L, i)) + result = false; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} + +bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild) +{ + ELUNA_GUARD(); + bool result = true; + if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_GUILD_CHAT)) + { + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, msg); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, lang); + sEluna->Push(sEluna->L, pGuild); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (!lua_toboolean(sEluna->L, i)) + result = false; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} + +bool HookMgr::OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel) +{ + ELUNA_GUARD(); + bool result = true; + if (sEluna->PlayerEventBindings.BeginCall(PLAYER_EVENT_ON_CHANNEL_CHAT)) + { + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, msg); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, lang); + sEluna->Push(sEluna->L, pChannel->GetChannelId()); + sEluna->PlayerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + if (!lua_toboolean(sEluna->L, i)) + result = false; + } + sEluna->PlayerEventBindings.EndCall(); + } + return result; +} + +#ifndef MANGOS +// Vehicle +void HookMgr::OnInstall(Vehicle* vehicle) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} + +void HookMgr::OnUninstall(Vehicle* vehicle) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_UNINSTALL)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} + +void HookMgr::OnReset(Vehicle* vehicle) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_RESET)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} + +void HookMgr::OnInstallAccessory(Vehicle* vehicle, Creature* accessory) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_INSTALL_ACCESSORY)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->Push(sEluna->L, accessory); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} + +void HookMgr::OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_ADD_PASSENGER)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->Push(sEluna->L, passenger); + sEluna->Push(sEluna->L, seatId); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} + +void HookMgr::OnRemovePassenger(Vehicle* vehicle, Unit* passenger) +{ + ELUNA_GUARD(); + if (!sEluna->VehicleEventBindings.BeginCall(VEHICLE_EVENT_ON_REMOVE_PASSENGER)) + return; + sEluna->Push(sEluna->L, vehicle); + sEluna->Push(sEluna->L, passenger); + sEluna->VehicleEventBindings.ExecuteCall(); + sEluna->VehicleEventBindings.EndCall(); +} +#endif + +// areatrigger +bool HookMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(TRIGGER_EVENT_ON_TRIGGER)) + return false; + sEluna->Push(sEluna->L, pPlayer); + sEluna->Push(sEluna->L, pTrigger->id); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + return false; +} +// weather +void HookMgr::OnChange(Weather* weather, WeatherState state, float grade) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WEATHER_EVENT_ON_CHANGE)) + return; + sEluna->Push(sEluna->L, (weather->GetZone())); + sEluna->Push(sEluna->L, state); + sEluna->Push(sEluna->L, grade); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} +// transport +void HookMgr::OnAddPassenger(Transport* transport, Player* player) +{ + ELUNA_GUARD(); +} +void HookMgr::OnAddCreaturePassenger(Transport* transport, Creature* creature) +{ + ELUNA_GUARD(); +} +void HookMgr::OnRemovePassenger(Transport* transport, Player* player) +{ + ELUNA_GUARD(); +} +void HookMgr::OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z) +{ + ELUNA_GUARD(); +} +// Auction House +void HookMgr::OnAdd(AuctionHouseObject* ah) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_ADD)) + return; + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +void HookMgr::OnRemove(AuctionHouseObject* ah) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_REMOVE)) + return; + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +void HookMgr::OnSuccessful(AuctionHouseObject* ah) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_SUCCESSFUL)) + return; + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +void HookMgr::OnExpire(AuctionHouseObject* ah) +{ + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(AUCTION_EVENT_ON_EXPIRE)) + return; + sEluna->Push(sEluna->L, (ah)); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); +} + +// Packet +bool HookMgr::OnPacketSend(WorldSession* session, WorldPacket& packet) +{ + ELUNA_GUARD(); + bool result = true; + Player* player = NULL; + if (session) + player = session->GetPlayer(); + if (sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_SEND)) + { + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->ServerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false); + if (data) + packet = *data; + if (!sEluna->CHECKOBJ(sEluna->L, i, true)) + result = false; + } + sEluna->ServerEventBindings.EndCall(); + } + if (sEluna->PacketEventBindings.BeginCall(packet.GetOpcode())) + { + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->PacketEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false); + if (data) + packet = *data; + if (!sEluna->CHECKOBJ(sEluna->L, i, true)) + result = false; + } + sEluna->PacketEventBindings.EndCall(); + } + return result; +} +bool HookMgr::OnPacketReceive(WorldSession* session, WorldPacket& packet) +{ + ELUNA_GUARD(); + bool result = true; + Player* player = NULL; + if (session) + player = session->GetPlayer(); + if (sEluna->ServerEventBindings.BeginCall(SERVER_EVENT_ON_PACKET_RECEIVE)) + { + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->ServerEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false); + if (data) + packet = *data; + if (!sEluna->CHECKOBJ(sEluna->L, i, true)) + result = false; + } + sEluna->ServerEventBindings.EndCall(); + } + if (sEluna->PacketEventBindings.BeginCall(packet.GetOpcode())) + { + sEluna->Push(sEluna->L, new WorldPacket(packet)); + sEluna->Push(sEluna->L, player); + sEluna->PacketEventBindings.ExecuteCall(); + for (int i = 1; i <= lua_gettop(sEluna->L); ++i) + { + if (lua_isnoneornil(sEluna->L, i)) + continue; + WorldPacket* data = sEluna->CHECKOBJ(sEluna->L, i, false); + if (data) + packet = *data; + if (!sEluna->CHECKOBJ(sEluna->L, i, true)) + result = false; + } + sEluna->PacketEventBindings.EndCall(); + } + return result; +} + +#ifndef MANGOS +class ElunaWorldAI : public WorldScript +{ +public: + ElunaWorldAI() : WorldScript("ElunaWorldAI") { } + ~ElunaWorldAI() { } + + void OnOpenStateChange(bool open) OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_OPEN_STATE_CHANGE)) + return; + sEluna->Push(sEluna->L, open); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnConfigLoad(bool reload) OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_CONFIG_LOAD)) + return; + sEluna->Push(sEluna->L, reload); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnMotdChange(std::string& newMotd) OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_MOTD_CHANGE)) + return; + sEluna->Push(sEluna->L, newMotd); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdownInitiate(ShutdownExitCode code, ShutdownMask mask) OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_INIT)) + return; + sEluna->Push(sEluna->L, code); + sEluna->Push(sEluna->L, mask); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdownCancel() OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN_CANCEL)) + return; + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnUpdate(uint32 diff) OVERRIDE + { + ELUNA_GUARD(); + sEluna->m_EventMgr.Update(diff); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_UPDATE)) + return; + sEluna->Push(sEluna->L, diff); + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnStartup() OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_STARTUP)) + return; + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } + + void OnShutdown() OVERRIDE + { + ELUNA_GUARD(); + if (!sEluna->ServerEventBindings.BeginCall(WORLD_EVENT_ON_SHUTDOWN)) + return; + sEluna->ServerEventBindings.ExecuteCall(); + sEluna->ServerEventBindings.EndCall(); + } +}; +#endif + +struct ElunaCreatureAI : ScriptedAI +{ + ElunaCreatureAI(Creature* creature) : ScriptedAI(creature) { } + ~ElunaCreatureAI() { } + +#ifdef MANGOS +#define me m_creature +#endif + + //Called at World update tick +#ifdef MANGOS + void UpdateAI( const uint32 diff) OVERRIDE +#else + void UpdateAI(uint32 diff) OVERRIDE +#endif + { + ELUNA_GUARD(); + ScriptedAI::UpdateAI(diff); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_AIUPDATE); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_AIUPDATE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, diff); + sEluna->ExecuteCall(3, 0); + } + + //Called for reaction at enter to combat if not in combat yet (enemy can be NULL) + //Called at creature aggro either by MoveInLOS or Attack Start + void EnterCombat(Unit* target) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::EnterCombat(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ENTER_COMBAT); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ENTER_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + // Called at any Damage from any attacker (before damage apply) + void DamageTaken(Unit* attacker, uint32& damage) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::DamageTaken(attacker, damage); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DAMAGE_TAKEN); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DAMAGE_TAKEN); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->Push(sEluna->L, damage); + sEluna->ExecuteCall(4, 0); + } + + //Called at creature death + void JustDied(Unit* killer) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::JustDied(killer); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_DIED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, killer); + sEluna->ExecuteCall(3, 0); + } + + //Called at creature killing another unit + void KilledUnit(Unit* victim) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::KilledUnit(victim); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_TARGET_DIED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_TARGET_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, victim); + sEluna->ExecuteCall(3, 0); + } + + // Called when the creature summon successfully other creature + void JustSummoned(Creature* summon) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::JustSummoned(summon); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->ExecuteCall(3, 0); + } + + // Called when a summoned creature is despawned + void SummonedCreatureDespawn(Creature* summon) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::SummonedCreatureDespawn(summon); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->ExecuteCall(3, 0); + } + + //Called at waypoint reached or PointMovement end + void MovementInform(uint32 type, uint32 id) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::MovementInform(type, id); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_WP); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_WP); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, type); + sEluna->Push(sEluna->L, id); + sEluna->ExecuteCall(4, 0); + } + + // Called before EnterCombat even before the creature is in combat. + void AttackStart(Unit* target) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::AttackStart(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PRE_COMBAT); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PRE_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + // Called for reaction at stopping attack at no attackers or targets + void EnterEvadeMode() OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::EnterEvadeMode(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_LEAVE_COMBAT); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_LEAVE_COMBAT); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc) + void AttackedBy(Unit* attacker) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::AttackedBy(attacker); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_ATTACKED_AT); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_ATTACKED_AT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->ExecuteCall(3, 0); + } + + // Called when creature is spawned or respawned (for reseting variables) + void JustRespawned() OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::JustRespawned(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPAWN); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPAWN); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called at reaching home after evade + void JustReachedHome() OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::JustReachedHome(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_REACH_HOME); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_REACH_HOME); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called at text emote receive from player + void ReceiveEmote(Player* player, uint32 emoteId) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::ReceiveEmote(player, emoteId); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RECEIVE_EMOTE); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RECEIVE_EMOTE); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, emoteId); + sEluna->ExecuteCall(4, 0); + } + + // called when the corpse of this creature gets removed + void CorpseRemoved(uint32& respawnDelay) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::CorpseRemoved(respawnDelay); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CORPSE_REMOVED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CORPSE_REMOVED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, respawnDelay); + sEluna->ExecuteCall(3, 0); + } + + void MoveInLineOfSight(Unit* who) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::MoveInLineOfSight(who); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_MOVE_IN_LOS); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_MOVE_IN_LOS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, who); + sEluna->ExecuteCall(3, 0); + } + +#ifndef MANGOS + // Called when hit by a spell + void SpellHit(Unit* caster, SpellInfo const* spell) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::SpellHit(caster, spell); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_HIT_BY_SPELL); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_HIT_BY_SPELL); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, caster); + sEluna->Push(sEluna->L, spell->Id); // Pass spell object? + sEluna->ExecuteCall(4, 0); + } + + // Called when spell hits a target + void SpellHitTarget(Unit* target, SpellInfo const* spell) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::SpellHitTarget(target, spell); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_HIT_TARGET); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_HIT_TARGET); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->Push(sEluna->L, spell->Id); // Pass spell object? + sEluna->ExecuteCall(4, 0); + } + + // Called when AI is temporarily replaced or put back when possess is applied or removed + void OnPossess(bool apply) + { + ELUNA_GUARD(); + ScriptedAI::OnPossess(apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_POSSESS); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_POSSESS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(3, 0); + } + + //Called at creature reset either by death or evade + void Reset() OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::Reset(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_RESET); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_RESET); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + } + + // Called in Creature::Update when deathstate = DEAD. Inherited classes may maniuplate the ability to respawn based on scripted events. + bool CanRespawn() OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::CanRespawn(); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CAN_RESPAWN); + if (!bind) + return true; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CAN_RESPAWN); + sEluna->Push(sEluna->L, me); + sEluna->ExecuteCall(2, 0); + return true; + } + + // Called when the creature is summoned successfully by other creature + void IsSummonedBy(Unit* summoner) OVERRIDE + { + ScriptedAI::IsSummonedBy(summoner); + sHookMgr->OnSummoned(me, summoner); + } + + void SummonedCreatureDies(Creature* summon, Unit* killer) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::SummonedCreatureDies(summon, killer); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, summon); + sEluna->Push(sEluna->L, killer); + sEluna->ExecuteCall(4, 0); + } + + void OnCharmed(bool apply) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::OnCharmed(apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_CHARMED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_CHARMED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(3, 0); + } + + // Called when owner takes damage + void OwnerAttackedBy(Unit* attacker) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::OwnerAttackedBy(attacker); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED_AT); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED_AT); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, attacker); + sEluna->ExecuteCall(3, 0); + } + + // Called when owner attacks something + void OwnerAttacked(Unit* target) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::OwnerAttacked(target); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_OWNER_ATTACKED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_OWNER_ATTACKED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, target); + sEluna->ExecuteCall(3, 0); + } + + void PassengerBoarded(Unit* passenger, int8 seatId, bool apply) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::PassengerBoarded(passenger, seatId, apply); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_PASSANGER_BOARDED); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_PASSANGER_BOARDED); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, passenger); + sEluna->Push(sEluna->L, seatId); + sEluna->Push(sEluna->L, apply); + sEluna->ExecuteCall(5, 0); + } + + void OnSpellClick(Unit* clicker, bool& result) OVERRIDE + { + ELUNA_GUARD(); + ScriptedAI::OnSpellClick(clicker, result); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_SPELL_CLICK); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_SPELL_CLICK); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, clicker); + sEluna->Push(sEluna->L, result); + sEluna->ExecuteCall(4, 0); + } + + // Called if IsVisible(Unit* who) is true at each who move, reaction at visibility zone enter + void MoveInLineOfSight_Safe(Unit* who) + { + ELUNA_GUARD(); + ScriptedAI::MoveInLineOfSight_Safe(who); + int bind = sEluna->CreatureEventBindings.GetBind(me->GetEntry(), CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS); + sEluna->Push(sEluna->L, me); + sEluna->Push(sEluna->L, who); + sEluna->ExecuteCall(3, 0); + } +#endif + +#ifdef MANGOS +#undef me +#endif +}; + +void HookMgr::UpdateAI(GameObject* pGameObject, uint32 diff) +{ + ELUNA_GUARD(); + int bind = sEluna->GameObjectEventBindings.GetBind(pGameObject->GetEntry(), GAMEOBJECT_EVENT_ON_AIUPDATE); + if (!bind) + return; + sEluna->BeginCall(bind); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_AIUPDATE); + sEluna->Push(sEluna->L, pGameObject); + sEluna->Push(sEluna->L, diff); + sEluna->ExecuteCall(3, 0); +} + +#ifndef MANGOS +struct ElunaGameObjectAI : public GameObjectAI +{ + ElunaGameObjectAI(GameObject* _go) : GameObjectAI(_go) { } + ~ElunaGameObjectAI() + { + } + + void Reset() OVERRIDE + { + ELUNA_GUARD(); + sEluna->BeginCall(sEluna->GameObjectEventBindings.GetBind(go->GetEntry(), GAMEOBJECT_EVENT_ON_RESET)); + sEluna->Push(sEluna->L, GAMEOBJECT_EVENT_ON_RESET); + sEluna->Push(sEluna->L, go); + sEluna->ExecuteCall(2, 0); + } +}; +#endif + +void HookMgr::OnAddMember(Guild* guild, Player* player, uint32 plRank) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ADD_MEMBER)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, plRank); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnRemoveMember(Guild* guild, Player* player, bool isDisbanding) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_REMOVE_MEMBER)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, isDisbanding); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnMOTDChanged(Guild* guild, const std::string& newMotd) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MOTD_CHANGE)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, newMotd); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnInfoChanged(Guild* guild, const std::string& newInfo) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_INFO_CHANGE)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, newInfo); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnCreate(Guild* guild, Player* leader, const std::string& name) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_CREATE)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, leader); + sEluna->Push(sEluna->L, name); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnDisband(Guild* guild) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_DISBAND)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnMemberWitdrawMoney(Guild* guild, Player* player, uint32 &amount, bool isRepair) // isRepair not a part of Mangos, implement? +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_WITHDRAW)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, amount); + sEluna->Push(sEluna->L, isRepair); // isRepair not a part of Mangos, implement? + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnMemberDepositMoney(Guild* guild, Player* player, uint32 &amount) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_MONEY_DEPOSIT)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, amount); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, + bool isDestBank, uint8 destContainer, uint8 destSlotId) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_ITEM_MOVE)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, player); + sEluna->Push(sEluna->L, pItem); + sEluna->Push(sEluna->L, isSrcBank); + sEluna->Push(sEluna->L, srcContainer); + sEluna->Push(sEluna->L, srcSlotId); + sEluna->Push(sEluna->L, isDestBank); + sEluna->Push(sEluna->L, destContainer); + sEluna->Push(sEluna->L, destSlotId); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_EVENT)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, eventType); + sEluna->Push(sEluna->L, playerGuid1); + sEluna->Push(sEluna->L, playerGuid2); + sEluna->Push(sEluna->L, newRank); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} + +void HookMgr::OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId) +{ + ELUNA_GUARD(); + if (!sEluna->GuildEventBindings.BeginCall(GUILD_EVENT_ON_BANK_EVENT)) + return; + sEluna->Push(sEluna->L, guild); + sEluna->Push(sEluna->L, eventType); + sEluna->Push(sEluna->L, tabId); + sEluna->Push(sEluna->L, playerGuid); + sEluna->Push(sEluna->L, itemOrMoney); + sEluna->Push(sEluna->L, itemStackCount); + sEluna->Push(sEluna->L, destTabId); + sEluna->GuildEventBindings.ExecuteCall(); + sEluna->GuildEventBindings.EndCall(); +} +// Group +void HookMgr::OnAddMember(Group* group, uint64 guid) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_ADD)) + return; + sEluna->Push(sEluna->L, group); + sEluna->Push(sEluna->L, guid); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +void HookMgr::OnInviteMember(Group* group, uint64 guid) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_INVITE)) + return; + sEluna->Push(sEluna->L, group); + sEluna->Push(sEluna->L, guid); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +void HookMgr::OnRemoveMember(Group* group, uint64 guid, uint8 method) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_MEMBER_REMOVE)) + return; + sEluna->Push(sEluna->L, group); + sEluna->Push(sEluna->L, guid); + sEluna->Push(sEluna->L, method); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +void HookMgr::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_LEADER_CHANGE)) + return; + sEluna->Push(sEluna->L, group); + sEluna->Push(sEluna->L, newLeaderGuid); + sEluna->Push(sEluna->L, oldLeaderGuid); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +void HookMgr::OnDisband(Group* group) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_DISBAND)) + return; + sEluna->Push(sEluna->L, group); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +void HookMgr::OnCreate(Group* group, uint64 leaderGuid, GroupType groupType) +{ + ELUNA_GUARD(); + if (!sEluna->GroupEventBindings.BeginCall(GROUP_EVENT_ON_CREATE)) + return; + sEluna->Push(sEluna->L, group); + sEluna->Push(sEluna->L, leaderGuid); + sEluna->Push(sEluna->L, groupType); + sEluna->GroupEventBindings.ExecuteCall(); + sEluna->GroupEventBindings.EndCall(); +} + +CreatureAI* HookMgr::GetAI(Creature* creature) +{ + if (!sEluna->CreatureEventBindings.GetBindMap(creature->GetEntry())) + return NULL; + return new ElunaCreatureAI(creature); +} + +#ifndef MANGOS +GameObjectAI* HookMgr::GetAI(GameObject* gameObject) +{ + if (!sEluna->GameObjectEventBindings.GetBindMap(gameObject->GetEntry())) + return NULL; + return new ElunaGameObjectAI(gameObject); +} +#endif + +void AddElunaScripts() +{ +#ifndef MANGOS + new ElunaWorldAI(); +#endif +} diff --git a/HookMgr.h b/HookMgr.h new file mode 100644 index 0000000..c79aa76 --- /dev/null +++ b/HookMgr.h @@ -0,0 +1,467 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef LUAHOOKS_H +#define LUAHOOKS_H + +#include "Includes.h" + +// Base +#include "Common.h" +#include "SharedDefines.h" +#include +#include +// enums +#ifdef MANGOS +#include "Player.h" +#else +#include "GameObjectAI.h" +#endif +#include "Group.h" +#include "Item.h" +#include "Weather.h" + +#ifdef MANGOS +#define ScriptedAI ReactorAI +#define SpellEffIndex SpellEffectIndex +#define ItemTemplate ItemPrototype +#define GetTemplate GetProto +//#include "Common.h" +//#include "Policies/Singleton.h" +//#include "ObjectGuid.h" +//#include "ace/Atomic_Op.h" +// +//enums +//#include "DBCEnums.h" +//#include "Includes.h" +#endif + +struct AreaTriggerEntry; +#ifdef MANGOS +class ScriptedAI; +#else +struct ScriptedAI; +#endif +class AuctionHouseObject; +class Channel; +class Creature; +class CreatureAI; +class GameObject; +class Guild; +class Group; +class Item; +class Player; +class Quest; +class Spell; +class SpellCastTargets; +class Transport; +class Unit; +class Weather; +class WorldPacket; + +enum RegisterTypes +{ + REGTYPE_PACKET, + REGTYPE_SERVER, + REGTYPE_PLAYER, + REGTYPE_GUILD, + REGTYPE_GROUP, + REGTYPE_CREATURE, + REGTYPE_VEHICLE, + REGTYPE_CREATURE_GOSSIP, + REGTYPE_GAMEOBJECT, + REGTYPE_GAMEOBJECT_GOSSIP, + REGTYPE_ITEM, + REGTYPE_ITEM_GOSSIP, + REGTYPE_PLAYER_GOSSIP, + REGTYPE_COUNT +}; + +// RegisterPacketEvent(Opcode, function) +// SERVER_EVENT_ON_PACKET_RECEIVE = 5, // (event, packet, player) - Player only if accessible. Can return false or a new packet +// 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 or a new packet + +// RegisterServerEvent(EventId, function) +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 or a new packet + 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 or a new packet + + // World // Not implemented on mangos + WORLD_EVENT_ON_OPEN_STATE_CHANGE = 8, // (event, open) + WORLD_EVENT_ON_CONFIG_LOAD = 9, // (event, reload) + WORLD_EVENT_ON_MOTD_CHANGE = 10, // (event, newMOTD) + 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_RESTART = 16, // (event) + + // Map + MAP_EVENT_ON_CREATE = 17, // Not Implemented + MAP_EVENT_ON_DESTROY = 18, // Not Implemented + MAP_EVENT_ON_LOAD = 19, // Not Implemented + MAP_EVENT_ON_UNLOAD = 20, // Not Implemented + MAP_EVENT_ON_PLAYER_ENTER = 21, // Not Implemented + MAP_EVENT_ON_PLAYER_LEAVE = 22, // Not Implemented + MAP_EVENT_ON_UPDATE = 23, // Not Implemented + + // Area trigger + TRIGGER_EVENT_ON_TRIGGER = 24, // (event, player, triggerId) + + // Weather + WEATHER_EVENT_ON_CHANGE = 25, // (event, weather, state, grade) + + // Auction house + AUCTION_EVENT_ON_ADD = 26, // (event, AHObject) + AUCTION_EVENT_ON_REMOVE = 27, // (event, AHObject) + AUCTION_EVENT_ON_SUCCESSFUL = 28, // (event, AHObject) // NOT SUPPORTED YET + AUCTION_EVENT_ON_EXPIRE = 29, // (event, AHObject) // NOT SUPPORTED YET + + SERVER_EVENT_COUNT +}; + +// RegisterPlayerEvent(eventId, function) +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) + PLAYER_EVENT_ON_LEVEL_CHANGE = 13, // (event, player, oldLevel) + PLAYER_EVENT_ON_MONEY_CHANGE = 14, // (event, player, amount) + PLAYER_EVENT_ON_REPUTATION_CHANGE = 15, // (event, player, factionId, standing, incremental) + 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 + PLAYER_EVENT_ON_WHISPER = 19, // (event, player, msg, Type, lang, receiver) + PLAYER_EVENT_ON_GROUP_CHAT = 20, // (event, player, msg, Type, lang, group) - Can return false + PLAYER_EVENT_ON_GUILD_CHAT = 21, // (event, player, msg, Type, lang, guild) - Can return false + PLAYER_EVENT_ON_CHANNEL_CHAT = 22, // (event, player, msg, Type, lang, channel) - Can return false + 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) + 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_GM_TICKET_CREATE = 39, // (event, player, ticketText) + PLAYER_EVENT_ON_GM_TICKET_UPDATE = 40, // (event, player, ticketText) + PLAYER_EVENT_ON_GM_TICKET_DELETE = 41, // (event, player) + PLAYER_EVENT_ON_COMMAND = 42, // (event, player, command) - Can return false + + PLAYER_EVENT_COUNT +}; + +// RegisterGuildEvent(eventId, function) +enum GuildEventTypes +{ + // Guild + GUILD_EVENT_ON_ADD_MEMBER = 1, // (event, guild, player, rank) + GUILD_EVENT_ON_REMOVE_MEMBER = 2, // (event, guild, 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) + GUILD_EVENT_ON_DISBAND = 6, // (event, guild) + GUILD_EVENT_ON_MONEY_WITHDRAW = 7, // (event, guild, player, amount, isRepair) + GUILD_EVENT_ON_MONEY_DEPOSIT = 8, // (event, guild, player, amount) + GUILD_EVENT_ON_ITEM_MOVE = 9, // (event, guild, player, item, isSrcBank, srcContainer, srcSlotId, isDestBank, destContainer, destSlotId) + GUILD_EVENT_ON_EVENT = 10, // (event, guild, eventType, plrGUIDLow1, plrGUIDLow2, newRank) + GUILD_EVENT_ON_BANK_EVENT = 11, // (event, guild, eventType, tabId, playerGUIDLow, itemOrMoney, itemStackCount, destTabId) + + GUILD_EVENT_COUNT +}; + +// RegisterGroupEvent(eventId, function) +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 +}; + +// RegisterVehicleEvent(eventId, function) +enum VehicleEvents +{ + VEHICLE_EVENT_ON_INSTALL = 1, + VEHICLE_EVENT_ON_UNINSTALL = 2, + VEHICLE_EVENT_ON_RESET = 3, + VEHICLE_EVENT_ON_INSTALL_ACCESSORY = 4, + VEHICLE_EVENT_ON_ADD_PASSENGER = 5, + VEHICLE_EVENT_ON_REMOVE_PASSENGER = 6, + + VEHICLE_EVENT_COUNT +}; + +// RegisterCreatureEvent(entry, EventId, function) +enum CreatureEvents +{ + CREATURE_EVENT_ON_ENTER_COMBAT = 1, // (event, creature, target) + CREATURE_EVENT_ON_LEAVE_COMBAT = 2, // (event, creature) + CREATURE_EVENT_ON_TARGET_DIED = 3, // (event, creature, victim) + CREATURE_EVENT_ON_DIED = 4, // (event, creature, killer) + CREATURE_EVENT_ON_SPAWN = 5, // (event, creature) + CREATURE_EVENT_ON_REACH_WP = 6, // (event, creature, type, id) + CREATURE_EVENT_ON_AIUPDATE = 7, // (event, creature, diff) + CREATURE_EVENT_ON_RECEIVE_EMOTE = 8, // (event, creature, player, emoteid) + CREATURE_EVENT_ON_DAMAGE_TAKEN = 9, // (event, creature, attacker, damage) + CREATURE_EVENT_ON_PRE_COMBAT = 10, // (event, creature, target) + CREATURE_EVENT_ON_ATTACKED_AT = 11, // (event, creature, attacker) + CREATURE_EVENT_ON_OWNER_ATTACKED = 12, // (event, creature, target) + CREATURE_EVENT_ON_OWNER_ATTACKED_AT = 13, // (event, creature, attacker) + CREATURE_EVENT_ON_HIT_BY_SPELL = 14, // (event, creature, caster, spellid) + CREATURE_EVENT_ON_SPELL_HIT_TARGET = 15, // (event, creature, target, spellid) + CREATURE_EVENT_ON_SPELL_CLICK = 16, // (event, creature, clicker) + CREATURE_EVENT_ON_CHARMED = 17, // (event, creature, apply) + CREATURE_EVENT_ON_POSSESS = 18, // (event, creature, apply) + CREATURE_EVENT_ON_JUST_SUMMONED_CREATURE = 19, // (event, creature, summon) + CREATURE_EVENT_ON_SUMMONED_CREATURE_DESPAWN = 20, // (event, creature, summon) + CREATURE_EVENT_ON_SUMMONED_CREATURE_DIED = 21, // (event, creature, summon, killer) + CREATURE_EVENT_ON_SUMMONED = 22, // (event, creature, summoner) + CREATURE_EVENT_ON_RESET = 23, // (event, creature) + CREATURE_EVENT_ON_REACH_HOME = 24, // (event, creature) + CREATURE_EVENT_ON_CAN_RESPAWN = 25, // (event, creature) + CREATURE_EVENT_ON_CORPSE_REMOVED = 26, // (event, creature, respawndelay) + CREATURE_EVENT_ON_MOVE_IN_LOS = 27, // (event, creature, unit) + CREATURE_EVENT_ON_VISIBLE_MOVE_IN_LOS = 28, // (event, creature, unit) + CREATURE_EVENT_ON_PASSANGER_BOARDED = 29, // (event, creature, passanger, seatid, apply) + CREATURE_EVENT_ON_DUMMY_EFFECT = 30, // (event, caster, spellid, effindex, creature) + CREATURE_EVENT_ON_QUEST_ACCEPT = 31, // (event, player, creature, quest) + CREATURE_EVENT_ON_QUEST_SELECT = 32, // (event, player, creature, quest) + CREATURE_EVENT_ON_QUEST_COMPLETE = 33, // (event, player, creature, quest) + CREATURE_EVENT_ON_QUEST_REWARD = 34, // (event, player, creature, quest, opt) + CREATURE_EVENT_ON_DIALOG_STATUS = 35, // (event, player, creature) + CREATURE_EVENT_COUNT +}; + +// RegisterGameObjectEvent(entry, EventId, function) +enum GameObjectEvents +{ + GAMEOBJECT_EVENT_ON_AIUPDATE = 1, // (event, go, diff) + GAMEOBJECT_EVENT_ON_RESET = 2, // (event, go) // TODO + GAMEOBJECT_EVENT_ON_DUMMY_EFFECT = 3, // (event, caster, spellid, effindex, go) + GAMEOBJECT_EVENT_ON_QUEST_ACCEPT = 4, // (event, player, go, quest) + GAMEOBJECT_EVENT_ON_QUEST_REWARD = 5, // (event, player, go, quest, opt) + GAMEOBJECT_EVENT_ON_DIALOG_STATUS = 6, // (event, player, go) + GAMEOBJECT_EVENT_ON_DESTROYED = 7, // (event, go, player) // TODO + GAMEOBJECT_EVENT_ON_DAMAGED = 8, // (event, go, player) // TODO + GAMEOBJECT_EVENT_ON_LOOT_STATE_CHANGE = 9, // (event, go, state, unit) // TODO + GAMEOBJECT_EVENT_ON_GO_STATE_CHANGED = 10, // (event, go, state) // TODO + GAMEOBJECT_EVENT_ON_QUEST_COMPLETE = 11, // (event, player, go, quest) + GAMEOBJECT_EVENT_COUNT +}; + +// RegisterItemEvent(entry, EventId, function) +enum ItemEvents +{ + ITEM_EVENT_ON_DUMMY_EFFECT = 1, // (event, caster, spellid, effindex, item) + ITEM_EVENT_ON_USE = 2, // (event, player, item, target) + ITEM_EVENT_ON_QUEST_ACCEPT = 3, // (event, player, item, quest) + ITEM_EVENT_ON_EXPIRE = 4, // (event, player, itemid) + ITEM_EVENT_COUNT +}; + +// RegisterCreatureGossipEvent(entry, EventId, function) +// RegisterGameObjectGossipEvent(entry, EventId, function) +// RegisterItemGossipEvent(entry, EventId, function) +// RegisterPlayerGossipEvent(menu_id, EventId, function) +enum GossipEvents +{ + GOSSIP_EVENT_ON_HELLO = 1, // (event, player, object) - Object is the Creature/GameObject/Item + GOSSIP_EVENT_ON_SELECT = 2, // (event, player, object, sender, intid, code, menu_id) - Object is the Creature/GameObject/Item/Player, menu_id is only for player gossip + GOSSIP_EVENT_COUNT +}; + +class HookMgr +{ +public: + CreatureAI* GetAI(Creature* creature); + +#ifndef MANGOS + GameObjectAI* GetAI(GameObject* gameObject); +#endif + + /* Custom */ + bool OnCommand(Player* player, const char* text); + void OnWorldUpdate(uint32 diff); + void OnLootItem(Player* pPlayer, Item* pItem, uint32 count, uint64 guid); + void OnLootMoney(Player* pPlayer, uint32 amount); + void OnFirstLogin(Player* pPlayer); + void OnEquip(Player* pPlayer, Item* pItem, uint8 bag, uint8 slot); + void OnRepop(Player* pPlayer); + void OnResurrect(Player* pPlayer); + void OnQuestAbandon(Player* pPlayer, uint32 questId); // Not on TC + void OnGmTicketCreate(Player* pPlayer, std::string& ticketText); // Not on TC + void OnGmTicketUpdate(Player* pPlayer, std::string& ticketText); // Not on TC + void OnGmTicketDelete(Player* pPlayer); // Not on TC + InventoryResult OnCanUseItem(const Player* pPlayer, uint32 itemEntry); + void OnEngineRestart(); + + /* Item */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Item* pTarget); + bool OnQuestAccept(Player* pPlayer, Item* pItem, Quest const* pQuest); + bool OnUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets); + bool OnExpire(Player* pPlayer, ItemTemplate const* pProto); + void HandleGossipSelectOption(Player* pPlayer, Item* item, uint32 sender, uint32 action, std::string code); + + /* Creature */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, Creature* pTarget); + bool OnGossipHello(Player* pPlayer, Creature* pCreature); + bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action); + bool OnGossipSelectCode(Player* pPlayer, Creature* pCreature, uint32 sender, uint32 action, const char* code); + bool OnQuestAccept(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + bool OnQuestSelect(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + bool OnQuestComplete(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + bool OnQuestReward(Player* pPlayer, Creature* pCreature, Quest const* pQuest); + uint32 GetDialogStatus(Player* pPlayer, Creature* pCreature); // Not on TC + void OnSummoned(Creature* creature, Unit* summoner); + + /* GameObject */ + bool OnDummyEffect(Unit* pCaster, uint32 spellId, SpellEffIndex effIndex, GameObject* pTarget); + bool OnGossipHello(Player* pPlayer, GameObject* pGameObject); + bool OnGossipSelect(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action); + bool OnGossipSelectCode(Player* pPlayer, GameObject* pGameObject, uint32 sender, uint32 action, const char* code); + bool OnQuestAccept(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + bool OnQuestComplete(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + bool OnQuestReward(Player* pPlayer, GameObject* pGameObject, Quest const* pQuest); + bool OnGameObjectUse(Player* pPlayer, GameObject* pGameObject) { return false; }; // TODO? Not on TC + uint32 GetDialogStatus(Player* pPlayer, GameObject* pGameObject); + void OnDestroyed(GameObject* pGameObject, Player* pPlayer); // TODO + void OnDamaged(GameObject* pGameObject, Player* pPlayer); // TODO + void OnLootStateChanged(GameObject* pGameObject, uint32 state, Unit* pUnit); // TODO + void OnGameObjectStateChanged(GameObject* pGameObject, uint32 state); // TODO + void UpdateAI(GameObject* pGameObject, uint32 diff); + + /* Packet */ + bool OnPacketSend(WorldSession* session, WorldPacket& packet); + bool OnPacketReceive(WorldSession* session, WorldPacket& packet); + + /* Player */ + void OnPlayerEnterCombat(Player* pPlayer, Unit* pEnemy); + void OnPlayerLeaveCombat(Player* pPlayer); + void OnPVPKill(Player* pKiller, Player* pKilled); + void OnCreatureKill(Player* pKiller, Creature* pKilled); + void OnPlayerKilledByCreature(Creature* pKiller, Player* pKilled); + void OnLevelChanged(Player* pPlayer, uint8 oldLevel); + void OnFreeTalentPointsChanged(Player* pPlayer, uint32 newPoints); + void OnTalentsReset(Player* pPlayer, bool noCost); + void OnMoneyChanged(Player* pPlayer, int32& amount); + void OnGiveXP(Player* pPlayer, uint32& amount, Unit* pVictim); + void OnReputationChange(Player* pPlayer, uint32 factionID, int32& standing, bool incremental); + void OnDuelRequest(Player* pTarget, Player* pChallenger); + void OnDuelStart(Player* pStarter, Player* pChallenger); + void OnDuelEnd(Player* pWinner, Player* pLoser, DuelCompleteType type); + void OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Player* pReceiver); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Group* pGroup); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Guild* pGuild); + bool OnChat(Player* pPlayer, uint32 type, uint32 lang, std::string& msg, Channel* pChannel); + void OnEmote(Player* pPlayer, uint32 emote); + void OnTextEmote(Player* pPlayer, uint32 textEmote, uint32 emoteNum, uint64 guid); + void OnSpellCast(Player* pPlayer, Spell* pSpell, bool skipCheck); + void OnLogin(Player* pPlayer); + void OnLogout(Player* pPlayer); + void OnCreate(Player* pPlayer); + void OnDelete(uint32 guid); + void OnSave(Player* pPlayer); + void OnBindToInstance(Player* pPlayer, Difficulty difficulty, uint32 mapid, bool permanent); + void OnUpdateZone(Player* pPlayer, uint32 newZone, uint32 newArea); + void OnMapChanged(Player* pPlayer); // TODO + void HandleGossipSelectOption(Player* pPlayer, uint32 menuId, uint32 sender, uint32 action, std::string code); + +#ifndef MANGOS + /* Vehicle */ + void OnInstall(Vehicle* vehicle); + void OnUninstall(Vehicle* vehicle); + void OnReset(Vehicle* vehicle); + void OnInstallAccessory(Vehicle* vehicle, Creature* accessory); + void OnAddPassenger(Vehicle* vehicle, Unit* passenger, int8 seatId); + void OnRemovePassenger(Vehicle* vehicle, Unit* passenger); +#endif + + /* AreaTrigger */ + bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* pTrigger); + + /* Weather */ + void OnChange(Weather* weather, WeatherState state, float grade); // TODO + + /* Auction House */ + void OnAdd(AuctionHouseObject* auctionHouse); + void OnRemove(AuctionHouseObject* auctionHouse); + void OnSuccessful(AuctionHouseObject* auctionHouse); + void OnExpire(AuctionHouseObject* auctionHouse); + + /* Condition */ + + /* Transport */ + void OnAddPassenger(Transport* transport, Player* player); // TODO + void OnAddCreaturePassenger(Transport* transport, Creature* creature); // TODO + void OnRemovePassenger(Transport* transport, Player* player); // TODO + void OnRelocate(Transport* transport, uint32 waypointId, uint32 mapId, float x, float y, float z); // TODO + + /* Guild */ + void OnAddMember(Guild* guild, Player* player, uint32 plRank); + void OnRemoveMember(Guild* guild, Player* player, bool isDisbanding); + void OnMOTDChanged(Guild* guild, const std::string& newMotd); + void OnInfoChanged(Guild* guild, const std::string& newInfo); + void OnCreate(Guild* guild, Player* leader, const std::string& name); // TODO: Implement to TC + void OnDisband(Guild* guild); + void OnMemberWitdrawMoney(Guild* guild, Player* player, uint32& amount, bool isRepair); + void OnMemberDepositMoney(Guild* guild, Player* player, uint32& amount); + void OnItemMove(Guild* guild, Player* player, Item* pItem, bool isSrcBank, uint8 srcContainer, uint8 srcSlotId, bool isDestBank, uint8 destContainer, uint8 destSlotId); // TODO: Implement + void OnEvent(Guild* guild, uint8 eventType, uint32 playerGuid1, uint32 playerGuid2, uint8 newRank); // TODO: Implement + void OnBankEvent(Guild* guild, uint8 eventType, uint8 tabId, uint32 playerGuid, uint32 itemOrMoney, uint16 itemStackCount, uint8 destTabId); + + /* Group */ + void OnAddMember(Group* group, uint64 guid); + void OnInviteMember(Group* group, uint64 guid); + void OnRemoveMember(Group* group, uint64 guid, uint8 method); + void OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid); + void OnDisband(Group* group); + void OnCreate(Group* group, uint64 leaderGuid, GroupType groupType); +}; +#ifdef MANGOS +#define sHookMgr (&MaNGOS::Singleton::Instance()) +#else +#define sHookMgr ACE_Singleton::instance() +#endif + +#endif diff --git a/ItemMethods.h b/ItemMethods.h new file mode 100644 index 0000000..86fc257 --- /dev/null +++ b/ItemMethods.h @@ -0,0 +1,498 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaItem +{ + /* BOOLEAN */ + int IsSoulBound(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsSoulBound()); + return 1; + } + +#ifndef TBC + int IsBoundAccountWide(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsBoundAccountWide()); + return 1; + } +#endif + + int IsBoundByEnchant(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsBoundByEnchant()); + return 1; + } + + int IsNotBoundToPlayer(lua_State* L, Item* item) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, item->IsBindedNotWith(player)); + return 1; + } + + int IsLocked(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsLocked()); + return 1; + } + + int IsBag(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsBag()); + return 1; + } + + int IsCurrencyToken(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsCurrencyToken()); + return 1; + } + + int IsNotEmptyBag(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsNotEmptyBag()); + return 1; + } + + int IsBroken(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsBroken()); + return 1; + } + + int CanBeTraded(lua_State* L, Item* item) + { +#ifdef TBC + sEluna->Push(L, item->CanBeTraded()); +#else + bool mail = sEluna->CHECKVAL(L, 2, false); + sEluna->Push(L, item->CanBeTraded(mail)); +#endif + return 1; + } + + int IsInTrade(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsInTrade()); + return 1; + } + + int IsInBag(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsInBag()); + return 1; + } + + int IsEquipped(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsEquipped()); + return 1; + } + + int HasQuest(lua_State* L, Item* item) + { + uint32 quest = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, item->HasQuest(quest)); +#else + sEluna->Push(L, item->hasQuest(quest)); +#endif + return 1; + } + + int IsPotion(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsPotion()); + return 1; + } + +#ifndef CATA + int IsWeaponVellum(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsWeaponVellum()); + return 1; + } + + int IsArmorVellum(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsArmorVellum()); + return 1; + } +#endif + + int IsConjuredConsumable(lua_State* L, Item* item) + { + sEluna->Push(L, item->IsConjuredConsumable()); + return 1; + } + + int IsRefundExpired(lua_State* L, Item* item)// TODO: Implement core support + { + /*sEluna->Push(L, item->IsRefundExpired()); + return 1;*/ + return 0; // Temp till supported + } + + /* GETTERS */ + int GetItemLink(lua_State* L, Item* item) + { + // 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 + + int loc_idx = sEluna->CHECKVAL(L, 2, DEFAULT_LOCALE); + if (loc_idx < 0 || loc_idx >= MAX_LOCALES) + return luaL_argerror(L, 2, "valid LocaleConstant expected"); + + const ItemTemplate* temp = item->GetTemplate(); + std::string name = temp->Name1; + if (ItemLocale const* il = sObjectMgr->GetItemLocale(temp->ItemId)) + ObjectMgr::GetLocaleString(il->Name, loc_idx, name); + + if (int32 itemRandPropId = item->GetItemRandomPropertyId()) + { +#ifdef CATA + 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) + { + //std::string test(suffix[(name != temp->Name1) ? loc_idx : DEFAULT_LOCALE]); + //if (!test.empty()) + //{ + name += ' '; + name += suffix[(name != temp->Name1) ? loc_idx : DEFAULT_LOCALE]; + /*}*/ + } + } + + std::ostringstream oss; + oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec << + "|Hitem:" << temp->ItemId << ":" << + item->GetEnchantmentId(PERM_ENCHANTMENT_SLOT) << ":" << + item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT) << ":" << + item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_2) << ":" << + item->GetEnchantmentId(SOCK_ENCHANTMENT_SLOT_3) << ":" << + item->GetEnchantmentId(BONUS_ENCHANTMENT_SLOT) << ":" << + item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" << + (uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r"; + + sEluna->Push(L, oss.str()); + return 1; + } + + int GetGUID(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetGUIDLow()); + return 1; + } + + int GetOwnerGUID(lua_State* L, Item* item) + { +#ifdef MANGOS + sEluna->Push(L, item->GetOwnerGuid()); +#else + sEluna->Push(L, item->GetOwnerGUID()); +#endif + return 1; + } + + int GetOwner(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetOwner()); + return 1; + } + + int GetCount(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetCount()); + return 1; + } + + int GetMaxStackCount(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetMaxStackCount()); + return 1; + } + + int GetSlot(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetSlot()); + return 1; + } + + int GetBagSlot(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetBagSlot()); + return 1; + } + + int GetGUIDLow(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetGUIDLow()); + return 1; + } + + int GetEnchantmentId(lua_State* L, Item* item) + { + uint32 enchant_slot = sEluna->CHECKVAL(L, 2); + + if (enchant_slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) + return 0; + + sEluna->Push(L, item->GetEnchantmentId(EnchantmentSlot(enchant_slot))); + return 1; + } + + int GetSpellId(lua_State* L, Item* item) + { + uint32 index = sEluna->CHECKVAL(L, 2); + if (index >= MAX_ITEM_PROTO_SPELLS) + return luaL_argerror(L, 2, "valid SpellIndex expected"); + + sEluna->Push(L, item->GetTemplate()->Spells[index].SpellId); + return 1; + } + + int GetSpellTrigger(lua_State* L, Item* item) + { + uint32 index = sEluna->CHECKVAL(L, 2); + if (index >= MAX_ITEM_PROTO_SPELLS) + return luaL_argerror(L, 2, "valid SpellIndex expected"); + + sEluna->Push(L, item->GetTemplate()->Spells[index].SpellTrigger); + return 1; + } + + int GetClass(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->Class); + return 1; + } + + int GetSubClass(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->SubClass); + return 1; + } + + int GetName(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->Name1); + return 1; + } + + int GetDisplayId(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->DisplayInfoID); + return 1; + } + + int GetQuality(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->Quality); + return 1; + } + + int GetBuyCount(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->BuyCount); + return 1; + } + + int GetBuyPrice(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->BuyPrice); + return 1; + } + + int GetSellPrice(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->SellPrice); + return 1; + } + + int GetInventoryType(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->InventoryType); + return 1; + } + + int GetAllowableClass(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->AllowableClass); + return 1; + } + + int GetAllowableRace(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->AllowableRace); + return 1; + } + + int GetItemLevel(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->ItemLevel); + return 1; + } + + int GetRequiredLevel(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->RequiredLevel); + return 1; + } + +#ifdef WOTLK + int GetStatsCount(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->StatsCount); + return 1; + } +#endif + + int GetRandomProperty(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->RandomProperty); + return 1; + } + + int GetRandomSuffix(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->RandomSuffix); + return 1; + } + + int GetItemSet(lua_State* L, Item* item) + { + sEluna->Push(L, item->GetTemplate()->ItemSet); + return 1; + } + + int GetBagSize(lua_State* L, Item* item) + { + if (Bag* bag = item->ToBag()) + sEluna->Push(L, bag->GetBagSize()); + else + sEluna->Push(L, 0); + return 1; + } + + /* SETTERS */ + int SetOwner(lua_State* L, Item* item) + { + Player* player = sEluna->CHECKOBJ(L, 2); +#ifdef MANGOS + item->SetOwnerGuid(player->GET_GUID()); +#else + item->SetOwnerGUID(player->GET_GUID()); +#endif + return 0; + } + + int SetBinding(lua_State* L, Item* item) + { + bool soulbound = sEluna->CHECKVAL(L, 2); + + item->SetBinding(soulbound); + return 0; + } + + int SetCount(lua_State* L, Item* item) + { + uint32 count = sEluna->CHECKVAL(L, 2); + item->SetCount(count); + return 0; + } + + int SetEnchantment(lua_State* L, Item* item) + { + Player* owner = item->GetOwner(); + if (!owner) + { + sEluna->Push(L, false); + return 1; + } + + uint32 enchant = sEluna->CHECKVAL(L, 2); + if (!sSpellItemEnchantmentStore.LookupEntry(enchant)) + { + sEluna->Push(L, false); + return 1; + } + + EnchantmentSlot slot = (EnchantmentSlot)sEluna->CHECKVAL(L, 3); + if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) + return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); + + owner->ApplyEnchantment(item, slot, false); + item->SetEnchantment(slot, enchant, 0, 0); + owner->ApplyEnchantment(item, slot, true); + sEluna->Push(L, true); + return 1; + } + + /* OTHER */ + int ClearEnchantment(lua_State* L, Item* item) + { + Player* owner = item->GetOwner(); + if (!owner) + { + sEluna->Push(L, false); + return 1; + } + + EnchantmentSlot slot = (EnchantmentSlot)sEluna->CHECKVAL(L, 2); + if (slot >= MAX_INSPECTED_ENCHANTMENT_SLOT) + return luaL_argerror(L, 2, "valid EnchantmentSlot expected"); + + if (!item->GetEnchantmentId(slot)) + { + sEluna->Push(L, false); + return 1; + } + + owner->ApplyEnchantment(item, slot, false); + item->ClearEnchantment(slot); + sEluna->Push(L, true); + return 1; + } + + int SaveToDB(lua_State* L, Item* item) + { +#ifdef MANGOS + item->SaveToDB(); +#else + SQLTransaction trans = SQLTransaction(NULL); + item->SaveToDB(trans); +#endif + return 0; + } +}; +#endif diff --git a/LuaEngine.cpp b/LuaEngine.cpp new file mode 100644 index 0000000..f1a906a --- /dev/null +++ b/LuaEngine.cpp @@ -0,0 +1,895 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#include "LuaEngine.h" + +#ifdef MANGOS +INSTANTIATE_SINGLETON_1(Eluna); +#endif + +#if PLATFORM == PLATFORM_UNIX +#include +#endif + +extern void RegisterFunctions(lua_State* L); +extern void AddElunaScripts(); + +// Start or restart eluna. Returns true if started +bool StartEluna() +{ +#ifndef ELUNA +#ifndef MANGOS + { + TC_LOG_ERROR("eluna", "[Eluna]: LuaEngine is Disabled. (If you want to use it please enable in cmake)"); + return false; + } +#endif +#endif + + ELUNA_GUARD(); + bool restart = false; + if (sEluna->L) + { + restart = true; + sHookMgr->OnEngineRestart(); + TC_LOG_INFO("eluna", "[Eluna]: Restarting Lua Engine"); + + // Unregisters and stops all timed events + sEluna->m_EventMgr.RemoveEvents(); + + // Remove bindings + sEluna->PacketEventBindings.Clear(); + sEluna->ServerEventBindings.Clear(); + sEluna->PlayerEventBindings.Clear(); + sEluna->GuildEventBindings.Clear(); + sEluna->GroupEventBindings.Clear(); + + sEluna->CreatureEventBindings.Clear(); + sEluna->CreatureGossipBindings.Clear(); + sEluna->GameObjectEventBindings.Clear(); + sEluna->GameObjectGossipBindings.Clear(); + sEluna->ItemEventBindings.Clear(); + sEluna->ItemGossipBindings.Clear(); + sEluna->playerGossipBindings.Clear(); + sEluna->VehicleEventBindings.Clear(); + + lua_close(sEluna->L); + } + else + AddElunaScripts(); + +#ifdef MANGOS + // Check config file for eluna is enabled or disabled + if (!sWorld->getConfig(CONFIG_BOOL_ELUNA_ENABLED)) + { + TC_LOG_ERROR("eluna", "[Eluna]: LuaEngine is Disabled. (If you want to use it please set config in 'mangosd.conf')"); + return false; + } +#endif + + sEluna->L = luaL_newstate(); + TC_LOG_INFO("eluna", "[Eluna]: Lua Engine loaded."); + + LoadedScripts loadedScripts; + sEluna->LoadDirectory("lua_scripts", &loadedScripts); + luaL_openlibs(sEluna->L); + RegisterFunctions(sEluna->L); + + // Randomize math.random() + // The macro fails on TC for unknown reason + // luaL_dostring(sEluna->L, "math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )"); + if (!luaL_loadstring(sEluna->L, "math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )")) + lua_pcall(sEluna->L, 0, LUA_MULTRET, 0); + + uint32 count = 0; + char filename[200]; + for (std::set::const_iterator itr = loadedScripts.begin(); itr != loadedScripts.end(); ++itr) + { + strcpy(filename, itr->c_str()); + if (luaL_loadfile(sEluna->L, filename) != 0) + { + TC_LOG_ERROR("eluna", "[Eluna]: Error loading file `%s`.", itr->c_str()); + sEluna->report(sEluna->L); + } + else + { + int err = lua_pcall(sEluna->L, 0, 0, 0); + if (err != 0 && err == LUA_ERRRUN) + { + TC_LOG_ERROR("eluna", "[Eluna]: Error loading file `%s`.", itr->c_str()); + sEluna->report(sEluna->L); + } + } + ++count; + } + + /* + if (restart) + { + //! Iterate over every supported source type (creature and gameobject) + //! Not entirely sure how this will affect units in non-loaded grids. + { + HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + HashMapHolder::MapType& m = HashMapHolder::GetContainer(); + for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) + { + if (itr->second->IsInWorld()) // must check? + // if(sEluna->CreatureEventBindings->GetBindMap(iter->second->GetEntry())) // update all AI or just Eluna? + itr->second->AIM_Initialize(); + } + } + + { + HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + HashMapHolder::MapType& m = HashMapHolder::GetContainer(); + for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) + { + if (itr->second->IsInWorld()) // must check? + // if(sEluna->GameObjectEventBindings->GetBindMap(iter->second->GetEntry())) // update all AI or just Eluna? + itr->second->AIM_Initialize(); + } + } + } + */ + + TC_LOG_INFO("eluna", "[Eluna]: Loaded %u Lua scripts..", count); + return true; +} + +// Loads lua scripts from given directory +void Eluna::LoadDirectory(char* Dirname, LoadedScripts* lscr) +{ +#ifdef WIN32 + HANDLE hFile; + WIN32_FIND_DATA FindData; + memset(&FindData, 0, sizeof(FindData)); + char SearchName[MAX_PATH]; + + strcpy(SearchName, Dirname); + strcat(SearchName, "\\*.*"); + + hFile = FindFirstFile(SearchName, &FindData); + if (hFile == INVALID_HANDLE_VALUE) + { + TC_LOG_ERROR("eluna", "[Eluna]: Error No `lua_scripts` directory found! Creating a 'lua_scripts' directory."); + CreateDirectory("lua_scripts", NULL); + return; + } + + FindNextFile(hFile, &FindData); + while (FindNextFile(hFile, &FindData)) + { + if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + strcpy(SearchName, Dirname); + strcat(SearchName, "\\"); + strcat(SearchName, FindData.cFileName); + LoadDirectory(SearchName, lscr); + } + else + { + std::string fname = Dirname; + fname += "\\"; + fname += FindData.cFileName; + size_t len = strlen(fname.c_str()); + int i = 0; + char ext[MAX_PATH]; + while (len > 0) + { + ext[i++] = fname[--len]; + if (fname[len] == '.') + break; + } + ext[i++] = '\0'; + if (!_stricmp(ext, "aul.")) + { + TC_LOG_DEBUG("eluna", "[Eluna]: Load File: %s", fname.c_str()); + lscr->insert(fname); + } + } + } + FindClose(hFile); +#else + char* dir = strrchr(Dirname, '/'); + if (strcmp(Dirname, "..") == 0 || strcmp(Dirname, ".") == 0) + return; + + if (dir && (strcmp(dir, "/..") == 0 || strcmp(dir, "/.") == 0 || strcmp(dir, "/.svn") == 0)) + return; + + struct dirent** list; + int fileCount = scandir(Dirname, &list, 0, 0); + + if (fileCount <= 0 || !list) + return; + + struct stat attributes; + bool error; + while (fileCount--) + { + char _path[200]; + sprintf(_path, "%s/%s", Dirname, list[fileCount]->d_name); + if (stat(_path, &attributes) == -1) + { + error = true; + TC_LOG_ERROR("eluna", "[Eluna]: Error opening `%s`", _path); + } + else + error = false; + + if (!error && S_ISDIR(attributes.st_mode)) + LoadDirectory((char*)_path, lscr); + else + { + char* ext = strrchr(list[fileCount]->d_name, '.'); + if (ext && !strcmp(ext, ".lua")) + lscr->insert(_path); + } + free(list[fileCount]); + } + free(list); +#endif +} + +void Eluna::report(lua_State* L) +{ + const char* msg = lua_tostring(L, -1); + while (msg) + { + lua_pop(L, -1); + TC_LOG_ERROR("eluna", "%s", msg); + msg = lua_tostring(L, -1); + } +} + +void Eluna::BeginCall(int fReference) +{ + lua_settop(L, 0); // stack should be empty + lua_rawgeti(L, LUA_REGISTRYINDEX, (fReference)); +} + +bool Eluna::ExecuteCall(int params, int res) +{ + bool ret = true; + int top = lua_gettop(L); + + if (lua_type(L, top - params) == LUA_TFUNCTION) // is function + { + if (lua_pcall(L, params, res, 0)) + { + report(L); + ret = false; + } + } + else + { + ret = false; + if (params > 0) + { + for (int i = top; i >= (top - params); i--) + { + if (!lua_isnone(L, i)) + lua_remove(L, i); + } + } + } + return ret; +} + +void Eluna::EndCall(int res) +{ + for (int i = res; i > 0; i--) + { + if (!lua_isnone(L, res)) + lua_remove(L, res); + } +} + +void Eluna::Push(lua_State* L) +{ + lua_pushnil(L); +} +void Eluna::Push(lua_State* L, const uint64 l) +{ + std::ostringstream ss; + ss << l; + sEluna->Push(L, ss.str()); +} +void Eluna::Push(lua_State* L, const int64 l) +{ + std::ostringstream ss; + ss << l; + sEluna->Push(L, ss.str()); +} +void Eluna::Push(lua_State* L, const uint32 u) +{ + lua_pushunsigned(L, u); +} +void Eluna::Push(lua_State* L, const int32 i) +{ + lua_pushinteger(L, i); +} +void Eluna::Push(lua_State* L, const double d) +{ + lua_pushnumber(L, d); +} +void Eluna::Push(lua_State* L, const float f) +{ + lua_pushnumber(L, f); +} +void Eluna::Push(lua_State* L, const bool b) +{ + lua_pushboolean(L, b); +} +void Eluna::Push(lua_State* L, const std::string str) +{ + lua_pushstring(L, str.c_str()); +} +void Eluna::Push(lua_State* L, const char* str) +{ + lua_pushstring(L, str); +} +void Eluna::Push(lua_State* L, Pet const* pet) +{ + Push(L, pet->ToCreature()); +} +void Eluna::Push(lua_State* L, TempSummon const* summon) +{ + Push(L, summon->ToCreature()); +} +void Eluna::Push(lua_State* L, Unit const* unit) +{ + if (!unit) + { + Push(L); + return; + } + switch (unit->GetTypeId()) + { + case TYPEID_UNIT: + Push(L, unit->ToCreature()); + break; + case TYPEID_PLAYER: + Push(L, unit->ToPlayer()); + break; + default: + ElunaTemplate::push(L, unit); + } +} +void Eluna::Push(lua_State* L, WorldObject const* obj) +{ + if (!obj) + { + Push(L); + return; + } + switch (obj->GetTypeId()) + { + case TYPEID_UNIT: + Push(L, obj->ToCreature()); + break; + case TYPEID_PLAYER: + Push(L, obj->ToPlayer()); + break; + case TYPEID_GAMEOBJECT: + Push(L, obj->ToGameObject()); + break; + case TYPEID_CORPSE: + Push(L, obj->ToCorpse()); + break; + default: + ElunaTemplate::push(L, obj); + } +} +void Eluna::Push(lua_State* L, Object const* obj) +{ + if (!obj) + { + Push(L); + return; + } + switch (obj->GetTypeId()) + { + case TYPEID_UNIT: + Push(L, obj->ToCreature()); + break; + case TYPEID_PLAYER: + Push(L, obj->ToPlayer()); + break; + case TYPEID_GAMEOBJECT: + Push(L, obj->ToGameObject()); + break; + case TYPEID_CORPSE: + Push(L, obj->ToCorpse()); + break; + default: + ElunaTemplate::push(L, obj); + } +} +template<> bool Eluna::CHECKVAL(lua_State* L, int narg) +{ + return lua_isnumber(L, narg) ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg); +} +template<> bool Eluna::CHECKVAL(lua_State* L, int narg, bool def) +{ + return lua_isnone(L, narg) ? def : lua_isnumber(L, narg) ? luaL_optnumber(L, narg, 1) ? true : false : lua_toboolean(L, narg); +} +template<> float Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checknumber(L, narg); +} +template<> float Eluna::CHECKVAL(lua_State* L, int narg, float def) +{ + return luaL_optnumber(L, narg, def); +} +template<> double Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checknumber(L, narg); +} +template<> double Eluna::CHECKVAL(lua_State* L, int narg, double def) +{ + return luaL_optnumber(L, narg, def); +} +template<> int8 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkint(L, narg); +} +template<> int8 Eluna::CHECKVAL(lua_State* L, int narg, int8 def) +{ + return luaL_optint(L, narg, def); +} +template<> uint8 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkunsigned(L, narg); +} +template<> uint8 Eluna::CHECKVAL(lua_State* L, int narg, uint8 def) +{ + return luaL_optunsigned(L, narg, def); +} +template<> int16 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkint(L, narg); +} +template<> int16 Eluna::CHECKVAL(lua_State* L, int narg, int16 def) +{ + return luaL_optint(L, narg, def); +} +template<> uint16 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkunsigned(L, narg); +} +template<> uint16 Eluna::CHECKVAL(lua_State* L, int narg, uint16 def) +{ + return luaL_optunsigned(L, narg, def); +} +template<> uint32 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkunsigned(L, narg); +} +template<> uint32 Eluna::CHECKVAL(lua_State* L, int narg, uint32 def) +{ + return luaL_optunsigned(L, narg, def); +} +template<> int32 Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checklong(L, narg); +} +template<> int32 Eluna::CHECKVAL(lua_State* L, int narg, int32 def) +{ + return luaL_optlong(L, narg, def); +} +template<> const char* Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkstring(L, narg); +} +template<> const char* Eluna::CHECKVAL(lua_State* L, int narg, const char* def) +{ + return luaL_optstring(L, narg, def); +} +template<> std::string Eluna::CHECKVAL(lua_State* L, int narg) +{ + return luaL_checkstring(L, narg); +} +template<> std::string Eluna::CHECKVAL(lua_State* L, int narg, std::string def) +{ + return luaL_optstring(L, narg, def.c_str()); +} +template<> uint64 Eluna::CHECKVAL(lua_State* L, int narg) +{ + const char* c_str = luaL_optstring(L, narg, NULL); + if (!c_str) + return luaL_argerror(L, narg, "uint64 (as string) expected"); + uint64 l = 0; + sscanf(c_str, UI64FMTD, &l); + return l; +} +template<> uint64 Eluna::CHECKVAL(lua_State* L, int narg, uint64 def) +{ + const char* c_str = luaL_checkstring(L, narg); + if (!c_str) + return def; + uint64 l = 0; + sscanf(c_str, UI64FMTD, &l); + return l; +} +template<> int64 Eluna::CHECKVAL(lua_State* L, int narg) +{ + const char* c_str = luaL_optstring(L, narg, NULL); + if (!c_str) + return luaL_argerror(L, narg, "int64 (as string) expected"); + int64 l = 0; + sscanf(c_str, SI64FMTD, &l); + return l; +} +template<> int64 Eluna::CHECKVAL(lua_State* L, int narg, int64 def) +{ + const char* c_str = luaL_checkstring(L, narg); + if (!c_str) + return def; + int64 l = 0; + sscanf(c_str, SI64FMTD, &l); + return l; +} +#define TEST_OBJ(T, O, E, F)\ +{\ + if (!O || !O->F())\ +{\ + if (E)\ +{\ + std::string errmsg(ElunaTemplate::tname);\ + errmsg += " expected";\ + luaL_argerror(L, narg, errmsg.c_str());\ +}\ + return NULL;\ +}\ + return O->F();\ +} +template<> Unit* Eluna::CHECKOBJ(lua_State* L, int narg, bool error) +{ + WorldObject* obj = CHECKOBJ(L, narg, false); + TEST_OBJ(Unit, obj, error, ToUnit); +} +template<> Player* Eluna::CHECKOBJ(lua_State* L, int narg, bool error) +{ + WorldObject* obj = CHECKOBJ(L, narg, false); + TEST_OBJ(Player, obj, error, ToPlayer); +} +template<> Creature* Eluna::CHECKOBJ(lua_State* L, int narg, bool error) +{ + WorldObject* obj = CHECKOBJ(L, narg, false); + TEST_OBJ(Creature, obj, error, ToCreature); +} +template<> GameObject* Eluna::CHECKOBJ(lua_State* L, int narg, bool error) +{ + WorldObject* obj = CHECKOBJ(L, narg, false); + TEST_OBJ(GameObject, obj, error, ToGameObject); +} +template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error) +{ + WorldObject* obj = CHECKOBJ(L, narg, false); + TEST_OBJ(Corpse, obj, error, ToCorpse); +} +#undef TEST_OBJ + +// Saves the function reference ID given to the register type's store for given entry under the given event +void Eluna::Register(uint8 regtype, uint32 id, uint32 evt, int functionRef) +{ + switch (regtype) + { + case REGTYPE_PACKET: + if (evt < NUM_MSG_TYPES) + { + PacketEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_SERVER: + if (evt < SERVER_EVENT_COUNT) + { + ServerEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_PLAYER: + if (evt < PLAYER_EVENT_COUNT) + { + PlayerEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_GUILD: + if (evt < GUILD_EVENT_COUNT) + { + GuildEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_GROUP: + if (evt < GROUP_EVENT_COUNT) + { + GroupEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_VEHICLE: + if (evt < VEHICLE_EVENT_COUNT) + { + VehicleEventBindings.Insert(evt, functionRef); + return; + } + break; + + case REGTYPE_CREATURE: + if (evt < CREATURE_EVENT_COUNT) + { + if (!sObjectMgr->GetCreatureTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a creature with (ID: %d)!", id); + return; + } + + sEluna->CreatureEventBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_CREATURE_GOSSIP: + if (evt < GOSSIP_EVENT_COUNT) + { + if (!sObjectMgr->GetCreatureTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a creature with (ID: %d)!", id); + return; + } + + sEluna->CreatureGossipBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_GAMEOBJECT: + if (evt < GAMEOBJECT_EVENT_COUNT) + { + if (!sObjectMgr->GetGameObjectTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", id); + return; + } + + sEluna->GameObjectEventBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_GAMEOBJECT_GOSSIP: + if (evt < GOSSIP_EVENT_COUNT) + { + if (!sObjectMgr->GetGameObjectTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a gameobject with (ID: %d)!", id); + return; + } + + sEluna->GameObjectGossipBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_ITEM: + if (evt < ITEM_EVENT_COUNT) + { + if (!sObjectMgr->GetItemTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a item with (ID: %d)!", id); + return; + } + + sEluna->ItemEventBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_ITEM_GOSSIP: + if (evt < GOSSIP_EVENT_COUNT) + { + if (!sObjectMgr->GetItemTemplate(id)) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Couldn't find a item with (ID: %d)!", id); + return; + } + + sEluna->ItemGossipBindings.Insert(id, evt, functionRef); + return; + } + break; + + case REGTYPE_PLAYER_GOSSIP: + if (evt < GOSSIP_EVENT_COUNT) + { + sEluna->playerGossipBindings.Insert(id, evt, functionRef); + return; + } + break; + + default: + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Unknown register type (regtype %d, id %d, event %d)", regtype, id, evt); + return; + } + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, functionRef); + luaL_error(L, "Unknown event type (regtype %d, id %d, event %d)", regtype, id, evt); +} + +void Eluna::EventBind::Clear() +{ + for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) + { + for (ElunaBindingMap::iterator it = itr->second.begin(); it != itr->second.end(); ++it) + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, (*it)); + itr->second.clear(); + } + Bindings.clear(); +} + +void Eluna::EventBind::Insert(int eventId, int funcRef) +{ + Bindings[eventId].push_back(funcRef); +} + +bool Eluna::EventBind::BeginCall(int eventId) const +{ + if (Bindings.empty()) + return false; + if (Bindings.find(eventId) == Bindings.end()) + return false; + lua_settop(sEluna->L, 0); // stack should be empty + sEluna->Push(sEluna->L, eventId); + return true; +} + +void Eluna::EventBind::ExecuteCall() +{ + int eventId = sEluna->CHECKVAL(sEluna->L, 1); + int params = lua_gettop(sEluna->L); + for (ElunaBindingMap::const_iterator it = Bindings[eventId].begin(); it != Bindings[eventId].end(); ++it) + { + lua_rawgeti(sEluna->L, LUA_REGISTRYINDEX, (*it)); // Fetch function + for (int i = 1; i <= params; ++i) // Copy original pushed params + lua_pushvalue(sEluna->L, i); + sEluna->ExecuteCall(params, LUA_MULTRET); // Do call and leave results to stack + } + for (int i = params; i > 0; --i) // Remove original pushed params + if (!lua_isnone(sEluna->L, i)) + lua_remove(sEluna->L, i); + // Results in stack, otherwise stack clean +} + +void Eluna::EventBind::EndCall() const +{ + lua_settop(sEluna->L, 0); // stack should be empty +}; + +void Eluna::EntryBind::Clear() +{ + for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) + { + for (ElunaBindingMap::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, it->second); + itr->second.clear(); + } + Bindings.clear(); +} + +void Eluna::EntryBind::Insert(uint32 entryId, int eventId, int funcRef) +{ + if (Bindings[entryId][eventId]) + { + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, funcRef); // free the unused ref + luaL_error(sEluna->L, "A function is already registered for entry (%d) event (%d)", entryId, eventId); + } + else + Bindings[entryId][eventId] = funcRef; +} + +EventMgr::LuaEvent::LuaEvent(EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj) : +events(_events), funcRef(_funcRef), delay(_delay), calls(_calls), obj(_obj) +{ + if (_events) + sEluna->m_EventMgr.LuaEvents[_events].insert(this); // Able to access the event if we have the processor +} + +EventMgr::LuaEvent::~LuaEvent() +{ + if (events) + { + // Attempt to remove the pointer from LuaEvents + EventMgr::EventMap::const_iterator it = sEluna->m_EventMgr.LuaEvents.find(events); // Get event set + if (it != sEluna->m_EventMgr.LuaEvents.end()) + sEluna->m_EventMgr.LuaEvents[events].erase(this);// Remove pointer + } + luaL_unref(sEluna->L, LUA_REGISTRYINDEX, funcRef); // Free lua function ref +} + +bool EventMgr::LuaEvent::Execute(uint64 time, uint32 diff) +{ + ELUNA_GUARD(); + bool remove = (calls == 1); + if (!remove) + events->AddEvent(this, events->CalculateTime(delay)); // Reschedule before calling incase RemoveEvents used + sEluna->BeginCall(funcRef); + sEluna->Push(sEluna->L, funcRef); + sEluna->Push(sEluna->L, delay); + sEluna->Push(sEluna->L, calls); + if (!remove && calls) + --calls; + sEluna->Push(sEluna->L, obj); + sEluna->ExecuteCall(4, 0); + return remove; // Destory (true) event if not run +} + +// Lua taxi helper functions +uint32 LuaTaxiMgr::nodeId = 500; +void LuaTaxiMgr::StartTaxi(Player* player, uint32 pathid) +{ + if (pathid >= sTaxiPathNodesByPath.size()) + return; + + TaxiPathNodeList const& path = sTaxiPathNodesByPath[pathid]; + if (path.size() < 2) + return; + + std::vector nodes; + nodes.resize(2); + nodes[0] = path[0].index; + nodes[1] = path[path.size() - 1].index; + + player->ActivateTaxiPathTo(nodes); +} + +uint32 LuaTaxiMgr::AddPath(std::list nodes, uint32 mountA, uint32 mountH, uint32 price, uint32 pathId) +{ + if (nodes.size() < 2) + return 0; + if (!pathId) + pathId = sTaxiPathNodesByPath.size(); + if (sTaxiPathNodesByPath.size() <= pathId) + sTaxiPathNodesByPath.resize(pathId + 1); + sTaxiPathNodesByPath[pathId].clear(); + sTaxiPathNodesByPath[pathId].resize(nodes.size()); + uint32 startNode = nodeId; + uint32 index = 0; + for (std::list::const_iterator it = nodes.begin(); it != nodes.end(); ++it) + { + TaxiPathNodeEntry entry = *it; + entry.path = pathId; + TaxiNodesEntry* nodeEntry = new TaxiNodesEntry(); + nodeEntry->ID = index; + nodeEntry->map_id = entry.mapid; + nodeEntry->MountCreatureID[0] = mountH; + nodeEntry->MountCreatureID[1] = mountA; + nodeEntry->x = entry.x; + nodeEntry->y = entry.y; + nodeEntry->z = entry.z; + sTaxiNodesStore.SetEntry(nodeId, nodeEntry); + entry.index = nodeId++; + sTaxiPathNodesByPath[pathId].set(index++, TaxiPathNodePtr(new TaxiPathNodeEntry(entry))); + } + if (startNode >= nodeId) + return 0; + sTaxiPathSetBySource[startNode][nodeId - 1] = TaxiPathBySourceAndDestination(pathId, price); + return pathId; +} diff --git a/LuaEngine.h b/LuaEngine.h new file mode 100644 index 0000000..5f598e6 --- /dev/null +++ b/LuaEngine.h @@ -0,0 +1,689 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef __ELUNA__H +#define __ELUNA__H + +extern "C" +{ +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +}; + +#include "Includes.h" +#include "HookMgr.h" + +// Required +#include "AccountMgr.h" +#include "ArenaTeam.h" +#include "AuctionHouseMgr.h" +#include "Cell.h" +#include "CellImpl.h" +#include "Chat.h" +#include "Channel.h" +#include "DBCStores.h" +#include "GossipDef.h" +#include "GridNotifiers.h" +#include "GridNotifiersImpl.h" +#include "Group.h" +#include "Guild.h" +#include "GuildMgr.h" +#include "Language.h" +#include "Mail.h" +#include "MapManager.h" +#include "ObjectAccessor.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "Player.h" +#include "Pet.h" +#include "ReputationMgr.h" +#include "revision.h" +#include "ScriptMgr.h" +#include "Spell.h" +#include "SpellAuras.h" +#include "SpellMgr.h" +#include "TemporarySummon.h" +#include "World.h" +#include "WorldPacket.h" +#include "WorldSession.h" +#ifdef MANGOS +#include "ReactorAI.h" +#include "revision_nr.h" +#else +#include "ScriptedCreature.h" +#include "SpellInfo.h" +#include "WeatherMgr.h" +#endif +#ifndef TBC +#include "Vehicle.h" +#endif + +typedef std::set LoadedScripts; + +#define ELUNA_GUARD() \ + ACE_Guard< ACE_Thread_Mutex > ELUNA_GUARD_OBJECT (sEluna->lock); + +#ifdef MANGOS +#undef sWorld +#undef sMapMgr +#undef sGuildMgr +#undef sObjectMgr +#undef sAccountMgr +#undef sObjectAccessor +#define sWorld (&MaNGOS::Singleton::Instance()) +#define sMapMgr (&MapManager::Instance()) +#define sGuildMgr (&MaNGOS::Singleton::Instance()) +#define sObjectMgr (&MaNGOS::Singleton::Instance()) +#define sAccountMgr (&MaNGOS::Singleton::Instance()) +#define sObjectAccessor (&ObjectAccessor::Instance()) +#define MAKE_NEW_GUID(l, e, h) ObjectGuid(h, e, l) +#define GUID_TYPE ObjectGuid +#define GET_GUID GetObjectGuid +#define GetGameObjectTemplate GetGameObjectInfo +#define GetItemTemplate GetItemPrototype +#define TC_LOG_INFO(L, ...) sLog.outString(__VA_ARGS__); +#define TC_LOG_ERROR(L, ...) sLog.outErrorEluna(__VA_ARGS__); +#define TC_LOG_DEBUG(L, ...) sLog.outDebug(__VA_ARGS__); +#define CORE_VERSION REVISION_NR +#define CORE_NAME "MaNGOS" +#define SERVER_MSG_STRING SERVER_MSG_CUSTOM +#define MAX_LOCALES MAX_LOCALE +#define OVERRIDE override +#define DIALOG_STATUS_SCRIPTED_NO_STATUS DIALOG_STATUS_UNDEFINED +#define TempSummon TemporarySummon +#define PLAYER_FIELD_LIFETIME_HONORABLE_KILLS PLAYER_FIELD_LIFETIME_HONORBALE_KILLS +#define MAX_TALENT_SPECS MAX_TALENT_SPEC_COUNT +#define Vehicle VehicleInfo +#define GUID_ENPART(guid) ObjectGuid(guid).GetEntry() +#define GUID_LOPART(guid) ObjectGuid(guid).GetCounter() +#define GUID_HIPART(guid) ObjectGuid(guid).GetHigh() +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 +}; +#ifdef TBC +#define SPELL_AURA_MOD_KILL_XP_PCT SPELL_AURA_MOD_XP_PCT +#endif +#else +#define GUID_TYPE uint64 +#define GET_GUID GetGUID +#define CORE_VERSION _DATE +#define CORE_NAME "TrinityCore" +#define REGEN_TIME_FULL +#define ThreatList ThreatContainer::StorageType +#ifdef CATA +#define NUM_MSG_TYPES NUM_OPCODE_HANDLERS +#endif +#endif + +template +struct ElunaRegister +{ + const char* name; + int(*mfunc)(lua_State*, T*); +}; + +template +class ElunaTemplate +{ +public: + static const char* tname; + static bool manageMemory; + + static int type(lua_State* L) + { + lua_pushstring(L, tname); + return 1; + } + + static int gcT(lua_State* L) + { + if (!manageMemory) + return 0; + T* obj = check(L, 1); + delete obj; // Deleting NULL should be safe + return 1; + } + + // name will be used as type name + // If gc is true, lua will handle the memory management for object pushed + // gc should be used if pushing for example WorldPacket, + // that will only be needed on lua side and will not be managed by TC/mangos/ + static void Register(lua_State* L, const char* name, bool gc = false) + { + tname = name; + manageMemory = gc; + + lua_settop(L, 0); // clean stack + + lua_newtable(L); + int methods = lua_gettop(L); + + luaL_newmetatable(L, tname); + int metatable = lua_gettop(L); + + // store method table in globals so that + // scripts can add functions in Lua + lua_pushvalue(L, methods); + lua_setglobal(L, tname); + + // hide metatable + lua_pushvalue(L, methods); + lua_setfield(L, metatable, "__metatable"); + + lua_pushvalue(L, methods); + lua_setfield(L, metatable, "__index"); + + lua_pushcfunction(L, tostringT); + lua_setfield(L, metatable, "__tostring"); + + lua_pushcfunction(L, gcT); + lua_setfield(L, metatable, "__gc"); + + lua_newtable(L); + lua_setmetatable(L, methods); + } + + template + static void SetMethods(lua_State* L, ElunaRegister* methodTable) + { + if (!methodTable) + return; + if (!lua_istable(L, 1)) + return; + lua_pushstring(L, "GetObjectType"); + lua_pushcclosure(L, type, 0); + lua_settable(L, 1); + for (; methodTable->name; ++methodTable) + { + lua_pushstring(L, methodTable->name); + lua_pushlightuserdata(L, (void*)methodTable); + lua_pushcclosure(L, thunk, 1); + lua_settable(L, 1); + } + } + + static int push(lua_State* L, T const* obj) + { + if (!obj) + { + lua_pushnil(L); + return lua_gettop(L); + } + luaL_getmetatable(L, tname); + if (lua_isnoneornil(L, -1)) + return luaL_error(L, "%s missing metatable", tname); + T const** ptrHold = (T const**)lua_newuserdata(L, sizeof(T**)); + if (ptrHold) + { + *ptrHold = obj; + lua_pushvalue(L, -2); + lua_setmetatable(L, -2); + } + lua_replace(L, -2); + return lua_gettop(L); + } + + static T* check(lua_State* L, int narg, bool error = true) + { + T** ptrHold = static_cast(lua_touserdata(L, narg)); + if (!ptrHold) + { + if (error) + { + std::string errmsg(ElunaTemplate::tname); + errmsg += " expected"; + luaL_argerror(L, narg, errmsg.c_str()); + } + return NULL; + } + return *ptrHold; + } + + static int thunk(lua_State* L) + { + T* obj = check(L, 1); // get self + ElunaRegister* l = static_cast*>(lua_touserdata(L, lua_upvalueindex(1))); + if (!obj) + return 0; + return l->mfunc(L, obj); + } + + static int tostringT(lua_State* L) + { + char buff[32]; + T** ptrHold = (T**)lua_touserdata(L, 1); + sprintf(buff, "%p", *ptrHold); + lua_pushfstring(L, "%s (%s)", tname, buff); + return 1; + } +}; + +struct EventMgr +{ + struct LuaEvent; + + typedef std::set EventSet; + typedef std::map EventMap; + // typedef UNORDERED_MAP ProcessorMap; + + EventMap LuaEvents; // LuaEvents[processor] = {LuaEvent, LuaEvent...} + // ProcessorMap Processors; // Processors[guid] = processor + EventProcessor GlobalEvents; + + struct LuaEvent : public BasicEvent + { + LuaEvent(EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj); + + ~LuaEvent(); + + // Should never execute on dead events + bool Execute(uint64 time, uint32 diff); + + EventProcessor* events; // Pointer to events (holds the timed event) + int funcRef; // Lua function reference ID, also used as event ID + uint32 delay; // Delay between event calls + uint32 calls; // Amount of calls to make, 0 for infinite + Object* obj; // Object to push + }; + + // Should be run on world tick + void Update(uint32 diff) + { + GlobalEvents.Update(diff); + } + + // Updates processor stored for guid || remove from Update() + // Should be run on gameobject tick + /*void Update(uint64 guid, uint32 diff) + { + if (Processors.find(guid) == Processors.end()) + return; + Processors[guid].Update(diff); + }*/ + + // Aborts all lua events + void KillAllEvents(EventProcessor* events) + { + if (!events) + return; + if (LuaEvents.empty()) + return; + EventMap::const_iterator it = LuaEvents.find(events); // Get event set + if (it == LuaEvents.end()) + return; + if (it->second.empty()) + return; + for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end();) // Loop events + (*(itr++))->to_Abort = true; // Abort event + } + + // Remove all timed events + void RemoveEvents() + { + if (!LuaEvents.empty()) + for (EventMap::const_iterator it = LuaEvents.begin(); it != LuaEvents.end();) // loop processors + KillAllEvents((it++)->first); + LuaEvents.clear(); // remove pointers + // This is handled automatically on delete + // for (ProcessorMap::iterator it = Processors.begin(); it != Processors.end();) + // (it++)->second.KillAllEvents(true); + // Processors.clear(); // remove guid saved processors + GlobalEvents.KillAllEvents(true); + } + + // Remove timed events from processor + void RemoveEvents(EventProcessor* events) + { + if (!events) + return; + KillAllEvents(events); + LuaEvents.erase(events); // remove pointer set + } + + // Remove timed events from guid + // void RemoveEvents(uint64 guid) + //{ + // if (Processors.empty()) + // return; + // if (Processors.find(guid) != Processors.end()) + // LuaEvents.erase(&Processors[guid]); + // // Processors[guid].KillAllEvents(true); // remove events + // Processors.erase(guid); // remove processor + //} + + // Adds a new event to the processor and returns the eventID or 0 (Never negative) + int AddEvent(EventProcessor* events, int funcRef, uint32 delay, uint32 calls, Object* obj = NULL) + { + if (!events || funcRef <= 0) // If funcRef <= 0, function reference failed + return 0; // on fail always return 0. funcRef can be negative. + events->AddEvent(new LuaEvent(events, funcRef, delay, calls, obj), events->CalculateTime(delay)); + return funcRef; // return the event ID + } + + // Creates a processor for the guid if needed and adds the event to it + // int AddEvent(uint64 guid, int funcRef, uint32 delay, uint32 calls, Object* obj = NULL) + //{ + // if (!guid) // 0 should be unused + // return 0; + // return AddEvent(&Processors[guid], funcRef, delay, calls, obj); + //} + + // Finds the event that has the ID from events + LuaEvent* GetEvent(EventProcessor* events, int eventId) + { + if (!events || !eventId) + return NULL; + if (LuaEvents.empty()) + return NULL; + EventMap::const_iterator it = LuaEvents.find(events); // Get event set + if (it == LuaEvents.end()) + return NULL; + if (it->second.empty()) + return NULL; + for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr) // Loop events + if ((*itr) && (*itr)->funcRef == eventId) // Check if the event has our ID + return *itr; // Return the event if found + return NULL; + } + + // Remove the event with the eventId from processor + // Returns true if event is removed + bool RemoveEvent(EventProcessor* events, int eventId) // eventId = funcRef + { + if (!events || !eventId) + return false; + LuaEvent* luaEvent = GetEvent(events, eventId); + if (!luaEvent) + return false; + luaEvent->to_Abort = true; // Set to remove on next call + LuaEvents[events].erase(luaEvent); // Remove pointer + return true; + } + + // Remove event by ID from processor stored for guid + /*bool RemoveEvent(uint64 guid, int eventId) + { + if (Processors.empty()) + return false; + if (!guid || Processors.find(guid) == Processors.end()) + return false; + return RemoveEvent(&Processors[guid], eventId); + }*/ + + // Removes the eventId from all events + void RemoveEvent(int eventId) + { + if (!eventId) + return; + if (LuaEvents.empty()) + return; + for (EventMap::const_iterator it = LuaEvents.begin(); it != LuaEvents.end();) // loop processors + if (RemoveEvent((it++)->first, eventId)) + break; // succesfully remove the event, stop loop. + } + + ~EventMgr() + { + RemoveEvents(); + } +}; + +class Eluna +{ +public: + friend class ScriptMgr; + lua_State* L; + EventMgr m_EventMgr; + ACE_Thread_Mutex lock; + + Eluna() + { + L = NULL; + } + + ~Eluna() + { + } + + struct EventBind + { + typedef std::vector ElunaBindingMap; + typedef std::map ElunaEntryMap; + + ~EventBind() + { + Clear(); + } + + void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) + void Insert(int eventId, int funcRef); // Inserts a new registered event + + // Gets the binding std::map containing all registered events with the function refs for the entry + ElunaBindingMap* GetBindMap(int eventId) + { + if (Bindings.empty()) + return NULL; + ElunaEntryMap::iterator itr = Bindings.find(eventId); + if (itr == Bindings.end()) + return NULL; + + return &itr->second; + } + + // Checks if there are events for ID, if so, cleans stack and pushes eventId + bool BeginCall(int eventId) const; + // Loops through all registered events for the eventId at stack index 1 + // Copies the whole stack as arguments for the called function. Before Executing, push all params to stack! + // Leaves return values from all functions in order to the stack. + void ExecuteCall(); + void EndCall() const; + + ElunaEntryMap Bindings; // Binding store Bindings[eventId] = {funcRef}; + }; + + struct EntryBind + { + typedef std::map ElunaBindingMap; + typedef std::map ElunaEntryMap; + + ~EntryBind() + { + Clear(); + } + + void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset) + void Insert(uint32 entryId, int eventId, int funcRef); // Inserts a new registered event + + // Gets the function ref of an entry for an event + int GetBind(uint32 entryId, int eventId) const + { + if (Bindings.empty()) + return 0; + ElunaEntryMap::const_iterator itr = Bindings.find(entryId); + if (itr == Bindings.end() || itr->second.empty()) + return 0; + ElunaBindingMap::const_iterator itr2 = itr->second.find(eventId); + if (itr2 == itr->second.end()) + return 0; + return itr2->second; + } + + // Gets the binding std::map containing all registered events with the function refs for the entry + const ElunaBindingMap* GetBindMap(uint32 entryId) const + { + if (Bindings.empty()) + return NULL; + ElunaEntryMap::const_iterator itr = Bindings.find(entryId); + if (itr == Bindings.end()) + return NULL; + + return &itr->second; + } + + // Returns true if the entry has registered binds + bool HasBinds(uint32 entryId) const + { + if (Bindings.empty()) + return false; + return Bindings.find(entryId) != Bindings.end(); + } + + ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef; + }; + + // Use templates for EventBind + EventBind PacketEventBindings; + EventBind ServerEventBindings; + EventBind PlayerEventBindings; + EventBind GuildEventBindings; + EventBind GroupEventBindings; + EventBind VehicleEventBindings; + + EntryBind CreatureEventBindings; + EntryBind CreatureGossipBindings; + EntryBind GameObjectEventBindings; + EntryBind GameObjectGossipBindings; + EntryBind ItemEventBindings; + EntryBind ItemGossipBindings; + EntryBind playerGossipBindings; + + static void report(lua_State*); + void Register(uint8 reg, uint32 id, uint32 evt, int func); + void BeginCall(int fReference); + bool ExecuteCall(int params, int res); + void EndCall(int res); + void LoadDirectory(char* directory, LoadedScripts* scr); + + // Pushes + void Push(lua_State*); // nil + void Push(lua_State*, const uint64); + void Push(lua_State*, const int64); + void Push(lua_State*, const uint32); + void Push(lua_State*, const int32); + void Push(lua_State*, const bool); + void Push(lua_State*, const float); + void Push(lua_State*, const double); + void Push(lua_State*, const char*); + void Push(lua_State*, const std::string); + template void Push(lua_State* L, T const* ptr) + { + ElunaTemplate::push(L, ptr); + } + void Push(lua_State* L, Object const* obj); + void Push(lua_State* L, WorldObject const* obj); + void Push(lua_State* L, Unit const* unit); + void Push(lua_State* L, Pet const* pet); + void Push(lua_State* L, TempSummon const* summon); + + // Checks + template T CHECKVAL(lua_State* L, int narg); + template T CHECKVAL(lua_State* L, int narg, T def); + template T* CHECKOBJ(lua_State* L, int narg, bool error = true) + { + return ElunaTemplate::check(L, narg, error); + } + + struct ObjectGUIDCheck + { + ObjectGUIDCheck(GUID_TYPE guid) : _guid(guid) { } + bool operator()(WorldObject* object) + { + return object->GET_GUID() == _guid; + } + + GUID_TYPE _guid; + }; + + // Binary predicate to sort WorldObjects based on the distance to a reference WorldObject + struct ObjectDistanceOrderPred + { + ObjectDistanceOrderPred(WorldObject const* pRefObj, bool ascending = true) : m_refObj(pRefObj), m_ascending(ascending) { } + bool operator()(WorldObject const* pLeft, WorldObject const* pRight) const + { + return m_ascending ? m_refObj->GetDistanceOrder(pLeft, pRight) : !m_refObj->GetDistanceOrder(pLeft, pRight); + } + + WorldObject const* m_refObj; + const bool m_ascending; + }; + + // Doesn't get self + struct WorldObjectInRangeCheck + { + WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range, + uint16 typeMask = 0, uint32 entry = 0, uint32 hostile = 0) : i_nearest(nearest), + i_obj(obj), i_range(range), i_typeMask(typeMask), i_entry(entry), i_hostile(hostile) {} + WorldObject const& GetFocusObject() const { return *i_obj; } + bool operator()(WorldObject* u) + { + if (i_typeMask && !u->isType(TypeMask(i_typeMask))) + return false; + if (i_entry && u->GetEntry() != i_entry) + return false; + if (i_obj->GET_GUID() == u->GET_GUID()) + return false; + if (!i_obj->IsWithinDistInMap(u, i_range)) + return false; + if (Unit* unit = u->ToUnit()) + { +#ifdef MANGOS + if (!unit->isAlive()) + return false; +#else + if (!unit->IsAlive()) + return false; +#endif + if (i_hostile) + { + if (const Unit* obj = i_obj->ToUnit()) + { + if ((i_hostile == 1) != obj->IsHostileTo(unit)) + return false; + } + } + } + if (i_nearest) + i_range = i_obj->GetDistance(u); + return true; + } + + WorldObject const* i_obj; + float i_range; + uint16 i_typeMask; + uint32 i_entry; + bool i_nearest; + uint32 i_hostile; + + WorldObjectInRangeCheck(WorldObjectInRangeCheck const&); + }; +}; +template<> Unit* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); +template<> Player* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); +template<> Creature* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); +template<> GameObject* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); +template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); + +#ifdef MANGOS +#define sEluna (&MaNGOS::Singleton::Instance()) +#else +#define sEluna ACE_Singleton::instance() +#endif + +class LuaTaxiMgr +{ +private: + static uint32 nodeId; +public: + static void StartTaxi(Player* player, uint32 pathid); + static uint32 AddPath(std::list nodes, uint32 mountA, uint32 mountH, uint32 price = 0, uint32 pathId = 0); +}; +#endif diff --git a/LuaFunctions.cpp b/LuaFunctions.cpp new file mode 100644 index 0000000..e342722 --- /dev/null +++ b/LuaFunctions.cpp @@ -0,0 +1,1215 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +// Eluna +#include "LuaEngine.h" +// Methods +#include "GlobalMethods.h" +#include "ObjectMethods.h" +#include "WorldObjectMethods.h" +#include "UnitMethods.h" +#include "PlayerMethods.h" +#include "CreatureMethods.h" +#include "GroupMethods.h" +#include "GuildMethods.h" +#include "GameObjectMethods.h" +#include "QueryMethods.h" +#include "AuraMethods.h" +#include "ItemMethods.h" +#include "WorldPacketMethods.h" +#include "SpellMethods.h" +#include "QuestMethods.h" +#include "MapMethods.h" +#include "CorpseMethods.h" +#include "WeatherMethods.h" +#include "VehicleMethods.h" + +void RegisterGlobals(lua_State* L) +{ + // Hooks + lua_register(L, "RegisterPacketEvent", &LuaGlobalFunctions::RegisterPacketEvent); // RegisterPacketEvent(opcodeID, function) + lua_register(L, "RegisterServerEvent", &LuaGlobalFunctions::RegisterServerEvent); // RegisterServerEvent(event, function) + lua_register(L, "RegisterPlayerEvent", &LuaGlobalFunctions::RegisterPlayerEvent); // RegisterPlayerEvent(event, function) + lua_register(L, "RegisterGuildEvent", &LuaGlobalFunctions::RegisterGuildEvent); // RegisterGuildEvent(event, function) + lua_register(L, "RegisterGroupEvent", &LuaGlobalFunctions::RegisterGroupEvent); // RegisterGroupEvent(event, function) + lua_register(L, "RegisterCreatureEvent", &LuaGlobalFunctions::RegisterCreatureEvent); // RegisterCreatureEvent(entry, event, function) + lua_register(L, "RegisterCreatureGossipEvent", &LuaGlobalFunctions::RegisterCreatureGossipEvent); // RegisterCreatureGossipEvent(entry, event, function) + lua_register(L, "RegisterGameObjectEvent", &LuaGlobalFunctions::RegisterGameObjectEvent); // RegisterGameObjectEvent(entry, event, function) + lua_register(L, "RegisterGameObjectGossipEvent", &LuaGlobalFunctions::RegisterGameObjectGossipEvent); // RegisterGameObjectGossipEvent(entry, event, function) + lua_register(L, "RegisterItemEvent", &LuaGlobalFunctions::RegisterItemEvent); // RegisterItemEvent(entry, event, function) + lua_register(L, "RegisterItemGossipEvent", &LuaGlobalFunctions::RegisterItemGossipEvent); // RegisterItemGossipEvent(entry, event, function) + lua_register(L, "RegisterPlayerGossipEvent", &LuaGlobalFunctions::RegisterPlayerGossipEvent); // RegisterPlayerGossipEvent(menu_id, event, function) + + // Getters + lua_register(L, "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine); // GetLuaEngine() - Returns ElunaEngine + lua_register(L, "GetCoreName", &LuaGlobalFunctions::GetCoreName); // GetCoreName() - Returns core name + lua_register(L, "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion); // GetCoreVersion() - Returns core version string + lua_register(L, "GetQuest", &LuaGlobalFunctions::GetQuest); // GetQuest(questId) - Returns quest object + lua_register(L, "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID); // GetPlayerByGUID(guid) - Returns player object by GUID + lua_register(L, "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName); // GetPlayerByName(name) - Returns player object by player name + lua_register(L, "GetGameTime", &LuaGlobalFunctions::GetGameTime); // GetGameTime() - Returns game time + lua_register(L, "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld); // GetPlayersInWorld([team, onlyGM]) - Returns a table with all player objects. Team can be 0 for ally, 1 for horde and 2 for neutral + lua_register(L, "GetPlayersInMap", &LuaGlobalFunctions::GetPlayersInMap); // GetPlayersInWorld(mapId[, instanceId, team]) - Returns a table with all player objects in map. Team can be 0 for ally, 1 for horde and 2 for neutral + lua_register(L, "GetGuildByName", &LuaGlobalFunctions::GetGuildByName); // GetGuildByName(name) - Returns guild object by the guild name + lua_register(L, "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID); // GetGuildByLeaderGUID(guid) - Returns guild by it's leader's guid + lua_register(L, "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount); // GetPlayerCount() - Returns the server's player count + lua_register(L, "GetPlayerGUID", &LuaGlobalFunctions::GetPlayerGUID); // GetPlayerGUID(lowguid) - Generates GUID (uint64) string from player lowguid UNDOCUMENTED + lua_register(L, "GetItemGUID", &LuaGlobalFunctions::GetItemGUID); // GetItemGUID(lowguid) - Generates GUID (uint64) string from item lowguid UNDOCUMENTED + lua_register(L, "GetObjectGUID", &LuaGlobalFunctions::GetObjectGUID); // GetObjectGUID(lowguid, entry) - Generates GUID (uint64) string from gameobject lowguid and entry UNDOCUMENTED + lua_register(L, "GetUnitGUID", &LuaGlobalFunctions::GetUnitGUID); // GetUnitGUID(lowguid, entry) - Generates GUID (uint64) string from unit (creature) lowguid and entry UNDOCUMENTED + lua_register(L, "GetGUIDLow", &LuaGlobalFunctions::GetGUIDLow); // GetGUIDLow(guid) - Returns GUIDLow (uint32) from guid (uint64 as string) UNDOCUMENTED + lua_register(L, "GetGUIDType", &LuaGlobalFunctions::GetGUIDType); // GetGUIDType(guid) - Returns Type (uint32) from guid (uint64 as string) UNDOCUMENTED + lua_register(L, "GetGUIDEntry", &LuaGlobalFunctions::GetGUIDEntry); // GetGUIDEntry(guid) - Returns Entry (uint32) from guid (uint64 as string), may be always 0 UNDOCUMENTED + lua_register(L, "bit_not", &LuaGlobalFunctions::bit_not); // bit_not(a) - Returns ~a UNDOCUMENTED + lua_register(L, "bit_xor", &LuaGlobalFunctions::bit_xor); // bit_xor(a, b) - Returns a ^ b UNDOCUMENTED + lua_register(L, "bit_rshift", &LuaGlobalFunctions::bit_rshift); // bit_rshift(a, b) - Returns a >> b UNDOCUMENTED + lua_register(L, "bit_lshift", &LuaGlobalFunctions::bit_lshift); // bit_lshift(a, b) - Returns a << b UNDOCUMENTED + lua_register(L, "bit_or", &LuaGlobalFunctions::bit_or); // bit_or(a, b) - Returns a | b UNDOCUMENTED + lua_register(L, "bit_and", &LuaGlobalFunctions::bit_and); // bit_and(a, b) - Returns a & b UNDOCUMENTED + lua_register(L, "GetItemLink", &LuaGlobalFunctions::GetItemLink); // GetItemLink(entry[, localeIndex]) - Returns the shift clickable link of the item. Item name translated if translate available for provided locale index UNDOCUMENTED + lua_register(L, "GetMapById", &LuaGlobalFunctions::GetMapById); // GetMapById(mapId, instance) - Returns map object of id specified. UNDOCUMENTED + + // Other + // lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); // ReloadEluna() - Reload's Eluna engine. Returns true if reload succesful. + lua_register(L, "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage); // SendWorldMessage(msg) - Sends a broadcast message to everyone + lua_register(L, "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery); // WorldDBQuery(sql) - Executes given SQL query to world database instantly and returns a QueryResult object + lua_register(L, "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute); // WorldDBExecute(sql) - Executes given SQL query to world database (not instant) + lua_register(L, "CharDBQuery", &LuaGlobalFunctions::CharDBQuery); // CharDBQuery(sql) - Executes given SQL query to character database instantly and returns a QueryResult object + lua_register(L, "CharDBExecute", &LuaGlobalFunctions::CharDBExecute); // CharDBExecute(sql) - Executes given SQL query to character database (not instant) + lua_register(L, "AuthDBQuery", &LuaGlobalFunctions::AuthDBQuery); // AuthDBQuery(sql) - Executes given SQL query to auth/logon database instantly and returns a QueryResult object + lua_register(L, "AuthDBExecute", &LuaGlobalFunctions::AuthDBExecute); // AuthDBExecute(sql) - Executes given SQL query to auth/logon database (not instant) + lua_register(L, "CreateLuaEvent", &LuaGlobalFunctions::CreateLuaEvent); // CreateLuaEvent(function, delay, calls) - Creates a global timed event. Returns Event ID. Calls set to 0 calls infinitely. + lua_register(L, "RemoveEventById", &LuaGlobalFunctions::RemoveEventById); // RemoveEventById(eventId, [all_events]) - Removes a global timed event by it's ID. If all_events is true, can remove any timed event by ID (unit, gameobject, global..) + lua_register(L, "RemoveEvents", &LuaGlobalFunctions::RemoveEvents); // RemoveEvents([all_events]) - Removes all global timed events. Removes all timed events (unit, gameobject, global) if all_events is true + lua_register(L, "PerformIngameSpawn", &LuaGlobalFunctions::PerformIngameSpawn); // PerformIngameSpawn(spawntype, entry, mapid, instanceid, x, y, z, o[, save, DurOrResptime, phase]) - spawntype: 1 Creature, 2 Object. DurOrResptime is respawntime for gameobjects and despawntime for creatures if creature is not saved. Returns spawned creature/gameobject + lua_register(L, "CreatePacket", &LuaGlobalFunctions::CreatePacket); // CreatePacket(opcode, size) - Creates a new packet object + lua_register(L, "AddVendorItem", &LuaGlobalFunctions::AddVendorItem); // AddVendorItem(entry, itemId, maxcount, incrtime, extendedcost) - Adds an item to vendor entry. + lua_register(L, "VendorRemoveItem", &LuaGlobalFunctions::VendorRemoveItem); // VendorRemoveItem(entry, item) - Removes an item from vendor entry + lua_register(L, "VendorRemoveAllItems", &LuaGlobalFunctions::VendorRemoveAllItems); // VendorRemoveAllItems(entry) - Removes all items from vendor entry + lua_register(L, "Kick", &LuaGlobalFunctions::Kick); // Kick(player) - Kicks given player + lua_register(L, "Ban", &LuaGlobalFunctions::Ban); // Ban(banMode(integer), nameOrIP(string), duration(string), reason(string), player(whoBanned)) - Banmode: 0 account, 1 character, 2 IP + lua_register(L, "SaveAllPlayers", &LuaGlobalFunctions::SaveAllPlayers); // SaveAllPlayers() - Saves all players + lua_register(L, "SendMail", &LuaGlobalFunctions::SendMail); // SendMail(subject, text, receiverLowGUID[, sender, stationary, delay, itemEntry, itemAmount, itemEntry2, itemAmount2...]) - Sends a mail to player with lowguid. use nil to use default values on optional arguments. Sender is an optional player object. UNDOCUMENTED + lua_register(L, "AddTaxiPath", &LuaGlobalFunctions::AddTaxiPath); // AddTaxiPath(pathTable, mountA, mountH[, price, pathId]) - Adds a new taxi path. Returns the path's ID. Will replace an existing path if pathId provided and already used. path table structure: T = {{map, x, y, z[, actionFlag, delay, arrivalEvId, departEvId]}, {...}, ...} UDOCUMENTED + lua_register(L, "AddCorpse", &LuaGlobalFunctions::AddCorpse); // AddCorpse(corpse) - Adds the player's corpse to the world. More specifically, the cell. + lua_register(L, "RemoveCorpse", &LuaGlobalFunctions::RemoveCorpse); // RemoveCorpse(corpse) - Removes the player's corpse from the world. + lua_register(L, "ConvertCorpseForPlayer", &LuaGlobalFunctions::ConvertCorpseForPlayer); // ConvertCorpseFromPlayer(guid[, insignia]) - Converts the player's corpse to bones. Adding insignia for PvP is optional (true or false). + lua_register(L, "RemoveOldCorpses", &LuaGlobalFunctions::RemoveOldCorpses); // RemoveOldCorpses() - Converts (removes) old corpses that aren't bones. + lua_register(L, "FindWeather", &LuaGlobalFunctions::FindWeather); // FindWeather(zoneId) - Finds the weather by zoneId and returns the weather + lua_register(L, "AddWeather", &LuaGlobalFunctions::AddWeather); // AddWeather(zoneId) - Adds weather to the following zone, also returns weather + lua_register(L, "RemoveWeather", &LuaGlobalFunctions::RemoveWeather); // RemoveWeather(zoneId) - Removes weather from a zone + lua_register(L, "SendFineWeatherToPlayer", &LuaGlobalFunctions::SendFineWeatherToPlayer); // SendFineWeatherToPlayer(player) - Sends WEATHER_STATE_FINE weather to the +} + +ElunaRegister ObjectMethods[] = +{ + // Getters + { "GetEntry", &LuaObject::GetEntry }, // :GetEntry() - Returns the object's entryId + { "GetGUID", &LuaObject::GetGUID }, // :GetGUID() - Returns uint64 guid as hex string + { "GetGUIDLow", &LuaObject::GetGUIDLow }, // :GetGUIDLow() - Returns uint32 guid (low guid) that is used in database. + { "GetInt32Value", &LuaObject::GetInt32Value }, // :GetInt32Value(index) - returns an int value from object fields + { "GetUInt32Value", &LuaObject::GetUInt32Value }, // :GetUInt32Value(index) - returns an uint value from object fields + { "GetFloatValue", &LuaObject::GetFloatValue }, // :GetFloatValue(index) - returns a float value from object fields + { "GetByteValue", &LuaObject::GetByteValue }, // :GetByteValue(index, offset) - returns a byte value from object fields + { "GetUInt16Value", &LuaObject::GetUInt16Value }, // :GetUInt16Value(index, offset) - returns a uint16 value from object fields + { "GetScale", &LuaObject::GetScale }, // :GetScale() + { "GetTypeId", &LuaObject::GetTypeId }, // :GetTypeId() - Returns the object's typeId + + // Setters + { "SetInt32Value", &LuaObject::SetInt32Value }, // :SetInt32Value(index, value) - Sets an int value for the object + { "SetUInt32Value", &LuaObject::SetUInt32Value }, // :SetUInt32Value(index, value) - Sets an uint value for the object + { "UpdateUInt32Value", &LuaObject::UpdateUInt32Value }, // :UpdateUInt32Value(index, value) - Updates an uint value for the object + { "SetFloatValue", &LuaObject::SetFloatValue }, // :SetFloatValue(index, value) - Sets a float value for the object + { "SetByteValue", &LuaObject::SetByteValue }, // :SetByteValue(index, offset, value) - Sets a byte value for the object + { "SetUInt16Value", &LuaObject::SetUInt16Value }, // :SetUInt16Value(index, offset, value) - Sets an uint16 value for the object + { "SetInt16Value", &LuaObject::SetInt16Value }, // :SetInt16Value(index, offset, value) - Sets an int16 value for the object + { "SetScale", &LuaObject::SetScale }, // :SetScale(scale) + { "SetFlag", &LuaObject::SetFlag }, // :SetFlag(index, flag) + + // Boolean + { "IsInWorld", &LuaObject::IsInWorld }, // :IsInWorld() - Returns if the object is in world + { "HasFlag", &LuaObject::HasFlag }, // :HasFlag(index, flag) + + // Other + { "ToGameObject", &LuaObject::ToGameObject }, // :ToGameObject() + { "ToUnit", &LuaObject::ToUnit }, // :ToUnit() + { "ToCreature", &LuaObject::ToCreature }, // :ToCreature() + { "ToPlayer", &LuaObject::ToPlayer }, // :ToPlayer() + { "ToCorpse", &LuaObject::ToCorpse }, // :ToCorpse() + { "RemoveFlag", &LuaObject::RemoveFlag }, // :RemoveFlag(index, flag) + + { NULL, NULL }, +}; + +ElunaRegister WorldObjectMethods[] = +{ + // Getters + { "GetName", &LuaWorldObject::GetName }, // :GetName() + { "GetMap", &LuaWorldObject::GetMap }, // :GetMap() - Returns the WorldObject's current map object +#ifndef TBC + { "GetPhaseMask", &LuaWorldObject::GetPhaseMask }, // :GetPhaseMask() +#endif + { "GetInstanceId", &LuaWorldObject::GetInstanceId }, // :GetInstanceId() + { "GetAreaId", &LuaWorldObject::GetAreaId }, // :GetAreaId() + { "GetZoneId", &LuaWorldObject::GetZoneId }, // :GetZoneId() + { "GetMapId", &LuaWorldObject::GetMapId }, // :GetMapId() - Returns the WorldObject's current map ID + { "GetX", &LuaWorldObject::GetX }, // :GetX() + { "GetY", &LuaWorldObject::GetY }, // :GetY() + { "GetZ", &LuaWorldObject::GetZ }, // :GetZ() + { "GetO", &LuaWorldObject::GetO }, // :GetO() + { "GetLocation", &LuaWorldObject::GetLocation }, // :GetLocation() - returns X, Y, Z and O co - ords (in that order) + { "GetPlayersInRange", &LuaWorldObject::GetPlayersInRange }, // :GetPlayersInRange([range]) - Returns a table with players in range of the WorldObject. + { "GetCreaturesInRange", &LuaWorldObject::GetCreaturesInRange }, // :GetCreaturesInRange([range, entry]) - Returns a table with creatures of given entry in range of the WorldObject. + { "GetGameObjectsInRange", &LuaWorldObject::GetGameObjectsInRange }, // :GetGameObjectsInRange([range, entry]) - Returns a table with gameobjects of given entry in range of the WorldObject. + { "GetNearestPlayer", &LuaWorldObject::GetNearestPlayer }, // :GetNearestPlayer([range]) - Returns nearest player in sight or given range. + { "GetNearestGameObject", &LuaWorldObject::GetNearestGameObject }, // :GetNearestGameObject([range, entry]) - Returns nearest gameobject with given entry in sight or given range entry can be 0 or nil for any. + { "GetNearestCreature", &LuaWorldObject::GetNearestCreature }, // :GetNearestCreature([range, entry]) - Returns nearest creature with given entry in sight or given range entry can be 0 or nil for any. + { "GetNearObject", &LuaWorldObject::GetNearObject }, // :GetNearObject([nearest, range, typemask, entry, hostile]) - Returns nearest WorldObject or table of objects in given range with given typemask (can contain several types) with given entry if given. Hostile can be 0 for any, 1 hostile, 2 friendly + { "GetWorldObject", &LuaWorldObject::GetWorldObject }, // :GetWorldObject(guid) - Returns a world object (creature, player, gameobject) from the guid. The world object returned must be on the same map as the world object in the arguments. + { "GetDistance", &LuaWorldObject::GetDistance }, // :GetDistance(WorldObject or x, y, z) - Returns the distance between 2 objects or location + { "GetRelativePoint", &LuaWorldObject::GetRelativePoint }, // :GetRelativePoint(dist, rad) - Returns the x, y and z of a point dist away from worldobject. + { "GetAngle", &LuaWorldObject::GetAngle }, // :GetAngle(WorldObject or x, y) - Returns angle between world object and target or x and y coords. + + // Other + { "SummonGameObject", &LuaWorldObject::SummonGameObject }, // :SummonGameObject(entry, x, y, z, o[, respawnDelay]) - Spawns an object to location. Returns the object or nil + { "SpawnCreature", &LuaWorldObject::SpawnCreature }, // :SpawnCreature(entry, x, y, z, o[, spawnType, despawnDelay]) - Spawns a creature to location that despawns after given time (0 for infinite). Returns the creature or nil + { "SendPacket", &LuaWorldObject::SendPacket }, // :SendPacket(packet) - Sends a specified packet to everyone around + + { NULL, NULL }, +}; + +ElunaRegister UnitMethods[] = +{ + // Getters + { "GetLevel", &LuaUnit::GetLevel }, // :GetLevel() + { "GetHealth", &LuaUnit::GetHealth }, // :GetHealth() + { "GetDisplayId", &LuaUnit::GetDisplayId }, // :GetDisplayId() + { "GetNativeDisplayId", &LuaUnit::GetNativeDisplayId }, // :GetNativeDisplayId() + { "GetPower", &LuaUnit::GetPower }, // :GetPower(index) - returns power at index. Index can be omitted + { "GetMaxPower", &LuaUnit::GetMaxPower }, // :GetMaxPower(index) - returns power at index. Index can be omitted + { "GetPowerType", &LuaUnit::GetPowerType }, // :GetPowerType() - Returns the power type + { "GetMaxHealth", &LuaUnit::GetMaxHealth }, // :GetMaxHealth() + { "GetHealthPct", &LuaUnit::GetHealthPct }, // :GetHealthPct() + { "GetPowerPct", &LuaUnit::GetPowerPct }, // :GetPowerPct(power_id) + { "GetGender", &LuaUnit::GetGender }, // :GetGender() - returns the gender where male = 0 female = 1 + { "GetRace", &LuaUnit::GetRace }, // :GetRace() + { "GetClass", &LuaUnit::GetClass }, // :GetClass() + { "GetClassAsString", &LuaUnit::GetClassAsString }, // :GetClassAsString() + { "GetAura", &LuaUnit::GetAura }, // :GetAura(spellID) - returns aura object + { "GetCombatTime", &LuaUnit::GetCombatTime }, // :GetCombatTime() - Returns how long the unit has been in combat + { "GetFaction", &LuaUnit::GetFaction }, // :GetFaction() - Returns the unit's factionId + { "GetCurrentSpell", &LuaUnit::GetCurrentSpell }, // :GetCurrentSpell(type) - Returns the currently casted spell of given type if any + { "GetCreatureType", &LuaUnit::GetCreatureType }, // :GetCreatureType() - Returns the unit's type + { "GetMountId", &LuaUnit::GetMountId }, // :GetMountId() + { "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, // :GetOwnerGUID() - Returns the GUID of the owner + { "GetOwner", &LuaUnit::GetOwner }, // :GetOwner() - Returns the owner + { "GetFriendlyUnitsInRange", &LuaUnit::GetFriendlyUnitsInRange }, // :GetFriendlyUnitsInRange([range]) - Returns a list of friendly units in range, can return nil + { "GetUnfriendlyUnitsInRange", &LuaUnit::GetUnfriendlyUnitsInRange }, // :GetUnfriendlyUnitsInRange([range]) - Returns a list of unfriendly units in range, can return nil + { "GetOwnerGUID", &LuaUnit::GetOwnerGUID }, // :GetOwnerGUID() - Returns the UNIT_FIELD_SUMMONEDBY owner + { "GetCreatorGUID", &LuaUnit::GetCreatorGUID }, // :GetCreatorGUID() - Returns the UNIT_FIELD_CREATEDBY creator + { "GetMinionGUID", &LuaUnit::GetMinionGUID }, // :GetMinionGUID() - Returns the UNIT_FIELD_SUMMON unit's minion GUID + { "GetCharmerGUID", &LuaUnit::GetCharmerGUID }, // :GetCharmerGUID() - Returns the UNIT_FIELD_CHARMEDBY charmer + { "GetCharmGUID", &LuaUnit::GetCharmGUID }, // :GetCharmGUID() - Returns the unit's UNIT_FIELD_CHARM guid + { "GetPetGUID", &LuaUnit::GetPetGUID }, // :GetPetGUID() - Returns the unit's pet GUID +#ifndef TBC + { "GetCritterGUID", &LuaUnit::GetCritterGUID }, // :GetCritterGUID() - Returns the critter's GUID +#endif + { "GetControllerGUID", &LuaUnit::GetControllerGUID }, // :GetControllerGUID() - Returns the Charmer or Owner GUID + { "GetControllerGUIDS", &LuaUnit::GetControllerGUIDS }, // :GetControllerGUIDS() - Returns the charmer, owner or unit's own GUID + { "GetStandState", &LuaUnit::GetStandState }, // :GetStandState() - Returns the unit's stand state + { "GetVictim", &LuaUnit::GetVictim }, // :GetVictim() - Returns creature's current target + { "GetStat", &LuaUnit::GetStat }, // :GetStat(stat) + { "GetBaseSpellPower", &LuaUnit::GetBaseSpellPower }, // :GetBaseSpellPower() +#ifndef TBC + { "GetVehicleKit", &LuaUnit::GetVehicleKit }, // :GetVehicleKit() - Gets unit's Vehicle kit if the unit is a vehicle + // {"GetVehicle", &LuaUnit::GetVehicle}, // :GetVehicle() - Gets the Vehicle kit of the vehicle the unit is on +#endif + + // Setters + { "SetFaction", &LuaUnit::SetFaction }, // :SetFaction(factionId) - Sets the unit's faction + { "SetLevel", &LuaUnit::SetLevel }, // :SetLevel(amount) + { "SetHealth", &LuaUnit::SetHealth }, // :SetHealth(amount) + { "SetMaxHealth", &LuaUnit::SetMaxHealth }, // :SetMaxHealth(amount) + { "SetPower", &LuaUnit::SetPower }, // :SetPower(index, amount) + { "SetMaxPower", &LuaUnit::SetMaxPower }, // :SetMaxPower(index, amount) + { "SetDisplayId", &LuaUnit::SetDisplayId }, // :SetDisplayId(id) + { "SetNativeDisplayId", &LuaUnit::SetNativeDisplayId }, // :SetNativeDisplayId(id) + { "SetFacing", &LuaUnit::SetFacing }, // :SetFacing(o) - Sets the Unit facing to arg + { "SetFacingToObject", &LuaUnit::SetFacingToObject }, // :SetFacingToObject(worldObject) - Sets the Unit facing towards the WorldObject +#ifndef TBC + { "SetPhaseMask", &LuaUnit::SetPhaseMask }, // :SetPhaseMask(Phase[, update]) - Sets the phase of the unit +#endif + { "SetSpeed", &LuaUnit::SetSpeed }, // :SetSpeed(type, speed[, forced]) - Sets speed for the movement type (0 = walk, 1 = run ..) + // {"SetStunned", &LuaUnit::SetStunned}, // :SetStunned([enable]) - Stuns or removes stun + // {"SetRooted", &LuaUnit::SetRooted}, // :SetRooted([enable]) - Roots or removes root + // {"SetConfused", &LuaUnit::SetConfused}, // :SetConfused([enable]) - Sets confused or removes confusion + // {"SetFeared", &LuaUnit::SetFeared}, // :SetFeared([enable]) - Fears or removes fear + { "SetPvP", &LuaUnit::SetPvP }, // :SetPvP([apply]) - Sets the units PvP on or off +#ifndef TBC + { "SetFFA", &LuaUnit::SetFFA }, // :SetFFA([apply]) - Sets the units FFA tag on or off + { "SetSanctuary", &LuaUnit::SetSanctuary }, // :SetSanctuary([apply]) - Enables or disables units sanctuary flag +#endif + // {"SetCanFly", &LuaUnit::SetCanFly}, // :SetCanFly(apply) + // {"SetVisible", &LuaUnit::SetVisible}, // :SetVisible(x) + { "SetOwnerGUID", &LuaUnit::SetOwnerGUID }, // :SetOwnerGUID(guid) - Sets the guid of the owner + { "SetName", &LuaUnit::SetName }, // :SetName(name) - Sets the unit's name + { "SetSheath", &LuaUnit::SetSheath }, // :SetSheath(SheathState) - Sets unit's sheathstate + { "SetCreatorGUID", &LuaUnit::SetCreatorGUID }, // :SetOwnerGUID(uint64 ownerGUID) - Sets the owner's guid of a summoned creature, etc + { "SetMinionGUID", &LuaUnit::SetMinionGUID }, // :SetCreatorGUID(uint64 creatorGUID) - Sets the UNIT_FIELD_CREATEDBY creator's guid + { "SetCharmerGUID", &LuaUnit::SetCharmerGUID }, // :SetCharmerGUID(uint64 ownerGUID) - Sets the UNIT_FIELD_CHARMEDBY charmer GUID + { "SetPetGUID", &LuaUnit::SetPetGUID }, // :SetPetGUID(uint64 guid) - Sets the pet's guid +#ifndef TBC + { "SetCritterGUID", &LuaUnit::SetCritterGUID }, // :SetCritterGUID(uint64 guid) - Sets the critter's guid +#endif + { "SetWaterWalk", &LuaUnit::SetWaterWalk }, // :SetWaterWalk([enable]) - Sets WaterWalk on or off + { "SetStandState", &LuaUnit::SetStandState }, // :SetStandState(state) - Sets the stand state (Stand, Kneel, sleep, etc) of the unit + + // Boolean + { "IsAlive", &LuaUnit::IsAlive }, // :IsAlive() + { "IsDead", &LuaUnit::IsDead }, // :IsDead() - Returns true if the unit is dead, false if they are alive + { "IsDying", &LuaUnit::IsDying }, // :IsDying() - Returns true if the unit death state is JUST_DIED. + { "IsPvPFlagged", &LuaUnit::IsPvPFlagged }, // :IsPvPFlagged() + { "IsInCombat", &LuaUnit::IsInCombat }, // :IsInCombat() + { "IsBanker", &LuaUnit::IsBanker }, // :IsBanker() - Returns true if the unit is a banker, false if not + { "IsBattleMaster", &LuaUnit::IsBattleMaster }, // :IsBattleMaster() - Returns true if the unit is a battle master, false if not + { "IsCharmed", &LuaUnit::IsCharmed }, // :IsCharmed() - Returns true if the unit is charmed, false if not + { "IsArmorer", &LuaUnit::IsArmorer }, // :IsArmorer() - Returns true if the unit is an Armorer, false if not + { "IsAttackingPlayer", &LuaUnit::IsAttackingPlayer }, // :IsAttackingPlayer() - Returns true if the unit is attacking a player, false if not + { "IsInWater", &LuaUnit::IsInWater }, // :IsInWater() - Returns true if the unit is in water + { "IsUnderWater", &LuaUnit::IsUnderWater }, // :IsUnderWater() - Returns true if the unit is under water + { "IsAuctioneer", &LuaUnit::IsAuctioneer }, // :IsAuctioneer() + { "IsGuildMaster", &LuaUnit::IsGuildMaster }, // :IsGuildMaster() + { "IsInnkeeper", &LuaUnit::IsInnkeeper }, // :IsInnkeeper() + { "IsTrainer", &LuaUnit::IsTrainer }, // :IsTrainer() + { "IsGossip", &LuaUnit::IsGossip }, // :IsGossip() + { "IsTaxi", &LuaUnit::IsTaxi }, // :IsTaxi() + { "IsSpiritHealer", &LuaUnit::IsSpiritHealer }, // :IsSpiritHealer() + { "IsSpiritGuide", &LuaUnit::IsSpiritGuide }, // :IsSpiritGuide() + { "IsTabardDesigner", &LuaUnit::IsTabardDesigner }, // :IsSpiritGuide() + { "IsServiceProvider", &LuaUnit::IsServiceProvider }, // :IsServiceProvider() + { "IsSpiritService", &LuaUnit::IsSpiritService }, // :IsSpiritService() + { "HealthBelowPct", &LuaUnit::HealthBelowPct }, // :HealthBelowPct(int32 pct) + { "HealthAbovePct", &LuaUnit::HealthAbovePct }, // :HealthAbovePct(int32 pct) + { "IsMounted", &LuaUnit::IsMounted }, // :IsMounted() + { "AttackStop", &LuaUnit::AttackStop }, // :AttackStop() + { "Attack", &LuaUnit::Attack }, // :Attack(who[, meleeAttack]) + // {"IsVisible", &LuaUnit::IsVisible}, // :IsVisible() + // {"IsMoving", &LuaUnit::IsMoving}, // :IsMoving() + // {"IsFlying", &LuaUnit::IsFlying}, // :IsFlying() + { "IsStopped", &LuaUnit::IsStopped }, // :IsStopped() + { "HasUnitState", &LuaUnit::HasUnitState }, // :HasUnitState(state) - state from UnitState enum + { "IsQuestGiver", &LuaUnit::IsQuestGiver }, // :IsQuestGiver() - Returns true if the unit is a quest giver, false if not + { "IsWithinDistInMap", &LuaUnit::IsWithinDistInMap }, // :IsWithinDistInMap(worldObject, radius) - Returns if the unit is within distance in map of the worldObject + { "IsInAccessiblePlaceFor", &LuaUnit::IsInAccessiblePlaceFor }, // :IsInAccessiblePlaceFor(creature) - Returns if the unit is in an accessible place for the specified creature + { "IsVendor", &LuaUnit::IsVendor }, // :IsVendor() - Returns if the unit is a vendor or not + { "IsWithinLoS", &LuaUnit::IsWithinLoS }, // :IsWithinLoS(x, y, z) + // {"IsRooted", &LuaUnit::IsRooted}, // :IsRooted() + { "IsFullHealth", &LuaUnit::IsFullHealth }, // :IsFullHealth() - Returns if the unit is full health + { "HasAura", &LuaUnit::HasAura }, // :HasAura(spellId) - Returns true if the unit has the aura from the spell + { "IsStandState", &LuaUnit::IsStandState }, // :IsStandState() - Returns true if the unit is standing + { "IsOnVehicle", &LuaUnit::IsOnVehicle }, // :IsOnVehicle() - Checks if the unit is on a vehicle + + // Other + { "RegisterEvent", &LuaUnit::RegisterEvent }, // :RegisterEvent(function, delay, calls) + { "RemoveEventById", &LuaUnit::RemoveEventById }, // :RemoveEventById(eventID) + { "RemoveEvents", &LuaUnit::RemoveEvents }, // :RemoveEvents() + { "AddAura", &LuaUnit::AddAura }, // :AddAura(spellId, target) - Adds an aura to the specified target + { "RemoveAura", &LuaUnit::RemoveAura }, // :RemoveAura(spellId[, casterGUID]) - Removes an aura from the unit by the spellId, casterGUID(Original caster) is optional + { "RemoveAllAuras", &LuaUnit::RemoveAllAuras }, // :RemoveAllAuras() - Removes all the unit's auras + { "ClearInCombat", &LuaUnit::ClearInCombat }, // :ClearInCombat() - Clears the unit's combat list (unit will be out of combat), resets the timer to 0, etc + { "DeMorph", &LuaUnit::DeMorph }, // :DeMorph() - Sets display back to native + { "SendUnitWhisper", &LuaUnit::SendUnitWhisper }, // :SendUnitWhisper(msg, receiver[, bossWhisper]) - Sends a whisper to the receiver + { "SendUnitEmote", &LuaUnit::SendUnitEmote }, // :SendUnitEmote(msg[, receiver, bossEmote]) - Sends a text emote + { "SendUnitSay", &LuaUnit::SendUnitSay }, // :SendUnitSay(msg, language) - Sends a "Say" message with the specified language (all languages: 0) + { "SendUnitYell", &LuaUnit::SendUnitYell }, // :SendUnitYell(msg, language) - Sends a "Yell" message with the specified language (all languages: 0) + { "CastSpell", &LuaUnit::CastSpell }, // :CastSpell(target, spellID[, triggered]) - Casts spell on target (player/npc/creature), if triggered is true then instant cast + { "CastSpellAoF", &LuaUnit::CastSpellAoF }, // :CastSpellAoF(x, y, z, spellID[, triggered]) - Casts the spell on coordinates, if triggered is false has mana cost and cast time + { "PlayDirectSound", &LuaUnit::PlayDirectSound }, // :PlayDirectSound(soundId, player) - Unit plays soundID to player, or everyone around if no player + { "PlayDistanceSound", &LuaUnit::PlayDistanceSound }, // :PlayDistanceSound(soundId, player) - Unit plays soundID to player, or everyone around if no player. The sound fades the further you are + // {"Kill", &LuaUnit::Kill}, // :Kill(target, durabilityLoss) - Unit kills the target. Durabilityloss is true by default + { "StopSpellCast", &LuaUnit::StopSpellCast }, // :StopSpellCast(spellId(optional)) - Stops the unit from casting a spell. If a spellId is defined, it will stop that unit from casting that spell + { "InterruptSpell", &LuaUnit::InterruptSpell }, // :InterruptSpell(spellType, delayed(optional)) - Interrupts the unit's spell by the spellType. If delayed is true it will skip if the spell is delayed. + { "SendChatMessageToPlayer", &LuaUnit::SendChatMessageToPlayer }, // :SendChatMessageToPlayer(type, lang, msg, target) - Unit sends a chat message to the given target player + { "Emote", &LuaUnit::Emote }, // :Emote(emote) + { "CountPctFromCurHealth", &LuaUnit::CountPctFromCurHealth }, // :CountPctFromCurHealth(int32 pct) + { "CountPctFromMaxHealth", &LuaUnit::CountPctFromMaxHealth }, // :CountPctFromMaxHealth() + { "Dismount", &LuaUnit::Dismount }, // :Dismount() - Dismounts the unit. + { "Mount", &LuaUnit::Mount }, // :Mount(displayId) - Mounts the unit on the specified displayId. + // {"RestoreDisplayId", &LuaUnit::RestoreDisplayId}, // :RestoreDisplayId() + // {"RestoreFaction", &LuaUnit::RestoreFaction}, // :RestoreFaction() + // {"RemoveBindSightAuras", &LuaUnit::RemoveBindSightAuras}, // :RemoveBindSightAuras() + // {"RemoveCharmAuras", &LuaUnit::RemoveCharmAuras}, // :RemoveCharmAuras() + { "ClearThreatList", &LuaUnit::ClearThreatList }, // :ClearThreatList() + { "ClearUnitState", &LuaUnit::ClearUnitState }, // :ClearUnitState(state) + { "AddUnitState", &LuaUnit::AddUnitState }, // :AddUnitState(state) + // {"DisableMelee", &LuaUnit::DisableMelee}, // :DisableMelee([disable]) - if true, enables + // {"SummonGuardian", &LuaUnit::SummonGuardian}, // :SummonGuardian(entry, x, y, z, o[, duration]) - summons a guardian to location. Scales with summoner, is friendly to him and guards him. + { "NearTeleport", &LuaUnit::NearTeleport }, // :NearTeleport(x, y, z, o) - Teleports to give coordinates. Does not leave combat or unsummon pet. + { "MoveIdle", &LuaUnit::MoveIdle }, // :MoveIdle() + { "MoveRandom", &LuaUnit::MoveRandom }, // :MoveRandom(radius) + { "MoveHome", &LuaUnit::MoveHome }, // :MoveHome() + { "MoveFollow", &LuaUnit::MoveFollow }, // :MoveFollow(target[, dist, angle]) + { "MoveChase", &LuaUnit::MoveChase }, // :MoveChase(target[, dist, angle]) + { "MoveConfused", &LuaUnit::MoveConfused }, // :MoveConfused() + { "MoveFleeing", &LuaUnit::MoveFleeing }, // :MoveFleeing(enemy[, time]) + { "MoveTo", &LuaUnit::MoveTo }, // :MoveTo(id, x, y, z[, genPath]) - Moves to point. id is sent to WP reach hook. genPath defaults to true +#ifndef TBC + { "MoveJump", &LuaUnit::MoveJump }, // :MoveJump(x, y, z, zSpeed, maxHeight, id) +#endif + { "MoveStop", &LuaUnit::MoveStop }, // :MoveStop() + { "MoveExpire", &LuaUnit::MoveExpire }, // :MoveExpire([reset]) + { "MoveClear", &LuaUnit::MoveClear }, // :MoveClear([reset]) + + { NULL, NULL }, +}; + +ElunaRegister PlayerMethods[] = +{ + // Getters + { "GetSelection", &LuaPlayer::GetSelection }, // :GetSelection() + { "GetGMRank", &LuaPlayer::GetGMRank }, // :GetSecurity() + { "GetGuildId", &LuaPlayer::GetGuildId }, // :GetGuildId() - nil on no guild + { "GetCoinage", &LuaPlayer::GetCoinage }, // :GetCoinage() + { "GetTeam", &LuaPlayer::GetTeam }, // :GetTeam() - returns the player's team. 0 for ally, 1 for horde + { "GetItemCount", &LuaPlayer::GetItemCount }, // :GetItemCount(item_id[, check_bank]) + { "GetGroup", &LuaPlayer::GetGroup }, // :GetGroup() + { "GetGuild", &LuaPlayer::GetGuild }, // :GetGuild() + { "GetAccountId", &LuaPlayer::GetAccountId }, // :GetAccountId() + { "GetAccountName", &LuaPlayer::GetAccountName }, // :GetAccountName() +#ifndef CATA + { "GetArenaPoints", &LuaPlayer::GetArenaPoints }, // :GetArenaPoints() + { "GetHonorPoints", &LuaPlayer::GetHonorPoints }, // :GetHonorPoints() +#endif + { "GetLifetimeKills", &LuaPlayer::GetLifetimeKills }, // :GetLifetimeKills() - Returns the player's lifetime (honorable) kills + { "GetPlayerIP", &LuaPlayer::GetPlayerIP }, // :GetPlayerIP() - Returns the player's IP Address + { "GetLevelPlayedTime", &LuaPlayer::GetLevelPlayedTime }, // :GetLevelPlayedTime() - Returns the player's played time at that level + { "GetTotalPlayedTime", &LuaPlayer::GetTotalPlayedTime }, // :GetTotalPlayedTime() - Returns the total played time of that player + { "GetItemByPos", &LuaPlayer::GetItemByPos }, // :GetItemByPos(bag, slot) - Returns item in given slot in a bag (bag: 19-22 slot : 0-35) or inventory (bag: -1 slot : 0-38) + { "GetReputation", &LuaPlayer::GetReputation }, // :GetReputation(faction) - Gets player's reputation with given faction + { "GetItemByEntry", &LuaPlayer::GetItemByEntry }, // :GetItemByEntry(entry) - Gets an item if the player has it + { "GetEquippedItemBySlot", &LuaPlayer::GetEquippedItemBySlot }, // :GetEquippedItemBySlot(slotId) - Returns equipped item by slot + { "GetQuestLevel", &LuaPlayer::GetQuestLevel }, // :GetQuestLevel(quest) - Returns quest's level + { "GetChatTag", &LuaPlayer::GetChatTag }, // :GetChatTag() - Returns player chat tag ID + { "GetRestBonus", &LuaPlayer::GetRestBonus }, // :GetRestBonus() - Gets player's rest bonus + { "GetRestType", &LuaPlayer::GetRestType }, // :GetRestType() - Returns the player's rest type +#ifdef WOTLK + { "GetPhaseMaskForSpawn", &LuaPlayer::GetPhaseMaskForSpawn }, // :GetPhaseMaskForSpawn() - Gets the real phasemask for spawning things. Used if the player is in GM mode +#endif + { "GetReqKillOrCastCurrentCount", &LuaPlayer::GetReqKillOrCastCurrentCount }, // :GetReqKillOrCastCurrentCount(questId, entry) - Gets the objective (kill or cast) current count done + { "GetQuestStatus", &LuaPlayer::GetQuestStatus }, // :GetQuestStatus(entry) - Gets the quest's status + { "GetInGameTime", &LuaPlayer::GetInGameTime }, // :GetInGameTime() - Returns player's ingame time + { "GetComboPoints", &LuaPlayer::GetComboPoints }, // :GetComboPoints() - Returns player's combo points + { "GetComboTarget", &LuaPlayer::GetComboTarget }, // :GetComboTarget() - Returns the player's combo target + { "GetGuildName", &LuaPlayer::GetGuildName }, // :GetGuildName() - Returns player's guild's name or nil + { "GetFreeTalentPoints", &LuaPlayer::GetFreeTalentPoints }, // :GetFreeTalentPoints() - Returns the amount of unused talent points +#ifndef TBC + { "GetActiveSpec", &LuaPlayer::GetActiveSpec }, // :GetActiveSpec() - Returns the active specID + { "GetSpecsCount", &LuaPlayer::GetSpecsCount }, // :GetSpecsCount() - Returns the player's spec count +#endif + { "GetSpellCooldownDelay", &LuaPlayer::GetSpellCooldownDelay }, // :GetSpellCooldownDelay(spellId) - Returns the spell's cooldown + { "GetGuildRank", &LuaPlayer::GetGuildRank }, // :GetGuildRank() - Gets the player's guild rank + { "GetDifficulty", &LuaPlayer::GetDifficulty }, // :GetDifficulty([isRaid]) - Returns the current difficulty + { "GetHealthBonusFromStamina", &LuaPlayer::GetHealthBonusFromStamina }, // :GetHealthBonusFromStamina() - Returns the HP bonus from stamina + { "GetManaBonusFromIntellect", &LuaPlayer::GetManaBonusFromIntellect }, // :GetManaBonusFromIntellect() - Returns the mana bonus from intellect + { "GetMaxSkillValue", &LuaPlayer::GetMaxSkillValue }, // :GetMaxSkillValue(skill) - Gets max skill value for the given skill + { "GetPureMaxSkillValue", &LuaPlayer::GetPureMaxSkillValue }, // :GetPureMaxSkillValue(skill) - Gets max base skill value + { "GetSkillValue", &LuaPlayer::GetSkillValue }, // :GetSkillValue(skill) - Gets current skill value + { "GetBaseSkillValue", &LuaPlayer::GetBaseSkillValue }, // :GetBaseSkillValue(skill) - Gets current base skill value (no temp bonus) + { "GetPureSkillValue", &LuaPlayer::GetPureSkillValue }, // :GetPureSkillValue(skill) - Gets current base skill value (no bonuses) + { "GetSkillPermBonusValue", &LuaPlayer::GetSkillPermBonusValue }, // :GetSkillPermBonusValue(skill) - Returns current permanent bonus + { "GetSkillTempBonusValue", &LuaPlayer::GetSkillTempBonusValue }, // :GetSkillTempBonusValue(skill) - Returns current temp bonus + { "GetReputationRank", &LuaPlayer::GetReputationRank }, // :GetReputationRank(faction) - Returns the reputation rank with given faction + { "GetSpellCooldowns", &LuaPlayer::GetSpellCooldowns }, // :GetSpellCooldowns() - Gets a table where spellIDs are the keys and values are cooldowns + { "GetDrunkValue", &LuaPlayer::GetDrunkValue }, // :GetDrunkValue() - Returns the current drunkness value + { "GetBattlegroundId", &LuaPlayer::GetBattlegroundId }, // :GetBattlegroundId() - Returns the player's current battleground ID + { "GetBattlegroundTypeId", &LuaPlayer::GetBattlegroundTypeId }, // :GetBattlegroundTypeId() - Returns the player's current battleground type ID + { "GetXPRestBonus", &LuaPlayer::GetXPRestBonus }, // :GetXPRestBonus(xp) - Returns the rested bonus XP from given XP + { "GetRestTime", &LuaPlayer::GetRestTime }, // :GetRestTime() - Returns the timed rested + { "GetGroupInvite", &LuaPlayer::GetGroupInvite }, // :GetGroupInvite() - Returns the group invited to + { "GetSubGroup", &LuaPlayer::GetSubGroup }, // :GetSubGroup() - Gets the player's current subgroup ID + { "GetNextRandomRaidMember", &LuaPlayer::GetNextRandomRaidMember }, // :GetNextRandomRaidMember(radius) - Gets a random raid member in given radius + { "GetOriginalGroup", &LuaPlayer::GetOriginalGroup }, // :GetOriginalGroup() - Gets the original group object + { "GetOriginalSubGroup", &LuaPlayer::GetOriginalSubGroup }, // :GetOriginalSubGroup() - Returns the original subgroup ID +#ifndef MANGOS + { "GetChampioningFaction", &LuaPlayer::GetChampioningFaction }, // :GetChampioningFaction() - Returns the player's championing faction +#endif + { "GetLatency", &LuaPlayer::GetLatency }, // :GetLatency() - Returns player's latency + // {"GetRecruiterId", &LuaPlayer::GetRecruiterId}, // :GetRecruiterId() - Returns player's recruiter's ID + { "GetDbLocaleIndex", &LuaPlayer::GetDbLocaleIndex }, // :GetDbLocaleIndex() - Returns locale index + { "GetDbcLocale", &LuaPlayer::GetDbcLocale }, // :GetDbcLocale() - Returns DBC locale + { "GetCorpse", &LuaPlayer::GetCorpse }, // :GetCorpse() - Returns the player's corpse + { "GetGossipTextId", &LuaPlayer::GetGossipTextId }, // :GetGossipTextId(worldObject) - Returns the WorldObject's gossip textId + { "GetQuestRewardStatus", &LuaPlayer::GetQuestRewardStatus }, // :GetQuestRewardStatus(questId) - Returns the true/false of the quest reward status +#ifndef CATA + { "GetShieldBlockValue", &LuaPlayer::GetShieldBlockValue }, // :GetShieldBlockValue() - Returns block value +#endif + + // Setters + { "AdvanceSkillsToMax", &LuaPlayer::AdvanceSkillsToMax }, // :AdvanceSkillsToMax() - Advances all currently known skills to the currently known max level + { "AdvanceSkill", &LuaPlayer::AdvanceSkill }, // :AdvanceSkill(skill_id, step) - Advances skill by ID and the amount(step) + { "AdvanceAllSkills", &LuaPlayer::AdvanceAllSkills }, // :AdvanceAllSkills(value) - Advances all current skills to your input(value) + { "AddLifetimeKills", &LuaPlayer::AddLifetimeKills }, // :AddLifetimeKills(val) - Adds lifetime (honorable) kills to your current lifetime kills + { "SetCoinage", &LuaPlayer::SetCoinage }, // :SetCoinage(amount) - sets plr's coinage to this + { "SetKnownTitle", &LuaPlayer::SetKnownTitle }, // :SetKnownTitle(id) + { "UnsetKnownTitle", &LuaPlayer::UnsetKnownTitle }, // :UnsetKnownTitle(id) + { "SetBindPoint", &LuaPlayer::SetBindPoint }, // :SetBindPoint(x, y, z, map, areaid) - sets home for hearthstone +#ifndef CATA + { "SetArenaPoints", &LuaPlayer::SetArenaPoints }, // :SetArenaPoints(amount) + { "SetHonorPoints", &LuaPlayer::SetHonorPoints }, // :SetHonorPoints(amount) +#endif + { "SetLifetimeKills", &LuaPlayer::SetLifetimeKills }, // :SetLifetimeKills(val) - Sets the overall lifetime (honorable) kills of the player + { "SetGameMaster", &LuaPlayer::SetGameMaster }, // :SetGameMaster([on]) - Sets GM mode on or off + { "SetGMChat", &LuaPlayer::SetGMChat }, // :SetGMChat([on]) - Sets GM chat on or off + { "SetTaxiCheat", &LuaPlayer::SetTaxiCheat }, // :SetTaxiCheat([on]) - Sets taxi cheat on or off + { "SetGMVisible", &LuaPlayer::SetGMVisible }, // :SetGMVisible([on]) - Sets gm visibility on or off + { "SetPvPDeath", &LuaPlayer::SetPvPDeath }, // :SetPvPDeath([on]) - Sets PvP death on or off + { "SetAcceptWhispers", &LuaPlayer::SetAcceptWhispers }, // :SetAcceptWhispers([on]) - Sets whisper accepting death on or off + { "SetRestBonus", &LuaPlayer::SetRestBonus }, // :SetRestBonus(bonusrate) - Sets new restbonus rate + { "SetRestType", &LuaPlayer::SetRestType }, // :SetRestType() - Sets rest type + { "SetQuestStatus", &LuaPlayer::SetQuestStatus }, // :SetQuestStatus(entry, status) - Sets the quest's status + { "SetReputation", &LuaPlayer::SetReputation }, // :SetReputation(faction, value) - Sets the faction reputation for the player + { "SetFreeTalentPoints", &LuaPlayer::SetFreeTalentPoints }, // :SetFreeTalentPoints(points) - Sets the amount of unused talent points + { "SetGuildRank", &LuaPlayer::SetGuildRank }, // :SetGuildRank(rank) - Sets player's guild rank + // {"SetMovement", &LuaPlayer::SetMovement}, // :SetMovement(type) - Sets player's movement type + { "SetSkill", &LuaPlayer::SetSkill }, // :SetSkill(skill, step, currVal, maxVal) - Sets the skill's boundaries and value + { "SetFactionForRace", &LuaPlayer::SetFactionForRace }, // :SetFactionForRace(race) - Sets the faction by raceID + { "SetDrunkValue", &LuaPlayer::SetDrunkValue }, // :SetDrunkValue(newDrunkValue) - Sets drunkness value + { "SetRestTime", &LuaPlayer::SetRestTime }, // :SetRestTime(value) - Sets the rested time + { "SetAtLoginFlag", &LuaPlayer::SetAtLoginFlag }, // :SetAtLoginFlag(flag) - Adds an at login flag + { "SetPlayerLock", &LuaPlayer::SetPlayerLock }, // :SetPlayerLock(on/off) + { "SetGender", &LuaPlayer::SetGender }, // :SetGender(value) - 0 = male 1 = female + { "SetSheath", &LuaPlayer::SetSheath }, // :SetSheath(SheathState) - Sets player's sheathstate +#ifdef MANGOS + { "SetFFA", &LuaPlayer::SetFFA }, // :SetFFA([apply]) - Sets the units FFA tag on or off +#endif + + // Boolean + { "IsInGroup", &LuaPlayer::IsInGroup }, // :IsInGroup() + { "IsInGuild", &LuaPlayer::IsInGuild }, // :IsInGuild() + { "IsGM", &LuaPlayer::IsGM }, // :IsGM() + { "IsAlliance", &LuaPlayer::IsAlliance }, // :IsAlliance() + { "IsHorde", &LuaPlayer::IsHorde }, // :IsHorde() + { "HasTitle", &LuaPlayer::HasTitle }, // :HasTitle(id) + { "HasItem", &LuaPlayer::HasItem }, // :HasItem(itemId[, count, check_bank]) - Returns true if the player has the item(itemId) and specified count, else it will return false + { "Teleport", &LuaPlayer::Teleport }, // :Teleport(Map, X, Y, Z, O) - Teleports player to specified co - ordinates. Returns true if success and false if not + { "AddItem", &LuaPlayer::AddItem }, // :AddItem(id, amount) - Adds amount of item to player. Returns true if success and false if not + { "IsInArenaTeam", &LuaPlayer::IsInArenaTeam }, // :IsInArenaTeam(type) - type : 0 = 2v2, 1 = 3v3, 2 = 5v5 + { "CanEquipItem", &LuaPlayer::CanEquipItem }, // :CanEquipItem(entry/item, slot) - Returns true if the player can equip given item/item entry + { "IsFalling", &LuaPlayer::IsFalling }, // :IsFalling() - Returns true if the unit is falling + { "ToggleAFK", &LuaPlayer::ToggleAFK }, // :ToggleAFK() - Toggles AFK state for player + { "ToggleDND", &LuaPlayer::ToggleDND }, // :ToggleDND() - Toggles DND state for player + { "IsAFK", &LuaPlayer::IsAFK }, // :IsAFK() - Returns true if the player is afk + { "IsDND", &LuaPlayer::IsDND }, // :IsDND() - Returns true if the player is in dnd mode + { "IsAcceptingWhispers", &LuaPlayer::IsAcceptingWhispers }, // :IsAcceptWhispers() - Returns true if the player accepts whispers + { "IsGMChat", &LuaPlayer::IsGMChat }, // :IsGMChat() - Returns true if the player has GM chat on + { "IsTaxiCheater", &LuaPlayer::IsTaxiCheater }, // :IsTaxiCheater() - Returns true if the player has taxi cheat on + { "IsGMVisible", &LuaPlayer::IsGMVisible }, // :IsGMVisible() - Returns true if the player is GM visible + { "HasQuest", &LuaPlayer::HasQuest }, // :HasQuest(entry) - Returns true if player has the quest + { "InBattlegroundQueue", &LuaPlayer::InBattlegroundQueue }, // :InBattlegroundQueue() - Returns true if the player is in a battleground queue + // {"IsImmuneToEnvironmentalDamage", &LuaPlayer::IsImmuneToEnvironmentalDamage}, // :IsImmuneToEnvironmentalDamage() - Returns true if the player is immune to enviromental damage + { "CanSpeak", &LuaPlayer::CanSpeak }, // :CanSpeak() - Returns true if the player can speak + { "HasAtLoginFlag", &LuaPlayer::HasAtLoginFlag }, // :HasAtLoginFlag(flag) - returns true if the player has the login flag + // {"InRandomLfgDungeon", &LuaPlayer::InRandomLfgDungeon}, // :InRandomLfgDungeon() - Returns true if the player is in a random LFG dungeon + // {"HasPendingBind", &LuaPlayer::HasPendingBind}, // :HasPendingBind() - Returns true if the player has a pending instance bind +#ifndef TBC + { "HasAchieved", &LuaPlayer::HasAchieved }, // :HasAchieved(achievementID) - Returns true if the player has achieved the achievement +#endif + { "CanUninviteFromGroup", &LuaPlayer::CanUninviteFromGroup }, // :CanUninviteFromGroup() - Returns true if the player can uninvite from group + { "IsRested", &LuaPlayer::IsRested }, // :IsRested() - Returns true if the player is rested + // {"CanFlyInZone", &LuaPlayer::CanFlyInZone}, // :CanFlyInZone(mapid, zone) - Returns true if the player can fly in the area + // {"IsNeverVisible", &LuaPlayer::IsNeverVisible}, // :IsNeverVisible() - Returns true if the player is never visible + { "IsVisibleForPlayer", &LuaPlayer::IsVisibleForPlayer }, // :IsVisibleForPlayer(player) - Returns true if the player is visible for the target player + // {"IsUsingLfg", &LuaPlayer::IsUsingLfg}, // :IsUsingLfg() - Returns true if the player is using LFG + { "HasQuestForItem", &LuaPlayer::HasQuestForItem }, // :HasQuestForItem(entry) - Returns true if the player has the quest for the item + { "HasQuestForGO", &LuaPlayer::HasQuestForGO }, // :HasQuestForGO(entry) - Returns true if the player has the quest for the gameobject + { "CanShareQuest", &LuaPlayer::CanShareQuest }, // :CanShareQuest(entry) - Returns true if the quest entry is shareable by the player + // {"HasReceivedQuestReward", &LuaPlayer::HasReceivedQuestReward}, // :HasReceivedQuestReward(entry) - Returns true if the player has recieved the quest's reward +#ifndef TBC + { "HasTalent", &LuaPlayer::HasTalent }, // :HasTalent(talentId, spec) - Returns true if the player has the talent in given spec +#endif + { "IsInSameGroupWith", &LuaPlayer::IsInSameGroupWith }, // :IsInSameGroupWith(player) - Returns true if the players are in the same group + { "IsInSameRaidWith", &LuaPlayer::IsInSameRaidWith }, // :IsInSameRaidWith(player) - Returns true if the players are in the same raid + { "IsGroupVisibleFor", &LuaPlayer::IsGroupVisibleFor }, // :IsGroupVisibleFor(player) - Player is group visible for the target + { "HasSkill", &LuaPlayer::HasSkill }, // :HasSkill(skill) - Returns true if the player has the skill + { "IsHonorOrXPTarget", &LuaPlayer::IsHonorOrXPTarget }, // :IsHonorOrXPTarget(victim) - Returns true if the victim gives honor or XP + { "CanParry", &LuaPlayer::CanParry }, // :CanParry() - Returns true if the player can parry + { "CanBlock", &LuaPlayer::CanBlock }, // :CanBlock() - Returns true if the player can block +#ifndef TBC + { "CanTitanGrip", &LuaPlayer::CanTitanGrip }, // :CanTitanGrip() - Returns true if the player has titan grip +#endif + { "InBattleground", &LuaPlayer::InBattleground }, // :InBattleground() - Returns true if the player is in a battleground + { "InArena", &LuaPlayer::InArena }, // :InArena() - Returns true if the player is in an arena + // {"IsOutdoorPvPActive", &LuaPlayer::IsOutdoorPvPActive}, // :IsOutdoorPvPActive() - Returns true if the player is outdoor pvp active + // {"IsARecruiter", &LuaPlayer::IsARecruiter}, // :IsARecruiter() - Returns true if the player is a recruiter + { "CanUseItem", &LuaPlayer::CanUseItem }, // :CanUseItem(item/entry) - Returns true if the player can use the item or item entry + { "HasSpell", &LuaPlayer::HasSpell }, // :HasSpell(id) + { "HasSpellCooldown", &LuaPlayer::HasSpellCooldown }, // :HasSpellCooldown(spellId) - Returns true if the spell is on cooldown + { "IsInWater", &LuaPlayer::IsInWater }, // :IsInWater() - Returns true if the player is in water + { "CanFly", &LuaPlayer::CanFly }, // :CanFly() - Returns true if the player can fly + { "IsMoving", &LuaPlayer::IsMoving }, // :IsMoving() + { "IsFlying", &LuaPlayer::IsFlying }, // :IsFlying() + + // Gossip + { "GossipMenuAddItem", &LuaPlayer::GossipMenuAddItem }, // :GossipMenuAddItem(icon, msg, sender, intid[, code, popup, money]) + { "GossipSendMenu", &LuaPlayer::GossipSendMenu }, // :GossipSendMenu(npc_text, unit[, menu_id]) - If unit is a player, you need to use a menu_id. menu_id is used to hook the gossip select function to the menu + { "GossipComplete", &LuaPlayer::GossipComplete }, // :GossipComplete() + { "GossipClearMenu", &LuaPlayer::GossipClearMenu }, // :GossipClearMenu() - Clears the gossip menu of options. Pretty much only useful with player gossip. Need to use before creating a new menu for the player + + // Other + { "SendClearCooldowns", &LuaPlayer::SendClearCooldowns }, // :SendClearCooldowns(spellId, (unit)target) - Clears the cooldown of the target with a specified spellId + { "SendBroadcastMessage", &LuaPlayer::SendBroadcastMessage }, // :SendBroadcastMessage(message) + { "SendAreaTriggerMessage", &LuaPlayer::SendAreaTriggerMessage }, // :SendAreaTriggerMessage(message) - Sends a yellow message in the middle of your screen + { "SendNotification", &LuaPlayer::SendNotification }, // :SendNotification(message) - Sends a red message in the middle of your screen + { "SendPacket", &LuaPlayer::SendPacket }, // :SendPacket(packet, selfOnly) - Sends a packet to player or everyone around also if selfOnly is false + { "SendVendorWindow", &LuaPlayer::SendVendorWindow }, // :SendVendorWindow(unit) - Sends the unit's vendor window to the player + { "ModifyMoney", &LuaPlayer::ModifyMoney }, // :ModifyMoney(amount[, sendError]) - Modifies (does not set) money (copper count) of the player. Amount can be negative to remove copper + { "LearnSpell", &LuaPlayer::LearnSpell }, // :LearnSpell(id) - learns the given spell + { "RemoveItem", &LuaPlayer::RemoveItem }, // :RemoveItem(item/entry, amount) - Removes amount of item from player + { "RemoveLifetimeKills", &LuaPlayer::RemoveLifetimeKills }, // :RemoveLifetimeKills(val) - Removes a specified amount(val) of the player's lifetime (honorable) kills + { "ResurrectPlayer", &LuaPlayer::ResurrectPlayer }, // :ResurrectPlayer([percent[, sickness(bool)]]) - Resurrects the player at percentage, player gets resurrection sickness if sickness set to true + { "PlaySoundToPlayer", &LuaPlayer::PlaySoundToPlayer }, // :PlaySoundToPlayer(soundId) - Plays the specified sound to the player + { "EquipItem", &LuaPlayer::EquipItem }, // :EquipItem(entry/item, slot) - Equips given item or item entry for player to given slot. Returns the equipped item or nil + { "ResetSpellCooldown", &LuaPlayer::ResetSpellCooldown }, // :ResetSpellCooldown(spellId, update(bool~optional)) - Resets cooldown of the specified spellId. If update is true, it will send WorldPacket SMSG_CLEAR_COOLDOWN to the player, else it will just clear the spellId from m_spellCooldowns. This is true by default + { "ResetTypeCooldowns", &LuaPlayer::ResetTypeCooldowns }, // :ResetTypeCooldowns(category, update(bool~optional)) - Resets all cooldowns for the spell category(type). If update is true, it will send WorldPacket SMSG_CLEAR_COOLDOWN to the player, else it will just clear the spellId from m_spellCooldowns. This is true by default + { "ResetAllCooldowns", &LuaPlayer::ResetAllCooldowns }, // :ResetAllCooldowns() - Resets all spell cooldowns + { "GiveLevel", &LuaPlayer::GiveLevel }, // :GiveLevel(level) - Gives levels to the player + { "GiveXP", &LuaPlayer::GiveXP }, // :GiveXP(xp[, victim, pureXP, triggerHook]) - Gives XP to the player. If pure is false, bonuses are count in. If triggerHook is false, GiveXp hook is not triggered. + // {"RemovePet", &LuaPlayer::RemovePet}, // :RemovePet([mode, returnreagent]) - Removes the player's pet. Mode determines if the pet is saved and how + // {"SummonPet", &LuaPlayer::SummonPet}, // :SummonPet(entry, x, y, z, o, petType, despwtime) - Summons a pet for the player + { "Say", &LuaPlayer::Say }, // :Say(text, lang) - The player says the text + { "Yell", &LuaPlayer::Yell }, // :Yell(text, lang) - The player yells the text + { "TextEmote", &LuaPlayer::TextEmote }, // :TextEmote(text) - The player does a textemote with the text + { "Whisper", &LuaPlayer::Whisper }, // :Whisper(text, lang, receiverGuid) - The player whispers the text to the guid + { "CompleteQuest", &LuaPlayer::CompleteQuest }, // :CompleteQuest(entry) - Completes a quest by entry + { "IncompleteQuest", &LuaPlayer::IncompleteQuest }, // :IncompleteQuest(entry) - Uncompletes the quest by entry for the player + { "FailQuest", &LuaPlayer::FailQuest }, // :FailQuest(entry) - Player fails the quest entry + // {"RemoveActiveQuest", &LuaPlayer::RemoveActiveQuest}, // :RemoveActiveQuest(entry) - Removes an active quest + // {"RemoveRewardedQuest", &LuaPlayer::RemoveRewardedQuest}, // :RemoveRewardedQuest(entry) - Removes a rewarded quest + { "AreaExploredOrEventHappens", &LuaPlayer::AreaExploredOrEventHappens }, // :AreaExploredOrEventHappens(questId) - Satisfies an area or event requrement for the questId + { "GroupEventHappens", &LuaPlayer::GroupEventHappens }, // :GroupEventHappens(questId, worldObject) - Satisfies a group event for the questId with the world object + { "KilledMonsterCredit", &LuaPlayer::KilledMonsterCredit }, // :KilledMonsterCredit(entry) - Satisfies a monsterkill for the player + // {"KilledPlayerCredit", &LuaPlayer::KilledPlayerCredit}, // :KilledPlayerCredit() - Satisfies a player kill for the player + // {"KillGOCredit", &LuaPlayer::KillGOCredit}, // :KillGOCredit(GOEntry[, GUID]) - Credits the player for destroying a GO, guid is optional + { "TalkedToCreature", &LuaPlayer::TalkedToCreature }, // :TalkedToCreature(npcEntry, creature) - Satisfies creature talk objective for the player +#ifndef TBC + { "ResetPetTalents", &LuaPlayer::ResetPetTalents }, // :ResetPetTalents() - Resets player's pet's talents +#endif + { "AddComboPoints", &LuaPlayer::AddComboPoints }, // :AddComboPoints(target, count[, spell]) - Adds combo points to the target for the player + // {"GainSpellComboPoints", &LuaPlayer::GainSpellComboPoints}, // :GainSpellComboPoints(amount) - Player gains spell combo points + { "ClearComboPoints", &LuaPlayer::ClearComboPoints }, // :ClearComboPoints() - Clears player's combo points + { "RemoveSpell", &LuaPlayer::RemoveSpell }, // :RemoveSpell(entry[, disabled, learn_low_rank]) - Removes (unlearn) the given spell + { "ResetTalents", &LuaPlayer::ResetTalents }, // :ResetTalents([no_cost]) - Resets player's talents + { "ResetTalentsCost", &LuaPlayer::ResetTalentsCost }, // :ResetTalentsCost() - Returns the reset talents cost + // {"AddTalent", &LuaPlayer::AddTalent}, // :AddTalent(spellid, spec, learning) - Adds a talent spell for the player to given spec + { "RemoveFromGroup", &LuaPlayer::RemoveFromGroup }, // :RemoveFromGroup() - Removes the player from his group + { "KillPlayer", &LuaPlayer::KillPlayer }, // :KillPlayer() - Kills the player + { "DurabilityLossAll", &LuaPlayer::DurabilityLossAll }, // :DurabilityLossAll(percent[, inventory]) - The player's items lose durability. Inventory true by default + { "DurabilityLoss", &LuaPlayer::DurabilityLoss }, // :DurabilityLoss(item, percent) - The given item loses durability + { "DurabilityPointsLoss", &LuaPlayer::DurabilityPointsLoss }, // :DurabilityPointsLoss(item, points) - The given item loses durability + { "DurabilityPointsLossAll", &LuaPlayer::DurabilityPointsLossAll }, // :DurabilityPointsLossAll(points, inventory) - Player's items lose durability + { "DurabilityPointLossForEquipSlot", &LuaPlayer::DurabilityPointLossForEquipSlot }, // :DurabilityPointLossForEquipSlot(slot) - Causes durability loss for the item in the given slot + { "DurabilityRepairAll", &LuaPlayer::DurabilityRepairAll }, // :DurabilityRepairAll([has_cost, discount, guildBank]) - Repairs all durability + { "DurabilityRepair", &LuaPlayer::DurabilityRepair }, // :DurabilityRepair(position[, has_cost, discount, guildBank]) - Repairs item durability of item in given position +#ifndef CATA + { "ModifyHonorPoints", &LuaPlayer::ModifyHonorPoints }, // :ModifyHonorPoints(amount) - Modifies the player's honor points + { "ModifyArenaPoints", &LuaPlayer::ModifyArenaPoints }, // :ModifyArenaPoints(amount) - Modifies the player's arena points +#endif + { "LeaveBattleground", &LuaPlayer::LeaveBattleground }, // :LeaveBattleground([teleToEntryPoint]) - The player leaves the battleground + // {"BindToInstance", &LuaPlayer::BindToInstance}, // :BindToInstance() - Binds the player to the current instance + { "UnbindInstance", &LuaPlayer::UnbindInstance }, // :UnbindInstance(map, difficulty) - Unbinds the player from an instance + { "RemoveFromBattlegroundRaid", &LuaPlayer::RemoveFromBattlegroundRaid }, // :RemoveFromBattlegroundRaid() - Removes the player from a battleground or battlefield raid +#ifndef TBC + { "ResetAchievements", &LuaPlayer::ResetAchievements }, // :ResetAchievements() - Resets players achievements +#endif + { "KickPlayer", &LuaPlayer::KickPlayer }, // :KickPlayer() - Kicks player from server + { "LogoutPlayer", &LuaPlayer::LogoutPlayer }, // :LogoutPlayer([save]) - Logs the player out and saves if true + { "SendTrainerList", &LuaPlayer::SendTrainerList }, // :SendTrainerList(WorldObject) - Sends trainer list from object to player + { "SendListInventory", &LuaPlayer::SendListInventory }, // :SendListInventory(WorldObject) - Sends vendor list from object to player + { "SendShowBank", &LuaPlayer::SendShowBank }, // :SendShowBank(WorldObject) - Sends bank window from object to player + { "SendTabardVendorActivate", &LuaPlayer::SendTabardVendorActivate }, // :SendTabardVendorActivate(WorldObject) - Sends tabard vendor window from object to player + { "SendSpiritResurrect", &LuaPlayer::SendSpiritResurrect }, // :SendSpiritResurrect() - Sends resurrect window to player + { "SendTaxiMenu", &LuaPlayer::SendTaxiMenu }, // :SendTaxiMenu(creature) - Sends flight window to player from creature + { "RewardQuest", &LuaPlayer::RewardQuest }, // :RewardQuest(entry) - Gives quest rewards for the player + { "SendAuctionMenu", &LuaPlayer::SendAuctionMenu }, // :SendAuctionMenu(unit) - Sends auction window to player. Auction house is sent by object. +#ifdef WOTLK + { "SendMailMenu", &LuaPlayer::SendMailMenu }, // :SendMailMenu(object) - Sends mail window to player from gameobject +#endif + { "StartTaxi", &LuaPlayer::StartTaxi }, // :StartTaxi(pathId) - player starts the given flight path + { "GossipSendPOI", &LuaPlayer::GossipSendPOI }, // :GossipSendPOI(X, Y, Icon, Flags, Data, Name) - Sends a point of interest to the player + { "GossipAddQuests", &LuaPlayer::GossipAddQuests }, // :GossipAddQuests(unit) - Adds unit's quests to player's gossip menu + { "SendQuestTemplate", &LuaPlayer::SendQuestTemplate }, // :SendQuestTemplate(questId, activeAccept) -- Sends quest template to player + { "SpawnBones", &LuaPlayer::SpawnBones }, // :SpawnBones() - Removes the player's corpse and spawns bones + { "RemovedInsignia", &LuaPlayer::RemovedInsignia }, // :RemovedInsignia(looter) - Looter removes the player's corpse, looting the player and replacing with lootable bones + { "SendGuildInvite", &LuaPlayer::SendGuildInvite }, // :SendGuildInvite(player) - Sends a guild invite to the specific player + { "CreateCorpse", &LuaPlayer::CreateCorpse }, // :CreateCorpse() - Creates the player's corpse + { "Mute", &LuaPlayer::Mute }, // :Mute(time[, reason]) - Mutes the player for given time in seconds. + { "SummonPlayer", &LuaPlayer::SummonPlayer }, // :SummonPlayer(player, map, x, y, z, zoneId[, delay]) - Sends a popup to the player asking if he wants to be summoned if yes, teleported to coords. ZoneID defines the location name shown in the popup Delay is the time until the popup closes automatically. + { "SaveToDB", &LuaPlayer::SaveToDB }, // :SaveToDB() - Saves to database + + { NULL, NULL }, +}; + +ElunaRegister CreatureMethods[] = +{ + // Getters + { "GetAITarget", &LuaCreature::GetAITarget }, // :GetAITarget(type[, playeronly, position, distance, aura]) - Get an unit in threat list + { "GetAITargets", &LuaCreature::GetAITargets }, // :GetAITargets() - Get units in threat list + { "GetAITargetsCount", &LuaCreature::GetAITargetsCount }, // :GetAITargetsCount() - Get threat list size + { "GetHomePosition", &LuaCreature::GetHomePosition }, // :GetHomePosition() - Returns x,y,z,o of spawn position + { "GetCorpseDelay", &LuaCreature::GetCorpseDelay }, // :GetCorpseDelay() - Returns corpse delay + { "GetCreatureSpellCooldownDelay", &LuaCreature::GetCreatureSpellCooldownDelay }, // :GetCreatureSpellCooldownDelay(spellId) - Returns spell cooldown delay + { "GetScriptId", &LuaCreature::GetScriptId }, // :GetScriptId() - Returns creature's script ID + { "GetAIName", &LuaCreature::GetAIName }, // :GetAIName() - Returns creature's AI name + { "GetScriptName", &LuaCreature::GetScriptName }, // :GetScriptName() - Returns creature's script name + { "GetReactState", &LuaCreature::GetReactState }, // :GetReactState() - Returns creature's react state + { "GetAttackDistance", &LuaCreature::GetAttackDistance }, // :GetAttackDistance(unit) - Returns attack distance to unit + { "GetAggroRange", &LuaCreature::GetAggroRange }, // :GetAggroRange(unit) - Returns aggro distance to unit + { "GetDefaultMovementType", &LuaCreature::GetDefaultMovementType }, // :GetDefaultMovementType() - Returns default movement type + { "GetRespawnDelay", &LuaCreature::GetRespawnDelay }, // :GetRespawnDelay() - Returns respawn delay + { "GetRespawnRadius", &LuaCreature::GetRespawnRadius }, // :GetRespawnRadius() - Returns respawn radius + // {"GetWaypointPath", &LuaCreature::GetWaypointPath}, // :GetWaypointPath() - Returns waypoint path ID + // {"GetCurrentWaypointId", &LuaCreature::GetCurrentWaypointId}, // :GetCurrentWaypointId() - Returns waypoint ID + // {"GetLootMode", &LuaCreature::GetLootMode}, // :GetLootMode() - Returns loot mode + { "GetLootRecipient", &LuaCreature::GetLootRecipient }, // :GetLootRecipient() - Returns loot receiver + { "GetLootRecipientGroup", &LuaCreature::GetLootRecipientGroup }, // :GetLootRecipientGroup() - Returns loot receiver group + { "GetNPCFlags", &LuaCreature::GetNPCFlags }, // :GetNPCFlags() - Returns NPC flags +#ifndef CATA + { "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue }, // :GetShieldBlockValue() - Returns block value +#endif + + // Setters + { "SetHover", &LuaCreature::SetHover }, // :SetHover([enable]) - Sets hover on or off + // {"SetDisableGravity", &LuaCreature::SetDisableGravity}, // :SetDisableGravity([disable, packetOnly]) - Disables or enables gravity + { "SetReactState", &LuaCreature::SetReactState }, // :SetReactState(state) - Sets react state + { "SetNoCallAssistance", &LuaCreature::SetNoCallAssistance }, // :SetNoCallAssistance([noCall]) - Sets call assistance to false or true + { "SetNoSearchAssistance", &LuaCreature::SetNoSearchAssistance }, // :SetNoSearchAssistance([noSearch]) - Sets assistance searhing to false or true + { "SetDefaultMovementType", &LuaCreature::SetDefaultMovementType }, // :SetDefaultMovementType(type) - Sets default movement type + { "SetRespawnDelay", &LuaCreature::SetRespawnDelay }, // :SetRespawnDelay(delay) - Sets the respawn delay + { "SetRespawnRadius", &LuaCreature::SetRespawnRadius }, // :SetRespawnRadius(dist) - Sets the respawn radius + { "SetInCombatWithZone", &LuaCreature::SetInCombatWithZone }, // :SetInCombatWithZone() - Sets the creature in combat with everyone in zone + { "SetDisableReputationGain", &LuaCreature::SetDisableReputationGain }, // :SetDisableReputationGain([disable]) - Disables or enables reputation gain from creature + // {"SetLootMode", &LuaCreature::SetLootMode}, // :SetLootMode(lootMode) - Sets the lootmode + { "SetNPCFlags", &LuaCreature::SetNPCFlags }, // :SetNPCFlags(flags) - Sets NPC flags + { "SetDeathState", &LuaCreature::SetDeathState }, // :SetDeathState(value) - 0 = alive 1 = just died 2 = corpse 3 = dead + { "SetWalk", &LuaCreature::SetWalk }, // :SetWalk([enable]) - If false, creature runs, otherwise walks + + // Booleans + { "IsWorldBoss", &LuaCreature::IsWorldBoss }, // :IsWorldBoss() - Returns true if the creature is a WorldBoss, false if not + { "IsRacialLeader", &LuaCreature::IsRacialLeader }, // :IsRacialLeader() - Returns true if the creature is a racial leader, false if not + { "IsCivilian", &LuaCreature::IsCivilian }, // :IsCivilian() - Returns true if the creature is a civilian, false if not + // {"IsTrigger", &LuaCreature::IsTrigger}, // :IsTrigger() - Returns true if the creature is a trigger, false if not + { "IsGuard", &LuaCreature::IsGuard }, // :IsGuard() - Returns true if the creature is a guard, false if not + { "IsElite", &LuaCreature::IsElite }, // :IsElite() - Returns true if the creature is an elite, false if not + { "IsInEvadeMode", &LuaCreature::IsInEvadeMode }, // :IsInEvadeMode() - Returns true if the creature is in evade mode, false if not + { "HasCategoryCooldown", &LuaCreature::HasCategoryCooldown }, // :HasCategoryCooldown(spellId) - Returns true if the creature has a cooldown for the spell's category + { "CanWalk", &LuaCreature::CanWalk }, // :CanWalk() - Returns true if the creature can walk + { "CanSwim", &LuaCreature::CanSwim }, // :CanSwim() - Returns true if the creature can swim + { "HasReactState", &LuaCreature::HasReactState }, // :HasReactState(state) - Returns true if the creature has react state + // {"CanStartAttack", &LuaCreature::CanStartAttack}, // :CanStartAttack(unit[, force]) - Returns true if the creature can attack the unit + { "HasSearchedAssistance", &LuaCreature::HasSearchedAssistance }, // :HasSearchedAssistance() - Returns true if the creature has searched assistance + { "CanAssistTo", &LuaCreature::CanAssistTo }, // :CanAssistTo(unit, enemy[, checkfaction]) - Returns true if the creature can assist unit with enemy + { "IsTargetAcceptable", &LuaCreature::IsTargetAcceptable }, // :IsTargetAcceptable(unit) - Returns true if the creature can target unit + { "HasInvolvedQuest", &LuaCreature::HasInvolvedQuest }, // :HasInvolvedQuest(questId) - Returns true if the creature can finish the quest for players + { "IsRegeneratingHealth", &LuaCreature::IsRegeneratingHealth }, // :IsRegeneratingHealth() - Returns true if the creature is regenerating health + { "IsReputationGainDisabled", &LuaCreature::IsReputationGainDisabled }, // :IsReputationGainDisabled() - Returns true if the creature has reputation gain disabled + // {"IsDamageEnoughForLootingAndReward", &LuaCreature::IsDamageEnoughForLootingAndReward}, // :IsDamageEnoughForLootingAndReward() + // {"HasLootMode", &LuaCreature::HasLootMode}, + { "HasSpell", &LuaCreature::HasSpell }, // :HasSpell(id) + { "HasQuest", &LuaCreature::HasQuest }, // :HasQuest(id) + { "HasSpellCooldown", &LuaCreature::HasSpellCooldown }, // :HasSpellCooldown(spellId) - Returns true if the spell is on cooldown + { "CanFly", &LuaCreature::CanFly }, // :CanFly() - Returns true if the creature can fly + + // Other + // {"Despawn", &LuaCreature::Despawn}, // :Despawn([despawnDelay]) - Creature despawns after given time + { "FleeToGetAssistance", &LuaCreature::FleeToGetAssistance }, // :FleeToGetAssistance() - Creature flees for assistance + { "CallForHelp", &LuaCreature::CallForHelp }, // :CallForHelp(radius) - Creature calls for help from units in radius + { "CallAssistance", &LuaCreature::CallAssistance }, // :CallAssistance() - Creature calls for assistance + { "RemoveCorpse", &LuaCreature::RemoveCorpse }, // :RemoveCorpse([setSpawnTime]) - Removes corpse + { "DespawnOrUnsummon", &LuaCreature::DespawnOrUnsummon }, // :DespawnOrUnsummon([Delay]) - Despawns the creature after delay if given + { "Respawn", &LuaCreature::Respawn }, // :Respawn([force]) - Respawns the creature + // {"AddLootMode", &LuaCreature::AddLootMode}, // :AddLootMode(lootMode) + // {"DealDamage", &LuaCreature::DealDamage}, // :DealDamage(target, amount) - Deals damage to target (if target) : if no target, unit will damage self + // {"SendCreatureTalk", &LuaCreature::SendCreatureTalk}, // :SendCreatureTalk(id, playerGUID) - Sends a chat message to a playerGUID (player) by id. Id can be found in creature_text under the 'group_id' column + { "AttackStart", &LuaCreature::AttackStart }, // :AttackStart(target) - Creature attacks the specified target + // {"ResetLootMode", &LuaCreature::ResetLootMode}, + // {"RemoveLootMode", &LuaCreature::RemoveLootMode}, + { "SaveToDB", &LuaCreature::SaveToDB }, // :SaveToDB() - Saves to database + { "SelectVictim", &LuaCreature::SelectVictim }, // :SelectVictim() - Selects a victim + { "MoveWaypoint", &LuaCreature::MoveWaypoint }, // :MoveWaypoint() + + { NULL, NULL }, +}; + +ElunaRegister GameObjectMethods[] = +{ + // Getters + { "GetDisplayId", &LuaGameObject::GetDisplayId }, // :GetDisplayId() + { "GetGoState", &LuaGameObject::GetGoState }, // :GetGoState() - Returns state + { "GetLootState", &LuaGameObject::GetLootState }, // :GetLootState() - Returns loot state + + // Setters + { "SetGoState", &LuaGameObject::SetGoState }, + { "SetLootState", &LuaGameObject::SetLootState }, + + // Boolean + { "IsTransport", &LuaGameObject::IsTransport }, // :IsTransport() + // {"IsDestructible", &LuaGameObject::IsDestructible}, // :IsDestructible() + { "IsActive", &LuaGameObject::IsActive }, // :IsActive() + { "HasQuest", &LuaGameObject::HasQuest }, // :HasQuest(questId) + { "IsSpawned", &LuaGameObject::IsSpawned }, // :IsSpawned() + + // Other + { "RegisterEvent", &LuaGameObject::RegisterEvent }, // :RegisterEvent(function, delay, calls) + { "RemoveEventById", &LuaGameObject::RemoveEventById }, // :RemoveEventById(eventID) + { "RemoveEvents", &LuaGameObject::RemoveEvents }, // :RemoveEvents() + { "RemoveFromWorld", &LuaGameObject::RemoveFromWorld }, // :RemoveFromWorld(del) + { "UseDoorOrButton", &LuaGameObject::UseDoorOrButton }, // :UseDoorOrButton(delay) - Activates/closes/opens after X delay UNDOCUMENTED + { "Despawn", &LuaGameObject::Despawn }, // :Despawn([delay]) - Despawns the object after delay + { "Respawn", &LuaGameObject::Respawn }, // :Respawn([delay]) - respawns the object after delay + { "SaveToDB", &LuaGameObject::SaveToDB }, // :SaveToDB() - Saves to database + + { NULL, NULL }, +}; + +ElunaRegister ItemMethods[] = +{ + // Getters + { "GetOwnerGUID", &LuaItem::GetOwnerGUID }, // :GetOwnerGUID() - Returns the owner's guid + { "GetOwner", &LuaItem::GetOwner }, // :GetOwner() - Returns the owner object (player) + { "GetCount", &LuaItem::GetCount }, // :GetCount() - Returns item stack count + { "GetMaxStackCount", &LuaItem::GetMaxStackCount }, // :GetMaxStackCount() - Returns item max stack count + { "GetSlot", &LuaItem::GetSlot }, // :GetSlot() - returns the slot the item is in + { "GetBagSlot", &LuaItem::GetBagSlot }, // :GetBagSlot() - returns the bagslot of the bag the item is in + { "GetEnchantmentId", &LuaItem::GetEnchantmentId }, // :GetEnchantmentId(enchant_slot) - Returns the enchantment in given slot. (permanent = 0) + { "GetSpellId", &LuaItem::GetSpellId }, // :GetSpellId(index) - Returns spellID at given index (0 - 4) + { "GetSpellTrigger", &LuaItem::GetSpellTrigger }, // :GetSpellTrigger(index) - Returns spell trigger at given index (0 - 4) + { "GetItemLink", &LuaItem::GetItemLink }, // :GetItemLink([localeID]) - Returns the shift clickable link of the item. Name translated if locale given and exists + { "GetClass", &LuaItem::GetClass }, // :GetClass() + { "GetSubClass", &LuaItem::GetSubClass }, // :GetSubClass() + { "GetName", &LuaItem::GetName }, // :GetName() + { "GetDisplayId", &LuaItem::GetDisplayId }, // :GetDisplayId() + { "GetQuality", &LuaItem::GetQuality }, // :GetQuality() + { "GetBuyCount", &LuaItem::GetBuyCount }, // :GetBuyCount() + { "GetBuyPrice", &LuaItem::GetBuyPrice }, // :GetBuyPrice() + { "GetSellPrice", &LuaItem::GetSellPrice }, // :GetSellPrice() + { "GetInventoryType", &LuaItem::GetInventoryType }, // :GetInventoryType() + { "GetAllowableClass", &LuaItem::GetAllowableClass }, // :GetAllowableClass() + { "GetAllowableRace", &LuaItem::GetAllowableRace }, // :GetAllowableRace() + { "GetItemLevel", &LuaItem::GetItemLevel }, // :GetItemLevel() + { "GetRequiredLevel", &LuaItem::GetRequiredLevel }, // :GetRequiredLevel() +#ifdef WOTLK + { "GetStatsCount", &LuaItem::GetStatsCount }, // :GetStatsCount() +#endif + { "GetRandomProperty", &LuaItem::GetRandomProperty }, // :GetRandomProperty() + { "GetRandomSuffix", &LuaItem::GetRandomSuffix }, // :GetRandomSuffix() + { "GetItemSet", &LuaItem::GetItemSet }, // :GetItemSet() + { "GetBagSize", &LuaItem::GetBagSize }, // :GetBagSize() + + // Setters + { "SetOwner", &LuaItem::SetOwner }, // :SetOwner(player) - Sets the owner of the item + { "SetBinding", &LuaItem::SetBinding }, // :SetBinding(bound) - Sets the item binding to true or false + { "SetCount", &LuaItem::SetCount }, // :SetCount(count) - Sets the item count + + // Boolean + { "IsSoulBound", &LuaItem::IsSoulBound }, // :IsSoulBound() - Returns true if the item is soulbound +#ifndef TBC + { "IsBoundAccountWide", &LuaItem::IsBoundAccountWide }, // :IsBoundAccountWide() - Returns true if the item is account bound +#endif + { "IsBoundByEnchant", &LuaItem::IsBoundByEnchant }, // :IsBoundByEnchant() - Returns true if the item is bound with an enchant + { "IsNotBoundToPlayer", &LuaItem::IsNotBoundToPlayer }, // :IsNotBoundToPlayer(player) - Returns true if the item is not bound with player + { "IsLocked", &LuaItem::IsLocked }, // :IsLocked() - Returns true if the item is locked + { "IsBag", &LuaItem::IsBag }, // :IsBag() - Returns true if the item is a bag + { "IsCurrencyToken", &LuaItem::IsCurrencyToken }, // :IsCurrencyToken() - Returns true if the item is a currency token + { "IsNotEmptyBag", &LuaItem::IsNotEmptyBag }, // :IsNotEmptyBag() - Returns true if the item is not an empty bag + { "IsBroken", &LuaItem::IsBroken }, // :IsBroken() - Returns true if the item is broken + { "CanBeTraded", &LuaItem::CanBeTraded }, // :CanBeTraded() - Returns true if the item can be traded + { "IsInTrade", &LuaItem::IsInTrade }, // :IsInTrade() - Returns true if the item is in trade + { "IsInBag", &LuaItem::IsInBag }, // :IsInBag() - Returns true if the item is in a bag + { "IsEquipped", &LuaItem::IsEquipped }, // :IsEquipped() - Returns true if the item is equipped + { "HasQuest", &LuaItem::HasQuest }, // :HasQuest(questId) - Returns true if the item starts the quest + { "IsPotion", &LuaItem::IsPotion }, // :IsPotion() - Returns true if the item is a potion +#ifndef CATA + { "IsWeaponVellum", &LuaItem::IsWeaponVellum }, // :IsWeaponVellum() - Returns true if the item is a weapon vellum + { "IsArmorVellum", &LuaItem::IsArmorVellum }, // :IsArmorVellum() - Returns true if the item is an armor vellum +#endif + { "IsConjuredConsumable", &LuaItem::IsConjuredConsumable }, // :IsConjuredConsumable() - Returns true if the item is a conjured consumable + // {"IsRefundExpired", &LuaItem::IsRefundExpired}, // :IsRefundExpired() - Returns true if the item's refund time has expired + { "SetEnchantment", &LuaItem::SetEnchantment }, // :SetEnchantment(enchantid, enchantmentslot) - Sets a new enchantment for the item. Returns true on success + { "ClearEnchantment", &LuaItem::ClearEnchantment }, // :ClearEnchantment(enchantmentslot) - Removes the enchantment from the item if one exists. Returns true on success + + // Other + { "SaveToDB", &LuaItem::SaveToDB }, // :SaveToDB() - Saves to database + + { NULL, NULL }, +}; + +ElunaRegister AuraMethods[] = +{ + // Getters + { "GetCaster", &LuaAura::GetCaster }, // :GetCaster() - Returns caster as object + { "GetCasterGUID", &LuaAura::GetCasterGUID }, // :GetCasterGUID() - Returns caster as GUID + { "GetCasterLevel", &LuaAura::GetCasterLevel }, // :GetCasterLevel() - Returns casters level + { "GetDuration", &LuaAura::GetDuration }, // :GetDuration() - Returns remaining duration + { "GetMaxDuration", &LuaAura::GetMaxDuration }, // :GetMaxDuration() - Returns maximum duration + { "GetCharges", &LuaAura::GetCharges }, // :GetCharges() - Returns remaining charges + { "GetAuraId", &LuaAura::GetAuraId }, // :GetAuraId() - Returns aura ID + { "GetStackAmount", &LuaAura::GetStackAmount }, // :GetStackAmount() - Returns current stack amount + { "GetOwner", &LuaAura::GetOwner }, // :GetOwner() - Gets the unit wearing the aura + + // Setters + { "SetDuration", &LuaAura::SetDuration }, // :SetDuration(duration) - Sets remaining duration + { "SetMaxDuration", &LuaAura::SetMaxDuration }, // :SetMaxDuration(duration) - Sets maximum duration + { "SetStackAmount", &LuaAura::SetStackAmount }, // :SetStackAmount(amount) - Sets current stack amount + + // Other + { "Remove", &LuaAura::Remove }, // :Remove() - Removes the aura + + { NULL, NULL }, +}; + +ElunaRegister SpellMethods[] = +{ + // Getters + { "GetCaster", &LuaSpell::GetCaster }, // :GetCaster() - Returns the spell's caster (UNIT) + { "GetCastTime", &LuaSpell::GetCastTime }, // :GetCastTime() - Returns the spell cast time + { "GetEntry", &LuaSpell::GetId }, // :GetEntry() - Returns the spell's ID + { "GetDuration", &LuaSpell::GetDuration }, // :GetDuration() - Returns the spell's duration + { "GetPowerCost", &LuaSpell::GetPowerCost }, // :GetPowerCost() - Returns the spell's power cost (mana, energy, rage, etc) + { "GetTargetDest", &LuaSpell::GetTargetDest }, // :GetTargetDest() - Returns the target destination (x,y,z,o,map) or nil. Orientation and map may be 0. + { "GetTarget", &LuaSpell::GetTarget }, // :GetTarget() - Returns spell cast target (item, worldobject) + + // Setters + { "SetAutoRepeat", &LuaSpell::SetAutoRepeat }, // :SetAutoRepeat(boolean) + + // Boolean + { "IsAutoRepeat", &LuaSpell::IsAutoRepeat }, // :IsAutoRepeat() + + // Other + { "Cancel", &LuaSpell::cancel }, // :Cancel() - Cancels the spell casting + { "Cast", &LuaSpell::Cast }, // :Cast(skipCheck) - Casts the spell (if true, removes the check for instant spells, etc) + { "Finish", &LuaSpell::Finish }, // :Finish() - Finishes the spell (SPELL_STATE_FINISH) + + { NULL, NULL }, +}; + +ElunaRegister QuestMethods[] = +{ + // Getters + { "GetId", &LuaQuest::GetId }, // :GetId() - Returns the quest's Id + { "GetLevel", &LuaQuest::GetLevel }, // :GetLevel() - Returns the quest's level + // {"GetMaxLevel", &LuaQuest::GetMaxLevel}, // :GetMaxLevel() - Returns the quest's max level + { "GetMinLevel", &LuaQuest::GetMinLevel }, // :GetMinLevel() - Returns the quest's min level + { "GetNextQuestId", &LuaQuest::GetNextQuestId }, // :GetNextQuestId() - Returns the quest's next quest ID + { "GetPrevQuestId", &LuaQuest::GetPrevQuestId }, // :GetPrevQuestId() - Returns the quest's previous quest ID + { "GetNextQuestInChain", &LuaQuest::GetNextQuestInChain }, // :GetNexQuestInChain() - Returns the next quest in its chain + { "GetFlags", &LuaQuest::GetFlags }, // :GetFlags() - Returns the quest's flags + { "GetType", &LuaQuest::GetType }, // :GetType() - Returns the quest's type + + // Boolean + { "HasFlag", &LuaQuest::HasFlag }, // :HasFlag(flag) - Returns true or false if the quest has the specified flag + { "IsDaily", &LuaQuest::IsDaily }, // :IsDaily() - Returns true or false if the quest is a daily + { "IsRepeatable", &LuaQuest::IsRepeatable }, // :IsRepeatable() - Returns true or false if the quest is repeatable + + // Setters + { "SetFlag", &LuaQuest::SetFlag }, // :SetFlag(flag) - Sets the flag of the quest by the specified flag + + { NULL, NULL }, +}; + +ElunaRegister GroupMethods[] = +{ + // Getters + { "GetMembers", &LuaGroup::GetMembers }, // :GetMembers() - returns a table the players in this group. (Online?) + { "GetLeaderGUID", &LuaGroup::GetLeaderGUID }, + { "GetLeader", &LuaGroup::GetLeader }, + { "GetGUID", &LuaGroup::GetGUID }, + { "GetMemberGroup", &LuaGroup::GetMemberGroup }, // :GetMemberGroup(player) - Returns the player's subgroup ID + { "GetMemberGUID", &LuaGroup::GetMemberGUID }, // :GetMemberGUID("name") - Returns the member's GUID + { "GetMembersCount", &LuaGroup::GetMembersCount }, // :GetMembersCount() - Returns the member count of the group + + // Setters + { "SetLeader", &LuaGroup::ChangeLeader }, // :SetLeader(Player) - Sets the player as the new leader + { "SetMembersGroup", &LuaGroup::ChangeMembersGroup }, // :ChangeMembersGroup(player, subGroup) - Changes the member's subgroup + + // Boolean + { "IsLeader", &LuaGroup::IsLeader }, // :IsLeader(GUID) + { "AddInvite", &LuaGroup::AddInvite }, // :AddInvite(player) - Adds a an invite to player. Returns true if succesful + { "RemoveMember", &LuaGroup::RemoveMember }, // :RemoveMember(player) - Removes player from group. Returns true on success + { "Disband", &LuaGroup::Disband }, // :Disband() - Disbands the group + { "IsFull", &LuaGroup::IsFull }, // :IsFull() - Returns true if the group is full + // {"IsLFGGroup", &LuaGroup::isLFGGroup}, // :IsLFGGroup() - Returns true if the group is an LFG group + { "IsRaidGroup", &LuaGroup::isRaidGroup }, // :IsRaidGroup() - Returns true if the group is a raid group + { "IsBGGroup", &LuaGroup::isBGGroup }, // :IsBGGroup() - Returns true if the group is a battleground group + // {"IsBFGroup", &LuaGroup::isBFGroup}, // :IsBFGroup() - Returns true if the group is a battlefield group + { "IsMember", &LuaGroup::IsMember }, // :IsMember(player) - Returns true if the player is a member of the group + { "IsAssistant", &LuaGroup::IsAssistant }, // :IsAssistant(player) - returns true if the player is an assistant in the group + { "SameSubGroup", &LuaGroup::SameSubGroup }, // :SameSubGroup(player1, player2) - Returns true if the players are in the same subgroup in the group + { "HasFreeSlotSubGroup", &LuaGroup::HasFreeSlotSubGroup }, // :HasFreeSlotSubGroup(subGroup) - Returns true if the subgroupID has free slots + + // Other + { "SendPacket", &LuaGroup::SendPacket }, // :SendPacket(packet, sendToPlayersInBattleground[, ignoreguid]) - Sends a specified packet to the group with the choice (true/false) to send it to players in a battleground. Optionally ignores given player guid + // {"ConvertToLFG", &LuaGroup::ConvertToLFG}, // :ConvertToLFG() - Converts the group to an LFG group + { "ConvertToRaid", &LuaGroup::ConvertToRaid }, // :ConvertToRaid() - Converts the group to a raid group + + { NULL, NULL }, +}; + +ElunaRegister GuildMethods[] = +{ + // Getters + { "GetMembers", &LuaGuild::GetMembers }, // :GetMembers() - returns a table containing the players in this guild. (Online?) + { "GetLeader", &LuaGuild::GetLeader }, // :GetLeader() - Returns the guild learder's object + { "GetLeaderGUID", &LuaGuild::GetLeaderGUID }, // :GetLeaderGUID() - Returns the guild learder's guid + { "GetId", &LuaGuild::GetId }, // :GetId() - Gets the guild's ID + { "GetName", &LuaGuild::GetName }, // :GetName() - Gets the guild name + { "GetMOTD", &LuaGuild::GetMOTD }, // :GetMOTD() - Gets the guild MOTD string + { "GetInfo", &LuaGuild::GetInfo }, // :GetInfo() - Gets the guild info string + { "GetMemberCount", &LuaGuild::GetMemberCount }, // :GetMemberCount() - Returns the amount of players in the guild + + // Setters + { "SetBankTabText", &LuaGuild::SetBankTabText }, // :SetBankTabText(tabId, text) + { "SetMemberRank", &LuaGuild::ChangeMemberRank }, // :SetMemberRank(player, newRank) - Sets the player rank in the guild to the new rank +#ifndef CATA + { "SetLeader", &LuaGuild::SetLeader }, // :SetLeader() - Sets the guild's leader +#endif + + // Boolean + + // Other + { "ChangeMemberRank", &LuaGuild::ChangeMemberRank }, // :ChangeMemberRank(player, rankId) - Changes players rank to rank specified + { "SendPacket", &LuaGuild::SendPacket }, // :SendPacket(packet) - sends packet to guild + { "SendPacketToRanked", &LuaGuild::SendPacketToRanked }, // :SendPacketToRanked(packet, rankId) - sends packet to guild, specifying a rankId will only send the packet to your ranked members + { "Disband", &LuaGuild::Disband }, // :Disband() - Disbands the guild + { "AddMember", &LuaGuild::AddMember }, // :AddMember(player, rank) - adds the player to the guild. Rank is optional + { "DeleteMember", &LuaGuild::DeleteMember }, // :DeleteMember(player, disbanding, kicked) - Deletes the player from the guild. Disbanding and kicked are optional bools + { "DepositBankMoney", &LuaGuild::DepositBankMoney }, // :DepositBankMoney(money) - Deposits money into the guild bank + { "WithdrawBankMoney", &LuaGuild::WithdrawBankMoney }, // :WithdrawBankMoney(money) - Withdraws money from the guild bank + + { NULL, NULL }, +}; + +#ifndef TBC +ElunaRegister VehicleMethods[] = +{ + // Getters + { "GetOwner", &LuaVehicle::GetOwner }, // :GetOwner() - Returns the the vehicle unit + { "GetEntry", &LuaVehicle::GetEntry }, // :GetEntry() - Returns vehicle ID + { "GetPassenger", &LuaVehicle::GetPassenger }, // :GetPassenger(seatId) - Returns the passenger by seatId + + // Boolean + { "IsOnBoard", &LuaVehicle::IsOnBoard }, // :IsOnBoard(unit) - Returns true if the unit is on board + + // Other + { "AddPassenger", &LuaVehicle::AddPassenger }, // :AddPassenger(passenger, seatId) - Adds a vehicle passenger + { "RemovePassenger", &LuaVehicle::RemovePassenger }, // :RemovePassenger(passenger) - Removes the passenger from the vehicle + + { NULL, NULL }, +}; +#endif + +ElunaRegister QueryMethods[] = +{ + { "NextRow", &LuaQuery::NextRow }, // :NextRow() - Advances to next rown in the query. Returns true if there is a next row, otherwise false + { "GetColumnCount", &LuaQuery::GetColumnCount }, // :GetColumnCount() - Gets the column count of the query + { "GetRowCount", &LuaQuery::GetRowCount }, // :GetRowCount() - Gets the row count of the query + + { "GetBool", &LuaQuery::GetBool }, // :GetBool(column) - returns a bool from a number column (for example tinyint) + { "GetUInt8", &LuaQuery::GetUInt8 }, // :GetUInt8(column) - returns the value of an unsigned tinyint column + { "GetUInt16", &LuaQuery::GetUInt16 }, // :GetUInt16(column) - returns the value of a unsigned smallint column + { "GetUInt32", &LuaQuery::GetUInt32 }, // :GetUInt32(column) - returns the value of an unsigned int or mediumint column + { "GetUInt64", &LuaQuery::GetUInt64 }, // :GetUInt64(column) - returns the value of an unsigned bigint column as string + { "GetInt8", &LuaQuery::GetInt8 }, // :GetInt8(column) - returns the value of an tinyint column + { "GetInt16", &LuaQuery::GetInt16 }, // :GetInt16(column) - returns the value of a smallint column + { "GetInt32", &LuaQuery::GetInt32 }, // :GetInt32(column) - returns the value of an int or mediumint column + { "GetInt64", &LuaQuery::GetInt64 }, // :GetInt64(column) - returns the value of a bigint column as string + { "GetFloat", &LuaQuery::GetFloat }, // :GetFloat(column) - returns the value of a float column + { "GetDouble", &LuaQuery::GetDouble }, // :GetDouble(column) - returns the value of a double column + { "GetString", &LuaQuery::GetString }, // :GetString(column) - returns the value of a string column + { "IsNull", &LuaQuery::IsNull }, // :IsNull(column) - returns true if the column is null + + { NULL, NULL }, +}; + +ElunaRegister PacketMethods[] = +{ + // Getters + { "GetOpcode", &LuaPacket::GetOpcode }, // :GetOpcode() - Returns an opcode + { "GetSize", &LuaPacket::GetSize }, // :GetSize() - Returns the packet size + + // Setters + { "SetOpcode", &LuaPacket::SetOpcode }, // :SetOpcode(opcode) - Sets the opcode by specifying an opcode + + // Readers + { "ReadByte", &LuaPacket::ReadByte }, // :ReadByte() - Reads an int8 value + { "ReadUByte", &LuaPacket::ReadUByte }, // :ReadUByte() - Reads an uint8 value + { "ReadShort", &LuaPacket::ReadShort }, // :ReadShort() - Reads an int16 value + { "ReadUShort", &LuaPacket::ReadUShort }, // :ReadUShort() - Reads an uint16 value + { "ReadLong", &LuaPacket::ReadLong }, // :ReadLong() - Reads an int32 value + { "ReadULong", &LuaPacket::ReadULong }, // :ReadULong() - Reads an uint32 value + { "ReadGUID", &LuaPacket::ReadGUID }, // :ReadGUID() - Reads an uint64 value + { "ReadString", &LuaPacket::ReadString }, // :ReadString() - Reads a string value + { "ReadFloat", &LuaPacket::ReadFloat }, // :ReadFloat() - Reads a float value + { "ReadDouble", &LuaPacket::ReadDouble }, // :ReadDouble() - Reads a double value + + // Writers + { "WriteByte", &LuaPacket::WriteByte }, // :WriteByte(val) - Writes an int8 value + { "WriteUByte", &LuaPacket::WriteUByte }, // :WriteUByte(val) - Writes a uint8 value + { "WriteShort", &LuaPacket::WriteShort }, // :WriteShort(val) - Writes an int16 value + { "WriteUShort", &LuaPacket::WriteUShort }, // :WriteUShort(val) - Writes a uint16 value + { "WriteLong", &LuaPacket::WriteLong }, // :WriteLong(val) - Writes an int32 value + { "WriteULong", &LuaPacket::WriteULong }, // :WriteULong(val) - Writes a uint32 value + { "WriteGUID", &LuaPacket::WriteGUID }, // :WriteGUID(guid) - Writes a uint64 value + { "WriteString", &LuaPacket::WriteString }, // :WriteString(val) - Writes a string value + { "WriteFloat", &LuaPacket::WriteFloat }, // :WriteFloat(val) - Writes a float value + { "WriteDouble", &LuaPacket::WriteDouble }, // :WriteDouble(val) - Writes a double value + + { NULL, NULL }, +}; + +ElunaRegister MapMethods[] = +{ + // Getters + { "GetName", &LuaMap::GetName }, // :GetName() - Returns the map's name UNDOCUMENTED + { "GetDifficulty", &LuaMap::GetDifficulty }, // :GetDifficulty() - Returns the map's difficulty UNDOCUMENTED + { "GetInstanceId", &LuaMap::GetInstanceId }, // :GetInstanceId() - Returns the map's instance ID UNDOCUMENTED + { "GetPlayerCount", &LuaMap::GetPlayerCount }, // :GetPlayerCount() - Returns the amount of players on map except GM's UNDOCUMENTED + { "GetMapId", &LuaMap::GetMapId }, // :GetMapId() - Returns the map's ID UNDOCUMENTED + { "GetAreaId", &LuaMap::GetAreaId }, // :GetAreaId(x, y, z) - Returns the map's area ID based on coords UNDOCUMENTED + { "GetHeight", &LuaMap::GetHeight }, // :GetHeight(x, y[, phasemask]) - Returns ground Z coordinate. UNDOCUMENTED + + // Booleans + { "IsArena", &LuaMap::IsArena }, // :IsArena() - Returns the true if the map is an arena, else false UNDOCUMENTED + { "IsBattleground", &LuaMap::IsBattleground }, // :IsBattleground() - Returns the true if the map is a battleground, else false UNDOCUMENTED + { "IsDungeon", &LuaMap::IsDungeon }, // :IsDungeon() - Returns the true if the map is a dungeon , else false UNDOCUMENTED + { "IsEmpty", &LuaMap::IsEmpty }, // :IsEmpty() - Returns the true if the map is empty, else false UNDOCUMENTED + { "IsHeroic", &LuaMap::IsHeroic }, // :IsHeroic() - Returns the true if the map is a heroic dungeon, else false UNDOCUMENTED + { "IsRaid", &LuaMap::IsRaid }, // :IsRaid() - Returns the true if the map is a raid map, else false UNDOCUMENTED + + { NULL, NULL }, +}; + +ElunaRegister CorpseMethods[] = +{ + { "GetOwnerGUID", &LuaCorpse::GetOwnerGUID }, // :GetOwnerGUID() - Returns the corpse owner GUID + { "GetGhostTime", &LuaCorpse::GetGhostTime }, // :GetGhostTime() - Returns the ghost time of a corpse + { "GetType", &LuaCorpse::GetType }, // :GetType() - Returns the (CorpseType) of a corpse + { "ResetGhostTime", &LuaCorpse::ResetGhostTime }, // :ResetGhostTime() - Resets the corpse's ghost time + { "SaveToDB", &LuaCorpse::SaveToDB }, // :SaveToDB() - Saves to database + { "DeleteBonesFromWorld", &LuaCorpse::DeleteBonesFromWorld }, // :DeleteBonesFromWorld() - Deletes all bones from the world + + { NULL, NULL } +}; + +ElunaRegister WeatherMethods[] = +{ + // Getters + { "GetZoneId", &LuaWeather::GetZoneId }, // :GetZoneId() - Returns the weather's zoneId + + // Setters + { "SetWeather", &LuaWeather::SetWeather }, // :SetWeather(weatherType, grade) - Sets the weather by weather type and grade + + // Boolean + { "Regenerate", &LuaWeather::Regenerate }, // :Regenerate() - Calculates weather, returns true if the weather changed + { "UpdateWeather", &LuaWeather::UpdateWeather }, // :UpdateWeather() - Updates the weather in a zone that has players in it, returns false if players aren't found + + // Other + { "SendWeatherUpdateToPlayer", &LuaWeather::SendWeatherUpdateToPlayer }, // :SendWeatherUpdateToPlayer(player) - Sends weather update to the player + + { NULL, NULL } +}; + +ElunaRegister AuctionMethods[] = +{ + { NULL, NULL } +}; + +template const char* ElunaTemplate::tname = NULL; +template bool ElunaTemplate::manageMemory = false; +#ifndef TBC +// fix compile error about accessing vehicle destructor +template<> int ElunaTemplate::gcT(lua_State* L) { return 0; } +#endif + +void RegisterFunctions(lua_State* L) +{ + RegisterGlobals(L); + lua_settop(L, 0); // clean stack + + ElunaTemplate::Register(L, "Object"); + ElunaTemplate::SetMethods(L, ObjectMethods); + + ElunaTemplate::Register(L, "WorldObject"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + + ElunaTemplate::Register(L, "Unit"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + ElunaTemplate::SetMethods(L, UnitMethods); + + ElunaTemplate::Register(L, "Player"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + ElunaTemplate::SetMethods(L, UnitMethods); + ElunaTemplate::SetMethods(L, PlayerMethods); + + ElunaTemplate::Register(L, "Creature"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + ElunaTemplate::SetMethods(L, UnitMethods); + ElunaTemplate::SetMethods(L, CreatureMethods); + + ElunaTemplate::Register(L, "GameObject"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + ElunaTemplate::SetMethods(L, GameObjectMethods); + + ElunaTemplate::Register(L, "Corpse"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, WorldObjectMethods); + ElunaTemplate::SetMethods(L, CorpseMethods); + + ElunaTemplate::Register(L, "Item"); + ElunaTemplate::SetMethods(L, ObjectMethods); + ElunaTemplate::SetMethods(L, ItemMethods); + +#ifndef TBC + ElunaTemplate::Register(L, "Vehicle"); + ElunaTemplate::SetMethods(L, VehicleMethods); +#endif + + ElunaTemplate::Register(L, "Group"); + ElunaTemplate::SetMethods(L, GroupMethods); + + ElunaTemplate::Register(L, "Guild"); + ElunaTemplate::SetMethods(L, GuildMethods); + + ElunaTemplate::Register(L, "Aura"); + ElunaTemplate::SetMethods(L, AuraMethods); + + ElunaTemplate::Register(L, "Spell"); + ElunaTemplate::SetMethods(L, SpellMethods); + + ElunaTemplate::Register(L, "Quest"); + ElunaTemplate::SetMethods(L, QuestMethods); + + ElunaTemplate::Register(L, "Map"); + ElunaTemplate::SetMethods(L, MapMethods); + + ElunaTemplate::Register(L, "Weather"); + ElunaTemplate::SetMethods(L, WeatherMethods); + + ElunaTemplate::Register(L, "AuctionHouseObject"); + ElunaTemplate::SetMethods(L, AuctionMethods); + + ElunaTemplate::Register(L, "WorldPacket", true); + ElunaTemplate::SetMethods(L, PacketMethods); + + ElunaTemplate::Register(L, "QueryResult", true); + ElunaTemplate::SetMethods(L, QueryMethods); + + lua_settop(L, 0); // clean stack +} diff --git a/MapMethods.h b/MapMethods.h new file mode 100644 index 0000000..b2f5635 --- /dev/null +++ b/MapMethods.h @@ -0,0 +1,114 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaMap +{ + /* BOOLEAN */ + int IsArena(lua_State* L, Map* map) + { + sEluna->Push(L, map->IsBattleArena()); + return 1; + } + + int IsBattleground(lua_State* L, Map* map) + { +#ifdef MANGOS + sEluna->Push(L, map->IsBattleGround()); +#else + sEluna->Push(L, map->IsBattleground()); +#endif + return 1; + } + + int IsDungeon(lua_State* L, Map* map) + { + sEluna->Push(L, map->IsDungeon()); + return 1; + } + + int IsEmpty(lua_State* L, Map* map) + { + sEluna->Push(L, map->isEmpty()); + return 1; + } + + int IsHeroic(lua_State* L, Map* map) + { + sEluna->Push(L, map->IsHeroic()); + return 1; + } + + int IsRaid(lua_State* L, Map* map) + { + sEluna->Push(L, map->IsRaid()); + return 1; + } + + /* GETTERS */ + int GetName(lua_State* L, Map* map) + { + sEluna->Push(L, map->GetMapName()); + return 1; + } + + int GetHeight(lua_State* L, Map* map) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); +#ifdef TBC + float z = map->GetHeight(x, y, MAX_HEIGHT); +#else + uint32 phasemask = sEluna->CHECKVAL(L, 4, 1); + float z = map->GetHeight(phasemask, x, y, MAX_HEIGHT); +#endif + if (z == INVALID_HEIGHT) + return 0; + sEluna->Push(L, z); + return 1; + } + + int GetDifficulty(lua_State* L, Map* map) + { + sEluna->Push(L, map->GetDifficulty()); + return 1; + } + + int GetInstanceId(lua_State* L, Map* map) + { + sEluna->Push(L, map->GetInstanceId()); + return 1; + } + + int GetPlayerCount(lua_State* L, Map* map) + { + sEluna->Push(L, map->GetPlayersCountExceptGMs()); + return 1; + } + + int GetMapId(lua_State* L, Map* map) + { + sEluna->Push(L, map->GetId()); + return 1; + } + + int GetAreaId(lua_State* L, Map* map) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + float z = sEluna->CHECKVAL(L, 4); + +#ifdef MANGOS + sEluna->Push(L, map->GetTerrain()->GetAreaId(x, y, z)); +#else + sEluna->Push(L, map->GetAreaId(x, y, z)); +#endif + return 1; + } +}; +#endif diff --git a/ObjectMethods.h b/ObjectMethods.h new file mode 100644 index 0000000..4783519 --- /dev/null +++ b/ObjectMethods.h @@ -0,0 +1,214 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaObject +{ + /* BOOLEAN */ + int HasFlag(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint32 flag = sEluna->CHECKVAL(L, 3); + + sEluna->Push(L, obj->HasFlag(index, flag)); + return 1; + } + + static int IsInWorld(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->IsInWorld()); + return 1; + } + + /* GETTERS */ + int GetInt32Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, obj->GetInt32Value(index)); + return 1; + } + + int GetUInt32Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, obj->GetUInt32Value(index)); + return 1; + } + + int GetFloatValue(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, obj->GetFloatValue(index)); + return 1; + } + + int GetByteValue(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint8 offset = sEluna->CHECKVAL(L, 3); + sEluna->Push(L, obj->GetByteValue(index, offset)); + return 1; + } + + int GetUInt16Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint8 offset = sEluna->CHECKVAL(L, 3); + sEluna->Push(L, obj->GetUInt16Value(index, offset)); + return 1; + } + + static int GetScale(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->GetObjectScale()); + return 1; + } + + static int GetEntry(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->GetEntry()); + return 1; + } + + static int GetGUID(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->GET_GUID()); + return 1; + } + + static int GetGUIDLow(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->GetGUIDLow()); + return 1; + } + + static int GetTypeId(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->GetTypeId()); + return 1; + } + + /* SETTERS */ + int SetFlag(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint32 flag = sEluna->CHECKVAL(L, 3); + + obj->SetFlag(index, flag); + return 0; + } + + int SetInt32Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + int32 value = sEluna->CHECKVAL(L, 3); + obj->SetInt32Value(index, value); + return 0; + } + + int SetUInt32Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint32 value = sEluna->CHECKVAL(L, 3); + obj->SetUInt32Value(index, value); + return 0; + } + + int SetFloatValue(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + float value = sEluna->CHECKVAL(L, 3); + + obj->SetFloatValue(index, value); + return 0; + } + + int SetByteValue(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint8 offset = sEluna->CHECKVAL(L, 3); + uint8 value = sEluna->CHECKVAL(L, 4); + obj->SetByteValue(index, offset, value); + return 0; + } + + int SetUInt16Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint8 offset = sEluna->CHECKVAL(L, 3); + uint16 value = sEluna->CHECKVAL(L, 4); + obj->SetUInt16Value(index, offset, value); + return 0; + } + + int SetInt16Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint8 offset = sEluna->CHECKVAL(L, 3); + int16 value = sEluna->CHECKVAL(L, 4); + obj->SetInt16Value(index, offset, value); + return 0; + } + + int SetScale(lua_State* L, Object* obj) + { + float size = sEluna->CHECKVAL(L, 2); + + obj->SetObjectScale(size); + return 0; + } + + /* OTHER */ + int RemoveFlag(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint32 flag = sEluna->CHECKVAL(L, 3); + + obj->RemoveFlag(index, flag); + return 0; + } + + int UpdateUInt32Value(lua_State* L, Object* obj) + { + uint16 index = sEluna->CHECKVAL(L, 2); + uint32 value = sEluna->CHECKVAL(L, 3); + obj->UpdateUInt32Value(index, value); + return 0; + } + + static int ToCorpse(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->ToCorpse()); + return 1; + } + + static int ToGameObject(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->ToGameObject()); + return 1; + } + + static int ToUnit(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->ToUnit()); + return 1; + } + + static int ToCreature(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->ToCreature()); + return 1; + } + + static int ToPlayer(lua_State* L, Object* obj) + { + sEluna->Push(L, obj->ToPlayer()); + return 1; + } +}; +#endif diff --git a/PlayerMethods.h b/PlayerMethods.h new file mode 100644 index 0000000..6ede225 --- /dev/null +++ b/PlayerMethods.h @@ -0,0 +1,2328 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaPlayer +{ + /* BOOLEAN */ +#ifndef TBC + int CanTitanGrip(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanTitanGrip()); + return 1; + } + + int HasTalent(lua_State* L, Player* player) + { + uint32 talentId = sEluna->CHECKVAL(L, 2); + uint8 spec = sEluna->CHECKVAL(L, 3); + if (spec >= MAX_TALENT_SPECS) + sEluna->Push(L, false); + else + sEluna->Push(L, player->HasTalent(talentId, spec)); + return 1; + } + + int HasAchieved(lua_State* L, Player* player) + { + uint32 achievementId = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, player->GetAchievementMgr().HasAchievement(achievementId)); +#else + sEluna->Push(L, player->HasAchieved(achievementId)); +#endif + return 1; + } +#endif + + int HasQuest(lua_State* L, Player* player) + { + uint32 quest = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->IsActiveQuest(quest)); + return 1; + } + + int HasSkill(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasSkill(skill)); + return 1; + } + + int HasSpell(lua_State* L, Player* player) + { + uint32 id = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasSpell(id)); + return 1; + } + + int HasAtLoginFlag(lua_State* L, Player* player) + { + uint32 flag = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasAtLoginFlag((AtLoginFlags)flag)); + return 1; + } + + int HasQuestForGO(lua_State* L, Player* player) + { + int32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasQuestForGO(entry)); + return 1; + } + + int HasTitle(lua_State* L, Player* player) + { + uint32 id = sEluna->CHECKVAL(L, 2); + CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); + if (titleInfo) + sEluna->Push(L, player->HasTitle(titleInfo)); + else + sEluna->Push(L, false); + return 1; + } + + int HasItem(lua_State* L, Player* player) + { + uint32 itemId = sEluna->CHECKVAL(L, 2); + uint32 count = sEluna->CHECKVAL(L, 3, 1); + bool check_bank = sEluna->CHECKVAL(L, 4, false); + sEluna->Push(L, player->HasItemCount(itemId, count, check_bank)); + return 1; + } + + int HasQuestForItem(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasQuestForItem(entry)); + return 1; + } + + int CanUseItem(lua_State* L, Player* player) + { + Item* item = sEluna->CHECKOBJ(L, 2, false); + if (item) + sEluna->Push(L, player->CanUseItem(item)); + else + { + uint32 entry = sEluna->CHECKVAL(L, 2); + const ItemTemplate* temp = sObjectMgr->GetItemTemplate(entry); + if (temp) + sEluna->Push(L, player->CanUseItem(temp)); + else + sEluna->Push(L, EQUIP_ERR_ITEM_NOT_FOUND); + } + return 1; + } + + int HasSpellCooldown(lua_State* L, Player* player) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->HasSpellCooldown(spellId)); + return 1; + } + + int CanShareQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->CanShareQuest(entry)); + return 1; + } + + int CanSpeak(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanSpeak()); + return 1; + } + + int CanUninviteFromGroup(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanUninviteFromGroup() == ERR_PARTY_RESULT_OK); + return 1; + } + + int CanFly(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanFly()); + return 1; + } + + int IsInWater(lua_State* L, Player* player) + { + sEluna->Push(L, player->IsInWater()); + return 1; + } + + int IsMoving(lua_State* L, Player* player) // enable for unit when mangos support it + { + sEluna->Push(L, player->isMoving()); + return 1; + } + + int IsFlying(lua_State* L, Player* player) // enable for unit when mangos support it + { + sEluna->Push(L, player->IsFlying()); + return 1; + } + + int IsInGroup(lua_State* L, Player* player) + { + sEluna->Push(L, (player->GetGroup() != NULL)); + return 1; + } + + int IsInGuild(lua_State* L, Player* player) + { + sEluna->Push(L, (player->GetGuildId() != 0)); + return 1; + } + + int IsGM(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->isGameMaster()); +#else + sEluna->Push(L, player->IsGameMaster()); +#endif + return 1; + } + + int IsInArenaTeam(lua_State* L, Player* player) + { + uint32 type = sEluna->CHECKVAL(L, 2); + if (type < MAX_ARENA_SLOT && player->GetArenaTeamId(type)) + sEluna->Push(L, true); + else + sEluna->Push(L, false); + return 1; + } + + int IsHorde(lua_State* L, Player* player) + { + sEluna->Push(L, (player->GetTeam() == HORDE)); + return 1; + } + + int IsAlliance(lua_State* L, Player* player) + { + sEluna->Push(L, (player->GetTeam() == ALLIANCE)); + return 1; + } + + int IsDND(lua_State* L, Player* player) + { + sEluna->Push(L, player->isDND()); + return 1; + } + + int IsAFK(lua_State* L, Player* player) + { + sEluna->Push(L, player->isAFK()); + return 1; + } + + int IsFalling(lua_State* L, Player* player) + { + sEluna->Push(L, player->IsFalling()); + return 1; + } + + int IsActiveQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->IsActiveQuest(entry)); + return 1; + } + + int IsGroupVisibleFor(lua_State* L, Player* player) + { + Player* target = sEluna->CHECKOBJ(L, 2); + sEluna->Push(L, player->IsGroupVisibleFor(target)); + return 1; + } + + int IsInSameRaidWith(lua_State* L, Player* player) + { + Player* target = sEluna->CHECKOBJ(L, 2); + sEluna->Push(L, player->IsInSameRaidWith(target)); + return 1; + } + + int IsInSameGroupWith(lua_State* L, Player* player) + { + Player* target = sEluna->CHECKOBJ(L, 2); + sEluna->Push(L, player->IsInSameGroupWith(target)); + return 1; + } + + int IsHonorOrXPTarget(lua_State* L, Player* player) + { + Unit* victim = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, player->isHonorOrXPTarget(victim)); + return 1; + } + + int IsVisibleForPlayer(lua_State* L, Player* player) + { + Player* target = sEluna->CHECKOBJ(L, 2); + + sEluna->Push(L, player->IsVisibleGloballyFor(target)); + return 1; + } + + int IsGMVisible(lua_State* L, Player* player) + { + sEluna->Push(L, player->isGMVisible()); + return 1; + } + + int IsTaxiCheater(lua_State* L, Player* player) + { + sEluna->Push(L, player->isTaxiCheater()); + return 1; + } + + int IsGMChat(lua_State* L, Player* player) + { + sEluna->Push(L, player->isGMChat()); + return 1; + } + + int IsAcceptingWhispers(lua_State* L, Player* player) + { + sEluna->Push(L, player->isAcceptWhispers()); + return 1; + } + + int IsRested(lua_State* L, Player* player) + { + sEluna->Push(L, player->isRested()); + return 1; + } + + int InBattlegroundQueue(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->InBattleGroundQueue()); +#else + sEluna->Push(L, player->InBattlegroundQueue()); +#endif + return 1; + } + + int InArena(lua_State* L, Player* player) + { + sEluna->Push(L, player->InArena()); + return 1; + } + + int InBattleground(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->InBattleGround()); +#else + sEluna->Push(L, player->InBattleground()); +#endif + return 1; + } + + int CanBlock(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanBlock()); + return 1; + } + + int CanParry(lua_State* L, Player* player) + { + sEluna->Push(L, player->CanParry()); + return 1; + } + + /*int HasReceivedQuestReward(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->IsQuestRewarded(entry)); + return 1; + }*/ + + /*int IsOutdoorPvPActive(lua_State* L, Player* player) + { + sEluna->Push(L, player->IsOutdoorPvPActive()); + return 1; + }*/ + + /*int IsImmuneToEnvironmentalDamage(lua_State* L, Player* player) + { + sEluna->Push(L, player->IsImmuneToEnvironmentalDamage()); + return 1; + }*/ + + /*int InRandomLfgDungeon(lua_State* L, Player* player) + { + sEluna->Push(L, player->inRandomLfgDungeon()); + return 1; + }*/ + + /*int IsUsingLfg(lua_State* L, Player* player) + { + sEluna->Push(L, player->isUsingLfg()); + return 1; + }*/ + + /*int IsNeverVisible(lua_State* L, Player* player) + { + sEluna->Push(L, player->IsNeverVisible()); + return 1; + }*/ + + /*int CanFlyInZone(lua_State* L, Player* player) + { + uint32 mapid = sEluna->CHECKVAL(L, 2); + uint32 zone = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->IsKnowHowFlyIn(mapid, zone)); + return 1; + }*/ + + /*int HasPendingBind(lua_State* L, Player* player) + { + sEluna->Push(L, player->PendingHasPendingBind()); + return 1; + }*/ + + /*int IsARecruiter(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->IsARecruiter() || (player->GetSession()->GetRecruiterId() != 0)); + return 1; + }*/ + + /* GETTERS */ +#ifndef TBC + int GetSpecsCount(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSpecsCount()); + return 1; + } + + int GetActiveSpec(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetActiveSpec()); + return 1; + } +#endif + +#ifdef WOTLK + int GetPhaseMaskForSpawn(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetPhaseMaskForSpawn()); + return 1; + } +#endif + +#ifndef CATA + int GetArenaPoints(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetArenaPoints()); + return 1; + } + + int GetHonorPoints(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetHonorPoints()); + return 1; + } + + int GetShieldBlockValue(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetShieldBlockValue()); + return 1; + } +#endif + + int GetSpellCooldownDelay(lua_State* L, Player* player) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, uint32(player->GetSpellCooldownDelay(spellId))); + return 1; + } + + int GetLatency(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetLatency()); + return 1; + } + +#ifndef MANGOS + int GetChampioningFaction(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetChampioningFaction()); + return 1; + } +#endif + + int GetOriginalSubGroup(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetOriginalSubGroup()); + return 1; + } + + int GetOriginalGroup(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetOriginalGroup()); + return 1; + } + + int GetNextRandomRaidMember(lua_State* L, Player* player) + { + float radius = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetNextRandomRaidMember(radius)); + return 1; + } + + int GetSubGroup(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSubGroup()); + return 1; + } + + int GetGroupInvite(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetGroupInvite()); + return 1; + } + + int GetRestTime(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetRestTime()); + return 1; + } + + int GetXPRestBonus(lua_State* L, Player* player) + { + uint32 xp = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetXPRestBonus(xp)); + return 1; + } + + int GetBattlegroundTypeId(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->GetBattleGroundTypeId()); +#else + sEluna->Push(L, player->GetBattlegroundTypeId()); +#endif + return 1; + } + + int GetBattlegroundId(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->GetBattleGroundId()); +#else + sEluna->Push(L, player->GetBattlegroundId()); +#endif + return 1; + } + + int GetReputationRank(lua_State* L, Player* player) + { + uint32 faction = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetReputationRank(faction)); + return 1; + } + + int GetDrunkValue(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetDrunkValue()); + return 1; + } + + int GetSpellCooldowns(lua_State* L, Player* player) + { + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (SpellCooldowns::const_iterator it = player->GetSpellCooldownMap().begin(); it != player->GetSpellCooldownMap().end(); ++it) + { + ++i; + sEluna->Push(L, it->first); + sEluna->Push(L, uint32(it->second.end)); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetSkillTempBonusValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetSkillTempBonusValue(skill)); + return 1; + } + + int GetSkillPermBonusValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetSkillPermBonusValue(skill)); + return 1; + } + + int GetPureSkillValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetPureSkillValue(skill)); + return 1; + } + + int GetBaseSkillValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetBaseSkillValue(skill)); + return 1; + } + + int GetSkillValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetSkillValue(skill)); + return 1; + } + + int GetPureMaxSkillValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetPureMaxSkillValue(skill)); + return 1; + } + + int GetMaxSkillValue(lua_State* L, Player* player) + { + uint32 skill = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetMaxSkillValue(skill)); + return 1; + } + + int GetManaBonusFromIntellect(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetManaBonusFromIntellect()); + return 1; + } + + int GetHealthBonusFromStamina(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetHealthBonusFromStamina()); + return 1; + } + + int GetDifficulty(lua_State* L, Player* player) + { +#ifdef TBC + sEluna->Push(L, player->GetDifficulty()); +#else + bool isRaid = sEluna->CHECKVAL(L, 2, true); + sEluna->Push(L, player->GetDifficulty(isRaid)); +#endif + return 1; + } + + int GetGuildRank(lua_State* L, Player* player) // TODO: Move to Guild Methods + { + sEluna->Push(L, player->GetRank()); + return 1; + } + + int GetFreeTalentPoints(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetFreeTalentPoints()); + return 1; + } + + int GetGuildName(lua_State* L, Player* player) + { + if (!player->GetGuildId()) + return 0; + sEluna->Push(L, sGuildMgr->GetGuildNameById(player->GetGuildId())); + return 1; + } + + int GetReputation(lua_State* L, Player* player) + { + uint32 faction = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetReputationMgr().GetReputation(faction)); + return 1; + } + + int GetComboTarget(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->GetMap()->GetUnit(player->GetComboTargetGuid())); +#else + sEluna->Push(L, Unit::GetUnit(*player, player->GetComboTarget())); +#endif + return 1; + } + + int GetComboPoints(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetComboPoints()); + return 1; + } + + int GetInGameTime(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetInGameTime()); + return 1; + } + + int GetQuestStatus(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetQuestStatus(entry)); + return 1; + } + + int GetQuestRewardStatus(lua_State* L, Player* player) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetQuestRewardStatus(questId)); + return 1; + } + + int GetReqKillOrCastCurrentCount(lua_State* L, Player* player) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + int32 entry = sEluna->CHECKVAL(L, 3); + + sEluna->Push(L, player->GetReqKillOrCastCurrentCount(questId, entry)); + return 1; + } + + int GetQuestLevel(lua_State* L, Player* player) + { + Quest* quest = sEluna->CHECKOBJ(L, 2); + +#ifdef MANGOS + sEluna->Push(L, player->GetQuestLevelForPlayer(quest)); +#else + sEluna->Push(L, player->GetQuestLevel(quest)); +#endif + return 1; + } + + int GetItemByEntry(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, player->GetItemByEntry(entry)); + return 1; + } + + int GetEquippedItemBySlot(lua_State* L, Player* player) + { + uint8 slot = sEluna->CHECKVAL(L, 2); + if (slot >= EQUIPMENT_SLOT_END) + return 0; + + Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); + sEluna->Push(L, item); + return 1; + } + + int GetRestType(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetRestType()); + return 1; + } + + int GetRestBonus(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetRestBonus()); + return 1; + } + + int GiveLevel(lua_State* L, Player* player) + { + uint8 level = sEluna->CHECKVAL(L, 2); + + player->GiveLevel(level); + return 0; + } + + int GetChatTag(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetChatTag()); + return 1; + } + + int GetItemByPos(lua_State* L, Player* player) + { + /* + bag = -1 for inventory and backpack, 19-22 other bags + slots 0-18 equipment + slots 19-22 bags + slots 23-38 backpack + slots 0-35 other bags + */ + uint8 bag = sEluna->CHECKVAL(L, 2); + uint8 slot = sEluna->CHECKVAL(L, 3); + + sEluna->Push(L, player->GetItemByPos(bag, slot)); + return 1; + } + + int GetGossipTextId(lua_State* L, Player* player) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + sEluna->Push(L, player->GetGossipTextId(obj)); + return 1; + } + + int GetSelection(lua_State* L, Player* player) + { +#ifdef MANGOS + sEluna->Push(L, player->GetMap()->GetUnit(player->GetSelectionGuid())); +#else + sEluna->Push(L, player->GetSelectedUnit()); +#endif + return 1; + } + + int GetGMRank(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetSecurity()); + return 1; + } + + int GetCoinage(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetMoney()); + return 1; + } + + int GetGuildId(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetGuildId()); + return 1; + } + + int GetTeam(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetTeamId()); + return 1; + } + + int GetItemCount(lua_State* L, Player* player) + { + int id = sEluna->CHECKVAL(L, 2); + bool checkinBank = sEluna->CHECKVAL(L, 3, false); + sEluna->Push(L, player->GetItemCount(id, checkinBank)); + return 1; + } + + int GetLifetimeKills(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)); + return 1; + } + + int GetPlayerIP(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetRemoteAddress()); + return 1; + } + + int GetLevelPlayedTime(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetLevelPlayedTime()); + return 1; + } + + int GetTotalPlayedTime(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetTotalPlayedTime()); + return 1; + } + + int GetGuild(lua_State* L, Player* player) + { + sEluna->Push(L, sGuildMgr->GetGuildById(player->GetGuildId())); + return 1; + } + + int GetGroup(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetGroup()); + return 1; + } + + int GetAccountId(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetAccountId()); + return 1; + } + + int GetAccountName(lua_State* L, Player* player) + { + std::string accName; + if (sAccountMgr->GetName(player->GetSession()->GetAccountId(), accName)) + sEluna->Push(L, accName); + else + return 0; + return 1; + } + + int GetCorpse(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetCorpse()); + return 1; + } + + int GetDbLocaleIndex(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetSessionDbLocaleIndex()); + return 1; + } + + int GetDbcLocale(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetSessionDbcLocale()); + return 1; + } + + /*int GetRecruiterId(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSession()->GetRecruiterId()); + return 1; + }*/ + + /*int GetSelectedPlayer(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSelectedPlayer()); + return 1; + }*/ + + /*int GetSelectedUnit(lua_State* L, Player* player) + { + sEluna->Push(L, player->GetSelectedUnit()); + return 1; + }*/ + + /*int GetNearbyGameObject(lua_State* L, Player* player) + { + sEluna->Push(L, ChatHandler(player->GetSession()).GetNearbyGameObject()); + return 1; + }*/ + + /* SETTERS */ + int SetPlayerLock(lua_State* L, Player* player) + { + bool apply = sEluna->CHECKVAL(L, 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; + } + + int SetAtLoginFlag(lua_State* L, Player* player) + { + uint32 flag = sEluna->CHECKVAL(L, 2); + + player->SetAtLoginFlag((AtLoginFlags)flag); + return 0; + } + + int SetSheath(lua_State* L, Player* player) + { + uint32 sheathed = sEluna->CHECKVAL(L, 2); + if (sheathed >= MAX_SHEATH_STATE) + return 0; + + player->SetSheath((SheathState)sheathed); + return 0; + } + + int SetRestTime(lua_State* L, Player* player) + { + uint32 value = sEluna->CHECKVAL(L, 2); + + player->SetRestTime(value); + return 0; + } + + int SetDrunkValue(lua_State* L, Player* player) + { + uint8 newDrunkValue = sEluna->CHECKVAL(L, 2); + + player->SetDrunkValue(newDrunkValue); + return 0; + } + + int SetFactionForRace(lua_State* L, Player* player) + { + uint8 race = sEluna->CHECKVAL(L, 2); + + player->setFactionForRace(race); + return 0; + } + + int SetSkill(lua_State* L, Player* player) + { + uint16 id = sEluna->CHECKVAL(L, 2); + uint16 step = sEluna->CHECKVAL(L, 3); + uint16 currVal = sEluna->CHECKVAL(L, 4); + uint16 maxVal = sEluna->CHECKVAL(L, 5); + + player->SetSkill(id, step, currVal, maxVal); + return 0; + } + + int SetGuildRank(lua_State* L, Player* player) // TODO: Move to Guild Methods + { + uint8 rank = sEluna->CHECKVAL(L, 2); + + if (!player->GetGuildId()) + return 0; + + player->SetRank(rank); + return 0; + } + + int SetFreeTalentPoints(lua_State* L, Player* player) + { + uint32 points = sEluna->CHECKVAL(L, 2); + + player->SetFreeTalentPoints(points); +#ifndef TBC + player->SendTalentsInfoData(false); +#endif + return 0; + } + + int SetReputation(lua_State* L, Player* player) + { + uint32 faction = sEluna->CHECKVAL(L, 2); + int32 value = sEluna->CHECKVAL(L, 3); + + FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); + player->GetReputationMgr().SetReputation(factionEntry, value); + return 0; + } + + int SetQuestStatus(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + uint32 status = sEluna->CHECKVAL(L, 3); + if (status >= MAX_QUEST_STATUS) + return 0; + + player->SetQuestStatus(entry, (QuestStatus)status); + return 0; + } + + int SetRestType(lua_State* L, Player* player) + { + int type = sEluna->CHECKVAL(L, 2); + + player->SetRestType((RestType)type); + return 0; + } + + int SetRestBonus(lua_State* L, Player* player) + { + float bonus = sEluna->CHECKVAL(L, 2); + + player->SetRestBonus(bonus); + return 0; + } + + int SetAcceptWhispers(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetAcceptWhispers(on); + return 0; + } + + int SetPvPDeath(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetPvPDeath(on); + return 0; + } + + int SetGMVisible(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetGMVisible(on); + return 0; + } + + int SetTaxiCheat(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetTaxiCheater(on); + return 0; + } + + int SetGMChat(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetGMChat(on); + return 0; + } + + int SetGameMaster(lua_State* L, Player* player) + { + bool on = sEluna->CHECKVAL(L, 2, true); + + player->SetGameMaster(on); + return 0; + } + + int SetGender(lua_State* L, Player* player) + { + uint32 _gender = sEluna->CHECKVAL(L, 2); + + Gender gender; + switch (_gender) + { + case 0: + gender = GENDER_MALE; + break; + case 1: + gender = GENDER_FEMALE; + break; + default: + return luaL_argerror(L, 2, "valid Gender expected"); + } + + player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender); + player->SetByteValue(PLAYER_BYTES_3, 0, gender); + player->InitDisplayIds(); + return 0; + } + +#ifndef CATA + int SetArenaPoints(lua_State* L, Player* player) + { + uint32 arenaP = sEluna->CHECKVAL(L, 2); + player->SetArenaPoints(arenaP); + return 0; + } + + int SetHonorPoints(lua_State* L, Player* player) + { + uint32 honorP = sEluna->CHECKVAL(L, 2); + player->SetHonorPoints(honorP); + return 0; + } +#endif + + int SetLifetimeKills(lua_State* L, Player* player) + { + uint32 val = sEluna->CHECKVAL(L, 2); + player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, val); + return 0; + } + + int SetCoinage(lua_State* L, Player* player) + { + uint32 amt = sEluna->CHECKVAL(L, 2); + player->SetMoney(amt); + return 0; + } + + int SetBindPoint(lua_State* L, Player* player) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + float z = sEluna->CHECKVAL(L, 4); + uint32 mapId = sEluna->CHECKVAL(L, 5); + uint32 areaId = sEluna->CHECKVAL(L, 6); + + WorldLocation loc(mapId, x, y, z); +#ifdef MANGOS + player->SetHomebindToLocation(loc, areaId); +#else + player->SetHomebind(loc, areaId); +#endif + return 0; + } + + int SetKnownTitle(lua_State* L, Player* player) + { + uint32 id = sEluna->CHECKVAL(L, 2); + CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); + if (t) + player->SetTitle(t, false); + return 0; + } + +#ifdef MANGOS + int SetFFA(lua_State* L, Player* player) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + + player->SetFFAPvP(apply); + return 0; + } +#endif + + /*int SetMovement(lua_State* L, Player* player) + { + int32 pType = sEluna->CHECKVAL(L, 2); + + player->SetMovement((PlayerMovementType)pType); + return 0; + }*/ + + /* OTHER */ +#ifndef TBC + int ResetPetTalents(lua_State* L, Player* player) + { +#ifdef MANGOS + Pet* pet = player->GetPet(); + Pet::resetTalentsForAllPetsOf(player, pet); + if (pet) + player->SendTalentsInfoData(true); +#else + player->ResetPetTalents(); + player->SendTalentsInfoData(true); +#endif + return 0; + } + + int ResetAchievements(lua_State* L, Player* player) + { +#ifdef MANGOS + player->GetAchievementMgr().Reset(); +#else + player->ResetAchievements(); +#endif + return 0; + } +#endif + +#ifdef WOTLK + int SendMailMenu(lua_State* L, Player* player) + { + GameObject* object = sEluna->CHECKOBJ(L, 2); + + WorldPacket data(SMSG_SHOW_MAILBOX, 8); + data << uint64(object->GetGUIDLow()); + player->GetSession()->HandleGetMailList(data); + return 0; + } +#endif + +#ifndef CATA + int ModifyArenaPoints(lua_State* L, Player* player) + { + int32 amount = sEluna->CHECKVAL(L, 2); + + player->ModifyArenaPoints(amount); + return 0; + } + + int ModifyHonorPoints(lua_State* L, Player* player) + { + int32 amount = sEluna->CHECKVAL(L, 2); + + player->ModifyHonorPoints(amount); + return 0; + } +#endif + + int SaveToDB(lua_State* L, Player* player) + { + player->SaveToDB(); + return 0; + } + + int SummonPlayer(lua_State* L, Player* player) + { + Player* target = sEluna->CHECKOBJ(L, 2); + uint32 map = sEluna->CHECKVAL(L, 3); + float x = sEluna->CHECKVAL(L, 4); + float y = sEluna->CHECKVAL(L, 5); + float z = sEluna->CHECKVAL(L, 6); + float zoneId = sEluna->CHECKVAL(L, 7); + uint32 delay = sEluna->CHECKVAL(L, 8, 0); + if (!MapManager::IsValidMapCoord(map, x, y, z)) + return 0; + + target->SetSummonPoint(map, x, y, z); + WorldPacket data(SMSG_SUMMON_REQUEST, 8 + 4 + 4); + data << uint64(player->GetGUIDLow()); + data << uint32(zoneId); + data << uint32(delay ? delay* IN_MILLISECONDS : MAX_PLAYER_SUMMON_DELAY * IN_MILLISECONDS); + target->GetSession()->SendPacket(&data); + return 0; + } + + int Mute(lua_State* L, Player* player) + { + uint32 muteseconds = sEluna->CHECKVAL(L, 2); + /*const char* reason = luaL_checkstring(L, 2);*/ // Mangos does not have a reason field in database. + + uint64 muteTime = time(NULL) + muteseconds; + player->GetSession()->m_muteTime = muteTime; + LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'", muteTime, player->GetSession()->GetAccountId()); + return 0; + } + + int CreateCorpse(lua_State* L, Player* player) + { + player->CreateCorpse(); + return 0; + } + + int RewardQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + Quest const* quest = sObjectMgr->GetQuestTemplate(entry); + if (quest) + player->RewardQuest(quest, 0, player); + return 0; + } + + int SendAuctionMenu(lua_State* L, Player* player) + { + Unit* unit = sEluna->CHECKOBJ(L, 2); + +#ifdef MANGOS + AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit); +#else + AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction()); +#endif + if (!ahEntry) + return 0; + + WorldPacket data(MSG_AUCTION_HELLO, 12); + data << uint64(unit->GetGUIDLow()); + data << uint32(ahEntry->houseId); + data << uint8(1); + player->GetSession()->SendPacket(&data); + return 0; + } + + int SendTaxiMenu(lua_State* L, Player* player) + { + Creature* creature = sEluna->CHECKOBJ(L, 2); + + player->GetSession()->SendTaxiMenu(creature); + return 0; + } + + int SendSpiritResurrect(lua_State* L, Player* player) + { + player->GetSession()->SendSpiritResurrect(); + return 0; + } + + int SendTabardVendorActivate(lua_State* L, Player* player) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + + player->GetSession()->SendTabardVendorActivate(obj->GET_GUID()); + return 0; + } + + int SendShowBank(lua_State* L, Player* player) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + + player->GetSession()->SendShowBank(obj->GET_GUID()); + return 0; + } + + int SendListInventory(lua_State* L, Player* player) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + uint32 entry = sEluna->CHECKVAL(L, 3, 0); + + player->GetSession()->SendListInventory(obj->GET_GUID()), entry; + return 0; + } + + int SendTrainerList(lua_State* L, Player* player) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + + player->GetSession()->SendTrainerList(obj->GET_GUID()); + return 0; + } + + int SendGuildInvite(lua_State* L, Player* player) + { + Player* plr = sEluna->CHECKOBJ(L, 2); + +#ifdef MANGOS + player->GetSession()->SendGuildInvite(plr); +#else + if (Guild* guild = player->GetGuild()) + guild->HandleInviteMember(player->GetSession(), plr->GetName()); +#endif + return 0; + } + + int LogoutPlayer(lua_State* L, Player* player) + { + bool save = sEluna->CHECKVAL(L, 2, true); + + player->GetSession()->LogoutPlayer(save); + return 0; + } + + int RemoveFromBattlegroundRaid(lua_State* L, Player* player) + { +#ifdef MANGOS + player->RemoveFromBattleGroundRaid(); +#else + player->RemoveFromBattlegroundOrBattlefieldRaid(); +#endif + return 0; + } + + int UnbindInstance(lua_State* L, Player* player) + { + uint32 map = sEluna->CHECKVAL(L, 2); + uint32 difficulty = sEluna->CHECKVAL(L, 3); + + if (difficulty < MAX_DIFFICULTY) + player->UnbindInstance(map, (Difficulty)difficulty); + return 0; + } + + int LeaveBattleground(lua_State* L, Player* player) + { + bool teleToEntryPoint = sEluna->CHECKVAL(L, 2, true); + + player->LeaveBattleground(teleToEntryPoint); + return 0; + } + + int DurabilityRepair(lua_State* L, Player* player) + { + uint16 position = sEluna->CHECKVAL(L, 2); + bool cost = sEluna->CHECKVAL(L, 3, true); + float discountMod = sEluna->CHECKVAL(L, 4); + bool guildBank = sEluna->CHECKVAL(L, 5, false); + + sEluna->Push(L, player->DurabilityRepair(position, cost, discountMod, guildBank)); + return 1; + } + + int DurabilityRepairAll(lua_State* L, Player* player) + { + bool cost = sEluna->CHECKVAL(L, 2, true); + float discountMod = sEluna->CHECKVAL(L, 3); + bool guildBank = sEluna->CHECKVAL(L, 4, false); + + sEluna->Push(L, player->DurabilityRepairAll(cost, discountMod, guildBank)); + return 1; + } + + int DurabilityPointLossForEquipSlot(lua_State* L, Player* player) + { + int32 slot = sEluna->CHECKVAL(L, 2); + + if (slot >= EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END) + player->DurabilityPointLossForEquipSlot((EquipmentSlots)slot); + return 0; + } + + int DurabilityPointsLossAll(lua_State* L, Player* player) + { + int32 points = sEluna->CHECKVAL(L, 2); + bool inventory = sEluna->CHECKVAL(L, 3, true); + + player->DurabilityPointsLossAll(points, inventory); + return 0; + } + + int DurabilityPointsLoss(lua_State* L, Player* player) + { + Item* item = sEluna->CHECKOBJ(L, 2); + int32 points = sEluna->CHECKVAL(L, 3); + + player->DurabilityPointsLoss(item, points); + return 0; + } + + int DurabilityLoss(lua_State* L, Player* player) + { + Item* item = sEluna->CHECKOBJ(L, 2); + double percent = sEluna->CHECKVAL(L, 3); + + player->DurabilityLoss(item, percent); + return 0; + } + + int DurabilityLossAll(lua_State* L, Player* player) + { + double percent = sEluna->CHECKVAL(L, 2); + bool inventory = sEluna->CHECKVAL(L, 3, true); + + player->DurabilityLossAll(percent, inventory); + return 0; + } + + int KillPlayer(lua_State* L, Player* player) + { + player->KillPlayer(); + return 0; + } + + int RemoveFromGroup(lua_State* L, Player* player) + { + if (!player->GetGroup()) + return 0; + + player->RemoveFromGroup(); + return 0; + } + + int ResetTalentsCost(lua_State* L, Player* player) + { +#ifdef CATA + sEluna->Push(L, player->GetNextResetTalentsCost()); +#else + sEluna->Push(L, player->resetTalentsCost()); +#endif + return 1; + } + + int ResetTalents(lua_State* L, Player* player) + { + bool no_cost = sEluna->CHECKVAL(L, 2, true); + +#ifdef CATA + player->ResetTalents(no_cost); +#else + player->resetTalents(no_cost); +#endif +#ifndef TBC + player->SendTalentsInfoData(false); +#endif + return 0; + } + + int RemoveSpell(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + bool disabled = sEluna->CHECKVAL(L, 3, false); + bool learn_low_rank = sEluna->CHECKVAL(L, 4, true); + + player->removeSpell(entry, disabled, learn_low_rank); + return 0; + } + + int ClearComboPoints(lua_State* L, Player* player) + { + player->ClearComboPoints(); + return 0; + } + + int AddComboPoints(lua_State* L, Player* player) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + int8 count = sEluna->CHECKVAL(L, 3); + + player->AddComboPoints(target, count); + return 0; + } + + int TalkedToCreature(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + Creature* creature = sEluna->CHECKOBJ(L, 3); + + player->TalkedToCreature(entry, creature->GET_GUID()); + return 0; + } + + int KilledMonsterCredit(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->KilledMonsterCredit(entry, player->GET_GUID()); + return 0; + } + + int GroupEventHappens(lua_State* L, Player* player) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + WorldObject* obj = sEluna->CHECKOBJ(L, 3); + + player->GroupEventHappens(questId, obj); + return 0; + } + + int AreaExploredOrEventHappens(lua_State* L, Player* player) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + + player->AreaExploredOrEventHappens(questId); + return 0; + } + + int FailQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->FailQuest(entry); + return 0; + } + + int IncompleteQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->IncompleteQuest(entry); + return 0; + } + + int CompleteQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->CompleteQuest(entry); + return 0; + } + + int Whisper(lua_State* L, Player* player) + { + std::string text = sEluna->CHECKVAL(L, 2); + uint32 lang = sEluna->CHECKVAL(L, 3); + uint64 guid = sEluna->CHECKVAL(L, 4); + + player->Whisper(text, lang, GUID_TYPE(guid)); + return 0; + } + + int TextEmote(lua_State* L, Player* player) + { + std::string text = sEluna->CHECKVAL(L, 2); + + player->TextEmote(text); + return 0; + } + + int Yell(lua_State* L, Player* player) + { + std::string text = sEluna->CHECKVAL(L, 2); + uint32 lang = sEluna->CHECKVAL(L, 3); + + player->Yell(text, lang); + return 0; + } + + int Say(lua_State* L, Player* player) + { + std::string text = sEluna->CHECKVAL(L, 2); + uint32 lang = sEluna->CHECKVAL(L, 3); + + player->Say(text, lang); + return 0; + } + + int GiveXP(lua_State* L, Player* player) + { + uint32 xp = sEluna->CHECKVAL(L, 2); + Unit* victim = sEluna->CHECKOBJ(L, 3, false); + bool pureXP = sEluna->CHECKVAL(L, 4, true); + bool triggerHook = sEluna->CHECKVAL(L, 5, true); + +#ifdef MANGOS + if (xp < 1) + return 0; + + if (!player->isAlive()) + return 0; + +#ifndef TBC + if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_XP_USER_DISABLED)) + return 0; +#endif + + uint32 level = player->getLevel(); + + if (triggerHook) + sHookMgr->OnGiveXP(player, xp, victim); + + // XP to money conversion processed in Player::RewardQuest + if (level >= sWorld->getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) + return 0; + + if (!pureXP) + { + if (victim) + { + // handle SPELL_AURA_MOD_KILL_XP_PCT auras + Unit::AuraList const& ModXPPctAuras = player->GetAurasByType(SPELL_AURA_MOD_KILL_XP_PCT); + for (Unit::AuraList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) + xp = uint32(xp * (1.0f + (*i)->GetModifier()->m_amount / 100.0f)); + } +#ifndef TBC + else + { + // handle SPELL_AURA_MOD_QUEST_XP_PCT auras + Unit::AuraList const& ModXPPctAuras = player->GetAurasByType(SPELL_AURA_MOD_QUEST_XP_PCT); + for (Unit::AuraList::const_iterator i = ModXPPctAuras.begin(); i != ModXPPctAuras.end(); ++i) + xp = uint32(xp * (1.0f + (*i)->GetModifier()->m_amount / 100.0f)); + } +#endif + } + + // XP resting bonus for kill + uint32 rested_bonus_xp = victim ? player->GetXPRestBonus(xp) : 0; + + player->SendLogXPGain(xp, victim, rested_bonus_xp); + + uint32 curXP = player->GetUInt32Value(PLAYER_XP); + uint32 nextLvlXP = player->GetUInt32Value(PLAYER_NEXT_LEVEL_XP); + uint32 newXP = curXP + xp + rested_bonus_xp; + + while (newXP >= nextLvlXP && level < sWorld->getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) + { + newXP -= nextLvlXP; + + if (level < sWorld->getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) + player->GiveLevel(level + 1); + + level = player->getLevel(); + nextLvlXP = player->GetUInt32Value(PLAYER_NEXT_LEVEL_XP); + } + + player->SetUInt32Value(PLAYER_XP, newXP); +#else + if (xp < 1) + return 0; + if (player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_NO_XP_GAIN)) + return 0; + if (victim && victim->GetTypeId() == TYPEID_UNIT && !victim->ToCreature()->hasLootRecipient()) + return 0; + + uint8 level = player->getLevel(); + + if (triggerHook) + sScriptMgr->OnGivePlayerXP(player, xp, victim); + + if (!pureXP) + { + // Favored experience increase START + uint32 zone = player->GetZoneId(); + float favored_exp_mult = 0; + if ((player->HasAura(32096) || player->HasAura(32098)) && (zone == 3483 || zone == 3562 || zone == 3836 || zone == 3713 || zone == 3714)) + favored_exp_mult = 0.05f; // Thrallmar's Favor and Honor Hold's Favor + xp = uint32(xp * (1 + favored_exp_mult)); + // Favored experience increase END + } + + // XP to money conversion processed in Player::RewardQuest + if (level >= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) + return 0; + + uint32 bonus_xp = 0; + bool recruitAFriend = pureXP ? false : player->GetsRecruitAFriendBonus(true); + if (!pureXP) + { + // RaF does NOT stack with rested experience + if (recruitAFriend) + bonus_xp = 2 * xp; // xp + bonus_xp must add up to 3 * xp for RaF; calculation for quests done client-side + else + bonus_xp = victim ? player->GetXPRestBonus(xp) : 0; // XP resting bonus + } + + player->SendLogXPGain(xp, victim, bonus_xp, recruitAFriend, 1.0f); + + uint32 curXP = player->GetUInt32Value(PLAYER_XP); + uint32 nextLvlXP = player->GetUInt32Value(PLAYER_NEXT_LEVEL_XP); + uint32 newXP = curXP + xp + bonus_xp; + + while (newXP >= nextLvlXP && level < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) + { + newXP -= nextLvlXP; + + if (level < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) + player->GiveLevel(level + 1); + + level = player->getLevel(); + nextLvlXP = player->GetUInt32Value(PLAYER_NEXT_LEVEL_XP); + } + + player->SetUInt32Value(PLAYER_XP, newXP); +#endif + return 0; + } + + int ToggleDND(lua_State* L, Player* player) + { + player->ToggleDND(); + return 0; + } + + int ToggleAFK(lua_State* L, Player* player) + { + player->ToggleAFK(); + return 0; + } + + int EquipItem(lua_State* L, Player* player) + { + uint16 dest = 0; + Item* item = sEluna->CHECKOBJ(L, 2, false); + uint32 slot = sEluna->CHECKVAL(L, 3); + + if (slot >= INVENTORY_SLOT_BAG_END) + return 0; + + if (!item) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + item = Item::CreateItem(entry, 1, player); + if (!item) + return 0; + + InventoryResult result = player->CanEquipItem(slot, dest, item, false); + if (result != EQUIP_ERR_OK) + { + delete item; + return 0; + } + player->ItemAddedQuestCheck(entry, 1); +#ifndef TBC + 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 0; + player->RemoveItem(item->GetBagSlot(), item->GetSlot(), true); + } + + sEluna->Push(L, player->EquipItem(dest, item, true)); + return 1; + } + + int CanEquipItem(lua_State* L, Player* player) + { + Item* item = sEluna->CHECKOBJ(L, 2, false); + uint32 slot = sEluna->CHECKVAL(L, 3); + if (slot >= EQUIPMENT_SLOT_END) + { + sEluna->Push(L, false); + return 1; + } + + if (!item) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + uint16 dest; + InventoryResult msg = player->CanEquipNewItem(slot, dest, entry, false); + if (msg != EQUIP_ERR_OK) + { + sEluna->Push(L, false); + return 1; + } + } + else + { + uint16 dest; + InventoryResult msg = player->CanEquipItem(slot, dest, item, false); + if (msg != EQUIP_ERR_OK) + { + sEluna->Push(L, false); + return 1; + } + } + sEluna->Push(L, true); + return 1; + } + + int UnsetKnownTitle(lua_State* L, Player* player) + { + uint32 id = sEluna->CHECKVAL(L, 2); + CharTitlesEntry const* t = sCharTitlesStore.LookupEntry(id); + if (t) + player->SetTitle(t, true); + return 0; + } + + int AdvanceSkillsToMax(lua_State* L, Player* player) + { + player->UpdateSkillsToMaxSkillsForLevel(); + return 0; + } + + int AdvanceAllSkills(lua_State* L, Player* player) + { + uint32 step = sEluna->CHECKVAL(L, 2); + + if (!step) + return 0; + + static const uint32 skillsArray[] = { SKILL_BOWS, SKILL_CROSSBOWS, SKILL_DAGGERS, SKILL_DEFENSE, SKILL_UNARMED, SKILL_GUNS, SKILL_AXES, SKILL_MACES, SKILL_SWORDS, SKILL_POLEARMS, + SKILL_STAVES, SKILL_2H_AXES, SKILL_2H_MACES, SKILL_2H_SWORDS, SKILL_WANDS, SKILL_SHIELD, SKILL_FISHING, SKILL_MINING, SKILL_ENCHANTING, SKILL_BLACKSMITHING, + SKILL_ALCHEMY, SKILL_HERBALISM, SKILL_ENGINEERING, SKILL_JEWELCRAFTING, SKILL_LEATHERWORKING, SKILL_LOCKPICKING, SKILL_SKINNING, SKILL_TAILORING, +#ifndef TBC + SKILL_INSCRIPTION +#endif + }; + static const uint32 skillsSize = sizeof(skillsArray) / sizeof(*skillsArray); + + for (int i = 0; i < skillsSize; ++i) + { + if (player->HasSkill(skillsArray[i])) + player->UpdateSkill(skillsArray[i], step); + } + return 0; + } + + int AdvanceSkill(lua_State* L, Player* player) + { + uint32 _skillId = sEluna->CHECKVAL(L, 2); + uint32 _step = sEluna->CHECKVAL(L, 3); + if (_skillId && _step) + { + if (player->HasSkill(_skillId)) + player->UpdateSkill(_skillId, _step); + } + return 0; + } + + int Teleport(lua_State* L, Player* player) + { + uint32 mapId = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + float o = sEluna->CHECKVAL(L, 6); +#ifdef MANGOS + if (player->IsTaxiFlying()) +#else + if (player->IsInFlight()) +#endif + { + player->GetMotionMaster()->MovementExpired(); + player->m_taxi.ClearTaxiDestinations(); + } + sEluna->Push(L, player->TeleportTo(mapId, x, y, z, o)); + return 1; + } + + int AddLifetimeKills(lua_State* L, Player* player) + { + uint32 val = sEluna->CHECKVAL(L, 2); + uint32 currentKills = player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS); + player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS, currentKills + val); + return 0; + } + + int AddItem(lua_State* L, Player* player) + { + uint32 itemId = sEluna->CHECKVAL(L, 2); + uint32 itemCount = sEluna->CHECKVAL(L, 3); +#ifdef MANGOS + sEluna->Push(L, player->StoreNewItemInInventorySlot(itemId, itemCount) ? true : false); +#else + sEluna->Push(L, player->AddItem(itemId, itemCount)); +#endif + return 1; + } + + int RemoveItem(lua_State* L, Player* player) + { + Item* item = sEluna->CHECKOBJ(L, 2, false); + uint32 itemCount = sEluna->CHECKVAL(L, 3); + if (!item) + { + uint32 itemId = sEluna->CHECKVAL(L, 2); + player->DestroyItemCount(itemId, itemCount, true); + } + else + player->DestroyItemCount(item, itemCount, true); + return 0; + } + + int RemoveLifetimeKills(lua_State* L, Player* player) + { + uint32 val = sEluna->CHECKVAL(L, 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; + } + + int ResetSpellCooldown(lua_State* L, Player* player) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + bool update = sEluna->CHECKVAL(L, 3, true); + player->RemoveSpellCooldown(spellId, update); + return 0; + } + + int ResetTypeCooldowns(lua_State* L, Player* player) + { + uint32 category = sEluna->CHECKVAL(L, 2); + bool update = sEluna->CHECKVAL(L, 3, true); + player->RemoveSpellCategoryCooldown(category, update); + return 0; + } + + int ResetAllCooldowns(lua_State* L, Player* player) + { + player->RemoveAllSpellCooldown(); + return 0; + } + + int SendClearCooldowns(lua_State* L, Player* player) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + Unit* target = sEluna->CHECKOBJ(L, 3); + + player->SendClearCooldown(spellId, target); + return 0; + } + + int SendBroadcastMessage(lua_State* L, Player* player) + { + const char* message = sEluna->CHECKVAL(L, 2); + if (std::string(message).length() > 0) + ChatHandler(player->GetSession()).SendSysMessage(message); + return 0; + } + + int SendAreaTriggerMessage(lua_State* L, Player* player) + { + const char* msg = sEluna->CHECKVAL(L, 2); + if (std::string(msg).length() > 0) + player->GetSession()->SendAreaTriggerMessage(msg); + return 0; + } + + int SendNotification(lua_State* L, Player* player) + { + const char* msg = sEluna->CHECKVAL(L, 2); + if (std::string(msg).length() > 0) + player->GetSession()->SendNotification(msg); + return 0; + } + + int SendPacketToPlayer(lua_State* L, Player* player) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + player->GetSession()->SendPacket(data); + return 0; + } + + int SendPacket(lua_State* L, Player* player) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + bool selfOnly = sEluna->CHECKVAL(L, 3, true); + if (selfOnly) + player->GetSession()->SendPacket(data); + else + player->SendMessageToSet(data, true); + return 0; + } + + int SendVendorWindow(lua_State* L, Player* player) + { + Unit* sendTo = sEluna->CHECKOBJ(L, 2); + player->GetSession()->SendListInventory(sendTo->GET_GUID()); + return 0; + } + + int KickPlayer(lua_State* L, Player* player) + { + player->GetSession()->KickPlayer(); + return 0; + } + + int ModifyMoney(lua_State* L, Player* player) + { + int32 amt = sEluna->CHECKVAL(L, 2); + + player->ModifyMoney(amt); + return 1; + } + + int LearnSpell(lua_State* L, Player* player) + { + uint32 id = sEluna->CHECKVAL(L, 2); + player->learnSpell(id, false); + return 0; + } + + int ResurrectPlayer(lua_State* L, Player* player) + { + float percent = sEluna->CHECKVAL(L, 2, 100.0f); + bool sickness = sEluna->CHECKVAL(L, 3, false); + player->ResurrectPlayer(percent, sickness); + player->SpawnCorpseBones(); + return 0; + } + + int GossipMenuAddItem(lua_State* L, Player* player) + { + uint32 _icon = sEluna->CHECKVAL(L, 2); + const char* msg = sEluna->CHECKVAL(L, 3); + uint32 _sender = sEluna->CHECKVAL(L, 4); + uint32 _intid = sEluna->CHECKVAL(L, 5); + bool _code = sEluna->CHECKVAL(L, 6, false); + const char* _promptMsg = sEluna->CHECKVAL(L, 7, ""); + uint32 _money = sEluna->CHECKVAL(L, 8, 0); +#ifdef MANGOS + player->PlayerTalkClass->GetGossipMenu().AddMenuItem(_icon, msg, _sender, _intid, _promptMsg, _money, _code); +#else + player->PlayerTalkClass->GetGossipMenu().AddMenuItem(-1, _icon, msg, _sender, _intid, _promptMsg, _money, _code); +#endif + return 0; + } + + int GossipComplete(lua_State* L, Player* player) + { +#ifdef MANGOS + player->PlayerTalkClass->CloseGossip(); +#else + player->PlayerTalkClass->SendCloseGossip(); +#endif + return 0; + } + + int GossipSendMenu(lua_State* L, Player* player) + { + uint32 _npcText = sEluna->CHECKVAL(L, 2); + WorldObject* sender = sEluna->CHECKOBJ(L, 3); + if (sender->GetTypeId() == TYPEID_PLAYER) + { + uint32 menu_id = sEluna->CHECKVAL(L, 4); + player->PlayerTalkClass->GetGossipMenu().SetMenuId(menu_id); + } + player->PlayerTalkClass->SendGossipMenu(_npcText, sender->GET_GUID()); + return 0; + } + + int GossipClearMenu(lua_State* L, Player* player) + { + player->PlayerTalkClass->ClearMenus(); + return 0; + } + + int PlaySoundToPlayer(lua_State* L, Player* player) + { + uint32 soundId = sEluna->CHECKVAL(L, 2); + SoundEntriesEntry const* soundEntry = sSoundEntriesStore.LookupEntry(soundId); + if (!soundEntry) + return 0; + + player->PlayDirectSound(soundId, player); + return 0; + } + + int StartTaxi(lua_State* L, Player* player) + { + uint32 pathId = sEluna->CHECKVAL(L, 2); + + LuaTaxiMgr::StartTaxi(player, pathId); + return 0; + } + + int GossipSendPOI(lua_State* L, Player* player) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + uint32 icon = sEluna->CHECKVAL(L, 4); + uint32 flags = sEluna->CHECKVAL(L, 5); + uint32 data = sEluna->CHECKVAL(L, 6); + std::string iconText = sEluna->CHECKVAL(L, 6); + + 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; + } + + int GossipAddQuests(lua_State* L, Player* player) + { + WorldObject* source = sEluna->CHECKOBJ(L, 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; + } + + int SendQuestTemplate(lua_State* L, Player* player) + { + uint32 questId = sEluna->CHECKVAL(L, 2); + bool activeAccept = sEluna->CHECKVAL(L, 3, true); + + Quest const* quest = sObjectMgr->GetQuestTemplate(questId); + if (!quest) + return 0; + + player->PlayerTalkClass->SendQuestGiverQuestDetails(quest, player->GET_GUID(), activeAccept); + return 0; + } + + int SpawnBones(lua_State* L, Player* player) + { + player->SpawnCorpseBones(); + return 0; + } + + int RemovedInsignia(lua_State* L, Player* player) + { + Player* looter = sEluna->CHECKOBJ(L, 2); + player->RemovedInsignia(looter); + return 0; + } + + /*int BindToInstance(lua_State* L, Player* player) + { + player->BindToInstance(); + return 0; + }*/ + + /*int AddTalent(lua_State* L, Player* player) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + uint8 spec = sEluna->CHECKVAL(L, 3); + bool learning = sEluna->CHECKVAL(L, 4, true); + if (spec >= MAX_TALENT_SPECS) + sEluna->Push(L, false); + else + sEluna->Push(L, player->AddTalent(spellId, spec, learning)); + return 1; + }*/ + + /*int GainSpellComboPoints(lua_State* L, Player* player) + { + int8 count = sEluna->CHECKVAL(L, 2); + + player->GainSpellComboPoints(count); + return 0; + }*/ + + /*int KillGOCredit(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + uint64 guid = sEluna->CHECKVAL(L, 3); + player->KillCreditGO(entry, guid); + return 0; + }*/ + + /*int KilledPlayerCredit(lua_State* L, Player* player) + { + player->KilledPlayerCredit(); + return 0; + }*/ + + /*int RemoveRewardedQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->RemoveRewardedQuest(entry); + return 0; + }*/ + + /*int RemoveActiveQuest(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + + player->RemoveActiveQuest(entry); + return 0; + }*/ + + /*int SummonPet(lua_State* L, Player* player) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + float o = sEluna->CHECKVAL(L, 6); + uint32 petType = sEluna->CHECKVAL(L, 7); + uint32 despwtime = sEluna->CHECKVAL(L, 8); + + if (petType >= MAX_PET_TYPE) + return 0; + + player->SummonPet(entry, x, y, z, o, (PetType)petType, despwtime); + return 0; + }*/ + + /*int RemovePet(lua_State* L, Player* player) + { + int mode = sEluna->CHECKVAL(L, 2, PET_SAVE_AS_DELETED); + bool returnreagent = sEluna->CHECKVAL(L, 2, false); + + if (!player->GetPet()) + return 0; + + player->RemovePet(player->GetPet(), (PetSaveMode)mode, returnreagent); + return 0; + }*/ +}; +#endif diff --git a/QueryMethods.h b/QueryMethods.h new file mode 100644 index 0000000..cb7d1c9 --- /dev/null +++ b/QueryMethods.h @@ -0,0 +1,188 @@ +/* +* Copyright (C) 2010 - 2014 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 + +#ifdef MANGOS +#define RESULT result +#else +#define RESULT (*result) +#endif +namespace LuaQuery +{ + /* BOOLEAN */ + int IsNull(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, true); + else +#ifdef MANGOS + sEluna->Push(L, RESULT->Fetch()[col].IsNULL()); +#else + sEluna->Push(L, RESULT->Fetch()[col].IsNull()); +#endif + return 1; + } + + /* GETTERS */ + int GetColumnCount(lua_State* L, QueryResult* result) + { + if (!result) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->GetFieldCount()); + return 1; + } + + int GetRowCount(lua_State* L, QueryResult* result) + { + if (!result) + sEluna->Push(L, 0); + else + { + if (RESULT->GetRowCount() > (uint32)-1) + sEluna->Push(L, (uint32)-1); + else + sEluna->Push(L, RESULT->GetRowCount()); + } + return 1; + } + + int GetBool(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, false); + else + sEluna->Push(L, RESULT->Fetch()[col].GetBool()); + return 1; + } + + int GetUInt8(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetUInt8()); + return 1; + } + + int GetUInt16(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetUInt16()); + return 1; + } + + int GetUInt32(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetUInt32()); + return 1; + } + + int GetUInt64(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetUInt64()); + return 1; + } + + int GetInt8(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetInt8()); + return 1; + } + + int GetInt16(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetInt16()); + return 1; + } + + int GetInt32(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetInt32()); + return 1; + } + + int GetInt64(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetInt64()); + return 1; + } + + int GetFloat(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0.0f); + else + sEluna->Push(L, RESULT->Fetch()[col].GetFloat()); + return 1; + } + + int GetDouble(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, 0.0); + else + sEluna->Push(L, RESULT->Fetch()[col].GetDouble()); + return 1; + } + + int GetString(lua_State* L, QueryResult* result) + { + uint32 col = sEluna->CHECKVAL(L, 2); + if (!result || col >= RESULT->GetFieldCount()) + sEluna->Push(L, ""); + else + sEluna->Push(L, RESULT->Fetch()[col].GetString()); + return 1; + } + + /* OTHER */ + int NextRow(lua_State* L, QueryResult* result) + { + if (!result) + sEluna->Push(L, false); + else + sEluna->Push(L, RESULT->NextRow()); + return 1; + } +}; +#undef RESULT + +#endif diff --git a/QuestMethods.h b/QuestMethods.h new file mode 100644 index 0000000..9fd7bb1 --- /dev/null +++ b/QuestMethods.h @@ -0,0 +1,103 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaQuest +{ + /* BOOLEAN */ + int HasFlag(lua_State* L, Quest* quest) + { + uint32 flag = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, quest->HasQuestFlag((QuestFlags)flag)); +#else + sEluna->Push(L, quest->HasFlag(flag)); +#endif + return 1; + } + + int IsDaily(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->IsDaily()); + return 1; + } + + int IsRepeatable(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->IsRepeatable()); + return 1; + } + + /* GETTERS */ + int GetId(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetQuestId()); + return 1; + } + + int GetLevel(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetQuestLevel()); + return 1; + } + + int GetMinLevel(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetMinLevel()); + return 1; + } + + int GetNextQuestId(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetNextQuestId()); + return 1; + } + + int GetPrevQuestId(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetPrevQuestId()); + return 1; + } + + int GetNextQuestInChain(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetNextQuestInChain()); + return 1; + } + + int GetFlags(lua_State* L, Quest* quest) + { +#ifdef MANGOS + sEluna->Push(L, quest->GetQuestFlags()); +#else + sEluna->Push(L, quest->GetFlags()); +#endif + return 1; + } + + int GetType(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetType()); + return 1; + } + + /*int GetMaxLevel(lua_State* L, Quest* quest) + { + sEluna->Push(L, quest->GetMaxLevel()); + return 1; + }*/ + + /* SETTERS */ + int SetFlag(lua_State* L, Quest* quest) + { + uint32 flag = sEluna->CHECKVAL(L, 2); + quest->SetSpecialFlag((QuestSpecialFlags)flag); + return 0; + } +}; +#endif diff --git a/README.md b/README.md new file mode 100644 index 0000000..81fee9d --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +![logo](https://dl.dropbox.com/u/98478761/eluna-DBCA-Designs.png) + +## About + +Eluna is a Lua Engine for World of Warcraft emulators. Eluna is supporting MaNGOS and TrinityCore. +We want to be the major Lua source for World of Warcraft emulation.
+Follow us on our [Twitter](https://twitter.com/EmuDevs) page to view the latest news about EmuDevs and what's going on with Eluna. + +If you're having trouble, post in Eluna's support here: [Eluna Support Forum](http://emudevs.com/forumdisplay.php/84-Support)
+If you need help regarding methods, hooks and other wiki related documentation, go to [Eluna's Wiki](http://wiki.emudevs.com/doku.php?id=eluna). + +## Source + +[![Build Status](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Wotlk.png?branch=master)](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Wotlk) [Eluna TrinityCore WOTLK](https://github.com/ElunaLuaEngine/Eluna-TC-Wotlk)
+[![Build Status](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Cata.png?branch=master)](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Cata) [Eluna TrinityCore Cataclysm](https://github.com/ElunaLuaEngine/Eluna-TC-Cata) + +[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreClassic.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreClassic) [Eluna cMaNGOS Classic](https://github.com/eluna-dev-mangos/ElunaCoreClassic)
+[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreTbc.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreTbc) [Eluna cMaNGOS TBC](https://github.com/eluna-dev-mangos/ElunaCoreTbc)
+[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreWotlk.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreWotlk) [Eluna cMaNGOS WotLK](https://github.com/eluna-dev-mangos/ElunaCoreWotlk) + +## Links + +* [Installation & Updating](/docs/INSTALL.md) +* [Eluna Wiki](http://wiki.emudevs.com/doku.php?id=eluna) +* [Eluna Scripts](https://github.com/ElunaLuaEngine/Scripts) +* [Eluna Support Forum](http://emudevs.com) +* [cMaNGOS](http://cmangos.net/) +* [TrinityCore](http://www.trinitycore.org/) +* [License](/docs/LICENSE.md) + +## Team + +* Tommy (Easelm) +* Foereaper +* Rochet2 +* Salja diff --git a/SpellMethods.h b/SpellMethods.h new file mode 100644 index 0000000..7351ec0 --- /dev/null +++ b/SpellMethods.h @@ -0,0 +1,131 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaSpell +{ + /* BOOLEAN */ + int IsAutoRepeat(lua_State* L, Spell* spell) + { + sEluna->Push(L, spell->IsAutoRepeat()); + return 1; + } + + /* GETTERS */ + int GetCaster(lua_State* L, Spell* spell) + { + sEluna->Push(L, spell->GetCaster()); + return 1; + } + + int GetCastTime(lua_State* L, Spell* spell) + { + sEluna->Push(L, spell->GetCastTime()); + return 1; + } + + int GetId(lua_State* L, Spell* spell) + { + sEluna->Push(L, spell->m_spellInfo->Id); + return 1; + } + + int GetPowerCost(lua_State* L, Spell* spell) + { + sEluna->Push(L, spell->GetPowerCost()); + return 1; + } + + int GetDuration(lua_State* L, Spell* spell) + { +#ifdef MANGOS + sEluna->Push(L, GetSpellDuration(spell->m_spellInfo)); +#else + sEluna->Push(L, spell->GetSpellInfo()->GetDuration()); +#endif + return 1; + } + + int GetTargetDest(lua_State* L, Spell* spell) + { +#ifdef MANGOS + if (!(spell->m_targets.m_targetMask & TARGET_FLAG_DEST_LOCATION)) + return 0; + float x, y, z; + spell->m_targets.getDestination(x, y, z); +#else + if (!spell->m_targets.HasDst()) + return 0; + float x, y, z; + spell->m_targets.GetDstPos()->GetPosition(x, y, z); +#endif + sEluna->Push(L, x); + sEluna->Push(L, y); + sEluna->Push(L, z); + return 3; + } + + int GetTarget(lua_State* L, Spell* spell) + { +#ifdef MANGOS + if (GameObject* target = spell->m_targets.getGOTarget()) + sEluna->Push(sEluna->L, target); + else if (Item* target = spell->m_targets.getItemTarget()) + sEluna->Push(sEluna->L, target); + else if (Corpse* target = spell->GetCaster()->GetMap()->GetCorpse(spell->m_targets.getCorpseTargetGuid())) + sEluna->Push(sEluna->L, target); + else if (Unit* target = spell->m_targets.getUnitTarget()) + sEluna->Push(sEluna->L, target); + else + sEluna->Push(sEluna->L); +#else + if (GameObject* target = spell->m_targets.GetGOTarget()) + sEluna->Push(L, target); + else if (Item* target = spell->m_targets.GetItemTarget()) + sEluna->Push(L, target); + else if (Corpse* target = spell->m_targets.GetCorpseTarget()) + sEluna->Push(L, target); + else if (Unit* target = spell->m_targets.GetUnitTarget()) + sEluna->Push(L, target); + else if (WorldObject* target = spell->m_targets.GetObjectTarget()) + sEluna->Push(L, target); + else + sEluna->Push(L); +#endif + return 1; + } + + /* SETTERS */ + int SetAutoRepeat(lua_State* L, Spell* spell) + { + bool repeat = sEluna->CHECKVAL(L, 2); + spell->SetAutoRepeat(repeat); + return 0; + } + + /* OTHER */ + int Cast(lua_State* L, Spell* spell) + { + bool skipCheck = sEluna->CHECKVAL(L, 2); + spell->cast(skipCheck); + return 0; + } + + int cancel(lua_State* L, Spell* spell) + { + spell->cancel(); + return 0; + } + + int Finish(lua_State* L, Spell* spell) + { + spell->finish(); + return 0; + } +}; +#endif diff --git a/UnitMethods.h b/UnitMethods.h new file mode 100644 index 0000000..445b496 --- /dev/null +++ b/UnitMethods.h @@ -0,0 +1,1710 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaUnit +{ + /* BOOLEAN */ + int Attack(lua_State* L, Unit* unit) + { + Unit* who = sEluna->CHECKOBJ(L, 2); + bool meleeAttack = sEluna->CHECKVAL(L, 3, false); + + sEluna->Push(L, unit->Attack(who, meleeAttack)); + return 1; + } + + int AttackStop(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->AttackStop()); + return 1; + } + + int IsStandState(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsStandState()); + return 1; + } + + int IsMounted(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsMounted()); + return 1; + } + + int IsWithinLoS(lua_State* L, Unit* unit) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + float z = sEluna->CHECKVAL(L, 4); + + sEluna->Push(L, unit->IsWithinLOS(x, y, z)); + return 1; + } + + int IsRooted(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isInRoots() || unit->IsRooted()); +#else + sEluna->Push(L, unit->isInRoots() || unit->HasUnitMovementFlag(MOVEMENTFLAG_ROOT)); +#endif + return 1; + } + + int IsFullHealth(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsFullHealth()); + return 1; + } + + int IsWithinDistInMap(lua_State* L, Unit* unit) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + float radius = sEluna->CHECKVAL(L, 3); + + sEluna->Push(L, unit->IsWithinDistInMap(obj, radius)); + return 1; + } + + int IsInAccessiblePlaceFor(lua_State* L, Unit* unit) + { + Creature* creature = sEluna->CHECKOBJ(L, 2); + +#ifdef MANGOS + sEluna->Push(L, unit->isInAccessablePlaceFor(creature)); +#else + sEluna->Push(L, unit->isInAccessiblePlaceFor(creature)); +#endif + return 1; + } + + int IsAuctioneer(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isAuctioner()); +#else + sEluna->Push(L, unit->IsAuctioner()); +#endif + return 1; + } + + int IsGuildMaster(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isGuildMaster()); +#else + sEluna->Push(L, unit->IsGuildMaster()); +#endif + return 1; + } + + int IsInnkeeper(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isInnkeeper()); +#else + sEluna->Push(L, unit->IsInnkeeper()); +#endif + return 1; + } + + int IsTrainer(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isTrainer()); +#else + sEluna->Push(L, unit->IsTrainer()); +#endif + return 1; + } + + int IsGossip(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isGossip()); +#else + sEluna->Push(L, unit->IsGossip()); +#endif + return 1; + } + + int IsTaxi(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isTaxi()); +#else + sEluna->Push(L, unit->IsTaxi()); +#endif + return 1; + } + + int IsSpiritHealer(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isSpiritHealer()); +#else + sEluna->Push(L, unit->IsSpiritHealer()); +#endif + return 1; + } + + int IsSpiritGuide(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isSpiritGuide()); +#else + sEluna->Push(L, unit->IsSpiritGuide()); +#endif + return 1; + } + + int IsTabardDesigner(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isTabardDesigner()); +#else + sEluna->Push(L, unit->IsTabardDesigner()); +#endif + return 1; + } + + int IsServiceProvider(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isServiceProvider()); +#else + sEluna->Push(L, unit->IsServiceProvider()); +#endif + return 1; + } + + int IsSpiritService(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isSpiritService()); +#else + sEluna->Push(L, unit->IsSpiritService()); +#endif + return 1; + } + + int IsAlive(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isAlive()); +#else + sEluna->Push(L, unit->IsAlive()); +#endif + return 1; + } + + int IsDead(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->isDead()); + return 1; + } + + int IsDying(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->isDying()); + return 1; + } + + int IsBanker(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isBanker()); +#else + sEluna->Push(L, unit->IsBanker()); +#endif + return 1; + } + + int IsVendor(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isVendor()); +#else + sEluna->Push(L, unit->IsVendor()); +#endif + return 1; + } + + int IsBattleMaster(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isBattleMaster()); +#else + sEluna->Push(L, unit->IsBattleMaster()); +#endif + return 1; + } + + int IsCharmed(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isCharmed()); +#else + sEluna->Push(L, unit->IsCharmed()); +#endif + return 1; + } + + int IsArmorer(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isArmorer()); +#else + sEluna->Push(L, unit->IsArmorer()); +#endif + return 1; + } + + int IsAttackingPlayer(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->isAttackingPlayer()); + return 1; + } + + int IsInWorld(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsInWorld()); + return 1; + } + + int IsPvPFlagged(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsPvP()); + return 1; + } + + int IsOnVehicle(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->IsBoarded()); +#else + sEluna->Push(L, unit->GetVehicle()); +#endif + return 1; + } + + int IsInCombat(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isInCombat()); +#else + sEluna->Push(L, unit->IsInCombat()); +#endif + return 1; + } + + int IsUnderWater(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsUnderWater()); + return 1; + } + + int IsInWater(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsInWater()); + return 1; + } + + int IsStopped(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsStopped()); + return 1; + } + + int IsQuestGiver(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->isQuestGiver()); +#else + sEluna->Push(L, unit->IsQuestGiver()); +#endif + return 1; + } + + int HealthBelowPct(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->HealthBelowPct(sEluna->CHECKVAL(L, 2))); + return 1; + } + + int HealthAbovePct(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->HealthAbovePct(sEluna->CHECKVAL(L, 2))); + return 1; + } + + int HasAura(lua_State* L, Unit* unit) + { + uint32 spell = sEluna->CHECKVAL(L, 2); + + sEluna->Push(L, unit->HasAura(spell)); + return 1; + } + + int HasUnitState(lua_State* L, Unit* unit) + { + uint32 state = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, unit->hasUnitState(state)); +#else + sEluna->Push(L, unit->HasUnitState(state)); +#endif + return 1; + } + + /*int IsVisible(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsVisible()); + return 1; + }*/ + + /*int IsMoving(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->isMoving()); + return 1; + }*/ + + /*int IsFlying(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->IsFlying()); + return 1; + }*/ + + /* GETTERS */ + int GetOwner(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetOwner()); + return 1; + } + + int GetOwnerGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetOwnerGuid()); +#else + sEluna->Push(L, unit->GetOwnerGUID()); +#endif + return 1; + } + + int GetMap(lua_State* L, Unit* unit) + { + Map* map = unit->GetMap(); + sEluna->Push(L, map); + return 1; + } + + int GetMountId(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetMountID()); + return 1; + } + + int GetDistance(lua_State* L, Unit* unit) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2, false); + if (obj && obj->IsInWorld()) + sEluna->Push(L, unit->GetDistance(obj)); + else + { + float X = sEluna->CHECKVAL(L, 2); + float Y = sEluna->CHECKVAL(L, 3); + float Z = sEluna->CHECKVAL(L, 4); + sEluna->Push(L, unit->GetDistance(X, Y, Z)); + } + return 1; + } + + int GetCreatorGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCreatorGuid()); +#else + sEluna->Push(L, unit->GetCreatorGUID()); +#endif + return 1; + } + + int GetMinionGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetPetGuid()); +#else + sEluna->Push(L, unit->GetPetGUID()); +#endif + return 1; + } + + int GetCharmerGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCharmerGuid()); +#else + sEluna->Push(L, unit->GetCharmerGUID()); +#endif + return 1; + } + + int GetCharmGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCharmGuid()); +#else + sEluna->Push(L, unit->GetCharmGUID()); +#endif + return 1; + } + + int GetPetGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetPetGuid()); +#else + sEluna->Push(L, unit->GetPetGUID()); +#endif + return 1; + } + + int GetControllerGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCharmerOrOwnerGuid()); +#else + sEluna->Push(L, unit->GetCharmerOrOwnerGUID()); +#endif + return 1; + } + + int GetControllerGUIDS(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCharmerOrOwnerOrOwnGuid()); +#else + sEluna->Push(L, unit->GetCharmerOrOwnerOrOwnGUID()); +#endif + return 1; + } + + int GetStat(lua_State* L, Unit* unit) + { + uint32 stat = sEluna->CHECKVAL(L, 2); + + if (stat >= MAX_STATS) + return 0; + + sEluna->Push(L, unit->GetStat((Stats)stat)); + return 1; + } + + int GetBaseSpellPower(lua_State* L, Unit* unit) + { + uint32 spellschool = sEluna->CHECKVAL(L, 2); + + if (spellschool >= MAX_SPELL_SCHOOL) + return 0; + + sEluna->Push(L, unit->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + spellschool)); + return 1; + } + + int GetVictim(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->getVictim()); +#else + sEluna->Push(L, unit->GetVictim()); +#endif + return 1; + } + + int GetCurrentSpell(lua_State* L, Unit* unit) + { + uint32 type = sEluna->CHECKVAL(L, 2); + if (type >= CURRENT_MAX_SPELL) + return luaL_argerror(L, 2, "valid CurrentSpellTypes expected"); + sEluna->Push(L, unit->GetCurrentSpell(type)); + return 1; + } + + int GetStandState(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getStandState()); + return 0; + } + + int GetDisplayId(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetDisplayId()); + return 1; + } + + int GetNativeDisplayId(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetNativeDisplayId()); + return 1; + } + + int GetLevel(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getLevel()); + return 1; + } + + int GetHealth(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetHealth()); + return 1; + } + + int GetPower(lua_State* L, Unit* unit) + { + int type = sEluna->CHECKVAL(L, 2, -1); + if (type == -1) + { + + switch (unit->getClass()) + { + case 1: + type = POWER_RAGE; + break; + case 4: + type = POWER_ENERGY; + break; +#ifndef TBC + case 6: + type = POWER_RUNIC_POWER; + break; +#endif + case 2: + case 3: + case 5: + case 7: + case 8: + case 9: + case 11: + type = POWER_MANA; + break; + default: + type = POWER_MANA; + } + } + else if (type < 0 || type >= POWER_ALL) + return luaL_argerror(L, 2, "valid Powers expected"); + + sEluna->Push(L, unit->GetPower((Powers)type)); + return 1; + } + + int GetMaxPower(lua_State* L, Unit* unit) + { + int type = sEluna->CHECKVAL(L, 2, -1); + if (type == -1) + { + + switch (unit->getClass()) + { + case 1: + type = POWER_RAGE; + break; + case 4: + type = POWER_ENERGY; + break; +#ifndef TBC + case 6: + type = POWER_RUNIC_POWER; + break; +#endif + case 2: + case 3: + case 5: + case 7: + case 8: + case 9: + case 11: + type = POWER_MANA; + break; + default: + type = POWER_MANA; + } + } + else if (type < 0 || type >= POWER_ALL) + return luaL_argerror(L, 2, "valid Powers expected"); + + sEluna->Push(L, unit->GetMaxPower((Powers)type)); + return 1; + } + + int GetPowerType(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getPowerType()); + return 1; + } + + int GetMaxHealth(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetMaxHealth()); + return 1; + } + + int GetHealthPct(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetHealthPercent()); +#else + sEluna->Push(L, unit->GetHealthPct()); +#endif + return 1; + } + + int GetPowerPct(lua_State* L, Unit* unit) + { + float percent = (unit->GetPower(unit->getPowerType()) / unit->GetMaxPower(unit->getPowerType())) * 100; + sEluna->Push(L, percent); + return 1; + } + + int GetGender(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getGender()); + return 1; + } + + int GetRace(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getRace()); + return 1; + } + + int GetClass(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getClass()); + return 1; + } + + int GetCreatureType(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetCreatureType()); + return 1; + } + + int GetClassAsString(lua_State* L, Unit* unit) + { + const char* str = NULL; + switch (unit->getClass()) + { + case 1: + str = "Warrior"; + break; + case 2: + str = "Paladin"; + break; + case 3: + str = "Hunter"; + break; + case 4: + str = "Rogue"; + break; + case 5: + str = "Priest"; + break; + case 6: + str = "Death Knight"; + break; + case 7: + str = "Shaman"; + break; + case 8: + str = "Mage"; + break; + case 9: + str = "Warlock"; + break; + case 11: + str = "Druid"; + break; + default: + str = NULL; + break; + } + + sEluna->Push(L, str); + return 1; + } + + int GetFaction(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->getFaction()); + return 1; + } + + int GetAura(lua_State* L, Unit* unit) + { + uint32 spellID = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + sEluna->Push(L, unit->GetAura(spellID, EFFECT_INDEX_0)); +#else + sEluna->Push(L, unit->GetAura(spellID)); +#endif + return 1; + } + + int GetCombatTime(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->GetCombatTimer()); + return 1; + } + + int GetFriendlyUnitsInRange(lua_State* L, Unit* unit) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + + std::list list; +#ifdef MANGOS + MaNGOS::AnyFriendlyUnitInObjectRangeCheck checker(unit, range); + MaNGOS::UnitListSearcher searcher(list, checker); + Cell::VisitGridObjects(unit, searcher, range); +#else + Trinity::AnyFriendlyUnitInObjectRangeCheck checker(unit, unit, range); + Trinity::UnitListSearcher searcher(unit, list, checker); + unit->VisitNearbyObject(range, searcher); +#endif + Eluna::ObjectGUIDCheck guidCheck(unit->GET_GUID()); + list.remove_if(guidCheck); + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetUnfriendlyUnitsInRange(lua_State* L, Unit* unit) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + + std::list list; +#ifdef MANGOS + MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck checker(unit, range); + MaNGOS::UnitListSearcher searcher(list, checker); + Cell::VisitGridObjects(unit, searcher, range); +#else + Trinity::AnyUnfriendlyUnitInObjectRangeCheck checker(unit, unit, range); + Trinity::UnitListSearcher searcher(unit, list, checker); + unit->VisitNearbyObject(range, searcher); +#endif + Eluna::ObjectGUIDCheck guidCheck(unit->GET_GUID()); + list.remove_if(guidCheck); + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + +#ifndef TBC + int GetVehicleKit(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetVehicleInfo()); +#else + sEluna->Push(L, unit->GetVehicleKit()); +#endif + return 1; + } + + int GetVehicle(lua_State* L, Unit* unit) + { + // sEluna->Push(L, unit->GetVehicle()); + return 1; + } + + int GetCritterGUID(lua_State* L, Unit* unit) + { +#ifdef MANGOS + sEluna->Push(L, unit->GetCritterGuid()); +#else + sEluna->Push(L, unit->GetCritterGUID()); +#endif + return 1; + } +#endif + + /* SETTERS */ + int SetOwnerGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + unit->SetOwnerGuid(GUID_TYPE(guid)); +#else + unit->SetOwnerGUID(GUID_TYPE(guid)); +#endif + return 0; + } + + int SetPvP(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + + unit->SetPvP(apply); + return 0; + } + + int SetSheath(lua_State* L, Unit* unit) + { + uint32 sheathed = sEluna->CHECKVAL(L, 2); + if (sheathed >= MAX_SHEATH_STATE) + return luaL_argerror(L, 2, "valid SheathState expected"); + + unit->SetSheath((SheathState)sheathed); + return 0; + } + + int SetName(lua_State* L, Unit* unit) + { + const char* name = sEluna->CHECKVAL(L, 2); + if (std::string(name).length() > 0) + unit->SetName(name); + return 0; + } + + int SetSpeed(lua_State* L, Unit* unit) + { + uint32 type = sEluna->CHECKVAL(L, 2); + float rate = sEluna->CHECKVAL(L, 3); + bool forced = sEluna->CHECKVAL(L, 4, false); + if (type >= MAX_MOVE_TYPE) + return luaL_argerror(L, 2, "valid UnitMoveType expected"); +#ifdef MANGOS + unit->SetSpeedRate((UnitMoveType)type, rate, forced); +#else + unit->SetSpeed((UnitMoveType)type, rate, forced); +#endif + return 0; + } + + int SetFaction(lua_State* L, Unit* unit) + { + uint32 factionId = sEluna->CHECKVAL(L, 2); + unit->setFaction(factionId); + return 0; + } + + int SetLevel(lua_State* L, Unit* unit) + { + uint32 newLevel = sEluna->CHECKVAL(L, 2); + unit->SetLevel(newLevel); + return 0; + } + + int SetHealth(lua_State* L, Unit* unit) + { + uint32 amt = sEluna->CHECKVAL(L, 2); + unit->SetHealth(amt); + return 0; + } + + int SetMaxHealth(lua_State* L, Unit* unit) + { + uint32 amt = sEluna->CHECKVAL(L, 2); + unit->SetMaxHealth(amt); + return 0; + } + + int SetPower(lua_State* L, Unit* unit) + { + int type = sEluna->CHECKVAL(L, 2); + uint32 amt = sEluna->CHECKVAL(L, 3); + + switch (type) + { + case POWER_MANA: + unit->SetPower(POWER_MANA, amt); + break; + case POWER_RAGE: + unit->SetPower(POWER_RAGE, amt); + break; + case POWER_ENERGY: + unit->SetPower(POWER_ENERGY, amt); + break; +#ifndef TBC + case POWER_RUNIC_POWER: + unit->SetMaxPower(POWER_RUNIC_POWER, amt); + break; +#endif + default: + return luaL_argerror(L, 2, "valid Powers expected"); + break; + } + return 0; + } + + int SetMaxPower(lua_State* L, Unit* unit) + { + int type = sEluna->CHECKVAL(L, 2); + uint32 amt = sEluna->CHECKVAL(L, 3); + + switch (type) + { + case POWER_MANA: + unit->SetMaxPower(POWER_MANA, amt); + break; + case POWER_RAGE: + unit->SetMaxPower(POWER_RAGE, amt); + break; + case POWER_ENERGY: + unit->SetMaxPower(POWER_ENERGY, amt); + break; +#ifndef TBC + case POWER_RUNIC_POWER: + unit->SetMaxPower(POWER_RUNIC_POWER, amt); + break; +#endif + default: + return luaL_argerror(L, 2, "valid Powers expected"); + break; + } + return 0; + } + + int SetDisplayId(lua_State* L, Unit* unit) + { + uint32 model = sEluna->CHECKVAL(L, 2); + unit->SetDisplayId(model); + return 0; + } + + int SetNativeDisplayId(lua_State* L, Unit* unit) + { + uint32 model = sEluna->CHECKVAL(L, 2); + unit->SetNativeDisplayId(model); + return 0; + } + + int SetFacing(lua_State* L, Unit* unit) + { + float o = sEluna->CHECKVAL(L, 2); + unit->SetFacingTo(o); + return 0; + } + + int SetFacingToObject(lua_State* L, Unit* unit) + { + WorldObject* obj = sEluna->CHECKOBJ(L, 2); + unit->SetFacingToObject(obj); + return 0; + } + + int SetCreatorGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + unit->SetOwnerGuid(GUID_TYPE(guid)); +#else + unit->SetOwnerGUID(GUID_TYPE(guid)); +#endif + return 0; + } + + int SetMinionGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + unit->SetPetGuid(GUID_TYPE(guid)); +#else + unit->SetMinionGUID(GUID_TYPE(guid)); +#endif + return 0; + } + + int SetCharmerGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + unit->SetCharmerGuid(GUID_TYPE(guid)); +#else + unit->SetCharmerGUID(GUID_TYPE(guid)); +#endif + return 0; + } + + int SetPetGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + unit->SetPetGuid(GUID_TYPE(guid)); +#else + unit->SetPetGUID(GUID_TYPE(guid)); +#endif + return 0; + } + + int SetWaterWalk(lua_State* L, Unit* unit) + { + bool enable = sEluna->CHECKVAL(L, 2, true); +#ifdef MANGOS + unit->SetWaterWalk(enable); +#else + unit->SetWaterWalking(enable); +#endif + return 0; + } + + int SetStandState(lua_State* L, Unit* unit) + { + uint8 state = sEluna->CHECKVAL(L, 2); + unit->SetStandState(state); + return 0; + } + +#ifndef TBC + int SetFFA(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + +#ifdef MANGOS + unit->SetFFAPvP(apply); +#else + if (apply) + { + unit->SetByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + for (Unit::ControlList::iterator itr = unit->m_Controlled.begin(); itr != unit->m_Controlled.end(); ++itr) + (*itr)->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + } + else + { + unit->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + for (Unit::ControlList::iterator itr = unit->m_Controlled.begin(); itr != unit->m_Controlled.end(); ++itr) + (*itr)->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + } +#endif + return 0; + } + + int SetSanctuary(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 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 SetPhaseMask(lua_State* L, Unit* unit) + { + uint32 phaseMask = sEluna->CHECKVAL(L, 2); + bool Update = sEluna->CHECKVAL(L, 3, true); + unit->SetPhaseMask(phaseMask, Update); + return 0; + } + + int SetCritterGUID(lua_State* L, Unit* unit) + { + uint64 guid = sEluna->CHECKVAL(L, 2); +#ifdef MANGOS + unit->SetCritterGuid(GUID_TYPE(guid)); +#else + unit->SetCritterGUID(GUID_TYPE(guid)); +#endif + return 0; + } +#endif + + /*int SetStunned(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + unit->SetControlled(apply, UNIT_STATE_STUNNED); + return 0; + }*/ + + /*int SetRooted(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + unit->SetControlled(apply, UNIT_STATE_ROOT); + return 0; + }*/ + + /*int SetConfused(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + unit->SetControlled(apply, UNIT_STATE_CONFUSED); + return 0; + }*/ + + /*int SetFeared(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + unit->SetControlled(apply, UNIT_STATE_FLEEING); + return 0; + }*/ + + /*int SetCanFly(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + unit->SetCanFly(apply); + return 0; + }*/ + + /*int SetVisible(lua_State* L, Unit* unit) + { + bool x = sEluna->CHECKVAL(L, 2, true); + unit->SetVisible(x); + return 0; + }*/ + + /* OTHER */ + int ClearThreatList(lua_State* L, Unit* unit) + { + unit->getThreatManager().clearReferences(); + return 0; + } + + int Mount(lua_State* L, Unit* unit) + { + uint32 displayId = sEluna->CHECKVAL(L, 2); + + unit->Mount(displayId); + return 0; + } + + int Dismount(lua_State* L, Unit* unit) + { + if (unit->IsMounted()) + { +#ifdef MANGOS + unit->Unmount(); + unit->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED); +#else + unit->Dismount(); + unit->RemoveAurasByType(SPELL_AURA_MOUNTED); +#endif + } + + return 0; + } + + int Emote(lua_State* L, Unit* unit) + { + unit->HandleEmoteCommand(sEluna->CHECKVAL(L, 2)); + return 0; + } + + int CountPctFromCurHealth(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->CountPctFromCurHealth(sEluna->CHECKVAL(L, 2))); + return 1; + } + + int CountPctFromMaxHealth(lua_State* L, Unit* unit) + { + sEluna->Push(L, unit->CountPctFromMaxHealth(sEluna->CHECKVAL(L, 2))); + return 1; + } + + int SendChatMessageToPlayer(lua_State* L, Unit* unit) + { + uint8 type = sEluna->CHECKVAL(L, 2); + uint32 lang = sEluna->CHECKVAL(L, 3); + const char* msg = sEluna->CHECKVAL(L, 4); + Player* target = sEluna->CHECKOBJ(L, 5); + if (type == CHAT_MSG_CHANNEL) + return 0; + + WorldPacket* data = new WorldPacket(); + uint32 messageLength = (uint32)strlen(msg) + 1; + data->Initialize(SMSG_MESSAGECHAT, 100); + *data << (uint8)type; + *data << lang; + *data << unit->GetGUIDLow(); + *data << uint32(0); + *data << unit->GetGUIDLow(); + *data << messageLength; + *data << msg; + if (unit->ToPlayer() && type != CHAT_MSG_WHISPER_INFORM && type != CHAT_MSG_DND && type != CHAT_MSG_AFK) + *data << uint8(unit->ToPlayer()->GetChatTag()); + else + *data << uint8(0); + target->GetSession()->SendPacket(data); + return 0; + } + + static void PrepareMove(Unit* unit) + { + unit->GetMotionMaster()->MovementExpired(); // Chase + unit->StopMoving(); // Some + unit->GetMotionMaster()->Clear(); // all + } + + int MoveStop(lua_State* L, Unit* unit) + { + unit->StopMoving(); + return 0; + } + + int MoveExpire(lua_State* L, Unit* unit) + { + bool reset = sEluna->CHECKVAL(L, 2, true); + unit->GetMotionMaster()->MovementExpired(reset); + return 0; + } + + int MoveClear(lua_State* L, Unit* unit) + { + bool reset = sEluna->CHECKVAL(L, 2, true); + unit->GetMotionMaster()->Clear(reset); + return 0; + } + + int MoveIdle(lua_State* L, Unit* unit) + { + unit->GetMotionMaster()->MoveIdle(); + return 0; + } + + int MoveRandom(lua_State* L, Unit* unit) + { + float radius = sEluna->CHECKVAL(L, 2); + float x, y, z; + unit->GetPosition(x, y, z); +#ifdef MANGOS + unit->GetMotionMaster()->MoveRandomAroundPoint(x, y, z, radius); +#else + unit->GetMotionMaster()->MoveRandom(radius); +#endif + return 0; + } + + int MoveHome(lua_State* L, Unit* unit) + { + unit->GetMotionMaster()->MoveTargetedHome(); + return 0; + } + + int MoveFollow(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + float dist = sEluna->CHECKVAL(L, 3, 0.0f); + float angle = sEluna->CHECKVAL(L, 4, 0.0f); + unit->GetMotionMaster()->MoveFollow(target, dist, angle); + return 0; + } + + int MoveChase(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + float dist = sEluna->CHECKVAL(L, 3, 0.0f); + float angle = sEluna->CHECKVAL(L, 4, 0.0f); + unit->GetMotionMaster()->MoveChase(target, dist, angle); + return 0; + } + + int MoveConfused(lua_State* L, Unit* unit) + { + unit->GetMotionMaster()->MoveConfused(); + return 0; + } + + int MoveFleeing(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + uint32 time = sEluna->CHECKVAL(L, 3, 0); + unit->GetMotionMaster()->MoveFleeing(target, time); + return 0; + } + + int MoveTo(lua_State* L, Unit* unit) + { + uint32 id = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + bool genPath = sEluna->CHECKVAL(L, 6, true); + unit->GetMotionMaster()->MovePoint(id, x, y, z, genPath); + return 0; + } + +#ifndef TBC + int MoveJump(lua_State* L, Unit* unit) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + float z = sEluna->CHECKVAL(L, 4); + float zSpeed = sEluna->CHECKVAL(L, 5); + float maxHeight = sEluna->CHECKVAL(L, 6); + uint32 id = sEluna->CHECKVAL(L, 7, 0); + unit->GetMotionMaster()->MoveJump(x, y, z, zSpeed, maxHeight, id); + return 0; + } +#endif + + int SendUnitWhisper(lua_State* L, Unit* unit) + { + const char* msg = sEluna->CHECKVAL(L, 2); + Player* receiver = sEluna->CHECKOBJ(L, 3); + bool bossWhisper = sEluna->CHECKVAL(L, 4, false); + if (std::string(msg).length() > 0) + unit->MonsterWhisper(msg, receiver, bossWhisper); + return 0; + } + + int SendUnitEmote(lua_State* L, Unit* unit) + { + const char* msg = sEluna->CHECKVAL(L, 2); + Unit* receiver = sEluna->CHECKOBJ(L, 3, false); + bool bossEmote = sEluna->CHECKVAL(L, 4, false); + if (std::string(msg).length() > 0) + unit->MonsterTextEmote(msg, receiver, bossEmote); + return 0; + } + + int SendUnitSay(lua_State* L, Unit* unit) + { + const char* msg = sEluna->CHECKVAL(L, 2); + uint32 language = sEluna->CHECKVAL(L, 3); + if (std::string(msg).length() > 0) + unit->MonsterSay(msg, language, unit); + return 0; + } + + int SendUnitYell(lua_State* L, Unit* unit) + { + const char* msg = sEluna->CHECKVAL(L, 2); + uint32 language = sEluna->CHECKVAL(L, 3); + if (std::string(msg).length() > 0) + unit->MonsterYell(msg, language, unit); + return 0; + } + + int DeMorph(lua_State* L, Unit* unit) + { + unit->DeMorph(); + return 0; + } + + int CastSpell(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + uint32 spell = sEluna->CHECKVAL(L, 3); + bool triggered = sEluna->CHECKVAL(L, 4, false); + SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell); + if (!spellEntry) + return 0; + + unit->CastSpell(target, spell, triggered); + return 0; + } + + int CastSpellAoF(lua_State* L, Unit* unit) + { + float _x = sEluna->CHECKVAL(L, 2); + float _y = sEluna->CHECKVAL(L, 3); + float _z = sEluna->CHECKVAL(L, 4); + uint32 spell = sEluna->CHECKVAL(L, 5); + bool triggered = sEluna->CHECKVAL(L, 6, true); + unit->CastSpell(_x, _y, _z, spell, triggered); + return 0; + } + + int ClearInCombat(lua_State* L, Unit* unit) + { + unit->ClearInCombat(); + return 0; + } + + int StopSpellCast(lua_State* L, Unit* unit) + { + uint32 spellId = sEluna->CHECKVAL(L, 2, 0); + unit->CastStop(spellId); + return 0; + } + + int InterruptSpell(lua_State* L, Unit* unit) + { + int spellType = sEluna->CHECKVAL(L, 2); + bool delayed = sEluna->CHECKVAL(L, 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; + } + unit->InterruptSpell((CurrentSpellTypes)spellType, delayed); + return 0; + } + + int AddAura(lua_State* L, Unit* unit) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + Unit* target = sEluna->CHECKOBJ(L, 3); + SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); + if (!spellInfo) + return 0; + +#ifdef MANGOS + if (!IsSpellAppliesAura(spellInfo) && !IsSpellHaveEffect(spellInfo, SPELL_EFFECT_PERSISTENT_AREA_AURA)) + return 0; + + SpellAuraHolder* holder = CreateSpellAuraHolder(spellInfo, target, unit); + + for (uint32 i = 0; i < MAX_EFFECT_INDEX; ++i) + { + uint8 eff = spellInfo->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(spellInfo, SpellEffIndex(i), NULL, holder, target); + holder->AddAura(aur, SpellEffIndex(i)); + } + } + sEluna->Push(L, target->AddSpellAuraHolder(holder)); +#else + sEluna->Push(L, unit->AddAura(spellId, target)); +#endif + return 1; + } + + int RemoveAura(lua_State* L, Unit* unit) + { + uint32 spellId = sEluna->CHECKVAL(L, 2); + unit->RemoveAurasDueToSpell(spellId); + return 0; + } + + int RemoveAllAuras(lua_State* L, Unit* unit) + { + unit->RemoveAllAuras(); + return 0; + } + + int PlayDirectSound(lua_State* L, Unit* unit) + { + uint32 soundId = sEluna->CHECKVAL(L, 2); + Player* player = sEluna->CHECKOBJ(L, 3, false); + if (!sSoundEntriesStore.LookupEntry(soundId)) + return 0; + + if (player) + unit->PlayDirectSound(soundId, player); + else + unit->PlayDirectSound(soundId); + return 0; + } + + int PlayDistanceSound(lua_State* L, Unit* unit) + { + uint32 soundId = sEluna->CHECKVAL(L, 2); + Player* player = sEluna->CHECKOBJ(L, 3, false); + if (!sSoundEntriesStore.LookupEntry(soundId)) + return 0; + + if (player) + unit->PlayDistanceSound(soundId, player); + else + unit->PlayDistanceSound(soundId); + return 0; + } + + int RegisterEvent(lua_State* L, Unit* unit) + { + luaL_checktype(L, 2, LUA_TFUNCTION); + uint32 delay = sEluna->CHECKVAL(L, 3); + uint32 repeats = sEluna->CHECKVAL(L, 4); + + lua_settop(L, 2); + int functionRef = lua_ref(L, true); + functionRef = sEluna->m_EventMgr.AddEvent(&unit->m_Events, functionRef, delay, repeats, unit); + if (functionRef) + sEluna->Push(L, functionRef); + else + sEluna->Push(L); + return 1; + } + + int RemoveEventById(lua_State* L, Unit* unit) + { + int eventId = sEluna->CHECKVAL(L, 2); + sEluna->m_EventMgr.RemoveEvent(&unit->m_Events, eventId); + return 0; + } + + int RemoveEvents(lua_State* L, Unit* unit) + { + sEluna->m_EventMgr.RemoveEvents(&unit->m_Events); + return 0; + } + + int AddUnitState(lua_State* L, Unit* unit) + { + uint32 state = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + unit->addUnitState(state); +#else + unit->AddUnitState(state); +#endif + return 0; + } + + int ClearUnitState(lua_State* L, Unit* unit) + { + uint32 state = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + unit->clearUnitState(state); +#else + unit->ClearUnitState(state); +#endif + return 0; + } + + int NearTeleport(lua_State* L, Unit* unit) + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + float z = sEluna->CHECKVAL(L, 4); + float o = sEluna->CHECKVAL(L, 5); + + unit->NearTeleportTo(x, y, z, o); + return 1; + } + + /*int DealDamage(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + uint32 amount = sEluna->CHECKVAL(L, 3); + + unit->DealDamage(target, amount); + return 0; + }*/ + + /*int Kill(lua_State* L, Unit* unit) + { + Unit* target = sEluna->CHECKOBJ(L, 2); + bool durLoss = sEluna->CHECKVAL(L, 3, true); + unit->Kill(target, durLoss); + return 0; + }*/ + + /*int RestoreDisplayId(lua_State* L, Unit* unit) + { + unit->RestoreDisplayId(); + return 0; + }*/ + + /*int RestoreFaction(lua_State* L, Unit* unit) + { + unit->RestoreFaction(); + return 0; + }*/ + + /*int RemoveBindSightAuras(lua_State* L, Unit* unit) + { + unit->RemoveBindSightAuras(); + return 0; + }*/ + + /*int RemoveCharmAuras(lua_State* L, Unit* unit) + { + unit->RemoveCharmAuras(); + return 0; + }*/ + + /*int DisableMelee(lua_State* L, Unit* unit) + { + bool apply = sEluna->CHECKVAL(L, 2, true); + + if (apply) + unit->AddUnitState(UNIT_STATE_CANNOT_AUTOATTACK); + else + unit->ClearUnitState(UNIT_STATE_CANNOT_AUTOATTACK); + return 0; + }*/ + + /*int SummonGuardian(lua_State* L, Unit* unit) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + float o = sEluna->CHECKVAL(L, 6); + uint32 desp = sEluna->CHECKVAL(L, 7, 0); + + SummonPropertiesEntry const* properties = sSummonPropertiesStore.LookupEntry(61); + if (!properties) + return 0; + Position pos; + pos.Relocate(x,y,z,o); + TempSummon* summon = unit->GetMap()->SummonCreature(entry, pos, properties, desp, unit); + + if (!summon) + return 0; + + if (summon->HasUnitTypeMask(UNIT_MASK_GUARDIAN)) + ((Guardian*)summon)->InitStatsForLevel(unit->getLevel()); + + if (properties && properties->Category == SUMMON_CATEGORY_ALLY) + summon->setFaction(unit->getFaction()); + if (summon->GetEntry() == 27893) + { + if (uint32 weapon = unit->GetUInt32Value(PLAYER_VISIBLE_ITEM_16_ENTRYID)) + { + summon->SetDisplayId(11686); + summon->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID, weapon); + } + else + summon->SetDisplayId(1126); + } + summon->AI()->EnterEvadeMode(); + + sEluna->Push(L, summon); + return 1; + }*/ +}; +#endif diff --git a/VehicleMethods.h b/VehicleMethods.h new file mode 100644 index 0000000..796e93a --- /dev/null +++ b/VehicleMethods.h @@ -0,0 +1,80 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef TBC +#ifndef VEHICLEMETHODS_H +#define VEHICLEMETHODS_H + +namespace LuaVehicle +{ + /* BOOLEAN */ + int IsOnBoard(lua_State* L, Vehicle* vehicle) + { + Unit* passenger = sEluna->CHECKOBJ(L, 2); +#ifdef MANGOS + sEluna->Push(L, vehicle->HasOnBoard(passenger)); +#else + sEluna->Push(L, passenger->IsOnVehicle(vehicle->GetBase())); +#endif + return 1; + } + + /* GETTERS */ + int GetOwner(lua_State* L, Vehicle* vehicle) + { +#ifdef MANGOS + sEluna->Push(L, vehicle->GetOwner()); +#else + sEluna->Push(L, vehicle->GetBase()); +#endif + return 1; + } + + int GetEntry(lua_State* L, Vehicle* vehicle) + { +#ifdef MANGOS + sEluna->Push(L, vehicle->GetVehicleEntry()->m_ID); +#else + sEluna->Push(L, vehicle->GetVehicleInfo()->m_ID); +#endif + return 1; + } + + int GetPassenger(lua_State* L, Vehicle* vehicle) + { + int8 seatId = sEluna->CHECKVAL(L, 2); + sEluna->Push(L, vehicle->GetPassenger(seatId)); + return 1; + } + + /* OTHER */ + int AddPassenger(lua_State* L, Vehicle* vehicle) + { + Unit* passenger = sEluna->CHECKOBJ(L, 2); + int8 seatId = sEluna->CHECKVAL(L, 3); +#ifdef MANGOS + if (vehicle->CanBoard(passenger)) + vehicle->Board(passenger, seatId); +#else + vehicle->AddPassenger(passenger, seatId); +#endif + return 0; + } + + int RemovePassenger(lua_State* L, Vehicle* vehicle) + { + Unit* passenger = sEluna->CHECKOBJ(L, 2); +#ifdef MANGOS + vehicle->UnBoard(passenger, false); +#else + vehicle->RemovePassenger(passenger); +#endif + return 0; + } +} + +#endif +#endif \ No newline at end of file diff --git a/WeatherMethods.h b/WeatherMethods.h new file mode 100644 index 0000000..117eeae --- /dev/null +++ b/WeatherMethods.h @@ -0,0 +1,51 @@ +/* +* Copyright (C) 2010 - 2014 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef WEATHERMETHODS_H +#define WEATHERMETHODS_H + +namespace LuaWeather +{ + /* GETTERS */ + int GetZoneId(lua_State* L, Weather* weather) + { + sEluna->Push(L, weather->GetZone()); + return 1; + } + + /* SETTERS */ + int SetWeather(lua_State* L, Weather* weather) + { + uint32 weatherType = sEluna->CHECKVAL(L, 2); + float grade = sEluna->CHECKVAL(L, 3); + + weather->SetWeather((WeatherType)weatherType, grade); + return 0; + } + + int SendWeatherUpdateToPlayer(lua_State* L, Weather* weather) + { + Player* player = sEluna->CHECKOBJ(L, 2); + + weather->SendWeatherUpdateToPlayer(player); + return 0; + } + + /* OTHER */ + int Regenerate(lua_State* L, Weather* weather) + { + sEluna->Push(L, weather->ReGenerate()); + return 1; + } + + int UpdateWeather(lua_State* L, Weather* weather) + { + sEluna->Push(L, weather->UpdateWeather()); + return 1; + } +}; + +#endif diff --git a/WorldObjectMethods.h b/WorldObjectMethods.h new file mode 100644 index 0000000..b749f6a --- /dev/null +++ b/WorldObjectMethods.h @@ -0,0 +1,432 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaWorldObject +{ + /* GETTERS */ + int GetName(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetName()); + return 1; + } + + int GetMap(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetMap()); + return 1; + } + +#ifndef TBC + int GetPhaseMask(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetPhaseMask()); + return 1; + } +#endif + + int GetInstanceId(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetInstanceId()); + return 1; + } + + int GetAreaId(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetAreaId()); + return 1; + } + + int GetZoneId(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetZoneId()); + return 1; + } + + int GetMapId(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetMapId()); + return 1; + } + + int GetX(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetPositionX()); + return 1; + } + + int GetY(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetPositionY()); + return 1; + } + + int GetZ(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetPositionZ()); + return 1; + } + + int GetO(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetOrientation()); + return 1; + } + + int GetLocation(lua_State* L, WorldObject* obj) + { + sEluna->Push(L, obj->GetPositionX()); + sEluna->Push(L, obj->GetPositionY()); + sEluna->Push(L, obj->GetPositionZ()); + sEluna->Push(L, obj->GetOrientation()); + return 4; + } + + int GetNearestPlayer(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + + Unit* target = NULL; + Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_PLAYER); +#ifdef MANGOS + MaNGOS::UnitLastSearcher searcher(target, checker); + Cell::VisitWorldObjects(obj, searcher, range); +#else + Trinity::UnitLastSearcher searcher(obj, target, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + sEluna->Push(L, target); + return 1; + } + + int GetNearestGameObject(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = sEluna->CHECKVAL(L, 3, 0); + + GameObject* target = NULL; + Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_GAMEOBJECT, entry); +#ifdef MANGOS + MaNGOS::GameObjectLastSearcher searcher(target, checker); + Cell::VisitGridObjects(obj, searcher, range); +#else + Trinity::GameObjectLastSearcher searcher(obj, target, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + sEluna->Push(L, target); + return 1; + } + + int GetNearestCreature(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = sEluna->CHECKVAL(L, 3, 0); + + Creature* target = NULL; + Eluna::WorldObjectInRangeCheck checker(true, obj, range, TYPEMASK_UNIT, entry); +#ifdef MANGOS + MaNGOS::CreatureLastSearcher searcher(target, checker); + Cell::VisitGridObjects(obj, searcher, range); +#else + Trinity::CreatureLastSearcher searcher(obj, target, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + sEluna->Push(L, target); + return 1; + } + + int GetPlayersInRange(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + + std::list list; + Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_PLAYER); +#ifdef MANGOS + MaNGOS::PlayerListSearcher searcher(list, checker); + Cell::VisitWorldObjects(obj, searcher, range); +#else + Trinity::PlayerListSearcher searcher(obj, list, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetCreaturesInRange(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = sEluna->CHECKVAL(L, 3, 0); + + std::list list; + Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_UNIT, entry); +#ifdef MANGOS + MaNGOS::CreatureListSearcher searcher(list, checker); + Cell::VisitGridObjects(obj, searcher, range); +#else + Trinity::CreatureListSearcher searcher(obj, list, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetGameObjectsInRange(lua_State* L, WorldObject* obj) + { + float range = sEluna->CHECKVAL(L, 2, SIZE_OF_GRIDS); + uint32 entry = sEluna->CHECKVAL(L, 3, 0); + + std::list list; + Eluna::WorldObjectInRangeCheck checker(false, obj, range, TYPEMASK_GAMEOBJECT, entry); +#ifdef MANGOS + MaNGOS::GameObjectListSearcher searcher(list, checker); + Cell::VisitGridObjects(obj, searcher, range); +#else + Trinity::GameObjectListSearcher searcher(obj, list, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + int GetNearObject(lua_State* L, WorldObject* obj) + { + bool nearest = sEluna->CHECKVAL(L, 2, true); + float range = sEluna->CHECKVAL(L, 3, SIZE_OF_GRIDS); + uint16 type = sEluna->CHECKVAL(L, 4, 0); // TypeMask + uint32 entry = sEluna->CHECKVAL(L, 5, 0); + uint32 hostile = sEluna->CHECKVAL(L, 6, 0); // 0 none, 1 hostile, 2 friendly + + float x, y, z; + obj->GetPosition(x, y, z); + Eluna::WorldObjectInRangeCheck checker(nearest, obj, range, type, entry, hostile); + if (nearest) + { + WorldObject* target = NULL; +#ifdef MANGOS + MaNGOS::WorldObjectLastSearcher searcher(target, checker); + Cell::VisitAllObjects(obj, searcher, range); +#else + Trinity::WorldObjectLastSearcher searcher(obj, target, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + sEluna->Push(L, target); + return 1; + } + else + { + std::list list; +#ifdef MANGOS + MaNGOS::WorldObjectListSearcher searcher(list, checker); + Cell::VisitAllObjects(obj, searcher, range); +#else + Trinity::WorldObjectListSearcher searcher(obj, list, checker); + obj->VisitNearbyObject(range, searcher); +#endif + + lua_newtable(L); + int tbl = lua_gettop(L); + uint32 i = 0; + + for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + sEluna->Push(L, ++i); + sEluna->Push(L, *it); + lua_settable(L, tbl); + } + + lua_settop(L, tbl); + return 1; + } + + return 0; + } + + int GetWorldObject(lua_State* L, WorldObject* obj) + { + uint64 guid = sEluna->CHECKVAL(L, 2); + +#ifdef MANGOS + switch (GUID_HIPART(guid)) + { + case HIGHGUID_PLAYER: sEluna->Push(L, obj->GetMap()->GetPlayer(GUID_TYPE(guid))); break; + case HIGHGUID_TRANSPORT: + case HIGHGUID_MO_TRANSPORT: + case HIGHGUID_GAMEOBJECT: sEluna->Push(L, obj->GetMap()->GetGameObject(GUID_TYPE(guid))); break; +#ifndef TBC + case HIGHGUID_VEHICLE: +#endif + case HIGHGUID_UNIT: + case HIGHGUID_PET: sEluna->Push(L, obj->GetMap()->GetAnyTypeCreature(GUID_TYPE(guid))); break; + default: return 0; + } +#else + switch (GUID_HIPART(guid)) + { + case HIGHGUID_PLAYER: sEluna->Push(L, sObjectAccessor->GetPlayer(*obj, GUID_TYPE(guid))); break; + case HIGHGUID_TRANSPORT: + case HIGHGUID_MO_TRANSPORT: + case HIGHGUID_GAMEOBJECT: sEluna->Push(L, sObjectAccessor->GetGameObject(*obj, GUID_TYPE(guid))); break; + case HIGHGUID_VEHICLE: + case HIGHGUID_UNIT: sEluna->Push(L, sObjectAccessor->GetCreature(*obj, GUID_TYPE(guid))); break; + case HIGHGUID_PET: sEluna->Push(L, sObjectAccessor->GetPet(*obj, GUID_TYPE(guid))); break; + default: return 0; + } +#endif + return 1; + } + + int GetDistance(lua_State* L, WorldObject* obj) + { + WorldObject* target = sEluna->CHECKOBJ(L, 2, false); + if (target && target->IsInWorld()) + sEluna->Push(L, obj->GetDistance(target)); + else + { + float X = sEluna->CHECKVAL(L, 2); + float Y = sEluna->CHECKVAL(L, 3); + float Z = sEluna->CHECKVAL(L, 4); + sEluna->Push(L, obj->GetDistance(X, Y, Z)); + } + return 1; + } + + int GetRelativePoint(lua_State* L, WorldObject* obj) + { + float dist = sEluna->CHECKVAL(L, 2); + float rad = sEluna->CHECKVAL(L, 3); + + float x, y, z; + obj->GetClosePoint(x, y, z, 0.0f, dist, rad); + + sEluna->Push(L, x); + sEluna->Push(L, y); + sEluna->Push(L, z); + return 3; + } + + int GetAngle(lua_State* L, WorldObject* obj) + { + WorldObject* target = sEluna->CHECKOBJ(L, 2, false); + + if (target && target->IsInWorld()) + sEluna->Push(L, obj->GetAngle(target)); + else + { + float x = sEluna->CHECKVAL(L, 2); + float y = sEluna->CHECKVAL(L, 3); + sEluna->Push(L, obj->GetAngle(x, y)); + } + return 1; + } + + /* OTHER */ + int SendPacket(lua_State* L, WorldObject* obj) + { + WorldPacket* data = sEluna->CHECKOBJ(L, 2); + obj->SendMessageToSet(data, true); + return 0; + } + + int SummonGameObject(lua_State* L, WorldObject* obj) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + float o = sEluna->CHECKVAL(L, 6); + uint32 respawnDelay = sEluna->CHECKVAL(L, 7, 30); +#ifdef MANGOS + sEluna->Push(L, obj->SummonGameObject(entry, x, y, z, o, respawnDelay)); +#else + sEluna->Push(L, obj->SummonGameObject(entry, x, y, z, o, 0, 0, 0, 0, respawnDelay)); +#endif + return 1; + } + + int SpawnCreature(lua_State* L, WorldObject* obj) + { + uint32 entry = sEluna->CHECKVAL(L, 2); + float x = sEluna->CHECKVAL(L, 3); + float y = sEluna->CHECKVAL(L, 4); + float z = sEluna->CHECKVAL(L, 5); + float o = sEluna->CHECKVAL(L, 6); + uint32 spawnType = sEluna->CHECKVAL(L, 7, 8); + uint32 despawnTimer = sEluna->CHECKVAL(L, 8, 0); + + TempSummonType type; + switch (spawnType) + { + case 1: + type = TEMPSUMMON_TIMED_OR_DEAD_DESPAWN; + break; + case 2: + type = TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN; + break; + case 3: + type = TEMPSUMMON_TIMED_DESPAWN; + break; + case 5: + type = TEMPSUMMON_CORPSE_DESPAWN; + break; + case 6: + type = TEMPSUMMON_CORPSE_TIMED_DESPAWN; + break; + case 7: + type = TEMPSUMMON_DEAD_DESPAWN; + break; + case 8: + type = TEMPSUMMON_MANUAL_DESPAWN; + break; + default: + return luaL_argerror(L, 7, "valid SpawnType expected"); + } + sEluna->Push(L, obj->SummonCreature(entry, x, y, z, o, type, despawnTimer)); + return 1; + } +}; +#endif diff --git a/WorldPacketMethods.h b/WorldPacketMethods.h new file mode 100644 index 0000000..16a1633 --- /dev/null +++ b/WorldPacketMethods.h @@ -0,0 +1,207 @@ +/* +* Copyright (C) 2010 - 2014 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 + +namespace LuaPacket +{ + // GetOpcode() + int GetOpcode(lua_State* L, WorldPacket* packet) + { + sEluna->Push(L, packet->GetOpcode()); + return 1; + } + + // GetSize() + int GetSize(lua_State* L, WorldPacket* packet) + { + sEluna->Push(L, packet->size()); + return 1; + } + + // SetOpcode(opcode) + int SetOpcode(lua_State* L, WorldPacket* packet) + { + uint32 opcode = sEluna->CHECKVAL(L, 2); + if (opcode >= NUM_MSG_TYPES) + return luaL_argerror(L, 2, "valid opcode expected"); + packet->SetOpcode((Opcodes)opcode); + return 0; + } + + // ReadByte() + int ReadByte(lua_State* L, WorldPacket* packet) + { + int8 byte; + (*packet) >> byte; + sEluna->Push(L, byte); + return 1; + } + + // ReadUByte() + int ReadUByte(lua_State* L, WorldPacket* packet) + { + uint8 byte; + (*packet) >> byte; + sEluna->Push(L, byte); + return 1; + } + + // ReadShort() + int ReadShort(lua_State* L, WorldPacket* packet) + { + int16 _short; + (*packet) >> _short; + sEluna->Push(L, _short); + return 1; + } + + // ReadUShort() + int ReadUShort(lua_State* L, WorldPacket* packet) + { + uint16 _ushort; + (*packet) >> _ushort; + sEluna->Push(L, _ushort); + return 1; + } + + // ReadLong() + int ReadLong(lua_State* L, WorldPacket* packet) + { + int32 _long; + (*packet) >> _long; + sEluna->Push(L, _long); + return 1; + } + + // ReadULong() + int ReadULong(lua_State* L, WorldPacket* packet) + { + uint32 _ulong; + (*packet) >> _ulong; + sEluna->Push(L, _ulong); + return 1; + } + + // ReadFloat() + int ReadFloat(lua_State* L, WorldPacket* packet) + { + float _val; + (*packet) >> _val; + sEluna->Push(L, _val); + return 1; + } + + // ReadDouble() + int ReadDouble(lua_State* L, WorldPacket* packet) + { + double _val; + (*packet) >> _val; + sEluna->Push(L, _val); + return 1; + } + + // ReadGUID() + int ReadGUID(lua_State* L, WorldPacket* packet) + { + uint64 guid; + (*packet) >> guid; + sEluna->Push(L, guid); + return 1; + } + + // ReadString() + int ReadString(lua_State* L, WorldPacket* packet) + { + std::string _val; + (*packet) >> _val; + sEluna->Push(L, _val); + return 1; + } + + // WriteGUID(guid) + int WriteGUID(lua_State* L, WorldPacket* packet) + { + uint64 guid = sEluna->CHECKVAL(L, 2); + (*packet) << guid; + return 0; + } + + // WriteString(string) + int WriteString(lua_State* L, WorldPacket* packet) + { + std::string _val = sEluna->CHECKVAL(L, 2); + (*packet) << _val; + return 0; + } + + // WriteBye(byte) + int WriteByte(lua_State* L, WorldPacket* packet) + { + int8 byte = sEluna->CHECKVAL(L, 2); + (*packet) << byte; + return 0; + } + + // WriteUByte(byte) + int WriteUByte(lua_State* L, WorldPacket* packet) + { + uint8 byte = sEluna->CHECKVAL(L, 2); + (*packet) << byte; + return 0; + } + + // WriteUShort(short) + int WriteUShort(lua_State* L, WorldPacket* packet) + { + uint16 _ushort = sEluna->CHECKVAL(L, 2); + (*packet) << _ushort; + return 0; + } + + // WriteShort(short) + int WriteShort(lua_State* L, WorldPacket* packet) + { + int16 _short = sEluna->CHECKVAL(L, 2); + (*packet) << _short; + return 0; + } + + // WriteLong(long) + int WriteLong(lua_State* L, WorldPacket* packet) + { + int32 _long = sEluna->CHECKVAL(L, 2); + (*packet) << _long; + return 0; + } + + // WriteULong(long) + int WriteULong(lua_State* L, WorldPacket* packet) + { + uint32 _ulong = sEluna->CHECKVAL(L, 2); + (*packet) << _ulong; + return 0; + } + + // WriteFloat(float) + int WriteFloat(lua_State* L, WorldPacket* packet) + { + float _val = sEluna->CHECKVAL(L, 2); + (*packet) << _val; + return 0; + } + + // WriteDouble(double) + int WriteDouble(lua_State* L, WorldPacket* packet) + { + double _val = sEluna->CHECKVAL(L, 2); + (*packet) << _val; + return 0; + } +}; + +#endif diff --git a/docs/INSTALL.md b/docs/INSTALL.md new file mode 100644 index 0000000..485c57d --- /dev/null +++ b/docs/INSTALL.md @@ -0,0 +1,33 @@ +#Installation +Get the core:
+[![Build Status](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Wotlk.png?branch=master)](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Wotlk) [Eluna TrinityCore WOTLK](https://github.com/ElunaLuaEngine/Eluna-TC-Wotlk)
+[![Build Status](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Cata.png?branch=master)](https://travis-ci.org/ElunaLuaEngine/Eluna-TC-Cata) [Eluna TrinityCore Cataclysm](https://github.com/ElunaLuaEngine/Eluna-TC-Cata) + +[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreClassic.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreClassic) [Eluna cMaNGOS Classic](https://github.com/eluna-dev-mangos/ElunaCoreClassic)
+[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreTbc.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreTbc) [Eluna cMaNGOS TBC](https://github.com/eluna-dev-mangos/ElunaCoreTbc)
+[![Build Status](https://travis-ci.org/eluna-dev-mangos/ElunaCoreWotlk.png?branch=master)](https://travis-ci.org/eluna-dev-mangos/ElunaCoreWotlk) [Eluna cMaNGOS WotLK](https://github.com/eluna-dev-mangos/ElunaCoreWotlk) + +On **TrinityCore** navigate to `\src\`
+On **MaNGOS** navigate to `\src\game\`
+ +Open `git bash` in `LuaEngine` folder and do +1. `git init` +2. `git remote add origin https://github.com/ElunaLuaEngine/Eluna` +3. `git pull origin master` + +Compile the core normally (use cmake on TC) + +#Updating +When updating you should take up the `commit hashes` you are on, just in case. +You can get it from git with `git log` for example. +Use this when git is open in the source folder as well as in LuaEngine folder. +You should take note what are the newest SQL updates in `sql/updates/*` folders. + +Use `git pull` in core source and in LuaEngine folder to get the newest source changes and Eluna from github. +Try compiling and if you encounter errors, report to [support](https://github.com/ElunaLuaEngine/Eluna#links) or [issues](https://github.com/ElunaLuaEngine/Eluna/issues). +You can revert back to the old sources by using `git reset --hard 000000`, where 000000 is the `commit hash`. + +If the compiling was successful, you should update your database if needed. +You can do this by running all **new** SQL files in `sql/updates/*`. +You need to see your notes from before pulling the updates or you can use the old commit hash to see on github what were the last files you ran. +An easy way is to just look at the created/modified date on the files. diff --git a/docs/LICENSE.md b/docs/LICENSE.md new file mode 100644 index 0000000..d1188bc --- /dev/null +++ b/docs/LICENSE.md @@ -0,0 +1,220 @@ +GNU GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS +0. Definitions. +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on the Program. + +To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. + +A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + +a) The work must carry prominent notices stating that you modified it, and giving a relevant date. +b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. +c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. +d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + +a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. +b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. +c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. +d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. +e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + +a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or +b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or +c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or +d) Limiting the use for publicity purposes of names of licensors or authors of the material; or +e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or +f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. +All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. +A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + Copyright (C) + + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. +The hypothetical commands 'show w' and 'show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read .