mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 18:10:26 +00:00
refactor(Scripts/Commands): Convert cs_event to new system (#8832)
This commit is contained in:
committed by
GitHub
parent
4a9a352807
commit
6c0bd9c2eb
@@ -15,25 +15,23 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
Name: event_commandscript
|
||||
%Complete: 100
|
||||
Comment: All event related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
/* ScriptData
|
||||
Name: event_commandscript
|
||||
%Complete: 100
|
||||
Comment: All event related commands
|
||||
Category: commandscripts
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "GameEventMgr.h"
|
||||
#include "Language.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
#if AC_COMPILER == AC_COMPILER_GNU
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
using namespace Acore::ChatCommands;
|
||||
|
||||
using EventEntry = Variant<Hyperlink<gameevent>, uint16>;
|
||||
|
||||
class event_commandscript : public CommandScript
|
||||
{
|
||||
public:
|
||||
@@ -43,19 +41,19 @@ public:
|
||||
{
|
||||
static ChatCommandTable eventCommandTable =
|
||||
{
|
||||
{ "activelist", SEC_GAMEMASTER, true, &HandleEventActiveListCommand, "" },
|
||||
{ "start", SEC_GAMEMASTER, true, &HandleEventStartCommand, "" },
|
||||
{ "stop", SEC_GAMEMASTER, true, &HandleEventStopCommand, "" },
|
||||
{ "", SEC_GAMEMASTER, true, &HandleEventInfoCommand, "" }
|
||||
{ "activelist", HandleEventActiveListCommand, SEC_GAMEMASTER, Console::Yes },
|
||||
{ "start", HandleEventStartCommand, SEC_GAMEMASTER, Console::Yes },
|
||||
{ "stop", HandleEventStopCommand, SEC_GAMEMASTER, Console::Yes },
|
||||
{ "info", HandleEventInfoCommand, SEC_GAMEMASTER, Console::Yes }
|
||||
};
|
||||
static ChatCommandTable commandTable =
|
||||
{
|
||||
{ "event", SEC_GAMEMASTER, false, nullptr, "", eventCommandTable }
|
||||
{ "event", eventCommandTable }
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
|
||||
static bool HandleEventActiveListCommand(ChatHandler* handler, char const* /*args*/)
|
||||
static bool HandleEventActiveListCommand(ChatHandler* handler)
|
||||
{
|
||||
uint32 counter = 0;
|
||||
|
||||
@@ -64,41 +62,37 @@ public:
|
||||
|
||||
char const* active = handler->GetAcoreString(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())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
|
||||
}
|
||||
|
||||
++counter;
|
||||
}
|
||||
|
||||
if (counter == 0)
|
||||
{
|
||||
handler->SendSysMessage(LANG_NOEVENTFOUND);
|
||||
}
|
||||
|
||||
handler->SetSentErrorMessage(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleEventInfoCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleEventInfoCommand(ChatHandler* handler, EventEntry 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 = atoi(id);
|
||||
|
||||
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
||||
|
||||
if (eventId >= events.size())
|
||||
if (std::size_t(eventId) >= events.size())
|
||||
{
|
||||
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
||||
handler->SetSentErrorMessage(true);
|
||||
@@ -127,27 +121,18 @@ public:
|
||||
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
|
||||
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
|
||||
|
||||
handler->PSendSysMessage(LANG_EVENT_INFO, eventId, eventData.description.c_str(), activeStr,
|
||||
startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
|
||||
nextStr.c_str());
|
||||
handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description.c_str(), activeStr,
|
||||
startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
|
||||
nextStr.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleEventStartCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleEventStartCommand(ChatHandler* handler, EventEntry 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;
|
||||
|
||||
int32 eventId = atoi(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);
|
||||
@@ -165,7 +150,7 @@ public:
|
||||
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
||||
if (activeEvents.find(eventId) != activeEvents.end())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, eventId);
|
||||
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
@@ -174,21 +159,11 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleEventStopCommand(ChatHandler* handler, char const* args)
|
||||
static bool HandleEventStopCommand(ChatHandler* handler, EventEntry 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;
|
||||
|
||||
int32 eventId = atoi(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);
|
||||
@@ -207,7 +182,7 @@ public:
|
||||
|
||||
if (activeEvents.find(eventId) == activeEvents.end())
|
||||
{
|
||||
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId);
|
||||
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId));
|
||||
handler->SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user