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 "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
27 #include "GameObject.h"
30 #include "ObjectAccessor.h"
31 #include "MapManager.h"
34 #include "GameEvent.h"
36 #include "AccountMgr.h"
37 #include "GMTicketMgr.h"
38 #include "WaypointManager.h"
44 #include "GlobalEvents.h"
46 #include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
48 static uint32 ReputationRankStrIndex
[MAX_REPUTATION_RANK
] =
50 LANG_REP_HATED
, LANG_REP_HOSTILE
, LANG_REP_UNFRIENDLY
, LANG_REP_NEUTRAL
,
51 LANG_REP_FRIENDLY
, LANG_REP_HONORED
, LANG_REP_REVERED
, LANG_REP_EXALTED
54 //mute player for some times
55 bool ChatHandler::HandleMuteCommand(const char* args
)
60 std::string name
= extractPlayerNameFromLink((char*)args
);
63 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
64 SetSentErrorMessage(true);
68 char *timetonotspeak
= strtok(NULL
, " ");
72 uint32 notspeaktime
= (uint32
) atoi(timetonotspeak
);
74 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
77 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
78 SetSentErrorMessage(true);
82 Player
*chr
= objmgr
.GetPlayer(guid
);
84 // must have strong lesser security level
85 if(HasLowerSecurity (chr
,guid
,true))
88 uint32 account_id
= chr
? chr
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(guid
);
90 time_t mutetime
= time(NULL
) + notspeaktime
*60;
93 chr
->GetSession()->m_muteTime
= mutetime
;
95 loginDatabase
.PExecute("UPDATE account SET mutetime = " I64FMTD
" WHERE id = '%u'",uint64(mutetime
), account_id
);
98 ChatHandler(chr
).PSendSysMessage(LANG_YOUR_CHAT_DISABLED
, notspeaktime
);
100 std::string nameLink
= playerLink(name
);
102 PSendSysMessage(LANG_YOU_DISABLE_CHAT
, nameLink
.c_str(), notspeaktime
);
108 bool ChatHandler::HandleUnmuteCommand(const char* args
)
113 std::string name
= extractPlayerNameFromLink((char*)args
);
116 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
117 SetSentErrorMessage(true);
121 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
124 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
125 SetSentErrorMessage(true);
129 Player
*chr
= objmgr
.GetPlayer(guid
);
131 // must have strong lesser security level
132 if(HasLowerSecurity (chr
,guid
,true))
135 uint32 account_id
= chr
? chr
->GetSession()->GetAccountId() : objmgr
.GetPlayerAccountIdByGUID(guid
);
141 SendSysMessage(LANG_CHAT_ALREADY_ENABLED
);
142 SetSentErrorMessage(true);
146 chr
->GetSession()->m_muteTime
= 0;
149 loginDatabase
.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id
);
152 ChatHandler(chr
).PSendSysMessage(LANG_YOUR_CHAT_ENABLED
);
154 std::string nameLink
= playerLink(name
);
156 PSendSysMessage(LANG_YOU_ENABLE_CHAT
, nameLink
.c_str());
160 bool ChatHandler::HandleTargetObjectCommand(const char* args
)
162 Player
* pl
= m_session
->GetPlayer();
164 GameEvent::ActiveEvents
const& activeEventsList
= gameeventmgr
.GetActiveEventList();
167 int32 id
= atoi((char*)args
);
169 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",
170 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),id
);
173 std::string name
= args
;
174 WorldDatabase
.escape_string(name
);
175 result
= WorldDatabase
.PQuery(
176 "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_ "
177 "FROM gameobject,gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" ORDER BY order_ ASC LIMIT 1",
178 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),name
.c_str());
183 std::ostringstream eventFilter
;
184 eventFilter
<< " AND (event IS NULL ";
185 bool initString
= true;
187 for (GameEvent::ActiveEvents::const_iterator itr
= activeEventsList
.begin(); itr
!= activeEventsList
.end(); ++itr
)
191 eventFilter
<< "OR event IN (" <<*itr
;
195 eventFilter
<< "," << *itr
;
203 result
= WorldDatabase
.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, "
204 "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
205 "LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 1",
206 m_session
->GetPlayer()->GetPositionX(), m_session
->GetPlayer()->GetPositionY(), m_session
->GetPlayer()->GetPositionZ(), m_session
->GetPlayer()->GetMapId(),eventFilter
.str().c_str());
211 SendSysMessage(LANG_COMMAND_TARGETOBJNOTFOUND
);
215 Field
*fields
= result
->Fetch();
216 uint32 lowguid
= fields
[0].GetUInt32();
217 uint32 id
= fields
[1].GetUInt32();
218 float x
= fields
[2].GetFloat();
219 float y
= fields
[3].GetFloat();
220 float z
= fields
[4].GetFloat();
221 float o
= fields
[5].GetFloat();
222 int mapid
= fields
[6].GetUInt16();
225 GameObjectInfo
const* goI
= objmgr
.GetGameObjectInfo(id
);
229 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
233 GameObject
* target
= ObjectAccessor::GetGameObject(*m_session
->GetPlayer(),MAKE_NEW_GUID(lowguid
,id
,HIGHGUID_GAMEOBJECT
));
235 PSendSysMessage(LANG_GAMEOBJECT_DETAIL
, lowguid
, goI
->name
, lowguid
, id
, x
, y
, z
, mapid
, o
);
239 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
240 if(curRespawnDelay
< 0)
243 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
244 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
246 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
251 //teleport to gameobject
252 bool ChatHandler::HandleGoObjectCommand(const char* args
)
257 Player
* _player
= m_session
->GetPlayer();
259 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
260 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
264 int32 guid
= atoi(cId
);
272 if (GameObjectData
const* go_data
= objmgr
.GetGOData(guid
))
277 ort
= go_data
->orientation
;
278 mapid
= go_data
->mapid
;
282 SendSysMessage(LANG_COMMAND_GOOBJNOTFOUND
);
283 SetSentErrorMessage(true);
287 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
,ort
))
289 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
290 SetSentErrorMessage(true);
294 // stop flight if need
295 if(_player
->isInFlight())
297 _player
->GetMotionMaster()->MovementExpired();
298 _player
->m_taxi
.ClearTaxiDestinations();
300 // save only in non-flight case
302 _player
->SaveRecallPosition();
304 _player
->TeleportTo(mapid
, x
, y
, z
, ort
);
308 bool ChatHandler::HandleGoTriggerCommand(const char* args
)
310 Player
* _player
= m_session
->GetPlayer();
315 char *atId
= strtok((char*)args
, " ");
319 int32 i_atId
= atoi(atId
);
324 AreaTriggerEntry
const* at
= sAreaTriggerStore
.LookupEntry(i_atId
);
327 PSendSysMessage(LANG_COMMAND_GOAREATRNOTFOUND
,i_atId
);
328 SetSentErrorMessage(true);
332 if(!MapManager::IsValidMapCoord(at
->mapid
,at
->x
,at
->y
,at
->z
))
334 PSendSysMessage(LANG_INVALID_TARGET_COORD
,at
->x
,at
->y
,at
->mapid
);
335 SetSentErrorMessage(true);
339 // stop flight if need
340 if(_player
->isInFlight())
342 _player
->GetMotionMaster()->MovementExpired();
343 _player
->m_taxi
.ClearTaxiDestinations();
345 // save only in non-flight case
347 _player
->SaveRecallPosition();
349 _player
->TeleportTo(at
->mapid
, at
->x
, at
->y
, at
->z
, _player
->GetOrientation());
353 bool ChatHandler::HandleGoGraveyardCommand(const char* args
)
355 Player
* _player
= m_session
->GetPlayer();
360 char *gyId
= strtok((char*)args
, " ");
364 int32 i_gyId
= atoi(gyId
);
369 WorldSafeLocsEntry
const* gy
= sWorldSafeLocsStore
.LookupEntry(i_gyId
);
372 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
,i_gyId
);
373 SetSentErrorMessage(true);
377 if(!MapManager::IsValidMapCoord(gy
->map_id
,gy
->x
,gy
->y
,gy
->z
))
379 PSendSysMessage(LANG_INVALID_TARGET_COORD
,gy
->x
,gy
->y
,gy
->map_id
);
380 SetSentErrorMessage(true);
384 // stop flight if need
385 if(_player
->isInFlight())
387 _player
->GetMotionMaster()->MovementExpired();
388 _player
->m_taxi
.ClearTaxiDestinations();
390 // save only in non-flight case
392 _player
->SaveRecallPosition();
394 _player
->TeleportTo(gy
->map_id
, gy
->x
, gy
->y
, gy
->z
, _player
->GetOrientation());
398 /** \brief Teleport the GM to the specified creature
400 * .gocreature <GUID> --> TP using creature.guid
401 * .gocreature azuregos --> TP player to the mob with this name
402 * Warning: If there is more than one mob with this name
403 * you will be teleported to the first one that is found.
404 * .gocreature id 6109 --> TP player to the mob, that has this creature_template.entry
405 * Warning: If there is more than one mob with this "id"
406 * you will be teleported to the first one that is found.
408 //teleport to creature
409 bool ChatHandler::HandleGoCreatureCommand(const char* args
)
413 Player
* _player
= m_session
->GetPlayer();
415 // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
416 char* pParam1
= extractKeyFromLink((char*)args
,"Hcreature");
420 std::ostringstream whereClause
;
422 // User wants to teleport to the NPC's template entry
423 if( strcmp(pParam1
, "id") == 0 )
425 //sLog.outError("DEBUG: ID found");
427 // Get the "creature_template.entry"
428 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
429 char* tail
= strtok(NULL
,"");
432 char* cId
= extractKeyFromLink(tail
,"Hcreature_entry");
436 int32 tEntry
= atoi(cId
);
437 //sLog.outError("DEBUG: ID value: %d", tEntry);
441 whereClause
<< "WHERE id = '" << tEntry
<< "'";
445 //sLog.outError("DEBUG: ID *not found*");
447 int32 guid
= atoi(pParam1
);
449 // Number is invalid - maybe the user specified the mob's name
452 std::string name
= pParam1
;
453 WorldDatabase
.escape_string(name
);
454 whereClause
<< ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name "_LIKE_
" '" << name
<< "'";
458 whereClause
<< "WHERE guid = '" << guid
<< "'";
461 //sLog.outError("DEBUG: %s", whereClause.c_str());
463 QueryResult
*result
= WorldDatabase
.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause
.str().c_str() );
466 SendSysMessage(LANG_COMMAND_GOCREATNOTFOUND
);
467 SetSentErrorMessage(true);
470 if( result
->GetRowCount() > 1 )
472 SendSysMessage(LANG_COMMAND_GOCREATMULTIPLE
);
475 Field
*fields
= result
->Fetch();
476 float x
= fields
[0].GetFloat();
477 float y
= fields
[1].GetFloat();
478 float z
= fields
[2].GetFloat();
479 float ort
= fields
[3].GetFloat();
480 int mapid
= fields
[4].GetUInt16();
484 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
,ort
))
486 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
487 SetSentErrorMessage(true);
491 // stop flight if need
492 if(_player
->isInFlight())
494 _player
->GetMotionMaster()->MovementExpired();
495 _player
->m_taxi
.ClearTaxiDestinations();
497 // save only in non-flight case
499 _player
->SaveRecallPosition();
501 _player
->TeleportTo(mapid
, x
, y
, z
, ort
);
505 bool ChatHandler::HandleGUIDCommand(const char* /*args*/)
507 uint64 guid
= m_session
->GetPlayer()->GetSelection();
511 SendSysMessage(LANG_NO_SELECTION
);
512 SetSentErrorMessage(true);
516 PSendSysMessage(LANG_OBJECT_GUID
, GUID_LOPART(guid
), GUID_HIPART(guid
));
520 bool ChatHandler::HandleLookupFactionCommand(const char* args
)
525 // Can be NULL at console call
526 Player
*target
= getSelectedPlayer ();
528 std::string namepart
= args
;
529 std::wstring wnamepart
;
531 if (!Utf8toWStr (namepart
,wnamepart
))
534 // converting string that we try to find to lower case
535 wstrToLower (wnamepart
);
537 uint32 counter
= 0; // Counter for figure out that we found smth.
539 for (uint32 id
= 0; id
< sFactionStore
.GetNumRows(); ++id
)
541 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry (id
);
544 FactionState
const* repState
= NULL
;
547 FactionStateList::const_iterator repItr
= target
->m_factions
.find (factionEntry
->reputationListID
);
548 if(repItr
!= target
->m_factions
.end())
549 repState
= &repItr
->second
;
553 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
554 std::string name
= factionEntry
->name
[loc
];
558 if (!Utf8FitTo(name
, wnamepart
))
561 for(; loc
< MAX_LOCALE
; ++loc
)
563 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
566 name
= factionEntry
->name
[loc
];
570 if (Utf8FitTo(name
, wnamepart
))
577 // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
578 // or "id - [faction] [no reputation]" format
579 std::ostringstream ss
;
581 ss
<< id
<< " - |cffffffff|Hfaction:" << id
<< "|h[" << name
<< " " << localeNames
[loc
] << "]|h|r";
583 ss
<< id
<< " - " << name
<< " " << localeNames
[loc
];
585 if (repState
) // and then target!=NULL also
587 ReputationRank rank
= target
->GetReputationRank(factionEntry
);
588 std::string rankName
= GetMangosString(ReputationRankStrIndex
[rank
]);
590 ss
<< " " << rankName
<< "|h|r (" << target
->GetReputation(factionEntry
) << ")";
592 if(repState
->Flags
& FACTION_FLAG_VISIBLE
)
593 ss
<< GetMangosString(LANG_FACTION_VISIBLE
);
594 if(repState
->Flags
& FACTION_FLAG_AT_WAR
)
595 ss
<< GetMangosString(LANG_FACTION_ATWAR
);
596 if(repState
->Flags
& FACTION_FLAG_PEACE_FORCED
)
597 ss
<< GetMangosString(LANG_FACTION_PEACE_FORCED
);
598 if(repState
->Flags
& FACTION_FLAG_HIDDEN
)
599 ss
<< GetMangosString(LANG_FACTION_HIDDEN
);
600 if(repState
->Flags
& FACTION_FLAG_INVISIBLE_FORCED
)
601 ss
<< GetMangosString(LANG_FACTION_INVISIBLE_FORCED
);
602 if(repState
->Flags
& FACTION_FLAG_INACTIVE
)
603 ss
<< GetMangosString(LANG_FACTION_INACTIVE
);
606 ss
<< GetMangosString(LANG_FACTION_NOREPUTATION
);
608 SendSysMessage(ss
.str().c_str());
614 if (counter
== 0) // if counter == 0 then we found nth
615 SendSysMessage(LANG_COMMAND_FACTION_NOTFOUND
);
619 bool ChatHandler::HandleModifyRepCommand(const char * args
)
621 if (!*args
) return false;
623 Player
* target
= NULL
;
624 target
= getSelectedPlayer();
628 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
629 SetSentErrorMessage(true);
633 // check online security
634 if (HasLowerSecurity(target
, 0))
637 char* factionTxt
= extractKeyFromLink((char*)args
,"Hfaction");
641 uint32 factionId
= atoi(factionTxt
);
644 char *rankTxt
= strtok(NULL
, " ");
645 if (!factionTxt
|| !rankTxt
)
648 amount
= atoi(rankTxt
);
649 if ((amount
== 0) && (rankTxt
[0] != '-') && !isdigit(rankTxt
[0]))
651 std::string rankStr
= rankTxt
;
652 std::wstring wrankStr
;
653 if(!Utf8toWStr(rankStr
,wrankStr
))
655 wstrToLower( wrankStr
);
659 for (; r
< MAX_REPUTATION_RANK
; ++r
)
661 std::string rank
= GetMangosString(ReputationRankStrIndex
[r
]);
666 if(!Utf8toWStr(rank
,wrank
))
671 if(wrank
.substr(0,wrankStr
.size())==wrankStr
)
673 char *deltaTxt
= strtok(NULL
, " ");
676 int32 delta
= atoi(deltaTxt
);
677 if ((delta
< 0) || (delta
> Player::ReputationRank_Length
[r
] -1))
679 PSendSysMessage(LANG_COMMAND_FACTION_DELTA
, (Player::ReputationRank_Length
[r
]-1));
680 SetSentErrorMessage(true);
687 amount
+= Player::ReputationRank_Length
[r
];
689 if (r
>= MAX_REPUTATION_RANK
)
691 PSendSysMessage(LANG_COMMAND_FACTION_INVPARAM
, rankTxt
);
692 SetSentErrorMessage(true);
697 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(factionId
);
701 PSendSysMessage(LANG_COMMAND_FACTION_UNKNOWN
, factionId
);
702 SetSentErrorMessage(true);
706 if (factionEntry
->reputationListID
< 0)
708 PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR
, factionEntry
->name
[m_session
->GetSessionDbcLocale()], factionId
);
709 SetSentErrorMessage(true);
713 target
->SetFactionReputation(factionEntry
,amount
);
714 PSendSysMessage(LANG_COMMAND_MODIFY_REP
, factionEntry
->name
[m_session
->GetSessionDbcLocale()], factionId
, GetNameLink(target
).c_str(), target
->GetReputation(factionId
));
718 bool ChatHandler::HandleNameCommand(const char* /*args*/)
724 if(strlen((char*)args)>75)
726 PSendSysMessage(LANG_TOO_LONG_NAME, strlen((char*)args)-75);
730 for (uint8 i = 0; i < strlen(args); i++)
732 if(!isalpha(args[i]) && args[i]!=' ')
734 SendSysMessage(LANG_CHARS_ONLY);
740 guid = m_session->GetPlayer()->GetSelection();
743 SendSysMessage(LANG_NO_SELECTION);
747 Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
751 SendSysMessage(LANG_SELECT_CREATURE);
755 pCreature->SetName(args);
756 uint32 idname = objmgr.AddCreatureTemplate(pCreature->GetName());
757 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
759 pCreature->SaveToDB();
765 bool ChatHandler::HandleSubNameCommand(const char* /*args*/)
772 if(strlen((char*)args)>75)
775 PSendSysMessage(LANG_TOO_LONG_SUBNAME, strlen((char*)args)-75);
779 for (uint8 i = 0; i < strlen(args); i++)
781 if(!isalpha(args[i]) && args[i]!=' ')
783 SendSysMessage(LANG_CHARS_ONLY);
788 guid = m_session->GetPlayer()->GetSelection();
791 SendSysMessage(LANG_NO_SELECTION);
795 Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
799 SendSysMessage(LANG_SELECT_CREATURE);
803 uint32 idname = objmgr.AddCreatureSubName(pCreature->GetName(),args,pCreature->GetUInt32Value(UNIT_FIELD_DISPLAYID));
804 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
806 pCreature->SaveToDB();
811 //move item to other slot
812 bool ChatHandler::HandleItemMoveCommand(const char* args
)
816 uint8 srcslot
, dstslot
;
818 char* pParam1
= strtok((char*)args
, " ");
822 char* pParam2
= strtok(NULL
, " ");
826 srcslot
= (uint8
)atoi(pParam1
);
827 dstslot
= (uint8
)atoi(pParam2
);
832 if(!m_session
->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0
,srcslot
))
835 if(!m_session
->GetPlayer()->IsValidPos(INVENTORY_SLOT_BAG_0
,dstslot
))
838 uint16 src
= ((INVENTORY_SLOT_BAG_0
<< 8) | srcslot
);
839 uint16 dst
= ((INVENTORY_SLOT_BAG_0
<< 8) | dstslot
);
841 m_session
->GetPlayer()->SwapItem( src
, dst
);
846 //add spawn of creature
847 bool ChatHandler::HandleNpcAddCommand(const char* args
)
851 char* charID
= extractKeyFromLink((char*)args
,"Hcreature_entry");
855 char* team
= strtok(NULL
, " ");
857 if (team
) { teamval
= atoi(team
); }
858 if (teamval
< 0) { teamval
= 0; }
860 uint32 id
= atoi(charID
);
862 Player
*chr
= m_session
->GetPlayer();
863 float x
= chr
->GetPositionX();
864 float y
= chr
->GetPositionY();
865 float z
= chr
->GetPositionZ();
866 float o
= chr
->GetOrientation();
867 Map
*map
= chr
->GetMap();
869 Creature
* pCreature
= new Creature
;
870 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, (uint32
)teamval
))
876 pCreature
->Relocate(x
,y
,z
,o
);
878 if(!pCreature
->IsPositionValid())
880 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
885 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
887 uint32 db_guid
= pCreature
->GetDBTableGUIDLow();
889 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
890 pCreature
->LoadFromDB(db_guid
, map
);
893 objmgr
.AddCreatureToGrid(db_guid
, objmgr
.GetCreatureData(db_guid
));
897 bool ChatHandler::HandleNpcDeleteCommand(const char* args
)
899 Creature
* unit
= NULL
;
903 // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
904 char* cId
= extractKeyFromLink((char*)args
,"Hcreature");
908 uint32 lowguid
= atoi(cId
);
912 if (CreatureData
const* cr_data
= objmgr
.GetCreatureData(lowguid
))
913 unit
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), MAKE_NEW_GUID(lowguid
, cr_data
->id
, HIGHGUID_UNIT
));
916 unit
= getSelectedCreature();
918 if(!unit
|| unit
->isPet() || unit
->isTotem() || unit
->isVehicle())
920 SendSysMessage(LANG_SELECT_CREATURE
);
921 SetSentErrorMessage(true);
925 // Delete the creature
927 unit
->DeleteFromDB();
928 unit
->CleanupsBeforeDelete();
929 unit
->AddObjectToRemoveList();
931 SendSysMessage(LANG_COMMAND_DELCREATMESSAGE
);
936 //delete object by selection or guid
937 bool ChatHandler::HandleDelObjectCommand(const char* args
)
939 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
940 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
944 uint32 lowguid
= atoi(cId
);
948 GameObject
* obj
= NULL
;
951 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
952 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
956 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
957 SetSentErrorMessage(true);
961 uint64 owner_guid
= obj
->GetOwnerGUID();
964 Unit
* owner
= ObjectAccessor::GetUnit(*m_session
->GetPlayer(),owner_guid
);
965 if(!owner
&& !IS_PLAYER_GUID(owner_guid
))
967 PSendSysMessage(LANG_COMMAND_DELOBJREFERCREATURE
, GUID_LOPART(owner_guid
), obj
->GetGUIDLow());
968 SetSentErrorMessage(true);
972 owner
->RemoveGameObject(obj
,false);
975 obj
->SetRespawnTime(0); // not save respawn time
979 PSendSysMessage(LANG_COMMAND_DELOBJMESSAGE
, obj
->GetGUIDLow());
984 //turn selected object
985 bool ChatHandler::HandleTurnObjectCommand(const char* args
)
987 // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
988 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
992 uint32 lowguid
= atoi(cId
);
996 GameObject
* obj
= NULL
;
999 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
1000 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
1004 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
1005 SetSentErrorMessage(true);
1009 char* po
= strtok(NULL
, " ");
1014 o
= (float)atof(po
);
1018 Player
*chr
= m_session
->GetPlayer();
1019 o
= chr
->GetOrientation();
1022 float rot2
= sin(o
/2);
1023 float rot3
= cos(o
/2);
1025 Map
* map
= obj
->GetMap();
1026 map
->Remove(obj
,false);
1028 obj
->Relocate(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), o
);
1030 obj
->SetFloatValue(GAMEOBJECT_FACING
, o
);
1031 obj
->SetFloatValue(GAMEOBJECT_PARENTROTATION
+2, rot2
);
1032 obj
->SetFloatValue(GAMEOBJECT_PARENTROTATION
+3, rot3
);
1039 PSendSysMessage(LANG_COMMAND_TURNOBJMESSAGE
, obj
->GetGUIDLow(), o
);
1044 //move selected creature
1045 bool ChatHandler::HandleNpcMoveCommand(const char* args
)
1049 Creature
* pCreature
= getSelectedCreature();
1053 // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
1054 char* cId
= extractKeyFromLink((char*)args
,"Hcreature");
1058 uint32 lowguid
= atoi(cId
);
1060 /* FIXME: impossibel without entry
1062 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1065 // Attempting creature load from DB data
1068 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1071 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1072 SetSentErrorMessage(true);
1076 uint32 map_id
= data
->mapid
;
1078 if(m_session
->GetPlayer()->GetMapId()!=map_id
)
1080 PSendSysMessage(LANG_COMMAND_CREATUREATSAMEMAP
, lowguid
);
1081 SetSentErrorMessage(true);
1087 lowguid
= pCreature
->GetDBTableGUIDLow();
1092 lowguid
= pCreature
->GetDBTableGUIDLow();
1095 float x
= m_session
->GetPlayer()->GetPositionX();
1096 float y
= m_session
->GetPlayer()->GetPositionY();
1097 float z
= m_session
->GetPlayer()->GetPositionZ();
1098 float o
= m_session
->GetPlayer()->GetOrientation();
1102 if(CreatureData
const* data
= objmgr
.GetCreatureData(pCreature
->GetDBTableGUIDLow()))
1104 const_cast<CreatureData
*>(data
)->posX
= x
;
1105 const_cast<CreatureData
*>(data
)->posY
= y
;
1106 const_cast<CreatureData
*>(data
)->posZ
= z
;
1107 const_cast<CreatureData
*>(data
)->orientation
= o
;
1109 pCreature
->GetMap()->CreatureRelocation(pCreature
,x
, y
, z
,o
);
1110 pCreature
->GetMotionMaster()->Initialize();
1111 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1113 pCreature
->setDeathState(JUST_DIED
);
1114 pCreature
->Respawn();
1118 WorldDatabase
.PExecuteLog("UPDATE creature SET position_x = '%f', position_y = '%f', position_z = '%f', orientation = '%f' WHERE guid = '%u'", x
, y
, z
, o
, lowguid
);
1119 PSendSysMessage(LANG_COMMAND_CREATUREMOVED
);
1123 //move selected object
1124 bool ChatHandler::HandleMoveObjectCommand(const char* args
)
1126 // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
1127 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
1131 uint32 lowguid
= atoi(cId
);
1135 GameObject
* obj
= NULL
;
1138 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
1139 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
1143 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
1144 SetSentErrorMessage(true);
1148 char* px
= strtok(NULL
, " ");
1149 char* py
= strtok(NULL
, " ");
1150 char* pz
= strtok(NULL
, " ");
1154 Player
*chr
= m_session
->GetPlayer();
1156 Map
* map
= obj
->GetMap();
1157 map
->Remove(obj
,false);
1159 obj
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), obj
->GetOrientation());
1160 obj
->SetFloatValue(GAMEOBJECT_POS_X
, chr
->GetPositionX());
1161 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, chr
->GetPositionY());
1162 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, chr
->GetPositionZ());
1171 float x
= (float)atof(px
);
1172 float y
= (float)atof(py
);
1173 float z
= (float)atof(pz
);
1175 if(!MapManager::IsValidMapCoord(obj
->GetMapId(),x
,y
,z
))
1177 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,obj
->GetMapId());
1178 SetSentErrorMessage(true);
1182 Map
* map
= obj
->GetMap();
1183 map
->Remove(obj
,false);
1185 obj
->Relocate(x
, y
, z
, obj
->GetOrientation());
1186 obj
->SetFloatValue(GAMEOBJECT_POS_X
, x
);
1187 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, y
);
1188 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, z
);
1196 PSendSysMessage(LANG_COMMAND_MOVEOBJMESSAGE
, obj
->GetGUIDLow());
1201 //demorph player or unit
1202 bool ChatHandler::HandleDeMorphCommand(const char* /*args*/)
1204 Unit
*target
= getSelectedUnit();
1206 target
= m_session
->GetPlayer();
1209 // check online security
1210 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
1218 //add item in vendorlist
1219 bool ChatHandler::HandleAddVendorItemCommand(const char* args
)
1224 char* pitem
= extractKeyFromLink((char*)args
,"Hitem");
1227 SendSysMessage(LANG_COMMAND_NEEDITEMSEND
);
1228 SetSentErrorMessage(true);
1232 uint32 itemId
= atol(pitem
);
1234 char* fmaxcount
= strtok(NULL
, " "); //add maxcount, default: 0
1235 uint32 maxcount
= 0;
1237 maxcount
= atol(fmaxcount
);
1239 char* fincrtime
= strtok(NULL
, " "); //add incrtime, default: 0
1240 uint32 incrtime
= 0;
1242 incrtime
= atol(fincrtime
);
1244 char* fextendedcost
= strtok(NULL
, " "); //add ExtendedCost, default: 0
1245 uint32 extendedcost
= fextendedcost
? atol(fextendedcost
) : 0;
1247 Creature
* vendor
= getSelectedCreature();
1249 uint32 vendor_entry
= vendor
? vendor
->GetEntry() : 0;
1251 if(!objmgr
.IsVendorItemValid(vendor_entry
,itemId
,maxcount
,incrtime
,extendedcost
,m_session
->GetPlayer()))
1253 SetSentErrorMessage(true);
1257 objmgr
.AddVendorItem(vendor_entry
,itemId
,maxcount
,incrtime
,extendedcost
);
1259 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(itemId
);
1261 PSendSysMessage(LANG_ITEM_ADDED_TO_LIST
,itemId
,pProto
->Name1
,maxcount
,incrtime
,extendedcost
);
1265 //del item from vendor list
1266 bool ChatHandler::HandleDelVendorItemCommand(const char* args
)
1271 Creature
* vendor
= getSelectedCreature();
1272 if (!vendor
|| !vendor
->isVendor())
1274 SendSysMessage(LANG_COMMAND_VENDORSELECTION
);
1275 SetSentErrorMessage(true);
1279 char* pitem
= extractKeyFromLink((char*)args
,"Hitem");
1282 SendSysMessage(LANG_COMMAND_NEEDITEMSEND
);
1283 SetSentErrorMessage(true);
1286 uint32 itemId
= atol(pitem
);
1288 if(!objmgr
.RemoveVendorItem(vendor
->GetEntry(),itemId
))
1290 PSendSysMessage(LANG_ITEM_NOT_IN_LIST
,itemId
);
1291 SetSentErrorMessage(true);
1295 ItemPrototype
const* pProto
= objmgr
.GetItemPrototype(itemId
);
1297 PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST
,itemId
,pProto
->Name1
);
1301 //add move for creature
1302 bool ChatHandler::HandleNpcAddMoveCommand(const char* args
)
1307 char* guid_str
= strtok((char*)args
, " ");
1308 char* wait_str
= strtok((char*)NULL
, " ");
1310 uint32 lowguid
= atoi((char*)guid_str
);
1312 Creature
* pCreature
= NULL
;
1314 /* FIXME: impossible without entry
1316 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1319 // attempt check creature existence by DB data
1322 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1325 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1326 SetSentErrorMessage(true);
1332 // obtain real GUID for DB operations
1333 lowguid
= pCreature
->GetDBTableGUIDLow();
1336 int wait
= wait_str
? atoi(wait_str
) : 0;
1341 Player
* player
= m_session
->GetPlayer();
1343 WaypointMgr
.AddLastNode(lowguid
, player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(), player
->GetOrientation(), wait
, 0);
1345 // update movement type
1346 WorldDatabase
.PExecuteLog("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE
,lowguid
);
1349 pCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
1350 pCreature
->GetMotionMaster()->Initialize();
1351 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1353 pCreature
->setDeathState(JUST_DIED
);
1354 pCreature
->Respawn();
1356 pCreature
->SaveToDB();
1359 SendSysMessage(LANG_WAYPOINT_ADDED
);
1365 * Set the movement type for an NPC.<br/>
1367 * Valid movement types are:
1369 * <li> stay - NPC wont move </li>
1370 * <li> random - NPC will move randomly according to the spawndist </li>
1371 * <li> way - NPC will move with given waypoints set </li>
1373 * additional parameter: NODEL - so no waypoints are deleted, if you
1374 * change the movement type
1376 bool ChatHandler::HandleNpcSetMoveTypeCommand(const char* args
)
1382 // GUID (optional - you can also select the creature)
1383 // stay|random|way (determines the kind of movement)
1384 // NODEL (optional - tells the system NOT to delete any waypoints)
1385 // this is very handy if you want to do waypoints, that are
1386 // later switched on/off according to special events (like escort
1388 char* guid_str
= strtok((char*)args
, " ");
1389 char* type_str
= strtok((char*)NULL
, " ");
1390 char* dontdel_str
= strtok((char*)NULL
, " ");
1392 bool doNotDelete
= false;
1398 Creature
* pCreature
= NULL
;
1402 //sLog.outError("DEBUG: All 3 params are set");
1404 // All 3 params are set
1408 if( stricmp( dontdel_str
, "NODEL" ) == 0 )
1410 //sLog.outError("DEBUG: doNotDelete = true;");
1416 // Only 2 params - but maybe NODEL is set
1419 sLog
.outError("DEBUG: Only 2 params ");
1420 if( stricmp( type_str
, "NODEL" ) == 0 )
1422 //sLog.outError("DEBUG: type_str, NODEL ");
1429 if(!type_str
) // case .setmovetype $move_type (with selected creature)
1431 type_str
= guid_str
;
1432 pCreature
= getSelectedCreature();
1433 if(!pCreature
|| pCreature
->isPet())
1435 lowguid
= pCreature
->GetDBTableGUIDLow();
1437 else // case .setmovetype #creature_guid $move_type (with selected creature)
1439 lowguid
= atoi((char*)guid_str
);
1441 /* impossible without entry
1443 pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1446 // attempt check creature existence by DB data
1449 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
1452 PSendSysMessage(LANG_COMMAND_CREATGUIDNOTFOUND
, lowguid
);
1453 SetSentErrorMessage(true);
1459 lowguid
= pCreature
->GetDBTableGUIDLow();
1463 // now lowguid is low guid really existed creature
1464 // and pCreature point (maybe) to this creature or NULL
1466 MovementGeneratorType move_type
;
1468 std::string type
= type_str
;
1471 move_type
= IDLE_MOTION_TYPE
;
1472 else if(type
== "random")
1473 move_type
= RANDOM_MOTION_TYPE
;
1474 else if(type
== "way")
1475 move_type
= WAYPOINT_MOTION_TYPE
;
1479 // update movement type
1480 if(doNotDelete
== false)
1481 WaypointMgr
.DeletePath(lowguid
);
1485 pCreature
->SetDefaultMovementType(move_type
);
1486 pCreature
->GetMotionMaster()->Initialize();
1487 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
1489 pCreature
->setDeathState(JUST_DIED
);
1490 pCreature
->Respawn();
1492 pCreature
->SaveToDB();
1494 if( doNotDelete
== false )
1496 PSendSysMessage(LANG_MOVE_TYPE_SET
,type_str
);
1500 PSendSysMessage(LANG_MOVE_TYPE_SET_NODEL
,type_str
);
1504 } // HandleNpcSetMoveTypeCommand
1506 //change level of creature or pet
1507 bool ChatHandler::HandleChangeLevelCommand(const char* args
)
1512 uint8 lvl
= (uint8
) atoi((char*)args
);
1513 if ( lvl
< 1 || lvl
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) + 3)
1515 SendSysMessage(LANG_BAD_VALUE
);
1516 SetSentErrorMessage(true);
1520 Creature
* pCreature
= getSelectedCreature();
1523 SendSysMessage(LANG_SELECT_CREATURE
);
1524 SetSentErrorMessage(true);
1528 if(pCreature
->isPet())
1530 ((Pet
*)pCreature
)->GivePetLevel(lvl
);
1534 pCreature
->SetMaxHealth( 100 + 30*lvl
);
1535 pCreature
->SetHealth( 100 + 30*lvl
);
1536 pCreature
->SetLevel( lvl
);
1537 pCreature
->SaveToDB();
1543 //set npcflag of creature
1544 bool ChatHandler::HandleNpcFlagCommand(const char* args
)
1549 uint32 npcFlags
= (uint32
) atoi((char*)args
);
1551 Creature
* pCreature
= getSelectedCreature();
1555 SendSysMessage(LANG_SELECT_CREATURE
);
1556 SetSentErrorMessage(true);
1560 pCreature
->SetUInt32Value(UNIT_NPC_FLAGS
, npcFlags
);
1562 WorldDatabase
.PExecuteLog("UPDATE creature_template SET npcflag = '%u' WHERE entry = '%u'", npcFlags
, pCreature
->GetEntry());
1564 SendSysMessage(LANG_VALUE_SAVED_REJOIN
);
1569 //set model of creature
1570 bool ChatHandler::HandleNpcSetModelCommand(const char* args
)
1575 uint32 displayId
= (uint32
) atoi((char*)args
);
1577 Creature
*pCreature
= getSelectedCreature();
1579 if(!pCreature
|| pCreature
->isPet())
1581 SendSysMessage(LANG_SELECT_CREATURE
);
1582 SetSentErrorMessage(true);
1586 pCreature
->SetDisplayId(displayId
);
1587 pCreature
->SetNativeDisplayId(displayId
);
1589 pCreature
->SaveToDB();
1594 //morph creature or player
1595 bool ChatHandler::HandleMorphCommand(const char* args
)
1600 uint16 display_id
= (uint16
)atoi((char*)args
);
1602 Unit
*target
= getSelectedUnit();
1604 target
= m_session
->GetPlayer();
1606 // check online security
1607 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
1610 target
->SetDisplayId(display_id
);
1615 //set faction of creature
1616 bool ChatHandler::HandleNpcFactionIdCommand(const char* args
)
1621 uint32 factionId
= (uint32
) atoi((char*)args
);
1623 if (!sFactionTemplateStore
.LookupEntry(factionId
))
1625 PSendSysMessage(LANG_WRONG_FACTION
, factionId
);
1626 SetSentErrorMessage(true);
1630 Creature
* pCreature
= getSelectedCreature();
1634 SendSysMessage(LANG_SELECT_CREATURE
);
1635 SetSentErrorMessage(true);
1639 pCreature
->setFaction(factionId
);
1641 // faction is set in creature_template - not inside creature
1644 if(CreatureInfo
const *cinfo
= pCreature
->GetCreatureInfo())
1646 const_cast<CreatureInfo
*>(cinfo
)->faction_A
= factionId
;
1647 const_cast<CreatureInfo
*>(cinfo
)->faction_H
= factionId
;
1651 WorldDatabase
.PExecuteLog("UPDATE creature_template SET faction_A = '%u', faction_H = '%u' WHERE entry = '%u'", factionId
, factionId
, pCreature
->GetEntry());
1657 bool ChatHandler::HandleKickPlayerCommand(const char *args
)
1661 Player
* player
= getSelectedPlayer();
1665 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1666 SetSentErrorMessage(true);
1670 if(player
==m_session
->GetPlayer())
1672 SendSysMessage(LANG_COMMAND_KICKSELF
);
1673 SetSentErrorMessage(true);
1677 // check online security
1678 if (HasLowerSecurity(player
, 0))
1681 player
->GetSession()->KickPlayer();
1685 std::string name
= extractPlayerNameFromLink((char*)args
);
1688 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1689 SetSentErrorMessage(true);
1693 if(m_session
&& name
==m_session
->GetPlayer()->GetName())
1695 SendSysMessage(LANG_COMMAND_KICKSELF
);
1696 SetSentErrorMessage(true);
1700 // check online security
1701 Player
* player
= ObjectAccessor::Instance().FindPlayerByName(name
.c_str());
1702 if (player
&& HasLowerSecurity(player
, 0))
1705 std::string nameLink
= playerLink(name
);
1707 if(sWorld
.KickPlayer(name
))
1709 PSendSysMessage(LANG_COMMAND_KICKMESSAGE
,nameLink
.c_str());
1712 PSendSysMessage(LANG_COMMAND_KICKNOTFOUNDPLAYER
,nameLink
.c_str());
1718 //set temporary phase mask for player
1719 bool ChatHandler::HandleModifyPhaseCommand(const char* args
)
1724 uint32 phasemask
= (uint32
)atoi((char*)args
);
1726 Unit
*target
= getSelectedUnit();
1728 target
= m_session
->GetPlayer();
1730 // check online security
1731 else if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
1734 target
->SetPhaseMask(phasemask
,true);
1739 //show info of player
1740 bool ChatHandler::HandlePInfoCommand(const char* args
)
1742 Player
* target
= NULL
;
1743 uint64 targetGUID
= 0;
1745 char* px
= strtok((char*)args
, " ");
1752 name
= extractPlayerNameFromLink(px
);
1755 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1756 SetSentErrorMessage(true);
1760 target
= objmgr
.GetPlayer(name
.c_str());
1762 py
= strtok(NULL
, " ");
1765 targetGUID
= objmgr
.GetPlayerGUIDByName(name
);
1767 py
= strtok(NULL
, " ");
1773 if(!target
&& !targetGUID
)
1775 target
= getSelectedPlayer();
1778 if(!target
&& !targetGUID
)
1780 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1781 SetSentErrorMessage(true);
1787 uint32 total_player_time
= 0;
1791 // get additional information from Player object
1794 // check online security
1795 if (HasLowerSecurity(target
, 0))
1798 targetGUID
= target
->GetGUID();
1799 name
= target
->GetName(); // re-read for case getSelectedPlayer() target
1800 accId
= target
->GetSession()->GetAccountId();
1801 money
= target
->GetMoney();
1802 total_player_time
= target
->GetTotalPlayedTime();
1803 level
= target
->getLevel();
1804 latency
= target
->GetSession()->GetLatency();
1806 // get additional information from DB
1809 // check offline security
1810 if (HasLowerSecurity(NULL
, targetGUID
))
1814 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT totaltime FROM characters WHERE guid = '%u'", GUID_LOPART(targetGUID
));
1817 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1818 SetSentErrorMessage(true);
1821 Field
*fields
= result
->Fetch();
1822 total_player_time
= fields
[0].GetUInt32();
1826 if (!Player::LoadValuesArrayFromDB(data
,targetGUID
))
1828 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1829 SetSentErrorMessage(true);
1833 money
= Player::GetUInt32ValueFromArray(data
, PLAYER_FIELD_COINAGE
);
1834 level
= Player::GetUInt32ValueFromArray(data
, UNIT_FIELD_LEVEL
);
1836 accId
= objmgr
.GetPlayerAccountIdByGUID(targetGUID
);
1839 std::string username
= GetMangosString(LANG_ERROR
);
1840 std::string last_ip
= GetMangosString(LANG_ERROR
);
1841 uint32 security
= 0;
1842 std::string last_login
= GetMangosString(LANG_ERROR
);
1844 QueryResult
* result
= loginDatabase
.PQuery("SELECT username,gmlevel,last_ip,last_login FROM account WHERE id = '%u'",accId
);
1847 Field
* fields
= result
->Fetch();
1848 username
= fields
[0].GetCppString();
1849 security
= fields
[1].GetUInt32();
1851 if(!m_session
|| m_session
->GetSecurity() >= security
)
1853 last_ip
= fields
[2].GetCppString();
1854 last_login
= fields
[3].GetCppString();
1865 std::string nameLink
= playerLink(name
);
1867 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
);
1869 std::string timeStr
= secsToTimeString(total_player_time
,true,true);
1870 uint32 gold
= money
/GOLD
;
1871 uint32 silv
= (money
% GOLD
) / SILVER
;
1872 uint32 copp
= (money
% GOLD
) % SILVER
;
1873 PSendSysMessage(LANG_PINFO_LEVEL
, timeStr
.c_str(), level
, gold
,silv
,copp
);
1875 if ( py
&& strncmp(py
, "rep", 3) == 0 )
1879 // rep option not implemented for offline case
1880 SendSysMessage(LANG_PINFO_NO_REP
);
1881 SetSentErrorMessage(true);
1885 for(FactionStateList::const_iterator itr
= target
->m_factions
.begin(); itr
!= target
->m_factions
.end(); ++itr
)
1887 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(itr
->second
.ID
);
1888 char const* factionName
= factionEntry
? factionEntry
->name
[m_session
->GetSessionDbcLocale()] : "#Not found#";
1889 ReputationRank rank
= target
->GetReputationRank(factionEntry
);
1890 std::string rankName
= GetMangosString(ReputationRankStrIndex
[rank
]);
1891 std::ostringstream ss
;
1892 ss
<< itr
->second
.ID
<< ": |cffffffff|Hfaction:" << itr
->second
.ID
<< "|h[" << factionName
<< "]|h|r " << rankName
<< "|h|r (" << target
->GetReputation(factionEntry
) << ")";
1894 if(itr
->second
.Flags
& FACTION_FLAG_VISIBLE
)
1895 ss
<< GetMangosString(LANG_FACTION_VISIBLE
);
1896 if(itr
->second
.Flags
& FACTION_FLAG_AT_WAR
)
1897 ss
<< GetMangosString(LANG_FACTION_ATWAR
);
1898 if(itr
->second
.Flags
& FACTION_FLAG_PEACE_FORCED
)
1899 ss
<< GetMangosString(LANG_FACTION_PEACE_FORCED
);
1900 if(itr
->second
.Flags
& FACTION_FLAG_HIDDEN
)
1901 ss
<< GetMangosString(LANG_FACTION_HIDDEN
);
1902 if(itr
->second
.Flags
& FACTION_FLAG_INVISIBLE_FORCED
)
1903 ss
<< GetMangosString(LANG_FACTION_INVISIBLE_FORCED
);
1904 if(itr
->second
.Flags
& FACTION_FLAG_INACTIVE
)
1905 ss
<< GetMangosString(LANG_FACTION_INACTIVE
);
1907 SendSysMessage(ss
.str().c_str());
1914 void ChatHandler::ShowTicket(uint64 guid
, char const* text
, char const* time
)
1917 if(!objmgr
.GetPlayerNameByGUID(guid
,name
))
1918 name
= GetMangosString(LANG_UNKNOWN
);
1920 std::string nameLink
= playerLink(name
);
1922 PSendSysMessage(LANG_COMMAND_TICKETVIEW
, nameLink
.c_str(),time
,text
);
1926 bool ChatHandler::HandleTicketCommand(const char* args
)
1928 char* px
= strtok((char*)args
, " ");
1935 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1936 SetSentErrorMessage(true);
1940 size_t count
= ticketmgr
.GetTicketCount();
1942 bool accept
= m_session
->GetPlayer()->isAcceptTickets();
1944 PSendSysMessage(LANG_COMMAND_TICKETCOUNT
, count
, accept
? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1949 if(strncmp(px
,"on",3) == 0)
1953 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1954 SetSentErrorMessage(true);
1958 m_session
->GetPlayer()->SetAcceptTicket(true);
1959 SendSysMessage(LANG_COMMAND_TICKETON
);
1964 if(strncmp(px
,"off",4) == 0)
1968 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1969 SetSentErrorMessage(true);
1973 m_session
->GetPlayer()->SetAcceptTicket(false);
1974 SendSysMessage(LANG_COMMAND_TICKETOFF
);
1982 QueryResult
*result
= CharacterDatabase
.PQuery("SELECT guid,ticket_text,ticket_lastchange FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_
, num
-1);
1986 PSendSysMessage(LANG_COMMAND_TICKENOTEXIST
, num
);
1987 SetSentErrorMessage(true);
1991 Field
* fields
= result
->Fetch();
1993 uint32 guid
= fields
[0].GetUInt32();
1994 char const* text
= fields
[1].GetString();
1995 char const* time
= fields
[2].GetString();
1997 ShowTicket(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
),text
,time
);
2002 std::string name
= extractPlayerNameFromLink(px
);
2005 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2006 SetSentErrorMessage(true);
2010 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
2015 // ticket $char_name
2016 GMTicket
* ticket
= ticketmgr
.GetGMTicket(GUID_LOPART(guid
));
2020 std::string time
= TimeToTimestampStr(ticket
->GetLastUpdate());
2022 ShowTicket(guid
, ticket
->GetText(), time
.c_str());
2028 bool ChatHandler::HandleDelTicketCommand(const char *args
)
2030 char* px
= strtok((char*)args
, " ");
2035 if(strncmp(px
,"all",4) == 0)
2037 ticketmgr
.DeleteAll();
2038 SendSysMessage(LANG_COMMAND_ALLTICKETDELETED
);
2042 int num
= (uint32
)atoi(px
);
2047 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT guid FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_
,num
-1);
2050 PSendSysMessage(LANG_COMMAND_TICKENOTEXIST
, num
);
2051 SetSentErrorMessage(true);
2054 Field
* fields
= result
->Fetch();
2055 uint32 guid
= fields
[0].GetUInt32();
2058 ticketmgr
.Delete(guid
);
2061 if(Player
* pl
= objmgr
.GetPlayer(MAKE_NEW_GUID(guid
, 0, HIGHGUID_PLAYER
)))
2063 pl
->GetSession()->SendGMTicketGetTicket(0x0A, 0);
2064 PSendSysMessage(LANG_COMMAND_TICKETPLAYERDEL
, GetNameLink(pl
).c_str());
2067 PSendSysMessage(LANG_COMMAND_TICKETDEL
);
2072 std::string name
= extractPlayerNameFromLink(px
);
2075 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2076 SetSentErrorMessage(true);
2080 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
);
2085 // delticket $char_name
2086 ticketmgr
.Delete(GUID_LOPART(guid
));
2088 // notify players about ticket deleting
2089 if(Player
* sender
= objmgr
.GetPlayer(guid
))
2090 sender
->GetSession()->SendGMTicketGetTicket(0x0A,0);
2092 std::string nameLink
= playerLink(name
);
2094 PSendSysMessage(LANG_COMMAND_TICKETPLAYERDEL
,nameLink
.c_str());
2098 //set spawn dist of creature
2099 bool ChatHandler::HandleNpcSpawnDistCommand(const char* args
)
2104 float option
= atof((char*)args
);
2107 SendSysMessage(LANG_BAD_VALUE
);
2111 MovementGeneratorType mtype
= IDLE_MOTION_TYPE
;
2113 mtype
= RANDOM_MOTION_TYPE
;
2115 Creature
*pCreature
= getSelectedCreature();
2116 uint32 u_guidlow
= 0;
2119 u_guidlow
= pCreature
->GetDBTableGUIDLow();
2123 pCreature
->SetRespawnRadius((float)option
);
2124 pCreature
->SetDefaultMovementType(mtype
);
2125 pCreature
->GetMotionMaster()->Initialize();
2126 if(pCreature
->isAlive()) // dead creature will reset movement generator at respawn
2128 pCreature
->setDeathState(JUST_DIED
);
2129 pCreature
->Respawn();
2132 WorldDatabase
.PExecuteLog("UPDATE creature SET spawndist=%f, MovementType=%i WHERE guid=%u",option
,mtype
,u_guidlow
);
2133 PSendSysMessage(LANG_COMMAND_SPAWNDIST
,option
);
2137 bool ChatHandler::HandleNpcSpawnTimeCommand(const char* args
)
2142 char* stime
= strtok((char*)args
, " ");
2147 int i_stime
= atoi((char*)stime
);
2151 SendSysMessage(LANG_BAD_VALUE
);
2152 SetSentErrorMessage(true);
2156 Creature
*pCreature
= getSelectedCreature();
2157 uint32 u_guidlow
= 0;
2160 u_guidlow
= pCreature
->GetDBTableGUIDLow();
2164 WorldDatabase
.PExecuteLog("UPDATE creature SET spawntimesecs=%i WHERE guid=%u",i_stime
,u_guidlow
);
2165 pCreature
->SetRespawnDelay((uint32
)i_stime
);
2166 PSendSysMessage(LANG_COMMAND_SPAWNTIME
,i_stime
);
2172 * Add a waypoint to a creature.
2174 * The user can either select an npc or provide its GUID.
2176 * The user can even select a visual waypoint - then the new waypoint
2177 * is placed *after* the selected one - this makes insertion of new
2178 * waypoints possible.
2182 * -> adds a waypoint to the npc with the GUID 12345
2185 * -> adds a waypoint to the currently selected creature
2188 * @param args if the user did not provide a GUID, it is NULL
2190 * @return true - command did succeed, false - something went wrong
2192 bool ChatHandler::HandleWpAddCommand(const char* args
)
2194 sLog
.outDebug("DEBUG: HandleWpAddCommand");
2197 char* guid_str
= NULL
;
2201 guid_str
= strtok((char*)args
, " ");
2206 Creature
* target
= getSelectedCreature();
2207 // Did player provide a GUID?
2210 sLog
.outDebug("DEBUG: HandleWpAddCommand - No GUID provided");
2213 // -> Player must have selected a creature
2215 if(!target
|| target
->isPet())
2217 SendSysMessage(LANG_SELECT_CREATURE
);
2218 SetSentErrorMessage(true);
2221 if (target
->GetEntry() == VISUAL_WAYPOINT
)
2223 sLog
.outDebug("DEBUG: HandleWpAddCommand - target->GetEntry() == VISUAL_WAYPOINT (1) ");
2225 QueryResult
*result
=
2226 WorldDatabase
.PQuery( "SELECT id, point FROM creature_movement WHERE wpguid = %u",
2227 target
->GetGUIDLow() );
2230 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, target
->GetGUIDLow());
2231 // User selected a visual spawnpoint -> get the NPC
2233 // Since we compare float values, we have to deal with
2234 // some difficulties.
2235 // Here we search for all waypoints that only differ in one from 1 thousand
2236 // (0.001) - There is no other way to compare C++ floats with mySQL floats
2237 // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
2238 const char* maxDIFF
= "0.01";
2239 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 )",
2240 target
->GetPositionX(), maxDIFF
, target
->GetPositionY(), maxDIFF
, target
->GetPositionZ(), maxDIFF
);
2243 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, target
->GetGUIDLow());
2244 SetSentErrorMessage(true);
2250 Field
*fields
= result
->Fetch();
2251 lowguid
= fields
[0].GetUInt32();
2252 point
= fields
[1].GetUInt32();
2253 }while( result
->NextRow() );
2256 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2259 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2260 SetSentErrorMessage(true);
2264 target
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
2267 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, lowguid
);
2268 SetSentErrorMessage(true);
2274 lowguid
= target
->GetDBTableGUIDLow();
2279 sLog
.outDebug("DEBUG: HandleWpAddCommand - GUID provided");
2282 // Warn if player also selected a creature
2283 // -> Creature selection is ignored <-
2286 SendSysMessage(LANG_WAYPOINT_CREATSELECTED
);
2288 lowguid
= atoi((char*)guid_str
);
2290 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2293 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2294 SetSentErrorMessage(true);
2298 target
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
2299 if(!target
|| target
->isPet())
2301 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2302 SetSentErrorMessage(true);
2306 // lowguid -> GUID of the NPC
2307 // point -> number of the waypoint (if not 0)
2308 sLog
.outDebug("DEBUG: HandleWpAddCommand - danach");
2310 sLog
.outDebug("DEBUG: HandleWpAddCommand - point == 0");
2312 Player
* player
= m_session
->GetPlayer();
2313 WaypointMgr
.AddLastNode(lowguid
, player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(), player
->GetOrientation(), 0, 0);
2315 // update movement type
2318 target
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
2319 target
->GetMotionMaster()->Initialize();
2320 if(target
->isAlive()) // dead creature will reset movement generator at respawn
2322 target
->setDeathState(JUST_DIED
);
2328 WorldDatabase
.PExecuteLog("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE
,lowguid
);
2330 PSendSysMessage(LANG_WAYPOINT_ADDED
, point
, lowguid
);
2333 } // HandleWpAddCommand
2336 * .wp modify emote | spell | text | del | move | add
2338 * add -> add a WP after the selected visual waypoint
2339 * User must select a visual waypoint and then issue ".wp modify add"
2342 * User has selected a visual waypoint before.
2343 * <emoteID> is added to this waypoint. Everytime the
2344 * NPC comes to this waypoint, the emote is called.
2346 * emote <GUID> <WPNUM> <emoteID>
2347 * User has not selected visual waypoint before.
2348 * For the waypoint <WPNUM> for the NPC with <GUID>
2349 * an emote <emoteID> is added.
2350 * Everytime the NPC comes to this waypoint, the emote is called.
2353 * info <GUID> <WPNUM> -> User did not select a visual waypoint and
2355 bool ChatHandler::HandleWpModifyCommand(const char* args
)
2357 sLog
.outDebug("DEBUG: HandleWpModifyCommand");
2362 // first arg: add del text emote spell waittime move
2363 char* show_str
= strtok((char*)args
, " ");
2369 std::string show
= show_str
;
2371 // Remember: "show" must also be the name of a column!
2372 if( (show
!= "emote") && (show
!= "spell") && (show
!= "textid1") && (show
!= "textid2")
2373 && (show
!= "textid3") && (show
!= "textid4") && (show
!= "textid5")
2374 && (show
!= "waittime") && (show
!= "del") && (show
!= "move") && (show
!= "add")
2375 && (show
!= "model1") && (show
!= "model2") && (show
!= "orientation"))
2380 // Next arg is: <GUID> <WPNUM> <ARGUMENT>
2382 // Did user provide a GUID
2383 // or did the user select a creature?
2384 // -> variable lowguid is filled with the GUID of the NPC
2388 Creature
* target
= getSelectedCreature();
2392 sLog
.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
2394 // Did the user select a visual spawnpoint?
2395 if (target
->GetEntry() != VISUAL_WAYPOINT
)
2397 PSendSysMessage(LANG_WAYPOINT_VP_SELECT
);
2398 SetSentErrorMessage(true);
2402 wpGuid
= target
->GetGUIDLow();
2404 // The visual waypoint
2405 QueryResult
*result
=
2406 WorldDatabase
.PQuery( "SELECT id, point FROM creature_movement WHERE wpguid = %u LIMIT 1",
2407 target
->GetGUIDLow() );
2410 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, wpGuid
);
2411 SetSentErrorMessage(true);
2414 sLog
.outDebug("DEBUG: HandleWpModifyCommand - After getting wpGuid");
2416 Field
*fields
= result
->Fetch();
2417 lowguid
= fields
[0].GetUInt32();
2418 point
= fields
[1].GetUInt32();
2421 sLog
.outDebug("DEBUG: HandleWpModifyCommand - Cleanup memory");
2426 // User did provide <GUID> <WPNUM>
2428 char* guid_str
= strtok((char*)NULL
, " ");
2431 SendSysMessage(LANG_WAYPOINT_NOGUID
);
2434 lowguid
= atoi((char*)guid_str
);
2436 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2439 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2440 SetSentErrorMessage(true);
2444 PSendSysMessage("DEBUG: GUID provided: %d", lowguid
);
2446 char* point_str
= strtok((char*)NULL
, " ");
2449 SendSysMessage(LANG_WAYPOINT_NOWAYPOINTGIVEN
);
2452 point
= atoi((char*)point_str
);
2454 PSendSysMessage("DEBUG: wpNumber provided: %d", point
);
2456 // Now we need the GUID of the visual waypoint
2457 // -> "del", "move", "add" command
2459 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT wpguid FROM creature_movement WHERE id = '%u' AND point = '%u' LIMIT 1", lowguid
, point
);
2462 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, lowguid
, point
);
2463 SetSentErrorMessage(true);
2467 Field
*fields
= result
->Fetch();
2468 wpGuid
= fields
[0].GetUInt32();
2474 char* arg_str
= NULL
;
2475 // Check for argument
2476 if( (show
.find("text") == std::string::npos
) && (show
!= "del") && (show
!= "move") && (show
!= "add"))
2478 // Text is enclosed in "<>", all other arguments not
2479 if( show
.find("text") != std::string::npos
)
2480 arg_str
= strtok((char*)NULL
, "<>");
2482 arg_str
= strtok((char*)NULL
, " ");
2486 PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ
, show_str
);
2491 sLog
.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
2493 // wpGuid -> GUID of the waypoint creature
2494 // lowguid -> GUID of the NPC
2495 // point -> waypoint number
2497 // Special functions:
2498 // add - move - del -> no args commands
2499 // Add a waypoint after the selected visual
2500 if(show
== "add" && target
)
2502 PSendSysMessage("DEBUG: wp modify add, GUID: %u", lowguid
);
2504 // Get the creature for which we read the waypoint
2505 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2508 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2509 SetSentErrorMessage(true);
2513 Creature
* npcCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2517 PSendSysMessage(LANG_WAYPOINT_NPCNOTFOUND
);
2518 SetSentErrorMessage(true);
2522 sLog
.outDebug("DEBUG: HandleWpModifyCommand - add -- npcCreature");
2525 // Add the visual spawnpoint (DB only)
2526 // Adjust the waypoints
2527 // Respawn the owner of the waypoints
2528 sLog
.outDebug("DEBUG: HandleWpModifyCommand - add");
2530 Player
* chr
= m_session
->GetPlayer();
2531 Map
*map
= chr
->GetMap();
2535 npcCreature
->GetMotionMaster()->Initialize();
2536 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2538 npcCreature
->setDeathState(JUST_DIED
);
2539 npcCreature
->Respawn();
2543 // create the waypoint creature
2545 Creature
* wpCreature
= new Creature
;
2546 if (!wpCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT
,0))
2548 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, VISUAL_WAYPOINT
);
2553 wpCreature
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), chr
->GetOrientation());
2555 if(!wpCreature
->IsPositionValid())
2557 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature
->GetGUIDLow(),wpCreature
->GetEntry(),wpCreature
->GetPositionX(),wpCreature
->GetPositionY());
2562 wpCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
2563 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2564 wpCreature
->LoadFromDB(wpCreature
->GetDBTableGUIDLow(), map
);
2565 map
->Add(wpCreature
);
2566 wpGuid
= wpCreature
->GetGUIDLow();
2570 WaypointMgr
.AddAfterNode(lowguid
, point
, chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), 0, 0, wpGuid
);
2575 PSendSysMessage(LANG_WAYPOINT_ADDED_NO
, point
+1);
2579 if(show
== "del" && target
)
2581 PSendSysMessage("DEBUG: wp modify del, GUID: %u", lowguid
);
2583 // Get the creature for which we read the waypoint
2584 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2587 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2588 SetSentErrorMessage(true);
2592 Creature
* npcCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2595 Creature
* wpCreature
= NULL
;
2598 wpCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(wpGuid
, VISUAL_WAYPOINT
, HIGHGUID_UNIT
));
2599 wpCreature
->DeleteFromDB();
2600 wpCreature
->CleanupsBeforeDelete();
2601 wpCreature
->AddObjectToRemoveList();
2605 // Remove the visual spawnpoint
2606 // Adjust the waypoints
2607 // Respawn the owner of the waypoints
2609 WaypointMgr
.DeleteNode(lowguid
, point
);
2613 // Any waypoints left?
2614 QueryResult
*result2
= WorldDatabase
.PQuery( "SELECT point FROM creature_movement WHERE id = '%u'",lowguid
);
2617 npcCreature
->SetDefaultMovementType(RANDOM_MOTION_TYPE
);
2621 npcCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
2624 npcCreature
->GetMotionMaster()->Initialize();
2625 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2627 npcCreature
->setDeathState(JUST_DIED
);
2628 npcCreature
->Respawn();
2630 npcCreature
->SaveToDB();
2633 PSendSysMessage(LANG_WAYPOINT_REMOVED
);
2637 if(show
== "move" && target
)
2639 PSendSysMessage("DEBUG: wp move, GUID: %u", lowguid
);
2641 Player
*chr
= m_session
->GetPlayer();
2642 Map
*map
= chr
->GetMap();
2644 // Get the creature for which we read the waypoint
2645 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2648 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2649 SetSentErrorMessage(true);
2653 Creature
* npcCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2656 Creature
* wpCreature
= NULL
;
2658 // Move the visual spawnpoint
2659 // Respawn the owner of the waypoints
2662 wpCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(wpGuid
, VISUAL_WAYPOINT
, HIGHGUID_UNIT
));
2663 wpCreature
->DeleteFromDB();
2664 wpCreature
->CleanupsBeforeDelete();
2665 wpCreature
->AddObjectToRemoveList();
2667 Creature
* wpCreature2
= new Creature
;
2668 if (!wpCreature2
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), VISUAL_WAYPOINT
, 0))
2670 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, VISUAL_WAYPOINT
);
2675 wpCreature2
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), chr
->GetOrientation());
2677 if(!wpCreature2
->IsPositionValid())
2679 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature2
->GetGUIDLow(),wpCreature2
->GetEntry(),wpCreature2
->GetPositionX(),wpCreature2
->GetPositionY());
2684 wpCreature2
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
2685 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2686 wpCreature2
->LoadFromDB(wpCreature2
->GetDBTableGUIDLow(), map
);
2687 map
->Add(wpCreature2
);
2688 //npcCreature->GetMap()->Add(wpCreature2);
2691 WaypointMgr
.SetNodePosition(lowguid
, point
, chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ());
2695 npcCreature
->GetMotionMaster()->Initialize();
2696 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2698 npcCreature
->setDeathState(JUST_DIED
);
2699 npcCreature
->Respawn();
2702 PSendSysMessage(LANG_WAYPOINT_CHANGED
);
2707 // Create creature - npc that has the waypoint
2708 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2711 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2712 SetSentErrorMessage(true);
2716 // set in game textids not supported
2717 if( show
== "textid1" || show
== "textid2" || show
== "textid3" ||
2718 show
== "textid4" || show
== "textid5" )
2723 WaypointMgr
.SetNodeText(lowguid
, point
, show_str
, arg_str
);
2725 Creature
* npcCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), MAKE_NEW_GUID(lowguid
, data
->id
, HIGHGUID_UNIT
));
2728 npcCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
2729 npcCreature
->GetMotionMaster()->Initialize();
2730 if(npcCreature
->isAlive()) // dead creature will reset movement generator at respawn
2732 npcCreature
->setDeathState(JUST_DIED
);
2733 npcCreature
->Respawn();
2736 PSendSysMessage(LANG_WAYPOINT_CHANGED_NO
, show_str
);
2742 * .wp show info | on | off
2744 * info -> User has selected a visual waypoint before
2746 * info <GUID> <WPNUM> -> User did not select a visual waypoint and
2747 * provided the GUID of the NPC and the number of
2750 * on -> User has selected an NPC; all visual waypoints for this
2751 * NPC are added to the world
2753 * on <GUID> -> User did not select an NPC - instead the GUID of the
2754 * NPC is provided. All visual waypoints for this NPC
2755 * are added from the world.
2757 * off -> User has selected an NPC; all visual waypoints for this
2758 * NPC are removed from the world.
2760 * on <GUID> -> User did not select an NPC - instead the GUID of the
2761 * NPC is provided. All visual waypoints for this NPC
2762 * are removed from the world.
2766 bool ChatHandler::HandleWpShowCommand(const char* args
)
2768 sLog
.outDebug("DEBUG: HandleWpShowCommand");
2773 // first arg: on, off, first, last
2774 char* show_str
= strtok((char*)args
, " ");
2779 // second arg: GUID (optional, if a creature is selected)
2780 char* guid_str
= strtok((char*)NULL
, " ");
2781 sLog
.outDebug("DEBUG: HandleWpShowCommand: show_str: %s guid_str: %s", show_str
, guid_str
);
2786 // Did user provide a GUID
2787 // or did the user select a creature?
2788 // -> variable lowguid is filled with the GUID
2789 Creature
* target
= getSelectedCreature();
2790 // Did player provide a GUID?
2793 sLog
.outDebug("DEBUG: HandleWpShowCommand: !guid_str");
2795 // -> Player must have selected a creature
2799 SendSysMessage(LANG_SELECT_CREATURE
);
2800 SetSentErrorMessage(true);
2806 sLog
.outDebug("DEBUG: HandleWpShowCommand: GUID provided");
2808 // Warn if player also selected a creature
2809 // -> Creature selection is ignored <-
2812 SendSysMessage(LANG_WAYPOINT_CREATSELECTED
);
2815 uint32 lowguid
= atoi((char*)guid_str
);
2817 CreatureData
const* data
= objmgr
.GetCreatureData(lowguid
);
2820 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2821 SetSentErrorMessage(true);
2825 target
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(lowguid
,data
->id
,HIGHGUID_UNIT
));
2829 PSendSysMessage(LANG_WAYPOINT_CREATNOTFOUND
, lowguid
);
2830 SetSentErrorMessage(true);
2835 uint32 lowguid
= target
->GetDBTableGUIDLow();
2837 std::string show
= show_str
;
2840 sLog
.outDebug("DEBUG: HandleWpShowCommand: lowguid: %u show: %s", lowguid
, show_str
);
2842 // Show info for the selected waypoint
2845 PSendSysMessage("DEBUG: wp info, GUID: %u", lowguid
);
2847 // Check if the user did specify a visual waypoint
2848 if( target
->GetEntry() != VISUAL_WAYPOINT
)
2850 PSendSysMessage(LANG_WAYPOINT_VP_SELECT
);
2851 SetSentErrorMessage(true);
2855 //PSendSysMessage("wp on, GUID: %u", lowguid);
2857 //pCreature->GetPositionX();
2859 QueryResult
*result
=
2860 WorldDatabase
.PQuery( "SELECT id, point, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5, model1, model2 FROM creature_movement WHERE wpguid = %u",
2861 target
->GetGUIDLow() );
2864 // Since we compare float values, we have to deal with
2865 // some difficulties.
2866 // Here we search for all waypoints that only differ in one from 1 thousand
2867 // (0.001) - There is no other way to compare C++ floats with mySQL floats
2868 // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
2869 const char* maxDIFF
= "0.01";
2870 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDSEARCH
, target
->GetGUID());
2872 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 )",
2873 target
->GetPositionX(), maxDIFF
, target
->GetPositionY(), maxDIFF
, target
->GetPositionZ(), maxDIFF
);
2876 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, lowguid
);
2877 SetSentErrorMessage(true);
2883 Field
*fields
= result
->Fetch();
2884 uint32 creGUID
= fields
[0].GetUInt32();
2885 uint32 point
= fields
[1].GetUInt32();
2886 int waittime
= fields
[2].GetUInt32();
2887 uint32 emote
= fields
[3].GetUInt32();
2888 uint32 spell
= fields
[4].GetUInt32();
2889 uint32 textid
[MAX_WAYPOINT_TEXT
];
2890 for(int i
= 0; i
< MAX_WAYPOINT_TEXT
; ++i
)
2891 textid
[i
] = fields
[5+i
].GetUInt32();
2892 uint32 model1
= fields
[10].GetUInt32();
2893 uint32 model2
= fields
[11].GetUInt32();
2895 // Get the creature for which we read the waypoint
2896 Creature
* wpCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(creGUID
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
2898 PSendSysMessage(LANG_WAYPOINT_INFO_TITLE
, point
, (wpCreature
? wpCreature
->GetName() : "<not found>"), creGUID
);
2899 PSendSysMessage(LANG_WAYPOINT_INFO_WAITTIME
, waittime
);
2900 PSendSysMessage(LANG_WAYPOINT_INFO_MODEL
, 1, model1
);
2901 PSendSysMessage(LANG_WAYPOINT_INFO_MODEL
, 2, model2
);
2902 PSendSysMessage(LANG_WAYPOINT_INFO_EMOTE
, emote
);
2903 PSendSysMessage(LANG_WAYPOINT_INFO_SPELL
, spell
);
2904 for(int i
= 0; i
< MAX_WAYPOINT_TEXT
; ++i
)
2905 PSendSysMessage(LANG_WAYPOINT_INFO_TEXT
, i
+1, textid
[i
], (textid
[i
] ? GetMangosString(textid
[i
]) : ""));
2907 }while( result
->NextRow() );
2915 PSendSysMessage("DEBUG: wp on, GUID: %u", lowguid
);
2917 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT point, position_x,position_y,position_z FROM creature_movement WHERE id = '%u'",lowguid
);
2920 PSendSysMessage(LANG_WAYPOINT_NOTFOUND
, lowguid
);
2921 SetSentErrorMessage(true);
2924 // Delete all visuals for this NPC
2925 QueryResult
*result2
= WorldDatabase
.PQuery( "SELECT wpguid FROM creature_movement WHERE id = '%u' and wpguid <> 0", lowguid
);
2928 bool hasError
= false;
2931 Field
*fields
= result2
->Fetch();
2932 uint32 wpguid
= fields
[0].GetUInt32();
2933 Creature
* pCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(wpguid
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
2937 PSendSysMessage(LANG_WAYPOINT_NOTREMOVED
, wpguid
);
2939 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", wpguid
);
2943 pCreature
->DeleteFromDB();
2944 pCreature
->CleanupsBeforeDelete();
2945 pCreature
->AddObjectToRemoveList();
2948 }while( result2
->NextRow() );
2952 PSendSysMessage(LANG_WAYPOINT_TOOFAR1
);
2953 PSendSysMessage(LANG_WAYPOINT_TOOFAR2
);
2954 PSendSysMessage(LANG_WAYPOINT_TOOFAR3
);
2960 Field
*fields
= result
->Fetch();
2961 uint32 point
= fields
[0].GetUInt32();
2962 float x
= fields
[1].GetFloat();
2963 float y
= fields
[2].GetFloat();
2964 float z
= fields
[3].GetFloat();
2966 uint32 id
= VISUAL_WAYPOINT
;
2968 Player
*chr
= m_session
->GetPlayer();
2969 Map
*map
= chr
->GetMap();
2970 float o
= chr
->GetOrientation();
2972 Creature
* wpCreature
= new Creature
;
2973 if (!wpCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
2975 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, id
);
2981 wpCreature
->Relocate(x
, y
, z
, o
);
2983 if(!wpCreature
->IsPositionValid())
2985 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",wpCreature
->GetGUIDLow(),wpCreature
->GetEntry(),wpCreature
->GetPositionX(),wpCreature
->GetPositionY());
2991 wpCreature
->SetVisibility(VISIBILITY_OFF
);
2992 sLog
.outDebug("DEBUG: UPDATE creature_movement SET wpguid = '%u");
2993 // set "wpguid" column to the visual waypoint
2994 WorldDatabase
.PExecuteLog("UPDATE creature_movement SET wpguid = '%u' WHERE id = '%u' and point = '%u'", wpCreature
->GetGUIDLow(), lowguid
, point
);
2996 wpCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
2997 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2998 wpCreature
->LoadFromDB(wpCreature
->GetDBTableGUIDLow(),map
);
2999 map
->Add(wpCreature
);
3000 //wpCreature->GetMap()->Add(wpCreature);
3001 }while( result
->NextRow() );
3010 PSendSysMessage("DEBUG: wp first, GUID: %u", lowguid
);
3012 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT position_x,position_y,position_z FROM creature_movement WHERE point='1' AND id = '%u'",lowguid
);
3015 PSendSysMessage(LANG_WAYPOINT_NOTFOUND
, lowguid
);
3016 SetSentErrorMessage(true);
3020 Field
*fields
= result
->Fetch();
3021 float x
= fields
[0].GetFloat();
3022 float y
= fields
[1].GetFloat();
3023 float z
= fields
[2].GetFloat();
3024 uint32 id
= VISUAL_WAYPOINT
;
3026 Player
*chr
= m_session
->GetPlayer();
3027 float o
= chr
->GetOrientation();
3028 Map
*map
= chr
->GetMap();
3030 Creature
* pCreature
= new Creature
;
3031 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
),map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
3033 PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED
, id
);
3039 pCreature
->Relocate(x
, y
, z
, o
);
3041 if(!pCreature
->IsPositionValid())
3043 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
3049 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3050 pCreature
->LoadFromDB(pCreature
->GetDBTableGUIDLow(), map
);
3051 map
->Add(pCreature
);
3052 //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "First Waypoint");
3061 PSendSysMessage("DEBUG: wp last, GUID: %u", lowguid
);
3063 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT MAX(point) FROM creature_movement WHERE id = '%u'",lowguid
);
3066 Maxpoint
= (*result
)[0].GetUInt32();
3073 result
= WorldDatabase
.PQuery( "SELECT position_x,position_y,position_z FROM creature_movement WHERE point ='%u' AND id = '%u'",Maxpoint
, lowguid
);
3076 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDLAST
, lowguid
);
3077 SetSentErrorMessage(true);
3080 Field
*fields
= result
->Fetch();
3081 float x
= fields
[0].GetFloat();
3082 float y
= fields
[1].GetFloat();
3083 float z
= fields
[2].GetFloat();
3084 uint32 id
= VISUAL_WAYPOINT
;
3086 Player
*chr
= m_session
->GetPlayer();
3087 float o
= chr
->GetOrientation();
3088 Map
*map
= chr
->GetMap();
3090 Creature
* pCreature
= new Creature
;
3091 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), map
, chr
->GetPhaseMaskForSpawn(), id
, 0))
3093 PSendSysMessage(LANG_WAYPOINT_NOTCREATED
, id
);
3099 pCreature
->Relocate(x
, y
, z
, o
);
3101 if(!pCreature
->IsPositionValid())
3103 sLog
.outError("ERROR: Creature (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
3109 pCreature
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()), chr
->GetPhaseMaskForSpawn());
3110 pCreature
->LoadFromDB(pCreature
->GetDBTableGUIDLow(), map
);
3111 map
->Add(pCreature
);
3112 //player->PlayerTalkClass->SendPointOfInterest(x, y, 6, 6, 0, "Last Waypoint");
3120 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid FROM creature WHERE id = '%d'", VISUAL_WAYPOINT
);
3123 SendSysMessage(LANG_WAYPOINT_VP_NOTFOUND
);
3124 SetSentErrorMessage(true);
3127 bool hasError
= false;
3130 Field
*fields
= result
->Fetch();
3131 uint32 guid
= fields
[0].GetUInt32();
3132 Creature
* pCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(),MAKE_NEW_GUID(guid
,VISUAL_WAYPOINT
,HIGHGUID_UNIT
));
3134 //Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3138 PSendSysMessage(LANG_WAYPOINT_NOTREMOVED
, guid
);
3140 WorldDatabase
.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", guid
);
3144 pCreature
->DeleteFromDB();
3145 pCreature
->CleanupsBeforeDelete();
3146 pCreature
->AddObjectToRemoveList();
3148 }while(result
->NextRow());
3149 // set "wpguid" column to "empty" - no visual waypoint spawned
3150 WorldDatabase
.PExecuteLog("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
3154 PSendSysMessage(LANG_WAYPOINT_TOOFAR1
);
3155 PSendSysMessage(LANG_WAYPOINT_TOOFAR2
);
3156 PSendSysMessage(LANG_WAYPOINT_TOOFAR3
);
3159 SendSysMessage(LANG_WAYPOINT_VP_ALLREMOVED
);
3166 PSendSysMessage("DEBUG: wpshow - no valid command found");
3169 } // HandleWpShowCommand
3171 bool ChatHandler::HandleWpExportCommand(const char *args
)
3176 // Next arg is: <GUID> <ARGUMENT>
3178 // Did user provide a GUID
3179 // or did the user select a creature?
3180 // -> variable lowguid is filled with the GUID of the NPC
3182 Creature
* target
= getSelectedCreature();
3183 char* arg_str
= NULL
;
3186 if (target
->GetEntry() != VISUAL_WAYPOINT
)
3187 lowguid
= target
->GetGUIDLow();
3190 QueryResult
*result
= WorldDatabase
.PQuery( "SELECT id FROM creature_movement WHERE wpguid = %u LIMIT 1", target
->GetGUIDLow() );
3193 PSendSysMessage(LANG_WAYPOINT_NOTFOUNDDBPROBLEM
, target
->GetGUIDLow());
3196 Field
*fields
= result
->Fetch();
3197 lowguid
= fields
[0].GetUInt32();;
3201 arg_str
= strtok((char*)args
, " ");
3205 // user provided <GUID>
3206 char* guid_str
= strtok((char*)args
, " ");
3209 SendSysMessage(LANG_WAYPOINT_NOGUID
);
3212 lowguid
= atoi((char*)guid_str
);
3214 arg_str
= strtok((char*)NULL
, " ");
3219 PSendSysMessage(LANG_WAYPOINT_ARGUMENTREQ
, "export");
3223 PSendSysMessage("DEBUG: wp export, GUID: %u", lowguid
);
3225 QueryResult
*result
= WorldDatabase
.PQuery(
3226 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
3227 "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
);
3231 PSendSysMessage(LANG_WAYPOINT_NOTHINGTOEXPORT
);
3232 SetSentErrorMessage(true);
3236 std::ofstream outfile
;
3237 outfile
.open (arg_str
);
3241 Field
*fields
= result
->Fetch();
3243 outfile
<< "INSERT INTO creature_movement ";
3244 outfile
<< "( id, point, position_x, position_y, position_z, orientation, model1, model2, waittime, emote, spell, textid1, textid2, textid3, textid4, textid5 ) VALUES ";
3247 outfile
<< fields
[15].GetUInt32(); // id
3249 outfile
<< fields
[0].GetUInt32(); // point
3251 outfile
<< fields
[1].GetFloat(); // position_x
3253 outfile
<< fields
[2].GetFloat(); // position_y
3255 outfile
<< fields
[3].GetUInt32(); // position_z
3257 outfile
<< fields
[4].GetUInt32(); // orientation
3259 outfile
<< fields
[5].GetUInt32(); // model1
3261 outfile
<< fields
[6].GetUInt32(); // model2
3263 outfile
<< fields
[7].GetUInt16(); // waittime
3265 outfile
<< fields
[8].GetUInt32(); // emote
3267 outfile
<< fields
[9].GetUInt32(); // spell
3269 outfile
<< fields
[10].GetUInt32(); // textid1
3271 outfile
<< fields
[11].GetUInt32(); // textid2
3273 outfile
<< fields
[12].GetUInt32(); // textid3
3275 outfile
<< fields
[13].GetUInt32(); // textid4
3277 outfile
<< fields
[14].GetUInt32(); // textid5
3280 } while( result
->NextRow() );
3283 PSendSysMessage(LANG_WAYPOINT_EXPORTED
);
3289 bool ChatHandler::HandleWpImportCommand(const char *args
)
3294 char* arg_str
= strtok((char*)args
, " ");
3299 std::ifstream
infile (arg_str
);
3300 if (infile
.is_open())
3302 while (! infile
.eof() )
3304 getline (infile
,line
);
3305 //cout << line << endl;
3306 QueryResult
*result
= WorldDatabase
.Query(line
.c_str());
3311 PSendSysMessage(LANG_WAYPOINT_IMPORTED
);
3317 bool ChatHandler::HandleRenameCommand(const char* args
)
3319 Player
* target
= NULL
;
3320 uint64 targetGUID
= 0;
3321 std::string oldname
;
3323 char* px
= strtok((char*)args
, " ");
3327 oldname
= extractPlayerNameFromLink(px
);
3330 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3331 SetSentErrorMessage(true);
3335 target
= objmgr
.GetPlayer(oldname
.c_str());
3338 targetGUID
= objmgr
.GetPlayerGUIDByName(oldname
);
3341 if(!target
&& !targetGUID
)
3343 target
= getSelectedPlayer();
3346 if(!target
&& !targetGUID
)
3348 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3349 SetSentErrorMessage(true);
3355 // check online security
3356 if (HasLowerSecurity(target
, 0))
3359 PSendSysMessage(LANG_RENAME_PLAYER
, GetNameLink(target
).c_str());
3360 target
->SetAtLoginFlag(AT_LOGIN_RENAME
);
3361 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", target
->GetGUIDLow());
3365 // check offline security
3366 if (HasLowerSecurity(NULL
, targetGUID
))
3369 std::string oldNameLink
= playerLink(oldname
);
3371 PSendSysMessage(LANG_RENAME_PLAYER_GUID
, oldNameLink
.c_str(), GUID_LOPART(targetGUID
));
3372 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(targetGUID
));
3378 // customize characters
3379 bool ChatHandler::HandleCustomizeCommand(const char* args
)
3381 Player
* target
= NULL
;
3382 uint64 targetGUID
= 0;
3383 std::string oldname
;
3385 char* px
= strtok((char*)args
, " ");
3389 oldname
= extractPlayerNameFromLink(px
);
3392 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3393 SetSentErrorMessage(true);
3397 target
= objmgr
.GetPlayer(oldname
.c_str());
3400 targetGUID
= objmgr
.GetPlayerGUIDByName(oldname
);
3403 if(!target
&& !targetGUID
)
3405 target
= getSelectedPlayer();
3408 if(!target
&& !targetGUID
)
3410 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3411 SetSentErrorMessage(true);
3417 PSendSysMessage(LANG_CUSTOMIZE_PLAYER
, GetNameLink(target
).c_str());
3418 target
->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE
);
3419 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", target
->GetGUIDLow());
3423 std::string oldNameLink
= playerLink(oldname
);
3425 PSendSysMessage(LANG_CUSTOMIZE_PLAYER_GUID
, oldNameLink
.c_str(), GUID_LOPART(targetGUID
));
3426 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '8' WHERE guid = '%u'", GUID_LOPART(targetGUID
));
3433 bool ChatHandler::HandleGameObjectCommand(const char* args
)
3438 char* pParam1
= strtok((char*)args
, " ");
3442 uint32 id
= atoi((char*)pParam1
);
3446 char* spawntimeSecs
= strtok(NULL
, " ");
3448 const GameObjectInfo
*goI
= objmgr
.GetGameObjectInfo(id
);
3452 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
3453 SetSentErrorMessage(true);
3457 Player
*chr
= m_session
->GetPlayer();
3458 float x
= float(chr
->GetPositionX());
3459 float y
= float(chr
->GetPositionY());
3460 float z
= float(chr
->GetPositionZ());
3461 float o
= float(chr
->GetOrientation());
3462 Map
*map
= chr
->GetMap();
3464 float rot2
= sin(o
/2);
3465 float rot3
= cos(o
/2);
3467 GameObject
* pGameObj
= new GameObject
;
3468 uint32 db_lowGUID
= objmgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
);
3470 if(!pGameObj
->Create(db_lowGUID
, goI
->id
, map
, chr
->GetPhaseMaskForSpawn(), x
, y
, z
, o
, 0, 0, rot2
, rot3
, 0, 1))
3478 uint32 value
= atoi((char*)spawntimeSecs
);
3479 pGameObj
->SetRespawnTime(value
);
3480 //sLog.outDebug("*** spawntimeSecs: %d", value);
3483 // fill the gameobject data and save to the db
3484 pGameObj
->SaveToDB(map
->GetId(), (1 << map
->GetSpawnMode()),chr
->GetPhaseMaskForSpawn());
3486 // this will generate a new guid if the object is in an instance
3487 if(!pGameObj
->LoadFromDB(db_lowGUID
, map
))
3493 sLog
.outDebug(GetMangosString(LANG_GAMEOBJECT_CURRENT
), goI
->name
, db_lowGUID
, x
, y
, z
, o
);
3497 // TODO: is it really necessary to add both the real and DB table guid here ?
3498 objmgr
.AddGameobjectToGrid(db_lowGUID
, objmgr
.GetGOData(db_lowGUID
));
3500 PSendSysMessage(LANG_GAMEOBJECT_ADD
,id
,goI
->name
,db_lowGUID
,x
,y
,z
);
3505 bool ChatHandler::HandleAnimCommand(const char* args
)
3510 uint32 anim_id
= atoi((char*)args
);
3511 m_session
->GetPlayer()->HandleEmoteCommand(anim_id
);
3516 bool ChatHandler::HandleStandStateCommand(const char* args
)
3521 uint32 anim_id
= atoi((char*)args
);
3522 m_session
->GetPlayer( )->SetUInt32Value( UNIT_NPC_EMOTESTATE
, anim_id
);
3527 bool ChatHandler::HandleAddHonorCommand(const char* args
)
3532 Player
*target
= getSelectedPlayer();
3535 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3536 SetSentErrorMessage(true);
3540 // check online security
3541 if (HasLowerSecurity(target
, 0))
3544 uint32 amount
= (uint32
)atoi(args
);
3545 target
->RewardHonor(NULL
, 1, amount
);
3549 bool ChatHandler::HandleHonorAddKillCommand(const char* /*args*/)
3551 Unit
*target
= getSelectedUnit();
3554 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3555 SetSentErrorMessage(true);
3559 // check online security
3560 if (target
->GetTypeId() == TYPEID_PLAYER
&& HasLowerSecurity((Player
*)target
, 0))
3563 m_session
->GetPlayer()->RewardHonor(target
, 1);
3567 bool ChatHandler::HandleUpdateHonorFieldsCommand(const char* /*args*/)
3569 Player
*target
= getSelectedPlayer();
3572 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3573 SetSentErrorMessage(true);
3577 // check online security
3578 if (HasLowerSecurity(target
, 0))
3581 target
->UpdateHonorFields();
3585 bool ChatHandler::HandleLookupEventCommand(const char* args
)
3590 std::string namepart
= args
;
3591 std::wstring wnamepart
;
3593 // converting string that we try to find to lower case
3594 if(!Utf8toWStr(namepart
,wnamepart
))
3597 wstrToLower(wnamepart
);
3601 GameEvent::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3602 GameEvent::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3604 for(uint32 id
= 0; id
< events
.size(); ++id
)
3606 GameEventData
const& eventData
= events
[id
];
3608 std::string descr
= eventData
.description
;
3612 if (Utf8FitTo(descr
, wnamepart
))
3614 char const* active
= activeEvents
.find(id
) != activeEvents
.end() ? GetMangosString(LANG_ACTIVE
) : "";
3617 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT
,id
,id
,eventData
.description
.c_str(),active
);
3619 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE
,id
,eventData
.description
.c_str(),active
);
3626 SendSysMessage(LANG_NOEVENTFOUND
);
3631 bool ChatHandler::HandleEventActiveListCommand(const char* /*args*/)
3635 GameEvent::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3636 GameEvent::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3638 char const* active
= GetMangosString(LANG_ACTIVE
);
3640 for(GameEvent::ActiveEvents::const_iterator itr
= activeEvents
.begin(); itr
!= activeEvents
.end(); ++itr
)
3642 uint32 event_id
= *itr
;
3643 GameEventData
const& eventData
= events
[event_id
];
3646 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT
,event_id
,event_id
,eventData
.description
.c_str(),active
);
3648 PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE
,event_id
,eventData
.description
.c_str(),active
);
3654 SendSysMessage(LANG_NOEVENTFOUND
);
3659 bool ChatHandler::HandleEventInfoCommand(const char* args
)
3664 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3665 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
3669 uint32 event_id
= atoi(cId
);
3671 GameEvent::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3673 if(event_id
>=events
.size())
3675 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3676 SetSentErrorMessage(true);
3680 GameEventData
const& eventData
= events
[event_id
];
3681 if(!eventData
.isValid())
3683 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3684 SetSentErrorMessage(true);
3688 GameEvent::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3689 bool active
= activeEvents
.find(event_id
) != activeEvents
.end();
3690 char const* activeStr
= active
? GetMangosString(LANG_ACTIVE
) : "";
3692 std::string startTimeStr
= TimeToTimestampStr(eventData
.start
);
3693 std::string endTimeStr
= TimeToTimestampStr(eventData
.end
);
3695 uint32 delay
= gameeventmgr
.NextCheck(event_id
);
3696 time_t nextTime
= time(NULL
)+delay
;
3697 std::string nextStr
= nextTime
>= eventData
.start
&& nextTime
< eventData
.end
? TimeToTimestampStr(time(NULL
)+delay
) : "-";
3699 std::string occurenceStr
= secsToTimeString(eventData
.occurence
* MINUTE
);
3700 std::string lengthStr
= secsToTimeString(eventData
.length
* MINUTE
);
3702 PSendSysMessage(LANG_EVENT_INFO
,event_id
,eventData
.description
.c_str(),activeStr
,
3703 startTimeStr
.c_str(),endTimeStr
.c_str(),occurenceStr
.c_str(),lengthStr
.c_str(),
3708 bool ChatHandler::HandleEventStartCommand(const char* args
)
3713 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3714 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
3718 int32 event_id
= atoi(cId
);
3720 GameEvent::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3722 if(event_id
< 1 || event_id
>=events
.size())
3724 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3725 SetSentErrorMessage(true);
3729 GameEventData
const& eventData
= events
[event_id
];
3730 if(!eventData
.isValid())
3732 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3733 SetSentErrorMessage(true);
3737 GameEvent::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3738 if(activeEvents
.find(event_id
) != activeEvents
.end())
3740 PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE
,event_id
);
3741 SetSentErrorMessage(true);
3745 gameeventmgr
.StartEvent(event_id
,true);
3749 bool ChatHandler::HandleEventStopCommand(const char* args
)
3754 // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3755 char* cId
= extractKeyFromLink((char*)args
,"Hgameevent");
3759 int32 event_id
= atoi(cId
);
3761 GameEvent::GameEventDataMap
const& events
= gameeventmgr
.GetEventMap();
3763 if(event_id
< 1 || event_id
>=events
.size())
3765 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3766 SetSentErrorMessage(true);
3770 GameEventData
const& eventData
= events
[event_id
];
3771 if(!eventData
.isValid())
3773 SendSysMessage(LANG_EVENT_NOT_EXIST
);
3774 SetSentErrorMessage(true);
3778 GameEvent::ActiveEvents
const& activeEvents
= gameeventmgr
.GetActiveEventList();
3780 if(activeEvents
.find(event_id
) == activeEvents
.end())
3782 PSendSysMessage(LANG_EVENT_NOT_ACTIVE
,event_id
);
3783 SetSentErrorMessage(true);
3787 gameeventmgr
.StopEvent(event_id
,true);
3791 bool ChatHandler::HandleCombatStopCommand(const char* args
)
3797 std::string playername
= extractPlayerNameFromLink((char*)args
);
3798 if(playername
.empty())
3800 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3801 SetSentErrorMessage(true);
3805 player
= objmgr
.GetPlayer(playername
.c_str());
3809 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3810 SetSentErrorMessage(true);
3816 player
= getSelectedPlayer();
3819 player
= m_session
->GetPlayer();
3822 // check online security
3823 if (HasLowerSecurity(player
, 0))
3826 player
->CombatStop();
3827 player
->getHostilRefManager().deleteReferences();
3831 bool ChatHandler::HandleLearnAllCraftsCommand(const char* /*args*/)
3833 uint32 classmask
= m_session
->GetPlayer()->getClassMask();
3835 for (uint32 i
= 0; i
< sSkillLineStore
.GetNumRows(); ++i
)
3837 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(i
);
3841 if( skillInfo
->categoryId
== SKILL_CATEGORY_PROFESSION
|| skillInfo
->categoryId
== SKILL_CATEGORY_SECONDARY
)
3843 for (uint32 j
= 0; j
< sSkillLineAbilityStore
.GetNumRows(); ++j
)
3845 SkillLineAbilityEntry
const *skillLine
= sSkillLineAbilityStore
.LookupEntry(j
);
3849 // skip racial skills
3850 if( skillLine
->racemask
!= 0 )
3853 // skip wrong class skills
3854 if( skillLine
->classmask
&& (skillLine
->classmask
& classmask
) == 0)
3857 if( skillLine
->skillId
!= i
|| skillLine
->forward_spellid
)
3860 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(skillLine
->spellId
);
3861 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
3864 m_session
->GetPlayer()->learnSpell(skillLine
->spellId
,false);
3869 SendSysMessage(LANG_COMMAND_LEARN_ALL_CRAFT
);
3873 bool ChatHandler::HandleLearnAllRecipesCommand(const char* args
)
3875 // Learns all recipes of specified profession and sets skill to max
3876 // Example: .learn all_recipes enchanting
3878 Player
* target
= getSelectedPlayer();
3881 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3888 std::wstring wnamepart
;
3890 if(!Utf8toWStr(args
,wnamepart
))
3893 // converting string that we try to find to lower case
3894 wstrToLower( wnamepart
);
3896 uint32 classmask
= m_session
->GetPlayer()->getClassMask();
3898 for (uint32 i
= 0; i
< sSkillLineStore
.GetNumRows(); ++i
)
3900 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(i
);
3904 if( skillInfo
->categoryId
!= SKILL_CATEGORY_PROFESSION
&&
3905 skillInfo
->categoryId
!= SKILL_CATEGORY_SECONDARY
)
3908 int loc
= m_session
->GetSessionDbcLocale();
3909 std::string name
= skillInfo
->name
[loc
];
3911 if(Utf8FitTo(name
, wnamepart
))
3913 for (uint32 j
= 0; j
< sSkillLineAbilityStore
.GetNumRows(); ++j
)
3915 SkillLineAbilityEntry
const *skillLine
= sSkillLineAbilityStore
.LookupEntry(j
);
3919 if( skillLine
->skillId
!= i
|| skillLine
->forward_spellid
)
3922 // skip racial skills
3923 if( skillLine
->racemask
!= 0 )
3926 // skip wrong class skills
3927 if( skillLine
->classmask
&& (skillLine
->classmask
& classmask
) == 0)
3930 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(skillLine
->spellId
);
3931 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
3934 if( !target
->HasSpell(spellInfo
->Id
) )
3935 m_session
->GetPlayer()->learnSpell(skillLine
->spellId
,false);
3938 uint16 maxLevel
= target
->GetPureMaxSkillValue(skillInfo
->id
);
3939 target
->SetSkill(skillInfo
->id
, maxLevel
, maxLevel
);
3940 PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES
, name
.c_str());
3948 bool ChatHandler::HandleLookupPlayerIpCommand(const char* args
)
3954 std::string ip
= strtok ((char*)args
, " ");
3955 char* limit_str
= strtok (NULL
, " ");
3956 int32 limit
= limit_str
? atoi (limit_str
) : -1;
3958 loginDatabase
.escape_string (ip
);
3960 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip
.c_str ());
3962 return LookupPlayerSearchCommand (result
,limit
);
3965 bool ChatHandler::HandleLookupPlayerAccountCommand(const char* args
)
3970 std::string account
= strtok ((char*)args
, " ");
3971 char* limit_str
= strtok (NULL
, " ");
3972 int32 limit
= limit_str
? atoi (limit_str
) : -1;
3974 if (!AccountMgr::normilizeString (account
))
3977 loginDatabase
.escape_string (account
);
3979 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account
.c_str ());
3981 return LookupPlayerSearchCommand (result
,limit
);
3984 bool ChatHandler::HandleLookupPlayerEmailCommand(const char* args
)
3990 std::string email
= strtok ((char*)args
, " ");
3991 char* limit_str
= strtok (NULL
, " ");
3992 int32 limit
= limit_str
? atoi (limit_str
) : -1;
3994 loginDatabase
.escape_string (email
);
3996 QueryResult
* result
= loginDatabase
.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email
.c_str ());
3998 return LookupPlayerSearchCommand (result
,limit
);
4001 bool ChatHandler::LookupPlayerSearchCommand(QueryResult
* result
, int32 limit
)
4005 PSendSysMessage(LANG_NO_PLAYERS_FOUND
);
4006 SetSentErrorMessage(true);
4013 Field
* fields
= result
->Fetch();
4014 uint32 acc_id
= fields
[0].GetUInt32();
4015 std::string acc_name
= fields
[1].GetCppString();
4017 QueryResult
* chars
= CharacterDatabase
.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id
);
4020 PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT
,acc_name
.c_str(),acc_id
);
4027 Field
* charfields
= chars
->Fetch();
4028 guid
= charfields
[0].GetUInt64();
4029 name
= charfields
[1].GetCppString();
4031 PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER
,name
.c_str(),guid
);
4034 } while( chars
->NextRow() && ( limit
== -1 || i
< limit
) );
4038 } while(result
->NextRow());
4045 /// Triggering corpses expire check in world
4046 bool ChatHandler::HandleServerCorpsesCommand(const char* /*args*/)
4052 bool ChatHandler::HandleRepairitemsCommand(const char* /*args*/)
4054 Player
*target
= getSelectedPlayer();
4058 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
4059 SetSentErrorMessage(true);
4063 // check online security
4064 if (HasLowerSecurity(target
, 0))
4068 target
->DurabilityRepairAll(false, 0, false);
4070 PSendSysMessage(LANG_YOU_REPAIR_ITEMS
, GetNameLink(target
).c_str());
4071 if(needReportToTarget(target
))
4072 ChatHandler(target
).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED
, GetNameLink().c_str());
4076 bool ChatHandler::HandleWaterwalkCommand(const char* args
)
4081 Player
*player
= getSelectedPlayer();
4085 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
4086 SetSentErrorMessage(true);
4090 // check online security
4091 if (HasLowerSecurity(player
, 0))
4094 if (strncmp(args
, "on", 3) == 0)
4095 player
->SetMovement(MOVE_WATER_WALK
); // ON
4096 else if (strncmp(args
, "off", 4) == 0)
4097 player
->SetMovement(MOVE_LAND_WALK
); // OFF
4100 SendSysMessage(LANG_USE_BOL
);
4104 PSendSysMessage(LANG_YOU_SET_WATERWALK
, args
, GetNameLink(player
).c_str());
4105 if(needReportToTarget(player
))
4106 ChatHandler(player
).PSendSysMessage(LANG_YOUR_WATERWALK_SET
, args
, GetNameLink().c_str());
4110 bool ChatHandler::HandleNpcFollowCommand(const char* /*args*/)
4112 Player
*player
= m_session
->GetPlayer();
4113 Creature
*creature
= getSelectedCreature();
4117 PSendSysMessage(LANG_SELECT_CREATURE
);
4118 SetSentErrorMessage(true);
4122 // Follow player - Using pet's default dist and angle
4123 creature
->GetMotionMaster()->MoveFollow(player
, PET_FOLLOW_DIST
, PET_FOLLOW_ANGLE
);
4125 PSendSysMessage(LANG_CREATURE_FOLLOW_YOU_NOW
, creature
->GetName());
4129 bool ChatHandler::HandleNpcUnFollowCommand(const char* /*args*/)
4131 Player
*player
= m_session
->GetPlayer();
4132 Creature
*creature
= getSelectedCreature();
4136 PSendSysMessage(LANG_SELECT_CREATURE
);
4137 SetSentErrorMessage(true);
4141 if (creature
->GetMotionMaster()->empty() ||
4142 creature
->GetMotionMaster()->GetCurrentMovementGeneratorType ()!=TARGETED_MOTION_TYPE
)
4144 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU
);
4145 SetSentErrorMessage(true);
4149 TargetedMovementGenerator
<Creature
> const* mgen
4150 = static_cast<TargetedMovementGenerator
<Creature
> const*>((creature
->GetMotionMaster()->top()));
4152 if(mgen
->GetTarget()!=player
)
4154 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU
);
4155 SetSentErrorMessage(true);
4160 creature
->GetMotionMaster()->MovementExpired(true);
4162 PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU_NOW
, creature
->GetName());
4166 bool ChatHandler::HandleNpcTameCommand(const char* /*args*/)
4168 Creature
*creatureTarget
= getSelectedCreature ();
4169 if (!creatureTarget
|| creatureTarget
->isPet ())
4171 PSendSysMessage (LANG_SELECT_CREATURE
);
4172 SetSentErrorMessage (true);
4176 Player
*player
= m_session
->GetPlayer ();
4178 if(player
->GetPetGUID ())
4180 SendSysMessage (LANG_YOU_ALREADY_HAVE_PET
);
4181 SetSentErrorMessage (true);
4185 CreatureInfo
const* cInfo
= creatureTarget
->GetCreatureInfo();
4187 if (!cInfo
->isTameable ())
4189 PSendSysMessage (LANG_CREATURE_NON_TAMEABLE
,cInfo
->Entry
);
4190 SetSentErrorMessage (true);
4194 // Everything looks OK, create new pet
4195 Pet
* pet
= player
->CreateTamedPetFrom (creatureTarget
);
4198 PSendSysMessage (LANG_CREATURE_NON_TAMEABLE
,cInfo
->Entry
);
4199 SetSentErrorMessage (true);
4203 // place pet before player
4205 player
->GetClosePoint (x
,y
,z
,creatureTarget
->GetObjectSize (),CONTACT_DISTANCE
);
4206 pet
->Relocate (x
,y
,z
,M_PI
-player
->GetOrientation ());
4208 // set pet to defensive mode by default (some classes can't control controlled pets in fact).
4209 pet
->GetCharmInfo()->SetReactState(REACT_DEFENSIVE
);
4211 // calculate proper level
4212 uint32 level
= (creatureTarget
->getLevel() < (player
->getLevel() - 5)) ? (player
->getLevel() - 5) : creatureTarget
->getLevel();
4214 // prepare visual effect for levelup
4215 pet
->SetUInt32Value(UNIT_FIELD_LEVEL
, level
- 1);
4218 pet
->GetMap()->Add((Creature
*)pet
);
4220 // visual effect for levelup
4221 pet
->SetUInt32Value(UNIT_FIELD_LEVEL
, level
);
4223 // caster have pet now
4224 player
->SetPet(pet
);
4226 pet
->SavePetToDB(PET_SAVE_AS_CURRENT
);
4227 player
->PetSpellInitialize();
4232 //change phasemask of creature or pet
4233 bool ChatHandler::HandleNpcSetPhaseCommand(const char* args
)
4238 uint32 phasemask
= (uint32
) atoi((char*)args
);
4239 if ( phasemask
== 0 )
4241 SendSysMessage(LANG_BAD_VALUE
);
4242 SetSentErrorMessage(true);
4246 Creature
* pCreature
= getSelectedCreature();
4249 SendSysMessage(LANG_SELECT_CREATURE
);
4250 SetSentErrorMessage(true);
4254 pCreature
->SetPhaseMask(phasemask
,true);
4256 if(!pCreature
->isPet())
4257 pCreature
->SaveToDB();
4262 //set pahsemask for selected object
4263 bool ChatHandler::HandleGOPhaseCommand(const char* args
)
4265 // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
4266 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject");
4270 uint32 lowguid
= atoi(cId
);
4274 GameObject
* obj
= NULL
;
4277 if (GameObjectData
const* go_data
= objmgr
.GetGOData(lowguid
))
4278 obj
= GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid
,go_data
->id
);
4282 PSendSysMessage(LANG_COMMAND_OBJNOTFOUND
, lowguid
);
4283 SetSentErrorMessage(true);
4287 char* phaseStr
= strtok (NULL
, " ");
4288 uint32 phasemask
= phaseStr
? atoi(phaseStr
) : 0;
4289 if ( phasemask
== 0 )
4291 SendSysMessage(LANG_BAD_VALUE
);
4292 SetSentErrorMessage(true);
4296 obj
->SetPhaseMask(phasemask
,true);
4301 bool ChatHandler::HandleNpcSetDeathStateCommand(const char* args
)
4306 Creature
* pCreature
= getSelectedCreature();
4307 if(!pCreature
|| pCreature
->isPet())
4309 SendSysMessage(LANG_SELECT_CREATURE
);
4310 SetSentErrorMessage(true);
4314 if (strncmp(args
, "on", 3) == 0)
4315 pCreature
->SetDeadByDefault(true);
4316 else if (strncmp(args
, "off", 4) == 0)
4317 pCreature
->SetDeadByDefault(false);
4320 SendSysMessage(LANG_USE_BOL
);
4321 SetSentErrorMessage(true);
4325 pCreature
->SaveToDB();
4326 pCreature
->Respawn();