TrinityCore
ChatCommandArgs.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 "ChatCommandArgs.h"
19#include "ChatCommand.h"
20#include "DB2Stores.h"
21#include "ObjectMgr.h"
22#include "SpellMgr.h"
23
24using namespace Trinity::ChatCommands;
26
28{
30 value_type operator()(Hyperlink<achievement> achData) const { return achData->Achievement; }
31 value_type operator()(uint32 achId) const { return sAchievementStore.LookupEntry(achId); }
32};
34{
36 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
37 if (!result || (data = val.visit(AchievementVisitor())))
38 return result;
39 if (uint32* id = std::get_if<uint32>(&val))
41 return std::nullopt;
42}
43
45{
47 value_type operator()(Hyperlink<currency> currency) const { return currency->Currency; }
48 value_type operator()(uint32 currencyId) const { return sCurrencyTypesStore.LookupEntry(currencyId); }
49};
51{
53 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
54 if (!result || (data = val.visit(CurrencyTypesVisitor())))
55 return result;
56 if (uint32* id = std::get_if<uint32>(&val))
58 return std::nullopt;
59}
60
62{
63 using value_type = GameTele const*;
64 value_type operator()(Hyperlink<tele> tele) const { return sObjectMgr->GetGameTele(tele); }
65 value_type operator()(std::string_view tele) const { return sObjectMgr->GetGameTele(tele); }
66};
68{
69 Variant<Hyperlink<tele>, std::string_view> val;
70 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
71 if (!result || (data = val.visit(GameTeleVisitor())))
72 return result;
74 return FormatTrinityString(handler, LANG_CMDPARSER_GAME_TELE_ID_NO_EXIST, static_cast<uint32>(std::get<Hyperlink<tele>>(val)));
75 else
76 return FormatTrinityString(handler, LANG_CMDPARSER_GAME_TELE_NO_EXIST, STRING_VIEW_FMT_ARG(std::get<std::string_view>(val)));
77}
78
80{
81 using value_type = ItemTemplate const*;
82 value_type operator()(Hyperlink<item> item) const { return item->Item; }
83 value_type operator()(uint32 item) const { return sObjectMgr->GetItemTemplate(item); }
84};
86{
88 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
89 if (!result || (data = val.visit(ItemTemplateVisitor())))
90 return result;
91 if (uint32* id = std::get_if<uint32>(&val))
93 return std::nullopt;
94}
95
97{
98 using value_type = Quest const*;
99 value_type operator()(Hyperlink<quest> quest) const { return quest->Quest; }
100 value_type operator()(uint32 questId) const { return sObjectMgr->GetQuestTemplate(questId); }
101};
103{
105 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
106 if (!result || (data = val.visit(QuestVisitor())))
107 return result;
108 if (uint32* id = std::get_if<uint32>(&val))
110 return std::nullopt;
111}
112
114{
115 using value_type = SpellInfo const*;
116
117 value_type operator()(Hyperlink<apower> artifactPower) const { return operator()(artifactPower->ArtifactPower->SpellID); }
118 value_type operator()(Hyperlink<conduit> soulbindConduit) const { return operator()((*soulbindConduit)->SpellID); }
119 value_type operator()(Hyperlink<enchant> enchant) const { return enchant; }
120 value_type operator()(Hyperlink<mawpower> mawPower) const { return operator()((*mawPower)->SpellID); }
121 value_type operator()(Hyperlink<mount> const& mount) const { return mount->Spell; }
122 value_type operator()(Hyperlink<pvptal> pvpTalent) const { return operator()((*pvpTalent)->SpellID); }
123 value_type operator()(Hyperlink<spell> spell) const { return spell->Spell; }
124 value_type operator()(Hyperlink<talent> talent) const { return operator()((*talent)->SpellID); }
125 value_type operator()(Hyperlink<trade> trade) const { return trade->Spell; }
126
127 value_type operator()(uint32 spellId) const { return sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE); }
128};
130{
132 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
133 if (!result || (data = val.visit(SpellInfoVisitor())))
134 return result;
135 if (uint32* id = std::get_if<uint32>(&val))
137 return std::nullopt;
138}
Trinity::Impl::ChatCommands::ChatCommandResult ChatCommandResult
DB2Storage< AchievementEntry > sAchievementStore("Achievement.db2", &AchievementLoadInfo::Instance)
DB2Storage< CurrencyTypesEntry > sCurrencyTypesStore("CurrencyTypes.db2", &CurrencyTypesLoadInfo::Instance)
@ DIFFICULTY_NONE
Definition: DBCEnums.h:874
#define STRING_VIEW_FMT_ARG(str)
Definition: Define.h:135
uint32_t uint32
Definition: Define.h:142
@ LANG_CMDPARSER_ITEM_NO_EXIST
Definition: Language.h:1011
@ LANG_CMDPARSER_GAME_TELE_ID_NO_EXIST
Definition: Language.h:1009
@ LANG_CMDPARSER_ACHIEVEMENT_NO_EXIST
Definition: Language.h:1008
@ LANG_CMDPARSER_GAME_TELE_NO_EXIST
Definition: Language.h:1010
@ LANG_CMDPARSER_QUEST_NO_EXIST
Definition: Language.h:1015
@ LANG_CMDPARSER_CURRENCY_NO_EXIST
Definition: Language.h:1014
@ LANG_CMDPARSER_SPELL_NO_EXIST
Definition: Language.h:1012
#define sObjectMgr
Definition: ObjectMgr.h:1946
#define sSpellMgr
Definition: SpellMgr.h:849
std::string FormatTrinityString(ChatHandler const *handler, TrinityStrings which, Ts &&... args)
value_type operator()(uint32 achId) const
AchievementEntry const * value_type
value_type operator()(Hyperlink< achievement > achData) const
value_type operator()(Hyperlink< currency > currency) const
value_type operator()(uint32 currencyId) const
CurrencyTypesEntry const * value_type
value_type operator()(std::string_view tele) const
value_type operator()(Hyperlink< tele > tele) const
GameTele const * value_type
value_type operator()(Hyperlink< item > item) const
value_type operator()(uint32 item) const
ItemTemplate const * value_type
value_type operator()(Hyperlink< quest > quest) const
value_type operator()(uint32 questId) const
Quest const * value_type
value_type operator()(Hyperlink< pvptal > pvpTalent) const
value_type operator()(Hyperlink< trade > trade) const
value_type operator()(uint32 spellId) const
value_type operator()(Hyperlink< enchant > enchant) const
value_type operator()(Hyperlink< mawpower > mawPower) const
SpellInfo const * value_type
value_type operator()(Hyperlink< conduit > soulbindConduit) const
value_type operator()(Hyperlink< spell > spell) const
value_type operator()(Hyperlink< apower > artifactPower) const
value_type operator()(Hyperlink< mount > const &mount) const
value_type operator()(Hyperlink< talent > talent) const
constexpr bool holds_alternative() const
constexpr decltype(auto) visit(T &&arg)