diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp index 520239f..c9bd8b1 100644 --- a/src/ElunaLuaEngine_SC.cpp +++ b/src/ElunaLuaEngine_SC.cpp @@ -237,7 +237,7 @@ class Eluna_AllMapScript : public AllMapScript public: Eluna_AllMapScript() : AllMapScript("Eluna_AllMapScript") { } - void OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript** instanceData, bool /*load*/, std::string /*data*/, uint32 /*completedEncounterMask*/) override + void OnBeforeCreateInstanceScript(InstanceMap* instanceMap, InstanceScript* instanceData, bool /*load*/, std::string /*data*/, uint32 /*completedEncounterMask*/) override { if (instanceData) *instanceData = sEluna->GetInstanceData(instanceMap); diff --git a/src/LuaEngine/CreatureMethods.h b/src/LuaEngine/CreatureMethods.h index f616399..944f5c7 100644 --- a/src/LuaEngine/CreatureMethods.h +++ b/src/LuaEngine/CreatureMethods.h @@ -393,6 +393,262 @@ namespace LuaCreature return 1; } + /** -- NPCBOT Start */ +// #if defined(AZEROTHCORE) + /** + * Return `true` if the [Creature] is a NPCBot, + * @return bool isNPCBot + */ + int IsNPCBot(lua_State* L, Creature* creature) + { + Eluna::Push(L, creature->IsNPCBot()); + return 1; + } + + /** + * Returns the [Creature]'s bot owner. + * @return [Player] botOwner + */ + int GetBotOwner(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + if (ai) { + Eluna::Push(L, ai->GetBotOwner()); + return 1; + } + else { + return 0; + } + } + + int GetBotOwnerGUID(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + if (ai) { + Eluna::Push(L, ai->GetBotOwnerGuid()); + return 1; + } + else { + return 0; + } + } + + /** + * Returns the [Creature]'s bot class. + * @return unint8 botClassID + */ + int GetBotClass(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + Eluna::Push(L, creature->GetBotClass()); + return 1; + } + + /** + * Get the [Creature]'s bot roles Tank, Healer, Damage that are enabled as a mask. + * @return uint32 botRoles + */ + int GetBotRoles(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + Eluna::Push(L, creature->GetBotRoles()); + return 1; + } + + /** + * Returns `true` if the [Creature] is has an assigned role as tank. + * @return bool isTank + */ + int IsBotTank(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + Eluna::Push(L, ai->IsTank()); + return 1; + } + /** + * Returns `true` if the [Creature] is has an assigned role as off-tank. + * @return bool isTank + */ + int IsBotOffTank(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + Eluna::Push(L, ai->IsOffTank()); + return 1; + } + + /** + * Returns `true` if the [Creature] is free and not assigned to a player + * @return bool isFree + */ + int IsFreeBot(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + Eluna::Push(L, creature->IsFreeBot()); + return 1; + } + + /** + * Get the [Creature]'s bot average item level of equipped items. + * @return float botAverageItemLevel + */ + int GetBotAverageItemLevel(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + Eluna::Push(L, creature->GetBotAverageItemLevel()); + return 1; + } + + int GetBotEquipment(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + if(creature->IsFreeBot()) + return 0; + + uint32 slot = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, creature->GetBotEquips(slot)); + return 1; + } + + int GetBotStat(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + uint8 botstat = Eluna::CHECKVAL(L, 2); + Eluna::Push(L, creature->GetTotalBotStat(BotStatMods(botstat))); + + return 1; + } + + int GetTalentSpec(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + Eluna::Push(L, ai->GetSpec()); + return 1; + } + + int BotEquipItem(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + // If this bot is not owned by a player return. + if(creature->IsFreeBot()) + return 0; + + // if the entry passed in was an item object + Item* item = Eluna::CHECKOBJ(L, 2, false); + uint32 slot = Eluna::CHECKVAL(L, 3); + Player* owner = creature->GetBotOwner(); + + // If an item entry was passed in instead + if(!item) + { + uint32 itemid = Eluna::CHECKVAL(L, 2); + item = owner->GetItemByEntry(itemid); + } + + if(slot > EQUIPMENT_SLOT_END) + return 0; + + bool result = creature->EquipItem(slot, item, owner->GetGUID()); + Eluna::Push(L, result); + return 1; + } + + int BotCanEquipItem(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + // If this bot is not owned by a player return. + if(creature->IsFreeBot()) + return 0; + + // if the entry passed in was an item object + uint32 entry = Eluna::CHECKVAL(L, 2); + uint32 slot = Eluna::CHECKVAL(L, 3); + + // If an item entry was passed in instead + if(entry) + { + const ItemTemplate* proto = eObjectMgr->GetItemTemplate(entry); + if(!proto) + return luaL_argerror(L, 1, "valid ItemEntry expected in BotCanEquipItem"); + + if(slot > EQUIPMENT_SLOT_END) + return luaL_argerror(L, 1, "valie slot expected in BotCanEquipItem"); + + bot_ai* ai = creature->GetBotAI(); + bool result = ai->CanEquip(proto, slot, true); + Eluna::Push(L, result); + + } + return 1; + } + + int BotUnequipItem(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + // If this bot is not owned by a player return. + if(creature->IsFreeBot()) + return 0; + + uint32 slot = Eluna::CHECKVAL(L, 2); + Player* owner = creature->GetBotOwner(); + + bot_ai* ai = creature->GetBotAI(); + bool result = ai->UnequipItem(slot, owner->GetGUID()); + Eluna::Push(L, result); + return 1; + } + + int GetBotDump(lua_State* L, Creature* creature) + { + if(!creature->IsNPCBot()) + return 0; + + bot_ai* ai = creature->GetBotAI(); + Player* owner = creature->GetBotOwner(); + const char* dump = ai->BotDump(owner, creature); + + if(!dump) + return luaL_argerror(L, 1, "BotDump failed for bot."); + + Eluna::Push(L, dump); + return 1; + } + +// #endif + /** -- NPCBot End */ + #if defined(TRINITY) || defined(AZEROTHCORE) /** * Returns `true` if the [Creature] is an invisible trigger, @@ -1017,7 +1273,7 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList(); creature->SetUInt32Value(UNIT_NPC_FLAGS, flags); return 0; } - + /** * Sets the [Creature]'s Unit flags to `flags`. * diff --git a/src/LuaEngine/ElunaIncludes.h b/src/LuaEngine/ElunaIncludes.h index 26f8c0c..c2993e4 100644 --- a/src/LuaEngine/ElunaIncludes.h +++ b/src/LuaEngine/ElunaIncludes.h @@ -80,6 +80,13 @@ #include "ArenaTeam.h" #endif +/** -- NPCBOT Start */ +#include "botdatamgr.h" +#include "botmgr.h" +#include "botcommon.h" +#include "bot_ai.h" +/** -- NPCBOT End */ + #ifndef CLASSIC typedef Opcodes OpcodesList; #endif @@ -120,6 +127,14 @@ typedef Opcodes OpcodesList; #define eObjectAccessor() ObjectAccessor:: #endif +/** -- NPCBOT Start */ +#if defined AZEROTHCORE +#define eBotMgr (sBotMgr) +#define eBotDataMgr (sBotDataMgr) +#endif +/** -- NPCBOT End */ + + #ifdef CATA #define NUM_MSG_TYPES NUM_OPCODE_HANDLERS #endif diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index a4c75b0..b381dd6 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -928,6 +928,33 @@ ElunaRegister CreatureMethods[] = { "MoveWaypoint", &LuaCreature::MoveWaypoint }, { "UpdateEntry", &LuaCreature::UpdateEntry }, + + /** -- NPCBOT Start */ +#if defined(AZEROTHCORE) + + // Getters & Flags + { "IsNPCBot", &LuaCreature::IsNPCBot }, + { "GetBotOwner", &LuaCreature::GetBotOwner }, + { "GetBotOwnerGUID", &LuaCreature::GetBotOwnerGUID }, + { "GetBotClass", &LuaCreature::GetBotClass }, + { "GetBotRoles", &LuaCreature::GetBotRoles }, + { "GetTalentSpec", &LuaCreature::GetTalentSpec }, + { "IsBotTank", &LuaCreature::IsBotTank }, + { "IsBotOffTank", &LuaCreature::IsBotOffTank }, + { "IsFreeBot", &LuaCreature::IsFreeBot }, + { "GetBotAverageItemLevel", &LuaCreature::GetBotAverageItemLevel }, + { "GetBotEquipment", &LuaCreature::GetBotEquipment }, + { "GetBotStat", &LuaCreature::GetBotStat }, + { "GetBotDump", &LuaCreature::GetBotDump }, + + + // Setters + { "BotEquipItem", &LuaCreature::BotEquipItem }, + { "BotCanEquipItem", &LuaCreature::BotCanEquipItem }, + { "BotUnequipBotItem", &LuaCreature::BotUnequipItem }, +#endif + /** -- NPCBOT End */ + { NULL, NULL } };