2 * Copyright (C) 2005-2013 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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
27 #include "GossipDef.h"
29 #include "BattleGround/BattleGroundMgr.h"
31 #include "ObjectMgr.h"
32 #include "ObjectGuid.h"
35 bool ChatHandler::HandleDebugSendSpellFailCommand(char* args
)
41 if (!ExtractUInt32(&args
, failnum
) || failnum
> 255)
45 if (!ExtractOptUInt32(&args
, failarg1
, 0))
49 if (!ExtractOptUInt32(&args
, failarg2
, 0))
52 WorldPacket
data(SMSG_CAST_FAILED
, 5);
55 data
<< uint8(failnum
);
56 if (failarg1
|| failarg2
)
57 data
<< uint32(failarg1
);
59 data
<< uint32(failarg2
);
61 m_session
->SendPacket(&data
);
66 bool ChatHandler::HandleDebugSendPoiCommand(char* args
)
68 Player
* pPlayer
= m_session
->GetPlayer();
69 Unit
* target
= getSelectedUnit();
72 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
77 if (!ExtractUInt32(&args
, icon
))
81 if (!ExtractUInt32(&args
, flags
))
84 DETAIL_LOG("Command : POI, NPC = %u, icon = %u flags = %u", target
->GetGUIDLow(), icon
, flags
);
85 pPlayer
->PlayerTalkClass
->SendPointOfInterest(target
->GetPositionX(), target
->GetPositionY(), Poi_Icon(icon
), flags
, 30, "Test POI");
89 bool ChatHandler::HandleDebugSendEquipErrorCommand(char* args
)
94 uint8 msg
= atoi(args
);
95 m_session
->GetPlayer()->SendEquipError(InventoryResult(msg
), NULL
, NULL
);
99 bool ChatHandler::HandleDebugSendSellErrorCommand(char* args
)
104 uint8 msg
= atoi(args
);
105 m_session
->GetPlayer()->SendSellError(SellResult(msg
), 0, ObjectGuid(), 0);
109 bool ChatHandler::HandleDebugSendBuyErrorCommand(char* args
)
114 uint8 msg
= atoi(args
);
115 m_session
->GetPlayer()->SendBuyError(BuyResult(msg
), 0, 0, 0);
119 bool ChatHandler::HandleDebugSendOpcodeCommand(char* /*args*/)
121 Unit
* unit
= getSelectedUnit();
122 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
123 unit
= m_session
->GetPlayer();
125 std::ifstream
ifs("opcode.txt");
132 WorldPacket
data(opcode
, 0);
148 else if (type
== "uint16")
154 else if (type
== "uint32")
160 else if (type
== "uint64")
166 else if (type
== "float")
172 else if (type
== "string")
178 else if (type
== "pguid")
180 data
<< unit
->GetPackGUID();
184 DEBUG_LOG("Sending opcode: unknown type '%s'", type
.c_str());
189 DEBUG_LOG("Sending opcode %u", data
.GetOpcode());
191 ((Player
*)unit
)->GetSession()->SendPacket(&data
);
192 PSendSysMessage(LANG_COMMAND_OPCODESENT
, data
.GetOpcode(), unit
->GetName());
196 bool ChatHandler::HandleDebugUpdateWorldStateCommand(char* args
)
199 if (!ExtractUInt32(&args
, world
))
203 if (!ExtractUInt32(&args
, state
))
206 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
210 bool ChatHandler::HandleDebugPlayCinematicCommand(char* args
)
212 // USAGE: .debug play cinematic #cinematicid
213 // #cinematicid - ID decimal number from CinemaicSequences.dbc (1st column)
215 if (!ExtractUInt32(&args
, dwId
))
218 if (!sCinematicSequencesStore
.LookupEntry(dwId
))
220 PSendSysMessage(LANG_CINEMATIC_NOT_EXIST
, dwId
);
221 SetSentErrorMessage(true);
225 m_session
->GetPlayer()->SendCinematicStart(dwId
);
229 bool ChatHandler::HandleDebugPlayMovieCommand(char* args
)
231 // USAGE: .debug play movie #movieid
232 // #movieid - ID decimal number from Movie.dbc (1st column)
234 if (!ExtractUInt32(&args
, dwId
))
237 if (!sMovieStore
.LookupEntry(dwId
))
239 PSendSysMessage(LANG_MOVIE_NOT_EXIST
, dwId
);
240 SetSentErrorMessage(true);
244 m_session
->GetPlayer()->SendMovieStart(dwId
);
249 bool ChatHandler::HandleDebugPlaySoundCommand(char* args
)
251 // USAGE: .debug playsound #soundid
252 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
254 if (!ExtractUInt32(&args
, dwSoundId
))
257 if (!sSoundEntriesStore
.LookupEntry(dwSoundId
))
259 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
260 SetSentErrorMessage(true);
264 Unit
* unit
= getSelectedUnit();
267 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
268 SetSentErrorMessage(true);
272 if (m_session
->GetPlayer()->GetSelectionGuid())
273 unit
->PlayDistanceSound(dwSoundId
, m_session
->GetPlayer());
275 unit
->PlayDirectSound(dwSoundId
, m_session
->GetPlayer());
277 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
281 // Send notification in channel
282 bool ChatHandler::HandleDebugSendChannelNotifyCommand(char* args
)
284 const char* name
= "test";
287 if (!ExtractUInt32(&args
, code
) || code
> 255)
290 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1 + 10));
291 data
<< uint8(code
); // notify type
292 data
<< name
; // channel name
295 m_session
->SendPacket(&data
);
299 // Send notification in chat
300 bool ChatHandler::HandleDebugSendChatMsgCommand(char* args
)
302 const char* msg
= "testtest";
305 if (!ExtractUInt32(&args
, type
) || type
> 255)
309 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetObjectGuid(), msg
, m_session
->GetPlayer());
310 m_session
->SendPacket(&data
);
314 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(char* args
)
317 if (!ExtractUInt32(&args
, msg
))
320 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
324 bool ChatHandler::HandleDebugGetLootRecipientCommand(char* /*args*/)
326 Creature
* target
= getSelectedCreature();
330 if (!target
->HasLootRecipient())
331 SendSysMessage("loot recipient: no loot recipient");
332 else if (Player
* recipient
= target
->GetLootRecipient())
333 PSendSysMessage("loot recipient: %s with raw data %s from group %u",
334 recipient
->GetGuidStr().c_str(),
335 target
->GetLootRecipientGuid().GetString().c_str(),
336 target
->GetLootGroupRecipientId());
338 SendSysMessage("loot recipient: offline ");
343 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(char* args
)
345 uint32 msg
= atol(args
);
346 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
350 bool ChatHandler::HandleDebugGetItemStateCommand(char* args
)
355 ItemUpdateState state
= ITEM_UNCHANGED
;
356 bool list_queue
= false, check_all
= false;
358 std::string state_str
;
360 if (strncmp(args
, "unchanged", strlen(args
)) == 0)
362 state
= ITEM_UNCHANGED
;
363 state_str
= "unchanged";
365 else if (strncmp(args
, "changed", strlen(args
)) == 0)
367 state
= ITEM_CHANGED
;
368 state_str
= "changed";
370 else if (strncmp(args
, "new", strlen(args
)) == 0)
375 else if (strncmp(args
, "removed", strlen(args
)) == 0)
377 state
= ITEM_REMOVED
;
378 state_str
= "removed";
380 else if (strncmp(args
, "queue", strlen(args
)) == 0)
382 else if (strncmp(args
, "all", strlen(args
)) == 0)
387 Player
* player
= getSelectedPlayer();
388 if (!player
) player
= m_session
->GetPlayer();
390 if (!list_queue
&& !check_all
)
392 state_str
= "The player has the following " + state_str
+ " items: ";
393 SendSysMessage(state_str
.c_str());
394 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; ++i
)
396 if (i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
399 Item
* item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
403 if (item
->GetState() == state
)
404 PSendSysMessage("%s bag: 255 slot: %u owner: %s",
405 item
->GetGuidStr().c_str(), item
->GetSlot(), item
->GetOwnerGuid().GetString().c_str());
409 Bag
* bag
= (Bag
*)item
;
410 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
412 Item
* item2
= bag
->GetItemByPos(j
);
413 if (item2
&& item2
->GetState() == state
)
414 PSendSysMessage("%s bag: %u slot: %u owner: %s",
415 item2
->GetGuidStr().c_str(), item2
->GetBagSlot(), item2
->GetSlot(),
416 item2
->GetOwnerGuid().GetString().c_str());
424 std::vector
<Item
*>& updateQueue
= player
->GetItemUpdateQueue();
425 for (size_t i
= 0; i
< updateQueue
.size(); ++i
)
427 Item
* item
= updateQueue
[i
];
430 Bag
* container
= item
->GetContainer();
431 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
434 switch (item
->GetState())
436 case ITEM_UNCHANGED
: st
= "unchanged"; break;
437 case ITEM_CHANGED
: st
= "changed"; break;
438 case ITEM_NEW
: st
= "new"; break;
439 case ITEM_REMOVED
: st
= "removed"; break;
442 PSendSysMessage("%s bag: %u slot: %u - state: %s",
443 item
->GetGuidStr().c_str(), bag_slot
, item
->GetSlot(), st
.c_str());
445 if (updateQueue
.empty())
446 PSendSysMessage("updatequeue empty");
452 std::vector
<Item
*>& updateQueue
= player
->GetItemUpdateQueue();
453 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; ++i
)
455 if (i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
458 Item
* item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
461 if (item
->GetSlot() != i
)
463 PSendSysMessage("%s at slot %u has an incorrect slot value: %d",
464 item
->GetGuidStr().c_str(), i
, item
->GetSlot());
465 error
= true; continue;
468 if (item
->GetOwnerGuid() != player
->GetObjectGuid())
470 PSendSysMessage("%s at slot %u owner (%s) and inventory owner (%s) don't match!",
471 item
->GetGuidStr().c_str(), item
->GetSlot(),
472 item
->GetOwnerGuid().GetString().c_str(), player
->GetGuidStr().c_str());
473 error
= true; continue;
476 if (Bag
* container
= item
->GetContainer())
478 PSendSysMessage("%s at slot %u has a container %s from slot %u but shouldnt!",
479 item
->GetGuidStr().c_str(), item
->GetSlot(),
480 container
->GetGuidStr().c_str(), container
->GetSlot());
481 error
= true; continue;
484 if (item
->IsInUpdateQueue())
486 uint16 qp
= item
->GetQueuePos();
487 if (qp
> updateQueue
.size())
489 PSendSysMessage("%s at slot %u has a queuepos (%d) larger than the update queue size! ",
490 item
->GetGuidStr().c_str(), item
->GetSlot(), qp
);
491 error
= true; continue;
494 if (updateQueue
[qp
] == NULL
)
496 PSendSysMessage("%s at slot %u has a queuepos (%d) that points to NULL in the queue!",
497 item
->GetGuidStr().c_str(), item
->GetSlot(), qp
);
498 error
= true; continue;
501 if (updateQueue
[qp
] != item
)
503 PSendSysMessage("%s at slot %u has a queuepos (%d) that points to %s in the queue (bag %u, slot %u)",
504 item
->GetGuidStr().c_str(), item
->GetSlot(), qp
,
505 updateQueue
[qp
]->GetGuidStr().c_str(), updateQueue
[qp
]->GetBagSlot(), updateQueue
[qp
]->GetSlot());
506 error
= true; continue;
509 else if (item
->GetState() != ITEM_UNCHANGED
)
511 PSendSysMessage("%s at slot %u is not in queue but should be (state: %d)!",
512 item
->GetGuidStr().c_str(), item
->GetSlot(), item
->GetState());
513 error
= true; continue;
518 Bag
* bag
= (Bag
*)item
;
519 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
521 Item
* item2
= bag
->GetItemByPos(j
);
522 if (!item2
) continue;
524 if (item2
->GetSlot() != j
)
526 PSendSysMessage("%s in bag %u at slot %u has an incorrect slot value: %u",
527 item2
->GetGuidStr().c_str(), bag
->GetSlot(), j
, item2
->GetSlot());
528 error
= true; continue;
531 if (item2
->GetOwnerGuid() != player
->GetObjectGuid())
533 PSendSysMessage("%s in bag %u at slot %u owner (%s) and inventory owner (%s) don't match!",
534 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(),
535 item2
->GetOwnerGuid().GetString().c_str(), player
->GetGuidStr().c_str());
536 error
= true; continue;
539 Bag
* container
= item2
->GetContainer();
542 PSendSysMessage("%s in bag %u at slot %u has no container!",
543 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot());
544 error
= true; continue;
547 if (container
!= bag
)
549 PSendSysMessage("%s in bag %u at slot %u has a different container %s from slot %u!",
550 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(),
551 container
->GetGuidStr().c_str(), container
->GetSlot());
552 error
= true; continue;
555 if (item2
->IsInUpdateQueue())
557 uint16 qp
= item2
->GetQueuePos();
558 if (qp
> updateQueue
.size())
560 PSendSysMessage("%s in bag %u at slot %u has a queuepos (%d) larger than the update queue size! ",
561 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(), qp
);
562 error
= true; continue;
565 if (updateQueue
[qp
] == NULL
)
567 PSendSysMessage("%s in bag %u at slot %u has a queuepos (%d) that points to NULL in the queue!",
568 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(), qp
);
569 error
= true; continue;
572 if (updateQueue
[qp
] != item2
)
574 PSendSysMessage("%s in bag %u at slot %u has a queuepos (%d) that points to %s in the queue (bag %u slot %u)",
575 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(), qp
,
576 updateQueue
[qp
]->GetGuidStr().c_str(), updateQueue
[qp
]->GetBagSlot(), updateQueue
[qp
]->GetSlot());
577 error
= true; continue;
580 else if (item2
->GetState() != ITEM_UNCHANGED
)
582 PSendSysMessage("%s in bag %u at slot %u is not in queue but should be (state: %d)!",
583 item2
->GetGuidStr().c_str(), bag
->GetSlot(), item2
->GetSlot(), item2
->GetState());
584 error
= true; continue;
590 for (size_t i
= 0; i
< updateQueue
.size(); ++i
)
592 Item
* item
= updateQueue
[i
];
595 if (item
->GetOwnerGuid() != player
->GetObjectGuid())
597 PSendSysMessage("queue(" SIZEFMTD
"): %s has the owner (%s) and inventory owner (%s) don't match!",
598 i
, item
->GetGuidStr().c_str(),
599 item
->GetOwnerGuid().GetString().c_str(), player
->GetGuidStr().c_str());
600 error
= true; continue;
603 if (item
->GetQueuePos() != i
)
605 PSendSysMessage("queue(" SIZEFMTD
"): %s has queuepos doesn't match it's position in the queue!",
606 i
, item
->GetGuidStr().c_str());
607 error
= true; continue;
610 if (item
->GetState() == ITEM_REMOVED
) continue;
611 Item
* test
= player
->GetItemByPos(item
->GetBagSlot(), item
->GetSlot());
615 PSendSysMessage("queue(" SIZEFMTD
"): %s has incorrect (bag %u slot %u) values, the player doesn't have an item at that position!",
616 i
, item
->GetGuidStr().c_str(), item
->GetBagSlot(), item
->GetSlot());
617 error
= true; continue;
622 PSendSysMessage("queue(" SIZEFMTD
"): %s has incorrect (bag %u slot %u) values, the %s is there instead!",
623 i
, item
->GetGuidStr().c_str(), item
->GetBagSlot(), item
->GetSlot(),
624 test
->GetGuidStr().c_str());
625 error
= true; continue;
629 SendSysMessage("All OK!");
635 bool ChatHandler::HandleDebugBattlegroundCommand(char* /*args*/)
637 sBattleGroundMgr
.ToggleTesting();
641 bool ChatHandler::HandleDebugArenaCommand(char* /*args*/)
643 sBattleGroundMgr
.ToggleArenaTesting();
647 bool ChatHandler::HandleDebugSpellCheckCommand(char* /*args*/)
649 sLog
.outString("Check expected in code spell properties base at table 'spell_check' content...");
650 sSpellMgr
.CheckUsedSpells("spell_check");
654 bool ChatHandler::HandleDebugSendLargePacketCommand(char* /*args*/)
656 const char* stuffingString
= "This is a dummy string to push the packet's size beyond 128000 bytes. ";
657 std::ostringstream ss
;
658 while (ss
.str().size() < 128000)
659 ss
<< stuffingString
;
660 SendSysMessage(ss
.str().c_str());
664 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(char* args
)
669 char* m
= strtok((char*)args
, " ");
670 char* p
= strtok(NULL
, " ");
672 uint16 MapId
= atoi(m
);
673 uint32 PhaseShift
= atoi(p
);
674 m_session
->SendSetPhaseShift(PhaseShift
, MapId
);
679 bool ChatHandler::HandleDebugAnimCommand(char* args
)
682 if (!ExtractUInt32(&args
, emote_id
))
685 m_session
->GetPlayer()->HandleEmoteCommand(emote_id
);
689 bool ChatHandler::HandleDebugSetAuraStateCommand(char* args
)
692 if (!ExtractInt32(&args
, state
))
695 Unit
* unit
= getSelectedUnit();
698 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
699 SetSentErrorMessage(true);
706 for (int i
= 1; i
<= 32; ++i
)
707 unit
->ModifyAuraState(AuraState(i
), false);
711 unit
->ModifyAuraState(AuraState(abs(state
)), state
> 0);
715 bool ChatHandler::HandleSetValueHelper(Object
* target
, uint32 field
, char* typeStr
, char* valStr
)
717 ObjectGuid guid
= target
->GetObjectGuid();
719 // not allow access to nonexistent or critical for work field
720 if (field
>= target
->GetValuesCount() || field
<= OBJECT_FIELD_ENTRY
)
722 PSendSysMessage(LANG_TOO_BIG_INDEX
, field
, guid
.GetString().c_str(), target
->GetValuesCount());
726 uint32 base
; // 0 -> float
729 else if (strncmp(typeStr
, "int", strlen(typeStr
)) == 0)
731 else if (strncmp(typeStr
, "hex", strlen(typeStr
)) == 0)
733 else if (strncmp(typeStr
, "bit", strlen(typeStr
)) == 0)
735 else if (strncmp(typeStr
, "float", strlen(typeStr
)) == 0)
743 if (!ExtractUInt32Base(&valStr
, iValue
, base
))
746 DEBUG_LOG(GetMangosString(LANG_SET_UINT
), guid
.GetString().c_str(), field
, iValue
);
747 target
->SetUInt32Value(field
, iValue
);
748 PSendSysMessage(LANG_SET_UINT_FIELD
, guid
.GetString().c_str(), field
, iValue
);
753 if (!ExtractFloat(&valStr
, fValue
))
756 DEBUG_LOG(GetMangosString(LANG_SET_FLOAT
), guid
.GetString().c_str(), field
, fValue
);
757 target
->SetFloatValue(field
, fValue
);
758 PSendSysMessage(LANG_SET_FLOAT_FIELD
, guid
.GetString().c_str(), field
, fValue
);
764 bool ChatHandler::HandleDebugSetItemValueCommand(char* args
)
767 if (!ExtractUInt32(&args
, guid
))
771 if (!ExtractUInt32(&args
, field
))
774 char* typeStr
= ExtractOptNotLastArg(&args
);
778 char* valStr
= ExtractLiteralArg(&args
);
782 Item
* item
= m_session
->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM
, guid
));
786 return HandleSetValueHelper(item
, field
, typeStr
, valStr
);
789 bool ChatHandler::HandleDebugSetValueCommand(char* args
)
791 Unit
* target
= getSelectedUnit();
794 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
795 SetSentErrorMessage(true);
800 if (!ExtractUInt32(&args
, field
))
803 char* typeStr
= ExtractOptNotLastArg(&args
);
807 char* valStr
= ExtractLiteralArg(&args
);
811 return HandleSetValueHelper(target
, field
, typeStr
, valStr
);
814 bool ChatHandler::HandleGetValueHelper(Object
* target
, uint32 field
, char* typeStr
)
816 ObjectGuid guid
= target
->GetObjectGuid();
818 if (field
>= target
->GetValuesCount())
820 PSendSysMessage(LANG_TOO_BIG_INDEX
, field
, guid
.GetString().c_str(), target
->GetValuesCount());
824 uint32 base
; // 0 -> float
827 else if (strncmp(typeStr
, "int", strlen(typeStr
)) == 0)
829 else if (strncmp(typeStr
, "hex", strlen(typeStr
)) == 0)
831 else if (strncmp(typeStr
, "bit", strlen(typeStr
)) == 0)
833 else if (strncmp(typeStr
, "float", strlen(typeStr
)) == 0)
840 uint32 iValue
= target
->GetUInt32Value(field
);
846 // starting 0 if need as required bitstring format
848 res
.reserve(1 + 32 + 1);
849 res
= iValue
& (1 << (32 - 1)) ? "0" : " ";
850 for (int i
= 32; i
> 0; --i
)
851 res
+= iValue
& (1 << (i
- 1)) ? "1" : "0";
852 DEBUG_LOG(GetMangosString(LANG_GET_BITSTR
), guid
.GetString().c_str(), field
, res
.c_str());
853 PSendSysMessage(LANG_GET_BITSTR_FIELD
, guid
.GetString().c_str(), field
, res
.c_str());
857 DEBUG_LOG(GetMangosString(LANG_GET_HEX
), guid
.GetString().c_str(), field
, iValue
);
858 PSendSysMessage(LANG_GET_HEX_FIELD
, guid
.GetString().c_str(), field
, iValue
);
862 DEBUG_LOG(GetMangosString(LANG_GET_UINT
), guid
.GetString().c_str(), field
, iValue
);
863 PSendSysMessage(LANG_GET_UINT_FIELD
, guid
.GetString().c_str(), field
, iValue
);
868 float fValue
= target
->GetFloatValue(field
);
869 DEBUG_LOG(GetMangosString(LANG_GET_FLOAT
), guid
.GetString().c_str(), field
, fValue
);
870 PSendSysMessage(LANG_GET_FLOAT_FIELD
, guid
.GetString().c_str(), field
, fValue
);
876 bool ChatHandler::HandleDebugGetItemValueCommand(char* args
)
879 if (!ExtractUInt32(&args
, guid
))
883 if (!ExtractUInt32(&args
, field
))
886 char* typeStr
= ExtractLiteralArg(&args
);
887 if (!typeStr
&& *args
) // optional arg but check format fail case
890 Item
* item
= m_session
->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM
, guid
));
894 return HandleGetValueHelper(item
, field
, typeStr
);
897 bool ChatHandler::HandleDebugGetValueCommand(char* args
)
899 Unit
* target
= getSelectedUnit();
902 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
903 SetSentErrorMessage(true);
908 if (!ExtractUInt32(&args
, field
))
911 char* typeStr
= ExtractLiteralArg(&args
);
912 if (!typeStr
&& *args
) // optional arg but check format fail case
915 return HandleGetValueHelper(target
, field
, typeStr
);
918 bool ChatHandler::HandlerDebugModValueHelper(Object
* target
, uint32 field
, char* typeStr
, char* valStr
)
920 ObjectGuid guid
= target
->GetObjectGuid();
922 // not allow access to nonexistent or critical for work field
923 if (field
>= target
->GetValuesCount() || field
<= OBJECT_FIELD_ENTRY
)
925 PSendSysMessage(LANG_TOO_BIG_INDEX
, field
, guid
.GetString().c_str(), target
->GetValuesCount());
929 uint32 type
; // 0 -> float 1 -> int add 2-> bit or 3 -> bit and 4 -> bit and not
930 if (strncmp(typeStr
, "int", strlen(typeStr
)) == 0)
932 else if (strncmp(typeStr
, "float", strlen(typeStr
)) == 0)
934 else if (strncmp(typeStr
, "|=", strlen("|=") + 1) == 0) // exactly copy
936 else if (strncmp(typeStr
, "&=", strlen("&=") + 1) == 0) // exactly copy
938 else if (strncmp(typeStr
, "&=~", strlen("&=~") + 1) == 0) // exactly copy
946 if (!ExtractUInt32Base(&valStr
, iValue
, type
== 1 ? 10 : 16))
949 uint32 value
= target
->GetUInt32Value(field
);
955 value
= uint32(int32(value
) + int32(iValue
));
956 DEBUG_LOG(GetMangosString(LANG_CHANGE_INT32
), guid
.GetString().c_str(), field
, iValue
, value
, value
);
957 PSendSysMessage(LANG_CHANGE_INT32_FIELD
, guid
.GetString().c_str(), field
, iValue
, value
, value
);
961 DEBUG_LOG(GetMangosString(LANG_CHANGE_HEX
), guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
962 PSendSysMessage(LANG_CHANGE_HEX_FIELD
, guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
964 case 3: // &= bit and
966 DEBUG_LOG(GetMangosString(LANG_CHANGE_HEX
), guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
967 PSendSysMessage(LANG_CHANGE_HEX_FIELD
, guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
969 case 4: // &=~ bit and not
971 DEBUG_LOG(GetMangosString(LANG_CHANGE_HEX
), guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
972 PSendSysMessage(LANG_CHANGE_HEX_FIELD
, guid
.GetString().c_str(), field
, typeStr
, iValue
, value
);
976 target
->SetUInt32Value(field
, value
);
981 if (!ExtractFloat(&valStr
, fValue
))
984 float value
= target
->GetFloatValue(field
);
988 DEBUG_LOG(GetMangosString(LANG_CHANGE_FLOAT
), guid
.GetString().c_str(), field
, fValue
, value
);
989 PSendSysMessage(LANG_CHANGE_FLOAT_FIELD
, guid
.GetString().c_str(), field
, fValue
, value
);
991 target
->SetFloatValue(field
, value
);
997 bool ChatHandler::HandleDebugModItemValueCommand(char* args
)
1000 if (!ExtractUInt32(&args
, guid
))
1004 if (!ExtractUInt32(&args
, field
))
1007 char* typeStr
= ExtractLiteralArg(&args
);
1011 char* valStr
= ExtractLiteralArg(&args
);
1015 Item
* item
= m_session
->GetPlayer()->GetItemByGuid(ObjectGuid(HIGHGUID_ITEM
, guid
));
1019 return HandlerDebugModValueHelper(item
, field
, typeStr
, valStr
);
1022 bool ChatHandler::HandleDebugModValueCommand(char* args
)
1024 Unit
* target
= getSelectedUnit();
1027 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
1028 SetSentErrorMessage(true);
1033 if (!ExtractUInt32(&args
, field
))
1036 char* typeStr
= ExtractLiteralArg(&args
);
1037 if (!typeStr
&& *args
) // optional arg but check format fail case
1040 char* valStr
= ExtractLiteralArg(&args
);
1044 return HandlerDebugModValueHelper(target
, field
, typeStr
, valStr
);
1047 bool ChatHandler::HandleDebugSpellCoefsCommand(char* args
)
1049 uint32 spellid
= ExtractSpellIdFromLink(&args
);
1053 SpellEntry
const* spellEntry
= sSpellStore
.LookupEntry(spellid
);
1057 SpellBonusEntry
const* bonus
= sSpellMgr
.GetSpellBonusData(spellid
);
1059 float direct_calc
= CalculateDefaultCoefficient(spellEntry
, SPELL_DIRECT_DAMAGE
);
1060 float dot_calc
= CalculateDefaultCoefficient(spellEntry
, DOT
);
1062 bool isDirectHeal
= false;
1063 for (int i
= 0; i
< 3; ++i
)
1065 SpellEffectEntry
const* spellEffect
= spellEntry
->GetSpellEffect(SpellEffectIndex(i
));
1068 // Heals (Also count Mana Shield and Absorb effects as heals)
1069 if (spellEffect
->Effect
== SPELL_EFFECT_HEAL
|| spellEffect
->Effect
== SPELL_EFFECT_HEAL_MAX_HEALTH
||
1070 (spellEffect
->Effect
== SPELL_EFFECT_APPLY_AURA
&& (spellEffect
->EffectApplyAuraName
== SPELL_AURA_SCHOOL_ABSORB
|| spellEffect
->EffectApplyAuraName
== SPELL_AURA_PERIODIC_HEAL
)))
1072 isDirectHeal
= true;
1077 bool isDotHeal
= false;
1078 for (int i
= 0; i
< 3; ++i
)
1080 SpellEffectEntry
const* spellEffect
= spellEntry
->GetSpellEffect(SpellEffectIndex(i
));
1084 if (spellEffect
->Effect
== SPELL_EFFECT_APPLY_AURA
&& spellEffect
->EffectApplyAuraName
== SPELL_AURA_PERIODIC_HEAL
)
1091 char const* directHealStr
= GetMangosString(LANG_DIRECT_HEAL
);
1092 char const* directDamageStr
= GetMangosString(LANG_DIRECT_DAMAGE
);
1093 char const* dotHealStr
= GetMangosString(LANG_DOT_HEAL
);
1094 char const* dotDamageStr
= GetMangosString(LANG_DOT_DAMAGE
);
1096 PSendSysMessage(LANG_SPELLCOEFS
, spellid
, isDirectHeal
? directHealStr
: directDamageStr
,
1097 direct_calc
, direct_calc
* 1.88f
, bonus
? bonus
->direct_damage
: 0.0f
, bonus
? bonus
->ap_bonus
: 0.0f
);
1098 PSendSysMessage(LANG_SPELLCOEFS
, spellid
, isDotHeal
? dotHealStr
: dotDamageStr
,
1099 dot_calc
, dot_calc
* 1.88f
, bonus
? bonus
->dot_damage
: 0.0f
, bonus
? bonus
->ap_dot_bonus
: 0.0f
);
1104 bool ChatHandler::HandleDebugSpellModsCommand(char* args
)
1106 char* typeStr
= ExtractLiteralArg(&args
);
1111 if (strncmp(typeStr
, "flat", strlen(typeStr
)) == 0)
1112 opcode
= SMSG_SET_FLAT_SPELL_MODIFIER
;
1113 else if (strncmp(typeStr
, "pct", strlen(typeStr
)) == 0)
1114 opcode
= SMSG_SET_PCT_SPELL_MODIFIER
;
1119 if (!ExtractUInt32(&args
, effidx
) || effidx
>= 64 + 32)
1123 if (!ExtractUInt32(&args
, spellmodop
) || spellmodop
>= MAX_SPELLMOD
)
1127 if (!ExtractInt32(&args
, value
))
1130 Player
* chr
= getSelectedPlayer();
1133 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1134 SetSentErrorMessage(true);
1138 // check online security
1139 if (HasLowerSecurity(chr
))
1142 PSendSysMessage(LANG_YOU_CHANGE_SPELLMODS
, opcode
== SMSG_SET_FLAT_SPELL_MODIFIER
? "flat" : "pct",
1143 spellmodop
, value
, effidx
, GetNameLink(chr
).c_str());
1144 if (needReportToTarget(chr
))
1145 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_SPELLMODS_CHANGED
, GetNameLink().c_str(),
1146 opcode
== SMSG_SET_FLAT_SPELL_MODIFIER
? "flat" : "pct", spellmodop
, value
, effidx
);
1148 WorldPacket
data(opcode
, (1 + 1 + 2 + 2));
1151 data
<< uint8(spellmodop
);
1152 data
<< uint8(effidx
);
1153 data
<< int32(value
);
1154 chr
->GetSession()->SendPacket(&data
);