diff --git a/sql/migrations/20180505221750_world.sql b/sql/migrations/20180505221750_world.sql new file mode 100644 index 000000000..e5771cbde --- /dev/null +++ b/sql/migrations/20180505221750_world.sql @@ -0,0 +1,110 @@ +DROP PROCEDURE IF EXISTS add_migration; +delimiter ?? +CREATE PROCEDURE `add_migration`() +BEGIN +DECLARE v INT DEFAULT 1; +SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20180505221750'); +IF v=0 THEN +INSERT INTO `migrations` VALUES ('20180505221750'); +-- Add your query below. + + +-- Update waypoint command texts. +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (220, 'Cannot find waypoint id %u for %s (in path %i, loaded from %s)', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (221, 'Last Waypoint not found for %s', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (222, '%s has no path or path empty, path-id %i (loaded from %s)', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (223, 'Creature (GUID: %u) No waypoints found - This is a MaNGOS db problem (single float).', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (224, 'Cannot access %s on map, maybe you are too far away from its spawn location', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (225, 'Creature (GUID: %u) not found', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (226, 'You must select a visual waypoint.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (227, 'No visual waypoints found', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (228, 'Could not create visual waypoint with creatureID: %d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (229, 'All visual waypoints removed', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (230, 'Could not add waypoint %u to %s (pathId %i stored by %s)', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (231, 'No GUID provided.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (232, 'No waypoint number provided.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (233, 'Argument required for \'%s\'.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (234, 'Added Waypoint %u to %s (PathId %i, path stored by %s)', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (235, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (236, 'Waypoint changed.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (237, 'Waypoint %s modified.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (238, 'WP export successfull.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (239, 'No waypoints found inside the database.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (240, 'File imported.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (241, 'Waypoint removed.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (242, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (243, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (244, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (245, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (246, 'Waypoint %u for %s (from pathId %i, stored by %s)', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (247, ' Waittime: %d', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (248, ' Orientation: %f', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (249, ' ScriptId: %u', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (250, 'ScriptID set to non-existing id %u, add it to DBScriptsEngine and reload the table.', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (251, 'UNUSED', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); +REPLACE INTO `mangos_string` (`entry`, `content_default`, `content_loc1`, `content_loc2`, `content_loc3`, `content_loc4`, `content_loc5`, `content_loc6`, `content_loc7`, `content_loc8`) VALUES (252, 'AIScriptName: %s', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + +-- This column is unused. +ALTER TABLE `creature_movement` + DROP COLUMN `wpguid`; +ALTER TABLE `creature_movement_template` + DROP COLUMN `wpguid`; + +-- Add new table for special waypoints. +CREATE TABLE IF NOT EXISTS `creature_movement_special` ( + `id` int(10) unsigned NOT NULL, + `point` mediumint(8) unsigned NOT NULL DEFAULT '0', + `position_x` float NOT NULL DEFAULT '0', + `position_y` float NOT NULL DEFAULT '0', + `position_z` float NOT NULL DEFAULT '0', + `waittime` int(10) unsigned NOT NULL DEFAULT '0', + `script_id` mediumint(8) unsigned NOT NULL DEFAULT '0', + `textid1` int(11) NOT NULL DEFAULT '0', + `textid2` int(11) NOT NULL DEFAULT '0', + `textid3` int(11) NOT NULL DEFAULT '0', + `textid4` int(11) NOT NULL DEFAULT '0', + `textid5` int(11) NOT NULL DEFAULT '0', + `emote` mediumint(8) unsigned NOT NULL DEFAULT '0', + `spell` mediumint(8) unsigned NOT NULL DEFAULT '0', + `orientation` float NOT NULL DEFAULT '0', + `model1` mediumint(9) NOT NULL DEFAULT '0', + `model2` mediumint(9) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`,`point`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Creature System'; + +-- Fix current waypoint for some npcs. +UPDATE `creature` SET `currentwaypoint`=0 WHERE `currentwaypoint`=1; +UPDATE `creature` SET `currentwaypoint`=24 WHERE `guid`=32905; +UPDATE `creature` SET `currentwaypoint`=2 WHERE `guid`=88303; + +-- Fix errors in script for mobs in naxxramas. +UPDATE `creature_movement` SET `script_id`=8844402 WHERE `id`=88444 && `point`=2; +DELETE FROM `creature_movement_scripts` WHERE `id`=8844402; +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 0, 1, 19, 0, 0, 0, 16157, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Doom Touched warrior chicken'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 1, 1, 36, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain attacks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 2, 1, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight parries'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 5, 1, 1, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain talks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 7, 1, 36, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain attacks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 8, 1, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight parries'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 10, 1, 15, 0, 0, 0, 16158, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Dark Touched warrior roar'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 14, 1, 60, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain kicks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 15, 1, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight parries'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 17, 1, 36, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain attacks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 18, 1, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight parries'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 20, 1, 5, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain shouts'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 22, 1, 36, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain attacks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 23, 1, 21, 0, 0, 0, 16157, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Doom Touched warrior applaude'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 23, 1, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight parries'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 26, 1, 60, 0, 0, 0, 16145, 10, 8, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight captain kicks'); +INSERT INTO `creature_movement_scripts` (`id`, `delay`, `command`, `datalong`, `datalong2`, `datalong3`, `datalong4`, `target_param1`, `target_param2`, `target_type`, `data_flags`, `dataint`, `dataint2`, `dataint3`, `dataint4`, `x`, `y`, `z`, `o`, `condition_id`, `comments`) VALUES (8844402, 27, 1, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'Deathknight attacks'); + +-- This guy should have waypoint movement. +UPDATE `creature` SET `MovementType`=2 WHERE `guid`=1816; + + +-- End of migration. +END IF; +END?? +delimiter ; +CALL add_migration(); +DROP PROCEDURE IF EXISTS add_migration; diff --git a/src/game/AI/CreatureEventAIMgr.cpp b/src/game/AI/CreatureEventAIMgr.cpp index 9288ebaf3..d52809e9a 100644 --- a/src/game/AI/CreatureEventAIMgr.cpp +++ b/src/game/AI/CreatureEventAIMgr.cpp @@ -269,7 +269,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Events() } case EVENT_T_MOVEMENT_INFORM: { - if (temp.move_inform.motionType > CHARGE_MOTION_TYPE) + if ((temp.move_inform.motionType > CHARGE_MOTION_TYPE) && (temp.move_inform.motionType < WAYPOINT_SPECIAL_REACHED)) sLog.outErrorDb("CreatureEventAI: Creature %u is using an invalid motion type. Event %u will never trigger! ", temp.creature_id, i); if (temp.move_inform.repeatMax < temp.move_inform.repeatMin) sLog.outErrorDb("CreatureEventAI: Creature %u are using repeatable event(%u) with param4 < param3 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index ae52ac253..4a7929614 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -505,7 +505,6 @@ ChatCommand * ChatHandler::getCommandTable() { { NODE, "add", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddCommand, "", nullptr }, { NODE, "additem", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddVendorItemCommand, "", nullptr }, - { NODE, "addmove", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAddMoveCommand, "", nullptr }, { NODE, "aiinfo", SEC_GAMEMASTER, false, &ChatHandler::HandleNpcAIInfoCommand, "", nullptr }, { NODE, "allowmove", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcAllowMovementCommand, "", nullptr }, { NODE, "changeentry", SEC_ADMINISTRATOR, false, &ChatHandler::HandleNpcChangeEntryCommand, "", nullptr }, @@ -822,7 +821,6 @@ ChatCommand * ChatHandler::getCommandTable() { NODE, "add", SEC_GAMEMASTER, false, &ChatHandler::HandleWpAddCommand, "", nullptr }, { NODE, "modify", SEC_GAMEMASTER, false, &ChatHandler::HandleWpModifyCommand, "", nullptr }, { NODE, "export", SEC_ADMINISTRATOR, false, &ChatHandler::HandleWpExportCommand, "", nullptr }, - { NODE, "import", SEC_ADMINISTRATOR, false, &ChatHandler::HandleWpImportCommand, "", nullptr }, { MSTR, nullptr, 0, false, nullptr, "", nullptr } }; diff --git a/src/game/Chat/Chat.h b/src/game/Chat/Chat.h index f92d119da..434fc00b2 100644 --- a/src/game/Chat/Chat.h +++ b/src/game/Chat/Chat.h @@ -588,7 +588,6 @@ class MANGOS_DLL_SPEC ChatHandler //-----------------------Npc Commands----------------------- bool HandleNpcAddCommand(char* args); bool HandleNpcSummonCommand(char* args); - bool HandleNpcAddMoveCommand(char* args); bool HandleNpcAddVendorItemCommand(char* args); bool HandleNpcAIInfoCommand(char* args); bool HandleNpcAllowMovementCommand(char* args); @@ -770,7 +769,6 @@ class MANGOS_DLL_SPEC ChatHandler bool HandleWpModifyCommand(char* args); bool HandleWpShowCommand(char* args); bool HandleWpExportCommand(char* args); - bool HandleWpImportCommand(char* args); bool HandleHelpCommand(char* args); bool HandleCommandsCommand(char* args); diff --git a/src/game/Commands/Level2.cpp b/src/game/Commands/Level2.cpp index ec2f60834..04aa811bf 100644 --- a/src/game/Commands/Level2.cpp +++ b/src/game/Commands/Level2.cpp @@ -50,6 +50,7 @@ #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "CellImpl.h" +#include "WaypointMovementGenerator.h" #include #include #include @@ -1712,57 +1713,6 @@ bool ChatHandler::HandleNpcAIInfoCommand(char* /*args*/) return true; } -//add move for creature -bool ChatHandler::HandleNpcAddMoveCommand(char* args) -{ - uint32 lowguid; - if (!ExtractUint32KeyFromLink(&args, "Hcreature", lowguid)) - return false; - - uint32 wait; - if (!ExtractOptUInt32(&args, wait, 0)) - return false; - - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - - Player* player = m_session->GetPlayer(); - - if (player->GetMapId() != data->mapid) - { - PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, lowguid); - SetSentErrorMessage(true); - return false; - } - - Creature* pCreature = player->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - - sWaypointMgr.AddLastNode(lowguid, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), wait, 0); - - // update movement type - WorldDatabase.PExecuteLog("UPDATE creature SET MovementType=%u WHERE guid=%u", WAYPOINT_MOTION_TYPE, lowguid); - if (pCreature) - { - pCreature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); - pCreature->GetMotionMaster()->Initialize(); - if (pCreature->isAlive()) // dead creature will reset movement generator at respawn - { - pCreature->SetDeathState(JUST_DIED); - pCreature->Respawn(); - } - pCreature->SaveToDB(); - } - - SendSysMessage(LANG_WAYPOINT_ADDED); - - return true; -} - //change level of creature or pet bool ChatHandler::HandleNpcChangeLevelCommand(char* args) { @@ -2547,25 +2497,63 @@ bool ChatHandler::HandlePInfoCommand(char* args) return true; } +/// Helper function +inline Creature* Helper_CreateWaypointFor(Creature* wpOwner, WaypointPathOrigin wpOrigin, int32 pathId, uint32 wpId, WaypointNode const* wpNode, CreatureInfo const* waypointInfo) +{ + TemporarySummonWaypoint* wpCreature = new TemporarySummonWaypoint(wpOwner->GetObjectGuid(), wpId, pathId, (uint32)wpOrigin); -/** - * Add a waypoint to a creature. + CreatureCreatePos pos(wpOwner->GetMap(), wpNode->x, wpNode->y, wpNode->z, wpNode->orientation != 100.0f ? wpNode->orientation : 0.0f); + + if (!wpCreature->Create(wpOwner->GetMap()->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) + { + delete wpCreature; + return NULL; + } + + wpCreature->SetVisibility(VISIBILITY_OFF); + wpCreature->SetSummonPoint(pos); + + wpCreature->SetActiveObjectState(true); + + wpCreature->Summon(TEMPSUMMON_TIMED_DESPAWN, 5 * MINUTE * IN_MILLISECONDS); // Also initializes the AI and MMGen + return wpCreature; +} +inline void UnsummonVisualWaypoints(Player const* player, ObjectGuid ownerGuid) +{ + std::list waypoints; + MaNGOS::AllCreaturesOfEntryInRange checkerForWaypoint(player, VISUAL_WAYPOINT, SIZE_OF_GRIDS); + MaNGOS::CreatureListSearcher searcher(waypoints, checkerForWaypoint); + Cell::VisitGridObjects(player, searcher, SIZE_OF_GRIDS); + + for (std::list::iterator itr = waypoints.begin(); itr != waypoints.end(); ++itr) + { + if ((*itr)->GetSubtype() != CREATURE_SUBTYPE_TEMPORARY_SUMMON) + continue; + + TemporarySummonWaypoint* wpTarget = dynamic_cast(*itr); + if (!wpTarget) + continue; + + if (wpTarget->GetSummonerGuid() == ownerGuid) + wpTarget->UnSummon(); + } +} + +/** Add a waypoint to a creature + * .wp add [dbGuid] [pathId] [source] * - * The user can either select an npc or provide its GUID. + * The user can either select an npc or provide its dbGuid. + * Also the user can specify pathId and source if wanted. * * 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 [pathId] [source] + * -> adds a waypoint to the currently selected creature, to path pathId in source-storage * - * .wp add - * -> adds a waypoint to the currently selected creature - * - * - * @param args if the user did not provide a GUID, it is NULL + * .wp add guid [pathId] [source] + * -> if no npc is selected, expect the creature provided with guid argument * * @return true - command did succeed, false - something went wrong */ @@ -2573,976 +2561,713 @@ bool ChatHandler::HandleWpAddCommand(char* args) { DEBUG_LOG("DEBUG: HandleWpAddCommand"); - // optional - char* guid_str = NULL; + CreatureInfo const* waypointInfo = ObjectMgr::GetCreatureTemplate(VISUAL_WAYPOINT); + if (!waypointInfo || waypointInfo->GetHighGuid() != HIGHGUID_UNIT) + return false; // must exist as normal creature in mangos.sql 'creature_template' - if (*args) - guid_str = strtok(args, " "); + Creature* targetCreature = getSelectedCreature(); + WaypointPathOrigin wpDestination = PATH_NO_PATH; ///< into which storage + int32 wpPathId = 0; ///< along which path + uint32 wpPointId = 0; ///< pointId if a waypoint was selected, in this case insert after + Creature* wpOwner; - uint32 lowguid = 0; - uint32 point = 0; - Creature* target = getSelectedCreature(); - // Did player provide a GUID? - if (!guid_str) + if (targetCreature) { - DEBUG_LOG("DEBUG: HandleWpAddCommand - No GUID provided"); - - // No GUID provided - // -> Player must have selected a creature - - if (!target || !target->HasStaticDBSpawnData()) + // Check if the user did specify a visual waypoint + if (targetCreature->GetEntry() == VISUAL_WAYPOINT && targetCreature->GetSubtype() == CREATURE_SUBTYPE_TEMPORARY_SUMMON) { - SendSysMessage(LANG_SELECT_CREATURE); + TemporarySummonWaypoint* wpTarget = dynamic_cast(targetCreature); + if (!wpTarget) + { + PSendSysMessage(LANG_WAYPOINT_VP_SELECT); + SetSentErrorMessage(true); + return false; + } + + // Who moves along this waypoint? + wpOwner = targetCreature->GetMap()->GetAnyTypeCreature(wpTarget->GetSummonerGuid()); + if (!wpOwner) + { + PSendSysMessage(LANG_WAYPOINT_NOTFOUND_NPC, wpTarget->GetSummonerGuid().GetString().c_str()); + SetSentErrorMessage(true); + return false; + } + wpDestination = (WaypointPathOrigin)wpTarget->GetPathOrigin(); + wpPathId = wpTarget->GetPathId(); + wpPointId = wpTarget->GetWaypointId() + 1; // Insert as next waypoint + } + else // normal creature selected + wpOwner = targetCreature; + } + else //!targetCreature - first argument must be dbGuid + { + uint32 dbGuid; + if (!ExtractUInt32(&args, dbGuid)) + { + PSendSysMessage(LANG_WAYPOINT_NOGUID); SetSentErrorMessage(true); return false; } - if (target->GetEntry() == VISUAL_WAYPOINT) - { - DEBUG_LOG("DEBUG: HandleWpAddCommand - target->GetEntry() == VISUAL_WAYPOINT (1) "); - - QueryResult *result = - WorldDatabase.PQuery("SELECT id, point FROM creature_movement WHERE wpguid = %u", - target->GetGUIDLow()); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetGUIDLow()); - // User selected a visual spawnpoint -> get the NPC - // Select NPC GUID - // Since we compare float values, we have to deal with - // some difficulties. - // Here we search for all waypoints that only differ in one from 1 thousand - // (0.001) - There is no other way to compare C++ floats with mySQL floats - // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html - const char* maxDIFF = "0.01"; - result = WorldDatabase.PQuery("SELECT id, point FROM creature_movement WHERE (abs(position_x - %f) <= %s ) and (abs(position_y - %f) <= %s ) and (abs(position_z - %f) <= %s )", - target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, target->GetGUIDLow()); - SetSentErrorMessage(true); - return false; - } - } - do - { - Field *fields = result->Fetch(); - lowguid = fields[0].GetUInt32(); - point = fields[1].GetUInt32(); - } - while (result->NextRow()); - delete result; - - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - - target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - if (!target) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, lowguid); - SetSentErrorMessage(true); - return false; - } - } - else - lowguid = target->GetGUIDLow(); - } - else - { - DEBUG_LOG("DEBUG: HandleWpAddCommand - GUID provided"); - - // GUID provided - // Warn if player also selected a creature - // -> Creature selection is ignored <- - if (target) - SendSysMessage(LANG_WAYPOINT_CREATSELECTED); - lowguid = atoi((char*)guid_str); - - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); + CreatureData const* data = sObjectMgr.GetCreatureData(dbGuid); if (!data) { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); SetSentErrorMessage(true); return false; } - target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - if (!target || target->IsPet()) + if (m_session->GetPlayer()->GetMapId() != data->mapid) { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); + PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, dbGuid); + SetSentErrorMessage(true); + return false; + } + + wpOwner = m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(data->GetObjectGuid(dbGuid)); + if (!wpOwner) + { + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); SetSentErrorMessage(true); return false; } } - // lowguid -> GUID of the NPC - // point -> number of the waypoint (if not 0) - DEBUG_LOG("DEBUG: HandleWpAddCommand - danach"); - DEBUG_LOG("DEBUG: HandleWpAddCommand - point == 0"); - - Player* player = m_session->GetPlayer(); - sWaypointMgr.AddLastNode(lowguid, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetOrientation(), 0, 0); - - // update movement type - if (target) + if (wpDestination == PATH_NO_PATH) // No Waypoint selected, parse additional params { - target->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); - target->GetMotionMaster()->Initialize(); - if (target->isAlive()) // dead creature will reset movement generator at respawn + if (ExtractOptInt32(&args, wpPathId, 0)) // Fill path-id and source { - target->SetDeathState(JUST_DIED); - target->Respawn(); + uint32 src = (uint32)PATH_NO_PATH; + if (ExtractOptUInt32(&args, src, src)) + wpDestination = (WaypointPathOrigin)src; + else // pathId provided but no destination + { + if (wpPathId != 0) + wpDestination = PATH_FROM_ENTRY; // Multiple Paths must only be assigned by entry + } } - target->SaveToDB(); - } - else - WorldDatabase.PExecuteLog("UPDATE creature SET MovementType=%u WHERE guid=%u", WAYPOINT_MOTION_TYPE, lowguid); - PSendSysMessage(LANG_WAYPOINT_ADDED, point, lowguid); + if (wpDestination == PATH_NO_PATH) // No overwrite params. Do best estimate + { + if (wpOwner->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + if (WaypointMovementGenerator const* wpMMGen = dynamic_cast const*>(wpOwner->GetMotionMaster()->GetCurrent())) + wpMMGen->GetPathInformation(wpPathId, wpDestination); + + // Get information about default path if no current path. If no default path, prepare data dependendy on uniqueness + if (wpDestination == PATH_NO_PATH && !sWaypointMgr.GetDefaultPath(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), &wpDestination)) + { + wpDestination = PATH_FROM_ENTRY; // Default place to store paths + if (wpOwner->HasStaticDBSpawnData()) + { + QueryResult* result = WorldDatabase.PQuery("SELECT COUNT(id) FROM creature WHERE id = %u", wpOwner->GetEntry()); + if (result && result->Fetch()[0].GetUInt32() != 1) + wpDestination = PATH_FROM_GUID; + delete result; + } + } + } + } + + // All arguments parsed + // wpOwner will get a new waypoint inserted into wpPath = GetPathFromOrigin(wpOwner, wpDestination, wpPathId) at wpPointId + + float x, y, z; + m_session->GetPlayer()->GetPosition(x, y, z); + if (!sWaypointMgr.AddNode(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPointId, wpDestination, x, y, z)) + { + PSendSysMessage(LANG_WAYPOINT_NOTCREATED, wpPointId, wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpDestination).c_str()); + SetSentErrorMessage(true); + return false; + } + + // Unsummon old visuals, summon new ones + UnsummonVisualWaypoints(m_session->GetPlayer(), wpOwner->GetObjectGuid()); + WaypointPath const* wpPath = sWaypointMgr.GetPathFromOrigin(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPathId, wpDestination); + for (WaypointPath::const_iterator itr = wpPath->begin(); itr != wpPath->end(); ++itr) + { + if (!Helper_CreateWaypointFor(wpOwner, wpDestination, wpPathId, itr->first, &itr->second, waypointInfo)) + { + PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); + SetSentErrorMessage(true); + return false; + } + } + + PSendSysMessage(LANG_WAYPOINT_ADDED, wpPointId, wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpDestination).c_str()); return true; } // HandleWpAddCommand /** - * .wp modify emote | spell | text | del | move | add + * .wp modify waittime | scriptid | orientation | del | move [dbGuid, id] [value] * - * add -> add a WP after the selected visual waypoint - * User must select a visual waypoint and then issue ".wp modify add" - * - * emote + * waittime * User has selected a visual waypoint before. - * is added to this waypoint. Everytime the - * NPC comes to this waypoint, the emote is called. + * Delay is added to this waypoint. Everytime the + * NPC comes to this waypoint, it will wait Delay millieseconds. * - * emote + * waittime * User has not selected visual waypoint before. - * For the waypoint for the NPC with - * an emote is added. - * Everytime the NPC comes to this waypoint, the emote is called. + * For the waypoint for the NPC with + * an delay Delay is added to this waypoint + * Everytime the NPC comes to this waypoint, it will wait Delay millieseconds. * + * scriptid + * User has selected a visual waypoint before. + * is added to this waypoint. Everytime the + * NPC comes to this waypoint, the DBScript scriptId is executed. * - * info -> User did not select a visual waypoint and + * scriptid + * User has not selected visual waypoint before. + * For the waypoint for the NPC with + * an emote is added. + * Everytime the NPC comes to this waypoint, the DBScript scriptId is executed. + * + * orientation [DBGuid, WpNum] + * Set the orientation of the selected waypoint or waypoint given with DbGuid/ WpId + * to the value of . + * + * del [DBGuid, WpId] + * Remove the selected waypoint or waypoint given with DbGuid/ WpId. + * + * move [DBGuid, WpId] + * Move the selected waypoint or waypoint given with DbGuid/ WpId to player's current positiion. */ bool ChatHandler::HandleWpModifyCommand(char* args) { DEBUG_LOG("DEBUG: HandleWpModifyCommand"); if (!*args) - return false; + { return false; } CreatureInfo const* waypointInfo = ObjectMgr::GetCreatureTemplate(VISUAL_WAYPOINT); if (!waypointInfo || waypointInfo->GetHighGuid() != HIGHGUID_UNIT) - return false; // must exist as normal creature in mangos.sql 'creature_template' + { return false; } // must exist as normal creature in mangos.sql 'creature_template' // first arg: add del text emote spell waittime move - char* show_str = strtok(args, " "); - if (!show_str) + char* subCmd_str = ExtractLiteralArg(&args); + if (!subCmd_str) + { return false; + } - std::string show = show_str; + std::string subCmd = subCmd_str; // Check // Remember: "show" must also be the name of a column! - if ((show != "emote") && (show != "spell") && (show != "textid1") && (show != "textid2") - && (show != "textid3") && (show != "textid4") && (show != "textid5") - && (show != "waittime") && (show != "del") && (show != "move") && (show != "add") - && (show != "model1") && (show != "model2") && (show != "orientation")) + if ((subCmd != "waittime") && (subCmd != "scriptid") && (subCmd != "orientation") && (subCmd != "del") && (subCmd != "move")) + { return false; + } // Next arg is: - // Did user provide a GUID - // or did the user select a creature? - // -> variable lowguid is filled with the GUID of the NPC - uint32 lowguid = 0; - uint32 point = 0; - uint32 wpGuid = 0; - Creature* target = getSelectedCreature(); + // Did user provide a GUID or did the user select a creature? + Creature* targetCreature = getSelectedCreature(); // Expect a visual waypoint to be selected + Creature* wpOwner; // Who moves along the waypoint + uint32 wpId = 0; + WaypointPathOrigin wpSource = PATH_NO_PATH; + int32 wpPathId = 0; - if (target) + if (targetCreature) { DEBUG_LOG("DEBUG: HandleWpModifyCommand - User did select an NPC"); - // Did the user select a visual spawnpoint? - if (target->GetEntry() != VISUAL_WAYPOINT) + // Check if the user did specify a visual waypoint + if (targetCreature->GetEntry() != VISUAL_WAYPOINT || targetCreature->GetSubtype() != CREATURE_SUBTYPE_TEMPORARY_SUMMON) + { + PSendSysMessage(LANG_WAYPOINT_VP_SELECT); + SetSentErrorMessage(true); + return false; + } + TemporarySummonWaypoint* wpTarget = dynamic_cast(targetCreature); + if (!wpTarget) { PSendSysMessage(LANG_WAYPOINT_VP_SELECT); SetSentErrorMessage(true); return false; } - wpGuid = target->GetGUIDLow(); - - // The visual waypoint - QueryResult *result = - WorldDatabase.PQuery("SELECT id, point FROM creature_movement WHERE wpguid = %u LIMIT 1", - target->GetGUIDLow()); - if (!result) + // Who moves along this waypoint? + wpOwner = targetCreature->GetMap()->GetAnyTypeCreature(wpTarget->GetSummonerGuid()); + if (!wpOwner) { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, wpGuid); + PSendSysMessage(LANG_WAYPOINT_NOTFOUND_NPC, wpTarget->GetSummonerGuid().GetString().c_str()); SetSentErrorMessage(true); return false; } - DEBUG_LOG("DEBUG: HandleWpModifyCommand - After getting wpGuid"); + wpId = wpTarget->GetWaypointId(); - Field *fields = result->Fetch(); - lowguid = fields[0].GetUInt32(); - point = fields[1].GetUInt32(); - - // Cleanup memory - DEBUG_LOG("DEBUG: HandleWpModifyCommand - Cleanup memory"); - delete result; + wpPathId = wpTarget->GetPathId(); + wpSource = (WaypointPathOrigin)wpTarget->GetPathOrigin(); } else { + uint32 dbGuid = 0; // User did provide - - char* guid_str = strtok((char*)NULL, " "); - if (!guid_str) + if (!ExtractUInt32(&args, dbGuid)) { SendSysMessage(LANG_WAYPOINT_NOGUID); - return false; - } - lowguid = atoi((char*)guid_str); - - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); SetSentErrorMessage(true); return false; } - PSendSysMessage("DEBUG: GUID provided: %d", lowguid); - - char* point_str = strtok((char*)NULL, " "); - if (!point_str) + if (!ExtractUInt32(&args, wpId)) { SendSysMessage(LANG_WAYPOINT_NOWAYPOINTGIVEN); - return false; - } - point = atoi((char*)point_str); - - PSendSysMessage("DEBUG: wpNumber provided: %d", point); - - // Now we need the GUID of the visual waypoint - // -> "del", "move", "add" command - - QueryResult *result = WorldDatabase.PQuery("SELECT wpguid FROM creature_movement WHERE id = '%u' AND point = '%u' LIMIT 1", lowguid, point); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, lowguid, point); SetSentErrorMessage(true); return false; } - Field *fields = result->Fetch(); - wpGuid = fields[0].GetUInt32(); - - // Free memory - delete result; - } - - char* arg_str = NULL; - // Check for argument - if ((show != "del") && (show != "move") && (show != "add")) - { - // Text is enclosed in "<>", all other arguments not - if (show.find("text") != std::string::npos) - arg_str = strtok((char*)NULL, "<>"); - else - arg_str = strtok((char*)NULL, " "); - - if (!arg_str) + CreatureData const* data = sObjectMgr.GetCreatureData(dbGuid); + if (!data) { - PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, show_str); + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); + SetSentErrorMessage(true); + return false; + } + + wpOwner = m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(data->GetObjectGuid(dbGuid)); + if (!wpOwner) + { + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); + SetSentErrorMessage(true); return false; } } - DEBUG_LOG("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command"); - - // wpGuid -> GUID of the waypoint creature - // lowguid -> GUID of the NPC - // point -> waypoint number - - // Special functions: - // add - move - del -> no args commands - // Add a waypoint after the selected visual - if (show == "add" && target) + if (wpSource == PATH_NO_PATH) // No waypoint selected { - PSendSysMessage("DEBUG: wp modify add, GUID: %u", lowguid); + if (wpOwner->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + if (WaypointMovementGenerator const* wpMMGen = dynamic_cast const*>(wpOwner->GetMotionMaster()->GetCurrent())) + wpMMGen->GetPathInformation(wpPathId, wpSource); - // Get the creature for which we read the waypoint - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } + if (wpSource == PATH_NO_PATH) + sWaypointMgr.GetDefaultPath(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), &wpSource); + } - Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - - if (!npcCreature) - { - PSendSysMessage(LANG_WAYPOINT_NPCNOTFOUND); - SetSentErrorMessage(true); - return false; - } - - DEBUG_LOG("DEBUG: HandleWpModifyCommand - add -- npcCreature"); - - // What to do: - // Add the visual spawnpoint (DB only) - // Adjust the waypoints - // Respawn the owner of the waypoints - DEBUG_LOG("DEBUG: HandleWpModifyCommand - add"); - - Player* chr = m_session->GetPlayer(); - Map *map = chr->GetMap(); - - if (npcCreature) - { - npcCreature->GetMotionMaster()->Initialize(); - if (npcCreature->isAlive()) // dead creature will reset movement generator at respawn - { - npcCreature->SetDeathState(JUST_DIED); - npcCreature->Respawn(); - } - } - - // create the waypoint creature - wpGuid = 0; - Creature* wpCreature = new Creature; - - CreatureCreatePos pos(chr, chr->GetOrientation()); - - if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) - { - PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); - delete wpCreature; - return false; - } - - wpCreature->SaveToDB(map->GetId()); - // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); - wpCreature->LoadFromDB(wpCreature->GetGUIDLow(), map); - map->Add(wpCreature); - wpGuid = wpCreature->GetGUIDLow(); - - sWaypointMgr.AddAfterNode(lowguid, point, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), 0, 0, wpGuid); - - if (!wpGuid) - return false; - - PSendSysMessage(LANG_WAYPOINT_ADDED_NO, point + 1); - return true; - } // add - - if (show == "del" && target) + WaypointPath const* wpPath = sWaypointMgr.GetPathFromOrigin(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPathId, wpSource); + if (!wpPath) { - PSendSysMessage("DEBUG: wp modify del, GUID: %u", lowguid); - - // Get the creature for which we read the waypoint - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - - Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - - // wpCreature - Creature* wpCreature = NULL; - if (wpGuid != 0) - { - wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, VISUAL_WAYPOINT, wpGuid)); - wpCreature->DeleteFromDB(); - wpCreature->AddObjectToRemoveList(); - } - - // What to do: - // Remove the visual spawnpoint - // Adjust the waypoints - // Respawn the owner of the waypoints - - sWaypointMgr.DeleteNode(lowguid, point); - - if (npcCreature) - { - // Any waypoints left? - QueryResult *result2 = WorldDatabase.PQuery("SELECT point FROM creature_movement WHERE id = '%u'", lowguid); - if (!result2) - npcCreature->SetDefaultMovementType(RANDOM_MOTION_TYPE); - else - { - npcCreature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); - delete result2; - } - npcCreature->GetMotionMaster()->Initialize(); - if (npcCreature->isAlive()) // dead creature will reset movement generator at respawn - { - npcCreature->SetDeathState(JUST_DIED); - npcCreature->Respawn(); - } - npcCreature->SaveToDB(); - } - - PSendSysMessage(LANG_WAYPOINT_REMOVED); - return true; - } // del - - if (show == "move" && target) - { - PSendSysMessage("DEBUG: wp move, GUID: %u", lowguid); - - Player *chr = m_session->GetPlayer(); - Map *map = chr->GetMap(); - { - // Get the creature for which we read the waypoint - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - - Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - - // wpCreature - Creature* wpCreature = NULL; - // What to do: - // Move the visual spawnpoint - // Respawn the owner of the waypoints - if (wpGuid != 0) - { - wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, VISUAL_WAYPOINT, wpGuid)); - wpCreature->DeleteFromDB(); - wpCreature->AddObjectToRemoveList(); - // re-create - Creature* wpCreature2 = new Creature; - - CreatureCreatePos pos(chr, chr->GetOrientation()); - - if (!wpCreature2->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) - { - PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); - delete wpCreature2; - return false; - } - - wpCreature2->SaveToDB(map->GetId()); - // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); - wpCreature2->LoadFromDB(wpCreature2->GetGUIDLow(), map); - map->Add(wpCreature2); - //npcCreature->GetMap()->Add(wpCreature2); - } - - sWaypointMgr.SetNodePosition(lowguid, point, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ()); - - if (npcCreature) - { - npcCreature->GetMotionMaster()->Initialize(); - if (npcCreature->isAlive()) // dead creature will reset movement generator at respawn - { - npcCreature->SetDeathState(JUST_DIED); - npcCreature->Respawn(); - } - } - PSendSysMessage(LANG_WAYPOINT_CHANGED); - } - return true; - } // move - - // Create creature - npc that has the waypoint - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); - if (!data) - { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); + PSendSysMessage(LANG_WAYPOINT_NOTFOUNDPATH, wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpSource).c_str()); SetSentErrorMessage(true); return false; } - // set in game textids not supported - if (show == "textid1" || show == "textid2" || show == "textid3" || - show == "textid4" || show == "textid5") - return false; - - sWaypointMgr.SetNodeText(lowguid, point, show_str, arg_str); - - Creature* npcCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - if (npcCreature) + WaypointPath::const_iterator point = wpPath->find(wpId); + if (point == wpPath->end()) { - npcCreature->SetDefaultMovementType(WAYPOINT_MOTION_TYPE); - npcCreature->GetMotionMaster()->Initialize(); - if (npcCreature->isAlive()) // dead creature will reset movement generator at respawn + PSendSysMessage(LANG_WAYPOINT_NOTFOUND, wpId, wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpSource).c_str()); + SetSentErrorMessage(true); + return false; + } + + // If no visual WP was selected, but we are not going to remove it + if (!targetCreature && subCmd != "del") + { + targetCreature = Helper_CreateWaypointFor(wpOwner, wpSource, wpPathId, wpId, &(point->second), waypointInfo); + if (!targetCreature) { - npcCreature->SetDeathState(JUST_DIED); - npcCreature->Respawn(); + PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); + SetSentErrorMessage(true); + return false; } } - PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, show_str); + if (subCmd == "del") // Remove WP, no additional command required + { + sWaypointMgr.DeleteNode(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpId, wpPathId, wpSource); + + if (TemporarySummonWaypoint* wpCreature = dynamic_cast(targetCreature)) + wpCreature->UnSummon(); + + if (wpPath->empty()) + { + wpOwner->SetDefaultMovementType(RANDOM_MOTION_TYPE); + wpOwner->GetMotionMaster()->Initialize(); + if (wpOwner->isAlive()) // Dead creature will reset movement generator at respawn + { + wpOwner->SetDeathState(JUST_DIED); + wpOwner->Respawn(); + } + wpOwner->SaveToDB(); + } + + PSendSysMessage(LANG_WAYPOINT_REMOVED); + return true; + } + else if (subCmd == "move") // Move to player position, no additional command required + { + float x, y, z; + m_session->GetPlayer()->GetPosition(x, y, z); + + // Move visual waypoint + targetCreature->NearTeleportTo(x, y, z, targetCreature->GetOrientation()); + + sWaypointMgr.SetNodePosition(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpId, wpPathId, wpSource, x, y, z); + + PSendSysMessage(LANG_WAYPOINT_CHANGED); + return true; + } + else if (subCmd == "waittime") + { + uint32 waittime; + if (!ExtractUInt32(&args, waittime)) + return false; + + sWaypointMgr.SetNodeWaittime(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpId, wpPathId, wpSource, waittime); + } + else if (subCmd == "scriptid") + { + uint32 scriptId; + if (!ExtractUInt32(&args, scriptId)) + return false; + + if (!sWaypointMgr.SetNodeScriptId(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpId, wpPathId, wpSource, scriptId)) + PSendSysMessage(LANG_WAYPOINT_INFO_UNK_SCRIPTID, scriptId); + } + else if (subCmd == "orientation") + { + float ori; + if (!ExtractFloat(&args, ori)) + return false; + + sWaypointMgr.SetNodeOrientation(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpId, wpPathId, wpSource, ori); + } + + PSendSysMessage(LANG_WAYPOINT_CHANGED_NO, subCmd_str); return true; } /** - * .wp show info | on | off + * .wp show info | on | off | first | last [dbGuid] [pathId [wpOrigin] ] * * info -> User has selected a visual waypoint before * - * info -> User did not select a visual waypoint and - * provided the GUID of the NPC and the number of - * the waypoint. - * * on -> User has selected an NPC; all visual waypoints for this * NPC are added to the world * - * on -> User did not select an NPC - instead the GUID of the + * on -> User did not select an NPC - instead the dbGuid of the * NPC is provided. All visual waypoints for this NPC * are added from the world. * * off -> User has selected an NPC; all visual waypoints for this * NPC are removed from the world. - * - * on -> User did not select an NPC - instead the GUID of the - * NPC is provided. All visual waypoints for this NPC - * are removed from the world. - * - * */ bool ChatHandler::HandleWpShowCommand(char* args) { DEBUG_LOG("DEBUG: HandleWpShowCommand"); if (!*args) - return false; + { return false; } CreatureInfo const* waypointInfo = ObjectMgr::GetCreatureTemplate(VISUAL_WAYPOINT); if (!waypointInfo || waypointInfo->GetHighGuid() != HIGHGUID_UNIT) - return false; // must exist as normal creature in mangos.sql 'creature_template' + { return false; } // must exist as normal creature in mangos.sql 'creature_template' - // first arg: on, off, first, last - char* show_str = strtok(args, " "); - if (!show_str) + // first arg: info, on, off, first, last + + char* subCmd_str = ExtractLiteralArg(&args); + if (!subCmd_str) return false; - // second arg: GUID (optional, if a creature is selected) - char* guid_str = strtok((char*)NULL, " "); - DEBUG_LOG("DEBUG: HandleWpShowCommand: show_str: %s guid_str: %s", show_str, guid_str); - //if (!guid_str) { - // return false; - //} + std::string subCmd = subCmd_str; ///< info, on, off, first, last - // Did user provide a GUID - // or did the user select a creature? - // -> variable lowguid is filled with the GUID - Creature* target = getSelectedCreature(); - // Did player provide a GUID? - if (!guid_str) + uint32 dbGuid = 0; + int32 wpPathId = 0; + WaypointPathOrigin wpOrigin = PATH_NO_PATH; + + // User selected an npc? + Creature* targetCreature = getSelectedCreature(); + if (targetCreature) { - DEBUG_LOG("DEBUG: HandleWpShowCommand: !guid_str"); - // No GUID provided - // -> Player must have selected a creature - - if (!target) + if (ExtractOptInt32(&args, wpPathId, 0)) // Fill path-id and source { - SendSysMessage(LANG_SELECT_CREATURE); - SetSentErrorMessage(true); - return false; + uint32 src; + if (ExtractOptUInt32(&args, src, (uint32)PATH_NO_PATH)) + wpOrigin = (WaypointPathOrigin)src; } } - else + else // Guid must be provided { - DEBUG_LOG("DEBUG: HandleWpShowCommand: GUID provided"); - // GUID provided - // Warn if player also selected a creature - // -> Creature selection is ignored <- - if (target) - SendSysMessage(LANG_WAYPOINT_CREATSELECTED); + if (!ExtractUInt32(&args, dbGuid)) // No creature selected and no dbGuid provided + return false; - uint32 lowguid = atoi((char*)guid_str); + if (ExtractOptInt32(&args, wpPathId, 0)) // Fill path-id and source + { + uint32 src = (uint32)PATH_NO_PATH; + if (ExtractOptUInt32(&args, src, src)) + wpOrigin = (WaypointPathOrigin)src; + } - CreatureData const* data = sObjectMgr.GetCreatureData(lowguid); + // Params now parsed, check them + CreatureData const* data = sObjectMgr.GetCreatureData(dbGuid); if (!data) { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); SetSentErrorMessage(true); return false; } - target = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(lowguid)); - - if (!target) + targetCreature = m_session->GetPlayer()->GetMap()->GetCreature(data->GetObjectGuid(dbGuid)); + if (!targetCreature) { - PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, lowguid); + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); SetSentErrorMessage(true); return false; } } - uint32 lowguid = target->GetGUIDLow(); + Creature* wpOwner; // Npc that is moving + TemporarySummonWaypoint* wpTarget = NULL; // Define here for wp-info command - std::string show = show_str; - uint32 Maxpoint; - - DEBUG_LOG("DEBUG: HandleWpShowCommand: lowguid: %u show: %s", lowguid, show_str); - - // Show info for the selected waypoint - if (show == "info") + // Show info for the selected waypoint (Step one: get moving npc) + if (subCmd == "info") { - PSendSysMessage("DEBUG: wp info, GUID: %u", lowguid); - // Check if the user did specify a visual waypoint - if (target->GetEntry() != VISUAL_WAYPOINT) + if (targetCreature->GetEntry() != VISUAL_WAYPOINT || targetCreature->GetSubtype() != CREATURE_SUBTYPE_TEMPORARY_SUMMON) + { + PSendSysMessage(LANG_WAYPOINT_VP_SELECT); + SetSentErrorMessage(true); + return false; + } + wpTarget = dynamic_cast(targetCreature); + if (!wpTarget) { PSendSysMessage(LANG_WAYPOINT_VP_SELECT); SetSentErrorMessage(true); return false; } - //PSendSysMessage("wp on, GUID: %u", lowguid); - - //pCreature->GetPositionX(); - - QueryResult *result = - WorldDatabase.PQuery("SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE wpguid = %u", - target->GetGUIDLow()); - if (!result) + // Who moves along this waypoint? + wpOwner = targetCreature->GetMap()->GetAnyTypeCreature(wpTarget->GetSummonerGuid()); + if (!wpOwner) { - // Since we compare float values, we have to deal with - // some difficulties. - // Here we search for all waypoints that only differ in one from 1 thousand - // (0.001) - There is no other way to compare C++ floats with mySQL floats - // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html - const char* maxDIFF = "0.01"; - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH, target->GetObjectGuid().GetRawValue()); + PSendSysMessage(LANG_WAYPOINT_NOTFOUND_NPC, wpTarget->GetSummonerGuid().GetString().c_str()); + SetSentErrorMessage(true); + return false; + } - result = WorldDatabase.PQuery("SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE (abs(position_x - %f) <= %s ) and (abs(position_y - %f) <= %s ) and (abs(position_z - %f) <= %s )", - target->GetPositionX(), maxDIFF, target->GetPositionY(), maxDIFF, target->GetPositionZ(), maxDIFF); - if (!result) + // Ignore params, use information of selected waypoint! + wpOrigin = (WaypointPathOrigin)wpTarget->GetPathOrigin(); + wpPathId = wpTarget->GetPathId(); + } + else + wpOwner = targetCreature; + + // Get the path + WaypointPath* wpPath = NULL; + if (wpOrigin != PATH_NO_PATH) // Might have been provided by param + wpPath = sWaypointMgr.GetPathFromOrigin(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPathId, wpOrigin); + else + { + if (wpOwner->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + if (WaypointMovementGenerator const* wpMMGen = dynamic_cast const*>(wpOwner->GetMotionMaster()->GetCurrent())) { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, lowguid); + wpMMGen->GetPathInformation(wpPathId, wpOrigin); + wpPath = sWaypointMgr.GetPathFromOrigin(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPathId, wpOrigin); + } + + if (wpOrigin == PATH_NO_PATH) + wpPath = sWaypointMgr.GetDefaultPath(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), &wpOrigin); + } + + if (!wpPath || wpPath->empty()) + { + PSendSysMessage(LANG_WAYPOINT_NOTFOUNDPATH, wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpOrigin).c_str()); + SetSentErrorMessage(true); + return false; + } + + // Show info for the selected waypoint (Step two: Show actual info) + if (subCmd == "info") + { + // Find the waypoint + WaypointPath::const_iterator point = wpPath->find(wpTarget->GetWaypointId()); + if (point == wpPath->end()) + { + PSendSysMessage(LANG_WAYPOINT_NOTFOUND, wpTarget->GetWaypointId(), wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpOrigin).c_str()); + SetSentErrorMessage(true); + return false; + } + + PSendSysMessage(LANG_WAYPOINT_INFO_TITLE, wpTarget->GetWaypointId(), wpOwner->GetGuidStr().c_str(), wpPathId, WaypointManager::GetOriginString(wpOrigin).c_str()); + PSendSysMessage(LANG_WAYPOINT_INFO_WAITTIME, point->second.delay); + PSendSysMessage(LANG_WAYPOINT_INFO_ORI, point->second.orientation); + PSendSysMessage(LANG_WAYPOINT_INFO_SCRIPTID, point->second.script_id); + if (wpOrigin == PATH_FROM_SPECIAL) + PSendSysMessage(LANG_WAYPOINT_INFO_AISCRIPT, wpOwner->GetScriptName().c_str()); + if (WaypointBehavior* behaviour = point->second.behavior) + { + PSendSysMessage(" ModelId1: %u", behaviour->model1); + PSendSysMessage(" ModelId2: %u", behaviour->model2); + PSendSysMessage(" Emote: %u", behaviour->emote); + PSendSysMessage(" Spell: %u", behaviour->spell); + for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + PSendSysMessage(" TextId%i: %i \'%s\'", i + 1, behaviour->textid[i], (behaviour->textid[i] ? sObjectMgr.GetBroadcastText(behaviour->textid[i], m_session->GetSessionDbLocaleIndex()) : "")); + } + + return true; + } + + if (subCmd == "on") + { + UnsummonVisualWaypoints(m_session->GetPlayer(), wpOwner->GetObjectGuid()); + + for (WaypointPath::const_iterator pItr = wpPath->begin(); pItr != wpPath->end(); ++pItr) + { + if (!Helper_CreateWaypointFor(wpOwner, wpOrigin, wpPathId, pItr->first, &(pItr->second), waypointInfo)) + { + printf("error %s wpPathId %i", wpOwner->GetName(), wpPathId); + PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); SetSentErrorMessage(true); return false; } } - do - { - Field *fields = result->Fetch(); - uint32 wpGuid = fields[0].GetUInt32(); - uint32 point = fields[1].GetUInt32(); - int waittime = fields[2].GetUInt32(); - uint32 emote = fields[3].GetUInt32(); - uint32 spell = fields[4].GetUInt32(); - uint32 textid[MAX_WAYPOINT_TEXT]; - for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i) - textid[i] = fields[5 + i].GetUInt32(); - uint32 model1 = fields[10].GetUInt32(); - uint32 model2 = fields[11].GetUInt32(); - // Get the creature for which we read the waypoint - Creature* wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, VISUAL_WAYPOINT, wpGuid)); - - PSendSysMessage(LANG_WAYPOINT_INFO_TITLE, point, (wpCreature ? wpCreature->GetName() : ""), wpGuid); - PSendSysMessage(LANG_WAYPOINT_INFO_WAITTIME, waittime); - PSendSysMessage(LANG_WAYPOINT_INFO_MODEL, 1, model1); - PSendSysMessage(LANG_WAYPOINT_INFO_MODEL, 2, model2); - PSendSysMessage(LANG_WAYPOINT_INFO_EMOTE, emote); - PSendSysMessage(LANG_WAYPOINT_INFO_SPELL, spell); - for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i) - PSendSysMessage(LANG_WAYPOINT_INFO_TEXT, i + 1, textid[i], (textid[i] ? GetMangosString(textid[i]) : "")); - - } - while (result->NextRow()); - // Cleanup memory - delete result; return true; } - if (show == "on") + if (subCmd == "first") { - PSendSysMessage("DEBUG: wp on, GUID: %u", lowguid); - - QueryResult *result = WorldDatabase.PQuery("SELECT point, position_x,position_y,position_z FROM creature_movement WHERE id = '%u'", lowguid); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - // Delete all visuals for this NPC - QueryResult *result2 = WorldDatabase.PQuery("SELECT wpguid FROM creature_movement WHERE id = '%u' and wpguid <> 0", lowguid); - if (result2) - { - bool hasError = false; - do - { - Field *fields = result2->Fetch(); - uint32 wpGuid = fields[0].GetUInt32(); - Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, VISUAL_WAYPOINT, wpGuid)); - - if (!pCreature) - { - PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpGuid); - hasError = true; - WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid=%u", wpGuid); - } - else - { - pCreature->DeleteFromDB(); - pCreature->AddObjectToRemoveList(); - } - - } - while (result2->NextRow()); - delete result2; - if (hasError) - { - PSendSysMessage(LANG_WAYPOINT_TOOFAR1); - PSendSysMessage(LANG_WAYPOINT_TOOFAR2); - PSendSysMessage(LANG_WAYPOINT_TOOFAR3); - } - } - - do - { - Player *chr = m_session->GetPlayer(); - Map *map = chr->GetMap(); - - Field *fields = result->Fetch(); - uint32 point = fields[0].GetUInt32(); - CreatureCreatePos pos(map, fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), chr->GetOrientation()); - - Creature* wpCreature = new Creature; - - if (!wpCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) - { - PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); - delete wpCreature; - delete result; - return false; - } - - wpCreature->SetVisibility(VISIBILITY_OFF); - DEBUG_LOG("DEBUG: UPDATE creature_movement SET wpguid = '%u", wpCreature->GetGUIDLow()); - // set "wpguid" column to the visual waypoint - WorldDatabase.PExecuteLog("UPDATE creature_movement SET wpguid=%u WHERE id=%u and point=%u", wpCreature->GetGUIDLow(), lowguid, point); - - wpCreature->SaveToDB(map->GetId()); - // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells(); - wpCreature->LoadFromDB(wpCreature->GetGUIDLow(), map); - map->Add(wpCreature); - //wpCreature->GetMap()->Add(wpCreature); - } - while (result->NextRow()); - - // Cleanup memory - delete result; - return true; - } - - if (show == "first") - { - PSendSysMessage("DEBUG: wp first, GUID: %u", lowguid); - - QueryResult *result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z FROM creature_movement WHERE point='1' AND id = '%u'", lowguid); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUND, lowguid); - SetSentErrorMessage(true); - return false; - } - - Player *chr = m_session->GetPlayer(); - Map *map = chr->GetMap(); - - Field *fields = result->Fetch(); - CreatureCreatePos pos(map, fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), chr->GetOrientation()); - - Creature* pCreature = new Creature; - - if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) + if (!Helper_CreateWaypointFor(wpOwner, wpOrigin, wpPathId, wpPath->begin()->first, &(wpPath->begin()->second), waypointInfo)) { PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); - delete pCreature; - delete result; - return false; - } - - pCreature->SaveToDB(map->GetId()); - pCreature->LoadFromDB(pCreature->GetGUIDLow(), map); - map->Add(pCreature); - //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "First Waypoint"); - - // Cleanup memory - delete result; - return true; - } - - if (show == "last") - { - PSendSysMessage("DEBUG: wp last, GUID: %u", lowguid); - - QueryResult *result = WorldDatabase.PQuery("SELECT MAX(point) FROM creature_movement WHERE id = '%u'", lowguid); - if (result) - { - Maxpoint = (*result)[0].GetUInt32(); - - delete result; - } - else - Maxpoint = 0; - - result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z FROM creature_movement WHERE point ='%u' AND id = '%u'", Maxpoint, lowguid); - if (!result) - { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST, lowguid); SetSentErrorMessage(true); return false; } - Player *chr = m_session->GetPlayer(); - Map *map = chr->GetMap(); - - Field *fields = result->Fetch(); - CreatureCreatePos pos(map, fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), chr->GetOrientation()); - - Creature* pCreature = new Creature; - - if (!pCreature->Create(map->GenerateLocalLowGuid(HIGHGUID_UNIT), pos, waypointInfo)) - { - PSendSysMessage(LANG_WAYPOINT_NOTCREATED, VISUAL_WAYPOINT); - delete pCreature; - delete result; - return false; - } - - pCreature->SaveToDB(map->GetId()); - pCreature->LoadFromDB(pCreature->GetGUIDLow(), map); - map->Add(pCreature); - //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "Last Waypoint"); - // Cleanup memory - delete result; + // player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "First Waypoint"); return true; } - if (show == "off") + if (subCmd == "last") { - QueryResult *result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id=%u", VISUAL_WAYPOINT); - if (!result) + if (!Helper_CreateWaypointFor(wpOwner, wpOrigin, wpPathId, wpPath->rbegin()->first, &(wpPath->rbegin()->second), waypointInfo)) { - SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND); + PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT); SetSentErrorMessage(true); return false; } - bool hasError = false; - do - { - Field *fields = result->Fetch(); - uint32 wpGuid = fields[0].GetUInt32(); - Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(ObjectGuid(HIGHGUID_UNIT, VISUAL_WAYPOINT, wpGuid)); - if (!pCreature) - { - PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, wpGuid); - hasError = true; - WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid=%u", wpGuid); - } - else - { - pCreature->DeleteFromDB(); - pCreature->AddObjectToRemoveList(); - } - } - while (result->NextRow()); - // set "wpguid" column to "empty" - no visual waypoint spawned - WorldDatabase.PExecuteLog("UPDATE creature_movement SET wpguid=0 WHERE wpguid <> 0"); - - if (hasError) - { - PSendSysMessage(LANG_WAYPOINT_TOOFAR1); - PSendSysMessage(LANG_WAYPOINT_TOOFAR2); - PSendSysMessage(LANG_WAYPOINT_TOOFAR3); - } - - SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED); - // Cleanup memory - delete result; + // player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "Last Waypoint"); return true; } - PSendSysMessage("DEBUG: wpshow - no valid command found"); + if (subCmd == "off") + { + UnsummonVisualWaypoints(m_session->GetPlayer(), wpOwner->GetObjectGuid()); + PSendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED); + return true; + } - return true; + return false; } // HandleWpShowCommand -bool ChatHandler::HandleWpExportCommand(char *args) + /// [Guid if no selected unit] [pathId [wpOrigin] ] +bool ChatHandler::HandleWpExportCommand(char* args) { if (!*args) return false; - // Next arg is: + Creature* wpOwner; + WaypointPathOrigin wpOrigin = PATH_NO_PATH; + int32 wpPathId = 0; - // Did user provide a GUID - // or did the user select a creature? - // -> variable lowguid is filled with the GUID of the NPC - uint32 lowguid = 0; - Creature* target = getSelectedCreature(); - char* arg_str = NULL; - if (target) + if (Creature* targetCreature = getSelectedCreature()) { - if (target->GetEntry() != VISUAL_WAYPOINT) - lowguid = target->GetGUIDLow(); - else + // Check if the user did specify a visual waypoint + if (targetCreature->GetEntry() == VISUAL_WAYPOINT && targetCreature->GetSubtype() == CREATURE_SUBTYPE_TEMPORARY_SUMMON) { - QueryResult *result = WorldDatabase.PQuery("SELECT id FROM creature_movement WHERE wpguid = %u LIMIT 1", target->GetGUIDLow()); - if (!result) + TemporarySummonWaypoint* wpTarget = dynamic_cast(targetCreature); + if (!wpTarget) { - PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM, target->GetGUIDLow()); - return true; + PSendSysMessage(LANG_WAYPOINT_VP_SELECT); + SetSentErrorMessage(true); + return false; } - Field *fields = result->Fetch(); - lowguid = fields[0].GetUInt32();; - delete result; - } - arg_str = strtok(args, " "); + // Who moves along this waypoint? + wpOwner = targetCreature->GetMap()->GetAnyTypeCreature(wpTarget->GetSummonerGuid()); + if (!wpOwner) + { + PSendSysMessage(LANG_WAYPOINT_NOTFOUND_NPC, wpTarget->GetSummonerGuid().GetString().c_str()); + SetSentErrorMessage(true); + return false; + } + wpOrigin = (WaypointPathOrigin)wpTarget->GetPathOrigin(); + wpPathId = wpTarget->GetPathId(); + } + else // normal creature selected + wpOwner = targetCreature; } else { - // user provided - char* guid_str = strtok(args, " "); - if (!guid_str) + uint32 dbGuid; + if (!ExtractUInt32(&args, dbGuid)) { - SendSysMessage(LANG_WAYPOINT_NOGUID); + PSendSysMessage(LANG_WAYPOINT_NOGUID); + SetSentErrorMessage(true); return false; } - lowguid = atoi((char*)guid_str); - arg_str = strtok((char*)NULL, " "); + CreatureData const* data = sObjectMgr.GetCreatureData(dbGuid); + if (!data) + { + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); + SetSentErrorMessage(true); + return false; + } + + if (m_session->GetPlayer()->GetMapId() != data->mapid) + { + PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP, dbGuid); + SetSentErrorMessage(true); + return false; + } + + wpOwner = m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(data->GetObjectGuid(dbGuid)); + if (!wpOwner) + { + PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND, dbGuid); + SetSentErrorMessage(true); + return false; + } } - if (!arg_str) + // wpOwner is now known, in case of export by visual waypoint also the to be exported path + char* export_str = ExtractLiteralArg(&args); + if (!export_str) { PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ, "export"); + SetSentErrorMessage(true); return false; } - PSendSysMessage("DEBUG: wp export, GUID: %u", lowguid); + if (wpOrigin == PATH_NO_PATH) // No WP selected, Extract optional arguments + { + if (ExtractOptInt32(&args, wpPathId, 0)) // Fill path-id and source + { + uint32 src = (uint32)PATH_NO_PATH; + if (ExtractOptUInt32(&args, src, src)) + wpOrigin = (WaypointPathOrigin)src; + else // pathId provided but no destination + { + if (wpPathId != 0) + wpOrigin = PATH_FROM_ENTRY; // Multiple Paths must only be assigned by entry + } + } - QueryResult *result = WorldDatabase.PQuery( - // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - "SELECT point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, id FROM creature_movement WHERE id = '%u' ORDER BY point", lowguid); + if (wpOrigin == PATH_NO_PATH) + { + if (wpOwner->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + if (WaypointMovementGenerator const* wpMMGen = dynamic_cast const*>(wpOwner->GetMotionMaster()->GetCurrent())) + wpMMGen->GetPathInformation(wpPathId, wpOrigin); + if (wpOrigin == PATH_NO_PATH) + sWaypointMgr.GetDefaultPath(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), &wpOrigin); + } + } - if (!result) + WaypointPath const* wpPath = sWaypointMgr.GetPathFromOrigin(wpOwner->GetEntry(), wpOwner->GetGUIDLow(), wpPathId, wpOrigin); + if (!wpPath || wpPath->empty()) { PSendSysMessage(LANG_WAYPOINT_NOTHINGTOEXPORT); SetSentErrorMessage(true); @@ -3550,52 +3275,40 @@ bool ChatHandler::HandleWpExportCommand(char *args) } std::ofstream outfile; - outfile.open(arg_str); + outfile.open(export_str); - do + std::string table; + char const* key_field; + uint32 key; + switch (wpOrigin) { - Field *fields = result->Fetch(); - - outfile << "INSERT INTO creature_movement "; - outfile << "( id, point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5 ) VALUES "; - - outfile << "( "; - outfile << fields[15].GetUInt32(); // id - outfile << ", "; - outfile << fields[0].GetUInt32(); // point - outfile << ", "; - outfile << fields[1].GetFloat(); // position_x - outfile << ", "; - outfile << fields[2].GetFloat(); // position_y - outfile << ", "; - outfile << fields[3].GetUInt32(); // position_z - outfile << ", "; - outfile << fields[4].GetUInt32(); // orientation - outfile << ", "; - outfile << fields[5].GetUInt32(); // model1 - outfile << ", "; - outfile << fields[6].GetUInt32(); // model2 - outfile << ", "; - outfile << fields[7].GetUInt16(); // waittime - outfile << ", "; - outfile << fields[8].GetUInt32(); // emote - outfile << ", "; - outfile << fields[9].GetUInt32(); // spell - outfile << ", "; - outfile << fields[10].GetUInt32(); // textid1 - outfile << ", "; - outfile << fields[11].GetUInt32(); // textid2 - outfile << ", "; - outfile << fields[12].GetUInt32(); // textid3 - outfile << ", "; - outfile << fields[13].GetUInt32(); // textid4 - outfile << ", "; - outfile << fields[14].GetUInt32(); // textid5 - outfile << ");\n "; - + case PATH_FROM_ENTRY: key = wpOwner->GetEntry(); key_field = "entry"; table = "creature_movement_template"; break; + case PATH_FROM_GUID: key = wpOwner->GetGUIDLow(); key_field = "id"; table = "creature_movement"; break; + case PATH_FROM_SPECIAL: key = wpOwner->GetEntry(); key_field = "id"; table = "creature_movement_special"; break; + case PATH_NO_PATH: + return false; + } + + outfile << "DELETE FROM " << table << " WHERE " << key_field << "=" << key << ";\n"; + outfile << "INSERT INTO " << table << " (" << key_field << ", point, position_x, position_y, position_z, orientation, waittime, script_id) VALUES\n"; + + WaypointPath::const_iterator itr = wpPath->begin(); + uint32 countDown = wpPath->size(); + for (; itr != wpPath->end(); ++itr, --countDown) + { + outfile << "(" << key << ","; + outfile << itr->first << ","; + outfile << itr->second.x << ","; + outfile << itr->second.y << ","; + outfile << itr->second.z << ","; + outfile << itr->second.orientation << ","; + outfile << itr->second.delay << ","; + outfile << itr->second.script_id << ")"; + if (countDown > 1) + outfile << ",\n"; + else + outfile << ";\n"; } - while (result->NextRow()); - delete result; PSendSysMessage(LANG_WAYPOINT_EXPORTED); outfile.close(); @@ -3603,33 +3316,6 @@ bool ChatHandler::HandleWpExportCommand(char *args) return true; } -bool ChatHandler::HandleWpImportCommand(char *args) -{ - if (!*args) - return false; - - char* arg_str = strtok(args, " "); - if (!arg_str) - return false; - - std::string line; - std::ifstream infile(arg_str); - if (infile.is_open()) - { - while (! infile.eof()) - { - getline(infile, line); - //cout << line << endl; - QueryResult *result = WorldDatabase.Query(line.c_str()); - delete result; - } - infile.close(); - } - PSendSysMessage(LANG_WAYPOINT_IMPORTED); - - return true; -} - //rename characters bool ChatHandler::HandleCharacterRenameCommand(char* args) { diff --git a/src/game/Language.h b/src/game/Language.h index 0ec6547f0..a07f3dc69 100644 --- a/src/game/Language.h +++ b/src/game/Language.h @@ -211,39 +211,39 @@ enum MangosStrings LANG_RESETALL_SPELLS = 218, LANG_RESETALL_TALENTS = 219, - LANG_WAYPOINT_NOTFOUND = 220, - LANG_WAYPOINT_NOTFOUNDLAST = 221, - LANG_WAYPOINT_NOTFOUNDSEARCH = 222, - LANG_WAYPOINT_NOTFOUNDDBPROBLEM = 223, - LANG_WAYPOINT_CREATSELECTED = 224, - LANG_WAYPOINT_CREATNOTFOUND = 225, - LANG_WAYPOINT_VP_SELECT = 226, - LANG_WAYPOINT_VP_NOTFOUND = 227, - LANG_WAYPOINT_VP_NOTCREATED = 228, - LANG_WAYPOINT_VP_ALLREMOVED = 229, - LANG_WAYPOINT_NOTCREATED = 230, - LANG_WAYPOINT_NOGUID = 231, - LANG_WAYPOINT_NOWAYPOINTGIVEN = 232, - LANG_WAYPOINT_ARGUMENTREQ = 233, - LANG_WAYPOINT_ADDED = 234, - LANG_WAYPOINT_ADDED_NO = 235, - LANG_WAYPOINT_CHANGED = 236, - LANG_WAYPOINT_CHANGED_NO = 237, - LANG_WAYPOINT_EXPORTED = 238, - LANG_WAYPOINT_NOTHINGTOEXPORT = 239, - LANG_WAYPOINT_IMPORTED = 240, - LANG_WAYPOINT_REMOVED = 241, - LANG_WAYPOINT_NOTREMOVED = 242, - LANG_WAYPOINT_TOOFAR1 = 243, - LANG_WAYPOINT_TOOFAR2 = 244, - LANG_WAYPOINT_TOOFAR3 = 245, - LANG_WAYPOINT_INFO_TITLE = 246, - LANG_WAYPOINT_INFO_WAITTIME = 247, - LANG_WAYPOINT_INFO_MODEL = 248, - LANG_WAYPOINT_INFO_EMOTE = 249, - LANG_WAYPOINT_INFO_SPELL = 250, - LANG_WAYPOINT_INFO_TEXT = 251, - LANG_WAYPOINT_INFO_AISCRIPT = 252, + LANG_WAYPOINT_NOTFOUND = 220, // Cannot find waypoint id %u for %s (in path %i, loaded from %s) + LANG_WAYPOINT_NOTFOUNDLAST = 221, // Last Waypoint not found for %s + LANG_WAYPOINT_NOTFOUNDPATH = 222, // %s has no path or path empty, path-id %i (loaded from %s) + LANG_WAYPOINT_NOTFOUNDDBPROBLEM = 223, // Creature (GUID: %u) No waypoints found - This is a MaNGOS db problem (single float). + LANG_WAYPOINT_NOTFOUND_NPC = 224, // Cannot access %s on map, maybe you are too far away from its spawn location + LANG_WAYPOINT_CREATNOTFOUND = 225, // Creature (GUID: %u) not found + LANG_WAYPOINT_VP_SELECT = 226, // You must select a visual waypoint. + LANG_WAYPOINT_VP_NOTFOUND = 227, // No visual waypoints found + LANG_WAYPOINT_VP_NOTCREATED = 228, // Could not create visual waypoint with creatureID: %d + LANG_WAYPOINT_VP_ALLREMOVED = 229, // All visual waypoints removed + LANG_WAYPOINT_NOTCREATED = 230, // Could not add waypoint %u to %s (pathId %i stored by %s) + LANG_WAYPOINT_NOGUID = 231, // No GUID provided. + LANG_WAYPOINT_NOWAYPOINTGIVEN = 232, // No waypoint number provided. + LANG_WAYPOINT_ARGUMENTREQ = 233, // Argument required for \'%s\'. + LANG_WAYPOINT_ADDED = 234, // Added Waypoint %u to %s (PathId %i, path stored by %s) + LANG_WAYPOINT_ADDED_NO = 235, // UNUSED + LANG_WAYPOINT_CHANGED = 236, // Waypoint changed. + LANG_WAYPOINT_CHANGED_NO = 237, // Waypoint %s modified. + LANG_WAYPOINT_EXPORTED = 238, // WP export successfull. + LANG_WAYPOINT_NOTHINGTOEXPORT = 239, // No waypoints found inside the database. + LANG_WAYPOINT_IMPORTED = 240, // File imported. + LANG_WAYPOINT_REMOVED = 241, // Waypoint removed. + LANG_WAYPOINT_NOTREMOVED = 242, // UNUSED + LANG_WAYPOINT_TOOFAR1 = 243, // UNUSED + LANG_WAYPOINT_TOOFAR2 = 244, // UNUSED + LANG_WAYPOINT_TOOFAR3 = 245, // UNUSED + LANG_WAYPOINT_INFO_TITLE = 246, // Waypoint %u for %s (from pathId %i, stored by %s) + LANG_WAYPOINT_INFO_WAITTIME = 247, // Waittime: %d + LANG_WAYPOINT_INFO_ORI = 248, // Orientation: %f + LANG_WAYPOINT_INFO_SCRIPTID = 249, // ScriptId: %u + LANG_WAYPOINT_INFO_UNK_SCRIPTID = 250, // ScriptID set to non-existing id %u, add it to DBScriptsEngine and reload the table. + LANG_WAYPOINT_INFO_TEXT = 251, // UNUSED + LANG_WAYPOINT_INFO_AISCRIPT = 252, // AIScriptName: %s LANG_RENAME_PLAYER = 253, LANG_RENAME_PLAYER_GUID = 254, diff --git a/src/game/Maps/Map.h b/src/game/Maps/Map.h index a5cff00c9..c604cfeb7 100644 --- a/src/game/Maps/Map.h +++ b/src/game/Maps/Map.h @@ -725,6 +725,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj bool ScriptCommand_AddSpellCooldown(const ScriptInfo& script, WorldObject* source, WorldObject* target); bool ScriptCommand_RemoveSpellCooldown(const ScriptInfo& script, WorldObject* source, WorldObject* target); bool ScriptCommand_SetReactState(const ScriptInfo& script, WorldObject* source, WorldObject* target); + bool ScriptCommand_StartWaypoints(const ScriptInfo& script, WorldObject* source, WorldObject* target); // Add any new script command functions to the array. const ScriptCommandFunction m_ScriptCommands[SCRIPT_COMMAND_MAX] = @@ -789,6 +790,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager, public MaNGOS::Obj &Map::ScriptCommand_AddSpellCooldown, // 57 &Map::ScriptCommand_RemoveSpellCooldown, // 58 &Map::ScriptCommand_SetReactState, // 59 + &Map::ScriptCommand_StartWaypoints, // 60 }; public: diff --git a/src/game/Maps/ScriptCommands.cpp b/src/game/Maps/ScriptCommands.cpp index effaf6727..3bbd9741f 100644 --- a/src/game/Maps/ScriptCommands.cpp +++ b/src/game/Maps/ScriptCommands.cpp @@ -165,7 +165,7 @@ bool Map::ScriptCommand_MoveTo(const ScriptInfo& script, WorldObject* source, Wo float orientation = script.o ? script.o : -10.0f; if (script.moveTo.flags & SF_MOVETO_POINT_MOVEGEN) - pSource->GetMotionMaster()->MovePoint(0, x, y, z, script.moveTo.movementOptions, speed, orientation); + pSource->GetMotionMaster()->MovePoint(script.moveTo.pointId, x, y, z, script.moveTo.movementOptions, speed, orientation); else pSource->MonsterMoveWithSpeed(x, y, z, orientation, speed, script.moveTo.movementOptions); @@ -706,7 +706,7 @@ bool Map::ScriptCommand_SetMovementType(const ScriptInfo& script, WorldObject* s pSource->GetMotionMaster()->MoveRandom(); break; case WAYPOINT_MOTION_TYPE: - pSource->GetMotionMaster()->MoveWaypoint(script.movement.boolParam); + pSource->GetMotionMaster()->MoveWaypoint(0, script.movement.intParam, 0, 0, 0, script.movement.boolParam); break; case CONFUSED_MOTION_TYPE: pSource->GetMotionMaster()->MoveConfused(); @@ -1595,5 +1595,21 @@ bool Map::ScriptCommand_SetReactState(const ScriptInfo& script, WorldObject* sou pSource->SetReactState(ReactStates(script.setReactState.state)); + return false; +} + +// SCRIPT_COMMAND_START_WAYPOINTS (60) +bool Map::ScriptCommand_StartWaypoints(const ScriptInfo& script, WorldObject* source, WorldObject* target) +{ + Creature* pSource = ToCreature(source); + + if (!pSource) + { + sLog.outError("SCRIPT_COMMAND_START_WAYPOINTS (script id %u) call for a NULL or non-creature source (TypeId: %u), skipping.", script.id, source ? source->GetTypeId() : 0); + return ShouldAbortScript(script); + } + + pSource->GetMotionMaster()->MoveWaypoint(script.startWaypoints.pathId, script.startWaypoints.startPoint, script.startWaypoints.wpSource, script.startWaypoints.initialDelay, script.startWaypoints.overwriteEntry, script.startWaypoints.canRepeat); + return false; } \ No newline at end of file diff --git a/src/game/Movement/MotionMaster.cpp b/src/game/Movement/MotionMaster.cpp index 4227ce5d0..293b70413 100644 --- a/src/game/Movement/MotionMaster.cpp +++ b/src/game/Movement/MotionMaster.cpp @@ -58,6 +58,8 @@ void MotionMaster::Initialize() MovementGenerator* movement = FactorySelector::selectMovementGenerator((Creature*)m_owner); push(movement == NULL ? &si_idleMovement : movement); top()->Initialize(*m_owner); + if (top()->GetMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + (static_cast*>(top()))->InitializeWaypointPath(*(static_cast(m_owner)), 0, static_cast(m_owner)->m_startwaypoint, PATH_NO_PATH, 0, 0, true); } else push(&si_idleMovement); @@ -439,7 +441,7 @@ void MotionMaster::MoveFeared(Unit* enemy, uint32 time) } } -void MotionMaster::MoveWaypoint(bool repeat) +void MotionMaster::MoveWaypoint(int32 id /*=0*/, uint32 startPoint /*=0*/, uint32 source /*=0==PATH_NO_PATH*/, uint32 initialDelay /*=0*/, uint32 overwriteEntry /*=0*/, bool repeat) { if (m_owner->GetTypeId() == TYPEID_UNIT) { @@ -452,7 +454,9 @@ void MotionMaster::MoveWaypoint(bool repeat) Creature* creature = (Creature*)m_owner; DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature %s (Entry %u) start MoveWaypoint()", m_owner->GetGuidStr().c_str(), m_owner->GetEntry()); - Mutate(new WaypointMovementGenerator(*creature, repeat)); + WaypointMovementGenerator* newWPMMgen = new WaypointMovementGenerator(*creature); + Mutate(newWPMMgen); + newWPMMgen->InitializeWaypointPath(*creature, id, startPoint, (WaypointPathOrigin)source, initialDelay, overwriteEntry, repeat); } else sLog.outError("Non-creature %s attempt to MoveWaypoint()", m_owner->GetGuidStr().c_str()); @@ -558,6 +562,16 @@ void MotionMaster::propagateSpeedChange() (*it)->unitSpeedChanged(); } +bool MotionMaster::SetNextWaypoint(uint32 pointId) +{ + for (Impl::container_type::reverse_iterator rItr = Impl::c.rbegin(); rItr != Impl::c.rend(); ++rItr) + { + if ((*rItr)->GetMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + return (static_cast*>(*rItr))->SetNextWaypoint(pointId); + } + return false; +} + uint32 MotionMaster::getLastReachedWaypoint() const { for (Impl::container_type::const_reverse_iterator rItr = Impl::c.rbegin(); rItr != Impl::c.rend(); ++rItr) @@ -574,6 +588,18 @@ MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const return top()->GetMovementGeneratorType(); } +void MotionMaster::GetWaypointPathInformation(std::ostringstream& oss) const +{ + for (Impl::container_type::const_reverse_iterator rItr = Impl::c.rbegin(); rItr != Impl::c.rend(); ++rItr) + { + if ((*rItr)->GetMovementGeneratorType() == WAYPOINT_MOTION_TYPE) + { + static_cast*>(*rItr)->GetPathInformation(oss); + return; + } + } +} + bool MotionMaster::GetDestination(float &x, float &y, float &z) { // Often used in motion gen, lock target movespline while checking in case diff --git a/src/game/Movement/MotionMaster.h b/src/game/Movement/MotionMaster.h index 325815831..9a7df868b 100644 --- a/src/game/Movement/MotionMaster.h +++ b/src/game/Movement/MotionMaster.h @@ -54,6 +54,10 @@ enum MovementGeneratorType EFFECT_MOTION_TYPE = 15, PATROL_MOTION_TYPE = 16, CHARGE_MOTION_TYPE = 17, + + WAYPOINT_SPECIAL_REACHED = 256, // Only used in CreatureAI::MovementInform when a special waypoint is reached. The pathId >= 0 is added as additonal value + WAYPOINT_SPECIAL_STARTED = 512, // Only used in CreatureAI::MovementInform when a special waypoint is started. The pathId >= 0 is added as additional value + WAYPOINT_SPECIAL_FINISHED_LAST = 1024, // Only used in CreatureAI::MovementInform when the waittime of the last special wp is finished. The pathId >= 0 is added as additional value }; enum MMCleanFlag @@ -89,7 +93,7 @@ class MANGOS_DLL_SPEC MotionMaster : std::stack void Initialize(); - MovementGenerator* operator->(void) { return top(); } + MovementGenerator const* GetCurrent() const { return top(); } //MovementGenerator* top() { return std::stack::top(); } using Impl::top; @@ -132,7 +136,7 @@ class MANGOS_DLL_SPEC MotionMaster : std::stack void MovePoint(uint32 id, float x, float y, float z, uint32 options = MOVE_NONE, float speed = 0.0f, float finalOrientation = -10); void MoveSeekAssistance(float x,float y,float z); void MoveSeekAssistanceDistract(uint32 timer); - void MoveWaypoint(bool repeat = true); + void MoveWaypoint(int32 id = 0, uint32 startPoint = 0, uint32 source = 0, uint32 initialDelay = 0, uint32 overwriteEntry = 0, bool repeat = true); void MoveTaxiFlight(uint32 path, uint32 pathnode); void MoveTaxiFlight(); void MoveDistract(uint32 timeLimit); @@ -142,12 +146,15 @@ class MANGOS_DLL_SPEC MotionMaster : std::stack MovementGeneratorType GetCurrentMovementGeneratorType() const; void propagateSpeedChange(); + bool SetNextWaypoint(uint32 pointId); + uint32 getLastReachedWaypoint() const; + void GetWaypointPathInformation(std::ostringstream& oss) const; + bool GetDestination(float& x, float& y, float& z); // will only work in MMgens where we have a target (TARGETED_MOTION_TYPE) void UpdateFinalDistanceToTarget(float fDistance); - bool GetDestination(float &x, float &y, float &z); bool NeedsAsyncUpdate() const { return m_needsAsyncUpdate; } void SetNeedAsyncUpdate() { m_needsAsyncUpdate = true; } private: diff --git a/src/game/Movement/WaypointManager.cpp b/src/game/Movement/WaypointManager.cpp index 403f8943b..5eba4c582 100644 --- a/src/game/Movement/WaypointManager.cpp +++ b/src/game/Movement/WaypointManager.cpp @@ -65,7 +65,10 @@ void WaypointManager::Load() for (ScriptMapMap::const_iterator itr = sCreatureMovementScripts.begin(); itr != sCreatureMovementScripts.end(); ++itr) movementScriptSet.insert(itr->first); + // ///////////////////////////////////////////////////// // creature_movement + // ///////////////////////////////////////////////////// + QueryResult *result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement GROUP BY id"); if (!result) @@ -83,12 +86,11 @@ void WaypointManager::Load() do { bar.step(); - Field *fields = result->Fetch(); + Field* fields = result->Fetch(); - uint32 id = fields[0].GetUInt32(); - uint32 count = fields[1].GetUInt32(); + // uint32 id = fields[0].GetUInt32(); + uint32 count = fields[1].GetUInt32(); - m_pathMap[id].resize(count); total_nodes += count; } while (result->NextRow()); @@ -130,7 +132,7 @@ void WaypointManager::Load() WaypointPath &path = m_pathMap[id]; // the cleanup queries make sure the following is true - MANGOS_ASSERT(point >= 1 && point <= path.size()); + MANGOS_ASSERT(point >= 1); WaypointNode &node = path[point - 1]; @@ -213,7 +215,7 @@ void WaypointManager::Load() ++total_behaviors; } else - node.behavior = NULL; + node.behavior = nullptr; } while (result->NextRow()); @@ -239,7 +241,10 @@ void WaypointManager::Load() delete result; } + // ///////////////////////////////////////////////////// // creature_movement_template + // ///////////////////////////////////////////////////// + result = WorldDatabase.Query("SELECT entry, COUNT(point) FROM creature_movement_template GROUP BY entry"); if (!result) @@ -259,12 +264,11 @@ void WaypointManager::Load() do { barRow.step(); - Field *fields = result->Fetch(); + Field* fields = result->Fetch(); - uint32 entry = fields[0].GetUInt32(); - uint32 count = fields[1].GetUInt32(); + // uint32 entry = fields[0].GetUInt32(); + uint32 count = fields[1].GetUInt32(); - m_pathTemplateMap[entry].resize(count); total_nodes += count; } while (result->NextRow()); @@ -298,10 +302,10 @@ void WaypointManager::Load() continue; } - WaypointPath &path = m_pathTemplateMap[entry]; + WaypointPath &path = m_pathTemplateMap[entry << 8]; // the cleanup queries make sure the following is true - MANGOS_ASSERT(point >= 1 && point <= path.size()); + MANGOS_ASSERT(point >= 1); WaypointNode &node = path[point - 1]; @@ -374,7 +378,7 @@ void WaypointManager::Load() ++total_behaviors; } else - node.behavior = NULL; + node.behavior = nullptr; } while (result->NextRow()); @@ -386,6 +390,155 @@ void WaypointManager::Load() sLog.outString(">>> Loaded %u path templates with %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors); } + // ///////////////////////////////////////////////////// + // creature_movement_special + // ///////////////////////////////////////////////////// + + result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement_special GROUP BY id"); + + if (!result) + { + BarGoLink bar(1); + bar.step(); + sLog.outString(); + sLog.outString(">> Loaded 0 paths. DB table `creature_movement_special` is empty."); + } + else + { + total_nodes = 0; + total_behaviors = 0; + total_paths = (uint32)result->GetRowCount(); + BarGoLink bar(total_paths); + + do + { + bar.step(); + Field* fields = result->Fetch(); + + // uint32 id = fields[0].GetUInt32(); + uint32 count = fields[1].GetUInt32(); + + total_nodes += count; + } + while (result->NextRow()); + + sLog.outString(); + sLog.outString(">> Paths loaded"); + + delete result; + + // 0 1 2 3 4 5 6 + result = WorldDatabase.Query("SELECT id, point, position_x, position_y, position_z, waittime, script_id," + // 7 8 9 10 11 12 13 14 15 16 + "textid1, textid2, textid3, textid4, textid5, emote, spell, orientation, model1, model2 FROM creature_movement_special"); + + BarGoLink barRow((int)result->GetRowCount()); + + do + { + barRow.step(); + Field *fields = result->Fetch(); + uint32 id = fields[0].GetUInt32(); + uint32 point = fields[1].GetUInt32(); + + WaypointPath &path = m_pathSpecialMap[id]; + + // the cleanup queries make sure the following is true + MANGOS_ASSERT(point >= 1); + + WaypointNode &node = path[point - 1]; + + node.x = fields[2].GetFloat(); + node.y = fields[3].GetFloat(); + node.z = fields[4].GetFloat(); + node.orientation = fields[14].GetFloat(); + node.delay = fields[5].GetUInt32(); + node.script_id = fields[6].GetUInt32(); + + // prevent using invalid coordinates + if (!MaNGOS::IsValidMapCoord(node.x, node.y, node.z, node.orientation == 100.0f ? 0.0f : node.orientation)) + { + QueryResult *result1 = WorldDatabase.PQuery("SELECT id, map FROM creature WHERE guid = '%u'", id); + if (result1) + sLog.outErrorDb("Creature (guidlow %d, entry %d) have invalid coordinates in his waypoint %d (X: %f, Y: %f).", + id, result1->Fetch()[0].GetUInt32(), point, node.x, node.y); + else + sLog.outErrorDb("Waypoint path %d, have invalid coordinates in his waypoint %d (X: %f, Y: %f).", + id, point, node.x, node.y); + + MaNGOS::NormalizeMapCoord(node.x); + MaNGOS::NormalizeMapCoord(node.y); + + if (result1) + { + node.z = sTerrainMgr.LoadTerrain(result1->Fetch()[1].GetUInt32())->GetHeightStatic(node.x, node.y, node.z); + delete result1; + } + + WorldDatabase.PExecute("UPDATE creature_movement_special SET position_x = '%f', position_y = '%f', position_z = '%f' WHERE id = '%u' AND point = '%u'", node.x, node.y, node.z, id, point); + } + + if (node.script_id) + { + if (sCreatureMovementScripts.find(node.script_id) == sCreatureMovementScripts.end()) + { + sLog.outErrorDb("Table creature_movement_special for id %u, point %u have script_id %u that does not exist in `creature_movement_scripts`, ignoring", id, point, node.script_id); + continue; + } + + movementScriptSet.erase(node.script_id); + } + + // WaypointBehavior can be dropped in time. Script_id added may 2010 and can handle all the below behavior. + + WaypointBehavior be; + be.model1 = fields[15].GetUInt32(); + be.model2 = fields[16].GetUInt32(); + be.emote = fields[12].GetUInt32(); + be.spell = fields[13].GetUInt32(); + + for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i) + { + be.textid[i] = fields[7 + i].GetUInt32(); + + if (be.textid[i] < 0) + { + sLog.outErrorDb("Broadcast text %u used in table `creature_movement_special` does not exist.", be.textid[i]); + continue; + } + } + + if (be.spell && ! sSpellMgr.GetSpellEntry(be.spell)) + { + sLog.outErrorDb("Table creature_movement_special references unknown spellid %u. Skipping id %u with point %u.", be.spell, id, point); + be.spell = 0; + } + + if (be.emote) + { + if (!sEmotesStore.LookupEntry(be.emote)) + sLog.outErrorDb("Waypoint path %u (Point %u) are using emote %u, but emote does not exist.", id, point, be.emote); + } + + // save memory by not storing empty behaviors + if (!be.isEmpty()) + { + node.behavior = new WaypointBehavior(be); + ++total_behaviors; + } + else + node.behavior = nullptr; + } + while (result->NextRow()); + + sLog.outString(); + sLog.outString(">> Special waypoints loaded"); + sLog.outString(); + sLog.outString(">>> Loaded %u paths, %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors); + + delete result; + } + if (!movementScriptSet.empty()) { for (std::set::const_iterator itr = movementScriptSet.begin(); itr != movementScriptSet.end(); ++itr) @@ -425,77 +578,113 @@ void WaypointManager::Cleanup() MANGOS_ASSERT(!(result = WorldDatabase.Query("SELECT 1 from creature_movement_template As T WHERE point <> (SELECT COUNT(*) FROM creature_movement_template WHERE entry = T.entry AND point <= T.point) LIMIT 1"))); } + + if (QueryResult *result = WorldDatabase.Query("SELECT 1 from creature_movement_special As T WHERE point <> (SELECT COUNT(*) FROM creature_movement_special WHERE id = T.id AND point <= T.point) LIMIT 1")) + { + delete result; + WorldDatabase.DirectExecute("CREATE TEMPORARY TABLE temp LIKE creature_movement_special"); + WorldDatabase.DirectExecute("INSERT INTO temp SELECT * FROM creature_movement_special"); + WorldDatabase.DirectExecute("ALTER TABLE creature_movement_special DROP PRIMARY KEY"); + WorldDatabase.DirectExecute("UPDATE creature_movement_special AS T SET point = (SELECT COUNT(*) FROM temp WHERE id = T.id AND point <= T.point)"); + WorldDatabase.DirectExecute("ALTER TABLE creature_movement_special ADD PRIMARY KEY (id, point)"); + WorldDatabase.DirectExecute("DROP TABLE temp"); + + sLog.outErrorDb("Table `creature_movement_special` was auto corrected for using points out of order (invalid or points missing)"); + + MANGOS_ASSERT(!(result = WorldDatabase.Query("SELECT 1 from creature_movement_special As T WHERE point <> (SELECT COUNT(*) FROM creature_movement_special WHERE id = T.id AND point <= T.point) LIMIT 1"))); + } } void WaypointManager::Unload() { for (WaypointPathMap::iterator itr = m_pathMap.begin(); itr != m_pathMap.end(); ++itr) _clearPath(itr->second); + m_pathMap.clear(); + for (WaypointPathMap::iterator itr = m_pathTemplateMap.begin(); itr != m_pathTemplateMap.end(); ++itr) _clearPath(itr->second); - m_pathMap.clear(); m_pathTemplateMap.clear(); + + for (WaypointPathMap::iterator itr = m_pathSpecialMap.begin(); itr != m_pathSpecialMap.end(); ++itr) + _clearPath(itr->second); + m_pathSpecialMap.clear(); } void WaypointManager::_clearPath(WaypointPath &path) { for (WaypointPath::const_iterator itr = path.begin(); itr != path.end(); ++itr) - if (itr->behavior) - delete itr->behavior; + if (itr->second.behavior) + delete itr->second.behavior; path.clear(); } -/// - Insert after the last point -void WaypointManager::AddLastNode(uint32 id, float x, float y, float z, float o, uint32 delay, uint32 wpGuid) +/// - Insert at a certain point, if pointId == 0 insert last. In this case pointId will be changed to the id to which the node was added +WaypointNode const* WaypointManager::AddNode(uint32 entry, uint32 dbGuid, uint32& pointId, WaypointPathOrigin wpDest, float x, float y, float z) { - _addNode(id, GetLastPoint(id, 0) + 1, x, y, z, o, delay, wpGuid); -} + // Support only normal movement tables + if (wpDest != PATH_FROM_GUID && wpDest != PATH_FROM_ENTRY) + return nullptr; -/// - Insert after a certain point -void WaypointManager::AddAfterNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid) -{ - for (uint32 i = GetLastPoint(id, 0); i > point; i--) - WorldDatabase.PExecuteLog("UPDATE creature_movement SET point=point+1 WHERE id=%u AND point=%u", id, i); + // Prepare information + char const* const table = wpDest == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpDest == PATH_FROM_GUID ? "id" : "entry"; + uint32 key = wpDest == PATH_FROM_GUID ? dbGuid : ((entry << 8) /*+ pathId*/); + uint32 keydb = wpDest == PATH_FROM_GUID ? dbGuid : entry; + WaypointPathMap* wpMap = wpDest == PATH_FROM_GUID ? &m_pathMap : &m_pathTemplateMap; - _addNode(id, point + 1, x, y, z, o, delay, wpGuid); -} + WaypointPath& path = (*wpMap)[key]; -/// - Insert without checking for collision -void WaypointManager::_addNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid) -{ - if (point == 0) return; // counted from 1 in the DB - WorldDatabase.PExecuteLog("INSERT INTO creature_movement (id,point,position_x,position_y,position_z,orientation,wpguid,waittime) " - "VALUES (%u,%u, %f,%f,%f,%f, %u,%u)", - id, point, x, y, z, o, wpGuid, delay); - WaypointPathMap::iterator itr = m_pathMap.find(id); - if (itr == m_pathMap.end()) - itr = m_pathMap.insert(WaypointPathMap::value_type(id, WaypointPath())).first; - itr->second.insert(itr->second.begin() + (point - 1), WaypointNode(x, y, z, o, delay, 0, NULL)); -} + if (pointId == 0 && !path.empty()) // Start with highest waypoint + pointId = path.rbegin()->first + 1; + else if (pointId == 0) + pointId = 1; -uint32 WaypointManager::GetLastPoint(uint32 id, uint32 default_notfound) -{ - uint32 point = default_notfound; - /*QueryResult *result = WorldDatabase.PQuery( "SELECT MAX(point) FROM creature_movement WHERE id = '%u'", id); - if( result ) + uint32 nextPoint = pointId; + WaypointNode temp = WaypointNode(x, y, z, 100, 0, 0, nullptr); + WaypointPath::iterator find = path.find(nextPoint); + if (find != path.end()) // Point already exists { - point = (*result)[0].GetUInt32()+1; - delete result; - }*/ - WaypointPathMap::const_iterator itr = m_pathMap.find(id); - if (itr != m_pathMap.end() && itr->second.size() != 0) - point = itr->second.size(); - return point; + do // Move points along until a free spot is found + { + std::swap(temp, find->second); + ++find; + ++nextPoint; + } while (find != path.end() && find->first == nextPoint); + // After this, we have: + // pointId, pointId+1, ..., nextPoint [ Can be == path.end ]] + } + + // Insert new or remaining + path[nextPoint] = temp; + + // Update original waypoints + for (WaypointPath::reverse_iterator rItr = path.rbegin(); rItr != path.rend() && rItr->first > pointId; ++rItr) + { + if (rItr->first <= nextPoint) + WorldDatabase.PExecuteLog("UPDATE %s SET point=point+1 WHERE %s=%u AND point=%u", table, key_field, keydb, rItr->first - 1); + } + // Insert new Point to database + WorldDatabase.PExecuteLog("INSERT INTO %s (%s,point,position_x,position_y,position_z,orientation) VALUES (%u,%u, %f,%f,%f, 100)", table, key_field, keydb, pointId, x, y, z); + + return &path[pointId]; } -void WaypointManager::DeleteNode(uint32 id, uint32 point) +void WaypointManager::DeleteNode(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin) { - if (point == 0) return; // counted from 1 in the DB - WorldDatabase.PExecuteLog("DELETE FROM creature_movement WHERE id=%u AND point=%u", id, point); - WorldDatabase.PExecuteLog("UPDATE creature_movement SET point=point-1 WHERE id=%u AND point>%u", id, point); - WaypointPathMap::iterator itr = m_pathMap.find(id); - if (itr != m_pathMap.end() && point <= itr->second.size()) - itr->second.erase(itr->second.begin() + (point - 1)); + // Support only normal movement tables + if (wpOrigin != PATH_FROM_GUID && wpOrigin != PATH_FROM_ENTRY) + return; + + WaypointPath* path = GetPathFromOrigin(entry, dbGuid, pathId, wpOrigin); + if (!path) + return; + + char const* const table = wpOrigin == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpOrigin == PATH_FROM_GUID ? "id" : "entry"; + uint32 const key = wpOrigin == PATH_FROM_GUID ? dbGuid : entry; + WorldDatabase.PExecuteLog("DELETE FROM %s WHERE %s=%u AND point=%u", table, key_field, key, point); + + path->erase(point); } void WaypointManager::DeletePath(uint32 id) @@ -510,136 +699,152 @@ void WaypointManager::DeletePath(uint32 id) // only meant to be called by GM commands } -void WaypointManager::SetNodePosition(uint32 id, uint32 point, float x, float y, float z) +void WaypointManager::SetNodePosition(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float x, float y, float z) { - if (point == 0) return; // counted from 1 in the DB - WorldDatabase.PExecuteLog("UPDATE creature_movement SET position_x=%f, position_y=%f, position_z=%f WHERE id=%u AND point=%u", x, y, z, id, point); - WaypointPathMap::iterator itr = m_pathMap.find(id); - if (itr != m_pathMap.end() && point <= itr->second.size()) + // Support only normal movement tables + if (wpOrigin != PATH_FROM_GUID && wpOrigin != PATH_FROM_ENTRY) { - itr->second[point - 1].x = x; - itr->second[point - 1].y = y; - itr->second[point - 1].z = z; + return; + } + + WaypointPath* path = GetPathFromOrigin(entry, dbGuid, pathId, wpOrigin); + if (!path) + { + return; + } + + char const* const table = wpOrigin == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpOrigin == PATH_FROM_GUID ? "id" : "entry"; + uint32 const key = wpOrigin == PATH_FROM_GUID ? dbGuid : entry; + WorldDatabase.PExecuteLog("UPDATE %s SET position_x=%f, position_y=%f, position_z=%f WHERE %s=%u AND point=%u", table, x, y, z, key_field, key, point); + + WaypointPath::iterator find = path->find(point); + if (find != path->end()) + { + find->second.x = x; + find->second.y = y; + find->second.z = z; } } -void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_field, const char *text) +void WaypointManager::SetNodeWaittime(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 waittime) { - if (point == 0) return; // counted from 1 in the DB - if (!text_field) return; - std::string field = text_field; - WorldDatabase.escape_string(field); + // Support only normal movement tables + if (wpOrigin != PATH_FROM_GUID && wpOrigin != PATH_FROM_ENTRY) + return; - if (!text) - WorldDatabase.PExecuteLog("UPDATE creature_movement SET %s=NULL WHERE id='%u' AND point='%u'", field.c_str(), id, point); - else + WaypointPath* path = GetPathFromOrigin(entry, dbGuid, pathId, wpOrigin); + if (!path) + return; + + char const* const table = wpOrigin == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpOrigin == PATH_FROM_GUID ? "id" : "entry"; + uint32 const key = wpOrigin == PATH_FROM_GUID ? dbGuid : entry; + WorldDatabase.PExecuteLog("UPDATE %s SET waittime=%u WHERE %s=%u AND point=%u", table, waittime, key_field, key, point); + + WaypointPath::iterator find = path->find(point); + if (find != path->end()) + find->second.delay = waittime; +} + +void WaypointManager::SetNodeOrientation(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float orientation) +{ + // Support only normal movement tables + if (wpOrigin != PATH_FROM_GUID && wpOrigin != PATH_FROM_ENTRY) + return; + + WaypointPath* path = GetPathFromOrigin(entry, dbGuid, pathId, wpOrigin); + if (!path) + return; + + char const* const table = wpOrigin == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpOrigin == PATH_FROM_GUID ? "id" : "entry"; + uint32 const key = wpOrigin == PATH_FROM_GUID ? dbGuid : entry; + WorldDatabase.PExecuteLog("UPDATE %s SET orientation=%f WHERE %s=%u AND point=%u", table, orientation, key_field, key, point); + + WaypointPath::iterator find = path->find(point); + if (find != path->end()) + find->second.orientation = orientation; +} + +/// return true if a valid scriptId is provided +bool WaypointManager::SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 scriptId) +{ + // Support only normal movement tables + if (wpOrigin != PATH_FROM_GUID && wpOrigin != PATH_FROM_ENTRY) + return false; + + WaypointPath* path = GetPathFromOrigin(entry, dbGuid, pathId, wpOrigin); + if (!path) + return false; + + char const* const table = wpOrigin == PATH_FROM_GUID ? "creature_movement" : "creature_movement_template"; + char const* const key_field = wpOrigin == PATH_FROM_GUID ? "id" : "entry"; + uint32 const key = wpOrigin == PATH_FROM_GUID ? dbGuid : entry; + WorldDatabase.PExecuteLog("UPDATE %s SET script_id=%u WHERE %s=%u AND point=%u", table, scriptId, key_field, key, point); + + WaypointPath::iterator find = path->find(point); + if (find != path->end()) + find->second.script_id = scriptId; + + return sCreatureMovementScripts.find(scriptId) != sCreatureMovementScripts.end(); +} + +inline void CheckWPText(std::string table, uint32 entryOrGuid, uint32 point, WaypointBehavior* be) +{ + int zeroCount = 0; // Counting leading zeros for futher textid shift + for (int j = 0; j < MAX_WAYPOINT_TEXT; ++j) { - std::string text2 = text; - WorldDatabase.escape_string(text2); - WorldDatabase.PExecuteLog("UPDATE creature_movement SET %s='%s' WHERE id='%u' AND point='%u'", field.c_str(), text2.c_str(), id, point); - } + if (!be->textid[j]) + { + ++zeroCount; + continue; + } + if (!sObjectMgr.GetBroadcastTextLocale(be->textid[j])) + { + sLog.outErrorDb("Table %s %u, PointId %u has textid%u with non existing textid %i.", + table.c_str(), entryOrGuid, point, j, be->textid[j]); + be->textid[j] = 0; + ++zeroCount; + continue; + } - WaypointPathMap::iterator itr = m_pathMap.find(id); - if (itr != m_pathMap.end() && point <= itr->second.size()) - { - WaypointNode &node = itr->second[point - 1]; - if (!node.behavior) node.behavior = new WaypointBehavior(); - -// if(field == "text1") node.behavior->text[0] = text ? text : ""; -// if(field == "text2") node.behavior->text[1] = text ? text : ""; -// if(field == "text3") node.behavior->text[2] = text ? text : ""; -// if(field == "text4") node.behavior->text[3] = text ? text : ""; -// if(field == "text5") node.behavior->text[4] = text ? text : ""; - if (field == "emote") node.behavior->emote = text ? atoi(text) : 0; - if (field == "spell") node.behavior->spell = text ? atoi(text) : 0; - if (field == "model1") node.behavior->model1 = text ? atoi(text) : 0; - if (field == "model2") node.behavior->model2 = text ? atoi(text) : 0; + // Shifting check + if (zeroCount) + { + // Correct textid but some zeros leading, so move it forward. + be->textid[j - zeroCount] = be->textid[j]; + be->textid[j] = 0; + } } } void WaypointManager::CheckTextsExistance() { - WaypointPathMap::const_iterator pmItr = m_pathMap.begin(); - for (; pmItr != m_pathMap.end(); ++pmItr) + for (WaypointPathMap::const_iterator pmItr = m_pathMap.begin(); pmItr != m_pathMap.end(); ++pmItr) { - for (size_t i = 0; i < pmItr->second.size(); ++i) - { - WaypointBehavior* be = pmItr->second[i].behavior; - if (!be) - continue; - - // Now we check text existence and put all zero texts ids to the end of array - - // Counting leading zeros for futher textid shift - int zeroCount = 0; - for (int j = 0; j < MAX_WAYPOINT_TEXT; ++j) + for (WaypointPath::const_iterator pItr = pmItr->second.begin(); pItr != pmItr->second.end(); ++pItr) + if (pItr->second.behavior) { - if (!be->textid[j]) - { - ++zeroCount; - continue; - } - else - { - if (!sObjectMgr.GetBroadcastTextLocale(be->textid[j])) - { - sLog.outErrorDb("Some waypoint has textid%u with not existing %u broadcast text.", j, be->textid[j]); - be->textid[j] = 0; - ++zeroCount; - continue; - } - - // Shifting check - if (zeroCount) - { - // Correct textid but some zeros leading, so move it forward. - be->textid[j - zeroCount] = be->textid[j]; - be->textid[j] = 0; - } - } + CheckWPText("`creature_movement` Id:", pmItr->first, pItr->first, pItr->second.behavior); } - } } - WaypointPathTemplateMap::const_iterator wptItr = m_pathTemplateMap.begin(); - for (; wptItr != m_pathTemplateMap.end(); ++wptItr) + for (WaypointPathMap::const_iterator pmItr = m_pathTemplateMap.begin(); pmItr != m_pathTemplateMap.end(); ++pmItr) { - for (size_t i = 0; i < wptItr->second.size(); ++i) - { - WaypointBehavior* be = wptItr->second[i].behavior; - if (!be) - continue; - - // Now we check text existence and put all zero texts ids to the end of array - - // Counting leading zeros for futher textid shift - int zeroCount = 0; - for (int j = 0; j < MAX_WAYPOINT_TEXT; ++j) + for (WaypointPath::const_iterator pItr = pmItr->second.begin(); pItr != pmItr->second.end(); ++pItr) + if (pItr->second.behavior) { - if (!be->textid[j]) - { - ++zeroCount; - continue; - } - else - { - if (!sObjectMgr.GetBroadcastTextLocale(be->textid[j])) - { - sLog.outErrorDb("Some waypoint has textid%u with not existing %u broadcast text.", j, be->textid[j]); - be->textid[j] = 0; - ++zeroCount; - continue; - } - - // Shifting check - if (zeroCount) - { - // Correct textid but some zeros leading, so move it forward. - be->textid[j - zeroCount] = be->textid[j]; - be->textid[j] = 0; - } - } + CheckWPText("`creature_movement_template` Entry:", pmItr->first, pItr->first, pItr->second.behavior); + } + } + + for (WaypointPathMap::const_iterator pmItr = m_pathSpecialMap.begin(); pmItr != m_pathSpecialMap.end(); ++pmItr) + { + for (WaypointPath::const_iterator pItr = pmItr->second.begin(); pItr != pmItr->second.end(); ++pItr) + if (pItr->second.behavior) + { + CheckWPText("`creature_movement_special` Id:", pmItr->first, pItr->first, pItr->second.behavior); } - } } } diff --git a/src/game/Movement/WaypointManager.h b/src/game/Movement/WaypointManager.h index 63957a8af..576572e1b 100644 --- a/src/game/Movement/WaypointManager.h +++ b/src/game/Movement/WaypointManager.h @@ -28,6 +28,14 @@ #include "Utilities/UnorderedMapSet.h" #include "Policies/Singleton.h" +enum WaypointPathOrigin +{ + PATH_NO_PATH = 0, + PATH_FROM_GUID = 1, + PATH_FROM_ENTRY = 2, + PATH_FROM_SPECIAL = 3 +}; + #define MAX_WAYPOINT_TEXT 5 struct WaypointBehavior { @@ -56,7 +64,7 @@ struct WaypointNode : x(_x), y(_y), z(_z), orientation(_o), delay(_delay), script_id(_script_id), behavior(_behavior) {} }; -typedef std::vector WaypointPath; +typedef std::map < uint32 /*pointId*/, WaypointNode > WaypointPath; class WaypointManager { @@ -69,35 +77,117 @@ class WaypointManager void Cleanup(); - WaypointPath *GetPath(uint32 id) + // We may get a path for several occasions: + + // 1: When creature.MovementType=2 + // 1a) Path is selected by creature.guid == creature_movement.id + // 1b) Path for 1a) does not exist and then use path from creature.GetEntry() == creature_movement_template.entry + + // 2: When creature_template.MovementType=2 + // 2a) Creature is summoned and has creature_template.MovementType=2 + // Creators need to be sure that creature_movement_template is always valid for summons. + // Mob that can be summoned anywhere should not have creature_movement_template for example. + + WaypointPath* GetDefaultPath(uint32 entry, uint32 lowGuid, WaypointPathOrigin* wpOrigin = NULL) { - WaypointPathMap::iterator itr = m_pathMap.find(id); - return itr != m_pathMap.end() ? &itr->second : NULL; + WaypointPath* path = NULL; + path = GetPath(lowGuid); + if (path && wpOrigin) + *wpOrigin = PATH_FROM_GUID; + + // No movement found for guid + if (!path) + { + path = GetPathTemplate(entry); + if (path && wpOrigin) + *wpOrigin = PATH_FROM_ENTRY; + } + + return path; } - WaypointPath *GetPathTemplate(uint32 entry) + // Helper function to get a path provided the required information + WaypointPath* GetPathFromOrigin(uint32 entry, uint32 lowGuid, int32 pathId, WaypointPathOrigin wpOrigin) { - WaypointPathTemplateMap::iterator itr = m_pathTemplateMap.find(entry); - return itr != m_pathTemplateMap.end() ? &itr->second : NULL; + WaypointPathMap* wpMap = nullptr; + uint32 key = 0; + + switch (wpOrigin) + { + case PATH_FROM_GUID: + key = lowGuid; + wpMap = &m_pathMap; + break; + case PATH_FROM_ENTRY: + if (pathId >= 0xFF || pathId < 0) + return nullptr; + key = (entry << 8) + pathId; + wpMap = &m_pathTemplateMap; + break; + case PATH_FROM_SPECIAL: + key = entry; + wpMap = &m_pathSpecialMap; + break; + case PATH_NO_PATH: + default: + return nullptr; + } + WaypointPathMap::iterator find = wpMap->find(key); + return find != wpMap->end() ? &find->second : nullptr; } - void AddLastNode(uint32 id, float x, float y, float z, float o, uint32 delay, uint32 wpGuid); - void AddAfterNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid); - uint32 GetLastPoint(uint32 id, uint32 default_notfound); - void DeleteNode(uint32 id, uint32 point); void DeletePath(uint32 id); - void SetNodePosition(uint32 id, uint32 point, float x, float y, float z); - void SetNodeText(uint32 id, uint32 point, const char *text_field, const char *text); void CheckTextsExistance(); - private: - void _addNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid); - void _clearPath(WaypointPath &path); + // Toolbox for .wp add command + /// Add a node as position pointId. If pointId == 0 then as last point + WaypointNode const* AddNode(uint32 entry, uint32 dbGuid, uint32& pointId, WaypointPathOrigin wpDest, float x, float y, float z); - typedef UNORDERED_MAP WaypointPathMap; + // Toolbox for .wp modify command + void DeleteNode(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin); + void SetNodePosition(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float x, float y, float z); + void SetNodeWaittime(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 waittime); + void SetNodeOrientation(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, float orientation); + bool SetNodeScriptId(uint32 entry, uint32 dbGuid, uint32 point, int32 pathId, WaypointPathOrigin wpOrigin, uint32 scriptId); + + // Small Helper for nice output + static std::string GetOriginString(WaypointPathOrigin origin) + { + switch (origin) + { + case PATH_NO_PATH: return ""; + case PATH_FROM_GUID: return "guid"; + case PATH_FROM_ENTRY: return "entry"; + case PATH_FROM_SPECIAL: return "special"; + default: return "invalid origin"; + } + } + + private: + WaypointPath* GetPath(uint32 id) + { + WaypointPathMap::iterator itr = m_pathMap.find(id); + return itr != m_pathMap.end() ? &itr->second : nullptr; + } + + WaypointPath* GetPathTemplate(uint32 entry) + { + WaypointPathMap::iterator itr = m_pathTemplateMap.find((entry << 8) /*+ pathId*/); + return itr != m_pathTemplateMap.end() ? &itr->second : nullptr; + } + + WaypointPath* GetPathSpecial(uint32 id) + { + WaypointPathMap::iterator itr = m_pathSpecialMap.find(id); + return itr != m_pathSpecialMap.end() ? &itr->second : nullptr; + } + + void _clearPath(WaypointPath& path); + + typedef UNORDERED_MAP < uint32 /*guidOrEntry*/, WaypointPath > WaypointPathMap; WaypointPathMap m_pathMap; - typedef UNORDERED_MAP WaypointPathTemplateMap; - WaypointPathTemplateMap m_pathTemplateMap; + WaypointPathMap m_pathTemplateMap; + WaypointPathMap m_pathSpecialMap; }; #define sWaypointMgr MaNGOS::Singleton::Instance() diff --git a/src/game/Movement/WaypointMovementGenerator.cpp b/src/game/Movement/WaypointMovementGenerator.cpp index f07c889db..fdacfc867 100644 --- a/src/game/Movement/WaypointMovementGenerator.cpp +++ b/src/game/Movement/WaypointMovementGenerator.cpp @@ -32,47 +32,61 @@ #include //-----------------------------------------------// -void WaypointMovementGenerator::LoadPath(Creature &creature) +void WaypointMovementGenerator::LoadPath(Creature &creature, int32 pathId, WaypointPathOrigin wpOrigin, uint32 overwriteEntry) { DETAIL_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "LoadPath: loading waypoint path for %s", creature.GetGuidStr().c_str()); - i_path = sWaypointMgr.GetPath(creature.GetGUIDLow()); + if (!overwriteEntry) + overwriteEntry = creature.GetEntry(); - // We may LoadPath() for several occasions: + if (wpOrigin == PATH_NO_PATH && pathId == 0) + i_path = sWaypointMgr.GetDefaultPath(overwriteEntry, creature.GetGUIDLow(), &m_PathOrigin); + else + { + m_PathOrigin = wpOrigin == PATH_NO_PATH ? PATH_FROM_ENTRY : wpOrigin; + i_path = sWaypointMgr.GetPathFromOrigin(overwriteEntry, creature.GetGUIDLow(), pathId, m_PathOrigin); + } + m_pathId = pathId; - // 1: When creature.MovementType=2 - // 1a) Path is selected by creature.guid == creature_movement.id - // 1b) Path for 1a) does not exist and then use path from creature.GetEntry() == creature_movement_template.entry - - // 2: When creature_template.MovementType=2 - // 2a) Creature is summoned and has creature_template.MovementType=2 - // Creators need to be sure that creature_movement_template is always valid for summons. - // Mob that can be summoned anywhere should not have creature_movement_template for example. - - // No movement found for guid + // No movement found for entry nor guid if (!i_path) { - i_path = sWaypointMgr.GetPathTemplate(creature.GetEntry()); - - // No movement found for entry - if (!i_path) - { - sLog.outErrorDb("WaypointMovementGenerator::LoadPath: creature %s (Entry: %u GUID: %u) doesn't have waypoint path", - creature.GetName(), creature.GetEntry(), creature.GetGUIDLow()); - return; - } + sLog.outErrorDb("WaypointMovementGenerator::LoadPath: %s doesn't have waypoint path %i", creature.GetGuidStr().c_str(), pathId); + return; } - StartMoveNow(creature); + if (i_path->empty()) + { + return; + } + // Initialize the i_currentNode to point to the first node + i_currentNode = i_path->begin()->first; m_lastReachedWaypoint = 0; } void WaypointMovementGenerator::Initialize(Creature &creature) { - LoadPath(creature); creature.addUnitState(UNIT_STAT_ROAMING | UNIT_STAT_ROAMING_MOVE); } +void WaypointMovementGenerator::InitializeWaypointPath(Creature& u, int32 id, uint32 startPoint, WaypointPathOrigin wpSource, uint32 initialDelay, uint32 overwriteEntry, bool repeat) +{ + m_repeating = repeat; + LoadPath(u, id, wpSource, overwriteEntry); + + if (startPoint) + { + if (i_path && !i_path->empty() && (i_path->find(startPoint) != i_path->end())) + i_currentNode = startPoint; + else + sLog.outError("WaypointMovementGenerator::InitializeWaypointPath: %s tries to start movement from invalid point id %u", u.GetGuidStr().c_str(), startPoint); + } + + i_nextMoveTime.Reset(initialDelay); + // Start moving if possible + StartMove(u); +} + void WaypointMovementGenerator::Finalize(Creature &creature) { creature.clearUnitState(UNIT_STAT_ROAMING | UNIT_STAT_ROAMING_MOVE); @@ -104,14 +118,18 @@ void WaypointMovementGenerator::OnArrived(Creature& creature) creature.clearUnitState(UNIT_STAT_ROAMING_MOVE); m_isArrivalDone = true; - if (i_path->at(i_currentNode).script_id) + WaypointPath::const_iterator currPoint = i_path->find(i_currentNode); + MANGOS_ASSERT(currPoint != i_path->end()); + WaypointNode const& node = currPoint->second; + + if (node.script_id) { - DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", i_path->at(i_currentNode).script_id, i_currentNode, creature.GetGuidStr().c_str()); - creature.GetMap()->ScriptsStart(sCreatureMovementScripts, i_path->at(i_currentNode).script_id, &creature, &creature); + DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "Creature movement start script %u at point %u for %s.", node.script_id, i_currentNode, creature.GetGuidStr().c_str()); + creature.GetMap()->ScriptsStart(sCreatureMovementScripts, node.script_id, &creature, &creature); } // We have reached the destination and can process behavior - if (WaypointBehavior *behavior = i_path->at(i_currentNode).behavior) + if (WaypointBehavior* behavior = node.behavior) { if (behavior->emote != 0) creature.HandleEmote(behavior->emote); @@ -124,6 +142,7 @@ void WaypointMovementGenerator::OnArrived(Creature& creature) if (behavior->textid[0]) { + int32 textId = behavior->textid[0]; // Not only one text is set if (behavior->textid[1]) { @@ -135,16 +154,24 @@ void WaypointMovementGenerator::OnArrived(Creature& creature) break; } - creature.MonsterSay(behavior->textid[rand() % i], LANG_UNIVERSAL); + textId = behavior->textid[urand(0, i - 1)]; } - else - creature.MonsterSay(behavior->textid[0], LANG_UNIVERSAL); + + DoScriptText(textId, &creature); } } // Inform script - MovementInform(creature); - Stop(i_path->at(i_currentNode).delay); + if (creature.AI()) + { + uint32 type = WAYPOINT_MOTION_TYPE; + if (m_PathOrigin == PATH_FROM_SPECIAL && m_pathId > 0) + type = WAYPOINT_SPECIAL_REACHED + m_pathId; + creature.AI()->MovementInform(type, i_currentNode); + } + + // Wait delay ms + Stop(node.delay); } void WaypointMovementGenerator::StartMove(Creature &creature) @@ -155,6 +182,9 @@ void WaypointMovementGenerator::StartMove(Creature &creature) if (Stopped()) return; + WaypointPath::const_iterator currPoint = i_path->find(i_currentNode); + MANGOS_ASSERT(currPoint != i_path->end()); + if (WaypointBehavior *behavior = i_path->at(i_currentNode).behavior) { if (behavior->model2 != 0) @@ -164,27 +194,48 @@ void WaypointMovementGenerator::StartMove(Creature &creature) if (m_isArrivalDone) { - if ((i_currentNode == i_path->size() - 1) && !m_repeating) // If that's our last waypoint + bool reachedLast = false; + ++currPoint; + if (currPoint == i_path->end()) { - creature.SetHomePosition(i_path->at(i_currentNode).x, i_path->at(i_currentNode).y, i_path->at(i_currentNode).z, i_path->at(i_currentNode).orientation); - creature.GetMotionMaster()->Initialize(); - return; + reachedLast = true; + + if (!m_repeating) + { + creature.SetHomePosition(i_path->at(i_currentNode).x, i_path->at(i_currentNode).y, i_path->at(i_currentNode).z, i_path->at(i_currentNode).orientation); + creature.GetMotionMaster()->Initialize(); + return; + } + + currPoint = i_path->begin(); } - i_currentNode = (i_currentNode + 1) % i_path->size(); + + // Inform AI + if (creature.AI() && m_PathOrigin == PATH_FROM_SPECIAL && m_pathId > 0) + { + if (!reachedLast) + creature.AI()->MovementInform(WAYPOINT_SPECIAL_STARTED + m_pathId, currPoint->first); + else + creature.AI()->MovementInform(WAYPOINT_SPECIAL_FINISHED_LAST + m_pathId, currPoint->first); + + if (creature.isDead() || !creature.IsInWorld()) // Might have happened with above calls + return; + } + + i_currentNode = currPoint->first; } m_isArrivalDone = false; creature.addUnitState(UNIT_STAT_ROAMING_MOVE); - ASSERT(i_currentNode < i_path->size()); - const WaypointNode &node = i_path->at(i_currentNode); + WaypointNode const& nextNode = currPoint->second;; creature.SetWalk(!creature.hasUnitState(UNIT_STAT_RUNNING) && !creature.IsLevitating(), false); Movement::MoveSplineInit init(creature, "WaypointMovementGenerator::StartMove"); - init.MoveTo(node.x, node.y, node.z, MOVE_PATHFINDING); + init.MoveTo(nextNode.x, nextNode.y, nextNode.z, MOVE_PATHFINDING); - if (node.orientation != 100 && node.delay != 0) - init.SetFacing(node.orientation); + if (nextNode.orientation != 100 && nextNode.delay != 0) + init.SetFacing(nextNode.orientation); init.Launch(); } @@ -221,25 +272,55 @@ bool WaypointMovementGenerator::Update(Creature &creature, const uint3 return true; } -void WaypointMovementGenerator::MovementInform(Creature &creature) -{ - if (creature.AI()) - creature.AI()->MovementInform(WAYPOINT_MOTION_TYPE, i_currentNode); -} - bool WaypointMovementGenerator::GetResetPosition(Creature&, float& x, float& y, float& z) { // prevent a crash at empty waypoint path. if (!i_path || i_path->empty()) return false; - const WaypointNode& node = i_path->at(i_currentNode); + const WaypointNode& node = i_path->at(m_lastReachedWaypoint); x = node.x; y = node.y; z = node.z; return true; } +void WaypointMovementGenerator::GetPathInformation(std::ostringstream& oss) const +{ + oss << "WaypointMovement: Last Reached WP: " << m_lastReachedWaypoint << " "; + oss << "(Loaded path " << m_pathId << " from " << WaypointManager::GetOriginString(m_PathOrigin) << ")\n"; +} + +void WaypointMovementGenerator::AddToWaypointPauseTime(int32 waitTimeDiff) +{ + if (!i_nextMoveTime.Passed()) + { + // Prevent <= 0, the code in Update requires to catch the change from moving to not moving + int32 newWaitTime = i_nextMoveTime.GetExpiry() + waitTimeDiff; + i_nextMoveTime.Reset(newWaitTime > 0 ? newWaitTime : 1); + } +} + +bool WaypointMovementGenerator::SetNextWaypoint(uint32 pointId) +{ + if (!i_path || i_path->empty()) + return false; + + WaypointPath::const_iterator currPoint = i_path->find(pointId); + if (currPoint == i_path->end()) + return false; + + // Allow Moving with next tick + // Handle allow movement this way to not interact with PAUSED state. + // If this function is called while PAUSED, it will move properly when unpaused. + i_nextMoveTime.Reset(1); + m_isArrivalDone = false; + + // Set the point + i_currentNode = pointId; + return true; +} + //----------------------------------------------------// uint32 FlightPathMovementGenerator::GetPathAtMapEnd() const { @@ -377,16 +458,6 @@ bool FlightPathMovementGenerator::GetResetPosition(Player&, float& x, float& y, return true; } -void WaypointMovementGenerator::AddToWaypointPauseTime(int32 waitTimeDiff) -{ - if (!i_nextMoveTime.Passed()) - { - // Prevent <= 0, the code in Update requires to catch the change from moving to not moving - int32 newWaitTime = i_nextMoveTime.GetExpiry() + waitTimeDiff; - i_nextMoveTime.Reset(newWaitTime > 0 ? newWaitTime : 1); - } -} - // ------------------------------------------------------ // -- PATROLS SYSTEM bool PatrolMovementGenerator::InitPatrol(Creature& creature) diff --git a/src/game/Movement/WaypointMovementGenerator.h b/src/game/Movement/WaypointMovementGenerator.h index 5c00831cd..a5d7f9d17 100644 --- a/src/game/Movement/WaypointMovementGenerator.h +++ b/src/game/Movement/WaypointMovementGenerator.h @@ -67,7 +67,7 @@ class MANGOS_DLL_SPEC WaypointMovementGenerator; template<> class MANGOS_DLL_SPEC WaypointMovementGenerator : public MovementGeneratorMedium< Creature, WaypointMovementGenerator >, -public PathMovementBase + public PathMovementBase { public: WaypointMovementGenerator(Creature &, bool repeating = true) : i_nextMoveTime(0), m_isArrivalDone(false), m_repeating(repeating), m_lastReachedWaypoint(0) {} @@ -77,21 +77,20 @@ public PathMovementBase void Finalize(Creature &); void Reset(Creature &u); bool Update(Creature &u, const uint32 &diff); - - void MovementInform(Creature &); + void InitializeWaypointPath(Creature& u, int32 id, uint32 startPoint, WaypointPathOrigin wpSource, uint32 initialDelay, uint32 overwriteEntry, bool repeat); MovementGeneratorType GetMovementGeneratorType() const { return WAYPOINT_MOTION_TYPE; } // now path movement implementation - void LoadPath(Creature &c); bool GetResetPosition(Creature&, float& x, float& y, float& z); + uint32 getLastReachedWaypoint() const { return m_lastReachedWaypoint; } + void GetPathInformation(int32& pathId, WaypointPathOrigin& wpOrigin) const { pathId = m_pathId; wpOrigin = m_PathOrigin; } + void GetPathInformation(std::ostringstream& oss) const; void AddToWaypointPauseTime(int32 waitTimeDiff); - - uint32 getLastReachedWaypoint() const { return m_lastReachedWaypoint; } - + bool SetNextWaypoint(uint32 pointId); protected: - + void LoadPath(Creature& c, int32 id, WaypointPathOrigin wpOrigin, uint32 overwriteEntry); void Stop(int32 time) { i_nextMoveTime.Reset(time);} bool Stopped() { return !i_nextMoveTime.Passed();} @@ -115,6 +114,9 @@ public PathMovementBase bool m_isArrivalDone; bool m_repeating; uint32 m_lastReachedWaypoint; + + int32 m_pathId; + WaypointPathOrigin m_PathOrigin; }; /** FlightPathMovementGenerator generates movement of the player for the paths @@ -122,7 +124,7 @@ public PathMovementBase */ class MANGOS_DLL_SPEC FlightPathMovementGenerator : public MovementGeneratorMedium< Player, FlightPathMovementGenerator >, -public PathMovementBase + public PathMovementBase { public: explicit FlightPathMovementGenerator(TaxiPathNodeList const& pathnodes, uint32 startNode = 0) diff --git a/src/game/Objects/Creature.cpp b/src/game/Objects/Creature.cpp index 5bf038a0b..395974c7a 100644 --- a/src/game/Objects/Creature.cpp +++ b/src/game/Objects/Creature.cpp @@ -177,7 +177,7 @@ Creature::Creature(CreatureSubtype subtype) : m_combatStartX(0.0f), m_combatStartY(0.0f), m_combatStartZ(0.0f), m_HomeX(0.0f), m_HomeY(0.0f), m_HomeZ(0.0f), m_HomeOrientation(0.0f), m_reactState(REACT_PASSIVE), m_CombatDistance(0.0f), _lastDamageTakenForEvade(0), _playerDamageTaken(0), _nonPlayerDamageTaken(0), m_creatureInfo(nullptr), - m_AI_InitializeOnRespawn(false), m_callForHelpDist(5.0f), m_combatWithZoneState(false) + m_AI_InitializeOnRespawn(false), m_callForHelpDist(5.0f), m_combatWithZoneState(false), m_startwaypoint(0) { m_regenTimer = 200; m_valuesCount = UNIT_END; @@ -353,6 +353,9 @@ bool Creature::InitEntry(uint32 Entry, Team team, CreatureData const* data /*=NU UpdateSpeed(MOVE_RUN, false); SetFly(CanFly()); + if (data) + m_startwaypoint = data->currentwaypoint; + // checked at loading m_defaultMovementType = MovementGeneratorType(cinfo->MovementType); @@ -766,7 +769,7 @@ void Creature::Update(uint32 update_diff, uint32 diff) GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && !HasDistanceCasterMovement() && (!CanReachWithMeleeAttack(getVictim()) || !IsWithinLOSInMap(getVictim())) && - !GetMotionMaster()->operator->()->IsReachable(); + !GetMotionMaster()->GetCurrent()->IsReachable(); // No evade mode for pets. if (unreachableTarget && GetCharmerOrOwnerGuid().IsPlayer()) unreachableTarget = false; @@ -3501,7 +3504,7 @@ SpellCastResult Creature::TryToCast(Unit* pTarget, const SpellEntry* pSpellInfo, return SPELL_FAILED_TOO_CLOSE; // This spell should only be cast when we cannot get into melee range. - if ((uiCastFlags & CF_TARGET_UNREACHABLE) && (CanReachWithMeleeAttack(pTarget) || (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE) || !(hasUnitState(UNIT_STAT_NOT_MOVE) || !GetMotionMaster()->operator->()->IsReachable()))) + if ((uiCastFlags & CF_TARGET_UNREACHABLE) && (CanReachWithMeleeAttack(pTarget) || (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE) || !(hasUnitState(UNIT_STAT_NOT_MOVE) || !GetMotionMaster()->GetCurrent()->IsReachable()))) return SPELL_FAILED_MOVING; // Custom checks diff --git a/src/game/Objects/Creature.h b/src/game/Objects/Creature.h index 5a461f2b9..65296a841 100644 --- a/src/game/Objects/Creature.h +++ b/src/game/Objects/Creature.h @@ -813,6 +813,8 @@ class MANGOS_DLL_SPEC Creature : public Unit bool _manaRegen; uint32 m_manaRegen; + uint32 m_startwaypoint; // currentwaypoint from creature table + void RegenerateHealth(); void RegenerateMana(); diff --git a/src/game/Objects/TemporarySummon.cpp b/src/game/Objects/TemporarySummon.cpp index 8678733ef..be3f7480c 100644 --- a/src/game/Objects/TemporarySummon.cpp +++ b/src/game/Objects/TemporarySummon.cpp @@ -278,3 +278,11 @@ TemporarySummon::~TemporarySummon() void TemporarySummon::SaveToDB() { } + +TemporarySummonWaypoint::TemporarySummonWaypoint(ObjectGuid summoner, uint32 waypoint_id, int32 path_id, uint32 pathOrigin) : + TemporarySummon(summoner), + m_waypoint_id(waypoint_id), + m_path_id(path_id), + m_pathOrigin(pathOrigin) +{ +} \ No newline at end of file diff --git a/src/game/Objects/TemporarySummon.h b/src/game/Objects/TemporarySummon.h index dda3a671a..01b0910df 100644 --- a/src/game/Objects/TemporarySummon.h +++ b/src/game/Objects/TemporarySummon.h @@ -48,4 +48,20 @@ class TemporarySummon : public Creature bool m_unSummonInformed; void InformSummonerOfDespawn(); }; + +class TemporarySummonWaypoint : public TemporarySummon +{ + public: + explicit TemporarySummonWaypoint(ObjectGuid summoner, uint32 waypoint_id, int32 path_id, uint32 pathOrigin); + + uint32 GetWaypointId() const { return m_waypoint_id; } + int32 GetPathId() const { return m_path_id; } + uint32 GetPathOrigin() const { return m_pathOrigin; } + + private: + uint32 m_waypoint_id; + int32 m_path_id; + uint32 m_pathOrigin; +}; + #endif diff --git a/src/game/ScriptMgr.cpp b/src/game/ScriptMgr.cpp index b74e97d19..486e3a81c 100644 --- a/src/game/ScriptMgr.cpp +++ b/src/game/ScriptMgr.cpp @@ -974,6 +974,24 @@ void ScriptMgr::LoadScripts(ScriptMapMap& scripts, const char* tablename) } break; } + case SCRIPT_COMMAND_SET_REACT_STATE: + { + if (tmp.setReactState.state > REACT_AGGRESSIVE) + { + sLog.outErrorDb("Table `%s` has datalong = %u in SCRIPT_COMMAND_SET_REACT_STATE for script id %u.", tablename, tmp.setReactState.state, tmp.id); + continue; + } + break; + } + case SCRIPT_COMMAND_START_WAYPOINTS: + { + if (tmp.startWaypoints.wpSource > PATH_FROM_SPECIAL) + { + sLog.outErrorDb("Table `%s` has datalong = %u in SCRIPT_COMMAND_START_WAYPOINTS for script id %u.", tablename, tmp.startWaypoints.wpSource, tmp.id); + continue; + } + break; + } } if (scripts.find(tmp.id) == scripts.end()) diff --git a/src/game/ScriptMgr.h b/src/game/ScriptMgr.h index 089192768..3f9ae5d79 100644 --- a/src/game/ScriptMgr.h +++ b/src/game/ScriptMgr.h @@ -68,6 +68,7 @@ enum eScriptCommand // datalong2 = time // datalong3 = movement_options (see enum MoveOptions) // datalong4 = eMoveToFlags + // dataint = path_id // x/y/z/o = coordinates SCRIPT_COMMAND_MODIFY_FLAGS = 4, // source = Object // datalong = field_id @@ -242,6 +243,13 @@ enum eScriptCommand // datalong = spell_id SCRIPT_COMMAND_SET_REACT_STATE = 59, // source = Creature // datalong = see enum ReactStates + SCRIPT_COMMAND_START_WAYPOINTS = 60, // source = Creature + // datalong = waypoints_source + // datalong2 = start_point + // datalong3 = initial_delay + // datalong4 = (bool) repeat + // dataint = path_id + // dataint2 = overwrite_entry SCRIPT_COMMAND_MAX, @@ -405,6 +413,8 @@ struct ScriptInfo uint32 travelTime; // datalong2 uint32 movementOptions; // datalong3 uint32 flags; // datalong4 + uint32 unused; // data_flags + int32 pointId; // dataint } moveTo; struct // SCRIPT_COMMAND_MODIFY_FLAGS (4) @@ -724,6 +734,17 @@ struct ScriptInfo uint32 state; // datalong } setReactState; + struct // SCRIPT_COMMAND_START_WAYPOINTS (60) + { + uint32 wpSource; // datalong + uint32 startPoint; // datalong2 + uint32 initialDelay; // datalong3 + uint32 canRepeat; // datalong4 + uint32 unused; // data_flags + int32 pathId; // dataint + int32 overwriteEntry; // dataint2 + } startWaypoints; + struct { uint32 data[9]; diff --git a/src/game/Spells/SpellEffects.cpp b/src/game/Spells/SpellEffects.cpp index c8e6bcf27..03aeb5ce6 100644 --- a/src/game/Spells/SpellEffects.cpp +++ b/src/game/Spells/SpellEffects.cpp @@ -3566,7 +3566,7 @@ void Spell::EffectSummonGuardian(SpellEffectIndex eff_idx) spawnCreature->GetMotionMaster()->MoveFollow(pCreature, 0.6f, M_PI_F); pCreature->MonsterSay(-1900171); pCreature->SetWalk(false); - pCreature->GetMotionMaster()->MoveWaypoint(false); + pCreature->GetMotionMaster()->MoveWaypoint(0, 0, 0, 0, 0, false); } break; case 976: // Tanaris @@ -3575,7 +3575,7 @@ void Spell::EffectSummonGuardian(SpellEffectIndex eff_idx) spawnCreature->GetMotionMaster()->MoveFollow(pCreature, 0.6f, M_PI_F); pCreature->MonsterTextEmote(-1900172); pCreature->SetWalk(false); - pCreature->GetMotionMaster()->MoveWaypoint(false); + pCreature->GetMotionMaster()->MoveWaypoint(0, 0, 0, 0, 0, false); } break; case 2255: // Winterspring @@ -3584,7 +3584,7 @@ void Spell::EffectSummonGuardian(SpellEffectIndex eff_idx) spawnCreature->GetMotionMaster()->MoveFollow(pCreature, 0.6f, M_PI_F); pCreature->MonsterTextEmote(-1900173); pCreature->SetWalk(false); - pCreature->GetMotionMaster()->MoveWaypoint(false); + pCreature->GetMotionMaster()->MoveWaypoint(0, 0, 0, 0, 0, false); } break; } diff --git a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp index 505ca6802..3c8e3b6bb 100644 --- a/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp +++ b/src/scripts/eastern_kingdoms/eastern_plaguelands/naxxramas/boss_sapphiron.cpp @@ -437,7 +437,7 @@ struct boss_sapphironAI : public ScriptedAI m_creature->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE && !m_creature->HasDistanceCasterMovement() && (!m_creature->IsWithinDistInMap(m_creature->getVictim(), m_creature->GetMaxChaseDistance(m_creature->getVictim())) || !m_creature->IsWithinLOSInMap(m_creature->getVictim())) && - !m_creature->GetMotionMaster()->operator->()->IsReachable(); + !m_creature->GetMotionMaster()->GetCurrent()->IsReachable(); if (unreachableTarget) { diff --git a/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/boss_rajaxx.cpp b/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/boss_rajaxx.cpp index 3a817a883..d117e6d12 100644 --- a/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/boss_rajaxx.cpp +++ b/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/boss_rajaxx.cpp @@ -482,7 +482,7 @@ struct npc_andorovAI : public ScriptedAI { DoScriptText(SAY_ANDOROV_INTRO, m_creature); - m_creature->GetMotionMaster()->MoveWaypoint(false); + m_creature->GetMotionMaster()->MoveWaypoint(0, 0, 0, 0, 0, false); m_pInstance->SetData(TYPE_GENERAL_ANDOROV, IN_PROGRESS); }