feat(Scripts/Commands): convert cs_object to new system (#8855)

This commit is contained in:
IntelligentQuantum
2021-11-01 21:58:19 +03:30
committed by GitHub
parent f106de8788
commit 2f25323456
+94 -225
View File
@@ -34,12 +34,11 @@ EndScriptData */
#include "ScriptMgr.h" #include "ScriptMgr.h"
#include "Transport.h" #include "Transport.h"
#if AC_COMPILER == AC_COMPILER_GNU
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
using namespace Acore::ChatCommands; using namespace Acore::ChatCommands;
using GameObjectSpawnId = Variant<Hyperlink<gameobject>, ObjectGuid::LowType>;
using GameObjectEntry = Variant<Hyperlink<gameobject_entry>, uint32>;
class gobject_commandscript : public CommandScript class gobject_commandscript : public CommandScript
{ {
public: public:
@@ -47,59 +46,42 @@ public:
ChatCommandTable GetCommands() const override ChatCommandTable GetCommands() const override
{ {
static ChatCommandTable gobjectAddCommandTable =
{
{ "temp", SEC_GAMEMASTER, false, &HandleGameObjectAddTempCommand, "" },
{ "", SEC_ADMINISTRATOR, false, &HandleGameObjectAddCommand, "" }
};
static ChatCommandTable gobjectSetCommandTable =
{
{ "phase", SEC_ADMINISTRATOR, false, &HandleGameObjectSetPhaseCommand, "" },
{ "state", SEC_ADMINISTRATOR, false, &HandleGameObjectSetStateCommand, "" }
};
static ChatCommandTable gobjectCommandTable = static ChatCommandTable gobjectCommandTable =
{ {
{ "activate", SEC_GAMEMASTER, false, &HandleGameObjectActivateCommand, "" }, { "activate", HandleGameObjectActivateCommand, SEC_GAMEMASTER, Console::No },
{ "delete", SEC_ADMINISTRATOR, false, &HandleGameObjectDeleteCommand, "" }, { "delete", HandleGameObjectDeleteCommand, SEC_ADMINISTRATOR, Console::No },
{ "info", SEC_MODERATOR, false, &HandleGameObjectInfoCommand, "" }, { "info", HandleGameObjectInfoCommand, SEC_MODERATOR, Console::No },
{ "move", SEC_ADMINISTRATOR, false, &HandleGameObjectMoveCommand, "" }, { "move", HandleGameObjectMoveCommand, SEC_ADMINISTRATOR, Console::No },
{ "near", SEC_MODERATOR, false, &HandleGameObjectNearCommand, "" }, { "near", HandleGameObjectNearCommand, SEC_MODERATOR, Console::No },
{ "target", SEC_MODERATOR, false, &HandleGameObjectTargetCommand, "" }, { "target", HandleGameObjectTargetCommand, SEC_MODERATOR, Console::No },
{ "turn", SEC_ADMINISTRATOR, false, &HandleGameObjectTurnCommand, "" }, { "turn", HandleGameObjectTurnCommand, SEC_ADMINISTRATOR, Console::No },
{ "add", SEC_ADMINISTRATOR, false, nullptr, "", gobjectAddCommandTable }, { "add temp", HandleGameObjectAddTempCommand, SEC_GAMEMASTER, Console::No },
{ "set", SEC_ADMINISTRATOR, false, nullptr, "", gobjectSetCommandTable } { "add", HandleGameObjectAddCommand, SEC_ADMINISTRATOR, Console::No },
{ "set phase", HandleGameObjectSetPhaseCommand, SEC_ADMINISTRATOR, Console::No },
{ "set state", HandleGameObjectSetStateCommand, SEC_ADMINISTRATOR, Console::No }
}; };
static ChatCommandTable commandTable = static ChatCommandTable commandTable =
{ {
{ "gobject", SEC_MODERATOR, false, nullptr, "", gobjectCommandTable } { "gobject", gobjectCommandTable }
}; };
return commandTable; return commandTable;
} }
static bool HandleGameObjectActivateCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectActivateCommand(ChatHandler* handler, GameObjectSpawnId guidLow)
{ {
if (!*args)
return false;
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
ObjectGuid::LowType guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(guidLow));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
uint32_t const autoCloseTime = object->GetGOInfo()->GetAutoCloseTime() ? 10000u : 0u;
// Activate // Activate
object->SetLootState(GO_READY); object->SetLootState(GO_READY);
object->UseDoorOrButton(10000, false, handler->GetSession()->GetPlayer()); object->UseDoorOrButton(autoCloseTime, false, handler->GetSession()->GetPlayer());
handler->PSendSysMessage("Object activated!"); handler->PSendSysMessage("Object activated!");
@@ -107,27 +89,15 @@ public:
} }
//spawn go //spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectAddCommand(ChatHandler* handler, GameObjectEntry objectId, Optional<int32> spawnTimeSecs)
{ {
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (!objectId) if (!objectId)
return false; return false;
char* spawntimeSecs = strtok(nullptr, " "); GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
if (!objectInfo) if (!objectInfo)
{ {
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId); handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, uint32(objectId));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
@@ -135,8 +105,8 @@ public:
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId)) if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{ {
// report to DB errors log as in loading case // report to DB errors log as in loading case
LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId); LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", *objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId); handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, uint32(objectId));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
@@ -157,51 +127,44 @@ public:
return false; return false;
} }
if (spawntimeSecs) if (spawnTimeSecs)
{ object->SetRespawnTime(*spawnTimeSecs);
uint32 value = atoi((char*)spawntimeSecs);
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db // fill the gameobject data and save to the db
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn()); object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
guidLow = object->GetSpawnId(); guidLow = object->GetSpawnId();
// delete the old object and do a clean load from DB with a fresh new GameObject instance. // delete the old object and do a clean load from DB with a fresh new GameObject instance.
// this is required to avoid weird behavior and memory leaks // this is required to avoid weird behavior and memory leaks
delete object; delete object;
object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject(); object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
// this will generate a new guid if the object is in an instance // this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map)) if (!object->LoadGameObjectFromDB(guidLow, map, true))
{ {
delete object; delete object;
return false; return false;
} }
// TODO: is it really necessary to add both the real and DB table guid here ? /// @todo is it really necessary to add both the real and DB table guid here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow)); sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z); handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, uint32(objectId), objectInfo->name.c_str(), guidLow, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
return true; return true;
} }
// add go, temp only // add go, temp only
static bool HandleGameObjectAddTempCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectAddTempCommand(ChatHandler* handler, GameObjectEntry objectId, Optional<uint64> spawntime)
{ {
if (!*args)
return false;
char* id = strtok((char*)args, " ");
if (!id)
return false;
Player* player = handler->GetSession()->GetPlayer(); Player* player = handler->GetSession()->GetPlayer();
uint64 spawntm(spawntime.value_or(300));
char* spawntime = strtok(nullptr, " "); if (!sObjectMgr->GetGameObjectTemplate(objectId))
uint32 spawntm = 300; {
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, uint32(objectId));
if (spawntime) handler->SetSentErrorMessage(true);
spawntm = atoi((char*)spawntime); return false;
}
float x = player->GetPositionX(); float x = player->GetPositionX();
float y = player->GetPositionY(); float y = player->GetPositionY();
@@ -211,38 +174,31 @@ public:
float rot2 = sin(ang / 2); float rot2 = sin(ang / 2);
float rot3 = cos(ang / 2); float rot3 = cos(ang / 2);
uint32 objectId = atoi(id);
player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm); player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
return true; return true;
} }
static bool HandleGameObjectTargetCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectTargetCommand(ChatHandler* handler, Optional<Variant<GameObjectEntry, std::string_view>> objectId)
{ {
Player* player = handler->GetSession()->GetPlayer(); Player* player = handler->GetSession()->GetPlayer();
QueryResult result; QueryResult result;
GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList(); GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList();
if (*args)
{
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
uint32 objectId = atol(id);
if (objectId) if (objectId)
{
if (objectId->holds_alternative<GameObjectEntry>())
{
result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1", result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), objectId); player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), static_cast<uint32>(objectId->get<GameObjectEntry>()));
}
else else
{ {
std::string name = id; std::string name = std::string(objectId->get<std::string_view>());
WorldDatabase.EscapeString(name); WorldDatabase.EscapeString(name);
result = WorldDatabase.PQuery( result = WorldDatabase.PQuery(
"SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ " "SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ "
"FROM gameobject, gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name LIKE '%%%s%%' ORDER BY order_ ASC LIMIT 1", "FROM gameobject LEFT JOIN gameobject_template ON gameobject_template.entry = gameobject.id WHERE map = %i AND name LIKE '%%%s%%' ORDER BY order_ ASC LIMIT 1",
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name.c_str()); player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name.c_str());
} }
} }
@@ -318,7 +274,7 @@ public:
return false; return false;
} }
GameObject* target = handler->GetSession()->GetPlayer()->GetMap()->GetGameObject(ObjectGuid::Create<HighGuid::GameObject>(id, guidLow)); GameObject* target = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name.c_str(), guidLow, id, x, y, z, mapId, o, phase); handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name.c_str(), guidLow, id, x, y, z, mapId, o, phase);
@@ -337,21 +293,12 @@ public:
} }
//delete object by selection or guid //delete object by selection or guid
static bool HandleGameObjectDeleteCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectDeleteCommand(ChatHandler* handler, GameObjectSpawnId spawnId)
{ {
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(spawnId);
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
ObjectGuid::LowType guidLow = atoi(id);
if (!guidLow)
return false;
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(spawnId));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
@@ -380,52 +327,26 @@ public:
} }
//turn selected object //turn selected object
static bool HandleGameObjectTurnCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectTurnCommand(ChatHandler* handler, GameObjectSpawnId guidLow, Optional<float> oz, Optional<float> oy, Optional<float> ox)
{ {
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
ObjectGuid::LowType guidLow = atoi(id);
if (!guidLow) if (!guidLow)
return false; return false;
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(guidLow));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
char* orientation = strtok(nullptr, " "); if (!oz)
float oz = 0.f, oy = 0.f, ox = 0.f; oz = handler->GetSession()->GetPlayer()->GetOrientation();
if (orientation)
{
oz = float(atof(orientation));
orientation = strtok(nullptr, " ");
if (orientation)
{
oy = float(atof(orientation));
orientation = strtok(nullptr, " ");
if (orientation)
ox = float(atof(orientation));
}
}
else
{
Player* player = handler->GetSession()->GetPlayer();
oz = player->GetOrientation();
}
Map* map = object->GetMap(); Map* map = object->GetMap();
object->Relocate(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), *oz);
object->Relocate(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), oz); object->SetLocalRotationAngles(*oz, oy.value_or(0.0f), ox.value_or(0.0f));
object->SetLocalRotationAngles(oz, oy, ox); object->SaveToDB();
object->SaveToDB(true);
// Generate a completely new spawn with new guid // Generate a completely new spawn with new guid
// 3.3.5a client caches recently deleted objects and brings them back to life // 3.3.5a client caches recently deleted objects and brings them back to life
@@ -434,63 +355,44 @@ public:
object->Delete(); object->Delete();
object = new GameObject(); object = new GameObject();
if (!object->LoadGameObjectFromDB(guidLow, map)) if (!object->LoadGameObjectFromDB(guidLow, map, true))
{ {
delete object; delete object;
return false; return false;
} }
handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetSpawnId(), oz, oy, ox); handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetSpawnId());
return true; return true;
} }
//move selected object //move selected object
static bool HandleGameObjectMoveCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectMoveCommand(ChatHandler* handler, GameObjectSpawnId guidLow, Optional<std::array<float,3>> xyz)
{ {
// 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;
ObjectGuid::LowType guidLow = atoi(id);
if (!guidLow) if (!guidLow)
return false; return false;
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(guidLow));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
char* toX = strtok(nullptr, " ");
char* toY = strtok(nullptr, " ");
char* toZ = strtok(nullptr, " ");
Position pos; Position pos;
if (!toX) if (xyz)
{ {
pos = handler->GetSession()->GetPlayer()->GetPosition(); pos = { (*xyz)[0], (*xyz)[1], (*xyz)[2] };
if (!MapMgr::IsValidMapCoord(object->GetMapId(), pos))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, pos.GetPositionX(), pos.GetPositionY(), object->GetMapId());
handler->SetSentErrorMessage(true);
return false;
}
} }
else else
{ {
if (!toY || !toZ) pos = handler->GetSession()->GetPlayer()->GetPosition();
return false;
float x = (float)atof(toX);
float y = (float)atof(toY);
float z = (float)atof(toZ);
if (!MapMgr::IsValidMapCoord(object->GetMapId(), x, y, z))
{
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, object->GetMapId());
handler->SetSentErrorMessage(true);
return false;
}
pos.Relocate(x, y, z);
} }
Map* map = object->GetMap(); Map* map = object->GetMap();
@@ -510,40 +412,31 @@ public:
object->Delete(); object->Delete();
object = new GameObject(); object = new GameObject();
if (!object->LoadGameObjectFromDB(guidLow, map)) if (!object->LoadGameObjectFromDB(guidLow, map, true))
{ {
delete object; delete object;
return false; return false;
} }
handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetSpawnId()); handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetSpawnId());
return true; return true;
} }
//set phasemask for selected object //set phasemask for selected object
static bool HandleGameObjectSetPhaseCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectSetPhaseCommand(ChatHandler* handler, GameObjectSpawnId guidLow, uint32 phaseMask)
{ {
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
ObjectGuid::LowType guidLow = atoi(id);
if (!guidLow) if (!guidLow)
return false; return false;
GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow); GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(guidLow));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
char* phase = strtok (nullptr, " "); if (!phaseMask)
uint32 phaseMask = phase ? atoi(phase) : 0;
if (phaseMask == 0)
{ {
handler->SendSysMessage(LANG_BAD_VALUE); handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
@@ -555,9 +448,9 @@ public:
return true; return true;
} }
static bool HandleGameObjectNearCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectNearCommand(ChatHandler* handler, Optional<float> dist)
{ {
float distance = (!*args) ? 10.0f : (float)(atof(args)); float distance = dist.value_or(10.0f);
uint32 count = 0; uint32 count = 0;
Player* player = handler->GetSession()->GetPlayer(); Player* player = handler->GetSession()->GetPlayer();
@@ -572,8 +465,8 @@ public:
stmt->setFloat(6, player->GetPositionZ()); stmt->setFloat(6, player->GetPositionZ());
stmt->setFloat(7, distance * distance); stmt->setFloat(7, distance * distance);
stmt->setUInt32(8, player->GetPhaseMask()); stmt->setUInt32(8, player->GetPhaseMask());
PreparedQueryResult result = WorldDatabase.Query(stmt); PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result) if (result)
{ {
do do
@@ -591,7 +484,7 @@ public:
if (!gameObjectInfo) if (!gameObjectInfo)
continue; continue;
handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name.c_str(), x, y, z, mapId); handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name.c_str(), x, y, z, mapId, "", "");
++count; ++count;
} while (result->NextRow()); } while (result->NextRow());
@@ -602,7 +495,7 @@ public:
} }
//show info of gameobject //show info of gameobject
static bool HandleGameObjectInfoCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectInfoCommand(ChatHandler* handler, Optional<Variant<GameObjectEntry, std::string_view>> objectId)
{ {
uint32 entry = 0; uint32 entry = 0;
uint32 type = 0; uint32 type = 0;
@@ -611,7 +504,7 @@ public:
uint32 lootId = 0; uint32 lootId = 0;
GameObject* gameObject = nullptr; GameObject* gameObject = nullptr;
if (!*args) if (!objectId)
{ {
if (WorldObject* object = handler->getSelectedObject()) if (WorldObject* object = handler->getSelectedObject())
{ {
@@ -621,12 +514,15 @@ public:
} }
} }
else else
entry = atoi((char*)args); entry = static_cast<uint32>(objectId->get<GameObjectEntry>());
GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry); GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!gameObjectInfo) if (!gameObjectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, entry);
handler->SetSentErrorMessage(true);
return false; return false;
}
type = gameObjectInfo->type; type = gameObjectInfo->type;
displayId = gameObjectInfo->displayId; displayId = gameObjectInfo->displayId;
@@ -655,38 +551,19 @@ public:
return true; return true;
} }
static bool HandleGameObjectSetStateCommand(ChatHandler* handler, char const* args) static bool HandleGameObjectSetStateCommand(ChatHandler* handler, GameObjectSpawnId guidLow, int32 objectType, Optional<uint32> objectState)
{ {
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
int32 guidLow = atoi(id);
if (!guidLow) if (!guidLow)
return false; return false;
GameObject* object = nullptr; GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
if (guidLow > 0)
{
object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
}
else
object = handler->GetSession()->GetPlayer()->FindNearestGameObject(-guidLow, 30.0f);
if (!object) if (!object)
{ {
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, abs(guidLow)); handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, uint32(guidLow));
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
char* type = strtok(nullptr, " ");
if (!type)
return false;
int32 objectType = atoi(type);
if (objectType < 0) if (objectType < 0)
{ {
if (objectType == -1) if (objectType == -1)
@@ -696,27 +573,19 @@ public:
return true; return true;
} }
char* state = strtok(nullptr, " "); if (!objectState)
if (!state)
return false; return false;
int32 objectState = atoi(state);
if (objectType < 4) if (objectType < 4)
object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, objectState); object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, *objectState);
else if (objectType == 4) else if (objectType == 4)
{ {
WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM, 8 + 4); WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM, 8+4);
data << object->GetGUID(); data << object->GetGUID();
data << (uint32)(objectState); data << static_cast<uint32>(*objectState);
object->SendMessageToSet(&data, true); object->SendMessageToSet(&data, true);
} }
else if (objectType == 5) handler->PSendSysMessage("Set gobject type %d state %u", objectType, *objectState);
object->SetUInt32Value(GAMEOBJECT_FLAGS, (uint32)(objectState));
else if (objectType == 6)
object->SetGoArtKit((uint32)(objectState));
handler->PSendSysMessage("Set gobject type %d state %d", objectType, objectState);
return true; return true;
} }
}; };