Files
TCPlayerbotCore/src/server/scripts/Commands/cs_gobject.cpp
T

680 lines
24 KiB
C++
Raw Normal View History

/*
2012-12-31 23:15:50 +01:00
* Copyright (C) 2008-2013 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: gobject_commandscript
%Complete: 100
Comment: All gobject related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "GameEventMgr.h"
#include "ObjectMgr.h"
#include "PoolMgr.h"
#include "MapManager.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "Opcodes.h"
class gobject_commandscript : public CommandScript
{
public:
gobject_commandscript() : CommandScript("gobject_commandscript") { }
ChatCommand* GetCommands() const
{
static ChatCommand gobjectAddCommandTable[] =
{
{ "temp", SEC_GAMEMASTER, false, &HandleGameObjectAddTempCommand, "", NULL },
{ "", SEC_GAMEMASTER, false, &HandleGameObjectAddCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand gobjectSetCommandTable[] =
{
{ "phase", SEC_GAMEMASTER, false, &HandleGameObjectSetPhaseCommand, "", NULL },
{ "state", SEC_GAMEMASTER, false, &HandleGameObjectSetStateCommand, "", NULL },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand gobjectCommandTable[] =
{
{ "activate", SEC_GAMEMASTER, false, &HandleGameObjectActivateCommand, "", NULL },
{ "delete", SEC_GAMEMASTER, false, &HandleGameObjectDeleteCommand, "", NULL },
{ "info", SEC_GAMEMASTER, false, &HandleGameObjectInfoCommand, "", NULL },
{ "move", SEC_GAMEMASTER, false, &HandleGameObjectMoveCommand, "", NULL },
{ "near", SEC_GAMEMASTER, false, &HandleGameObjectNearCommand, "", NULL },
{ "target", SEC_GAMEMASTER, false, &HandleGameObjectTargetCommand, "", NULL },
{ "turn", SEC_GAMEMASTER, false, &HandleGameObjectTurnCommand, "", NULL },
{ "add", SEC_GAMEMASTER, false, NULL, "", gobjectAddCommandTable },
{ "set", SEC_GAMEMASTER, false, NULL, "", gobjectSetCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
static ChatCommand commandTable[] =
{
{ "gobject", SEC_GAMEMASTER, false, NULL, "", gobjectCommandTable },
{ NULL, 0, false, NULL, "", NULL }
};
return commandTable;
}
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectActivateCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
// by DB guid
2011-10-10 10:33:13 -03:00
if (GameObjectData const* goData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, goData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
// Activate
2011-10-10 10:33:13 -03:00
object->SetLootState(GO_READY);
object->UseDoorOrButton(10000, false, handler->GetSession()->GetPlayer());
handler->PSendSysMessage("Object activated!");
return true;
}
//spawn go
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectAddCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 objectId = atol(id);
if (!objectId)
return false;
char* spawntimeSecs = strtok(NULL, " ");
2011-10-10 10:33:13 -03:00
const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
2011-10-10 10:33:13 -03:00
if (!objectInfo)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
sLog->outError(LOG_FILTER_SQL, "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA, objectId);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
float x = float(player->GetPositionX());
float y = float(player->GetPositionY());
float z = float(player->GetPositionZ());
float o = float(player->GetOrientation());
Map* map = player->GetMap();
2011-10-10 10:33:13 -03:00
GameObject* object = new GameObject;
uint32 guidLow = sObjectMgr->GenerateLowGuid(HIGHGUID_GAMEOBJECT);
2011-10-10 10:33:13 -03:00
if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
{
2011-10-10 10:33:13 -03:00
delete object;
return false;
}
if (spawntimeSecs)
{
uint32 value = atoi((char*)spawntimeSecs);
2011-10-10 10:33:13 -03:00
object->SetRespawnTime(value);
}
// fill the gameobject data and save to the db
2011-10-10 10:33:13 -03:00
object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
// this will generate a new guid if the object is in an instance
if (!object->LoadGameObjectFromDB(guidLow, map))
{
2011-10-10 10:33:13 -03:00
delete object;
return false;
}
/// @todo is it really necessary to add both the real and DB table guid here ?
2011-10-10 10:33:13 -03:00
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
return true;
}
// add go, temp only
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectAddTempCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
2011-10-10 10:33:13 -03:00
char* id = strtok((char*)args, " ");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
char* spawntime = strtok(NULL, " ");
uint32 spawntm = 300;
if (spawntime)
spawntm = atoi((char*)spawntime);
2011-10-10 10:33:13 -03:00
float x = player->GetPositionX();
float y = player->GetPositionY();
float z = player->GetPositionZ();
float ang = player->GetOrientation();
2012-10-02 15:06:19 +02:00
float rot2 = std::sin(ang/2);
float rot3 = std::cos(ang/2);
2011-10-10 10:33:13 -03:00
uint32 objectId = atoi(id);
2011-10-10 10:33:13 -03:00
player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
return true;
}
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectTargetCommand(ChatHandler* handler, char const* args)
{
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
QueryResult result;
GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList();
2011-10-10 10:33:13 -03:00
if (*args)
{
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 objectId = atol(id);
2011-10-10 10:33:13 -03:00
if (objectId)
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",
2011-10-10 10:33:13 -03:00
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), objectId);
else
{
2011-10-10 10:33:13 -03:00
std::string name = id;
WorldDatabase.EscapeString(name);
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_ "
2011-04-29 20:47:02 +02:00
"FROM gameobject, gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name "_LIKE_" "_CONCAT3_("'%%'", "'%s'", "'%%'")" ORDER BY order_ ASC LIMIT 1",
2011-10-10 10:33:13 -03:00
player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name.c_str());
}
}
else
{
std::ostringstream eventFilter;
2011-03-19 18:10:28 +01:00
eventFilter << " AND (eventEntry IS NULL ";
bool initString = true;
for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
{
if (initString)
{
2011-10-10 10:33:13 -03:00
eventFilter << "OR eventEntry IN (" << *itr;
initString = false;
}
else
eventFilter << ',' << *itr;
}
if (!initString)
eventFilter << "))";
else
eventFilter << ')';
result = WorldDatabase.PQuery("SELECT gameobject.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 "
2011-03-18 18:49:15 +01:00
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
handler->GetSession()->GetPlayer()->GetPositionX(), handler->GetSession()->GetPlayer()->GetPositionY(), handler->GetSession()->GetPlayer()->GetPositionZ(),
2011-04-29 20:47:02 +02:00
handler->GetSession()->GetPlayer()->GetMapId(), eventFilter.str().c_str());
}
if (!result)
{
handler->SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND);
return true;
}
bool found = false;
float x, y, z, o;
2011-10-10 10:33:13 -03:00
uint32 guidLow, id;
uint16 mapId, phase;
uint32 poolId;
do
{
Field* fields = result->Fetch();
2011-10-10 10:33:13 -03:00
guidLow = fields[0].GetUInt32();
id = fields[1].GetUInt32();
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
o = fields[5].GetFloat();
2011-10-10 10:33:13 -03:00
mapId = fields[6].GetUInt16();
phase = fields[7].GetUInt16();
2011-10-10 10:33:13 -03:00
poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
found = true;
2011-10-10 10:33:13 -03:00
} while (result->NextRow() && !found);
if (!found)
{
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
2011-10-10 10:33:13 -03:00
GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(id);
2011-10-10 10:33:13 -03:00
if (!objectInfo)
{
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
2011-10-10 10:33:13 -03:00
GameObject* target = handler->GetSession()->GetPlayer()->GetMap()->GetGameObject(MAKE_NEW_GUID(guidLow, id, HIGHGUID_GAMEOBJECT));
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name.c_str(), guidLow, id, x, y, z, mapId, o, phase);
if (target)
{
2011-10-10 10:33:13 -03:00
int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - time(NULL));
if (curRespawnDelay < 0)
curRespawnDelay = 0;
2011-04-29 20:47:02 +02:00
std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
}
return true;
}
//delete object by selection or guid
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectDeleteCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
// by DB guid
2011-10-10 10:33:13 -03:00
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
uint64 ownerGuid = object->GetOwnerGUID();
if (ownerGuid)
{
2011-10-10 10:33:13 -03:00
Unit* owner = ObjectAccessor::GetUnit(*handler->GetSession()->GetPlayer(), ownerGuid);
if (!owner || !IS_PLAYER_GUID(ownerGuid))
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, GUID_LOPART(ownerGuid), object->GetGUIDLow());
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
owner->RemoveGameObject(object, false);
}
2011-10-10 10:33:13 -03:00
object->SetRespawnTime(0); // not save respawn time
object->Delete();
object->DeleteFromDB();
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetGUIDLow());
return true;
}
//turn selected object
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectTurnCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
// by DB guid
2011-10-10 10:33:13 -03:00
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
char* orientation = strtok(NULL, " ");
float o;
2011-10-10 10:33:13 -03:00
if (orientation)
o = (float)atof(orientation);
else
{
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
o = player->GetOrientation();
}
2011-10-10 10:33:13 -03:00
object->Relocate(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), o);
object->UpdateRotationFields();
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
2011-10-10 10:33:13 -03:00
object->SaveToDB();
object->Refresh();
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetGUIDLow(), object->GetGOInfo()->name.c_str(), object->GetGUIDLow(), o);
return true;
}
//move selected object
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectMoveCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
// by DB guid
2011-10-10 10:33:13 -03:00
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
char* toX = strtok(NULL, " ");
char* toY = strtok(NULL, " ");
char* toZ = strtok(NULL, " ");
2011-10-10 10:33:13 -03:00
if (!toX)
{
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
object->Relocate(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), object->GetOrientation());
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
}
else
{
2011-10-10 10:33:13 -03:00
if (!toY || !toZ)
return false;
2011-10-10 10:33:13 -03:00
float x = (float)atof(toX);
float y = (float)atof(toY);
float z = (float)atof(toZ);
2011-10-10 10:33:13 -03:00
if (!MapManager::IsValidMapCoord(object->GetMapId(), x, y, z))
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, object->GetMapId());
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
object->Relocate(x, y, z, object->GetOrientation());
object->DestroyForNearbyPlayers();
object->UpdateObjectVisibility();
}
2011-10-10 10:33:13 -03:00
object->SaveToDB();
object->Refresh();
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetGUIDLow(), object->GetGOInfo()->name.c_str(), object->GetGUIDLow());
return true;
}
2011-10-10 10:33:13 -03:00
//set phasemask for selected object
static bool HandleGameObjectSetPhaseCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
// by DB guid
2011-10-10 10:33:13 -03:00
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
char* phase = strtok (NULL, " ");
uint32 phaseMask = phase ? atoi(phase) : 0;
if (phaseMask == 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
object->SetPhaseMask(phaseMask, true);
object->SaveToDB();
return true;
}
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectNearCommand(ChatHandler* handler, char const* args)
{
float distance = (!*args) ? 10.0f : (float)(atof(args));
uint32 count = 0;
2011-10-10 10:33:13 -03:00
Player* player = handler->GetSession()->GetPlayer();
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_GAMEOBJECT_NEAREST);
stmt->setFloat(0, player->GetPositionX());
stmt->setFloat(1, player->GetPositionY());
stmt->setFloat(2, player->GetPositionZ());
stmt->setUInt32(3, player->GetMapId());
stmt->setFloat(4, player->GetPositionX());
stmt->setFloat(5, player->GetPositionY());
stmt->setFloat(6, player->GetPositionZ());
stmt->setFloat(7, distance * distance);
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
uint32 guid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
2011-10-10 10:33:13 -03:00
uint16 mapId = fields[5].GetUInt16();
2011-10-10 10:33:13 -03:00
GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
2011-10-10 10:33:13 -03:00
if (!gameObjectInfo)
continue;
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name.c_str(), x, y, z, mapId);
++count;
} while (result->NextRow());
}
2011-04-29 20:47:02 +02:00
handler->PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, count);
return true;
}
//show info of gameobject
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectInfoCommand(ChatHandler* handler, char const* args)
{
uint32 entry = 0;
uint32 type = 0;
2011-10-10 10:33:13 -03:00
uint32 displayId = 0;
std::string name;
uint32 lootId = 0;
if (!*args)
2010-11-22 10:10:46 +01:00
{
2011-10-10 10:33:13 -03:00
if (WorldObject* object = handler->getSelectedObject())
entry = object->GetEntry();
else
entry = atoi((char*)args);
2010-11-22 10:10:46 +01:00
}
2011-10-10 10:33:13 -03:00
GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
2011-10-10 10:33:13 -03:00
if (!gameObjectInfo)
return false;
2011-10-10 10:33:13 -03:00
type = gameObjectInfo->type;
displayId = gameObjectInfo->displayId;
name = gameObjectInfo->name;
if (type == GAMEOBJECT_TYPE_CHEST)
2011-10-10 10:33:13 -03:00
lootId = gameObjectInfo->chest.lootId;
else if (type == GAMEOBJECT_TYPE_FISHINGHOLE)
2011-10-10 10:33:13 -03:00
lootId = gameObjectInfo->fishinghole.lootId;
handler->PSendSysMessage(LANG_GOINFO_ENTRY, entry);
handler->PSendSysMessage(LANG_GOINFO_TYPE, type);
handler->PSendSysMessage(LANG_GOINFO_LOOTID, lootId);
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_GOINFO_DISPLAYID, displayId);
handler->PSendSysMessage(LANG_GOINFO_NAME, name.c_str());
return true;
}
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectSetStateCommand(ChatHandler* handler, char const* args)
{
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
if (!id)
return false;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi(id);
if (!guidLow)
return false;
2011-10-10 10:33:13 -03:00
GameObject* object = NULL;
2011-10-10 10:33:13 -03:00
if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
2011-10-10 10:33:13 -03:00
if (!object)
{
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
handler->SetSentErrorMessage(true);
return false;
}
2011-10-10 10:33:13 -03:00
char* type = strtok(NULL, " ");
if (!type)
return false;
2011-10-10 10:33:13 -03:00
int32 objectType = atoi(type);
if (objectType < 0)
{
2011-10-10 10:33:13 -03:00
if (objectType == -1)
object->SendObjectDeSpawnAnim(object->GetGUID());
else if (objectType == -2)
return false;
return true;
}
2011-10-10 10:33:13 -03:00
char* state = strtok(NULL, " ");
if (!state)
return false;
2011-10-10 10:33:13 -03:00
int32 objectState = atoi(state);
2011-10-10 10:33:13 -03:00
if (objectType < 4)
object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, objectState);
else if (objectType == 4)
{
2011-04-29 20:47:02 +02:00
WorldPacket data(SMSG_GAMEOBJECT_CUSTOM_ANIM, 8+4);
2011-10-10 10:33:13 -03:00
data << object->GetGUID();
data << (uint32)(objectState);
object->SendMessageToSet(&data, true);
}
2011-10-10 10:33:13 -03:00
handler->PSendSysMessage("Set gobject type %d state %d", objectType, objectState);
return true;
}
};
void AddSC_gobject_commandscript()
{
new gobject_commandscript();
}