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 "ChatCommand.h"
22#include "Language.h"
23#include "RBAC.h"
24
25using namespace Trinity::ChatCommands;
26
37
39{
40public:
41 ahbot_commandscript(): CommandScript("ahbot_commandscript") {}
42
43 template <auto Const>
44 using Wrap = std::integral_constant<decltype(Const), Const>;
45
46 std::span<ChatCommandBuilder const> GetCommands() const override
47 {
48 static ChatCommandTable ahbotItemsAmountCommandTable =
49 {
50 { "gray", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_GRAY>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GRAY, Console::Yes },
51 { "white", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_WHITE>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_WHITE, Console::Yes },
52 { "green", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_GREEN>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_GREEN, Console::Yes },
53 { "blue", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_BLUE>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_BLUE, Console::Yes },
54 { "purple", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_PURPLE>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_PURPLE, Console::Yes },
55 { "orange", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_ORANGE>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_ORANGE, Console::Yes },
56 { "yellow", HandleAHBotItemsAmountQualityCommand<Wrap<AUCTION_QUALITY_YELLOW>>, rbac::RBAC_PERM_COMMAND_AHBOT_ITEMS_YELLOW, Console::Yes },
58 };
59
60 static ChatCommandTable ahbotItemsRatioCommandTable =
61 {
62 { "alliance", HandleAHBotItemsRatioHouseCommand<Wrap<AUCTION_HOUSE_ALLIANCE>>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_ALLIANCE, Console::Yes },
63 { "horde", HandleAHBotItemsRatioHouseCommand<Wrap<AUCTION_HOUSE_HORDE>>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_HORDE, Console::Yes },
64 { "neutral", HandleAHBotItemsRatioHouseCommand<Wrap<AUCTION_HOUSE_NEUTRAL>>, rbac::RBAC_PERM_COMMAND_AHBOT_RATIO_NEUTRAL, Console::Yes },
66 };
67
68 static ChatCommandTable ahbotCommandTable =
69 {
70 { "items", ahbotItemsAmountCommandTable },
71 { "ratio", ahbotItemsRatioCommandTable },
75 };
76
77 static ChatCommandTable commandTable =
78 {
79 { "ahbot", ahbotCommandTable },
80 };
81
82 return commandTable;
83 }
84
85 static bool HandleAHBotItemsAmountCommand(ChatHandler* handler, std::array<uint32, MAX_AUCTION_QUALITY> const& items)
86 {
87 sAuctionBot->SetItemsAmount(items);
88
89 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
90 handler->PSendSysMessage(LANG_AHBOT_ITEMS_AMOUNT, handler->GetTrinityString(AhbotQualityLangIds[quality]), sAuctionBotConfig->GetConfigItemQualityAmount(quality));
91
92 return true;
93 }
94
95 template <typename QConst>
97 {
98 static constexpr AuctionQuality Q = QConst::value;
99 sAuctionBot->SetItemsAmountForQuality(Q, amount);
101 sAuctionBotConfig->GetConfigItemQualityAmount(Q));
102
103 return true;
104 }
105
106 static bool HandleAHBotItemsRatioCommand(ChatHandler* handler, uint32 alliance, uint32 horde, uint32 neutral)
107 {
108 sAuctionBot->SetItemsRatio(alliance, horde, neutral);
109
110 for (AuctionHouseType type : EnumUtils::Iterate<AuctionHouseType>())
111 handler->PSendSysMessage(LANG_AHBOT_ITEMS_RATIO, AuctionBotConfig::GetHouseTypeName(type), sAuctionBotConfig->GetConfigItemAmountRatio(type));
112 return true;
113 }
114
115 template <typename HConst>
117 {
118 static constexpr AuctionHouseType H = HConst::value;
119 sAuctionBot->SetItemsRatioForHouse(H, ratio);
121 return true;
122 }
123
124 static bool HandleAHBotRebuildCommand(ChatHandler* /*handler*/, Optional<EXACT_SEQUENCE("all")> all)
125 {
126 sAuctionBot->Rebuild(all.has_value());
127 return true;
128 }
129
131 {
132 sAuctionBot->ReloadAllConfig();
134 return true;
135 }
136
138 {
139 std::array<AuctionHouseBotStatusInfoPerType, MAX_AUCTION_HOUSE_TYPE> statusInfo;
140 sAuctionBot->PrepareStatusInfos(statusInfo);
141
142 WorldSession* session = handler->GetSession();
143
144 if (!session)
145 {
149 }
150 else
152
154
156 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount,
157 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount,
158 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount,
159 statusInfo[AUCTION_HOUSE_ALLIANCE].ItemsCount +
160 statusInfo[AUCTION_HOUSE_HORDE].ItemsCount +
161 statusInfo[AUCTION_HOUSE_NEUTRAL].ItemsCount);
162
163 if (all)
164 {
172
173 if (!session)
174 {
178 }
179 else
181
182 for (AuctionQuality quality : EnumUtils::Iterate<AuctionQuality>())
183 handler->PSendSysMessage(fmtId, handler->GetTrinityString(AhbotQualityLangIds[quality]),
184 statusInfo[AUCTION_HOUSE_ALLIANCE].QualityInfo[quality],
185 statusInfo[AUCTION_HOUSE_HORDE].QualityInfo[quality],
186 statusInfo[AUCTION_HOUSE_NEUTRAL].QualityInfo[quality],
187 sAuctionBotConfig->GetConfigItemQualityAmount(quality));
188 }
189
190 if (!session)
192
193 return true;
194 }
195
196};
197
@ CONFIG_AHBOT_HORDE_ITEM_AMOUNT_RATIO
@ CONFIG_AHBOT_ALLIANCE_ITEM_AMOUNT_RATIO
@ CONFIG_AHBOT_NEUTRAL_ITEM_AMOUNT_RATIO
#define sAuctionBot
AuctionQuality
AuctionHouseType
@ AUCTION_HOUSE_NEUTRAL
@ AUCTION_HOUSE_HORDE
@ AUCTION_HOUSE_ALLIANCE
#define sAuctionBotConfig
#define EXACT_SEQUENCE(str)
uint32_t uint32
Definition Define.h:154
@ 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:42
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:62
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:111
virtual char const * GetTrinityString(uint32 entry) const
Definition Chat.cpp:46
Player session in the World.
static bool HandleAHBotItemsAmountQualityCommand(ChatHandler *handler, uint32 amount)
Definition cs_ahbot.cpp:96
static bool HandleAHBotStatusCommand(ChatHandler *handler, Optional< EXACT_SEQUENCE("all")> all)
Definition cs_ahbot.cpp:137
static bool HandleAHBotRebuildCommand(ChatHandler *, Optional< EXACT_SEQUENCE("all")> all)
Definition cs_ahbot.cpp:124
std::span< ChatCommandBuilder const > GetCommands() const override
Definition cs_ahbot.cpp:46
static bool HandleAHBotReloadCommand(ChatHandler *handler)
Definition cs_ahbot.cpp:130
std::integral_constant< decltype(Const), Const > Wrap
Definition cs_ahbot.cpp:44
static bool HandleAHBotItemsRatioHouseCommand(ChatHandler *handler, uint32 ratio)
Definition cs_ahbot.cpp:116
static bool HandleAHBotItemsRatioCommand(ChatHandler *handler, uint32 alliance, uint32 horde, uint32 neutral)
Definition cs_ahbot.cpp:106
static bool HandleAHBotItemsAmountCommand(ChatHandler *handler, std::array< uint32, MAX_AUCTION_QUALITY > const &items)
Definition cs_ahbot.cpp:85
void AddSC_ahbot_commandscript()
Definition cs_ahbot.cpp:198
static constexpr std::array< uint32, MAX_AUCTION_QUALITY > AhbotQualityLangIds
Definition cs_ahbot.cpp:27
ChatCommandBuilder const [] 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