Core/Commands: Convert quest commands to new system

This commit is contained in:
Shauren
2022-09-02 19:17:56 +02:00
parent 10302dca55
commit 6d2b851154
5 changed files with 55 additions and 80 deletions

View File

@@ -1,10 +1,12 @@
--
SET @STRINGENTRY := 884;
SET @OBJECTIVE_STRING_ID := 884;
SET @QUEST_NOT_FOUND_STRING_ID := 1517;
DELETE FROM `command` WHERE `name`='quest objective complete';
INSERT INTO `command` (`name`,`help`) VALUES
('quest objective complete','Syntax: .quest objective complete #questObjectiveId\nMark specific quest objective as completed for target character.');
DELETE FROM `trinity_string` WHERE `entry`=@STRINGENTRY;
DELETE FROM `trinity_string` WHERE `entry` IN (@OBJECTIVE_STRING_ID,@QUEST_NOT_FOUND_STRING_ID);
INSERT INTO `trinity_string` (`entry`, `content_default`) VALUES
(@STRINGENTRY, 'Objective %u not found.');
(@OBJECTIVE_STRING_ID, 'Objective %u not found.'),
(@QUEST_NOT_FOUND_STRING_ID, 'Quest ID %u does not exist.');

View File

@@ -93,6 +93,23 @@ ChatCommandResult Trinity::Impl::ChatCommands::ArgInfo<ItemTemplate const*>::Try
return std::nullopt;
}
struct QuestVisitor
{
using value_type = Quest const*;
value_type operator()(Hyperlink<quest> quest) const { return quest->Quest; }
value_type operator()(uint32 questId) const { return sObjectMgr->GetQuestTemplate(questId); }
};
ChatCommandResult Trinity::Impl::ChatCommands::ArgInfo<Quest const*, void>::TryConsume(Quest const*& data, ChatHandler const* handler, std::string_view args)
{
Variant<Hyperlink<quest>, uint32> val;
ChatCommandResult result = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
if (!result || (data = val.visit(QuestVisitor())))
return result;
if (uint32* id = std::get_if<uint32>(&val))
return FormatTrinityString(handler, LANG_CMDPARSER_QUEST_NO_EXIST, *id);
return std::nullopt;
}
struct SpellInfoVisitor
{
using value_type = SpellInfo const*;

View File

@@ -319,6 +319,13 @@ namespace Trinity::Impl::ChatCommands
static ChatCommandResult TryConsume(ItemTemplate const*&, ChatHandler const*, std::string_view);
};
// Quest* from numeric id or link
template <>
struct TC_GAME_API ArgInfo<Quest const*>
{
static ChatCommandResult TryConsume(Quest const*&, ChatHandler const*, std::string_view);
};
// SpellInfo const* from spell id or link
template <>
struct TC_GAME_API ArgInfo<SpellInfo const*>

View File

@@ -1012,6 +1012,7 @@ enum TrinityStrings
LANG_CMDPARSER_SPELL_NO_EXIST = 1514,
LANG_CMDPARSER_EXACT_SEQ_MISMATCH = 1515,
LANG_CMDPARSER_CURRENCY_NO_EXIST = 1516,
LANG_CMDPARSER_QUEST_NO_EXIST = 1517,
// 1516-1998 - free
LANG_DEBUG_AREATRIGGER_LEFT = 1999,

View File

@@ -34,10 +34,6 @@ EndScriptData */
#include "ReputationMgr.h"
#include "World.h"
#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
using namespace Trinity::ChatCommands;
class quest_commandscript : public CommandScript
@@ -66,7 +62,7 @@ public:
return commandTable;
}
static bool HandleQuestAdd(ChatHandler* handler, char const* args)
static bool HandleQuestAdd(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
@@ -76,19 +72,9 @@ public:
return false;
}
// .addquest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest || DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, entry, nullptr))
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
@@ -102,12 +88,12 @@ public:
if (itr != std::end(itc))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, itr->first);
handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, quest->GetQuestId(), itr->first);
handler->SetSentErrorMessage(true);
return false;
}
if (player->IsActiveQuest(entry))
if (player->IsActiveQuest(quest->GetQuestId()))
return false;
// ok, normal (creature/GO starting) quest
@@ -117,7 +103,7 @@ public:
return true;
}
static bool HandleQuestRemove(ChatHandler* handler, char const* args)
static bool HandleQuestRemove(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayer();
if (!player)
@@ -127,32 +113,15 @@ public:
return false;
}
// .removequest #entry'
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
QuestStatus oldStatus = player->GetQuestStatus(quest->GetQuestId());
uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
if (!quest)
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->SetSentErrorMessage(true);
return false;
}
QuestStatus oldStatus = player->GetQuestStatus(entry);
if (player->GetQuestStatus(entry) != QUEST_STATUS_NONE)
if (oldStatus != QUEST_STATUS_NONE)
{
// remove all quest entries for 'entry' from quest log
for (uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 logQuest = player->GetQuestSlotQuestId(slot);
if (logQuest == entry)
if (logQuest == quest->GetQuestId())
{
player->SetQuestSlot(slot, 0);
@@ -166,10 +135,10 @@ public:
}
}
}
player->RemoveActiveQuest(entry, false);
player->RemoveRewardedQuest(entry);
player->RemoveActiveQuest(quest->GetQuestId(), false);
player->RemoveRewardedQuest(quest->GetQuestId());
sScriptMgr->OnQuestStatusChange(player, entry);
sScriptMgr->OnQuestStatusChange(player, quest->GetQuestId());
sScriptMgr->OnQuestStatusChange(player, quest, oldStatus, QUEST_STATUS_NONE);
handler->SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
@@ -177,7 +146,7 @@ public:
}
else
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
@@ -239,10 +208,12 @@ public:
player->KilledPlayerCredit(ObjectGuid::Empty);
break;
}
default:
break;
}
}
static bool HandleQuestComplete(ChatHandler* handler, char const* args)
static bool HandleQuestComplete(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayerOrSelf();
if (!player)
@@ -252,30 +223,17 @@ public:
return false;
}
// .quest complete #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, entry, nullptr))
if (player->GetQuestStatus(quest->GetQuestId()) == QUEST_STATUS_NONE
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}
for (uint32 i = 0; i < quest->Objectives.size(); ++i)
{
QuestObjective const& obj = quest->Objectives[i];
for (QuestObjective const& obj : quest->Objectives)
CompleteObjective(player, obj);
}
if (sWorld->getBoolConfig(CONFIG_QUEST_ENABLE_QUEST_TRACKER)) // check if Quest Tracker is enabled
{
@@ -288,7 +246,7 @@ public:
CharacterDatabase.Execute(stmt);
}
player->CompleteQuest(entry);
player->CompleteQuest(quest->GetQuestId());
return true;
}
@@ -314,7 +272,7 @@ public:
return true;
}
static bool HandleQuestReward(ChatHandler* handler, char const* args)
static bool HandleQuestReward(ChatHandler* handler, Quest const* quest)
{
Player* player = handler->getSelectedPlayer();
if (!player)
@@ -324,21 +282,11 @@ public:
return false;
}
// .quest reward #entry
// number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
char* cId = handler->extractKeyFromLink((char*)args, "Hquest");
if (!cId)
return false;
uint32 entry = atoul(cId);
Quest const* quest = sObjectMgr->GetQuestTemplate(entry);
// If player doesn't have the quest
if (!quest || player->GetQuestStatus(entry) != QUEST_STATUS_COMPLETE
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, entry, nullptr))
if (player->GetQuestStatus(quest->GetQuestId()) != QUEST_STATUS_COMPLETE
|| DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest->GetQuestId(), nullptr))
{
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
handler->PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, quest->GetQuestId());
handler->SetSentErrorMessage(true);
return false;
}