[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / debugcmds.cpp
blob74a76c6d324ec15f9bd9f25162caa0290eb77e33
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
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 "Vehicle.h"
23 #include "Player.h"
24 #include "Opcodes.h"
25 #include "Chat.h"
26 #include "Log.h"
27 #include "Unit.h"
28 #include "GossipDef.h"
29 #include "Language.h"
30 #include "BattleGroundMgr.h"
31 #include <fstream>
32 #include "ObjectMgr.h"
33 #include "ObjectGuid.h"
34 #include "SpellMgr.h"
36 bool ChatHandler::HandleDebugSendSpellFailCommand(const char* args)
38 if (!*args)
39 return false;
41 char* px = strtok((char*)args, " ");
42 if (!px)
43 return false;
45 uint8 failnum = (uint8)atoi(px);
46 if (failnum==0 && *px!='0')
47 return false;
49 char* p1 = strtok(NULL, " ");
50 uint8 failarg1 = p1 ? (uint8)atoi(p1) : 0;
52 char* p2 = strtok(NULL, " ");
53 uint8 failarg2 = p2 ? (uint8)atoi(p2) : 0;
55 WorldPacket data(SMSG_CAST_FAILED, 5);
56 data << uint8(0);
57 data << uint32(133);
58 data << uint8(failnum);
59 if (p1 || p2)
60 data << uint32(failarg1);
61 if (p2)
62 data << uint32(failarg2);
64 m_session->SendPacket(&data);
66 return true;
69 bool ChatHandler::HandleDebugSendPoiCommand(const char* args)
71 if (!*args)
72 return false;
74 Player *pPlayer = m_session->GetPlayer();
75 Unit* target = getSelectedUnit();
76 if (!target)
78 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
79 return true;
82 char* icon_text = strtok((char*)args, " ");
83 char* flags_text = strtok(NULL, " ");
84 if (!icon_text || !flags_text)
85 return false;
87 uint32 icon = atol(icon_text);
88 uint32 flags = atol(flags_text);
90 sLog.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target->GetGUIDLow(), icon,flags);
91 pPlayer->PlayerTalkClass->SendPointOfInterest(target->GetPositionX(), target->GetPositionY(), Poi_Icon(icon), flags, 30, "Test POI");
92 return true;
95 bool ChatHandler::HandleDebugSendEquipErrorCommand(const char* args)
97 if (!*args)
98 return false;
100 uint8 msg = atoi(args);
101 m_session->GetPlayer()->SendEquipError(msg, NULL, NULL);
102 return true;
105 bool ChatHandler::HandleDebugSendSellErrorCommand(const char* args)
107 if (!*args)
108 return false;
110 uint8 msg = atoi(args);
111 m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
112 return true;
115 bool ChatHandler::HandleDebugSendBuyErrorCommand(const char* args)
117 if (!*args)
118 return false;
120 uint8 msg = atoi(args);
121 m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
122 return true;
125 bool ChatHandler::HandleDebugSendOpcodeCommand(const char* /*args*/)
127 Unit *unit = getSelectedUnit();
128 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
129 unit = m_session->GetPlayer();
131 std::ifstream ifs("opcode.txt");
132 if (ifs.bad())
133 return false;
135 uint32 opcode;
136 ifs >> opcode;
138 WorldPacket data(opcode, 0);
140 while(!ifs.eof())
142 std::string type;
143 ifs >> type;
145 if(type == "")
146 break;
148 if(type == "uint8")
150 uint16 val1;
151 ifs >> val1;
152 data << uint8(val1);
154 else if(type == "uint16")
156 uint16 val2;
157 ifs >> val2;
158 data << val2;
160 else if(type == "uint32")
162 uint32 val3;
163 ifs >> val3;
164 data << val3;
166 else if(type == "uint64")
168 uint64 val4;
169 ifs >> val4;
170 data << val4;
172 else if(type == "float")
174 float val5;
175 ifs >> val5;
176 data << val5;
178 else if(type == "string")
180 std::string val6;
181 ifs >> val6;
182 data << val6;
184 else if(type == "pguid")
186 data << unit->GetPackGUID();
188 else
190 sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());
191 break;
194 ifs.close();
195 sLog.outDebug("Sending opcode %u", data.GetOpcode());
196 data.hexlike();
197 ((Player*)unit)->GetSession()->SendPacket(&data);
198 PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
199 return true;
202 bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args)
204 char* w = strtok((char*)args, " ");
205 char* s = strtok(NULL, " ");
207 if (!w || !s)
208 return false;
210 uint32 world = (uint32)atoi(w);
211 uint32 state = (uint32)atoi(s);
212 m_session->GetPlayer()->SendUpdateWorldState(world, state);
213 return true;
216 bool ChatHandler::HandleDebugPlayCinematicCommand(const char* args)
218 // USAGE: .debug play cinematic #cinematicid
219 // #cinematicid - ID decimal number from CinemaicSequences.dbc (1st column)
220 if (!*args)
222 SendSysMessage(LANG_BAD_VALUE);
223 SetSentErrorMessage(true);
224 return false;
227 uint32 dwId = atoi((char*)args);
229 if (!sCinematicSequencesStore.LookupEntry(dwId))
231 PSendSysMessage(LANG_CINEMATIC_NOT_EXIST, dwId);
232 SetSentErrorMessage(true);
233 return false;
236 m_session->GetPlayer()->SendCinematicStart(dwId);
237 return true;
240 bool ChatHandler::HandleDebugPlayMovieCommand(const char* args)
242 // USAGE: .debug play movie #movieid
243 // #movieid - ID decimal number from Movie.dbc (1st column)
244 if (!*args)
246 SendSysMessage(LANG_BAD_VALUE);
247 SetSentErrorMessage(true);
248 return false;
251 uint32 dwId = atoi((char*)args);
253 if (!sMovieStore.LookupEntry(dwId))
255 PSendSysMessage(LANG_MOVIE_NOT_EXIST, dwId);
256 SetSentErrorMessage(true);
257 return false;
260 m_session->GetPlayer()->SendMovieStart(dwId);
261 return true;
264 //Play sound
265 bool ChatHandler::HandleDebugPlaySoundCommand(const char* args)
267 // USAGE: .debug playsound #soundid
268 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
269 if (!*args)
271 SendSysMessage(LANG_BAD_VALUE);
272 SetSentErrorMessage(true);
273 return false;
276 uint32 dwSoundId = atoi((char*)args);
278 if (!sSoundEntriesStore.LookupEntry(dwSoundId))
280 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
281 SetSentErrorMessage(true);
282 return false;
285 Unit* unit = getSelectedUnit();
286 if (!unit)
288 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
289 SetSentErrorMessage(true);
290 return false;
293 if (m_session->GetPlayer()->GetSelection())
294 unit->PlayDistanceSound(dwSoundId,m_session->GetPlayer());
295 else
296 unit->PlayDirectSound(dwSoundId,m_session->GetPlayer());
298 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
299 return true;
302 //Send notification in channel
303 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args)
305 if (!*args)
306 return false;
308 const char *name = "test";
309 uint8 code = atoi(args);
311 WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
312 data << code; // notify type
313 data << name; // channel name
314 data << uint32(0);
315 data << uint32(0);
316 m_session->SendPacket(&data);
317 return true;
320 //Send notification in chat
321 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args)
323 if (!*args)
324 return false;
326 const char *msg = "testtest";
327 uint8 type = atoi(args);
328 WorldPacket data;
329 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
330 m_session->SendPacket(&data);
331 return true;
334 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args)
336 uint32 msg = atol((char*)args);
337 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
338 return true;
341 bool ChatHandler::HandleDebugGetLootRecipientCommand(const char* /*args*/)
343 Creature* target = getSelectedCreature();
344 if (!target)
345 return false;
347 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
348 return true;
351 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args)
353 uint32 msg = atol((char*)args);
354 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
355 return true;
358 bool ChatHandler::HandleDebugGetItemStateCommand(const char* args)
360 if (!*args)
361 return false;
363 std::string state_str = args;
365 ItemUpdateState state = ITEM_UNCHANGED;
366 bool list_queue = false, check_all = false;
367 if (state_str == "unchanged") state = ITEM_UNCHANGED;
368 else if (state_str == "changed") state = ITEM_CHANGED;
369 else if (state_str == "new") state = ITEM_NEW;
370 else if (state_str == "removed") state = ITEM_REMOVED;
371 else if (state_str == "queue") list_queue = true;
372 else if (state_str == "check_all") check_all = true;
373 else return false;
375 Player* player = getSelectedPlayer();
376 if (!player) player = m_session->GetPlayer();
378 if (!list_queue && !check_all)
380 state_str = "The player has the following " + state_str + " items: ";
381 SendSysMessage(state_str.c_str());
382 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i)
384 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
385 continue;
387 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
388 if (!item) continue;
389 if (!item->IsBag())
391 if (item->GetState() == state)
392 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
394 else
396 Bag *bag = (Bag*)item;
397 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
399 Item* item2 = bag->GetItemByPos(j);
400 if (item2 && item2->GetState() == state)
401 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item2->GetSlot(), item2->GetGUIDLow(), GUID_LOPART(item2->GetOwnerGUID()));
407 if (list_queue)
409 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
410 for(size_t i = 0; i < updateQueue.size(); ++i)
412 Item *item = updateQueue[i];
413 if(!item) continue;
415 Bag *container = item->GetContainer();
416 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
418 std::string st;
419 switch(item->GetState())
421 case ITEM_UNCHANGED: st = "unchanged"; break;
422 case ITEM_CHANGED: st = "changed"; break;
423 case ITEM_NEW: st = "new"; break;
424 case ITEM_REMOVED: st = "removed"; break;
427 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
429 if (updateQueue.empty())
430 PSendSysMessage("updatequeue empty");
433 if (check_all)
435 bool error = false;
436 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
437 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i)
439 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
440 continue;
442 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
443 if (!item) continue;
445 if (item->GetSlot() != i)
447 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
448 error = true; continue;
451 if (item->GetOwnerGUID() != player->GetGUID())
453 PSendSysMessage("for the item at slot %d and itemguid %d, owner's guid (%d) and player's guid (%d) don't match!", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()), player->GetGUIDLow());
454 error = true; continue;
457 if (Bag *container = item->GetContainer())
459 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item->GetSlot(), item->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
460 error = true; continue;
463 if (item->IsInUpdateQueue())
465 uint16 qp = item->GetQueuePos();
466 if (qp > updateQueue.size())
468 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUIDLow(), qp);
469 error = true; continue;
472 if (updateQueue[qp] == NULL)
474 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item->GetSlot(), item->GetGUIDLow(), qp);
475 error = true; continue;
478 if (updateQueue[qp] != item)
480 PSendSysMessage("item at slot: %d guid: %d has has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", item->GetSlot(), item->GetGUIDLow(), qp, updateQueue[qp]->GetBagSlot(), updateQueue[qp]->GetSlot(), updateQueue[qp]->GetGUIDLow());
481 error = true; continue;
484 else if (item->GetState() != ITEM_UNCHANGED)
486 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUIDLow(), item->GetState());
487 error = true; continue;
490 if(item->IsBag())
492 Bag *bag = (Bag*)item;
493 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
495 Item* item2 = bag->GetItemByPos(j);
496 if (!item2) continue;
498 if (item2->GetSlot() != j)
500 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag->GetSlot(), j, item2->GetGUIDLow(), item2->GetSlot());
501 error = true; continue;
504 if (item2->GetOwnerGUID() != player->GetGUID())
506 PSendSysMessage("for the item in bag %d at slot %d and itemguid %d, owner's guid (%d) and player's guid (%d) don't match!", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), GUID_LOPART(item2->GetOwnerGUID()), player->GetGUIDLow());
507 error = true; continue;
510 Bag *container = item2->GetContainer();
511 if (!container)
513 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow());
514 error = true; continue;
517 if (container != bag)
519 PSendSysMessage("the item in bag %d at slot %d with guid %d has a different container(slot %d guid %d)!", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
520 error = true; continue;
523 if (item2->IsInUpdateQueue())
525 uint16 qp = item2->GetQueuePos();
526 if (qp > updateQueue.size())
528 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), qp);
529 error = true; continue;
532 if (updateQueue[qp] == NULL)
534 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), qp);
535 error = true; continue;
538 if (updateQueue[qp] != item2)
540 PSendSysMessage("item in bag: %d at slot: %d guid: %d has has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), qp, updateQueue[qp]->GetBagSlot(), updateQueue[qp]->GetSlot(), updateQueue[qp]->GetGUIDLow());
541 error = true; continue;
544 else if (item2->GetState() != ITEM_UNCHANGED)
546 PSendSysMessage("item in bag: %d at slot: %d guid: %d is not in queue but should be (state: %d)!", bag->GetSlot(), item2->GetSlot(), item2->GetGUIDLow(), item2->GetState());
547 error = true; continue;
553 for(size_t i = 0; i < updateQueue.size(); ++i)
555 Item *item = updateQueue[i];
556 if(!item) continue;
558 if (item->GetOwnerGUID() != player->GetGUID())
560 PSendSysMessage("queue(" SIZEFMTD "): for the an item (guid %d), the owner's guid (%d) and player's guid (%d) don't match!", i, item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()), player->GetGUIDLow());
561 error = true; continue;
564 if (item->GetQueuePos() != i)
566 PSendSysMessage("queue(" SIZEFMTD "): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
567 error = true; continue;
570 if (item->GetState() == ITEM_REMOVED) continue;
571 Item *test = player->GetItemByPos( item->GetBagSlot(), item->GetSlot());
573 if (test == NULL)
575 PSendSysMessage("queue(" SIZEFMTD "): the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have an item at that position!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow());
576 error = true; continue;
579 if (test != item)
581 PSendSysMessage("queue(" SIZEFMTD "): the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the item with guid %d is there instead!", i, item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow(), test->GetGUIDLow());
582 error = true; continue;
585 if (!error)
586 SendSysMessage("All OK!");
589 return true;
592 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
594 sBattleGroundMgr.ToggleTesting();
595 return true;
598 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
600 sBattleGroundMgr.ToggleArenaTesting();
601 return true;
604 bool ChatHandler::HandleDebugSpawnVehicle(const char* args)
606 if (!*args)
607 return false;
609 char* e = strtok((char*)args, " ");
610 char* i = strtok(NULL, " ");
612 if (!e || !i)
613 return false;
615 uint32 entry = (uint32)atoi(e);
616 uint32 id = (uint32)atoi(i);
618 CreatureInfo const *ci = ObjectMgr::GetCreatureTemplate(entry);
620 if (!ci)
621 return false;
623 VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
625 if (!ve)
626 return false;
628 Vehicle *v = new Vehicle;
629 Map *map = m_session->GetPlayer()->GetMap();
630 if (!v->Create(map->GenerateLocalLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
632 delete v;
633 return false;
636 float px, py, pz;
637 m_session->GetPlayer()->GetClosePoint(px, py, pz, m_session->GetPlayer()->GetObjectSize());
639 v->Relocate(px, py, pz, m_session->GetPlayer()->GetOrientation());
641 if (!v->IsPositionValid())
643 sLog.outError("Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
644 v->GetGUIDLow(), v->GetEntry(), v->GetPositionX(), v->GetPositionY());
645 delete v;
646 return false;
649 map->Add((Creature*)v);
651 return true;
654 bool ChatHandler::HandleDebugSpellCheckCommand(const char* /*args*/)
656 sLog.outString( "Check expected in code spell properties base at table 'spell_check' content...");
657 sSpellMgr.CheckUsedSpells("spell_check");
658 return true;
661 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
663 const char* stuffingString = "This is a dummy string to push the packet's size beyond 128000 bytes. ";
664 std::ostringstream ss;
665 while(ss.str().size() < 128000)
666 ss << stuffingString;
667 SendSysMessage(ss.str().c_str());
668 return true;
671 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args)
673 if (!*args)
674 return false;
676 uint32 PhaseShift = atoi(args);
677 m_session->SendSetPhaseShift(PhaseShift);
678 return true;
681 bool ChatHandler::HandleDebugGetItemValueCommand(const char* args)
683 if (!*args)
684 return false;
686 char* e = strtok((char*)args, " ");
687 char* f = strtok(NULL, " ");
689 if (!e || !f)
690 return false;
692 uint32 guid = (uint32)atoi(e);
693 uint32 index = (uint32)atoi(f);
695 Item *i = m_session->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM, guid));
697 if (!i)
698 return false;
700 if (index >= i->GetValuesCount())
701 return false;
703 uint32 value = i->GetUInt32Value(index);
705 PSendSysMessage("Item %u: value at %u is %u", guid, index, value);
707 return true;
710 bool ChatHandler::HandleDebugSetItemValueCommand(const char* args)
712 if (!*args)
713 return false;
715 char* e = strtok((char*)args, " ");
716 char* f = strtok(NULL, " ");
717 char* g = strtok(NULL, " ");
719 if (!e || !f || !g)
720 return false;
722 uint32 guid = (uint32)atoi(e);
723 uint32 index = (uint32)atoi(f);
724 uint32 value = (uint32)atoi(g);
726 Item *i = m_session->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM, guid));
728 if (!i)
729 return false;
731 if (index >= i->GetValuesCount())
732 return false;
734 i->SetUInt32Value(index, value);
736 return true;
739 //show animation
740 bool ChatHandler::HandleDebugAnimCommand(const char* args)
742 if (!*args)
743 return false;
745 uint32 anim_id = atoi((char*)args);
746 m_session->GetPlayer()->HandleEmoteCommand(anim_id);
747 return true;
750 bool ChatHandler::HandleDebugSetAuraStateCommand(const char* args)
752 if (!*args)
754 SendSysMessage(LANG_BAD_VALUE);
755 SetSentErrorMessage(true);
756 return false;
759 Unit* unit = getSelectedUnit();
760 if (!unit)
762 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
763 SetSentErrorMessage(true);
764 return false;
767 int32 state = atoi((char*)args);
768 if (!state)
770 // reset all states
771 for(int i = 1; i <= 32; ++i)
772 unit->ModifyAuraState(AuraState(i),false);
773 return true;
776 unit->ModifyAuraState(AuraState(abs(state)),state > 0);
777 return true;
780 bool ChatHandler::HandleDebugSetValueCommand(const char* args)
782 if(!*args)
783 return false;
785 char* px = strtok((char*)args, " ");
786 char* py = strtok(NULL, " ");
787 char* pz = strtok(NULL, " ");
789 if (!px || !py)
790 return false;
792 Unit* target = getSelectedUnit();
793 if(!target)
795 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
796 SetSentErrorMessage(true);
797 return false;
800 uint64 guid = target->GetGUID();
802 uint32 Opcode = (uint32)atoi(px);
803 if(Opcode >= target->GetValuesCount())
805 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
806 return false;
808 uint32 iValue;
809 float fValue;
810 bool isint32 = true;
811 if(pz)
812 isint32 = (bool)atoi(pz);
813 if(isint32)
815 iValue = (uint32)atoi(py);
816 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
817 target->SetUInt32Value( Opcode , iValue );
818 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
820 else
822 fValue = (float)atof(py);
823 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
824 target->SetFloatValue( Opcode , fValue );
825 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
828 return true;
831 bool ChatHandler::HandleDebugGetValueCommand(const char* args)
833 if(!*args)
834 return false;
836 char* px = strtok((char*)args, " ");
837 char* pz = strtok(NULL, " ");
839 if (!px)
840 return false;
842 Unit* target = getSelectedUnit();
843 if(!target)
845 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
846 SetSentErrorMessage(true);
847 return false;
850 uint64 guid = target->GetGUID();
852 uint32 Opcode = (uint32)atoi(px);
853 if(Opcode >= target->GetValuesCount())
855 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
856 return false;
858 uint32 iValue;
859 float fValue;
860 bool isint32 = true;
861 if(pz)
862 isint32 = (bool)atoi(pz);
864 if(isint32)
866 iValue = target->GetUInt32Value( Opcode );
867 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
868 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
870 else
872 fValue = target->GetFloatValue( Opcode );
873 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
874 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
877 return true;
880 bool ChatHandler::HandleDebugMod32ValueCommand(const char* args)
882 if(!*args)
883 return false;
885 char* px = strtok((char*)args, " ");
886 char* py = strtok(NULL, " ");
888 if (!px || !py)
889 return false;
891 uint32 Opcode = (uint32)atoi(px);
892 int Value = atoi(py);
894 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
896 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
897 return false;
900 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
902 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
904 CurrentValue += Value;
905 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
907 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
909 return true;
912 bool ChatHandler::HandleDebugUpdateCommand(const char* args)
914 if(!*args)
915 return false;
917 uint32 updateIndex;
918 uint32 value;
920 char* pUpdateIndex = strtok((char*)args, " ");
922 Unit* chr = getSelectedUnit();
923 if (chr == NULL)
925 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
926 SetSentErrorMessage(true);
927 return false;
930 if(!pUpdateIndex)
932 return true;
934 updateIndex = atoi(pUpdateIndex);
935 //check updateIndex
936 if(chr->GetTypeId() == TYPEID_PLAYER)
938 if (updateIndex>=PLAYER_END) return true;
940 else
942 if (updateIndex>=UNIT_END) return true;
945 char* pvalue = strtok(NULL, " ");
946 if (!pvalue)
948 value=chr->GetUInt32Value(updateIndex);
950 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
951 return true;
954 value=atoi(pvalue);
956 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
958 chr->SetUInt32Value(updateIndex,value);
960 return true;