[9362] Make specs work at least for action bars
[getmangos.git] / src / game / Level1.cpp
blob29516d54f0b1986c6421eabb7394734658ddd391
1 /*
2 * Copyright (C) 2005-2010 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(sObjectMgr.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[GetSessionDbcLocale()] : "<unknown>" ),
313 zone_id, (zoneEntry ? zoneEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
314 area_id, (areaEntry ? areaEntry->area_name[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 Player* target;
347 uint64 target_guid;
348 std::string target_name;
349 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
350 return false;
352 Player* _player = m_session->GetPlayer();
353 if (target == _player || target_guid == _player->GetGUID())
355 PSendSysMessage(LANG_CANT_TELEPORT_SELF);
356 SetSentErrorMessage(true);
357 return false;
360 if (target)
362 std::string nameLink = playerLink(target_name);
363 // check online security
364 if (HasLowerSecurity(target, 0))
365 return false;
367 if (target->IsBeingTeleported())
369 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
370 SetSentErrorMessage(true);
371 return false;
374 Map* pMap = m_session->GetPlayer()->GetMap();
376 if (pMap->IsBattleGroundOrArena())
378 // only allow if gm mode is on
379 if (!target->isGameMaster())
381 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,nameLink.c_str());
382 SetSentErrorMessage(true);
383 return false;
385 // if both players are in different bgs
386 else if (target->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != target->GetBattleGroundId())
388 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,nameLink.c_str());
389 SetSentErrorMessage(true);
390 return false;
392 // all's well, set bg id
393 // when porting out from the bg, it will be reset to 0
394 target->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
395 // remember current position as entry point for return at bg end teleportation
396 if (!target->GetMap()->IsBattleGroundOrArena())
397 target->SetBattleGroundEntryPoint();
399 else if (pMap->IsDungeon())
401 Map* cMap = target->GetMap();
402 if (cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId())
404 // cannot summon from instance to instance
405 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
406 SetSentErrorMessage(true);
407 return false;
410 // we are in instance, and can summon only player in our group with us as lead
411 if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
412 (target->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
413 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()))
414 // the last check is a bit excessive, but let it be, just in case
416 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
417 SetSentErrorMessage(true);
418 return false;
422 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
423 if (needReportToTarget(target))
424 ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, playerLink(_player->GetName()).c_str());
426 // stop flight if need
427 if (target->isInFlight())
429 target->GetMotionMaster()->MovementExpired();
430 target->m_taxi.ClearTaxiDestinations();
432 // save only in non-flight case
433 else
434 target->SaveRecallPosition();
436 // before GM
437 float x,y,z;
438 m_session->GetPlayer()->GetClosePoint(x,y,z,target->GetObjectSize());
439 target->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,target->GetOrientation());
441 else
443 // check offline security
444 if (HasLowerSecurity(NULL, target_guid))
445 return false;
447 std::string nameLink = playerLink(target_name);
449 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
451 // in point where GM stay
452 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
453 m_session->GetPlayer()->GetPositionX(),
454 m_session->GetPlayer()->GetPositionY(),
455 m_session->GetPlayer()->GetPositionZ(),
456 m_session->GetPlayer()->GetOrientation(),
457 m_session->GetPlayer()->GetZoneId(),
458 target_guid);
461 return true;
464 //Teleport to Player
465 bool ChatHandler::HandleGonameCommand(const char* args)
467 Player* target;
468 uint64 target_guid;
469 std::string target_name;
470 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
471 return false;
473 Player* _player = m_session->GetPlayer();
474 if (target == _player || target_guid == _player->GetGUID())
476 SendSysMessage(LANG_CANT_TELEPORT_SELF);
477 SetSentErrorMessage(true);
478 return false;
482 if (target)
484 // check online security
485 if (HasLowerSecurity(target, 0))
486 return false;
488 std::string chrNameLink = playerLink(target_name);
490 Map* cMap = target->GetMap();
491 if (cMap->IsBattleGroundOrArena())
493 // only allow if gm mode is on
494 if (!_player->isGameMaster())
496 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
497 SetSentErrorMessage(true);
498 return false;
500 // if both players are in different bgs
501 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
503 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
504 SetSentErrorMessage(true);
505 return false;
507 // all's well, set bg id
508 // when porting out from the bg, it will be reset to 0
509 _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
510 // remember current position as entry point for return at bg end teleportation
511 if (!_player->GetMap()->IsBattleGroundOrArena())
512 _player->SetBattleGroundEntryPoint();
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() != target->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(target->GetMapId(), target->GetDifficulty(cMap->IsRaid()));
543 if (!pBind)
545 Group *group = _player->GetGroup();
546 // if no bind exists, create a solo bind
547 InstanceGroupBind *gBind = group ? group->GetBoundInstance(target) : NULL;
548 // if no bind exists, create a solo bind
549 if (!gBind)
550 if (InstanceSave *save = sInstanceSaveMgr.GetInstanceSave(target->GetInstanceId()))
551 _player->BindToInstance(save, !save->CanReset());
554 if(cMap->IsRaid())
555 _player->SetRaidDifficulty(target->GetRaidDifficulty());
556 else
557 _player->SetDungeonDifficulty(target->GetDungeonDifficulty());
560 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
561 if (needReportToTarget(target))
562 ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
564 // stop flight if need
565 if (_player->isInFlight())
567 _player->GetMotionMaster()->MovementExpired();
568 _player->m_taxi.ClearTaxiDestinations();
570 // save only in non-flight case
571 else
572 _player->SaveRecallPosition();
574 // to point to see at target with same orientation
575 float x,y,z;
576 target->GetContactPoint(_player,x,y,z);
578 _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
580 else
582 // check offline security
583 if (HasLowerSecurity(NULL, target_guid))
584 return false;
586 std::string nameLink = playerLink(target_name);
588 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
590 // to point where player stay (if loaded)
591 float x,y,z,o;
592 uint32 map;
593 bool in_flight;
594 if (!Player::LoadPositionFromDB(map,x,y,z,o,in_flight,target_guid))
595 return false;
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());
610 return true;
613 // Teleport player to last position
614 bool ChatHandler::HandleRecallCommand(const char* args)
616 Player* target;
617 if(!extractPlayerTarget((char*)args,&target))
618 return false;
620 // check online security
621 if (HasLowerSecurity(target, 0))
622 return false;
624 if (target->IsBeingTeleported())
626 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
627 SetSentErrorMessage(true);
628 return false;
631 // stop flight if need
632 if(target->isInFlight())
634 target->GetMotionMaster()->MovementExpired();
635 target->m_taxi.ClearTaxiDestinations();
638 target->TeleportTo(target->m_recallMap, target->m_recallX, target->m_recallY, target->m_recallZ, target->m_recallO);
639 return true;
642 //Edit Player HP
643 bool ChatHandler::HandleModifyHPCommand(const char* args)
645 if(!*args)
646 return false;
648 // char* pHp = strtok((char*)args, " ");
649 // if (!pHp)
650 // return false;
652 // char* pHpMax = strtok(NULL, " ");
653 // if (!pHpMax)
654 // return false;
656 // int32 hpm = atoi(pHpMax);
657 // int32 hp = atoi(pHp);
659 int32 hp = atoi((char*)args);
660 int32 hpm = atoi((char*)args);
662 if (hp <= 0 || hpm <= 0 || hpm < hp)
664 SendSysMessage(LANG_BAD_VALUE);
665 SetSentErrorMessage(true);
666 return false;
669 Player *chr = getSelectedPlayer();
670 if (chr == NULL)
672 SendSysMessage(LANG_NO_CHAR_SELECTED);
673 SetSentErrorMessage(true);
674 return false;
677 // check online security
678 if (HasLowerSecurity(chr, 0))
679 return false;
681 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
682 if (needReportToTarget(chr))
683 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
685 chr->SetMaxHealth( hpm );
686 chr->SetHealth( hp );
688 return true;
691 //Edit Player Mana
692 bool ChatHandler::HandleModifyManaCommand(const char* args)
694 if(!*args)
695 return false;
697 // char* pmana = strtok((char*)args, " ");
698 // if (!pmana)
699 // return false;
701 // char* pmanaMax = strtok(NULL, " ");
702 // if (!pmanaMax)
703 // return false;
705 // int32 manam = atoi(pmanaMax);
706 // int32 mana = atoi(pmana);
707 int32 mana = atoi((char*)args);
708 int32 manam = atoi((char*)args);
710 if (mana <= 0 || manam <= 0 || manam < mana)
712 SendSysMessage(LANG_BAD_VALUE);
713 SetSentErrorMessage(true);
714 return false;
717 Player *chr = getSelectedPlayer();
718 if (chr == NULL)
720 SendSysMessage(LANG_NO_CHAR_SELECTED);
721 SetSentErrorMessage(true);
722 return false;
725 // check online security
726 if (HasLowerSecurity(chr, 0))
727 return false;
729 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
730 if (needReportToTarget(chr))
731 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
733 chr->SetMaxPower(POWER_MANA,manam );
734 chr->SetPower(POWER_MANA, mana );
736 return true;
739 //Edit Player Energy
740 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
742 if(!*args)
743 return false;
745 // char* pmana = strtok((char*)args, " ");
746 // if (!pmana)
747 // return false;
749 // char* pmanaMax = strtok(NULL, " ");
750 // if (!pmanaMax)
751 // return false;
753 // int32 manam = atoi(pmanaMax);
754 // int32 mana = atoi(pmana);
756 int32 energy = atoi((char*)args)*10;
757 int32 energym = atoi((char*)args)*10;
759 if (energy <= 0 || energym <= 0 || energym < energy)
761 SendSysMessage(LANG_BAD_VALUE);
762 SetSentErrorMessage(true);
763 return false;
766 Player *chr = getSelectedPlayer();
767 if (!chr)
769 SendSysMessage(LANG_NO_CHAR_SELECTED);
770 SetSentErrorMessage(true);
771 return false;
774 // check online security
775 if (HasLowerSecurity(chr, 0))
776 return false;
778 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
779 if (needReportToTarget(chr))
780 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
782 chr->SetMaxPower(POWER_ENERGY,energym );
783 chr->SetPower(POWER_ENERGY, energy );
785 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
787 return true;
790 //Edit Player Rage
791 bool ChatHandler::HandleModifyRageCommand(const char* args)
793 if(!*args)
794 return false;
796 // char* pmana = strtok((char*)args, " ");
797 // if (!pmana)
798 // return false;
800 // char* pmanaMax = strtok(NULL, " ");
801 // if (!pmanaMax)
802 // return false;
804 // int32 manam = atoi(pmanaMax);
805 // int32 mana = atoi(pmana);
807 int32 rage = atoi((char*)args)*10;
808 int32 ragem = atoi((char*)args)*10;
810 if (rage <= 0 || ragem <= 0 || ragem < rage)
812 SendSysMessage(LANG_BAD_VALUE);
813 SetSentErrorMessage(true);
814 return false;
817 Player *chr = getSelectedPlayer();
818 if (chr == NULL)
820 SendSysMessage(LANG_NO_CHAR_SELECTED);
821 SetSentErrorMessage(true);
822 return false;
825 // check online security
826 if (HasLowerSecurity(chr, 0))
827 return false;
829 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
830 if (needReportToTarget(chr))
831 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
833 chr->SetMaxPower(POWER_RAGE,ragem );
834 chr->SetPower(POWER_RAGE, rage );
836 return true;
839 // Edit Player Runic Power
840 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
842 if(!*args)
843 return false;
845 int32 rune = atoi((char*)args)*10;
846 int32 runem = atoi((char*)args)*10;
848 if (rune <= 0 || runem <= 0 || runem < rune)
850 SendSysMessage(LANG_BAD_VALUE);
851 SetSentErrorMessage(true);
852 return false;
855 Player *chr = getSelectedPlayer();
856 if (chr == NULL)
858 SendSysMessage(LANG_NO_CHAR_SELECTED);
859 SetSentErrorMessage(true);
860 return false;
863 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
864 if (needReportToTarget(chr))
865 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
867 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
868 chr->SetPower(POWER_RUNIC_POWER, rune );
870 return true;
873 //Edit Player Faction
874 bool ChatHandler::HandleModifyFactionCommand(const char* args)
876 if(!*args)
877 return false;
879 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
881 Creature* chr = getSelectedCreature();
882 if(!chr)
884 SendSysMessage(LANG_SELECT_CREATURE);
885 SetSentErrorMessage(true);
886 return false;
889 if(!pfactionid)
891 if(chr)
893 uint32 factionid = chr->getFaction();
894 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
895 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
896 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
897 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
899 return true;
902 if( !chr )
904 SendSysMessage(LANG_NO_CHAR_SELECTED);
905 SetSentErrorMessage(true);
906 return false;
909 uint32 factionid = atoi(pfactionid);
910 uint32 flag;
912 char *pflag = strtok(NULL, " ");
913 if (!pflag)
914 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
915 else
916 flag = atoi(pflag);
918 char* pnpcflag = strtok(NULL, " ");
920 uint32 npcflag;
921 if(!pnpcflag)
922 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
923 else
924 npcflag = atoi(pnpcflag);
926 char* pdyflag = strtok(NULL, " ");
928 uint32 dyflag;
929 if(!pdyflag)
930 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
931 else
932 dyflag = atoi(pdyflag);
934 if(!sFactionTemplateStore.LookupEntry(factionid))
936 PSendSysMessage(LANG_WRONG_FACTION, factionid);
937 SetSentErrorMessage(true);
938 return false;
941 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
943 chr->setFaction(factionid);
944 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
945 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
946 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
948 return true;
951 //Edit Player Spell
952 bool ChatHandler::HandleModifySpellCommand(const char* args)
954 if(!*args) return false;
955 char* pspellflatid = strtok((char*)args, " ");
956 if (!pspellflatid)
957 return false;
959 char* pop = strtok(NULL, " ");
960 if (!pop)
961 return false;
963 char* pval = strtok(NULL, " ");
964 if (!pval)
965 return false;
967 uint16 mark;
969 char* pmark = strtok(NULL, " ");
971 uint8 spellflatid = atoi(pspellflatid);
972 uint8 op = atoi(pop);
973 uint16 val = atoi(pval);
974 if(!pmark)
975 mark = 65535;
976 else
977 mark = atoi(pmark);
979 Player *chr = getSelectedPlayer();
980 if (chr == NULL)
982 SendSysMessage(LANG_NO_CHAR_SELECTED);
983 SetSentErrorMessage(true);
984 return false;
987 // check online security
988 if (HasLowerSecurity(chr, 0))
989 return false;
991 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
992 if (needReportToTarget(chr))
993 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
995 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
996 data << uint8(spellflatid);
997 data << uint8(op);
998 data << uint16(val);
999 data << uint16(mark);
1000 chr->GetSession()->SendPacket(&data);
1002 return true;
1005 //Edit Player TP
1006 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1008 if (!*args)
1009 return false;
1011 int tp = atoi((char*)args);
1012 if (tp < 0)
1013 return false;
1015 Unit* target = getSelectedUnit();
1016 if(!target)
1018 SendSysMessage(LANG_NO_CHAR_SELECTED);
1019 SetSentErrorMessage(true);
1020 return false;
1023 if(target->GetTypeId()==TYPEID_PLAYER)
1025 // check online security
1026 if (HasLowerSecurity((Player*)target, 0))
1027 return false;
1029 ((Player*)target)->SetFreeTalentPoints(tp);
1030 ((Player*)target)->SendTalentsInfoData(false);
1031 return true;
1033 else if(((Creature*)target)->isPet())
1035 Unit *owner = target->GetOwner();
1036 if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor((Player*)owner))
1038 // check online security
1039 if (HasLowerSecurity((Player*)owner, 0))
1040 return false;
1042 ((Pet *)target)->SetFreeTalentPoints(tp);
1043 ((Player*)owner)->SendTalentsInfoData(true);
1044 return true;
1048 SendSysMessage(LANG_NO_CHAR_SELECTED);
1049 SetSentErrorMessage(true);
1050 return false;
1053 //Enable On\OFF all taxi paths
1054 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1056 if (!*args)
1058 SendSysMessage(LANG_USE_BOL);
1059 SetSentErrorMessage(true);
1060 return false;
1063 std::string argstr = (char*)args;
1065 Player *chr = getSelectedPlayer();
1066 if (!chr)
1068 chr=m_session->GetPlayer();
1071 // check online security
1072 else if (HasLowerSecurity(chr, 0))
1073 return false;
1075 if (argstr == "on")
1077 chr->SetTaxiCheater(true);
1078 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1079 if (needReportToTarget(chr))
1080 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1081 return true;
1084 if (argstr == "off")
1086 chr->SetTaxiCheater(false);
1087 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1088 if (needReportToTarget(chr))
1089 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1091 return true;
1094 SendSysMessage(LANG_USE_BOL);
1095 SetSentErrorMessage(true);
1096 return false;
1099 //Edit Player Aspeed
1100 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1102 if (!*args)
1103 return false;
1105 float ASpeed = (float)atof((char*)args);
1107 if (ASpeed > 10 || ASpeed < 0.1)
1109 SendSysMessage(LANG_BAD_VALUE);
1110 SetSentErrorMessage(true);
1111 return false;
1114 Player *chr = getSelectedPlayer();
1115 if (chr == NULL)
1117 SendSysMessage(LANG_NO_CHAR_SELECTED);
1118 SetSentErrorMessage(true);
1119 return false;
1122 // check online security
1123 if (HasLowerSecurity(chr, 0))
1124 return false;
1126 std::string chrNameLink = GetNameLink(chr);
1128 if(chr->isInFlight())
1130 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1131 SetSentErrorMessage(true);
1132 return false;
1135 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1136 if (needReportToTarget(chr))
1137 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1139 chr->SetSpeedRate(MOVE_WALK, ASpeed,true);
1140 chr->SetSpeedRate(MOVE_RUN, ASpeed,true);
1141 chr->SetSpeedRate(MOVE_SWIM, ASpeed,true);
1142 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1143 chr->SetSpeedRate(MOVE_FLIGHT, ASpeed,true);
1144 return true;
1147 //Edit Player Speed
1148 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1150 if (!*args)
1151 return false;
1153 float Speed = (float)atof((char*)args);
1155 if (Speed > 10 || Speed < 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_SPEED, Speed, chrNameLink.c_str());
1184 if (needReportToTarget(chr))
1185 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1187 chr->SetSpeedRate(MOVE_RUN,Speed,true);
1189 return true;
1192 //Edit Player Swim Speed
1193 bool ChatHandler::HandleModifySwimCommand(const char* args)
1195 if (!*args)
1196 return false;
1198 float Swim = (float)atof((char*)args);
1200 if (Swim > 10.0f || Swim < 0.01f)
1202 SendSysMessage(LANG_BAD_VALUE);
1203 SetSentErrorMessage(true);
1204 return false;
1207 Player *chr = getSelectedPlayer();
1208 if (chr == NULL)
1210 SendSysMessage(LANG_NO_CHAR_SELECTED);
1211 SetSentErrorMessage(true);
1212 return false;
1215 // check online security
1216 if (HasLowerSecurity(chr, 0))
1217 return false;
1219 std::string chrNameLink = GetNameLink(chr);
1221 if(chr->isInFlight())
1223 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1224 SetSentErrorMessage(true);
1225 return false;
1228 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1229 if (needReportToTarget(chr))
1230 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1232 chr->SetSpeedRate(MOVE_SWIM,Swim,true);
1234 return true;
1237 //Edit Player Walk Speed
1238 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1240 if (!*args)
1241 return false;
1243 float BSpeed = (float)atof((char*)args);
1245 if (BSpeed > 10.0f || BSpeed < 0.1f)
1247 SendSysMessage(LANG_BAD_VALUE);
1248 SetSentErrorMessage(true);
1249 return false;
1252 Player *chr = getSelectedPlayer();
1253 if (chr == NULL)
1255 SendSysMessage(LANG_NO_CHAR_SELECTED);
1256 SetSentErrorMessage(true);
1257 return false;
1260 // check online security
1261 if (HasLowerSecurity(chr, 0))
1262 return false;
1264 std::string chrNameLink = GetNameLink(chr);
1266 if(chr->isInFlight())
1268 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1269 SetSentErrorMessage(true);
1270 return false;
1273 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1274 if (needReportToTarget(chr))
1275 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1277 chr->SetSpeedRate(MOVE_RUN_BACK,BSpeed,true);
1279 return true;
1282 //Edit Player Fly
1283 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1285 if (!*args)
1286 return false;
1288 float FSpeed = (float)atof((char*)args);
1290 if (FSpeed > 10.0f || FSpeed < 0.1f)
1292 SendSysMessage(LANG_BAD_VALUE);
1293 SetSentErrorMessage(true);
1294 return false;
1297 Player *chr = getSelectedPlayer();
1298 if (chr == NULL)
1300 SendSysMessage(LANG_NO_CHAR_SELECTED);
1301 SetSentErrorMessage(true);
1302 return false;
1305 // check online security
1306 if (HasLowerSecurity(chr, 0))
1307 return false;
1309 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1310 if (needReportToTarget(chr))
1311 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1313 chr->SetSpeedRate(MOVE_FLIGHT,FSpeed,true);
1315 return true;
1318 //Edit Player Scale
1319 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1321 if (!*args)
1322 return false;
1324 float Scale = (float)atof((char*)args);
1325 if (Scale > 10.0f || Scale <= 0.0f)
1327 SendSysMessage(LANG_BAD_VALUE);
1328 SetSentErrorMessage(true);
1329 return false;
1332 Unit *target = getSelectedUnit();
1333 if (target == NULL)
1335 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
1336 SetSentErrorMessage(true);
1337 return false;
1340 if (target->GetTypeId()==TYPEID_PLAYER)
1342 // check online security
1343 if (HasLowerSecurity((Player*)target, 0))
1344 return false;
1346 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink((Player*)target).c_str());
1347 if (needReportToTarget((Player*)target))
1348 ChatHandler((Player*)target).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1351 target->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1353 return true;
1356 //Enable Player mount
1357 bool ChatHandler::HandleModifyMountCommand(const char* args)
1359 if(!*args)
1360 return false;
1362 uint16 mId = 1147;
1363 float speed = (float)15;
1364 uint32 num = 0;
1366 num = atoi((char*)args);
1367 switch(num)
1369 case 1:
1370 mId=14340;
1371 break;
1372 case 2:
1373 mId=4806;
1374 break;
1375 case 3:
1376 mId=6471;
1377 break;
1378 case 4:
1379 mId=12345;
1380 break;
1381 case 5:
1382 mId=6472;
1383 break;
1384 case 6:
1385 mId=6473;
1386 break;
1387 case 7:
1388 mId=10670;
1389 break;
1390 case 8:
1391 mId=10719;
1392 break;
1393 case 9:
1394 mId=10671;
1395 break;
1396 case 10:
1397 mId=10672;
1398 break;
1399 case 11:
1400 mId=10720;
1401 break;
1402 case 12:
1403 mId=14349;
1404 break;
1405 case 13:
1406 mId=11641;
1407 break;
1408 case 14:
1409 mId=12244;
1410 break;
1411 case 15:
1412 mId=12242;
1413 break;
1414 case 16:
1415 mId=14578;
1416 break;
1417 case 17:
1418 mId=14579;
1419 break;
1420 case 18:
1421 mId=14349;
1422 break;
1423 case 19:
1424 mId=12245;
1425 break;
1426 case 20:
1427 mId=14335;
1428 break;
1429 case 21:
1430 mId=207;
1431 break;
1432 case 22:
1433 mId=2328;
1434 break;
1435 case 23:
1436 mId=2327;
1437 break;
1438 case 24:
1439 mId=2326;
1440 break;
1441 case 25:
1442 mId=14573;
1443 break;
1444 case 26:
1445 mId=14574;
1446 break;
1447 case 27:
1448 mId=14575;
1449 break;
1450 case 28:
1451 mId=604;
1452 break;
1453 case 29:
1454 mId=1166;
1455 break;
1456 case 30:
1457 mId=2402;
1458 break;
1459 case 31:
1460 mId=2410;
1461 break;
1462 case 32:
1463 mId=2409;
1464 break;
1465 case 33:
1466 mId=2408;
1467 break;
1468 case 34:
1469 mId=2405;
1470 break;
1471 case 35:
1472 mId=14337;
1473 break;
1474 case 36:
1475 mId=6569;
1476 break;
1477 case 37:
1478 mId=10661;
1479 break;
1480 case 38:
1481 mId=10666;
1482 break;
1483 case 39:
1484 mId=9473;
1485 break;
1486 case 40:
1487 mId=9476;
1488 break;
1489 case 41:
1490 mId=9474;
1491 break;
1492 case 42:
1493 mId=14374;
1494 break;
1495 case 43:
1496 mId=14376;
1497 break;
1498 case 44:
1499 mId=14377;
1500 break;
1501 case 45:
1502 mId=2404;
1503 break;
1504 case 46:
1505 mId=2784;
1506 break;
1507 case 47:
1508 mId=2787;
1509 break;
1510 case 48:
1511 mId=2785;
1512 break;
1513 case 49:
1514 mId=2736;
1515 break;
1516 case 50:
1517 mId=2786;
1518 break;
1519 case 51:
1520 mId=14347;
1521 break;
1522 case 52:
1523 mId=14346;
1524 break;
1525 case 53:
1526 mId=14576;
1527 break;
1528 case 54:
1529 mId=9695;
1530 break;
1531 case 55:
1532 mId=9991;
1533 break;
1534 case 56:
1535 mId=6448;
1536 break;
1537 case 57:
1538 mId=6444;
1539 break;
1540 case 58:
1541 mId=6080;
1542 break;
1543 case 59:
1544 mId=6447;
1545 break;
1546 case 60:
1547 mId=4805;
1548 break;
1549 case 61:
1550 mId=9714;
1551 break;
1552 case 62:
1553 mId=6448;
1554 break;
1555 case 63:
1556 mId=6442;
1557 break;
1558 case 64:
1559 mId=14632;
1560 break;
1561 case 65:
1562 mId=14332;
1563 break;
1564 case 66:
1565 mId=14331;
1566 break;
1567 case 67:
1568 mId=8469;
1569 break;
1570 case 68:
1571 mId=2830;
1572 break;
1573 case 69:
1574 mId=2346;
1575 break;
1576 default:
1577 SendSysMessage(LANG_NO_MOUNT);
1578 SetSentErrorMessage(true);
1579 return false;
1582 Player *chr = getSelectedPlayer();
1583 if (chr == NULL)
1585 SendSysMessage(LANG_NO_CHAR_SELECTED);
1586 SetSentErrorMessage(true);
1587 return false;
1590 // check online security
1591 if (HasLowerSecurity(chr, 0))
1592 return false;
1594 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1595 if (needReportToTarget(chr))
1596 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1598 chr->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP);
1599 chr->Mount(mId);
1601 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1602 data.append(chr->GetPackGUID());
1603 data << (uint32)0;
1604 data << (uint8)0; //new 2.1.0
1605 data << float(speed);
1606 chr->SendMessageToSet( &data, true );
1608 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1609 data.append(chr->GetPackGUID());
1610 data << (uint32)0;
1611 data << float(speed);
1612 chr->SendMessageToSet( &data, true );
1614 return true;
1617 //Edit Player money
1618 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1620 if (!*args)
1621 return false;
1623 Player *chr = getSelectedPlayer();
1624 if (chr == NULL)
1626 SendSysMessage(LANG_NO_CHAR_SELECTED);
1627 SetSentErrorMessage(true);
1628 return false;
1631 // check online security
1632 if (HasLowerSecurity(chr, 0))
1633 return false;
1635 int32 addmoney = atoi((char*)args);
1637 uint32 moneyuser = chr->GetMoney();
1639 if (addmoney < 0)
1641 int32 newmoney = int32(moneyuser) + addmoney;
1643 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1644 if (newmoney <= 0 )
1646 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1647 if (needReportToTarget(chr))
1648 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1650 chr->SetMoney(0);
1652 else
1654 if (newmoney > MAX_MONEY_AMOUNT)
1655 newmoney = MAX_MONEY_AMOUNT;
1657 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1658 if (needReportToTarget(chr))
1659 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1660 chr->SetMoney( newmoney );
1663 else
1665 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1666 if (needReportToTarget(chr))
1667 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1669 if (addmoney >=MAX_MONEY_AMOUNT)
1670 chr->SetMoney(MAX_MONEY_AMOUNT);
1671 else
1672 chr->ModifyMoney( addmoney );
1675 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1677 return true;
1680 //Edit Unit field
1681 bool ChatHandler::HandleModifyBitCommand(const char* args)
1683 if( !*args )
1684 return false;
1686 Unit *unit = getSelectedUnit();
1687 if (!unit)
1689 SendSysMessage(LANG_NO_CHAR_SELECTED);
1690 SetSentErrorMessage(true);
1691 return false;
1694 // check online security
1695 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1696 return false;
1698 char* pField = strtok((char*)args, " ");
1699 if (!pField)
1700 return false;
1702 char* pBit = strtok(NULL, " ");
1703 if (!pBit)
1704 return false;
1706 uint16 field = atoi(pField);
1707 uint32 bit = atoi(pBit);
1709 if (field < OBJECT_END || field >= unit->GetValuesCount())
1711 SendSysMessage(LANG_BAD_VALUE);
1712 SetSentErrorMessage(true);
1713 return false;
1715 if (bit < 1 || bit > 32)
1717 SendSysMessage(LANG_BAD_VALUE);
1718 SetSentErrorMessage(true);
1719 return false;
1722 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1724 unit->RemoveFlag( field, (1<<(bit-1)) );
1725 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1727 else
1729 unit->SetFlag( field, (1<<(bit-1)) );
1730 PSendSysMessage(LANG_SET_BIT, bit, field);
1732 return true;
1735 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1737 if (!*args)
1738 return false;
1740 Player *target = getSelectedPlayer();
1741 if(!target)
1743 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1744 SetSentErrorMessage(true);
1745 return false;
1748 // check online security
1749 if (HasLowerSecurity(target, 0))
1750 return false;
1752 int32 amount = (uint32)atoi(args);
1754 target->ModifyHonorPoints(amount);
1756 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1758 return true;
1761 bool ChatHandler::HandleTeleCommand(const char * args)
1763 if(!*args)
1764 return false;
1766 Player* _player = m_session->GetPlayer();
1768 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1769 GameTele const* tele = extractGameTeleFromLink((char*)args);
1771 if (!tele)
1773 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1774 SetSentErrorMessage(true);
1775 return false;
1778 // stop flight if need
1779 if(_player->isInFlight())
1781 _player->GetMotionMaster()->MovementExpired();
1782 _player->m_taxi.ClearTaxiDestinations();
1784 // save only in non-flight case
1785 else
1786 _player->SaveRecallPosition();
1788 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1789 return true;
1792 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1794 if (!*args)
1795 return false;
1797 std::string namepart = args;
1798 std::wstring wnamepart;
1800 if (!Utf8toWStr (namepart,wnamepart))
1801 return false;
1803 uint32 counter = 0; // Counter for figure out that we found smth.
1805 // converting string that we try to find to lower case
1806 wstrToLower (wnamepart);
1808 // Search in AreaTable.dbc
1809 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1811 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1812 if (areaEntry)
1814 int loc = GetSessionDbcLocale ();
1815 std::string name = areaEntry->area_name[loc];
1816 if (name.empty())
1817 continue;
1819 if (!Utf8FitTo (name, wnamepart))
1821 loc = 0;
1822 for(; loc < MAX_LOCALE; ++loc)
1824 if (loc==GetSessionDbcLocale ())
1825 continue;
1827 name = areaEntry->area_name[loc];
1828 if (name.empty ())
1829 continue;
1831 if (Utf8FitTo (name, wnamepart))
1832 break;
1836 if (loc < MAX_LOCALE)
1838 // send area in "id - [name]" format
1839 std::ostringstream ss;
1840 if (m_session)
1841 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1842 else
1843 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1845 SendSysMessage (ss.str ().c_str());
1847 ++counter;
1852 if (counter == 0) // if counter == 0 then we found nth
1853 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1855 return true;
1858 //Find tele in game_tele order by name
1859 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1861 if(!*args)
1863 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1864 SetSentErrorMessage(true);
1865 return false;
1868 char const* str = strtok((char*)args, " ");
1869 if(!str)
1870 return false;
1872 std::string namepart = str;
1873 std::wstring wnamepart;
1875 if(!Utf8toWStr(namepart,wnamepart))
1876 return false;
1878 // converting string that we try to find to lower case
1879 wstrToLower( wnamepart );
1881 std::ostringstream reply;
1883 GameTeleMap const & teleMap = sObjectMgr.GetGameTeleMap();
1884 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1886 GameTele const* tele = &itr->second;
1888 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1889 continue;
1891 if (m_session)
1892 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1893 else
1894 reply << " " << itr->first << " " << tele->name << "\n";
1897 if(reply.str().empty())
1898 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1899 else
1900 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1902 return true;
1905 //Enable\Dissable accept whispers (for GM)
1906 bool ChatHandler::HandleWhispersCommand(const char* args)
1908 if(!*args)
1910 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1911 return true;
1914 std::string argstr = (char*)args;
1915 // whisper on
1916 if (argstr == "on")
1918 m_session->GetPlayer()->SetAcceptWhispers(true);
1919 SendSysMessage(LANG_COMMAND_WHISPERON);
1920 return true;
1923 // whisper off
1924 if (argstr == "off")
1926 m_session->GetPlayer()->SetAcceptWhispers(false);
1927 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1928 return true;
1931 SendSysMessage(LANG_USE_BOL);
1932 SetSentErrorMessage(true);
1933 return false;
1936 //Save all players in the world
1937 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1939 sObjectAccessor.SaveAllPlayers();
1940 SendSysMessage(LANG_PLAYERS_SAVED);
1941 return true;
1944 //Send mail by command
1945 bool ChatHandler::HandleSendMailCommand(const char* args)
1947 // format: name "subject text" "mail text"
1948 Player* target;
1949 uint64 target_guid;
1950 std::string target_name;
1951 if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
1952 return false;
1954 char* tail1 = strtok(NULL, "");
1955 if(!tail1)
1956 return false;
1958 char* msgSubject = extractQuotedArg(tail1);
1959 if (!msgSubject)
1960 return false;
1962 char* tail2 = strtok(NULL, "");
1963 if(!tail2)
1964 return false;
1966 char* msgText = extractQuotedArg(tail2);
1967 if (!msgText)
1968 return false;
1970 // msgSubject, msgText isn't NUL after prev. check
1971 std::string subject = msgSubject;
1972 std::string text = msgText;
1974 // from console show not existed sender
1975 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
1977 uint32 itemTextId = !text.empty() ? sObjectMgr.CreateItemText( text ) : 0;
1979 MailDraft(subject, itemTextId)
1980 .SendMailTo(MailReceiver(target,GUID_LOPART(target_guid)),sender);
1982 std::string nameLink = playerLink(target_name);
1983 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
1984 return true;
1987 // teleport player to given game_tele.entry
1988 bool ChatHandler::HandleTeleNameCommand(const char * args)
1990 char* nameStr;
1991 char* teleStr;
1992 extractOptFirstArg((char*)args,&nameStr,&teleStr);
1993 if(!teleStr)
1994 return false;
1996 Player* target;
1997 uint64 target_guid;
1998 std::string target_name;
1999 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
2000 return false;
2002 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2003 GameTele const* tele = extractGameTeleFromLink(teleStr);
2004 if(!tele)
2006 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2007 SetSentErrorMessage(true);
2008 return false;
2011 if (target)
2013 // check online security
2014 if (HasLowerSecurity(target, 0))
2015 return false;
2017 std::string chrNameLink = playerLink(target_name);
2019 if(target->IsBeingTeleported()==true)
2021 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2022 SetSentErrorMessage(true);
2023 return false;
2026 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2027 if (needReportToTarget(target))
2028 ChatHandler(target).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2030 // stop flight if need
2031 if(target->isInFlight())
2033 target->GetMotionMaster()->MovementExpired();
2034 target->m_taxi.ClearTaxiDestinations();
2036 // save only in non-flight case
2037 else
2038 target->SaveRecallPosition();
2040 target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2042 else
2044 // check offline security
2045 if (HasLowerSecurity(NULL, target_guid))
2046 return false;
2048 std::string nameLink = playerLink(target_name);
2050 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2051 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2052 sMapMgr.GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
2055 return true;
2058 //Teleport group to given game_tele.entry
2059 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2061 if(!*args)
2062 return false;
2064 Player *player = getSelectedPlayer();
2065 if (!player)
2067 SendSysMessage(LANG_NO_CHAR_SELECTED);
2068 SetSentErrorMessage(true);
2069 return false;
2072 // check online security
2073 if (HasLowerSecurity(player, 0))
2074 return false;
2076 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2077 GameTele const* tele = extractGameTeleFromLink((char*)args);
2078 if(!tele)
2080 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2081 SetSentErrorMessage(true);
2082 return false;
2085 std::string nameLink = GetNameLink(player);
2087 Group *grp = player->GetGroup();
2088 if(!grp)
2090 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2091 SetSentErrorMessage(true);
2092 return false;
2095 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2097 Player *pl = itr->getSource();
2099 if(!pl || !pl->GetSession() )
2100 continue;
2102 // check online security
2103 if (HasLowerSecurity(pl, 0))
2104 return false;
2106 std::string plNameLink = GetNameLink(pl);
2108 if(pl->IsBeingTeleported())
2110 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2111 continue;
2114 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2115 if (needReportToTarget(pl))
2116 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2118 // stop flight if need
2119 if(pl->isInFlight())
2121 pl->GetMotionMaster()->MovementExpired();
2122 pl->m_taxi.ClearTaxiDestinations();
2124 // save only in non-flight case
2125 else
2126 pl->SaveRecallPosition();
2128 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2131 return true;
2134 //Summon group of player
2135 bool ChatHandler::HandleGroupgoCommand(const char* args)
2137 Player* target;
2138 if(!extractPlayerTarget((char*)args,&target))
2139 return false;
2141 // check online security
2142 if (HasLowerSecurity(target, 0))
2143 return false;
2145 Group *grp = target->GetGroup();
2147 std::string nameLink = GetNameLink(target);
2149 if(!grp)
2151 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2152 SetSentErrorMessage(true);
2153 return false;
2156 Map* gmMap = m_session->GetPlayer()->GetMap();
2157 bool to_instance = gmMap->Instanceable();
2159 // we are in instance, and can summon only player in our group with us as lead
2160 if ( to_instance && (
2161 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2162 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2163 // the last check is a bit excessive, but let it be, just in case
2165 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2166 SetSentErrorMessage(true);
2167 return false;
2170 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2172 Player *pl = itr->getSource();
2174 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2175 continue;
2177 // check online security
2178 if (HasLowerSecurity(pl, 0))
2179 return false;
2181 std::string plNameLink = GetNameLink(pl);
2183 if(pl->IsBeingTeleported()==true)
2185 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2186 SetSentErrorMessage(true);
2187 return false;
2190 if (to_instance)
2192 Map* plMap = pl->GetMap();
2194 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2196 // cannot summon from instance to instance
2197 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2198 SetSentErrorMessage(true);
2199 return false;
2203 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2204 if (needReportToTarget(pl))
2205 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2207 // stop flight if need
2208 if(pl->isInFlight())
2210 pl->GetMotionMaster()->MovementExpired();
2211 pl->m_taxi.ClearTaxiDestinations();
2213 // save only in non-flight case
2214 else
2215 pl->SaveRecallPosition();
2217 // before GM
2218 float x,y,z;
2219 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2220 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2223 return true;
2226 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2228 Player* _player = m_session->GetPlayer();
2230 if (!*args)
2231 return false;
2233 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2234 if (!cNodeId)
2235 return false;
2237 int32 i_nodeId = atoi(cNodeId);
2238 if (!i_nodeId)
2239 return false;
2241 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2242 if (!node)
2244 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2245 SetSentErrorMessage(true);
2246 return false;
2249 if ((node->x == 0.0f && node->y == 0.0f && node->z == 0.0f) ||
2250 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2252 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2253 SetSentErrorMessage(true);
2254 return false;
2257 // stop flight if need
2258 if (_player->isInFlight())
2260 _player->GetMotionMaster()->MovementExpired();
2261 _player->m_taxi.ClearTaxiDestinations();
2263 // save only in non-flight case
2264 else
2265 _player->SaveRecallPosition();
2267 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2268 return true;
2271 //teleport at coordinates
2272 bool ChatHandler::HandleGoXYCommand(const char* args)
2274 if(!*args)
2275 return false;
2277 Player* _player = m_session->GetPlayer();
2279 char* px = strtok((char*)args, " ");
2280 char* py = strtok(NULL, " ");
2281 char* pmapid = strtok(NULL, " ");
2283 if (!px || !py)
2284 return false;
2286 float x = (float)atof(px);
2287 float y = (float)atof(py);
2288 uint32 mapid;
2289 if (pmapid)
2290 mapid = (uint32)atoi(pmapid);
2291 else mapid = _player->GetMapId();
2293 if(!MapManager::IsValidMapCoord(mapid,x,y))
2295 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2296 SetSentErrorMessage(true);
2297 return false;
2300 // stop flight if need
2301 if(_player->isInFlight())
2303 _player->GetMotionMaster()->MovementExpired();
2304 _player->m_taxi.ClearTaxiDestinations();
2306 // save only in non-flight case
2307 else
2308 _player->SaveRecallPosition();
2310 Map const *map = sMapMgr.CreateBaseMap(mapid);
2311 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2313 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2315 return true;
2318 //teleport at coordinates, including Z
2319 bool ChatHandler::HandleGoXYZCommand(const char* args)
2321 if(!*args)
2322 return false;
2324 Player* _player = m_session->GetPlayer();
2326 char* px = strtok((char*)args, " ");
2327 char* py = strtok(NULL, " ");
2328 char* pz = strtok(NULL, " ");
2329 char* pmapid = strtok(NULL, " ");
2331 if (!px || !py || !pz)
2332 return false;
2334 float x = (float)atof(px);
2335 float y = (float)atof(py);
2336 float z = (float)atof(pz);
2337 uint32 mapid;
2338 if (pmapid)
2339 mapid = (uint32)atoi(pmapid);
2340 else
2341 mapid = _player->GetMapId();
2343 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2345 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2346 SetSentErrorMessage(true);
2347 return false;
2350 // stop flight if need
2351 if(_player->isInFlight())
2353 _player->GetMotionMaster()->MovementExpired();
2354 _player->m_taxi.ClearTaxiDestinations();
2356 // save only in non-flight case
2357 else
2358 _player->SaveRecallPosition();
2360 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2362 return true;
2365 //teleport at coordinates
2366 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2368 if(!*args)
2369 return false;
2371 Player* _player = m_session->GetPlayer();
2373 char* px = strtok((char*)args, " ");
2374 char* py = strtok(NULL, " ");
2375 char* tail = strtok(NULL,"");
2377 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2379 if (!px || !py)
2380 return false;
2382 float x = (float)atof(px);
2383 float y = (float)atof(py);
2385 // prevent accept wrong numeric args
2386 if ((x==0.0f && *px!='0') || (y==0.0f && *py!='0'))
2387 return false;
2389 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2391 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2393 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2395 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2396 SetSentErrorMessage(true);
2397 return false;
2400 // update to parent zone if exist (client map show only zones without parents)
2401 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2403 Map const *map = sMapMgr.CreateBaseMap(zoneEntry->mapid);
2405 if(map->Instanceable())
2407 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2408 SetSentErrorMessage(true);
2409 return false;
2412 Zone2MapCoordinates(x,y,zoneEntry->ID);
2414 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2416 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2417 SetSentErrorMessage(true);
2418 return false;
2421 // stop flight if need
2422 if(_player->isInFlight())
2424 _player->GetMotionMaster()->MovementExpired();
2425 _player->m_taxi.ClearTaxiDestinations();
2427 // save only in non-flight case
2428 else
2429 _player->SaveRecallPosition();
2431 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2432 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2434 return true;
2437 //teleport to grid
2438 bool ChatHandler::HandleGoGridCommand(const char* args)
2440 if(!*args) return false;
2441 Player* _player = m_session->GetPlayer();
2443 char* px = strtok((char*)args, " ");
2444 char* py = strtok(NULL, " ");
2445 char* pmapid = strtok(NULL, " ");
2447 if (!px || !py)
2448 return false;
2450 float grid_x = (float)atof(px);
2451 float grid_y = (float)atof(py);
2452 uint32 mapid;
2453 if (pmapid)
2454 mapid = (uint32)atoi(pmapid);
2455 else mapid = _player->GetMapId();
2457 // center of grid
2458 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2459 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2461 if(!MapManager::IsValidMapCoord(mapid,x,y))
2463 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2464 SetSentErrorMessage(true);
2465 return false;
2468 // stop flight if need
2469 if(_player->isInFlight())
2471 _player->GetMotionMaster()->MovementExpired();
2472 _player->m_taxi.ClearTaxiDestinations();
2474 // save only in non-flight case
2475 else
2476 _player->SaveRecallPosition();
2478 Map const *map = sMapMgr.CreateBaseMap(mapid);
2479 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2480 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2482 return true;
2485 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2487 if(!*args) return false;
2489 uint32 drunklevel = (uint32)atoi(args);
2490 if(drunklevel > 100)
2491 drunklevel = 100;
2493 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2495 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2497 return true;