TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gobject_commandscript Class Reference

Public Member Functions

 gobject_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleGameObjectActivateCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectAddCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectAddTempCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectTargetCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectDeleteCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectTurnCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectMoveCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectSetPhaseCommand (ChatHandler *, char const *)
 
static bool HandleGameObjectNearCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectInfoCommand (ChatHandler *handler, char const *args)
 
static bool HandleGameObjectSetStateCommand (ChatHandler *handler, char const *args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

gobject_commandscript::gobject_commandscript ( )
inline
38 : CommandScript("gobject_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> gobject_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

41  {
42  static std::vector<ChatCommand> gobjectAddCommandTable =
43  {
46  };
47  static std::vector<ChatCommand> gobjectSetCommandTable =
48  {
51  };
52  static std::vector<ChatCommand> gobjectCommandTable =
53  {
61  { "add", rbac::RBAC_PERM_COMMAND_GOBJECT_ADD, false, NULL, "", gobjectAddCommandTable },
62  { "set", rbac::RBAC_PERM_COMMAND_GOBJECT_SET, false, NULL, "", gobjectSetCommandTable },
63  };
64  static std::vector<ChatCommand> commandTable =
65  {
66  { "gobject", rbac::RBAC_PERM_COMMAND_GOBJECT, false, NULL, "", gobjectCommandTable },
67  };
68  return commandTable;
69  }
static bool HandleGameObjectTargetCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:228
static bool HandleGameObjectNearCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:546
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleGameObjectSetStateCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:628
static bool HandleGameObjectAddTempCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:189
static bool HandleGameObjectTurnCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:396
static bool HandleGameObjectInfoCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:592
static bool HandleGameObjectAddCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:107
static bool HandleGameObjectDeleteCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:348
static bool HandleGameObjectSetPhaseCommand(ChatHandler *, char const *)
Definition: cs_gobject.cpp:508
Definition: RBAC.h:294
static bool HandleGameObjectMoveCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:445
static bool HandleGameObjectActivateCommand(ChatHandler *handler, char const *args)
Definition: cs_gobject.cpp:71

+ Here is the call graph for this function:

static bool gobject_commandscript::HandleGameObjectActivateCommand ( ChatHandler handler,
char const args 
)
inlinestatic
72  {
73  if (!*args)
74  return false;
75 
76  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
77  if (!id)
78  return false;
79 
80  ObjectGuid::LowType guidLow = strtoull(id, nullptr, 10);
81  if (!guidLow)
82  return false;
83 
84  GameObject* object = NULL;
85 
86  // by DB guid
87  if (GameObjectData const* goData = sObjectMgr->GetGOData(guidLow))
88  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, goData->id);
89 
90  if (!object)
91  {
92  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
93  handler->SetSentErrorMessage(true);
94  return false;
95  }
96 
97  // Activate
98  object->SetLootState(GO_READY);
99  object->UseDoorOrButton(10000, false, handler->GetSession()->GetPlayer());
100 
101  handler->PSendSysMessage("Object activated!");
102 
103  return true;
104  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
Definition: Chat.cpp:766
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: GameObject.h:880
Definition: GameObject.h:833
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
Definition: GameObject.h:869
Definition: Language.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectAddCommand ( ChatHandler handler,
char const args 
)
inlinestatic
Todo:
is it really necessary to add both the real and DB table guid here ?
108  {
109  if (!*args)
110  return false;
111 
112  // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
113  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
114  if (!id)
115  return false;
116 
117  uint32 objectId = atoul(id);
118  if (!objectId)
119  return false;
120 
121  char* spawntimeSecs = strtok(NULL, " ");
122 
123  const GameObjectTemplate* objectInfo = sObjectMgr->GetGameObjectTemplate(objectId);
124 
125  if (!objectInfo)
126  {
127  handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
128  handler->SetSentErrorMessage(true);
129  return false;
130  }
131 
132  if (objectInfo->displayId && !sGameObjectDisplayInfoStore.LookupEntry(objectInfo->displayId))
133  {
134  // report to DB errors log as in loading case
135  TC_LOG_ERROR("sql.sql", "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned.", objectId, objectInfo->type, objectInfo->displayId);
137  handler->SetSentErrorMessage(true);
138  return false;
139  }
140 
141  Player* player = handler->GetSession()->GetPlayer();
142  float x = float(player->GetPositionX());
143  float y = float(player->GetPositionY());
144  float z = float(player->GetPositionZ());
145  float o = float(player->GetOrientation());
146  Map* map = player->GetMap();
147 
148  GameObject* object = new GameObject;
149  ObjectGuid::LowType guidLow = map->GenerateLowGuid<HighGuid::GameObject>();
150 
151  if (!object->Create(guidLow, objectInfo->entry, map, 0, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
152  {
153  delete object;
154  return false;
155  }
156 
157  object->CopyPhaseFrom(player);
158 
159  if (spawntimeSecs)
160  {
161  uint32 value = atoi((char*)spawntimeSecs);
162  object->SetRespawnTime(value);
163  }
164 
165  // fill the gameobject data and save to the db
166  object->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), player->GetPhaseMask());
167  guidLow = object->GetSpawnId();
168 
169  // delete the old object and do a clean load from DB with a fresh new GameObject instance.
170  // this is required to avoid weird behavior and memory leaks
171  delete object;
172 
173  object = new GameObject();
174  // this will generate a new guid if the object is in an instance
175  if (!object->LoadGameObjectFromDB(guidLow, map))
176  {
177  delete object;
178  return false;
179  }
180 
182  sObjectMgr->AddGameobjectToGrid(guidLow, ASSERT_NOTNULL(sObjectMgr->GetGOData(guidLow)));
183 
184  handler->PSendSysMessage(LANG_GAMEOBJECT_ADD, objectId, objectInfo->name.c_str(), guidLow, x, y, z);
185  return true;
186  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
T * ASSERT_NOTNULL(T *pointer)
Definition: Errors.h:58
Definition: GameObject.h:34
Definition: Language.h:536
arena_t NULL
Definition: jemalloc_internal.h:624
void CopyPhaseFrom(WorldObject *obj, bool update=false)
Definition: Object.cpp:2915
uint32 displayId
Definition: GameObject.h:38
Player * GetPlayer() const
Definition: WorldSession.h:927
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
unsigned long atoul(char const *str)
Definition: Common.h:90
G3D::int16 z
Definition: Vector3int16.h:46
uint32_t uint32
Definition: Define.h:150
bool LoadGameObjectFromDB(ObjectGuid::LowType spawnId, Map *map, bool addToMap=true)
Definition: GameObject.cpp:858
G3D::int16 y
Definition: Vector2int16.h:38
Definition: GameObject.h:880
uint32 entry
Definition: GameObject.h:36
Definition: Language.h:376
Definition: Map.h:259
DBCStorage< GameObjectDisplayInfoEntry > sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt)
Definition: GameObject.h:823
std::string name
Definition: GameObject.h:39
bool Create(ObjectGuid::LowType guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state, uint32 artKit=0)
Definition: GameObject.cpp:173
WorldSession * GetSession()
Definition: Chat.h:59
Definition: Language.h:540
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
const FieldDescriptor value
Definition: descriptor.h:1522
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
G3D::int16 x
Definition: Vector2int16.h:37
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
uint32 type
Definition: GameObject.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectAddTempCommand ( ChatHandler handler,
char const args 
)
inlinestatic
190  {
191  if (!*args)
192  return false;
193 
194  char* id = strtok((char*)args, " ");
195  if (!id)
196  return false;
197 
198  Player* player = handler->GetSession()->GetPlayer();
199 
200  char* spawntime = strtok(NULL, " ");
201  uint32 spawntm = 300;
202 
203  if (spawntime)
204  spawntm = atoi((char*)spawntime);
205 
206  float x = player->GetPositionX();
207  float y = player->GetPositionY();
208  float z = player->GetPositionZ();
209  float ang = player->GetOrientation();
210 
211  float rot2 = std::sin(ang/2);
212  float rot3 = std::cos(ang/2);
213 
214  uint32 objectId = atoi(id);
215 
216  if (!sObjectMgr->GetGameObjectTemplate(objectId))
217  {
218  handler->PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST, objectId);
219  handler->SetSentErrorMessage(true);
220  return false;
221  }
222 
223  player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
224 
225  return true;
226  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:536
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
#define sObjectMgr
Definition: ObjectMgr.h:1567
G3D::int16 z
Definition: Vector3int16.h:46
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
G3D::int16 x
Definition: Vector2int16.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectDeleteCommand ( ChatHandler handler,
char const args 
)
inlinestatic
349  {
350  // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
351  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
352  if (!id)
353  return false;
354 
355  ObjectGuid::LowType guidLow = strtoull(id, nullptr, 10);
356  if (!guidLow)
357  return false;
358 
359  GameObject* object = NULL;
360 
361  // by DB guid
362  if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
363  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
364 
365  if (!object)
366  {
367  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
368  handler->SetSentErrorMessage(true);
369  return false;
370  }
371 
372  ObjectGuid ownerGuid = object->GetOwnerGUID();
373  if (!ownerGuid.IsEmpty())
374  {
375  Unit* owner = ObjectAccessor::GetUnit(*handler->GetSession()->GetPlayer(), ownerGuid);
376  if (!owner || !ownerGuid.IsPlayer())
377  {
378  handler->PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE, ownerGuid.ToString().c_str(), object->GetGUID().ToString().c_str());
379  handler->SetSentErrorMessage(true);
380  return false;
381  }
382 
383  owner->RemoveGameObject(object, false);
384  }
385 
386  object->SetRespawnTime(0); // not save respawn time
387  object->Delete();
388  object->DeleteFromDB();
389 
390  handler->PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE, object->GetGUID().ToString().c_str());
391 
392  return true;
393  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
bool IsPlayer() const
Definition: ObjectGuid.h:249
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
ObjectData const gameObjectData[]
Definition: instance_gundrak.cpp:40
Definition: Language.h:306
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
Definition: Chat.cpp:766
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: Language.h:307
Definition: GameObject.h:880
Definition: GameObject.h:833
ObjectGuid const & GetGUID() const
Definition: Object.h:105
void RemoveGameObject(GameObject *gameObj, bool del)
Definition: Unit.cpp:4765
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
Definition: Unit.h:1305
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
std::string ToString() const
Definition: ObjectGuid.cpp:99
bool IsEmpty() const
Definition: ObjectGuid.h:242
Definition: Language.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectInfoCommand ( ChatHandler handler,
char const args 
)
inlinestatic
593  {
594  uint32 entry = 0;
595  uint32 type = 0;
596  uint32 displayId = 0;
597  std::string name;
598  uint32 lootId = 0;
599 
600  if (!*args)
601  {
602  if (WorldObject* object = handler->getSelectedObject())
603  entry = object->GetEntry();
604  else
605  entry = atoi((char*)args);
606  } else
607  entry = atoi((char*)args);
608 
609  GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
610 
611  if (!gameObjectInfo)
612  return false;
613 
614  type = gameObjectInfo->type;
615  displayId = gameObjectInfo->displayId;
616  name = gameObjectInfo->name;
617  lootId = gameObjectInfo->GetLootId();
618 
619  handler->PSendSysMessage(LANG_GOINFO_ENTRY, entry);
620  handler->PSendSysMessage(LANG_GOINFO_TYPE, type);
621  handler->PSendSysMessage(LANG_GOINFO_LOOTID, lootId);
622  handler->PSendSysMessage(LANG_GOINFO_DISPLAYID, displayId);
623  handler->PSendSysMessage(LANG_GOINFO_NAME, name.c_str());
624 
625  return true;
626  }
Definition: GameObject.h:34
Definition: Object.h:423
uint32 displayId
Definition: GameObject.h:38
Definition: Language.h:1093
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: Language.h:1090
Definition: Language.h:1092
uint32 GetLootId() const
Definition: GameObject.h:726
uint32_t uint32
Definition: Define.h:150
WorldObject * getSelectedObject()
Definition: Chat.cpp:602
std::string name
Definition: GameObject.h:39
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
uint32 type
Definition: GameObject.h:37
Definition: Language.h:1094
Definition: Language.h:1091

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectMoveCommand ( ChatHandler handler,
char const args 
)
inlinestatic
446  {
447  // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
448  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
449  if (!id)
450  return false;
451 
452  ObjectGuid::LowType guidLow = strtoull(id, nullptr, 10);
453  if (!guidLow)
454  return false;
455 
456  GameObject* object = NULL;
457 
458  // by DB guid
459  if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
460  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
461 
462  if (!object)
463  {
464  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
465  handler->SetSentErrorMessage(true);
466  return false;
467  }
468 
469  char* toX = strtok(NULL, " ");
470  char* toY = strtok(NULL, " ");
471  char* toZ = strtok(NULL, " ");
472 
473  float x, y, z;
474  if (!toX)
475  {
476  Player* player = handler->GetSession()->GetPlayer();
477  player->GetPosition(x, y, z);
478  }
479  else
480  {
481  if (!toY || !toZ)
482  return false;
483 
484  x = (float)atof(toX);
485  y = (float)atof(toY);
486  z = (float)atof(toZ);
487 
488  if (!MapManager::IsValidMapCoord(object->GetMapId(), x, y, z))
489  {
490  handler->PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, object->GetMapId());
491  handler->SetSentErrorMessage(true);
492  return false;
493  }
494  }
495 
496  object->DestroyForNearbyPlayers();
497  object->RelocateStationaryPosition(x, y, z, object->GetOrientation());
498  object->GetMap()->GameObjectRelocation(object, x, y, z, object->GetOrientation());
499 
500  object->SaveToDB();
501 
502  handler->PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetGUID().ToString().c_str());
503 
504  return true;
505  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
ObjectData const gameObjectData[]
Definition: instance_gundrak.cpp:40
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
Definition: Chat.cpp:766
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:309
Player * GetPlayer() const
Definition: WorldSession.h:927
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:902
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
float GetOrientation() const
Definition: Position.h:107
Definition: Language.h:295
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
Definition: GameObject.h:880
uint32 GetMapId() const
Definition: Position.h:254
Definition: GameObject.h:833
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition: MapManager.h:83
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
G3D::int16 x
Definition: Vector2int16.h:37
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
Definition: Language.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectNearCommand ( ChatHandler handler,
char const args 
)
inlinestatic
547  {
548  float distance = (!*args) ? 10.0f : (float)(atof(args));
549  uint32 count = 0;
550 
551  Player* player = handler->GetSession()->GetPlayer();
552 
554  stmt->setFloat(0, player->GetPositionX());
555  stmt->setFloat(1, player->GetPositionY());
556  stmt->setFloat(2, player->GetPositionZ());
557  stmt->setUInt32(3, player->GetMapId());
558  stmt->setFloat(4, player->GetPositionX());
559  stmt->setFloat(5, player->GetPositionY());
560  stmt->setFloat(6, player->GetPositionZ());
561  stmt->setFloat(7, distance * distance);
562  PreparedQueryResult result = WorldDatabase.Query(stmt);
563 
564  if (result)
565  {
566  do
567  {
568  Field* fields = result->Fetch();
569  ObjectGuid::LowType guid = fields[0].GetUInt64();
570  uint32 entry = fields[1].GetUInt32();
571  float x = fields[2].GetFloat();
572  float y = fields[3].GetFloat();
573  float z = fields[4].GetFloat();
574  uint16 mapId = fields[5].GetUInt16();
575 
576  GameObjectTemplate const* gameObjectInfo = sObjectMgr->GetGameObjectTemplate(entry);
577 
578  if (!gameObjectInfo)
579  continue;
580 
581  handler->PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gameObjectInfo->name.c_str(), x, y, z, mapId);
582 
583  ++count;
584  } while (result->NextRow());
585  }
586 
587  handler->PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, count);
588  return true;
589  }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
uint64 GetUInt64() const
Definition: Field.h:184
float GetFloat() const
Definition: Field.h:222
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: GameObject.h:34
Definition: WorldDatabase.h:89
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Player * GetPlayer() const
Definition: WorldSession.h:927
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: PreparedStatement.h:74
double distance(double x, double y)
Definition: g3dmath.h:731
G3D::int16 z
Definition: Vector3int16.h:46
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: Language.h:530
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
std::string name
Definition: GameObject.h:39
uint32 GetUInt32() const
Definition: Field.h:146
void setFloat(const uint8 index, const float value)
Definition: PreparedStatement.cpp:169
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
G3D::int16 x
Definition: Vector2int16.h:37
Definition: Language.h:607

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectSetPhaseCommand ( ChatHandler ,
char const  
)
inlinestatic
509  {
510  /*// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
511  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
512  if (!id)
513  return false;
514 
515  uint32 guidLow = atoi(id);
516  if (!guidLow)
517  return false;
518 
519  GameObject* object = NULL;
520 
521  // by DB guid
522  if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
523  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
524 
525  if (!object)
526  {
527  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
528  handler->SetSentErrorMessage(true);
529  return false;
530  }
531 
532  char* phase = strtok (NULL, " ");
533  uint32 phaseMask = phase ? atoi(phase) : 0;
534  if (phaseMask == 0)
535  {
536  handler->SendSysMessage(LANG_BAD_VALUE);
537  handler->SetSentErrorMessage(true);
538  return false;
539  }
540 
541  object->SetPhaseMask(phaseMask, true);
542  object->SaveToDB();*/
543  return true;
544  }

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectSetStateCommand ( ChatHandler handler,
char const args 
)
inlinestatic
629  {
630  // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
631  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
632  if (!id)
633  return false;
634 
635  ObjectGuid::LowType guidLow = strtoull(id, nullptr, 10);
636  if (!guidLow)
637  return false;
638 
639  GameObject* object = NULL;
640 
641  if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
642  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
643 
644  if (!object)
645  {
646  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
647  handler->SetSentErrorMessage(true);
648  return false;
649  }
650 
651  char* type = strtok(NULL, " ");
652  if (!type)
653  return false;
654 
655  int32 objectType = atoi(type);
656  if (objectType < 0)
657  {
658  if (objectType == -1)
659  object->SendObjectDeSpawnAnim(object->GetGUID());
660  else if (objectType == -2)
661  return false;
662  return true;
663  }
664 
665  char* state = strtok(NULL, " ");
666  if (!state)
667  return false;
668 
669  int32 objectState = atoi(state);
670 
671  if (objectType < 4)
672  object->SetByteValue(GAMEOBJECT_BYTES_1, objectType, objectState);
673  else if (objectType == 4)
674  object->SendCustomAnim(objectState);
675 
676  handler->PSendSysMessage("Set gobject type %d state %d", objectType, objectState);
677  return true;
678  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
ObjectData const gameObjectData[]
Definition: instance_gundrak.cpp:40
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
Definition: Chat.cpp:766
arena_t NULL
Definition: jemalloc_internal.h:624
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: UpdateFields.h:323
int32_t int32
Definition: Define.h:146
Definition: GameObject.h:880
Definition: GameObject.h:833
ObjectGuid const & GetGUID() const
Definition: Object.h:105
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
Definition: Language.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectTargetCommand ( ChatHandler handler,
char const args 
)
inlinestatic
229  {
230  Player* player = handler->GetSession()->GetPlayer();
231  QueryResult result;
232  GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr->GetActiveEventList();
233 
234  if (*args)
235  {
236  // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
237  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject_entry");
238  if (!id)
239  return false;
240 
241  uint32 objectId = atoul(id);
242 
243  if (objectId)
244  result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (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",
245  player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), objectId);
246  else
247  {
248  std::string name = id;
250  result = WorldDatabase.PQuery(
251  "SELECT guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ "
252  "FROM gameobject, gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name " _LIKE_" " _CONCAT3_("'%%'", "'%s'", "'%%'")" ORDER BY order_ ASC LIMIT 1",
253  player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), name.c_str());
254  }
255  }
256  else
257  {
258  std::ostringstream eventFilter;
259  eventFilter << " AND (eventEntry IS NULL ";
260  bool initString = true;
261 
262  for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
263  {
264  if (initString)
265  {
266  eventFilter << "OR eventEntry IN (" << *itr;
267  initString = false;
268  }
269  else
270  eventFilter << ',' << *itr;
271  }
272 
273  if (!initString)
274  eventFilter << "))";
275  else
276  eventFilter << ')';
277 
278  result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, PhaseId, PhaseGroup, "
279  "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
280  "LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
281  handler->GetSession()->GetPlayer()->GetPositionX(), handler->GetSession()->GetPlayer()->GetPositionY(), handler->GetSession()->GetPlayer()->GetPositionZ(),
282  handler->GetSession()->GetPlayer()->GetMapId(), eventFilter.str().c_str());
283  }
284 
285  if (!result)
286  {
288  return true;
289  }
290 
291  bool found = false;
292  float x, y, z, o;
293  ObjectGuid::LowType guidLow;
294  uint32 id, phaseId, phaseGroup;
295  uint16 mapId;
296  uint32 poolId;
297 
298  do
299  {
300  Field* fields = result->Fetch();
301  guidLow = fields[0].GetUInt64();
302  id = fields[1].GetUInt32();
303  x = fields[2].GetFloat();
304  y = fields[3].GetFloat();
305  z = fields[4].GetFloat();
306  o = fields[5].GetFloat();
307  mapId = fields[6].GetUInt16();
308  phaseId = fields[7].GetUInt32();
309  phaseGroup = fields[8].GetUInt32();
310  poolId = sPoolMgr->IsPartOfAPool<GameObject>(guidLow);
311  if (!poolId || sPoolMgr->IsSpawnedObject<GameObject>(guidLow))
312  found = true;
313  } while (result->NextRow() && !found);
314 
315  if (!found)
316  {
318  return false;
319  }
320 
321  GameObjectTemplate const* objectInfo = sObjectMgr->GetGameObjectTemplate(id);
322 
323  if (!objectInfo)
324  {
326  return false;
327  }
328 
329  GameObject* target = handler->GetSession()->GetPlayer()->GetMap()->GetGameObject(ObjectGuid::Create<HighGuid::GameObject>(mapId, id, guidLow));
330 
331  handler->PSendSysMessage(LANG_GAMEOBJECT_DETAIL, guidLow, objectInfo->name.c_str(), guidLow, id, x, y, z, mapId, o, phaseId, phaseGroup);
332 
333  if (target)
334  {
335  int32 curRespawnDelay = int32(target->GetRespawnTimeEx() - time(NULL));
336  if (curRespawnDelay < 0)
337  curRespawnDelay = 0;
338 
339  std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
340  std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
341 
342  handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
343  }
344  return true;
345  }
uint64 GetUInt64() const
Definition: Field.h:184
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
float GetFloat() const
Definition: Field.h:222
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: GameObject.h:34
Definition: Language.h:608
Definition: Language.h:536
Definition: Language.h:539
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
time_t GetRespawnTimeEx() const
Definition: GameObject.h:936
Player * GetPlayer() const
Definition: WorldSession.h:927
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32 GetRespawnDelay() const
Definition: GameObject.h:959
#define sPoolMgr
Definition: PoolMgr.h:166
unsigned long atoul(char const *str)
Definition: Common.h:90
G3D::int16 z
Definition: Vector3int16.h:46
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
G3D::int16 y
Definition: Vector2int16.h:38
uint16_t uint16
Definition: Define.h:151
#define _LIKE_
Definition: DatabaseEnv.h:32
Definition: GameObject.h:880
uint16 GetUInt16() const
Definition: Field.h:108
Definition: Language.h:298
#define sGameEventMgr
Definition: GameEventMgr.h:184
#define _CONCAT3_(A, B, C)
Definition: DatabaseEnv.h:34
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:106
std::string name
Definition: GameObject.h:39
uint32 GetUInt32() const
Definition: Field.h:146
int32_t int32
Definition: g3dmath.h:167
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
G3D::int16 x
Definition: Vector2int16.h:37
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool gobject_commandscript::HandleGameObjectTurnCommand ( ChatHandler handler,
char const args 
)
inlinestatic
397  {
398  // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
399  char* id = handler->extractKeyFromLink((char*)args, "Hgameobject");
400  if (!id)
401  return false;
402 
403  ObjectGuid::LowType guidLow = strtoull(id, nullptr, 10);
404  if (!guidLow)
405  return false;
406 
407  GameObject* object = NULL;
408 
409  // by DB guid
410  if (GameObjectData const* gameObjectData = sObjectMgr->GetGOData(guidLow))
411  object = handler->GetObjectGlobalyWithGuidOrNearWithDbGuid(guidLow, gameObjectData->id);
412 
413  if (!object)
414  {
415  handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, guidLow);
416  handler->SetSentErrorMessage(true);
417  return false;
418  }
419 
420  char* orientation = strtok(NULL, " ");
421  float o;
422 
423  if (orientation)
424  o = (float)atof(orientation);
425  else
426  {
427  Player* player = handler->GetSession()->GetPlayer();
428  o = player->GetOrientation();
429  }
430 
431  object->Relocate(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), o);
432  object->RelocateStationaryPosition(object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), o);
433  object->UpdateRotationFields();
434  object->DestroyForNearbyPlayers();
435  object->UpdateObjectVisibility();
436 
437  object->SaveToDB();
438 
439  handler->PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE, object->GetSpawnId(), object->GetGOInfo()->name.c_str(), object->GetGUID().ToString().c_str(), o);
440 
441  return true;
442  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
ObjectData const gameObjectData[]
Definition: instance_gundrak.cpp:40
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(ObjectGuid::LowType lowguid, uint32 entry)
Definition: Chat.cpp:766
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
ObjectGuid::LowType GetSpawnId() const
Definition: GameObject.h:902
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: Language.h:308
Definition: GameObject.h:880
Definition: GameObject.h:833
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
float GetPositionX() const
Definition: Position.h:104
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
Definition: Language.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: