[7804] Allow swap and move by bag slots equipped ammopouch and quiver
[getmangos.git] / src / game / Level1.cpp
blob79b9ab1c5d23ce4d1e1baec648fd4ccdec7b7255
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Opcodes.h"
27 #include "Chat.h"
28 #include "Log.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
31 #include "Language.h"
32 #include "CellImpl.h"
33 #include "InstanceSaveMgr.h"
34 #include "Util.h"
35 #ifdef _DEBUG_VMAPS
36 #include "VMapFactory.h"
37 #endif
39 //-----------------------Npc Commands-----------------------
40 bool ChatHandler::HandleNpcSayCommand(const char* args)
42 if(!*args)
43 return false;
45 Creature* pCreature = getSelectedCreature();
46 if(!pCreature)
48 SendSysMessage(LANG_SELECT_CREATURE);
49 SetSentErrorMessage(true);
50 return false;
53 pCreature->MonsterSay(args, LANG_UNIVERSAL, 0);
55 return true;
58 bool ChatHandler::HandleNpcYellCommand(const char* args)
60 if(!*args)
61 return false;
63 Creature* pCreature = getSelectedCreature();
64 if(!pCreature)
66 SendSysMessage(LANG_SELECT_CREATURE);
67 SetSentErrorMessage(true);
68 return false;
71 pCreature->MonsterYell(args, LANG_UNIVERSAL, 0);
73 return true;
76 //show text emote by creature in chat
77 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args)
79 if(!*args)
80 return false;
82 Creature* pCreature = getSelectedCreature();
84 if(!pCreature)
86 SendSysMessage(LANG_SELECT_CREATURE);
87 SetSentErrorMessage(true);
88 return false;
91 pCreature->MonsterTextEmote(args, 0);
93 return true;
96 // make npc whisper to player
97 bool ChatHandler::HandleNpcWhisperCommand(const char* args)
99 if(!*args)
100 return false;
102 char* receiver_str = strtok((char*)args, " ");
103 char* text = strtok(NULL, "");
105 uint64 guid = m_session->GetPlayer()->GetSelection();
106 Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid);
108 if(!pCreature || !receiver_str || !text)
110 return false;
113 uint64 receiver_guid= atol(receiver_str);
115 // check online security
116 if (HasLowerSecurity(objmgr.GetPlayer(receiver_guid), 0))
117 return false;
119 pCreature->MonsterWhisper(text,receiver_guid);
121 return true;
123 //----------------------------------------------------------
125 // global announce
126 bool ChatHandler::HandleAnnounceCommand(const char* args)
128 if(!*args)
129 return false;
131 sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
132 return true;
135 //notification player at the screen
136 bool ChatHandler::HandleNotifyCommand(const char* args)
138 if(!*args)
139 return false;
141 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
142 str += args;
144 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
145 data << str;
146 sWorld.SendGlobalMessage(&data);
148 return true;
151 //Enable\Dissable GM Mode
152 bool ChatHandler::HandleGMCommand(const char* args)
154 if(!*args)
156 if(m_session->GetPlayer()->isGameMaster())
157 m_session->SendNotification(LANG_GM_ON);
158 else
159 m_session->SendNotification(LANG_GM_OFF);
160 return true;
163 std::string argstr = (char*)args;
165 if (argstr == "on")
167 m_session->GetPlayer()->SetGameMaster(true);
168 m_session->SendNotification(LANG_GM_ON);
169 #ifdef _DEBUG_VMAPS
170 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
171 vMapManager->processCommand("stoplog");
172 #endif
173 return true;
176 if (argstr == "off")
178 m_session->GetPlayer()->SetGameMaster(false);
179 m_session->SendNotification(LANG_GM_OFF);
180 #ifdef _DEBUG_VMAPS
181 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
182 vMapManager->processCommand("startlog");
183 #endif
184 return true;
187 SendSysMessage(LANG_USE_BOL);
188 SetSentErrorMessage(true);
189 return false;
192 // Enables or disables hiding of the staff badge
193 bool ChatHandler::HandleGMChatCommand(const char* args)
195 if(!*args)
197 if(m_session->GetPlayer()->isGMChat())
198 m_session->SendNotification(LANG_GM_CHAT_ON);
199 else
200 m_session->SendNotification(LANG_GM_CHAT_OFF);
201 return true;
204 std::string argstr = (char*)args;
206 if (argstr == "on")
208 m_session->GetPlayer()->SetGMChat(true);
209 m_session->SendNotification(LANG_GM_CHAT_ON);
210 return true;
213 if (argstr == "off")
215 m_session->GetPlayer()->SetGMChat(false);
216 m_session->SendNotification(LANG_GM_CHAT_OFF);
217 return true;
220 SendSysMessage(LANG_USE_BOL);
221 SetSentErrorMessage(true);
222 return false;
225 //Enable\Dissable Invisible mode
226 bool ChatHandler::HandleGMVisibleCommand(const char* args)
228 if (!*args)
230 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
231 return true;
234 std::string argstr = (char*)args;
236 if (argstr == "on")
238 m_session->GetPlayer()->SetGMVisible(true);
239 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
240 return true;
243 if (argstr == "off")
245 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
246 m_session->GetPlayer()->SetGMVisible(false);
247 return true;
250 SendSysMessage(LANG_USE_BOL);
251 SetSentErrorMessage(true);
252 return false;
257 bool ChatHandler::HandleGPSCommand(const char* args)
259 WorldObject *obj = NULL;
260 if (*args)
262 uint64 guid = extractGuidFromLink((char*)args);
263 if(guid)
264 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
266 if(!obj)
268 SendSysMessage(LANG_PLAYER_NOT_FOUND);
269 SetSentErrorMessage(true);
270 return false;
273 else
275 obj = getSelectedUnit();
277 if(!obj)
279 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
280 SetSentErrorMessage(true);
281 return false;
284 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
285 Cell cell(cell_val);
287 uint32 zone_id, area_id;
288 obj->GetZoneAndAreaId(zone_id,area_id);
290 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
291 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
292 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
294 float zone_x = obj->GetPositionX();
295 float zone_y = obj->GetPositionY();
297 Map2ZoneCoordinates(zone_x,zone_y,zone_id);
299 Map const *map = obj->GetMap();
300 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
301 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
303 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
305 int gx=63-p.x_coord;
306 int gy=63-p.y_coord;
308 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
309 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
311 PSendSysMessage(LANG_MAP_POSITION,
312 obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
314 area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
315 obj->GetPhaseMask(),
316 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
317 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
318 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
320 sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
321 m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND),
322 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
323 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
325 sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
326 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
327 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
328 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
329 obj->GetPhaseMask(),
330 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
331 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
332 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
334 LiquidData liquid_status;
335 ZLiquidStatus res = map->getLiquidStatus(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), MAP_ALL_LIQUIDS, &liquid_status);
336 if (res)
338 PSendSysMessage(LANG_LIQUID_STATUS, liquid_status.level, liquid_status.depth_level, liquid_status.type, res);
340 return true;
343 //Summon Player
344 bool ChatHandler::HandleNamegoCommand(const char* args)
346 if(!*args)
347 return false;
349 std::string name = extractPlayerNameFromLink((char*)args);
350 if(name.empty())
352 SendSysMessage(LANG_PLAYER_NOT_FOUND);
353 SetSentErrorMessage(true);
354 return false;
357 Player *chr = objmgr.GetPlayer(name.c_str());
358 if (chr)
360 std::string nameLink = playerLink(name);
361 // check online security
362 if (HasLowerSecurity(chr, 0))
363 return false;
365 if(chr->IsBeingTeleported())
367 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
368 SetSentErrorMessage(true);
369 return false;
372 Map* pMap = m_session->GetPlayer()->GetMap();
374 if(pMap->IsBattleGroundOrArena())
376 // only allow if gm mode is on
377 if (!chr->isGameMaster())
379 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chr->GetName());
380 SetSentErrorMessage(true);
381 return false;
383 // if both players are in different bgs
384 else if (chr->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != chr->GetBattleGroundId())
386 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chr->GetName());
387 SetSentErrorMessage(true);
388 return false;
390 // all's well, set bg id
391 // when porting out from the bg, it will be reset to 0
392 chr->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
393 // remember current position as entry point for return at bg end teleportation
394 chr->SetBattleGroundEntryPoint(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation());
396 else if(pMap->IsDungeon())
398 Map* cMap = chr->GetMap();
399 if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
401 // cannot summon from instance to instance
402 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
403 SetSentErrorMessage(true);
404 return false;
407 // we are in instance, and can summon only player in our group with us as lead
408 if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
409 (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
410 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
411 // the last check is a bit excessive, but let it be, just in case
413 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
414 SetSentErrorMessage(true);
415 return false;
419 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
420 if (needReportToTarget(chr))
421 ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
423 // stop flight if need
424 if(chr->isInFlight())
426 chr->GetMotionMaster()->MovementExpired();
427 chr->m_taxi.ClearTaxiDestinations();
429 // save only in non-flight case
430 else
431 chr->SaveRecallPosition();
433 // before GM
434 float x,y,z;
435 m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
436 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
438 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
440 // check offline security
441 if (HasLowerSecurity(NULL, guid))
442 return false;
444 std::string nameLink = playerLink(name);
446 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
448 // in point where GM stay
449 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
450 m_session->GetPlayer()->GetPositionX(),
451 m_session->GetPlayer()->GetPositionY(),
452 m_session->GetPlayer()->GetPositionZ(),
453 m_session->GetPlayer()->GetOrientation(),
454 m_session->GetPlayer()->GetZoneId(),
455 guid);
457 else
459 PSendSysMessage(LANG_NO_PLAYER, args);
460 SetSentErrorMessage(true);
463 return true;
466 //Teleport to Player
467 bool ChatHandler::HandleGonameCommand(const char* args)
469 if(!*args)
470 return false;
472 Player* _player = m_session->GetPlayer();
474 std::string name = extractPlayerNameFromLink((char*)args);
475 if(name.empty())
477 SendSysMessage(LANG_PLAYER_NOT_FOUND);
478 SetSentErrorMessage(true);
479 return false;
482 Player *chr = objmgr.GetPlayer(name.c_str());
483 if (chr)
485 // check online security
486 if (HasLowerSecurity(chr, 0))
487 return false;
489 std::string chrNameLink = playerLink(name);
491 Map* cMap = chr->GetMap();
492 if(cMap->IsBattleGroundOrArena())
494 // only allow if gm mode is on
495 if (!_player->isGameMaster())
497 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
498 SetSentErrorMessage(true);
499 return false;
501 // if both players are in different bgs
502 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != chr->GetBattleGroundId())
504 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
505 SetSentErrorMessage(true);
506 return false;
508 // all's well, set bg id
509 // when porting out from the bg, it will be reset to 0
510 _player->SetBattleGroundId(chr->GetBattleGroundId(), chr->GetBattleGroundTypeId());
511 // remember current position as entry point for return at bg end teleportation
512 _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
514 else if(cMap->IsDungeon())
516 // we have to go to instance, and can go to player only if:
517 // 1) we are in his group (either as leader or as member)
518 // 2) we are not bound to any group and have GM mode on
519 if (_player->GetGroup())
521 // we are in group, we can go only if we are in the player group
522 if (_player->GetGroup() != chr->GetGroup())
524 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
525 SetSentErrorMessage(true);
526 return false;
529 else
531 // we are not in group, let's verify our GM mode
532 if (!_player->isGameMaster())
534 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
535 SetSentErrorMessage(true);
536 return false;
540 // if the player or the player's group is bound to another instance
541 // the player will not be bound to another one
542 InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
543 if(!pBind)
545 Group *group = _player->GetGroup();
546 InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
547 if(!gBind)
549 // if no bind exists, create a solo bind
550 InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
551 if(save) _player->BindToInstance(save, !save->CanReset());
555 _player->SetDifficulty(chr->GetDifficulty());
558 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
559 if (_player->IsVisibleGloballyFor(chr))
560 ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
562 // stop flight if need
563 if(_player->isInFlight())
565 _player->GetMotionMaster()->MovementExpired();
566 _player->m_taxi.ClearTaxiDestinations();
568 // save only in non-flight case
569 else
570 _player->SaveRecallPosition();
572 // to point to see at target with same orientation
573 float x,y,z;
574 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
576 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
578 return true;
581 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
583 // check offline security
584 if (HasLowerSecurity(NULL, guid))
585 return false;
587 std::string nameLink = playerLink(name);
589 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
591 // to point where player stay (if loaded)
592 float x,y,z,o;
593 uint32 map;
594 bool in_flight;
595 if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
597 // stop flight if need
598 if(_player->isInFlight())
600 _player->GetMotionMaster()->MovementExpired();
601 _player->m_taxi.ClearTaxiDestinations();
603 // save only in non-flight case
604 else
605 _player->SaveRecallPosition();
607 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
608 return true;
612 PSendSysMessage(LANG_NO_PLAYER, args);
614 SetSentErrorMessage(true);
615 return false;
618 // Teleport player to last position
619 bool ChatHandler::HandleRecallCommand(const char* args)
621 Player* chr = NULL;
623 if(!*args)
625 chr = getSelectedPlayer();
626 if(!chr)
627 chr = m_session->GetPlayer();
629 // check online security
630 else if (HasLowerSecurity(chr, 0))
631 return false;
633 else
635 std::string name = extractPlayerNameFromLink((char*)args);
636 if(name.empty())
638 SendSysMessage(LANG_PLAYER_NOT_FOUND);
639 SetSentErrorMessage(true);
640 return false;
643 chr = objmgr.GetPlayer(name.c_str());
645 if(!chr)
647 PSendSysMessage(LANG_NO_PLAYER, args);
648 SetSentErrorMessage(true);
649 return false;
652 // check online security
653 if (HasLowerSecurity(chr, 0))
654 return false;
657 if(chr->IsBeingTeleported())
659 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(chr).c_str());
660 SetSentErrorMessage(true);
661 return false;
664 // stop flight if need
665 if(chr->isInFlight())
667 chr->GetMotionMaster()->MovementExpired();
668 chr->m_taxi.ClearTaxiDestinations();
671 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
672 return true;
675 //Edit Player KnownTitles
676 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
678 if(!*args)
679 return false;
681 uint64 titles = 0;
683 sscanf((char*)args, I64FMTD, &titles);
685 Player *chr = getSelectedPlayer();
686 if (!chr)
688 SendSysMessage(LANG_NO_CHAR_SELECTED);
689 SetSentErrorMessage(true);
690 return false;
693 // check online security
694 if (HasLowerSecurity(chr, 0))
695 return false;
697 uint64 titles2 = titles;
699 for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
700 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
701 titles2 &= ~(uint64(1) << tEntry->bit_index);
703 titles &= ~titles2; // remove not existed titles
705 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
706 SendSysMessage(LANG_DONE);
708 return true;
711 //Edit Player HP
712 bool ChatHandler::HandleModifyHPCommand(const char* args)
714 if(!*args)
715 return false;
717 // char* pHp = strtok((char*)args, " ");
718 // if (!pHp)
719 // return false;
721 // char* pHpMax = strtok(NULL, " ");
722 // if (!pHpMax)
723 // return false;
725 // int32 hpm = atoi(pHpMax);
726 // int32 hp = atoi(pHp);
728 int32 hp = atoi((char*)args);
729 int32 hpm = atoi((char*)args);
731 if (hp <= 0 || hpm <= 0 || hpm < hp)
733 SendSysMessage(LANG_BAD_VALUE);
734 SetSentErrorMessage(true);
735 return false;
738 Player *chr = getSelectedPlayer();
739 if (chr == NULL)
741 SendSysMessage(LANG_NO_CHAR_SELECTED);
742 SetSentErrorMessage(true);
743 return false;
746 // check online security
747 if (HasLowerSecurity(chr, 0))
748 return false;
750 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
751 if (needReportToTarget(chr))
752 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
754 chr->SetMaxHealth( hpm );
755 chr->SetHealth( hp );
757 return true;
760 //Edit Player Mana
761 bool ChatHandler::HandleModifyManaCommand(const char* args)
763 if(!*args)
764 return false;
766 // char* pmana = strtok((char*)args, " ");
767 // if (!pmana)
768 // return false;
770 // char* pmanaMax = strtok(NULL, " ");
771 // if (!pmanaMax)
772 // return false;
774 // int32 manam = atoi(pmanaMax);
775 // int32 mana = atoi(pmana);
776 int32 mana = atoi((char*)args);
777 int32 manam = atoi((char*)args);
779 if (mana <= 0 || manam <= 0 || manam < mana)
781 SendSysMessage(LANG_BAD_VALUE);
782 SetSentErrorMessage(true);
783 return false;
786 Player *chr = getSelectedPlayer();
787 if (chr == NULL)
789 SendSysMessage(LANG_NO_CHAR_SELECTED);
790 SetSentErrorMessage(true);
791 return false;
794 // check online security
795 if (HasLowerSecurity(chr, 0))
796 return false;
798 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
799 if (needReportToTarget(chr))
800 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
802 chr->SetMaxPower(POWER_MANA,manam );
803 chr->SetPower(POWER_MANA, mana );
805 return true;
808 //Edit Player Energy
809 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
811 if(!*args)
812 return false;
814 // char* pmana = strtok((char*)args, " ");
815 // if (!pmana)
816 // return false;
818 // char* pmanaMax = strtok(NULL, " ");
819 // if (!pmanaMax)
820 // return false;
822 // int32 manam = atoi(pmanaMax);
823 // int32 mana = atoi(pmana);
825 int32 energy = atoi((char*)args)*10;
826 int32 energym = atoi((char*)args)*10;
828 if (energy <= 0 || energym <= 0 || energym < energy)
830 SendSysMessage(LANG_BAD_VALUE);
831 SetSentErrorMessage(true);
832 return false;
835 Player *chr = getSelectedPlayer();
836 if (!chr)
838 SendSysMessage(LANG_NO_CHAR_SELECTED);
839 SetSentErrorMessage(true);
840 return false;
843 // check online security
844 if (HasLowerSecurity(chr, 0))
845 return false;
847 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
848 if (needReportToTarget(chr))
849 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
851 chr->SetMaxPower(POWER_ENERGY,energym );
852 chr->SetPower(POWER_ENERGY, energy );
854 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
856 return true;
859 //Edit Player Rage
860 bool ChatHandler::HandleModifyRageCommand(const char* args)
862 if(!*args)
863 return false;
865 // char* pmana = strtok((char*)args, " ");
866 // if (!pmana)
867 // return false;
869 // char* pmanaMax = strtok(NULL, " ");
870 // if (!pmanaMax)
871 // return false;
873 // int32 manam = atoi(pmanaMax);
874 // int32 mana = atoi(pmana);
876 int32 rage = atoi((char*)args)*10;
877 int32 ragem = atoi((char*)args)*10;
879 if (rage <= 0 || ragem <= 0 || ragem < rage)
881 SendSysMessage(LANG_BAD_VALUE);
882 SetSentErrorMessage(true);
883 return false;
886 Player *chr = getSelectedPlayer();
887 if (chr == NULL)
889 SendSysMessage(LANG_NO_CHAR_SELECTED);
890 SetSentErrorMessage(true);
891 return false;
894 // check online security
895 if (HasLowerSecurity(chr, 0))
896 return false;
898 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
899 if (needReportToTarget(chr))
900 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
902 chr->SetMaxPower(POWER_RAGE,ragem );
903 chr->SetPower(POWER_RAGE, rage );
905 return true;
908 // Edit Player Runic Power
909 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
911 if(!*args)
912 return false;
914 int32 rune = atoi((char*)args)*10;
915 int32 runem = atoi((char*)args)*10;
917 if (rune <= 0 || runem <= 0 || runem < rune)
919 SendSysMessage(LANG_BAD_VALUE);
920 SetSentErrorMessage(true);
921 return false;
924 Player *chr = getSelectedPlayer();
925 if (chr == NULL)
927 SendSysMessage(LANG_NO_CHAR_SELECTED);
928 SetSentErrorMessage(true);
929 return false;
932 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
933 if (needReportToTarget(chr))
934 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
936 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
937 chr->SetPower(POWER_RUNIC_POWER, rune );
939 return true;
942 //Edit Player Faction
943 bool ChatHandler::HandleModifyFactionCommand(const char* args)
945 if(!*args)
946 return false;
948 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
950 Creature* chr = getSelectedCreature();
951 if(!chr)
953 SendSysMessage(LANG_SELECT_CREATURE);
954 SetSentErrorMessage(true);
955 return false;
958 if(!pfactionid)
960 if(chr)
962 uint32 factionid = chr->getFaction();
963 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
964 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
965 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
966 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
968 return true;
971 if( !chr )
973 SendSysMessage(LANG_NO_CHAR_SELECTED);
974 SetSentErrorMessage(true);
975 return false;
978 uint32 factionid = atoi(pfactionid);
979 uint32 flag;
981 char *pflag = strtok(NULL, " ");
982 if (!pflag)
983 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
984 else
985 flag = atoi(pflag);
987 char* pnpcflag = strtok(NULL, " ");
989 uint32 npcflag;
990 if(!pnpcflag)
991 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
992 else
993 npcflag = atoi(pnpcflag);
995 char* pdyflag = strtok(NULL, " ");
997 uint32 dyflag;
998 if(!pdyflag)
999 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
1000 else
1001 dyflag = atoi(pdyflag);
1003 if(!sFactionTemplateStore.LookupEntry(factionid))
1005 PSendSysMessage(LANG_WRONG_FACTION, factionid);
1006 SetSentErrorMessage(true);
1007 return false;
1010 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
1012 chr->setFaction(factionid);
1013 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
1014 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
1015 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
1017 return true;
1020 //Edit Player Spell
1021 bool ChatHandler::HandleModifySpellCommand(const char* args)
1023 if(!*args) return false;
1024 char* pspellflatid = strtok((char*)args, " ");
1025 if (!pspellflatid)
1026 return false;
1028 char* pop = strtok(NULL, " ");
1029 if (!pop)
1030 return false;
1032 char* pval = strtok(NULL, " ");
1033 if (!pval)
1034 return false;
1036 uint16 mark;
1038 char* pmark = strtok(NULL, " ");
1040 uint8 spellflatid = atoi(pspellflatid);
1041 uint8 op = atoi(pop);
1042 uint16 val = atoi(pval);
1043 if(!pmark)
1044 mark = 65535;
1045 else
1046 mark = atoi(pmark);
1048 Player *chr = getSelectedPlayer();
1049 if (chr == NULL)
1051 SendSysMessage(LANG_NO_CHAR_SELECTED);
1052 SetSentErrorMessage(true);
1053 return false;
1056 // check online security
1057 if (HasLowerSecurity(chr, 0))
1058 return false;
1060 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1061 if (needReportToTarget(chr))
1062 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1064 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1065 data << uint8(spellflatid);
1066 data << uint8(op);
1067 data << uint16(val);
1068 data << uint16(mark);
1069 chr->GetSession()->SendPacket(&data);
1071 return true;
1074 //Edit Player TP
1075 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1077 if (!*args)
1078 return false;
1080 int tp = atoi((char*)args);
1081 if (tp>0)
1083 Player* player = getSelectedPlayer();
1084 if(!player)
1086 SendSysMessage(LANG_NO_CHAR_SELECTED);
1087 SetSentErrorMessage(true);
1088 return false;
1091 // check online security
1092 if (HasLowerSecurity(player, 0))
1093 return false;
1095 player->SetFreeTalentPoints(tp);
1096 return true;
1098 return false;
1101 //Enable On\OFF all taxi paths
1102 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1104 if (!*args)
1106 SendSysMessage(LANG_USE_BOL);
1107 SetSentErrorMessage(true);
1108 return false;
1111 std::string argstr = (char*)args;
1113 Player *chr = getSelectedPlayer();
1114 if (!chr)
1116 chr=m_session->GetPlayer();
1119 // check online security
1120 else if (HasLowerSecurity(chr, 0))
1121 return false;
1123 if (argstr == "on")
1125 chr->SetTaxiCheater(true);
1126 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1127 if (needReportToTarget(chr))
1128 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1129 return true;
1132 if (argstr == "off")
1134 chr->SetTaxiCheater(false);
1135 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1136 if (needReportToTarget(chr))
1137 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1139 return true;
1142 SendSysMessage(LANG_USE_BOL);
1143 SetSentErrorMessage(true);
1144 return false;
1147 //Edit Player Aspeed
1148 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1150 if (!*args)
1151 return false;
1153 float ASpeed = (float)atof((char*)args);
1155 if (ASpeed > 10 || ASpeed < 0.1)
1157 SendSysMessage(LANG_BAD_VALUE);
1158 SetSentErrorMessage(true);
1159 return false;
1162 Player *chr = getSelectedPlayer();
1163 if (chr == NULL)
1165 SendSysMessage(LANG_NO_CHAR_SELECTED);
1166 SetSentErrorMessage(true);
1167 return false;
1170 // check online security
1171 if (HasLowerSecurity(chr, 0))
1172 return false;
1174 std::string chrNameLink = GetNameLink(chr);
1176 if(chr->isInFlight())
1178 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1179 SetSentErrorMessage(true);
1180 return false;
1183 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1184 if (needReportToTarget(chr))
1185 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1187 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1188 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1189 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1190 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1191 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1192 return true;
1195 //Edit Player Speed
1196 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1198 if (!*args)
1199 return false;
1201 float Speed = (float)atof((char*)args);
1203 if (Speed > 10 || Speed < 0.1)
1205 SendSysMessage(LANG_BAD_VALUE);
1206 SetSentErrorMessage(true);
1207 return false;
1210 Player *chr = getSelectedPlayer();
1211 if (chr == NULL)
1213 SendSysMessage(LANG_NO_CHAR_SELECTED);
1214 SetSentErrorMessage(true);
1215 return false;
1218 // check online security
1219 if (HasLowerSecurity(chr, 0))
1220 return false;
1222 std::string chrNameLink = GetNameLink(chr);
1224 if(chr->isInFlight())
1226 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1227 SetSentErrorMessage(true);
1228 return false;
1231 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1232 if (needReportToTarget(chr))
1233 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1235 chr->SetSpeed(MOVE_RUN,Speed,true);
1237 return true;
1240 //Edit Player Swim Speed
1241 bool ChatHandler::HandleModifySwimCommand(const char* args)
1243 if (!*args)
1244 return false;
1246 float Swim = (float)atof((char*)args);
1248 if (Swim > 10.0f || Swim < 0.01f)
1250 SendSysMessage(LANG_BAD_VALUE);
1251 SetSentErrorMessage(true);
1252 return false;
1255 Player *chr = getSelectedPlayer();
1256 if (chr == NULL)
1258 SendSysMessage(LANG_NO_CHAR_SELECTED);
1259 SetSentErrorMessage(true);
1260 return false;
1263 // check online security
1264 if (HasLowerSecurity(chr, 0))
1265 return false;
1267 std::string chrNameLink = GetNameLink(chr);
1269 if(chr->isInFlight())
1271 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1272 SetSentErrorMessage(true);
1273 return false;
1276 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1277 if (needReportToTarget(chr))
1278 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1280 chr->SetSpeed(MOVE_SWIM,Swim,true);
1282 return true;
1285 //Edit Player Walk Speed
1286 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1288 if (!*args)
1289 return false;
1291 float BSpeed = (float)atof((char*)args);
1293 if (BSpeed > 10.0f || BSpeed < 0.1f)
1295 SendSysMessage(LANG_BAD_VALUE);
1296 SetSentErrorMessage(true);
1297 return false;
1300 Player *chr = getSelectedPlayer();
1301 if (chr == NULL)
1303 SendSysMessage(LANG_NO_CHAR_SELECTED);
1304 SetSentErrorMessage(true);
1305 return false;
1308 // check online security
1309 if (HasLowerSecurity(chr, 0))
1310 return false;
1312 std::string chrNameLink = GetNameLink(chr);
1314 if(chr->isInFlight())
1316 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1317 SetSentErrorMessage(true);
1318 return false;
1321 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1322 if (needReportToTarget(chr))
1323 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1325 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1327 return true;
1330 //Edit Player Fly
1331 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1333 if (!*args)
1334 return false;
1336 float FSpeed = (float)atof((char*)args);
1338 if (FSpeed > 10.0f || FSpeed < 0.1f)
1340 SendSysMessage(LANG_BAD_VALUE);
1341 SetSentErrorMessage(true);
1342 return false;
1345 Player *chr = getSelectedPlayer();
1346 if (chr == NULL)
1348 SendSysMessage(LANG_NO_CHAR_SELECTED);
1349 SetSentErrorMessage(true);
1350 return false;
1353 // check online security
1354 if (HasLowerSecurity(chr, 0))
1355 return false;
1357 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1358 if (needReportToTarget(chr))
1359 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1361 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1363 return true;
1366 //Edit Player Scale
1367 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1369 if (!*args)
1370 return false;
1372 float Scale = (float)atof((char*)args);
1373 if (Scale > 3.0f || Scale <= 0.0f)
1375 SendSysMessage(LANG_BAD_VALUE);
1376 SetSentErrorMessage(true);
1377 return false;
1380 Player *chr = getSelectedPlayer();
1381 if (chr == NULL)
1383 SendSysMessage(LANG_NO_CHAR_SELECTED);
1384 SetSentErrorMessage(true);
1385 return false;
1388 // check online security
1389 if (HasLowerSecurity(chr, 0))
1390 return false;
1392 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1393 if (needReportToTarget(chr))
1394 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1396 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1398 return true;
1401 //Enable Player mount
1402 bool ChatHandler::HandleModifyMountCommand(const char* args)
1404 if(!*args)
1405 return false;
1407 uint16 mId = 1147;
1408 float speed = (float)15;
1409 uint32 num = 0;
1411 num = atoi((char*)args);
1412 switch(num)
1414 case 1:
1415 mId=14340;
1416 break;
1417 case 2:
1418 mId=4806;
1419 break;
1420 case 3:
1421 mId=6471;
1422 break;
1423 case 4:
1424 mId=12345;
1425 break;
1426 case 5:
1427 mId=6472;
1428 break;
1429 case 6:
1430 mId=6473;
1431 break;
1432 case 7:
1433 mId=10670;
1434 break;
1435 case 8:
1436 mId=10719;
1437 break;
1438 case 9:
1439 mId=10671;
1440 break;
1441 case 10:
1442 mId=10672;
1443 break;
1444 case 11:
1445 mId=10720;
1446 break;
1447 case 12:
1448 mId=14349;
1449 break;
1450 case 13:
1451 mId=11641;
1452 break;
1453 case 14:
1454 mId=12244;
1455 break;
1456 case 15:
1457 mId=12242;
1458 break;
1459 case 16:
1460 mId=14578;
1461 break;
1462 case 17:
1463 mId=14579;
1464 break;
1465 case 18:
1466 mId=14349;
1467 break;
1468 case 19:
1469 mId=12245;
1470 break;
1471 case 20:
1472 mId=14335;
1473 break;
1474 case 21:
1475 mId=207;
1476 break;
1477 case 22:
1478 mId=2328;
1479 break;
1480 case 23:
1481 mId=2327;
1482 break;
1483 case 24:
1484 mId=2326;
1485 break;
1486 case 25:
1487 mId=14573;
1488 break;
1489 case 26:
1490 mId=14574;
1491 break;
1492 case 27:
1493 mId=14575;
1494 break;
1495 case 28:
1496 mId=604;
1497 break;
1498 case 29:
1499 mId=1166;
1500 break;
1501 case 30:
1502 mId=2402;
1503 break;
1504 case 31:
1505 mId=2410;
1506 break;
1507 case 32:
1508 mId=2409;
1509 break;
1510 case 33:
1511 mId=2408;
1512 break;
1513 case 34:
1514 mId=2405;
1515 break;
1516 case 35:
1517 mId=14337;
1518 break;
1519 case 36:
1520 mId=6569;
1521 break;
1522 case 37:
1523 mId=10661;
1524 break;
1525 case 38:
1526 mId=10666;
1527 break;
1528 case 39:
1529 mId=9473;
1530 break;
1531 case 40:
1532 mId=9476;
1533 break;
1534 case 41:
1535 mId=9474;
1536 break;
1537 case 42:
1538 mId=14374;
1539 break;
1540 case 43:
1541 mId=14376;
1542 break;
1543 case 44:
1544 mId=14377;
1545 break;
1546 case 45:
1547 mId=2404;
1548 break;
1549 case 46:
1550 mId=2784;
1551 break;
1552 case 47:
1553 mId=2787;
1554 break;
1555 case 48:
1556 mId=2785;
1557 break;
1558 case 49:
1559 mId=2736;
1560 break;
1561 case 50:
1562 mId=2786;
1563 break;
1564 case 51:
1565 mId=14347;
1566 break;
1567 case 52:
1568 mId=14346;
1569 break;
1570 case 53:
1571 mId=14576;
1572 break;
1573 case 54:
1574 mId=9695;
1575 break;
1576 case 55:
1577 mId=9991;
1578 break;
1579 case 56:
1580 mId=6448;
1581 break;
1582 case 57:
1583 mId=6444;
1584 break;
1585 case 58:
1586 mId=6080;
1587 break;
1588 case 59:
1589 mId=6447;
1590 break;
1591 case 60:
1592 mId=4805;
1593 break;
1594 case 61:
1595 mId=9714;
1596 break;
1597 case 62:
1598 mId=6448;
1599 break;
1600 case 63:
1601 mId=6442;
1602 break;
1603 case 64:
1604 mId=14632;
1605 break;
1606 case 65:
1607 mId=14332;
1608 break;
1609 case 66:
1610 mId=14331;
1611 break;
1612 case 67:
1613 mId=8469;
1614 break;
1615 case 68:
1616 mId=2830;
1617 break;
1618 case 69:
1619 mId=2346;
1620 break;
1621 default:
1622 SendSysMessage(LANG_NO_MOUNT);
1623 SetSentErrorMessage(true);
1624 return false;
1627 Player *chr = getSelectedPlayer();
1628 if (chr == NULL)
1630 SendSysMessage(LANG_NO_CHAR_SELECTED);
1631 SetSentErrorMessage(true);
1632 return false;
1635 // check online security
1636 if (HasLowerSecurity(chr, 0))
1637 return false;
1639 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1640 if (needReportToTarget(chr))
1641 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1643 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1644 chr->Mount(mId);
1646 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1647 data.append(chr->GetPackGUID());
1648 data << (uint32)0;
1649 data << (uint8)0; //new 2.1.0
1650 data << float(speed);
1651 chr->SendMessageToSet( &data, true );
1653 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1654 data.append(chr->GetPackGUID());
1655 data << (uint32)0;
1656 data << float(speed);
1657 chr->SendMessageToSet( &data, true );
1659 return true;
1662 //Edit Player money
1663 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1665 if (!*args)
1666 return false;
1668 Player *chr = getSelectedPlayer();
1669 if (chr == NULL)
1671 SendSysMessage(LANG_NO_CHAR_SELECTED);
1672 SetSentErrorMessage(true);
1673 return false;
1676 // check online security
1677 if (HasLowerSecurity(chr, 0))
1678 return false;
1680 int32 addmoney = atoi((char*)args);
1682 uint32 moneyuser = chr->GetMoney();
1684 if (addmoney < 0)
1686 int32 newmoney = int32(moneyuser) + addmoney;
1688 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1689 if (newmoney <= 0 )
1691 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1692 if (needReportToTarget(chr))
1693 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1695 chr->SetMoney(0);
1697 else
1699 if (newmoney > MAX_MONEY_AMOUNT)
1700 newmoney = MAX_MONEY_AMOUNT;
1702 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1703 if (needReportToTarget(chr))
1704 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1705 chr->SetMoney( newmoney );
1708 else
1710 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1711 if (needReportToTarget(chr))
1712 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1714 if (addmoney >=MAX_MONEY_AMOUNT)
1715 chr->SetMoney(MAX_MONEY_AMOUNT);
1716 else
1717 chr->ModifyMoney( addmoney );
1720 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1722 return true;
1725 //Edit Unit field
1726 bool ChatHandler::HandleModifyBitCommand(const char* args)
1728 if( !*args )
1729 return false;
1731 Unit *unit = getSelectedUnit();
1732 if (!unit)
1734 SendSysMessage(LANG_NO_CHAR_SELECTED);
1735 SetSentErrorMessage(true);
1736 return false;
1739 // check online security
1740 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1741 return false;
1743 char* pField = strtok((char*)args, " ");
1744 if (!pField)
1745 return false;
1747 char* pBit = strtok(NULL, " ");
1748 if (!pBit)
1749 return false;
1751 uint16 field = atoi(pField);
1752 uint32 bit = atoi(pBit);
1754 if (field < OBJECT_END || field >= unit->GetValuesCount())
1756 SendSysMessage(LANG_BAD_VALUE);
1757 SetSentErrorMessage(true);
1758 return false;
1760 if (bit < 1 || bit > 32)
1762 SendSysMessage(LANG_BAD_VALUE);
1763 SetSentErrorMessage(true);
1764 return false;
1767 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1769 unit->RemoveFlag( field, (1<<(bit-1)) );
1770 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1772 else
1774 unit->SetFlag( field, (1<<(bit-1)) );
1775 PSendSysMessage(LANG_SET_BIT, bit, field);
1777 return true;
1780 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1782 if (!*args)
1783 return false;
1785 Player *target = getSelectedPlayer();
1786 if(!target)
1788 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1789 SetSentErrorMessage(true);
1790 return false;
1793 // check online security
1794 if (HasLowerSecurity(target, 0))
1795 return false;
1797 int32 amount = (uint32)atoi(args);
1799 target->ModifyHonorPoints(amount);
1801 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1803 return true;
1806 bool ChatHandler::HandleTeleCommand(const char * args)
1808 if(!*args)
1809 return false;
1811 Player* _player = m_session->GetPlayer();
1813 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1814 GameTele const* tele = extractGameTeleFromLink((char*)args);
1816 if (!tele)
1818 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1819 SetSentErrorMessage(true);
1820 return false;
1823 // stop flight if need
1824 if(_player->isInFlight())
1826 _player->GetMotionMaster()->MovementExpired();
1827 _player->m_taxi.ClearTaxiDestinations();
1829 // save only in non-flight case
1830 else
1831 _player->SaveRecallPosition();
1833 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1834 return true;
1837 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1839 if (!*args)
1840 return false;
1842 std::string namepart = args;
1843 std::wstring wnamepart;
1845 if (!Utf8toWStr (namepart,wnamepart))
1846 return false;
1848 uint32 counter = 0; // Counter for figure out that we found smth.
1850 // converting string that we try to find to lower case
1851 wstrToLower (wnamepart);
1853 // Search in AreaTable.dbc
1854 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1856 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1857 if (areaEntry)
1859 int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1860 std::string name = areaEntry->area_name[loc];
1861 if (name.empty())
1862 continue;
1864 if (!Utf8FitTo (name, wnamepart))
1866 loc = 0;
1867 for(; loc < MAX_LOCALE; ++loc)
1869 if (m_session && loc==m_session->GetSessionDbcLocale ())
1870 continue;
1872 name = areaEntry->area_name[loc];
1873 if (name.empty ())
1874 continue;
1876 if (Utf8FitTo (name, wnamepart))
1877 break;
1881 if (loc < MAX_LOCALE)
1883 // send area in "id - [name]" format
1884 std::ostringstream ss;
1885 if (m_session)
1886 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1887 else
1888 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1890 SendSysMessage (ss.str ().c_str());
1892 ++counter;
1897 if (counter == 0) // if counter == 0 then we found nth
1898 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1900 return true;
1903 //Find tele in game_tele order by name
1904 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1906 if(!*args)
1908 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1909 SetSentErrorMessage(true);
1910 return false;
1913 char const* str = strtok((char*)args, " ");
1914 if(!str)
1915 return false;
1917 std::string namepart = str;
1918 std::wstring wnamepart;
1920 if(!Utf8toWStr(namepart,wnamepart))
1921 return false;
1923 // converting string that we try to find to lower case
1924 wstrToLower( wnamepart );
1926 std::ostringstream reply;
1928 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1929 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1931 GameTele const* tele = &itr->second;
1933 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1934 continue;
1936 if (m_session)
1937 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1938 else
1939 reply << " " << itr->first << " " << tele->name << "\n";
1942 if(reply.str().empty())
1943 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1944 else
1945 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1947 return true;
1950 //Enable\Dissable accept whispers (for GM)
1951 bool ChatHandler::HandleWhispersCommand(const char* args)
1953 if(!*args)
1955 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1956 return true;
1959 std::string argstr = (char*)args;
1960 // whisper on
1961 if (argstr == "on")
1963 m_session->GetPlayer()->SetAcceptWhispers(true);
1964 SendSysMessage(LANG_COMMAND_WHISPERON);
1965 return true;
1968 // whisper off
1969 if (argstr == "off")
1971 m_session->GetPlayer()->SetAcceptWhispers(false);
1972 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1973 return true;
1976 SendSysMessage(LANG_USE_BOL);
1977 SetSentErrorMessage(true);
1978 return false;
1981 //Save all players in the world
1982 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1984 ObjectAccessor::Instance().SaveAllPlayers();
1985 SendSysMessage(LANG_PLAYERS_SAVED);
1986 return true;
1989 //Send mail by command
1990 bool ChatHandler::HandleSendMailCommand(const char* args)
1992 if(!*args)
1993 return false;
1995 // format: name "subject text" "mail text"
1997 std::string name = extractPlayerNameFromLink((char*)args);
1998 if(name.empty())
2000 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2001 SetSentErrorMessage(true);
2002 return false;
2005 char* tail1 = strtok(NULL, "");
2006 if(!tail1)
2007 return false;
2009 char* msgSubject;
2010 if(*tail1=='"')
2011 msgSubject = strtok(tail1+1, "\"");
2012 else
2014 char* space = strtok(tail1, "\"");
2015 if(!space)
2016 return false;
2017 msgSubject = strtok(NULL, "\"");
2020 if (!msgSubject)
2021 return false;
2023 char* tail2 = strtok(NULL, "");
2024 if(!tail2)
2025 return false;
2027 char* msgText;
2028 if(*tail2=='"')
2029 msgText = strtok(tail2+1, "\"");
2030 else
2032 char* space = strtok(tail2, "\"");
2033 if(!space)
2034 return false;
2035 msgText = strtok(NULL, "\"");
2038 if (!msgText)
2039 return false;
2041 // msgSubject, msgText isn't NUL after prev. check
2042 std::string subject = msgSubject;
2043 std::string text = msgText;
2045 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
2046 if(!receiver_guid)
2048 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2049 SetSentErrorMessage(true);
2050 return false;
2053 // from console show not existed sender
2054 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
2056 uint32 messagetype = MAIL_NORMAL;
2057 uint32 stationery = MAIL_STATIONERY_GM;
2058 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
2060 Player *receiver = objmgr.GetPlayer(receiver_guid);
2062 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
2064 std::string nameLink = playerLink(name);
2065 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
2066 return true;
2069 // teleport player to given game_tele.entry
2070 bool ChatHandler::HandleTeleNameCommand(const char * args)
2072 if(!*args)
2073 return false;
2075 std::string name = extractPlayerNameFromLink((char*)args);
2076 if(name.empty())
2078 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2079 SetSentErrorMessage(true);
2080 return false;
2083 char* tail = strtok(NULL, "");
2084 if(!tail)
2085 return false;
2087 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2088 GameTele const* tele = extractGameTeleFromLink(tail);
2089 if(!tele)
2091 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2092 SetSentErrorMessage(true);
2093 return false;
2096 Player *chr = objmgr.GetPlayer(name.c_str());
2097 if (chr)
2099 // check online security
2100 if (HasLowerSecurity(chr, 0))
2101 return false;
2103 std::string chrNameLink = playerLink(name);
2105 if(chr->IsBeingTeleported()==true)
2107 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2108 SetSentErrorMessage(true);
2109 return false;
2112 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2113 if (needReportToTarget(chr))
2114 ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2116 // stop flight if need
2117 if(chr->isInFlight())
2119 chr->GetMotionMaster()->MovementExpired();
2120 chr->m_taxi.ClearTaxiDestinations();
2122 // save only in non-flight case
2123 else
2124 chr->SaveRecallPosition();
2126 chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2128 else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
2130 // check offline security
2131 if (HasLowerSecurity(NULL, guid))
2132 return false;
2134 std::string nameLink = playerLink(name);
2136 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2137 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2138 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),guid);
2140 else
2141 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2143 return true;
2146 //Teleport group to given game_tele.entry
2147 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2149 if(!*args)
2150 return false;
2152 Player *player = getSelectedPlayer();
2153 if (!player)
2155 SendSysMessage(LANG_NO_CHAR_SELECTED);
2156 SetSentErrorMessage(true);
2157 return false;
2160 // check online security
2161 if (HasLowerSecurity(player, 0))
2162 return false;
2164 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2165 GameTele const* tele = extractGameTeleFromLink((char*)args);
2166 if(!tele)
2168 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2169 SetSentErrorMessage(true);
2170 return false;
2173 std::string nameLink = GetNameLink(player);
2175 Group *grp = player->GetGroup();
2176 if(!grp)
2178 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2179 SetSentErrorMessage(true);
2180 return false;
2183 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2185 Player *pl = itr->getSource();
2187 if(!pl || !pl->GetSession() )
2188 continue;
2190 // check online security
2191 if (HasLowerSecurity(pl, 0))
2192 return false;
2194 std::string plNameLink = GetNameLink(pl);
2196 if(pl->IsBeingTeleported())
2198 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2199 continue;
2202 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2203 if (needReportToTarget(pl))
2204 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2206 // stop flight if need
2207 if(pl->isInFlight())
2209 pl->GetMotionMaster()->MovementExpired();
2210 pl->m_taxi.ClearTaxiDestinations();
2212 // save only in non-flight case
2213 else
2214 pl->SaveRecallPosition();
2216 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2219 return true;
2222 //Summon group of player
2223 bool ChatHandler::HandleGroupgoCommand(const char* args)
2225 if(!*args)
2226 return false;
2228 std::string name = extractPlayerNameFromLink((char*)args);
2229 if(name.empty())
2231 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2232 SetSentErrorMessage(true);
2233 return false;
2236 Player *player = objmgr.GetPlayer(name.c_str());
2237 if (!player)
2239 PSendSysMessage(LANG_NO_PLAYER, args);
2240 SetSentErrorMessage(true);
2241 return false;
2244 // check online security
2245 if (HasLowerSecurity(player, 0))
2246 return false;
2248 Group *grp = player->GetGroup();
2250 std::string nameLink = playerLink(name);
2252 if(!grp)
2254 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2255 SetSentErrorMessage(true);
2256 return false;
2259 Map* gmMap = m_session->GetPlayer()->GetMap();
2260 bool to_instance = gmMap->Instanceable();
2262 // we are in instance, and can summon only player in our group with us as lead
2263 if ( to_instance && (
2264 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2265 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2266 // the last check is a bit excessive, but let it be, just in case
2268 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2269 SetSentErrorMessage(true);
2270 return false;
2273 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2275 Player *pl = itr->getSource();
2277 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2278 continue;
2280 // check online security
2281 if (HasLowerSecurity(pl, 0))
2282 return false;
2284 std::string plNameLink = playerLink(name);
2286 if(pl->IsBeingTeleported()==true)
2288 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2289 SetSentErrorMessage(true);
2290 return false;
2293 if (to_instance)
2295 Map* plMap = pl->GetMap();
2297 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2299 // cannot summon from instance to instance
2300 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2301 SetSentErrorMessage(true);
2302 return false;
2306 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2307 if (needReportToTarget(pl))
2308 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2310 // stop flight if need
2311 if(pl->isInFlight())
2313 pl->GetMotionMaster()->MovementExpired();
2314 pl->m_taxi.ClearTaxiDestinations();
2316 // save only in non-flight case
2317 else
2318 pl->SaveRecallPosition();
2320 // before GM
2321 float x,y,z;
2322 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2323 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2326 return true;
2329 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2331 Player* _player = m_session->GetPlayer();
2333 if (!*args)
2334 return false;
2336 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2337 if (!cNodeId)
2338 return false;
2340 int32 i_nodeId = atoi(cNodeId);
2341 if (!i_nodeId)
2342 return false;
2344 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2345 if (!node)
2347 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2348 SetSentErrorMessage(true);
2349 return false;
2352 if (node->x == 0.0f && node->y == 0.0f && node->z == 0.0f ||
2353 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2355 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2356 SetSentErrorMessage(true);
2357 return false;
2360 // stop flight if need
2361 if (_player->isInFlight())
2363 _player->GetMotionMaster()->MovementExpired();
2364 _player->m_taxi.ClearTaxiDestinations();
2366 // save only in non-flight case
2367 else
2368 _player->SaveRecallPosition();
2370 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2371 return true;
2374 //teleport at coordinates
2375 bool ChatHandler::HandleGoXYCommand(const char* args)
2377 if(!*args)
2378 return false;
2380 Player* _player = m_session->GetPlayer();
2382 char* px = strtok((char*)args, " ");
2383 char* py = strtok(NULL, " ");
2384 char* pmapid = strtok(NULL, " ");
2386 if (!px || !py)
2387 return false;
2389 float x = (float)atof(px);
2390 float y = (float)atof(py);
2391 uint32 mapid;
2392 if (pmapid)
2393 mapid = (uint32)atoi(pmapid);
2394 else mapid = _player->GetMapId();
2396 if(!MapManager::IsValidMapCoord(mapid,x,y))
2398 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2399 SetSentErrorMessage(true);
2400 return false;
2403 // stop flight if need
2404 if(_player->isInFlight())
2406 _player->GetMotionMaster()->MovementExpired();
2407 _player->m_taxi.ClearTaxiDestinations();
2409 // save only in non-flight case
2410 else
2411 _player->SaveRecallPosition();
2413 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2414 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2416 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2418 return true;
2421 //teleport at coordinates, including Z
2422 bool ChatHandler::HandleGoXYZCommand(const char* args)
2424 if(!*args)
2425 return false;
2427 Player* _player = m_session->GetPlayer();
2429 char* px = strtok((char*)args, " ");
2430 char* py = strtok(NULL, " ");
2431 char* pz = strtok(NULL, " ");
2432 char* pmapid = strtok(NULL, " ");
2434 if (!px || !py || !pz)
2435 return false;
2437 float x = (float)atof(px);
2438 float y = (float)atof(py);
2439 float z = (float)atof(pz);
2440 uint32 mapid;
2441 if (pmapid)
2442 mapid = (uint32)atoi(pmapid);
2443 else
2444 mapid = _player->GetMapId();
2446 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2448 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2449 SetSentErrorMessage(true);
2450 return false;
2453 // stop flight if need
2454 if(_player->isInFlight())
2456 _player->GetMotionMaster()->MovementExpired();
2457 _player->m_taxi.ClearTaxiDestinations();
2459 // save only in non-flight case
2460 else
2461 _player->SaveRecallPosition();
2463 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2465 return true;
2468 //teleport at coordinates
2469 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2471 if(!*args)
2472 return false;
2474 Player* _player = m_session->GetPlayer();
2476 char* px = strtok((char*)args, " ");
2477 char* py = strtok(NULL, " ");
2478 char* tail = strtok(NULL,"");
2480 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2482 if (!px || !py)
2483 return false;
2485 float x = (float)atof(px);
2486 float y = (float)atof(py);
2488 // prevent accept wrong numeric args
2489 if (x==0.0f && *px!='0' || y==0.0f && *py!='0')
2490 return false;
2492 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2494 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2496 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2498 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2499 SetSentErrorMessage(true);
2500 return false;
2503 // update to parent zone if exist (client map show only zones without parents)
2504 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2506 Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2508 if(map->Instanceable())
2510 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2511 SetSentErrorMessage(true);
2512 return false;
2515 Zone2MapCoordinates(x,y,zoneEntry->ID);
2517 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2519 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2520 SetSentErrorMessage(true);
2521 return false;
2524 // stop flight if need
2525 if(_player->isInFlight())
2527 _player->GetMotionMaster()->MovementExpired();
2528 _player->m_taxi.ClearTaxiDestinations();
2530 // save only in non-flight case
2531 else
2532 _player->SaveRecallPosition();
2534 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2535 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2537 return true;
2540 //teleport to grid
2541 bool ChatHandler::HandleGoGridCommand(const char* args)
2543 if(!*args) return false;
2544 Player* _player = m_session->GetPlayer();
2546 char* px = strtok((char*)args, " ");
2547 char* py = strtok(NULL, " ");
2548 char* pmapid = strtok(NULL, " ");
2550 if (!px || !py)
2551 return false;
2553 float grid_x = (float)atof(px);
2554 float grid_y = (float)atof(py);
2555 uint32 mapid;
2556 if (pmapid)
2557 mapid = (uint32)atoi(pmapid);
2558 else mapid = _player->GetMapId();
2560 // center of grid
2561 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2562 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2564 if(!MapManager::IsValidMapCoord(mapid,x,y))
2566 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2567 SetSentErrorMessage(true);
2568 return false;
2571 // stop flight if need
2572 if(_player->isInFlight())
2574 _player->GetMotionMaster()->MovementExpired();
2575 _player->m_taxi.ClearTaxiDestinations();
2577 // save only in non-flight case
2578 else
2579 _player->SaveRecallPosition();
2581 Map const *map = MapManager::Instance().GetBaseMap(mapid);
2582 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2583 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2585 return true;
2588 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2590 if(!*args) return false;
2592 uint32 drunklevel = (uint32)atoi(args);
2593 if(drunklevel > 100)
2594 drunklevel = 100;
2596 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2598 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2600 return true;