2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "ObjectMgr.h"
24 #include "GameObject.h"
27 #include "ObjectAccessor.h"
28 #include "MapManager.h"
31 #include "GameEventMgr.h"
33 #include "PoolHandler.h"
34 #include "AccountMgr.h"
35 #include "GMTicketMgr.h"
36 #include "WaypointManager.h"
42 #include "GlobalEvents.h"
44 #include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
46 static uint32 ReputationRankStrIndex
[MAX_REPUTATION_RANK
] =
48 LANG_REP_HATED
, LANG_REP_HOSTILE
, LANG_REP_UNFRIENDLY
, LANG_REP_NEUTRAL
,
49 LANG_REP_FRIENDLY
, LANG_REP_HONORED
, LANG_REP_REVERED
, LANG_REP_EXALTED
52 //mute player for some times
53 bool ChatHandler::HandleMuteCommand(const char* args
)
58 std::string name
= extractPlayerNameFromLink((char*)args
);
61 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
62 SetSentErrorMessage(true);
66 char *timetonotspeak
= strtok(NULL
, " ");
70 uint32 notspeaktime
= (uint32
) atoi(timetonotspeak
);
72 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
75 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
76 SetSentErrorMessage(true);
80 Player
*chr
= objmgr
.GetPlayer(guid
);
82 // must have strong lesser security level
83 if(HasLowerSecurity (chr
,guid
,true))
86 uint32 account_id
= chr
? chr
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(guid
);
88 time_t mutetime
= time(NULL
) + notspeaktime
*60;
91 chr
->GetSession()->m_muteTime
= mutetime
;
93 loginDatabase
.PExecute("UPDATE account SET mutetime = " I64FMTD
" WHERE id = '%u'",uint64(mutetime
), account_id
);
96 ChatHandler(chr
).PSendSysMessage(LANG_YOUR_CHAT_DISABLED
, notspeaktime
);
98 std::string nameLink
= playerLink(name
);
100 PSendSysMessage(LANG_YOU_DISABLE_CHAT
, nameLink
.c_str(), notspeaktime
);
106 bool ChatHandler::HandleUnmuteCommand(const char* args
)
111 std::string name
= extractPlayerNameFromLink((char*)args
);
114 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
115 SetSentErrorMessage(true);
119 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
122 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
123 SetSentErrorMessage(true);
127 Player
*chr
= objmgr
.GetPlayer(guid
);
129 // must have strong lesser security level
130 if(HasLowerSecurity (chr
,guid
,true))
133 uint32 account_id
= chr
? chr
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(guid
);
139 SendSysMessage(LANG_CHAT_ALREADY_ENABLED
);
140 SetSentErrorMessage(true);
144 chr
->GetSession()->m_muteTime
= 0;
147 loginDatabase
.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id
);
150 ChatHandler(chr
).PSendSysMessage(LANG_YOUR_CHAT_ENABLED
);
152 std::string nameLink
= playerLink(name
);
154 PSendSysMessage(LANG_YOU_ENABLE_CHAT
, nameLink
.c_str());
158 bool ChatHandler::HandleGoTriggerCommand(const char* args
)
160 Player
* _player
= m_session
->GetPlayer();
165 char *atId
= strtok((char*)args
, " ");
169 int32 i_atId
= atoi(atId
);
174 AreaTriggerEntry
const* at
= sAreaTriggerStore
.LookupEntry(i_atId
);
177 PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND
,i_atId
);
178 SetSentErrorMessage(true);
182 if(!MapManager::IsValidMapCoord(at
->mapid
,at
->x
,at
->y
,at
->z
))
184 PSendSysMessage(LANG_INVALID_TARGET_COORD
,at
->x
,at
->y
,at
->mapid
);
185 SetSentErrorMessage(true);
189 // stop flight if need
190 if(_player
->isInFlight())
192 _player
->GetMotionMaster()->MovementExpired();
193 _player
->m_taxi
.ClearTaxiDestinations();
195 // save only in non-flight case
197 _player
->SaveRecallPosition();
199 _player
->TeleportTo(at
->mapid
, at
->x
, at
->y
, at
->z
, _player
->GetOrientation());
203 bool ChatHandler::HandleGoGraveyardCommand(const char* args
)
205 Player
* _player
= m_session
->GetPlayer();
210 char *gyId
= strtok((char*)args
, " ");
214 int32 i_gyId
= atoi(gyId
);
219 WorldSafeLocsEntry
const* gy
= sWorldSafeLocsStore
.LookupEntry(i_gyId
);
222 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
,i_gyId
);
223 SetSentErrorMessage(true);
227 if(!MapManager::IsValidMapCoord(gy
->map_id
,gy
->x
,gy
->y
,gy
->z
))
229 PSendSysMessage(LANG_INVALID_TARGET_COORD
,gy
->x
,gy
->y
,gy
->map_id
);
230 SetSentErrorMessage(true);
234 // stop flight if need
235 if(_player
->isInFlight())
237 _player
->GetMotionMaster()->MovementExpired();
238 _player
->m_taxi
.ClearTaxiDestinations();
240 // save only in non-flight case
242 _player
->SaveRecallPosition();
244 _player
->TeleportTo(gy
->map_id
, gy
->x
, gy
->y
, gy
->z
, _player
->GetOrientation());
248 /** \brief Teleport the GM to the specified creature
250 * .gocreature <GUID> --> TP using creature.guid
251 * .gocreature azuregos --> TP player to the mob with this name
252 * Warning: If there is more than one mob with this name
253 * you will be teleported to the first one that is found.
254 * .gocreature id 6109 --> TP player to the mob, that has this creature_template.entry
255 * Warning: If there is more than one mob with this "id"
256 * you will be teleported to the first one that is found.
258 //teleport to creature
259 bool ChatHandler::HandleGoCreatureCommand(const char* args
)
263 Player
* _player
= m_session
->GetPlayer();
265 // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
266 char* pParam1
= extractKeyFromLink((char*)args
,"Hcreature");
270 std::ostringstream whereClause
;
272 // User wants to teleport to the NPC's template entry
273 if( strcmp(pParam1
, "id") == 0 )
275 //sLog.outError("DEBUG: ID found");
277 // Get the "creature_template.entry"
278 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
279 char* tail
= strtok(NULL
,"");
282 char* cId
= extractKeyFromLink(tail
,"Hcreature_entry");
286 int32 tEntry
= atoi(cId
);
287 //sLog.outError("DEBUG: ID value: %d", tEntry);
291 whereClause
<< "WHERE id = '" << tEntry
<< "'";
295 //sLog.outError("DEBUG: ID *not found*");
297 int32 guid
= atoi(pParam1
);
299 // Number is invalid - maybe the user specified the mob's name
302 std::string name
= pParam1
;
303 WorldDatabase
.escape_string(name
);
304 whereClause
<< ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name "_LIKE_
" '" << name
<< "'";
308 whereClause
<< "WHERE guid = '" << guid
<< "'";
311 //sLog.outError("DEBUG: %s", whereClause.c_str());
313 QueryResult
*result
= WorldDatabase
.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause
.str().c_str() );
316 SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND
);
317 SetSentErrorMessage(true);
320 if( result
->GetRowCount() > 1 )
322 SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE
);
325 Field
*fields
= result
->Fetch();
326 float x
= fields
[0].GetFloat();
327 float y
= fields
[1].GetFloat();
328 float z
= fields
[2].GetFloat();
329 float ort
= fields
[3].GetFloat();
330 int mapid
= fields
[4].GetUInt16();
334 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
,ort
))
336 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
337 SetSentErrorMessage(true);
341 // stop flight if need
342 if(_player
->isInFlight())
344 _player
->GetMotionMaster()->MovementExpired();
345 _player
->m_taxi
.ClearTaxiDestinations();
347 // save only in non-flight case
349 _player
->SaveRecallPosition();
351 _player
->TeleportTo(mapid
, x
, y
, z
, ort
);
355 //teleport to gameobject
356 bool ChatHandler::HandleGoObjectCommand(const char* args
)
361 Player
* _player
= m_session
->GetPlayer();
363 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
364 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
368 int32 guid
= atoi(cId
);
376 if (GameObjectData
const* go_data
= objmgr
.GetGOData(guid
))
381 ort
= go_data
->orientation
;
382 mapid
= go_data
->mapid
;
386 SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND
);
387 SetSentErrorMessage(true);
391 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
,ort
))
393 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
394 SetSentErrorMessage(true);
398 // stop flight if need
399 if(_player
->isInFlight())
401 _player
->GetMotionMaster()->MovementExpired();
402 _player
->m_taxi
.ClearTaxiDestinations();
404 // save only in non-flight case
406 _player
->SaveRecallPosition();
408 _player
->TeleportTo(mapid
, x
, y
, z
, ort
);
412 bool ChatHandler::HandleGameObjectTargetCommand(const char* args
)
414 Player
* pl
= m_session
->GetPlayer();
416 GameEventMgr::ActiveEvents
const& activeEventsList
= gameeventmgr
.GetActiveEventList();
419 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
420 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
424 uint32 id
= atol(cId
);
427 result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, orientation, map, (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",
428 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),id
);
431 std::string name
= cId
;
432 WorldDatabase
.escape_string(name
);
433 result
= WorldDatabase
.PQuery(
434 "SELECT guid, id, position_x, position_y, position_z, orientation, map, (POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ "
435 "FROM gameobject,gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" ORDER BY order_ ASC LIMIT 1",
436 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),name
.c_str());
441 std::ostringstream eventFilter
;
442 eventFilter
<< " AND (event IS NULL ";
443 bool initString
= true;
445 for (GameEventMgr::ActiveEvents::const_iterator itr
= activeEventsList
.begin(); itr
!= activeEventsList
.end(); ++itr
)
449 eventFilter
<< "OR event IN (" <<*itr
;
453 eventFilter
<< "," << *itr
;
461 result
= WorldDatabase
.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, "
462 "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
463 "LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
464 m_session
->GetPlayer()->GetPositionX(), m_session
->GetPlayer()->GetPositionY(), m_session
->GetPlayer()->GetPositionZ(), m_session
->GetPlayer()->GetMapId(),eventFilter
.str().c_str());
469 SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND
);
476 uint16 mapid
, pool_id
;
480 Field
*fields
= result
->Fetch();
481 lowguid
= fields
[0].GetUInt32();
482 id
= fields
[1].GetUInt32();
483 x
= fields
[2].GetFloat();
484 y
= fields
[3].GetFloat();
485 z
= fields
[4].GetFloat();
486 o
= fields
[5].GetFloat();
487 mapid
= fields
[6].GetUInt16();
488 pool_id
= poolhandler
.IsPartOfAPool(lowguid
, TYPEID_GAMEOBJECT
);
489 if (!pool_id
|| (pool_id
&& poolhandler
.IsSpawnedObject(pool_id
, lowguid
, TYPEID_GAMEOBJECT
)))
491 } while( result
->NextRow() && (!found
) );
497 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
501 GameObjectInfo
const* goI
= objmgr
.GetGameObjectInfo(id
);
505 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
509 GameObject
* target
= m_session
->GetPlayer()->GetMap()->GetGameObject(MAKE_NEW_GUID(lowguid
,id
,HIGHGUID_GAMEOBJECT
));
511 PSendSysMessage(LANG_GAMEOBJECT_DETAIL
, lowguid
, goI
->name
, lowguid
, id
, x
, y
, z
, mapid
, o
);
515 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
516 if(curRespawnDelay
< 0)
519 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
520 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
522 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
527 //delete object by selection or guid
528 bool ChatHandler::HandleGameObjectDeleteCommand(const char* args
)
530 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
531 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
535 uint32 lowguid
= atoi(cId
);
539 GameObject
* obj
= NULL
;
542 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
543 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
547 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
548 SetSentErrorMessage(true);
552 uint64 owner_guid
= obj
->GetOwnerGUID();
555 Unit
* owner
= ObjectAccessor::GetUnit(*m_session
->GetPlayer(),owner_guid
);
556 if(!owner
|| !IS_PLAYER_GUID(owner_guid
))
558 PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE
, GUID_LOPART(owner_guid
), obj
->GetGUIDLow());
559 SetSentErrorMessage(true);
563 owner
->RemoveGameObject(obj
,false);
566 obj
->SetRespawnTime(0); // not save respawn time
570 PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE
, obj
->GetGUIDLow());
575 //turn selected object
576 bool ChatHandler::HandleGameObjectTurnCommand(const char* args
)
578 // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
579 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
583 uint32 lowguid
= atoi(cId
);
587 GameObject
* obj
= NULL
;
590 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
591 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
595 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
596 SetSentErrorMessage(true);
600 char* po
= strtok(NULL
, " ");
609 Player
*chr
= m_session
->GetPlayer();
610 o
= chr
->GetOrientation();
613 Map
* map
= obj
->GetMap();
614 map
->Remove(obj
,false);
616 obj
->Relocate(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), o
);
617 obj
->UpdateRotationFields();
624 PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE
, obj
->GetGUIDLow(), obj
->GetGOInfo()->name
, obj
->GetGUIDLow(), o
);
629 //move selected object
630 bool ChatHandler::HandleGameObjectMoveCommand(const char* args
)
632 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
633 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
637 uint32 lowguid
= atoi(cId
);
641 GameObject
* obj
= NULL
;
644 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
645 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
649 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
650 SetSentErrorMessage(true);
654 char* px
= strtok(NULL
, " ");
655 char* py
= strtok(NULL
, " ");
656 char* pz
= strtok(NULL
, " ");
660 Player
*chr
= m_session
->GetPlayer();
662 Map
* map
= obj
->GetMap();
663 map
->Remove(obj
,false);
665 obj
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), obj
->GetOrientation());
666 obj
->SetFloatValue(GAMEOBJECT_POS_X
, chr
->GetPositionX());
667 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, chr
->GetPositionY());
668 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, chr
->GetPositionZ());
677 float x
= (float)atof(px
);
678 float y
= (float)atof(py
);
679 float z
= (float)atof(pz
);
681 if(!MapManager::IsValidMapCoord(obj
->GetMapId(),x
,y
,z
))
683 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,obj
->GetMapId());
684 SetSentErrorMessage(true);
688 Map
* map
= obj
->GetMap();
689 map
->Remove(obj
,false);
691 obj
->Relocate(x
, y
, z
, obj
->GetOrientation());
692 obj
->SetFloatValue(GAMEOBJECT_POS_X
, x
);
693 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, y
);
694 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, z
);
702 PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE
, obj
->GetGUIDLow(), obj
->GetGOInfo()->name
, obj
->GetGUIDLow());
708 bool ChatHandler::HandleGameObjectAddCommand(const char* args
)
713 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
714 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
718 uint32 id
= atol(cId
);
722 char* spawntimeSecs
= strtok(NULL
, " ");
724 const GameObjectInfo
*goI
= objmgr
.GetGameObjectInfo(id
);
728 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
729 SetSentErrorMessage(true);
733 Player
*chr
= m_session
->GetPlayer();
734 float x
= float(chr
->GetPositionX());
735 float y
= float(chr
->GetPositionY());
736 float z
= float(chr
->GetPositionZ());
737 float o
= float(chr
->GetOrientation());
738 Map
*map
= chr
->GetMap();
740 GameObject
* pGameObj
= new GameObject
;
741 uint32 db_lowGUID
= objmgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
);
743 if(!pGameObj
->Create(db_lowGUID
, goI
->id
, map
, chr
->GetPhaseMaskForSpawn(), x
, y
, z
, o
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0, GO_STATE_READY
))
751 uint32 value
= atoi((char*)spawntimeSecs
);
752 pGameObj
->SetRespawnTime(value
);
753 //sLog.outDebug("*** spawntimeSecs: %d", value);
756 // fill the gameobject data and save to the db
757 pGameObj
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()),chr
->GetPhaseMaskForSpawn());
759 // this will generate a new guid if the object is in an instance
760 if(!pGameObj
->LoadFromDB(db_lowGUID
, map
))
766 sLog
.outDebug(GetMangosString(LANG_GAMEOBJECT_CURRENT
), goI
->name
, db_lowGUID
, x
, y
, z
, o
);
770 // TODO: is it really necessary to add both the real and DB table guid here ?
771 objmgr
.AddGameobjectToGrid(db_lowGUID
, objmgr
.GetGOData(db_lowGUID
));
773 PSendSysMessage(LANG_GAMEOBJECT_ADD
,id
,goI
->name
,db_lowGUID
,x
,y
,z
);
777 //set pahsemask for selected object
778 bool ChatHandler::HandleGameObjectPhaseCommand(const char* args
)
780 // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
781 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
785 uint32 lowguid
= atoi(cId
);
789 GameObject
* obj
= NULL
;
792 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
793 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
797 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
798 SetSentErrorMessage(true);
802 char* phaseStr
= strtok (NULL
, " ");
803 uint32 phasemask
= phaseStr
? atoi(phaseStr
) : 0;
804 if ( phasemask
== 0 )
806 SendSysMessage(LANG_BAD_VALUE
);
807 SetSentErrorMessage(true);
811 obj
->SetPhaseMask(phasemask
,true);
816 bool ChatHandler::HandleGameObjectNearCommand(const char* args
)
818 float distance
= (!*args
) ? 10 : atol(args
);
821 Player
* pl
= m_session
->GetPlayer();
822 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
823 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
824 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
825 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
826 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
832 Field
*fields
= result
->Fetch();
833 uint32 guid
= fields
[0].GetUInt32();
834 uint32 entry
= fields
[1].GetUInt32();
835 float x
= fields
[2].GetFloat();
836 float y
= fields
[3].GetFloat();
837 float z
= fields
[4].GetFloat();
838 int mapid
= fields
[5].GetUInt16();
840 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
845 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
848 } while (result
->NextRow());
853 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
857 bool ChatHandler::HandleGUIDCommand(const char* /*args*/)
859 uint64 guid
= m_session
->GetPlayer()->GetSelection();
863 SendSysMessage(LANG_NO_SELECTION
);
864 SetSentErrorMessage(true);
868 PSendSysMessage(LANG_OBJECT_GUID
, GUID_LOPART(guid
), GUID_HIPART(guid
));
872 bool ChatHandler::HandleLookupFactionCommand(const char* args
)
877 // Can be NULL at console call
878 Player
*target
= getSelectedPlayer ();
880 std::string namepart
= args
;
881 std::wstring wnamepart
;
883 if (!Utf8toWStr (namepart
,wnamepart
))
886 // converting string that we try to find to lower case
887 wstrToLower (wnamepart
);
889 uint32 counter
= 0; // Counter for figure out that we found smth.
891 for (uint32 id
= 0; id
< sFactionStore
.GetNumRows(); ++id
)
893 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry (id
);
896 FactionState
const* repState
= target
? target
->GetReputationMgr().GetState(factionEntry
) : NULL
;
898 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
899 std::string name
= factionEntry
->name
[loc
];
903 if (!Utf8FitTo(name
, wnamepart
))
906 for(; loc
< MAX_LOCALE
; ++loc
)
908 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
911 name
= factionEntry
->name
[loc
];
915 if (Utf8FitTo(name
, wnamepart
))
922 // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
923 // or "id - [faction] [no reputation]" format
924 std::ostringstream ss
;
926 ss
<< id
<< " - |cffffffff|Hfaction:" << id
<< "|h[" << name
<< " " << localeNames
[loc
] << "]|h|r";
928 ss
<< id
<< " - " << name
<< " " << localeNames
[loc
];
930 if (repState
) // and then target!=NULL also
932 ReputationRank rank
= target
->GetReputationMgr().GetRank(factionEntry
);
933 std::string rankName
= GetMangosString(ReputationRankStrIndex
[rank
]);
935 ss
<< " " << rankName
<< "|h|r (" << target
->GetReputationMgr().GetReputation(factionEntry
) << ")";
937 if(repState
->Flags
& FACTION_FLAG_VISIBLE
)
938 ss
<< GetMangosString(LANG_FACTION_VISIBLE
);
939 if(repState
->Flags
& FACTION_FLAG_AT_WAR
)
940 ss
<< GetMangosString(LANG_FACTION_ATWAR
);
941 if(repState
->Flags
& FACTION_FLAG_PEACE_FORCED
)
942 ss
<< GetMangosString(LANG_FACTION_PEACE_FORCED
);
943 if(repState
->Flags
& FACTION_FLAG_HIDDEN
)
944 ss
<< GetMangosString(LANG_FACTION_HIDDEN
);
945 if(repState
->Flags
& FACTION_FLAG_INVISIBLE_FORCED
)
946 ss
<< GetMangosString(LANG_FACTION_INVISIBLE_FORCED
);
947 if(repState
->Flags
& FACTION_FLAG_INACTIVE
)
948 ss
<< GetMangosString(LANG_FACTION_INACTIVE
);
951 ss
<< GetMangosString(LANG_FACTION_NOREPUTATION
);
953 SendSysMessage(ss
.str().c_str());
959 if (counter
== 0) // if counter == 0 then we found nth
960 SendSysMessage(LANG_COMMAND_FACTION_NOTFOUND
);
964 bool ChatHandler::HandleModifyRepCommand(const char * args
)
966 if (!*args
) return false;
968 Player
* target
= NULL
;
969 target
= getSelectedPlayer();
973 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
974 SetSentErrorMessage(true);
978 // check online security
979 if (HasLowerSecurity(target
, 0))
982 char* factionTxt
= extractKeyFromLink((char*)args
,"Hfaction");
986 uint32 factionId
= atoi(factionTxt
);
989 char *rankTxt
= strtok(NULL
, " ");
990 if (!factionTxt
|| !rankTxt
)
993 amount
= atoi(rankTxt
);
994 if ((amount
== 0) && (rankTxt
[0] != '-') && !isdigit(rankTxt
[0]))
996 std::string rankStr
= rankTxt
;
997 std::wstring wrankStr
;
998 if(!Utf8toWStr(rankStr
,wrankStr
))
1000 wstrToLower( wrankStr
);
1004 for (; r
< MAX_REPUTATION_RANK
; ++r
)
1006 std::string rank
= GetMangosString(ReputationRankStrIndex
[r
]);
1011 if(!Utf8toWStr(rank
,wrank
))
1016 if(wrank
.substr(0,wrankStr
.size())==wrankStr
)
1018 char *deltaTxt
= strtok(NULL
, " ");
1021 int32 delta
= atoi(deltaTxt
);
1022 if ((delta
< 0) || (delta
> ReputationMgr::PointsInRank
[r
] -1))
1024 PSendSysMessage(LANG_COMMAND_FACTION_DELTA
, (ReputationMgr::PointsInRank
[r
]-1));
1025 SetSentErrorMessage(true);
1032 amount
+= ReputationMgr::PointsInRank
[r
];
1034 if (r
>= MAX_REPUTATION_RANK
)
1036 PSendSysMessage(LANG_COMMAND_FACTION_INVPARAM
, rankTxt
);
1037 SetSentErrorMessage(true);
1042 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionId
);
1046 PSendSysMessage(LANG_COMMAND_FACTION_UNKNOWN
, factionId
);
1047 SetSentErrorMessage(true);
1051 if (factionEntry
->reputationListID
< 0)
1053 PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR
, factionEntry
->name
[m_session
->GetSessionDbcLocale()], factionId
);
1054 SetSentErrorMessage(true);
1058 target
->GetReputationMgr().SetReputation(factionEntry
,amount
);
1059 PSendSysMessage(LANG_COMMAND_MODIFY_REP
, factionEntry
->name
[m_session
->GetSessionDbcLocale()], factionId
,
1060 GetNameLink(target
).c_str(), target
->GetReputationMgr().GetReputation(factionEntry
));
1064 //-----------------------Npc Commands-----------------------
1065 //add spawn of creature
1066 bool ChatHandler::HandleNpcAddCommand(const char* args
)
1070 char* charID
= extractKeyFromLink((char*)args
,"Hcreature_entry");
1074 char* team
= strtok(NULL
, " ");
1076 if (team
) { teamval
= atoi(team
); }
1077 if (teamval
< 0) { teamval
= 0; }
1079 uint32 id
= atoi(charID
);
1081 Player
*chr
= m_session
->GetPlayer();
1082 float x
= chr
->GetPositionX();
1083 float y
= chr
->GetPositionY();
1084 float z
= chr
->GetPositionZ();
1085 float o
= chr
->GetOrientation();
1086 Map
*map
= chr
->GetMap();
1088 Creature
* pCreature
= new Creature
;
1089 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, (uint32
)teamval
))
1095 pCreature
->Relocate(x
,y
,z
,o
);
1097 if(!pCreature
->IsPositionValid())
1099 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
1104 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
1106 uint32 db_guid
= pCreature
->GetDBTableGUIDLow();
1108 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
1109 pCreature
->LoadFromDB(db_guid
, map
);
1111 map
->Add(pCreature
);
1112 objmgr
.AddCreatureToGrid(db_guid
, objmgr
.GetCreatureData(db_guid
));
1116 //add item in vendorlist
1117 bool ChatHandler::HandleNpcAddVendorItemCommand(const char* args
)
1122 char* pitem
= extractKeyFromLink((char*)args
,"Hitem");
1125 SendSysMessage(LANG_COMMAND_NEEDITEMSEND
);
1126 SetSentErrorMessage(true);
1130 uint32 itemId
= atol(pitem
);
1132 char* fmaxcount
= strtok(NULL
, " "); //add maxcount, default: 0
1133 uint32 maxcount
= 0;
1135 maxcount
= atol(fmaxcount
);
1137 char* fincrtime
= strtok(NULL
, " "); //add incrtime, default: 0
1138 uint32 incrtime
= 0;
1140 incrtime
= atol(fincrtime
);
1142 char* fextendedcost
= strtok(NULL
, " "); //add ExtendedCost, default: 0
1143 uint32 extendedcost
= fextendedcost
? atol(fextendedcost
) : 0;
1145 Creature
* vendor
= getSelectedCreature();
1147 uint32 vendor_entry
= vendor
? vendor
->GetEntry() : 0;
1149 if(!objmgr
.IsVendorItemValid(vendor_entry
,itemId
,maxcount
,incrtime
,extendedcost
,m_session
->GetPlayer()))
1151 SetSentErrorMessage(true);
1155 objmgr
.AddVendorItem(vendor_entry
,itemId
,maxcount
,incrtime
,extendedcost
);
1157 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(itemId
);
1159 PSendSysMessage(LANG_ITEM_ADDED_TO_LIST
,itemId
,pProto
->Name1
,maxcount
,incrtime
,extendedcost
);
1163 //del item from vendor list
1164 bool ChatHandler::HandleNpcDelVendorItemCommand(const char* args
)
1169 Creature
* vendor
= getSelectedCreature();
1170 if (!vendor
|| !vendor
->isVendor())
1172 SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
1173 SetSentErrorMessage(true);
1177 char* pitem
= extractKeyFromLink((char*)args
,"Hitem");
1180 SendSysMessage(LANG_COMMAND_NEEDITEMSEND
);
1181 SetSentErrorMessage(true);
1184 uint32 itemId
= atol(pitem
);
1186 if(!objmgr
.RemoveVendorItem(vendor
->GetEntry(),itemId
))
1188 PSendSysMessage(LANG_ITEM_NOT_IN_LIST
,itemId
);
1189 SetSentErrorMessage(true);
1193 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(itemId
);
1195 PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST
,itemId
,pProto
->Name1
);
1199 //add move for creature
1200 bool ChatHandler::HandleNpcAddMoveCommand(const char* args
)
1205 char* guid_str
= strtok((char*)args
, " ");
1206 char* wait_str
= strtok((char*)NULL
, " ");
1208 uint32 lowguid
= atoi((char*)guid_str
);
1210 Creature
* pCreature
= NULL
;
1212 /* FIXME: impossible without entry
1214 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1217 // attempt check creature existence by DB data
1220 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1223 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1224 SetSentErrorMessage(true);
1230 // obtain real GUID for DB operations
1231 lowguid
= pCreature
->GetDBTableGUIDLow();
1234 int wait
= wait_str
? atoi(wait_str
) : 0;
1239 Player
* player
= m_session
->GetPlayer();
1241 WaypointMgr
.AddLastNode(lowguid
, player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(), player
->GetOrientation(), wait
, 0);
1243 // update movement type
1244 WorldDatabase
.PExecuteLog("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE
,lowguid
);
1247 pCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
1248 pCreature
->GetMotionMaster()->Initialize();
1249 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1251 pCreature
->setDeathState(JUST_DIED
);
1252 pCreature
->Respawn();
1254 pCreature
->SaveToDB();
1257 SendSysMessage(LANG_WAYPOINT_ADDED
);
1262 //change level of creature or pet
1263 bool ChatHandler::HandleNpcChangeLevelCommand(const char* args
)
1268 uint8 lvl
= (uint8
) atoi((char*)args
);
1269 if ( lvl
< 1 || lvl
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) + 3)
1271 SendSysMessage(LANG_BAD_VALUE
);
1272 SetSentErrorMessage(true);
1276 Creature
* pCreature
= getSelectedCreature();
1279 SendSysMessage(LANG_SELECT_CREATURE
);
1280 SetSentErrorMessage(true);
1284 if(pCreature
->isPet())
1286 ((Pet
*)pCreature
)->GivePetLevel(lvl
);
1290 pCreature
->SetMaxHealth( 100 + 30*lvl
);
1291 pCreature
->SetHealth( 100 + 30*lvl
);
1292 pCreature
->SetLevel( lvl
);
1293 pCreature
->SaveToDB();
1299 //set npcflag of creature
1300 bool ChatHandler::HandleNpcFlagCommand(const char* args
)
1305 uint32 npcFlags
= (uint32
) atoi((char*)args
);
1307 Creature
* pCreature
= getSelectedCreature();
1311 SendSysMessage(LANG_SELECT_CREATURE
);
1312 SetSentErrorMessage(true);
1316 pCreature
->SetUInt32Value(UNIT_NPC_FLAGS
, npcFlags
);
1318 WorldDatabase
.PExecuteLog("UPDATE creature_template SET npcflag = '%u' WHERE entry = '%u'", npcFlags
, pCreature
->GetEntry());
1320 SendSysMessage(LANG_VALUE_SAVED_REJOIN
);
1325 bool ChatHandler::HandleNpcDeleteCommand(const char* args
)
1327 Creature
* unit
= NULL
;
1331 // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
1332 char* cId
= extractKeyFromLink((char*)args
,"Hcreature");
1336 uint32 lowguid
= atoi(cId
);
1340 if (CreatureData
const* cr_data
= objmgr
.GetCreatureData(lowguid
))
1341 unit
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
, cr_data
->id
, HIGHGUID_UNIT
));
1344 unit
= getSelectedCreature();
1346 if(!unit
|| unit
->isPet() || unit
->isTotem() || unit
->isVehicle())
1348 SendSysMessage(LANG_SELECT_CREATURE
);
1349 SetSentErrorMessage(true);
1353 // Delete the creature
1355 unit
->DeleteFromDB();
1356 unit
->CleanupsBeforeDelete();
1357 unit
->AddObjectToRemoveList();
1359 SendSysMessage(LANG_COMMAND_DELCREATMESSAGE
);
1364 //move selected creature
1365 bool ChatHandler::HandleNpcMoveCommand(const char* args
)
1369 Creature
* pCreature
= getSelectedCreature();
1373 // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
1374 char* cId
= extractKeyFromLink((char*)args
,"Hcreature");
1378 lowguid
= atoi(cId
);
1380 /* FIXME: impossibel without entry
1382 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1385 // Attempting creature load from DB data
1388 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1391 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1392 SetSentErrorMessage(true);
1396 uint32 map_id
= data
->mapid
;
1398 if(m_session
->GetPlayer()->GetMapId()!=map_id
)
1400 PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP
, lowguid
);
1401 SetSentErrorMessage(true);
1407 lowguid
= pCreature
->GetDBTableGUIDLow();
1412 lowguid
= pCreature
->GetDBTableGUIDLow();
1415 float x
= m_session
->GetPlayer()->GetPositionX();
1416 float y
= m_session
->GetPlayer()->GetPositionY();
1417 float z
= m_session
->GetPlayer()->GetPositionZ();
1418 float o
= m_session
->GetPlayer()->GetOrientation();
1422 if(CreatureData
const* data
= objmgr
.GetCreatureData(pCreature
->GetDBTableGUIDLow()))
1424 const_cast<CreatureData
*>(data
)->posX
= x
;
1425 const_cast<CreatureData
*>(data
)->posY
= y
;
1426 const_cast<CreatureData
*>(data
)->posZ
= z
;
1427 const_cast<CreatureData
*>(data
)->orientation
= o
;
1429 pCreature
->GetMap()->CreatureRelocation(pCreature
,x
, y
, z
,o
);
1430 pCreature
->GetMotionMaster()->Initialize();
1431 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1433 pCreature
->setDeathState(JUST_DIED
);
1434 pCreature
->Respawn();
1438 WorldDatabase
.PExecuteLog("UPDATE creature SET position_x = '%f', position_y = '%f', position_z = '%f', orientation = '%f' WHERE guid = '%u'", x
, y
, z
, o
, lowguid
);
1439 PSendSysMessage(LANG_COMMAND_CREATUREMOVED
);
1443 /**HandleNpcSetMoveTypeCommand
1444 * Set the movement type for an NPC.<br/>
1446 * Valid movement types are:
1448 * <li> stay - NPC wont move </li>
1449 * <li> random - NPC will move randomly according to the spawndist </li>
1450 * <li> way - NPC will move with given waypoints set </li>
1452 * additional parameter: NODEL - so no waypoints are deleted, if you
1453 * change the movement type
1455 bool ChatHandler::HandleNpcSetMoveTypeCommand(const char* args
)
1461 // GUID (optional - you can also select the creature)
1462 // stay|random|way (determines the kind of movement)
1463 // NODEL (optional - tells the system NOT to delete any waypoints)
1464 // this is very handy if you want to do waypoints, that are
1465 // later switched on/off according to special events (like escort
1467 char* guid_str
= strtok((char*)args
, " ");
1468 char* type_str
= strtok((char*)NULL
, " ");
1469 char* dontdel_str
= strtok((char*)NULL
, " ");
1471 bool doNotDelete
= false;
1477 Creature
* pCreature
= NULL
;
1481 //sLog.outError("DEBUG: All 3 params are set");
1483 // All 3 params are set
1487 if( stricmp( dontdel_str
, "NODEL" ) == 0 )
1489 //sLog.outError("DEBUG: doNotDelete = true;");
1495 // Only 2 params - but maybe NODEL is set
1498 sLog
.outError("DEBUG: Only 2 params ");
1499 if( stricmp( type_str
, "NODEL" ) == 0 )
1501 //sLog.outError("DEBUG: type_str, NODEL ");
1508 if(!type_str
) // case .setmovetype $move_type (with selected creature)
1510 type_str
= guid_str
;
1511 pCreature
= getSelectedCreature();
1512 if(!pCreature
|| pCreature
->isPet())
1514 lowguid
= pCreature
->GetDBTableGUIDLow();
1516 else // case .setmovetype #creature_guid $move_type (with selected creature)
1518 lowguid
= atoi((char*)guid_str
);
1520 /* impossible without entry
1522 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1525 // attempt check creature existence by DB data
1528 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1531 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1532 SetSentErrorMessage(true);
1538 lowguid
= pCreature
->GetDBTableGUIDLow();
1542 // now lowguid is low guid really existed creature
1543 // and pCreature point (maybe) to this creature or NULL
1545 MovementGeneratorType move_type
;
1547 std::string type
= type_str
;
1550 move_type
= IDLE_MOTION_TYPE
;
1551 else if(type
== "random")
1552 move_type
= RANDOM_MOTION_TYPE
;
1553 else if(type
== "way")
1554 move_type
= WAYPOINT_MOTION_TYPE
;
1558 // update movement type
1559 if(doNotDelete
== false)
1560 WaypointMgr
.DeletePath(lowguid
);
1564 pCreature
->SetDefaultMovementType(move_type
);
1565 pCreature
->GetMotionMaster()->Initialize();
1566 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1568 pCreature
->setDeathState(JUST_DIED
);
1569 pCreature
->Respawn();
1571 pCreature
->SaveToDB();
1573 if( doNotDelete
== false )
1575 PSendSysMessage(LANG_MOVE_TYPE_SET
,type_str
);
1579 PSendSysMessage(LANG_MOVE_TYPE_SET_NODEL
,type_str
);
1585 //set model of creature
1586 bool ChatHandler::HandleNpcSetModelCommand(const char* args
)
1591 uint32 displayId
= (uint32
) atoi((char*)args
);
1593 Creature
*pCreature
= getSelectedCreature();
1595 if(!pCreature
|| pCreature
->isPet())
1597 SendSysMessage(LANG_SELECT_CREATURE
);
1598 SetSentErrorMessage(true);
1602 pCreature
->SetDisplayId(displayId
);
1603 pCreature
->SetNativeDisplayId(displayId
);
1605 pCreature
->SaveToDB();
1609 //set faction of creature
1610 bool ChatHandler::HandleNpcFactionIdCommand(const char* args
)
1615 uint32 factionId
= (uint32
) atoi((char*)args
);
1617 if (!sFactionTemplateStore
.LookupEntry(factionId
))
1619 PSendSysMessage(LANG_WRONG_FACTION
, factionId
);
1620 SetSentErrorMessage(true);
1624 Creature
* pCreature
= getSelectedCreature();
1628 SendSysMessage(LANG_SELECT_CREATURE
);
1629 SetSentErrorMessage(true);
1633 pCreature
->setFaction(factionId
);
1635 // faction is set in creature_template - not inside creature
1638 if(CreatureInfo
const *cinfo
= pCreature
->GetCreatureInfo())
1640 const_cast<CreatureInfo
*>(cinfo
)->faction_A
= factionId
;
1641 const_cast<CreatureInfo
*>(cinfo
)->faction_H
= factionId
;
1645 WorldDatabase
.PExecuteLog("UPDATE creature_template SET faction_A = '%u', faction_H = '%u' WHERE entry = '%u'", factionId
, factionId
, pCreature
->GetEntry());
1649 //set spawn dist of creature
1650 bool ChatHandler::HandleNpcSpawnDistCommand(const char* args
)
1655 float option
= atof((char*)args
);
1658 SendSysMessage(LANG_BAD_VALUE
);
1662 MovementGeneratorType mtype
= IDLE_MOTION_TYPE
;
1664 mtype
= RANDOM_MOTION_TYPE
;
1666 Creature
*pCreature
= getSelectedCreature();
1667 uint32 u_guidlow
= 0;
1670 u_guidlow
= pCreature
->GetDBTableGUIDLow();
1674 pCreature
->SetRespawnRadius((float)option
);
1675 pCreature
->SetDefaultMovementType(mtype
);
1676 pCreature
->GetMotionMaster()->Initialize();
1677 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1679 pCreature
->setDeathState(JUST_DIED
);
1680 pCreature
->Respawn();
1683 WorldDatabase
.PExecuteLog("UPDATE creature SET spawndist=%f, MovementType=%i WHERE guid=%u",option
,mtype
,u_guidlow
);
1684 PSendSysMessage(LANG_COMMAND_SPAWNDIST
,option
);
1687 //spawn time handling
1688 bool ChatHandler::HandleNpcSpawnTimeCommand(const char* args
)
1693 char* stime
= strtok((char*)args
, " ");
1698 int i_stime
= atoi((char*)stime
);
1702 SendSysMessage(LANG_BAD_VALUE
);
1703 SetSentErrorMessage(true);
1707 Creature
*pCreature
= getSelectedCreature();
1708 uint32 u_guidlow
= 0;
1711 u_guidlow
= pCreature
->GetDBTableGUIDLow();
1715 WorldDatabase
.PExecuteLog("UPDATE creature SET spawntimesecs=%i WHERE guid=%u",i_stime
,u_guidlow
);
1716 pCreature
->SetRespawnDelay((uint32
)i_stime
);
1717 PSendSysMessage(LANG_COMMAND_SPAWNTIME
,i_stime
);
1721 //npc follow handling
1722 bool ChatHandler::HandleNpcFollowCommand(const char* /*args*/)
1724 Player
*player
= m_session
->GetPlayer();
1725 Creature
*creature
= getSelectedCreature();
1729 PSendSysMessage(LANG_SELECT_CREATURE
);
1730 SetSentErrorMessage(true);
1734 // Follow player - Using pet's default dist and angle
1735 creature
->GetMotionMaster()->MoveFollow(player
, PET_FOLLOW_DIST
, PET_FOLLOW_ANGLE
);
1737 PSendSysMessage(LANG_CREATURE_FOLLOW_YOU_NOW
, creature
->GetName());
1740 //npc unfollow handling
1741 bool ChatHandler::HandleNpcUnFollowCommand(const char* /*args*/)
1743 Player
*player
= m_session
->GetPlayer();
1744 Creature
*creature
= getSelectedCreature();
1748 PSendSysMessage(LANG_SELECT_CREATURE
);
1749 SetSentErrorMessage(true);
1753 if (creature
->GetMotionMaster()->empty() ||
1754 creature
->GetMotionMaster()->GetCurrentMovementGeneratorType ()!=TARGETED_MOTION_TYPE
)
1756 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU
);
1757 SetSentErrorMessage(true);
1761 TargetedMovementGenerator
<Creature
> const* mgen
1762 = static_cast<TargetedMovementGenerator
<Creature
> const*>((creature
->GetMotionMaster()->top()));
1764 if(mgen
->GetTarget()!=player
)
1766 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU
);
1767 SetSentErrorMessage(true);
1772 creature
->GetMotionMaster()->MovementExpired(true);
1774 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU_NOW
, creature
->GetName());
1778 bool ChatHandler::HandleNpcTameCommand(const char* /*args*/)
1780 Creature
*creatureTarget
= getSelectedCreature ();
1781 if (!creatureTarget
|| creatureTarget
->isPet ())
1783 PSendSysMessage (LANG_SELECT_CREATURE
);
1784 SetSentErrorMessage (true);
1788 Player
*player
= m_session
->GetPlayer ();
1790 if(player
->GetPetGUID ())
1792 SendSysMessage (LANG_YOU_ALREADY_HAVE_PET
);
1793 SetSentErrorMessage (true);
1797 CreatureInfo
const* cInfo
= creatureTarget
->GetCreatureInfo();
1799 if (!cInfo
->isTameable ())
1801 PSendSysMessage (LANG_CREATURE_NON_TAMEABLE
,cInfo
->Entry
);
1802 SetSentErrorMessage (true);
1806 // Everything looks OK, create new pet
1807 Pet
* pet
= player
->CreateTamedPetFrom (creatureTarget
);
1810 PSendSysMessage (LANG_CREATURE_NON_TAMEABLE
,cInfo
->Entry
);
1811 SetSentErrorMessage (true);
1815 // place pet before player
1817 player
->GetClosePoint (x
,y
,z
,creatureTarget
->GetObjectSize (),CONTACT_DISTANCE
);
1818 pet
->Relocate (x
,y
,z
,M_PI
-player
->GetOrientation ());
1820 // set pet to defensive mode by default (some classes can't control controlled pets in fact).
1821 pet
->GetCharmInfo()->SetReactState(REACT_DEFENSIVE
);
1823 // calculate proper level
1824 uint32 level
= (creatureTarget
->getLevel() < (player
->getLevel() - 5)) ? (player
->getLevel() - 5) : creatureTarget
->getLevel();
1826 // prepare visual effect for levelup
1827 pet
->SetUInt32Value(UNIT_FIELD_LEVEL
, level
- 1);
1830 pet
->GetMap()->Add((Creature
*)pet
);
1832 // visual effect for levelup
1833 pet
->SetUInt32Value(UNIT_FIELD_LEVEL
, level
);
1835 // caster have pet now
1836 player
->SetPet(pet
);
1838 pet
->SavePetToDB(PET_SAVE_AS_CURRENT
);
1839 player
->PetSpellInitialize();
1843 //npc phasemask handling
1844 //change phasemask of creature or pet
1845 bool ChatHandler::HandleNpcSetPhaseCommand(const char* args
)
1850 uint32 phasemask
= (uint32
) atoi((char*)args
);
1851 if ( phasemask
== 0 )
1853 SendSysMessage(LANG_BAD_VALUE
);
1854 SetSentErrorMessage(true);
1858 Creature
* pCreature
= getSelectedCreature();
1861 SendSysMessage(LANG_SELECT_CREATURE
);
1862 SetSentErrorMessage(true);
1866 pCreature
->SetPhaseMask(phasemask
,true);
1868 if(!pCreature
->isPet())
1869 pCreature
->SaveToDB();
1873 //npc deathstate handling
1874 bool ChatHandler::HandleNpcSetDeathStateCommand(const char* args
)
1879 Creature
* pCreature
= getSelectedCreature();
1880 if(!pCreature
|| pCreature
->isPet())
1882 SendSysMessage(LANG_SELECT_CREATURE
);
1883 SetSentErrorMessage(true);
1887 if (strncmp(args
, "on", 3) == 0)
1888 pCreature
->SetDeadByDefault(true);
1889 else if (strncmp(args
, "off", 4) == 0)
1890 pCreature
->SetDeadByDefault(false);
1893 SendSysMessage(LANG_USE_BOL
);
1894 SetSentErrorMessage(true);
1898 pCreature
->SaveToDB();
1899 pCreature
->Respawn();
1904 //TODO: NpcCommands that need to be fixed :
1906 bool ChatHandler::HandleNpcNameCommand(const char* /*args*/)
1912 if(strlen((char*)args)>75)
1914 PSendSysMessage(LANG_TOO_LONG_NAME, strlen((char*)args)-75);
1918 for (uint8 i = 0; i < strlen(args); i++)
1920 if(!isalpha(args[i]) && args[i]!=' ')
1922 SendSysMessage(LANG_CHARS_ONLY);
1928 guid = m_session->GetPlayer()->GetSelection();
1931 SendSysMessage(LANG_NO_SELECTION);
1935 Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
1939 SendSysMessage(LANG_SELECT_CREATURE);
1943 pCreature->SetName(args);
1944 uint32 idname = objmgr.AddCreatureTemplate(pCreature->GetName());
1945 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
1947 pCreature->SaveToDB();
1953 bool ChatHandler::HandleNpcSubNameCommand(const char* /*args*/)
1960 if(strlen((char*)args)>75)
1963 PSendSysMessage(LANG_TOO_LONG_SUBNAME, strlen((char*)args)-75);
1967 for (uint8 i = 0; i < strlen(args); i++)
1969 if(!isalpha(args[i]) && args[i]!=' ')
1971 SendSysMessage(LANG_CHARS_ONLY);
1976 guid = m_session->GetPlayer()->GetSelection();
1979 SendSysMessage(LANG_NO_SELECTION);
1983 Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
1987 SendSysMessage(LANG_SELECT_CREATURE);
1991 uint32 idname = objmgr.AddCreatureSubName(pCreature->GetName(),args,pCreature->GetUInt32Value(UNIT_FIELD_DISPLAYID));
1992 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
1994 pCreature->SaveToDB();
1999 //move item to other slot
2000 bool ChatHandler::HandleItemMoveCommand(const char* args
)
2004 uint8 srcslot
, dstslot
;
2006 char* pParam1
= strtok((char*)args
, " ");
2010 char* pParam2
= strtok(NULL
, " ");
2014 srcslot
= (uint8
)atoi(pParam1
);
2015 dstslot
= (uint8
)atoi(pParam2
);
2017 if(srcslot
==dstslot
)
2020 if(!m_session
->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0
,srcslot
))
2023 if(!m_session
->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0
,dstslot
))
2026 uint16 src
= ((INVENTORY_SLOT_BAG_0
<< 8) | srcslot
);
2027 uint16 dst
= ((INVENTORY_SLOT_BAG_0
<< 8) | dstslot
);
2029 m_session
->GetPlayer()->SwapItem( src
, dst
);
2034 //demorph player or unit
2035 bool ChatHandler::HandleDeMorphCommand(const char* /*args*/)
2037 Unit
*target
= getSelectedUnit();
2039 target
= m_session
->GetPlayer();
2042 // check online security
2043 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
2051 //morph creature or player
2052 bool ChatHandler::HandleModifyMorphCommand(const char* args
)
2057 uint16 display_id
= (uint16
)atoi((char*)args
);
2059 Unit
*target
= getSelectedUnit();
2061 target
= m_session
->GetPlayer();
2063 // check online security
2064 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
2067 target
->SetDisplayId(display_id
);
2073 bool ChatHandler::HandleKickPlayerCommand(const char *args
)
2077 Player
* player
= getSelectedPlayer();
2081 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2082 SetSentErrorMessage(true);
2086 if(player
==m_session
->GetPlayer())
2088 SendSysMessage(LANG_COMMAND_KICKSELF
);
2089 SetSentErrorMessage(true);
2093 // check online security
2094 if (HasLowerSecurity(player
, 0))
2097 player
->GetSession()->KickPlayer();
2101 std::string name
= extractPlayerNameFromLink((char*)args
);
2104 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2105 SetSentErrorMessage(true);
2109 if(m_session
&& name
==m_session
->GetPlayer()->GetName())
2111 SendSysMessage(LANG_COMMAND_KICKSELF
);
2112 SetSentErrorMessage(true);
2116 // check online security
2117 Player
* player
= ObjectAccessor::Instance().FindPlayerByName(name
.c_str());
2118 if (player
&& HasLowerSecurity(player
, 0))
2121 std::string nameLink
= playerLink(name
);
2123 if(sWorld
.KickPlayer(name
))
2125 PSendSysMessage(LANG_COMMAND_KICKMESSAGE
,nameLink
.c_str());
2128 PSendSysMessage(LANG_COMMAND_KICKNOTFOUNDPLAYER
,nameLink
.c_str());
2134 //set temporary phase mask for player
2135 bool ChatHandler::HandleModifyPhaseCommand(const char* args
)
2140 uint32 phasemask
= (uint32
)atoi((char*)args
);
2142 Unit
*target
= getSelectedUnit();
2144 target
= m_session
->GetPlayer();
2146 // check online security
2147 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
2150 target
->SetPhaseMask(phasemask
,true);
2155 //show info of player
2156 bool ChatHandler::HandlePInfoCommand(const char* args
)
2158 Player
* target
= NULL
;
2159 uint64 targetGUID
= 0;
2161 char* px
= strtok((char*)args
, " ");
2168 name
= extractPlayerNameFromLink(px
);
2171 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2172 SetSentErrorMessage(true);
2176 target
= objmgr
.GetPlayer(name
.c_str());
2178 py
= strtok(NULL
, " ");
2181 targetGUID
= objmgr
.GetPlayerGUIDByName(name
);
2183 py
= strtok(NULL
, " ");
2189 if(!target
&& !targetGUID
)
2191 target
= getSelectedPlayer();
2194 if(!target
&& !targetGUID
)
2196 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2197 SetSentErrorMessage(true);
2203 uint32 total_player_time
= 0;
2207 // get additional information from Player object
2210 // check online security
2211 if (HasLowerSecurity(target
, 0))
2214 targetGUID
= target
->GetGUID();
2215 name
= target
->GetName(); // re-read for case getSelectedPlayer() target
2216 accId
= target
->GetSession()->GetAccountId();
2217 money
= target
->GetMoney();
2218 total_player_time
= target
->GetTotalPlayedTime();
2219 level
= target
->getLevel();
2220 latency
= target
->GetSession()->GetLatency();
2222 // get additional information from DB
2225 // check offline security
2226 if (HasLowerSecurity(NULL
, targetGUID
))
2230 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT totaltime FROM characters WHERE guid = '%u'", GUID_LOPART(targetGUID
));
2233 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2234 SetSentErrorMessage(true);
2237 Field
*fields
= result
->Fetch();
2238 total_player_time
= fields
[0].GetUInt32();
2242 if (!Player::LoadValuesArrayFromDB(data
,targetGUID
))
2244 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2245 SetSentErrorMessage(true);
2249 money
= Player::GetUInt32ValueFromArray(data
, PLAYER_FIELD_COINAGE
);
2250 level
= Player::GetUInt32ValueFromArray(data
, UNIT_FIELD_LEVEL
);
2252 accId
= objmgr
.GetPlayerAccountIdByGUID(targetGUID
);
2255 std::string username
= GetMangosString(LANG_ERROR
);
2256 std::string last_ip
= GetMangosString(LANG_ERROR
);
2257 uint32 security
= 0;
2258 std::string last_login
= GetMangosString(LANG_ERROR
);
2260 QueryResult
* result
= loginDatabase
.PQuery("SELECT username,gmlevel,last_ip,last_login FROM account WHERE id = '%u'",accId
);
2263 Field
* fields
= result
->Fetch();
2264 username
= fields
[0].GetCppString();
2265 security
= fields
[1].GetUInt32();
2267 if(!m_session
|| m_session
->GetSecurity() >= security
)
2269 last_ip
= fields
[2].GetCppString();
2270 last_login
= fields
[3].GetCppString();
2281 std::string nameLink
= playerLink(name
);
2283 PSendSysMessage(LANG_PINFO_ACCOUNT
, (target
?"":GetMangosString(LANG_OFFLINE
)), nameLink
.c_str(), GUID_LOPART(targetGUID
), username
.c_str(), accId
, security
, last_ip
.c_str(), last_login
.c_str(), latency
);
2285 std::string timeStr
= secsToTimeString(total_player_time
,true,true);
2286 uint32 gold
= money
/GOLD
;
2287 uint32 silv
= (money
% GOLD
) / SILVER
;
2288 uint32 copp
= (money
% GOLD
) % SILVER
;
2289 PSendSysMessage(LANG_PINFO_LEVEL
, timeStr
.c_str(), level
, gold
,silv
,copp
);
2291 if ( py
&& strncmp(py
, "rep", 3) == 0 )
2295 // rep option not implemented for offline case
2296 SendSysMessage(LANG_PINFO_NO_REP
);
2297 SetSentErrorMessage(true);
2301 FactionStateList
const& targetFSL
= target
->GetReputationMgr().GetStateList();
2302 for(FactionStateList::const_iterator itr
= targetFSL
.begin(); itr
!= targetFSL
.end(); ++itr
)
2304 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(itr
->second
.ID
);
2305 char const* factionName
= factionEntry
? factionEntry
->name
[m_session
->GetSessionDbcLocale()] : "#Not found#";
2306 ReputationRank rank
= target
->GetReputationMgr().GetRank(factionEntry
);
2307 std::string rankName
= GetMangosString(ReputationRankStrIndex
[rank
]);
2308 std::ostringstream ss
;
2309 ss
<< itr
->second
.ID
<< ": |cffffffff|Hfaction:" << itr
->second
.ID
<< "|h[" << factionName
<< "]|h|r " << rankName
<< "|h|r ("
2310 << target
->GetReputationMgr().GetReputation(factionEntry
) << ")";
2312 if(itr
->second
.Flags
& FACTION_FLAG_VISIBLE
)
2313 ss
<< GetMangosString(LANG_FACTION_VISIBLE
);
2314 if(itr
->second
.Flags
& FACTION_FLAG_AT_WAR
)
2315 ss
<< GetMangosString(LANG_FACTION_ATWAR
);
2316 if(itr
->second
.Flags
& FACTION_FLAG_PEACE_FORCED
)
2317 ss
<< GetMangosString(LANG_FACTION_PEACE_FORCED
);
2318 if(itr
->second
.Flags
& FACTION_FLAG_HIDDEN
)
2319 ss
<< GetMangosString(LANG_FACTION_HIDDEN
);
2320 if(itr
->second
.Flags
& FACTION_FLAG_INVISIBLE_FORCED
)
2321 ss
<< GetMangosString(LANG_FACTION_INVISIBLE_FORCED
);
2322 if(itr
->second
.Flags
& FACTION_FLAG_INACTIVE
)
2323 ss
<< GetMangosString(LANG_FACTION_INACTIVE
);
2325 SendSysMessage(ss
.str().c_str());
2332 void ChatHandler::ShowTicket(uint64 guid
, char const* text
, char const* time
)
2335 if(!objmgr
.GetPlayerNameByGUID(guid
,name
))
2336 name
= GetMangosString(LANG_UNKNOWN
);
2338 std::string nameLink
= playerLink(name
);
2340 PSendSysMessage(LANG_COMMAND_TICKETVIEW
, nameLink
.c_str(),time
,text
);
2344 bool ChatHandler::HandleTicketCommand(const char* args
)
2346 char* px
= strtok((char*)args
, " ");
2353 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2354 SetSentErrorMessage(true);
2358 size_t count
= ticketmgr
.GetTicketCount();
2360 bool accept
= m_session
->GetPlayer()->isAcceptTickets();
2362 PSendSysMessage(LANG_COMMAND_TICKETCOUNT
, count
, accept
? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
2367 if(strncmp(px
,"on",3) == 0)
2371 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2372 SetSentErrorMessage(true);
2376 m_session
->GetPlayer()->SetAcceptTicket(true);
2377 SendSysMessage(LANG_COMMAND_TICKETON
);
2382 if(strncmp(px
,"off",4) == 0)
2386 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2387 SetSentErrorMessage(true);
2391 m_session
->GetPlayer()->SetAcceptTicket(false);
2392 SendSysMessage(LANG_COMMAND_TICKETOFF
);
2400 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT guid,ticket_text,ticket_lastchange FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_
, num
-1);
2404 PSendSysMessage(LANG_COMMAND_TICKENOTEXIST
, num
);
2405 SetSentErrorMessage(true);
2409 Field
* fields
= result
->Fetch();
2411 uint32 guid
= fields
[0].GetUInt32();
2412 char const* text
= fields
[1].GetString();
2413 char const* time
= fields
[2].GetString();
2415 ShowTicket(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
),text
,time
);
2420 std::string name
= extractPlayerNameFromLink(px
);
2423 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2424 SetSentErrorMessage(true);
2428 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
2433 // ticket $char_name
2434 GMTicket
* ticket
= ticketmgr
.GetGMTicket(GUID_LOPART(guid
));
2438 std::string time
= TimeToTimestampStr(ticket
->GetLastUpdate());
2440 ShowTicket(guid
, ticket
->GetText(), time
.c_str());
2446 bool ChatHandler::HandleDelTicketCommand(const char *args
)
2448 char* px
= strtok((char*)args
, " ");
2453 if(strncmp(px
,"all",4) == 0)
2455 ticketmgr
.DeleteAll();
2456 SendSysMessage(LANG_COMMAND_ALLTICKETDELETED
);
2460 int num
= (uint32
)atoi(px
);
2465 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT guid FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_
,num
-1);
2468 PSendSysMessage(LANG_COMMAND_TICKENOTEXIST
, num
);
2469 SetSentErrorMessage(true);
2472 Field
* fields
= result
->Fetch();
2473 uint32 guid
= fields
[0].GetUInt32();
2476 ticketmgr
.Delete(guid
);
2479 if(Player
* pl
= objmgr
.GetPlayer(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
)))
2481 pl
->GetSession()->SendGMTicketGetTicket(0x0A, 0);
2482 PSendSysMessage(LANG_COMMAND_TICKETPLAYERDEL
, GetNameLink(pl
).c_str());
2485 PSendSysMessage(LANG_COMMAND_TICKETDEL
);
2490 std::string name
= extractPlayerNameFromLink(px
);
2493 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2494 SetSentErrorMessage(true);
2498 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
2503 // delticket $char_name
2504 ticketmgr
.Delete(GUID_LOPART(guid
));
2506 // notify players about ticket deleting
2507 if(Player
* sender
= objmgr
.GetPlayer(guid
))
2508 sender
->GetSession()->SendGMTicketGetTicket(0x0A,0);
2510 std::string nameLink
= playerLink(name
);
2512 PSendSysMessage(LANG_COMMAND_TICKETPLAYERDEL
,nameLink
.c_str());
2517 * Add a waypoint to a creature.
2519 * The user can either select an npc or provide its GUID.
2521 * The user can even select a visual waypoint - then the new waypoint
2522 * is placed *after* the selected one - this makes insertion of new
2523 * waypoints possible.
2527 * -> adds a waypoint to the npc with the GUID 12345
2530 * -> adds a waypoint to the currently selected creature
2533 * @param args if the user did not provide a GUID, it is NULL
2535 * @return true - command did succeed, false - something went wrong
2537 bool ChatHandler::HandleWpAddCommand(const char* args
)
2539 sLog
.outDebug("DEBUG: HandleWpAddCommand");
2542 char* guid_str
= NULL
;
2546 guid_str
= strtok((char*)args
, " ");
2551 Creature
* target
= getSelectedCreature();
2552 // Did player provide a GUID?
2555 sLog
.outDebug("DEBUG: HandleWpAddCommand - No GUID provided");
2558 // -> Player must have selected a creature
2560 if(!target
|| target
->isPet())
2562 SendSysMessage(LANG_SELECT_CREATURE
);
2563 SetSentErrorMessage(true);
2566 if (target
->GetEntry() == VISUAL_WAYPOINT
)
2568 sLog
.outDebug("DEBUG: HandleWpAddCommand - target->GetEntry() == VISUAL_WAYPOINT (1) ");
2570 QueryResult
*result
=
2571 WorldDatabase
.PQuery( "SELECT id, point FROM creature_movement WHERE wpguid = %u",
2572 target
->GetGUIDLow() );
2575 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, target
->GetGUIDLow());
2576 // User selected a visual spawnpoint -> get the NPC
2578 // Since we compare float values, we have to deal with
2579 // some difficulties.
2580 // Here we search for all waypoints that only differ in one from 1 thousand
2581 // (0.001) - There is no other way to compare C++ floats with mySQL floats
2582 // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
2583 const char* maxDIFF
= "0.01";
2584 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 )",
2585 target
->GetPositionX(), maxDIFF
, target
->GetPositionY(), maxDIFF
, target
->GetPositionZ(), maxDIFF
);
2588 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, target
->GetGUIDLow());
2589 SetSentErrorMessage(true);
2595 Field
*fields
= result
->Fetch();
2596 lowguid
= fields
[0].GetUInt32();
2597 point
= fields
[1].GetUInt32();
2598 }while( result
->NextRow() );
2601 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2604 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2605 SetSentErrorMessage(true);
2609 target
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
2612 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, lowguid
);
2613 SetSentErrorMessage(true);
2619 lowguid
= target
->GetDBTableGUIDLow();
2624 sLog
.outDebug("DEBUG: HandleWpAddCommand - GUID provided");
2627 // Warn if player also selected a creature
2628 // -> Creature selection is ignored <-
2631 SendSysMessage(LANG_WAYPOINT_CREATSELECTED
);
2633 lowguid
= atoi((char*)guid_str
);
2635 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2638 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2639 SetSentErrorMessage(true);
2643 target
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
2644 if(!target
|| target
->isPet())
2646 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2647 SetSentErrorMessage(true);
2651 // lowguid -> GUID of the NPC
2652 // point -> number of the waypoint (if not 0)
2653 sLog
.outDebug("DEBUG: HandleWpAddCommand - danach");
2655 sLog
.outDebug("DEBUG: HandleWpAddCommand - point == 0");
2657 Player
* player
= m_session
->GetPlayer();
2658 WaypointMgr
.AddLastNode(lowguid
, player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(), player
->GetOrientation(), 0, 0);
2660 // update movement type
2663 target
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
2664 target
->GetMotionMaster()->Initialize();
2665 if(target
->isAlive()) // dead creature will reset movement generator at respawn
2667 target
->setDeathState(JUST_DIED
);
2673 WorldDatabase
.PExecuteLog("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE
,lowguid
);
2675 PSendSysMessage(LANG_WAYPOINT_ADDED
, point
, lowguid
);
2678 } // HandleWpAddCommand
2681 * .wp modify emote | spell | text | del | move | add
2683 * add -> add a WP after the selected visual waypoint
2684 * User must select a visual waypoint and then issue ".wp modify add"
2687 * User has selected a visual waypoint before.
2688 * <emoteID> is added to this waypoint. Everytime the
2689 * NPC comes to this waypoint, the emote is called.
2691 * emote <GUID> <WPNUM> <emoteID>
2692 * User has not selected visual waypoint before.
2693 * For the waypoint <WPNUM> for the NPC with <GUID>
2694 * an emote <emoteID> is added.
2695 * Everytime the NPC comes to this waypoint, the emote is called.
2698 * info <GUID> <WPNUM> -> User did not select a visual waypoint and
2700 bool ChatHandler::HandleWpModifyCommand(const char* args
)
2702 sLog
.outDebug("DEBUG: HandleWpModifyCommand");
2707 // first arg: add del text emote spell waittime move
2708 char* show_str
= strtok((char*)args
, " ");
2714 std::string show
= show_str
;
2716 // Remember: "show" must also be the name of a column!
2717 if( (show
!= "emote") && (show
!= "spell") && (show
!= "textid1") && (show
!= "textid2")
2718 && (show
!= "textid3") && (show
!= "textid4") && (show
!= "textid5")
2719 && (show
!= "waittime") && (show
!= "del") && (show
!= "move") && (show
!= "add")
2720 && (show
!= "model1") && (show
!= "model2") && (show
!= "orientation"))
2725 // Next arg is: <GUID> <WPNUM> <ARGUMENT>
2727 // Did user provide a GUID
2728 // or did the user select a creature?
2729 // -> variable lowguid is filled with the GUID of the NPC
2733 Creature
* target
= getSelectedCreature();
2737 sLog
.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
2739 // Did the user select a visual spawnpoint?
2740 if (target
->GetEntry() != VISUAL_WAYPOINT
)
2742 PSendSysMessage(LANG_WAYPOINT_VP_SELECT
);
2743 SetSentErrorMessage(true);
2747 wpGuid
= target
->GetGUIDLow();
2749 // The visual waypoint
2750 QueryResult
*result
=
2751 WorldDatabase
.PQuery( "SELECT id, point FROM creature_movement WHERE wpguid = %u LIMIT 1",
2752 target
->GetGUIDLow() );
2755 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, wpGuid
);
2756 SetSentErrorMessage(true);
2759 sLog
.outDebug("DEBUG: HandleWpModifyCommand - After getting wpGuid");
2761 Field
*fields
= result
->Fetch();
2762 lowguid
= fields
[0].GetUInt32();
2763 point
= fields
[1].GetUInt32();
2766 sLog
.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
2771 // User did provide <GUID> <WPNUM>
2773 char* guid_str
= strtok((char*)NULL
, " ");
2776 SendSysMessage(LANG_WAYPOINT_NOGUID
);
2779 lowguid
= atoi((char*)guid_str
);
2781 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2784 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2785 SetSentErrorMessage(true);
2789 PSendSysMessage("DEBUG: GUID provided: %d", lowguid
);
2791 char* point_str
= strtok((char*)NULL
, " ");
2794 SendSysMessage(LANG_WAYPOINT_NOWAYPOINTGIVEN
);
2797 point
= atoi((char*)point_str
);
2799 PSendSysMessage("DEBUG: wpNumber provided: %d", point
);
2801 // Now we need the GUID of the visual waypoint
2802 // -> "del", "move", "add" command
2804 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT wpguid FROM creature_movement WHERE id = '%u' AND point = '%u' LIMIT 1", lowguid
, point
);
2807 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, lowguid
, point
);
2808 SetSentErrorMessage(true);
2812 Field
*fields
= result
->Fetch();
2813 wpGuid
= fields
[0].GetUInt32();
2819 char* arg_str
= NULL
;
2820 // Check for argument
2821 if( (show
.find("text") == std::string::npos
) && (show
!= "del") && (show
!= "move") && (show
!= "add"))
2823 // Text is enclosed in "<>", all other arguments not
2824 if( show
.find("text") != std::string::npos
)
2825 arg_str
= strtok((char*)NULL
, "<>");
2827 arg_str
= strtok((char*)NULL
, " ");
2831 PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ
, show_str
);
2836 sLog
.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
2838 // wpGuid -> GUID of the waypoint creature
2839 // lowguid -> GUID of the NPC
2840 // point -> waypoint number
2842 // Special functions:
2843 // add - move - del -> no args commands
2844 // Add a waypoint after the selected visual
2845 if(show
== "add" && target
)
2847 PSendSysMessage("DEBUG: wp modify add, GUID: %u", lowguid
);
2849 // Get the creature for which we read the waypoint
2850 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2853 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2854 SetSentErrorMessage(true);
2858 Creature
* npcCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2862 PSendSysMessage(LANG_WAYPOINT_NPCNOTFOUND
);
2863 SetSentErrorMessage(true);
2867 sLog
.outDebug("DEBUG: HandleWpModifyCommand - add -- npcCreature");
2870 // Add the visual spawnpoint (DB only)
2871 // Adjust the waypoints
2872 // Respawn the owner of the waypoints
2873 sLog
.outDebug("DEBUG: HandleWpModifyCommand - add");
2875 Player
* chr
= m_session
->GetPlayer();
2876 Map
*map
= chr
->GetMap();
2880 npcCreature
->GetMotionMaster()->Initialize();
2881 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2883 npcCreature
->setDeathState(JUST_DIED
);
2884 npcCreature
->Respawn();
2888 // create the waypoint creature
2890 Creature
* wpCreature
= new Creature
;
2891 if (!wpCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT
,0))
2893 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, VISUAL_WAYPOINT
);
2898 wpCreature
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), chr
->GetOrientation());
2900 if(!wpCreature
->IsPositionValid())
2902 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature
->GetGUIDLow(),wpCreature
->GetEntry(),wpCreature
->GetPositionX(),wpCreature
->GetPositionY());
2907 wpCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
2908 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2909 wpCreature
->LoadFromDB(wpCreature
->GetDBTableGUIDLow(), map
);
2910 map
->Add(wpCreature
);
2911 wpGuid
= wpCreature
->GetGUIDLow();
2915 WaypointMgr
.AddAfterNode(lowguid
, point
, chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), 0, 0, wpGuid
);
2920 PSendSysMessage(LANG_WAYPOINT_ADDED_NO
, point
+1);
2924 if(show
== "del" && target
)
2926 PSendSysMessage("DEBUG: wp modify del, GUID: %u", lowguid
);
2928 // Get the creature for which we read the waypoint
2929 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2932 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2933 SetSentErrorMessage(true);
2937 Creature
* npcCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2940 Creature
* wpCreature
= NULL
;
2943 wpCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid
, VISUAL_WAYPOINT
, HIGHGUID_UNIT
));
2944 wpCreature
->DeleteFromDB();
2945 wpCreature
->CleanupsBeforeDelete();
2946 wpCreature
->AddObjectToRemoveList();
2950 // Remove the visual spawnpoint
2951 // Adjust the waypoints
2952 // Respawn the owner of the waypoints
2954 WaypointMgr
.DeleteNode(lowguid
, point
);
2958 // Any waypoints left?
2959 QueryResult
*result2
= WorldDatabase
.PQuery( "SELECT point FROM creature_movement WHERE id = '%u'",lowguid
);
2962 npcCreature
->SetDefaultMovementType(RANDOM_MOTION_TYPE
);
2966 npcCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
2969 npcCreature
->GetMotionMaster()->Initialize();
2970 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2972 npcCreature
->setDeathState(JUST_DIED
);
2973 npcCreature
->Respawn();
2975 npcCreature
->SaveToDB();
2978 PSendSysMessage(LANG_WAYPOINT_REMOVED
);
2982 if(show
== "move" && target
)
2984 PSendSysMessage("DEBUG: wp move, GUID: %u", lowguid
);
2986 Player
*chr
= m_session
->GetPlayer();
2987 Map
*map
= chr
->GetMap();
2989 // Get the creature for which we read the waypoint
2990 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2993 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2994 SetSentErrorMessage(true);
2998 Creature
* npcCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
3001 Creature
* wpCreature
= NULL
;
3003 // Move the visual spawnpoint
3004 // Respawn the owner of the waypoints
3007 wpCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid
, VISUAL_WAYPOINT
, HIGHGUID_UNIT
));
3008 wpCreature
->DeleteFromDB();
3009 wpCreature
->CleanupsBeforeDelete();
3010 wpCreature
->AddObjectToRemoveList();
3012 Creature
* wpCreature2
= new Creature
;
3013 if (!wpCreature2
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT
, 0))
3015 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, VISUAL_WAYPOINT
);
3020 wpCreature2
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), chr
->GetOrientation());
3022 if(!wpCreature2
->IsPositionValid())
3024 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature2
->GetGUIDLow(),wpCreature2
->GetEntry(),wpCreature2
->GetPositionX(),wpCreature2
->GetPositionY());
3029 wpCreature2
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3030 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
3031 wpCreature2
->LoadFromDB(wpCreature2
->GetDBTableGUIDLow(), map
);
3032 map
->Add(wpCreature2
);
3033 //npcCreature->GetMap()->Add(wpCreature2);
3036 WaypointMgr
.SetNodePosition(lowguid
, point
, chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ());
3040 npcCreature
->GetMotionMaster()->Initialize();
3041 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
3043 npcCreature
->setDeathState(JUST_DIED
);
3044 npcCreature
->Respawn();
3047 PSendSysMessage(LANG_WAYPOINT_CHANGED
);
3052 // Create creature - npc that has the waypoint
3053 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
3056 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
3057 SetSentErrorMessage(true);
3061 // set in game textids not supported
3062 if( show
== "textid1" || show
== "textid2" || show
== "textid3" ||
3063 show
== "textid4" || show
== "textid5" )
3068 WaypointMgr
.SetNodeText(lowguid
, point
, show_str
, arg_str
);
3070 Creature
* npcCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
3073 npcCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
3074 npcCreature
->GetMotionMaster()->Initialize();
3075 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
3077 npcCreature
->setDeathState(JUST_DIED
);
3078 npcCreature
->Respawn();
3081 PSendSysMessage(LANG_WAYPOINT_CHANGED_NO
, show_str
);
3087 * .wp show info | on | off
3089 * info -> User has selected a visual waypoint before
3091 * info <GUID> <WPNUM> -> User did not select a visual waypoint and
3092 * provided the GUID of the NPC and the number of
3095 * on -> User has selected an NPC; all visual waypoints for this
3096 * NPC are added to the world
3098 * on <GUID> -> User did not select an NPC - instead the GUID of the
3099 * NPC is provided. All visual waypoints for this NPC
3100 * are added from the world.
3102 * off -> User has selected an NPC; all visual waypoints for this
3103 * NPC are removed from the world.
3105 * on <GUID> -> User did not select an NPC - instead the GUID of the
3106 * NPC is provided. All visual waypoints for this NPC
3107 * are removed from the world.
3111 bool ChatHandler::HandleWpShowCommand(const char* args
)
3113 sLog
.outDebug("DEBUG: HandleWpShowCommand");
3118 // first arg: on, off, first, last
3119 char* show_str
= strtok((char*)args
, " ");
3124 // second arg: GUID (optional, if a creature is selected)
3125 char* guid_str
= strtok((char*)NULL
, " ");
3126 sLog
.outDebug("DEBUG: HandleWpShowCommand: show_str: %s guid_str: %s", show_str
, guid_str
);
3131 // Did user provide a GUID
3132 // or did the user select a creature?
3133 // -> variable lowguid is filled with the GUID
3134 Creature
* target
= getSelectedCreature();
3135 // Did player provide a GUID?
3138 sLog
.outDebug("DEBUG: HandleWpShowCommand: !guid_str");
3140 // -> Player must have selected a creature
3144 SendSysMessage(LANG_SELECT_CREATURE
);
3145 SetSentErrorMessage(true);
3151 sLog
.outDebug("DEBUG: HandleWpShowCommand: GUID provided");
3153 // Warn if player also selected a creature
3154 // -> Creature selection is ignored <-
3157 SendSysMessage(LANG_WAYPOINT_CREATSELECTED
);
3160 uint32 lowguid
= atoi((char*)guid_str
);
3162 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
3165 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
3166 SetSentErrorMessage(true);
3170 target
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
3174 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
3175 SetSentErrorMessage(true);
3180 uint32 lowguid
= target
->GetDBTableGUIDLow();
3182 std::string show
= show_str
;
3185 sLog
.outDebug("DEBUG: HandleWpShowCommand: lowguid: %u show: %s", lowguid
, show_str
);
3187 // Show info for the selected waypoint
3190 PSendSysMessage("DEBUG: wp info, GUID: %u", lowguid
);
3192 // Check if the user did specify a visual waypoint
3193 if( target
->GetEntry() != VISUAL_WAYPOINT
)
3195 PSendSysMessage(LANG_WAYPOINT_VP_SELECT
);
3196 SetSentErrorMessage(true);
3200 //PSendSysMessage("wp on, GUID: %u", lowguid);
3202 //pCreature->GetPositionX();
3204 QueryResult
*result
=
3205 WorldDatabase
.PQuery( "SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE wpguid = %u",
3206 target
->GetGUIDLow() );
3209 // Since we compare float values, we have to deal with
3210 // some difficulties.
3211 // Here we search for all waypoints that only differ in one from 1 thousand
3212 // (0.001) - There is no other way to compare C++ floats with mySQL floats
3213 // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
3214 const char* maxDIFF
= "0.01";
3215 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, target
->GetGUID());
3217 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 )",
3218 target
->GetPositionX(), maxDIFF
, target
->GetPositionY(), maxDIFF
, target
->GetPositionZ(), maxDIFF
);
3221 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, lowguid
);
3222 SetSentErrorMessage(true);
3228 Field
*fields
= result
->Fetch();
3229 uint32 creGUID
= fields
[0].GetUInt32();
3230 uint32 point
= fields
[1].GetUInt32();
3231 int waittime
= fields
[2].GetUInt32();
3232 uint32 emote
= fields
[3].GetUInt32();
3233 uint32 spell
= fields
[4].GetUInt32();
3234 uint32 textid
[MAX_WAYPOINT_TEXT
];
3235 for(int i
= 0; i
< MAX_WAYPOINT_TEXT
; ++i
)
3236 textid
[i
] = fields
[5+i
].GetUInt32();
3237 uint32 model1
= fields
[10].GetUInt32();
3238 uint32 model2
= fields
[11].GetUInt32();
3240 // Get the creature for which we read the waypoint
3241 Creature
* wpCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(creGUID
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
3243 PSendSysMessage(LANG_WAYPOINT_INFO_TITLE
, point
, (wpCreature
? wpCreature
->GetName() : "<not found>"), creGUID
);
3244 PSendSysMessage(LANG_WAYPOINT_INFO_WAITTIME
, waittime
);
3245 PSendSysMessage(LANG_WAYPOINT_INFO_MODEL
, 1, model1
);
3246 PSendSysMessage(LANG_WAYPOINT_INFO_MODEL
, 2, model2
);
3247 PSendSysMessage(LANG_WAYPOINT_INFO_EMOTE
, emote
);
3248 PSendSysMessage(LANG_WAYPOINT_INFO_SPELL
, spell
);
3249 for(int i
= 0; i
< MAX_WAYPOINT_TEXT
; ++i
)
3250 PSendSysMessage(LANG_WAYPOINT_INFO_TEXT
, i
+1, textid
[i
], (textid
[i
] ? GetMangosString(textid
[i
]) : ""));
3252 }while( result
->NextRow() );
3260 PSendSysMessage("DEBUG: wp on, GUID: %u", lowguid
);
3262 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT point, position_x,position_y,position_z FROM creature_movement WHERE id = '%u'",lowguid
);
3265 PSendSysMessage(LANG_WAYPOINT_NOTFOUND
, lowguid
);
3266 SetSentErrorMessage(true);
3269 // Delete all visuals for this NPC
3270 QueryResult
*result2
= WorldDatabase
.PQuery( "SELECT wpguid FROM creature_movement WHERE id = '%u' and wpguid <> 0", lowguid
);
3273 bool hasError
= false;
3276 Field
*fields
= result2
->Fetch();
3277 uint32 wpguid
= fields
[0].GetUInt32();
3278 Creature
* pCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpguid
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
3282 PSendSysMessage(LANG_WAYPOINT_NOTREMOVED
, wpguid
);
3284 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", wpguid
);
3288 pCreature
->DeleteFromDB();
3289 pCreature
->CleanupsBeforeDelete();
3290 pCreature
->AddObjectToRemoveList();
3293 }while( result2
->NextRow() );
3297 PSendSysMessage(LANG_WAYPOINT_TOOFAR1
);
3298 PSendSysMessage(LANG_WAYPOINT_TOOFAR2
);
3299 PSendSysMessage(LANG_WAYPOINT_TOOFAR3
);
3305 Field
*fields
= result
->Fetch();
3306 uint32 point
= fields
[0].GetUInt32();
3307 float x
= fields
[1].GetFloat();
3308 float y
= fields
[2].GetFloat();
3309 float z
= fields
[3].GetFloat();
3311 uint32 id
= VISUAL_WAYPOINT
;
3313 Player
*chr
= m_session
->GetPlayer();
3314 Map
*map
= chr
->GetMap();
3315 float o
= chr
->GetOrientation();
3317 Creature
* wpCreature
= new Creature
;
3318 if (!wpCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
3320 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, id
);
3326 wpCreature
->Relocate(x
, y
, z
, o
);
3328 if(!wpCreature
->IsPositionValid())
3330 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature
->GetGUIDLow(),wpCreature
->GetEntry(),wpCreature
->GetPositionX(),wpCreature
->GetPositionY());
3336 wpCreature
->SetVisibility(VISIBILITY_OFF
);
3337 sLog
.outDebug("DEBUG: UPDATE creature_movement SET wpguid = '%u");
3338 // set "wpguid" column to the visual waypoint
3339 WorldDatabase
.PExecuteLog("UPDATE creature_movement SET wpguid = '%u' WHERE id = '%u' and point = '%u'", wpCreature
->GetGUIDLow(), lowguid
, point
);
3341 wpCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3342 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
3343 wpCreature
->LoadFromDB(wpCreature
->GetDBTableGUIDLow(),map
);
3344 map
->Add(wpCreature
);
3345 //wpCreature->GetMap()->Add(wpCreature);
3346 }while( result
->NextRow() );
3355 PSendSysMessage("DEBUG: wp first, GUID: %u", lowguid
);
3357 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT position_x,position_y,position_z FROM creature_movement WHERE point='1' AND id = '%u'",lowguid
);
3360 PSendSysMessage(LANG_WAYPOINT_NOTFOUND
, lowguid
);
3361 SetSentErrorMessage(true);
3365 Field
*fields
= result
->Fetch();
3366 float x
= fields
[0].GetFloat();
3367 float y
= fields
[1].GetFloat();
3368 float z
= fields
[2].GetFloat();
3369 uint32 id
= VISUAL_WAYPOINT
;
3371 Player
*chr
= m_session
->GetPlayer();
3372 float o
= chr
->GetOrientation();
3373 Map
*map
= chr
->GetMap();
3375 Creature
* pCreature
= new Creature
;
3376 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
),map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
3378 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, id
);
3384 pCreature
->Relocate(x
, y
, z
, o
);
3386 if(!pCreature
->IsPositionValid())
3388 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
3394 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3395 pCreature
->LoadFromDB(pCreature
->GetDBTableGUIDLow(), map
);
3396 map
->Add(pCreature
);
3397 //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "First Waypoint");
3406 PSendSysMessage("DEBUG: wp last, GUID: %u", lowguid
);
3408 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT MAX(point) FROM creature_movement WHERE id = '%u'",lowguid
);
3411 Maxpoint
= (*result
)[0].GetUInt32();
3418 result
= WorldDatabase
.PQuery( "SELECT position_x,position_y,position_z FROM creature_movement WHERE point ='%u' AND id = '%u'",Maxpoint
, lowguid
);
3421 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST
, lowguid
);
3422 SetSentErrorMessage(true);
3425 Field
*fields
= result
->Fetch();
3426 float x
= fields
[0].GetFloat();
3427 float y
= fields
[1].GetFloat();
3428 float z
= fields
[2].GetFloat();
3429 uint32 id
= VISUAL_WAYPOINT
;
3431 Player
*chr
= m_session
->GetPlayer();
3432 float o
= chr
->GetOrientation();
3433 Map
*map
= chr
->GetMap();
3435 Creature
* pCreature
= new Creature
;
3436 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
3438 PSendSysMessage(LANG_WAYPOINT_NOTCREATED
, id
);
3444 pCreature
->Relocate(x
, y
, z
, o
);
3446 if(!pCreature
->IsPositionValid())
3448 sLog
.outError("Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
3454 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3455 pCreature
->LoadFromDB(pCreature
->GetDBTableGUIDLow(), map
);
3456 map
->Add(pCreature
);
3457 //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "Last Waypoint");
3465 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid FROM creature WHERE id = '%d'", VISUAL_WAYPOINT
);
3468 SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND
);
3469 SetSentErrorMessage(true);
3472 bool hasError
= false;
3475 Field
*fields
= result
->Fetch();
3476 uint32 guid
= fields
[0].GetUInt32();
3477 Creature
* pCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(guid
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
3480 PSendSysMessage(LANG_WAYPOINT_NOTREMOVED
, guid
);
3482 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", guid
);
3486 pCreature
->DeleteFromDB();
3487 pCreature
->CleanupsBeforeDelete();
3488 pCreature
->AddObjectToRemoveList();
3490 }while(result
->NextRow());
3491 // set "wpguid" column to "empty" - no visual waypoint spawned
3492 WorldDatabase
.PExecuteLog("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
3496 PSendSysMessage(LANG_WAYPOINT_TOOFAR1
);
3497 PSendSysMessage(LANG_WAYPOINT_TOOFAR2
);
3498 PSendSysMessage(LANG_WAYPOINT_TOOFAR3
);
3501 SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED
);
3508 PSendSysMessage("DEBUG: wpshow - no valid command found");
3511 } // HandleWpShowCommand
3513 bool ChatHandler::HandleWpExportCommand(const char *args
)
3518 // Next arg is: <GUID> <ARGUMENT>
3520 // Did user provide a GUID
3521 // or did the user select a creature?
3522 // -> variable lowguid is filled with the GUID of the NPC
3524 Creature
* target
= getSelectedCreature();
3525 char* arg_str
= NULL
;
3528 if (target
->GetEntry() != VISUAL_WAYPOINT
)
3529 lowguid
= target
->GetGUIDLow();
3532 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT id FROM creature_movement WHERE wpguid = %u LIMIT 1", target
->GetGUIDLow() );
3535 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, target
->GetGUIDLow());
3538 Field
*fields
= result
->Fetch();
3539 lowguid
= fields
[0].GetUInt32();;
3543 arg_str
= strtok((char*)args
, " ");
3547 // user provided <GUID>
3548 char* guid_str
= strtok((char*)args
, " ");
3551 SendSysMessage(LANG_WAYPOINT_NOGUID
);
3554 lowguid
= atoi((char*)guid_str
);
3556 arg_str
= strtok((char*)NULL
, " ");
3561 PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ
, "export");
3565 PSendSysMessage("DEBUG: wp export, GUID: %u", lowguid
);
3567 QueryResult
*result
= WorldDatabase
.PQuery(
3568 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
3569 "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
);
3573 PSendSysMessage(LANG_WAYPOINT_NOTHINGTOEXPORT
);
3574 SetSentErrorMessage(true);
3578 std::ofstream outfile
;
3579 outfile
.open (arg_str
);
3583 Field
*fields
= result
->Fetch();
3585 outfile
<< "INSERT INTO creature_movement ";
3586 outfile
<< "( id, point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5 ) VALUES ";
3589 outfile
<< fields
[15].GetUInt32(); // id
3591 outfile
<< fields
[0].GetUInt32(); // point
3593 outfile
<< fields
[1].GetFloat(); // position_x
3595 outfile
<< fields
[2].GetFloat(); // position_y
3597 outfile
<< fields
[3].GetUInt32(); // position_z
3599 outfile
<< fields
[4].GetUInt32(); // orientation
3601 outfile
<< fields
[5].GetUInt32(); // model1
3603 outfile
<< fields
[6].GetUInt32(); // model2
3605 outfile
<< fields
[7].GetUInt16(); // waittime
3607 outfile
<< fields
[8].GetUInt32(); // emote
3609 outfile
<< fields
[9].GetUInt32(); // spell
3611 outfile
<< fields
[10].GetUInt32(); // textid1
3613 outfile
<< fields
[11].GetUInt32(); // textid2
3615 outfile
<< fields
[12].GetUInt32(); // textid3
3617 outfile
<< fields
[13].GetUInt32(); // textid4
3619 outfile
<< fields
[14].GetUInt32(); // textid5
3622 } while( result
->NextRow() );
3625 PSendSysMessage(LANG_WAYPOINT_EXPORTED
);
3631 bool ChatHandler::HandleWpImportCommand(const char *args
)
3636 char* arg_str
= strtok((char*)args
, " ");
3641 std::ifstream
infile (arg_str
);
3642 if (infile
.is_open())
3644 while (! infile
.eof() )
3646 getline (infile
,line
);
3647 //cout << line << endl;
3648 QueryResult
*result
= WorldDatabase
.Query(line
.c_str());
3653 PSendSysMessage(LANG_WAYPOINT_IMPORTED
);
3659 bool ChatHandler::HandleCharacterRenameCommand(const char* args
)
3661 Player
* target
= NULL
;
3662 uint64 targetGUID
= 0;
3663 std::string oldname
;
3665 char* px
= strtok((char*)args
, " ");
3669 oldname
= extractPlayerNameFromLink(px
);
3672 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3673 SetSentErrorMessage(true);
3677 target
= objmgr
.GetPlayer(oldname
.c_str());
3680 targetGUID
= objmgr
.GetPlayerGUIDByName(oldname
);
3683 if(!target
&& !targetGUID
)
3685 target
= getSelectedPlayer();
3688 if(!target
&& !targetGUID
)
3690 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3691 SetSentErrorMessage(true);
3697 // check online security
3698 if (HasLowerSecurity(target
, 0))
3701 PSendSysMessage(LANG_RENAME_PLAYER
, GetNameLink(target
).c_str());
3702 target
->SetAtLoginFlag(AT_LOGIN_RENAME
);
3703 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", target
->GetGUIDLow());
3707 // check offline security
3708 if (HasLowerSecurity(NULL
, targetGUID
))
3711 std::string oldNameLink
= playerLink(oldname
);
3713 PSendSysMessage(LANG_RENAME_PLAYER_GUID
, oldNameLink
.c_str(), GUID_LOPART(targetGUID
));
3714 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(targetGUID
));
3720 // customize characters
3721 bool ChatHandler::HandleCharacterCustomizeCommand(const char* args
)
3723 Player
* target
= NULL
;
3724 uint64 targetGUID
= 0;
3725 std::string oldname
;
3727 char* px
= strtok((char*)args
, " ");
3731 oldname
= extractPlayerNameFromLink(px
);
3734 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3735 SetSentErrorMessage(true);
3739 target
= objmgr
.GetPlayer(oldname
.c_str());
3742 targetGUID
= objmgr
.GetPlayerGUIDByName(oldname
);
3745 if(!target
&& !targetGUID
)
3747 target
= getSelectedPlayer();
3750 if(!target
&& !targetGUID
)
3752 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3753 SetSentErrorMessage(true);
3759 PSendSysMessage(LANG_CUSTOMIZE_PLAYER
, GetNameLink(target
).c_str());
3760 target
->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE
);
3761 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", target
->GetGUIDLow());
3765 std::string oldNameLink
= playerLink(oldname
);
3767 PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID
, oldNameLink
.c_str(), GUID_LOPART(targetGUID
));
3768 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", GUID_LOPART(targetGUID
));
3775 bool ChatHandler::HandleModifyStandStateCommand(const char* args
)
3780 uint32 anim_id
= atoi((char*)args
);
3781 m_session
->GetPlayer( )->SetUInt32Value( UNIT_NPC_EMOTESTATE
, anim_id
);
3786 bool ChatHandler::HandleHonorAddCommand(const char* args
)
3791 Player
*target
= getSelectedPlayer();
3794 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3795 SetSentErrorMessage(true);
3799 // check online security
3800 if (HasLowerSecurity(target
, 0))
3803 uint32 amount
= (uint32
)atoi(args
);
3804 target
->RewardHonor(NULL
, 1, amount
);
3808 bool ChatHandler::HandleHonorAddKillCommand(const char* /*args*/)
3810 Unit
*target
= getSelectedUnit();
3813 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3814 SetSentErrorMessage(true);
3818 // check online security
3819 if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
3822 m_session
->GetPlayer()->RewardHonor(target
, 1);
3826 bool ChatHandler::HandleHonorUpdateCommand(const char* /*args*/)
3828 Player
*target
= getSelectedPlayer();
3831 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3832 SetSentErrorMessage(true);
3836 // check online security
3837 if (HasLowerSecurity(target
, 0))
3840 target
->UpdateHonorFields();
3844 bool ChatHandler::HandleLookupEventCommand(const char* args
)
3849 std::string namepart
= args
;
3850 std::wstring wnamepart
;
3852 // converting string that we try to find to lower case
3853 if(!Utf8toWStr(namepart
,wnamepart
))
3856 wstrToLower(wnamepart
);
3860 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3861 GameEventMgr::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3863 for(uint32 id
= 0; id
< events
.size(); ++id
)
3865 GameEventData
const& eventData
= events
[id
];
3867 std::string descr
= eventData
.description
;
3871 if (Utf8FitTo(descr
, wnamepart
))
3873 char const* active
= activeEvents
.find(id
) != activeEvents
.end() ? GetMangosString(LANG_ACTIVE
) : "";
3876 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT
,id
,id
,eventData
.description
.c_str(),active
);
3878 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE
,id
,eventData
.description
.c_str(),active
);
3885 SendSysMessage(LANG_NOEVENTFOUND
);
3890 bool ChatHandler::HandleEventActiveListCommand(const char* /*args*/)
3894 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3895 GameEventMgr::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3897 char const* active
= GetMangosString(LANG_ACTIVE
);
3899 for(GameEventMgr::ActiveEvents::const_iterator itr
= activeEvents
.begin(); itr
!= activeEvents
.end(); ++itr
)
3901 uint32 event_id
= *itr
;
3902 GameEventData
const& eventData
= events
[event_id
];
3905 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT
,event_id
,event_id
,eventData
.description
.c_str(),active
);
3907 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE
,event_id
,eventData
.description
.c_str(),active
);
3913 SendSysMessage(LANG_NOEVENTFOUND
);
3918 bool ChatHandler::HandleEventInfoCommand(const char* args
)
3923 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3924 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
3928 uint32 event_id
= atoi(cId
);
3930 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3932 if(event_id
>=events
.size())
3934 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3935 SetSentErrorMessage(true);
3939 GameEventData
const& eventData
= events
[event_id
];
3940 if(!eventData
.isValid())
3942 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3943 SetSentErrorMessage(true);
3947 GameEventMgr::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3948 bool active
= activeEvents
.find(event_id
) != activeEvents
.end();
3949 char const* activeStr
= active
? GetMangosString(LANG_ACTIVE
) : "";
3951 std::string startTimeStr
= TimeToTimestampStr(eventData
.start
);
3952 std::string endTimeStr
= TimeToTimestampStr(eventData
.end
);
3954 uint32 delay
= gameeventmgr
.NextCheck(event_id
);
3955 time_t nextTime
= time(NULL
)+delay
;
3956 std::string nextStr
= nextTime
>= eventData
.start
&& nextTime
< eventData
.end
? TimeToTimestampStr(time(NULL
)+delay
) : "-";
3958 std::string occurenceStr
= secsToTimeString(eventData
.occurence
* MINUTE
);
3959 std::string lengthStr
= secsToTimeString(eventData
.length
* MINUTE
);
3961 PSendSysMessage(LANG_EVENT_INFO
,event_id
,eventData
.description
.c_str(),activeStr
,
3962 startTimeStr
.c_str(),endTimeStr
.c_str(),occurenceStr
.c_str(),lengthStr
.c_str(),
3967 bool ChatHandler::HandleEventStartCommand(const char* args
)
3972 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3973 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
3977 int32 event_id
= atoi(cId
);
3979 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3981 if(event_id
< 1 || event_id
>=events
.size())
3983 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3984 SetSentErrorMessage(true);
3988 GameEventData
const& eventData
= events
[event_id
];
3989 if(!eventData
.isValid())
3991 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3992 SetSentErrorMessage(true);
3996 GameEventMgr::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3997 if(activeEvents
.find(event_id
) != activeEvents
.end())
3999 PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE
,event_id
);
4000 SetSentErrorMessage(true);
4004 gameeventmgr
.StartEvent(event_id
,true);
4008 bool ChatHandler::HandleEventStopCommand(const char* args
)
4013 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
4014 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
4018 int32 event_id
= atoi(cId
);
4020 GameEventMgr::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
4022 if(event_id
< 1 || event_id
>=events
.size())
4024 SendSysMessage(LANG_EVENT_NOT_EXIST
);
4025 SetSentErrorMessage(true);
4029 GameEventData
const& eventData
= events
[event_id
];
4030 if(!eventData
.isValid())
4032 SendSysMessage(LANG_EVENT_NOT_EXIST
);
4033 SetSentErrorMessage(true);
4037 GameEventMgr::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
4039 if(activeEvents
.find(event_id
) == activeEvents
.end())
4041 PSendSysMessage(LANG_EVENT_NOT_ACTIVE
,event_id
);
4042 SetSentErrorMessage(true);
4046 gameeventmgr
.StopEvent(event_id
,true);
4050 bool ChatHandler::HandleCombatStopCommand(const char* args
)
4056 std::string playername
= extractPlayerNameFromLink((char*)args
);
4057 if(playername
.empty())
4059 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4060 SetSentErrorMessage(true);
4064 player
= objmgr
.GetPlayer(playername
.c_str());
4068 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4069 SetSentErrorMessage(true);
4075 player
= getSelectedPlayer();
4078 player
= m_session
->GetPlayer();
4081 // check online security
4082 if (HasLowerSecurity(player
, 0))
4085 player
->CombatStop();
4086 player
->getHostilRefManager().deleteReferences();
4090 bool ChatHandler::HandleLearnAllCraftsCommand(const char* /*args*/)
4092 uint32 classmask
= m_session
->GetPlayer()->getClassMask();
4094 for (uint32 i
= 0; i
< sSkillLineStore
.GetNumRows(); ++i
)
4096 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(i
);
4100 if( skillInfo
->categoryId
== SKILL_CATEGORY_PROFESSION
|| skillInfo
->categoryId
== SKILL_CATEGORY_SECONDARY
)
4102 for (uint32 j
= 0; j
< sSkillLineAbilityStore
.GetNumRows(); ++j
)
4104 SkillLineAbilityEntry
const *skillLine
= sSkillLineAbilityStore
.LookupEntry(j
);
4108 // skip racial skills
4109 if( skillLine
->racemask
!= 0 )
4112 // skip wrong class skills
4113 if( skillLine
->classmask
&& (skillLine
->classmask
& classmask
) == 0)
4116 if( skillLine
->skillId
!= i
|| skillLine
->forward_spellid
)
4119 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(skillLine
->spellId
);
4120 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
4123 m_session
->GetPlayer()->learnSpell(skillLine
->spellId
,false);
4128 SendSysMessage(LANG_COMMAND_LEARN_ALL_CRAFT
);
4132 bool ChatHandler::HandleLearnAllRecipesCommand(const char* args
)
4134 // Learns all recipes of specified profession and sets skill to max
4135 // Example: .learn all_recipes enchanting
4137 Player
* target
= getSelectedPlayer();
4140 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4147 std::wstring wnamepart
;
4149 if(!Utf8toWStr(args
,wnamepart
))
4152 // converting string that we try to find to lower case
4153 wstrToLower( wnamepart
);
4155 uint32 classmask
= m_session
->GetPlayer()->getClassMask();
4157 for (uint32 i
= 0; i
< sSkillLineStore
.GetNumRows(); ++i
)
4159 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(i
);
4163 if( skillInfo
->categoryId
!= SKILL_CATEGORY_PROFESSION
&&
4164 skillInfo
->categoryId
!= SKILL_CATEGORY_SECONDARY
)
4167 int loc
= m_session
->GetSessionDbcLocale();
4168 std::string name
= skillInfo
->name
[loc
];
4170 if(Utf8FitTo(name
, wnamepart
))
4172 for (uint32 j
= 0; j
< sSkillLineAbilityStore
.GetNumRows(); ++j
)
4174 SkillLineAbilityEntry
const *skillLine
= sSkillLineAbilityStore
.LookupEntry(j
);
4178 if( skillLine
->skillId
!= i
|| skillLine
->forward_spellid
)
4181 // skip racial skills
4182 if( skillLine
->racemask
!= 0 )
4185 // skip wrong class skills
4186 if( skillLine
->classmask
&& (skillLine
->classmask
& classmask
) == 0)
4189 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(skillLine
->spellId
);
4190 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
4193 if( !target
->HasSpell(spellInfo
->Id
) )
4194 m_session
->GetPlayer()->learnSpell(skillLine
->spellId
,false);
4197 uint16 maxLevel
= target
->GetPureMaxSkillValue(skillInfo
->id
);
4198 target
->SetSkill(skillInfo
->id
, maxLevel
, maxLevel
);
4199 PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES
, name
.c_str());
4207 bool ChatHandler::HandleLookupPlayerIpCommand(const char* args
)
4213 std::string ip
= strtok ((char*)args
, " ");
4214 char* limit_str
= strtok (NULL
, " ");
4215 int32 limit
= limit_str
? atoi (limit_str
) : -1;
4217 loginDatabase
.escape_string (ip
);
4219 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip
.c_str ());
4221 return LookupPlayerSearchCommand (result
,limit
);
4224 bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args
)
4229 std::string account
= strtok ((char*)args
, " ");
4230 char* limit_str
= strtok (NULL
, " ");
4231 int32 limit
= limit_str
? atoi (limit_str
) : -1;
4233 if (!AccountMgr::normilizeString (account
))
4236 loginDatabase
.escape_string (account
);
4238 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account
.c_str ());
4240 return LookupPlayerSearchCommand (result
,limit
);
4243 bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args
)
4249 std::string email
= strtok ((char*)args
, " ");
4250 char* limit_str
= strtok (NULL
, " ");
4251 int32 limit
= limit_str
? atoi (limit_str
) : -1;
4253 loginDatabase
.escape_string (email
);
4255 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email
.c_str ());
4257 return LookupPlayerSearchCommand (result
,limit
);
4260 bool ChatHandler::LookupPlayerSearchCommand(QueryResult
* result
, int32 limit
)
4264 PSendSysMessage(LANG_NO_PLAYERS_FOUND
);
4265 SetSentErrorMessage(true);
4272 Field
* fields
= result
->Fetch();
4273 uint32 acc_id
= fields
[0].GetUInt32();
4274 std::string acc_name
= fields
[1].GetCppString();
4276 QueryResult
* chars
= CharacterDatabase
.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id
);
4279 PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT
,acc_name
.c_str(),acc_id
);
4286 Field
* charfields
= chars
->Fetch();
4287 guid
= charfields
[0].GetUInt64();
4288 name
= charfields
[1].GetCppString();
4290 PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER
,name
.c_str(),guid
);
4293 } while( chars
->NextRow() && ( limit
== -1 || i
< limit
) );
4297 } while(result
->NextRow());
4301 if(i
==0) // empty accounts only
4303 PSendSysMessage(LANG_NO_PLAYERS_FOUND
);
4304 SetSentErrorMessage(true);
4311 /// Triggering corpses expire check in world
4312 bool ChatHandler::HandleServerCorpsesCommand(const char* /*args*/)
4318 bool ChatHandler::HandleRepairitemsCommand(const char* /*args*/)
4320 Player
*target
= getSelectedPlayer();
4324 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
4325 SetSentErrorMessage(true);
4329 // check online security
4330 if (HasLowerSecurity(target
, 0))
4334 target
->DurabilityRepairAll(false, 0, false);
4336 PSendSysMessage(LANG_YOU_REPAIR_ITEMS
, GetNameLink(target
).c_str());
4337 if(needReportToTarget(target
))
4338 ChatHandler(target
).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED
, GetNameLink().c_str());
4342 bool ChatHandler::HandleWaterwalkCommand(const char* args
)
4347 Player
*player
= getSelectedPlayer();
4351 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
4352 SetSentErrorMessage(true);
4356 // check online security
4357 if (HasLowerSecurity(player
, 0))
4360 if (strncmp(args
, "on", 3) == 0)
4361 player
->SetMovement(MOVE_WATER_WALK
); // ON
4362 else if (strncmp(args
, "off", 4) == 0)
4363 player
->SetMovement(MOVE_LAND_WALK
); // OFF
4366 SendSysMessage(LANG_USE_BOL
);
4370 PSendSysMessage(LANG_YOU_SET_WATERWALK
, args
, GetNameLink(player
).c_str());
4371 if(needReportToTarget(player
))
4372 ChatHandler(player
).PSendSysMessage(LANG_YOUR_WATERWALK_SET
, args
, GetNameLink().c_str());