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/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* ScriptData
|
/* ScriptData
|
||||||
Name: event_commandscript
|
Name: event_commandscript
|
||||||
%Complete: 100
|
%Complete: 100
|
||||||
Comment: All event related commands
|
Comment: All event related commands
|
||||||
Category: commandscripts
|
Category: commandscripts
|
||||||
EndScriptData */
|
EndScriptData */
|
||||||
|
|
||||||
|
#include "ScriptMgr.h"
|
||||||
#include "Chat.h"
|
#include "Chat.h"
|
||||||
#include "GameEventMgr.h"
|
#include "GameEventMgr.h"
|
||||||
#include "Language.h"
|
#include "Language.h"
|
||||||
#include "Player.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 namespace Acore::ChatCommands;
|
||||||
|
|
||||||
|
using EventEntry = Variant<Hyperlink<gameevent>, uint16>;
|
||||||
|
|
||||||
class event_commandscript : public CommandScript
|
class event_commandscript : public CommandScript
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -43,19 +41,19 @@ public:
|
|||||||
{
|
{
|
||||||
static ChatCommandTable eventCommandTable =
|
static ChatCommandTable eventCommandTable =
|
||||||
{
|
{
|
||||||
{ "activelist", SEC_GAMEMASTER, true, &HandleEventActiveListCommand, "" },
|
{ "activelist", HandleEventActiveListCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
{ "start", SEC_GAMEMASTER, true, &HandleEventStartCommand, "" },
|
{ "start", HandleEventStartCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
{ "stop", SEC_GAMEMASTER, true, &HandleEventStopCommand, "" },
|
{ "stop", HandleEventStopCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
{ "", SEC_GAMEMASTER, true, &HandleEventInfoCommand, "" }
|
{ "info", HandleEventInfoCommand, SEC_GAMEMASTER, Console::Yes }
|
||||||
};
|
};
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
{ "event", SEC_GAMEMASTER, false, nullptr, "", eventCommandTable }
|
{ "event", eventCommandTable }
|
||||||
};
|
};
|
||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleEventActiveListCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleEventActiveListCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
uint32 counter = 0;
|
uint32 counter = 0;
|
||||||
|
|
||||||
@@ -64,41 +62,37 @@ public:
|
|||||||
|
|
||||||
char const* active = handler->GetAcoreString(LANG_ACTIVE);
|
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];
|
GameEventData const& eventData = events[eventId];
|
||||||
|
|
||||||
if (handler->GetSession())
|
if (handler->GetSession())
|
||||||
|
{
|
||||||
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
|
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description.c_str(), active);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
|
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description.c_str(), active);
|
||||||
|
}
|
||||||
|
|
||||||
++counter;
|
++counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter == 0)
|
if (counter == 0)
|
||||||
|
{
|
||||||
handler->SendSysMessage(LANG_NOEVENTFOUND);
|
handler->SendSysMessage(LANG_NOEVENTFOUND);
|
||||||
|
}
|
||||||
|
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
|
|
||||||
return 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();
|
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
||||||
|
|
||||||
if (eventId >= events.size())
|
if (std::size_t(eventId) >= events.size())
|
||||||
{
|
{
|
||||||
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
@@ -127,27 +121,18 @@ public:
|
|||||||
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
|
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
|
||||||
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
|
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);
|
||||||
|
|
||||||
handler->PSendSysMessage(LANG_EVENT_INFO, eventId, eventData.description.c_str(), activeStr,
|
handler->PSendSysMessage(LANG_EVENT_INFO, uint16(eventId), eventData.description.c_str(), activeStr,
|
||||||
startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
|
startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
|
||||||
nextStr.c_str());
|
nextStr.c_str());
|
||||||
|
|
||||||
return true;
|
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();
|
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->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
@@ -165,7 +150,7 @@ public:
|
|||||||
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
||||||
if (activeEvents.find(eventId) != activeEvents.end())
|
if (activeEvents.find(eventId) != activeEvents.end())
|
||||||
{
|
{
|
||||||
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, eventId);
|
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, uint16(eventId));
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -174,21 +159,11 @@ public:
|
|||||||
return true;
|
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();
|
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->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
@@ -207,7 +182,7 @@ public:
|
|||||||
|
|
||||||
if (activeEvents.find(eventId) == activeEvents.end())
|
if (activeEvents.find(eventId) == activeEvents.end())
|
||||||
{
|
{
|
||||||
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId);
|
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, uint16(eventId));
|
||||||
handler->SetSentErrorMessage(true);
|
handler->SetSentErrorMessage(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user