AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
bg_commandscript Class Reference
Inheritance diagram for bg_commandscript:
CommandScript ScriptObject

Public Member Functions

 bg_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleBagsClearCommand (ChatHandler *handler, std::string_view args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ bg_commandscript()

bg_commandscript::bg_commandscript ( )
inline
40: CommandScript("bg_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable bg_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

43 {
44 static ChatCommandTable commandTable =
45 {
46 { "bags clear", HandleBagsClearCommand, SEC_GAMEMASTER, Console::No },
47 };
48
49 return commandTable;
50 }
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleBagsClearCommand(ChatHandler *handler, std::string_view args)
Definition: cs_bag.cpp:52

References HandleBagsClearCommand(), and SEC_GAMEMASTER.

◆ HandleBagsClearCommand()

static bool bg_commandscript::HandleBagsClearCommand ( ChatHandler handler,
std::string_view  args 
)
inlinestatic
53 {
54 if (args.empty())
55 {
56 return false;
57 }
58
59 Player* player = handler->GetSession()->GetPlayer();
60 if (!player)
61 {
62 return false;
63 }
64
65 uint8 itemQuality = MAX_ITEM_QUALITY;
66 for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
67 {
68 if (args == itemQualityToString[i])
69 {
70 itemQuality = i;
71 break;
72 }
73 }
74
75 if (itemQuality == MAX_ITEM_QUALITY)
76 {
77 return false;
78 }
79
80 std::array<uint32, MAX_ITEM_QUALITY> removedItems = { };
81
82 // in inventory
84 {
85 if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
86 {
87 if (ItemTemplate const* itemTemplate = item->GetTemplate())
88 {
89 if (itemTemplate->Quality <= itemQuality)
90 {
91 player->DestroyItem(INVENTORY_SLOT_BAG_0, i, true);
92 ++removedItems[itemTemplate->Quality];
93 }
94 }
95 }
96 }
97
98 // in inventory bags
100 {
101 if (Bag* bag = player->GetBagByPos(i))
102 {
103 for (uint32 j = 0; j < bag->GetBagSize(); j++)
104 {
105 if (Item* item = bag->GetItemByPos(j))
106 {
107 if (ItemTemplate const* itemTemplate = item->GetTemplate())
108 {
109 if (itemTemplate->Quality <= itemQuality)
110 {
111 player->DestroyItem(i, j, true);
112 ++removedItems[itemTemplate->Quality];
113 }
114 }
115 }
116 }
117 }
118 }
119
120 std::ostringstream str;
121 str << "Removed ";
122 if (itemQuality == ITEM_QUALITY_HEIRLOOM)
123 {
124 str << "all";
125 }
126 else
127 {
128 bool initialize = true;
129 for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
130 {
131 if (uint32 itemCount = removedItems[i])
132 {
133 std::string_view itemQualityString = itemQualityToString[i];
134
135 if (!initialize)
136 {
137 str << ", ";
138 }
139
140 str << "|c";
141 str << std::hex << ItemQualityColors[i] << std::dec;
142 str << itemCount << " " << itemQualityString << "|r";
143
144 initialize = false;
145 }
146 }
147 }
148
149 str << " items from your bags.";
150
151 handler->SendSysMessage(str.str().c_str());
152
153 return true;
154 };
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
constexpr std::array< std::string_view, MAX_ITEM_QUALITY > itemQualityToString
Definition: cs_bag.cpp:23
const uint32 ItemQualityColors[MAX_ITEM_QUALITY]
Definition: SharedDefines.h:353
@ ITEM_QUALITY_HEIRLOOM
Definition: SharedDefines.h:336
@ ITEM_QUALITY_POOR
Definition: SharedDefines.h:329
#define MAX_ITEM_QUALITY
Definition: SharedDefines.h:339
@ INVENTORY_SLOT_ITEM_START
Definition: Player.h:705
@ INVENTORY_SLOT_ITEM_END
Definition: Player.h:706
@ INVENTORY_SLOT_BAG_START
Definition: Player.h:699
@ INVENTORY_SLOT_BAG_END
Definition: Player.h:700
#define INVENTORY_SLOT_BAG_0
Definition: Player.h:670
WorldSession * GetSession()
Definition: Chat.h:242
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
Definition: Bag.h:28
Definition: Item.h:220
Definition: ItemTemplate.h:619
Definition: Player.h:1064
Bag * GetBagByPos(uint8 slot) const
Definition: PlayerStorage.cpp:457
Item * GetItemByPos(uint16 pos) const
Definition: PlayerStorage.cpp:441
void DestroyItem(uint8 bag, uint8 slot, bool update)
Definition: PlayerStorage.cpp:3023
Player * GetPlayer() const
Definition: WorldSession.h:362

References Player::DestroyItem(), Player::GetBagByPos(), Player::GetItemByPos(), WorldSession::GetPlayer(), ChatHandler::GetSession(), INVENTORY_SLOT_BAG_0, INVENTORY_SLOT_BAG_END, INVENTORY_SLOT_BAG_START, INVENTORY_SLOT_ITEM_END, INVENTORY_SLOT_ITEM_START, ITEM_QUALITY_HEIRLOOM, ITEM_QUALITY_POOR, ItemQualityColors, itemQualityToString, MAX_ITEM_QUALITY, and ChatHandler::SendSysMessage().

Referenced by GetCommands().