mod-playerbots/src/strategy/actions/OpenItemAction.cpp

34 lines
875 B
C++

#include "OpenItemAction.h"
#include "PlayerbotAI.h"
#include "ItemTemplate.h"
#include "WorldPacket.h"
#include "Player.h"
#include "ObjectMgr.h"
bool OpenItemAction::Execute(Event event)
{
bool foundOpenable = false;
Item* item = botAI->FindOpenableItem();
if (item)
{
uint8 bag = item->GetBagSlot(); // Retrieves the bag slot (0 for main inventory)
uint8 slot = item->GetSlot(); // Retrieves the actual slot inside the bag
OpenItem(item, bag, slot);
foundOpenable = true;
}
return foundOpenable;
}
void OpenItemAction::OpenItem(Item* item, uint8 bag, uint8 slot)
{
WorldPacket packet(CMSG_OPEN_ITEM);
packet << bag << slot;
bot->GetSession()->HandleOpenItemOpcode(packet);
std::ostringstream out;
out << "Opened item: " << item->GetTemplate()->Name1;
botAI->TellMaster(out.str());
}