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

Public Member Functions

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

Static Public Member Functions

static bool HandleWpAddCommand (ChatHandler *handler, const char *args)
 
static bool HandleWpLoadCommand (ChatHandler *handler, const char *args)
 
static bool HandleWpReloadCommand (ChatHandler *handler, const char *args)
 
static bool HandleWpUnLoadCommand (ChatHandler *handler, const char *)
 
static bool HandleWpEventCommand (ChatHandler *handler, const char *args)
 
static bool HandleWpModifyCommand (ChatHandler *handler, const char *args)
 
static bool HandleWpShowCommand (ChatHandler *handler, const char *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

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

Member Function Documentation

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

Implements CommandScript.

38  {
39  static std::vector<ChatCommand> wpCommandTable =
40  {
41  { "add", rbac::RBAC_PERM_COMMAND_WP_ADD, false, &HandleWpAddCommand, "" },
48  };
49  static std::vector<ChatCommand> commandTable =
50  {
51  { "wp", rbac::RBAC_PERM_COMMAND_WP, false, NULL, "", wpCommandTable },
52  };
53  return commandTable;
54  }
static bool HandleWpReloadCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:220
static bool HandleWpShowCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:736
static bool HandleWpModifyCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:537
Definition: RBAC.h:664
Definition: RBAC.h:666
static bool HandleWpAddCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:76
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleWpEventCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:280
Definition: RBAC.h:661
Definition: RBAC.h:663
static bool HandleWpUnLoadCommand(ChatHandler *handler, const char *)
Definition: cs_wp.cpp:235
static bool HandleWpLoadCommand(ChatHandler *handler, const char *args)
Definition: cs_wp.cpp:139
Definition: RBAC.h:668
Definition: RBAC.h:662
Definition: RBAC.h:665
Definition: RBAC.h:667

+ Here is the call graph for this function:

static bool wp_commandscript::HandleWpAddCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic

Add a waypoint to a creature.

The user can either select an npc or provide its GUID.

The user can even select a visual waypoint - then the new waypoint is placed after the selected one - this makes insertion of new waypoints possible.

eg: .wp add 12345 -> adds a waypoint to the npc with the GUID 12345

.wp add -> adds a waypoint to the currently selected creature

Parameters
argsif the user did not provide a GUID, it is NULL
Returns
true - command did succeed, false - something went wrong
77  {
78  // optional
79  char* path_number = NULL;
80  uint32 pathid = 0;
81 
82  if (*args)
83  path_number = strtok((char*)args, " ");
84 
85  uint32 point = 0;
86  Creature* target = handler->getSelectedCreature();
87 
88  if (!path_number)
89  {
90  if (target)
91  pathid = target->GetWaypointPath();
92  else
93  {
95 
97 
98  uint32 maxpathid = result->Fetch()->GetInt32();
99  pathid = maxpathid+1;
100  handler->PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
101  }
102  }
103  else
104  pathid = atoi(path_number);
105 
106  // path_id -> ID of the Path
107  // point -> number of the waypoint (if not 0)
108 
109  if (!pathid)
110  {
111  handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature haven't loaded path.");
112  return true;
113  }
114 
116  stmt->setUInt32(0, pathid);
117  PreparedQueryResult result = WorldDatabase.Query(stmt);
118 
119  if (result)
120  point = (*result)[0].GetUInt32();
121 
122  Player* player = handler->GetSession()->GetPlayer();
123  //Map* map = player->GetMap();
124 
126 
127  stmt->setUInt32(0, pathid);
128  stmt->setUInt32(1, point + 1);
129  stmt->setFloat(2, player->GetPositionX());
130  stmt->setFloat(3, player->GetPositionY());
131  stmt->setFloat(4, player->GetPositionZ());
132 
133  WorldDatabase.Execute(stmt);
134 
135  handler->PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point+1, "|r|cff00ff00 created. ");
136  return true;
137  } // HandleWpAddCommand
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Creature * getSelectedCreature()
Definition: Chat.cpp:615
uint32 GetWaypointPath() const
Definition: Creature.h:680
Definition: WorldDatabase.h:54
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: WorldDatabase.h:60
Definition: Creature.h:467
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: WorldDatabase.h:67
Definition: PreparedStatement.h:74
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpEventCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic
281  {
282  if (!*args)
283  return false;
284 
285  char* show_str = strtok((char*)args, " ");
286  std::string show = show_str;
287  PreparedStatement* stmt = NULL;
288 
289  // Check
290  if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid"))
291  return false;
292 
293  char* arg_id = strtok(NULL, " ");
294  uint32 id = 0;
295 
296  if (show == "add")
297  {
298  if (arg_id)
299  id = atoi(arg_id);
300 
301  if (id)
302  {
304  stmt->setUInt32(0, id);
305  PreparedQueryResult result = WorldDatabase.Query(stmt);
306 
307  if (!result)
308  {
310  stmt->setUInt32(0, id);
311  WorldDatabase.Execute(stmt);
312 
313  handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id);
314  }
315  else
316  handler->PSendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r", id);
317  }
318  else
319  {
321  PreparedQueryResult result = WorldDatabase.Query(stmt);
322  id = result->Fetch()->GetUInt32();
324  stmt->setUInt32(0, id + 1);
325  WorldDatabase.Execute(stmt);
326 
327  handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: |r|cff00ffff", id+1);
328  }
329 
330  return true;
331  }
332 
333  if (show == "listid")
334  {
335  if (!arg_id)
336  {
337  handler->PSendSysMessage("%s%s|r", "|cff33ffff", "Wp Event: You must provide waypoint script id.");
338  return true;
339  }
340 
341  id = atoi(arg_id);
342 
343  uint32 a2, a3, a4, a5, a6;
344  float a8, a9, a10, a11;
345  char const* a7;
346 
348  stmt->setUInt32(0, id);
349  PreparedQueryResult result = WorldDatabase.Query(stmt);
350 
351  if (!result)
352  {
353  handler->PSendSysMessage("%s%s%u|r", "|cff33ffff", "Wp Event: No waypoint scripts found on id: ", id);
354  return true;
355  }
356 
357  Field* fields;
358 
359  do
360  {
361  fields = result->Fetch();
362  a2 = fields[0].GetUInt32();
363  a3 = fields[1].GetUInt32();
364  a4 = fields[2].GetUInt32();
365  a5 = fields[3].GetUInt32();
366  a6 = fields[4].GetUInt32();
367  a7 = fields[5].GetCString();
368  a8 = fields[6].GetFloat();
369  a9 = fields[7].GetFloat();
370  a10 = fields[8].GetFloat();
371  a11 = fields[9].GetFloat();
372 
373  handler->PSendSysMessage("|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
374  }
375  while (result->NextRow());
376  }
377 
378  if (show == "del")
379  {
380  if (!arg_id)
381  {
382  handler->SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
383  return true;
384  }
385 
386  id = atoi(arg_id);
387 
389  stmt->setUInt32(0, id);
390  PreparedQueryResult result = WorldDatabase.Query(stmt);
391 
392  if (result)
393  {
395  stmt->setUInt32(0, id);
396  WorldDatabase.Execute(stmt);
397 
398  handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: Waypoint script removed: ", id);
399  }
400  else
401  handler->PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: %u|r", id);
402 
403  return true;
404  }
405 
406  if (show == "mod")
407  {
408  if (!arg_id)
409  {
410  handler->SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
411  return true;
412  }
413 
414  id = atoi(arg_id);
415 
416  if (!id)
417  {
418  handler->SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r");
419  return true;
420  }
421 
422  char* arg_2 = strtok(NULL, " ");
423 
424  if (!arg_2)
425  {
426  handler->SendSysMessage("|cffff33ffERROR: No argument present.|r");
427  return true;
428  }
429 
430  std::string arg_string = arg_2;
431 
432  if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command")
433  && (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx")
434  && (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation"))
435  {
436  handler->SendSysMessage("|cffff33ffERROR: No valid argument present.|r");
437  return true;
438  }
439 
440  char* arg_3;
441  std::string arg_str_2 = arg_2;
442  arg_3 = strtok(NULL, " ");
443 
444  if (!arg_3)
445  {
446  handler->SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
447  return true;
448  }
449 
450  if (arg_str_2 == "setid")
451  {
452  uint32 newid = atoi(arg_3);
453  handler->PSendSysMessage("%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r", "|cff00ff00", "Wp Event: Wypoint scipt guid: ", newid, " id changed: ", id);
454 
456  stmt->setUInt32(0, newid);
457  stmt->setUInt32(1, id);
458  WorldDatabase.Execute(stmt);
459 
460  return true;
461  }
462  else
463  {
465  stmt->setUInt32(0, id);
466  PreparedQueryResult result = WorldDatabase.Query(stmt);
467 
468  if (!result)
469  {
470  handler->SendSysMessage("|cffff33ffERROR: You have selected an non existing waypoint script guid.|r");
471  return true;
472  }
473 
474  if (arg_str_2 == "posx")
475  {
477  stmt->setFloat(0, float(atof(arg_3)));
478  stmt->setUInt32(1, id);
479 
480  WorldDatabase.Execute(stmt);
481 
482  handler->PSendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r", id);
483  return true;
484  }
485  else if (arg_str_2 == "posy")
486  {
488  stmt->setFloat(0, float(atof(arg_3)));
489  stmt->setUInt32(1, id);
490 
491  WorldDatabase.Execute(stmt);
492 
493  handler->PSendSysMessage("|cff00ff00Waypoint script: %u position_y updated.|r", id);
494  return true;
495  }
496  else if (arg_str_2 == "posz")
497  {
499  stmt->setFloat(0, float(atof(arg_3)));
500  stmt->setUInt32(1, id);
501 
502  WorldDatabase.Execute(stmt);
503 
504  handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r", id);
505  return true;
506  }
507  else if (arg_str_2 == "orientation")
508  {
510  stmt->setFloat(0, float(atof(arg_3)));
511  stmt->setUInt32(1, id);
512 
513  WorldDatabase.Execute(stmt);
514 
515  handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r", id);
516  return true;
517  }
518  else if (arg_str_2 == "dataint")
519  {
520  WorldDatabase.PExecute("UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'", arg_2, atoi(arg_3), id); // Query can't be a prepared statement
521 
522  handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r", id);
523  return true;
524  }
525  else
526  {
527  std::string arg_str_3 = arg_3;
528  WorldDatabase.EscapeString(arg_str_3);
529  WorldDatabase.PExecute("UPDATE waypoint_scripts SET %s='%s' WHERE guid='%u'", arg_2, arg_str_3.c_str(), id); // Query can't be a prepared statement
530  }
531  }
532  handler->PSendSysMessage("%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r", "|cff00ff00", "Waypoint script:", id, arg_2, "updated.");
533  }
534  return true;
535  }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
float GetFloat() const
Definition: Field.h:222
Class used to access individual fields of database query result.
Definition: Field.h:56
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: WorldDatabase.h:71
Definition: PreparedStatement.h:74
char const * GetCString() const
Definition: Field.h:260
void PExecute(Format &&sql, Args &&...args)
Definition: DatabaseWorkerPool.h:99
Definition: WorldDatabase.h:77
Definition: WorldDatabase.h:78
Definition: WorldDatabase.h:81
uint32_t uint32
Definition: Define.h:150
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
Definition: WorldDatabase.h:87
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: WorldDatabase.h:83
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: WorldDatabase.h:79
uint32 GetUInt32() const
Definition: Field.h:146
void setFloat(const uint8 index, const float value)
Definition: PreparedStatement.cpp:169
Definition: WorldDatabase.h:82
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: WorldDatabase.h:80
Definition: WorldDatabase.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpLoadCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic
140  {
141  if (!*args)
142  return false;
143 
144  // optional
145  char* path_number = NULL;
146 
147  if (*args)
148  path_number = strtok((char*)args, " ");
149 
150  uint32 pathid = 0;
151  ObjectGuid::LowType guidLow = UI64LIT(0);
152  Creature* target = handler->getSelectedCreature();
153 
154  // Did player provide a path_id?
155  if (!path_number)
156  return false;
157 
158  if (!target)
159  {
161  handler->SetSentErrorMessage(true);
162  return false;
163  }
164 
165  if (target->GetEntry() == 1)
166  {
167  handler->PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
168  handler->SetSentErrorMessage(true);
169  return false;
170  }
171 
172  pathid = atoi(path_number);
173 
174  if (!pathid)
175  {
176  handler->PSendSysMessage("%s%s|r", "|cffff33ff", "No valid path number provided.");
177  return true;
178  }
179 
180  guidLow = target->GetSpawnId();
181 
183 
184  stmt->setUInt64(0, guidLow);
185 
186  PreparedQueryResult result = WorldDatabase.Query(stmt);
187 
188  if (result)
189  {
191 
192  stmt->setUInt32(0, pathid);
193  stmt->setUInt64(1, guidLow);
194  }
195  else
196  {
198 
199  stmt->setUInt64(0, guidLow);
200  stmt->setUInt32(1, pathid);
201  }
202 
203  WorldDatabase.Execute(stmt);
204 
206 
208  stmt->setUInt64(1, guidLow);
209 
210  WorldDatabase.Execute(stmt);
211 
212  target->LoadPath(pathid);
214  target->GetMotionMaster()->Initialize();
215  target->Say("Path loaded.", LANG_UNIVERSAL);
216 
217  return true;
218  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: WorldDatabase.h:73
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: SharedDefines.h:961
Creature * getSelectedCreature()
Definition: Chat.cpp:615
MotionMaster * GetMotionMaster()
Definition: Unit.h:2101
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
#define UI64LIT(N)
Definition: Define.h:138
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: WorldDatabase.h:75
Definition: Creature.h:467
void LoadPath(uint32 pathid)
Definition: Creature.h:681
uint64 LowType
Definition: ObjectGuid.h:199
Definition: PreparedStatement.h:74
Definition: Language.h:33
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:625
Definition: WorldDatabase.h:72
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
uint8_t uint8
Definition: g3dmath.h:164
virtual void Say(std::string const &text, Language language, WorldObject const *target=nullptr)
Definition: Unit.cpp:16393
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
Definition: WorldDatabase.h:47
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
uint32 GetEntry() const
Definition: Object.h:107
void Initialize()
Definition: MotionMaster.cpp:39
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: MotionMaster.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpModifyCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic
Todo:
Should we first use "Create" then use "LoadFromDB"?
538  {
539  if (!*args)
540  return false;
541 
542  // first arg: add del text emote spell waittime move
543  char* show_str = strtok((char*)args, " ");
544  if (!show_str)
545  {
546  return false;
547  }
548 
549  std::string show = show_str;
550  // Check
551  // Remember: "show" must also be the name of a column!
552  if ((show != "delay") && (show != "action") && (show != "action_chance")
553  && (show != "move_type") && (show != "del") && (show != "move")
554  )
555  {
556  return false;
557  }
558 
559  // Next arg is: <PATHID> <WPNUM> <ARGUMENT>
560  char* arg_str = NULL;
561 
562  // Did user provide a GUID
563  // or did the user select a creature?
564  // -> variable lowguid is filled with the GUID of the NPC
565  uint32 pathid = 0;
566  uint32 point = 0;
567  ObjectGuid wpGuid;
568  Creature* target = handler->getSelectedCreature();
569  PreparedStatement* stmt = NULL;
570 
571  if (!target || target->GetEntry() != VISUAL_WAYPOINT)
572  {
573  handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
574  return false;
575  }
576 
577  // The visual waypoint
578  wpGuid = target->GetGUID();
579 
580  // User did select a visual waypoint?
581 
582  // Check the creature
584  stmt->setUInt64(0, wpGuid.GetCounter());
585  PreparedQueryResult result = WorldDatabase.Query(stmt);
586 
587  if (!result)
588  {
589  handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUID().ToString().c_str());
590  // Select waypoint number from database
591  // Since we compare float values, we have to deal with
592  // some difficulties.
593  // Here we search for all waypoints that only differ in one from 1 thousand
594  // (0.001) - There is no other way to compare C++ floats with mySQL floats
595  // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
596  std::string maxDiff = "0.01";
597 
599  stmt->setFloat(0, target->GetPositionX());
600  stmt->setString(1, maxDiff);
601  stmt->setFloat(2, target->GetPositionY());
602  stmt->setString(3, maxDiff);
603  stmt->setFloat(4, target->GetPositionZ());
604  stmt->setString(5, maxDiff);
605  PreparedQueryResult queryResult = WorldDatabase.Query(stmt);
606 
607  if (!queryResult)
608  {
609  handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid.ToString().c_str());
610  return true;
611  }
612  }
613 
614  do
615  {
616  Field* fields = result->Fetch();
617  pathid = fields[0].GetUInt32();
618  point = fields[1].GetUInt32();
619  }
620  while (result->NextRow());
621 
622  // We have the waypoint number and the GUID of the "master npc"
623  // Text is enclosed in "<>", all other arguments not
624  arg_str = strtok((char*)NULL, " ");
625 
626  // Check for argument
627  if (show != "del" && show != "move" && arg_str == NULL)
628  {
629  handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
630  return false;
631  }
632 
633  if (show == "del")
634  {
635  handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
636 
637  if (!wpGuid.IsEmpty())
638  {
639  if (Creature* wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(wpGuid))
640  {
641  wpCreature->CombatStop();
642  wpCreature->DeleteFromDB();
643  wpCreature->AddObjectToRemoveList();
644  }
645  }
646 
648  stmt->setUInt32(0, pathid);
649  stmt->setUInt32(1, point);
650  WorldDatabase.Execute(stmt);
651 
653  stmt->setUInt32(0, pathid);
654  stmt->setUInt32(1, point);
655  WorldDatabase.Execute(stmt);
656 
658  return true;
659  } // del
660 
661  if (show == "move")
662  {
663  handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
664 
665  Player* chr = handler->GetSession()->GetPlayer();
666  Map* map = chr->GetMap();
667  {
668  // What to do:
669  // Move the visual spawnpoint
670  // Respawn the owner of the waypoints
671  if (!wpGuid.IsEmpty())
672  {
673  if (Creature* wpCreature = map->GetCreature(wpGuid))
674  {
675  wpCreature->CombatStop();
676  wpCreature->DeleteFromDB();
677  wpCreature->AddObjectToRemoveList();
678  }
679  // re-create
680  Creature* wpCreature2 = new Creature();
681  if (!wpCreature2->Create(map->GenerateLowGuid<HighGuid::Creature>(), map, chr->GetPhaseMask(), VISUAL_WAYPOINT, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
682  {
684  delete wpCreature2;
685  wpCreature2 = NULL;
686  return false;
687  }
688 
689  wpCreature2->CopyPhaseFrom(chr);
690 
691  wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMask());
692  // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
694  if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetSpawnId(), map))
695  {
697  delete wpCreature2;
698  wpCreature2 = NULL;
699  return false;
700  }
701  //sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
702  }
703 
705  stmt->setFloat(0, chr->GetPositionX());
706  stmt->setFloat(1, chr->GetPositionY());
707  stmt->setFloat(2, chr->GetPositionZ());
708  stmt->setUInt32(3, pathid);
709  stmt->setUInt32(4, point);
710  WorldDatabase.Execute(stmt);
711 
713  }
714  return true;
715  } // move
716 
717  const char *text = arg_str;
718 
719  if (text == 0)
720  {
721  // show_str check for present in list of correct values, no sql injection possible
722  WorldDatabase.PExecute("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'", show_str, pathid, point); // Query can't be a prepared statement
723  }
724  else
725  {
726  // show_str check for present in list of correct values, no sql injection possible
727  std::string text2 = text;
729  WorldDatabase.PExecute("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'", show_str, text2.c_str(), pathid, point); // Query can't be a prepared statement
730  }
731 
732  handler->PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str);
733  return true;
734  }
uint8 GetSpawnMode() const
Definition: Map.h:369
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Creature * getSelectedCreature()
Definition: Chat.cpp:615
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: WorldDatabase.h:65
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
void SaveToDB()
Definition: Creature.cpp:1034
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 entry, float x, float y, float z, float ang, CreatureData const *data=nullptr, uint32 vehId=0)
Definition: Creature.cpp:834
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:261
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
void CopyPhaseFrom(WorldObject *obj, bool update=false)
Definition: Object.cpp:2915
void AddObjectToRemoveList(WorldObject *obj)
Definition: Map.cpp:2804
Definition: Creature.h:467
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: PreparedStatement.h:74
Definition: Language.h:256
void PExecute(Format &&sql, Args &&...args)
Definition: DatabaseWorkerPool.h:99
uint32 GetId(void) const
Definition: Map.h:325
Definition: Language.h:269
Definition: WorldDatabase.h:68
Definition: WorldDatabase.h:57
float GetPositionY() const
Definition: Position.h:105
float GetPositionZ() const
Definition: Position.h:106
uint32_t uint32
Definition: Define.h:150
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
Definition: WorldDatabase.h:56
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: Map.h:259
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
ObjectGuid const & GetGUID() const
Definition: Object.h:105
Creature * GetCreature(ObjectGuid const &guid)
Definition: Map.cpp:3535
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: Language.h:265
uint32 GetUInt32() const
Definition: Field.h:146
void setFloat(const uint8 index, const float value)
Definition: PreparedStatement.cpp:169
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
WorldSession * GetSession()
Definition: Chat.h:59
Definition: WorldDatabase.h:55
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
uint32 GetEntry() const
Definition: Object.h:107
Definition: ObjectGuid.h:189
ObjectGuid::LowType GenerateLowGuid()
Definition: Map.h:561
float GetPositionX() const
Definition: Position.h:104
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:32
bool LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map *map, bool addToMap=true, bool allowDuplicate=false)
Definition: Creature.cpp:1327
Definition: Language.h:264
std::string ToString() const
Definition: ObjectGuid.cpp:99
bool IsEmpty() const
Definition: ObjectGuid.h:242
Definition: Language.h:251
LowType GetCounter() const
Definition: ObjectGuid.h:221
Definition: Language.h:250

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpReloadCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic
221  {
222  if (!*args)
223  return false;
224 
225  uint32 id = atoi(args);
226 
227  if (!id)
228  return false;
229 
230  handler->PSendSysMessage("%s%s|r|cff00ffff%u|r", "|cff00ff00", "Loading Path: ", id);
231  sWaypointMgr->ReloadPath(id);
232  return true;
233  }
#define sWaypointMgr
Definition: WaypointManager.h:75
uint32_t uint32
Definition: Define.h:150
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpShowCommand ( ChatHandler handler,
const char *  args 
)
inlinestatic
737  {
738  if (!*args)
739  return false;
740 
741  // first arg: on, off, first, last
742  char* show_str = strtok((char*)args, " ");
743  if (!show_str)
744  return false;
745 
746  // second arg: GUID (optional, if a creature is selected)
747  char* guid_str = strtok((char*)NULL, " ");
748 
749  uint32 pathid = 0;
750  Creature* target = handler->getSelectedCreature();
751  PreparedStatement* stmt = NULL;
752 
753  // Did player provide a PathID?
754 
755  if (!guid_str)
756  {
757  // No PathID provided
758  // -> Player must have selected a creature
759 
760  if (!target)
761  {
763  handler->SetSentErrorMessage(true);
764  return false;
765  }
766 
767  pathid = target->GetWaypointPath();
768  }
769  else
770  {
771  // PathID provided
772  // Warn if player also selected a creature
773  // -> Creature selection is ignored <-
774  if (target)
776 
777  pathid = atoi((char*)guid_str);
778  }
779 
780  std::string show = show_str;
781 
782  //handler->PSendSysMessage("wpshow - show: %s", show);
783 
784  // Show info for the selected waypoint
785  if (show == "info")
786  {
787  // Check if the user did specify a visual waypoint
788  if (!target || target->GetEntry() != VISUAL_WAYPOINT)
789  {
791  handler->SetSentErrorMessage(true);
792  return false;
793  }
794 
796  stmt->setUInt64(0, target->GetGUID().GetCounter());
797  PreparedQueryResult result = WorldDatabase.Query(stmt);
798 
799  if (!result)
800  {
802  return true;
803  }
804 
805  handler->SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
806  do
807  {
808  Field* fields = result->Fetch();
809  pathid = fields[0].GetUInt32();
810  uint32 point = fields[1].GetUInt32();
811  uint32 delay = fields[2].GetUInt32();
812  uint32 flag = fields[3].GetUInt32();
813  uint32 ev_id = fields[4].GetUInt32();
814  uint32 ev_chance = fields[5].GetUInt32();
815 
816  handler->PSendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid);
817  handler->PSendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay);
818  handler->PSendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag);
819  handler->PSendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id);
820  handler->PSendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance);
821  }
822  while (result->NextRow());
823 
824  return true;
825  }
826 
827  if (show == "on")
828  {
830  stmt->setUInt32(0, pathid);
831  PreparedQueryResult result = WorldDatabase.Query(stmt);
832 
833  if (!result)
834  {
835  handler->SendSysMessage("|cffff33ffPath no found.|r");
836  handler->SetSentErrorMessage(true);
837  return false;
838  }
839 
840  handler->PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
841 
842  // Delete all visuals for this NPC
844 
845  stmt->setUInt32(0, pathid);
846 
847  PreparedQueryResult result2 = WorldDatabase.Query(stmt);
848 
849  if (result2)
850  {
851  bool hasError = false;
852  Map* map = handler->GetSession()->GetPlayer()->GetMap();
853  do
854  {
855  Field* fields = result2->Fetch();
856  ObjectGuid::LowType wpguid = fields[0].GetUInt64();
857  Creature* creature = map->GetCreature(ObjectGuid::Create<HighGuid::Creature>(map->GetId(), VISUAL_WAYPOINT, wpguid));
858 
859  if (!creature)
860  {
861  handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpguid);
862  hasError = true;
863 
865  stmt->setUInt64(0, wpguid);
866  WorldDatabase.Execute(stmt);
867  }
868  else
869  {
870  creature->CombatStop();
871  creature->DeleteFromDB();
872  creature->AddObjectToRemoveList();
873  }
874 
875  }
876  while (result2->NextRow());
877 
878  if (hasError)
879  {
883  }
884  }
885 
886  do
887  {
888  Field* fields = result->Fetch();
889  uint32 point = fields[0].GetUInt32();
890  float x = fields[1].GetFloat();
891  float y = fields[2].GetFloat();
892  float z = fields[3].GetFloat();
893 
894  uint32 id = VISUAL_WAYPOINT;
895 
896  Player* chr = handler->GetSession()->GetPlayer();
897  Map* map = chr->GetMap();
898  float o = chr->GetOrientation();
899 
900  Creature* wpCreature = new Creature();
901  if (!wpCreature->Create(map->GenerateLowGuid<HighGuid::Creature>(), map, chr->GetPhaseMask(), id, x, y, z, o))
902  {
904  delete wpCreature;
905  return false;
906  }
907 
908  wpCreature->CopyPhaseFrom(chr);
909 
910  // Set "wpguid" column to the visual waypoint
912  stmt->setUInt64(0, wpCreature->GetGUID().GetCounter());
913  stmt->setUInt32(1, pathid);
914  stmt->setUInt32(2, point);
915  WorldDatabase.Execute(stmt);
916 
917  wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMask());
918  // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
919  if (!wpCreature->LoadCreatureFromDB(wpCreature->GetSpawnId(), map))
920  {
922  delete wpCreature;
923  return false;
924  }
925 
926  if (target)
927  {
928  wpCreature->SetDisplayId(target->GetDisplayId());
929  wpCreature->SetObjectScale(0.5f);
930  wpCreature->SetLevel(std::min<uint32>(point, STRONG_MAX_LEVEL));
931  }
932  }
933  while (result->NextRow());
934 
935  handler->SendSysMessage("|cff00ff00Showing the current creature's path.|r");
936  return true;
937  }
938 
939  if (show == "first")
940  {
941  handler->PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
942 
944  stmt->setUInt32(0, pathid);
945  PreparedQueryResult result = WorldDatabase.Query(stmt);
946 
947  if (!result)
948  {
949  handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
950  handler->SetSentErrorMessage(true);
951  return false;
952  }
953 
954  Field* fields = result->Fetch();
955  float x = fields[0].GetFloat();
956  float y = fields[1].GetFloat();
957  float z = fields[2].GetFloat();
958  uint32 id = VISUAL_WAYPOINT;
959 
960  Player* chr = handler->GetSession()->GetPlayer();
961  float o = chr->GetOrientation();
962  Map* map = chr->GetMap();
963 
964  Creature* creature = new Creature();
965  if (!creature->Create(map->GenerateLowGuid<HighGuid::Creature>(), map, chr->GetPhaseMask(), id, x, y, z, o))
966  {
968  delete creature;
969  return false;
970  }
971 
972  creature->CopyPhaseFrom(chr);
973 
974  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMask());
975  if (!creature->LoadCreatureFromDB(creature->GetSpawnId(), map))
976  {
978  delete creature;
979  return false;
980  }
981 
982  if (target)
983  {
984  creature->SetDisplayId(target->GetDisplayId());
985  creature->SetObjectScale(0.5f);
986  }
987 
988  return true;
989  }
990 
991  if (show == "last")
992  {
993  handler->PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
994 
996  stmt->setUInt32(0, pathid);
997  PreparedQueryResult result = WorldDatabase.Query(stmt);
998 
999  if (!result)
1000  {
1001  handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST, pathid);
1002  handler->SetSentErrorMessage(true);
1003  return false;
1004  }
1005  Field* fields = result->Fetch();
1006  float x = fields[0].GetFloat();
1007  float y = fields[1].GetFloat();
1008  float z = fields[2].GetFloat();
1009  float o = fields[3].GetFloat();
1010  uint32 id = VISUAL_WAYPOINT;
1011 
1012  Player* chr = handler->GetSession()->GetPlayer();
1013  Map* map = chr->GetMap();
1014 
1015  Creature* creature = new Creature();
1016  if (!creature->Create(map->GenerateLowGuid<HighGuid::Creature>(), map, chr->GetPhaseMask(), id, x, y, z, o))
1017  {
1019  delete creature;
1020  return false;
1021  }
1022 
1023  creature->CopyPhaseFrom(chr);
1024 
1025  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMask());
1026  if (!creature->LoadCreatureFromDB(creature->GetSpawnId(), map))
1027  {
1029  delete creature;
1030  return false;
1031  }
1032 
1033  if (target)
1034  {
1035  creature->SetDisplayId(target->GetDisplayId());
1036  creature->SetObjectScale(0.5f);
1037  }
1038 
1039  return true;
1040  }
1041 
1042  if (show == "off")
1043  {
1045  stmt->setUInt32(0, 1);
1046  PreparedQueryResult result = WorldDatabase.Query(stmt);
1047 
1048  if (!result)
1049  {
1051  handler->SetSentErrorMessage(true);
1052  return false;
1053  }
1054  bool hasError = false;
1055  Map* map = handler->GetSession()->GetPlayer()->GetMap();
1056  do
1057  {
1058  Field* fields = result->Fetch();
1059  ObjectGuid::LowType guid = fields[0].GetUInt64();
1060  Creature* creature = map->GetCreature(ObjectGuid::Create<HighGuid::Creature>(map->GetId(), VISUAL_WAYPOINT, guid));
1061  if (!creature)
1062  {
1063  handler->PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, guid);
1064  hasError = true;
1065 
1067  stmt->setUInt64(0, guid);
1068  WorldDatabase.Execute(stmt);
1069  }
1070  else
1071  {
1072  creature->CombatStop();
1073  creature->DeleteFromDB();
1074  creature->AddObjectToRemoveList();
1075  }
1076  }
1077  while (result->NextRow());
1078  // set "wpguid" column to "empty" - no visual waypoint spawned
1080 
1081  WorldDatabase.Execute(stmt);
1082  //WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
1083 
1084  if (hasError)
1085  {
1089  }
1090 
1092  return true;
1093  }
1094 
1095  handler->PSendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
1096  return true;
1097  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
uint8 GetSpawnMode() const
Definition: Map.h:369
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: WorldDatabase.h:66
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
uint64 GetUInt64() const
Definition: Field.h:184
Creature * getSelectedCreature()
Definition: Chat.cpp:615
uint32 GetDisplayId() const
Definition: Unit.h:2012
float GetFloat() const
Definition: Field.h:222
uint32 GetWaypointPath() const
Definition: Creature.h:680
Definition: WorldDatabase.h:58
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: WorldDatabase.h:84
Definition: Language.h:249
Definition: WorldDatabase.h:64
void SaveToDB()
Definition: Creature.cpp:1034
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 entry, float x, float y, float z, float ang, CreatureData const *data=nullptr, uint32 vehId=0)
Definition: Creature.cpp:834
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: DBCEnums.h:54
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
void CopyPhaseFrom(WorldObject *obj, bool update=false)
Definition: Object.cpp:2915
Definition: Creature.h:467
Player * GetPlayer() const
Definition: WorldSession.h:927
void SetObjectScale(float scale) override
Definition: Creature.cpp:2653
uint64 LowType
Definition: ObjectGuid.h:199
Definition: PreparedStatement.h:74
Definition: Language.h:256
Definition: WorldDatabase.h:63
virtual void DeleteFromDB()
Definition: Creature.cpp:1474
uint32 GetId(void) const
Definition: Map.h:325
Definition: Language.h:271
Definition: Language.h:257
Definition: Language.h:33
void AddObjectToRemoveList()
Definition: Object.cpp:2205
void SetLevel(uint8 lvl)
Definition: Unit.cpp:11523
G3D::int16 z
Definition: Vector3int16.h:46
Definition: WorldDatabase.h:59
Definition: Language.h:248
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
Definition: WorldDatabase.h:69
Definition: Language.h:272
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: Map.h:259
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
ObjectGuid const & GetGUID() const
Definition: Object.h:105
void SetDisplayId(uint32 modelId) override
Definition: Creature.cpp:2664
Creature * GetCreature(ObjectGuid const &guid)
Definition: Map.cpp:3535
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: Language.h:255
Definition: Language.h:252
Definition: Language.h:270
uint32 GetUInt32() const
Definition: Field.h:146
Definition: WorldDatabase.h:88
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
uint32 GetEntry() const
Definition: Object.h:107
G3D::int16 x
Definition: Vector2int16.h:37
ObjectGuid::LowType GenerateLowGuid()
Definition: Map.h:561
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: WorldDatabase.h:62
Definition: Language.h:273
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:32
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:7371
bool LoadCreatureFromDB(ObjectGuid::LowType spawnId, Map *map, bool addToMap=true, bool allowDuplicate=false)
Definition: Creature.cpp:1327
Definition: Language.h:258
Definition: Language.h:254
Definition: Language.h:251
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool wp_commandscript::HandleWpUnLoadCommand ( ChatHandler handler,
const char *   
)
inlinestatic
236  {
237 
238  Creature* target = handler->getSelectedCreature();
239  PreparedStatement* stmt = NULL;
240 
241  if (!target)
242  {
243  handler->PSendSysMessage("%s%s|r", "|cff33ffff", "You must select a target.");
244  return true;
245  }
246 
247  ObjectGuid::LowType guidLow = target->GetSpawnId();
248  if (!guidLow)
249  {
250  handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Target is not saved to DB.");
251  return true;
252  }
253 
254  CreatureAddon const* addon = sObjectMgr->GetCreatureAddon(guidLow);
255  if (!addon || addon->path_id == 0)
256  {
257  handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Target does not have a loaded path.");
258  return true;
259  }
260 
262  stmt->setUInt64(0, guidLow);
263  WorldDatabase.Execute(stmt);
264 
265  target->UpdateWaypointID(0);
266 
268  stmt->setUInt8(0, uint8(IDLE_MOTION_TYPE));
269  stmt->setUInt64(1, guidLow);
270  WorldDatabase.Execute(stmt);
271 
272  target->LoadPath(0);
274  target->GetMotionMaster()->MoveTargetedHome();
275  target->GetMotionMaster()->Initialize();
276  target->Say("Path unloaded.", LANG_UNIVERSAL);
277  return true;
278  }
Definition: WorldDatabase.h:74
Definition: MotionMaster.h:37
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: SharedDefines.h:961
Creature * getSelectedCreature()
Definition: Chat.cpp:615
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:684
MotionMaster * GetMotionMaster()
Definition: Unit.h:2101
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
void MoveTargetedHome()
Definition: MotionMaster.cpp:201
uint32 path_id
Definition: Creature.h:355
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:487
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: Creature.h:467
void LoadPath(uint32 pathid)
Definition: Creature.h:681
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: PreparedStatement.h:74
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:625
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: Creature.h:353
uint8_t uint8
Definition: g3dmath.h:164
virtual void Say(std::string const &text, Language language, WorldObject const *target=nullptr)
Definition: Unit.cpp:16393
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
Definition: WorldDatabase.h:47
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
void Initialize()
Definition: MotionMaster.cpp:39

+ 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: