[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / Level1.cpp
blob19e8225a70e13c6d0f93c8968d8a765faaf2dceb
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Opcodes.h"
27 #include "Chat.h"
28 #include "Log.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
31 #include "Language.h"
32 #include "CellImpl.h"
33 #include "InstanceSaveMgr.h"
34 #include "Util.h"
35 #ifdef _DEBUG_VMAPS
36 #include "VMapFactory.h"
37 #endif
39 //-----------------------Npc Commands-----------------------
40 bool ChatHandler::HandleNpcSayCommand(const char* args)
42 if(!*args)
43 return false;
45 Creature* pCreature = getSelectedCreature();
46 if(!pCreature)
48 SendSysMessage(LANG_SELECT_CREATURE);
49 SetSentErrorMessage(true);
50 return false;
53 pCreature->MonsterSay(args, LANG_UNIVERSAL, 0);
55 return true;
58 bool ChatHandler::HandleNpcYellCommand(const char* args)
60 if(!*args)
61 return false;
63 Creature* pCreature = getSelectedCreature();
64 if(!pCreature)
66 SendSysMessage(LANG_SELECT_CREATURE);
67 SetSentErrorMessage(true);
68 return false;
71 pCreature->MonsterYell(args, LANG_UNIVERSAL, 0);
73 return true;
76 //show text emote by creature in chat
77 bool ChatHandler::HandleNpcTextEmoteCommand(const char* args)
79 if(!*args)
80 return false;
82 Creature* pCreature = getSelectedCreature();
84 if(!pCreature)
86 SendSysMessage(LANG_SELECT_CREATURE);
87 SetSentErrorMessage(true);
88 return false;
91 pCreature->MonsterTextEmote(args, 0);
93 return true;
96 // make npc whisper to player
97 bool ChatHandler::HandleNpcWhisperCommand(const char* args)
99 if(!*args)
100 return false;
102 char* receiver_str = strtok((char*)args, " ");
103 char* text = strtok(NULL, "");
105 uint64 guid = m_session->GetPlayer()->GetSelection();
106 Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid);
108 if(!pCreature || !receiver_str || !text)
110 return false;
113 uint64 receiver_guid= atol(receiver_str);
115 // check online security
116 if (HasLowerSecurity(objmgr.GetPlayer(receiver_guid), 0))
117 return false;
119 pCreature->MonsterWhisper(text,receiver_guid);
121 return true;
123 //----------------------------------------------------------
125 // global announce
126 bool ChatHandler::HandleAnnounceCommand(const char* args)
128 if(!*args)
129 return false;
131 sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
132 return true;
135 //notification player at the screen
136 bool ChatHandler::HandleNotifyCommand(const char* args)
138 if(!*args)
139 return false;
141 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
142 str += args;
144 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
145 data << str;
146 sWorld.SendGlobalMessage(&data);
148 return true;
151 //Enable\Dissable GM Mode
152 bool ChatHandler::HandleGMCommand(const char* args)
154 if(!*args)
156 if(m_session->GetPlayer()->isGameMaster())
157 m_session->SendNotification(LANG_GM_ON);
158 else
159 m_session->SendNotification(LANG_GM_OFF);
160 return true;
163 std::string argstr = (char*)args;
165 if (argstr == "on")
167 m_session->GetPlayer()->SetGameMaster(true);
168 m_session->SendNotification(LANG_GM_ON);
169 #ifdef _DEBUG_VMAPS
170 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
171 vMapManager->processCommand("stoplog");
172 #endif
173 return true;
176 if (argstr == "off")
178 m_session->GetPlayer()->SetGameMaster(false);
179 m_session->SendNotification(LANG_GM_OFF);
180 #ifdef _DEBUG_VMAPS
181 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
182 vMapManager->processCommand("startlog");
183 #endif
184 return true;
187 SendSysMessage(LANG_USE_BOL);
188 SetSentErrorMessage(true);
189 return false;
192 // Enables or disables hiding of the staff badge
193 bool ChatHandler::HandleGMChatCommand(const char* args)
195 if(!*args)
197 if(m_session->GetPlayer()->isGMChat())
198 m_session->SendNotification(LANG_GM_CHAT_ON);
199 else
200 m_session->SendNotification(LANG_GM_CHAT_OFF);
201 return true;
204 std::string argstr = (char*)args;
206 if (argstr == "on")
208 m_session->GetPlayer()->SetGMChat(true);
209 m_session->SendNotification(LANG_GM_CHAT_ON);
210 return true;
213 if (argstr == "off")
215 m_session->GetPlayer()->SetGMChat(false);
216 m_session->SendNotification(LANG_GM_CHAT_OFF);
217 return true;
220 SendSysMessage(LANG_USE_BOL);
221 SetSentErrorMessage(true);
222 return false;
225 //Enable\Dissable Invisible mode
226 bool ChatHandler::HandleGMVisibleCommand(const char* args)
228 if (!*args)
230 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
231 return true;
234 std::string argstr = (char*)args;
236 if (argstr == "on")
238 m_session->GetPlayer()->SetGMVisible(true);
239 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
240 return true;
243 if (argstr == "off")
245 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
246 m_session->GetPlayer()->SetGMVisible(false);
247 return true;
250 SendSysMessage(LANG_USE_BOL);
251 SetSentErrorMessage(true);
252 return false;
257 bool ChatHandler::HandleGPSCommand(const char* args)
259 WorldObject *obj = NULL;
260 if (*args)
262 uint64 guid = extractGuidFromLink((char*)args);
263 if(guid)
264 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
266 if(!obj)
268 SendSysMessage(LANG_PLAYER_NOT_FOUND);
269 SetSentErrorMessage(true);
270 return false;
273 else
275 obj = getSelectedUnit();
277 if(!obj)
279 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
280 SetSentErrorMessage(true);
281 return false;
284 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
285 Cell cell(cell_val);
287 uint32 zone_id, area_id;
288 obj->GetZoneAndAreaId(zone_id,area_id);
290 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
291 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
292 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
294 float zone_x = obj->GetPositionX();
295 float zone_y = obj->GetPositionY();
297 Map2ZoneCoordinates(zone_x,zone_y,zone_id);
299 Map const *map = obj->GetMap();
300 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
301 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
303 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
305 int gx=63-p.x_coord;
306 int gy=63-p.y_coord;
308 uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
309 uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
311 PSendSysMessage(LANG_MAP_POSITION,
312 obj->GetMapId(), (mapEntry ? mapEntry->name[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 target->SetBattleGroundEntryPoint();
398 else if (pMap->IsDungeon())
400 Map* cMap = target->GetMap();
401 if (cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId())
403 // cannot summon from instance to instance
404 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
405 SetSentErrorMessage(true);
406 return false;
409 // we are in instance, and can summon only player in our group with us as lead
410 if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
411 (target->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
412 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()))
413 // the last check is a bit excessive, but let it be, just in case
415 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str());
416 SetSentErrorMessage(true);
417 return false;
421 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),"");
422 if (needReportToTarget(target))
423 ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
425 // stop flight if need
426 if (target->isInFlight())
428 target->GetMotionMaster()->MovementExpired();
429 target->m_taxi.ClearTaxiDestinations();
431 // save only in non-flight case
432 else
433 target->SaveRecallPosition();
435 // before GM
436 float x,y,z;
437 m_session->GetPlayer()->GetClosePoint(x,y,z,target->GetObjectSize());
438 target->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,target->GetOrientation());
440 else
442 // check offline security
443 if (HasLowerSecurity(NULL, target_guid))
444 return false;
446 std::string nameLink = playerLink(target_name);
448 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetMangosString(LANG_OFFLINE));
450 // in point where GM stay
451 Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
452 m_session->GetPlayer()->GetPositionX(),
453 m_session->GetPlayer()->GetPositionY(),
454 m_session->GetPlayer()->GetPositionZ(),
455 m_session->GetPlayer()->GetOrientation(),
456 m_session->GetPlayer()->GetZoneId(),
457 target_guid);
460 return true;
463 //Teleport to Player
464 bool ChatHandler::HandleGonameCommand(const char* args)
466 Player* target;
467 uint64 target_guid;
468 std::string target_name;
469 if (!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
470 return false;
472 Player* _player = m_session->GetPlayer();
473 if (target == _player || target_guid == _player->GetGUID())
475 SendSysMessage(LANG_CANT_TELEPORT_SELF);
476 SetSentErrorMessage(true);
477 return false;
481 if (target)
483 // check online security
484 if (HasLowerSecurity(target, 0))
485 return false;
487 std::string chrNameLink = playerLink(target_name);
489 Map* cMap = target->GetMap();
490 if (cMap->IsBattleGroundOrArena())
492 // only allow if gm mode is on
493 if (!_player->isGameMaster())
495 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str());
496 SetSentErrorMessage(true);
497 return false;
499 // if both players are in different bgs
500 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
502 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str());
503 SetSentErrorMessage(true);
504 return false;
506 // all's well, set bg id
507 // when porting out from the bg, it will be reset to 0
508 _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
509 // remember current position as entry point for return at bg end teleportation
510 _player->SetBattleGroundEntryPoint();
512 else if(cMap->IsDungeon())
514 // we have to go to instance, and can go to player only if:
515 // 1) we are in his group (either as leader or as member)
516 // 2) we are not bound to any group and have GM mode on
517 if (_player->GetGroup())
519 // we are in group, we can go only if we are in the player group
520 if (_player->GetGroup() != target->GetGroup())
522 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str());
523 SetSentErrorMessage(true);
524 return false;
527 else
529 // we are not in group, let's verify our GM mode
530 if (!_player->isGameMaster())
532 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str());
533 SetSentErrorMessage(true);
534 return false;
538 // if the player or the player's group is bound to another instance
539 // the player will not be bound to another one
540 InstancePlayerBind *pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty());
541 if (!pBind)
543 Group *group = _player->GetGroup();
544 // if no bind exists, create a solo bind
545 InstanceGroupBind *gBind = group ? group->GetBoundInstance(target->GetMapId(), target->GetDifficulty()) : NULL;
546 // if no bind exists, create a solo bind
547 if (!gBind)
548 if (InstanceSave *save = sInstanceSaveManager.GetInstanceSave(target->GetInstanceId()))
549 _player->BindToInstance(save, !save->CanReset());
552 _player->SetDifficulty(target->GetDifficulty());
555 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
556 if (needReportToTarget(target))
557 ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
559 // stop flight if need
560 if (_player->isInFlight())
562 _player->GetMotionMaster()->MovementExpired();
563 _player->m_taxi.ClearTaxiDestinations();
565 // save only in non-flight case
566 else
567 _player->SaveRecallPosition();
569 // to point to see at target with same orientation
570 float x,y,z;
571 target->GetContactPoint(_player,x,y,z);
573 _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
575 else
577 // check offline security
578 if (HasLowerSecurity(NULL, target_guid))
579 return false;
581 std::string nameLink = playerLink(target_name);
583 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
585 // to point where player stay (if loaded)
586 float x,y,z,o;
587 uint32 map;
588 bool in_flight;
589 if (!Player::LoadPositionFromDB(map,x,y,z,o,in_flight,target_guid))
590 return false;
592 // stop flight if need
593 if (_player->isInFlight())
595 _player->GetMotionMaster()->MovementExpired();
596 _player->m_taxi.ClearTaxiDestinations();
598 // save only in non-flight case
599 else
600 _player->SaveRecallPosition();
602 _player->TeleportTo(map, x, y, z,_player->GetOrientation());
605 return true;
608 // Teleport player to last position
609 bool ChatHandler::HandleRecallCommand(const char* args)
611 Player* target;
612 if(!extractPlayerTarget((char*)args,&target))
613 return false;
615 // check online security
616 if (HasLowerSecurity(target, 0))
617 return false;
619 if (target->IsBeingTeleported())
621 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
622 SetSentErrorMessage(true);
623 return false;
626 // stop flight if need
627 if(target->isInFlight())
629 target->GetMotionMaster()->MovementExpired();
630 target->m_taxi.ClearTaxiDestinations();
633 target->TeleportTo(target->m_recallMap, target->m_recallX, target->m_recallY, target->m_recallZ, target->m_recallO);
634 return true;
637 //Edit Player KnownTitles
638 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
640 if(!*args)
641 return false;
643 uint64 titles = 0;
645 sscanf((char*)args, UI64FMTD, &titles);
647 Player *chr = getSelectedPlayer();
648 if (!chr)
650 SendSysMessage(LANG_NO_CHAR_SELECTED);
651 SetSentErrorMessage(true);
652 return false;
655 // check online security
656 if (HasLowerSecurity(chr, 0))
657 return false;
659 uint64 titles2 = titles;
661 for(int i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
662 if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
663 titles2 &= ~(uint64(1) << tEntry->bit_index);
665 titles &= ~titles2; // remove not existed titles
667 chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
668 SendSysMessage(LANG_DONE);
670 return true;
673 //Edit Player HP
674 bool ChatHandler::HandleModifyHPCommand(const char* args)
676 if(!*args)
677 return false;
679 // char* pHp = strtok((char*)args, " ");
680 // if (!pHp)
681 // return false;
683 // char* pHpMax = strtok(NULL, " ");
684 // if (!pHpMax)
685 // return false;
687 // int32 hpm = atoi(pHpMax);
688 // int32 hp = atoi(pHp);
690 int32 hp = atoi((char*)args);
691 int32 hpm = atoi((char*)args);
693 if (hp <= 0 || hpm <= 0 || hpm < hp)
695 SendSysMessage(LANG_BAD_VALUE);
696 SetSentErrorMessage(true);
697 return false;
700 Player *chr = getSelectedPlayer();
701 if (chr == NULL)
703 SendSysMessage(LANG_NO_CHAR_SELECTED);
704 SetSentErrorMessage(true);
705 return false;
708 // check online security
709 if (HasLowerSecurity(chr, 0))
710 return false;
712 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
713 if (needReportToTarget(chr))
714 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
716 chr->SetMaxHealth( hpm );
717 chr->SetHealth( hp );
719 return true;
722 //Edit Player Mana
723 bool ChatHandler::HandleModifyManaCommand(const char* args)
725 if(!*args)
726 return false;
728 // char* pmana = strtok((char*)args, " ");
729 // if (!pmana)
730 // return false;
732 // char* pmanaMax = strtok(NULL, " ");
733 // if (!pmanaMax)
734 // return false;
736 // int32 manam = atoi(pmanaMax);
737 // int32 mana = atoi(pmana);
738 int32 mana = atoi((char*)args);
739 int32 manam = atoi((char*)args);
741 if (mana <= 0 || manam <= 0 || manam < mana)
743 SendSysMessage(LANG_BAD_VALUE);
744 SetSentErrorMessage(true);
745 return false;
748 Player *chr = getSelectedPlayer();
749 if (chr == NULL)
751 SendSysMessage(LANG_NO_CHAR_SELECTED);
752 SetSentErrorMessage(true);
753 return false;
756 // check online security
757 if (HasLowerSecurity(chr, 0))
758 return false;
760 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
761 if (needReportToTarget(chr))
762 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
764 chr->SetMaxPower(POWER_MANA,manam );
765 chr->SetPower(POWER_MANA, mana );
767 return true;
770 //Edit Player Energy
771 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
773 if(!*args)
774 return false;
776 // char* pmana = strtok((char*)args, " ");
777 // if (!pmana)
778 // return false;
780 // char* pmanaMax = strtok(NULL, " ");
781 // if (!pmanaMax)
782 // return false;
784 // int32 manam = atoi(pmanaMax);
785 // int32 mana = atoi(pmana);
787 int32 energy = atoi((char*)args)*10;
788 int32 energym = atoi((char*)args)*10;
790 if (energy <= 0 || energym <= 0 || energym < energy)
792 SendSysMessage(LANG_BAD_VALUE);
793 SetSentErrorMessage(true);
794 return false;
797 Player *chr = getSelectedPlayer();
798 if (!chr)
800 SendSysMessage(LANG_NO_CHAR_SELECTED);
801 SetSentErrorMessage(true);
802 return false;
805 // check online security
806 if (HasLowerSecurity(chr, 0))
807 return false;
809 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10);
810 if (needReportToTarget(chr))
811 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10);
813 chr->SetMaxPower(POWER_ENERGY,energym );
814 chr->SetPower(POWER_ENERGY, energy );
816 sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
818 return true;
821 //Edit Player Rage
822 bool ChatHandler::HandleModifyRageCommand(const char* args)
824 if(!*args)
825 return false;
827 // char* pmana = strtok((char*)args, " ");
828 // if (!pmana)
829 // return false;
831 // char* pmanaMax = strtok(NULL, " ");
832 // if (!pmanaMax)
833 // return false;
835 // int32 manam = atoi(pmanaMax);
836 // int32 mana = atoi(pmana);
838 int32 rage = atoi((char*)args)*10;
839 int32 ragem = atoi((char*)args)*10;
841 if (rage <= 0 || ragem <= 0 || ragem < rage)
843 SendSysMessage(LANG_BAD_VALUE);
844 SetSentErrorMessage(true);
845 return false;
848 Player *chr = getSelectedPlayer();
849 if (chr == NULL)
851 SendSysMessage(LANG_NO_CHAR_SELECTED);
852 SetSentErrorMessage(true);
853 return false;
856 // check online security
857 if (HasLowerSecurity(chr, 0))
858 return false;
860 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10);
861 if (needReportToTarget(chr))
862 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10);
864 chr->SetMaxPower(POWER_RAGE,ragem );
865 chr->SetPower(POWER_RAGE, rage );
867 return true;
870 // Edit Player Runic Power
871 bool ChatHandler::HandleModifyRunicPowerCommand(const char* args)
873 if(!*args)
874 return false;
876 int32 rune = atoi((char*)args)*10;
877 int32 runem = atoi((char*)args)*10;
879 if (rune <= 0 || runem <= 0 || runem < rune)
881 SendSysMessage(LANG_BAD_VALUE);
882 SetSentErrorMessage(true);
883 return false;
886 Player *chr = getSelectedPlayer();
887 if (chr == NULL)
889 SendSysMessage(LANG_NO_CHAR_SELECTED);
890 SetSentErrorMessage(true);
891 return false;
894 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10);
895 if (needReportToTarget(chr))
896 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10);
898 chr->SetMaxPower(POWER_RUNIC_POWER,runem );
899 chr->SetPower(POWER_RUNIC_POWER, rune );
901 return true;
904 //Edit Player Faction
905 bool ChatHandler::HandleModifyFactionCommand(const char* args)
907 if(!*args)
908 return false;
910 char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
912 Creature* chr = getSelectedCreature();
913 if(!chr)
915 SendSysMessage(LANG_SELECT_CREATURE);
916 SetSentErrorMessage(true);
917 return false;
920 if(!pfactionid)
922 if(chr)
924 uint32 factionid = chr->getFaction();
925 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
926 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
927 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
928 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
930 return true;
933 if( !chr )
935 SendSysMessage(LANG_NO_CHAR_SELECTED);
936 SetSentErrorMessage(true);
937 return false;
940 uint32 factionid = atoi(pfactionid);
941 uint32 flag;
943 char *pflag = strtok(NULL, " ");
944 if (!pflag)
945 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
946 else
947 flag = atoi(pflag);
949 char* pnpcflag = strtok(NULL, " ");
951 uint32 npcflag;
952 if(!pnpcflag)
953 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
954 else
955 npcflag = atoi(pnpcflag);
957 char* pdyflag = strtok(NULL, " ");
959 uint32 dyflag;
960 if(!pdyflag)
961 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
962 else
963 dyflag = atoi(pdyflag);
965 if(!sFactionTemplateStore.LookupEntry(factionid))
967 PSendSysMessage(LANG_WRONG_FACTION, factionid);
968 SetSentErrorMessage(true);
969 return false;
972 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
974 chr->setFaction(factionid);
975 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
976 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
977 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
979 return true;
982 //Edit Player Spell
983 bool ChatHandler::HandleModifySpellCommand(const char* args)
985 if(!*args) return false;
986 char* pspellflatid = strtok((char*)args, " ");
987 if (!pspellflatid)
988 return false;
990 char* pop = strtok(NULL, " ");
991 if (!pop)
992 return false;
994 char* pval = strtok(NULL, " ");
995 if (!pval)
996 return false;
998 uint16 mark;
1000 char* pmark = strtok(NULL, " ");
1002 uint8 spellflatid = atoi(pspellflatid);
1003 uint8 op = atoi(pop);
1004 uint16 val = atoi(pval);
1005 if(!pmark)
1006 mark = 65535;
1007 else
1008 mark = atoi(pmark);
1010 Player *chr = getSelectedPlayer();
1011 if (chr == NULL)
1013 SendSysMessage(LANG_NO_CHAR_SELECTED);
1014 SetSentErrorMessage(true);
1015 return false;
1018 // check online security
1019 if (HasLowerSecurity(chr, 0))
1020 return false;
1022 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str());
1023 if (needReportToTarget(chr))
1024 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark);
1026 WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
1027 data << uint8(spellflatid);
1028 data << uint8(op);
1029 data << uint16(val);
1030 data << uint16(mark);
1031 chr->GetSession()->SendPacket(&data);
1033 return true;
1036 //Edit Player TP
1037 bool ChatHandler::HandleModifyTalentCommand (const char* args)
1039 if (!*args)
1040 return false;
1042 int tp = atoi((char*)args);
1043 if (tp < 0)
1044 return false;
1046 Unit* target = getSelectedUnit();
1047 if(!target)
1049 SendSysMessage(LANG_NO_CHAR_SELECTED);
1050 SetSentErrorMessage(true);
1051 return false;
1054 if(target->GetTypeId()==TYPEID_PLAYER)
1056 // check online security
1057 if (HasLowerSecurity((Player*)target, 0))
1058 return false;
1060 ((Player*)target)->SetFreeTalentPoints(tp);
1061 ((Player*)target)->SendTalentsInfoData(false);
1062 return true;
1064 else if(((Creature*)target)->isPet())
1066 Unit *owner = target->GetOwner();
1067 if(owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet *)target)->IsPermanentPetFor((Player*)owner))
1069 // check online security
1070 if (HasLowerSecurity((Player*)owner, 0))
1071 return false;
1073 ((Pet *)target)->SetFreeTalentPoints(tp);
1074 ((Player*)owner)->SendTalentsInfoData(true);
1075 return true;
1079 SendSysMessage(LANG_NO_CHAR_SELECTED);
1080 SetSentErrorMessage(true);
1081 return false;
1084 //Enable On\OFF all taxi paths
1085 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
1087 if (!*args)
1089 SendSysMessage(LANG_USE_BOL);
1090 SetSentErrorMessage(true);
1091 return false;
1094 std::string argstr = (char*)args;
1096 Player *chr = getSelectedPlayer();
1097 if (!chr)
1099 chr=m_session->GetPlayer();
1102 // check online security
1103 else if (HasLowerSecurity(chr, 0))
1104 return false;
1106 if (argstr == "on")
1108 chr->SetTaxiCheater(true);
1109 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1110 if (needReportToTarget(chr))
1111 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1112 return true;
1115 if (argstr == "off")
1117 chr->SetTaxiCheater(false);
1118 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1119 if (needReportToTarget(chr))
1120 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1122 return true;
1125 SendSysMessage(LANG_USE_BOL);
1126 SetSentErrorMessage(true);
1127 return false;
1130 //Edit Player Aspeed
1131 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1133 if (!*args)
1134 return false;
1136 float ASpeed = (float)atof((char*)args);
1138 if (ASpeed > 10 || ASpeed < 0.1)
1140 SendSysMessage(LANG_BAD_VALUE);
1141 SetSentErrorMessage(true);
1142 return false;
1145 Player *chr = getSelectedPlayer();
1146 if (chr == NULL)
1148 SendSysMessage(LANG_NO_CHAR_SELECTED);
1149 SetSentErrorMessage(true);
1150 return false;
1153 // check online security
1154 if (HasLowerSecurity(chr, 0))
1155 return false;
1157 std::string chrNameLink = GetNameLink(chr);
1159 if(chr->isInFlight())
1161 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1162 SetSentErrorMessage(true);
1163 return false;
1166 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str());
1167 if (needReportToTarget(chr))
1168 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed);
1170 chr->SetSpeed(MOVE_WALK, ASpeed,true);
1171 chr->SetSpeed(MOVE_RUN, ASpeed,true);
1172 chr->SetSpeed(MOVE_SWIM, ASpeed,true);
1173 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
1174 chr->SetSpeed(MOVE_FLIGHT, ASpeed,true);
1175 return true;
1178 //Edit Player Speed
1179 bool ChatHandler::HandleModifySpeedCommand(const char* args)
1181 if (!*args)
1182 return false;
1184 float Speed = (float)atof((char*)args);
1186 if (Speed > 10 || Speed < 0.1)
1188 SendSysMessage(LANG_BAD_VALUE);
1189 SetSentErrorMessage(true);
1190 return false;
1193 Player *chr = getSelectedPlayer();
1194 if (chr == NULL)
1196 SendSysMessage(LANG_NO_CHAR_SELECTED);
1197 SetSentErrorMessage(true);
1198 return false;
1201 // check online security
1202 if (HasLowerSecurity(chr, 0))
1203 return false;
1205 std::string chrNameLink = GetNameLink(chr);
1207 if(chr->isInFlight())
1209 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1210 SetSentErrorMessage(true);
1211 return false;
1214 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str());
1215 if (needReportToTarget(chr))
1216 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed);
1218 chr->SetSpeed(MOVE_RUN,Speed,true);
1220 return true;
1223 //Edit Player Swim Speed
1224 bool ChatHandler::HandleModifySwimCommand(const char* args)
1226 if (!*args)
1227 return false;
1229 float Swim = (float)atof((char*)args);
1231 if (Swim > 10.0f || Swim < 0.01f)
1233 SendSysMessage(LANG_BAD_VALUE);
1234 SetSentErrorMessage(true);
1235 return false;
1238 Player *chr = getSelectedPlayer();
1239 if (chr == NULL)
1241 SendSysMessage(LANG_NO_CHAR_SELECTED);
1242 SetSentErrorMessage(true);
1243 return false;
1246 // check online security
1247 if (HasLowerSecurity(chr, 0))
1248 return false;
1250 std::string chrNameLink = GetNameLink(chr);
1252 if(chr->isInFlight())
1254 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1255 SetSentErrorMessage(true);
1256 return false;
1259 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str());
1260 if (needReportToTarget(chr))
1261 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim);
1263 chr->SetSpeed(MOVE_SWIM,Swim,true);
1265 return true;
1268 //Edit Player Walk Speed
1269 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1271 if (!*args)
1272 return false;
1274 float BSpeed = (float)atof((char*)args);
1276 if (BSpeed > 10.0f || BSpeed < 0.1f)
1278 SendSysMessage(LANG_BAD_VALUE);
1279 SetSentErrorMessage(true);
1280 return false;
1283 Player *chr = getSelectedPlayer();
1284 if (chr == NULL)
1286 SendSysMessage(LANG_NO_CHAR_SELECTED);
1287 SetSentErrorMessage(true);
1288 return false;
1291 // check online security
1292 if (HasLowerSecurity(chr, 0))
1293 return false;
1295 std::string chrNameLink = GetNameLink(chr);
1297 if(chr->isInFlight())
1299 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str());
1300 SetSentErrorMessage(true);
1301 return false;
1304 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str());
1305 if (needReportToTarget(chr))
1306 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed);
1308 chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true);
1310 return true;
1313 //Edit Player Fly
1314 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1316 if (!*args)
1317 return false;
1319 float FSpeed = (float)atof((char*)args);
1321 if (FSpeed > 10.0f || FSpeed < 0.1f)
1323 SendSysMessage(LANG_BAD_VALUE);
1324 SetSentErrorMessage(true);
1325 return false;
1328 Player *chr = getSelectedPlayer();
1329 if (chr == NULL)
1331 SendSysMessage(LANG_NO_CHAR_SELECTED);
1332 SetSentErrorMessage(true);
1333 return false;
1336 // check online security
1337 if (HasLowerSecurity(chr, 0))
1338 return false;
1340 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str());
1341 if (needReportToTarget(chr))
1342 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed);
1344 chr->SetSpeed(MOVE_FLIGHT,FSpeed,true);
1346 return true;
1349 //Edit Player Scale
1350 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1352 if (!*args)
1353 return false;
1355 float Scale = (float)atof((char*)args);
1356 if (Scale > 3.0f || Scale <= 0.0f)
1358 SendSysMessage(LANG_BAD_VALUE);
1359 SetSentErrorMessage(true);
1360 return false;
1363 Player *chr = getSelectedPlayer();
1364 if (chr == NULL)
1366 SendSysMessage(LANG_NO_CHAR_SELECTED);
1367 SetSentErrorMessage(true);
1368 return false;
1371 // check online security
1372 if (HasLowerSecurity(chr, 0))
1373 return false;
1375 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str());
1376 if (needReportToTarget(chr))
1377 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1379 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1381 return true;
1384 //Enable Player mount
1385 bool ChatHandler::HandleModifyMountCommand(const char* args)
1387 if(!*args)
1388 return false;
1390 uint16 mId = 1147;
1391 float speed = (float)15;
1392 uint32 num = 0;
1394 num = atoi((char*)args);
1395 switch(num)
1397 case 1:
1398 mId=14340;
1399 break;
1400 case 2:
1401 mId=4806;
1402 break;
1403 case 3:
1404 mId=6471;
1405 break;
1406 case 4:
1407 mId=12345;
1408 break;
1409 case 5:
1410 mId=6472;
1411 break;
1412 case 6:
1413 mId=6473;
1414 break;
1415 case 7:
1416 mId=10670;
1417 break;
1418 case 8:
1419 mId=10719;
1420 break;
1421 case 9:
1422 mId=10671;
1423 break;
1424 case 10:
1425 mId=10672;
1426 break;
1427 case 11:
1428 mId=10720;
1429 break;
1430 case 12:
1431 mId=14349;
1432 break;
1433 case 13:
1434 mId=11641;
1435 break;
1436 case 14:
1437 mId=12244;
1438 break;
1439 case 15:
1440 mId=12242;
1441 break;
1442 case 16:
1443 mId=14578;
1444 break;
1445 case 17:
1446 mId=14579;
1447 break;
1448 case 18:
1449 mId=14349;
1450 break;
1451 case 19:
1452 mId=12245;
1453 break;
1454 case 20:
1455 mId=14335;
1456 break;
1457 case 21:
1458 mId=207;
1459 break;
1460 case 22:
1461 mId=2328;
1462 break;
1463 case 23:
1464 mId=2327;
1465 break;
1466 case 24:
1467 mId=2326;
1468 break;
1469 case 25:
1470 mId=14573;
1471 break;
1472 case 26:
1473 mId=14574;
1474 break;
1475 case 27:
1476 mId=14575;
1477 break;
1478 case 28:
1479 mId=604;
1480 break;
1481 case 29:
1482 mId=1166;
1483 break;
1484 case 30:
1485 mId=2402;
1486 break;
1487 case 31:
1488 mId=2410;
1489 break;
1490 case 32:
1491 mId=2409;
1492 break;
1493 case 33:
1494 mId=2408;
1495 break;
1496 case 34:
1497 mId=2405;
1498 break;
1499 case 35:
1500 mId=14337;
1501 break;
1502 case 36:
1503 mId=6569;
1504 break;
1505 case 37:
1506 mId=10661;
1507 break;
1508 case 38:
1509 mId=10666;
1510 break;
1511 case 39:
1512 mId=9473;
1513 break;
1514 case 40:
1515 mId=9476;
1516 break;
1517 case 41:
1518 mId=9474;
1519 break;
1520 case 42:
1521 mId=14374;
1522 break;
1523 case 43:
1524 mId=14376;
1525 break;
1526 case 44:
1527 mId=14377;
1528 break;
1529 case 45:
1530 mId=2404;
1531 break;
1532 case 46:
1533 mId=2784;
1534 break;
1535 case 47:
1536 mId=2787;
1537 break;
1538 case 48:
1539 mId=2785;
1540 break;
1541 case 49:
1542 mId=2736;
1543 break;
1544 case 50:
1545 mId=2786;
1546 break;
1547 case 51:
1548 mId=14347;
1549 break;
1550 case 52:
1551 mId=14346;
1552 break;
1553 case 53:
1554 mId=14576;
1555 break;
1556 case 54:
1557 mId=9695;
1558 break;
1559 case 55:
1560 mId=9991;
1561 break;
1562 case 56:
1563 mId=6448;
1564 break;
1565 case 57:
1566 mId=6444;
1567 break;
1568 case 58:
1569 mId=6080;
1570 break;
1571 case 59:
1572 mId=6447;
1573 break;
1574 case 60:
1575 mId=4805;
1576 break;
1577 case 61:
1578 mId=9714;
1579 break;
1580 case 62:
1581 mId=6448;
1582 break;
1583 case 63:
1584 mId=6442;
1585 break;
1586 case 64:
1587 mId=14632;
1588 break;
1589 case 65:
1590 mId=14332;
1591 break;
1592 case 66:
1593 mId=14331;
1594 break;
1595 case 67:
1596 mId=8469;
1597 break;
1598 case 68:
1599 mId=2830;
1600 break;
1601 case 69:
1602 mId=2346;
1603 break;
1604 default:
1605 SendSysMessage(LANG_NO_MOUNT);
1606 SetSentErrorMessage(true);
1607 return false;
1610 Player *chr = getSelectedPlayer();
1611 if (chr == NULL)
1613 SendSysMessage(LANG_NO_CHAR_SELECTED);
1614 SetSentErrorMessage(true);
1615 return false;
1618 // check online security
1619 if (HasLowerSecurity(chr, 0))
1620 return false;
1622 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1623 if (needReportToTarget(chr))
1624 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1626 chr->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP);
1627 chr->Mount(mId);
1629 WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1630 data.append(chr->GetPackGUID());
1631 data << (uint32)0;
1632 data << (uint8)0; //new 2.1.0
1633 data << float(speed);
1634 chr->SendMessageToSet( &data, true );
1636 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1637 data.append(chr->GetPackGUID());
1638 data << (uint32)0;
1639 data << float(speed);
1640 chr->SendMessageToSet( &data, true );
1642 return true;
1645 //Edit Player money
1646 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1648 if (!*args)
1649 return false;
1651 Player *chr = getSelectedPlayer();
1652 if (chr == NULL)
1654 SendSysMessage(LANG_NO_CHAR_SELECTED);
1655 SetSentErrorMessage(true);
1656 return false;
1659 // check online security
1660 if (HasLowerSecurity(chr, 0))
1661 return false;
1663 int32 addmoney = atoi((char*)args);
1665 uint32 moneyuser = chr->GetMoney();
1667 if (addmoney < 0)
1669 int32 newmoney = int32(moneyuser) + addmoney;
1671 sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1672 if (newmoney <= 0 )
1674 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1675 if (needReportToTarget(chr))
1676 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1678 chr->SetMoney(0);
1680 else
1682 if (newmoney > MAX_MONEY_AMOUNT)
1683 newmoney = MAX_MONEY_AMOUNT;
1685 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str());
1686 if (needReportToTarget(chr))
1687 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney));
1688 chr->SetMoney( newmoney );
1691 else
1693 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str());
1694 if (needReportToTarget(chr))
1695 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney);
1697 if (addmoney >=MAX_MONEY_AMOUNT)
1698 chr->SetMoney(MAX_MONEY_AMOUNT);
1699 else
1700 chr->ModifyMoney( addmoney );
1703 sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1705 return true;
1708 //Edit Unit field
1709 bool ChatHandler::HandleModifyBitCommand(const char* args)
1711 if( !*args )
1712 return false;
1714 Unit *unit = getSelectedUnit();
1715 if (!unit)
1717 SendSysMessage(LANG_NO_CHAR_SELECTED);
1718 SetSentErrorMessage(true);
1719 return false;
1722 // check online security
1723 if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0))
1724 return false;
1726 char* pField = strtok((char*)args, " ");
1727 if (!pField)
1728 return false;
1730 char* pBit = strtok(NULL, " ");
1731 if (!pBit)
1732 return false;
1734 uint16 field = atoi(pField);
1735 uint32 bit = atoi(pBit);
1737 if (field < OBJECT_END || field >= unit->GetValuesCount())
1739 SendSysMessage(LANG_BAD_VALUE);
1740 SetSentErrorMessage(true);
1741 return false;
1743 if (bit < 1 || bit > 32)
1745 SendSysMessage(LANG_BAD_VALUE);
1746 SetSentErrorMessage(true);
1747 return false;
1750 if ( unit->HasFlag( field, (1<<(bit-1)) ) )
1752 unit->RemoveFlag( field, (1<<(bit-1)) );
1753 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1755 else
1757 unit->SetFlag( field, (1<<(bit-1)) );
1758 PSendSysMessage(LANG_SET_BIT, bit, field);
1760 return true;
1763 bool ChatHandler::HandleModifyHonorCommand (const char* args)
1765 if (!*args)
1766 return false;
1768 Player *target = getSelectedPlayer();
1769 if(!target)
1771 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1772 SetSentErrorMessage(true);
1773 return false;
1776 // check online security
1777 if (HasLowerSecurity(target, 0))
1778 return false;
1780 int32 amount = (uint32)atoi(args);
1782 target->ModifyHonorPoints(amount);
1784 PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints());
1786 return true;
1789 bool ChatHandler::HandleTeleCommand(const char * args)
1791 if(!*args)
1792 return false;
1794 Player* _player = m_session->GetPlayer();
1796 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1797 GameTele const* tele = extractGameTeleFromLink((char*)args);
1799 if (!tele)
1801 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1802 SetSentErrorMessage(true);
1803 return false;
1806 // stop flight if need
1807 if(_player->isInFlight())
1809 _player->GetMotionMaster()->MovementExpired();
1810 _player->m_taxi.ClearTaxiDestinations();
1812 // save only in non-flight case
1813 else
1814 _player->SaveRecallPosition();
1816 _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1817 return true;
1820 bool ChatHandler::HandleLookupAreaCommand(const char* args)
1822 if (!*args)
1823 return false;
1825 std::string namepart = args;
1826 std::wstring wnamepart;
1828 if (!Utf8toWStr (namepart,wnamepart))
1829 return false;
1831 uint32 counter = 0; // Counter for figure out that we found smth.
1833 // converting string that we try to find to lower case
1834 wstrToLower (wnamepart);
1836 // Search in AreaTable.dbc
1837 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1839 AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1840 if (areaEntry)
1842 int loc = GetSessionDbcLocale ();
1843 std::string name = areaEntry->area_name[loc];
1844 if (name.empty())
1845 continue;
1847 if (!Utf8FitTo (name, wnamepart))
1849 loc = 0;
1850 for(; loc < MAX_LOCALE; ++loc)
1852 if (loc==GetSessionDbcLocale ())
1853 continue;
1855 name = areaEntry->area_name[loc];
1856 if (name.empty ())
1857 continue;
1859 if (Utf8FitTo (name, wnamepart))
1860 break;
1864 if (loc < MAX_LOCALE)
1866 // send area in "id - [name]" format
1867 std::ostringstream ss;
1868 if (m_session)
1869 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1870 else
1871 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1873 SendSysMessage (ss.str ().c_str());
1875 ++counter;
1880 if (counter == 0) // if counter == 0 then we found nth
1881 SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1883 return true;
1886 //Find tele in game_tele order by name
1887 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1889 if(!*args)
1891 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1892 SetSentErrorMessage(true);
1893 return false;
1896 char const* str = strtok((char*)args, " ");
1897 if(!str)
1898 return false;
1900 std::string namepart = str;
1901 std::wstring wnamepart;
1903 if(!Utf8toWStr(namepart,wnamepart))
1904 return false;
1906 // converting string that we try to find to lower case
1907 wstrToLower( wnamepart );
1909 std::ostringstream reply;
1911 GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1912 for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1914 GameTele const* tele = &itr->second;
1916 if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1917 continue;
1919 if (m_session)
1920 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1921 else
1922 reply << " " << itr->first << " " << tele->name << "\n";
1925 if(reply.str().empty())
1926 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1927 else
1928 PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1930 return true;
1933 //Enable\Dissable accept whispers (for GM)
1934 bool ChatHandler::HandleWhispersCommand(const char* args)
1936 if(!*args)
1938 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1939 return true;
1942 std::string argstr = (char*)args;
1943 // whisper on
1944 if (argstr == "on")
1946 m_session->GetPlayer()->SetAcceptWhispers(true);
1947 SendSysMessage(LANG_COMMAND_WHISPERON);
1948 return true;
1951 // whisper off
1952 if (argstr == "off")
1954 m_session->GetPlayer()->SetAcceptWhispers(false);
1955 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1956 return true;
1959 SendSysMessage(LANG_USE_BOL);
1960 SetSentErrorMessage(true);
1961 return false;
1964 //Save all players in the world
1965 bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1967 ObjectAccessor::Instance().SaveAllPlayers();
1968 SendSysMessage(LANG_PLAYERS_SAVED);
1969 return true;
1972 //Send mail by command
1973 bool ChatHandler::HandleSendMailCommand(const char* args)
1975 // format: name "subject text" "mail text"
1976 Player* target;
1977 uint64 target_guid;
1978 std::string target_name;
1979 if(!extractPlayerTarget((char*)args,&target,&target_guid,&target_name))
1980 return false;
1982 char* tail1 = strtok(NULL, "");
1983 if(!tail1)
1984 return false;
1986 char* msgSubject = extractQuotedArg(tail1);
1987 if (!msgSubject)
1988 return false;
1990 char* tail2 = strtok(NULL, "");
1991 if(!tail2)
1992 return false;
1994 char* msgText = extractQuotedArg(tail2);
1995 if (!msgText)
1996 return false;
1998 // msgSubject, msgText isn't NUL after prev. check
1999 std::string subject = msgSubject;
2000 std::string text = msgText;
2002 // from console show not existed sender
2003 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
2005 uint32 messagetype = MAIL_NORMAL;
2006 uint32 stationery = MAIL_STATIONERY_GM;
2007 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
2009 WorldSession::SendMailTo(target,messagetype, stationery, sender_guidlo, GUID_LOPART(target_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE);
2011 std::string nameLink = playerLink(target_name);
2012 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
2013 return true;
2016 // teleport player to given game_tele.entry
2017 bool ChatHandler::HandleTeleNameCommand(const char * args)
2019 char* nameStr;
2020 char* teleStr;
2021 extractOptFirstArg((char*)args,&nameStr,&teleStr);
2022 if(!teleStr)
2023 return false;
2025 Player* target;
2026 uint64 target_guid;
2027 std::string target_name;
2028 if(!extractPlayerTarget(nameStr,&target,&target_guid,&target_name))
2029 return false;
2031 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2032 GameTele const* tele = extractGameTeleFromLink(teleStr);
2033 if(!tele)
2035 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2036 SetSentErrorMessage(true);
2037 return false;
2040 if (target)
2042 // check online security
2043 if (HasLowerSecurity(target, 0))
2044 return false;
2046 std::string chrNameLink = playerLink(target_name);
2048 if(target->IsBeingTeleported()==true)
2050 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
2051 SetSentErrorMessage(true);
2052 return false;
2055 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str());
2056 if (needReportToTarget(target))
2057 ChatHandler(target).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
2059 // stop flight if need
2060 if(target->isInFlight())
2062 target->GetMotionMaster()->MovementExpired();
2063 target->m_taxi.ClearTaxiDestinations();
2065 // save only in non-flight case
2066 else
2067 target->SaveRecallPosition();
2069 target->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2071 else
2073 // check offline security
2074 if (HasLowerSecurity(NULL, target_guid))
2075 return false;
2077 std::string nameLink = playerLink(target_name);
2079 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2080 Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,
2081 MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),target_guid);
2084 return true;
2087 //Teleport group to given game_tele.entry
2088 bool ChatHandler::HandleTeleGroupCommand(const char * args)
2090 if(!*args)
2091 return false;
2093 Player *player = getSelectedPlayer();
2094 if (!player)
2096 SendSysMessage(LANG_NO_CHAR_SELECTED);
2097 SetSentErrorMessage(true);
2098 return false;
2101 // check online security
2102 if (HasLowerSecurity(player, 0))
2103 return false;
2105 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2106 GameTele const* tele = extractGameTeleFromLink((char*)args);
2107 if(!tele)
2109 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2110 SetSentErrorMessage(true);
2111 return false;
2114 std::string nameLink = GetNameLink(player);
2116 Group *grp = player->GetGroup();
2117 if(!grp)
2119 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2120 SetSentErrorMessage(true);
2121 return false;
2124 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2126 Player *pl = itr->getSource();
2128 if(!pl || !pl->GetSession() )
2129 continue;
2131 // check online security
2132 if (HasLowerSecurity(pl, 0))
2133 return false;
2135 std::string plNameLink = GetNameLink(pl);
2137 if(pl->IsBeingTeleported())
2139 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2140 continue;
2143 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str());
2144 if (needReportToTarget(pl))
2145 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
2147 // stop flight if need
2148 if(pl->isInFlight())
2150 pl->GetMotionMaster()->MovementExpired();
2151 pl->m_taxi.ClearTaxiDestinations();
2153 // save only in non-flight case
2154 else
2155 pl->SaveRecallPosition();
2157 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2160 return true;
2163 //Summon group of player
2164 bool ChatHandler::HandleGroupgoCommand(const char* args)
2166 Player* target;
2167 if(!extractPlayerTarget((char*)args,&target))
2168 return false;
2170 // check online security
2171 if (HasLowerSecurity(target, 0))
2172 return false;
2174 Group *grp = target->GetGroup();
2176 std::string nameLink = GetNameLink(target);
2178 if(!grp)
2180 PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str());
2181 SetSentErrorMessage(true);
2182 return false;
2185 Map* gmMap = m_session->GetPlayer()->GetMap();
2186 bool to_instance = gmMap->Instanceable();
2188 // we are in instance, and can summon only player in our group with us as lead
2189 if ( to_instance && (
2190 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2191 (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2192 // the last check is a bit excessive, but let it be, just in case
2194 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2195 SetSentErrorMessage(true);
2196 return false;
2199 for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2201 Player *pl = itr->getSource();
2203 if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2204 continue;
2206 // check online security
2207 if (HasLowerSecurity(pl, 0))
2208 return false;
2210 std::string plNameLink = GetNameLink(pl);
2212 if(pl->IsBeingTeleported()==true)
2214 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
2215 SetSentErrorMessage(true);
2216 return false;
2219 if (to_instance)
2221 Map* plMap = pl->GetMap();
2223 if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2225 // cannot summon from instance to instance
2226 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str());
2227 SetSentErrorMessage(true);
2228 return false;
2232 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),"");
2233 if (needReportToTarget(pl))
2234 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2236 // stop flight if need
2237 if(pl->isInFlight())
2239 pl->GetMotionMaster()->MovementExpired();
2240 pl->m_taxi.ClearTaxiDestinations();
2242 // save only in non-flight case
2243 else
2244 pl->SaveRecallPosition();
2246 // before GM
2247 float x,y,z;
2248 m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2249 pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2252 return true;
2255 bool ChatHandler::HandleGoTaxinodeCommand(const char* args)
2257 Player* _player = m_session->GetPlayer();
2259 if (!*args)
2260 return false;
2262 char* cNodeId = extractKeyFromLink((char*)args,"Htaxinode");
2263 if (!cNodeId)
2264 return false;
2266 int32 i_nodeId = atoi(cNodeId);
2267 if (!i_nodeId)
2268 return false;
2270 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i_nodeId);
2271 if (!node)
2273 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND,i_nodeId);
2274 SetSentErrorMessage(true);
2275 return false;
2278 if (node->x == 0.0f && node->y == 0.0f && node->z == 0.0f ||
2279 !MapManager::IsValidMapCoord(node->map_id,node->x,node->y,node->z))
2281 PSendSysMessage(LANG_INVALID_TARGET_COORD,node->x,node->y,node->map_id);
2282 SetSentErrorMessage(true);
2283 return false;
2286 // stop flight if need
2287 if (_player->isInFlight())
2289 _player->GetMotionMaster()->MovementExpired();
2290 _player->m_taxi.ClearTaxiDestinations();
2292 // save only in non-flight case
2293 else
2294 _player->SaveRecallPosition();
2296 _player->TeleportTo(node->map_id, node->x, node->y, node->z, _player->GetOrientation());
2297 return true;
2300 //teleport at coordinates
2301 bool ChatHandler::HandleGoXYCommand(const char* args)
2303 if(!*args)
2304 return false;
2306 Player* _player = m_session->GetPlayer();
2308 char* px = strtok((char*)args, " ");
2309 char* py = strtok(NULL, " ");
2310 char* pmapid = strtok(NULL, " ");
2312 if (!px || !py)
2313 return false;
2315 float x = (float)atof(px);
2316 float y = (float)atof(py);
2317 uint32 mapid;
2318 if (pmapid)
2319 mapid = (uint32)atoi(pmapid);
2320 else mapid = _player->GetMapId();
2322 if(!MapManager::IsValidMapCoord(mapid,x,y))
2324 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2325 SetSentErrorMessage(true);
2326 return false;
2329 // stop flight if need
2330 if(_player->isInFlight())
2332 _player->GetMotionMaster()->MovementExpired();
2333 _player->m_taxi.ClearTaxiDestinations();
2335 // save only in non-flight case
2336 else
2337 _player->SaveRecallPosition();
2339 Map const *map = MapManager::Instance().CreateBaseMap(mapid);
2340 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2342 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2344 return true;
2347 //teleport at coordinates, including Z
2348 bool ChatHandler::HandleGoXYZCommand(const char* args)
2350 if(!*args)
2351 return false;
2353 Player* _player = m_session->GetPlayer();
2355 char* px = strtok((char*)args, " ");
2356 char* py = strtok(NULL, " ");
2357 char* pz = strtok(NULL, " ");
2358 char* pmapid = strtok(NULL, " ");
2360 if (!px || !py || !pz)
2361 return false;
2363 float x = (float)atof(px);
2364 float y = (float)atof(py);
2365 float z = (float)atof(pz);
2366 uint32 mapid;
2367 if (pmapid)
2368 mapid = (uint32)atoi(pmapid);
2369 else
2370 mapid = _player->GetMapId();
2372 if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2374 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2375 SetSentErrorMessage(true);
2376 return false;
2379 // stop flight if need
2380 if(_player->isInFlight())
2382 _player->GetMotionMaster()->MovementExpired();
2383 _player->m_taxi.ClearTaxiDestinations();
2385 // save only in non-flight case
2386 else
2387 _player->SaveRecallPosition();
2389 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2391 return true;
2394 //teleport at coordinates
2395 bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2397 if(!*args)
2398 return false;
2400 Player* _player = m_session->GetPlayer();
2402 char* px = strtok((char*)args, " ");
2403 char* py = strtok(NULL, " ");
2404 char* tail = strtok(NULL,"");
2406 char* cAreaId = extractKeyFromLink(tail,"Harea"); // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2408 if (!px || !py)
2409 return false;
2411 float x = (float)atof(px);
2412 float y = (float)atof(py);
2414 // prevent accept wrong numeric args
2415 if (x==0.0f && *px!='0' || y==0.0f && *py!='0')
2416 return false;
2418 uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2420 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2422 if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2424 PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2425 SetSentErrorMessage(true);
2426 return false;
2429 // update to parent zone if exist (client map show only zones without parents)
2430 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2432 Map const *map = MapManager::Instance().CreateBaseMap(zoneEntry->mapid);
2434 if(map->Instanceable())
2436 PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2437 SetSentErrorMessage(true);
2438 return false;
2441 Zone2MapCoordinates(x,y,zoneEntry->ID);
2443 if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2445 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2446 SetSentErrorMessage(true);
2447 return false;
2450 // stop flight if need
2451 if(_player->isInFlight())
2453 _player->GetMotionMaster()->MovementExpired();
2454 _player->m_taxi.ClearTaxiDestinations();
2456 // save only in non-flight case
2457 else
2458 _player->SaveRecallPosition();
2460 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2461 _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2463 return true;
2466 //teleport to grid
2467 bool ChatHandler::HandleGoGridCommand(const char* args)
2469 if(!*args) return false;
2470 Player* _player = m_session->GetPlayer();
2472 char* px = strtok((char*)args, " ");
2473 char* py = strtok(NULL, " ");
2474 char* pmapid = strtok(NULL, " ");
2476 if (!px || !py)
2477 return false;
2479 float grid_x = (float)atof(px);
2480 float grid_y = (float)atof(py);
2481 uint32 mapid;
2482 if (pmapid)
2483 mapid = (uint32)atoi(pmapid);
2484 else mapid = _player->GetMapId();
2486 // center of grid
2487 float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2488 float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2490 if(!MapManager::IsValidMapCoord(mapid,x,y))
2492 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2493 SetSentErrorMessage(true);
2494 return false;
2497 // stop flight if need
2498 if(_player->isInFlight())
2500 _player->GetMotionMaster()->MovementExpired();
2501 _player->m_taxi.ClearTaxiDestinations();
2503 // save only in non-flight case
2504 else
2505 _player->SaveRecallPosition();
2507 Map const *map = MapManager::Instance().CreateBaseMap(mapid);
2508 float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2509 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2511 return true;
2514 bool ChatHandler::HandleModifyDrunkCommand(const char* args)
2516 if(!*args) return false;
2518 uint32 drunklevel = (uint32)atoi(args);
2519 if(drunklevel > 100)
2520 drunklevel = 100;
2522 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2524 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2526 return true;