2010-11-16 21:27:25 +01:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-11-16 21:27:25 +01:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: wp_commandscript
%Complete: 100
Comment: All wp related commands
Category: commandscripts
EndScriptData */
2017-05-20 00:09:37 +02:00
#include "ScriptMgr.h"
2010-11-16 21:27:25 +01:00
#include "Chat.h"
2017-06-04 01:00:45 +02:00
#include "Creature.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2017-06-04 01:00:45 +02:00
#include "Map.h"
#include "MotionMaster.h"
2012-11-20 12:30:30 +01:00
#include "ObjectMgr.h"
2018-01-28 11:37:20 +01:00
#include "PhasingHandler.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2017-05-20 00:09:37 +02:00
#include "RBAC.h"
2017-08-12 01:40:25 +02:00
#include "WaypointDefines.h"
2012-11-20 12:30:30 +01:00
#include "WaypointManager.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2010-11-16 21:27:25 +01:00
class wp_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
wp_commandscript () : CommandScript ( "wp_commandscript" ) { }
2010-11-16 21:27:25 +01:00
2015-10-22 20:26:56 +02:00
std :: vector < ChatCommand > GetCommands () const override
2010-11-16 21:27:25 +01:00
{
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > wpCommandTable =
2010-11-19 14:04:21 +01:00
{
2015-10-22 20:26:56 +02:00
{ "add" , rbac :: RBAC_PERM_COMMAND_WP_ADD , false , & HandleWpAddCommand , "" },
{ "event" , rbac :: RBAC_PERM_COMMAND_WP_EVENT , false , & HandleWpEventCommand , "" },
{ "load" , rbac :: RBAC_PERM_COMMAND_WP_LOAD , false , & HandleWpLoadCommand , "" },
{ "modify" , rbac :: RBAC_PERM_COMMAND_WP_MODIFY , false , & HandleWpModifyCommand , "" },
{ "unload" , rbac :: RBAC_PERM_COMMAND_WP_UNLOAD , false , & HandleWpUnLoadCommand , "" },
{ "reload" , rbac :: RBAC_PERM_COMMAND_WP_RELOAD , false , & HandleWpReloadCommand , "" },
{ "show" , rbac :: RBAC_PERM_COMMAND_WP_SHOW , false , & HandleWpShowCommand , "" },
2010-11-19 14:04:21 +01:00
};
2015-10-22 20:26:56 +02:00
static std :: vector < ChatCommand > commandTable =
2010-11-19 14:04:21 +01:00
{
2020-08-14 17:06:03 +02:00
{ "wp" , rbac :: RBAC_PERM_COMMAND_WP , false , nullptr , "" , wpCommandTable },
2010-11-19 14:04:21 +01:00
};
return commandTable ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
/**
* Add a waypoint to a creature.
*
* The user can either select an npc or provide its GUID.
*
* The user can even select a visual waypoint - then the new waypoint
* is placed *after* the selected one - this makes insertion of new
* waypoints possible.
*
* eg:
* .wp add 12345
* -> adds a waypoint to the npc with the GUID 12345
*
* .wp add
* -> adds a waypoint to the currently selected creature
*
*
* @param args if the user did not provide a GUID, it is NULL
*
* @return true - command did succeed, false - something went wrong
*/
static bool HandleWpAddCommand ( ChatHandler * handler , const char * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// optional
2020-08-14 17:06:03 +02:00
char * path_number = nullptr ;
2010-11-19 14:04:21 +01:00
uint32 pathid = 0 ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( * args )
path_number = strtok (( char * ) args , " " );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 point = 0 ;
Creature * target = handler -> getSelectedCreature ();
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! path_number )
{
if ( target )
pathid = target -> GetWaypointPath ();
else
{
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_MAX_ID );
2012-03-24 01:25:08 +01:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
uint32 maxpathid = result -> Fetch () -> GetInt32 ();
pathid = maxpathid + 1 ;
handler -> PSendSysMessage ( "%s%s|r" , "|cff00ff00" , "New path started." );
}
}
else
pathid = atoi ( path_number );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// path_id -> ID of the Path
// point -> number of the waypoint (if not 0)
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! pathid )
{
handler -> PSendSysMessage ( "%s%s|r" , "|cffff33ff" , "Current creature haven't loaded path." );
return true ;
}
2010-11-16 21:27:25 +01:00
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_MAX_POINT );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , pathid );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( result )
point = ( * result )[ 0 ]. GetUInt32 ();
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
Player * player = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
//Map* map = player->GetMap();
2010-11-16 21:27:25 +01:00
2012-03-24 01:25:08 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_WAYPOINT_DATA );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , pathid );
stmt -> setUInt32 ( 1 , point + 1 );
stmt -> setFloat ( 2 , player -> GetPositionX ());
stmt -> setFloat ( 3 , player -> GetPositionY ());
stmt -> setFloat ( 4 , player -> GetPositionZ ());
WorldDatabase . Execute ( stmt );
2010-11-16 21:27:25 +01:00
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( "%s%s%u%s%u%s|r" , "|cff00ff00" , "PathID: |r|cff00ffff" , pathid , "|r|cff00ff00: Waypoint |r|cff00ffff" , point + 1 , "|r|cff00ff00 created. " );
2010-11-19 14:04:21 +01:00
return true ;
} // HandleWpAddCommand
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
static bool HandleWpLoadCommand ( ChatHandler * handler , const char * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// optional
2020-08-14 17:06:03 +02:00
char * path_number = nullptr ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( * args )
path_number = strtok (( char * ) args , " " );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 pathid = 0 ;
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType guidLow = UI64LIT ( 0 );
2010-11-19 14:04:21 +01:00
Creature * target = handler -> getSelectedCreature ();
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Did player provide a path_id?
if ( ! path_number )
2011-02-20 20:16:34 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( target -> GetEntry () == 1 )
{
handler -> PSendSysMessage ( "%s%s|r" , "|cffff33ff" , "You want to load path to a waypoint? Aren't you?" );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
pathid = atoi ( path_number );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! pathid )
{
2011-02-20 20:16:34 +01:00
handler -> PSendSysMessage ( "%s%s|r" , "|cffff33ff" , "No valid path number provided." );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
2015-02-25 00:13:14 +01:00
guidLow = target -> GetSpawnId ();
2011-12-31 19:06:24 +01:00
2019-07-27 01:00:37 +02:00
WorldDatabasePreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_CREATURE_ADDON_BY_GUID );
2012-03-24 01:25:08 +01:00
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , guidLow );
2012-03-24 01:25:08 +01:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( result )
2011-12-31 19:06:24 +01:00
{
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_ADDON_PATH );
stmt -> setUInt32 ( 0 , pathid );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , guidLow );
2011-12-31 19:06:24 +01:00
}
2010-11-19 14:04:21 +01:00
else
2011-12-31 19:06:24 +01:00
{
stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_CREATURE_ADDON );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , guidLow );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 1 , pathid );
}
WorldDatabase . Execute ( stmt );
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_MOVEMENT_TYPE );
stmt -> setUInt8 ( 0 , uint8 ( WAYPOINT_MOTION_TYPE ));
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , guidLow );
2010-11-16 21:27:25 +01:00
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
target -> LoadPath ( pathid );
target -> SetDefaultMovementType ( WAYPOINT_MOTION_TYPE );
target -> GetMotionMaster () -> Initialize ();
2014-09-13 20:41:31 +02:00
target -> Say ( "Path loaded." , LANG_UNIVERSAL );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
static bool HandleWpReloadCommand ( ChatHandler * handler , const char * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 id = atoi ( args );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! id )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "%s%s|r|cff00ffff%u|r" , "|cff00ff00" , "Loading Path: " , id );
2011-05-24 23:13:47 +02:00
sWaypointMgr -> ReloadPath ( id );
2010-11-19 14:04:21 +01:00
return true ;
}
2012-03-01 12:16:06 +01:00
2010-11-19 14:04:21 +01:00
static bool HandleWpUnLoadCommand ( ChatHandler * handler , const char * /*args*/ )
2010-11-16 21:27:25 +01:00
{
2011-08-30 23:09:39 +03:00
2010-11-19 14:04:21 +01:00
Creature * target = handler -> getSelectedCreature ();
2020-08-14 17:06:03 +02:00
WorldDatabasePreparedStatement * stmt = nullptr ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! target )
2010-11-16 21:27:25 +01:00
{
2012-11-16 09:51:44 +01:00
handler -> PSendSysMessage ( "%s%s|r" , "|cff33ffff" , "You must select a target." );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
2015-02-25 00:13:14 +01:00
ObjectGuid :: LowType guidLow = target -> GetSpawnId ();
2014-10-26 02:57:28 +02:00
if ( ! guidLow )
2012-11-16 09:51:44 +01:00
{
handler -> PSendSysMessage ( "%s%s|r" , "|cffff33ff" , "Target is not saved to DB." );
return true ;
}
2011-08-30 23:09:39 +03:00
2012-11-16 09:51:44 +01:00
CreatureAddon const * addon = sObjectMgr -> GetCreatureAddon ( guidLow );
if ( ! addon || addon -> path_id == 0 )
2010-11-19 14:04:21 +01:00
{
2012-11-16 09:51:44 +01:00
handler -> PSendSysMessage ( "%s%s|r" , "|cffff33ff" , "Target does not have a loaded path." );
return true ;
}
2011-12-31 19:06:24 +01:00
2014-07-14 21:01:55 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE_ADDON );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , guidLow );
2012-11-16 09:51:44 +01:00
WorldDatabase . Execute ( stmt );
2011-12-31 19:06:24 +01:00
2012-11-16 09:51:44 +01:00
target -> UpdateWaypointID ( 0 );
2011-12-31 19:06:24 +01:00
2012-11-16 09:51:44 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_CREATURE_MOVEMENT_TYPE );
stmt -> setUInt8 ( 0 , uint8 ( IDLE_MOTION_TYPE ));
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 1 , guidLow );
2012-11-16 09:51:44 +01:00
WorldDatabase . Execute ( stmt );
target -> LoadPath ( 0 );
target -> SetDefaultMovementType ( IDLE_MOTION_TYPE );
target -> GetMotionMaster () -> MoveTargetedHome ();
target -> GetMotionMaster () -> Initialize ();
2014-09-13 22:38:25 +02:00
target -> Say ( "Path unloaded." , LANG_UNIVERSAL );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
static bool HandleWpEventCommand ( ChatHandler * handler , const char * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
char * show_str = strtok (( char * ) args , " " );
std :: string show = show_str ;
2020-08-14 17:06:03 +02:00
WorldDatabasePreparedStatement * stmt = nullptr ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Check
2012-03-16 19:40:57 +08:00
if (( show != "add" ) && ( show != "mod" ) && ( show != "del" ) && ( show != "listid" ))
return false ;
2010-11-16 21:27:25 +01:00
2020-08-14 17:06:03 +02:00
char * arg_id = strtok ( nullptr , " " );
2010-11-19 14:04:21 +01:00
uint32 id = 0 ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( show == "add" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( arg_id )
2017-07-22 10:22:17 +03:00
id = atoul ( arg_id );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( id )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , id );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! result )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_WAYPOINT_SCRIPT );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , id );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "%s%s%u|r" , "|cff00ff00" , "Wp Event: New waypoint event added: " , id );
}
else
handler -> PSendSysMessage ( "|cff00ff00Wp Event: You have choosed an existing waypoint script guid: %u|r" , id );
}
else
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_SCRIPTS_MAX_ID );
2012-03-24 01:25:08 +01:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
id = result -> Fetch () -> GetUInt32 ();
2012-03-24 01:25:08 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_WAYPOINT_SCRIPT );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , id + 1 );
WorldDatabase . Execute ( stmt );
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( "%s%s%u|r" , "|cff00ff00" , "Wp Event: New waypoint event added: |r|cff00ffff" , id + 1 );
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( show == "listid" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( ! arg_id )
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( "%s%s|r" , "|cff33ffff" , "Wp Event: You must provide waypoint script id." );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
2017-07-22 10:22:17 +03:00
id = atoul ( arg_id );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 a2 , a3 , a4 , a5 , a6 ;
float a8 , a9 , a10 , a11 ;
char const * a7 ;
2010-11-16 21:27:25 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_SCRIPT_BY_ID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , id );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! result )
{
handler -> PSendSysMessage ( "%s%s%u|r" , "|cff33ffff" , "Wp Event: No waypoint scripts found on id: " , id );
return true ;
}
2010-11-16 21:27:25 +01:00
2011-09-15 14:08:17 +02:00
Field * fields ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
do
{
fields = result -> Fetch ();
a2 = fields [ 0 ]. GetUInt32 ();
a3 = fields [ 1 ]. GetUInt32 ();
a4 = fields [ 2 ]. GetUInt32 ();
a5 = fields [ 3 ]. GetUInt32 ();
a6 = fields [ 4 ]. GetUInt32 ();
a7 = fields [ 5 ]. GetCString ();
a8 = fields [ 6 ]. GetFloat ();
a9 = fields [ 7 ]. GetFloat ();
a10 = fields [ 8 ]. GetFloat ();
a11 = fields [ 9 ]. GetFloat ();
handler -> PSendSysMessage ( "|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r" , id , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 , a10 , a11 );
}
while ( result -> NextRow ());
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
if ( show == "del" )
2010-11-16 21:27:25 +01:00
{
2015-12-06 21:02:52 +01:00
if ( ! arg_id )
{
handler -> SendSysMessage ( "|cffff33ffERROR: Waypoint script guid not present.|r" );
return true ;
}
2017-07-22 10:22:17 +03:00
id = atoul ( arg_id );
2010-11-16 21:27:25 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , id );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( result )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_WAYPOINT_SCRIPT );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , id );
WorldDatabase . Execute ( stmt );
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( "%s%s%u|r" , "|cff00ff00" , "Wp Event: Waypoint script removed: " , id );
2010-11-19 14:04:21 +01:00
}
else
handler -> PSendSysMessage ( "|cffff33ffWp Event: ERROR: you have selected a non existing script: %u|r" , id );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
if ( show == "mod" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( ! arg_id )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "|cffff33ffERROR: Waypoint script guid not present.|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
2017-07-22 10:22:17 +03:00
id = atoul ( arg_id );
2010-11-19 14:04:21 +01:00
if ( ! id )
2010-11-16 21:27:25 +01:00
{
2017-07-22 10:22:17 +03:00
handler -> SendSysMessage ( "|cffff33ffERROR: No valid waypoint script id not present.|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
2020-08-14 17:06:03 +02:00
char * arg_2 = strtok ( nullptr , " " );
2010-11-19 14:04:21 +01:00
if ( ! arg_2 )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "|cffff33ffERROR: No argument present.|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
std :: string arg_string = arg_2 ;
if (( arg_string != "setid" ) && ( arg_string != "delay" ) && ( arg_string != "command" )
&& ( arg_string != "datalong" ) && ( arg_string != "datalong2" ) && ( arg_string != "dataint" ) && ( arg_string != "posx" )
&& ( arg_string != "posy" ) && ( arg_string != "posz" ) && ( arg_string != "orientation" ))
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "|cffff33ffERROR: No valid argument present.|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
char * arg_3 ;
std :: string arg_str_2 = arg_2 ;
2020-08-14 17:06:03 +02:00
arg_3 = strtok ( nullptr , " " );
2010-11-19 14:04:21 +01:00
if ( ! arg_3 )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "|cffff33ffERROR: No additional argument present.|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
if ( arg_str_2 == "setid" )
2010-11-16 21:27:25 +01:00
{
2017-07-22 10:22:17 +03:00
uint32 newid = atoul ( arg_3 );
handler -> PSendSysMessage ( "%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r" , "|cff00ff00" , "Wp Event: Waypoint script guid: " , newid , " id changed: " , id );
2011-12-31 19:06:24 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_SCRIPT_ID );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , newid );
stmt -> setUInt32 ( 1 , id );
WorldDatabase . Execute ( stmt );
return true ;
2010-11-16 21:27:25 +01:00
}
else
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_SCRIPT_ID_BY_GUID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , id );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( ! result )
{
handler -> SendSysMessage ( "|cffff33ffERROR: You have selected an non existing waypoint script guid.|r" );
return true ;
}
if ( arg_str_2 == "posx" )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_SCRIPT_X );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 0 , float ( atof ( arg_3 )));
stmt -> setUInt32 ( 1 , id );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r" , id );
return true ;
}
else if ( arg_str_2 == "posy" )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_SCRIPT_Y );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 0 , float ( atof ( arg_3 )));
stmt -> setUInt32 ( 1 , id );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00Waypoint script: %u position_y updated.|r" , id );
return true ;
}
else if ( arg_str_2 == "posz" )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_SCRIPT_Z );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 0 , float ( atof ( arg_3 )));
stmt -> setUInt32 ( 1 , id );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r" , id );
return true ;
}
else if ( arg_str_2 == "orientation" )
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_SCRIPT_O );
2011-12-31 19:06:24 +01:00
stmt -> setFloat ( 0 , float ( atof ( arg_3 )));
stmt -> setUInt32 ( 1 , id );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r" , id );
return true ;
}
else if ( arg_str_2 == "dataint" )
{
2017-07-22 10:22:17 +03:00
WorldDatabase . PExecute ( "UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'" , arg_2 , atoul ( arg_3 ), id ); // Query can't be a prepared statement
2011-12-31 19:06:24 +01:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r" , id );
return true ;
}
else
{
2010-11-16 21:27:25 +01:00
std :: string arg_str_3 = arg_3 ;
2011-06-30 14:52:44 +02:00
WorldDatabase . EscapeString ( arg_str_3 );
2011-12-31 19:06:24 +01:00
WorldDatabase . PExecute ( "UPDATE waypoint_scripts SET %s='%s' WHERE guid='%u'" , arg_2 , arg_str_3 . c_str (), id ); // Query can't be a prepared statement
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
}
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( "%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r" , "|cff00ff00" , "Waypoint script:" , id , arg_2 , "updated." );
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
static bool HandleWpModifyCommand ( ChatHandler * handler , const char * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// first arg: add del text emote spell waittime move
char * show_str = strtok (( char * ) args , " " );
if ( ! show_str )
{
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
std :: string show = show_str ;
// Check
// Remember: "show" must also be the name of a column!
if (( show != "delay" ) && ( show != "action" ) && ( show != "action_chance" )
2014-07-25 20:18:43 -05:00
&& ( show != "move_type" ) && ( show != "del" ) && ( show != "move" )
2010-11-19 14:04:21 +01:00
)
{
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Next arg is: <PATHID> <WPNUM> <ARGUMENT>
2020-08-14 17:06:03 +02:00
char * arg_str = nullptr ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Did user provide a GUID
// or did the user select a creature?
// -> variable lowguid is filled with the GUID of the NPC
uint32 pathid = 0 ;
uint32 point = 0 ;
Creature * target = handler -> getSelectedCreature ();
2020-08-14 17:06:03 +02:00
WorldDatabasePreparedStatement * stmt = nullptr ;
2010-11-16 21:27:25 +01:00
2016-03-05 20:14:58 +01:00
// User did select a visual waypoint?
2010-11-19 14:04:21 +01:00
if ( ! target || target -> GetEntry () != VISUAL_WAYPOINT )
{
handler -> SendSysMessage ( "|cffff33ffERROR: You must select a waypoint.|r" );
return false ;
}
// Check the creature
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_BY_WPGUID );
2016-03-05 20:14:58 +01:00
stmt -> setUInt64 ( 0 , target -> GetSpawnId ());
2012-03-24 01:25:08 +01:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
2011-11-23 19:17:33 +01:00
if ( ! result )
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTFOUNDSEARCH , std :: to_string ( target -> GetSpawnId ()). c_str ());
2011-11-23 19:17:33 +01:00
// Select waypoint number from database
// 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
2012-03-24 01:25:08 +01:00
std :: string maxDiff = "0.01" ;
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_BY_POS );
2012-03-24 01:25:08 +01:00
stmt -> setFloat ( 0 , target -> GetPositionX ());
stmt -> setString ( 1 , maxDiff );
stmt -> setFloat ( 2 , target -> GetPositionY ());
stmt -> setString ( 3 , maxDiff );
stmt -> setFloat ( 4 , target -> GetPositionZ ());
stmt -> setString ( 5 , maxDiff );
2016-03-05 20:16:42 +01:00
result = WorldDatabase . Query ( stmt );
2012-03-24 01:25:08 +01:00
2016-03-05 20:16:42 +01:00
if ( ! result )
2010-11-16 21:27:25 +01:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTFOUNDDBPROBLEM , std :: to_string ( target -> GetSpawnId ()). c_str ());
2011-11-23 19:17:33 +01:00
return true ;
2010-11-19 14:04:21 +01:00
}
2011-11-23 19:17:33 +01:00
}
2010-11-16 21:27:25 +01:00
2011-11-23 19:17:33 +01:00
do
{
Field * fields = result -> Fetch ();
pathid = fields [ 0 ]. GetUInt32 ();
point = fields [ 1 ]. GetUInt32 ();
2010-11-19 14:04:21 +01:00
}
2011-11-23 19:17:33 +01:00
while ( result -> NextRow ());
// We have the waypoint number and the GUID of the "master npc"
// Text is enclosed in "<>", all other arguments not
2020-08-14 17:06:03 +02:00
arg_str = strtok (( char * ) nullptr , " " );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Check for argument
2020-08-14 17:06:03 +02:00
if ( show != "del" && show != "move" && arg_str == nullptr )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_ARGUMENTREQ , show_str );
return false ;
2010-11-16 21:27:25 +01:00
}
2012-03-01 12:16:06 +01:00
if ( show == "del" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r" , pathid );
2016-03-05 20:14:58 +01:00
target -> DeleteFromDB ();
target -> AddObjectToRemoveList ();
2010-11-19 14:04:21 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_WAYPOINT_DATA );
2011-12-31 19:06:24 +01:00
stmt -> setUInt32 ( 0 , pathid );
stmt -> setUInt32 ( 1 , point );
WorldDatabase . Execute ( stmt );
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_DATA_POINT );
stmt -> setUInt32 ( 0 , pathid );
stmt -> setUInt32 ( 1 , point );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_REMOVED );
return true ;
} // del
2012-03-01 12:16:06 +01:00
if ( show == "move" )
2010-11-19 14:04:21 +01:00
{
handler -> PSendSysMessage ( "|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r" , pathid );
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2016-03-05 20:14:58 +01:00
// What to do:
// Move the visual spawnpoint
// Respawn the owner of the waypoints
target -> DeleteFromDB ();
target -> AddObjectToRemoveList ();
// re-create
2018-01-27 21:47:37 +01:00
Creature * wpCreature = Creature :: CreateCreature ( VISUAL_WAYPOINT , map , chr -> GetPosition ());
if ( ! wpCreature )
2010-11-19 14:04:21 +01:00
{
2016-03-05 20:14:58 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , VISUAL_WAYPOINT );
return false ;
}
2014-06-01 22:27:29 -05:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: InheritPhaseShift ( wpCreature , chr );
2018-09-15 17:55:26 +02:00
wpCreature -> SaveToDB ( map -> GetId (), { map -> GetDifficultyID () });
2018-01-27 21:47:37 +01:00
ObjectGuid :: LowType dbGuid = wpCreature -> GetSpawnId ();
// current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
wpCreature -> CleanupsBeforeDelete ();
delete wpCreature ;
2016-03-05 20:14:58 +01:00
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2017-05-07 21:48:41 +01:00
wpCreature = Creature :: CreateCreatureFromDB ( dbGuid , map , true , true );
2018-01-27 21:47:37 +01:00
if ( ! wpCreature )
2016-03-05 20:14:58 +01:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , VISUAL_WAYPOINT );
return false ;
}
2010-11-16 21:27:25 +01:00
2016-03-05 20:14:58 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_DATA_POSITION );
stmt -> setFloat ( 0 , chr -> GetPositionX ());
stmt -> setFloat ( 1 , chr -> GetPositionY ());
stmt -> setFloat ( 2 , chr -> GetPositionZ ());
stmt -> setUInt32 ( 3 , pathid );
stmt -> setUInt32 ( 4 , point );
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
2016-03-05 20:14:58 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_CHANGED );
2010-11-19 14:04:21 +01:00
return true ;
} // move
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
const char * text = arg_str ;
2010-11-16 21:27:25 +01:00
2020-08-14 17:06:03 +02:00
if ( text == nullptr )
2010-11-19 14:04:21 +01:00
{
// show_str check for present in list of correct values, no sql injection possible
2011-12-31 19:06:24 +01:00
WorldDatabase . PExecute ( "UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'" , show_str , pathid , point ); // Query can't be a prepared statement
2010-11-19 14:04:21 +01:00
}
else
{
// show_str check for present in list of correct values, no sql injection possible
std :: string text2 = text ;
2011-06-30 14:52:44 +02:00
WorldDatabase . EscapeString ( text2 );
2011-12-31 19:06:24 +01:00
WorldDatabase . PExecute ( "UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'" , show_str , text2 . c_str (), pathid , point ); // Query can't be a prepared statement
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_CHANGED_NO , show_str );
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
static bool HandleWpShowCommand ( ChatHandler * handler , const char * args )
{
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// first arg: on, off, first, last
char * show_str = strtok (( char * ) args , " " );
if ( ! show_str )
return false ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// second arg: GUID (optional, if a creature is selected)
2020-08-14 17:06:03 +02:00
char * guid_str = strtok (( char * ) nullptr , " " );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 pathid = 0 ;
Creature * target = handler -> getSelectedCreature ();
2020-08-14 17:06:03 +02:00
WorldDatabasePreparedStatement * stmt = nullptr ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Did player provide a PathID?
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! guid_str )
{
// No PathID provided
// -> Player must have selected a creature
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
pathid = target -> GetWaypointPath ();
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
else
{
// PathID provided
// Warn if player also selected a creature
// -> Creature selection is ignored <-
if ( target )
handler -> SendSysMessage ( LANG_WAYPOINT_CREATSELECTED );
2010-11-16 21:27:25 +01:00
2017-03-11 12:29:37 +01:00
pathid = atoul ( guid_str );
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
std :: string show = show_str ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
//handler->PSendSysMessage("wpshow - show: %s", show);
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Show info for the selected waypoint
if ( show == "info" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// Check if the user did specify a visual waypoint
2013-08-01 21:31:11 +02:00
if ( ! target || target -> GetEntry () != VISUAL_WAYPOINT )
2010-11-19 14:04:21 +01:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_SELECT );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_ALL_BY_WPGUID );
2017-03-11 12:29:37 +01:00
stmt -> setUInt64 ( 0 , target -> GetSpawnId ());
2012-03-24 01:25:08 +01:00
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( ! result )
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTFOUNDDBPROBLEM , std :: to_string ( target -> GetSpawnId ()). c_str ());
2010-11-19 14:04:21 +01:00
return true ;
}
handler -> SendSysMessage ( "|cff00ffffDEBUG: wp show info:|r" );
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2010-11-19 14:04:21 +01:00
pathid = fields [ 0 ]. GetUInt32 ();
uint32 point = fields [ 1 ]. GetUInt32 ();
uint32 delay = fields [ 2 ]. GetUInt32 ();
uint32 flag = fields [ 3 ]. GetUInt32 ();
uint32 ev_id = fields [ 4 ]. GetUInt32 ();
uint32 ev_chance = fields [ 5 ]. GetUInt32 ();
handler -> PSendSysMessage ( "|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r" , point , pathid );
handler -> PSendSysMessage ( "|cff00ff00Show info: delay: |r|cff00ffff%u|r" , delay );
handler -> PSendSysMessage ( "|cff00ff00Show info: Move flag: |r|cff00ffff%u|r" , flag );
handler -> PSendSysMessage ( "|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r" , ev_id );
handler -> PSendSysMessage ( "|cff00ff00Show info: Event chance: |r|cff00ffff%u|r" , ev_chance );
}
while ( result -> NextRow ());
2010-11-16 21:27:25 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
if ( show == "on" )
2010-11-16 21:27:25 +01:00
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_POS_BY_ID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , pathid );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( ! result )
{
handler -> SendSysMessage ( "|cffff33ffPath no found.|r" );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r" , pathid );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Delete all visuals for this NPC
2012-03-24 01:25:08 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_WPGUID_BY_ID );
stmt -> setUInt32 ( 0 , pathid );
PreparedQueryResult result2 = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( result2 )
{
bool hasError = false ;
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result2 -> Fetch ();
2014-10-26 02:57:28 +02:00
ObjectGuid :: LowType wpguid = fields [ 0 ]. GetUInt64 ();
2017-03-11 12:29:37 +01:00
Creature * creature = handler -> GetCreatureFromPlayerMapByDbGuid ( wpguid );
2010-11-19 14:04:21 +01:00
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTREMOVED , std :: to_string ( wpguid ). c_str ());
2010-11-19 14:04:21 +01:00
hasError = true ;
2011-12-31 19:06:24 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE );
2014-10-26 02:57:28 +02:00
stmt -> setUInt64 ( 0 , wpguid );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
}
else
{
2011-07-02 22:18:03 +02:00
creature -> CombatStop ();
creature -> DeleteFromDB ();
creature -> AddObjectToRemoveList ();
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
}
while ( result2 -> NextRow ());
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( hasError )
{
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR1 );
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR2 );
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR3 );
}
}
2010-11-16 21:27:25 +01:00
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2010-11-19 14:04:21 +01:00
uint32 point = fields [ 0 ]. GetUInt32 ();
float x = fields [ 1 ]. GetFloat ();
float y = fields [ 2 ]. GetFloat ();
float z = fields [ 3 ]. GetFloat ();
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
uint32 id = VISUAL_WAYPOINT ;
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2018-01-27 21:47:37 +01:00
Position pos = { x , y , z , chr -> GetOrientation () };
2010-11-19 14:04:21 +01:00
2018-01-27 21:47:37 +01:00
Creature * wpCreature = Creature :: CreateCreature ( id , map , pos );
if ( ! wpCreature )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , id );
return false ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: InheritPhaseShift ( wpCreature , chr );
2018-09-15 17:55:26 +02:00
wpCreature -> SaveToDB ( map -> GetId (), { map -> GetDifficultyID () });
2014-06-01 22:27:29 -05:00
2018-01-27 21:47:37 +01:00
ObjectGuid :: LowType dbGuid = wpCreature -> GetSpawnId ();
// current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
wpCreature -> CleanupsBeforeDelete ();
delete wpCreature ;
2010-11-19 14:04:21 +01:00
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2017-05-07 21:48:41 +01:00
wpCreature = Creature :: CreateCreatureFromDB ( dbGuid , map , true , true );
2018-01-27 21:47:37 +01:00
if ( ! wpCreature )
2011-11-28 14:05:25 -05:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , id );
return false ;
}
2010-11-19 14:04:21 +01:00
if ( target )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
wpCreature -> SetDisplayId ( target -> GetDisplayId ());
2012-05-26 23:00:54 +02:00
wpCreature -> SetObjectScale ( 0.5f );
2012-10-16 09:35:15 +02:00
wpCreature -> SetLevel ( std :: min < uint32 > ( point , STRONG_MAX_LEVEL ));
2010-11-16 21:27:25 +01:00
}
2018-01-27 21:47:37 +01:00
// Set "wpguid" column to the visual waypoint
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_DATA_WPGUID );
stmt -> setUInt64 ( 0 , wpCreature -> GetSpawnId ());
stmt -> setUInt32 ( 1 , pathid );
stmt -> setUInt32 ( 2 , point );
WorldDatabase . Execute ( stmt );
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
while ( result -> NextRow ());
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( "|cff00ff00Showing the current creature's path.|r" );
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
if ( show == "first" )
2010-11-16 21:27:25 +01:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( "|cff00ff00DEBUG: wp first, pathid: %u|r" , pathid );
2010-11-19 14:04:21 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_POS_FIRST_BY_ID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , pathid );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( ! result )
{
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTFOUND , pathid );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2010-11-19 14:04:21 +01:00
float x = fields [ 0 ]. GetFloat ();
float y = fields [ 1 ]. GetFloat ();
float z = fields [ 2 ]. GetFloat ();
2010-11-16 21:27:25 +01:00
uint32 id = VISUAL_WAYPOINT ;
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2018-01-27 21:47:37 +01:00
Position pos = { x , y , z , chr -> GetOrientation () };
2010-11-16 21:27:25 +01:00
2018-01-27 21:47:37 +01:00
Creature * creature = Creature :: CreateCreature ( id , map , pos );
if ( ! creature )
2010-11-16 21:27:25 +01:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , id );
return false ;
}
2018-01-28 11:37:20 +01:00
PhasingHandler :: InheritPhaseShift ( creature , chr );
2018-09-15 17:55:26 +02:00
creature -> SaveToDB ( map -> GetId (), { map -> GetDifficultyID () });
2014-06-01 22:27:29 -05:00
2018-01-27 21:47:37 +01:00
ObjectGuid :: LowType dbGuid = creature -> GetSpawnId ();
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
creature -> CleanupsBeforeDelete ();
delete creature ;
2017-05-07 21:48:41 +01:00
creature = Creature :: CreateCreatureFromDB ( dbGuid , map , true , true );
2018-01-27 21:47:37 +01:00
if ( ! creature )
2011-11-28 14:05:25 -05:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_VP_NOTCREATED , id );
return false ;
}
2010-11-16 21:27:25 +01:00
if ( target )
{
2011-07-02 22:18:03 +02:00
creature -> SetDisplayId ( target -> GetDisplayId ());
2012-05-26 23:00:54 +02:00
creature -> SetObjectScale ( 0.5f );
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
if ( show == "last" )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r" , pathid );
2010-11-16 21:27:25 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_WAYPOINT_DATA_POS_LAST_BY_ID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , pathid );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( ! result )
{
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTFOUNDLAST , pathid );
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2011-10-15 18:38:27 +02:00
float x = fields [ 0 ]. GetFloat ();
float y = fields [ 1 ]. GetFloat ();
float z = fields [ 2 ]. GetFloat ();
float o = fields [ 3 ]. GetFloat ();
2010-11-19 14:04:21 +01:00
uint32 id = VISUAL_WAYPOINT ;
2010-11-16 21:27:25 +01:00
2011-06-30 14:24:56 +02:00
Player * chr = handler -> GetSession () -> GetPlayer ();
2011-09-15 14:08:17 +02:00
Map * map = chr -> GetMap ();
2018-01-27 21:47:37 +01:00
Position pos = { x , y , z , o };
2010-11-16 21:27:25 +01:00
2018-01-27 21:47:37 +01:00
Creature * creature = Creature :: CreateCreature ( id , map , pos );
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTCREATED , id );
return false ;
}
2010-11-16 21:27:25 +01:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: InheritPhaseShift ( creature , chr );
2018-09-15 17:55:26 +02:00
creature -> SaveToDB ( map -> GetId (), { map -> GetDifficultyID () });
2014-06-01 22:27:29 -05:00
2018-01-27 21:47:37 +01:00
ObjectGuid :: LowType dbGuid = creature -> GetSpawnId ();
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
creature -> CleanupsBeforeDelete ();
delete creature ;
2017-05-07 21:48:41 +01:00
creature = Creature :: CreateCreatureFromDB ( dbGuid , map , true , true );
2018-01-27 21:47:37 +01:00
if ( ! creature )
2011-11-28 14:05:25 -05:00
{
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTCREATED , id );
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( target )
{
2011-07-02 22:18:03 +02:00
creature -> SetDisplayId ( target -> GetDisplayId ());
2012-05-26 23:00:54 +02:00
creature -> SetObjectScale ( 0.5f );
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
if ( show == "off" )
2010-11-16 21:27:25 +01:00
{
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_CREATURE_BY_ID );
2012-03-24 01:25:08 +01:00
stmt -> setUInt32 ( 0 , 1 );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-19 14:04:21 +01:00
if ( ! result )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_WAYPOINT_VP_NOTFOUND );
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
bool hasError = false ;
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2017-03-11 12:29:37 +01:00
ObjectGuid :: LowType lowguid = fields [ 0 ]. GetUInt64 ();
Creature * creature = handler -> GetCreatureFromPlayerMapByDbGuid ( lowguid );
2011-07-02 22:18:03 +02:00
if ( ! creature )
2010-11-19 14:04:21 +01:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_WAYPOINT_NOTREMOVED , std :: to_string ( lowguid ). c_str ());
2010-11-19 14:04:21 +01:00
hasError = true ;
2011-12-31 19:06:24 +01:00
2014-07-14 10:53:49 +02:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE );
2017-03-11 12:29:37 +01:00
stmt -> setUInt64 ( 0 , lowguid );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
}
else
{
2011-07-02 22:18:03 +02:00
creature -> CombatStop ();
creature -> DeleteFromDB ();
creature -> AddObjectToRemoveList ();
2010-11-19 14:04:21 +01:00
}
}
while ( result -> NextRow ());
// set "wpguid" column to "empty" - no visual waypoint spawned
2012-03-24 01:25:08 +01:00
stmt = WorldDatabase . GetPreparedStatement ( WORLD_UPD_WAYPOINT_DATA_ALL_WPGUID );
2011-12-31 19:06:24 +01:00
WorldDatabase . Execute ( stmt );
2010-11-19 14:04:21 +01:00
//WorldDatabase.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
if ( hasError )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR1 );
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR2 );
handler -> PSendSysMessage ( LANG_WAYPOINT_TOOFAR3 );
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_WAYPOINT_VP_ALLREMOVED );
return true ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "|cffff33ffDEBUG: wpshow - no valid command found|r" );
2010-11-16 21:27:25 +01:00
return true ;
}
};
void AddSC_wp_commandscript ()
{
new wp_commandscript ();
}