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

Revision 6, 62.1 kB (checked in by yumileroy, 17 years ago)

[svn] * Added ACE for Linux and Windows (Thanks Derex for Linux part and partial Windows part)
* Updated to 6721 and 676
* Fixed TrinityScript? logo
* Version updated to 0.2.6721.676

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