-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00b16db
commit 7b50803
Showing
2 changed files
with
105 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
#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; | ||
|
||
// Check main inventory slots | ||
for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot) | ||
{ | ||
Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); | ||
|
||
if (item && CanOpenItem(item)) | ||
{ | ||
OpenItem(item, INVENTORY_SLOT_BAG_0, slot); | ||
foundOpenable = true; | ||
} | ||
} | ||
|
||
// Check items in the bags | ||
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag) | ||
{ | ||
Bag* bagItem = bot->GetBagByPos(bag); | ||
if (!bagItem) | ||
continue; | ||
|
||
for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot) | ||
{ | ||
Item* item = bot->GetItemByPos(bag, slot); | ||
|
||
if (item && CanOpenItem(item)) | ||
{ | ||
OpenItem(item, bag, slot); | ||
foundOpenable = true; | ||
} | ||
} | ||
} | ||
|
||
// If no openable items found | ||
if (!foundOpenable) | ||
{ | ||
botAI->TellError("No openable items in inventory."); | ||
} | ||
|
||
return foundOpenable; | ||
} | ||
|
||
bool OpenItemAction::CanOpenItem(Item* item) | ||
{ | ||
if (!item) | ||
return false; | ||
|
||
ItemTemplate const* itemTemplate = item->GetTemplate(); | ||
if (!itemTemplate) | ||
return false; | ||
|
||
// Check if the item has the openable flag | ||
return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT; | ||
} | ||
|
||
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()); | ||
} | ||
#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; | ||
|
||
// Check main inventory slots | ||
for (uint8 slot = EQUIPMENT_SLOT_START; slot < INVENTORY_SLOT_ITEM_END; ++slot) | ||
{ | ||
Item* item = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); | ||
|
||
if (item && CanOpenItem(item)) | ||
{ | ||
OpenItem(item, INVENTORY_SLOT_BAG_0, slot); | ||
foundOpenable = true; | ||
} | ||
} | ||
|
||
// Check items in the bags | ||
for (uint8 bag = INVENTORY_SLOT_BAG_START; bag < INVENTORY_SLOT_BAG_END; ++bag) | ||
{ | ||
Bag* bagItem = bot->GetBagByPos(bag); | ||
if (!bagItem) | ||
continue; | ||
|
||
for (uint32 slot = 0; slot < bagItem->GetBagSize(); ++slot) | ||
{ | ||
Item* item = bot->GetItemByPos(bag, slot); | ||
|
||
if (item && CanOpenItem(item)) | ||
{ | ||
OpenItem(item, bag, slot); | ||
foundOpenable = true; | ||
} | ||
} | ||
} | ||
|
||
// If no openable items found | ||
if (!foundOpenable) | ||
{ | ||
botAI->TellError("No openable items in inventory."); | ||
} | ||
|
||
return foundOpenable; | ||
} | ||
|
||
bool OpenItemAction::CanOpenItem(Item* item) | ||
{ | ||
if (!item) | ||
return false; | ||
|
||
ItemTemplate const* itemTemplate = item->GetTemplate(); | ||
if (!itemTemplate) | ||
return false; | ||
|
||
// Check if the item has the openable flag | ||
return itemTemplate->Flags & ITEM_FLAG_HAS_LOOT; | ||
} | ||
|
||
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#ifndef _PLAYERBOT_OPENITEMACTION_H | ||
#define _PLAYERBOT_OPENITEMACTION_H | ||
|
||
#include "Action.h" | ||
|
||
class Player; | ||
class Item; | ||
class Event; | ||
|
||
class OpenItemAction : public Action | ||
{ | ||
public: | ||
OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") { } | ||
|
||
// The main function that is executed when the action is triggered | ||
bool Execute(Event event) override; | ||
|
||
private: | ||
// Checks if the given item can be opened (i.e., has the openable flag) | ||
bool CanOpenItem(Item* item); | ||
|
||
// Performs the action of opening the item | ||
void OpenItem(Item* item, uint8 bag, uint8 slot); | ||
}; | ||
|
||
#endif | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#ifndef _PLAYERBOT_OPENITEMACTION_H | ||
#define _PLAYERBOT_OPENITEMACTION_H | ||
|
||
#include "Action.h" | ||
|
||
class Player; | ||
class Item; | ||
class Event; | ||
|
||
class OpenItemAction : public Action | ||
{ | ||
public: | ||
OpenItemAction(PlayerbotAI* botAI) : Action(botAI, "open item") { } | ||
|
||
// The main function that is executed when the action is triggered | ||
bool Execute(Event event) override; | ||
|
||
private: | ||
// Checks if the given item can be opened (i.e., has the openable flag) | ||
bool CanOpenItem(Item* item); | ||
|
||
// Performs the action of opening the item | ||
void OpenItem(Item* item, uint8 bag, uint8 slot); | ||
}; | ||
|
||
#endif |