feat(Core/Commands): command to teleport character to npc (#8887)

This commit is contained in:
IntelligentQuantum
2021-12-04 12:28:30 +03:30
committed by GitHub
parent 5df73f6680
commit c21d83b30a
2 changed files with 92 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "Group.h"
#include "Language.h"
#include "MapMgr.h"
@@ -39,13 +41,24 @@ public:
ChatCommandTable GetCommands() const override
{
static ChatCommandTable teleNameNpcCommandTable =
{
{ "id", HandleTeleNameNpcIdCommand, SEC_GAMEMASTER, Console::Yes },
{ "guid", HandleTeleNameNpcSpawnIdCommand, SEC_GAMEMASTER, Console::Yes },
{ "name", HandleTeleNameNpcNameCommand, SEC_GAMEMASTER, Console::Yes },
};
static ChatCommandTable teleNameCommandTable =
{
{ "npc", teleNameNpcCommandTable },
{ "", HandleTeleNameCommand, SEC_GAMEMASTER, Console::Yes },
};
static ChatCommandTable teleCommandTable =
{
{ "add", HandleTeleAddCommand, SEC_ADMINISTRATOR, Console::No },
{ "del", HandleTeleDelCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "name", HandleTeleNameCommand, SEC_GAMEMASTER, Console::Yes },
{ "group", HandleTeleGroupCommand, SEC_GAMEMASTER, Console::No },
{ "", HandleTeleCommand, SEC_GAMEMASTER, Console::No }
{ "add", HandleTeleAddCommand, SEC_ADMINISTRATOR, Console::No },
{ "del", HandleTeleDelCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "name", teleNameCommandTable },
{ "group", HandleTeleGroupCommand, SEC_GAMEMASTER, Console::No },
{ "", HandleTeleCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
@@ -97,7 +110,6 @@ public:
handler->SetSentErrorMessage(true);
return false;
}
std::string name = tele->name;
sObjectMgr->DeleteGameTele(name);
handler->SendSysMessage(LANG_COMMAND_TP_DELETED);
@@ -310,6 +322,70 @@ public:
player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
return true;
}
static bool HandleTeleNameNpcIdCommand(ChatHandler* handler, PlayerIdentifier player, Variant<Hyperlink<creature_entry>, uint32> creatureId)
{
CreatureData const* spawnpoint = nullptr;
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id != *creatureId)
continue;
if (!spawnpoint)
spawnpoint = &pair.second;
else
{
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
break;
}
}
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(*creatureId));
return DoNameTeleport(handler, player, spawnpoint->mapid, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, creatureTemplate->Name);
}
static bool HandleTeleNameNpcSpawnIdCommand(ChatHandler* handler, PlayerIdentifier player, Variant<Hyperlink<creature>, ObjectGuid::LowType> spawnId)
{
CreatureData const* spawnpoint = sObjectMgr->GetCreatureData(spawnId);
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
CreatureTemplate const* creatureTemplate = ASSERT_NOTNULL(sObjectMgr->GetCreatureTemplate(spawnpoint->id));
return DoNameTeleport(handler, player, spawnpoint->mapid, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, creatureTemplate->Name);
}
static bool HandleTeleNameNpcNameCommand(ChatHandler* handler, PlayerIdentifier player, Tail name)
{
std::string normalizedName(name);
WorldDatabase.EscapeString(normalizedName);
QueryResult result = WorldDatabase.PQuery("SELECT c.position_x, c.position_y, c.position_z, c.orientation, c.map, ct.name FROM creature c INNER JOIN creature_template ct ON c.id = ct.entry WHERE ct.name LIKE '%s'", normalizedName.c_str());
if (!result)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (result->GetRowCount() > 1)
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
Field* fields = result->Fetch();
return DoNameTeleport(handler, player, fields[4].GetUInt16(), { fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat() }, fields[5].GetString());
}
};
void AddSC_tele_commandscript()