TrinityCore
cs_ahbot.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ScriptMgr.h"
19#include "AuctionHouseBot.h"
20#include "Chat.h"
21#include "ChatCommand.h"
22#include "Language.h"
23#include "RBAC.h"
24
25using namespace Trinity::ChatCommands;
26
27static std::unordered_map<AuctionQuality, uint32> const ahbotQualityLangIds =
28{
36};
37
39{
40public:
41 ahbot_commandscript(): CommandScript("ahbot_commandscript") {}
42
44 {
45 static ChatCommandTable ahbotItemsAmountCommandTable =
46 {
47 { "gray", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GRAY>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GRAY, Console::Yes },
48 { "white", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_WHITE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_WHITE, Console::Yes },
49 { "green", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GREEN>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GREEN, Console::Yes },
50 { "blue", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_BLUE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_BLUE, Console::Yes },
51 { "purple", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_PURPLE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_PURPLE, Console::Yes },
52 { "orange", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_ORANGE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_ORANGE, Console::Yes },
53 { "yellow", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_YELLOW>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_YELLOW, Console::Yes },
55 };
56
57 static ChatCommandTable ahbotItemsRatioCommandTable =
58 {
59 { "alliance", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_ALLIANCE>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_ALLIANCE, Console::Yes },
60 { "horde", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_HORDE>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_HORDE, Console::Yes },
61 { "neutral", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_NEUTRAL>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_NEUTRAL, Console::Yes },
63 };
64
65 static ChatCommandTable ahbotCommandTable =
66 {
67 { "items", ahbotItemsAmountCommandTable },
68 { "ratio", ahbotItemsRatioCommandTable },
72 };
73
74 static ChatCommandTable commandTable =
75 {
76 { "ahbot", ahbotCommandTable },
77 };
78
79 return commandTable;
80 }
81
82 static bool HandleAHBotItemsAmountCommand(ChatHandler* handler, std::array<uint32, MAX_AUCTION_QUALITY> items)
83 {
84 sAuctionBot->SetItemsAmount(items);
85
86 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
87 handler->PSendSysMessage(LANG_AHBOT_ITEMS_AMOUNT, handler->GetTrinityString(ahbotQualityLangIds.at(quality)), sAuctionBotConfig->GetConfigItemQualityAmount(quality));
88
89 return true;
90 }
91
92 template <AuctionQuality Q>
94 {
95 sAuctionBot->SetItemsAmountForQuality(Q, amount);
97 sAuctionBotConfig->GetConfigItemQualityAmount(Q));
98
99 return true;
100 }
101
102 static bool HandleAHBotItemsRatioCommand(ChatHandler* handler, uint32 alliance, uint32 horde, uint32 neutral)
103 {
104 sAuctionBot->SetItemsRatio(alliance, horde, neutral);
105
106 for (AuctionHouseType type : EnumUtils::Iterate<AuctionHouseType>())
107 handler->PSendSysMessage(LANG_AHBOT_ITEMS_RATIO, AuctionBotConfig::GetHouseTypeName(type), sAuctionBotConfig->GetConfigItemAmountRatio(type));
108 return true;
109 }
110
111 template<AuctionHouseType H>
113 {
114 sAuctionBot->SetItemsRatioForHouse(H, ratio);
116 return true;
117 }
118
119 static bool HandleAHBotRebuildCommand(ChatHandler* /*handler*/, Optional<EXACT_SEQUENCE("all")> all)
120 {
121 sAuctionBot->Rebuild(all.has_value());
122 return true;
123 }
124
126 {
127 sAuctionBot->ReloadAllConfig();
129 return true;
130 }
131
133 {
134 std::unordered_map<AuctionHouseType, AuctionHouseBotStatusInfoPerType> statusInfo;
135 sAuctionBot->PrepareStatusInfos(statusInfo);
136
137 WorldSession* session = handler->GetSession();
138
139 if (!session)
140 {
144 }
145 else
147
149
151 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount,
152 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount,
153 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount,
154 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount +
155 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount +
156 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount);
157
158 if (all)
159 {
167
168 if (!session)
169 {
173 }
174 else
176
177 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
178 handler->PSendSysMessage(fmtId, handler->GetTrinityString(ahbotQualityLangIds.at(quality)),
179 statusInfo[AUCTION_HOUSE_ALLIANCE].QualityInfo.at(quality),
180 statusInfo[AUCTION_HOUSE_HORDE].QualityInfo.at(quality),
181 statusInfo[AUCTION_HOUSE_NEUTRAL].QualityInfo.at(quality),
182 sAuctionBotConfig->GetConfigItemQualityAmount(quality));
183 }
184
185 if (!session)
187
188 return true;
189 }
190
191};
192
193template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GRAY>(ChatHandler* handler, uint32 amount);
194template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_WHITE>(ChatHandler* handler, uint32 amount);
195template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GREEN>(ChatHandler* handler, uint32 amount);
196template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_BLUE>(ChatHandler* handler, uint32 amount);
197template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_PURPLE>(ChatHandler* handler, uint32 amount);
198template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_ORANGE>(ChatHandler* handler, uint32 amount);
199template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_YELLOW>(ChatHandler* handler, uint32 amount);
200
201template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_ALLIANCE>(ChatHandler* handler, uint32 ratio);
202template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_HORDE>(ChatHandler* handler, uint32 ratio);
203template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_NEUTRAL>(ChatHandler* handler, uint32 ratio);
204
206{
208}
@ CONFIG_AHBOT_HORDE_ITEM_AMOUNT_RATIO
@ CONFIG_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO
@ CONFIG_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO
#define sAuctionBot
AuctionQuality
@ AUCTION_QUALITY_ORANGE
@ AUCTION_QUALITY_WHITE
@ AUCTION_QUALITY_PURPLE
@ AUCTION_QUALITY_BLUE
@ AUCTION_QUALITY_YELLOW
@ AUCTION_QUALITY_GREEN
@ AUCTION_QUALITY_GRAY
AuctionHouseType
@ AUCTION_HOUSE_NEUTRAL
@ AUCTION_HOUSE_HORDE
@ AUCTION_HOUSE_ALLIANCE
#define sAuctionBotConfig
#define EXACT_SEQUENCE(str)
uint32_t uint32
Definition: Define.h:142
@ LANG_AHBOT_STATUS_TITLE1_CHAT
Definition: Language.h:934
@ LANG_AHBOT_QUALITY_ORANGE
Definition: Language.h:946
@ LANG_AHBOT_STATUS_ITEM_COUNT
Definition: Language.h:937
@ LANG_AHBOT_STATUS_ITEM_RATIO
Definition: Language.h:938
@ LANG_AHBOT_STATUS_MIDBAR_CONSOLE
Definition: Language.h:932
@ LANG_AHBOT_QUALITY_BLUE
Definition: Language.h:944
@ LANG_AHBOT_STATUS_TITLE2_CONSOLE
Definition: Language.h:939
@ LANG_AHBOT_STATUS_FORMAT_CHAT
Definition: Language.h:936
@ LANG_AHBOT_ITEMS_AMOUNT
Definition: Language.h:948
@ LANG_AHBOT_STATUS_FORMAT_CONSOLE
Definition: Language.h:935
@ LANG_AHBOT_QUALITY_GREEN
Definition: Language.h:943
@ LANG_AHBOT_STATUS_BAR_CONSOLE
Definition: Language.h:931
@ LANG_AHBOT_QUALITY_YELLOW
Definition: Language.h:947
@ LANG_AHBOT_RELOAD_OK
Definition: Language.h:930
@ LANG_AHBOT_STATUS_TITLE2_CHAT
Definition: Language.h:940
@ LANG_AHBOT_ITEMS_RATIO
Definition: Language.h:949
@ LANG_AHBOT_QUALITY_WHITE
Definition: Language.h:942
@ LANG_AHBOT_QUALITY_PURPLE
Definition: Language.h:945
@ LANG_AHBOT_STATUS_TITLE1_CONSOLE
Definition: Language.h:933
@ LANG_AHBOT_QUALITY_GRAY
Definition: Language.h:941
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Role Based Access Control related classes definition.
static char const * GetHouseTypeName(AuctionHouseType houseType)
WorldSession * GetSession()
Definition: Chat.h:42
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:48
Player session in the World.
Definition: WorldSession.h:963
static bool HandleAHBotStatusCommand(ChatHandler *handler, Optional< EXACT_SEQUENCE("all")> all)
Definition: cs_ahbot.cpp:132
static bool HandleAHBotItemsRatioHouseCommand(ChatHandler *handler, uint32 ratio)
Definition: cs_ahbot.cpp:112
static bool HandleAHBotRebuildCommand(ChatHandler *, Optional< EXACT_SEQUENCE("all")> all)
Definition: cs_ahbot.cpp:119
static bool HandleAHBotItemsAmountCommand(ChatHandler *handler, std::array< uint32, MAX_AUCTION_QUALITY > items)
Definition: cs_ahbot.cpp:82
ChatCommandTable GetCommands() const override
Definition: cs_ahbot.cpp:43
static bool HandleAHBotItemsAmountQualityCommand(ChatHandler *handler, uint32 amount)
Definition: cs_ahbot.cpp:93
static bool HandleAHBotReloadCommand(ChatHandler *handler)
Definition: cs_ahbot.cpp:125
static bool HandleAHBotItemsRatioCommand(ChatHandler *handler, uint32 alliance, uint32 horde, uint32 neutral)
Definition: cs_ahbot.cpp:102
void AddSC_ahbot_commandscript()
Definition: cs_ahbot.cpp:205
static std::unordered_map< AuctionQuality, uint32 > const ahbotQualityLangIds
Definition: cs_ahbot.cpp:27
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
@ RBAC_PERM_COMMAND_AHBOT_RATIO
Definition: RBAC.h:659
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_BLUE
Definition: RBAC.h:655
@ RBAC_PERM_COMMAND_AHBOT_REBUILD
Definition: RBAC.h:663
@ RBAC_PERM_COMMAND_AHBOT_ITEMS
Definition: RBAC.h:651
@ RBAC_PERM_COMMAND_AHBOT_RELOAD
Definition: RBAC.h:664
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_YELLOW
Definition: RBAC.h:658
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_GREEN
Definition: RBAC.h:654
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_WHITE
Definition: RBAC.h:653
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_GRAY
Definition: RBAC.h:652
@ RBAC_PERM_COMMAND_AHBOT_RATIO_ALLIANCE
Definition: RBAC.h:660
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_PURPLE
Definition: RBAC.h:656
@ RBAC_PERM_COMMAND_AHBOT_RATIO_HORDE
Definition: RBAC.h:661
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_ORANGE
Definition: RBAC.h:657
@ RBAC_PERM_COMMAND_AHBOT_RATIO_NEUTRAL
Definition: RBAC.h:662
@ RBAC_PERM_COMMAND_AHBOT_STATUS
Definition: RBAC.h:665