2010-11-16 21:27:25 +01:00
/*
2012-12-31 23:15:50 +01:00
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
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: gobject_commandscript
%Complete: 100
Comment: All gobject related commands
Category: commandscripts
EndScriptData */
#include "ScriptMgr.h"
#include "GameEventMgr.h"
#include "ObjectMgr.h"
#include "PoolMgr.h"
#include "MapManager.h"
#include "Chat.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2012-11-17 05:18:37 +01:00
#include "Player.h"
2012-11-20 14:54:33 +01:00
#include "Opcodes.h"
2010-11-16 21:27:25 +01:00
class gobject_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
gobject_commandscript () : CommandScript ( "gobject_commandscript" ) { }
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
ChatCommand * GetCommands () const
{
static ChatCommand gobjectAddCommandTable [] =
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
{ "temp" , SEC_GAMEMASTER , false , & HandleGameObjectAddTempCommand , "" , NULL },
{ "" , SEC_GAMEMASTER , false , & HandleGameObjectAddCommand , "" , NULL },
{ NULL , 0 , false , NULL , "" , NULL }
};
static ChatCommand gobjectSetCommandTable [] =
{
{ "phase" , SEC_GAMEMASTER , false , & HandleGameObjectSetPhaseCommand , "" , NULL },
{ "state" , SEC_GAMEMASTER , false , & HandleGameObjectSetStateCommand , "" , NULL },
{ NULL , 0 , false , NULL , "" , NULL }
};
static ChatCommand gobjectCommandTable [] =
{
{ "activate" , SEC_GAMEMASTER , false , & HandleGameObjectActivateCommand , "" , NULL },
{ "delete" , SEC_GAMEMASTER , false , & HandleGameObjectDeleteCommand , "" , NULL },
{ "info" , SEC_GAMEMASTER , false , & HandleGameObjectInfoCommand , "" , NULL },
{ "move" , SEC_GAMEMASTER , false , & HandleGameObjectMoveCommand , "" , NULL },
{ "near" , SEC_GAMEMASTER , false , & HandleGameObjectNearCommand , "" , NULL },
{ "target" , SEC_GAMEMASTER , false , & HandleGameObjectTargetCommand , "" , NULL },
{ "turn" , SEC_GAMEMASTER , false , & HandleGameObjectTurnCommand , "" , NULL },
{ "add" , SEC_GAMEMASTER , false , NULL , "" , gobjectAddCommandTable },
{ "set" , SEC_GAMEMASTER , false , NULL , "" , gobjectSetCommandTable },
{ NULL , 0 , false , NULL , "" , NULL }
};
static ChatCommand commandTable [] =
{
{ "gobject" , SEC_GAMEMASTER , false , NULL , "" , gobjectCommandTable },
{ NULL , 0 , false , NULL , "" , NULL }
};
return commandTable ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectActivateCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// by DB guid
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * goData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , goData -> id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// Activate
2011-10-10 10:33:13 -03:00
object -> SetLootState ( GO_READY );
2012-01-22 20:36:01 -05:00
object -> UseDoorOrButton ( 10000 , false , handler -> GetSession () -> GetPlayer ());
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( "Object activated!" );
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
//spawn go
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectAddCommand ( ChatHandler * handler , char const * args )
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
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject_entry" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 objectId = atol ( id );
if ( ! objectId )
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
char * spawntimeSecs = strtok ( NULL , " " );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
const GameObjectTemplate * objectInfo = sObjectMgr -> GetGameObjectTemplate ( objectId );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! objectInfo )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_NOT_EXIST , objectId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( objectInfo -> displayId && ! sGameObjectDisplayInfoStore . LookupEntry ( objectInfo -> displayId ))
2010-11-19 14:04:21 +01:00
{
// report to DB errors log as in loading case
2012-08-03 14:20:18 +02:00
sLog -> outError ( LOG_FILTER_SQL , "Gameobject (Entry %u GoType: %u) have invalid displayId (%u), not spawned." , objectId , objectInfo -> type , objectInfo -> displayId );
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_HAVE_INVALID_DATA , objectId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
float x = float ( player -> GetPositionX ());
float y = float ( player -> GetPositionY ());
float z = float ( player -> GetPositionZ ());
float o = float ( player -> GetOrientation ());
Map * map = player -> GetMap ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = new GameObject ;
uint32 guidLow = sObjectMgr -> GenerateLowGuid ( HIGHGUID_GAMEOBJECT );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object -> Create ( guidLow , objectInfo -> entry , map , player -> GetPhaseMaskForSpawn (), x , y , z , o , 0.0f , 0.0f , 0.0f , 0.0f , 0 , GO_STATE_READY ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
delete object ;
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
if ( spawntimeSecs )
{
uint32 value = atoi (( char * ) spawntimeSecs );
2011-10-10 10:33:13 -03:00
object -> SetRespawnTime ( value );
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// fill the gameobject data and save to the db
2011-10-10 10:33:13 -03:00
object -> SaveToDB ( map -> GetId (), ( 1 << map -> GetSpawnMode ()), player -> GetPhaseMaskForSpawn ());
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// this will generate a new guid if the object is in an instance
2011-11-28 14:05:25 -05:00
if ( ! object -> LoadGameObjectFromDB ( guidLow , map ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
delete object ;
2010-11-19 14:04:21 +01:00
return false ;
}
2010-11-16 21:27:25 +01:00
2013-03-08 21:41:30 +01:00
/// @todo is it really necessary to add both the real and DB table guid here ?
2011-10-10 10:33:13 -03:00
sObjectMgr -> AddGameobjectToGrid ( guidLow , sObjectMgr -> GetGOData ( guidLow ));
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_ADD , objectId , objectInfo -> name . c_str (), guidLow , x , y , z );
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
// add go, temp only
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectAddTempCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
if ( !* args )
return false ;
2011-10-10 10:33:13 -03:00
char * id = strtok (( char * ) args , " " );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
char * spawntime = strtok ( NULL , " " );
uint32 spawntm = 300 ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( spawntime )
spawntm = atoi (( char * ) spawntime );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
float x = player -> GetPositionX ();
float y = player -> GetPositionY ();
float z = player -> GetPositionZ ();
float ang = player -> GetOrientation ();
2010-11-16 21:27:25 +01:00
2012-10-02 15:06:19 +02:00
float rot2 = std :: sin ( ang / 2 );
float rot3 = std :: cos ( ang / 2 );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 objectId = atoi ( id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
player -> SummonGameObject ( objectId , x , y , z , ang , 0 , 0 , rot2 , rot3 , spawntm );
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
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectTargetCommand ( ChatHandler * handler , char const * args )
2010-11-16 21:27:25 +01:00
{
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
2010-11-19 14:04:21 +01:00
QueryResult result ;
2010-12-22 21:25:23 +01:00
GameEventMgr :: ActiveEvents const & activeEventsList = sGameEventMgr -> GetActiveEventList ();
2011-10-10 10:33:13 -03:00
2010-11-19 14:04:21 +01:00
if ( * args )
{
// number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject_entry" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 objectId = atol ( id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( objectId )
2010-11-19 14:04:21 +01:00
result = WorldDatabase . PQuery ( "SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1" ,
2011-10-10 10:33:13 -03:00
player -> GetPositionX (), player -> GetPositionY (), player -> GetPositionZ (), player -> GetMapId (), objectId );
2010-11-19 14:04:21 +01:00
else
{
2011-10-10 10:33:13 -03:00
std :: string name = id ;
2011-06-30 14:52:44 +02:00
WorldDatabase . EscapeString ( name );
2010-11-19 14:04:21 +01:00
result = WorldDatabase . PQuery (
"SELECT guid, id, position_x, position_y, position_z, orientation, map, phaseMask, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ "
2011-04-29 20:47:02 +02:00
"FROM gameobject, gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name " _LIKE_ " " _CONCAT3_ ( "'%%'" , "'%s'" , "'%%'" ) " ORDER BY order_ ASC LIMIT 1" ,
2011-10-10 10:33:13 -03:00
player -> GetPositionX (), player -> GetPositionY (), player -> GetPositionZ (), player -> GetMapId (), name . c_str ());
2010-11-19 14:04:21 +01:00
}
}
2010-11-16 21:27:25 +01:00
else
{
2010-11-19 14:04:21 +01:00
std :: ostringstream eventFilter ;
2011-03-19 18:10:28 +01:00
eventFilter << " AND (eventEntry IS NULL " ;
2010-11-19 14:04:21 +01:00
bool initString = true ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
for ( GameEventMgr :: ActiveEvents :: const_iterator itr = activeEventsList . begin (); itr != activeEventsList . end (); ++ itr )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
if ( initString )
{
2011-10-10 10:33:13 -03:00
eventFilter << "OR eventEntry IN (" << * itr ;
initString = false ;
2010-11-19 14:04:21 +01:00
}
else
2011-07-29 14:18:28 +02:00
eventFilter << ',' << * itr ;
2010-11-16 21:27:25 +01:00
}
2010-11-19 14:04:21 +01:00
if ( ! initString )
eventFilter << "))" ;
else
2011-07-29 14:18:28 +02:00
eventFilter << ')' ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
result = WorldDatabase . PQuery ( "SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, phaseMask, "
"(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
2011-03-18 18:49:15 +01:00
"LEFT OUTER JOIN game_event_gameobject on gameobject.guid = game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10" ,
handler -> GetSession () -> GetPlayer () -> GetPositionX (), handler -> GetSession () -> GetPlayer () -> GetPositionY (), handler -> GetSession () -> GetPlayer () -> GetPositionZ (),
2011-04-29 20:47:02 +02:00
handler -> GetSession () -> GetPlayer () -> GetMapId (), eventFilter . str (). c_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
if ( ! result )
{
handler -> SendSysMessage ( LANG_COMMAND_TARGETOBJNOTFOUND );
return true ;
}
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
bool found = false ;
float x , y , z , o ;
2011-10-10 10:33:13 -03:00
uint32 guidLow , id ;
uint16 mapId , phase ;
uint32 poolId ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2011-10-10 10:33:13 -03:00
guidLow = fields [ 0 ]. GetUInt32 ();
2010-11-19 14:04:21 +01:00
id = fields [ 1 ]. GetUInt32 ();
x = fields [ 2 ]. GetFloat ();
y = fields [ 3 ]. GetFloat ();
z = fields [ 4 ]. GetFloat ();
o = fields [ 5 ]. GetFloat ();
2011-10-10 10:33:13 -03:00
mapId = fields [ 6 ]. GetUInt16 ();
2010-11-19 14:04:21 +01:00
phase = fields [ 7 ]. GetUInt16 ();
2011-10-10 10:33:13 -03:00
poolId = sPoolMgr -> IsPartOfAPool < GameObject > ( guidLow );
if ( ! poolId || sPoolMgr -> IsSpawnedObject < GameObject > ( guidLow ))
2010-11-19 14:04:21 +01:00
found = true ;
2011-10-10 10:33:13 -03:00
} while ( result -> NextRow () && ! found );
2010-11-19 14:04:21 +01:00
if ( ! found )
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_NOT_EXIST , id );
2010-11-19 14:04:21 +01:00
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObjectTemplate const * objectInfo = sObjectMgr -> GetGameObjectTemplate ( id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! objectInfo )
2010-11-19 14:04:21 +01:00
{
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_NOT_EXIST , id );
2010-11-19 14:04:21 +01:00
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * target = handler -> GetSession () -> GetPlayer () -> GetMap () -> GetGameObject ( MAKE_NEW_GUID ( guidLow , id , HIGHGUID_GAMEOBJECT ));
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GAMEOBJECT_DETAIL , guidLow , objectInfo -> name . c_str (), guidLow , id , x , y , z , mapId , o , phase );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( target )
{
2011-10-10 10:33:13 -03:00
int32 curRespawnDelay = int32 ( target -> GetRespawnTimeEx () - time ( NULL ));
2010-11-19 14:04:21 +01:00
if ( curRespawnDelay < 0 )
curRespawnDelay = 0 ;
2010-11-16 21:27:25 +01:00
2011-04-29 20:47:02 +02:00
std :: string curRespawnDelayStr = secsToTimeString ( curRespawnDelay , true );
std :: string defRespawnDelayStr = secsToTimeString ( target -> GetRespawnDelay (), true );
2010-11-16 21:27:25 +01:00
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_RAWPAWNTIMES , defRespawnDelayStr . c_str (), curRespawnDelayStr . c_str ());
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
//delete object by selection or guid
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectDeleteCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// by DB guid
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * gameObjectData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , gameObjectData -> id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-16 21:27:25 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-16 21:27:25 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-10-10 10:33:13 -03:00
uint64 ownerGuid = object -> GetOwnerGUID ();
if ( ownerGuid )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
Unit * owner = ObjectAccessor :: GetUnit ( * handler -> GetSession () -> GetPlayer (), ownerGuid );
if ( ! owner || ! IS_PLAYER_GUID ( ownerGuid ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_DELOBJREFERCREATURE , GUID_LOPART ( ownerGuid ), object -> GetGUIDLow ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
owner -> RemoveGameObject ( object , false );
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> SetRespawnTime ( 0 ); // not save respawn time
object -> Delete ();
object -> DeleteFromDB ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_DELOBJMESSAGE , object -> GetGUIDLow ());
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
//turn selected object
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectTurnCommand ( ChatHandler * handler , char const * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// by DB guid
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * gameObjectData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , gameObjectData -> id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
char * orientation = strtok ( NULL , " " );
2010-11-19 14:04:21 +01:00
float o ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( orientation )
o = ( float ) atof ( orientation );
2010-11-19 14:04:21 +01:00
else
{
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
o = player -> GetOrientation ();
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> Relocate ( object -> GetPositionX (), object -> GetPositionY (), object -> GetPositionZ (), o );
object -> UpdateRotationFields ();
object -> DestroyForNearbyPlayers ();
object -> UpdateObjectVisibility ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> SaveToDB ();
object -> Refresh ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_TURNOBJMESSAGE , object -> GetGUIDLow (), object -> GetGOInfo () -> name . c_str (), object -> GetGUIDLow (), o );
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
//move selected object
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectMoveCommand ( ChatHandler * handler , char const * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-16 21:27:25 +01:00
return false ;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-19 14:04:21 +01:00
// by DB guid
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * gameObjectData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , gameObjectData -> id );
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-16 21:27:25 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-16 21:27:25 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2011-10-10 10:33:13 -03:00
char * toX = strtok ( NULL , " " );
char * toY = strtok ( NULL , " " );
char * toZ = strtok ( NULL , " " );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! toX )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
object -> Relocate ( player -> GetPositionX (), player -> GetPositionY (), player -> GetPositionZ (), object -> GetOrientation ());
object -> DestroyForNearbyPlayers ();
object -> UpdateObjectVisibility ();
2010-11-19 14:04:21 +01:00
}
else
{
2011-10-10 10:33:13 -03:00
if ( ! toY || ! toZ )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
float x = ( float ) atof ( toX );
float y = ( float ) atof ( toY );
float z = ( float ) atof ( toZ );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! MapManager :: IsValidMapCoord ( object -> GetMapId (), x , y , z ))
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_INVALID_TARGET_COORD , x , y , object -> GetMapId ());
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> Relocate ( x , y , z , object -> GetOrientation ());
object -> DestroyForNearbyPlayers ();
object -> UpdateObjectVisibility ();
2010-11-19 14:04:21 +01:00
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> SaveToDB ();
object -> Refresh ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_MOVEOBJMESSAGE , object -> GetGUIDLow (), object -> GetGOInfo () -> name . c_str (), object -> GetGUIDLow ());
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
}
2011-10-10 10:33:13 -03:00
//set phasemask for selected object
static bool HandleGameObjectSetPhaseCommand ( ChatHandler * handler , char const * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
// by DB guid
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * gameObjectData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , gameObjectData -> id );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-16 21:27:25 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
char * phase = strtok ( NULL , " " );
uint32 phaseMask = phase ? atoi ( phase ) : 0 ;
if ( phaseMask == 0 )
2010-11-19 14:04:21 +01:00
{
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
object -> SetPhaseMask ( phaseMask , true );
object -> SaveToDB ();
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectNearCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
float distance = ( !* args ) ? 10.0f : ( float )( atof ( args ));
uint32 count = 0 ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
Player * player = handler -> GetSession () -> GetPlayer ();
2012-03-24 01:25:08 +01:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_SEL_GAMEOBJECT_NEAREST );
stmt -> setFloat ( 0 , player -> GetPositionX ());
stmt -> setFloat ( 1 , player -> GetPositionY ());
stmt -> setFloat ( 2 , player -> GetPositionZ ());
stmt -> setUInt32 ( 3 , player -> GetMapId ());
stmt -> setFloat ( 4 , player -> GetPositionX ());
stmt -> setFloat ( 5 , player -> GetPositionY ());
stmt -> setFloat ( 6 , player -> GetPositionZ ());
stmt -> setFloat ( 7 , distance * distance );
PreparedQueryResult result = WorldDatabase . Query ( stmt );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
if ( result )
{
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2010-11-19 14:04:21 +01:00
uint32 guid = fields [ 0 ]. GetUInt32 ();
uint32 entry = fields [ 1 ]. GetUInt32 ();
float x = fields [ 2 ]. GetFloat ();
float y = fields [ 3 ]. GetFloat ();
float z = fields [ 4 ]. GetFloat ();
2011-10-10 10:33:13 -03:00
uint16 mapId = fields [ 5 ]. GetUInt16 ();
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObjectTemplate const * gameObjectInfo = sObjectMgr -> GetGameObjectTemplate ( entry );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! gameObjectInfo )
2010-11-19 14:04:21 +01:00
continue ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GO_LIST_CHAT , guid , entry , guid , gameObjectInfo -> name . c_str (), x , y , z , mapId );
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
++ count ;
} while ( result -> NextRow ());
}
2011-04-29 20:47:02 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_NEAROBJMESSAGE , distance , count );
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
//show info of gameobject
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectInfoCommand ( ChatHandler * handler , char const * args )
2010-11-19 14:04:21 +01:00
{
uint32 entry = 0 ;
uint32 type = 0 ;
2011-10-10 10:33:13 -03:00
uint32 displayId = 0 ;
2010-11-19 14:04:21 +01:00
std :: string name ;
uint32 lootId = 0 ;
if ( !* args )
2010-11-22 10:10:46 +01:00
{
2011-10-10 10:33:13 -03:00
if ( WorldObject * object = handler -> getSelectedObject ())
entry = object -> GetEntry ();
2010-11-19 14:04:21 +01:00
else
entry = atoi (( char * ) args );
2010-11-22 10:10:46 +01:00
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObjectTemplate const * gameObjectInfo = sObjectMgr -> GetGameObjectTemplate ( entry );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( ! gameObjectInfo )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
type = gameObjectInfo -> type ;
displayId = gameObjectInfo -> displayId ;
name = gameObjectInfo -> name ;
2010-11-19 14:04:21 +01:00
if ( type == GAMEOBJECT_TYPE_CHEST )
2011-10-10 10:33:13 -03:00
lootId = gameObjectInfo -> chest . lootId ;
2010-11-19 14:04:21 +01:00
else if ( type == GAMEOBJECT_TYPE_FISHINGHOLE )
2011-10-10 10:33:13 -03:00
lootId = gameObjectInfo -> fishinghole . lootId ;
2010-11-16 21:27:25 +01:00
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_GOINFO_ENTRY , entry );
handler -> PSendSysMessage ( LANG_GOINFO_TYPE , type );
handler -> PSendSysMessage ( LANG_GOINFO_LOOTID , lootId );
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_GOINFO_DISPLAYID , displayId );
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_GOINFO_NAME , name . c_str ());
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
2011-10-10 10:33:13 -03:00
static bool HandleGameObjectSetStateCommand ( ChatHandler * handler , char const * args )
2010-11-16 21:27:25 +01:00
{
2010-11-19 14:04:21 +01:00
// number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2011-10-10 10:33:13 -03:00
char * id = handler -> extractKeyFromLink (( char * ) args , "Hgameobject" );
if ( ! id )
2010-11-19 14:04:21 +01:00
return false ;
2011-10-10 10:33:13 -03:00
uint32 guidLow = atoi ( id );
if ( ! guidLow )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
GameObject * object = NULL ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( GameObjectData const * gameObjectData = sObjectMgr -> GetGOData ( guidLow ))
object = handler -> GetObjectGlobalyWithGuidOrNearWithDbGuid ( guidLow , gameObjectData -> id );
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
if ( ! object )
2010-11-16 21:27:25 +01:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , guidLow );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
2010-11-16 21:27:25 +01:00
return false ;
}
2011-10-10 10:33:13 -03:00
char * type = strtok ( NULL , " " );
if ( ! type )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
int32 objectType = atoi ( type );
if ( objectType < 0 )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
if ( objectType == - 1 )
object -> SendObjectDeSpawnAnim ( object -> GetGUID ());
else if ( objectType == - 2 )
2010-11-19 14:04:21 +01:00
return false ;
return true ;
}
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
char * state = strtok ( NULL , " " );
if ( ! state )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
int32 objectState = atoi ( state );
2010-11-16 21:27:25 +01:00
2011-10-10 10:33:13 -03:00
if ( objectType < 4 )
object -> SetByteValue ( GAMEOBJECT_BYTES_1 , objectType , objectState );
else if ( objectType == 4 )
2010-11-19 14:04:21 +01:00
{
2011-04-29 20:47:02 +02:00
WorldPacket data ( SMSG_GAMEOBJECT_CUSTOM_ANIM , 8 + 4 );
2011-10-10 10:33:13 -03:00
data << object -> GetGUID ();
data << ( uint32 )( objectState );
object -> SendMessageToSet ( & data , true );
2010-11-19 14:04:21 +01:00
}
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( "Set gobject type %d state %d" , objectType , objectState );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-16 21:27:25 +01:00
};
void AddSC_gobject_commandscript ()
{
new gobject_commandscript ();
}