[2390] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Level1.cpp
blob23274752fba08ddd662fa5ae4d71a4188ec8eb39
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 "RedZoneDistrict.h"
34 bool ChatHandler::HandleAnnounceCommand(const char* args)
36 WorldPacket data;
38 if(!*args)
39 return false;
41 char pAnnounce[256];
43 sprintf((char*)pAnnounce, LANG_BROADCAST, args);
44 sWorld.SendWorldText(pAnnounce);
46 return true;
49 bool ChatHandler::HandleGMOnCommand(const char* args)
51 m_session->GetPlayer()->SetGameMaster(true);
52 m_session->GetPlayer()->CombatStop();
54 return true;
57 bool ChatHandler::HandleGMOffCommand(const char* args)
59 m_session->GetPlayer()->SetGameMaster(false);
61 return true;
64 bool ChatHandler::HandleGPSCommand(const char* args)
66 Object *obj = getSelectedUnit();
68 if(!obj)
70 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
71 return true;
74 CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
75 Cell cell = RedZone::GetZone(cell_val);
77 PSendSysMultilineMessage(LANG_MAP_POSITION,
78 obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
79 obj->GetOrientation(),cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
81 sLog.outDebug("Player %s GPS call unit " I64FMT " " LANG_MAP_POSITION, m_session->GetPlayer()->GetName(), obj->GetGUID(),
82 obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
83 obj->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
85 return true;
88 bool ChatHandler::HandleNamegoCommand(const char* args)
90 WorldPacket data;
92 if(!*args)
93 return false;
95 Player *chr = objmgr.GetPlayer(args);
96 if (chr)
99 if(chr->IsBeingTeleported()==true)
101 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
102 return true;
104 PSendSysMessage(LANG_SUMMONING, chr->GetName());
106 char buf0[256];
107 snprintf((char*)buf0,256,LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
108 FillSystemMessageData(&data, m_session, buf0);
109 chr->GetSession()->SendPacket( &data );
111 chr->TeleportTo(m_session->GetPlayer()->GetMapId(),
112 m_session->GetPlayer()->GetPositionX(),
113 m_session->GetPlayer()->GetPositionY(),
114 m_session->GetPlayer()->GetPositionZ()
115 ,0.0f);
117 else
118 PSendSysMessage(LANG_NO_PLAYER, args);
120 return true;
123 bool ChatHandler::HandleGonameCommand(const char* args)
125 WorldPacket data;
127 if(!*args)
128 return false;
130 Player *chr = objmgr.GetPlayer(args);
131 if (chr)
133 if(chr->IsBeingTeleported()==true)
135 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
136 return true;
139 PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
141 char buf0[256];
142 sprintf((char*)buf0,LANG_APPEARING_TO, m_session->GetPlayer()->GetName());
143 FillSystemMessageData(&data, m_session, buf0);
145 chr->GetSession()->SendPacket(&data);
147 m_session->GetPlayer()->TeleportTo(chr->GetMapId(), chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(),0.0f);
149 else
150 PSendSysMessage(LANG_NO_PLAYER, args);
152 return true;
155 bool ChatHandler::HandleRecallCommand(const char* args)
157 if(!*args)
158 return false;
160 if (strncmp((char*)args,"sunr",5)==0)
161 m_session->GetPlayer()->TeleportTo(1, -180.949f, -296.467f, 11.5384f,0.0f);
162 else if (strncmp((char*)args,"thun",5)==0)
163 m_session->GetPlayer()->TeleportTo(1, -1196.22f, 29.0941f, 176.949f,0.0f);
164 else if (strncmp((char*)args,"cross",6)==0)
165 m_session->GetPlayer()->TeleportTo(1, -443.128f, -2598.87f, 96.2114f,0.0f);
166 else if (strncmp((char*)args,"ogri",5)==0)
167 m_session->GetPlayer()->TeleportTo(1, 1676.21f, -4315.29f, 61.5293f,0.0f);
168 else if (strncmp((char*)args,"neth",5)==0)
169 m_session->GetPlayer()->TeleportTo(0, -10996.9f, -3427.67f, 61.996f,0.0f);
170 else if (strncmp((char*)args,"thel",5)==0)
171 m_session->GetPlayer()->TeleportTo(0, -5395.57f, -3015.79f, 327.58f,0.0f);
172 else if (strncmp((char*)args,"storm",6)==0)
173 m_session->GetPlayer()->TeleportTo(0, -8913.23f, 554.633f, 93.7944f,0.0f);
174 else if (strncmp((char*)args,"iron",5)==0)
175 m_session->GetPlayer()->TeleportTo(0, -4981.25f, -881.542f, 501.66f,0.0f);
176 else if (strncmp((char*)args,"under",6)==0)
177 m_session->GetPlayer()->TeleportTo(0, 1586.48f, 239.562f, -52.149f,0.0f);
178 else if (strncmp((char*)args,"darr",5)==0)
179 m_session->GetPlayer()->TeleportTo(1, 10037.6f, 2496.8f, 1318.4f,0.0f);
180 else if (strncmp((char*)args,"gm",5)==0)
181 m_session->GetPlayer()->TeleportTo(1, 16202.5, 16205, 1,1.15);
182 else
183 return false;
185 return true;
188 bool ChatHandler::HandleModifyHPCommand(const char* args)
190 WorldPacket data;
192 // char* pHp = strtok((char*)args, " ");
193 // if (!pHp)
194 // return false;
196 // char* pHpMax = strtok(NULL, " ");
197 // if (!pHpMax)
198 // return false;
200 // int32 hpm = atoi(pHpMax);
201 // int32 hp = atoi(pHp);
203 int32 hp = atoi((char*)args);
204 int32 hpm = atoi((char*)args);
206 if (hp <= 0 || hpm <= 0 || hpm < hp)
208 SendSysMessage(LANG_BAD_VALUE);
209 return true;
212 Player *chr = getSelectedPlayer();
213 if (chr == NULL)
215 SendSysMessage(LANG_NO_CHAR_SELECTED);
216 return true;
219 PSendSysMessage(LANG_YOU_CHANGE_HP, hp, hpm, chr->GetName());
221 char buf[256];
222 sprintf((char*)buf,LANG_YOURS_HP_CHANGED, m_session->GetPlayer()->GetName(), hp, hpm);
223 FillSystemMessageData(&data, m_session, buf);
225 chr->GetSession()->SendPacket(&data);
227 chr->SetMaxHealth( hpm );
228 chr->SetHealth( hp );
230 return true;
233 bool ChatHandler::HandleModifyManaCommand(const char* args)
235 WorldPacket data;
237 // char* pmana = strtok((char*)args, " ");
238 // if (!pmana)
239 // return false;
241 // char* pmanaMax = strtok(NULL, " ");
242 // if (!pmanaMax)
243 // return false;
245 // int32 manam = atoi(pmanaMax);
246 // int32 mana = atoi(pmana);
247 int32 mana = atoi((char*)args);
248 int32 manam = atoi((char*)args);
250 if (mana <= 0 || manam <= 0 || manam < mana)
252 SendSysMessage(LANG_BAD_VALUE);
253 return true;
256 Player *chr = getSelectedPlayer();
257 if (chr == NULL)
259 SendSysMessage(LANG_NO_CHAR_SELECTED);
260 return true;
263 PSendSysMessage(LANG_YOU_CHANGE_MANA, mana, manam, chr->GetName());
265 char buf[256];
266 sprintf((char*)buf,LANG_YOURS_MANA_CHANGED, m_session->GetPlayer()->GetName(), mana, manam);
267 FillSystemMessageData(&data, m_session, buf);
269 chr->GetSession()->SendPacket(&data);
271 chr->SetMaxPower(POWER_MANA,manam );
272 chr->SetPower(POWER_MANA, mana );
274 return true;
277 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
279 WorldPacket data;
281 // char* pmana = strtok((char*)args, " ");
282 // if (!pmana)
283 // return false;
285 // char* pmanaMax = strtok(NULL, " ");
286 // if (!pmanaMax)
287 // return false;
289 // int32 manam = atoi(pmanaMax);
290 // int32 mana = atoi(pmana);
291 int32 mana = atoi((char*)args)*10;
292 int32 manam = atoi((char*)args)*10;
294 if (mana <= 0 || manam <= 0 || manam < mana)
296 SendSysMessage(LANG_BAD_VALUE);
297 return true;
300 Player *chr = getSelectedPlayer();
301 if (chr == NULL)
303 PSendSysMessage(LANG_NO_CHAR_SELECTED);
304 return true;
307 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, mana/10, manam/10, chr->GetName());
309 char buf[256];
310 sprintf((char*)buf,LANG_YOURS_ENERGY_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
311 FillSystemMessageData(&data, m_session, buf);
313 chr->GetSession()->SendPacket(&data);
315 chr->SetMaxPower(POWER_ENERGY,manam );
316 chr->SetPower(POWER_ENERGY, mana );
318 sLog.outDetail(LANG_CURRENT_ENERGY,chr->GetMaxPower(POWER_ENERGY));
320 return true;
323 bool ChatHandler::HandleModifyRageCommand(const char* args)
325 WorldPacket data;
327 // char* pmana = strtok((char*)args, " ");
328 // if (!pmana)
329 // return false;
331 // char* pmanaMax = strtok(NULL, " ");
332 // if (!pmanaMax)
333 // return false;
335 // int32 manam = atoi(pmanaMax);
336 // int32 mana = atoi(pmana);
337 int32 mana = atoi((char*)args)*10;
338 int32 manam = atoi((char*)args)*10;
340 if (mana <= 0 || manam <= 0 || manam < mana)
342 SendSysMessage(LANG_BAD_VALUE);
343 return true;
346 Player *chr = getSelectedPlayer();
347 if (chr == NULL)
349 SendSysMessage(LANG_NO_CHAR_SELECTED);
350 return true;
353 PSendSysMessage(LANG_YOU_CHANGE_RAGE, mana/10, manam/10, chr->GetName());
355 char buf[256];
356 sprintf((char*)buf,LANG_YOURS_RAGE_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
357 FillSystemMessageData(&data, m_session, buf);
359 chr->GetSession()->SendPacket(&data);
361 chr->SetMaxPower(POWER_RAGE,manam );
362 chr->SetPower(POWER_RAGE, mana );
364 return true;
367 bool ChatHandler::HandleModifyFactionCommand(const char* args)
370 uint32 factionid;
371 uint32 flag;
372 uint32 npcflag;
373 uint32 dyflag;
375 char* pfactionid = strtok((char*)args, " ");
377 Unit* chr = getSelectedCreature();
378 if(!chr)
380 SendSysMessage(LANG_SELECT_CREATURE);
381 return true;
384 if(!pfactionid)
386 if(chr)
388 factionid = chr->getFaction();
389 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
390 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
391 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
392 PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
394 return true;
397 if (chr == NULL)
399 SendSysMessage(LANG_NO_CHAR_SELECTED);
400 return true;
403 factionid = atoi(pfactionid);
405 char* pflag = strtok(NULL, " ");
406 if (!pflag)
407 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
408 else
409 flag = atoi(pflag);
411 char* pnpcflag = strtok(NULL, " ");
412 if(!pnpcflag)
413 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
414 else
415 npcflag = atoi(pnpcflag);
417 char* pdyflag = strtok(NULL, " ");
418 if(!pdyflag)
419 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
420 else
421 dyflag = atoi(pdyflag);
423 if(!sFactionTemplateStore.LookupEntry(factionid))
425 PSendSysMessage(LANG_WRONG_FACTION, factionid);
426 return true;
429 PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
431 //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
432 //FillSystemMessageData(&data, m_session, buf);
434 //chr->GetSession()->SendPacket(&data);
436 chr->setFaction(factionid);
437 chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
438 chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
439 chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
441 return true;
444 bool ChatHandler::HandleModifySpellCommand(const char* args)
447 WorldPacket data;
449 char* pspellflatid = strtok((char*)args, " ");
450 if (!pspellflatid)
451 return false;
453 char* pop = strtok(NULL, " ");
454 if (!pop)
455 return false;
457 char* pval = strtok(NULL, " ");
458 if (!pval)
459 return false;
461 uint16 mark;
463 char* pmark = strtok(NULL, " ");
465 uint8 spellflatid = atoi(pspellflatid);
466 uint8 op = atoi(pop);
467 uint16 val = atoi(pval);
468 if(!pmark)
469 mark = 65535;
470 else
471 mark = atoi(pmark);
473 Player *chr = getSelectedPlayer();
474 if (chr == NULL)
476 SendSysMessage(LANG_NO_CHAR_SELECTED);
477 return true;
480 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
482 char buf[256];
483 sprintf((char*)buf,LANG_YOURS_SPELLFLATID_CHANGED, m_session->GetPlayer()->GetName(), spellflatid, val, mark);
484 FillSystemMessageData(&data, m_session, buf);
486 chr->GetSession()->SendPacket(&data);
488 data.Initialize(SMSG_SET_FLAT_SPELL_MODIFIER);
489 data << uint8(spellflatid);
490 data << uint8(op);
491 data << uint16(val);
492 data << uint16(mark);
493 chr->GetSession()->SendPacket(&data);
495 return true;
498 bool ChatHandler::HandleModifyTalentCommand (const char* args)
500 int tp = atoi((char*)args);
501 if (tp>0)
503 Player* player = m_session->GetPlayer();
504 if(!player)
506 SendSysMessage(LANG_NO_CHAR_SELECTED);
507 return true;
509 player->SetUInt32Value(PLAYER_CHARACTER_POINTS1, tp);
510 return true;
512 return false;
515 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
517 WorldPacket data;
519 if (!*args)
520 return false;
522 int flag = atoi((char*)args);
524 Player *chr = getSelectedPlayer();
525 if (chr == NULL)
527 SendSysMessage(LANG_NO_CHAR_SELECTED);
528 return true;
531 if (flag != 0)
532 PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
533 else
534 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
536 char buf[256];
538 if (flag != 0)
540 chr->SetTaxiCheater(true);
541 sprintf((char*)buf,LANG_YOURS_TAXIS_ADDED,
542 m_session->GetPlayer()->GetName());
544 else
546 chr->SetTaxiCheater(false);
547 sprintf((char*)buf,LANG_YOURS_TAXIS_REMOVED,
548 m_session->GetPlayer()->GetName());
550 FillSystemMessageData(&data, m_session, buf);
551 chr->GetSession()->SendPacket(&data);
553 return true;
556 bool ChatHandler::HandleModifyASpedCommand(const char* args)
558 WorldPacket data;
560 if (!*args)
561 return false;
563 float ASpeed = (float)atof((char*)args);
565 if (ASpeed > 50 || ASpeed <= 0)
567 SendSysMessage(LANG_BAD_VALUE);
568 return true;
571 Player *chr = getSelectedPlayer();
572 if (chr == NULL)
574 SendSysMessage(LANG_NO_CHAR_SELECTED);
575 return true;
578 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
580 char buf[256];
581 sprintf((char*)buf,LANG_YOURS_ASPEED_CHANGED, m_session->GetPlayer()->GetName(), ASpeed);
582 FillSystemMessageData(&data, m_session, buf);
584 chr->GetSession()->SendPacket(&data);
586 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
587 data << uint8(0xFF);
588 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
589 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
590 data << (uint32)0;
591 data << (float)ASpeed;
592 chr->SendMessageToSet( &data, true );
594 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
595 data << uint8(0xFF);
596 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
597 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
598 data << (uint32)0;
599 data << (float)ASpeed;
600 chr->SendMessageToSet( &data, true );
601 data.Initialize( SMSG_FORCE_RUN_BACK_SPEED_CHANGE );
602 data << uint8(0xFF);
603 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
604 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
605 data << (uint32)0;
606 data << (float)ASpeed;
607 chr->SendMessageToSet( &data, true );
608 return true;
611 bool ChatHandler::HandleModifySpeedCommand(const char* args)
613 WorldPacket data;
615 if (!*args)
616 return false;
618 float Speed = (float)atof((char*)args);
620 if (Speed > 50 || Speed <= 0)
622 SendSysMessage(LANG_BAD_VALUE);
623 return true;
626 Player *chr = getSelectedPlayer();
627 if (chr == NULL)
629 SendSysMessage(LANG_NO_CHAR_SELECTED);
630 return true;
633 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
635 char buf[256];
636 sprintf((char*)buf,LANG_YOURS_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Speed);
637 FillSystemMessageData(&data, m_session, buf);
639 chr->GetSession()->SendPacket(&data);
641 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
642 data << uint8(0xFF);
643 data << chr->GetUInt32Value( OBJECT_FIELD_GUID ); //4
644 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 ); //4
645 data << uint32(0x0);
646 data << (float)Speed; //4
648 chr->SendMessageToSet( &data, true );
650 return true;
653 bool ChatHandler::HandleModifySwimCommand(const char* args)
655 WorldPacket data;
657 if (!*args)
658 return false;
660 float Swim = (float)atof((char*)args);
662 if (Swim > 50 || Swim <= 0)
664 SendSysMessage(LANG_BAD_VALUE);
665 return true;
668 Player *chr = getSelectedPlayer();
669 if (chr == NULL)
671 SendSysMessage(LANG_NO_CHAR_SELECTED);
672 return true;
675 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
677 char buf[256];
678 sprintf((char*)buf,LANG_YOURS_SWIM_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Swim);
679 FillSystemMessageData(&data, m_session, buf);
681 chr->GetSession()->SendPacket(&data);
683 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
684 data << uint8(0xFF);
685 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
686 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
687 data << (uint32)0;
688 data << (float)Swim;
689 chr->SendMessageToSet( &data, true );
691 return true;
694 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
696 WorldPacket data;
698 if (!*args)
699 return false;
701 float BSpeed = (float)atof((char*)args);
703 if (BSpeed > 50 || BSpeed <= 0)
705 SendSysMessage(LANG_BAD_VALUE);
706 return true;
709 Player *chr = getSelectedPlayer();
710 if (chr == NULL)
712 SendSysMessage(LANG_NO_CHAR_SELECTED);
713 return true;
716 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
718 char buf[256];
719 sprintf((char*)buf,LANG_YOURS_BACK_SPEED_CHANGED, m_session->GetPlayer()->GetName(), BSpeed);
720 FillSystemMessageData(&data, m_session, buf);
722 chr->GetSession()->SendPacket(&data);
724 data.Initialize( SMSG_FORCE_RUN_BACK_SPEED_CHANGE );
725 data << uint8(0xFF);
726 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
727 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
728 data << (uint32)0;
729 data << (float)BSpeed;
730 chr->SendMessageToSet( &data, true );
732 return true;
735 bool ChatHandler::HandleModifyScaleCommand(const char* args)
737 WorldPacket data;
739 if (!*args)
740 return false;
742 float Scale = (float)atof((char*)args);
743 if (Scale > 3 || Scale <= 0)
745 SendSysMessage(LANG_BAD_VALUE);
746 return true;
749 Player *chr = getSelectedPlayer();
750 if (chr == NULL)
752 SendSysMessage(LANG_NO_CHAR_SELECTED);
753 return true;
756 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
758 char buf[256];
759 sprintf((char*)buf,LANG_YOURS_SIZE_CHANGED, m_session->GetPlayer()->GetName(), Scale);
760 FillSystemMessageData(&data, m_session, buf);
762 chr->GetSession()->SendPacket(&data);
764 chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
766 return true;
769 bool ChatHandler::HandleModifyMountCommand(const char* args)
771 WorldPacket data;
773 if(!*args)
774 return false;
776 uint16 mId = 1147;
777 float speed = (float)15;
778 uint32 num = 0;
780 num = atoi((char*)args);
781 switch(num)
783 case 1:
784 mId=14340;
785 break;
786 case 2:
787 mId=4806;
788 break;
789 case 3:
790 mId=6471;
791 break;
792 case 4:
793 mId=12345;
794 break;
795 case 5:
796 mId=6472;
797 break;
798 case 6:
799 mId=6473;
800 break;
801 case 7:
802 mId=10670;
803 break;
804 case 8:
805 mId=10719;
806 break;
807 case 9:
808 mId=10671;
809 break;
810 case 10:
811 mId=10672;
812 break;
813 case 11:
814 mId=10720;
815 break;
816 case 12:
817 mId=14349;
818 break;
819 case 13:
820 mId=11641;
821 break;
822 case 14:
823 mId=12244;
824 break;
825 case 15:
826 mId=12242;
827 break;
828 case 16:
829 mId=14578;
830 break;
831 case 17:
832 mId=14579;
833 break;
834 case 18:
835 mId=14349;
836 break;
837 case 19:
838 mId=12245;
839 break;
840 case 20:
841 mId=14335;
842 break;
843 case 21:
844 mId=207;
845 break;
846 case 22:
847 mId=2328;
848 break;
849 case 23:
850 mId=2327;
851 break;
852 case 24:
853 mId=2326;
854 break;
855 case 25:
856 mId=14573;
857 break;
858 case 26:
859 mId=14574;
860 break;
861 case 27:
862 mId=14575;
863 break;
864 case 28:
865 mId=604;
866 break;
867 case 29:
868 mId=1166;
869 break;
870 case 30:
871 mId=2402;
872 break;
873 case 31:
874 mId=2410;
875 break;
876 case 32:
877 mId=2409;
878 break;
879 case 33:
880 mId=2408;
881 break;
882 case 34:
883 mId=2405;
884 break;
885 case 35:
886 mId=14337;
887 break;
888 case 36:
889 mId=6569;
890 break;
891 case 37:
892 mId=10661;
893 break;
894 case 38:
895 mId=10666;
896 break;
897 case 39:
898 mId=9473;
899 break;
900 case 40:
901 mId=9476;
902 break;
903 case 41:
904 mId=9474;
905 break;
906 case 42:
907 mId=14374;
908 break;
909 case 43:
910 mId=14376;
911 break;
912 case 44:
913 mId=14377;
914 break;
915 case 45:
916 mId=2404;
917 break;
918 case 46:
919 mId=2784;
920 break;
921 case 47:
922 mId=2787;
923 break;
924 case 48:
925 mId=2785;
926 break;
927 case 49:
928 mId=2736;
929 break;
930 case 50:
931 mId=2786;
932 break;
933 case 51:
934 mId=14347;
935 break;
936 case 52:
937 mId=14346;
938 break;
939 case 53:
940 mId=14576;
941 break;
942 case 54:
943 mId=9695;
944 break;
945 case 55:
946 mId=9991;
947 break;
948 case 56:
949 mId=6448;
950 break;
951 case 57:
952 mId=6444;
953 break;
954 case 58:
955 mId=6080;
956 break;
957 case 59:
958 mId=6447;
959 break;
960 case 60:
961 mId=4805;
962 break;
963 case 61:
964 mId=9714;
965 break;
966 case 62:
967 mId=6448;
968 break;
969 case 63:
970 mId=6442;
971 break;
972 case 64:
973 mId=14632;
974 break;
975 case 65:
976 mId=14332;
977 break;
978 case 66:
979 mId=14331;
980 break;
981 case 67:
982 mId=8469;
983 break;
984 case 68:
985 mId=2830;
986 break;
987 case 69:
988 mId=2346;
989 break;
990 default:
991 SendSysMessage(LANG_NO_MOUNT);
992 return true;
995 Player *chr = getSelectedPlayer();
996 if (chr == NULL)
998 SendSysMessage(LANG_NO_CHAR_SELECTED);
999 return true;
1002 PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1004 char buf[256];
1005 sprintf((char*)buf,LANG_MOUNT_GIVED, m_session->GetPlayer()->GetName());
1006 FillSystemMessageData(&data, m_session, buf);
1008 chr->GetSession()->SendPacket(&data);
1010 chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1011 chr->Mount(mId);
1013 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE );
1014 data << uint8(0xFF);
1015 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
1016 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
1017 data << (uint32)0;
1018 data << float(speed);
1019 chr->SendMessageToSet( &data, true );
1021 data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE );
1022 data << uint8(0xFF);
1023 data << chr->GetUInt32Value( OBJECT_FIELD_GUID );
1024 data << chr->GetUInt32Value( OBJECT_FIELD_GUID + 1 );
1025 data << (uint32)0;
1026 data << float(speed);
1027 chr->SendMessageToSet( &data, true );
1029 return true;
1032 bool ChatHandler::HandleModifyGoldCommand(const char* args)
1034 WorldPacket data;
1036 if (!*args)
1037 return false;
1039 int32 gold = atoi((char*)args);
1041 Player *chr = getSelectedPlayer();
1042 if (chr == NULL)
1044 SendSysMessage(LANG_NO_CHAR_SELECTED);
1045 return true;
1048 uint32 moneyuser = m_session->GetPlayer()->GetMoney();
1050 if(gold < 0)
1052 int32 newmoney = moneyuser + gold;
1054 sLog.outDetail(LANG_CURRENT_MONEY, moneyuser, gold, newmoney);
1055 if(newmoney < 0 )
1058 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1060 char buf[256];
1061 sprintf((char*)buf,LANG_YOURS_ALL_MONEY_GONE, m_session->GetPlayer()->GetName());
1062 FillSystemMessageData(&data, m_session, buf);
1063 chr->GetSession()->SendPacket(&data);
1065 chr->SetMoney(0);
1067 else
1070 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(gold), chr->GetName());
1072 char buf[256];
1073 sprintf((char*)buf,LANG_YOURS_MONEY_TAKEN, m_session->GetPlayer()->GetName(), abs(gold));
1074 FillSystemMessageData(&data, m_session, buf);
1075 chr->GetSession()->SendPacket(&data);
1077 chr->SetMoney( newmoney );
1080 else
1083 PSendSysMessage(LANG_YOU_GIVE_MONEY, gold, chr->GetName());
1085 char buf[256];
1086 sprintf((char*)buf,LANG_YOURS_MONEY_GIVEN, m_session->GetPlayer()->GetName(), gold);
1087 FillSystemMessageData(&data, m_session, buf);
1088 chr->GetSession()->SendPacket(&data);
1090 chr->ModifyMoney( gold );
1093 sLog.outDetail(LANG_NEW_MONEY, moneyuser, gold, chr->GetMoney() );
1095 return true;
1098 bool ChatHandler::HandleModifyBitCommand(const char* args)
1100 Player *chr = getSelectedPlayer();
1101 if (chr == NULL)
1103 SendSysMessage(LANG_NO_CHAR_SELECTED);
1104 return true;
1107 char* pField = strtok((char*)args, " ");
1108 if (!pField)
1109 return false;
1111 char* pBit = strtok(NULL, " ");
1112 if (!pBit)
1113 return false;
1115 uint16 field = atoi(pField);
1116 uint32 bit = atoi(pBit);
1118 if (field < 1 || field >= PLAYER_END)
1120 SendSysMessage(LANG_BAD_VALUE);
1121 return true;
1124 if (bit < 1 || bit > 32)
1126 SendSysMessage(LANG_BAD_VALUE);
1127 return true;
1130 if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1132 chr->RemoveFlag( field, (1<<(bit-1)) );
1133 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1135 else
1137 chr->SetFlag( field, (1<<(bit-1)) );
1138 PSendSysMessage(LANG_SET_BIT, bit, field);
1141 return true;
1144 bool ChatHandler::HandleTeleCommand(const char * args)
1146 QueryResult *result;
1147 if(!*args)
1149 result = sDatabase.Query("SELECT `name` FROM `game_tele`");
1150 if (!result)
1152 SendSysMessage("Teleport location table is empty!");
1153 return true;
1155 std::string reply="Valid locations are:";
1156 for (uint64 i=0; i < result->GetRowCount(); i++)
1158 Field *fields = result->Fetch();
1159 reply += " ";
1160 reply += fields[0].GetCppString();
1161 result->NextRow();
1163 SendSysMessage(reply.c_str());
1164 delete result;
1165 return true;
1167 char *name = (char*)args;
1168 result = sDatabase.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `game_tele` WHERE `name` = '%s'",name);
1169 if (!result)
1171 SendSysMessage("Teleport location not found!");
1172 return true;
1174 Field *fields = result->Fetch();
1175 float x = fields[0].GetFloat();
1176 float y = fields[1].GetFloat();
1177 float z = fields[2].GetFloat();
1178 float ort = fields[3].GetFloat();
1179 int mapid = fields[4].GetUInt16();
1180 delete result;
1182 if(!MapManager::ExistMAP(mapid,x,y))
1184 PSendSysMessage(".tele target map not exist (X: %f Y: %f MapId:%u)",x,y,mapid);
1185 return true;
1188 m_session->GetPlayer()->TeleportTo(mapid, x, y, z, ort);
1189 return true;
1192 bool ChatHandler::HandleSearchTeleCommand(const char * args)
1194 QueryResult *result;
1195 if(!*args)
1197 SendSysMessage("Requires search parameter.");
1198 return true;
1200 char const* str = strtok((char*)args, " ");
1201 result = sDatabase.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",str);
1202 if (!result)
1204 SendSysMessage("There are no teleport locations matching your request.");
1205 return true;
1207 std::string reply;
1208 for (uint64 i=0; i < result->GetRowCount(); i++)
1210 Field *fields = result->Fetch();
1211 reply += " ";
1212 reply += fields[0].GetCppString();
1213 reply += '\n';
1214 result->NextRow();
1216 delete result;
1218 if(reply.empty())
1219 SendSysMessage("None locations found.");
1220 else
1222 reply = "Locations found are:\n" + reply;
1223 SendSysMultilineMessage(reply.c_str());
1225 return true;
1228 bool ChatHandler::HandleWhispersCommand(const char* args)
1230 char* px = strtok((char*)args, " ");
1232 // ticket<end>
1233 if (!px)
1235 PSendSysMessage("Whispers accepting: %s", m_session->GetPlayer()->isAcceptWhispers() ? "on" : "off");
1236 return true;
1239 // ticket on
1240 if(strncmp(px,"on",3) == 0)
1242 m_session->GetPlayer()->SetAcceptWhispers(true);
1243 SendSysMessage("Whispers accepting: on");
1244 return true;
1247 // ticket off
1248 if(strncmp(px,"off",4) == 0)
1250 m_session->GetPlayer()->SetAcceptWhispers(false);
1251 SendSysMessage("Whispers accepting: off");
1252 return true;
1255 return false;