1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Chat.h"
#include "CommandScript.h"
#include "ObjectMgr.h"
#include "Player.h"
constexpr std::array<std::string_view, MAX_ITEM_QUALITY> itemQualityToString =
{
"poor",
"normal",
"uncommon",
"rare",
"epic",
"legendary",
"artifact",
"all"
};
using namespace Acore::ChatCommands;
class bg_commandscript : public CommandScript
{
public:
bg_commandscript() : CommandScript("bg_commandscript") { }
ChatCommandTable GetCommands() const override
{
static ChatCommandTable commandTable =
{
{ "bags clear", HandleBagsClearCommand, SEC_GAMEMASTER, Console::No },
};
return commandTable;
}
static bool HandleBagsClearCommand(ChatHandler* handler, std::string_view args)
{
if (args.empty())
{
return false;
}
Player* player = handler->GetSession()->GetPlayer();
if (!player)
{
return false;
}
uint8 itemQuality = MAX_ITEM_QUALITY;
for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
{
if (args == itemQualityToString[i])
{
itemQuality = i;
break;
}
}
if (itemQuality == MAX_ITEM_QUALITY)
{
return false;
}
std::array<uint32, MAX_ITEM_QUALITY> removedItems = { };
// in inventory
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
{
if (Item* item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
if (ItemTemplate const* itemTemplate = item->GetTemplate())
{
if (itemTemplate->Quality <= itemQuality)
{
player->DestroyItem(INVENTORY_SLOT_BAG_0, i, true);
++removedItems[itemTemplate->Quality];
}
}
}
}
// in inventory bags
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
{
if (Bag* bag = player->GetBagByPos(i))
{
for (uint32 j = 0; j < bag->GetBagSize(); j++)
{
if (Item* item = bag->GetItemByPos(j))
{
if (ItemTemplate const* itemTemplate = item->GetTemplate())
{
if (itemTemplate->Quality <= itemQuality)
{
player->DestroyItem(i, j, true);
++removedItems[itemTemplate->Quality];
}
}
}
}
}
}
std::ostringstream str;
str << "Removed ";
if (itemQuality == ITEM_QUALITY_HEIRLOOM)
{
str << "all";
}
else
{
bool initialize = true;
for (uint8 i = ITEM_QUALITY_POOR; i < MAX_ITEM_QUALITY; ++i)
{
if (uint32 itemCount = removedItems[i])
{
std::string_view itemQualityString = itemQualityToString[i];
if (!initialize)
{
str << ", ";
}
str << "|c";
str << std::hex << ItemQualityColors[i] << std::dec;
str << itemCount << " " << itemQualityString << "|r";
initialize = false;
}
}
}
str << " items from your bags.";
handler->SendSysMessage(str.str().c_str());
return true;
};
};
void AddSC_bag_commandscript()
{
new bg_commandscript();
}
|