Scripts/Commands: Convert argument parsing of event commands to new system (PR #25275)

This commit is contained in:
Peter Keresztes Schmidt
2020-08-20 02:30:21 +02:00
committed by GitHub
parent 643b9209f8
commit 7bfeb03c13
3 changed files with 17 additions and 40 deletions

View File

@@ -152,6 +152,12 @@ namespace Trinity::ChatCommands
return operator*();
}
template<bool C = have_operators>
operator std::enable_if_t<C && std::is_convertible<first_type, size_t>::value, size_t>() const
{
return operator*();
}
template <typename T>
Variant& operator=(T&& arg) { base::operator=(std::forward<T>(arg)); return *this; }

View File

@@ -133,7 +133,7 @@ namespace Trinity::Hyperlinks
make_base_tag(areatrigger, uint32);
make_base_tag(creature, ObjectGuid::LowType);
make_base_tag(creature_entry, uint32);
make_base_tag(gameevent, uint32);
make_base_tag(gameevent, uint16);
make_base_tag(gameobject, ObjectGuid::LowType);
make_base_tag(gameobject_entry, uint32);
make_base_tag(itemset, uint32);

View File

@@ -30,6 +30,8 @@ EndScriptData */
#include "Player.h"
#include "RBAC.h"
using namespace Trinity::ChatCommands;
class event_commandscript : public CommandScript
{
public:
@@ -51,7 +53,7 @@ public:
return commandTable;
}
static bool HandleEventActiveListCommand(ChatHandler* handler, char const* /*args*/)
static bool HandleEventActiveListCommand(ChatHandler* handler)
{
uint32 counter = 0;
@@ -60,9 +62,8 @@ public:
char const* active = handler->GetTrinityString(LANG_ACTIVE);
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
for (uint16 eventId : activeEvents)
{
uint32 eventId = *itr;
GameEventData const& eventData = events[eventId];
if (handler->GetSession())
@@ -80,21 +81,11 @@ public:
return true;
}
static bool HandleEventInfoCommand(ChatHandler* handler, char const* args)
static bool HandleEventInfoCommand(ChatHandler* handler, Variant<Hyperlink<gameevent>, uint16> const eventId)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
uint32 eventId = atoul(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId >= events.size())
if (*eventId >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
@@ -129,21 +120,11 @@ public:
return true;
}
static bool HandleEventStartCommand(ChatHandler* handler, char const* args)
static bool HandleEventStartCommand(ChatHandler* handler, Variant<Hyperlink<gameevent>, uint16> const eventId)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
uint32 eventId = atoul(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId < 1 || uint32(eventId) >= events.size())
if (*eventId < 1 || *eventId >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);
@@ -170,21 +151,11 @@ public:
return true;
}
static bool HandleEventStopCommand(ChatHandler* handler, char const* args)
static bool HandleEventStopCommand(ChatHandler* handler, Variant<Hyperlink<gameevent>, uint16> const eventId)
{
if (!*args)
return false;
// id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameevent");
if (!id)
return false;
uint32 eventId = atoul(id);
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
if (eventId < 1 || uint32(eventId) >= events.size())
if (*eventId < 1 || *eventId >= events.size())
{
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
handler->SetSentErrorMessage(true);