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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
33 #include "MapPersistentStateMgr.h"
38 #include "VMapFactory.h"
41 //-----------------------Npc Commands-----------------------
42 bool ChatHandler::HandleNpcSayCommand(char* args
)
47 Creature
* pCreature
= getSelectedCreature();
50 SendSysMessage(LANG_SELECT_CREATURE
);
51 SetSentErrorMessage(true);
55 pCreature
->MonsterSay(args
, LANG_UNIVERSAL
);
60 bool ChatHandler::HandleNpcYellCommand(char* args
)
65 Creature
* pCreature
= getSelectedCreature();
68 SendSysMessage(LANG_SELECT_CREATURE
);
69 SetSentErrorMessage(true);
73 pCreature
->MonsterYell(args
, LANG_UNIVERSAL
);
78 // show text emote by creature in chat
79 bool ChatHandler::HandleNpcTextEmoteCommand(char* args
)
84 Creature
* pCreature
= getSelectedCreature();
88 SendSysMessage(LANG_SELECT_CREATURE
);
89 SetSentErrorMessage(true);
93 pCreature
->MonsterTextEmote(args
, NULL
);
98 // make npc whisper to player
99 bool ChatHandler::HandleNpcWhisperCommand(char* args
)
102 if (!ExtractPlayerTarget(&args
, &target
))
105 ObjectGuid guid
= m_session
->GetPlayer()->GetSelectionGuid();
109 Creature
* pCreature
= m_session
->GetPlayer()->GetMap()->GetCreature(guid
);
111 if (!pCreature
|| !target
|| !*args
)
114 // check online security
115 if (HasLowerSecurity(target
))
118 pCreature
->MonsterWhisper(args
, target
);
122 //----------------------------------------------------------
125 bool ChatHandler::HandleAnnounceCommand(char* args
)
130 sWorld
.SendWorldText(LANG_SYSTEMMESSAGE
, args
);
134 // notification player at the screen
135 bool ChatHandler::HandleNotifyCommand(char* args
)
140 std::string str
= GetMangosString(LANG_GLOBAL_NOTIFY
);
143 WorldPacket
data(SMSG_NOTIFICATION
, str
.size() + 1);
144 data
.WriteBits(str
.length(), 13);
146 data
.append(str
.c_str(), str
.length());
147 sWorld
.SendGlobalMessage(&data
);
152 // Enable\Dissable GM Mode
153 bool ChatHandler::HandleGMCommand(char* args
)
157 if (m_session
->GetPlayer()->isGameMaster())
158 m_session
->SendNotification(LANG_GM_ON
);
160 m_session
->SendNotification(LANG_GM_OFF
);
165 if (!ExtractOnOff(&args
, value
))
167 SendSysMessage(LANG_USE_BOL
);
168 SetSentErrorMessage(true);
174 m_session
->GetPlayer()->SetGameMaster(true);
175 m_session
->SendNotification(LANG_GM_ON
);
179 m_session
->GetPlayer()->SetGameMaster(false);
180 m_session
->SendNotification(LANG_GM_OFF
);
186 // Enables or disables hiding of the staff badge
187 bool ChatHandler::HandleGMChatCommand(char* args
)
191 if (m_session
->GetPlayer()->isGMChat())
192 m_session
->SendNotification(LANG_GM_CHAT_ON
);
194 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
199 if (!ExtractOnOff(&args
, value
))
201 SendSysMessage(LANG_USE_BOL
);
202 SetSentErrorMessage(true);
208 m_session
->GetPlayer()->SetGMChat(true);
209 m_session
->SendNotification(LANG_GM_CHAT_ON
);
213 m_session
->GetPlayer()->SetGMChat(false);
214 m_session
->SendNotification(LANG_GM_CHAT_OFF
);
220 // Enable\Dissable Invisible mode
221 bool ChatHandler::HandleGMVisibleCommand(char* args
)
225 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? GetMangosString(LANG_VISIBLE
) : GetMangosString(LANG_INVISIBLE
));
230 if (!ExtractOnOff(&args
, value
))
232 SendSysMessage(LANG_USE_BOL
);
233 SetSentErrorMessage(true);
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
;
244 player
->SetGMVisible(true);
245 m_session
->SendNotification(LANG_INVISIBLE_VISIBLE
);
246 if (invisibleAuraInfo
)
247 player
->RemoveAurasDueToSpell(invisibleAuraInfo
->Id
);
251 m_session
->SendNotification(LANG_INVISIBLE_INVISIBLE
);
252 player
->SetGMVisible(false);
253 if (invisibleAuraInfo
)
254 player
->CastSpell(player
, invisibleAuraInfo
, true);
260 bool ChatHandler::HandleGPSCommand(char* args
)
262 WorldObject
* obj
= NULL
;
265 if (ObjectGuid guid
= ExtractGuidFromLink(&args
))
266 obj
= (WorldObject
*)m_session
->GetPlayer()->GetObjectByTypeMask(guid
, TYPEMASK_CREATURE_OR_GAMEOBJECT
);
270 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
271 SetSentErrorMessage(true);
277 obj
= getSelectedUnit();
281 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
282 SetSentErrorMessage(true);
286 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
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
))
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;
319 if (map
->IsOutdoors(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ()))
320 PSendSysMessage("You are OUTdoor");
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>"),
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>"),
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
);
353 PSendSysMessage(LANG_LIQUID_STATUS
, liquid_status
.level
, liquid_status
.depth_level
, liquid_status
.type
, res
);
359 bool ChatHandler::HandleNamegoCommand(char* args
)
362 ObjectGuid target_guid
;
363 std::string target_name
;
364 if (!ExtractPlayerTarget(&args
, &target
, &target_guid
, &target_name
))
367 Player
* _player
= m_session
->GetPlayer();
368 if (target
== _player
|| target_guid
== _player
->GetObjectGuid())
370 PSendSysMessage(LANG_CANT_TELEPORT_SELF
);
371 SetSentErrorMessage(true);
377 std::string nameLink
= playerLink(target_name
);
378 // check online security
379 if (HasLowerSecurity(target
))
382 if (target
->IsBeingTeleported())
384 PSendSysMessage(LANG_IS_TELEPORTED
, nameLink
.c_str());
385 SetSentErrorMessage(true);
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);
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);
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);
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);
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
449 target
->SaveRecallPosition();
453 m_session
->GetPlayer()->GetClosePoint(x
, y
, z
, target
->GetObjectBoundingRadius());
454 target
->TeleportTo(m_session
->GetPlayer()->GetMapId(), x
, y
, z
, target
->GetOrientation());
458 // check offline security
459 if (HasLowerSecurity(NULL
, target_guid
))
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());
478 // Teleport to Player
479 bool ChatHandler::HandleGonameCommand(char* args
)
482 ObjectGuid target_guid
;
483 std::string target_name
;
484 if (!ExtractPlayerTarget(&args
, &target
, &target_guid
, &target_name
))
487 Player
* _player
= m_session
->GetPlayer();
488 if (target
== _player
|| target_guid
== _player
->GetObjectGuid())
490 SendSysMessage(LANG_CANT_TELEPORT_SELF
);
491 SetSentErrorMessage(true);
498 // check online security
499 if (HasLowerSecurity(target
))
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);
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);
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);
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);
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()));
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
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());
571 _player
->BindToInstance(save
, !save
->CanReset());
576 _player
->SetRaidDifficulty(target
->GetRaidDifficulty());
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
593 _player
->SaveRecallPosition();
595 // to point to see at target with same orientation
597 target
->GetContactPoint(_player
, x
, y
, z
);
599 _player
->TeleportTo(target
->GetMapId(), x
, y
, z
, _player
->GetAngle(target
), TELE_TO_GM_MODE
);
603 // check offline security
604 if (HasLowerSecurity(NULL
, target_guid
))
607 std::string nameLink
= playerLink(target_name
);
609 PSendSysMessage(LANG_APPEARING_AT
, nameLink
.c_str());
611 // to point where player stay (if loaded)
615 if (!Player::LoadPositionFromDB(target_guid
, map
, x
, y
, z
, o
, in_flight
))
618 return HandleGoHelper(_player
, map
, x
, y
, &z
);
624 // Teleport player to last position
625 bool ChatHandler::HandleRecallCommand(char* args
)
628 if (!ExtractPlayerTarget(&args
, &target
))
631 // check online security
632 if (HasLowerSecurity(target
))
635 if (target
->IsBeingTeleported())
637 PSendSysMessage(LANG_IS_TELEPORTED
, GetNameLink(target
).c_str());
638 SetSentErrorMessage(true);
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
)
650 int32 power
= atoi(args
);
654 SendSysMessage(LANG_BAD_VALUE
);
655 SetSentErrorMessage(true);
659 Player
* chr
= getSelectedPlayer();
662 SendSysMessage(LANG_NO_CHAR_SELECTED
);
663 SetSentErrorMessage(true);
667 // check online security
668 if (HasLowerSecurity(chr
))
671 int32 maxPower
= int32(chr
->GetMaxPower(POWER_HOLY_POWER
));
672 if (power
> maxPower
)
674 SendSysMessage(LANG_BAD_VALUE
);
675 SetSentErrorMessage(true);
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
);
689 bool ChatHandler::HandleModifyHPCommand(char* args
)
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);
704 Player
* chr
= getSelectedPlayer();
707 SendSysMessage(LANG_NO_CHAR_SELECTED
);
708 SetSentErrorMessage(true);
712 // check online security
713 if (HasLowerSecurity(chr
))
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
);
727 bool ChatHandler::HandleModifyManaCommand(char* args
)
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);
742 Player
* chr
= getSelectedPlayer();
745 SendSysMessage(LANG_NO_CHAR_SELECTED
);
746 SetSentErrorMessage(true);
750 // check online security
751 if (HasLowerSecurity(chr
))
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
);
764 // Edit Player Energy
765 bool ChatHandler::HandleModifyEnergyCommand(char* args
)
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);
780 Player
* chr
= getSelectedPlayer();
783 SendSysMessage(LANG_NO_CHAR_SELECTED
);
784 SetSentErrorMessage(true);
788 // check online security
789 if (HasLowerSecurity(chr
))
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
));
805 bool ChatHandler::HandleModifyRageCommand(char* args
)
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);
820 Player
* chr
= getSelectedPlayer();
823 SendSysMessage(LANG_NO_CHAR_SELECTED
);
824 SetSentErrorMessage(true);
828 // check online security
829 if (HasLowerSecurity(chr
))
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
);
842 // Edit Player Runic Power
843 bool ChatHandler::HandleModifyRunicPowerCommand(char* args
)
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);
858 Player
* chr
= getSelectedPlayer();
861 SendSysMessage(LANG_NO_CHAR_SELECTED
);
862 SetSentErrorMessage(true);
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
);
876 // Edit Player Faction
877 bool ChatHandler::HandleModifyFactionCommand(char* args
)
879 Creature
* chr
= getSelectedCreature();
882 SendSysMessage(LANG_SELECT_CREATURE
);
883 SetSentErrorMessage(true);
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
);
902 SendSysMessage(LANG_NO_CHAR_SELECTED
);
903 SetSentErrorMessage(true);
908 if (!ExtractUint32KeyFromLink(&args
, "Hfaction", factionid
))
911 if (!sFactionTemplateStore
.LookupEntry(factionid
))
913 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
914 SetSentErrorMessage(true);
919 if (!ExtractOptUInt32(&args
, flag
, chr
->GetUInt32Value(UNIT_FIELD_FLAGS
)))
923 if (!ExtractOptUInt32(&args
, npcflag
, chr
->GetUInt32Value(UNIT_NPC_FLAGS
)))
927 if (!ExtractOptUInt32(&args
, dyflag
, chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
)))
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
);
941 bool ChatHandler::HandleModifyTalentCommand(char* args
)
950 Unit
* target
= getSelectedUnit();
953 SendSysMessage(LANG_NO_CHAR_SELECTED
);
954 SetSentErrorMessage(true);
958 if (target
->GetTypeId() == TYPEID_PLAYER
)
960 // check online security
961 if (HasLowerSecurity((Player
*)target
))
964 ((Player
*)target
)->SetFreeTalentPoints(tp
);
965 ((Player
*)target
)->SendTalentsInfoData(false);
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
))
977 ((Pet
*)target
)->SetFreeTalentPoints(tp
);
978 ((Player
*)owner
)->SendTalentsInfoData(true);
983 SendSysMessage(LANG_NO_CHAR_SELECTED
);
984 SetSentErrorMessage(true);
988 // Enable On\OFF all taxi paths
989 bool ChatHandler::HandleTaxiCheatCommand(char* args
)
992 if (!ExtractOnOff(&args
, value
))
994 SendSysMessage(LANG_USE_BOL
);
995 SetSentErrorMessage(true);
999 Player
* chr
= getSelectedPlayer();
1001 chr
= m_session
->GetPlayer();
1002 // check online security
1003 else if (HasLowerSecurity(chr
))
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());
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());
1024 // Edit Player Aspeed
1025 bool ChatHandler::HandleModifyASpeedCommand(char* args
)
1030 float modSpeed
= (float)atof(args
);
1032 if (modSpeed
> 10 || modSpeed
< 0.1)
1034 SendSysMessage(LANG_BAD_VALUE
);
1035 SetSentErrorMessage(true);
1039 Player
* chr
= getSelectedPlayer();
1042 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1043 SetSentErrorMessage(true);
1047 // check online security
1048 if (HasLowerSecurity(chr
))
1051 std::string chrNameLink
= GetNameLink(chr
);
1053 if (chr
->IsTaxiFlying())
1055 PSendSysMessage(LANG_CHAR_IN_FLIGHT
, chrNameLink
.c_str());
1056 SetSentErrorMessage(true);
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
);
1072 // Edit Player Speed
1073 bool ChatHandler::HandleModifySpeedCommand(char* args
)
1078 float modSpeed
= (float)atof(args
);
1080 if (modSpeed
> 10 || modSpeed
< 0.1)
1082 SendSysMessage(LANG_BAD_VALUE
);
1083 SetSentErrorMessage(true);
1087 Player
* chr
= getSelectedPlayer();
1090 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1091 SetSentErrorMessage(true);
1095 // check online security
1096 if (HasLowerSecurity(chr
))
1099 std::string chrNameLink
= GetNameLink(chr
);
1101 if (chr
->IsTaxiFlying())
1103 PSendSysMessage(LANG_CHAR_IN_FLIGHT
, chrNameLink
.c_str());
1104 SetSentErrorMessage(true);
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
);
1117 // Edit Player Swim Speed
1118 bool ChatHandler::HandleModifySwimCommand(char* args
)
1123 float modSpeed
= (float)atof(args
);
1125 if (modSpeed
> 10.0f
|| modSpeed
< 0.01f
)
1127 SendSysMessage(LANG_BAD_VALUE
);
1128 SetSentErrorMessage(true);
1132 Player
* chr
= getSelectedPlayer();
1135 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1136 SetSentErrorMessage(true);
1140 // check online security
1141 if (HasLowerSecurity(chr
))
1144 std::string chrNameLink
= GetNameLink(chr
);
1146 if (chr
->IsTaxiFlying())
1148 PSendSysMessage(LANG_CHAR_IN_FLIGHT
, chrNameLink
.c_str());
1149 SetSentErrorMessage(true);
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
);
1162 // Edit Player Walk Speed
1163 bool ChatHandler::HandleModifyBWalkCommand(char* args
)
1168 float modSpeed
= (float)atof(args
);
1170 if (modSpeed
> 10.0f
|| modSpeed
< 0.1f
)
1172 SendSysMessage(LANG_BAD_VALUE
);
1173 SetSentErrorMessage(true);
1177 Player
* chr
= getSelectedPlayer();
1180 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1181 SetSentErrorMessage(true);
1185 // check online security
1186 if (HasLowerSecurity(chr
))
1189 std::string chrNameLink
= GetNameLink(chr
);
1191 if (chr
->IsTaxiFlying())
1193 PSendSysMessage(LANG_CHAR_IN_FLIGHT
, chrNameLink
.c_str());
1194 SetSentErrorMessage(true);
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
);
1208 bool ChatHandler::HandleModifyFlyCommand(char* args
)
1213 float modSpeed
= (float)atof(args
);
1215 if (modSpeed
> 10.0f
|| modSpeed
< 0.1f
)
1217 SendSysMessage(LANG_BAD_VALUE
);
1218 SetSentErrorMessage(true);
1222 Player
* chr
= getSelectedPlayer();
1225 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1226 SetSentErrorMessage(true);
1230 // check online security
1231 if (HasLowerSecurity(chr
))
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
);
1243 // Edit Player Scale
1244 bool ChatHandler::HandleModifyScaleCommand(char* args
)
1249 float Scale
= (float)atof(args
);
1250 if (Scale
> 10.0f
|| Scale
<= 0.0f
)
1252 SendSysMessage(LANG_BAD_VALUE
);
1253 SetSentErrorMessage(true);
1257 Unit
* target
= getSelectedUnit();
1260 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
1261 SetSentErrorMessage(true);
1265 if (target
->GetTypeId() == TYPEID_PLAYER
)
1267 // check online security
1268 if (HasLowerSecurity((Player
*)target
))
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();
1282 // Enable Player mount
1283 bool ChatHandler::HandleModifyMountCommand(char* args
)
1289 float speed
= (float)15;
1290 uint32 num
= atoi(args
);
1501 SendSysMessage(LANG_NO_MOUNT
);
1502 SetSentErrorMessage(true);
1506 Player
* chr
= getSelectedPlayer();
1509 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1510 SetSentErrorMessage(true);
1514 // check online security
1515 if (HasLowerSecurity(chr
))
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
);
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
);
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
);
1539 data
.WriteGuidBytes
<6, 3, 5, 2>(guid
);
1540 data
<< float(speed
);
1541 data
.WriteGuidBytes
<1, 7, 4>(guid
);
1542 chr
->SendMessageToSet(&data
, true);
1547 // Edit Player money
1548 bool ChatHandler::HandleModifyMoneyCommand(char* args
)
1553 Player
* chr
= getSelectedPlayer();
1556 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1557 SetSentErrorMessage(true);
1561 // check online security
1562 if (HasLowerSecurity(chr
))
1566 if (!ExtractInt64(&args
, addmoney
))
1569 uint64 moneyuser
= chr
->GetMoney();
1571 std::stringstream absadd
; absadd
<< abs(addmoney
);
1572 std::stringstream add
; add
<< addmoney
;
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());
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());
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
);
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
);
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());
1616 bool ChatHandler::HandleTeleCommand(char* args
)
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
);
1628 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1629 SetSentErrorMessage(true);
1633 return HandleGoHelper(_player
, tele
->mapId
, tele
->position_x
, tele
->position_y
, &tele
->position_z
, &tele
->orientation
);
1636 bool ChatHandler::HandleLookupAreaCommand(char* args
)
1641 std::string namepart
= args
;
1642 std::wstring wnamepart
;
1644 if (!Utf8toWStr(namepart
, wnamepart
))
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
);
1658 int loc
= GetSessionDbcLocale();
1659 std::string name
= areaEntry
->area_name
[loc
];
1663 if (!Utf8FitTo(name
, wnamepart
))
1666 for (; loc
< MAX_LOCALE
; ++loc
)
1668 if (loc
== GetSessionDbcLocale())
1671 name
= areaEntry
->area_name
[loc
];
1675 if (Utf8FitTo(name
, wnamepart
))
1680 if (loc
< MAX_LOCALE
)
1682 // send area in "id - [name]" format
1683 std::ostringstream ss
;
1685 ss
<< areaEntry
->ID
<< " - |cffffffff|Harea:" << areaEntry
->ID
<< "|h[" << name
<< " " << localeNames
[loc
] << "]|h|r";
1687 ss
<< areaEntry
->ID
<< " - " << name
<< " " << localeNames
[loc
];
1689 SendSysMessage(ss
.str().c_str());
1696 if (counter
== 0) // if counter == 0 then we found nth
1697 SendSysMessage(LANG_COMMAND_NOAREAFOUND
);
1702 // Find tele in game_tele order by name
1703 bool ChatHandler::HandleLookupTeleCommand(char* args
)
1707 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1708 SetSentErrorMessage(true);
1712 std::string namepart
= args
;
1713 std::wstring wnamepart
;
1715 if (!Utf8toWStr(namepart
, wnamepart
))
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
)
1732 reply
<< " |cffffffff|Htele:" << itr
->first
<< "|h[" << tele
->name
<< "]|h|r\n";
1734 reply
<< " " << itr
->first
<< " " << tele
->name
<< "\n";
1737 if (reply
.str().empty())
1738 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1740 PSendSysMessage(LANG_COMMAND_TELE_LOCATION
, reply
.str().c_str());
1745 // Enable\Dissable accept whispers (for GM)
1746 bool ChatHandler::HandleWhispersCommand(char* args
)
1750 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, GetOnOffStr(m_session
->GetPlayer()->isAcceptWhispers()));
1755 if (!ExtractOnOff(&args
, value
))
1757 SendSysMessage(LANG_USE_BOL
);
1758 SetSentErrorMessage(true);
1765 m_session
->GetPlayer()->SetAcceptWhispers(true);
1766 SendSysMessage(LANG_COMMAND_WHISPERON
);
1771 m_session
->GetPlayer()->SetAcceptWhispers(false);
1772 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1778 // Save all players in the world
1779 bool ChatHandler::HandleSaveAllCommand(char* /*args*/)
1781 sObjectAccessor
.SaveAllPlayers();
1782 SendSysMessage(LANG_PLAYERS_SAVED
);
1786 // Send mail by command
1787 bool ChatHandler::HandleSendMailCommand(char* args
)
1789 // format: name "subject text" "mail text"
1791 ObjectGuid target_guid
;
1792 std::string target_name
;
1793 if (!ExtractPlayerTarget(&args
, &target
, &target_guid
, &target_name
))
1799 if (!HandleSendMailHelper(draft
, args
))
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());
1812 // teleport player to given game_tele.entry
1813 bool ChatHandler::HandleTeleNameCommand(char* args
)
1815 char* nameStr
= ExtractOptNotLastArg(&args
);
1818 ObjectGuid target_guid
;
1819 std::string target_name
;
1820 if (!ExtractPlayerTarget(&nameStr
, &target
, &target_guid
, &target_name
))
1823 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1824 GameTele
const* tele
= ExtractGameTeleFromLink(&args
);
1827 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1828 SetSentErrorMessage(true);
1834 // check online security
1835 if (HasLowerSecurity(target
))
1838 std::string chrNameLink
= playerLink(target_name
);
1840 if (target
->IsBeingTeleported() == true)
1842 PSendSysMessage(LANG_IS_TELEPORTED
, chrNameLink
.c_str());
1843 SetSentErrorMessage(true);
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
);
1855 // check offline security
1856 if (HasLowerSecurity(NULL
, target_guid
))
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
));
1870 // Teleport group to given game_tele.entry
1871 bool ChatHandler::HandleTeleGroupCommand(char* args
)
1876 Player
* player
= getSelectedPlayer();
1879 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1880 SetSentErrorMessage(true);
1884 // check online security
1885 if (HasLowerSecurity(player
))
1888 // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1889 GameTele
const* tele
= ExtractGameTeleFromLink(&args
);
1892 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1893 SetSentErrorMessage(true);
1897 std::string nameLink
= GetNameLink(player
);
1899 Group
* grp
= player
->GetGroup();
1902 PSendSysMessage(LANG_NOT_IN_GROUP
, nameLink
.c_str());
1903 SetSentErrorMessage(true);
1907 for (GroupReference
* itr
= grp
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1909 Player
* pl
= itr
->getSource();
1911 if (!pl
|| !pl
->GetSession())
1914 // check online security
1915 if (HasLowerSecurity(pl
))
1918 std::string plNameLink
= GetNameLink(pl
);
1920 if (pl
->IsBeingTeleported())
1922 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
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
1938 pl
->SaveRecallPosition();
1940 pl
->TeleportTo(tele
->mapId
, tele
->position_x
, tele
->position_y
, tele
->position_z
, tele
->orientation
);
1946 // Summon group of player
1947 bool ChatHandler::HandleGroupgoCommand(char* args
)
1950 if (!ExtractPlayerTarget(&args
, &target
))
1953 // check online security
1954 if (HasLowerSecurity(target
))
1957 Group
* grp
= target
->GetGroup();
1959 std::string nameLink
= GetNameLink(target
);
1963 PSendSysMessage(LANG_NOT_IN_GROUP
, nameLink
.c_str());
1964 SetSentErrorMessage(true);
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);
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())
1989 // check online security
1990 if (HasLowerSecurity(pl
))
1993 std::string plNameLink
= GetNameLink(pl
);
1995 if (pl
->IsBeingTeleported() == true)
1997 PSendSysMessage(LANG_IS_TELEPORTED
, plNameLink
.c_str());
1998 SetSentErrorMessage(true);
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);
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
2027 pl
->SaveRecallPosition();
2031 m_session
->GetPlayer()->GetClosePoint(x
, y
, z
, pl
->GetObjectBoundingRadius());
2032 pl
->TeleportTo(m_session
->GetPlayer()->GetMapId(), x
, y
, z
, pl
->GetOrientation());
2038 bool ChatHandler::HandleGoHelper(Player
* player
, uint32 mapid
, float x
, float y
, float const* zPtr
, float const* ortPtr
)
2041 float ort
= player
->GetOrientation();
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);
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);
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
2080 player
->SaveRecallPosition();
2082 player
->TeleportTo(mapid
, x
, y
, z
, ort
);
2087 bool ChatHandler::HandleGoTaxinodeCommand(char* args
)
2089 Player
* _player
= m_session
->GetPlayer();
2092 if (!ExtractUint32KeyFromLink(&args
, "Htaxinode", nodeId
))
2095 TaxiNodesEntry
const* node
= sTaxiNodesStore
.LookupEntry(nodeId
);
2098 PSendSysMessage(LANG_COMMAND_GOTAXINODENOTFOUND
, nodeId
);
2099 SetSentErrorMessage(true);
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);
2110 return HandleGoHelper(_player
, node
->map_id
, node
->x
, node
->y
, &node
->z
);
2113 bool ChatHandler::HandleGoCommand(char* args
)
2118 Player
* _player
= m_session
->GetPlayer();
2123 // raw coordinates case
2124 if (ExtractFloat(&args
, x
))
2126 if (!ExtractFloat(&args
, y
))
2129 if (!ExtractFloat(&args
, z
))
2132 if (!ExtractOptUInt32(&args
, mapid
, _player
->GetMapId()))
2136 else if (!ExtractLocationFromLink(&args
, mapid
, x
, y
, z
))
2139 return HandleGoHelper(_player
, mapid
, x
, y
, &z
);
2144 // teleport at coordinates
2145 bool ChatHandler::HandleGoXYCommand(char* args
)
2147 Player
* _player
= m_session
->GetPlayer();
2150 if (!ExtractFloat(&args
, x
))
2154 if (!ExtractFloat(&args
, y
))
2158 if (!ExtractOptUInt32(&args
, mapid
, _player
->GetMapId()))
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();
2170 if (!ExtractFloat(&args
, x
))
2174 if (!ExtractFloat(&args
, y
))
2178 if (!ExtractFloat(&args
, z
))
2182 if (!ExtractOptUInt32(&args
, mapid
, _player
->GetMapId()))
2185 return HandleGoHelper(_player
, mapid
, x
, y
, &z
);
2188 // teleport at coordinates
2189 bool ChatHandler::HandleGoZoneXYCommand(char* args
)
2191 Player
* _player
= m_session
->GetPlayer();
2194 if (!ExtractFloat(&args
, x
))
2198 if (!ExtractFloat(&args
, y
))
2204 if (!ExtractUint32KeyFromLink(&args
, "Harea", areaid
))
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);
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);
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);
2240 return HandleGoHelper(_player
, mapEntry
->MapID
, x
, y
);
2244 bool ChatHandler::HandleGoGridCommand(char* args
)
2246 Player
* _player
= m_session
->GetPlayer();
2249 if (!ExtractFloat(&args
, grid_x
))
2253 if (!ExtractFloat(&args
, grid_y
))
2257 if (!ExtractOptUInt32(&args
, mapid
, _player
->GetMapId()))
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)
2275 uint16 drunkMod
= drunklevel
* 0xFFFF / 100;
2277 m_session
->GetPlayer()->SetDrunkValue(drunkMod
);
2282 bool ChatHandler::HandleSetViewCommand(char* /*args*/)
2284 if (Unit
* unit
= getSelectedUnit())
2285 m_session
->GetPlayer()->GetCamera().SetView(unit
);
2288 PSendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2289 SetSentErrorMessage(true);