Updated Copyright year to 2013
[getmangos.git] / src / game / Level1.cpp
blob78c226c68dc74623dcea5bbd32010028d8af1ff8
1 /*
2 * Copyright (C) 2005-2013 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 "MapPersistentStateMgr.h"
34 #include "Mail.h"
35 #include "Util.h"
36 #include "SpellMgr.h"
37 #ifdef _DEBUG_VMAPS
38 #include "VMapFactory.h"
39 #endif
41 //-----------------------Npc Commands-----------------------
42 bool ChatHandler::HandleNpcSayCommand(char* args)
44 if (!*args)
45 return false;
47 Creature* pCreature = getSelectedCreature();
48 if (!pCreature)
50 SendSysMessage(LANG_SELECT_CREATURE);
51 SetSentErrorMessage(true);
52 return false;
55 pCreature->MonsterSay(args, LANG_UNIVERSAL);
57 return true;
60 bool ChatHandler::HandleNpcYellCommand(char* args)
62 if (!*args)
63 return false;
65 Creature* pCreature = getSelectedCreature();
66 if (!pCreature)
68 SendSysMessage(LANG_SELECT_CREATURE);
69 SetSentErrorMessage(true);
70 return false;
73 pCreature->MonsterYell(args, LANG_UNIVERSAL);
75 return true;
78 // show text emote by creature in chat
79 bool ChatHandler::HandleNpcTextEmoteCommand(char* args)
81 if (!*args)
82 return false;
84 Creature* pCreature = getSelectedCreature();
86 if (!pCreature)
88 SendSysMessage(LANG_SELECT_CREATURE);
89 SetSentErrorMessage(true);
90 return false;
93 pCreature->MonsterTextEmote(args, NULL);
95 return true;
98 // make npc whisper to player
99 bool ChatHandler::HandleNpcWhisperCommand(char* args)
101 Player* target;
102 if (!ExtractPlayerTarget(&args, &target))
103 return false;
105 ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid();
106 if (!guid)
107 return false;
109 Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid);
111 if (!pCreature || !target || !*args)
112 return false;
114 // check online security
115 if (HasLowerSecurity(target))
116 return false;
118 pCreature->MonsterWhisper(args, target);
120 return true;
122 //----------------------------------------------------------
124 // global announce
125 bool ChatHandler::HandleAnnounceCommand(char* args)
127 if (!*args)
128 return false;
130 sWorld.SendWorldText(LANG_SYSTEMMESSAGE, args);
131 return true;
134 // notification player at the screen
135 bool ChatHandler::HandleNotifyCommand(char* args)
137 if (!*args)
138 return false;
140 std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
141 str += args;
143 WorldPacket data(SMSG_NOTIFICATION, str.size() + 1);
144 data.WriteBits(str.length(), 13);
145 data.FlushBits();
146 data.append(str.c_str(), str.length());
147 sWorld.SendGlobalMessage(&data);
149 return true;
152 // Enable\Dissable GM Mode
153 bool ChatHandler::HandleGMCommand(char* args)
155 if (!*args)
157 if (m_session->GetPlayer()->isGameMaster())
158 m_session->SendNotification(LANG_GM_ON);
159 else
160 m_session->SendNotification(LANG_GM_OFF);
161 return true;
164 bool value;
165 if (!ExtractOnOff(&args, value))
167 SendSysMessage(LANG_USE_BOL);
168 SetSentErrorMessage(true);
169 return false;
172 if (value)
174 m_session->GetPlayer()->SetGameMaster(true);
175 m_session->SendNotification(LANG_GM_ON);
177 else
179 m_session->GetPlayer()->SetGameMaster(false);
180 m_session->SendNotification(LANG_GM_OFF);
183 return true;
186 // Enables or disables hiding of the staff badge
187 bool ChatHandler::HandleGMChatCommand(char* args)
189 if (!*args)
191 if (m_session->GetPlayer()->isGMChat())
192 m_session->SendNotification(LANG_GM_CHAT_ON);
193 else
194 m_session->SendNotification(LANG_GM_CHAT_OFF);
195 return true;
198 bool value;
199 if (!ExtractOnOff(&args, value))
201 SendSysMessage(LANG_USE_BOL);
202 SetSentErrorMessage(true);
203 return false;
206 if (value)
208 m_session->GetPlayer()->SetGMChat(true);
209 m_session->SendNotification(LANG_GM_CHAT_ON);
211 else
213 m_session->GetPlayer()->SetGMChat(false);
214 m_session->SendNotification(LANG_GM_CHAT_OFF);
217 return true;
220 // Enable\Dissable Invisible mode
221 bool ChatHandler::HandleGMVisibleCommand(char* args)
223 if (!*args)
225 PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
226 return true;
229 bool value;
230 if (!ExtractOnOff(&args, value))
232 SendSysMessage(LANG_USE_BOL);
233 SetSentErrorMessage(true);
234 return false;
237 Player* player = m_session->GetPlayer();
238 SpellEntry const* invisibleAuraInfo = sSpellStore.LookupEntry(sWorld.getConfig(CONFIG_UINT32_GM_INVISIBLE_AURA));
239 if (!invisibleAuraInfo || !IsSpellAppliesAura(invisibleAuraInfo))
240 invisibleAuraInfo = NULL;
242 if (value)
244 player->SetGMVisible(true);
245 m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
246 if (invisibleAuraInfo)
247 player->RemoveAurasDueToSpell(invisibleAuraInfo->Id);
249 else
251 m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
252 player->SetGMVisible(false);
253 if (invisibleAuraInfo)
254 player->CastSpell(player, invisibleAuraInfo, true);
257 return true;
260 bool ChatHandler::HandleGPSCommand(char* args)
262 WorldObject* obj = NULL;
263 if (*args)
265 if (ObjectGuid guid = ExtractGuidFromLink(&args))
266 obj = (WorldObject*)m_session->GetPlayer()->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);
268 if (!obj)
270 SendSysMessage(LANG_PLAYER_NOT_FOUND);
271 SetSentErrorMessage(true);
272 return false;
275 else
277 obj = getSelectedUnit();
279 if (!obj)
281 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
282 SetSentErrorMessage(true);
283 return false;
286 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
287 Cell cell(cell_val);
289 uint32 zone_id, area_id;
290 obj->GetZoneAndAreaId(zone_id, area_id);
292 MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
293 AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
294 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
296 float zone_x = obj->GetPositionX();
297 float zone_y = obj->GetPositionY();
299 if (!Map2ZoneCoordinates(zone_x, zone_y, zone_id))
301 zone_x = 0;
302 zone_y = 0;
305 TerrainInfo const* map = obj->GetTerrain();
306 float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
307 float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
309 GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
311 int gx = 63 - p.x_coord;
312 int gy = 63 - p.y_coord;
314 uint32 have_map = GridMap::ExistMap(obj->GetMapId(), gx, gy) ? 1 : 0;
315 uint32 have_vmap = GridMap::ExistVMap(obj->GetMapId(), gx, gy) ? 1 : 0;
317 if (have_vmap)
319 if (map->IsOutdoors(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ()))
320 PSendSysMessage("You are OUTdoor");
321 else
322 PSendSysMessage("You are INdoor");
324 else PSendSysMessage("no VMAP available for area info");
326 PSendSysMessage(LANG_MAP_POSITION,
327 obj->GetMapId(), (mapEntry ? mapEntry->name[GetSessionDbcLocale()] : "<unknown>"),
328 zone_id, (zoneEntry ? zoneEntry->area_name[GetSessionDbcLocale()] : "<unknown>"),
329 area_id, (areaEntry ? areaEntry->area_name[GetSessionDbcLocale()] : "<unknown>"),
330 obj->GetPhaseMask(),
331 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
332 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
333 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap);
335 DEBUG_LOG("Player %s GPS call for %s '%s' (%s: %u):",
336 m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND),
337 (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
338 (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow() : obj->GetEntry()));
340 DEBUG_LOG(GetMangosString(LANG_MAP_POSITION),
341 obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>"),
342 zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>"),
343 area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>"),
344 obj->GetPhaseMask(),
345 obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
346 cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
347 zone_x, zone_y, ground_z, floor_z, have_map, have_vmap);
349 GridMapLiquidData liquid_status;
350 GridMapLiquidStatus res = map->getLiquidStatus(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), MAP_ALL_LIQUIDS, &liquid_status);
351 if (res)
353 PSendSysMessage(LANG_LIQUID_STATUS, liquid_status.level, liquid_status.depth_level, liquid_status.type, res);
355 return true;
358 // Summon Player
359 bool ChatHandler::HandleNamegoCommand(char* args)
361 Player* target;
362 ObjectGuid target_guid;
363 std::string target_name;
364 if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))
365 return false;
367 Player* _player = m_session->GetPlayer();
368 if (target == _player || target_guid == _player->GetObjectGuid())
370 PSendSysMessage(LANG_CANT_TELEPORT_SELF);
371 SetSentErrorMessage(true);
372 return false;
375 if (target)
377 std::string nameLink = playerLink(target_name);
378 // check online security
379 if (HasLowerSecurity(target))
380 return false;
382 if (target->IsBeingTeleported())
384 PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
385 SetSentErrorMessage(true);
386 return false;
389 Map* pMap = m_session->GetPlayer()->GetMap();
391 if (pMap->IsBattleGroundOrArena())
393 // only allow if gm mode is on
394 if (!target->isGameMaster())
396 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM, nameLink.c_str());
397 SetSentErrorMessage(true);
398 return false;
400 // if both players are in different bgs
401 else if (target->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != target->GetBattleGroundId())
403 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG, nameLink.c_str());
404 SetSentErrorMessage(true);
405 return false;
407 // all's well, set bg id
408 // when porting out from the bg, it will be reset to 0
409 target->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId());
410 // remember current position as entry point for return at bg end teleportation
411 if (!target->GetMap()->IsBattleGroundOrArena())
412 target->SetBattleGroundEntryPoint();
414 else if (pMap->IsDungeon())
416 Map* cMap = target->GetMap();
417 if (cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId())
419 // cannot summon from instance to instance
420 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, nameLink.c_str());
421 SetSentErrorMessage(true);
422 return false;
425 // we are in instance, and can summon only player in our group with us as lead
426 if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
427 (target->GetGroup()->GetLeaderGuid() != m_session->GetPlayer()->GetObjectGuid()) ||
428 (m_session->GetPlayer()->GetGroup()->GetLeaderGuid() != m_session->GetPlayer()->GetObjectGuid()))
429 // the last check is a bit excessive, but let it be, just in case
431 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, nameLink.c_str());
432 SetSentErrorMessage(true);
433 return false;
437 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(), "");
438 if (needReportToTarget(target))
439 ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, playerLink(_player->GetName()).c_str());
441 // stop flight if need
442 if (target->IsTaxiFlying())
444 target->GetMotionMaster()->MovementExpired();
445 target->m_taxi.ClearTaxiDestinations();
447 // save only in non-flight case
448 else
449 target->SaveRecallPosition();
451 // before GM
452 float x, y, z;
453 m_session->GetPlayer()->GetClosePoint(x, y, z, target->GetObjectBoundingRadius());
454 target->TeleportTo(m_session->GetPlayer()->GetMapId(), x, y, z, target->GetOrientation());
456 else
458 // check offline security
459 if (HasLowerSecurity(NULL, target_guid))
460 return false;
462 std::string nameLink = playerLink(target_name);
464 PSendSysMessage(LANG_SUMMONING, nameLink.c_str(), GetMangosString(LANG_OFFLINE));
466 // in point where GM stay
467 Player::SavePositionInDB(target_guid, m_session->GetPlayer()->GetMapId(),
468 m_session->GetPlayer()->GetPositionX(),
469 m_session->GetPlayer()->GetPositionY(),
470 m_session->GetPlayer()->GetPositionZ(),
471 m_session->GetPlayer()->GetOrientation(),
472 m_session->GetPlayer()->GetZoneId());
475 return true;
478 // Teleport to Player
479 bool ChatHandler::HandleGonameCommand(char* args)
481 Player* target;
482 ObjectGuid target_guid;
483 std::string target_name;
484 if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))
485 return false;
487 Player* _player = m_session->GetPlayer();
488 if (target == _player || target_guid == _player->GetObjectGuid())
490 SendSysMessage(LANG_CANT_TELEPORT_SELF);
491 SetSentErrorMessage(true);
492 return false;
496 if (target)
498 // check online security
499 if (HasLowerSecurity(target))
500 return false;
502 std::string chrNameLink = playerLink(target_name);
504 Map* cMap = target->GetMap();
505 if (cMap->IsBattleGroundOrArena())
507 // only allow if gm mode is on
508 if (!_player->isGameMaster())
510 PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM, chrNameLink.c_str());
511 SetSentErrorMessage(true);
512 return false;
514 // if both players are in different bgs
515 else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != target->GetBattleGroundId())
517 PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG, chrNameLink.c_str());
518 SetSentErrorMessage(true);
519 return false;
521 // all's well, set bg id
522 // when porting out from the bg, it will be reset to 0
523 _player->SetBattleGroundId(target->GetBattleGroundId(), target->GetBattleGroundTypeId());
524 // remember current position as entry point for return at bg end teleportation
525 if (!_player->GetMap()->IsBattleGroundOrArena())
526 _player->SetBattleGroundEntryPoint();
528 else if (cMap->IsDungeon())
530 // we have to go to instance, and can go to player only if:
531 // 1) we are in his group (either as leader or as member)
532 // 2) we are not bound to any group and have GM mode on
533 if (_player->GetGroup())
535 // we are in group, we can go only if we are in the player group
536 if (_player->GetGroup() != target->GetGroup())
538 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY, chrNameLink.c_str());
539 SetSentErrorMessage(true);
540 return false;
543 else
545 // we are not in group, let's verify our GM mode
546 if (!_player->isGameMaster())
548 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM, chrNameLink.c_str());
549 SetSentErrorMessage(true);
550 return false;
554 // if the player or the player's group is bound to another instance
555 // the player will not be bound to another one
556 InstancePlayerBind* pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty(cMap->IsRaid()));
557 if (!pBind)
559 Group* group = _player->GetGroup();
560 // if no bind exists, create a solo bind
561 InstanceGroupBind* gBind = group ? group->GetBoundInstance(target->GetMapId(), target) : NULL;
562 // if no bind exists, create a solo bind
563 if (!gBind)
565 DungeonPersistentState* save = ((DungeonMap*)target->GetMap())->GetPersistanceState();
567 // if player is group leader then we need add group bind
568 if (group && group->IsLeader(_player->GetObjectGuid()))
569 group->BindToInstance(save, !save->CanReset());
570 else
571 _player->BindToInstance(save, !save->CanReset());
575 if (cMap->IsRaid())
576 _player->SetRaidDifficulty(target->GetRaidDifficulty());
577 else
578 _player->SetDungeonDifficulty(target->GetDungeonDifficulty());
581 PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
582 if (needReportToTarget(target))
583 ChatHandler(target).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str());
585 // stop flight if need
586 if (_player->IsTaxiFlying())
588 _player->GetMotionMaster()->MovementExpired();
589 _player->m_taxi.ClearTaxiDestinations();
591 // save only in non-flight case
592 else
593 _player->SaveRecallPosition();
595 // to point to see at target with same orientation
596 float x, y, z;
597 target->GetContactPoint(_player, x, y, z);
599 _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
601 else
603 // check offline security
604 if (HasLowerSecurity(NULL, target_guid))
605 return false;
607 std::string nameLink = playerLink(target_name);
609 PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
611 // to point where player stay (if loaded)
612 float x, y, z, o;
613 uint32 map;
614 bool in_flight;
615 if (!Player::LoadPositionFromDB(target_guid, map, x, y, z, o, in_flight))
616 return false;
618 return HandleGoHelper(_player, map, x, y, &z);
621 return true;
624 // Teleport player to last position
625 bool ChatHandler::HandleRecallCommand(char* args)
627 Player* target;
628 if (!ExtractPlayerTarget(&args, &target))
629 return false;
631 // check online security
632 if (HasLowerSecurity(target))
633 return false;
635 if (target->IsBeingTeleported())
637 PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
638 SetSentErrorMessage(true);
639 return false;
642 return HandleGoHelper(target, target->m_recallMap, target->m_recallX, target->m_recallY, &target->m_recallZ, &target->m_recallO);
645 bool ChatHandler::HandleModifyHolyPowerCommand(char* args)
647 if (!*args)
648 return false;
650 int32 power = atoi(args);
652 if (power < 0)
654 SendSysMessage(LANG_BAD_VALUE);
655 SetSentErrorMessage(true);
656 return false;
659 Player* chr = getSelectedPlayer();
660 if (!chr)
662 SendSysMessage(LANG_NO_CHAR_SELECTED);
663 SetSentErrorMessage(true);
664 return false;
667 // check online security
668 if (HasLowerSecurity(chr))
669 return false;
671 int32 maxPower = int32(chr->GetMaxPower(POWER_HOLY_POWER));
672 if (power > maxPower)
674 SendSysMessage(LANG_BAD_VALUE);
675 SetSentErrorMessage(true);
676 return false;
679 PSendSysMessage(LANG_YOU_CHANGE_HOLY_POWER, GetNameLink(chr).c_str(), power, maxPower);
680 if (needReportToTarget(chr))
681 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HOLY_POWER_CHANGED, GetNameLink().c_str(), power, maxPower);
683 chr->SetPower(POWER_HOLY_POWER, power);
685 return true;
688 // Edit Player HP
689 bool ChatHandler::HandleModifyHPCommand(char* args)
691 if (!*args)
692 return false;
694 int32 hp = atoi(args);
695 int32 hpm = atoi(args);
697 if (hp <= 0 || hpm <= 0 || hpm < hp)
699 SendSysMessage(LANG_BAD_VALUE);
700 SetSentErrorMessage(true);
701 return false;
704 Player* chr = getSelectedPlayer();
705 if (chr == NULL)
707 SendSysMessage(LANG_NO_CHAR_SELECTED);
708 SetSentErrorMessage(true);
709 return false;
712 // check online security
713 if (HasLowerSecurity(chr))
714 return false;
716 PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm);
717 if (needReportToTarget(chr))
718 ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm);
720 chr->SetMaxHealth(hpm);
721 chr->SetHealth(hp);
723 return true;
726 // Edit Player Mana
727 bool ChatHandler::HandleModifyManaCommand(char* args)
729 if (!*args)
730 return false;
732 int32 mana = atoi(args);
733 int32 manam = atoi(args);
735 if (mana <= 0 || manam <= 0 || manam < mana)
737 SendSysMessage(LANG_BAD_VALUE);
738 SetSentErrorMessage(true);
739 return false;
742 Player* chr = getSelectedPlayer();
743 if (chr == NULL)
745 SendSysMessage(LANG_NO_CHAR_SELECTED);
746 SetSentErrorMessage(true);
747 return false;
750 // check online security
751 if (HasLowerSecurity(chr))
752 return false;
754 PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam);
755 if (needReportToTarget(chr))
756 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam);
758 chr->SetMaxPower(POWER_MANA, manam);
759 chr->SetPower(POWER_MANA, mana);
761 return true;
764 // Edit Player Energy
765 bool ChatHandler::HandleModifyEnergyCommand(char* args)
767 if (!*args)
768 return false;
770 int32 energy = atoi(args) * 10;
771 int32 energym = atoi(args) * 10;
773 if (energy <= 0 || energym <= 0 || energym < energy)
775 SendSysMessage(LANG_BAD_VALUE);
776 SetSentErrorMessage(true);
777 return false;
780 Player* chr = getSelectedPlayer();
781 if (!chr)
783 SendSysMessage(LANG_NO_CHAR_SELECTED);
784 SetSentErrorMessage(true);
785 return false;
788 // check online security
789 if (HasLowerSecurity(chr))
790 return false;
792 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy / 10, energym / 10);
793 if (needReportToTarget(chr))
794 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy / 10, energym / 10);
796 chr->SetMaxPower(POWER_ENERGY, energym);
797 chr->SetPower(POWER_ENERGY, energy);
799 DETAIL_LOG(GetMangosString(LANG_CURRENT_ENERGY), chr->GetMaxPower(POWER_ENERGY));
801 return true;
804 // Edit Player Rage
805 bool ChatHandler::HandleModifyRageCommand(char* args)
807 if (!*args)
808 return false;
810 int32 rage = atoi(args) * 10;
811 int32 ragem = atoi(args) * 10;
813 if (rage <= 0 || ragem <= 0 || ragem < rage)
815 SendSysMessage(LANG_BAD_VALUE);
816 SetSentErrorMessage(true);
817 return false;
820 Player* chr = getSelectedPlayer();
821 if (chr == NULL)
823 SendSysMessage(LANG_NO_CHAR_SELECTED);
824 SetSentErrorMessage(true);
825 return false;
828 // check online security
829 if (HasLowerSecurity(chr))
830 return false;
832 PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage / 10, ragem / 10);
833 if (needReportToTarget(chr))
834 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage / 10, ragem / 10);
836 chr->SetMaxPower(POWER_RAGE, ragem);
837 chr->SetPower(POWER_RAGE, rage);
839 return true;
842 // Edit Player Runic Power
843 bool ChatHandler::HandleModifyRunicPowerCommand(char* args)
845 if (!*args)
846 return false;
848 int32 rune = atoi(args) * 10;
849 int32 runem = atoi(args) * 10;
851 if (rune <= 0 || runem <= 0 || runem < rune)
853 SendSysMessage(LANG_BAD_VALUE);
854 SetSentErrorMessage(true);
855 return false;
858 Player* chr = getSelectedPlayer();
859 if (chr == NULL)
861 SendSysMessage(LANG_NO_CHAR_SELECTED);
862 SetSentErrorMessage(true);
863 return false;
866 PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune / 10, runem / 10);
867 if (needReportToTarget(chr))
868 ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune / 10, runem / 10);
870 chr->SetMaxPower(POWER_RUNIC_POWER, runem);
871 chr->SetPower(POWER_RUNIC_POWER, rune);
873 return true;
876 // Edit Player Faction
877 bool ChatHandler::HandleModifyFactionCommand(char* args)
879 Creature* chr = getSelectedCreature();
880 if (!chr)
882 SendSysMessage(LANG_SELECT_CREATURE);
883 SetSentErrorMessage(true);
884 return false;
887 if (!*args)
889 if (chr)
891 uint32 factionid = chr->getFaction();
892 uint32 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
893 uint32 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
894 uint32 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
895 PSendSysMessage(LANG_CURRENT_FACTION, chr->GetGUIDLow(), factionid, flag, npcflag, dyflag);
897 return true;
900 if (!chr)
902 SendSysMessage(LANG_NO_CHAR_SELECTED);
903 SetSentErrorMessage(true);
904 return false;
907 uint32 factionid;
908 if (!ExtractUint32KeyFromLink(&args, "Hfaction", factionid))
909 return false;
911 if (!sFactionTemplateStore.LookupEntry(factionid))
913 PSendSysMessage(LANG_WRONG_FACTION, factionid);
914 SetSentErrorMessage(true);
915 return false;
918 uint32 flag;
919 if (!ExtractOptUInt32(&args, flag, chr->GetUInt32Value(UNIT_FIELD_FLAGS)))
920 return false;
922 uint32 npcflag;
923 if (!ExtractOptUInt32(&args, npcflag, chr->GetUInt32Value(UNIT_NPC_FLAGS)))
924 return false;
926 uint32 dyflag;
927 if (!ExtractOptUInt32(&args, dyflag, chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS)))
928 return false;
930 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(), factionid, flag, npcflag, dyflag);
932 chr->setFaction(factionid);
933 chr->SetUInt32Value(UNIT_FIELD_FLAGS, flag);
934 chr->SetUInt32Value(UNIT_NPC_FLAGS, npcflag);
935 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS, dyflag);
937 return true;
940 // Edit Player TP
941 bool ChatHandler::HandleModifyTalentCommand(char* args)
943 if (!*args)
944 return false;
946 int tp = atoi(args);
947 if (tp < 0)
948 return false;
950 Unit* target = getSelectedUnit();
951 if (!target)
953 SendSysMessage(LANG_NO_CHAR_SELECTED);
954 SetSentErrorMessage(true);
955 return false;
958 if (target->GetTypeId() == TYPEID_PLAYER)
960 // check online security
961 if (HasLowerSecurity((Player*)target))
962 return false;
964 ((Player*)target)->SetFreeTalentPoints(tp);
965 ((Player*)target)->SendTalentsInfoData(false);
966 return true;
968 else if (((Creature*)target)->IsPet())
970 Unit* owner = target->GetOwner();
971 if (owner && owner->GetTypeId() == TYPEID_PLAYER && ((Pet*)target)->IsPermanentPetFor((Player*)owner))
973 // check online security
974 if (HasLowerSecurity((Player*)owner))
975 return false;
977 ((Pet*)target)->SetFreeTalentPoints(tp);
978 ((Player*)owner)->SendTalentsInfoData(true);
979 return true;
983 SendSysMessage(LANG_NO_CHAR_SELECTED);
984 SetSentErrorMessage(true);
985 return false;
988 // Enable On\OFF all taxi paths
989 bool ChatHandler::HandleTaxiCheatCommand(char* args)
991 bool value;
992 if (!ExtractOnOff(&args, value))
994 SendSysMessage(LANG_USE_BOL);
995 SetSentErrorMessage(true);
996 return false;
999 Player* chr = getSelectedPlayer();
1000 if (!chr)
1001 chr = m_session->GetPlayer();
1002 // check online security
1003 else if (HasLowerSecurity(chr))
1004 return false;
1006 if (value)
1008 chr->SetTaxiCheater(true);
1009 PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
1010 if (needReportToTarget(chr))
1011 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
1013 else
1015 chr->SetTaxiCheater(false);
1016 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
1017 if (needReportToTarget(chr))
1018 ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
1021 return true;
1024 // Edit Player Aspeed
1025 bool ChatHandler::HandleModifyASpeedCommand(char* args)
1027 if (!*args)
1028 return false;
1030 float modSpeed = (float)atof(args);
1032 if (modSpeed > 10 || modSpeed < 0.1)
1034 SendSysMessage(LANG_BAD_VALUE);
1035 SetSentErrorMessage(true);
1036 return false;
1039 Player* chr = getSelectedPlayer();
1040 if (chr == NULL)
1042 SendSysMessage(LANG_NO_CHAR_SELECTED);
1043 SetSentErrorMessage(true);
1044 return false;
1047 // check online security
1048 if (HasLowerSecurity(chr))
1049 return false;
1051 std::string chrNameLink = GetNameLink(chr);
1053 if (chr->IsTaxiFlying())
1055 PSendSysMessage(LANG_CHAR_IN_FLIGHT, chrNameLink.c_str());
1056 SetSentErrorMessage(true);
1057 return false;
1060 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, modSpeed, chrNameLink.c_str());
1061 if (needReportToTarget(chr))
1062 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), modSpeed);
1064 chr->UpdateSpeed(MOVE_WALK, true, modSpeed);
1065 chr->UpdateSpeed(MOVE_RUN, true, modSpeed);
1066 chr->UpdateSpeed(MOVE_SWIM, true, modSpeed);
1067 // chr->UpdateSpeed(MOVE_TURN, true, modSpeed);
1068 chr->UpdateSpeed(MOVE_FLIGHT, true, modSpeed);
1069 return true;
1072 // Edit Player Speed
1073 bool ChatHandler::HandleModifySpeedCommand(char* args)
1075 if (!*args)
1076 return false;
1078 float modSpeed = (float)atof(args);
1080 if (modSpeed > 10 || modSpeed < 0.1)
1082 SendSysMessage(LANG_BAD_VALUE);
1083 SetSentErrorMessage(true);
1084 return false;
1087 Player* chr = getSelectedPlayer();
1088 if (chr == NULL)
1090 SendSysMessage(LANG_NO_CHAR_SELECTED);
1091 SetSentErrorMessage(true);
1092 return false;
1095 // check online security
1096 if (HasLowerSecurity(chr))
1097 return false;
1099 std::string chrNameLink = GetNameLink(chr);
1101 if (chr->IsTaxiFlying())
1103 PSendSysMessage(LANG_CHAR_IN_FLIGHT, chrNameLink.c_str());
1104 SetSentErrorMessage(true);
1105 return false;
1108 PSendSysMessage(LANG_YOU_CHANGE_SPEED, modSpeed, chrNameLink.c_str());
1109 if (needReportToTarget(chr))
1110 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), modSpeed);
1112 chr->UpdateSpeed(MOVE_RUN, true, modSpeed);
1114 return true;
1117 // Edit Player Swim Speed
1118 bool ChatHandler::HandleModifySwimCommand(char* args)
1120 if (!*args)
1121 return false;
1123 float modSpeed = (float)atof(args);
1125 if (modSpeed > 10.0f || modSpeed < 0.01f)
1127 SendSysMessage(LANG_BAD_VALUE);
1128 SetSentErrorMessage(true);
1129 return false;
1132 Player* chr = getSelectedPlayer();
1133 if (chr == NULL)
1135 SendSysMessage(LANG_NO_CHAR_SELECTED);
1136 SetSentErrorMessage(true);
1137 return false;
1140 // check online security
1141 if (HasLowerSecurity(chr))
1142 return false;
1144 std::string chrNameLink = GetNameLink(chr);
1146 if (chr->IsTaxiFlying())
1148 PSendSysMessage(LANG_CHAR_IN_FLIGHT, chrNameLink.c_str());
1149 SetSentErrorMessage(true);
1150 return false;
1153 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, modSpeed, chrNameLink.c_str());
1154 if (needReportToTarget(chr))
1155 ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), modSpeed);
1157 chr->UpdateSpeed(MOVE_SWIM, true, modSpeed);
1159 return true;
1162 // Edit Player Walk Speed
1163 bool ChatHandler::HandleModifyBWalkCommand(char* args)
1165 if (!*args)
1166 return false;
1168 float modSpeed = (float)atof(args);
1170 if (modSpeed > 10.0f || modSpeed < 0.1f)
1172 SendSysMessage(LANG_BAD_VALUE);
1173 SetSentErrorMessage(true);
1174 return false;
1177 Player* chr = getSelectedPlayer();
1178 if (chr == NULL)
1180 SendSysMessage(LANG_NO_CHAR_SELECTED);
1181 SetSentErrorMessage(true);
1182 return false;
1185 // check online security
1186 if (HasLowerSecurity(chr))
1187 return false;
1189 std::string chrNameLink = GetNameLink(chr);
1191 if (chr->IsTaxiFlying())
1193 PSendSysMessage(LANG_CHAR_IN_FLIGHT, chrNameLink.c_str());
1194 SetSentErrorMessage(true);
1195 return false;
1198 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, modSpeed, chrNameLink.c_str());
1199 if (needReportToTarget(chr))
1200 ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), modSpeed);
1202 chr->UpdateSpeed(MOVE_RUN_BACK, true, modSpeed);
1204 return true;
1207 // Edit Player Fly
1208 bool ChatHandler::HandleModifyFlyCommand(char* args)
1210 if (!*args)
1211 return false;
1213 float modSpeed = (float)atof(args);
1215 if (modSpeed > 10.0f || modSpeed < 0.1f)
1217 SendSysMessage(LANG_BAD_VALUE);
1218 SetSentErrorMessage(true);
1219 return false;
1222 Player* chr = getSelectedPlayer();
1223 if (chr == NULL)
1225 SendSysMessage(LANG_NO_CHAR_SELECTED);
1226 SetSentErrorMessage(true);
1227 return false;
1230 // check online security
1231 if (HasLowerSecurity(chr))
1232 return false;
1234 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, modSpeed, GetNameLink(chr).c_str());
1235 if (needReportToTarget(chr))
1236 ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), modSpeed);
1238 chr->UpdateSpeed(MOVE_FLIGHT, true, modSpeed);
1240 return true;
1243 // Edit Player Scale
1244 bool ChatHandler::HandleModifyScaleCommand(char* args)
1246 if (!*args)
1247 return false;
1249 float Scale = (float)atof(args);
1250 if (Scale > 10.0f || Scale <= 0.0f)
1252 SendSysMessage(LANG_BAD_VALUE);
1253 SetSentErrorMessage(true);
1254 return false;
1257 Unit* target = getSelectedUnit();
1258 if (target == NULL)
1260 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
1261 SetSentErrorMessage(true);
1262 return false;
1265 if (target->GetTypeId() == TYPEID_PLAYER)
1267 // check online security
1268 if (HasLowerSecurity((Player*)target))
1269 return false;
1271 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink((Player*)target).c_str());
1272 if (needReportToTarget((Player*)target))
1273 ChatHandler((Player*)target).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale);
1276 target->SetObjectScale(Scale);
1277 target->UpdateModelData();
1279 return true;
1282 // Enable Player mount
1283 bool ChatHandler::HandleModifyMountCommand(char* args)
1285 if (!*args)
1286 return false;
1288 uint16 mId = 1147;
1289 float speed = (float)15;
1290 uint32 num = atoi(args);
1291 switch (num)
1293 case 1:
1294 mId = 14340;
1295 break;
1296 case 2:
1297 mId = 4806;
1298 break;
1299 case 3:
1300 mId = 6471;
1301 break;
1302 case 4:
1303 mId = 12345;
1304 break;
1305 case 5:
1306 mId = 6472;
1307 break;
1308 case 6:
1309 mId = 6473;
1310 break;
1311 case 7:
1312 mId = 10670;
1313 break;
1314 case 8:
1315 mId = 10719;
1316 break;
1317 case 9:
1318 mId = 10671;
1319 break;
1320 case 10:
1321 mId = 10672;
1322 break;
1323 case 11:
1324 mId = 10720;
1325 break;
1326 case 12:
1327 mId = 14349;
1328 break;
1329 case 13:
1330 mId = 11641;
1331 break;
1332 case 14:
1333 mId = 12244;
1334 break;
1335 case 15:
1336 mId = 12242;
1337 break;
1338 case 16:
1339 mId = 14578;
1340 break;
1341 case 17:
1342 mId = 14579;
1343 break;
1344 case 18:
1345 mId = 14349;
1346 break;
1347 case 19:
1348 mId = 12245;
1349 break;
1350 case 20:
1351 mId = 14335;
1352 break;
1353 case 21:
1354 mId = 207;
1355 break;
1356 case 22:
1357 mId = 2328;
1358 break;
1359 case 23:
1360 mId = 2327;
1361 break;
1362 case 24:
1363 mId = 2326;
1364 break;
1365 case 25:
1366 mId = 14573;
1367 break;
1368 case 26:
1369 mId = 14574;
1370 break;
1371 case 27:
1372 mId = 14575;
1373 break;
1374 case 28:
1375 mId = 604;
1376 break;
1377 case 29:
1378 mId = 1166;
1379 break;
1380 case 30:
1381 mId = 2402;
1382 break;
1383 case 31:
1384 mId = 2410;
1385 break;
1386 case 32:
1387 mId = 2409;
1388 break;
1389 case 33:
1390 mId = 2408;
1391 break;
1392 case 34:
1393 mId = 2405;
1394 break;
1395 case 35:
1396 mId = 14337;
1397 break;
1398 case 36:
1399 mId = 6569;
1400 break;
1401 case 37:
1402 mId = 10661;
1403 break;
1404 case 38:
1405 mId = 10666;
1406 break;
1407 case 39:
1408 mId = 9473;
1409 break;
1410 case 40:
1411 mId = 9476;
1412 break;
1413 case 41:
1414 mId = 9474;
1415 break;
1416 case 42:
1417 mId = 14374;
1418 break;
1419 case 43:
1420 mId = 14376;
1421 break;
1422 case 44:
1423 mId = 14377;
1424 break;
1425 case 45:
1426 mId = 2404;
1427 break;
1428 case 46:
1429 mId = 2784;
1430 break;
1431 case 47:
1432 mId = 2787;
1433 break;
1434 case 48:
1435 mId = 2785;
1436 break;
1437 case 49:
1438 mId = 2736;
1439 break;
1440 case 50:
1441 mId = 2786;
1442 break;
1443 case 51:
1444 mId = 14347;
1445 break;
1446 case 52:
1447 mId = 14346;
1448 break;
1449 case 53:
1450 mId = 14576;
1451 break;
1452 case 54:
1453 mId = 9695;
1454 break;
1455 case 55:
1456 mId = 9991;
1457 break;
1458 case 56:
1459 mId = 6448;
1460 break;
1461 case 57:
1462 mId = 6444;
1463 break;
1464 case 58:
1465 mId = 6080;
1466 break;
1467 case 59:
1468 mId = 6447;
1469 break;
1470 case 60:
1471 mId = 4805;
1472 break;
1473 case 61:
1474 mId = 9714;
1475 break;
1476 case 62:
1477 mId = 6448;
1478 break;
1479 case 63:
1480 mId = 6442;
1481 break;
1482 case 64:
1483 mId = 14632;
1484 break;
1485 case 65:
1486 mId = 14332;
1487 break;
1488 case 66:
1489 mId = 14331;
1490 break;
1491 case 67:
1492 mId = 8469;
1493 break;
1494 case 68:
1495 mId = 2830;
1496 break;
1497 case 69:
1498 mId = 2346;
1499 break;
1500 default:
1501 SendSysMessage(LANG_NO_MOUNT);
1502 SetSentErrorMessage(true);
1503 return false;
1506 Player* chr = getSelectedPlayer();
1507 if (!chr)
1509 SendSysMessage(LANG_NO_CHAR_SELECTED);
1510 SetSentErrorMessage(true);
1511 return false;
1514 // check online security
1515 if (HasLowerSecurity(chr))
1516 return false;
1518 PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str());
1519 if (needReportToTarget(chr))
1520 ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str());
1522 chr->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP);
1523 chr->Mount(mId);
1525 ObjectGuid guid = chr->GetObjectGuid();
1527 WorldPacket data(SMSG_MOVE_SET_RUN_SPEED, 8 + 4 + 4);
1528 data.WriteGuidMask<6, 1, 5, 2, 7, 0, 3, 4>(guid);
1529 data.WriteGuidBytes<5, 3, 1, 4>(guid);
1530 data << uint32(0);
1531 data << float(speed);
1532 data.WriteGuidBytes<6, 0, 7, 2>(guid);
1533 chr->SendMessageToSet(&data, true);
1535 data.Initialize(SMSG_MOVE_SET_SWIM_SPEED, 8 + 4 + 4);
1536 data.WriteGuidMask<5, 4, 7, 3, 2, 0, 1, 6>(guid);
1537 data.WriteGuidBytes<0>(guid);
1538 data << uint32(0);
1539 data.WriteGuidBytes<6, 3, 5, 2>(guid);
1540 data << float(speed);
1541 data.WriteGuidBytes<1, 7, 4>(guid);
1542 chr->SendMessageToSet(&data, true);
1544 return true;
1547 // Edit Player money
1548 bool ChatHandler::HandleModifyMoneyCommand(char* args)
1550 if (!*args)
1551 return false;
1553 Player* chr = getSelectedPlayer();
1554 if (chr == NULL)
1556 SendSysMessage(LANG_NO_CHAR_SELECTED);
1557 SetSentErrorMessage(true);
1558 return false;
1561 // check online security
1562 if (HasLowerSecurity(chr))
1563 return false;
1565 int64 addmoney;
1566 if (!ExtractInt64(&args, addmoney))
1567 return false;
1569 uint64 moneyuser = chr->GetMoney();
1571 std::stringstream absadd; absadd << abs(addmoney);
1572 std::stringstream add; add << addmoney;
1574 if (addmoney < 0)
1576 int64 newmoney = int64(moneyuser) + addmoney;
1577 DETAIL_LOG("USER1: %s, ADD: %s, DIF: %s",
1578 MoneyToString(moneyuser).c_str(), MoneyToString(addmoney).c_str(), MoneyToString(newmoney).c_str());
1579 if (newmoney <= 0)
1581 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str());
1582 if (needReportToTarget(chr))
1583 ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str());
1585 chr->SetMoney(0);
1587 else
1589 if (newmoney > MAX_MONEY_AMOUNT)
1590 newmoney = MAX_MONEY_AMOUNT;
1592 PSendSysMessage(LANG_YOU_TAKE_MONEY, MoneyToString(abs(addmoney)).c_str(), GetNameLink(chr).c_str());
1593 if (needReportToTarget(chr))
1594 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), MoneyToString(abs(addmoney)).c_str());
1595 chr->SetMoney(newmoney);
1598 else
1600 PSendSysMessage(LANG_YOU_GIVE_MONEY, MoneyToString(addmoney).c_str(), GetNameLink(chr).c_str());
1601 if (needReportToTarget(chr))
1602 ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), MoneyToString(addmoney).c_str());
1604 if (addmoney >= MAX_MONEY_AMOUNT)
1605 chr->SetMoney(MAX_MONEY_AMOUNT);
1606 else
1607 chr->ModifyMoney(addmoney);
1610 DETAIL_LOG("USER2: %s, ADD: %s, RESULT: %s\n",
1611 MoneyToString(moneyuser).c_str(), MoneyToString(addmoney).c_str(), MoneyToString(chr->GetMoney()).c_str());
1613 return true;
1616 bool ChatHandler::HandleTeleCommand(char* args)
1618 if (!*args)
1619 return false;
1621 Player* _player = m_session->GetPlayer();
1623 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1624 GameTele const* tele = ExtractGameTeleFromLink(&args);
1626 if (!tele)
1628 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1629 SetSentErrorMessage(true);
1630 return false;
1633 return HandleGoHelper(_player, tele->mapId, tele->position_x, tele->position_y, &tele->position_z, &tele->orientation);
1636 bool ChatHandler::HandleLookupAreaCommand(char* args)
1638 if (!*args)
1639 return false;
1641 std::string namepart = args;
1642 std::wstring wnamepart;
1644 if (!Utf8toWStr(namepart, wnamepart))
1645 return false;
1647 uint32 counter = 0; // Counter for figure out that we found smth.
1649 // converting string that we try to find to lower case
1650 wstrToLower(wnamepart);
1652 // Search in AreaTable.dbc
1653 for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows(); ++areaflag)
1655 AreaTableEntry const* areaEntry = sAreaStore.LookupEntry(areaflag);
1656 if (areaEntry)
1658 int loc = GetSessionDbcLocale();
1659 std::string name = areaEntry->area_name[loc];
1660 if (name.empty())
1661 continue;
1663 if (!Utf8FitTo(name, wnamepart))
1665 loc = 0;
1666 for (; loc < MAX_LOCALE; ++loc)
1668 if (loc == GetSessionDbcLocale())
1669 continue;
1671 name = areaEntry->area_name[loc];
1672 if (name.empty())
1673 continue;
1675 if (Utf8FitTo(name, wnamepart))
1676 break;
1680 if (loc < MAX_LOCALE)
1682 // send area in "id - [name]" format
1683 std::ostringstream ss;
1684 if (m_session)
1685 ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc] << "]|h|r";
1686 else
1687 ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1689 SendSysMessage(ss.str().c_str());
1691 ++counter;
1696 if (counter == 0) // if counter == 0 then we found nth
1697 SendSysMessage(LANG_COMMAND_NOAREAFOUND);
1699 return true;
1702 // Find tele in game_tele order by name
1703 bool ChatHandler::HandleLookupTeleCommand(char* args)
1705 if (!*args)
1707 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1708 SetSentErrorMessage(true);
1709 return false;
1712 std::string namepart = args;
1713 std::wstring wnamepart;
1715 if (!Utf8toWStr(namepart, wnamepart))
1716 return false;
1718 // converting string that we try to find to lower case
1719 wstrToLower(wnamepart);
1721 std::ostringstream reply;
1723 GameTeleMap const& teleMap = sObjectMgr.GetGameTeleMap();
1724 for (GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1726 GameTele const* tele = &itr->second;
1728 if (tele->wnameLow.find(wnamepart) == std::wstring::npos)
1729 continue;
1731 if (m_session)
1732 reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1733 else
1734 reply << " " << itr->first << " " << tele->name << "\n";
1737 if (reply.str().empty())
1738 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1739 else
1740 PSendSysMessage(LANG_COMMAND_TELE_LOCATION, reply.str().c_str());
1742 return true;
1745 // Enable\Dissable accept whispers (for GM)
1746 bool ChatHandler::HandleWhispersCommand(char* args)
1748 if (!*args)
1750 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, GetOnOffStr(m_session->GetPlayer()->isAcceptWhispers()));
1751 return true;
1754 bool value;
1755 if (!ExtractOnOff(&args, value))
1757 SendSysMessage(LANG_USE_BOL);
1758 SetSentErrorMessage(true);
1759 return false;
1762 // whisper on
1763 if (value)
1765 m_session->GetPlayer()->SetAcceptWhispers(true);
1766 SendSysMessage(LANG_COMMAND_WHISPERON);
1768 // whisper off
1769 else
1771 m_session->GetPlayer()->SetAcceptWhispers(false);
1772 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1775 return true;
1778 // Save all players in the world
1779 bool ChatHandler::HandleSaveAllCommand(char* /*args*/)
1781 sObjectAccessor.SaveAllPlayers();
1782 SendSysMessage(LANG_PLAYERS_SAVED);
1783 return true;
1786 // Send mail by command
1787 bool ChatHandler::HandleSendMailCommand(char* args)
1789 // format: name "subject text" "mail text"
1790 Player* target;
1791 ObjectGuid target_guid;
1792 std::string target_name;
1793 if (!ExtractPlayerTarget(&args, &target, &target_guid, &target_name))
1794 return false;
1796 MailDraft draft;
1798 // fill draft
1799 if (!HandleSendMailHelper(draft, args))
1800 return false;
1802 // from console show nonexistent sender
1803 MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetObjectGuid().GetCounter() : 0, MAIL_STATIONERY_GM);
1805 draft.SendMailTo(MailReceiver(target, target_guid), sender);
1807 std::string nameLink = playerLink(target_name);
1808 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
1809 return true;
1812 // teleport player to given game_tele.entry
1813 bool ChatHandler::HandleTeleNameCommand(char* args)
1815 char* nameStr = ExtractOptNotLastArg(&args);
1817 Player* target;
1818 ObjectGuid target_guid;
1819 std::string target_name;
1820 if (!ExtractPlayerTarget(&nameStr, &target, &target_guid, &target_name))
1821 return false;
1823 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1824 GameTele const* tele = ExtractGameTeleFromLink(&args);
1825 if (!tele)
1827 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1828 SetSentErrorMessage(true);
1829 return false;
1832 if (target)
1834 // check online security
1835 if (HasLowerSecurity(target))
1836 return false;
1838 std::string chrNameLink = playerLink(target_name);
1840 if (target->IsBeingTeleported() == true)
1842 PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str());
1843 SetSentErrorMessage(true);
1844 return false;
1847 PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(), "", tele->name.c_str());
1848 if (needReportToTarget(target))
1849 ChatHandler(target).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str());
1851 return HandleGoHelper(target, tele->mapId, tele->position_x, tele->position_y, &tele->position_z, &tele->orientation);
1853 else
1855 // check offline security
1856 if (HasLowerSecurity(NULL, target_guid))
1857 return false;
1859 std::string nameLink = playerLink(target_name);
1861 PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
1862 Player::SavePositionInDB(target_guid, tele->mapId,
1863 tele->position_x, tele->position_y, tele->position_z, tele->orientation,
1864 sTerrainMgr.GetZoneId(tele->mapId, tele->position_x, tele->position_y, tele->position_z));
1867 return true;
1870 // Teleport group to given game_tele.entry
1871 bool ChatHandler::HandleTeleGroupCommand(char* args)
1873 if (!*args)
1874 return false;
1876 Player* player = getSelectedPlayer();
1877 if (!player)
1879 SendSysMessage(LANG_NO_CHAR_SELECTED);
1880 SetSentErrorMessage(true);
1881 return false;
1884 // check online security
1885 if (HasLowerSecurity(player))
1886 return false;
1888 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1889 GameTele const* tele = ExtractGameTeleFromLink(&args);
1890 if (!tele)
1892 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1893 SetSentErrorMessage(true);
1894 return false;
1897 std::string nameLink = GetNameLink(player);
1899 Group* grp = player->GetGroup();
1900 if (!grp)
1902 PSendSysMessage(LANG_NOT_IN_GROUP, nameLink.c_str());
1903 SetSentErrorMessage(true);
1904 return false;
1907 for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
1909 Player* pl = itr->getSource();
1911 if (!pl || !pl->GetSession())
1912 continue;
1914 // check online security
1915 if (HasLowerSecurity(pl))
1916 return false;
1918 std::string plNameLink = GetNameLink(pl);
1920 if (pl->IsBeingTeleported())
1922 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
1923 continue;
1926 PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(), "", tele->name.c_str());
1927 if (needReportToTarget(pl))
1928 ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str());
1930 // stop flight if need
1931 if (pl->IsTaxiFlying())
1933 pl->GetMotionMaster()->MovementExpired();
1934 pl->m_taxi.ClearTaxiDestinations();
1936 // save only in non-flight case
1937 else
1938 pl->SaveRecallPosition();
1940 pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1943 return true;
1946 // Summon group of player
1947 bool ChatHandler::HandleGroupgoCommand(char* args)
1949 Player* target;
1950 if (!ExtractPlayerTarget(&args, &target))
1951 return false;
1953 // check online security
1954 if (HasLowerSecurity(target))
1955 return false;
1957 Group* grp = target->GetGroup();
1959 std::string nameLink = GetNameLink(target);
1961 if (!grp)
1963 PSendSysMessage(LANG_NOT_IN_GROUP, nameLink.c_str());
1964 SetSentErrorMessage(true);
1965 return false;
1968 Map* gmMap = m_session->GetPlayer()->GetMap();
1969 bool to_instance = gmMap->Instanceable();
1971 // we are in instance, and can summon only player in our group with us as lead
1972 if (to_instance && (
1973 !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGuid() != m_session->GetPlayer()->GetObjectGuid()) ||
1974 (m_session->GetPlayer()->GetGroup()->GetLeaderGuid() != m_session->GetPlayer()->GetObjectGuid())))
1975 // the last check is a bit excessive, but let it be, just in case
1977 SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
1978 SetSentErrorMessage(true);
1979 return false;
1982 for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
1984 Player* pl = itr->getSource();
1986 if (!pl || pl == m_session->GetPlayer() || !pl->GetSession())
1987 continue;
1989 // check online security
1990 if (HasLowerSecurity(pl))
1991 return false;
1993 std::string plNameLink = GetNameLink(pl);
1995 if (pl->IsBeingTeleported() == true)
1997 PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
1998 SetSentErrorMessage(true);
1999 return false;
2002 if (to_instance)
2004 Map* plMap = pl->GetMap();
2006 if (plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId())
2008 // cannot summon from instance to instance
2009 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, plNameLink.c_str());
2010 SetSentErrorMessage(true);
2011 return false;
2015 PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(), "");
2016 if (needReportToTarget(pl))
2017 ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, nameLink.c_str());
2019 // stop flight if need
2020 if (pl->IsTaxiFlying())
2022 pl->GetMotionMaster()->MovementExpired();
2023 pl->m_taxi.ClearTaxiDestinations();
2025 // save only in non-flight case
2026 else
2027 pl->SaveRecallPosition();
2029 // before GM
2030 float x, y, z;
2031 m_session->GetPlayer()->GetClosePoint(x, y, z, pl->GetObjectBoundingRadius());
2032 pl->TeleportTo(m_session->GetPlayer()->GetMapId(), x, y, z, pl->GetOrientation());
2035 return true;
2038 bool ChatHandler::HandleGoHelper(Player* player, uint32 mapid, float x, float y, float const* zPtr, float const* ortPtr)
2040 float z;
2041 float ort = player->GetOrientation();
2043 if (zPtr)
2045 z = *zPtr;
2047 if (ortPtr)
2048 ort = *ortPtr;
2050 // check full provided coordinates
2051 if (!MapManager::IsValidMapCoord(mapid, x, y, z, ort))
2053 PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapid);
2054 SetSentErrorMessage(true);
2055 return false;
2058 else
2060 // we need check x,y before ask Z or can crash at invalide coordinates
2061 if (!MapManager::IsValidMapCoord(mapid, x, y))
2063 PSendSysMessage(LANG_INVALID_TARGET_COORD, x, y, mapid);
2064 SetSentErrorMessage(true);
2065 return false;
2068 TerrainInfo const* map = sTerrainMgr.LoadTerrain(mapid);
2069 z = map->GetWaterOrGroundLevel(x, y, MAX_HEIGHT);
2072 // stop flight if need
2073 if (player->IsTaxiFlying())
2075 player->GetMotionMaster()->MovementExpired();
2076 player->m_taxi.ClearTaxiDestinations();
2078 // save only in non-flight case
2079 else
2080 player->SaveRecallPosition();
2082 player->TeleportTo(mapid, x, y, z, ort);
2084 return true;
2087 bool ChatHandler::HandleGoTaxinodeCommand(char* args)
2089 Player* _player = m_session->GetPlayer();
2091 uint32 nodeId;
2092 if (!ExtractUint32KeyFromLink(&args, "Htaxinode", nodeId))
2093 return false;
2095 TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(nodeId);
2096 if (!node)
2098 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND, nodeId);
2099 SetSentErrorMessage(true);
2100 return false;
2103 if (node->x == 0.0f && node->y == 0.0f && node->z == 0.0f)
2105 PSendSysMessage(LANG_INVALID_TARGET_COORD, node->x, node->y, node->map_id);
2106 SetSentErrorMessage(true);
2107 return false;
2110 return HandleGoHelper(_player, node->map_id, node->x, node->y, &node->z);
2113 bool ChatHandler::HandleGoCommand(char* args)
2115 if (!*args)
2116 return false;
2118 Player* _player = m_session->GetPlayer();
2120 uint32 mapid;
2121 float x, y, z;
2123 // raw coordinates case
2124 if (ExtractFloat(&args, x))
2126 if (!ExtractFloat(&args, y))
2127 return false;
2129 if (!ExtractFloat(&args, z))
2130 return false;
2132 if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
2133 return false;
2135 // link case
2136 else if (!ExtractLocationFromLink(&args, mapid, x, y, z))
2137 return false;
2139 return HandleGoHelper(_player, mapid, x, y, &z);
2144 // teleport at coordinates
2145 bool ChatHandler::HandleGoXYCommand(char* args)
2147 Player* _player = m_session->GetPlayer();
2149 float x;
2150 if (!ExtractFloat(&args, x))
2151 return false;
2153 float y;
2154 if (!ExtractFloat(&args, y))
2155 return false;
2157 uint32 mapid;
2158 if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
2159 return false;
2161 return HandleGoHelper(_player, mapid, x, y);
2164 // teleport at coordinates, including Z
2165 bool ChatHandler::HandleGoXYZCommand(char* args)
2167 Player* _player = m_session->GetPlayer();
2169 float x;
2170 if (!ExtractFloat(&args, x))
2171 return false;
2173 float y;
2174 if (!ExtractFloat(&args, y))
2175 return false;
2177 float z;
2178 if (!ExtractFloat(&args, z))
2179 return false;
2181 uint32 mapid;
2182 if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
2183 return false;
2185 return HandleGoHelper(_player, mapid, x, y, &z);
2188 // teleport at coordinates
2189 bool ChatHandler::HandleGoZoneXYCommand(char* args)
2191 Player* _player = m_session->GetPlayer();
2193 float x;
2194 if (!ExtractFloat(&args, x))
2195 return false;
2197 float y;
2198 if (!ExtractFloat(&args, y))
2199 return false;
2201 uint32 areaid;
2202 if (*args)
2204 if (!ExtractUint32KeyFromLink(&args, "Harea", areaid))
2205 return false;
2207 else
2208 areaid = _player->GetZoneId();
2210 AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2212 if (x < 0 || x > 100 || y < 0 || y > 100 || !areaEntry)
2214 PSendSysMessage(LANG_INVALID_ZONE_COORD, x, y, areaid);
2215 SetSentErrorMessage(true);
2216 return false;
2219 // update to parent zone if exist (client map show only zones without parents)
2220 AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2222 MapEntry const* mapEntry = sMapStore.LookupEntry(zoneEntry->mapid);
2224 if (mapEntry->Instanceable())
2226 PSendSysMessage(LANG_INVALID_ZONE_MAP, areaEntry->ID, areaEntry->area_name[GetSessionDbcLocale()],
2227 mapEntry->MapID, mapEntry->name[GetSessionDbcLocale()]);
2228 SetSentErrorMessage(true);
2229 return false;
2232 if (!Zone2MapCoordinates(x, y, zoneEntry->ID))
2234 PSendSysMessage(LANG_INVALID_ZONE_MAP, areaEntry->ID, areaEntry->area_name[GetSessionDbcLocale()],
2235 mapEntry->MapID, mapEntry->name[GetSessionDbcLocale()]);
2236 SetSentErrorMessage(true);
2237 return false;
2240 return HandleGoHelper(_player, mapEntry->MapID, x, y);
2243 // teleport to grid
2244 bool ChatHandler::HandleGoGridCommand(char* args)
2246 Player* _player = m_session->GetPlayer();
2248 float grid_x;
2249 if (!ExtractFloat(&args, grid_x))
2250 return false;
2252 float grid_y;
2253 if (!ExtractFloat(&args, grid_y))
2254 return false;
2256 uint32 mapid;
2257 if (!ExtractOptUInt32(&args, mapid, _player->GetMapId()))
2258 return false;
2260 // center of grid
2261 float x = (grid_x - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
2262 float y = (grid_y - CENTER_GRID_ID + 0.5f) * SIZE_OF_GRIDS;
2264 return HandleGoHelper(_player, mapid, x, y);
2267 bool ChatHandler::HandleModifyDrunkCommand(char* args)
2269 if (!*args) return false;
2271 uint32 drunklevel = (uint32)atoi(args);
2272 if (drunklevel > 100)
2273 drunklevel = 100;
2275 uint16 drunkMod = drunklevel * 0xFFFF / 100;
2277 m_session->GetPlayer()->SetDrunkValue(drunkMod);
2279 return true;
2282 bool ChatHandler::HandleSetViewCommand(char* /*args*/)
2284 if (Unit* unit = getSelectedUnit())
2285 m_session->GetPlayer()->GetCamera().SetView(unit);
2286 else
2288 PSendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2289 SetSentErrorMessage(true);
2290 return false;
2293 return true;