- Fix targeting gameobjects and creatures for .dist and .gps. The old code used DB guid to search from core generated guid lists. - Fix some error messages saying 'no player found' even if creatures and gameobjects and players were searched - Change atoi to atoul when receiving lowguids as string or other uint32 values - Use ObjectGuid::LowType instead of uint32 for lowguid type - Allow .gob info to take in gameobject guid link as well as entry link in addition to gameobject entry and update the documentation of the command - Change .gob delete to post the spawnid (dbguid) instead of the ingame generated guid (which is basically never seen or used by the player in any other commands that I see) - Allow spawntimesecs to be negative when spawning a gameobject - Disable searching by ingame spawn id in commands. (it makes little sense for a user to provide a number which is then attempted to be used as DB guid and non DB guid when both could have a match) - Update .gob turn documentation to tell about possibility to provide orientation in command - Correct the types in .gob add command result trinity_string - Correct the creature search for .npc del - Change .event to .event info - Add .go offset command - Remove the .go command for empty string (no subcommand given) because it just used .go xyz - Extend .gob info to show size, faction, flags and model dimensions - Remove some unnecessary casts - Document .wp show better (first and last were not documented) - Insert spawnid to .wp show info error message - Fix spawntime printing for .gobject target - Fix guid targetting for .npc set movetype - Fix query by spawnid for .wp show info - Fix deleting of existing waypoints when twice doing the command .wp show on - Fix deleting of existing waypoints when doing the command .wp show off - Change wpguid column in DB and in core to uint32, which is what the spawnid type is in core and db.
218 lines
7.4 KiB
C++
218 lines
7.4 KiB
C++
/*
|
|
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 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 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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/* ScriptData
|
|
Name: event_commandscript
|
|
%Complete: 100
|
|
Comment: All event related commands
|
|
Category: commandscripts
|
|
EndScriptData */
|
|
|
|
#include "Chat.h"
|
|
#include "GameEventMgr.h"
|
|
#include "Language.h"
|
|
#include "Player.h"
|
|
#include "ScriptMgr.h"
|
|
|
|
class event_commandscript : public CommandScript
|
|
{
|
|
public:
|
|
event_commandscript() : CommandScript("event_commandscript") { }
|
|
|
|
std::vector<ChatCommand> GetCommands() const override
|
|
{
|
|
static std::vector<ChatCommand> eventCommandTable =
|
|
{
|
|
{ "activelist", rbac::RBAC_PERM_COMMAND_EVENT_ACTIVELIST, true, &HandleEventActiveListCommand, "" },
|
|
{ "start", rbac::RBAC_PERM_COMMAND_EVENT_START, true, &HandleEventStartCommand, "" },
|
|
{ "stop", rbac::RBAC_PERM_COMMAND_EVENT_STOP, true, &HandleEventStopCommand, "" },
|
|
{ "info", rbac::RBAC_PERM_COMMAND_EVENT, true, &HandleEventInfoCommand, "" },
|
|
};
|
|
static std::vector<ChatCommand> commandTable =
|
|
{
|
|
{ "event", rbac::RBAC_PERM_COMMAND_EVENT, false, NULL, "", eventCommandTable },
|
|
};
|
|
return commandTable;
|
|
}
|
|
|
|
static bool HandleEventActiveListCommand(ChatHandler* handler, char const* /*args*/)
|
|
{
|
|
uint32 counter = 0;
|
|
|
|
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
|
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
|
|
|
char const* active = handler->GetTrinityString(LANG_ACTIVE);
|
|
|
|
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
|
|
{
|
|
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)
|
|
{
|
|
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())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventData const& eventData = events[eventId];
|
|
if (!eventData.isValid())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
|
bool active = activeEvents.find(eventId) != activeEvents.end();
|
|
char const* activeStr = active ? handler->GetTrinityString(LANG_ACTIVE) : "";
|
|
|
|
std::string startTimeStr = TimeToTimestampStr(eventData.start);
|
|
std::string endTimeStr = TimeToTimestampStr(eventData.end);
|
|
|
|
uint32 delay = sGameEventMgr->NextCheck(eventId);
|
|
time_t nextTime = time(NULL) + delay;
|
|
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL) + delay) : "-";
|
|
|
|
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
|
|
std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
|
|
|
|
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());
|
|
return true;
|
|
}
|
|
|
|
static bool HandleEventStartCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
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 = atoul(id);
|
|
|
|
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
|
|
|
if (eventId < 1 || uint32(eventId) >= events.size())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventData const& eventData = events[eventId];
|
|
if (!eventData.isValid())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
|
if (activeEvents.find(eventId) != activeEvents.end())
|
|
{
|
|
handler->PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE, eventId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
sGameEventMgr->StartEvent(eventId, true);
|
|
return true;
|
|
}
|
|
|
|
static bool HandleEventStopCommand(ChatHandler* handler, char const* args)
|
|
{
|
|
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 = atoul(id);
|
|
|
|
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
|
|
|
|
if (eventId < 1 || uint32(eventId) >= events.size())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventData const& eventData = events[eventId];
|
|
if (!eventData.isValid())
|
|
{
|
|
handler->SendSysMessage(LANG_EVENT_NOT_EXIST);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
|
|
|
|
if (activeEvents.find(eventId) == activeEvents.end())
|
|
{
|
|
handler->PSendSysMessage(LANG_EVENT_NOT_ACTIVE, eventId);
|
|
handler->SetSentErrorMessage(true);
|
|
return false;
|
|
}
|
|
|
|
sGameEventMgr->StopEvent(eventId, true);
|
|
return true;
|
|
}
|
|
};
|
|
|
|
void AddSC_event_commandscript()
|
|
{
|
|
new event_commandscript();
|
|
}
|