refactor(Scripts/Commands): Convert cs_go to new system (#8874)

This commit is contained in:
IntelligentQuantum
2021-11-04 19:11:59 +03:30
committed by GitHub
parent ea2c880fc8
commit d5509ceb37
3 changed files with 121 additions and 322 deletions

View File

@@ -31,10 +31,6 @@ EndScriptData */
#include "ScriptMgr.h"
#include "TicketMgr.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
using namespace Acore::ChatCommands;
class go_commandscript : public CommandScript
@@ -46,115 +42,35 @@ public:
{
static ChatCommandTable goCommandTable =
{
{ "creature", SEC_MODERATOR, false, &HandleGoCreatureCommand, "" },
{ "graveyard", SEC_MODERATOR, false, &HandleGoGraveyardCommand, "" },
{ "grid", SEC_MODERATOR, false, &HandleGoGridCommand, "" },
{ "object", SEC_MODERATOR, false, &HandleGoObjectCommand, "" },
{ "gobject", SEC_MODERATOR, false, &HandleGoObjectCommand, "" },
{ "taxinode", SEC_MODERATOR, false, &HandleGoTaxinodeCommand, "" },
{ "trigger", SEC_MODERATOR, false, &HandleGoTriggerCommand, "" },
{ "zonexy", SEC_MODERATOR, false, &HandleGoZoneXYCommand, "" },
{ "xyz", SEC_MODERATOR, false, &HandleGoXYZCommand, "" },
{ "ticket", SEC_GAMEMASTER, false, &HandleGoTicketCommand, "" },
{ "", SEC_MODERATOR, false, &HandleGoXYZCommand, "" }
{ "creature", HandleGoCreatureSpawnIdCommand, SEC_MODERATOR, Console::No },
{ "creature id", HandleGoCreatureCIdCommand, SEC_MODERATOR, Console::No },
{ "gameobject", HandleGoGameObjectSpawnIdCommand, SEC_MODERATOR, Console::No },
{ "gameobject id", HandleGoGameObjectGOIdCommand, SEC_MODERATOR, Console::No },
{ "graveyard", HandleGoGraveyardCommand, SEC_MODERATOR, Console::No },
{ "grid", HandleGoGridCommand, SEC_MODERATOR, Console::No },
{ "taxinode", HandleGoTaxinodeCommand, SEC_MODERATOR, Console::No },
{ "trigger", HandleGoTriggerCommand, SEC_MODERATOR, Console::No },
{ "zonexy", HandleGoZoneXYCommand, SEC_MODERATOR, Console::No },
{ "xyz", HandleGoXYZCommand, SEC_MODERATOR, Console::No },
{ "ticket", HandleGoTicketCommand, SEC_GAMEMASTER, Console::No }
};
static ChatCommandTable commandTable =
{
{ "go", SEC_MODERATOR, false, nullptr, "", goCommandTable }
{ "go", goCommandTable }
};
return commandTable;
}
/** \brief Teleport the GM to the specified creature
*
* .gocreature <GUID> --> TP using creature.guid
* .gocreature azuregos --> TP player to the mob with this name
* Warning: If there is more than one mob with this name
* you will be teleported to the first one that is found.
* .gocreature id 6109 --> TP player to the mob, that has this creature_template.entry
* Warning: If there is more than one mob with this "id"
* you will be teleported to the first one that is found.
*/
//teleport to creature
static bool HandleGoCreatureCommand(ChatHandler* handler, char const* args)
static bool DoTeleport(ChatHandler* handler, Position pos, uint32 mapId = MAPID_INVALID)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
// "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* param1 = handler->extractKeyFromLink((char*)args, "Hcreature");
if (!param1)
return false;
std::ostringstream whereClause;
// User wants to teleport to the NPC's template entry
if (strcmp(param1, "id") == 0)
if (mapId == MAPID_INVALID)
mapId = player->GetMapId();
if (!MapMgr::IsValidMapCoord(mapId, pos) || sObjectMgr->IsTransportMap(mapId))
{
// Get the "creature_template.entry"
// number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
char* tail = strtok(nullptr, "");
if (!tail)
return false;
char* id = handler->extractKeyFromLink(tail, "Hcreature_entry");
if (!id)
return false;
int32 entry = atoi(id);
if (!entry)
return false;
whereClause << "WHERE id = '" << entry << '\'';
}
else
{
int32 guid = atoi(param1);
// Number is invalid - maybe the user specified the mob's name
if (!guid)
{
std::string name = param1;
WorldDatabase.EscapeString(name);
whereClause << ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name LIKE '" << name << '\'';
}
else
whereClause << "WHERE guid = '" << guid << '\'';
}
QueryResult result = WorldDatabase.PQuery("SELECT position_x, position_y, position_z, orientation, map, guid, id FROM creature %s", whereClause.str().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();
float x = fields[0].GetFloat();
float y = fields[1].GetFloat();
float z = fields[2].GetFloat();
float ort = fields[3].GetFloat();
int mapId = fields[4].GetUInt16();
ObjectGuid::LowType guid = fields[5].GetUInt32();
uint32 id = fields[6].GetUInt32();
// if creature is in same map with caster go at its current location
if (Creature* creature = ObjectAccessor::GetCreature(*player, ObjectGuid::Create<HighGuid::Unit>(id, guid)))
{
x = creature->GetPositionX();
y = creature->GetPositionY();
z = creature->GetPositionZ();
ort = creature->GetOrientation();
}
if (!MapMgr::IsValidMapCoord(mapId, x, y, z, ort))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, pos.GetPositionX(), pos.GetPositionY(), mapId);
handler->SetSentErrorMessage(true);
return false;
}
@@ -169,30 +85,96 @@ public:
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
player->TeleportTo({ mapId, pos });
return true;
}
static bool HandleGoGraveyardCommand(ChatHandler* handler, char const* args)
static bool HandleGoCreatureCIdCommand(ChatHandler* handler, Variant<Hyperlink<creature_entry>, uint32> cId)
{
Player* player = handler->GetSession()->GetPlayer();
CreatureData const* spawnpoint = nullptr;
for (auto const& pair : sObjectMgr->GetAllCreatureData())
{
if (pair.second.id != *cId)
continue;
if (!*args)
if (!spawnpoint)
spawnpoint = &pair.second;
else
{
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
break;
}
}
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
char* gyId = strtok((char*)args, " ");
if (!gyId)
return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid);
}
static bool HandleGoCreatureSpawnIdCommand(ChatHandler* handler, Variant<Hyperlink<creature>, ObjectGuid::LowType> spawnId)
{
CreatureData const* spawnpoint = sObjectMgr->GetCreatureData(spawnId);
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
int32 graveyardId = atoi(gyId);
return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid);
}
if (!graveyardId)
static bool HandleGoGameObjectSpawnIdCommand(ChatHandler* handler, uint32 spawnId)
{
GameObjectData const* spawnpoint = sObjectMgr->GetGOData(spawnId);
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
GraveyardStruct const* gy = sGraveyard->GetGraveyard(graveyardId);
return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid);
}
static bool HandleGoGameObjectGOIdCommand(ChatHandler* handler, uint32 goId)
{
GameObjectData const* spawnpoint = nullptr;
for (auto const& pair : sObjectMgr->GetAllGOData())
{
if (pair.second.id != goId)
continue;
if (!spawnpoint)
spawnpoint = &pair.second;
else
{
handler->SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE);
break;
}
}
if (!spawnpoint)
{
handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
return DoTeleport(handler, { spawnpoint->posX, spawnpoint->posY, spawnpoint->posZ }, spawnpoint->mapid);
}
static bool HandleGoGraveyardCommand(ChatHandler* handler, uint32 gyId)
{
GraveyardStruct const* gy = sGraveyard->GetGraveyard(gyId);
if (!gy)
{
handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, graveyardId);
handler->PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, gyId);
handler->SetSentErrorMessage(true);
return false;
}
@@ -204,6 +186,7 @@ public:
return false;
}
Player* player = handler->GetSession()->GetPlayer();
// stop flight if need
if (player->IsInFlight())
{
@@ -219,25 +202,14 @@ public:
}
//teleport to grid
static bool HandleGoGridCommand(ChatHandler* handler, char const* args)
static bool HandleGoGridCommand(ChatHandler* handler, float gridX, float gridY, Optional<uint32> oMapId)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* gridX = strtok((char*)args, " ");
char* gridY = strtok(nullptr, " ");
char* id = strtok(nullptr, " ");
if (!gridX || !gridY)
return false;
uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
uint32 mapId = oMapId.value_or(player->GetMapId());
// center of grid
float x = ((float)atof(gridX) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
float y = ((float)atof(gridY) - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
float x = (gridX - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
float y = (gridY - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
if (!MapMgr::IsValidMapCoord(mapId, x, y))
{
@@ -263,178 +235,36 @@ public:
return true;
}
//teleport to gameobject
static bool HandleGoObjectCommand(ChatHandler* handler, char const* args)
static bool HandleGoTaxinodeCommand(ChatHandler* handler, Variant<Hyperlink<taxinode>, uint32> nodeId)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
int32 guid = atoi(id);
if (!guid)
return false;
float x, y, z, ort;
int mapId;
// by DB guid
if (GameObjectData const* goData = sObjectMgr->GetGOData(guid))
{
x = goData->posX;
y = goData->posY;
z = goData->posZ;
ort = goData->orientation;
mapId = goData->mapid;
}
else
{
handler->SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND);
handler->SetSentErrorMessage(true);
return false;
}
if (!MapMgr::IsValidMapCoord(mapId, x, y, z, ort))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
return true;
}
static bool HandleGoTaxinodeCommand(ChatHandler* handler, char const* args)
{
Player* player = handler->GetSession()->GetPlayer();
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Htaxinode");
if (!id)
return false;
int32 nodeId = atoi(id);
if (!nodeId)
return false;
TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(nodeId);
if (!node)
{
handler->PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND, nodeId);
handler->PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND, uint32(nodeId));
handler->SetSentErrorMessage(true);
return false;
}
if ((node->x == 0.0f && node->y == 0.0f && node->z == 0.0f) ||
!MapMgr::IsValidMapCoord(node->map_id, node->x, node->y, node->z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, node->x, node->y, node->map_id);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(node->map_id, node->x, node->y, node->z, player->GetOrientation());
return true;
return DoTeleport(handler, { node->x, node->y, node->z }, node->map_id);
}
static bool HandleGoTriggerCommand(ChatHandler* handler, char const* args)
static bool HandleGoTriggerCommand(ChatHandler* handler, Variant<Hyperlink<areatrigger>, uint32> areaTriggerId)
{
Player* player = handler->GetSession()->GetPlayer();
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
int32 areaTriggerId = atoi(id);
if (!areaTriggerId)
return false;
AreaTrigger const* at = sObjectMgr->GetAreaTrigger(areaTriggerId);
if (!at)
{
handler->PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND, areaTriggerId);
handler->PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND, uint32(areaTriggerId));
handler->SetSentErrorMessage(true);
return false;
}
if (!MapMgr::IsValidMapCoord(at->map, at->x, at->y, at->z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, at->x, at->y, at->map);
handler->SetSentErrorMessage(true);
return false;
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(at->map, at->x, at->y, at->z, player->GetOrientation());
return true;
return DoTeleport(handler, { at->x, at->y, at->z }, at->map);
}
//teleport at coordinates
static bool HandleGoZoneXYCommand(ChatHandler* handler, char const* args)
static bool HandleGoZoneXYCommand(ChatHandler* handler, float x, float y, Optional<Variant<Hyperlink<area>, uint32>> areaIdArg)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
char* zoneX = strtok((char*)args, " ");
char* zoneY = strtok(nullptr, " ");
char* tail = strtok(nullptr, "");
char* id = handler->extractKeyFromLink(tail, "Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
if (!zoneX || !zoneY)
return false;
float x = (float)atof(zoneX);
float y = (float)atof(zoneY);
// prevent accept wrong numeric args
if ((x == 0.0f && *zoneX != '0') || (y == 0.0f && *zoneY != '0'))
return false;
uint32 areaId = id ? (uint32)atoi(id) : player->GetZoneId();
uint32 areaId = areaIdArg ? *areaIdArg : player->GetZoneId();
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(areaId);
@@ -447,6 +277,7 @@ public:
// update to parent zone if exist (client map show only zones without parents)
AreaTableEntry const* zoneEntry = areaEntry->zone ? sAreaTableStore.LookupEntry(areaEntry->zone) : areaEntry;
ASSERT(zoneEntry);
Map const* map = sMapMgr->CreateBaseMap(zoneEntry->mapid);
@@ -483,32 +314,14 @@ public:
}
//teleport at coordinates, including Z and orientation
static bool HandleGoXYZCommand(ChatHandler* handler, char const* args)
static bool HandleGoXYZCommand(ChatHandler* handler, float x, float y, Optional<float> z, Optional<uint32> id, Optional<float> o)
{
if (!*args)
return false;
Player* player = handler->GetSession()->GetPlayer();
uint32 mapId = id.value_or(player->GetMapId());
char* goX = strtok((char*)args, " ");
char* goY = strtok(nullptr, " ");
char* goZ = strtok(nullptr, " ");
char* id = strtok(nullptr, " ");
char* port = strtok(nullptr, " ");
if (!goX || !goY)
return false;
float x = (float)atof(goX);
float y = (float)atof(goY);
float z;
float ort = port ? (float)atof(port) : player->GetOrientation();
uint32 mapId = id ? (uint32)atoi(id) : player->GetMapId();
if (goZ)
if (z)
{
z = (float)atof(goZ);
if (!MapMgr::IsValidMapCoord(mapId, x, y, z))
if (!MapMgr::IsValidMapCoord(mapId, x, y, *z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapId);
handler->SetSentErrorMessage(true);
@@ -527,33 +340,11 @@ public:
z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
}
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
player->TeleportTo(mapId, x, y, z, ort);
return true;
return DoTeleport(handler, { x, y, *z, o.value_or(0.0f) }, mapId);
}
static bool HandleGoTicketCommand(ChatHandler* handler, char const* args)
static bool HandleGoTicketCommand(ChatHandler* handler, uint32 ticketId)
{
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
uint32 ticketId = atoi(id);
if (!ticketId)
return false;
GmTicket* ticket = sTicketMgr->GetTicket(ticketId);
if (!ticket)
{
@@ -562,11 +353,14 @@ public:
}
Player* player = handler->GetSession()->GetPlayer();
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();