[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / Level1.cpp
blob51d30c00294bda18ed9c439e01263af2cbd47609
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*)m_session->GetPlayer()->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_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 if (!Map2ZoneCoordinates(zone_x, zone_y, zone_id))
299 zone_x = 0;
300 zone_y = 0;
303 Map const *map = obj->GetMap();
304 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
305 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
307 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
309 int gx=63-p.x_coord;
310 int gy=63-p.y_coord;
312 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
313 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
315 PSendSysMessage(LANG_MAP_POSITION,
316 obj->GetMapId(), (mapEntry ? mapEntry->name[GetSessionDbcLocale()] : "<unknown>" ),
317 zone_id, (zoneEntry ? zoneEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
318 area_id, (areaEntry ? areaEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
319 obj->GetPhaseMask(),
320 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
321 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
322 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
324 sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
325 m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND),
326 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
327 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
329 sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
330 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
331 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
332 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
333 obj->GetPhaseMask(),
334 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
335 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
336 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
338 LiquidData liquid_status;
339 ZLiquidStatus res = map->getLiquidStatus(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), MAP_ALL_LIQUIDS, &liquid_status);
340 if (res)
342 PSendSysMessage(LANG_LIQUID_STATUS, liquid_status.level, liquid_status.depth_level, liquid_status.type, res);
344 return true;
347 //Summon Player
348 bool ChatHandler::HandleNamegoCommand(const char* args)
350 Player* target;
351 uint64 target_guid;
352 std::string target_name;
353 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
354 return false;
356 Player* _player = m_session->GetPlayer();
357 if (target == _player || target_guid == _player->GetGUID())
359 PSendSysMessage(LANG_CANT_TELEPORT_SELF);
360 SetSentErrorMessage(true);
361 return false;
364 if (target)
366 std::string nameLink = playerLink(target_name);
367 // check online security
368 if (HasLowerSecurity(target, 0))
369 return false;
371 if (target->IsBeingTeleported())
373 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
374 SetSentErrorMessage(true);
375 return false;
378 Map* pMap = m_session->GetPlayer()->GetMap();
380 if (pMap->IsBattleGroundOrArena())
382 // only allow if gm mode is on
383 if (!target->isGameMaster())
385 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,nameLink.c_str());
386 SetSentErrorMessage(true);
387 return false;
389 // if both players are in different bgs
390 else if (target->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != target->GetBattleGroundId())
392 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,nameLink.c_str());
393 SetSentErrorMessage(true);
394 return false;
396 // all's well, set bg id
397 // when porting out from the bg, it will be reset to 0
398 target->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
399 // remember current position as entry point for return at bg end teleportation
400 if (!target->GetMap()->IsBattleGroundOrArena())
401 target->SetBattleGroundEntryPoint();
403 else if (pMap->IsDungeon())
405 Map* cMap = target->GetMap();
406 if (cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId())
408 // cannot summon from instance to instance
409 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
410 SetSentErrorMessage(true);
411 return false;
414 // we are in instance, and can summon only player in our group with us as lead
415 if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
416 (target->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
417 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()))
418 // the last check is a bit excessive, but let it be, just in case
420 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
421 SetSentErrorMessage(true);
422 return false;
426 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
427 if (needReportToTarget(target))
428 ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, playerLink(_player->GetName()).c_str());
430 // stop flight if need
431 if (target->isInFlight())
433 target->GetMotionMaster()->MovementExpired();
434 target->m_taxi.ClearTaxiDestinations();
436 // save only in non-flight case
437 else
438 target->SaveRecallPosition();
440 // before GM
441 float x,y,z;
442 m_session->GetPlayer()->GetClosePoint(x,y,z,target->GetObjectSize());
443 target->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,target->GetOrientation());
445 else
447 // check offline security
448 if (HasLowerSecurity(NULL, target_guid))
449 return false;
451 std::string nameLink = playerLink(target_name);
453 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
455 // in point where GM stay
456 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
457 m_session->GetPlayer()->GetPositionX(),
458 m_session->GetPlayer()->GetPositionY(),
459 m_session->GetPlayer()->GetPositionZ(),
460 m_session->GetPlayer()->GetOrientation(),
461 m_session->GetPlayer()->GetZoneId(),
462 target_guid);
465 return true;
468 //Teleport to Player
469 bool ChatHandler::HandleGonameCommand(const char* args)
471 Player* target;
472 uint64 target_guid;
473 std::string target_name;
474 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
475 return false;
477 Player* _player = m_session->GetPlayer();
478 if (target == _player || target_guid == _player->GetGUID())
480 SendSysMessage(LANG_CANT_TELEPORT_SELF);
481 SetSentErrorMessage(true);
482 return false;
486 if (target)
488 // check online security
489 if (HasLowerSecurity(target, 0))
490 return false;
492 std::string chrNameLink = playerLink(target_name);
494 Map* cMap = target->GetMap();
495 if (cMap->IsBattleGroundOrArena())
497 // only allow if gm mode is on
498 if (!_player->isGameMaster())
500 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
501 SetSentErrorMessage(true);
502 return false;
504 // if both players are in different bgs
505 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
507 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
508 SetSentErrorMessage(true);
509 return false;
511 // all's well, set bg id
512 // when porting out from the bg, it will be reset to 0
513 _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
514 // remember current position as entry point for return at bg end teleportation
515 if (!_player->GetMap()->IsBattleGroundOrArena())
516 _player->SetBattleGroundEntryPoint();
518 else if(cMap->IsDungeon())
520 // we have to go to instance, and can go to player only if:
521 // 1) we are in his group (either as leader or as member)
522 // 2) we are not bound to any group and have GM mode on
523 if (_player->GetGroup())
525 // we are in group, we can go only if we are in the player group
526 if (_player->GetGroup() != target->GetGroup())
528 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
529 SetSentErrorMessage(true);
530 return false;
533 else
535 // we are not in group, let's verify our GM mode
536 if (!_player->isGameMaster())
538 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
539 SetSentErrorMessage(true);
540 return false;
544 // if the player or the player's group is bound to another instance
545 // the player will not be bound to another one
546 InstancePlayerBind *pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty(cMap->IsRaid()));
547 if (!pBind)
549 Group *group = _player->GetGroup();
550 // if no bind exists, create a solo bind
551 InstanceGroupBind *gBind = group ? group->GetBoundInstance(target) : NULL;
552 // if no bind exists, create a solo bind
553 if (!gBind)
554 if (InstanceSave *save = sInstanceSaveMgr.GetInstanceSave(target->GetInstanceId()))
555 _player->BindToInstance(save, !save->CanReset());
558 if(cMap->IsRaid())
559 _player->SetRaidDifficulty(target->GetRaidDifficulty());
560 else
561 _player->SetDungeonDifficulty(target->GetDungeonDifficulty());
564 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
565 if (needReportToTarget(target))
566 ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
568 // stop flight if need
569 if (_player->isInFlight())
571 _player->GetMotionMaster()->MovementExpired();
572 _player->m_taxi.ClearTaxiDestinations();
574 // save only in non-flight case
575 else
576 _player->SaveRecallPosition();
578 // to point to see at target with same orientation
579 float x,y,z;
580 target->GetContactPoint(_player,x,y,z);
582 _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
584 else
586 // check offline security
587 if (HasLowerSecurity(NULL, target_guid))
588 return false;
590 std::string nameLink = playerLink(target_name);
592 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
594 // to point where player stay (if loaded)
595 float x,y,z,o;
596 uint32 map;
597 bool in_flight;
598 if (!Player::LoadPositionFromDB(map,x,y,z,o,in_flight,target_guid))
599 return false;
601 // stop flight if need
602 if (_player->isInFlight())
604 _player->GetMotionMaster()->MovementExpired();
605 _player->m_taxi.ClearTaxiDestinations();
607 // save only in non-flight case
608 else
609 _player->SaveRecallPosition();
611 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
614 return true;
617 // Teleport player to last position
618 bool ChatHandler::HandleRecallCommand(const char* args)
620 Player* target;
621 if(!extractPlayerTarget((char*)args,&target))
622 return false;
624 // check online security
625 if (HasLowerSecurity(target, 0))
626 return false;
628 if (target->IsBeingTeleported())
630 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
631 SetSentErrorMessage(true);
632 return false;
635 // stop flight if need
636 if(target->isInFlight())
638 target->GetMotionMaster()->MovementExpired();
639 target->m_taxi.ClearTaxiDestinations();
642 target->TeleportTo(target->m_recallMap, target->m_recallX, target->m_recallY, target->m_recallZ, target->m_recallO);
643 return true;
646 //Edit Player HP
647 bool ChatHandler::HandleModifyHPCommand(const char* args)
649 if(!*args)
650 return false;
652 // char* pHp = strtok((char*)args, " ");
653 // if (!pHp)
654 // return false;
656 // char* pHpMax = strtok(NULL, " ");
657 // if (!pHpMax)
658 // return false;
660 // int32 hpm = atoi(pHpMax);
661 // int32 hp = atoi(pHp);
663 int32 hp = atoi((char*)args);
664 int32 hpm = atoi((char*)args);
666 if (hp <= 0 || hpm <= 0 || hpm < hp)
668 SendSysMessage(LANG_BAD_VALUE);
669 SetSentErrorMessage(true);
670 return false;
673 Player *chr = getSelectedPlayer();
674 if (chr == NULL)
676 SendSysMessage(LANG_NO_CHAR_SELECTED);
677 SetSentErrorMessage(true);
678 return false;
681 // check online security
682 if (HasLowerSecurity(chr, 0))
683 return false;
685 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
686 if (needReportToTarget(chr))
687 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
689 chr->SetMaxHealth( hpm );
690 chr->SetHealth( hp );
692 return true;
695 //Edit Player Mana
696 bool ChatHandler::HandleModifyManaCommand(const char* args)
698 if(!*args)
699 return false;
701 // char* pmana = strtok((char*)args, " ");
702 // if (!pmana)
703 // return false;
705 // char* pmanaMax = strtok(NULL, " ");
706 // if (!pmanaMax)
707 // return false;
709 // int32 manam = atoi(pmanaMax);
710 // int32 mana = atoi(pmana);
711 int32 mana = atoi((char*)args);
712 int32 manam = atoi((char*)args);
714 if (mana <= 0 || manam <= 0 || manam < mana)
716 SendSysMessage(LANG_BAD_VALUE);
717 SetSentErrorMessage(true);
718 return false;
721 Player *chr = getSelectedPlayer();
722 if (chr == NULL)
724 SendSysMessage(LANG_NO_CHAR_SELECTED);
725 SetSentErrorMessage(true);
726 return false;
729 // check online security
730 if (HasLowerSecurity(chr, 0))
731 return false;
733 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
734 if (needReportToTarget(chr))
735 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
737 chr->SetMaxPower(POWER_MANA,manam );
738 chr->SetPower(POWER_MANA, mana );
740 return true;
743 //Edit Player Energy
744 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
746 if(!*args)
747 return false;
749 // char* pmana = strtok((char*)args, " ");
750 // if (!pmana)
751 // return false;
753 // char* pmanaMax = strtok(NULL, " ");
754 // if (!pmanaMax)
755 // return false;
757 // int32 manam = atoi(pmanaMax);
758 // int32 mana = atoi(pmana);
760 int32 energy = atoi((char*)args)*10;
761 int32 energym = atoi((char*)args)*10;
763 if (energy <= 0 || energym <= 0 || energym < energy)
765 SendSysMessage(LANG_BAD_VALUE);
766 SetSentErrorMessage(true);
767 return false;
770 Player *chr = getSelectedPlayer();
771 if (!chr)
773 SendSysMessage(LANG_NO_CHAR_SELECTED);
774 SetSentErrorMessage(true);
775 return false;
778 // check online security
779 if (HasLowerSecurity(chr, 0))
780 return false;
782 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
783 if (needReportToTarget(chr))
784 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
786 chr->SetMaxPower(POWER_ENERGY,energym );
787 chr->SetPower(POWER_ENERGY, energy );
789 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
791 return true;
794 //Edit Player Rage
795 bool ChatHandler::HandleModifyRageCommand(const char* args)
797 if(!*args)
798 return false;
800 // char* pmana = strtok((char*)args, " ");
801 // if (!pmana)
802 // return false;
804 // char* pmanaMax = strtok(NULL, " ");
805 // if (!pmanaMax)
806 // return false;
808 // int32 manam = atoi(pmanaMax);
809 // int32 mana = atoi(pmana);
811 int32 rage = atoi((char*)args)*10;
812 int32 ragem = atoi((char*)args)*10;
814 if (rage <= 0 || ragem <= 0 || ragem < rage)
816 SendSysMessage(LANG_BAD_VALUE);
817 SetSentErrorMessage(true);
818 return false;
821 Player *chr = getSelectedPlayer();
822 if (chr == NULL)
824 SendSysMessage(LANG_NO_CHAR_SELECTED);
825 SetSentErrorMessage(true);
826 return false;
829 // check online security
830 if (HasLowerSecurity(chr, 0))
831 return false;
833 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
834 if (needReportToTarget(chr))
835 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
837 chr->SetMaxPower(POWER_RAGE,ragem );
838 chr->SetPower(POWER_RAGE, rage );
840 return true;
843 // Edit Player Runic Power
844 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
846 if(!*args)
847 return false;
849 int32 rune = atoi((char*)args)*10;
850 int32 runem = atoi((char*)args)*10;
852 if (rune <= 0 || runem <= 0 || runem < rune)
854 SendSysMessage(LANG_BAD_VALUE);
855 SetSentErrorMessage(true);
856 return false;
859 Player *chr = getSelectedPlayer();
860 if (chr == NULL)
862 SendSysMessage(LANG_NO_CHAR_SELECTED);
863 SetSentErrorMessage(true);
864 return false;
867 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
868 if (needReportToTarget(chr))
869 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
871 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
872 chr->SetPower(POWER_RUNIC_POWER, rune );
874 return true;
877 //Edit Player Faction
878 bool ChatHandler::HandleModifyFactionCommand(const char* args)
880 if(!*args)
881 return false;
883 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
885 Creature* chr = getSelectedCreature();
886 if(!chr)
888 SendSysMessage(LANG_SELECT_CREATURE);
889 SetSentErrorMessage(true);
890 return false;
893 if(!pfactionid)
895 if(chr)
897 uint32 factionid = chr->getFaction();
898 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
899 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
900 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
901 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
903 return true;
906 if( !chr )
908 SendSysMessage(LANG_NO_CHAR_SELECTED);
909 SetSentErrorMessage(true);
910 return false;
913 uint32 factionid = atoi(pfactionid);
914 uint32 flag;
916 char *pflag = strtok(NULL, " ");
917 if (!pflag)
918 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
919 else
920 flag = atoi(pflag);
922 char* pnpcflag = strtok(NULL, " ");
924 uint32 npcflag;
925 if(!pnpcflag)
926 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
927 else
928 npcflag = atoi(pnpcflag);
930 char* pdyflag = strtok(NULL, " ");
932 uint32 dyflag;
933 if(!pdyflag)
934 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
935 else
936 dyflag = atoi(pdyflag);
938 if(!sFactionTemplateStore.LookupEntry(factionid))
940 PSendSysMessage(LANG_WRONG_FACTION, factionid);
941 SetSentErrorMessage(true);
942 return false;
945 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
947 chr->setFaction(factionid);
948 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
949 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
950 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
952 return true;
955 //Edit Player Spell
956 bool ChatHandler::HandleModifySpellCommand(const char* args)
958 if(!*args) return false;
959 char* pspellflatid = strtok((char*)args, " ");
960 if (!pspellflatid)
961 return false;
963 char* pop = strtok(NULL, " ");
964 if (!pop)
965 return false;
967 char* pval = strtok(NULL, " ");
968 if (!pval)
969 return false;
971 uint16 mark;
973 char* pmark = strtok(NULL, " ");
975 uint8 spellflatid = atoi(pspellflatid);
976 uint8 op = atoi(pop);
977 uint16 val = atoi(pval);
978 if(!pmark)
979 mark = 65535;
980 else
981 mark = atoi(pmark);
983 Player *chr = getSelectedPlayer();
984 if (chr == NULL)
986 SendSysMessage(LANG_NO_CHAR_SELECTED);
987 SetSentErrorMessage(true);
988 return false;
991 // check online security
992 if (HasLowerSecurity(chr, 0))
993 return false;
995 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
996 if (needReportToTarget(chr))
997 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
999 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1000 data << uint8(spellflatid);
1001 data << uint8(op);
1002 data << uint16(val);
1003 data << uint16(mark);
1004 chr->GetSession()->SendPacket(&data);
1006 return true;
1009 //Edit Player TP
1010 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1012 if (!*args)
1013 return false;
1015 int tp = atoi((char*)args);
1016 if (tp < 0)
1017 return false;
1019 Unit* target = getSelectedUnit();
1020 if(!target)
1022 SendSysMessage(LANG_NO_CHAR_SELECTED);
1023 SetSentErrorMessage(true);
1024 return false;
1027 if(target->GetTypeId()==TYPEID_PLAYER)
1029 // check online security
1030 if (HasLowerSecurity((Player*)target, 0))
1031 return false;
1033 ((Player*)target)->SetFreeTalentPoints(tp);
1034 ((Player*)target)->SendTalentsInfoData(false);
1035 return true;
1037 else if(((Creature*)target)->isPet())
1039 Unit *owner = target->GetOwner();
1040 if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor((Player*)owner))
1042 // check online security
1043 if (HasLowerSecurity((Player*)owner, 0))
1044 return false;
1046 ((Pet *)target)->SetFreeTalentPoints(tp);
1047 ((Player*)owner)->SendTalentsInfoData(true);
1048 return true;
1052 SendSysMessage(LANG_NO_CHAR_SELECTED);
1053 SetSentErrorMessage(true);
1054 return false;
1057 //Enable On\OFF all taxi paths
1058 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1060 if (!*args)
1062 SendSysMessage(LANG_USE_BOL);
1063 SetSentErrorMessage(true);
1064 return false;
1067 std::string argstr = (char*)args;
1069 Player *chr = getSelectedPlayer();
1070 if (!chr)
1072 chr=m_session->GetPlayer();
1075 // check online security
1076 else if (HasLowerSecurity(chr, 0))
1077 return false;
1079 if (argstr == "on")
1081 chr->SetTaxiCheater(true);
1082 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1083 if (needReportToTarget(chr))
1084 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1085 return true;
1088 if (argstr == "off")
1090 chr->SetTaxiCheater(false);
1091 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1092 if (needReportToTarget(chr))
1093 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1095 return true;
1098 SendSysMessage(LANG_USE_BOL);
1099 SetSentErrorMessage(true);
1100 return false;
1103 //Edit Player Aspeed
1104 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1106 if (!*args)
1107 return false;
1109 float ASpeed = (float)atof((char*)args);
1111 if (ASpeed > 10 || ASpeed < 0.1)
1113 SendSysMessage(LANG_BAD_VALUE);
1114 SetSentErrorMessage(true);
1115 return false;
1118 Player *chr = getSelectedPlayer();
1119 if (chr == NULL)
1121 SendSysMessage(LANG_NO_CHAR_SELECTED);
1122 SetSentErrorMessage(true);
1123 return false;
1126 // check online security
1127 if (HasLowerSecurity(chr, 0))
1128 return false;
1130 std::string chrNameLink = GetNameLink(chr);
1132 if(chr->isInFlight())
1134 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1135 SetSentErrorMessage(true);
1136 return false;
1139 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1140 if (needReportToTarget(chr))
1141 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1143 chr->SetSpeedRate(MOVE_WALK, ASpeed,true);
1144 chr->SetSpeedRate(MOVE_RUN, ASpeed,true);
1145 chr->SetSpeedRate(MOVE_SWIM, ASpeed,true);
1146 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1147 chr->SetSpeedRate(MOVE_FLIGHT, ASpeed,true);
1148 return true;
1151 //Edit Player Speed
1152 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1154 if (!*args)
1155 return false;
1157 float Speed = (float)atof((char*)args);
1159 if (Speed > 10 || Speed < 0.1)
1161 SendSysMessage(LANG_BAD_VALUE);
1162 SetSentErrorMessage(true);
1163 return false;
1166 Player *chr = getSelectedPlayer();
1167 if (chr == NULL)
1169 SendSysMessage(LANG_NO_CHAR_SELECTED);
1170 SetSentErrorMessage(true);
1171 return false;
1174 // check online security
1175 if (HasLowerSecurity(chr, 0))
1176 return false;
1178 std::string chrNameLink = GetNameLink(chr);
1180 if(chr->isInFlight())
1182 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1183 SetSentErrorMessage(true);
1184 return false;
1187 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1188 if (needReportToTarget(chr))
1189 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1191 chr->SetSpeedRate(MOVE_RUN,Speed,true);
1193 return true;
1196 //Edit Player Swim Speed
1197 bool ChatHandler::HandleModifySwimCommand(const char* args)
1199 if (!*args)
1200 return false;
1202 float Swim = (float)atof((char*)args);
1204 if (Swim > 10.0f || Swim < 0.01f)
1206 SendSysMessage(LANG_BAD_VALUE);
1207 SetSentErrorMessage(true);
1208 return false;
1211 Player *chr = getSelectedPlayer();
1212 if (chr == NULL)
1214 SendSysMessage(LANG_NO_CHAR_SELECTED);
1215 SetSentErrorMessage(true);
1216 return false;
1219 // check online security
1220 if (HasLowerSecurity(chr, 0))
1221 return false;
1223 std::string chrNameLink = GetNameLink(chr);
1225 if(chr->isInFlight())
1227 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1228 SetSentErrorMessage(true);
1229 return false;
1232 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1233 if (needReportToTarget(chr))
1234 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1236 chr->SetSpeedRate(MOVE_SWIM,Swim,true);
1238 return true;
1241 //Edit Player Walk Speed
1242 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1244 if (!*args)
1245 return false;
1247 float BSpeed = (float)atof((char*)args);
1249 if (BSpeed > 10.0f || BSpeed < 0.1f)
1251 SendSysMessage(LANG_BAD_VALUE);
1252 SetSentErrorMessage(true);
1253 return false;
1256 Player *chr = getSelectedPlayer();
1257 if (chr == NULL)
1259 SendSysMessage(LANG_NO_CHAR_SELECTED);
1260 SetSentErrorMessage(true);
1261 return false;
1264 // check online security
1265 if (HasLowerSecurity(chr, 0))
1266 return false;
1268 std::string chrNameLink = GetNameLink(chr);
1270 if(chr->isInFlight())
1272 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1273 SetSentErrorMessage(true);
1274 return false;
1277 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1278 if (needReportToTarget(chr))
1279 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1281 chr->SetSpeedRate(MOVE_RUN_BACK,BSpeed,true);
1283 return true;
1286 //Edit Player Fly
1287 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1289 if (!*args)
1290 return false;
1292 float FSpeed = (float)atof((char*)args);
1294 if (FSpeed > 10.0f || FSpeed < 0.1f)
1296 SendSysMessage(LANG_BAD_VALUE);
1297 SetSentErrorMessage(true);
1298 return false;
1301 Player *chr = getSelectedPlayer();
1302 if (chr == NULL)
1304 SendSysMessage(LANG_NO_CHAR_SELECTED);
1305 SetSentErrorMessage(true);
1306 return false;
1309 // check online security
1310 if (HasLowerSecurity(chr, 0))
1311 return false;
1313 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1314 if (needReportToTarget(chr))
1315 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1317 chr->SetSpeedRate(MOVE_FLIGHT,FSpeed,true);
1319 return true;
1322 //Edit Player Scale
1323 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1325 if (!*args)
1326 return false;
1328 float Scale = (float)atof((char*)args);
1329 if (Scale > 10.0f || Scale <= 0.0f)
1331 SendSysMessage(LANG_BAD_VALUE);
1332 SetSentErrorMessage(true);
1333 return false;
1336 Unit *target = getSelectedUnit();
1337 if (target == NULL)
1339 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
1340 SetSentErrorMessage(true);
1341 return false;
1344 if (target->GetTypeId()==TYPEID_PLAYER)
1346 // check online security
1347 if (HasLowerSecurity((Player*)target, 0))
1348 return false;
1350 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink((Player*)target).c_str());
1351 if (needReportToTarget((Player*)target))
1352 ChatHandler((Player*)target).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1355 target->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1357 return true;
1360 //Enable Player mount
1361 bool ChatHandler::HandleModifyMountCommand(const char* args)
1363 if(!*args)
1364 return false;
1366 uint16 mId = 1147;
1367 float speed = (float)15;
1368 uint32 num = 0;
1370 num = atoi((char*)args);
1371 switch(num)
1373 case 1:
1374 mId=14340;
1375 break;
1376 case 2:
1377 mId=4806;
1378 break;
1379 case 3:
1380 mId=6471;
1381 break;
1382 case 4:
1383 mId=12345;
1384 break;
1385 case 5:
1386 mId=6472;
1387 break;
1388 case 6:
1389 mId=6473;
1390 break;
1391 case 7:
1392 mId=10670;
1393 break;
1394 case 8:
1395 mId=10719;
1396 break;
1397 case 9:
1398 mId=10671;
1399 break;
1400 case 10:
1401 mId=10672;
1402 break;
1403 case 11:
1404 mId=10720;
1405 break;
1406 case 12:
1407 mId=14349;
1408 break;
1409 case 13:
1410 mId=11641;
1411 break;
1412 case 14:
1413 mId=12244;
1414 break;
1415 case 15:
1416 mId=12242;
1417 break;
1418 case 16:
1419 mId=14578;
1420 break;
1421 case 17:
1422 mId=14579;
1423 break;
1424 case 18:
1425 mId=14349;
1426 break;
1427 case 19:
1428 mId=12245;
1429 break;
1430 case 20:
1431 mId=14335;
1432 break;
1433 case 21:
1434 mId=207;
1435 break;
1436 case 22:
1437 mId=2328;
1438 break;
1439 case 23:
1440 mId=2327;
1441 break;
1442 case 24:
1443 mId=2326;
1444 break;
1445 case 25:
1446 mId=14573;
1447 break;
1448 case 26:
1449 mId=14574;
1450 break;
1451 case 27:
1452 mId=14575;
1453 break;
1454 case 28:
1455 mId=604;
1456 break;
1457 case 29:
1458 mId=1166;
1459 break;
1460 case 30:
1461 mId=2402;
1462 break;
1463 case 31:
1464 mId=2410;
1465 break;
1466 case 32:
1467 mId=2409;
1468 break;
1469 case 33:
1470 mId=2408;
1471 break;
1472 case 34:
1473 mId=2405;
1474 break;
1475 case 35:
1476 mId=14337;
1477 break;
1478 case 36:
1479 mId=6569;
1480 break;
1481 case 37:
1482 mId=10661;
1483 break;
1484 case 38:
1485 mId=10666;
1486 break;
1487 case 39:
1488 mId=9473;
1489 break;
1490 case 40:
1491 mId=9476;
1492 break;
1493 case 41:
1494 mId=9474;
1495 break;
1496 case 42:
1497 mId=14374;
1498 break;
1499 case 43:
1500 mId=14376;
1501 break;
1502 case 44:
1503 mId=14377;
1504 break;
1505 case 45:
1506 mId=2404;
1507 break;
1508 case 46:
1509 mId=2784;
1510 break;
1511 case 47:
1512 mId=2787;
1513 break;
1514 case 48:
1515 mId=2785;
1516 break;
1517 case 49:
1518 mId=2736;
1519 break;
1520 case 50:
1521 mId=2786;
1522 break;
1523 case 51:
1524 mId=14347;
1525 break;
1526 case 52:
1527 mId=14346;
1528 break;
1529 case 53:
1530 mId=14576;
1531 break;
1532 case 54:
1533 mId=9695;
1534 break;
1535 case 55:
1536 mId=9991;
1537 break;
1538 case 56:
1539 mId=6448;
1540 break;
1541 case 57:
1542 mId=6444;
1543 break;
1544 case 58:
1545 mId=6080;
1546 break;
1547 case 59:
1548 mId=6447;
1549 break;
1550 case 60:
1551 mId=4805;
1552 break;
1553 case 61:
1554 mId=9714;
1555 break;
1556 case 62:
1557 mId=6448;
1558 break;
1559 case 63:
1560 mId=6442;
1561 break;
1562 case 64:
1563 mId=14632;
1564 break;
1565 case 65:
1566 mId=14332;
1567 break;
1568 case 66:
1569 mId=14331;
1570 break;
1571 case 67:
1572 mId=8469;
1573 break;
1574 case 68:
1575 mId=2830;
1576 break;
1577 case 69:
1578 mId=2346;
1579 break;
1580 default:
1581 SendSysMessage(LANG_NO_MOUNT);
1582 SetSentErrorMessage(true);
1583 return false;
1586 Player *chr = getSelectedPlayer();
1587 if (chr == NULL)
1589 SendSysMessage(LANG_NO_CHAR_SELECTED);
1590 SetSentErrorMessage(true);
1591 return false;
1594 // check online security
1595 if (HasLowerSecurity(chr, 0))
1596 return false;
1598 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1599 if (needReportToTarget(chr))
1600 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1602 chr->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP);
1603 chr->Mount(mId);
1605 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1606 data << chr->GetPackGUID();
1607 data << (uint32)0;
1608 data << (uint8)0; //new 2.1.0
1609 data << float(speed);
1610 chr->SendMessageToSet( &data, true );
1612 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1613 data << chr->GetPackGUID();
1614 data << (uint32)0;
1615 data << float(speed);
1616 chr->SendMessageToSet( &data, true );
1618 return true;
1621 //Edit Player money
1622 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1624 if (!*args)
1625 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 int32 addmoney = atoi((char*)args);
1641 uint32 moneyuser = chr->GetMoney();
1643 if (addmoney < 0)
1645 int32 newmoney = int32(moneyuser) + addmoney;
1647 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1648 if (newmoney <= 0 )
1650 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1651 if (needReportToTarget(chr))
1652 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1654 chr->SetMoney(0);
1656 else
1658 if (newmoney > MAX_MONEY_AMOUNT)
1659 newmoney = MAX_MONEY_AMOUNT;
1661 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1662 if (needReportToTarget(chr))
1663 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1664 chr->SetMoney( newmoney );
1667 else
1669 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1670 if (needReportToTarget(chr))
1671 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1673 if (addmoney >=MAX_MONEY_AMOUNT)
1674 chr->SetMoney(MAX_MONEY_AMOUNT);
1675 else
1676 chr->ModifyMoney( addmoney );
1679 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1681 return true;
1684 //Edit Unit field
1685 bool ChatHandler::HandleModifyBitCommand(const char* args)
1687 if( !*args )
1688 return false;
1690 Unit *unit = getSelectedUnit();
1691 if (!unit)
1693 SendSysMessage(LANG_NO_CHAR_SELECTED);
1694 SetSentErrorMessage(true);
1695 return false;
1698 // check online security
1699 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1700 return false;
1702 char* pField = strtok((char*)args, " ");
1703 if (!pField)
1704 return false;
1706 char* pBit = strtok(NULL, " ");
1707 if (!pBit)
1708 return false;
1710 uint16 field = atoi(pField);
1711 uint32 bit = atoi(pBit);
1713 if (field < OBJECT_END || field >= unit->GetValuesCount())
1715 SendSysMessage(LANG_BAD_VALUE);
1716 SetSentErrorMessage(true);
1717 return false;
1719 if (bit < 1 || bit > 32)
1721 SendSysMessage(LANG_BAD_VALUE);
1722 SetSentErrorMessage(true);
1723 return false;
1726 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1728 unit->RemoveFlag( field, (1<<(bit-1)) );
1729 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1731 else
1733 unit->SetFlag( field, (1<<(bit-1)) );
1734 PSendSysMessage(LANG_SET_BIT, bit, field);
1736 return true;
1739 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1741 if (!*args)
1742 return false;
1744 Player *target = getSelectedPlayer();
1745 if(!target)
1747 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1748 SetSentErrorMessage(true);
1749 return false;
1752 // check online security
1753 if (HasLowerSecurity(target, 0))
1754 return false;
1756 int32 amount = (uint32)atoi(args);
1758 target->ModifyHonorPoints(amount);
1760 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1762 return true;
1765 bool ChatHandler::HandleTeleCommand(const char * args)
1767 if(!*args)
1768 return false;
1770 Player* _player = m_session->GetPlayer();
1772 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1773 GameTele const* tele = extractGameTeleFromLink((char*)args);
1775 if (!tele)
1777 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1778 SetSentErrorMessage(true);
1779 return false;
1782 // stop flight if need
1783 if(_player->isInFlight())
1785 _player->GetMotionMaster()->MovementExpired();
1786 _player->m_taxi.ClearTaxiDestinations();
1788 // save only in non-flight case
1789 else
1790 _player->SaveRecallPosition();
1792 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1793 return true;
1796 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1798 if (!*args)
1799 return false;
1801 std::string namepart = args;
1802 std::wstring wnamepart;
1804 if (!Utf8toWStr (namepart,wnamepart))
1805 return false;
1807 uint32 counter = 0; // Counter for figure out that we found smth.
1809 // converting string that we try to find to lower case
1810 wstrToLower (wnamepart);
1812 // Search in AreaTable.dbc
1813 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1815 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1816 if (areaEntry)
1818 int loc = GetSessionDbcLocale ();
1819 std::string name = areaEntry->area_name[loc];
1820 if (name.empty())
1821 continue;
1823 if (!Utf8FitTo (name, wnamepart))
1825 loc = 0;
1826 for(; loc < MAX_LOCALE; ++loc)
1828 if (loc==GetSessionDbcLocale ())
1829 continue;
1831 name = areaEntry->area_name[loc];
1832 if (name.empty ())
1833 continue;
1835 if (Utf8FitTo (name, wnamepart))
1836 break;
1840 if (loc < MAX_LOCALE)
1842 // send area in "id - [name]" format
1843 std::ostringstream ss;
1844 if (m_session)
1845 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1846 else
1847 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1849 SendSysMessage (ss.str ().c_str());
1851 ++counter;
1856 if (counter == 0) // if counter == 0 then we found nth
1857 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1859 return true;
1862 //Find tele in game_tele order by name
1863 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1865 if(!*args)
1867 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1868 SetSentErrorMessage(true);
1869 return false;
1872 char const* str = strtok((char*)args, " ");
1873 if(!str)
1874 return false;
1876 std::string namepart = str;
1877 std::wstring wnamepart;
1879 if(!Utf8toWStr(namepart,wnamepart))
1880 return false;
1882 // converting string that we try to find to lower case
1883 wstrToLower( wnamepart );
1885 std::ostringstream reply;
1887 GameTeleMap const & teleMap = sObjectMgr.GetGameTeleMap();
1888 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1890 GameTele const* tele = &itr->second;
1892 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1893 continue;
1895 if (m_session)
1896 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1897 else
1898 reply << " " << itr->first << " " << tele->name << "\n";
1901 if(reply.str().empty())
1902 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1903 else
1904 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1906 return true;
1909 //Enable\Dissable accept whispers (for GM)
1910 bool ChatHandler::HandleWhispersCommand(const char* args)
1912 if(!*args)
1914 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1915 return true;
1918 std::string argstr = (char*)args;
1919 // whisper on
1920 if (argstr == "on")
1922 m_session->GetPlayer()->SetAcceptWhispers(true);
1923 SendSysMessage(LANG_COMMAND_WHISPERON);
1924 return true;
1927 // whisper off
1928 if (argstr == "off")
1930 m_session->GetPlayer()->SetAcceptWhispers(false);
1931 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1932 return true;
1935 SendSysMessage(LANG_USE_BOL);
1936 SetSentErrorMessage(true);
1937 return false;
1940 //Save all players in the world
1941 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1943 sObjectAccessor.SaveAllPlayers();
1944 SendSysMessage(LANG_PLAYERS_SAVED);
1945 return true;
1948 //Send mail by command
1949 bool ChatHandler::HandleSendMailCommand(const char* args)
1951 // format: name "subject text" "mail text"
1952 Player* target;
1953 uint64 target_guid;
1954 std::string target_name;
1955 if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
1956 return false;
1958 char* tail1 = strtok(NULL, "");
1959 if(!tail1)
1960 return false;
1962 char* msgSubject = extractQuotedArg(tail1);
1963 if (!msgSubject)
1964 return false;
1966 char* tail2 = strtok(NULL, "");
1967 if(!tail2)
1968 return false;
1970 char* msgText = extractQuotedArg(tail2);
1971 if (!msgText)
1972 return false;
1974 // msgSubject, msgText isn't NUL after prev. check
1975 std::string subject = msgSubject;
1976 std::string text = msgText;
1978 // from console show not existed sender
1979 MailSender sender(MAIL_NORMAL,m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
1981 uint32 itemTextId = !text.empty() ? sObjectMgr.CreateItemText( text ) : 0;
1983 MailDraft(subject, itemTextId)
1984 .SendMailTo(MailReceiver(target,GUID_LOPART(target_guid)),sender);
1986 std::string nameLink = playerLink(target_name);
1987 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
1988 return true;
1991 // teleport player to given game_tele.entry
1992 bool ChatHandler::HandleTeleNameCommand(const char * args)
1994 char* nameStr;
1995 char* teleStr;
1996 extractOptFirstArg((char*)args,&nameStr,&teleStr);
1997 if(!teleStr)
1998 return false;
2000 Player* target;
2001 uint64 target_guid;
2002 std::string target_name;
2003 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
2004 return false;
2006 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2007 GameTele const* tele = extractGameTeleFromLink(teleStr);
2008 if(!tele)
2010 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2011 SetSentErrorMessage(true);
2012 return false;
2015 if (target)
2017 // check online security
2018 if (HasLowerSecurity(target, 0))
2019 return false;
2021 std::string chrNameLink = playerLink(target_name);
2023 if(target->IsBeingTeleported()==true)
2025 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2026 SetSentErrorMessage(true);
2027 return false;
2030 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2031 if (needReportToTarget(target))
2032 ChatHandler(target).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2034 // stop flight if need
2035 if(target->isInFlight())
2037 target->GetMotionMaster()->MovementExpired();
2038 target->m_taxi.ClearTaxiDestinations();
2040 // save only in non-flight case
2041 else
2042 target->SaveRecallPosition();
2044 target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2046 else
2048 // check offline security
2049 if (HasLowerSecurity(NULL, target_guid))
2050 return false;
2052 std::string nameLink = playerLink(target_name);
2054 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2055 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2056 sMapMgr.GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
2059 return true;
2062 //Teleport group to given game_tele.entry
2063 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2065 if(!*args)
2066 return false;
2068 Player *player = getSelectedPlayer();
2069 if (!player)
2071 SendSysMessage(LANG_NO_CHAR_SELECTED);
2072 SetSentErrorMessage(true);
2073 return false;
2076 // check online security
2077 if (HasLowerSecurity(player, 0))
2078 return false;
2080 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2081 GameTele const* tele = extractGameTeleFromLink((char*)args);
2082 if(!tele)
2084 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2085 SetSentErrorMessage(true);
2086 return false;
2089 std::string nameLink = GetNameLink(player);
2091 Group *grp = player->GetGroup();
2092 if(!grp)
2094 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2095 SetSentErrorMessage(true);
2096 return false;
2099 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2101 Player *pl = itr->getSource();
2103 if(!pl || !pl->GetSession() )
2104 continue;
2106 // check online security
2107 if (HasLowerSecurity(pl, 0))
2108 return false;
2110 std::string plNameLink = GetNameLink(pl);
2112 if(pl->IsBeingTeleported())
2114 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2115 continue;
2118 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2119 if (needReportToTarget(pl))
2120 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2122 // stop flight if need
2123 if(pl->isInFlight())
2125 pl->GetMotionMaster()->MovementExpired();
2126 pl->m_taxi.ClearTaxiDestinations();
2128 // save only in non-flight case
2129 else
2130 pl->SaveRecallPosition();
2132 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2135 return true;
2138 //Summon group of player
2139 bool ChatHandler::HandleGroupgoCommand(const char* args)
2141 Player* target;
2142 if(!extractPlayerTarget((char*)args,&target))
2143 return false;
2145 // check online security
2146 if (HasLowerSecurity(target, 0))
2147 return false;
2149 Group *grp = target->GetGroup();
2151 std::string nameLink = GetNameLink(target);
2153 if(!grp)
2155 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2156 SetSentErrorMessage(true);
2157 return false;
2160 Map* gmMap = m_session->GetPlayer()->GetMap();
2161 bool to_instance = gmMap->Instanceable();
2163 // we are in instance, and can summon only player in our group with us as lead
2164 if ( to_instance && (
2165 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2166 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2167 // the last check is a bit excessive, but let it be, just in case
2169 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2170 SetSentErrorMessage(true);
2171 return false;
2174 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2176 Player *pl = itr->getSource();
2178 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2179 continue;
2181 // check online security
2182 if (HasLowerSecurity(pl, 0))
2183 return false;
2185 std::string plNameLink = GetNameLink(pl);
2187 if(pl->IsBeingTeleported()==true)
2189 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2190 SetSentErrorMessage(true);
2191 return false;
2194 if (to_instance)
2196 Map* plMap = pl->GetMap();
2198 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2200 // cannot summon from instance to instance
2201 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2202 SetSentErrorMessage(true);
2203 return false;
2207 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2208 if (needReportToTarget(pl))
2209 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2211 // stop flight if need
2212 if(pl->isInFlight())
2214 pl->GetMotionMaster()->MovementExpired();
2215 pl->m_taxi.ClearTaxiDestinations();
2217 // save only in non-flight case
2218 else
2219 pl->SaveRecallPosition();
2221 // before GM
2222 float x,y,z;
2223 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2224 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2227 return true;
2230 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2232 Player* _player = m_session->GetPlayer();
2234 if (!*args)
2235 return false;
2237 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2238 if (!cNodeId)
2239 return false;
2241 int32 i_nodeId = atoi(cNodeId);
2242 if (!i_nodeId)
2243 return false;
2245 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2246 if (!node)
2248 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2249 SetSentErrorMessage(true);
2250 return false;
2253 if ((node->x == 0.0f && node->y == 0.0f && node->z == 0.0f) ||
2254 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2256 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2257 SetSentErrorMessage(true);
2258 return false;
2261 // stop flight if need
2262 if (_player->isInFlight())
2264 _player->GetMotionMaster()->MovementExpired();
2265 _player->m_taxi.ClearTaxiDestinations();
2267 // save only in non-flight case
2268 else
2269 _player->SaveRecallPosition();
2271 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2272 return true;
2275 //teleport at coordinates
2276 bool ChatHandler::HandleGoXYCommand(const char* args)
2278 if(!*args)
2279 return false;
2281 Player* _player = m_session->GetPlayer();
2283 char* px = strtok((char*)args, " ");
2284 char* py = strtok(NULL, " ");
2285 char* pmapid = strtok(NULL, " ");
2287 if (!px || !py)
2288 return false;
2290 float x = (float)atof(px);
2291 float y = (float)atof(py);
2292 uint32 mapid;
2293 if (pmapid)
2294 mapid = (uint32)atoi(pmapid);
2295 else mapid = _player->GetMapId();
2297 if(!MapManager::IsValidMapCoord(mapid,x,y))
2299 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2300 SetSentErrorMessage(true);
2301 return false;
2304 // stop flight if need
2305 if(_player->isInFlight())
2307 _player->GetMotionMaster()->MovementExpired();
2308 _player->m_taxi.ClearTaxiDestinations();
2310 // save only in non-flight case
2311 else
2312 _player->SaveRecallPosition();
2314 Map const *map = sMapMgr.CreateBaseMap(mapid);
2315 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2317 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2319 return true;
2322 //teleport at coordinates, including Z
2323 bool ChatHandler::HandleGoXYZCommand(const char* args)
2325 if(!*args)
2326 return false;
2328 Player* _player = m_session->GetPlayer();
2330 char* px = strtok((char*)args, " ");
2331 char* py = strtok(NULL, " ");
2332 char* pz = strtok(NULL, " ");
2333 char* pmapid = strtok(NULL, " ");
2335 if (!px || !py || !pz)
2336 return false;
2338 float x = (float)atof(px);
2339 float y = (float)atof(py);
2340 float z = (float)atof(pz);
2341 uint32 mapid;
2342 if (pmapid)
2343 mapid = (uint32)atoi(pmapid);
2344 else
2345 mapid = _player->GetMapId();
2347 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2349 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2350 SetSentErrorMessage(true);
2351 return false;
2354 // stop flight if need
2355 if(_player->isInFlight())
2357 _player->GetMotionMaster()->MovementExpired();
2358 _player->m_taxi.ClearTaxiDestinations();
2360 // save only in non-flight case
2361 else
2362 _player->SaveRecallPosition();
2364 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2366 return true;
2369 //teleport at coordinates
2370 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2372 if(!*args)
2373 return false;
2375 Player* _player = m_session->GetPlayer();
2377 char* px = strtok((char*)args, " ");
2378 char* py = strtok(NULL, " ");
2379 char* tail = strtok(NULL,"");
2381 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2383 if (!px || !py)
2384 return false;
2386 float x = (float)atof(px);
2387 float y = (float)atof(py);
2389 // prevent accept wrong numeric args
2390 if ((x==0.0f && *px!='0') || (y==0.0f && *py!='0'))
2391 return false;
2393 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2395 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2397 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2399 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2400 SetSentErrorMessage(true);
2401 return false;
2404 // update to parent zone if exist (client map show only zones without parents)
2405 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2407 Map const *map = sMapMgr.CreateBaseMap(zoneEntry->mapid);
2409 if(map->Instanceable())
2411 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2412 SetSentErrorMessage(true);
2413 return false;
2416 if (!Zone2MapCoordinates(x,y,zoneEntry->ID))
2418 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2419 SetSentErrorMessage(true);
2420 return false;
2423 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2425 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2426 SetSentErrorMessage(true);
2427 return false;
2430 // stop flight if need
2431 if(_player->isInFlight())
2433 _player->GetMotionMaster()->MovementExpired();
2434 _player->m_taxi.ClearTaxiDestinations();
2436 // save only in non-flight case
2437 else
2438 _player->SaveRecallPosition();
2440 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2441 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2443 return true;
2446 //teleport to grid
2447 bool ChatHandler::HandleGoGridCommand(const char* args)
2449 if(!*args) return false;
2450 Player* _player = m_session->GetPlayer();
2452 char* px = strtok((char*)args, " ");
2453 char* py = strtok(NULL, " ");
2454 char* pmapid = strtok(NULL, " ");
2456 if (!px || !py)
2457 return false;
2459 float grid_x = (float)atof(px);
2460 float grid_y = (float)atof(py);
2461 uint32 mapid;
2462 if (pmapid)
2463 mapid = (uint32)atoi(pmapid);
2464 else mapid = _player->GetMapId();
2466 // center of grid
2467 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2468 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2470 if(!MapManager::IsValidMapCoord(mapid,x,y))
2472 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2473 SetSentErrorMessage(true);
2474 return false;
2477 // stop flight if need
2478 if(_player->isInFlight())
2480 _player->GetMotionMaster()->MovementExpired();
2481 _player->m_taxi.ClearTaxiDestinations();
2483 // save only in non-flight case
2484 else
2485 _player->SaveRecallPosition();
2487 Map const *map = sMapMgr.CreateBaseMap(mapid);
2488 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2489 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2491 return true;
2494 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2496 if(!*args) return false;
2498 uint32 drunklevel = (uint32)atoi(args);
2499 if(drunklevel > 100)
2500 drunklevel = 100;
2502 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2504 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2506 return true;