TrinityCore
Loading...
Searching...
No Matches
cs_npc.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/* ScriptData
19Name: npc_commandscript
20%Complete: 100
21Comment: All npc related commands
22Category: commandscripts
23EndScriptData */
24
25#include "ScriptMgr.h"
26#include "Chat.h"
27#include "CreatureAI.h"
28#include "CreatureGroups.h"
29#include "DatabaseEnv.h"
31#include "GameTime.h"
32#include "Language.h"
33#include "Log.h"
34#include "Map.h"
35#include "MotionMaster.h"
36#include "MovementDefines.h"
37#include "ObjectAccessor.h"
38#include "ObjectMgr.h"
39#include "Pet.h"
40#include "Player.h"
41#include "RBAC.h"
42#include "SmartEnum.h"
43#include "Transport.h"
44#include "World.h"
45#include "WorldSession.h"
46
47using namespace Trinity::ChatCommands;
48
51
52// shared with cs_gobject.cpp, definitions are at the bottom of this file
53bool HandleNpcSpawnGroup(ChatHandler* handler, std::vector<Variant<uint32, EXACT_SEQUENCE("force"), EXACT_SEQUENCE("ignorerespawn")>> const& opts);
54bool HandleNpcDespawnGroup(ChatHandler* handler, std::vector<Variant<uint32, EXACT_SEQUENCE("removerespawntime")>> const& opts);
55
57{
58public:
59 npc_commandscript() : CommandScript("npc_commandscript") { }
60
62 {
63 static ChatCommandTable npcAddCommandTable =
64 {
69// { "weapon", HandleNpcAddWeaponCommand, rbac::RBAC_PERM_COMMAND_NPC_ADD_WEAPON, Console::No },
71 };
72 static ChatCommandTable npcSetCommandTable =
73 {
86 };
87 static ChatCommandTable npcCommandTable =
88 {
89 { "add", npcAddCommandTable },
90 { "set", npcSetCommandTable },
100 { "spawngroup", HandleNpcSpawnGroup, rbac::RBAC_PERM_COMMAND_NPC_SPAWNGROUP, Console::No },
101 { "despawngroup", HandleNpcDespawnGroup, rbac::RBAC_PERM_COMMAND_NPC_DESPAWNGROUP, Console::No },
105 { "follow stop", HandleNpcUnFollowCommand, rbac::RBAC_PERM_COMMAND_NPC_FOLLOW, Console::No },
108 };
109 static ChatCommandTable commandTable =
110 {
111 { "npc", npcCommandTable },
112 };
113 return commandTable;
114 }
115
116 //add spawn of creature
118 {
119 if (!sObjectMgr->GetCreatureTemplate(id))
120 return false;
121
122 Player* chr = handler->GetSession()->GetPlayer();
123 Map* map = chr->GetMap();
124
125 if (Transport* trans = chr->GetTransport())
126 {
127 ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
128 CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
129 data.spawnId = guid;
130 data.spawnGroupData = sObjectMgr->GetDefaultSpawnGroup();
131 data.id = id;
132 data.phaseMask = chr->GetPhaseMaskForSpawn();
134 if (Creature* creature = trans->CreateNPCPassenger(guid, &data))
135 {
136 creature->SaveToDB(trans->GetGOInfo()->moTransport.mapID, 1 << map->GetSpawnMode(), chr->GetPhaseMaskForSpawn());
137 sObjectMgr->AddCreatureToGrid(guid, &data);
138 }
139 return true;
140 }
141
142 Creature* creature = new Creature();
143 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, chr->GetPhaseMaskForSpawn(), id, *chr))
144 {
145 delete creature;
146 return false;
147 }
148
149 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
150
151 ObjectGuid::LowType db_guid = creature->GetSpawnId();
152
153 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
154 // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
155 creature->CleanupsBeforeDelete();
156 delete creature;
157 creature = new Creature();
158 if (!creature->LoadFromDB(db_guid, map, true, true))
159 {
160 delete creature;
161 return false;
162 }
163
164 sObjectMgr->AddCreatureToGrid(db_guid, sObjectMgr->GetCreatureData(db_guid));
165 return true;
166 }
167
168 //add item in vendorlist
170 {
171 if (!item)
172 {
174 handler->SetSentErrorMessage(true);
175 return false;
176 }
177
178 Creature* vendor = handler->getSelectedCreature();
179 if (!vendor)
180 {
182 handler->SetSentErrorMessage(true);
183 return false;
184 }
185
186 uint32 itemId = item->ItemId;
187 uint32 maxcount = mc.value_or(0);
188 uint32 incrtime = it.value_or(0);
189 uint32 extendedcost = ec.value_or(0);
190 uint32 vendor_entry = vendor->GetEntry();
191
192 if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
193 {
194 handler->SetSentErrorMessage(true);
195 return false;
196 }
197
198 sObjectMgr->AddVendorItem(vendor_entry, itemId, maxcount, incrtime, extendedcost);
199
200 handler->PSendSysMessage(LANG_ITEM_ADDED_TO_LIST, itemId, item->Name1.c_str(), maxcount, incrtime, extendedcost);
201 return true;
202 }
203
204 //add move for creature
206 {
207 // attempt check creature existence by DB data
208 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
209 if (!data)
210 {
212 handler->SetSentErrorMessage(true);
213 return false;
214 }
215
216 // Update movement type
218
220 stmt->setUInt32(1, lowGuid);
221
222 WorldDatabase.Execute(stmt);
223
225
226 return true;
227 }
228
230 {
231 if (sWorld->getAllowMovement())
232 {
233 sWorld->SetAllowMovement(false);
235 }
236 else
237 {
238 sWorld->SetAllowMovement(true);
240 }
241 return true;
242 }
243
244 static bool HandleNpcSetEntryCommand(ChatHandler* handler, CreatureEntry newEntryNum)
245 {
246 if (!newEntryNum)
247 return false;
248
249 Unit* unit = handler->getSelectedUnit();
250 if (!unit || unit->GetTypeId() != TYPEID_UNIT)
251 {
253 handler->SetSentErrorMessage(true);
254 return false;
255 }
256 Creature* creature = unit->ToCreature();
257 if (creature->UpdateEntry(newEntryNum))
258 handler->SendSysMessage(LANG_DONE);
259 else
260 handler->SendSysMessage(LANG_ERROR);
261 return true;
262 }
263
264 //change level of creature or pet
265 static bool HandleNpcSetLevelCommand(ChatHandler* handler, uint8 lvl)
266 {
267 if (lvl < 1 || lvl > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL) + 3)
268 {
270 handler->SetSentErrorMessage(true);
271 return false;
272 }
273
274 Creature* creature = handler->getSelectedCreature();
275 if (!creature || creature->IsPet())
276 {
278 handler->SetSentErrorMessage(true);
279 return false;
280 }
281
282 creature->SetMaxHealth(100 + 30*lvl);
283 creature->SetHealth(100 + 30*lvl);
284 creature->SetLevel(lvl);
285 creature->SaveToDB();
286
287 return true;
288 }
289
291 {
292 ObjectGuid::LowType spawnId;
293 if (spawnIdArg)
294 spawnId = *spawnIdArg;
295 else
296 {
297 Creature* creature = handler->getSelectedCreature();
298 if (!creature || creature->IsPet() || creature->IsTotem())
299 {
301 handler->SetSentErrorMessage(true);
302 return false;
303 }
304 if (TempSummon* summon = creature->ToTempSummon())
305 {
306 summon->UnSummon();
308 return true;
309 }
310 spawnId = creature->GetSpawnId();
311 }
312
313 if (Creature::DeleteFromDB(spawnId))
314 {
316 return true;
317 }
318 else
319 {
321 handler->SetSentErrorMessage(true);
322 return false;
323 }
324 }
325
326 //del item from vendor list
328 {
329 Creature* vendor = handler->getSelectedCreature();
330 if (!vendor || !vendor->IsVendor())
331 {
333 handler->SetSentErrorMessage(true);
334 return false;
335 }
336
337 if (!item)
338 {
340 handler->SetSentErrorMessage(true);
341 return false;
342 }
343
344 uint32 itemId = item->ItemId;
345 if (!sObjectMgr->RemoveVendorItem(vendor->GetEntry(), itemId))
346 {
347 handler->PSendSysMessage(LANG_ITEM_NOT_IN_LIST, itemId);
348 handler->SetSentErrorMessage(true);
349 return false;
350 }
351
352 handler->PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST, itemId, item->Name1.c_str());
353 return true;
354 }
355
356 //set faction of creature
357 static bool HandleNpcSetFactionIdCommand(ChatHandler* handler, uint32 factionId)
358 {
359 if (!sFactionTemplateStore.LookupEntry(factionId))
360 {
361 handler->PSendSysMessage(LANG_WRONG_FACTION, factionId);
362 handler->SetSentErrorMessage(true);
363 return false;
364 }
365
366 Creature* creature = handler->getSelectedCreature();
367
368 if (!creature)
369 {
371 handler->SetSentErrorMessage(true);
372 return false;
373 }
374
375 creature->SetFaction(factionId);
376
377 // Faction is set in creature_template - not inside creature
378
379 // Update in memory..
380 if (CreatureTemplate const* cinfo = creature->GetCreatureTemplate())
381 const_cast<CreatureTemplate*>(cinfo)->faction = factionId;
382
383 // ..and DB
385
386 stmt->setUInt16(0, uint16(factionId));
387 stmt->setUInt32(1, creature->GetEntry());
388
389 WorldDatabase.Execute(stmt);
390
391 return true;
392 }
393
394 //set npcflag of creature
395 static bool HandleNpcSetFlagCommand(ChatHandler* handler, NPCFlags npcFlags)
396 {
397 Creature* creature = handler->getSelectedCreature();
398
399 if (!creature)
400 {
402 handler->SetSentErrorMessage(true);
403 return false;
404 }
405
406 creature->ReplaceAllNpcFlags(npcFlags);
407
409
410 stmt->setUInt32(0, npcFlags);
411 stmt->setUInt32(1, creature->GetEntry());
412
413 WorldDatabase.Execute(stmt);
414
416
417 return true;
418 }
419
420 //set data of creature for testing scripting
421 static bool HandleNpcSetDataCommand(ChatHandler* handler, uint32 data_1, uint32 data_2)
422 {
423 Creature* creature = handler->getSelectedCreature();
424
425 if (!creature)
426 {
428 handler->SetSentErrorMessage(true);
429 return false;
430 }
431
432 creature->AI()->SetData(data_1, data_2);
433 std::string AIorScript = !creature->GetAIName().empty() ? "AI type: " + creature->GetAIName() : (!creature->GetScriptName().empty() ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set");
434 handler->PSendSysMessage(LANG_NPC_SETDATA, creature->GetGUID().ToString().c_str(), creature->GetName().c_str(), data_1, data_2, AIorScript.c_str());
435 return true;
436 }
437
438 //npc follow handling
440 {
441 Player* player = handler->GetSession()->GetPlayer();
442 Creature* creature = handler->getSelectedCreature();
443
444 if (!creature)
445 {
447 handler->SetSentErrorMessage(true);
448 return false;
449 }
450
451 // Follow player - Using pet's default dist and angle
452 creature->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, creature->GetFollowAngle());
453
454 handler->PSendSysMessage(LANG_CREATURE_FOLLOW_YOU_NOW, creature->GetName().c_str());
455 return true;
456 }
457
458 static bool HandleNpcInfoCommand(ChatHandler* handler)
459 {
460 Creature* target = handler->getSelectedCreature();
461
462 if (!target)
463 {
465 handler->SetSentErrorMessage(true);
466 return false;
467 }
468
469 CreatureTemplate const* cInfo = target->GetCreatureTemplate();
470
471 uint32 faction = target->GetFaction();
472 uint32 npcflags = target->GetNpcFlags();
473 uint32 mechanicImmuneMask = cInfo->MechanicImmuneMask;
474 uint32 displayid = target->GetDisplayId();
475 uint32 nativeid = target->GetNativeDisplayId();
476 uint32 entry = target->GetEntry();
477
479
480 if (curRespawnDelay < 0)
481 curRespawnDelay = 0;
482 std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), TimeFormat::ShortText);
483 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), TimeFormat::ShortText);
484
485 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetName().c_str(), target->GetSpawnId(), target->GetGUID().ToString().c_str(), entry, faction, npcflags, displayid, nativeid);
486 if (target->GetCreatureData() && target->GetCreatureData()->spawnGroupData->groupId)
487 {
488 SpawnGroupTemplateData const* const groupData = target->GetCreatureData()->spawnGroupData;
489 handler->PSendSysMessage(LANG_SPAWNINFO_GROUP_ID, groupData->name.c_str(), groupData->groupId, groupData->flags, target->GetMap()->IsSpawnGroupActive(groupData->groupId));
490 }
492 handler->PSendSysMessage(LANG_NPCINFO_LEVEL, target->GetLevel());
494 handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
496
498 for (UnitFlags flag : EnumUtils::Iterate<UnitFlags>())
499 if (target->HasUnitFlag(flag))
500 handler->PSendSysMessage("* %s (0x%X)", EnumUtils::ToTitle(flag), flag);
501
502 handler->PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUnitFlags2(), target->GetDynamicFlags(), target->GetFaction());
503 handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
504 handler->PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid, cInfo->pickpocketLootId, cInfo->SkinLootId);
507 handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor());
508 handler->PSendSysMessage(LANG_NPCINFO_POSITION, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ());
509 handler->PSendSysMessage(LANG_OBJECTINFO_AIINFO, target->GetAIName().c_str(), target->GetScriptName().c_str());
513 if (CreatureAI const* ai = target->AI())
516 for (CreatureFlagsExtra flag : EnumUtils::Iterate<CreatureFlagsExtra>())
517 if (cInfo->flags_extra & flag)
518 handler->PSendSysMessage("* %s (0x%X)", EnumUtils::ToTitle(flag), flag);
519
520 for (NPCFlags flag : EnumUtils::Iterate<NPCFlags>())
521 if (npcflags & flag)
522 handler->PSendSysMessage("* %s (0x%X)", EnumUtils::ToTitle(flag), flag);
523
524 handler->PSendSysMessage(LANG_NPCINFO_MECHANIC_IMMUNE, mechanicImmuneMask);
525 for (Mechanics m : EnumUtils::Iterate<Mechanics>())
526 if (m && (mechanicImmuneMask & (1 << (m-1))))
527 handler->PSendSysMessage("* %s (0x%X)", EnumUtils::ToTitle(m), m);
528
529 return true;
530 }
531
533 {
534 float distance = dist.value_or(10.0f);
535 uint32 count = 0;
536
537 Player* player = handler->GetSession()->GetPlayer();
538
540 stmt->setFloat(0, player->GetPositionX());
541 stmt->setFloat(1, player->GetPositionY());
542 stmt->setFloat(2, player->GetPositionZ());
543 stmt->setUInt32(3, player->GetMapId());
544 stmt->setFloat(4, player->GetPositionX());
545 stmt->setFloat(5, player->GetPositionY());
546 stmt->setFloat(6, player->GetPositionZ());
547 stmt->setFloat(7, distance * distance);
548 PreparedQueryResult result = WorldDatabase.Query(stmt);
549
550 if (result)
551 {
552 do
553 {
554 Field* fields = result->Fetch();
555 ObjectGuid::LowType guid = fields[0].GetUInt32();
556 uint32 entry = fields[1].GetUInt32();
557 float x = fields[2].GetFloat();
558 float y = fields[3].GetFloat();
559 float z = fields[4].GetFloat();
560 uint16 mapId = fields[5].GetUInt16();
561
562 CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
563 if (!creatureTemplate)
564 continue;
565
566 handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, creatureTemplate->Name.c_str(), x, y, z, mapId, "", "");
567
568 ++count;
569 }
570 while (result->NextRow());
571 }
572
573 handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
574
575 return true;
576 }
577
578 //move selected creature
580 {
581 Creature* creature = handler->getSelectedCreature();
582 Player const* player = handler->GetSession()->GetPlayer();
583 if (!player)
584 return false;
585
586 if (!spawnid && !creature)
587 return false;
588
589 ObjectGuid::LowType lowguid = spawnid ? *spawnid : creature->GetSpawnId();
590 // Attempting creature load from DB data
591 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
592 if (!data)
593 {
595 handler->SetSentErrorMessage(true);
596 return false;
597 }
598
599 if (player->GetMapId() != data->mapId)
600 {
602 handler->SetSentErrorMessage(true);
603 return false;
604 }
605
606 // update position in memory
607 sObjectMgr->RemoveCreatureFromGrid(lowguid, data);
608 const_cast<CreatureData*>(data)->spawnPoint.Relocate(*player);
609 sObjectMgr->AddCreatureToGrid(lowguid, data);
610
611 // update position in DB
613 stmt->setFloat(0, player->GetPositionX());
614 stmt->setFloat(1, player->GetPositionY());
615 stmt->setFloat(2, player->GetPositionZ());
616 stmt->setFloat(3, player->GetOrientation());
617 stmt->setUInt32(4, lowguid);
618 WorldDatabase.Execute(stmt);
619
620 // respawn selected creature at the new location
621 if (creature)
622 creature->DespawnOrUnsummon(0s, 1s);
623
625 return true;
626 }
627
628 //play npc emote
629 static bool HandleNpcPlayEmoteCommand(ChatHandler* handler, Emote emote)
630 {
631 Creature* target = handler->getSelectedCreature();
632 if (!target)
633 {
635 handler->SetSentErrorMessage(true);
636 return false;
637 }
638
639 target->SetEmoteState(emote);
640
641 return true;
642 }
643
644 //set model of creature
645 static bool HandleNpcSetModelCommand(ChatHandler* handler, uint32 displayId)
646 {
647 Creature* creature = handler->getSelectedCreature();
648
649 if (!creature || creature->IsPet())
650 {
652 handler->SetSentErrorMessage(true);
653 return false;
654 }
655
656 if (!sCreatureDisplayInfoStore.LookupEntry(displayId))
657 {
659 handler->SetSentErrorMessage(true);
660 return false;
661 }
662
663 creature->SetDisplayId(displayId);
664 creature->SetNativeDisplayId(displayId);
665
666 creature->SaveToDB();
667
668 return true;
669 }
670
684 {
685 // 3 arguments:
686 // GUID (optional - you can also select the creature)
687 // stay|random|way (determines the kind of movement)
688 // NODEL (optional - tells the system NOT to delete any waypoints)
689 // this is very handy if you want to do waypoints, that are
690 // later switched on/off according to special events (like escort
691 // quests, etc)
692
693 bool doNotDelete = nodel.has_value();
694
695 ObjectGuid::LowType lowguid = 0;
696 Creature* creature = nullptr;
697
698 if (!lowGuid) // case .setmovetype $move_type (with selected creature)
699 {
700 creature = handler->getSelectedCreature();
701 if (!creature || creature->IsPet())
702 return false;
703 lowguid = creature->GetSpawnId();
704 }
705 else // case .setmovetype #creature_guid $move_type (with selected creature)
706 {
707 lowguid = *lowGuid;
708
709 if (lowguid)
710 creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
711
712 // attempt check creature existence by DB data
713 if (!creature)
714 {
715 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
716 if (!data)
717 {
719 handler->SetSentErrorMessage(true);
720 return false;
721 }
722 }
723 else
724 {
725 lowguid = creature->GetSpawnId();
726 }
727 }
728
729 // now lowguid is low guid really existed creature
730 // and creature point (maybe) to this creature or nullptr
731
732 MovementGeneratorType move_type;
733 switch (type.index())
734 {
735 case 0:
736 move_type = IDLE_MOTION_TYPE;
737 break;
738 case 1:
739 move_type = RANDOM_MOTION_TYPE;
740 break;
741 case 2:
742 move_type = WAYPOINT_MOTION_TYPE;
743 break;
744 default:
745 return false;
746 }
747
748 // update movement type
749 //if (doNotDelete == false)
750 // WaypointMgr.DeletePath(lowguid);
751
752 if (creature)
753 {
754 // update movement type
755 if (doNotDelete == false)
756 creature->LoadPath(0);
757
758 creature->SetDefaultMovementType(move_type);
759 creature->GetMotionMaster()->Initialize();
760 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
761 {
762 creature->setDeathState(JUST_DIED);
763 creature->Respawn();
764 }
765 creature->SaveToDB();
766 }
767 if (doNotDelete == false)
768 {
770 }
771 else
772 {
774 }
775
776 return true;
777 }
778
779 //npc phasemask handling
780 //change phasemask of creature or pet
781 static bool HandleNpcSetPhaseCommand(ChatHandler* handler, uint32 phasemask)
782 {
783 if (phasemask == 0)
784 {
786 handler->SetSentErrorMessage(true);
787 return false;
788 }
789
790 Creature* creature = handler->getSelectedCreature();
791 if (!creature)
792 {
794 handler->SetSentErrorMessage(true);
795 return false;
796 }
797
798 creature->SetPhaseMask(phasemask, true);
799
800 if (!creature->IsPet())
801 creature->SaveToDB();
802
803 return true;
804 }
805
806 //set spawn dist of creature
807 static bool HandleNpcSetWanderDistanceCommand(ChatHandler* handler, float option)
808 {
809 if (option < 0.0f)
810 {
812 return false;
813 }
814
816 if (option > 0.0f)
817 mtype = RANDOM_MOTION_TYPE;
818
819 Creature* creature = handler->getSelectedCreature();
820 ObjectGuid::LowType guidLow = 0;
821
822 if (creature)
823 guidLow = creature->GetSpawnId();
824 else
825 return false;
826
827 creature->SetWanderDistance((float)option);
828 creature->SetDefaultMovementType(mtype);
829 creature->GetMotionMaster()->Initialize();
830 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
831 {
832 creature->setDeathState(JUST_DIED);
833 creature->Respawn();
834 }
835
837
838 stmt->setFloat(0, option);
839 stmt->setUInt8(1, uint8(mtype));
840 stmt->setUInt32(2, guidLow);
841
842 WorldDatabase.Execute(stmt);
843
845 return true;
846 }
847
848 //spawn time handling
849 static bool HandleNpcSetSpawnTimeCommand(ChatHandler* handler, uint32 spawnTime)
850 {
851 Creature* creature = handler->getSelectedCreature();
852 if (!creature)
853 return false;
854
856 stmt->setUInt32(0, spawnTime);
857 stmt->setUInt32(1, creature->GetSpawnId());
858 WorldDatabase.Execute(stmt);
859
860 creature->SetRespawnDelay(spawnTime);
861 handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, spawnTime);
862
863 return true;
864 }
865
866 static bool HandleNpcSayCommand(ChatHandler* handler, Tail text)
867 {
868 if (text.empty())
869 return false;
870
871 Creature* creature = handler->getSelectedCreature();
872 if (!creature)
873 {
875 handler->SetSentErrorMessage(true);
876 return false;
877 }
878
879 creature->Say(text, LANG_UNIVERSAL);
880
881 // make some emotes
882 switch (text.back())
883 {
884 case '?': creature->HandleEmoteCommand(EMOTE_ONESHOT_QUESTION); break;
885 case '!': creature->HandleEmoteCommand(EMOTE_ONESHOT_EXCLAMATION); break;
886 default: creature->HandleEmoteCommand(EMOTE_ONESHOT_TALK); break;
887 }
888
889 return true;
890 }
891
892 //show text emote by creature in chat
893 static bool HandleNpcTextEmoteCommand(ChatHandler* handler, Tail text)
894 {
895 if (text.empty())
896 return false;
897
898 Creature* creature = handler->getSelectedCreature();
899
900 if (!creature)
901 {
903 handler->SetSentErrorMessage(true);
904 return false;
905 }
906
907 creature->TextEmote(text);
908
909 return true;
910 }
911
912 // npc unfollow handling
914 {
915 Player* player = handler->GetSession()->GetPlayer();
916 Creature* creature = handler->getSelectedCreature();
917
918 if (!creature)
919 {
921 handler->SetSentErrorMessage(true);
922 return false;
923 }
924
925 MovementGenerator* movement = creature->GetMotionMaster()->GetMovementGenerator([player](MovementGenerator const* a) -> bool
926 {
928 {
929 FollowMovementGenerator const* followMovement = dynamic_cast<FollowMovementGenerator const*>(a);
930 return followMovement && followMovement->GetTarget() == player;
931 }
932 return false;
933 });
934
935 if (!movement)
936 {
937 handler->PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
938 handler->SetSentErrorMessage(true);
939 return false;
940 }
941
942 creature->GetMotionMaster()->Remove(movement);
943 handler->PSendSysMessage(LANG_CREATURE_NOT_FOLLOW_YOU_NOW, creature->GetName().c_str());
944 return true;
945 }
946
947 // make npc whisper to player
948 static bool HandleNpcWhisperCommand(ChatHandler* handler, Variant<Hyperlink<player>, std::string_view> recv, Tail text)
949 {
950 if (text.empty())
951 return false;
952
953 Creature* creature = handler->getSelectedCreature();
954 if (!creature)
955 {
957 handler->SetSentErrorMessage(true);
958 return false;
959 }
960
961 // check online security
963 if (handler->HasLowerSecurity(receiver, ObjectGuid::Empty))
964 return false;
965
966 creature->Whisper(text, LANG_UNIVERSAL, receiver);
967 return true;
968 }
969
970 static bool HandleNpcYellCommand(ChatHandler* handler, Tail text)
971 {
972 if (text.empty())
973 return false;
974
975 Creature* creature = handler->getSelectedCreature();
976 if (!creature)
977 {
979 handler->SetSentErrorMessage(true);
980 return false;
981 }
982
983 creature->Yell(text, LANG_UNIVERSAL);
984
985 // make an emote
987
988 return true;
989 }
990
991 // add creature, temp only
993 {
994 bool loot = false;
995 if (lootStr)
996 {
997 if (StringEqualI(*lootStr, "loot"))
998 loot = true;
999 else if (StringEqualI(*lootStr, "noloot"))
1000 loot = false;
1001 else
1002 return false;
1003 }
1004
1005 Player* chr = handler->GetSession()->GetPlayer();
1006 if (!sObjectMgr->GetCreatureTemplate(id))
1007 return false;
1008
1010
1011 return true;
1012 }
1013
1014 //npc tame handling
1015 static bool HandleNpcTameCommand(ChatHandler* handler)
1016 {
1017 Creature* creatureTarget = handler->getSelectedCreature();
1018 if (!creatureTarget || creatureTarget->IsPet())
1019 {
1021 handler->SetSentErrorMessage (true);
1022 return false;
1023 }
1024
1025 Player* player = handler->GetSession()->GetPlayer();
1026
1027 if (!player->GetPetGUID().IsEmpty())
1028 {
1030 handler->SetSentErrorMessage (true);
1031 return false;
1032 }
1033
1034 CreatureTemplate const* cInfo = creatureTarget->GetCreatureTemplate();
1035
1036 if (!cInfo->IsTameable (player->CanTameExoticPets()))
1037 {
1039 handler->SetSentErrorMessage (true);
1040 return false;
1041 }
1042
1043 // Everything looks OK, create new pet
1044 Pet* pet = player->CreateTamedPetFrom(creatureTarget);
1045 if (!pet)
1046 {
1048 handler->SetSentErrorMessage (true);
1049 return false;
1050 }
1051
1052 // place pet before player
1053 float x, y, z;
1054 player->GetClosePoint (x, y, z, creatureTarget->GetCombatReach(), CONTACT_DISTANCE);
1055 pet->Relocate(x, y, z, float(M_PI) - player->GetOrientation());
1056
1057 // set pet to defensive mode by default (some classes can't control controlled pets in fact).
1059
1060 // calculate proper level
1061 uint8 level = std::max<uint8>(player->GetLevel()-5, creatureTarget->GetLevel());
1062
1063 // prepare visual effect for levelup
1064 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
1065
1066 // add to world
1067 pet->GetMap()->AddToMap(pet->ToCreature());
1068
1069 // visual effect for levelup
1070 pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
1071
1072 // caster have pet now
1073 player->SetMinion(pet, true);
1074
1076 player->PetSpellInitialize();
1077
1078 return true;
1079 }
1080
1082 {
1083 Creature* creatureTarget = handler->getSelectedCreature();
1084 if (!creatureTarget || creatureTarget->IsPet())
1085 {
1087 handler->SetSentErrorMessage(true);
1088 return false;
1089 }
1090
1091 if (!creatureTarget->IsAIEnabled())
1092 {
1094 handler->SetSentErrorMessage(true);
1095 return false;
1096 }
1097
1098 if (force)
1099 creatureTarget->ClearUnitState(UNIT_STATE_EVADE);
1100 creatureTarget->AI()->EnterEvadeMode(why.value_or(CreatureAI::EVADE_REASON_OTHER));
1101
1102 return true;
1103 }
1104
1105 static void _ShowLootEntry(ChatHandler* handler, uint32 itemId, uint8 itemCount, bool alternateString = false)
1106 {
1107 ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
1108 ItemLocale const* itemLocale = sObjectMgr->GetItemLocale(itemId);
1109 char const* name = nullptr;
1110 if (itemLocale)
1111 name = itemLocale->Name[handler->GetSessionDbcLocale()].c_str();
1112 if ((!name || !*name) && itemTemplate)
1113 name = itemTemplate->Name1.c_str();
1114 if (!name)
1115 name = "Unknown item";
1117 itemCount, ItemQualityColors[itemTemplate ? itemTemplate->Quality : uint32(ITEM_QUALITY_POOR)], itemId, name, itemId);
1118 }
1119 static void _IterateNotNormalLootMap(ChatHandler* handler, NotNormalLootItemMap const& map, std::vector<LootItem> const& items)
1120 {
1121 for (NotNormalLootItemMap::value_type const& pair : map)
1122 {
1123 if (!pair.second)
1124 continue;
1125 Player const* player = ObjectAccessor::FindConnectedPlayer(pair.first);
1126 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_SUBLABEL, player ? player->GetName() : Trinity::StringFormat("Offline player ({})", pair.first.ToString()), pair.second->size());
1127
1128 for (auto it = pair.second->cbegin(); it != pair.second->cend(); ++it)
1129 {
1130 LootItem const& item = items[it->index];
1131 if (!(it->is_looted) && !item.is_looted)
1132 _ShowLootEntry(handler, item.itemid, item.count, true);
1133 }
1134 }
1135 }
1137 {
1138 Creature* creatureTarget = handler->getSelectedCreature();
1139 if (!creatureTarget || creatureTarget->IsPet())
1140 {
1142 handler->SetSentErrorMessage(true);
1143 return false;
1144 }
1145
1146 Loot const& loot = creatureTarget->loot;
1147 if (!creatureTarget->isDead() || loot.empty())
1148 {
1149 handler->PSendSysMessage(LANG_COMMAND_NOT_DEAD_OR_NO_LOOT, creatureTarget->GetName());
1150 handler->SetSentErrorMessage(true);
1151 return false;
1152 }
1153
1154 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_HEADER, creatureTarget->GetName(), creatureTarget->GetEntry());
1156
1157 if (!all)
1158 {
1159 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot.items.size());
1160 for (LootItem const& item : loot.items)
1161 if (!item.is_looted)
1162 _ShowLootEntry(handler, item.itemid, item.count);
1163
1164 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Quest items", loot.quest_items.size());
1165 for (LootItem const& item : loot.quest_items)
1166 if (!item.is_looted)
1167 _ShowLootEntry(handler, item.itemid, item.count);
1168 }
1169 else
1170 {
1171 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL, "Standard items", loot.items.size());
1172 for (LootItem const& item : loot.items)
1173 if (!item.is_looted && !item.freeforall && item.conditions.empty())
1174 _ShowLootEntry(handler, item.itemid, item.count);
1175
1176 if (!loot.GetPlayerQuestItems().empty())
1177 {
1178 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, "Per-player quest items");
1180 }
1181
1182 if (!loot.GetPlayerFFAItems().empty())
1183 {
1184 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, "FFA items per allowed player");
1185 _IterateNotNormalLootMap(handler, loot.GetPlayerFFAItems(), loot.items);
1186 }
1187
1188 if (!loot.GetPlayerNonQuestNonFFAConditionalItems().empty())
1189 {
1190 handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_LABEL_2, "Per-player conditional items");
1192 }
1193 }
1194
1195 return true;
1196 }
1197
1199 {
1200 Creature* creature = handler->getSelectedCreature();
1201
1202 if (!creature || !creature->GetSpawnId())
1203 {
1205 handler->SetSentErrorMessage(true);
1206 return false;
1207 }
1208
1209 ObjectGuid::LowType lowguid = creature->GetSpawnId();
1210 if (creature->GetFormation())
1211 {
1212 handler->PSendSysMessage("Selected creature is already member of group %u", creature->GetFormation()->GetLeaderSpawnId());
1213 return false;
1214 }
1215
1216 if (!lowguid)
1217 return false;
1218
1219 Player* chr = handler->GetSession()->GetPlayer();
1220
1221 float followAngle = (creature->GetAbsoluteAngle(chr) - chr->GetOrientation()) * 180.0f / float(M_PI);
1222 float followDist = std::sqrt(std::pow(chr->GetPositionX() - creature->GetPositionX(), 2.f) + std::pow(chr->GetPositionY() - creature->GetPositionY(), 2.f));
1223 uint32 groupAI = 0;
1224 sFormationMgr->AddFormationMember(lowguid, followAngle, followDist, leaderGUID, groupAI);
1225 creature->SearchFormation();
1226
1228 stmt->setUInt32(0, leaderGUID);
1229 stmt->setUInt32(1, lowguid);
1230 stmt->setFloat (2, followAngle);
1231 stmt->setFloat (3, followDist);
1232 stmt->setUInt32(4, groupAI);
1233
1234 WorldDatabase.Execute(stmt);
1235
1236 handler->PSendSysMessage("Creature %u added to formation with leader %u", lowguid, leaderGUID);
1237
1238 return true;
1239 }
1240
1242 {
1243 Creature* creature = handler->getSelectedCreature();
1244
1245 if (!creature)
1246 {
1248 handler->SetSentErrorMessage(true);
1249 return false;
1250 }
1251
1252 if (!creature->GetSpawnId())
1253 {
1254 handler->PSendSysMessage("Selected creature %u isn't in creature table", creature->GetGUID().GetCounter());
1255 handler->SetSentErrorMessage(true);
1256 return false;
1257 }
1258
1259 if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetSpawnId(), linkguid))
1260 {
1261 handler->PSendSysMessage("Selected creature can't link with guid '%u'", linkguid);
1262 handler->SetSentErrorMessage(true);
1263 return false;
1264 }
1265
1266 handler->PSendSysMessage("LinkGUID '%u' added to creature with DBTableGUID: '%u'", linkguid, creature->GetSpawnId());
1267 return true;
1268 }
1269
1271 static bool HandleNpcAddWeaponCommand([[maybe_unused]] ChatHandler* handler, [[maybe_unused]] uint32 SlotID, [[maybe_unused]] ItemTemplate const* tmpItem)
1272 {
1273 /*
1274 if (!tmpItem)
1275 return;
1276
1277 uint64 guid = handler->GetSession()->GetPlayer()->GetSelection();
1278 if (guid == 0)
1279 {
1280 handler->SendSysMessage(LANG_NO_SELECTION);
1281 handler->SetSentErrorMessage(true);
1282 return false;
1283 }
1284
1285 Creature* creature = ObjectAccessor::GetCreature(*handler->GetSession()->GetPlayer(), guid);
1286
1287 if (!creature)
1288 {
1289 handler->SendSysMessage(LANG_SELECT_CREATURE);
1290 handler->SetSentErrorMessage(true);
1291 return false;
1292 }
1293
1294 switch (SlotID)
1295 {
1296 case 1:
1297 creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, tmpItem->ItemId);
1298 break;
1299 case 2:
1300 creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, tmpItem->ItemId);
1301 break;
1302 case 3:
1303 creature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, tmpItem->ItemId);
1304 break;
1305 default:
1306 handler->PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST, SlotID);
1307 handler->SetSentErrorMessage(true);
1308 return false;
1309 }
1310
1311 handler->PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT, tmpItem->ItemID, tmpItem->Name1, SlotID);
1312 */
1313 return true;
1314 }
1315};
1316
1318{
1319 new npc_commandscript();
1320}
1321
1322bool HandleNpcSpawnGroup(ChatHandler* handler, std::vector<Variant<uint32, EXACT_SEQUENCE("force"), EXACT_SEQUENCE("ignorerespawn")>> const& opts)
1323{
1324 if (opts.empty())
1325 return false;
1326
1327 bool ignoreRespawn = false;
1328 bool force = false;
1329 uint32 groupId = 0;
1330
1331 // Decode arguments
1332 for (auto const& variant : opts)
1333 {
1334 switch (variant.index())
1335 {
1336 case 0:
1337 groupId = variant.get<uint32>();
1338 break;
1339 case 1:
1340 force = true;
1341 break;
1342 case 2:
1343 ignoreRespawn = true;
1344 break;
1345 }
1346 }
1347
1348 Player* player = handler->GetSession()->GetPlayer();
1349
1350 std::vector <WorldObject*> creatureList;
1351 if (!player->GetMap()->SpawnGroupSpawn(groupId, ignoreRespawn, force, &creatureList))
1352 {
1353 handler->PSendSysMessage(LANG_SPAWNGROUP_BADGROUP, groupId);
1354 handler->SetSentErrorMessage(true);
1355 return false;
1356 }
1357
1358 handler->PSendSysMessage(LANG_SPAWNGROUP_SPAWNCOUNT, creatureList.size());
1359
1360 return true;
1361}
1362
1363bool HandleNpcDespawnGroup(ChatHandler* handler, std::vector<Variant<uint32, EXACT_SEQUENCE("removerespawntime")>> const& opts)
1364{
1365 if (opts.empty())
1366 return false;
1367
1368 bool deleteRespawnTimes = false;
1369 uint32 groupId = 0;
1370
1371 // Decode arguments
1372 for (auto const& variant : opts)
1373 {
1374 if (variant.holds_alternative<uint32>())
1375 groupId = variant.get<uint32>();
1376 else
1377 deleteRespawnTimes = true;
1378 }
1379
1380 Player* player = handler->GetSession()->GetPlayer();
1381
1382 size_t n = 0;
1383 if (!player->GetMap()->SpawnGroupDespawn(groupId, deleteRespawnTimes, &n))
1384 {
1385 handler->PSendSysMessage(LANG_SPAWNGROUP_BADGROUP, groupId);
1386 handler->SetSentErrorMessage(true);
1387 return false;
1388 }
1389 handler->PSendSysMessage("Despawned a total of %zu objects.", n);
1390
1391 return true;
1392}
#define EXACT_SEQUENCE(str)
#define M_PI
Definition Common.h:72
CreatureFlagsExtra
#define sFormationMgr
DBCStorage< CreatureDisplayInfoEntry > sCreatureDisplayInfoStore(CreatureDisplayInfofmt)
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
uint8_t uint8
Definition Define.h:135
#define STRING_VIEW_FMT_ARG(str)
Definition Define.h:126
int64_t int64
Definition Define.h:128
uint64_t uint64
Definition Define.h:132
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
@ LANG_NPCINFO_EQUIPMENT
Definition Language.h:1095
@ LANG_NPC_SETDATA
Definition Language.h:636
@ LANG_OBJECTINFO_STRINGIDS
Definition Language.h:1156
@ LANG_COMMAND_NPC_SHOWLOOT_ENTRY
Definition Language.h:342
@ LANG_OBJECTINFO_AIINFO
Definition Language.h:1090
@ LANG_SELECT_CREATURE
Definition Language.h:32
@ LANG_SPAWNGROUP_SPAWNCOUNT
Definition Language.h:1143
@ LANG_CREATURE_NON_TAMEABLE
Definition Language.h:398
@ LANG_CREATURE_NOT_FOLLOW_YOU
Definition Language.h:396
@ LANG_ERROR
Definition Language.h:78
@ LANG_CREATURE_FOLLOW_YOU_NOW
Definition Language.h:395
@ LANG_YOU_ALREADY_HAVE_PET
Definition Language.h:399
@ LANG_WAYPOINT_ADDED
Definition Language.h:281
@ LANG_NPCINFO_LOOT
Definition Language.h:621
@ LANG_OBJECTINFO_AITYPE
Definition Language.h:1150
@ LANG_CREATURE_NOT_AI_ENABLED
Definition Language.h:1240
@ LANG_CREATURE_MOVE_ENABLED
Definition Language.h:462
@ LANG_COMMAND_NOT_DEAD_OR_NO_LOOT
Definition Language.h:339
@ LANG_NPCINFO_POSITION
Definition Language.h:622
@ LANG_NPCINFO_FLAGS
Definition Language.h:620
@ LANG_NPCINFO_UNIT_FIELD_FLAGS
Definition Language.h:1097
@ LANG_VALUE_SAVED_REJOIN
Definition Language.h:311
@ LANG_COMMAND_CREATUREMOVED
Definition Language.h:322
@ LANG_MOVE_TYPE_SET
Definition Language.h:307
@ LANG_NPCINFO_REACTSTATE
Definition Language.h:1077
@ LANG_COMMAND_DELCREATMESSAGE
Definition Language.h:321
@ LANG_CREATURE_NOT_FOLLOW_YOU_NOW
Definition Language.h:397
@ LANG_WRONG_FACTION
Definition Language.h:165
@ LANG_COMMAND_CREATUREATSAMEMAP
Definition Language.h:323
@ LANG_COMMAND_NEAR_NPC_MESSAGE
Old ones now free:
Definition Language.h:639
@ LANG_COMMAND_NEEDITEMSEND
Definition Language.h:330
@ LANG_COMMAND_NPC_SHOWLOOT_ENTRY_2
Definition Language.h:346
@ LANG_NPCINFO_HEALTH
Definition Language.h:619
@ LANG_COMMAND_VENDORSELECTION
Definition Language.h:329
@ LANG_COMMAND_NPC_SHOWLOOT_SUBLABEL
Definition Language.h:345
@ LANG_CREATURE_MOVE_DISABLED
Definition Language.h:461
@ LANG_ITEM_ADDED_TO_LIST
Definition Language.h:250
@ LANG_NPCINFO_MOVEMENT_DATA
Definition Language.h:1232
@ LANG_COMMAND_SPAWNTIME
Definition Language.h:351
@ LANG_NPCINFO_CHAR
Definition Language.h:617
@ LANG_ITEM_DELETED_FROM_LIST
Definition Language.h:252
@ LANG_MOVE_TYPE_SET_NODEL
Definition Language.h:308
@ LANG_COMMAND_INVALID_PARAM
Definition Language.h:364
@ LANG_SPAWNINFO_GROUP_ID
Definition Language.h:1137
@ LANG_NPCINFO_PHASEMASK
Definition Language.h:1079
@ LANG_COMMAND_WANDER_DISTANCE
Definition Language.h:350
@ LANG_COMMAND_CREATGUIDNOTFOUND
Definition Language.h:338
@ LANG_BAD_VALUE
Definition Language.h:149
@ LANG_NPCINFO_LEVEL
Definition Language.h:618
@ LANG_ITEM_NOT_IN_LIST
Definition Language.h:253
@ LANG_NPCINFO_FLAGS_EXTRA
Definition Language.h:1233
@ LANG_DONE
Definition Language.h:75
@ LANG_CREATURE_LIST_CHAT
Definition Language.h:589
@ LANG_SPAWNINFO_COMPATIBILITY_MODE
Definition Language.h:1138
@ LANG_COMMAND_RAWPAWNTIMES
Definition Language.h:669
@ LANG_COMMAND_NPC_SHOWLOOT_LABEL
Definition Language.h:341
@ LANG_NPCINFO_ARMOR
Definition Language.h:1080
@ LANG_SPAWNGROUP_BADGROUP
Definition Language.h:1142
@ LANG_COMMAND_NPC_SHOWLOOT_LABEL_2
Definition Language.h:344
@ LANG_COMMAND_NPC_SHOWLOOT_HEADER
Definition Language.h:340
@ LANG_NPCINFO_DUNGEON_ID
Definition Language.h:625
@ LANG_NPCINFO_MECHANIC_IMMUNE
Definition Language.h:1096
@ LANG_COMMAND_NPC_SHOWLOOT_MONEY
Definition Language.h:343
std::unordered_map< ObjectGuid, NotNormalLootItemList * > NotNormalLootItemMap
Definition Loot.h:177
MovementGeneratorType
@ IDLE_MOTION_TYPE
@ WAYPOINT_MOTION_TYPE
@ FOLLOW_MOTION_TYPE
@ RANDOM_MOTION_TYPE
@ TEMPSUMMON_CORPSE_DESPAWN
@ TEMPSUMMON_CORPSE_TIMED_DESPAWN
#define CONTACT_DISTANCE
@ TYPEID_UNIT
Definition ObjectGuid.h:38
#define sObjectMgr
Definition ObjectMgr.h:1721
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
@ PET_SAVE_AS_CURRENT
Definition PetDefines.h:42
#define PET_FOLLOW_DIST
Definition PetDefines.h:85
Role Based Access Control related classes definition.
uint32 constexpr ItemQualityColors[MAX_ITEM_QUALITY]
@ LANG_UNIVERSAL
@ EMOTE_ONESHOT_EXCLAMATION
@ EMOTE_ONESHOT_QUESTION
@ EMOTE_ONESHOT_SHOUT
@ EMOTE_ONESHOT_TALK
@ ITEM_QUALITY_POOR
Mechanics
@ SILVER
@ GOLD
@ REACT_DEFENSIVE
NPCFlags
Non Player Character flags.
char const * DescribeReactState(ReactStates state)
UnitFlags
@ JUST_DIED
Definition Unit.h:212
@ UNIT_STATE_EVADE
Definition Unit.h:242
@ UNIT_FIELD_LEVEL
bool StringEqualI(std::string_view a, std::string_view b)
Definition Util.cpp:706
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
Definition Util.cpp:115
@ WORLD_UPD_CREATURE_POSITION
@ WORLD_UPD_CREATURE_NPCFLAG
@ WORLD_SEL_CREATURE_NEAREST
@ WORLD_INS_CREATURE_FORMATION
@ WORLD_UPD_CREATURE_MOVEMENT_TYPE
@ WORLD_UPD_CREATURE_SPAWN_TIME_SECS
@ WORLD_UPD_CREATURE_WANDER_DISTANCE
@ WORLD_UPD_CREATURE_FACTION
Unit * getSelectedUnit()
Definition Chat.cpp:314
WorldSession * GetSession()
Definition Chat.h:46
virtual LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:692
Creature * GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
Definition Chat.cpp:499
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition Chat.cpp:51
Creature * getSelectedCreature()
Definition Chat.cpp:338
void SetSentErrorMessage(bool val)
Definition Chat.h:134
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:69
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
@ EVADE_REASON_OTHER
Definition CreatureAI.h:98
virtual void EnterEvadeMode(EvadeReason why=EVADE_REASON_OTHER)
ObjectGuid::LowType GetLeaderSpawnId() const
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Creature.cpp:652
Loot loot
Definition Creature.h:209
int8 GetOriginalEquipmentId() const
Definition Creature.h:176
void Respawn(bool force=false)
bool LoadFromDB(ObjectGuid::LowType spawnId, Map *map, bool addToMap, bool allowDuplicate)
void setDeathState(DeathState s) override
void SetDisplayId(uint32 modelId) override
void SetReactState(ReactStates st)
Definition Creature.h:119
bool GetRespawnCompatibilityMode()
Definition Creature.h:331
void SetRespawnDelay(uint32 delay)
Definition Creature.h:262
void DespawnOrUnsummon(Milliseconds timeToDespawn=0s, Seconds forceRespawnTime=0s)
bool UpdateEntry(uint32 entry, CreatureData const *data=nullptr, bool updateLevel=true)
Definition Creature.cpp:540
CreatureData const * GetCreatureData() const
Definition Creature.h:187
ObjectGuid::LowType GetSpawnId() const
Definition Creature.h:83
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:186
uint32 GetRespawnDelay() const
Definition Creature.h:261
static bool DeleteFromDB(ObjectGuid::LowType spawnId)
CreatureGroup * GetFormation()
Definition Creature.h:313
std::string_view GetStringId(StringIdType type) const
Definition Creature.h:196
void SearchFormation()
Definition Creature.cpp:328
ReactStates GetReactState() const
Definition Creature.h:120
void SetWanderDistance(float dist)
Definition Creature.h:265
std::string GetScriptName() const
uint8 GetCurrentEquipmentId() const
Definition Creature.h:177
void SaveToDB()
CreatureMovementData const & GetMovementTemplate() const
time_t GetRespawnTimeEx() const
std::string const & GetAIName() const
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 entry, Position const &pos, CreatureData const *data=nullptr, uint32 vehId=0, bool dynamic=false)
CreatureAI * AI() const
Definition Creature.h:154
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition Creature.h:112
void LoadPath(uint32 pathid)
Definition Creature.h:304
static char const * ToTitle(Enum value)
Definition SmartEnum.h:123
Class used to access individual fields of database query result.
Definition Field.h:92
uint16 GetUInt16() const
Definition Field.cpp:45
float GetFloat() const
Definition Field.cpp:93
uint32 GetUInt32() const
Definition Field.cpp:61
Definition Map.h:281
bool SpawnGroupSpawn(uint32 groupId, bool ignoreRespawn=false, bool force=false, std::vector< WorldObject * > *spawnedObjects=nullptr)
Definition Map.cpp:3382
bool AddToMap(T *)
Definition Map.cpp:630
uint8 GetSpawnMode() const
Definition Map.h:388
ObjectGuid::LowType GenerateLowGuid()
Definition Map.h:587
time_t GetCreatureRespawnTime(ObjectGuid::LowType spawnId) const
Definition Map.h:554
bool IsSpawnGroupActive(uint32 groupId) const
Definition Map.cpp:3495
bool SpawnGroupDespawn(uint32 groupId, bool deleteRespawnTimes=false, size_t *count=nullptr)
Definition Map.cpp:3458
uint32 GetId() const
Definition Map.cpp:4216
void MoveFollow(Unit *target, float dist, ChaseAngle angle, MovementSlot slot=MOTION_SLOT_ACTIVE)
MovementGenerator * GetMovementGenerator(std::function< bool(MovementGenerator const *)> const &filter, MovementSlot slot=MOTION_SLOT_ACTIVE) const
void Remove(MovementGenerator *movement, MovementSlot slot=MOTION_SLOT_ACTIVE)
virtual MovementGeneratorType GetMovementGeneratorType() const =0
LowType GetCounter() const
Definition ObjectGuid.h:156
static ObjectGuid const Empty
Definition ObjectGuid.h:140
bool IsEmpty() const
Definition ObjectGuid.h:172
std::string ToString() const
uint32 LowType
Definition ObjectGuid.h:142
static Creature * ToCreature(Object *o)
Definition Object.h:186
TypeID GetTypeId() const
Definition Object.h:93
uint32 GetEntry() const
Definition Object.h:81
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
void SetUInt32Value(uint16 index, uint32 value)
Definition Object.cpp:585
Definition Pet.h:40
void SavePetToDB(PetSaveMode mode)
Definition Pet.cpp:437
bool CanTameExoticPets() const
Definition Player.h:1902
void PetSpellInitialize()
Definition Player.cpp:20596
uint32 GetPhaseMaskForSpawn() const
Definition Player.cpp:24769
void setUInt16(uint8 index, uint16 value)
void setUInt32(uint8 index, uint32 value)
void setFloat(uint8 index, float value)
void setUInt8(uint8 index, uint8 value)
virtual void SetData(uint32, uint32)
Definition UnitAI.h:156
Definition Unit.h:769
void ClearUnitState(uint32 f)
Definition Unit.h:877
void SetMinion(Minion *minion, bool apply)
Definition Unit.cpp:5910
virtual void Say(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:13834
NPCFlags GetNpcFlags() const
Definition Unit.h:1095
void SetFaction(uint32 faction) override
Definition Unit.h:974
virtual void Yell(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:13839
Pet * CreateTamedPetFrom(Creature *creatureTarget, uint32 spell_id=0)
Definition Unit.cpp:10856
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
bool IsPet() const
Definition Unit.h:884
bool HasUnitFlag(UnitFlags flags) const
Definition Unit.h:953
void CleanupsBeforeDelete(bool finalCleanup=true) override
Definition Unit.cpp:9679
uint32 GetMaxHealth() const
Definition Unit.h:914
bool IsAlive() const
Definition Unit.h:1234
float GetCombatReach() const override
Definition Unit.h:839
void SetHealth(uint32 val)
Definition Unit.cpp:9361
UnitFlags GetUnitFlags() const
Definition Unit.h:952
TempSummon * ToTempSummon()
Definition Unit.h:1794
void SetNativeDisplayId(uint32 displayId)
Definition Unit.h:1586
void SetEmoteState(Emote emote)
Definition Unit.h:967
uint32 GetDisplayId() const
Definition Unit.h:1582
bool IsAIEnabled() const
Definition Unit.h:798
uint32 GetNativeDisplayId() const
Definition Unit.h:1584
uint32 GetHealth() const
Definition Unit.h:913
uint32 GetFaction() const override
Definition Unit.h:973
virtual void TextEmote(std::string_view text, WorldObject const *target=nullptr, bool isBossEmote=false)
Definition Unit.cpp:13844
uint32 GetCreateHealth() const
Definition Unit.h:1450
uint32 GetArmor() const
Definition Unit.h:905
virtual float GetFollowAngle() const
Definition Unit.h:1782
void SetLevel(uint8 lvl, bool sendUpdate=true)
Definition Unit.cpp:9344
void HandleEmoteCommand(Emote emoteId)
Definition Unit.cpp:1568
void SetMaxHealth(uint32 val)
Definition Unit.cpp:9393
bool IsVendor() const
Definition Unit.h:1101
bool IsTotem() const
Definition Unit.h:886
void ReplaceAllNpcFlags(NPCFlags flags)
Definition Unit.h:1099
virtual void Whisper(std::string_view text, Language language, Player *target, bool isBossWhisper=false)
Definition Unit.cpp:13849
uint8 GetLevel() const
Definition Unit.h:889
UnitFlags2 GetUnitFlags2() const
Definition Unit.h:958
uint32 GetDynamicFlags() const override
Definition Unit.h:818
ObjectGuid GetPetGUID() const
Definition Unit.h:1247
bool isDead() const
Definition Unit.h:1236
uint32 GetMapId() const
Definition Position.h:193
uint32 GetPhaseMask() const
Definition Object.h:368
Map * GetMap() const
Definition Object.h:449
void GetClosePoint(float &x, float &y, float &z, float size, float distance2d=0, float relAngle=0) const
Definition Object.cpp:3244
float GetTransOffsetX() const
Definition Object.h:565
TempSummon * SummonCreature(uint32 entry, Position const &pos, TempSummonType despawnType=TEMPSUMMON_MANUAL_DESPAWN, Milliseconds despawnTime=0s, uint32 vehId=0, uint32 spellId=0, ObjectGuid privateObjectOwner=ObjectGuid::Empty)
Definition Object.cpp:1992
uint32 GetInstanceId() const
Definition Object.h:365
float GetTransOffsetY() const
Definition Object.h:566
std::string const & GetName() const
Definition Object.h:382
float GetTransOffsetZ() const
Definition Object.h:567
Transport * GetTransport() const
Definition Object.h:564
float GetTransOffsetO() const
Definition Object.h:568
Player * GetPlayer() const
static bool HandleNpcAddFormationCommand(ChatHandler *handler, ObjectGuid::LowType leaderGUID)
Definition cs_npc.cpp:1198
static bool HandleNpcSetWanderDistanceCommand(ChatHandler *handler, float option)
Definition cs_npc.cpp:807
static bool HandleNpcAddCommand(ChatHandler *handler, CreatureEntry id)
Definition cs_npc.cpp:117
static bool HandleNpcTameCommand(ChatHandler *handler)
Definition cs_npc.cpp:1015
static bool HandleNpcTextEmoteCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:893
static bool HandleNpcAddVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< uint32 > mc, Optional< uint32 > it, Optional< uint32 > ec)
Definition cs_npc.cpp:169
static void _IterateNotNormalLootMap(ChatHandler *handler, NotNormalLootItemMap const &map, std::vector< LootItem > const &items)
Definition cs_npc.cpp:1119
static bool HandleNpcDeleteCommand(ChatHandler *handler, Optional< CreatureSpawnId > spawnIdArg)
Definition cs_npc.cpp:290
static bool HandleNpcSetModelCommand(ChatHandler *handler, uint32 displayId)
Definition cs_npc.cpp:645
static bool HandleNpcYellCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:970
static bool HandleNpcSetPhaseCommand(ChatHandler *handler, uint32 phasemask)
Definition cs_npc.cpp:781
static bool HandleNpcFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:439
static bool HandleNpcSetSpawnTimeCommand(ChatHandler *handler, uint32 spawnTime)
Definition cs_npc.cpp:849
static bool HandleNpcSetMoveTypeCommand(ChatHandler *handler, Optional< CreatureSpawnId > lowGuid, Variant< EXACT_SEQUENCE("stay"), EXACT_SEQUENCE("random"), EXACT_SEQUENCE("way")> type, Optional< EXACT_SEQUENCE("nodel")> nodel)
Definition cs_npc.cpp:683
static bool HandleNpcUnFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:913
static bool HandleNpcSetLevelCommand(ChatHandler *handler, uint8 lvl)
Definition cs_npc.cpp:265
static bool HandleNpcSetAllowMovementCommand(ChatHandler *handler)
Definition cs_npc.cpp:229
static bool HandleNpcShowLootCommand(ChatHandler *handler, Optional< EXACT_SEQUENCE("all")> all)
Definition cs_npc.cpp:1136
static bool HandleNpcSayCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:866
static bool HandleNpcInfoCommand(ChatHandler *handler)
Definition cs_npc.cpp:458
static bool HandleNpcAddWeaponCommand(ChatHandler *handler, uint32 SlotID, ItemTemplate const *tmpItem)
Definition cs_npc.cpp:1271
static bool HandleNpcNearCommand(ChatHandler *handler, Optional< float > dist)
Definition cs_npc.cpp:532
static bool HandleNpcDeleteVendorItemCommand(ChatHandler *handler, ItemTemplate const *item)
Definition cs_npc.cpp:327
static bool HandleNpcSetDataCommand(ChatHandler *handler, uint32 data_1, uint32 data_2)
Definition cs_npc.cpp:421
static void _ShowLootEntry(ChatHandler *handler, uint32 itemId, uint8 itemCount, bool alternateString=false)
Definition cs_npc.cpp:1105
static bool HandleNpcPlayEmoteCommand(ChatHandler *handler, Emote emote)
Definition cs_npc.cpp:629
static bool HandleNpcSetFlagCommand(ChatHandler *handler, NPCFlags npcFlags)
Definition cs_npc.cpp:395
static bool HandleNpcEvadeCommand(ChatHandler *handler, Optional< CreatureAI::EvadeReason > why, Optional< EXACT_SEQUENCE("force")> force)
Definition cs_npc.cpp:1081
static bool HandleNpcSetLinkCommand(ChatHandler *handler, ObjectGuid::LowType linkguid)
Definition cs_npc.cpp:1241
static bool HandleNpcWhisperCommand(ChatHandler *handler, Variant< Hyperlink< player >, std::string_view > recv, Tail text)
Definition cs_npc.cpp:948
ChatCommandTable GetCommands() const override
Definition cs_npc.cpp:61
static bool HandleNpcMoveCommand(ChatHandler *handler, Optional< CreatureSpawnId > spawnid)
Definition cs_npc.cpp:579
static bool HandleNpcSetFactionIdCommand(ChatHandler *handler, uint32 factionId)
Definition cs_npc.cpp:357
static bool HandleNpcSetEntryCommand(ChatHandler *handler, CreatureEntry newEntryNum)
Definition cs_npc.cpp:244
static bool HandleNpcAddMoveCommand(ChatHandler *handler, CreatureSpawnId lowGuid)
Definition cs_npc.cpp:205
static bool HandleNpcAddTempSpawnCommand(ChatHandler *handler, Optional< std::string_view > lootStr, CreatureEntry id)
Definition cs_npc.cpp:992
bool HandleNpcSpawnGroup(ChatHandler *handler, std::vector< Variant< uint32, EXACT_SEQUENCE("force"), EXACT_SEQUENCE("ignorerespawn")> > const &opts)
Definition cs_npc.cpp:1322
void AddSC_npc_commandscript()
Definition cs_npc.cpp:1317
bool HandleNpcDespawnGroup(ChatHandler *handler, std::vector< Variant< uint32, EXACT_SEQUENCE("removerespawntime")> > const &opts)
Definition cs_npc.cpp:1363
#define sWorld
Definition World.h:900
@ CONFIG_MAX_PLAYER_LEVEL
Definition World.h:236
time_t GetGameTime()
Definition GameTime.cpp:42
TC_GAME_API Player * FindPlayerByName(std::string_view name)
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
std::string ToString(Type &&val, Params &&... params)
std::string GetTypeName()
Definition Util.h:577
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
@ RBAC_PERM_COMMAND_NPC_SET_LEVEL
Definition RBAC.h:455
@ RBAC_PERM_COMMAND_NPC_PLAYEMOTE
Definition RBAC.h:466
@ RBAC_PERM_COMMAND_NPC_FOLLOW
Definition RBAC.h:448
@ RBAC_PERM_COMMAND_NPC_EVADE
Definition RBAC.h:706
@ RBAC_PERM_COMMAND_NPC_INFO
Definition RBAC.h:463
@ RBAC_PERM_COMMAND_NPC_TEXTEMOTE
Definition RBAC.h:468
@ RBAC_PERM_COMMAND_NPC_ADD_FORMATION
Definition RBAC.h:442
@ RBAC_PERM_COMMAND_NPC_ADD
Definition RBAC.h:441
@ RBAC_PERM_COMMAND_NPC_NEAR
Definition RBAC.h:464
@ RBAC_PERM_COMMAND_NPC_SET_SPAWNDIST
Definition RBAC.h:460
@ RBAC_PERM_COMMAND_NPC_SET_PHASE
Definition RBAC.h:459
@ RBAC_PERM_COMMAND_NPC_DELETE
Definition RBAC.h:446
@ RBAC_PERM_COMMAND_NPC_SET_ENTRY
Definition RBAC.h:452
@ RBAC_PERM_COMMAND_NPC_DESPAWNGROUP
Definition RBAC.h:726
@ RBAC_PERM_COMMAND_NPC_TAME
Definition RBAC.h:471
@ RBAC_PERM_COMMAND_NPC_MOVE
Definition RBAC.h:465
@ RBAC_PERM_COMMAND_NPC_ADD_ITEM
Definition RBAC.h:443
@ RBAC_PERM_COMMAND_NPC_SET_SPAWNTIME
Definition RBAC.h:461
@ RBAC_PERM_COMMAND_NPC_SET_FACTIONID
Definition RBAC.h:453
@ RBAC_PERM_COMMAND_NPC_SET_MOVETYPE
Definition RBAC.h:458
@ RBAC_PERM_COMMAND_NPC_SPAWNGROUP
Definition RBAC.h:725
@ RBAC_PERM_COMMAND_NPC_SET_DATA
Definition RBAC.h:462
@ RBAC_PERM_COMMAND_NPC_SHOWLOOT
Definition RBAC.h:734
@ RBAC_PERM_COMMAND_NPC_SET_ALLOWMOVE
Definition RBAC.h:451
@ RBAC_PERM_COMMAND_NPC_SET_MODEL
Definition RBAC.h:457
@ RBAC_PERM_COMMAND_NPC_ADD_MOVE
Definition RBAC.h:444
@ RBAC_PERM_COMMAND_NPC_SET_LINK
Definition RBAC.h:456
@ RBAC_PERM_COMMAND_NPC_WHISPER
Definition RBAC.h:469
@ RBAC_PERM_COMMAND_NPC_SET_FLAG
Definition RBAC.h:454
@ RBAC_PERM_COMMAND_NPC_YELL
Definition RBAC.h:470
@ RBAC_PERM_COMMAND_NPC_SAY
Definition RBAC.h:467
@ RBAC_PERM_COMMAND_NPC_ADD_TEMP
Definition RBAC.h:445
@ RBAC_PERM_COMMAND_NPC_DELETE_ITEM
Definition RBAC.h:447
std::string ToString() const
Definition Creature.cpp:60
uint32 MechanicImmuneMask
std::string Name
bool IsTameable(bool canTameExotic) const
std::vector< std::string > Name
std::string Name1
uint32 itemid
Definition Loot.h:127
uint8 count
Definition Loot.h:134
bool is_looted
Definition Loot.h:135
Definition Loot.h:207
bool empty() const
Definition Loot.h:238
NotNormalLootItemMap const & GetPlayerQuestItems() const
Definition Loot.h:210
NotNormalLootItemMap const & GetPlayerNonQuestNonFFAConditionalItems() const
Definition Loot.h:212
uint32 gold
Definition Loot.h:216
std::vector< LootItem > items
Definition Loot.h:214
NotNormalLootItemMap const & GetPlayerFFAItems() const
Definition Loot.h:211
std::vector< LootItem > quest_items
Definition Loot.h:215
float GetPositionZ() const
Definition Position.h:81
float GetOrientation() const
Definition Position.h:82
float GetAbsoluteAngle(float x, float y) const
Definition Position.h:128
float GetPositionX() const
Definition Position.h:79
void GetPosition(float &x, float &y) const
Definition Position.h:84
float GetPositionY() const
Definition Position.h:80
void Relocate(float x, float y)
Definition Position.h:66
uint32 phaseMask
Definition SpawnData.h:98
uint32 id
Definition SpawnData.h:96
Position spawnPoint
Definition SpawnData.h:97
SpawnGroupFlags flags
Definition SpawnData.h:63
uint32 spawnId
Definition SpawnData.h:85
SpawnGroupTemplateData const * spawnGroupData
Definition SpawnData.h:88
uint32 mapId
Definition SpawnData.h:86