root/trunk/src/game/Level1.cpp @ 28

Revision 28, 67.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Updated to 6743 and 685

Moved language id used by Arena to a higher place to solve conflicts
Added the empty script folders

Original author: Neo2003
Date: 2008-10-09 08:42:22-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "Common.h"
20#include "Database/DatabaseEnv.h"
21#include "WorldPacket.h"
22#include "WorldSession.h"
23#include "World.h"
24#include "ObjectMgr.h"
25#include "Player.h"
26#include "Opcodes.h"
27#include "Chat.h"
28#include "Log.h"
29#include "MapManager.h"
30#include "ObjectAccessor.h"
31#include "Language.h"
32#include "CellImpl.h"
33#include "InstanceSaveMgr.h"
34#include "Util.h"
35#ifdef _DEBUG_VMAPS
36#include "VMapFactory.h"
37#endif
38
39bool ChatHandler::HandleSayCommand(const char* args)
40{
41    if(!*args)
42        return false;
43
44    Creature* pCreature = getSelectedCreature();
45    if(!pCreature)
46    {
47        SendSysMessage(LANG_SELECT_CREATURE);
48        SetSentErrorMessage(true);
49        return false;
50    }
51
52    pCreature->Say(args, LANG_UNIVERSAL, 0);
53
54    return true;
55}
56
57bool ChatHandler::HandleYellCommand(const char* args)
58{
59    if(!*args)
60        return false;
61
62    Creature* pCreature = getSelectedCreature();
63    if(!pCreature)
64    {
65        SendSysMessage(LANG_SELECT_CREATURE);
66        SetSentErrorMessage(true);
67        return false;
68    }
69
70    pCreature->Yell(args, LANG_UNIVERSAL, 0);
71
72    return true;
73}
74
75//show text emote by creature in chat
76bool ChatHandler::HandleTextEmoteCommand(const char* args)
77{
78    if(!*args)
79        return false;
80
81    Creature* pCreature = getSelectedCreature();
82
83    if(!pCreature)
84    {
85        SendSysMessage(LANG_SELECT_CREATURE);
86        SetSentErrorMessage(true);
87        return false;
88    }
89
90    pCreature->TextEmote(args, 0);
91
92    return true;
93}
94
95// make npc whisper to player
96bool ChatHandler::HandleNpcWhisperCommand(const char* args)
97{
98    if(!*args)
99        return false;
100
101    char* receiver_str = strtok((char*)args, " ");
102    char* text = strtok(NULL, "");
103
104    uint64 guid = m_session->GetPlayer()->GetSelection();
105    Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
106
107    if(!pCreature || !receiver_str || !text)
108    {
109        return false;
110    }
111
112    uint64 receiver_guid= atol(receiver_str);
113
114    pCreature->Whisper(text,receiver_guid);
115
116    return true;
117}
118
119// global announce
120bool ChatHandler::HandleAnnounceCommand(const char* args)
121{
122    if(!*args)
123        return false;
124
125    sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
126    return true;
127}
128
129//notification player at the screen
130bool ChatHandler::HandleNotifyCommand(const char* args)
131{
132    if(!*args)
133        return false;
134
135    std::string str = GetMangosString(LANG_GLOBAL_NOTIFY);
136    str += args;
137
138    WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
139    data << str;
140    sWorld.SendGlobalMessage(&data);
141
142    return true;
143}
144
145//Enable\Dissable GM Mode
146bool ChatHandler::HandleGMmodeCommand(const char* args)
147{
148    if(!*args)
149    {
150        if(m_session->GetPlayer()->isGameMaster())
151            m_session->SendNotification(LANG_GM_ON);
152        else
153            m_session->SendNotification(LANG_GM_OFF);
154        return true;
155    }
156
157    std::string argstr = (char*)args;
158
159    if (argstr == "on")
160    {
161        m_session->GetPlayer()->SetGameMaster(true);
162        m_session->SendNotification(LANG_GM_ON);
163        #ifdef _DEBUG_VMAPS
164        VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
165        vMapManager->processCommand("stoplog");
166        #endif
167        return true;
168    }
169
170    if (argstr == "off")
171    {
172        m_session->GetPlayer()->SetGameMaster(false);
173        m_session->SendNotification(LANG_GM_OFF);
174        #ifdef _DEBUG_VMAPS
175        VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
176        vMapManager->processCommand("startlog");
177        #endif
178        return true;
179    }
180
181    SendSysMessage(LANG_USE_BOL);
182    SetSentErrorMessage(true);
183    return false;
184}
185
186// Enables or disables hiding of the staff badge
187bool ChatHandler::HandleGMChatCommand(const char* args)
188{
189    if(!*args)
190    {
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;
196    }
197
198    std::string argstr = (char*)args;
199
200    if (argstr == "on")
201    {
202        m_session->GetPlayer()->SetGMChat(true);
203        m_session->SendNotification(LANG_GM_CHAT_ON);
204        return true;
205    }
206
207    if (argstr == "off")
208    {
209        m_session->GetPlayer()->SetGMChat(false);
210        m_session->SendNotification(LANG_GM_CHAT_OFF);
211        return true;
212    }
213
214    SendSysMessage(LANG_USE_BOL);
215    SetSentErrorMessage(true);
216    return false;
217}
218
219
220//Enable\Dissable Invisible mode
221bool ChatHandler::HandleVisibleCommand(const char* args)
222{
223    if (!*args)
224    {
225        PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ?  GetMangosString(LANG_VISIBLE) : GetMangosString(LANG_INVISIBLE));
226        return true;
227    }
228
229    std::string argstr = (char*)args;
230
231    if (argstr == "on")
232    {
233        m_session->GetPlayer()->SetGMVisible(true);
234        m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
235        return true;
236    }
237
238    if (argstr == "off")
239    {
240        m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
241        m_session->GetPlayer()->SetGMVisible(false);
242        return true;
243    }
244
245    SendSysMessage(LANG_USE_BOL);
246    SetSentErrorMessage(true);
247    return false;
248}
249
250bool ChatHandler::HandleGPSCommand(const char* args)
251{
252    WorldObject *obj = NULL;
253    if (*args)
254    {
255        std::string name = args;
256        if(normalizePlayerName(name))
257            obj = objmgr.GetPlayer(name.c_str());
258
259        if(!obj)
260        {
261            SendSysMessage(LANG_PLAYER_NOT_FOUND);
262            SetSentErrorMessage(true);
263            return false;
264        }
265    }
266    else
267    {
268        obj = getSelectedUnit();
269
270        if(!obj)
271        {
272            SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
273            SetSentErrorMessage(true);
274            return false;
275        }
276    }
277    CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
278    Cell cell(cell_val);
279
280    uint32 zone_id = obj->GetZoneId();
281    uint32 area_id = obj->GetAreaId();
282
283    MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
284    AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
285    AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
286
287    float zone_x = obj->GetPositionX();
288    float zone_y = obj->GetPositionY();
289
290    Map2ZoneCoordinates(zone_x,zone_y,zone_id);
291
292    Map const *map = MapManager::Instance().GetMap(obj->GetMapId(), obj);
293    float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
294    float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
295
296    GridPair p = MaNGOS::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
297
298    int gx=63-p.x_coord;
299    int gy=63-p.y_coord;
300
301    uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
302    uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
303
304    PSendSysMessage(LANG_MAP_POSITION,
305        obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
306        zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
307        area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
308        obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
309        cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
310        zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
311
312    sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
313        m_session->GetPlayer()->GetName(),
314        (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
315        (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
316    sLog.outDebug(GetMangosString(LANG_MAP_POSITION),
317        obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
318        zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
319        area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
320        obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
321        cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
322        zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
323
324    return true;
325}
326
327//Summon Player
328bool ChatHandler::HandleNamegoCommand(const char* args)
329{
330    if(!*args)
331        return false;
332
333    std::string name = args;
334
335    if(!normalizePlayerName(name))
336    {
337        SendSysMessage(LANG_PLAYER_NOT_FOUND);
338        SetSentErrorMessage(true);
339        return false;
340    }
341
342    Player *chr = objmgr.GetPlayer(name.c_str());
343    if (chr)
344    {
345        if(chr->IsBeingTeleported()==true)
346        {
347            PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
348            SetSentErrorMessage(true);
349            return false;
350        }
351
352        Map* pMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
353
354        if(pMap->IsBattleGroundOrArena())
355        {
356            // cannot summon to bg
357            SendSysMessage(LANG_CANNOT_SUMMON_TO_BG);
358            SetSentErrorMessage(true);
359            return false;
360        }
361        else if(pMap->IsDungeon())
362        {
363            Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
364            if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
365            {
366                // cannot summon from instance to instance
367                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
368                SetSentErrorMessage(true);
369                return false;
370            }
371
372            // we are in instance, and can summon only player in our group with us as lead
373            if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
374                (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
375                (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
376                // the last check is a bit excessive, but let it be, just in case
377            {
378                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
379                SetSentErrorMessage(true);
380                return false;
381            }
382        }
383
384        PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
385
386        if (m_session->GetPlayer()->IsVisibleGloballyFor(chr))
387            ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
388
389        // stop flight if need
390        if(chr->isInFlight())
391        {
392            chr->GetMotionMaster()->MovementExpired();
393            chr->m_taxi.ClearTaxiDestinations();
394        }
395        // save only in non-flight case
396        else
397            chr->SaveRecallPosition();
398
399        // before GM
400        float x,y,z;
401        m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
402        chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
403    }
404    else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
405    {
406        PSendSysMessage(LANG_SUMMONING, name.c_str(),GetMangosString(LANG_OFFLINE));
407
408        // in point where GM stay
409        Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
410            m_session->GetPlayer()->GetPositionX(),
411            m_session->GetPlayer()->GetPositionY(),
412            m_session->GetPlayer()->GetPositionZ(),
413            m_session->GetPlayer()->GetOrientation(),
414            m_session->GetPlayer()->GetZoneId(),
415            guid);
416    }
417    else
418    {
419        PSendSysMessage(LANG_NO_PLAYER, args);
420        SetSentErrorMessage(true);
421    }
422
423    return true;
424}
425
426//Teleport to Player
427bool ChatHandler::HandleGonameCommand(const char* args)
428{
429    if(!*args)
430        return false;
431
432    Player* _player = m_session->GetPlayer();
433
434    std::string name = args;
435
436    if(!normalizePlayerName(name))
437    {
438        SendSysMessage(LANG_PLAYER_NOT_FOUND);
439        SetSentErrorMessage(true);
440        return false;
441    }
442
443    Player *chr = objmgr.GetPlayer(name.c_str());
444    if (chr)
445    {
446        Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
447        if(cMap->IsBattleGroundOrArena())
448        {
449            // only allow if gm mode is on
450            if (!_player->isGameMaster())
451            {
452                SendSysMessage(LANG_CANNOT_GO_TO_BG_GM);
453                SetSentErrorMessage(true);
454                return false;
455            }
456            // if already in a bg, don't let port to other
457            else if (_player->GetBattleGroundId())
458            {
459                SendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG);
460                SetSentErrorMessage(true);
461                return false;
462            }
463            // all's well, set bg id
464            // when porting out from the bg, it will be reset to 0
465            _player->SetBattleGroundId(chr->GetBattleGroundId());
466        }
467        else if(cMap->IsDungeon())
468        {
469            Map* pMap = MapManager::Instance().GetMap(_player->GetMapId(),_player);
470
471            // we have to go to instance, and can go to player only if:
472            //   1) we are in his group (either as leader or as member)
473            //   2) we are not bound to any group and have GM mode on
474            if (_player->GetGroup())
475            {
476                // we are in group, we can go only if we are in the player group
477                if (_player->GetGroup() != chr->GetGroup())
478                {
479                    PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName());
480                    SetSentErrorMessage(true);
481                    return false;
482                }
483            }
484            else
485            {
486                // we are not in group, let's verify our GM mode
487                if (!_player->isGameMaster())
488                {
489                    PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName());
490                    SetSentErrorMessage(true);
491                    return false;
492                }
493            }
494
495            // if the player or the player's group is bound to another instance
496            // the player will not be bound to another one
497            InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
498            if(!pBind)
499            {
500                Group *group = _player->GetGroup();
501                InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
502                if(!gBind)
503                {
504                    // if no bind exists, create a solo bind
505                    InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
506                    if(save) _player->BindToInstance(save, !save->CanReset());
507                }
508            }
509
510            _player->SetDifficulty(chr->GetDifficulty());
511        }
512
513        PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
514
515        if (_player->IsVisibleGloballyFor(chr))
516            ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, _player->GetName());
517
518        // stop flight if need
519        if(_player->isInFlight())
520        {
521            _player->GetMotionMaster()->MovementExpired();
522            _player->m_taxi.ClearTaxiDestinations();
523        }
524        // save only in non-flight case
525        else
526            _player->SaveRecallPosition();
527
528        // to point to see at target with same orientation
529        float x,y,z;
530        chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
531
532        _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
533
534        return true;
535    }
536
537    if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
538    {
539        PSendSysMessage(LANG_APPEARING_AT, name.c_str());
540
541        // to point where player stay (if loaded)
542        float x,y,z,o;
543        uint32 map;
544        bool in_flight;
545        if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
546        {
547            // stop flight if need
548            if(_player->isInFlight())
549            {
550                _player->GetMotionMaster()->MovementExpired();
551                _player->m_taxi.ClearTaxiDestinations();
552            }
553            // save only in non-flight case
554            else
555                _player->SaveRecallPosition();
556
557            _player->TeleportTo(map, x, y, z,_player->GetOrientation());
558            return true;
559        }
560    }
561
562    PSendSysMessage(LANG_NO_PLAYER, args);
563
564    SetSentErrorMessage(true);
565    return false;
566}
567
568// Teleport player to last position
569bool ChatHandler::HandleRecallCommand(const char* args)
570{
571    Player* chr = NULL;
572
573    if(!*args)
574    {
575        chr = getSelectedPlayer();
576        if(!chr)
577            chr = m_session->GetPlayer();
578    }
579    else
580    {
581        std::string name = args;
582
583        if(!normalizePlayerName(name))
584        {
585            SendSysMessage(LANG_PLAYER_NOT_FOUND);
586            SetSentErrorMessage(true);
587            return false;
588        }
589
590        chr = objmgr.GetPlayer(name.c_str());
591
592        if(!chr)
593        {
594            PSendSysMessage(LANG_NO_PLAYER, args);
595            SetSentErrorMessage(true);
596            return false;
597        }
598    }
599
600    if(chr->IsBeingTeleported())
601    {
602        PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
603        SetSentErrorMessage(true);
604        return false;
605    }
606
607    // stop flight if need
608    if(chr->isInFlight())
609    {
610        chr->GetMotionMaster()->MovementExpired();
611        chr->m_taxi.ClearTaxiDestinations();
612    }
613
614    chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
615    return true;
616}
617
618//Edit Player KnownTitles
619bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
620{
621    if(!*args)
622        return false;
623
624    uint64 titles = 0;
625
626    sscanf((char*)args, I64FMTD, &titles);
627
628    Player *chr = getSelectedPlayer();
629    if (!chr)
630    {
631        SendSysMessage(LANG_NO_CHAR_SELECTED);
632        SetSentErrorMessage(true);
633        return false;
634    }
635
636    uint64 titles2 = titles;
637
638    for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
639        if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
640            titles2 &= ~(uint64(1) << tEntry->bit_index);
641
642    titles &= ~titles2;                                     // remove not existed titles
643
644    chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
645    SendSysMessage(LANG_DONE);
646
647    return true;
648}
649
650//Edit Player HP
651bool ChatHandler::HandleModifyHPCommand(const char* args)
652{
653    if(!*args)
654        return false;
655
656    //    char* pHp = strtok((char*)args, " ");
657    //    if (!pHp)
658    //        return false;
659
660    //    char* pHpMax = strtok(NULL, " ");
661    //    if (!pHpMax)
662    //        return false;
663
664    //    int32 hpm = atoi(pHpMax);
665    //    int32 hp = atoi(pHp);
666
667    int32 hp = atoi((char*)args);
668    int32 hpm = atoi((char*)args);
669
670    if (hp <= 0 || hpm <= 0 || hpm < hp)
671    {
672        SendSysMessage(LANG_BAD_VALUE);
673        SetSentErrorMessage(true);
674        return false;
675    }
676
677    Player *chr = getSelectedPlayer();
678    if (chr == NULL)
679    {
680        SendSysMessage(LANG_NO_CHAR_SELECTED);
681        SetSentErrorMessage(true);
682        return false;
683    }
684
685    PSendSysMessage(LANG_YOU_CHANGE_HP, chr->GetName(), hp, hpm);
686    ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, m_session->GetPlayer()->GetName(), hp, hpm);
687
688    chr->SetMaxHealth( hpm );
689    chr->SetHealth( hp );
690
691    return true;
692}
693
694//Edit Player Mana
695bool ChatHandler::HandleModifyManaCommand(const char* args)
696{
697    if(!*args)
698        return false;
699
700    // char* pmana = strtok((char*)args, " ");
701    // if (!pmana)
702    //     return false;
703
704    // char* pmanaMax = strtok(NULL, " ");
705    // if (!pmanaMax)
706    //     return false;
707
708    // int32 manam = atoi(pmanaMax);
709    // int32 mana = atoi(pmana);
710    int32 mana = atoi((char*)args);
711    int32 manam = atoi((char*)args);
712
713    if (mana <= 0 || manam <= 0 || manam < mana)
714    {
715        SendSysMessage(LANG_BAD_VALUE);
716        SetSentErrorMessage(true);
717        return false;
718    }
719
720    Player *chr = getSelectedPlayer();
721    if (chr == NULL)
722    {
723        SendSysMessage(LANG_NO_CHAR_SELECTED);
724        SetSentErrorMessage(true);
725        return false;
726    }
727
728    PSendSysMessage(LANG_YOU_CHANGE_MANA, chr->GetName(), mana, manam);
729    ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, m_session->GetPlayer()->GetName(), mana, manam);
730
731    chr->SetMaxPower(POWER_MANA,manam );
732    chr->SetPower(POWER_MANA, mana );
733
734    return true;
735}
736
737//Edit Player Energy
738bool ChatHandler::HandleModifyEnergyCommand(const char* args)
739{
740    if(!*args)
741        return false;
742
743    // char* pmana = strtok((char*)args, " ");
744    // if (!pmana)
745    //     return false;
746
747    // char* pmanaMax = strtok(NULL, " ");
748    // if (!pmanaMax)
749    //     return false;
750
751    // int32 manam = atoi(pmanaMax);
752    // int32 mana = atoi(pmana);
753
754    int32 energy = atoi((char*)args)*10;
755    int32 energym = atoi((char*)args)*10;
756
757    if (energy <= 0 || energym <= 0 || energym < energy)
758    {
759        SendSysMessage(LANG_BAD_VALUE);
760        SetSentErrorMessage(true);
761        return false;
762    }
763
764    Player *chr = getSelectedPlayer();
765    if (!chr)
766    {
767        SendSysMessage(LANG_NO_CHAR_SELECTED);
768        SetSentErrorMessage(true);
769        return false;
770    }
771
772    PSendSysMessage(LANG_YOU_CHANGE_ENERGY, chr->GetName(), energy/10, energym/10);
773    ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, m_session->GetPlayer()->GetName(), energy/10, energym/10);
774
775    chr->SetMaxPower(POWER_ENERGY,energym );
776    chr->SetPower(POWER_ENERGY, energy );
777
778    sLog.outDetail(GetMangosString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
779
780    return true;
781}
782
783//Edit Player Rage
784bool ChatHandler::HandleModifyRageCommand(const char* args)
785{
786    if(!*args)
787        return false;
788
789    // char* pmana = strtok((char*)args, " ");
790    // if (!pmana)
791    //     return false;
792
793    // char* pmanaMax = strtok(NULL, " ");
794    // if (!pmanaMax)
795    //     return false;
796
797    // int32 manam = atoi(pmanaMax);
798    // int32 mana = atoi(pmana);
799
800    int32 rage = atoi((char*)args)*10;
801    int32 ragem = atoi((char*)args)*10;
802
803    if (rage <= 0 || ragem <= 0 || ragem < rage)
804    {
805        SendSysMessage(LANG_BAD_VALUE);
806        SetSentErrorMessage(true);
807        return false;
808    }
809
810    Player *chr = getSelectedPlayer();
811    if (chr == NULL)
812    {
813        SendSysMessage(LANG_NO_CHAR_SELECTED);
814        SetSentErrorMessage(true);
815        return false;
816    }
817
818    PSendSysMessage(LANG_YOU_CHANGE_RAGE, chr->GetName(), rage/10, ragem/10);
819                                                            // Special case: I use GetMangosString here to get local of destination char ;)
820    ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_RAGE_CHANGED), m_session->GetPlayer()->GetName(), rage/10, ragem/10);
821
822    chr->SetMaxPower(POWER_RAGE,ragem );
823    chr->SetPower(POWER_RAGE, rage );
824
825    return true;
826}
827
828//Edit Player Faction
829bool ChatHandler::HandleModifyFactionCommand(const char* args)
830{
831    if(!*args)
832        return false;
833
834    char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
835
836    Creature* chr = getSelectedCreature();
837    if(!chr)
838    {
839        SendSysMessage(LANG_SELECT_CREATURE);
840        SetSentErrorMessage(true);
841        return false;
842    }
843
844    if(!pfactionid)
845    {
846        if(chr)
847        {
848            uint32 factionid = chr->getFaction();
849            uint32 flag      = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
850            uint32 npcflag   = chr->GetUInt32Value(UNIT_NPC_FLAGS);
851            uint32 dyflag    = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
852            PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
853        }
854        return true;
855    }
856
857    if( !chr )
858    {
859        SendSysMessage(LANG_NO_CHAR_SELECTED);
860        SetSentErrorMessage(true);
861        return false;
862    }
863
864    uint32 factionid = atoi(pfactionid);
865    uint32 flag;
866
867    char *pflag = strtok(NULL, " ");
868    if (!pflag)
869        flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
870    else
871        flag = atoi(pflag);
872
873    char* pnpcflag = strtok(NULL, " ");
874
875    uint32 npcflag;
876    if(!pnpcflag)
877        npcflag   = chr->GetUInt32Value(UNIT_NPC_FLAGS);
878    else
879        npcflag = atoi(pnpcflag);
880
881    char* pdyflag = strtok(NULL, " ");
882
883    uint32  dyflag;
884    if(!pdyflag)
885        dyflag   = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
886    else
887        dyflag = atoi(pdyflag);
888
889    if(!sFactionTemplateStore.LookupEntry(factionid))
890    {
891        PSendSysMessage(LANG_WRONG_FACTION, factionid);
892        SetSentErrorMessage(true);
893        return false;
894    }
895
896    PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
897
898    //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
899    //FillSystemMessageData(&data, m_session, buf);
900
901    //chr->GetSession()->SendPacket(&data);
902
903    chr->setFaction(factionid);
904    chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
905    chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
906    chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
907
908    return true;
909}
910
911//Edit Player Spell
912bool ChatHandler::HandleModifySpellCommand(const char* args)
913{
914    if(!*args) return false;
915    char* pspellflatid = strtok((char*)args, " ");
916    if (!pspellflatid)
917        return false;
918
919    char* pop = strtok(NULL, " ");
920    if (!pop)
921        return false;
922
923    char* pval = strtok(NULL, " ");
924    if (!pval)
925        return false;
926
927    uint16 mark;
928
929    char* pmark = strtok(NULL, " ");
930
931    uint8 spellflatid = atoi(pspellflatid);
932    uint8 op   = atoi(pop);
933    uint16 val = atoi(pval);
934    if(!pmark)
935        mark = 65535;
936    else
937        mark = atoi(pmark);
938
939    Player *chr = getSelectedPlayer();
940    if (chr == NULL)
941    {
942        SendSysMessage(LANG_NO_CHAR_SELECTED);
943        SetSentErrorMessage(true);
944        return false;
945    }
946
947    PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
948    if(chr != m_session->GetPlayer())
949        ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, m_session->GetPlayer()->GetName(), spellflatid, val, mark);
950
951    WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
952    data << uint8(spellflatid);
953    data << uint8(op);
954    data << uint16(val);
955    data << uint16(mark);
956    chr->GetSession()->SendPacket(&data);
957
958    return true;
959}
960
961//Edit Player TP
962bool ChatHandler::HandleModifyTalentCommand (const char* args)
963{
964    if (!*args)
965        return false;
966
967    int tp = atoi((char*)args);
968    if (tp>0)
969    {
970        Player* player = getSelectedPlayer();
971        if(!player)
972        {
973            SendSysMessage(LANG_NO_CHAR_SELECTED);
974            SetSentErrorMessage(true);
975            return false;
976        }
977        player->SetFreeTalentPoints(tp);
978        return true;
979    }
980    return false;
981}
982
983//Enable On\OFF all taxi paths
984bool ChatHandler::HandleTaxiCheatCommand(const char* args)
985{
986    if (!*args)
987    {
988        SendSysMessage(LANG_USE_BOL);
989        SetSentErrorMessage(true);
990        return false;
991    }
992
993    std::string argstr = (char*)args;
994
995    Player *chr = getSelectedPlayer();
996    if (!chr)
997    {
998        chr=m_session->GetPlayer();
999    }
1000
1001    if (argstr == "on")
1002    {
1003        chr->SetTaxiCheater(true);
1004        PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
1005
1006        if(chr != m_session->GetPlayer())
1007            // to send localized data to target
1008            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_TAXIS_ADDED), m_session->GetPlayer()->GetName());
1009        return true;
1010    }
1011
1012    if (argstr == "off")
1013    {
1014        chr->SetTaxiCheater(false);
1015        PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
1016
1017        if(chr != m_session->GetPlayer())
1018            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_TAXIS_REMOVED), m_session->GetPlayer()->GetName());
1019
1020        return true;
1021    }
1022
1023    SendSysMessage(LANG_USE_BOL);
1024    SetSentErrorMessage(true);
1025    return false;
1026}
1027
1028//Edit Player Aspeed
1029bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1030{
1031    if (!*args)
1032        return false;
1033
1034    float ASpeed = (float)atof((char*)args);
1035
1036    if (ASpeed > 10 || ASpeed < 0.1)
1037    {
1038        SendSysMessage(LANG_BAD_VALUE);
1039        SetSentErrorMessage(true);
1040        return false;
1041    }
1042
1043    Player *chr = getSelectedPlayer();
1044    if (chr == NULL)
1045    {
1046        SendSysMessage(LANG_NO_CHAR_SELECTED);
1047        SetSentErrorMessage(true);
1048        return false;
1049    }
1050
1051    if(chr->isInFlight())
1052    {
1053        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1054        SetSentErrorMessage(true);
1055        return false;
1056    }
1057
1058    PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
1059
1060    if(chr != m_session->GetPlayer())
1061        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_ASPEED_CHANGED), m_session->GetPlayer()->GetName(), ASpeed);
1062
1063    chr->SetSpeed(MOVE_WALK,    ASpeed,true);
1064    chr->SetSpeed(MOVE_RUN,     ASpeed,true);
1065    chr->SetSpeed(MOVE_SWIM,    ASpeed,true);
1066    //chr->SetSpeed(MOVE_TURN,    ASpeed,true);
1067    chr->SetSpeed(MOVE_FLY,     ASpeed,true);
1068    return true;
1069}
1070
1071//Edit Player Speed
1072bool ChatHandler::HandleModifySpeedCommand(const char* args)
1073{
1074    if (!*args)
1075        return false;
1076
1077    float Speed = (float)atof((char*)args);
1078
1079    if (Speed > 10 || Speed < 0.1)
1080    {
1081        SendSysMessage(LANG_BAD_VALUE);
1082        SetSentErrorMessage(true);
1083        return false;
1084    }
1085
1086    Player *chr = getSelectedPlayer();
1087    if (chr == NULL)
1088    {
1089        SendSysMessage(LANG_NO_CHAR_SELECTED);
1090        SetSentErrorMessage(true);
1091        return false;
1092    }
1093
1094    if(chr->isInFlight())
1095    {
1096        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1097        SetSentErrorMessage(true);
1098        return false;
1099    }
1100
1101    PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
1102
1103    if(chr != m_session->GetPlayer())
1104        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_SPEED_CHANGED), m_session->GetPlayer()->GetName(), Speed);
1105
1106    chr->SetSpeed(MOVE_RUN,Speed,true);
1107
1108    return true;
1109}
1110
1111//Edit Player Swim Speed
1112bool ChatHandler::HandleModifySwimCommand(const char* args)
1113{
1114    if (!*args)
1115        return false;
1116
1117    float Swim = (float)atof((char*)args);
1118
1119    if (Swim > 10.0f || Swim < 0.01f)
1120    {
1121        SendSysMessage(LANG_BAD_VALUE);
1122        SetSentErrorMessage(true);
1123        return false;
1124    }
1125
1126    Player *chr = getSelectedPlayer();
1127    if (chr == NULL)
1128    {
1129        SendSysMessage(LANG_NO_CHAR_SELECTED);
1130        SetSentErrorMessage(true);
1131        return false;
1132    }
1133
1134    if(chr->isInFlight())
1135    {
1136        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1137        SetSentErrorMessage(true);
1138        return false;
1139    }
1140
1141    PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
1142
1143    if(chr != m_session->GetPlayer())
1144        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_SWIM_SPEED_CHANGED), m_session->GetPlayer()->GetName(), Swim);
1145
1146    chr->SetSpeed(MOVE_SWIM,Swim,true);
1147
1148    return true;
1149}
1150
1151//Edit Player Walk Speed
1152bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1153{
1154    if (!*args)
1155        return false;
1156
1157    float BSpeed = (float)atof((char*)args);
1158
1159    if (BSpeed > 10.0f || BSpeed < 0.1f)
1160    {
1161        SendSysMessage(LANG_BAD_VALUE);
1162        SetSentErrorMessage(true);
1163        return false;
1164    }
1165
1166    Player *chr = getSelectedPlayer();
1167    if (chr == NULL)
1168    {
1169        SendSysMessage(LANG_NO_CHAR_SELECTED);
1170        SetSentErrorMessage(true);
1171        return false;
1172    }
1173
1174    if(chr->isInFlight())
1175    {
1176        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1177        SetSentErrorMessage(true);
1178        return false;
1179    }
1180
1181    PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
1182
1183    if(chr != m_session->GetPlayer())
1184        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_BACK_SPEED_CHANGED), m_session->GetPlayer()->GetName(), BSpeed);
1185
1186    chr->SetSpeed(MOVE_WALKBACK,BSpeed,true);
1187
1188    return true;
1189}
1190
1191//Edit Player Fly
1192bool ChatHandler::HandleModifyFlyCommand(const char* args)
1193{
1194    if (!*args)
1195        return false;
1196
1197    float FSpeed = (float)atof((char*)args);
1198
1199    if (FSpeed > 10.0f || FSpeed < 0.1f)
1200    {
1201        SendSysMessage(LANG_BAD_VALUE);
1202        SetSentErrorMessage(true);
1203        return false;
1204    }
1205
1206    Player *chr = getSelectedPlayer();
1207    if (chr == NULL)
1208    {
1209        SendSysMessage(LANG_NO_CHAR_SELECTED);
1210        SetSentErrorMessage(true);
1211        return false;
1212    }
1213
1214    PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName());
1215
1216    if(chr != m_session->GetPlayer())
1217        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_FLY_SPEED_CHANGED), m_session->GetPlayer()->GetName(), FSpeed);
1218
1219    chr->SetSpeed(MOVE_FLY,FSpeed,true);
1220
1221    return true;
1222}
1223
1224//Edit Player Scale
1225bool ChatHandler::HandleModifyScaleCommand(const char* args)
1226{
1227    if (!*args)
1228        return false;
1229
1230    float Scale = (float)atof((char*)args);
1231    if (Scale > 3.0f || Scale <= 0.0f)
1232    {
1233        SendSysMessage(LANG_BAD_VALUE);
1234        SetSentErrorMessage(true);
1235        return false;
1236    }
1237
1238    Player *chr = getSelectedPlayer();
1239    if (chr == NULL)
1240    {
1241        SendSysMessage(LANG_NO_CHAR_SELECTED);
1242        SetSentErrorMessage(true);
1243        return false;
1244    }
1245
1246    PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
1247
1248    if(chr != m_session->GetPlayer())
1249        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_SIZE_CHANGED), m_session->GetPlayer()->GetName(), Scale);
1250
1251    chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1252
1253    return true;
1254}
1255
1256//Enable Player mount
1257bool ChatHandler::HandleModifyMountCommand(const char* args)
1258{
1259    if(!*args)
1260        return false;
1261
1262    uint16 mId = 1147;
1263    float speed = (float)15;
1264    uint32 num = 0;
1265
1266    num = atoi((char*)args);
1267    switch(num)
1268    {
1269        case 1:
1270            mId=14340;
1271            break;
1272        case 2:
1273            mId=4806;
1274            break;
1275        case 3:
1276            mId=6471;
1277            break;
1278        case 4:
1279            mId=12345;
1280            break;
1281        case 5:
1282            mId=6472;
1283            break;
1284        case 6:
1285            mId=6473;
1286            break;
1287        case 7:
1288            mId=10670;
1289            break;
1290        case 8:
1291            mId=10719;
1292            break;
1293        case 9:
1294            mId=10671;
1295            break;
1296        case 10:
1297            mId=10672;
1298            break;
1299        case 11:
1300            mId=10720;
1301            break;
1302        case 12:
1303            mId=14349;
1304            break;
1305        case 13:
1306            mId=11641;
1307            break;
1308        case 14:
1309            mId=12244;
1310            break;
1311        case 15:
1312            mId=12242;
1313            break;
1314        case 16:
1315            mId=14578;
1316            break;
1317        case 17:
1318            mId=14579;
1319            break;
1320        case 18:
1321            mId=14349;
1322            break;
1323        case 19:
1324            mId=12245;
1325            break;
1326        case 20:
1327            mId=14335;
1328            break;
1329        case 21:
1330            mId=207;
1331            break;
1332        case 22:
1333            mId=2328;
1334            break;
1335        case 23:
1336            mId=2327;
1337            break;
1338        case 24:
1339            mId=2326;
1340            break;
1341        case 25:
1342            mId=14573;
1343            break;
1344        case 26:
1345            mId=14574;
1346            break;
1347        case 27:
1348            mId=14575;
1349            break;
1350        case 28:
1351            mId=604;
1352            break;
1353        case 29:
1354            mId=1166;
1355            break;
1356        case 30:
1357            mId=2402;
1358            break;
1359        case 31:
1360            mId=2410;
1361            break;
1362        case 32:
1363            mId=2409;
1364            break;
1365        case 33:
1366            mId=2408;
1367            break;
1368        case 34:
1369            mId=2405;
1370            break;
1371        case 35:
1372            mId=14337;
1373            break;
1374        case 36:
1375            mId=6569;
1376            break;
1377        case 37:
1378            mId=10661;
1379            break;
1380        case 38:
1381            mId=10666;
1382            break;
1383        case 39:
1384            mId=9473;
1385            break;
1386        case 40:
1387            mId=9476;
1388            break;
1389        case 41:
1390            mId=9474;
1391            break;
1392        case 42:
1393            mId=14374;
1394            break;
1395        case 43:
1396            mId=14376;
1397            break;
1398        case 44:
1399            mId=14377;
1400            break;
1401        case 45:
1402            mId=2404;
1403            break;
1404        case 46:
1405            mId=2784;
1406            break;
1407        case 47:
1408            mId=2787;
1409            break;
1410        case 48:
1411            mId=2785;
1412            break;
1413        case 49:
1414            mId=2736;
1415            break;
1416        case 50:
1417            mId=2786;
1418            break;
1419        case 51:
1420            mId=14347;
1421            break;
1422        case 52:
1423            mId=14346;
1424            break;
1425        case 53:
1426            mId=14576;
1427            break;
1428        case 54:
1429            mId=9695;
1430            break;
1431        case 55:
1432            mId=9991;
1433            break;
1434        case 56:
1435            mId=6448;
1436            break;
1437        case 57:
1438            mId=6444;
1439            break;
1440        case 58:
1441            mId=6080;
1442            break;
1443        case 59:
1444            mId=6447;
1445            break;
1446        case 60:
1447            mId=4805;
1448            break;
1449        case 61:
1450            mId=9714;
1451            break;
1452        case 62:
1453            mId=6448;
1454            break;
1455        case 63:
1456            mId=6442;
1457            break;
1458        case 64:
1459            mId=14632;
1460            break;
1461        case 65:
1462            mId=14332;
1463            break;
1464        case 66:
1465            mId=14331;
1466            break;
1467        case 67:
1468            mId=8469;
1469            break;
1470        case 68:
1471            mId=2830;
1472            break;
1473        case 69:
1474            mId=2346;
1475            break;
1476        default:
1477            SendSysMessage(LANG_NO_MOUNT);
1478            SetSentErrorMessage(true);
1479            return false;
1480    }
1481
1482    Player *chr = getSelectedPlayer();
1483    if (chr == NULL)
1484    {
1485        SendSysMessage(LANG_NO_CHAR_SELECTED);
1486        SetSentErrorMessage(true);
1487        return false;
1488    }
1489
1490    PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1491
1492    if(chr != m_session->GetPlayer())
1493        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_MOUNT_GIVED), m_session->GetPlayer()->GetName());
1494
1495    chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1496    chr->Mount(mId);
1497
1498    WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1499    data.append(chr->GetPackGUID());
1500    data << (uint32)0;
1501    data << (uint8)0;                                       //new 2.1.0
1502    data << float(speed);
1503    chr->SendMessageToSet( &data, true );
1504
1505    data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1506    data.append(chr->GetPackGUID());
1507    data << (uint32)0;
1508    data << float(speed);
1509    chr->SendMessageToSet( &data, true );
1510
1511    return true;
1512}
1513
1514//Edit Player money
1515bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1516{
1517    if (!*args)
1518        return false;
1519
1520    Player *chr = getSelectedPlayer();
1521    if (chr == NULL)
1522    {
1523        SendSysMessage(LANG_NO_CHAR_SELECTED);
1524        SetSentErrorMessage(true);
1525        return false;
1526    }
1527
1528    int32 addmoney = atoi((char*)args);
1529
1530    uint32 moneyuser = chr->GetMoney();
1531
1532    if(addmoney < 0)
1533    {
1534        int32 newmoney = moneyuser + addmoney;
1535
1536        sLog.outDetail(GetMangosString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1537        if(newmoney <= 0 )
1538        {
1539            PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1540
1541            if(chr != m_session->GetPlayer())
1542                ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_ALL_MONEY_GONE), m_session->GetPlayer()->GetName());
1543
1544            chr->SetMoney(0);
1545        }
1546        else
1547        {
1548            PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1549            if(chr != m_session->GetPlayer())
1550                ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_MONEY_TAKEN), m_session->GetPlayer()->GetName(), abs(addmoney));
1551            chr->SetMoney( newmoney );
1552        }
1553    }
1554    else
1555    {
1556        PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1557        if(chr != m_session->GetPlayer())
1558            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetMangosString(LANG_YOURS_MONEY_GIVEN), m_session->GetPlayer()->GetName(), addmoney);
1559        chr->ModifyMoney( addmoney );
1560    }
1561
1562    sLog.outDetail(GetMangosString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1563
1564    return true;
1565}
1566
1567//Edit Player field
1568bool ChatHandler::HandleModifyBitCommand(const char* args)
1569{
1570    if( !*args )
1571        return false;
1572
1573    Player *chr = getSelectedPlayer();
1574    if (chr == NULL)
1575    {
1576        SendSysMessage(LANG_NO_CHAR_SELECTED);
1577        SetSentErrorMessage(true);
1578        return false;
1579    }
1580
1581    char* pField = strtok((char*)args, " ");
1582    if (!pField)
1583        return false;
1584
1585    char* pBit = strtok(NULL, " ");
1586    if (!pBit)
1587        return false;
1588
1589    uint16 field = atoi(pField);
1590    uint32 bit   = atoi(pBit);
1591
1592    if (field < 1 || field >= PLAYER_END)
1593    {
1594        SendSysMessage(LANG_BAD_VALUE);
1595        SetSentErrorMessage(true);
1596        return false;
1597    }
1598
1599    if (bit < 1 || bit > 32)
1600    {
1601        SendSysMessage(LANG_BAD_VALUE);
1602        SetSentErrorMessage(true);
1603        return false;
1604    }
1605
1606    if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1607    {
1608        chr->RemoveFlag( field, (1<<(bit-1)) );
1609        PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1610    }
1611    else
1612    {
1613        chr->SetFlag( field, (1<<(bit-1)) );
1614        PSendSysMessage(LANG_SET_BIT, bit, field);
1615    }
1616
1617    return true;
1618}
1619
1620bool ChatHandler::HandleModifyHonorCommand (const char* args)
1621{
1622    if (!*args)
1623        return false;
1624
1625    Player *target = getSelectedPlayer();
1626    if(!target)
1627    {
1628        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1629        SetSentErrorMessage(true);
1630        return false;
1631    }
1632
1633    int32 amount = (uint32)atoi(args);
1634
1635    target->ModifyHonorPoints(amount);
1636
1637    PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, target->GetName(), target->GetHonorPoints());
1638
1639    return true;
1640}
1641
1642bool ChatHandler::HandleTeleCommand(const char * args)
1643{
1644    if(!*args)
1645        return false;
1646
1647    Player* _player = m_session->GetPlayer();
1648
1649    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1650    GameTele const* tele = extractGameTeleFromLink((char*)args);
1651    if (!tele)
1652    {
1653        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1654        SetSentErrorMessage(true);
1655        return false;
1656    }
1657
1658    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
1659    if(!me || me->IsBattleGroundOrArena())
1660    {
1661        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
1662        SetSentErrorMessage(true);
1663        return false;
1664    }
1665
1666    // stop flight if need
1667    if(_player->isInFlight())
1668    {
1669        _player->GetMotionMaster()->MovementExpired();
1670        _player->m_taxi.ClearTaxiDestinations();
1671    }
1672    // save only in non-flight case
1673    else
1674        _player->SaveRecallPosition();
1675
1676    _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1677    return true;
1678}
1679
1680bool ChatHandler::HandleLookupAreaCommand(const char* args)
1681{
1682    if(!*args)
1683        return false;
1684
1685    std::string namepart = args;
1686    std::wstring wnamepart;
1687
1688    if(!Utf8toWStr(namepart,wnamepart))
1689        return false;
1690
1691    uint32 counter = 0;                                     // Counter for figure out that we found smth.
1692
1693    // converting string that we try to find to lower case
1694    wstrToLower( wnamepart );
1695
1696    // Search in AreaTable.dbc
1697    for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows(); ++areaflag)
1698    {
1699        AreaTableEntry const *areaEntry = sAreaStore.LookupEntry(areaflag);
1700        if(areaEntry)
1701        {
1702            int loc = m_session->GetSessionDbcLocale();
1703            std::string name = areaEntry->area_name[loc];
1704            if(name.empty())
1705                continue;
1706
1707            if(!Utf8FitTo(name, wnamepart))
1708            {
1709                loc = 0;
1710                for(; loc < MAX_LOCALE; ++loc)
1711                {
1712                    if(loc==m_session->GetSessionDbcLocale())
1713                        continue;
1714
1715                    name = areaEntry->area_name[loc];
1716                    if(name.empty())
1717                        continue;
1718
1719                    if (Utf8FitTo(name, wnamepart))
1720                        break;
1721                }
1722            }
1723
1724            if(loc < MAX_LOCALE)
1725            {
1726                // send area in "id - [name]" format
1727                std::ostringstream ss;
1728                ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1729
1730                SendSysMessage(ss.str().c_str());
1731
1732                ++counter;
1733            }
1734        }
1735    }
1736    if (counter == 0)                                       // if counter == 0 then we found nth
1737        SendSysMessage(LANG_COMMAND_NOAREAFOUND);
1738    return true;
1739}
1740
1741//Find tele in game_tele order by name
1742bool ChatHandler::HandleLookupTeleCommand(const char * args)
1743{
1744    if(!*args)
1745    {
1746        SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1747        SetSentErrorMessage(true);
1748        return false;
1749    }
1750    char const* str = strtok((char*)args, " ");
1751    if(!str)
1752        return false;
1753
1754    std::string namepart = str;
1755    std::wstring wnamepart;
1756
1757    if(!Utf8toWStr(namepart,wnamepart))
1758        return false;
1759
1760    // converting string that we try to find to lower case
1761    wstrToLower( wnamepart );
1762
1763    GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1764
1765    std::ostringstream reply;
1766    for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1767    {
1768        GameTele const* tele = &itr->second;
1769
1770        if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1771            continue;
1772
1773        reply << "  |cffffffff|Htele:";
1774        reply << itr->first;
1775        reply << "|h[";
1776        reply << tele->name;
1777        reply << "]|h|r\n";
1778    }
1779
1780    if(reply.str().empty())
1781        SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1782    else
1783        PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1784
1785    return true;
1786}
1787
1788//Enable\Dissable accept whispers (for GM)
1789bool ChatHandler::HandleWhispersCommand(const char* args)
1790{
1791    if(!*args)
1792    {
1793        PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ?  GetMangosString(LANG_ON) : GetMangosString(LANG_OFF));
1794        return true;
1795    }
1796
1797    std::string argstr = (char*)args;
1798    // whisper on
1799    if (argstr == "on")
1800    {
1801        m_session->GetPlayer()->SetAcceptWhispers(true);
1802        SendSysMessage(LANG_COMMAND_WHISPERON);
1803        return true;
1804    }
1805
1806    // whisper off
1807    if (argstr == "off")
1808    {
1809        m_session->GetPlayer()->SetAcceptWhispers(false);
1810        SendSysMessage(LANG_COMMAND_WHISPEROFF);
1811        return true;
1812    }
1813
1814    SendSysMessage(LANG_USE_BOL);
1815    SetSentErrorMessage(true);
1816    return false;
1817}
1818
1819//Play sound
1820bool ChatHandler::HandlePlaySoundCommand(const char* args)
1821{
1822    // USAGE: .debug playsound #soundid
1823    // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1824    // this file have about 5000 sounds.
1825    // In this realization only caller can hear this sound.
1826    if( *args )
1827    {
1828        uint32 dwSoundId = atoi((char*)args);
1829
1830        if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1831        {
1832            PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1833            SetSentErrorMessage(true);
1834            return false;
1835        }
1836
1837        WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1838        data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1839        m_session->SendPacket(&data);
1840
1841        PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1842        return true;
1843    }
1844
1845    return false;
1846}
1847
1848//Save all players in the world
1849bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1850{
1851    ObjectAccessor::Instance().SaveAllPlayers();
1852    SendSysMessage(LANG_PLAYERS_SAVED);
1853    return true;
1854}
1855
1856//Send mail by command
1857bool ChatHandler::HandleSendMailCommand(const char* args)
1858{
1859    if(!*args)
1860        return false;
1861
1862    // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
1863
1864    char* pName = strtok((char*)args, " ");
1865    if(!pName)
1866        return false;
1867
1868    char* tail1 = strtok(NULL, "");
1869    if(!tail1)
1870        return false;
1871
1872    char* msgSubject;
1873    if(*tail1=='"')
1874        msgSubject = strtok(tail1+1, "\"");
1875    else
1876    {
1877        char* space = strtok(tail1, "\"");
1878        if(!space)
1879            return false;
1880        msgSubject = strtok(NULL, "\"");
1881    }
1882
1883    if (!msgSubject)
1884        return false;
1885
1886    char* tail2 = strtok(NULL, "");
1887    if(!tail2)
1888        return false;
1889
1890    char* msgText;
1891    if(*tail2=='"')
1892        msgText = strtok(tail2+1, "\"");
1893    else
1894    {
1895        char* space = strtok(tail2, "\"");
1896        if(!space)
1897            return false;
1898        msgText = strtok(NULL, "\"");
1899    }
1900
1901    if (!msgText)
1902        return false;
1903
1904    // pName, msgSubject, msgText isn't NUL after prev. check
1905    std::string name    = pName;
1906    std::string subject = msgSubject;
1907    std::string text    = msgText;
1908
1909    // extract items
1910    typedef std::pair<uint32,uint32> ItemPair;
1911    typedef std::list< ItemPair > ItemPairs;
1912    ItemPairs items;
1913
1914    // get all tail string
1915    char* tail = strtok(NULL, "");
1916
1917    // get from tail next item str
1918    while(char* itemStr = strtok(tail, " "))
1919    {
1920        // and get new tail
1921        tail = strtok(NULL, "");
1922
1923        // parse item str
1924        char* itemIdStr = strtok(itemStr, ":");
1925        char* itemCountStr = strtok(NULL, " ");
1926       
1927        uint32 item_id = atoi(itemIdStr);
1928        if(!item_id)
1929            return false;
1930
1931        ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
1932        if(!item_proto)
1933        {
1934            PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
1935            SetSentErrorMessage(true);
1936            return false;
1937        }
1938
1939        uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
1940        if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
1941        {
1942            PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
1943            SetSentErrorMessage(true);
1944            return false;
1945        }
1946
1947        while(item_count > item_proto->Stackable)
1948        {
1949            items.push_back(ItemPair(item_id,item_proto->Stackable));
1950            item_count -= item_proto->Stackable;
1951        }
1952
1953        items.push_back(ItemPair(item_id,item_count));
1954
1955        if(items.size() > MAX_MAIL_ITEMS)
1956        {
1957            PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
1958            SetSentErrorMessage(true);
1959            return false;
1960        }
1961    }
1962
1963    if(!normalizePlayerName(name))
1964    {
1965        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1966        SetSentErrorMessage(true);
1967        return false;
1968    }
1969
1970    uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
1971    if(!receiver_guid)
1972    {
1973        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1974        SetSentErrorMessage(true);
1975        return false;
1976    }
1977
1978    uint32 mailId = objmgr.GenerateMailID();
1979    uint32 sender_guidlo = m_session->GetPlayer()->GetGUIDLow();
1980    uint32 messagetype = MAIL_NORMAL;
1981    uint32 stationery = MAIL_STATIONERY_GM;
1982    uint32 itemTextId = 0;
1983    if (!text.empty())
1984    {
1985        itemTextId = objmgr.CreateItemText( text );
1986    }
1987
1988    Player *receiver = objmgr.GetPlayer(receiver_guid);
1989
1990    // fill mail
1991    MailItemsInfo mi;                                       // item list preparing
1992
1993    for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
1994    {
1995        if(Item* item = Item::CreateItem(itr->first,itr->second,m_session->GetPlayer()))
1996        {
1997            item->SaveToDB();                               // save for prevent lost at next mail load, if send fail then item will deleted
1998            mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
1999        }
2000    }
2001
2002    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
2003
2004    PSendSysMessage(LANG_MAIL_SENT, name.c_str());
2005    return true;
2006}
2007
2008// teleport player to given game_tele.entry
2009bool ChatHandler::HandleNameTeleCommand(const char * args)
2010{
2011    if(!*args)
2012        return false;
2013
2014    char* pName = strtok((char*)args, " ");
2015
2016    if(!pName)
2017        return false;
2018
2019    std::string name = pName;
2020
2021    if(!normalizePlayerName(name))
2022    {
2023        SendSysMessage(LANG_PLAYER_NOT_FOUND);
2024        SetSentErrorMessage(true);
2025        return false;
2026    }
2027
2028    char* tail = strtok(NULL, "");
2029    if(!tail)
2030        return false;
2031
2032    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2033    GameTele const* tele = extractGameTeleFromLink(tail);
2034    if(!tele)
2035    {
2036        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2037        SetSentErrorMessage(true);
2038        return false;
2039    }
2040
2041    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
2042    if(!me || me->IsBattleGroundOrArena())
2043    {
2044        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
2045        SetSentErrorMessage(true);
2046        return false;
2047    }
2048
2049    Player *chr = objmgr.GetPlayer(name.c_str());
2050    if (chr)
2051    {
2052
2053        if(chr->IsBeingTeleported()==true)
2054        {
2055            PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
2056            SetSentErrorMessage(true);
2057            return false;
2058        }
2059
2060        PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", tele->name.c_str());
2061
2062        if (m_session->GetPlayer()->IsVisibleGloballyFor(chr))
2063            ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, m_session->GetPlayer()->GetName());
2064
2065        // stop flight if need
2066        if(chr->isInFlight())
2067        {
2068            chr->GetMotionMaster()->MovementExpired();
2069            chr->m_taxi.ClearTaxiDestinations();
2070        }
2071        // save only in non-flight case
2072        else
2073            chr->SaveRecallPosition();
2074
2075        chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2076    }
2077    else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
2078    {
2079        PSendSysMessage(LANG_TELEPORTING_TO, name.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str());
2080        Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y),guid);
2081    }
2082    else
2083        PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2084
2085    return true;
2086}
2087
2088//Teleport group to given game_tele.entry
2089bool ChatHandler::HandleGroupTeleCommand(const char * args)
2090{
2091    if(!*args)
2092        return false;
2093
2094    Player *player = getSelectedPlayer();
2095    if (!player)
2096    {
2097        SendSysMessage(LANG_NO_CHAR_SELECTED);
2098        SetSentErrorMessage(true);
2099        return false;
2100    }
2101
2102    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2103    GameTele const* tele = extractGameTeleFromLink((char*)args);
2104    if(!tele)
2105    {
2106        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2107        SetSentErrorMessage(true);
2108        return false;
2109    }
2110
2111    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
2112    if(!me || me->IsBattleGroundOrArena())
2113    {
2114        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
2115        SetSentErrorMessage(true);
2116        return false;
2117    }
2118    Group *grp = player->GetGroup();
2119    if(!grp)
2120    {
2121        PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2122        SetSentErrorMessage(true);
2123        return false;
2124    }
2125
2126    for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2127    {
2128        Player *pl = itr->getSource();
2129
2130        if(!pl || !pl->GetSession() )
2131            continue;
2132
2133        if(pl->IsBeingTeleported())
2134        {
2135            PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2136            continue;
2137        }
2138
2139        PSendSysMessage(LANG_TELEPORTING_TO, pl->GetName(),"", tele->name.c_str());
2140
2141        if (m_session->GetPlayer() != pl && m_session->GetPlayer()->IsVisibleGloballyFor(pl))
2142            ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, m_session->GetPlayer()->GetName());
2143
2144        // stop flight if need
2145        if(pl->isInFlight())
2146        {
2147            pl->GetMotionMaster()->MovementExpired();
2148            pl->m_taxi.ClearTaxiDestinations();
2149        }
2150        // save only in non-flight case
2151        else
2152            pl->SaveRecallPosition();
2153
2154        pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2155    }
2156
2157    return true;
2158}
2159
2160//Summon group of player
2161bool ChatHandler::HandleGroupgoCommand(const char* args)
2162{
2163    if(!*args)
2164        return false;
2165
2166    std::string name = args;
2167
2168    if(!normalizePlayerName(name))
2169    {
2170        SendSysMessage(LANG_PLAYER_NOT_FOUND);
2171        SetSentErrorMessage(true);
2172        return false;
2173    }
2174
2175    Player *player = objmgr.GetPlayer(name.c_str());
2176    if (!player)
2177    {
2178        PSendSysMessage(LANG_NO_PLAYER, args);
2179        SetSentErrorMessage(true);
2180        return false;
2181    }
2182
2183    Group *grp = player->GetGroup();
2184
2185    if(!grp)
2186    {
2187        PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2188        SetSentErrorMessage(true);
2189        return false;
2190    }
2191
2192    Map* gmMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
2193    bool to_instance =  gmMap->Instanceable();
2194
2195    // we are in instance, and can summon only player in our group with us as lead
2196    if ( to_instance && (
2197        !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2198        (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2199        // the last check is a bit excessive, but let it be, just in case
2200    {
2201        SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2202        SetSentErrorMessage(true);
2203        return false;
2204    }
2205
2206    for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2207    {
2208        Player *pl = itr->getSource();
2209
2210        if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2211            continue;
2212
2213        if(pl->IsBeingTeleported()==true)
2214        {
2215            PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2216            SetSentErrorMessage(true);
2217            return false;
2218        }
2219
2220        if (to_instance)
2221        {
2222            Map* plMap = MapManager::Instance().GetMap(pl->GetMapId(),pl);
2223
2224            if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2225            {
2226                // cannot summon from instance to instance
2227                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,pl->GetName());
2228                SetSentErrorMessage(true);
2229                return false;
2230            }
2231        }
2232
2233        PSendSysMessage(LANG_SUMMONING, pl->GetName(),"");
2234
2235        if (m_session->GetPlayer()->IsVisibleGloballyFor(pl))
2236            ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
2237
2238        // stop flight if need
2239        if(pl->isInFlight())
2240        {
2241            pl->GetMotionMaster()->MovementExpired();
2242            pl->m_taxi.ClearTaxiDestinations();
2243        }
2244        // save only in non-flight case
2245        else
2246            pl->SaveRecallPosition();
2247
2248        // before GM
2249        float x,y,z;
2250        m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2251        pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2252    }
2253
2254    return true;
2255}
2256
2257//teleport at coordinates
2258bool ChatHandler::HandleGoXYCommand(const char* args)
2259{
2260    if(!*args)
2261        return false;
2262
2263    Player* _player = m_session->GetPlayer();
2264
2265    char* px = strtok((char*)args, " ");
2266    char* py = strtok(NULL, " ");
2267    char* pmapid = strtok(NULL, " ");
2268
2269    if (!px || !py)
2270        return false;
2271
2272    float x = (float)atof(px);
2273    float y = (float)atof(py);
2274    uint32 mapid;
2275    if (pmapid)
2276        mapid = (uint32)atoi(pmapid);
2277    else mapid = _player->GetMapId();
2278
2279    if(!MapManager::IsValidMapCoord(mapid,x,y))
2280    {
2281        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2282        SetSentErrorMessage(true);
2283        return false;
2284    }
2285
2286    // stop flight if need
2287    if(_player->isInFlight())
2288    {
2289        _player->GetMotionMaster()->MovementExpired();
2290        _player->m_taxi.ClearTaxiDestinations();
2291    }
2292    // save only in non-flight case
2293    else
2294        _player->SaveRecallPosition();
2295
2296    Map const *map = MapManager::Instance().GetBaseMap(mapid);
2297    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2298
2299    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2300
2301    return true;
2302}
2303
2304//teleport at coordinates, including Z
2305bool ChatHandler::HandleGoXYZCommand(const char* args)
2306{
2307    if(!*args)
2308        return false;
2309
2310    Player* _player = m_session->GetPlayer();
2311
2312    char* px = strtok((char*)args, " ");
2313    char* py = strtok(NULL, " ");
2314    char* pz = strtok(NULL, " ");
2315    char* pmapid = strtok(NULL, " ");
2316
2317    if (!px || !py || !pz)
2318        return false;
2319
2320    float x = (float)atof(px);
2321    float y = (float)atof(py);
2322    float z = (float)atof(pz);
2323    uint32 mapid;
2324    if (pmapid)
2325        mapid = (uint32)atoi(pmapid);
2326    else
2327        mapid = _player->GetMapId();
2328
2329    if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2330    {
2331        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2332        SetSentErrorMessage(true);
2333        return false;
2334    }
2335
2336    // stop flight if need
2337    if(_player->isInFlight())
2338    {
2339        _player->GetMotionMaster()->MovementExpired();
2340        _player->m_taxi.ClearTaxiDestinations();
2341    }
2342    // save only in non-flight case
2343    else
2344        _player->SaveRecallPosition();
2345
2346    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2347
2348    return true;
2349}
2350
2351//teleport at coordinates
2352bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2353{
2354    if(!*args)
2355        return false;
2356
2357    Player* _player = m_session->GetPlayer();
2358
2359    char* px = strtok((char*)args, " ");
2360    char* py = strtok(NULL, " ");
2361    char* tail = strtok(NULL,"");
2362
2363    char* cAreaId = extractKeyFromLink(tail,"Harea");       // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2364
2365    if (!px || !py)
2366        return false;
2367
2368    float x = (float)atof(px);
2369    float y = (float)atof(py);
2370    uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2371
2372    AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2373
2374    if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2375    {
2376        PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2377        SetSentErrorMessage(true);
2378        return false;
2379    }
2380
2381    // update to parent zone if exist (client map show only zones without parents)
2382    AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2383
2384    Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2385
2386    if(map->Instanceable())
2387    {
2388        PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2389        SetSentErrorMessage(true);
2390        return false;
2391    }
2392
2393    Zone2MapCoordinates(x,y,zoneEntry->ID);
2394
2395    if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2396    {
2397        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2398        SetSentErrorMessage(true);
2399        return false;
2400    }
2401
2402    // stop flight if need
2403    if(_player->isInFlight())
2404    {
2405        _player->GetMotionMaster()->MovementExpired();
2406        _player->m_taxi.ClearTaxiDestinations();
2407    }
2408    // save only in non-flight case
2409    else
2410        _player->SaveRecallPosition();
2411
2412    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2413    _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2414
2415    return true;
2416}
2417
2418//teleport to grid
2419bool ChatHandler::HandleGoGridCommand(const char* args)
2420{
2421    if(!*args)    return false;
2422    Player* _player = m_session->GetPlayer();
2423
2424    char* px = strtok((char*)args, " ");
2425    char* py = strtok(NULL, " ");
2426    char* pmapid = strtok(NULL, " ");
2427
2428    if (!px || !py)
2429        return false;
2430
2431    float grid_x = (float)atof(px);
2432    float grid_y = (float)atof(py);
2433    uint32 mapid;
2434    if (pmapid)
2435        mapid = (uint32)atoi(pmapid);
2436    else mapid = _player->GetMapId();
2437
2438    // center of grid
2439    float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2440    float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2441
2442    if(!MapManager::IsValidMapCoord(mapid,x,y))
2443    {
2444        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2445        SetSentErrorMessage(true);
2446        return false;
2447    }
2448
2449    // stop flight if need
2450    if(_player->isInFlight())
2451    {
2452        _player->GetMotionMaster()->MovementExpired();
2453        _player->m_taxi.ClearTaxiDestinations();
2454    }
2455    // save only in non-flight case
2456    else
2457        _player->SaveRecallPosition();
2458
2459    Map const *map = MapManager::Instance().GetBaseMap(mapid);
2460    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2461    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2462
2463    return true;
2464}
2465
2466bool ChatHandler::HandleDrunkCommand(const char* args)
2467{
2468    if(!*args)    return false;
2469
2470    uint32 drunklevel = (uint32)atoi(args);
2471    if(drunklevel > 100)
2472        drunklevel = 100;
2473
2474    uint16 drunkMod = drunklevel * 0xFFFF / 100;
2475
2476    m_session->GetPlayer()->SetDrunkValue(drunkMod);
2477
2478    return true;
2479}
Note: See TracBrowser for help on using the browser.