mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
CRLF replaced with LF
This commit is contained in:
@@ -1,74 +1,74 @@
|
|||||||
#include "OpenItemAction.h"
|
#include "OpenItemAction.h"
|
||||||
#include "PlayerbotAI.h"
|
#include "PlayerbotAI.h"
|
||||||
#include "ItemTemplate.h"
|
#include "ItemTemplate.h"
|
||||||
#include "WorldPacket.h"
|
#include "WorldPacket.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "ObjectMgr.h"
|
#include "ObjectMgr.h"
|
||||||
|
|
||||||
bool OpenItemAction::Execute(Event event)
|
bool OpenItemAction::Execute(Event event)
|
||||||
{
|
{
|
||||||
bool foundOpenable = false;
|
bool foundOpenable = false;
|
||||||
|
|
||||||
// Check main inventory slots
|
// Check main inventory slots
|
||||||
for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
|
for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot)
|
||||||
{
|
{
|
||||||
Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
||||||
|
|
||||||
if (item && CanOpenItem(item))
|
if (item && CanOpenItem(item))
|
||||||
{
|
{
|
||||||
OpenItem(item, INVENTORY_SLOT_BAG_0, slot);
|
OpenItem(item, INVENTORY_SLOT_BAG_0, slot);
|
||||||
foundOpenable = true;
|
foundOpenable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check items in the bags
|
// Check items in the bags
|
||||||
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag)
|
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag)
|
||||||
{
|
{
|
||||||
Bag* bagItem = bot->GetBagByPos(bag);
|
Bag* bagItem = bot->GetBagByPos(bag);
|
||||||
if (!bagItem)
|
if (!bagItem)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot)
|
for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot)
|
||||||
{
|
{
|
||||||
Item* item = bot->GetItemByPos(bag, slot);
|
Item* item = bot->GetItemByPos(bag, slot);
|
||||||
|
|
||||||
if (item && CanOpenItem(item))
|
if (item && CanOpenItem(item))
|
||||||
{
|
{
|
||||||
OpenItem(item, bag, slot);
|
OpenItem(item, bag, slot);
|
||||||
foundOpenable = true;
|
foundOpenable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no openable items found
|
// If no openable items found
|
||||||
if (!foundOpenable)
|
if (!foundOpenable)
|
||||||
{
|
{
|
||||||
botAI->TellError("No openable items in inventory.");
|
botAI->TellError("No openable items in inventory.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundOpenable;
|
return foundOpenable;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenItemAction::CanOpenItem(Item* item)
|
bool OpenItemAction::CanOpenItem(Item* item)
|
||||||
{
|
{
|
||||||
if (!item)
|
if (!item)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ItemTemplate const* itemTemplate = item->GetTemplate();
|
ItemTemplate const* itemTemplate = item->GetTemplate();
|
||||||
if (!itemTemplate)
|
if (!itemTemplate)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if the item has the openable flag
|
// Check if the item has the openable flag
|
||||||
return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT;
|
return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenItemAction::OpenItem(Item* item, uint8 bag, uint8 slot)
|
void OpenItemAction::OpenItem(Item* item, uint8 bag, uint8 slot)
|
||||||
{
|
{
|
||||||
WorldPacket packet(CMSG_OPEN_ITEM);
|
WorldPacket packet(CMSG_OPEN_ITEM);
|
||||||
packet << bag << slot;
|
packet << bag << slot;
|
||||||
bot->GetSession()->HandleOpenItemOpcode(packet);
|
bot->GetSession()->HandleOpenItemOpcode(packet);
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
out << "Opened item: " << item->GetTemplate()->Name1;
|
out << "Opened item: " << item->GetTemplate()->Name1;
|
||||||
botAI->TellMaster(out.str());
|
botAI->TellMaster(out.str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license,
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license,
|
||||||
* you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
* you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _PLAYERBOT_OPENITEMACTION_H
|
#ifndef _PLAYERBOT_OPENITEMACTION_H
|
||||||
#define _PLAYERBOT_OPENITEMACTION_H
|
#define _PLAYERBOT_OPENITEMACTION_H
|
||||||
|
|
||||||
#include "Action.h"
|
#include "Action.h"
|
||||||
|
|
||||||
class Player;
|
class Player;
|
||||||
class Item;
|
class Item;
|
||||||
class Event;
|
class Event;
|
||||||
|
|
||||||
class OpenItemAction : public Action
|
class OpenItemAction : public Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") { }
|
OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") { }
|
||||||
|
|
||||||
// The main function that is executed when the action is triggered
|
// The main function that is executed when the action is triggered
|
||||||
bool Execute(Event event) override;
|
bool Execute(Event event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Checks if the given item can be opened (i.e., has the openable flag)
|
// Checks if the given item can be opened (i.e., has the openable flag)
|
||||||
bool CanOpenItem(Item* item);
|
bool CanOpenItem(Item* item);
|
||||||
|
|
||||||
// Performs the action of opening the item
|
// Performs the action of opening the item
|
||||||
void OpenItem(Item* item, uint8 bag, uint8 slot);
|
void OpenItem(Item* item, uint8 bag, uint8 slot);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user