Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
cs_wp.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/* ScriptData
7Name: wp_commandscript
8%Complete: 100
9Comment: All wp related commands
10Category: commandscripts
11EndScriptData */
12
13#include "Chat.h"
14#include "Language.h"
15#include "ObjectMgr.h"
16#include "Player.h"
17#include "ScriptMgr.h"
18#include "WaypointManager.h"
19
21{
22public:
23 wp_commandscript() : CommandScript("wp_commandscript") { }
24
25 std::vector<ChatCommand> GetCommands() const OVERRIDE
26 {
27 static std::vector<ChatCommand> wpCommandTable =
28 {
36 };
37 static std::vector<ChatCommand> commandTable =
38 {
39 { "wp", rbac::RBAC_PERM_COMMAND_WP, false, NULL, "", wpCommandTable },
40 };
41 return commandTable;
42 }
43
64 static bool HandleWpAddCommand(ChatHandler* handler, const char* args)
65 {
66 // optional
67 char* path_number = NULL;
68 uint32 pathid = 0;
69
70 if (*args)
71 path_number = strtok((char*)args, " ");
72
73 uint32 point = 0;
74 Creature* target = handler->getSelectedCreature();
75
76 if (!path_number)
77 {
78 if (target)
79 pathid = target->GetWaypointPath();
80 else
81 {
83
84 PreparedQueryResult result = WorldDatabase.Query(stmt);
85
86 uint32 maxpathid = result->Fetch()->GetInt32();
87 pathid = maxpathid + 1;
88 handler->PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
89 }
90 }
91 else
92 pathid = atoi(path_number);
93
94 // path_id -> ID of the Path
95 // point -> number of the waypoint (if not 0)
96
97 if (!pathid)
98 {
99 handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature haven't loaded path.");
100 return true;
101 }
102
104 stmt->setUInt32(0, pathid);
105 PreparedQueryResult result = WorldDatabase.Query(stmt);
106
107 if (result)
108 point = (*result)[0].GetUInt32();
109
110 Player* player = handler->GetSession()->GetPlayer();
111 //Map* map = player->GetMap();
112
113 stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_DATA);
114
115 stmt->setUInt32(0, pathid);
116 stmt->setUInt32(1, point + 1);
117 stmt->setFloat(2, player->GetPositionX());
118 stmt->setFloat(3, player->GetPositionY());
119 stmt->setFloat(4, player->GetPositionZ());
120
121 WorldDatabase.Execute(stmt);
122
123 handler->PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point + 1, "|r|cff00ff00 created. ");
124 return true;
125 } // HandleWpAddCommand
126
127 static bool HandleWpLoadCommand(ChatHandler* handler, const char* args)
128 {
129 if (!*args)
130 return false;
131
132 // optional
133 char* path_number = NULL;
134
135 if (*args)
136 path_number = strtok((char*)args, " ");
137
138 uint32 pathid = 0;
139 uint32 guidLow = 0;
140 Creature* target = handler->getSelectedCreature();
141
142 // Did player provide a path_id?
143 if (!path_number)
144 return false;
145
146 if (!target)
147 {
149 handler->SetSentErrorMessage(true);
150 return false;
151 }
152
153 if (target->GetEntry() == 1)
154 {
155 handler->PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
156 handler->SetSentErrorMessage(true);
157 return false;
158 }
159
160 pathid = atoi(path_number);
161
162 if (!pathid)
163 {
164 handler->PSendSysMessage("%s%s|r", "|cffff33ff", "No valid path number provided.");
165 return true;
166 }
167
168 guidLow = target->GetDBTableGUIDLow();
169
171
172 stmt->setUInt32(0, guidLow);
173
174 PreparedQueryResult result = WorldDatabase.Query(stmt);
175
176 if (result)
177 {
178 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_ADDON_PATH);
179
180 stmt->setUInt32(0, pathid);
181 stmt->setUInt32(1, guidLow);
182 }
183 else
184 {
185 stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_CREATURE_ADDON);
186
187 stmt->setUInt32(0, guidLow);
188 stmt->setUInt32(1, pathid);
189 }
190
191 WorldDatabase.Execute(stmt);
192
193 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_MOVEMENT_TYPE);
194
196 stmt->setUInt32(1, guidLow);
197
198 WorldDatabase.Execute(stmt);
199
200 target->LoadPath(pathid);
202 target->GetMotionMaster()->Initialize();
203 target->MonsterSay("Path loaded.", Language::LANG_UNIVERSAL, NULL);
204
205 return true;
206 }
207
208 static bool HandleWpReloadCommand(ChatHandler* handler, const char* args)
209 {
210 if (!*args)
211 return false;
212
213 uint32 id = atoi(args);
214
215 if (!id)
216 return false;
217
218 handler->PSendSysMessage("%s%s|r|cff00ffff%u|r", "|cff00ff00", "Loading Path: ", id);
219 sWaypointMgr->ReloadPath(id);
220 return true;
221 }
222
223 static bool HandleWpUnLoadCommand(ChatHandler* handler, const char* /*args*/)
224 {
225 Creature* target = handler->getSelectedCreature();
226
227 if (!target)
228 {
229 handler->PSendSysMessage("%s%s|r", "|cff33ffff", "You must select a target.");
230 return true;
231 }
232
233 uint32 guidLow = target->GetDBTableGUIDLow();
234 if (guidLow == 0)
235 {
236 handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Target is not saved to DB.");
237 return true;
238 }
239
240 CreatureAddon const* addon = sObjectMgr->GetCreatureAddon(guidLow);
241 if (!addon || addon->path_id == 0)
242 {
243 handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Target does not have a loaded path.");
244 return true;
245 }
246
247 PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE_ADDON);
248
249 stmt->setUInt32(0, guidLow);
250
251 WorldDatabase.Execute(stmt);
252
253 target->UpdateWaypointID(0);
254
255 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_MOVEMENT_TYPE);
256
258 stmt->setUInt32(1, guidLow);
259
260 WorldDatabase.Execute(stmt);
261
262 target->LoadPath(0);
265 target->GetMotionMaster()->Initialize();
266 target->MonsterSay("Path unloaded.", Language::LANG_UNIVERSAL, 0);
267 return true;
268 }
269
270 static bool HandleWpEventCommand(ChatHandler* handler, const char* args)
271 {
272 if (!*args)
273 return false;
274
275 char* show_str = strtok((char*)args, " ");
276 std::string show = show_str;
277
278 // Check
279 if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid"))
280 return false;
281
282 char* arg_id = strtok(NULL, " ");
283 uint32 id = 0;
284
285 if (show == "add")
286 {
287 if (arg_id)
288 id = atoi(arg_id);
289
290 if (id)
291 {
293 stmt->setUInt32(0, id);
294 PreparedQueryResult result = WorldDatabase.Query(stmt);
295
296 if (!result)
297 {
298 stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_SCRIPT);
299
300 stmt->setUInt32(0, id);
301
302 WorldDatabase.Execute(stmt);
303
304 handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id);
305 }
306 else
307 handler->PSendSysMessage("|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r", id);
308 }
309 else
310 {
312
313 PreparedQueryResult result = WorldDatabase.Query(stmt);
314
315 id = result->Fetch()->GetUInt32();
316
317 stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_SCRIPT);
318
319 stmt->setUInt32(0, id + 1);
320
321 WorldDatabase.Execute(stmt);
322
323 handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: |r|cff00ffff", id + 1);
324 }
325
326 return true;
327 }
328
329 if (show == "listid")
330 {
331 if (!arg_id)
332 {
333 handler->PSendSysMessage("%s%s|r", "|cff33ffff", "Wp Event: You must provide waypoint script id.");
334 return true;
335 }
336
337 id = atoi(arg_id);
338
339 uint32 a2, a3, a4, a5, a6;
340 float a8, a9, a10, a11;
341 char const* a7;
342
344 stmt->setUInt32(0, id);
345 PreparedQueryResult result = WorldDatabase.Query(stmt);
346
347 if (!result)
348 {
349 handler->PSendSysMessage("%s%s%u|r", "|cff33ffff", "Wp Event: No waypoint scripts found on id: ", id);
350 return true;
351 }
352
353 Field* fields;
354
355 do
356 {
357 fields = result->Fetch();
358 a2 = fields[0].GetUInt32();
359 a3 = fields[1].GetUInt32();
360 a4 = fields[2].GetUInt32();
361 a5 = fields[3].GetUInt32();
362 a6 = fields[4].GetUInt32();
363 a7 = fields[5].GetCString();
364 a8 = fields[6].GetFloat();
365 a9 = fields[7].GetFloat();
366 a10 = fields[8].GetFloat();
367 a11 = fields[9].GetFloat();
368
369 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);
370 } while (result->NextRow());
371 }
372
373 if (show == "del")
374 {
375 id = atoi(arg_id);
376
378
379 stmt->setUInt32(0, id);
380
381 PreparedQueryResult result = WorldDatabase.Query(stmt);
382
383 if (result)
384 {
385 stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_SCRIPT);
386
387 stmt->setUInt32(0, id);
388
389 WorldDatabase.Execute(stmt);
390
391 handler->PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: Waypoint script removed: ", id);
392 }
393 else
394 handler->PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected a non existing script: %u|r", id);
395
396 return true;
397 }
398
399 if (show == "mod")
400 {
401 if (!arg_id)
402 {
403 handler->SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
404 return true;
405 }
406
407 id = atoi(arg_id);
408
409 if (!id)
410 {
411 handler->SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r");
412 return true;
413 }
414
415 char* arg_2 = strtok(NULL, " ");
416
417 if (!arg_2)
418 {
419 handler->SendSysMessage("|cffff33ffERROR: No argument present.|r");
420 return true;
421 }
422
423 std::string arg_string = arg_2;
424
425 if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command")
426 && (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx")
427 && (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation"))
428 {
429 handler->SendSysMessage("|cffff33ffERROR: No valid argument present.|r");
430 return true;
431 }
432
433 char* arg_3;
434 std::string arg_str_2 = arg_2;
435 arg_3 = strtok(NULL, " ");
436
437 if (!arg_3)
438 {
439 handler->SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
440 return true;
441 }
442
443 if (arg_str_2 == "setid")
444 {
445 uint32 newid = atoi(arg_3);
446 handler->PSendSysMessage("%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r", "|cff00ff00", "Wp Event: Wypoint scipt guid: ", newid, " id changed: ", id);
447
449
450 stmt->setUInt32(0, newid);
451 stmt->setUInt32(1, id);
452
453 WorldDatabase.Execute(stmt);
454
455 return true;
456 }
457 else
458 {
460 stmt->setUInt32(0, id);
461 PreparedQueryResult result = WorldDatabase.Query(stmt);
462
463 if (!result)
464 {
465 handler->SendSysMessage("|cffff33ffERROR: You have selected an non existing waypoint script guid.|r");
466 return true;
467 }
468
469 if (arg_str_2 == "posx")
470 {
471 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_X);
472
473 stmt->setFloat(0, float(atof(arg_3)));
474 stmt->setUInt32(1, id);
475
476 WorldDatabase.Execute(stmt);
477
478 handler->PSendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r", id);
479 return true;
480 }
481 else if (arg_str_2 == "posy")
482 {
483 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_Y);
484
485 stmt->setFloat(0, float(atof(arg_3)));
486 stmt->setUInt32(1, id);
487
488 WorldDatabase.Execute(stmt);
489
490 handler->PSendSysMessage("|cff00ff00Waypoint script: %u position_y updated.|r", id);
491 return true;
492 }
493 else if (arg_str_2 == "posz")
494 {
495 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_Z);
496
497 stmt->setFloat(0, float(atof(arg_3)));
498 stmt->setUInt32(1, id);
499
500 WorldDatabase.Execute(stmt);
501
502 handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r", id);
503 return true;
504 }
505 else if (arg_str_2 == "orientation")
506 {
507 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_SCRIPT_O);
508
509 stmt->setFloat(0, float(atof(arg_3)));
510 stmt->setUInt32(1, id);
511
512 WorldDatabase.Execute(stmt);
513
514 handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r", id);
515 return true;
516 }
517 else if (arg_str_2 == "dataint")
518 {
519 WorldDatabase.PExecute("UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'", arg_2, atoi(arg_3), id); // Query can't be a prepared statement
520
521 handler->PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r", id);
522 return true;
523 }
524 else
525 {
526 std::string arg_str_3 = arg_3;
527 WorldDatabase.EscapeString(arg_str_3);
528 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
529 }
530 }
531 handler->PSendSysMessage("%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r", "|cff00ff00", "Waypoint script:", id, arg_2, "updated.");
532 }
533 return true;
534 }
535
536 static bool HandleWpModifyCommand(ChatHandler* handler, const char* args)
537 {
538 if (!*args)
539 return false;
540
541 // first arg: add del text emote spell waittime move
542 char* show_str = strtok((char*)args, " ");
543 if (!show_str)
544 {
545 return false;
546 }
547
548 std::string show = show_str;
549 // Check
550 // Remember: "show" must also be the name of a column!
551 if ((show != "delay") && (show != "action") && (show != "action_chance")
552 && (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")
553 )
554 {
555 return false;
556 }
557
558 // Next arg is: <PATHID> <WPNUM> <ARGUMENT>
559 char* arg_str = NULL;
560
561 // Did user provide a GUID
562 // or did the user select a creature?
563 // -> variable lowguid is filled with the GUID of the NPC
564 uint32 pathid = 0;
565 uint32 point = 0;
566 uint32 wpGuid = 0;
567 Creature* target = handler->getSelectedCreature();
568
569 if (!target || target->GetEntry() != VISUAL_WAYPOINT)
570 {
571 handler->SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
572 return false;
573 }
574
575 // The visual waypoint
576 wpGuid = target->GetGUIDLow();
577
578 // User did select a visual waypoint?
579
580 // Check the creature
582 stmt->setUInt32(0, wpGuid);
583 PreparedQueryResult result = WorldDatabase.Query(stmt);
584
585 if (!result)
586 {
588 // Select waypoint number from database
589 // Since we compare float values, we have to deal with
590 // some difficulties.
591 // Here we search for all waypoints that only differ in one from 1 thousand
592 // (0.001) - There is no other way to compare C++ floats with mySQL floats
593 // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
594 std::string maxDiff = "0.01";
595
596 stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_BY_POS);
597 stmt->setFloat(0, target->GetPositionX());
598 stmt->setString(1, maxDiff);
599 stmt->setFloat(2, target->GetPositionY());
600 stmt->setString(3, maxDiff);
601 stmt->setFloat(4, target->GetPositionZ());
602 stmt->setString(5, maxDiff);
603 result = WorldDatabase.Query(stmt);
604
605 if (!result)
606 {
608 return true;
609 }
610 }
611
612 do
613 {
614 Field* fields = result->Fetch();
615 pathid = fields[0].GetUInt32();
616 point = fields[1].GetUInt32();
617 } while (result->NextRow());
618
619 // We have the waypoint number and the GUID of the "master npc"
620 // Text is enclosed in "<>", all other arguments not
621 arg_str = strtok((char*)NULL, " ");
622
623 // Check for argument
624 if (show != "del" && show != "move" && arg_str == NULL)
625 {
626 handler->PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str);
627 return false;
628 }
629
630 if (show == "del")
631 {
632 handler->PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
633
634 if (wpGuid != 0)
635 if (Creature* wpCreature = handler->GetSession()->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)))
636 {
637 wpCreature->CombatStop();
638 wpCreature->DeleteFromDB();
639 wpCreature->AddObjectToRemoveList();
640 }
641
642 stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_WAYPOINT_DATA);
643
644 stmt->setUInt32(0, pathid);
645 stmt->setUInt32(1, point);
646
647 WorldDatabase.Execute(stmt);
648
649 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POINT);
650
651 stmt->setUInt32(0, pathid);
652 stmt->setUInt32(1, point);
653
654 WorldDatabase.Execute(stmt);
655
657 return true;
658 } // del
659
660 if (show == "move")
661 {
662 handler->PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
663
664 Player* chr = handler->GetSession()->GetPlayer();
665 Map* map = chr->GetMap();
666 {
667 // What to do:
668 // Move the visual spawnpoint
669 // Respawn the owner of the waypoints
670 if (wpGuid != 0)
671 {
672 if (Creature* wpCreature = map->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT)))
673 {
674 wpCreature->CombatStop();
675 wpCreature->DeleteFromDB();
676 wpCreature->AddObjectToRemoveList();
677 }
678 // re-create
679 Creature* wpCreature2 = new Creature;
680 if (!wpCreature2->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, VISUAL_WAYPOINT, 0, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
681 {
683 delete wpCreature2;
684 wpCreature2 = NULL;
685 return false;
686 }
687 for (auto phase : chr->GetPhases())
688 wpCreature2->SetPhased(phase, false, true);
689 wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
690 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
692 if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
693 {
695 delete wpCreature2;
696 wpCreature2 = NULL;
697 return false;
698 }
699 //sMapMgr->GetMap(npcCreature->GetMapId())->Add(wpCreature2);
700 }
701
702 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_POSITION);
703
704 stmt->setFloat(0, chr->GetPositionX());
705 stmt->setFloat(1, chr->GetPositionY());
706 stmt->setFloat(2, chr->GetPositionZ());
707 stmt->setUInt32(3, pathid);
708 stmt->setUInt32(4, point);
709
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;
728 WorldDatabase.EscapeString(text2);
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 }
735
736 static bool HandleWpShowCommand(ChatHandler* handler, const char* args)
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
752 // Did player provide a PathID?
753
754 if (!guid_str)
755 {
756 // No PathID provided
757 // -> Player must have selected a creature
758
759 if (!target)
760 {
762 handler->SetSentErrorMessage(true);
763 return false;
764 }
765
766 pathid = target->GetWaypointPath();
767 }
768 else
769 {
770 // PathID provided
771 // Warn if player also selected a creature
772 // -> Creature selection is ignored <-
773 if (target)
775
776 pathid = atoi((char*)guid_str);
777 }
778
779 std::string show = show_str;
780
781 //handler->PSendSysMessage("wpshow - show: %s", show);
782
783 // Show info for the selected waypoint
784 if (show == "info")
785 {
786 // Check if the user did specify a visual waypoint
787 if (!target || target->GetEntry() != VISUAL_WAYPOINT)
788 {
790 handler->SetSentErrorMessage(true);
791 return false;
792 }
793
795
796 stmt->setUInt32(0, target->GetGUIDLow());
797
798 PreparedQueryResult result = WorldDatabase.Query(stmt);
799
800 if (!result)
801 {
803 return true;
804 }
805
806 handler->SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
807 do
808 {
809 Field* fields = result->Fetch();
810 pathid = fields[0].GetUInt32();
811 uint32 point = fields[1].GetUInt32();
812 uint32 delay = fields[2].GetUInt32();
813 uint32 flag = fields[3].GetUInt32();
814 uint32 ev_id = fields[4].GetUInt32();
815 uint32 ev_chance = fields[5].GetUInt32();
816
817 handler->PSendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid);
818 handler->PSendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay);
819 handler->PSendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag);
820 handler->PSendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id);
821 handler->PSendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance);
822 } while (result->NextRow());
823
824 return true;
825 }
826
827 if (show == "on")
828 {
830
831 stmt->setUInt32(0, pathid);
832
833 PreparedQueryResult result = WorldDatabase.Query(stmt);
834
835 if (!result)
836 {
837 handler->SendSysMessage("|cffff33ffPath no found.|r");
838 handler->SetSentErrorMessage(true);
839 return false;
840 }
841
842 handler->PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
843
844 // Delete all visuals for this NPC
845 stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_DATA_WPGUID_BY_ID);
846
847 stmt->setUInt32(0, pathid);
848
849 PreparedQueryResult result2 = WorldDatabase.Query(stmt);
850
851 if (result2)
852 {
853 bool hasError = false;
854 do
855 {
856 Field* fields = result2->Fetch();
857 uint32 wpguid = fields[0].GetUInt32();
859
860 if (!creature)
861 {
863 hasError = true;
864
865 stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE);
866
867 stmt->setUInt32(0, wpguid);
868
869 WorldDatabase.Execute(stmt);
870 }
871 else
872 {
873 creature->CombatStop();
874 creature->DeleteFromDB();
875 creature->AddObjectToRemoveList();
876 }
877 } while (result2->NextRow());
878
879 if (hasError)
880 {
884 }
885 }
886
887 do
888 {
889 Field* fields = result->Fetch();
890 uint32 point = fields[0].GetUInt32();
891 float x = fields[1].GetFloat();
892 float y = fields[2].GetFloat();
893 float z = fields[3].GetFloat();
894
896
897 Player* chr = handler->GetSession()->GetPlayer();
898 Map* map = chr->GetMap();
899 float o = chr->GetOrientation();
900
901 Creature* wpCreature = new Creature;
902 if (!wpCreature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, 0, x, y, z, o))
903 {
905 delete wpCreature;
906 return false;
907 }
908 for (auto phase : chr->GetPhases())
909 wpCreature->SetPhased(phase, false, true);
910 // Set "wpguid" column to the visual waypoint
911 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_WPGUID);
912
913 stmt->setInt32(0, int32(wpCreature->GetGUIDLow()));
914 stmt->setUInt32(1, pathid);
915 stmt->setUInt32(2, point);
916
917 WorldDatabase.Execute(stmt);
918
919 wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
920 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
921 if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
922 {
924 delete wpCreature;
925 return false;
926 }
927
928 if (target)
929 {
930 wpCreature->SetDisplayId(target->GetDisplayId());
931 wpCreature->SetObjectScale(0.5f);
932 wpCreature->SetLevel(std::min<uint32>(point, STRONG_MAX_LEVEL));
933 }
934 } while (result->NextRow());
935
936 handler->SendSysMessage("|cff00ff00Showing the current creature's path.|r");
937 return true;
938 }
939
940 if (show == "first")
941 {
942 handler->PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
943
945 stmt->setUInt32(0, pathid);
946 PreparedQueryResult result = WorldDatabase.Query(stmt);
947
948 if (!result)
949 {
950 handler->PSendSysMessage(LANG_WAYPOINT_NOTFOUND, pathid);
951 handler->SetSentErrorMessage(true);
952 return false;
953 }
954
955 Field* fields = result->Fetch();
956 float x = fields[0].GetFloat();
957 float y = fields[1].GetFloat();
958 float z = fields[2].GetFloat();
960
961 Player* chr = handler->GetSession()->GetPlayer();
962 float o = chr->GetOrientation();
963 Map* map = chr->GetMap();
964
965 Creature* creature = new Creature;
966 if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, 0, x, y, z, o))
967 {
969 delete creature;
970 return false;
971 }
972
973 for (auto phase : chr->GetPhases())
974 creature->SetPhased(phase, false, true);
975
976 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
977 if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
978 {
980 delete creature;
981 return false;
982 }
983
984 if (target)
985 {
986 creature->SetDisplayId(target->GetDisplayId());
987 creature->SetObjectScale(0.5f);
988 }
989
990 return true;
991 }
992
993 if (show == "last")
994 {
995 handler->PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
996
998 stmt->setUInt32(0, pathid);
999 PreparedQueryResult result = WorldDatabase.Query(stmt);
1000
1001 if (!result)
1002 {
1004 handler->SetSentErrorMessage(true);
1005 return false;
1006 }
1007 Field* fields = result->Fetch();
1008 float x = fields[0].GetFloat();
1009 float y = fields[1].GetFloat();
1010 float z = fields[2].GetFloat();
1011 float o = fields[3].GetFloat();
1013
1014 Player* chr = handler->GetSession()->GetPlayer();
1015 Map* map = chr->GetMap();
1016
1017 Creature* creature = new Creature;
1018 if (!creature->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, 0, x, y, z, o))
1019 {
1021 delete creature;
1022 return false;
1023 }
1024
1025 for (auto phase : chr->GetPhases())
1026 creature->SetPhased(phase, false, true);
1027
1028 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
1029 if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
1030 {
1032 delete creature;
1033 return false;
1034 }
1035
1036 if (target)
1037 {
1038 creature->SetDisplayId(target->GetDisplayId());
1039 creature->SetObjectScale(0.5f);
1040 }
1041
1042 return true;
1043 }
1044
1045 if (show == "off")
1046 {
1047 PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_BY_ID);
1048 stmt->setUInt32(0, 1);
1049 PreparedQueryResult result = WorldDatabase.Query(stmt);
1050
1051 if (!result)
1052 {
1054 handler->SetSentErrorMessage(true);
1055 return false;
1056 }
1057 bool hasError = false;
1058 do
1059 {
1060 Field* fields = result->Fetch();
1061 uint32 guid = fields[0].GetUInt32();
1063 if (!creature)
1064 {
1066 hasError = true;
1067
1068 stmt = WorldDatabase.GetPreparedStatement(WORLD_DEL_CREATURE);
1069
1070 stmt->setUInt32(0, guid);
1071
1072 WorldDatabase.Execute(stmt);
1073 }
1074 else
1075 {
1076 creature->CombatStop();
1077 creature->DeleteFromDB();
1078 creature->AddObjectToRemoveList();
1079 }
1080 } while (result->NextRow());
1081 // set "wpguid" column to "empty" - no visual waypoint spawned
1082 stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_WAYPOINT_DATA_ALL_WPGUID);
1083
1084 WorldDatabase.Execute(stmt);
1085 //WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
1086
1087 if (hasError)
1088 {
1092 }
1093
1095 return true;
1096 }
1097
1098 handler->PSendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
1099 return true;
1100 }
1101};
1102
1104{
1105 new wp_commandscript();
1106}
@ STRONG_MAX_LEVEL
Definition DBCEnums.h:24
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define OVERRIDE
Definition Define.h:60
@ LANG_WAYPOINT_TOOFAR2
Definition Language.h:247
@ LANG_WAYPOINT_REMOVED
Definition Language.h:244
@ LANG_SELECT_CREATURE
Definition Language.h:13
@ LANG_WAYPOINT_CHANGED
Definition Language.h:239
@ LANG_WAYPOINT_CHANGED_NO
Definition Language.h:240
@ LANG_WAYPOINT_ARGUMENTREQ
Definition Language.h:236
@ LANG_WAYPOINT_VP_NOTFOUND
Definition Language.h:230
@ LANG_WAYPOINT_NOTFOUNDLAST
Definition Language.h:224
@ LANG_WAYPOINT_VP_NOTCREATED
Definition Language.h:231
@ LANG_WAYPOINT_NOTREMOVED
Definition Language.h:245
@ LANG_WAYPOINT_NOTFOUNDDBPROBLEM
Definition Language.h:226
@ LANG_WAYPOINT_NOTFOUND
Definition Language.h:223
@ LANG_WAYPOINT_NOTFOUNDSEARCH
Definition Language.h:225
@ LANG_WAYPOINT_NOTCREATED
Definition Language.h:233
@ LANG_WAYPOINT_CREATSELECTED
Definition Language.h:227
@ LANG_WAYPOINT_VP_ALLREMOVED
Definition Language.h:232
@ LANG_WAYPOINT_TOOFAR1
Definition Language.h:246
@ LANG_WAYPOINT_VP_SELECT
Definition Language.h:229
@ LANG_WAYPOINT_TOOFAR3
Definition Language.h:248
@ IDLE_MOTION_TYPE
@ WAYPOINT_MOTION_TYPE
#define VISUAL_WAYPOINT
@ HIGHGUID_UNIT
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
#define sObjectMgr
Definition ObjectMgr.h:1617
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
#define sWaypointMgr
@ WORLD_SEL_WAYPOINT_DATA_POS_LAST_BY_ID
@ WORLD_SEL_WAYPOINT_DATA_BY_WPGUID
@ WORLD_DEL_WAYPOINT_DATA
@ WORLD_UPD_WAYPOINT_SCRIPT_O
@ WORLD_INS_WAYPOINT_DATA
@ WORLD_SEL_WAYPOINT_DATA_POS_FIRST_BY_ID
@ WORLD_INS_CREATURE_ADDON
@ WORLD_SEL_CREATURE_ADDON_BY_GUID
@ WORLD_UPD_WAYPOINT_DATA_POINT
@ WORLD_UPD_WAYPOINT_SCRIPT_Z
@ WORLD_UPD_WAYPOINT_DATA_POSITION
@ WORLD_UPD_CREATURE_MOVEMENT_TYPE
@ WORLD_SEL_WAYPOINT_DATA_BY_POS
@ WORLD_UPD_CREATURE_ADDON_PATH
@ WORLD_DEL_CREATURE_ADDON
@ WORLD_UPD_WAYPOINT_SCRIPT_X
@ WORLD_INS_WAYPOINT_SCRIPT
@ WORLD_SEL_WAYPOINT_DATA_POS_BY_ID
@ WORLD_SEL_CREATURE_BY_ID
@ WORLD_DEL_WAYPOINT_SCRIPT
@ WORLD_SEL_WAYPOINT_DATA_WPGUID_BY_ID
@ WORLD_SEL_WAYPOINT_SCRIPTS_MAX_ID
@ WORLD_SEL_WAYPOINT_DATA_ALL_BY_WPGUID
@ WORLD_UPD_WAYPOINT_DATA_WPGUID
@ WORLD_DEL_CREATURE
@ WORLD_SEL_WAYPOINT_SCRIPT_BY_ID
@ WORLD_UPD_WAYPOINT_DATA_ALL_WPGUID
@ WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID
@ WORLD_SEL_WAYPOINT_DATA_MAX_ID
@ WORLD_SEL_WAYPOINT_DATA_MAX_POINT
@ WORLD_UPD_WAYPOINT_SCRIPT_Y
@ WORLD_UPD_WAYPOINT_SCRIPT_ID
WorldSession * GetSession()
Definition Chat.h:43
Creature * getSelectedCreature()
Definition Chat.cpp:865
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
void SetSentErrorMessage(bool val)
Definition Chat.h:114
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
CommandScript(const char *name)
uint32 GetDBTableGUIDLow() const
Definition Creature.h:445
virtual void DeleteFromDB()
uint32 GetWaypointPath() const
Definition Creature.h:636
void SetDisplayId(uint32 modelId) OVERRIDE
void UpdateWaypointID(uint32 wpID)
Definition Creature.h:640
void SetObjectScale(float scale) OVERRIDE
bool Create(uint32 guidlow, Map *map, uint32 Entry, uint32 vehId, uint32 team, float x, float y, float z, float ang, const CreatureData *data=NULL)
Definition Creature.cpp:740
void SaveToDB()
Definition Creature.cpp:934
bool LoadCreatureFromDB(uint32 guid, Map *map, bool addToMap=true)
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition Creature.h:590
void LoadPath(uint32 pathid)
Definition Creature.h:637
Definition Field.h:16
char const * GetCString() const
Definition Field.h:213
float GetFloat() const
Definition Field.h:177
uint32 GetUInt32() const
Definition Field.h:105
Definition Map.h:238
uint8 GetSpawnMode() const
Definition Map.h:358
Creature * GetCreature(uint64 guid)
Definition Map.cpp:3179
uint32 GetId(void) const
Definition Map.h:300
void MoveTargetedHome()
uint32 GetGUIDLow() const
Definition Object.h:120
uint32 GetEntry() const
Definition Object.h:125
void setFloat(const uint8 index, const float value)
void setString(const uint8 index, const std::string &value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
void setInt32(const uint8 index, const int32 value)
void CombatStop(bool includingCast=false)
bool SetPhased(uint32 id, bool update, bool apply) OVERRIDE
Definition Unit.cpp:7516
MotionMaster * GetMotionMaster()
Definition Unit.h:2605
uint32 GetDisplayId() const
Definition Unit.h:2490
void SetLevel(uint8 lvl)
Definition Unit.cpp:5150
Map * GetMap() const
Definition Object.h:740
std::set< uint32 > const & GetPhases() const
Definition Object.h:647
void AddObjectToRemoveList()
Definition Object.cpp:2550
void MonsterSay(const char *text, Language language, WorldObject const *target)
Definition Object.cpp:2383
Player * GetPlayer() const
static bool HandleWpEventCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:270
static bool HandleWpLoadCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:127
static bool HandleWpReloadCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:208
static bool HandleWpModifyCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:536
static bool HandleWpUnLoadCommand(ChatHandler *handler, const char *)
Definition cs_wp.cpp:223
static bool HandleWpShowCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:736
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition cs_wp.cpp:25
static bool HandleWpAddCommand(ChatHandler *handler, const char *args)
Definition cs_wp.cpp:64
void AddSC_wp_commandscript()
Definition cs_wp.cpp:1103
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
@ RBAC_PERM_COMMAND_WP_SHOW
Definition RBAC.h:662
@ RBAC_PERM_COMMAND_WP_MODIFY
Definition RBAC.h:659
@ RBAC_PERM_COMMAND_WP_UNLOAD
Definition RBAC.h:660
@ RBAC_PERM_COMMAND_WP_LOAD
Definition RBAC.h:658
@ RBAC_PERM_COMMAND_WP_ADD
Definition RBAC.h:656
@ RBAC_PERM_COMMAND_WP
Definition RBAC.h:655
@ RBAC_PERM_COMMAND_WP_EVENT
Definition RBAC.h:657
@ RBAC_PERM_COMMAND_WP_RELOAD
Definition RBAC.h:661
uint32 path_id
Definition Creature.h:325
float GetPositionZ() const
Definition Object.h:330
float GetOrientation() const
Definition Object.h:331
float GetPositionX() const
Definition Object.h:328
float GetPositionY() const
Definition Object.h:329