TrinityCore
Loading...
Searching...
No Matches
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 "Language.h"
22#include "RBAC.h"
23
24using namespace Trinity::ChatCommands;
25
36
38{
39public:
40 ahbot_commandscript(): CommandScript("ahbot_commandscript") {}
41
43 {
44 static ChatCommandTable ahbotItemsAmountCommandTable =
45 {
46 { "gray", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GRAY>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GRAY, Console::Yes },
47 { "white", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_WHITE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_WHITE, Console::Yes },
48 { "green", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GREEN>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GREEN, Console::Yes },
49 { "blue", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_BLUE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_BLUE, Console::Yes },
50 { "purple", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_PURPLE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_PURPLE, Console::Yes },
51 { "orange", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_ORANGE>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_ORANGE, Console::Yes },
52 { "yellow", HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_YELLOW>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_YELLOW, Console::Yes },
54 };
55
56 static ChatCommandTable ahbotItemsRatioCommandTable =
57 {
58 { "alliance", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_ALLIANCE>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_ALLIANCE, Console::Yes },
59 { "horde", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_HORDE>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_HORDE, Console::Yes },
60 { "neutral", HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_NEUTRAL>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_NEUTRAL, Console::Yes },
62 };
63
64 static ChatCommandTable ahbotCommandTable =
65 {
66 { "items", ahbotItemsAmountCommandTable },
67 { "ratio", ahbotItemsRatioCommandTable },
71 };
72
73 static ChatCommandTable commandTable =
74 {
75 { "ahbot", ahbotCommandTable },
76 };
77
78 return commandTable;
79 }
80
81 static bool HandleAHBotItemsAmountCommand(ChatHandler* handler, std::array<uint32, MAX_AUCTION_QUALITY> items)
82 {
83 sAuctionBot->SetItemsAmount(items);
84
85 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
86 handler->PSendSysMessage(LANG_AHBOT_ITEMS_AMOUNT, handler->GetTrinityString(ahbotQualityLangIds.at(quality)), sAuctionBotConfig->GetConfigItemQualityAmount(quality));
87
88 return true;
89 }
90
91 template <AuctionQuality Q>
93 {
94 sAuctionBot->SetItemsAmountForQuality(Q, amount);
96 sAuctionBotConfig->GetConfigItemQualityAmount(Q));
97
98 return true;
99 }
100
101 static bool HandleAHBotItemsRatioCommand(ChatHandler* handler, uint32 alliance, uint32 horde, uint32 neutral)
102 {
103 sAuctionBot->SetItemsRatio(alliance, horde, neutral);
104
105 for (AuctionHouseType type : EnumUtils::Iterate<AuctionHouseType>())
106 handler->PSendSysMessage(LANG_AHBOT_ITEMS_RATIO, AuctionBotConfig::GetHouseTypeName(type), sAuctionBotConfig->GetConfigItemAmountRatio(type));
107 return true;
108 }
109
110 template<AuctionHouseType H>
112 {
113 sAuctionBot->SetItemsRatioForHouse(H, ratio);
115 return true;
116 }
117
118 static bool HandleAHBotRebuildCommand(ChatHandler* /*handler*/, Optional<EXACT_SEQUENCE("all")> all)
119 {
120 sAuctionBot->Rebuild(all.has_value());
121 return true;
122 }
123
125 {
126 sAuctionBot->ReloadAllConfig();
128 return true;
129 }
130
132 {
133 std::unordered_map<AuctionHouseType, AuctionHouseBotStatusInfoPerType> statusInfo;
134 sAuctionBot->PrepareStatusInfos(statusInfo);
135
136 WorldSession* session = handler->GetSession();
137
138 if (!session)
139 {
143 }
144 else
146
148
150 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount,
151 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount,
152 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount,
153 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount +
154 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount +
155 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount);
156
157 if (all)
158 {
166
167 if (!session)
168 {
172 }
173 else
175
176 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
177 handler->PSendSysMessage(fmtId, handler->GetTrinityString(ahbotQualityLangIds.at(quality)),
178 statusInfo[AUCTION_HOUSE_ALLIANCE].QualityInfo.at(quality),
179 statusInfo[AUCTION_HOUSE_HORDE].QualityInfo.at(quality),
180 statusInfo[AUCTION_HOUSE_NEUTRAL].QualityInfo.at(quality),
181 sAuctionBotConfig->GetConfigItemQualityAmount(quality));
182 }
183
184 if (!session)
186
187 return true;
188 }
189
190};
191
192template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GRAY>(ChatHandler* handler, uint32 amount);
193template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_WHITE>(ChatHandler* handler, uint32 amount);
194template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_GREEN>(ChatHandler* handler, uint32 amount);
195template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_BLUE>(ChatHandler* handler, uint32 amount);
196template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_PURPLE>(ChatHandler* handler, uint32 amount);
197template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_ORANGE>(ChatHandler* handler, uint32 amount);
198template bool ahbot_commandscript::HandleAHBotItemsAmountQualityCommand<AUCTION_QUALITY_YELLOW>(ChatHandler* handler, uint32 amount);
199
200template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_ALLIANCE>(ChatHandler* handler, uint32 ratio);
201template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_HORDE>(ChatHandler* handler, uint32 ratio);
202template bool ahbot_commandscript::HandleAHBotItemsRatioHouseCommand<AUCTION_HOUSE_NEUTRAL>(ChatHandler* handler, uint32 ratio);
203
@ 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:133
@ LANG_AHBOT_STATUS_TITLE1_CHAT
Definition Language.h:937
@ LANG_AHBOT_QUALITY_ORANGE
Definition Language.h:949
@ LANG_AHBOT_STATUS_ITEM_COUNT
Definition Language.h:940
@ LANG_AHBOT_STATUS_ITEM_RATIO
Definition Language.h:941
@ LANG_AHBOT_STATUS_MIDBAR_CONSOLE
Definition Language.h:935
@ LANG_AHBOT_QUALITY_BLUE
Definition Language.h:947
@ LANG_AHBOT_STATUS_TITLE2_CONSOLE
Definition Language.h:942
@ LANG_AHBOT_STATUS_FORMAT_CHAT
Definition Language.h:939
@ LANG_AHBOT_ITEMS_AMOUNT
Definition Language.h:951
@ LANG_AHBOT_STATUS_FORMAT_CONSOLE
Definition Language.h:938
@ LANG_AHBOT_QUALITY_GREEN
Definition Language.h:946
@ LANG_AHBOT_STATUS_BAR_CONSOLE
Definition Language.h:934
@ LANG_AHBOT_QUALITY_YELLOW
Definition Language.h:950
@ LANG_AHBOT_RELOAD_OK
Definition Language.h:933
@ LANG_AHBOT_STATUS_TITLE2_CHAT
Definition Language.h:943
@ LANG_AHBOT_ITEMS_RATIO
Definition Language.h:952
@ LANG_AHBOT_QUALITY_WHITE
Definition Language.h:945
@ LANG_AHBOT_QUALITY_PURPLE
Definition Language.h:948
@ LANG_AHBOT_STATUS_TITLE1_CONSOLE
Definition Language.h:936
@ LANG_AHBOT_QUALITY_GRAY
Definition Language.h:944
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:46
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:69
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
virtual char const * GetTrinityString(uint32 entry) const
Definition Chat.cpp:36
Player session in the World.
static bool HandleAHBotStatusCommand(ChatHandler *handler, Optional< EXACT_SEQUENCE("all")> all)
Definition cs_ahbot.cpp:131
static bool HandleAHBotItemsRatioHouseCommand(ChatHandler *handler, uint32 ratio)
Definition cs_ahbot.cpp:111
static bool HandleAHBotRebuildCommand(ChatHandler *, Optional< EXACT_SEQUENCE("all")> all)
Definition cs_ahbot.cpp:118
static bool HandleAHBotItemsAmountCommand(ChatHandler *handler, std::array< uint32, MAX_AUCTION_QUALITY > items)
Definition cs_ahbot.cpp:81
ChatCommandTable GetCommands() const override
Definition cs_ahbot.cpp:42
static bool HandleAHBotItemsAmountQualityCommand(ChatHandler *handler, uint32 amount)
Definition cs_ahbot.cpp:92
static bool HandleAHBotReloadCommand(ChatHandler *handler)
Definition cs_ahbot.cpp:124
static bool HandleAHBotItemsRatioCommand(ChatHandler *handler, uint32 alliance, uint32 horde, uint32 neutral)
Definition cs_ahbot.cpp:101
void AddSC_ahbot_commandscript()
Definition cs_ahbot.cpp:204
static std::unordered_map< AuctionQuality, uint32 > const ahbotQualityLangIds
Definition cs_ahbot.cpp:26
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
@ RBAC_PERM_COMMAND_AHBOT_RATIO
Definition RBAC.h:657
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_BLUE
Definition RBAC.h:653
@ RBAC_PERM_COMMAND_AHBOT_REBUILD
Definition RBAC.h:661
@ RBAC_PERM_COMMAND_AHBOT_ITEMS
Definition RBAC.h:649
@ RBAC_PERM_COMMAND_AHBOT_RELOAD
Definition RBAC.h:662
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_YELLOW
Definition RBAC.h:656
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_GREEN
Definition RBAC.h:652
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_WHITE
Definition RBAC.h:651
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_GRAY
Definition RBAC.h:650
@ RBAC_PERM_COMMAND_AHBOT_RATIO_ALLIANCE
Definition RBAC.h:658
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_PURPLE
Definition RBAC.h:654
@ RBAC_PERM_COMMAND_AHBOT_RATIO_HORDE
Definition RBAC.h:659
@ RBAC_PERM_COMMAND_AHBOT_ITEMS_ORANGE
Definition RBAC.h:655
@ RBAC_PERM_COMMAND_AHBOT_RATIO_NEUTRAL
Definition RBAC.h:660
@ RBAC_PERM_COMMAND_AHBOT_STATUS
Definition RBAC.h:663