2 * Copyright (C) 2005-2008 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"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
33 #include "InstanceSaveMgr.h"
36 #include "VMapFactory.h"
39 bool ChatHandler::HandleNpcSayCommand(const char* args
)
44 Creature
* pCreature
= getSelectedCreature();
47 SendSysMessage(LANG_SELECT_CREATURE
);
48 SetSentErrorMessage(true);
52 pCreature
->Say(args
, LANG_UNIVERSAL
, 0);
57 bool ChatHandler::HandleNpcYellCommand(const char* args
)
62 Creature
* pCreature
= getSelectedCreature();
65 SendSysMessage(LANG_SELECT_CREATURE
);
66 SetSentErrorMessage(true);
70 pCreature
->Yell(args
, LANG_UNIVERSAL
, 0);
75 //show text emote by creature in chat
76 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args
)
81 Creature
* pCreature
= getSelectedCreature();
85 SendSysMessage(LANG_SELECT_CREATURE
);
86 SetSentErrorMessage(true);
90 pCreature
->TextEmote(args
, 0);
95 // make npc whisper to player
96 bool ChatHandler::HandleNpcWhisperCommand(const char* args
)
101 char* receiver_str
= strtok((char*)args
, " ");
102 char* text
= strtok(NULL
, "");
104 uint64 guid
= m_session
->GetPlayer()->GetSelection();
105 Creature
* pCreature
= ObjectAccessor::GetCreature(*m_session
->GetPlayer(), guid
);
107 if(!pCreature
|| !receiver_str
|| !text
)
112 uint64 receiver_guid
= atol(receiver_str
);
114 pCreature
->Whisper(text
,receiver_guid
);
120 bool ChatHandler::HandleAnnounceCommand(const char* args
)
125 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
,args
);
129 //notification player at the screen
130 bool ChatHandler::HandleNotifyCommand(const char* args
)
135 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
138 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
140 sWorld
.SendGlobalMessage(&data
);
145 //Enable\Dissable GM Mode
146 bool ChatHandler::HandleGMmodeCommand(const char* args
)
150 if(m_session
->GetPlayer()->isGameMaster())
151 m_session
->SendNotification(LANG_GM_ON
);
153 m_session
->SendNotification(LANG_GM_OFF
);
157 std::string argstr
= (char*)args
;
161 m_session
->GetPlayer()->SetGameMaster(true);
162 m_session
->SendNotification(LANG_GM_ON
);
164 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
165 vMapManager
->processCommand("stoplog");
172 m_session
->GetPlayer()->SetGameMaster(false);
173 m_session
->SendNotification(LANG_GM_OFF
);
175 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
176 vMapManager
->processCommand("startlog");
181 SendSysMessage(LANG_USE_BOL
);
182 SetSentErrorMessage(true);
186 // Enables or disables hiding of the staff badge
187 bool ChatHandler::HandleGMChatCommand(const char* args
)
191 if(m_session
->GetPlayer()->isGMChat())
192 m_session
->SendNotification(LANG_GM_CHAT_ON
);
194 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
198 std::string argstr
= (char*)args
;
202 m_session
->GetPlayer()->SetGMChat(true);
203 m_session
->SendNotification(LANG_GM_CHAT_ON
);
209 m_session
->GetPlayer()->SetGMChat(false);
210 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
214 SendSysMessage(LANG_USE_BOL
);
215 SetSentErrorMessage(true);
219 //Enable\Dissable Invisible mode
220 bool ChatHandler::HandleVisibleCommand(const char* args
)
224 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
228 std::string argstr
= (char*)args
;
232 m_session
->GetPlayer()->SetGMVisible(true);
233 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
239 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
240 m_session
->GetPlayer()->SetGMVisible(false);
244 SendSysMessage(LANG_USE_BOL
);
245 SetSentErrorMessage(true);
249 bool ChatHandler::HandleGPSCommand(const char* args
)
251 WorldObject
*obj
= NULL
;
254 std::string name
= args
;
255 if(normalizePlayerName(name
))
256 obj
= objmgr
.GetPlayer(name
.c_str());
260 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
261 SetSentErrorMessage(true);
267 obj
= getSelectedUnit();
271 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
272 SetSentErrorMessage(true);
276 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
279 uint32 zone_id
= obj
->GetZoneId();
280 uint32 area_id
= obj
->GetAreaId();
282 MapEntry
const* mapEntry
= sMapStore
.LookupEntry(obj
->GetMapId());
283 AreaTableEntry
const* zoneEntry
= GetAreaEntryByAreaID(zone_id
);
284 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(area_id
);
286 float zone_x
= obj
->GetPositionX();
287 float zone_y
= obj
->GetPositionY();
289 Map2ZoneCoordinates(zone_x
,zone_y
,zone_id
);
291 Map
const *map
= obj
->GetMap();
292 float ground_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), MAX_HEIGHT
);
293 float floor_z
= map
->GetHeight(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ());
295 GridPair p
= MaNGOS::ComputeGridPair(obj
->GetPositionX(), obj
->GetPositionY());
300 uint32 have_map
= Map::ExistMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
301 uint32 have_vmap
= Map::ExistVMap(obj
->GetMapId(),gx
,gy
) ? 1 : 0;
303 PSendSysMessage(LANG_MAP_POSITION
,
304 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
305 zone_id
, (zoneEntry
? zoneEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
306 area_id
, (areaEntry
? areaEntry
->area_name
[m_session
->GetSessionDbcLocale()] : "<unknown>" ),
307 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
308 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
309 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
311 sLog
.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
313 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetName(),
314 (obj
->GetTypeId() == TYPEID_PLAYER
? "GUID" : "Entry"), (obj
->GetTypeId() == TYPEID_PLAYER
? obj
->GetGUIDLow(): obj
->GetEntry()) );
316 sLog
.outDebug(GetMangosString(LANG_MAP_POSITION
),
317 obj
->GetMapId(), (mapEntry
? mapEntry
->name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
318 zone_id
, (zoneEntry
? zoneEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
319 area_id
, (areaEntry
? areaEntry
->area_name
[sWorld
.GetDefaultDbcLocale()] : "<unknown>" ),
320 obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), obj
->GetOrientation(),
321 cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(), obj
->GetInstanceId(),
322 zone_x
, zone_y
, ground_z
, floor_z
, have_map
, have_vmap
);
328 bool ChatHandler::HandleNamegoCommand(const char* args
)
333 std::string name
= args
;
335 if(!normalizePlayerName(name
))
337 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
338 SetSentErrorMessage(true);
342 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
345 if(chr
->IsBeingTeleported()==true)
347 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
348 SetSentErrorMessage(true);
352 Map
* pMap
= m_session
->GetPlayer()->GetMap();
354 if(pMap
->IsBattleGroundOrArena())
356 // cannot summon to bg
357 PSendSysMessage(LANG_CANNOT_SUMMON_TO_BG
,chr
->GetName());
358 SetSentErrorMessage(true);
361 else if(pMap
->IsDungeon())
363 Map
* cMap
= chr
->GetMap();
364 if( cMap
->Instanceable() && cMap
->GetInstanceId() != pMap
->GetInstanceId() )
366 // cannot summon from instance to instance
367 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
368 SetSentErrorMessage(true);
372 // we are in instance, and can summon only player in our group with us as lead
373 if ( !m_session
->GetPlayer()->GetGroup() || !chr
->GetGroup() ||
374 (chr
->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
375 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
376 // the last check is a bit excessive, but let it be, just in case
378 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
379 SetSentErrorMessage(true);
384 PSendSysMessage(LANG_SUMMONING
, chr
->GetName(),"");
385 if (needReportToTarget(chr
))
386 ChatHandler(chr
).PSendSysMessage(LANG_SUMMONED_BY
, GetName());
388 // stop flight if need
389 if(chr
->isInFlight())
391 chr
->GetMotionMaster()->MovementExpired();
392 chr
->m_taxi
.ClearTaxiDestinations();
394 // save only in non-flight case
396 chr
->SaveRecallPosition();
400 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,chr
->GetObjectSize());
401 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
403 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
405 PSendSysMessage(LANG_SUMMONING
, name
.c_str(),GetMangosString(LANG_OFFLINE
));
407 // in point where GM stay
408 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
409 m_session
->GetPlayer()->GetPositionX(),
410 m_session
->GetPlayer()->GetPositionY(),
411 m_session
->GetPlayer()->GetPositionZ(),
412 m_session
->GetPlayer()->GetOrientation(),
413 m_session
->GetPlayer()->GetZoneId(),
418 PSendSysMessage(LANG_NO_PLAYER
, args
);
419 SetSentErrorMessage(true);
426 bool ChatHandler::HandleGonameCommand(const char* args
)
431 Player
* _player
= m_session
->GetPlayer();
433 std::string name
= args
;
435 if(!normalizePlayerName(name
))
437 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
438 SetSentErrorMessage(true);
442 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
445 Map
* cMap
= chr
->GetMap();
446 if(cMap
->IsBattleGroundOrArena())
448 // only allow if gm mode is on
449 if (!_player
->isGameMaster())
451 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM
,chr
->GetName());
452 SetSentErrorMessage(true);
455 // if already in a bg, don't let port to other
456 else if (_player
->GetBattleGroundId())
458 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG
,chr
->GetName());
459 SetSentErrorMessage(true);
462 // all's well, set bg id
463 // when porting out from the bg, it will be reset to 0
464 _player
->SetBattleGroundId(chr
->GetBattleGroundId());
466 else if(cMap
->IsDungeon())
467 Map
* cMap
= chr
->GetMap();
468 if(cMap
->Instanceable())
470 // we have to go to instance, and can go to player only if:
471 // 1) we are in his group (either as leader or as member)
472 // 2) we are not bound to any group and have GM mode on
473 if (_player
->GetGroup())
475 // we are in group, we can go only if we are in the player group
476 if (_player
->GetGroup() != chr
->GetGroup())
478 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chr
->GetName());
479 SetSentErrorMessage(true);
485 // we are not in group, let's verify our GM mode
486 if (!_player
->isGameMaster())
488 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chr
->GetName());
489 SetSentErrorMessage(true);
494 // if the player or the player's group is bound to another instance
495 // the player will not be bound to another one
496 InstancePlayerBind
*pBind
= _player
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty());
499 Group
*group
= _player
->GetGroup();
500 InstanceGroupBind
*gBind
= group
? group
->GetBoundInstance(chr
->GetMapId(), chr
->GetDifficulty()) : NULL
;
503 // if no bind exists, create a solo bind
504 InstanceSave
*save
= sInstanceSaveManager
.GetInstanceSave(chr
->GetInstanceId());
505 if(save
) _player
->BindToInstance(save
, !save
->CanReset());
509 _player
->SetDifficulty(chr
->GetDifficulty());
512 PSendSysMessage(LANG_APPEARING_AT
, chr
->GetName());
514 if (_player
->IsVisibleGloballyFor(chr
))
515 ChatHandler(chr
).PSendSysMessage(LANG_APPEARING_TO
, _player
->GetName());
517 // stop flight if need
518 if(_player
->isInFlight())
520 _player
->GetMotionMaster()->MovementExpired();
521 _player
->m_taxi
.ClearTaxiDestinations();
523 // save only in non-flight case
525 _player
->SaveRecallPosition();
527 // to point to see at target with same orientation
529 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
531 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), TELE_TO_GM_MODE
);
536 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
538 PSendSysMessage(LANG_APPEARING_AT
, name
.c_str());
540 // to point where player stay (if loaded)
544 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,in_flight
,guid
))
546 // stop flight if need
547 if(_player
->isInFlight())
549 _player
->GetMotionMaster()->MovementExpired();
550 _player
->m_taxi
.ClearTaxiDestinations();
552 // save only in non-flight case
554 _player
->SaveRecallPosition();
556 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
561 PSendSysMessage(LANG_NO_PLAYER
, args
);
563 SetSentErrorMessage(true);
567 // Teleport player to last position
568 bool ChatHandler::HandleRecallCommand(const char* args
)
574 chr
= getSelectedPlayer();
576 chr
= m_session
->GetPlayer();
580 std::string name
= args
;
582 if(!normalizePlayerName(name
))
584 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
585 SetSentErrorMessage(true);
589 chr
= objmgr
.GetPlayer(name
.c_str());
593 PSendSysMessage(LANG_NO_PLAYER
, args
);
594 SetSentErrorMessage(true);
599 if(chr
->IsBeingTeleported())
601 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
602 SetSentErrorMessage(true);
606 // stop flight if need
607 if(chr
->isInFlight())
609 chr
->GetMotionMaster()->MovementExpired();
610 chr
->m_taxi
.ClearTaxiDestinations();
613 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
617 //Edit Player KnownTitles
618 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
625 sscanf((char*)args
, I64FMTD
, &titles
);
627 Player
*chr
= getSelectedPlayer();
630 SendSysMessage(LANG_NO_CHAR_SELECTED
);
631 SetSentErrorMessage(true);
635 uint64 titles2
= titles
;
637 for(int i
=1; i
< sCharTitlesStore
.GetNumRows(); ++i
)
638 if(CharTitlesEntry
const* tEntry
= sCharTitlesStore
.LookupEntry(i
))
639 titles2
&= ~(uint64(1) << tEntry
->bit_index
);
641 titles
&= ~titles2
; // remove not existed titles
643 chr
->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES
, titles
);
644 SendSysMessage(LANG_DONE
);
650 bool ChatHandler::HandleModifyHPCommand(const char* args
)
655 // char* pHp = strtok((char*)args, " ");
659 // char* pHpMax = strtok(NULL, " ");
663 // int32 hpm = atoi(pHpMax);
664 // int32 hp = atoi(pHp);
666 int32 hp
= atoi((char*)args
);
667 int32 hpm
= atoi((char*)args
);
669 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
671 SendSysMessage(LANG_BAD_VALUE
);
672 SetSentErrorMessage(true);
676 Player
*chr
= getSelectedPlayer();
679 SendSysMessage(LANG_NO_CHAR_SELECTED
);
680 SetSentErrorMessage(true);
684 PSendSysMessage(LANG_YOU_CHANGE_HP
, chr
->GetName(), hp
, hpm
);
685 if (needReportToTarget(chr
))
686 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_HP_CHANGED
, GetName(), hp
, hpm
);
688 chr
->SetMaxHealth( hpm
);
689 chr
->SetHealth( hp
);
695 bool ChatHandler::HandleModifyManaCommand(const char* args
)
700 // char* pmana = strtok((char*)args, " ");
704 // char* pmanaMax = strtok(NULL, " ");
708 // int32 manam = atoi(pmanaMax);
709 // int32 mana = atoi(pmana);
710 int32 mana
= atoi((char*)args
);
711 int32 manam
= atoi((char*)args
);
713 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
715 SendSysMessage(LANG_BAD_VALUE
);
716 SetSentErrorMessage(true);
720 Player
*chr
= getSelectedPlayer();
723 SendSysMessage(LANG_NO_CHAR_SELECTED
);
724 SetSentErrorMessage(true);
728 PSendSysMessage(LANG_YOU_CHANGE_MANA
, chr
->GetName(), mana
, manam
);
729 if (needReportToTarget(chr
))
730 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MANA_CHANGED
, GetName(), mana
, manam
);
732 chr
->SetMaxPower(POWER_MANA
,manam
);
733 chr
->SetPower(POWER_MANA
, mana
);
739 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
744 // char* pmana = strtok((char*)args, " ");
748 // char* pmanaMax = strtok(NULL, " ");
752 // int32 manam = atoi(pmanaMax);
753 // int32 mana = atoi(pmana);
755 int32 energy
= atoi((char*)args
)*10;
756 int32 energym
= atoi((char*)args
)*10;
758 if (energy
<= 0 || energym
<= 0 || energym
< energy
)
760 SendSysMessage(LANG_BAD_VALUE
);
761 SetSentErrorMessage(true);
765 Player
*chr
= getSelectedPlayer();
768 SendSysMessage(LANG_NO_CHAR_SELECTED
);
769 SetSentErrorMessage(true);
773 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, chr
->GetName(), energy
/10, energym
/10);
774 if (needReportToTarget(chr
))
775 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED
, GetName(), energy
/10, energym
/10);
777 chr
->SetMaxPower(POWER_ENERGY
,energym
);
778 chr
->SetPower(POWER_ENERGY
, energy
);
780 sLog
.outDetail(GetMangosString(LANG_CURRENT_ENERGY
),chr
->GetMaxPower(POWER_ENERGY
));
786 bool ChatHandler::HandleModifyRageCommand(const char* args
)
791 // char* pmana = strtok((char*)args, " ");
795 // char* pmanaMax = strtok(NULL, " ");
799 // int32 manam = atoi(pmanaMax);
800 // int32 mana = atoi(pmana);
802 int32 rage
= atoi((char*)args
)*10;
803 int32 ragem
= atoi((char*)args
)*10;
805 if (rage
<= 0 || ragem
<= 0 || ragem
< rage
)
807 SendSysMessage(LANG_BAD_VALUE
);
808 SetSentErrorMessage(true);
812 Player
*chr
= getSelectedPlayer();
815 SendSysMessage(LANG_NO_CHAR_SELECTED
);
816 SetSentErrorMessage(true);
820 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, chr
->GetName(), rage
/10, ragem
/10);
821 if (needReportToTarget(chr
))
822 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_RAGE_CHANGED
, GetName(), rage
/10, ragem
/10);
824 chr
->SetMaxPower(POWER_RAGE
,ragem
);
825 chr
->SetPower(POWER_RAGE
, rage
);
830 //Edit Player Faction
831 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
836 char* pfactionid
= extractKeyFromLink((char*)args
,"Hfaction");
838 Creature
* chr
= getSelectedCreature();
841 SendSysMessage(LANG_SELECT_CREATURE
);
842 SetSentErrorMessage(true);
850 uint32 factionid
= chr
->getFaction();
851 uint32 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
852 uint32 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
853 uint32 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
854 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
861 SendSysMessage(LANG_NO_CHAR_SELECTED
);
862 SetSentErrorMessage(true);
866 uint32 factionid
= atoi(pfactionid
);
869 char *pflag
= strtok(NULL
, " ");
871 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
875 char* pnpcflag
= strtok(NULL
, " ");
879 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
881 npcflag
= atoi(pnpcflag
);
883 char* pdyflag
= strtok(NULL
, " ");
887 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
889 dyflag
= atoi(pdyflag
);
891 if(!sFactionTemplateStore
.LookupEntry(factionid
))
893 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
894 SetSentErrorMessage(true);
898 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
900 chr
->setFaction(factionid
);
901 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
902 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
903 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
909 bool ChatHandler::HandleModifySpellCommand(const char* args
)
911 if(!*args
) return false;
912 char* pspellflatid
= strtok((char*)args
, " ");
916 char* pop
= strtok(NULL
, " ");
920 char* pval
= strtok(NULL
, " ");
926 char* pmark
= strtok(NULL
, " ");
928 uint8 spellflatid
= atoi(pspellflatid
);
929 uint8 op
= atoi(pop
);
930 uint16 val
= atoi(pval
);
936 Player
*chr
= getSelectedPlayer();
939 SendSysMessage(LANG_NO_CHAR_SELECTED
);
940 SetSentErrorMessage(true);
944 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, chr
->GetName());
945 if (needReportToTarget(chr
))
946 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED
, GetName(), spellflatid
, val
, mark
);
948 WorldPacket
data(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
949 data
<< uint8(spellflatid
);
952 data
<< uint16(mark
);
953 chr
->GetSession()->SendPacket(&data
);
959 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
964 int tp
= atoi((char*)args
);
967 Player
* player
= getSelectedPlayer();
970 SendSysMessage(LANG_NO_CHAR_SELECTED
);
971 SetSentErrorMessage(true);
974 player
->SetFreeTalentPoints(tp
);
980 //Enable On\OFF all taxi paths
981 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
985 SendSysMessage(LANG_USE_BOL
);
986 SetSentErrorMessage(true);
990 std::string argstr
= (char*)args
;
992 Player
*chr
= getSelectedPlayer();
995 chr
=m_session
->GetPlayer();
1000 chr
->SetTaxiCheater(true);
1001 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, chr
->GetName());
1002 if (needReportToTarget(chr
))
1003 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_ADDED
, GetName());
1007 if (argstr
== "off")
1009 chr
->SetTaxiCheater(false);
1010 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, chr
->GetName());
1011 if (needReportToTarget(chr
))
1012 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED
, GetName());
1017 SendSysMessage(LANG_USE_BOL
);
1018 SetSentErrorMessage(true);
1022 //Edit Player Aspeed
1023 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
1028 float ASpeed
= (float)atof((char*)args
);
1030 if (ASpeed
> 10 || ASpeed
< 0.1)
1032 SendSysMessage(LANG_BAD_VALUE
);
1033 SetSentErrorMessage(true);
1037 Player
*chr
= getSelectedPlayer();
1040 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1041 SetSentErrorMessage(true);
1045 if(chr
->isInFlight())
1047 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1048 SetSentErrorMessage(true);
1052 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chr
->GetName());
1053 if (needReportToTarget(chr
))
1054 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED
, GetName(), ASpeed
);
1056 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
1057 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
1058 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
1059 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1060 chr
->SetSpeed(MOVE_FLIGHT
, ASpeed
,true);
1065 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
1070 float Speed
= (float)atof((char*)args
);
1072 if (Speed
> 10 || Speed
< 0.1)
1074 SendSysMessage(LANG_BAD_VALUE
);
1075 SetSentErrorMessage(true);
1079 Player
*chr
= getSelectedPlayer();
1082 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1083 SetSentErrorMessage(true);
1087 if(chr
->isInFlight())
1089 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1090 SetSentErrorMessage(true);
1094 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chr
->GetName());
1095 if (needReportToTarget(chr
))
1096 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPEED_CHANGED
, GetName(), Speed
);
1098 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
1103 //Edit Player Swim Speed
1104 bool ChatHandler::HandleModifySwimCommand(const char* args
)
1109 float Swim
= (float)atof((char*)args
);
1111 if (Swim
> 10.0f
|| Swim
< 0.01f
)
1113 SendSysMessage(LANG_BAD_VALUE
);
1114 SetSentErrorMessage(true);
1118 Player
*chr
= getSelectedPlayer();
1121 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1122 SetSentErrorMessage(true);
1126 if(chr
->isInFlight())
1128 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1129 SetSentErrorMessage(true);
1133 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chr
->GetName());
1134 if (needReportToTarget(chr
))
1135 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED
, GetName(), Swim
);
1137 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
1142 //Edit Player Walk Speed
1143 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
1148 float BSpeed
= (float)atof((char*)args
);
1150 if (BSpeed
> 10.0f
|| BSpeed
< 0.1f
)
1152 SendSysMessage(LANG_BAD_VALUE
);
1153 SetSentErrorMessage(true);
1157 Player
*chr
= getSelectedPlayer();
1160 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1161 SetSentErrorMessage(true);
1165 if(chr
->isInFlight())
1167 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1168 SetSentErrorMessage(true);
1172 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chr
->GetName());
1173 if (needReportToTarget(chr
))
1174 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED
, GetName(), BSpeed
);
1176 chr
->SetSpeed(MOVE_RUN_BACK
,BSpeed
,true);
1182 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1187 float FSpeed
= (float)atof((char*)args
);
1189 if (FSpeed
> 10.0f
|| FSpeed
< 0.1f
)
1191 SendSysMessage(LANG_BAD_VALUE
);
1192 SetSentErrorMessage(true);
1196 Player
*chr
= getSelectedPlayer();
1199 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1200 SetSentErrorMessage(true);
1204 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, chr
->GetName());
1205 if (needReportToTarget(chr
))
1206 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED
, GetName(), FSpeed
);
1208 chr
->SetSpeed(MOVE_FLIGHT
,FSpeed
,true);
1214 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1219 float Scale
= (float)atof((char*)args
);
1220 if (Scale
> 3.0f
|| Scale
<= 0.0f
)
1222 SendSysMessage(LANG_BAD_VALUE
);
1223 SetSentErrorMessage(true);
1227 Player
*chr
= getSelectedPlayer();
1230 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1231 SetSentErrorMessage(true);
1235 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, chr
->GetName());
1236 if (needReportToTarget(chr
))
1237 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SIZE_CHANGED
, GetName(), Scale
);
1239 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1244 //Enable Player mount
1245 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1251 float speed
= (float)15;
1254 num
= atoi((char*)args
);
1465 SendSysMessage(LANG_NO_MOUNT
);
1466 SetSentErrorMessage(true);
1470 Player
*chr
= getSelectedPlayer();
1473 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1474 SetSentErrorMessage(true);
1478 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, chr
->GetName());
1479 if (needReportToTarget(chr
))
1480 ChatHandler(chr
).PSendSysMessage(LANG_MOUNT_GIVED
, GetName());
1482 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1485 WorldPacket
data( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+1+4) );
1486 data
.append(chr
->GetPackGUID());
1488 data
<< (uint8
)0; //new 2.1.0
1489 data
<< float(speed
);
1490 chr
->SendMessageToSet( &data
, true );
1492 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1493 data
.append(chr
->GetPackGUID());
1495 data
<< float(speed
);
1496 chr
->SendMessageToSet( &data
, true );
1502 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1507 Player
*chr
= getSelectedPlayer();
1510 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1511 SetSentErrorMessage(true);
1515 int32 addmoney
= atoi((char*)args
);
1517 uint32 moneyuser
= chr
->GetMoney();
1521 int32 newmoney
= moneyuser
+ addmoney
;
1523 sLog
.outDetail(GetMangosString(LANG_CURRENT_MONEY
), moneyuser
, addmoney
, newmoney
);
1526 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, chr
->GetName());
1527 if (needReportToTarget(chr
))
1528 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE
, GetName());
1534 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), chr
->GetName());
1535 if (needReportToTarget(chr
))
1536 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_TAKEN
, GetName(), abs(addmoney
));
1537 chr
->SetMoney( newmoney
);
1542 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, chr
->GetName());
1543 if (needReportToTarget(chr
))
1544 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_MONEY_GIVEN
, GetName(), addmoney
);
1545 chr
->ModifyMoney( addmoney
);
1548 sLog
.outDetail(GetMangosString(LANG_NEW_MONEY
), moneyuser
, addmoney
, chr
->GetMoney() );
1554 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1559 Player
*chr
= getSelectedPlayer();
1562 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1563 SetSentErrorMessage(true);
1567 char* pField
= strtok((char*)args
, " ");
1571 char* pBit
= strtok(NULL
, " ");
1575 uint16 field
= atoi(pField
);
1576 uint32 bit
= atoi(pBit
);
1578 if (field
< 1 || field
>= PLAYER_END
)
1580 SendSysMessage(LANG_BAD_VALUE
);
1581 SetSentErrorMessage(true);
1585 if (bit
< 1 || bit
> 32)
1587 SendSysMessage(LANG_BAD_VALUE
);
1588 SetSentErrorMessage(true);
1592 if ( chr
->HasFlag( field
, (1<<(bit
-1)) ) )
1594 chr
->RemoveFlag( field
, (1<<(bit
-1)) );
1595 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1599 chr
->SetFlag( field
, (1<<(bit
-1)) );
1600 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1606 bool ChatHandler::HandleModifyHonorCommand (const char* args
)
1611 Player
*target
= getSelectedPlayer();
1614 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1615 SetSentErrorMessage(true);
1619 int32 amount
= (uint32
)atoi(args
);
1621 target
->ModifyHonorPoints(amount
);
1623 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR
, target
->GetName(), target
->GetHonorPoints());
1628 bool ChatHandler::HandleTeleCommand(const char * args
)
1633 Player
* _player
= m_session
->GetPlayer();
1635 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1636 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
1640 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1641 SetSentErrorMessage(true);
1645 // stop flight if need
1646 if(_player
->isInFlight())
1648 _player
->GetMotionMaster()->MovementExpired();
1649 _player
->m_taxi
.ClearTaxiDestinations();
1651 // save only in non-flight case
1653 _player
->SaveRecallPosition();
1655 _player
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1659 bool ChatHandler::HandleLookupAreaCommand(const char* args
)
1664 std::string namepart
= args
;
1665 std::wstring wnamepart
;
1667 if (!Utf8toWStr (namepart
,wnamepart
))
1670 uint32 counter
= 0; // Counter for figure out that we found smth.
1672 // converting string that we try to find to lower case
1673 wstrToLower (wnamepart
);
1675 // Search in AreaTable.dbc
1676 for (uint32 areaflag
= 0; areaflag
< sAreaStore
.GetNumRows (); ++areaflag
)
1678 AreaTableEntry
const *areaEntry
= sAreaStore
.LookupEntry (areaflag
);
1681 int loc
= m_session
? m_session
->GetSessionDbcLocale () : sWorld
.GetDefaultDbcLocale();
1682 std::string name
= areaEntry
->area_name
[loc
];
1686 if (!Utf8FitTo (name
, wnamepart
))
1689 for(; loc
< MAX_LOCALE
; ++loc
)
1691 if (m_session
&& loc
==m_session
->GetSessionDbcLocale ())
1694 name
= areaEntry
->area_name
[loc
];
1698 if (Utf8FitTo (name
, wnamepart
))
1703 if (loc
< MAX_LOCALE
)
1705 // send area in "id - [name]" format
1706 std::ostringstream ss
;
1708 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
]<< "]|h|r";
1710 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1712 SendSysMessage (ss
.str ().c_str());
1719 if (counter
== 0) // if counter == 0 then we found nth
1720 SendSysMessage (LANG_COMMAND_NOAREAFOUND
);
1725 //Find tele in game_tele order by name
1726 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1730 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1731 SetSentErrorMessage(true);
1735 char const* str
= strtok((char*)args
, " ");
1739 std::string namepart
= str
;
1740 std::wstring wnamepart
;
1742 if(!Utf8toWStr(namepart
,wnamepart
))
1745 // converting string that we try to find to lower case
1746 wstrToLower( wnamepart
);
1748 std::ostringstream reply
;
1750 GameTeleMap
const & teleMap
= objmgr
.GetGameTeleMap();
1751 for(GameTeleMap::const_iterator itr
= teleMap
.begin(); itr
!= teleMap
.end(); ++itr
)
1753 GameTele
const* tele
= &itr
->second
;
1755 if(tele
->wnameLow
.find(wnamepart
) == std::wstring::npos
)
1759 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1761 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1764 if(reply
.str().empty())
1765 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1767 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
,reply
.str().c_str());
1772 //Enable\Dissable accept whispers (for GM)
1773 bool ChatHandler::HandleWhispersCommand(const char* args
)
1777 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON
) : GetMangosString(LANG_OFF
));
1781 std::string argstr
= (char*)args
;
1785 m_session
->GetPlayer()->SetAcceptWhispers(true);
1786 SendSysMessage(LANG_COMMAND_WHISPERON
);
1791 if (argstr
== "off")
1793 m_session
->GetPlayer()->SetAcceptWhispers(false);
1794 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1798 SendSysMessage(LANG_USE_BOL
);
1799 SetSentErrorMessage(true);
1804 bool ChatHandler::HandlePlaySoundCommand(const char* args
)
1806 // USAGE: .debug playsound #soundid
1807 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1808 // this file have about 5000 sounds.
1809 // In this realization only caller can hear this sound.
1812 uint32 dwSoundId
= atoi((char*)args
);
1814 if( !sSoundEntriesStore
.LookupEntry(dwSoundId
) )
1816 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
1817 SetSentErrorMessage(true);
1821 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1822 data
<< uint32(dwSoundId
) << m_session
->GetPlayer()->GetGUID();
1823 m_session
->SendPacket(&data
);
1825 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
1832 //Save all players in the world
1833 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1835 ObjectAccessor::Instance().SaveAllPlayers();
1836 SendSysMessage(LANG_PLAYERS_SAVED
);
1840 //Send mail by command
1841 bool ChatHandler::HandleSendMailCommand(const char* args
)
1846 // format: name "subject text" "mail text"
1848 char* pName
= strtok((char*)args
, " ");
1852 char* tail1
= strtok(NULL
, "");
1858 msgSubject
= strtok(tail1
+1, "\"");
1861 char* space
= strtok(tail1
, "\"");
1864 msgSubject
= strtok(NULL
, "\"");
1870 char* tail2
= strtok(NULL
, "");
1876 msgText
= strtok(tail2
+1, "\"");
1879 char* space
= strtok(tail2
, "\"");
1882 msgText
= strtok(NULL
, "\"");
1888 // pName, msgSubject, msgText isn't NUL after prev. check
1889 std::string name
= pName
;
1890 std::string subject
= msgSubject
;
1891 std::string text
= msgText
;
1893 if(!normalizePlayerName(name
))
1895 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1896 SetSentErrorMessage(true);
1900 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
1903 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1904 SetSentErrorMessage(true);
1908 // from console show not existed sender
1909 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
1911 uint32 messagetype
= MAIL_NORMAL
;
1912 uint32 stationery
= MAIL_STATIONERY_GM
;
1913 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
1915 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
1917 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, 0, 0, MAIL_CHECK_MASK_NONE
);
1919 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
1923 // teleport player to given game_tele.entry
1924 bool ChatHandler::HandleNameTeleCommand(const char * args
)
1929 char* pName
= strtok((char*)args
, " ");
1934 std::string name
= pName
;
1936 if(!normalizePlayerName(name
))
1938 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1939 SetSentErrorMessage(true);
1943 char* tail
= strtok(NULL
, "");
1947 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1948 GameTele
const* tele
= extractGameTeleFromLink(tail
);
1951 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1952 SetSentErrorMessage(true);
1956 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
1960 if(chr
->IsBeingTeleported()==true)
1962 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
1963 SetSentErrorMessage(true);
1967 PSendSysMessage(LANG_TELEPORTING_TO
, chr
->GetName(),"", tele
->name
.c_str());
1968 if (needReportToTarget(chr
))
1969 ChatHandler(chr
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetName());
1971 // stop flight if need
1972 if(chr
->isInFlight())
1974 chr
->GetMotionMaster()->MovementExpired();
1975 chr
->m_taxi
.ClearTaxiDestinations();
1977 // save only in non-flight case
1979 chr
->SaveRecallPosition();
1981 chr
->TeleportTo(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
);
1983 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str()))
1985 PSendSysMessage(LANG_TELEPORTING_TO
, name
.c_str(), GetMangosString(LANG_OFFLINE
), tele
->name
.c_str());
1986 Player::SavePositionInDB(tele
->mapId
,tele
->position_x
,tele
->position_y
,tele
->position_z
,tele
->orientation
,MapManager::Instance().GetZoneId(tele
->mapId
,tele
->position_x
,tele
->position_y
),guid
);
1989 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());
1994 //Teleport group to given game_tele.entry
1995 bool ChatHandler::HandleGroupTeleCommand(const char * args
)
2000 Player
*player
= getSelectedPlayer();
2003 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2004 SetSentErrorMessage(true);
2008 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2009 GameTele
const* tele
= extractGameTeleFromLink((char*)args
);
2012 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
2013 SetSentErrorMessage(true);
2017 Group
*grp
= player
->GetGroup();
2020 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2021 SetSentErrorMessage(true);
2025 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2027 Player
*pl
= itr
->getSource();
2029 if(!pl
|| !pl
->GetSession() )
2032 if(pl
->IsBeingTeleported())
2034 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2038 PSendSysMessage(LANG_TELEPORTING_TO
, pl
->GetName(),"", tele
->name
.c_str());
2039 if (needReportToTarget(pl
))
2040 ChatHandler(pl
).PSendSysMessage(LANG_TELEPORTED_TO_BY
, GetName());
2042 // stop flight if need
2043 if(pl
->isInFlight())
2045 pl
->GetMotionMaster()->MovementExpired();
2046 pl
->m_taxi
.ClearTaxiDestinations();
2048 // save only in non-flight case
2050 pl
->SaveRecallPosition();
2052 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
2058 //Summon group of player
2059 bool ChatHandler::HandleGroupgoCommand(const char* args
)
2064 std::string name
= args
;
2066 if(!normalizePlayerName(name
))
2068 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2069 SetSentErrorMessage(true);
2073 Player
*player
= objmgr
.GetPlayer(name
.c_str());
2076 PSendSysMessage(LANG_NO_PLAYER
, args
);
2077 SetSentErrorMessage(true);
2081 Group
*grp
= player
->GetGroup();
2085 PSendSysMessage(LANG_NOT_IN_GROUP
,player
->GetName());
2086 SetSentErrorMessage(true);
2090 Map
* gmMap
= m_session
->GetPlayer()->GetMap();
2091 bool to_instance
= gmMap
->Instanceable();
2093 // we are in instance, and can summon only player in our group with us as lead
2094 if ( to_instance
&& (
2095 !m_session
->GetPlayer()->GetGroup() || (grp
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
2096 (m_session
->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ) )
2097 // the last check is a bit excessive, but let it be, just in case
2099 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST
);
2100 SetSentErrorMessage(true);
2104 for(GroupReference
*itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2106 Player
*pl
= itr
->getSource();
2108 if(!pl
|| pl
==m_session
->GetPlayer() || !pl
->GetSession() )
2111 if(pl
->IsBeingTeleported()==true)
2113 PSendSysMessage(LANG_IS_TELEPORTED
, pl
->GetName());
2114 SetSentErrorMessage(true);
2120 Map
* plMap
= pl
->GetMap();
2122 if ( plMap
->Instanceable() && plMap
->GetInstanceId() != gmMap
->GetInstanceId() )
2124 // cannot summon from instance to instance
2125 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,pl
->GetName());
2126 SetSentErrorMessage(true);
2131 PSendSysMessage(LANG_SUMMONING
, pl
->GetName(),"");
2132 if (needReportToTarget(pl
))
2133 ChatHandler(pl
).PSendSysMessage(LANG_SUMMONED_BY
, GetName());
2135 // stop flight if need
2136 if(pl
->isInFlight())
2138 pl
->GetMotionMaster()->MovementExpired();
2139 pl
->m_taxi
.ClearTaxiDestinations();
2141 // save only in non-flight case
2143 pl
->SaveRecallPosition();
2147 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,pl
->GetObjectSize());
2148 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,pl
->GetOrientation());
2154 //teleport at coordinates
2155 bool ChatHandler::HandleGoXYCommand(const char* args
)
2160 Player
* _player
= m_session
->GetPlayer();
2162 char* px
= strtok((char*)args
, " ");
2163 char* py
= strtok(NULL
, " ");
2164 char* pmapid
= strtok(NULL
, " ");
2169 float x
= (float)atof(px
);
2170 float y
= (float)atof(py
);
2173 mapid
= (uint32
)atoi(pmapid
);
2174 else mapid
= _player
->GetMapId();
2176 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2178 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2179 SetSentErrorMessage(true);
2183 // stop flight if need
2184 if(_player
->isInFlight())
2186 _player
->GetMotionMaster()->MovementExpired();
2187 _player
->m_taxi
.ClearTaxiDestinations();
2189 // save only in non-flight case
2191 _player
->SaveRecallPosition();
2193 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2194 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2196 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2201 //teleport at coordinates, including Z
2202 bool ChatHandler::HandleGoXYZCommand(const char* args
)
2207 Player
* _player
= m_session
->GetPlayer();
2209 char* px
= strtok((char*)args
, " ");
2210 char* py
= strtok(NULL
, " ");
2211 char* pz
= strtok(NULL
, " ");
2212 char* pmapid
= strtok(NULL
, " ");
2214 if (!px
|| !py
|| !pz
)
2217 float x
= (float)atof(px
);
2218 float y
= (float)atof(py
);
2219 float z
= (float)atof(pz
);
2222 mapid
= (uint32
)atoi(pmapid
);
2224 mapid
= _player
->GetMapId();
2226 if(!MapManager::IsValidMapCoord(mapid
,x
,y
,z
))
2228 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2229 SetSentErrorMessage(true);
2233 // stop flight if need
2234 if(_player
->isInFlight())
2236 _player
->GetMotionMaster()->MovementExpired();
2237 _player
->m_taxi
.ClearTaxiDestinations();
2239 // save only in non-flight case
2241 _player
->SaveRecallPosition();
2243 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2248 //teleport at coordinates
2249 bool ChatHandler::HandleGoZoneXYCommand(const char* args
)
2254 Player
* _player
= m_session
->GetPlayer();
2256 char* px
= strtok((char*)args
, " ");
2257 char* py
= strtok(NULL
, " ");
2258 char* tail
= strtok(NULL
,"");
2260 char* cAreaId
= extractKeyFromLink(tail
,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2265 float x
= (float)atof(px
);
2266 float y
= (float)atof(py
);
2267 uint32 areaid
= cAreaId
? (uint32
)atoi(cAreaId
) : _player
->GetZoneId();
2269 AreaTableEntry
const* areaEntry
= GetAreaEntryByAreaID(areaid
);
2271 if( x
<0 || x
>100 || y
<0 || y
>100 || !areaEntry
)
2273 PSendSysMessage(LANG_INVALID_ZONE_COORD
,x
,y
,areaid
);
2274 SetSentErrorMessage(true);
2278 // update to parent zone if exist (client map show only zones without parents)
2279 AreaTableEntry
const* zoneEntry
= areaEntry
->zone
? GetAreaEntryByAreaID(areaEntry
->zone
) : areaEntry
;
2281 Map
const *map
= MapManager::Instance().GetBaseMap(zoneEntry
->mapid
);
2283 if(map
->Instanceable())
2285 PSendSysMessage(LANG_INVALID_ZONE_MAP
,areaEntry
->ID
,areaEntry
->area_name
[m_session
->GetSessionDbcLocale()],map
->GetId(),map
->GetMapName());
2286 SetSentErrorMessage(true);
2290 Zone2MapCoordinates(x
,y
,zoneEntry
->ID
);
2292 if(!MapManager::IsValidMapCoord(zoneEntry
->mapid
,x
,y
))
2294 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,zoneEntry
->mapid
);
2295 SetSentErrorMessage(true);
2299 // stop flight if need
2300 if(_player
->isInFlight())
2302 _player
->GetMotionMaster()->MovementExpired();
2303 _player
->m_taxi
.ClearTaxiDestinations();
2305 // save only in non-flight case
2307 _player
->SaveRecallPosition();
2309 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2310 _player
->TeleportTo(zoneEntry
->mapid
, x
, y
, z
, _player
->GetOrientation());
2316 bool ChatHandler::HandleGoGridCommand(const char* args
)
2318 if(!*args
) return false;
2319 Player
* _player
= m_session
->GetPlayer();
2321 char* px
= strtok((char*)args
, " ");
2322 char* py
= strtok(NULL
, " ");
2323 char* pmapid
= strtok(NULL
, " ");
2328 float grid_x
= (float)atof(px
);
2329 float grid_y
= (float)atof(py
);
2332 mapid
= (uint32
)atoi(pmapid
);
2333 else mapid
= _player
->GetMapId();
2336 float x
= (grid_x
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2337 float y
= (grid_y
-CENTER_GRID_ID
+0.5f
)*SIZE_OF_GRIDS
;
2339 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
2341 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
2342 SetSentErrorMessage(true);
2346 // stop flight if need
2347 if(_player
->isInFlight())
2349 _player
->GetMotionMaster()->MovementExpired();
2350 _player
->m_taxi
.ClearTaxiDestinations();
2352 // save only in non-flight case
2354 _player
->SaveRecallPosition();
2356 Map
const *map
= MapManager::Instance().GetBaseMap(mapid
);
2357 float z
= std::max(map
->GetHeight(x
, y
, MAX_HEIGHT
), map
->GetWaterLevel(x
, y
));
2358 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
2363 bool ChatHandler::HandleDrunkCommand(const char* args
)
2365 if(!*args
) return false;
2367 uint32 drunklevel
= (uint32
)atoi(args
);
2368 if(drunklevel
> 100)
2371 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2373 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);