AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
gobject_commandscript Class Reference
Inheritance diagram for gobject_commandscript:
CommandScript ScriptObject

Public Member Functions

 gobject_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleGameObjectActivateCommand (ChatHandler *handler, GameObjectSpawnId guidLow)
 
static bool HandleGameObjectAddCommand (ChatHandler *handler, GameObjectEntry objectId, Optional< int32 > spawnTimeSecs)
 
static bool HandleGameObjectAddTempCommand (ChatHandler *handler, GameObjectEntry objectId, Optional< uint64 > spawntime)
 
static bool HandleGameObjectTargetCommand (ChatHandler *handler, Optional< Variant< GameObjectEntry, std::string_view > > objectId)
 
static bool HandleGameObjectDeleteCommand (ChatHandler *handler, GameObjectSpawnId spawnId)
 
static bool HandleGameObjectTurnCommand (ChatHandler *handler, GameObjectSpawnId guidLow, Optional< float > oz, Optional< float > oy, Optional< float > ox)
 
static bool HandleGameObjectMoveCommand (ChatHandler *handler, GameObjectSpawnId guidLow, Optional< std::array< float, 3 > > xyz)
 
static bool HandleGameObjectSetPhaseCommand (ChatHandler *handler, GameObjectSpawnId guidLow, uint32 phaseMask)
 
static bool HandleGameObjectNearCommand (ChatHandler *handler, Optional< float > dist)
 
static bool HandleGameObjectInfoCommand (ChatHandler *handler, Optional< EXACT_SEQUENCE("guid")> isGuid, Variant< Hyperlink< gameobject_entry >, Hyperlink< gameobject >, uint32 > data)
 
static bool HandleGameObjectSetStateCommand (ChatHandler *handler, GameObjectSpawnId guidLow, int32 objectType, Optional< uint32 > objectState)
 
static bool HandleGameObjectRespawn (ChatHandler *handler, GameObjectSpawnId guidLow)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ gobject_commandscript()

gobject_commandscript::gobject_commandscript ( )
inline
38: CommandScript("gobject_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable gobject_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

41 {
42 static ChatCommandTable gobjectCommandTable =
43 {
44 { "activate", HandleGameObjectActivateCommand, SEC_GAMEMASTER, Console::No },
45 { "delete", HandleGameObjectDeleteCommand, SEC_ADMINISTRATOR, Console::No },
46 { "info", HandleGameObjectInfoCommand, SEC_MODERATOR, Console::No },
47 { "move", HandleGameObjectMoveCommand, SEC_ADMINISTRATOR, Console::No },
48 { "near", HandleGameObjectNearCommand, SEC_MODERATOR, Console::No },
49 { "target", HandleGameObjectTargetCommand, SEC_MODERATOR, Console::No },
50 { "turn", HandleGameObjectTurnCommand, SEC_ADMINISTRATOR, Console::No },
51 { "add temp", HandleGameObjectAddTempCommand, SEC_GAMEMASTER, Console::No },
52 { "add", HandleGameObjectAddCommand, SEC_ADMINISTRATOR, Console::No },
53 { "set phase", HandleGameObjectSetPhaseCommand, SEC_ADMINISTRATOR, Console::No },
54 { "set state", HandleGameObjectSetStateCommand, SEC_ADMINISTRATOR, Console::No },
55 { "respawn", HandleGameObjectRespawn, SEC_GAMEMASTER, Console::No }
56 };
57 static ChatCommandTable commandTable =
58 {
59 { "gobject", gobjectCommandTable }
60 };
61 return commandTable;
62 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
@ SEC_MODERATOR
Definition: Common.h:58
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleGameObjectDeleteCommand(ChatHandler *handler, GameObjectSpawnId spawnId)
Definition: cs_gobject.cpp:286
static bool HandleGameObjectTargetCommand(ChatHandler *handler, Optional< Variant< GameObjectEntry, std::string_view > > objectId)
Definition: cs_gobject.cpp:172
static bool HandleGameObjectNearCommand(ChatHandler *handler, Optional< float > dist)
Definition: cs_gobject.cpp:434
static bool HandleGameObjectInfoCommand(ChatHandler *handler, Optional< EXACT_SEQUENCE("guid")> isGuid, Variant< Hyperlink< gameobject_entry >, Hyperlink< gameobject >, uint32 > data)
Definition: cs_gobject.cpp:481
static bool HandleGameObjectAddCommand(ChatHandler *handler, GameObjectEntry objectId, Optional< int32 > spawnTimeSecs)
Definition: cs_gobject.cpp:85
static bool HandleGameObjectActivateCommand(ChatHandler *handler, GameObjectSpawnId guidLow)
Definition: cs_gobject.cpp:64
static bool HandleGameObjectAddTempCommand(ChatHandler *handler, GameObjectEntry objectId, Optional< uint64 > spawntime)
Definition: cs_gobject.cpp:148
static bool HandleGameObjectMoveCommand(ChatHandler *handler, GameObjectSpawnId guidLow, Optional< std::array< float, 3 > > xyz)
Definition: cs_gobject.cpp:356
static bool HandleGameObjectTurnCommand(ChatHandler *handler, GameObjectSpawnId guidLow, Optional< float > oz, Optional< float > oy, Optional< float > ox)
Definition: cs_gobject.cpp:318
static bool HandleGameObjectRespawn(ChatHandler *handler, GameObjectSpawnId guidLow)
Definition: cs_gobject.cpp:578
static bool HandleGameObjectSetStateCommand(ChatHandler *handler, GameObjectSpawnId guidLow, int32 objectType, Optional< uint32 > objectState)
Definition: cs_gobject.cpp:544
static bool HandleGameObjectSetPhaseCommand(ChatHandler *handler, GameObjectSpawnId guidLow, uint32 phaseMask)
Definition: cs_gobject.cpp:411

References HandleGameObjectActivateCommand(), HandleGameObjectAddCommand(), HandleGameObjectAddTempCommand(), HandleGameObjectDeleteCommand(), HandleGameObjectInfoCommand(), HandleGameObjectMoveCommand(), HandleGameObjectNearCommand(), HandleGameObjectRespawn(), HandleGameObjectSetPhaseCommand(), HandleGameObjectSetStateCommand(), HandleGameObjectTargetCommand(), HandleGameObjectTurnCommand(), SEC_ADMINISTRATOR, SEC_GAMEMASTER, and SEC_MODERATOR.

◆ HandleGameObjectActivateCommand()

static bool gobject_commandscript::HandleGameObjectActivateCommand ( ChatHandler handler,
GameObjectSpawnId  guidLow 
)
inlinestatic
65 {
66 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
67 if (!object)
68 {
70 return false;
71 }
72
73 uint32_t const autoCloseTime = object->GetGOInfo()->GetAutoCloseTime() ? 10000u : 0u;
74
75 // Activate
76 object->SetLootState(GO_READY);
77 object->UseDoorOrButton(autoCloseTime, false, handler->GetSession()->GetPlayer());
78
79 handler->PSendSysMessage("Object activated!");
80
81 return true;
82 }
std::uint32_t uint32
Definition: Define.h:107
@ LANG_COMMAND_OBJNOTFOUND
Definition: Language.h:318
@ GO_READY
Definition: GameObject.h:111
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
GameObject * GetObjectFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
Definition: Chat.cpp:596
Definition: GameObject.h:120
Player * GetPlayer() const
Definition: WorldSession.h:362

References ChatHandler::GetObjectFromPlayerMapByDbGuid(), WorldSession::GetPlayer(), ChatHandler::GetSession(), GO_READY, LANG_COMMAND_OBJNOTFOUND, ChatHandler::PSendSysMessage(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleGameObjectAddCommand()

static bool gobject_commandscript::HandleGameObjectAddCommand ( ChatHandler handler,
GameObjectEntry  objectId,
Optional< int32 spawnTimeSecs 
)
inlinestatic
Todo:
is it really necessary to add both the real and DB table guid here ?
86 {
87 if (!objectId)
88 return false;
89
90 GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
91 if (!objectInfo)
92 {
94 return false;
95 }
96
97 if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
98 {
99 // report to DB errors log as in loading case
100 LOG_ERROR("sql.sql", "Gameobject (Entry {} GoType: {}) have invalid displayId ({}), not spawned.", *objectId, objectInfo->type, objectInfo->displayId);
102 return false;
103 }
104
105 Player* player = handler->GetSession()->GetPlayer();
106 float x = float(player->GetPositionX());
107 float y = float(player->GetPositionY());
108 float z = float(player->GetPositionZ());
109 float o = float(player->GetOrientation());
110 Map* map = player->GetMap();
111
112 GameObject* object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
113 ObjectGuid::LowType guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
114
115 if (!object->Create(guidLow, objectInfo->entry, map, player->GetPhaseMaskForSpawn(), x, y, z, o, G3D::Quat(), 0, GO_STATE_READY))
116 {
117 delete object;
118 return false;
119 }
120
121 if (spawnTimeSecs)
122 object->SetRespawnTime(*spawnTimeSecs);
123
124 // fill the gameobject data and save to the db
125 object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMaskForSpawn());
126 guidLow = object->GetSpawnId();
127
128 // delete the old object and do a clean load from DB with a fresh new GameObject instance.
129 // this is required to avoid weird behavior and memory leaks
130 delete object;
131
132 object = sObjectMgr->IsGameObjectStaticTransport(objectInfo->entry) ? new StaticTransport() : new GameObject();
133 // this will generate a new guid if the object is in an instance
134 if (!object->LoadGameObjectFromDB(guidLow, map, true))
135 {
136 delete object;
137 return false;
138 }
139
141 sObjectMgr->AddGameobjectToGrid(guidLow, sObjectMgr->GetGameObjectData(guidLow));
142
143 handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, uint32(objectId), objectInfo->name, guidLow, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
144 return true;
145 }
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define sObjectMgr
Definition: ObjectMgr.h:1635
@ LANG_GAMEOBJECT_HAVE_INVALID_DATA
Definition: Language.h:389
@ LANG_GAMEOBJECT_NOT_EXIST
Definition: Language.h:566
@ LANG_GAMEOBJECT_ADD
Definition: Language.h:570
@ GO_STATE_READY
Definition: GameObjectData.h:690
DBCStorage< GameObjectDisplayInfoEntry > sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt)
virtual bool Create(ObjectGuid::LowType guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, G3D::Quat const &rotation, uint32 animprogress, GOState go_state, uint32 artKit=0)
Definition: GameObject.cpp:254
void SetRespawnTime(int32 respawn)
Definition: GameObject.cpp:1303
bool LoadGameObjectFromDB(ObjectGuid::LowType guid, Map *map, bool addToMap=true)
Definition: GameObject.cpp:1123
Definition: GameObjectData.h:31
uint32 type
Definition: GameObjectData.h:33
uint32 entry
Definition: GameObjectData.h:32
std::string name
Definition: GameObjectData.h:35
uint32 displayId
Definition: GameObjectData.h:34
Map * GetMap() const
Definition: Object.h:531
uint32 LowType
Definition: ObjectGuid.h:122
float GetPositionZ() const
Definition: Position.h:118
float GetOrientation() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:116
float GetPositionY() const
Definition: Position.h:117
Definition: Player.h:1064
uint32 GetPhaseMaskForSpawn() const
Definition: Player.cpp:13780
Definition: Transport.h:112
Definition: Map.h:311
uint8 GetSpawnMode() const
Definition: Map.h:418
ObjectGuid::LowType GenerateLowGuid()
Definition: Map.h:636
uint32 GetId() const
Definition: Map.h:377

References GameObject::Create(), GameObjectTemplate::displayId, GameObjectTemplate::entry, Map::GenerateLowGuid(), Map::GetId(), WorldObject::GetMap(), Position::GetOrientation(), Player::GetPhaseMaskForSpawn(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), Map::GetSpawnMode(), GO_STATE_READY, LANG_GAMEOBJECT_ADD, LANG_GAMEOBJECT_HAVE_INVALID_DATA, LANG_GAMEOBJECT_NOT_EXIST, GameObject::LoadGameObjectFromDB(), LOG_ERROR, GameObjectTemplate::name, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), GameObject::SetRespawnTime(), sGameObjectDisplayInfoStore, sObjectMgr, and GameObjectTemplate::type.

Referenced by GetCommands().

◆ HandleGameObjectAddTempCommand()

static bool gobject_commandscript::HandleGameObjectAddTempCommand ( ChatHandler handler,
GameObjectEntry  objectId,
Optional< uint64 spawntime 
)
inlinestatic
149 {
150 Player* player = handler->GetSession()->GetPlayer();
151 uint64 spawntm(spawntime.value_or(300));
152
153 if (!sObjectMgr->GetGameObjectTemplate(objectId))
154 {
156 return false;
157 }
158
159 float x = player->GetPositionX();
160 float y = player->GetPositionY();
161 float z = player->GetPositionZ();
162 float ang = player->GetOrientation();
163
164 float rot2 = std::sin(ang / 2);
165 float rot3 = cos(ang / 2);
166
167 player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
168
169 return true;
170 }
std::uint64_t uint64
Definition: Define.h:106
GameObject * SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime, bool checkTransport=true, GOSummonType summonType=GO_SUMMON_TIMED_OR_CORPSE_DESPAWN)
Definition: Object.cpp:2369

References Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), LANG_GAMEOBJECT_NOT_EXIST, ChatHandler::SendErrorMessage(), sObjectMgr, and WorldObject::SummonGameObject().

Referenced by GetCommands().

◆ HandleGameObjectDeleteCommand()

static bool gobject_commandscript::HandleGameObjectDeleteCommand ( ChatHandler handler,
GameObjectSpawnId  spawnId 
)
inlinestatic
287 {
288 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(spawnId);
289 if (!object)
290 {
292 return false;
293 }
294
295 ObjectGuid ownerGuid = object->GetOwnerGUID();
296 if (ownerGuid)
297 {
298 Unit* owner = ObjectAccessor::GetUnit(*handler->GetSession()->GetPlayer(), ownerGuid);
299 if (!owner || !ownerGuid.IsPlayer())
300 {
302 return false;
303 }
304
305 owner->RemoveGameObject(object, false);
306 }
307
308 object->SetRespawnTime(0); // not save respawn time
309 object->Delete();
310 object->DeleteFromDB();
311
313
314 return true;
315 }
@ LANG_COMMAND_DELOBJMESSAGE
Definition: Language.h:320
@ LANG_COMMAND_DELOBJREFERCREATURE
Definition: Language.h:319
Unit * GetUnit(WorldObject const &, ObjectGuid const guid)
Definition: ObjectAccessor.cpp:199
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:144
Definition: ObjectGuid.h:118
bool IsPlayer() const
Definition: ObjectGuid.h:168
std::string ToString() const
Definition: ObjectGuid.cpp:47
Definition: Unit.h:630
void RemoveGameObject(GameObject *gameObj, bool del)
Definition: Unit.cpp:6197

References ChatHandler::GetObjectFromPlayerMapByDbGuid(), WorldSession::GetPlayer(), ChatHandler::GetSession(), GameObject::GetSpawnId(), ObjectAccessor::GetUnit(), ObjectGuid::IsPlayer(), LANG_COMMAND_DELOBJMESSAGE, LANG_COMMAND_DELOBJREFERCREATURE, LANG_COMMAND_OBJNOTFOUND, ChatHandler::PSendSysMessage(), Unit::RemoveGameObject(), ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleGameObjectInfoCommand()

static bool gobject_commandscript::HandleGameObjectInfoCommand ( ChatHandler handler,
Optional< EXACT_SEQUENCE("guid")>  isGuid,
Variant< Hyperlink< gameobject_entry >, Hyperlink< gameobject >, uint32 data 
)
inlinestatic
482 {
483 uint32 entry = 0;
484 uint32 type = 0;
485 uint32 displayId = 0;
486 std::string name;
487 uint32 lootId = 0;
488 GameObject* gameObject = nullptr;
489
490 ObjectGuid::LowType spawnId = 0;
491 if (isGuid || data.holds_alternative<Hyperlink<gameobject>>())
492 {
493 spawnId = *data;
494 GameObjectData const* spawnData = sObjectMgr->GetGameObjectData(spawnId);
495 if (!spawnData)
496 {
498 return false;
499 }
500 entry = spawnData->id;
501 gameObject = handler->GetObjectFromPlayerMapByDbGuid(spawnId);
502 }
503 else
504 {
505 entry = *data;
506 }
507
508 GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
509 if (!gameObjectInfo)
510 {
512 return false;
513 }
514
515 type = gameObjectInfo->type;
516 displayId = gameObjectInfo->displayId;
517 name = gameObjectInfo->name;
518 if (type == GAMEOBJECT_TYPE_CHEST)
519 lootId = gameObjectInfo->chest.lootId;
520 else if (type == GAMEOBJECT_TYPE_FISHINGHOLE)
521 lootId = gameObjectInfo->fishinghole.lootId;
522
523 handler->PSendSysMessage(LANG_GOINFO_ENTRY, entry);
524 if (gameObject)
525 handler->PSendSysMessage("GUID: {}", gameObject->GetGUID().ToString());
526 handler->PSendSysMessage(LANG_GOINFO_TYPE, type);
527 handler->PSendSysMessage(LANG_GOINFO_LOOTID, lootId);
528 handler->PSendSysMessage(LANG_GOINFO_DISPLAYID, displayId);
529 if (gameObject)
530 {
531 handler->PSendSysMessage("LootMode: {}", gameObject->GetLootMode());
532 handler->PSendSysMessage("LootState: {}", gameObject->getLootState());
533 handler->PSendSysMessage("GOState: {}", gameObject->GetGoState());
534 handler->PSendSysMessage("PhaseMask: {}", gameObject->GetPhaseMask());
535 handler->PSendSysMessage("IsLootEmpty: {}", gameObject->loot.empty());
536 handler->PSendSysMessage("IsLootLooted: {}", gameObject->loot.isLooted());
537 }
538
539 handler->PSendSysMessage(LANG_GOINFO_NAME, name);
540
541 return true;
542 }
@ GAMEOBJECT_TYPE_CHEST
Definition: SharedDefines.h:1563
@ GAMEOBJECT_TYPE_FISHINGHOLE
Definition: SharedDefines.h:1585
@ LANG_GOINFO_NAME
Definition: Language.h:1074
@ LANG_GOINFO_DISPLAYID
Definition: Language.h:1073
@ LANG_GOINFO_ENTRY
Definition: Language.h:1071
@ LANG_GOINFO_LOOTID
Definition: Language.h:1075
@ LANG_GOINFO_TYPE
Definition: Language.h:1072
Definition: ChatCommandTags.h:200
constexpr bool holds_alternative() const
Definition: ChatCommandTags.h:298
Loot loot
Definition: GameObject.h:247
GOState GetGoState() const
Definition: GameObject.h:205
LootState getLootState() const
Definition: GameObject.h:224
uint16 GetLootMode() const
Definition: GameObject.h:228
uint32 lootId
Definition: GameObjectData.h:84
struct GameObjectTemplate::@230::@251 fishinghole
struct GameObjectTemplate::@230::@235 chest
Definition: GameObjectData.h:696
uint32 id
Definition: GameObjectData.h:698
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
uint32 GetPhaseMask() const
Definition: Object.h:446
bool empty() const
Definition: LootMgr.h:367
bool isLooted() const
Definition: LootMgr.h:368

References GameObjectTemplate::chest, GameObjectTemplate::displayId, Loot::empty(), GameObjectTemplate::fishinghole, GAMEOBJECT_TYPE_CHEST, GAMEOBJECT_TYPE_FISHINGHOLE, GameObject::GetGoState(), Object::GetGUID(), GameObject::GetLootMode(), GameObject::getLootState(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), WorldObject::GetPhaseMask(), GameObjectData::id, Loot::isLooted(), LANG_COMMAND_OBJNOTFOUND, LANG_GAMEOBJECT_NOT_EXIST, LANG_GOINFO_DISPLAYID, LANG_GOINFO_ENTRY, LANG_GOINFO_LOOTID, LANG_GOINFO_NAME, LANG_GOINFO_TYPE, GameObject::loot, GameObjectTemplate::lootId, GameObjectTemplate::name, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), sObjectMgr, ObjectGuid::ToString(), and GameObjectTemplate::type.

Referenced by GetCommands().

◆ HandleGameObjectMoveCommand()

static bool gobject_commandscript::HandleGameObjectMoveCommand ( ChatHandler handler,
GameObjectSpawnId  guidLow,
Optional< std::array< float, 3 > >  xyz 
)
inlinestatic
357 {
358 if (!guidLow)
359 return false;
360
361 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
362 if (!object)
363 {
365 return false;
366 }
367
368 Position pos;
369 if (xyz)
370 {
371 pos = { (*xyz)[0], (*xyz)[1], (*xyz)[2] };
372 if (!MapMgr::IsValidMapCoord(object->GetMapId(), pos))
373 {
375 return false;
376 }
377 }
378 else
379 {
380 pos = handler->GetSession()->GetPlayer()->GetPosition();
381 }
382
383 Map* map = object->GetMap();
384
385 pos.SetOrientation(object->GetOrientation());
386 object->Relocate(pos);
387
388 // update which cell has this gameobject registered for loading
389 sObjectMgr->RemoveGameobjectFromGrid(guidLow, object->GetGameObjectData());
390 object->SaveToDB();
391 sObjectMgr->AddGameobjectToGrid(guidLow, object->GetGameObjectData());
392
393 // Generate a completely new spawn with new guid
394 // 3.3.5a client caches recently deleted objects and brings them back to life
395 // when CreateObject block for this guid is received again
396 // however it entirely skips parsing that block and only uses already known location
397 object->Delete();
398
399 object = new GameObject();
400 if (!object->LoadGameObjectFromDB(guidLow, map, true))
401 {
402 delete object;
403 return false;
404 }
405
406 handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name, object->GetSpawnId());
407 return true;
408 }
@ LANG_COMMAND_MOVEOBJMESSAGE
Definition: Language.h:322
@ LANG_INVALID_TARGET_COORD
Definition: Language.h:308
GameObjectTemplate const * GetGOInfo() const
Definition: GameObject.h:136
GameObjectData const * GetGameObjectData() const
Definition: GameObject.h:138
Definition: Position.h:27
void SetOrientation(float orientation)
Definition: Position.h:111
void GetPosition(float &x, float &y) const
Definition: Position.h:121
uint32 GetMapId() const
Definition: Position.h:275
static bool IsValidMapCoord(uint32 mapid, Position const &pos)
Definition: MapMgr.h:89

References GameObject::GetGameObjectData(), GameObject::GetGOInfo(), WorldLocation::GetMapId(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPosition(), Position::GetPositionX(), Position::GetPositionY(), ChatHandler::GetSession(), GameObject::GetSpawnId(), MapMgr::IsValidMapCoord(), LANG_COMMAND_MOVEOBJMESSAGE, LANG_COMMAND_OBJNOTFOUND, LANG_INVALID_TARGET_COORD, GameObject::LoadGameObjectFromDB(), GameObjectTemplate::name, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), Position::SetOrientation(), and sObjectMgr.

Referenced by GetCommands().

◆ HandleGameObjectNearCommand()

static bool gobject_commandscript::HandleGameObjectNearCommand ( ChatHandler handler,
Optional< float >  dist 
)
inlinestatic
435 {
436 float distance = dist.value_or(10.0f);
437 uint32 count = 0;
438
439 Player* player = handler->GetSession()->GetPlayer();
440
442 stmt->SetData(0, player->GetPositionX());
443 stmt->SetData(1, player->GetPositionY());
444 stmt->SetData(2, player->GetPositionZ());
445 stmt->SetData(3, player->GetMapId());
446 stmt->SetData(4, player->GetPositionX());
447 stmt->SetData(5, player->GetPositionY());
448 stmt->SetData(6, player->GetPositionZ());
449 stmt->SetData(7, distance * distance);
450 stmt->SetData(8, player->GetPhaseMask());
451 PreparedQueryResult result = WorldDatabase.Query(stmt);
452
453 if (result)
454 {
455 do
456 {
457 Field* fields = result->Fetch();
458 ObjectGuid::LowType guid = fields[0].Get<uint32>();
459 uint32 entry = fields[1].Get<uint32>();
460 float x = fields[2].Get<float>();
461 float y = fields[3].Get<float>();
462 float z = fields[4].Get<float>();
463 uint16 mapId = fields[5].Get<uint16>();
464
465 GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
466
467 if (!gameObjectInfo)
468 continue;
469
470 handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name, x, y, z, mapId, "", "");
471
472 ++count;
473 } while (result->NextRow());
474 }
475
476 handler->PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, count);
477 return true;
478 }
std::uint16_t uint16
Definition: Define.h:108
@ LANG_GO_LIST_CHAT
Definition: Language.h:560
@ LANG_COMMAND_NEAROBJMESSAGE
Definition: Language.h:640
@ WORLD_SEL_GAMEOBJECT_NEAREST
Definition: WorldDatabase.h:89
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: PreparedStatement.h:157
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77

References Field::Get(), WorldLocation::GetMapId(), WorldObject::GetPhaseMask(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), LANG_COMMAND_NEAROBJMESSAGE, LANG_GO_LIST_CHAT, ChatHandler::PSendSysMessage(), PreparedStatementBase::SetData(), sObjectMgr, WORLD_SEL_GAMEOBJECT_NEAREST, and WorldDatabase.

Referenced by GetCommands().

◆ HandleGameObjectRespawn()

static bool gobject_commandscript::HandleGameObjectRespawn ( ChatHandler handler,
GameObjectSpawnId  guidLow 
)
inlinestatic
579 {
580 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
581 if (!object)
582 {
584 return false;
585 }
586
587 object->Respawn();
588 handler->PSendSysMessage(LANG_CMD_GO_RESPAWN, object->GetNameForLocaleIdx(handler->GetSessionDbcLocale()), object->GetEntry(), object->GetSpawnId());
589 return true;
590 }
@ LANG_CMD_GO_RESPAWN
Definition: Language.h:1146
virtual LocaleConstant GetSessionDbcLocale() const
Definition: Chat.cpp:869
std::string const & GetNameForLocaleIdx(LocaleConstant locale_idx) const override
Definition: GameObject.cpp:2207
uint32 GetEntry() const
Definition: Object.h:112

References Object::GetEntry(), GameObject::GetNameForLocaleIdx(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), ChatHandler::GetSessionDbcLocale(), GameObject::GetSpawnId(), LANG_CMD_GO_RESPAWN, LANG_COMMAND_OBJNOTFOUND, ChatHandler::PSendSysMessage(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleGameObjectSetPhaseCommand()

static bool gobject_commandscript::HandleGameObjectSetPhaseCommand ( ChatHandler handler,
GameObjectSpawnId  guidLow,
uint32  phaseMask 
)
inlinestatic
412 {
413 if (!guidLow)
414 return false;
415
416 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
417 if (!object)
418 {
420 return false;
421 }
422
423 if (!phaseMask)
424 {
426 return false;
427 }
428
429 object->SetPhaseMask(phaseMask, true);
430 object->SaveToDB();
431 return true;
432 }
@ LANG_BAD_VALUE
Definition: Language.h:147

References ChatHandler::GetObjectFromPlayerMapByDbGuid(), LANG_BAD_VALUE, LANG_COMMAND_OBJNOTFOUND, and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleGameObjectSetStateCommand()

static bool gobject_commandscript::HandleGameObjectSetStateCommand ( ChatHandler handler,
GameObjectSpawnId  guidLow,
int32  objectType,
Optional< uint32 objectState 
)
inlinestatic
545 {
546 if (!guidLow)
547 return false;
548
549 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
550 if (!object)
551 {
553 return false;
554 }
555
556 if (objectType < 0)
557 {
558 if (objectType == -1)
559 object->SendObjectDeSpawnAnim(object->GetGUID());
560 else if (objectType == -2)
561 return false;
562 return true;
563 }
564
565 if (!objectState)
566 return false;
567
568 if (objectType < 4)
569 object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, *objectState);
570 else if (objectType == 4)
571 {
572 object->SendCustomAnim(*objectState);
573 }
574 handler->PSendSysMessage("Set gobject type {} state {}", objectType, *objectState);
575 return true;
576 }
@ GAMEOBJECT_BYTES_1
Definition: UpdateFields.h:404

References GAMEOBJECT_BYTES_1, Object::GetGUID(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), LANG_COMMAND_OBJNOTFOUND, ChatHandler::PSendSysMessage(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleGameObjectTargetCommand()

static bool gobject_commandscript::HandleGameObjectTargetCommand ( ChatHandler handler,
Optional< Variant< GameObjectEntry, std::string_view > >  objectId 
)
inlinestatic
173 {
174 Player* player = handler->GetSession()->GetPlayer();
175 QueryResult result;
176 GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList();
177
178 if (objectId)
179 {
180 if (objectId->holds_alternative<GameObjectEntry>())
181 {
182 result = WorldDatabase.Query("SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '{}', 2) + POW(position_y - '{}', 2) + POW(position_z - '{}', 2)) AS order_ FROM gameobject WHERE map = '{}' AND id = '{}' ORDER BY order_ ASC LIMIT 1",
183 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), static_cast<uint32>(objectId->get<GameObjectEntry>()));
184 }
185 else
186 {
187 std::string name = std::string(objectId->get<std::string_view>());
188 WorldDatabase.EscapeString(name);
189 result = WorldDatabase.Query(
190 "SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - {}, 2) + POW(position_y - {}, 2) + POW(position_z - {}, 2)) AS order_ "
191 "FROM gameobject LEFT JOIN gameobject_template ON gameobject_template.entry = gameobject.id WHERE map = {} AND name LIKE '%{}%' ORDER BY order_ ASC LIMIT 1",
192 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name);
193 }
194 }
195 else
196 {
197 std::ostringstream eventFilter;
198 eventFilter << " AND (eventEntry IS NULL ";
199 bool initString = true;
200
201 for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
202 {
203 if (initString)
204 {
205 eventFilter << "OR eventEntry IN (" << *itr;
206 initString = false;
207 }
208 else
209 eventFilter << ',' << *itr;
210 }
211
212 if (!initString)
213 eventFilter << "))";
214 else
215 eventFilter << ')';
216
217 result = WorldDatabase.Query("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, phaseMask, "
218 "(POW(position_x - {}, 2) + POW(position_y - {}, 2) + POW(position_z - {}, 2)) AS order_ FROM gameobject "
219 "LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '{}' {} ORDER BY order_ ASC LIMIT 10",
220 handler->GetSession()->GetPlayer()->GetPositionX(), handler->GetSession()->GetPlayer()->GetPositionY(), handler->GetSession()->GetPlayer()->GetPositionZ(),
221 handler->GetSession()->GetPlayer()->GetMapId(), eventFilter.str());
222 }
223
224 if (!result)
225 {
227 return true;
228 }
229
230 bool found = false;
231 float x, y, z, o;
232 ObjectGuid::LowType guidLow;
233 uint32 id, phase;
234 uint16 mapId;
235 uint32 poolId;
236
237 do
238 {
239 Field* fields = result->Fetch();
240 guidLow = fields[0].Get<uint32>();
241 id = fields[1].Get<uint32>();
242 x = fields[2].Get<float>();
243 y = fields[3].Get<float>();
244 z = fields[4].Get<float>();
245 o = fields[5].Get<float>();
246 mapId = fields[6].Get<uint16>();
247 phase = fields[7].Get<uint32>();
248 poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
249 if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
250 found = true;
251 } while (result->NextRow() && !found);
252
253 if (!found)
254 {
256 return false;
257 }
258
259 GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(id);
260
261 if (!objectInfo)
262 {
264 return false;
265 }
266
267 GameObject* target = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
268
269 handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name, guidLow, id, x, y, z, mapId, o, phase);
270
271 if (target)
272 {
273 int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - GameTime::GetGameTime().count());
274 if (curRespawnDelay < 0)
275 curRespawnDelay = 0;
276
277 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
278 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
279
280 handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr, curRespawnDelayStr);
281 }
282 return true;
283 }
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
std::int32_t int32
Definition: Define.h:103
phase
Definition: boss_skadi.cpp:103
@ LANG_GAMEOBJECT_DETAIL
Definition: Language.h:569
@ LANG_COMMAND_TARGETOBJNOTFOUND
Definition: Language.h:311
@ LANG_COMMAND_RAWPAWNTIMES
Definition: Language.h:641
#define sGameEventMgr
Definition: GameEventMgr.h:186
#define sPoolMgr
Definition: PoolMgr.h:163
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
Seconds GetGameTime()
Definition: GameTime.cpp:38
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
Definition: ChatCommandTags.h:253
uint32 GetRespawnDelay() const
Definition: GameObject.h:197
time_t GetRespawnTimeEx() const
Definition: GameObject.cpp:2923
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:106

References Field::Get(), GameTime::GetGameTime(), WorldLocation::GetMapId(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), GameObject::GetRespawnDelay(), GameObject::GetRespawnTimeEx(), ChatHandler::GetSession(), LANG_COMMAND_RAWPAWNTIMES, LANG_COMMAND_TARGETOBJNOTFOUND, LANG_GAMEOBJECT_DETAIL, LANG_GAMEOBJECT_NOT_EXIST, GameObjectTemplate::name, ChatHandler::PSendSysMessage(), secsToTimeString(), ChatHandler::SendSysMessage(), sGameEventMgr, sObjectMgr, sPoolMgr, and WorldDatabase.

Referenced by GetCommands().

◆ HandleGameObjectTurnCommand()

static bool gobject_commandscript::HandleGameObjectTurnCommand ( ChatHandler handler,
GameObjectSpawnId  guidLow,
Optional< float >  oz,
Optional< float >  oy,
Optional< float >  ox 
)
inlinestatic
319 {
320 if (!guidLow)
321 return false;
322
323 GameObject* object = handler->GetObjectFromPlayerMapByDbGuid(guidLow);
324 if (!object)
325 {
327 return false;
328 }
329
330 if (!oz)
331 oz = handler->GetSession()->GetPlayer()->GetOrientation();
332
333 Map* map = object->GetMap();
334 object->Relocate(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), *oz);
335 object->SetLocalRotationAngles(*oz, oy.value_or(0.0f), ox.value_or(0.0f));
336 object->SaveToDB();
337
338 // Generate a completely new spawn with new guid
339 // 3.3.5a client caches recently deleted objects and brings them back to life
340 // when CreateObject block for this guid is received again
341 // however it entirely skips parsing that block and only uses already known location
342 object->Delete();
343
344 object = new GameObject();
345 if (!object->LoadGameObjectFromDB(guidLow, map, true))
346 {
347 delete object;
348 return false;
349 }
350
351 handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name, object->GetSpawnId());
352 return true;
353 }
@ LANG_COMMAND_TURNOBJMESSAGE
Definition: Language.h:321

References GameObject::GetGOInfo(), ChatHandler::GetObjectFromPlayerMapByDbGuid(), Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), GameObject::GetSpawnId(), LANG_COMMAND_OBJNOTFOUND, LANG_COMMAND_TURNOBJMESSAGE, GameObject::LoadGameObjectFromDB(), GameObjectTemplate::name, ChatHandler::PSendSysMessage(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().