Added support for new NPC Bot commands

This commit is contained in:
2024-02-06 17:59:00 -05:00
parent d0dbc0c349
commit 4111d20bc3
3 changed files with 250 additions and 7 deletions

View File

@@ -394,22 +394,233 @@ namespace LuaCreature
}
/** -- NPCBOT Start */
#if defined(AZEROTHCORE)
// #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;
Eluna::Push(L, creature->GetBotOwner());
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;
}
#endif
/**
* 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 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;
}
// #endif
/** -- NPCBot End */
#if defined(TRINITY) || defined(AZEROTHCORE)
@@ -1025,7 +1236,7 @@ auto const& threatlist = creature->GetThreatMgr().GetThreatList();
creature->SetUInt32Value(UNIT_NPC_FLAGS, flags);
return 0;
}
/**
* Sets the [Creature]'s Unit flags to `flags`.
*

View File

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

View File

@@ -912,9 +912,26 @@ ElunaRegister<Creature> CreatureMethods[] =
/** -- NPCBOT Start */
#if defined(AZEROTHCORE)
#if defined(AZEROTHCORE)
// Getters & Flags
{ "IsNPCBot", &LuaCreature::IsNPCBot },
{ "GetBotOwner", }
{ "GetBotOwner", &LuaCreature::GetBotOwner },
{ "GetBotOwnerGUID", &LuaCreature::GetBotOwnerGUID },
{ "GetBotClass", &LuaCreature::GetBotClass },
{ "GetBotRoles", &LuaCreature::GetBotRoles },
{ "IsBotTank", &LuaCreature::IsBotTank },
{ "IsBotOffTank", &LuaCreature::IsBotOffTank },
{ "IsFreeBot", &LuaCreature::IsFreeBot },
{ "GetBotAverageItemLevel", &LuaCreature::GetBotAverageItemLevel },
{ "GetBotEquipment", &LuaCreature::GetBotEquipment },
{ "GetBotStat", &LuaCreature::GetBotStat },
// Setters
{ "BotEquipItem", &LuaCreature::BotEquipItem },
{ "BotCanEquipItem", &LuaCreature::BotCanEquipItem },
{ "BotUnequipBotItem", &LuaCreature::BotUnequipItem },
#endif
/** -- NPCBOT End */