/* * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Affero General Public License as published by the * Free Software Foundation; either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #include "ChatCommandArgs.h" #include "AchievementMgr.h" #include "ChatCommand.h" #include "ObjectMgr.h" #include "SpellMgr.h" #include "Util.h" using namespace Acore::ChatCommands; using ChatCommandResult = Acore::Impl::ChatCommands::ChatCommandResult; struct AchievementVisitor { using value_type = AchievementEntry const*; value_type operator()(Hyperlink achData) const { return achData->Achievement; } value_type operator()(uint32 achId) const { return sAchievementMgr->GetAchievement(achId); } }; ChatCommandResult Acore::Impl::ChatCommands::ArgInfo::TryConsume(AchievementEntry const*& data, ChatHandler const* handler, std::string_view args) { Variant, uint32> val; ChatCommandResult result = ArgInfo::TryConsume(val, handler, args); if (!result || (data = val.visit(AchievementVisitor()))) return result; if (uint32* id = std::get_if(&val)) return FormatAcoreString(handler, LANG_CMDPARSER_ACHIEVEMENT_NO_EXIST, *id); return std::nullopt; } struct GameTeleVisitor { using value_type = GameTele const*; value_type operator()(Hyperlink tele) const { return sObjectMgr->GetGameTele(tele); } value_type operator()(std::string_view tele) const { return sObjectMgr->GetGameTele(tele); } }; ChatCommandResult Acore::Impl::ChatCommands::ArgInfo::TryConsume(GameTele const*& data, ChatHandler const* handler, std::string_view args) { Variant, std::string_view> val; ChatCommandResult result = ArgInfo::TryConsume(val, handler, args); if (!result || (data = val.visit(GameTeleVisitor()))) return result; if (val.holds_alternative>()) return FormatAcoreString(handler, LANG_CMDPARSER_GAME_TELE_ID_NO_EXIST, static_cast(std::get>(val))); else return FormatAcoreString(handler, LANG_CMDPARSER_GAME_TELE_NO_EXIST, STRING_VIEW_FMT_ARG(std::get(val))); } struct ItemTemplateVisitor { using value_type = ItemTemplate const*; value_type operator()(Hyperlink item) const { return item->Item; } value_type operator()(uint32 item) { return sObjectMgr->GetItemTemplate(item); } }; ChatCommandResult Acore::Impl::ChatCommands::ArgInfo::TryConsume(ItemTemplate const*& data, ChatHandler const* handler, std::string_view args) { Variant, uint32> val; ChatCommandResult result = ArgInfo::TryConsume(val, handler, args); if (!result || (data = val.visit(ItemTemplateVisitor()))) return result; if (uint32* id = std::get_if(&val)) return FormatAcoreString(handler, LANG_CMDPARSER_ITEM_NO_EXIST, *id); return std::nullopt; } struct SpellInfoVisitor { using value_type = SpellInfo const*; value_type operator()(Hyperlink enchant) const { return enchant; }; value_type operator()(Hyperlink glyph) const { return operator()(glyph->Glyph->SpellId); }; value_type operator()(Hyperlink spell) const { return *spell; } value_type operator()(Hyperlink talent) const { return operator()(talent->Talent->RankID[talent->Rank - 1]); }; value_type operator()(Hyperlink trade) const { return trade->Spell; }; value_type operator()(uint32 spellId) const { return sSpellMgr->GetSpellInfo(spellId); } }; ChatCommandResult Acore::Impl::ChatCommands::ArgInfo::TryConsume(SpellInfo const*& data, ChatHandler const* handler, std::string_view args) { Variant, Hyperlink, Hyperlink, Hyperlink, Hyperlink, uint32> val; ChatCommandResult result = ArgInfo::TryConsume(val, handler, args); if (!result || (data = val.visit(SpellInfoVisitor()))) return result; if (uint32* id = std::get_if(&val)) return FormatAcoreString(handler, LANG_CMDPARSER_SPELL_NO_EXIST, *id); return std::nullopt; } struct QuestVisitor { using value_type = Quest const*; value_type operator()(Hyperlink quest_template) const { return quest_template->Quest; }; value_type operator()(uint32 questId) const { return sObjectMgr->GetQuestTemplate(questId); }; }; ChatCommandResult Acore::Impl::ChatCommands::ArgInfo::TryConsume(Quest const*& data, ChatHandler const* handler, std::string_view args) { Variant, uint32> val; ChatCommandResult result = ArgInfo::TryConsume(val, handler, args); if (!result || (data = val.visit(QuestVisitor()))) { return result; } if (uint32* id = std::get_if(&val)) { return FormatAcoreString(handler, LANG_CMDPARSER_QUEST_NO_EXIST, *id); } return std::nullopt; }