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

Revision 177, 64.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Avoid access to bag item prototype for getting bag size, use related item
update field instead as more fast source. source mangos.
* Further reduce of DB access in guild handlers.
* Multi-locale DBC extracting - source Foks

*** Devs not responsible if all your player items drop to the ground and get eaten by ants or rabbits.. or some kind of wierd ant-rabbits..

Original author: KingPin?
Date: 2008-11-06 08:20:26-06:00

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