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

Revision 9, 63.7 kB (checked in by yumileroy, 17 years ago)

[svn] -enabled instantiated battlegrounds
-enabled arena matches
-rewritten battleground queuing to support joining as group
-removed queue announcements

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