moved NPCBots into own class methods and updated for new core changes

This commit is contained in:
2025-01-23 00:24:26 -05:00
parent fa9b7987d2
commit 2947c06a7b
5 changed files with 317 additions and 287 deletions

View File

@@ -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<uint32>(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<uint8>(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<Item>(L, 2, false);
uint32 slot = Eluna::CHECKVAL<uint32>(L, 3);
Player* owner = creature->GetBotOwner();
// If an item entry was passed in instead
if(!item)
{
uint32 itemid = Eluna::CHECKVAL<uint32>(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<uint32>(L, 2);
uint32 slot = Eluna::CHECKVAL<uint32>(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<uint32>(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,

View File

@@ -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<Creature> 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 */

View File

@@ -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<uint32>(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<uint8>(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<Item>(L, 2, false);
uint32 slot = Eluna::CHECKVAL<uint32>(L, 3);
Player* owner = creature->GetBotOwner();
// If an item entry was passed in instead
if(!item)
{
uint32 itemid = Eluna::CHECKVAL<uint32>(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<uint32>(L, 2);
uint32 slot = Eluna::CHECKVAL<uint32>(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<uint32>(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

View File

@@ -2480,25 +2480,26 @@ namespace LuaPlayer
Unit* unit = Eluna::CHECKOBJ<Unit>(L, 2);
#if defined TRINITY || AZEROTHCORE
AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->GetFaction());
// AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseFactionFromHouseId(static_cast<AuctionHouseId>(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<std::string>(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;
}

View File

@@ -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;
}