TrinityCore
Loading...
Searching...
No Matches
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 "DBCStores.h"
21#include "ObjectMgr.h"
22#include "SpellMgr.h"
23#include "Util.h"
24
25using namespace Trinity::ChatCommands;
27
29{
31 value_type operator()(Hyperlink<achievement> achData) const { return achData->Achievement; }
32 value_type operator()(uint32 achId) const { return sAchievementStore.LookupEntry(achId); }
33};
35{
37 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
38 if (!result || (data = val.visit(AchievementVisitor())))
39 return result;
40 if (uint32* id = std::get_if<uint32>(&val))
42 return std::nullopt;
43}
44
46{
47 using value_type = GameTele const*;
48 value_type operator()(Hyperlink<tele> tele) const { return sObjectMgr->GetGameTele(tele); }
49 value_type operator()(std::string_view tele) const { return sObjectMgr->GetGameTele(tele); }
50};
52{
53 Variant<Hyperlink<tele>, std::string_view> val;
54 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
55 if (!result || (data = val.visit(GameTeleVisitor())))
56 return result;
58 return FormatTrinityString(handler, LANG_CMDPARSER_GAME_TELE_ID_NO_EXIST, static_cast<uint32>(std::get<Hyperlink<tele>>(val)));
59 else
60 return FormatTrinityString(handler, LANG_CMDPARSER_GAME_TELE_NO_EXIST, STRING_VIEW_FMT_ARG(std::get<std::string_view>(val)));
61}
62
64{
65 using value_type = ItemTemplate const*;
66 value_type operator()(Hyperlink<item> item) const { return item->Item; }
67 value_type operator()(uint32 item) { return sObjectMgr->GetItemTemplate(item); }
68};
70{
72 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
73 if (!result || (data = val.visit(ItemTemplateVisitor())))
74 return result;
75 if (uint32* id = std::get_if<uint32>(&val))
77 return std::nullopt;
78}
79
81{
82 using value_type = Quest const*;
83 value_type operator()(Hyperlink<quest> quest) const { return quest->Quest; }
84 value_type operator()(uint32 questId) const { return sObjectMgr->GetQuestTemplate(questId); }
85};
87{
89 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
90 if (!result || (data = val.visit(QuestVisitor())))
91 return result;
92 if (uint32* id = std::get_if<uint32>(&val))
94 return std::nullopt;
95}
96
98{
99 using value_type = SpellInfo const*;
100 value_type operator()(Hyperlink<enchant> enchant) const { return enchant; };
101 value_type operator()(Hyperlink<glyph> glyph) const { return operator()(glyph->Glyph->SpellID); };
102 value_type operator()(Hyperlink<spell> spell) const { return *spell; }
103 value_type operator()(Hyperlink<talent> talent) const { return talent->Spell; };
104 value_type operator()(Hyperlink<trade> trade) const { return trade->Spell; };
105
106 value_type operator()(uint32 spellId) const { return sSpellMgr->GetSpellInfo(spellId); }
107};
109{
111 ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
112 if (!result || (data = val.visit(SpellInfoVisitor())))
113 return result;
114 if (uint32* id = std::get_if<uint32>(&val))
116 return std::nullopt;
117}
DBCStorage< AchievementEntry > sAchievementStore(Achievementfmt)
#define STRING_VIEW_FMT_ARG(str)
Definition Define.h:126
uint32_t uint32
Definition Define.h:133
@ LANG_CMDPARSER_ITEM_NO_EXIST
Definition Language.h:1014
@ LANG_CMDPARSER_GAME_TELE_ID_NO_EXIST
Definition Language.h:1012
@ LANG_CMDPARSER_ACHIEVEMENT_NO_EXIST
Definition Language.h:1011
@ LANG_CMDPARSER_GAME_TELE_NO_EXIST
Definition Language.h:1013
@ LANG_CMDPARSER_QUEST_NO_EXIST
Definition Language.h:1018
@ LANG_CMDPARSER_SPELL_NO_EXIST
Definition Language.h:1015
#define sObjectMgr
Definition ObjectMgr.h:1721
#define sSpellMgr
Definition SpellMgr.h:738
TC_GAME_API std::string FormatTrinityString(std::string_view messageFormat, fmt::printf_args messageFormatArgs)
value_type operator()(uint32 achId) const
AchievementEntry const * value_type
value_type operator()(Hyperlink< achievement > achData) const
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)
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< trade > trade) const
value_type operator()(uint32 spellId) const
value_type operator()(Hyperlink< enchant > enchant) const
value_type operator()(Hyperlink< glyph > glyph) const
SpellInfo const * value_type
value_type operator()(Hyperlink< spell > spell) const
value_type operator()(Hyperlink< talent > talent) const
constexpr bool holds_alternative() const
constexpr decltype(auto) visit(T &&arg)