Professional Documents
Culture Documents
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright
information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "Chat.h"
#include "GameEventMgr.h"
#include "GameObject.h"
#include "GameTime.h"
#include "Language.h"
#include "MapMgr.h"
#include "ObjectMgr.h"
#include "Opcodes.h"
#include "Player.h"
#include "PoolMgr.h"
#include "ScriptMgr.h"
#include "Transport.h"
// Activate
object->SetLootState(GO_READY);
object->UseDoorOrButton(autoCloseTime, false, handler->GetSession()-
>GetPlayer());
handler->PSendSysMessage("Object activated!");
return true;
}
//spawn go
static bool HandleGameObjectAddCommand(ChatHandler* handler, GameObjectEntry
objectId, Optional<int32> spawnTimeSecs)
{
if (!objectId)
return false;
if (objectInfo->displayId && !
sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
{
// report to DB errors log as in loading case
LOG_ERROR("sql.sql", "Gameobject (Entry {} GoType: {}) have invalid
displayId ({}), not spawned.", *objectId, objectInfo->type, objectInfo->displayId);
handler->PSendSysMessage(LANG_GAMEOBJECT_HAVE_INVALID_DATA,
uint32(objectId));
handler->SetSentErrorMessage(true);
return false;
}
if (spawnTimeSecs)
object->SetRespawnTime(*spawnTimeSecs);
// 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
delete object;
/// @todo is it really necessary to add both the real and DB table guid
here ?
sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGOData(guidLow));
handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, uint32(objectId), objectInfo-
>name.c_str(), guidLow, player->GetPositionX(), player->GetPositionY(), player-
>GetPositionZ());
return true;
}
if (!sObjectMgr->GetGameObjectTemplate(objectId))
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, uint32(objectId));
handler->SetSentErrorMessage(true);
return false;
}
float x = player->GetPositionX();
float y = player->GetPositionY();
float z = player->GetPositionZ();
float ang = player->GetOrientation();
return true;
}
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",
player->GetPositionX(), player-
>GetPositionY(), player->GetPositionZ(), player->GetMapId(),
static_cast<uint32>(objectId->get<GameObjectEntry>()));
}
else
{
std::string name = std::string(objectId->get<std::string_view>());
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_ "
"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());
}
}
else
{
std::ostringstream eventFilter;
eventFilter << " AND (eventEntry IS NULL ";
bool initString = true;
if (!initString)
eventFilter << "))";
else
eventFilter << ')';
if (!result)
{
handler->SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND);
return true;
}
do
{
Field* fields = result->Fetch();
guidLow = fields[0].GetUInt32();
id = fields[1].GetUInt32();
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
o = fields[5].GetFloat();
mapId = fields[6].GetUInt16();
phase = fields[7].GetUInt32();
poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
found = true;
} while (result->NextRow() && !found);
if (!found)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
if (!objectInfo)
{
handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, id);
return false;
}
if (target)
{
int32 curRespawnDelay = int32(target->GetRespawnTimeEx() -
GameTime::GetGameTime().count());
if (curRespawnDelay < 0)
curRespawnDelay = 0;
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES,
defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
}
return true;
}
owner->RemoveGameObject(object, false);
}
handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetSpawnId());
return true;
}
if (!oz)
oz = handler->GetSession()->GetPlayer()->GetOrientation();
handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetSpawnId(),
object->GetGOInfo()->name.c_str(), object->GetSpawnId());
return true;
}
Position pos;
if (xyz)
{
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
{
pos = handler->GetSession()->GetPlayer()->GetPosition();
}
pos.SetOrientation(object->GetOrientation());
object->Relocate(pos);
handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetSpawnId(),
object->GetGOInfo()->name.c_str(), object->GetSpawnId());
return true;
}
if (!phaseMask)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
object->SetPhaseMask(phaseMask, true);
object->SaveToDB();
return true;
}
WorldDatabasePreparedStatement* 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);
stmt->setUInt32(8, player->GetPhaseMask());
PreparedQueryResult result = WorldDatabase.Query(stmt);
if (result)
{
do
{
Field* fields = result->Fetch();
ObjectGuid::LowType guid = fields[0].GetUInt32();
uint32 entry = fields[1].GetUInt32();
float x = fields[2].GetFloat();
float y = fields[3].GetFloat();
float z = fields[4].GetFloat();
uint16 mapId = fields[5].GetUInt16();
if (!gameObjectInfo)
continue;
++count;
} while (result->NextRow());
}
if (!objectId)
{
if (WorldObject* object = handler->getSelectedObject())
{
entry = object->GetEntry();
if (object->GetTypeId() == TYPEID_GAMEOBJECT)
gameObject = object->ToGameObject();
}
}
else
entry = static_cast<uint32>(objectId->get<GameObjectEntry>());
type = gameObjectInfo->type;
displayId = gameObjectInfo->displayId;
name = gameObjectInfo->name;
if (type == GAMEOBJECT_TYPE_CHEST)
lootId = gameObjectInfo->chest.lootId;
else if (type == GAMEOBJECT_TYPE_FISHINGHOLE)
lootId = gameObjectInfo->fishinghole.lootId;
handler->PSendSysMessage(LANG_GOINFO_ENTRY, entry);
handler->PSendSysMessage(LANG_GOINFO_TYPE, type);
handler->PSendSysMessage(LANG_GOINFO_LOOTID, lootId);
handler->PSendSysMessage(LANG_GOINFO_DISPLAYID, displayId);
if (gameObject)
{
handler->PSendSysMessage("LootMode: %u", gameObject->GetLootMode());
handler->PSendSysMessage("LootState: %u", gameObject->getLootState());
handler->PSendSysMessage("GOState: %u", gameObject->GetGoState());
handler->PSendSysMessage("PhaseMask: %u", gameObject->GetPhaseMask());
handler->PSendSysMessage("IsLootEmpty: %u", gameObject->loot.empty());
handler->PSendSysMessage("IsLootLooted: %u", gameObject-
>loot.isLooted());
}
handler->PSendSysMessage(LANG_GOINFO_NAME, name.c_str());
return true;
}
if (objectType < 0)
{
if (objectType == -1)
object->SendObjectDeSpawnAnim(object->GetGUID());
else if (objectType == -2)
return false;
return true;
}
if (!objectState)
return false;
if (objectType < 4)
object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, *objectState);
else if (objectType == 4)
{
object->SendCustomAnim(*objectState);
}
handler->PSendSysMessage("Set gobject type %d state %u", objectType,
*objectState);
return true;
}
};
void AddSC_gobject_commandscript()
{
new gobject_commandscript();
}