From 2947c06a7bec55d23f6428894d2b34d996b849b0 Mon Sep 17 00:00:00 2001 From: Ben Carter Date: Thu, 23 Jan 2025 00:24:26 -0500 Subject: [PATCH] moved NPCBots into own class methods and updated for new core changes --- src/LuaEngine/CreatureMethods.h | 256 ----------------------------- src/LuaEngine/LuaFunctions.cpp | 39 +++-- src/LuaEngine/NpcBotMethods.h | 279 ++++++++++++++++++++++++++++++++ src/LuaEngine/PlayerMethods.h | 26 +-- src/LuaEngine/UnitMethods.h | 4 +- 5 files changed, 317 insertions(+), 287 deletions(-) create mode 100644 src/LuaEngine/NpcBotMethods.h diff --git a/src/LuaEngine/CreatureMethods.h b/src/LuaEngine/CreatureMethods.h index 944f5c7..ef6418c 100644 --- a/src/LuaEngine/CreatureMethods.h +++ b/src/LuaEngine/CreatureMethods.h @@ -393,262 +393,6 @@ 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, diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index b381dd6..52a6824 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -41,6 +41,11 @@ extern "C" #include "ItemTemplateMethods.h" #include "RollMethods.h" +// If this is runnong on NPCBOTS core fork include methods for NpcBot management in Lua +#if defined(MOD_PRESENT_NPCBOTS) +#include "NpcBotMethods.h" +#endif + luaL_Reg GlobalMethods[] = { // Hooks @@ -930,28 +935,28 @@ ElunaRegister CreatureMethods[] = /** -- NPCBOT Start */ -#if defined(AZEROTHCORE) +#if defined(AZEROTHCORE) && defined(MOD_PRESENT_NPCBOTS) // 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 }, + { "IsNPCBot", &LuaNpcBot::IsNPCBot }, + { "GetBotOwner", &LuaNpcBot::GetBotOwner }, + { "GetBotOwnerGUID", &LuaNpcBot::GetBotOwnerGUID }, + { "GetBotClass", &LuaNpcBot::GetBotClass }, + { "GetBotRoles", &LuaNpcBot::GetBotRoles }, + { "GetTalentSpec", &LuaNpcBot::GetTalentSpec }, + { "IsBotTank", &LuaNpcBot::IsBotTank }, + { "IsBotOffTank", &LuaNpcBot::IsBotOffTank }, + { "IsFreeBot", &LuaNpcBot::IsFreeBot }, + { "GetBotAverageItemLevel", &LuaNpcBot::GetBotAverageItemLevel }, + { "GetBotEquipment", &LuaNpcBot::GetBotEquipment }, + { "GetBotStat", &LuaNpcBot::GetBotStat }, + { "GetBotDump", &LuaNpcBot::GetBotDump }, // Setters - { "BotEquipItem", &LuaCreature::BotEquipItem }, - { "BotCanEquipItem", &LuaCreature::BotCanEquipItem }, - { "BotUnequipBotItem", &LuaCreature::BotUnequipItem }, + { "BotEquipItem", &LuaNpcBot::BotEquipItem }, + { "BotCanEquipItem", &LuaNpcBot::BotCanEquipItem }, + { "BotUnequipBotItem", &LuaNpcBot::BotUnequipItem }, #endif /** -- NPCBOT End */ diff --git a/src/LuaEngine/NpcBotMethods.h b/src/LuaEngine/NpcBotMethods.h new file mode 100644 index 0000000..f38f2e2 --- /dev/null +++ b/src/LuaEngine/NpcBotMethods.h @@ -0,0 +1,279 @@ + +#ifndef NPCBOTMETHODS_H +#define NPCBOTMETHODS_H + +#include "bot_ai_eluna.h" + +/*** + * Player controlled bot party members, relies on latest changes to + * NPCBots fork of AzerothCore + * + * Inherits all methods from: [Object], [WorldObject], [Unit] + */ +namespace LuaNpcBot +{ + /** + * 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); + /** + * @fix this to be optional for the bot owner to see the stats + */ + + bot_ai* ai = creature->GetBotAI(); + Eluna::Push(L, ai->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; + + bot_ai* ai = creature->GetBotAI(); + BotAIEluna elunaAi(ai); + bool result = elunaAi.Equip(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, "value slot expected in BotCanEquipItem"); + + bot_ai* ai = creature->GetBotAI(); + bool result = BotAIEluna(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(); + BotAIEluna elunaAi(ai); + bool result = elunaAi.Unequip(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(); + BotAIEluna elunaAi(ai); + std::string dump = elunaAi.BotDump(owner, creature); + + if(dump.empty()) + return luaL_argerror(L, 1, "BotDump failed for bot."); + + Eluna::Push(L, dump); + return 1; + } + +} + +#endif // NPCBOTMETHODS_H diff --git a/src/LuaEngine/PlayerMethods.h b/src/LuaEngine/PlayerMethods.h index a1f8cb2..817b07a 100644 --- a/src/LuaEngine/PlayerMethods.h +++ b/src/LuaEngine/PlayerMethods.h @@ -2480,25 +2480,26 @@ namespace LuaPlayer Unit* unit = Eluna::CHECKOBJ(L, 2); #if defined TRINITY || AZEROTHCORE - AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->GetFaction()); + // AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseFactionFromHouseId(static_cast(unit->GetFaction())); + // AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->GetFaction()); #else - AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit); + // AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit); #endif - if (!ahEntry) - return 0; + // if (!ahEntry) + // return 0; - WorldPacket data(MSG_AUCTION_HELLO, 12); - data << unit->GET_GUID(); + // WorldPacket data(MSG_AUCTION_HELLO, 12); + // data << unit->GET_GUID(); #ifdef TRINITY data << uint32(ahEntry->ID); #else - data << uint32(ahEntry->houseId); + // data << uint32(ahEntry->houseId); #endif - data << uint8(1); + // data << uint8(1); #ifdef CMANGOS - player->GetSession()->SendPacket(data); + // player->GetSession()->SendPacket(data); #else - player->GetSession()->SendPacket(&data); + // player->GetSession()->SendPacket(&data); #endif return 0; } @@ -3804,8 +3805,9 @@ namespace LuaPlayer { std::string msg = Eluna::CHECKVAL(L, 2); if (msg.length() > 0) - player->GetSession()->SendNotification("%s", msg.c_str()); - // ChatHandler(player->GetSession()).SendNotification("{}", msg); -- + + // player->GetSession()->SendNotification("%s", msg.c_str()); + ChatHandler(player->GetSession()).SendNotification("{}", msg); return 0; } diff --git a/src/LuaEngine/UnitMethods.h b/src/LuaEngine/UnitMethods.h index 38c948a..618b516 100644 --- a/src/LuaEngine/UnitMethods.h +++ b/src/LuaEngine/UnitMethods.h @@ -61,7 +61,7 @@ namespace LuaUnit unit->ApplySpellImmune(0, 5, immunity, apply); return 0; } - + /** * The [Unit] modifies a specific stat * @@ -139,7 +139,7 @@ namespace LuaUnit */ int IsRooted(lua_State* L, Unit* unit) { - Eluna::Push(L, unit->isInRoots() || unit->HasUnitMovementFlag(MOVEMENTFLAG_ROOT)); + Eluna::Push(L, unit->HasRootAura() || unit->HasUnitMovementFlag(MOVEMENTFLAG_ROOT)); return 1; }