AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
npc_commandscript Class Reference
Inheritance diagram for npc_commandscript:
CommandScript ScriptObject

Public Member Functions

 npc_commandscript ()
 
ChatCommandTable GetCommands () const override
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleNpcAddCommand (ChatHandler *handler, CreatureEntry id)
 
static bool HandleNpcLoadCommand (ChatHandler *handler, CreatureSpawnId spawnId)
 
static bool HandleNpcAddVendorItemCommand (ChatHandler *handler, ItemTemplate const *item, Optional< uint32 > mc, Optional< uint32 > it, Optional< uint32 > ec, Optional< bool > addMulti)
 
static bool HandleNpcAddMoveCommand (ChatHandler *handler, CreatureSpawnId lowGuid)
 
static bool HandleNpcSetAllowMovementCommand (ChatHandler *handler)
 
static bool HandleNpcSetEntryCommand (ChatHandler *handler, CreatureEntry newEntryNum)
 
static bool HandleNpcSetLevelCommand (ChatHandler *handler, uint8 lvl)
 
static bool HandleNpcDeleteCommand (ChatHandler *handler, Optional< ObjectGuid::LowType > lowGuid)
 
static bool HandleNpcDeleteVendorItemCommand (ChatHandler *handler, ItemTemplate const *item, Optional< bool > addMulti)
 
static bool HandleNpcSetFactionIdCommand (ChatHandler *handler, uint32 factionId)
 
static bool HandleNpcSetFactionTempIdCommand (ChatHandler *handler, uint32 tempfaction)
 
static bool HandleNpcSetOriginalFaction (ChatHandler *handler)
 
static bool HandleNpcSetFlagCommand (ChatHandler *handler, uint32 npcFlags)
 
static bool HandleNpcSetDataCommand (ChatHandler *handler, uint32 data_1, uint32 data_2)
 
static bool HandleNpcFollowCommand (ChatHandler *handler)
 
static bool HandleNpcInfoCommand (ChatHandler *handler, Optional< CreatureSpawnId > spawnIdArg)
 
static bool HandleNpcInfoCommandShowCreature (ChatHandler *handler, Creature *target)
 
static bool HandleNpcInfoCommandShowFromDB (ChatHandler *handler, ObjectGuid::LowType lowGuid, CreatureData const *cData)
 
static bool HandleNpcGuidCommand (ChatHandler *handler)
 
static bool HandleNpcNearCommand (ChatHandler *handler, Optional< float > dist)
 
static bool HandleNpcMoveCommand (ChatHandler *handler, Optional< ObjectGuid::LowType > guid)
 
static bool HandleNpcPlayEmoteCommand (ChatHandler *handler, uint32 emote)
 
static bool HandleNpcSetModelCommand (ChatHandler *handler, uint32 displayId)
 
static bool HandleNpcSetMoveTypeCommand (ChatHandler *handler, Optional< CreatureSpawnId > lowGuid, Variant< EXACT_SEQUENCE("stay"), EXACT_SEQUENCE("random"), EXACT_SEQUENCE("way")> type, Optional< EXACT_SEQUENCE("nodel")> nodel)
 
static bool HandleNpcSetPhaseCommand (ChatHandler *handler, uint32 phasemask)
 
static bool HandleNpcSetWanderDistanceCommand (ChatHandler *handler, float option)
 
static bool HandleNpcSetSpawnTimeCommand (ChatHandler *handler, std::string spawnTimeStr)
 
static bool HandleNpcSayCommand (ChatHandler *handler, Tail text)
 
static bool HandleNpcTextEmoteCommand (ChatHandler *handler, Tail text)
 
static bool HandleNpcUnFollowCommand (ChatHandler *handler)
 
static bool HandleNpcWhisperCommand (ChatHandler *handler, std::string const &recv, Tail text)
 
static bool HandleNpcYellCommand (ChatHandler *handler, Tail text)
 
static bool HandleNpcAddTempSpawnCommand (ChatHandler *handler, CreatureEntry id)
 
static bool HandleNpcTameCommand (ChatHandler *handler)
 
static bool HandleNpcDoActionCommand (ChatHandler *handler, uint32 actionId)
 
static bool HandleNpcAddFormationCommand (ChatHandler *handler, ObjectGuid::LowType leaderGUID)
 
static bool HandleNpcSetLinkCommand (ChatHandler *handler, ObjectGuid::LowType linkguid)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ npc_commandscript()

npc_commandscript::npc_commandscript ( )
inline
140: CommandScript("npc_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable npc_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

143 {
144 static ChatCommandTable npcAddCommandTable =
145 {
146 { "formation", HandleNpcAddFormationCommand, SEC_ADMINISTRATOR, Console::No },
147 { "item", HandleNpcAddVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
148 { "move", HandleNpcAddMoveCommand, SEC_ADMINISTRATOR, Console::No },
149 { "temp", HandleNpcAddTempSpawnCommand, SEC_ADMINISTRATOR, Console::No },
150 { "", HandleNpcAddCommand, SEC_ADMINISTRATOR, Console::No }
151 };
152 static ChatCommandTable npcDeleteCommandTable =
153 {
154 { "item", HandleNpcDeleteVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
155 { "", HandleNpcDeleteCommand, SEC_ADMINISTRATOR, Console::No }
156 };
157 static ChatCommandTable npcFollowCommandTable =
158 {
159 { "stop", HandleNpcUnFollowCommand, SEC_GAMEMASTER, Console::No },
160 { "", HandleNpcFollowCommand, SEC_GAMEMASTER, Console::No }
161 };
162
163 static ChatCommandTable npcFactionCommandTable =
164 {
165 { "permanent", HandleNpcSetFactionIdCommand, SEC_ADMINISTRATOR, Console::No },
166 { "temp", HandleNpcSetFactionTempIdCommand, SEC_ADMINISTRATOR, Console::No },
167 { "original", HandleNpcSetOriginalFaction, SEC_ADMINISTRATOR, Console::No }
168 };
169
170 static ChatCommandTable npcSetCommandTable =
171 {
172 { "allowmove", HandleNpcSetAllowMovementCommand, SEC_ADMINISTRATOR, Console::No },
173 { "entry", HandleNpcSetEntryCommand, SEC_ADMINISTRATOR, Console::No },
174 { "faction", npcFactionCommandTable},
175 { "flag", HandleNpcSetFlagCommand, SEC_ADMINISTRATOR, Console::No },
176 { "level", HandleNpcSetLevelCommand, SEC_ADMINISTRATOR, Console::No },
177 { "link", HandleNpcSetLinkCommand, SEC_ADMINISTRATOR, Console::No },
178 { "model", HandleNpcSetModelCommand, SEC_ADMINISTRATOR, Console::No },
179 { "movetype", HandleNpcSetMoveTypeCommand, SEC_ADMINISTRATOR, Console::No },
180 { "phase", HandleNpcSetPhaseCommand, SEC_ADMINISTRATOR, Console::No },
181 { "wanderdistance", HandleNpcSetWanderDistanceCommand, SEC_ADMINISTRATOR, Console::No },
182 { "spawntime", HandleNpcSetSpawnTimeCommand, SEC_ADMINISTRATOR, Console::No },
183 { "data", HandleNpcSetDataCommand, SEC_ADMINISTRATOR, Console::No }
184 };
185 static ChatCommandTable npcCommandTable =
186 {
187 { "info", HandleNpcInfoCommand, SEC_GAMEMASTER, Console::No },
188 { "guid", HandleNpcGuidCommand, SEC_GAMEMASTER, Console::No },
189 { "near", HandleNpcNearCommand, SEC_GAMEMASTER, Console::No },
190 { "move", HandleNpcMoveCommand, SEC_GAMEMASTER, Console::No },
191 { "playemote", HandleNpcPlayEmoteCommand, SEC_GAMEMASTER, Console::No },
192 { "say", HandleNpcSayCommand, SEC_GAMEMASTER, Console::No },
193 { "textemote", HandleNpcTextEmoteCommand, SEC_GAMEMASTER, Console::No },
194 { "whisper", HandleNpcWhisperCommand, SEC_GAMEMASTER, Console::No },
195 { "yell", HandleNpcYellCommand, SEC_GAMEMASTER, Console::No },
196 { "tame", HandleNpcTameCommand, SEC_GAMEMASTER, Console::No },
197 { "do", HandleNpcDoActionCommand, SEC_GAMEMASTER, Console::No },
198 { "add", npcAddCommandTable },
199 { "delete", npcDeleteCommandTable },
200 { "follow", npcFollowCommandTable },
201 { "load", HandleNpcLoadCommand, SEC_ADMINISTRATOR, Console::Yes },
202 { "set", npcSetCommandTable }
203 };
204 static ChatCommandTable commandTable =
205 {
206 { "npc", npcCommandTable }
207 };
208 return commandTable;
209 }
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ SEC_GAMEMASTER
Definition Common.h:59
static bool HandleNpcWhisperCommand(ChatHandler *handler, std::string const &recv, Tail text)
Definition cs_npc.cpp:1264
static bool HandleNpcAddFormationCommand(ChatHandler *handler, ObjectGuid::LowType leaderGUID)
Definition cs_npc.cpp:1369
static bool HandleNpcAddTempSpawnCommand(ChatHandler *handler, CreatureEntry id)
Definition cs_npc.cpp:1306
static bool HandleNpcSetFactionTempIdCommand(ChatHandler *handler, uint32 tempfaction)
Definition cs_npc.cpp:523
static bool HandleNpcSetWanderDistanceCommand(ChatHandler *handler, float option)
Definition cs_npc.cpp:1101
static bool HandleNpcAddCommand(ChatHandler *handler, CreatureEntry id)
Definition cs_npc.cpp:212
static bool HandleNpcSetOriginalFaction(ChatHandler *handler)
Definition cs_npc.cpp:542
static bool HandleNpcTameCommand(ChatHandler *handler)
Definition cs_npc.cpp:1319
static bool HandleNpcTextEmoteCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1211
static bool HandleNpcSetModelCommand(ChatHandler *handler, uint32 displayId)
Definition cs_npc.cpp:942
static bool HandleNpcYellCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1285
static bool HandleNpcGuidCommand(ChatHandler *handler)
Definition cs_npc.cpp:743
static bool HandleNpcSetPhaseCommand(ChatHandler *handler, uint32 phasemask)
Definition cs_npc.cpp:1077
static bool HandleNpcFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:605
static bool HandleNpcInfoCommand(ChatHandler *handler, Optional< CreatureSpawnId > spawnIdArg)
Definition cs_npc.cpp:623
static bool HandleNpcMoveCommand(ChatHandler *handler, Optional< ObjectGuid::LowType > guid)
Definition cs_npc.cpp:858
static bool HandleNpcPlayEmoteCommand(ChatHandler *handler, uint32 emote)
Definition cs_npc.cpp:927
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:977
static bool HandleNpcUnFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:1230
static bool HandleNpcSetLevelCommand(ChatHandler *handler, uint8 lvl)
Definition cs_npc.cpp:412
static bool HandleNpcSetAllowMovementCommand(ChatHandler *handler)
Definition cs_npc.cpp:377
static bool HandleNpcDeleteCommand(ChatHandler *handler, Optional< ObjectGuid::LowType > lowGuid)
Definition cs_npc.cpp:435
static bool HandleNpcSayCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1185
static bool HandleNpcNearCommand(ChatHandler *handler, Optional< float > dist)
Definition cs_npc.cpp:773
static bool HandleNpcSetSpawnTimeCommand(ChatHandler *handler, std::string spawnTimeStr)
Definition cs_npc.cpp:1145
static bool HandleNpcSetDataCommand(ChatHandler *handler, uint32 data_1, uint32 data_2)
Definition cs_npc.cpp:588
static bool HandleNpcAddVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< uint32 > mc, Optional< uint32 > it, Optional< uint32 > ec, Optional< bool > addMulti)
Definition cs_npc.cpp:322
static bool HandleNpcDeleteVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< bool > addMulti)
Definition cs_npc.cpp:460
static bool HandleNpcSetFlagCommand(ChatHandler *handler, uint32 npcFlags)
Definition cs_npc.cpp:563
static bool HandleNpcSetLinkCommand(ChatHandler *handler, ObjectGuid::LowType linkguid)
Definition cs_npc.cpp:1413
static bool HandleNpcLoadCommand(ChatHandler *handler, CreatureSpawnId spawnId)
Definition cs_npc.cpp:270
static bool HandleNpcSetFactionIdCommand(ChatHandler *handler, uint32 factionId)
Definition cs_npc.cpp:487
static bool HandleNpcSetEntryCommand(ChatHandler *handler, CreatureEntry newEntryNum)
Definition cs_npc.cpp:392
static bool HandleNpcAddMoveCommand(ChatHandler *handler, CreatureSpawnId lowGuid)
Definition cs_npc.cpp:356
static bool HandleNpcDoActionCommand(ChatHandler *handler, uint32 actionId)
Definition cs_npc.cpp:1355
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46

References HandleNpcAddCommand(), HandleNpcAddFormationCommand(), HandleNpcAddMoveCommand(), HandleNpcAddTempSpawnCommand(), HandleNpcAddVendorItemCommand(), HandleNpcDeleteCommand(), HandleNpcDeleteVendorItemCommand(), HandleNpcDoActionCommand(), HandleNpcFollowCommand(), HandleNpcGuidCommand(), HandleNpcInfoCommand(), HandleNpcLoadCommand(), HandleNpcMoveCommand(), HandleNpcNearCommand(), HandleNpcPlayEmoteCommand(), HandleNpcSayCommand(), HandleNpcSetAllowMovementCommand(), HandleNpcSetDataCommand(), HandleNpcSetEntryCommand(), HandleNpcSetFactionIdCommand(), HandleNpcSetFactionTempIdCommand(), HandleNpcSetFlagCommand(), HandleNpcSetLevelCommand(), HandleNpcSetLinkCommand(), HandleNpcSetModelCommand(), HandleNpcSetMoveTypeCommand(), HandleNpcSetOriginalFaction(), HandleNpcSetPhaseCommand(), HandleNpcSetSpawnTimeCommand(), HandleNpcSetWanderDistanceCommand(), HandleNpcTameCommand(), HandleNpcTextEmoteCommand(), HandleNpcUnFollowCommand(), HandleNpcWhisperCommand(), HandleNpcYellCommand(), SEC_ADMINISTRATOR, and SEC_GAMEMASTER.

◆ HandleNpcAddCommand()

static bool npc_commandscript::HandleNpcAddCommand ( ChatHandler handler,
CreatureEntry  id 
)
inlinestatic
213 {
214 if (!sObjectMgr->GetCreatureTemplate(id))
215 return false;
216
217 Player* chr = handler->GetSession()->GetPlayer();
218 float x = chr->GetPositionX();
219 float y = chr->GetPositionY();
220 float z = chr->GetPositionZ();
221 float o = chr->GetOrientation();
222 Map* map = chr->GetMap();
223
224 if (Transport* tt = chr->GetTransport())
225 if (MotionTransport* trans = tt->ToMotionTransport())
226 {
227 ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
228 CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
229 data.id1 = id;
230 data.phaseMask = chr->GetPhaseMaskForSpawn();
231 data.posX = chr->GetTransOffsetX();
232 data.posY = chr->GetTransOffsetY();
233 data.posZ = chr->GetTransOffsetZ();
234 data.orientation = chr->GetTransOffsetO();
235
236 Creature* creature = trans->CreateNPCPassenger(guid, &data);
237
238 creature->SaveToDB(trans->GetGOInfo()->moTransport.mapID, 1 << map->GetSpawnMode(), chr->GetPhaseMaskForSpawn());
239
240 sObjectMgr->AddCreatureToGrid(guid, &data);
241 return true;
242 }
243
244 Creature* creature = new Creature();
245 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
246 {
247 delete creature;
248 return false;
249 }
250
251 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
252
253 ObjectGuid::LowType spawnId = creature->GetSpawnId();
254
255 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
256 // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
257 creature->CleanupsBeforeDelete();
258 delete creature;
259 creature = new Creature();
260 if (!creature->LoadCreatureFromDB(spawnId, map, true, true))
261 {
262 delete creature;
263 return false;
264 }
265
266 sObjectMgr->AddCreatureToGrid(spawnId, sObjectMgr->GetCreatureData(spawnId));
267 return true;
268 }
#define sObjectMgr
Definition ObjectMgr.h:1712
WorldSession * GetSession()
Definition Chat.h:242
Definition Creature.h:47
bool LoadCreatureFromDB(ObjectGuid::LowType guid, Map *map, bool addToMap=true, bool allowDuplicate=false)
Definition Creature.cpp:1627
ObjectGuid::LowType GetSpawnId() const
Definition Creature.h:69
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 vehId, float x, float y, float z, float ang, const CreatureData *data=nullptr)
Definition Creature.cpp:1099
void SaveToDB()
Definition Creature.cpp:1328
MotionTransport * ToMotionTransport()
Definition GameObject.h:327
Definition Map.h:164
uint8 GetSpawnMode() const
Definition Map.h:267
ObjectGuid::LowType GenerateLowGuid()
Definition Map.h:480
uint32 GetId() const
Definition Map.h:230
Definition Transport.h:51
uint32 LowType
Definition ObjectGuid.h:122
Definition Player.h:1084
uint32 GetPhaseMaskForSpawn() const
Definition Player.cpp:13792
Definition Transport.h:30
void CleanupsBeforeDelete(bool finalCleanup=true) override
Definition Unit.cpp:12575
Map * GetMap() const
Definition Object.h:625
float GetTransOffsetX() const
Definition Object.h:689
float GetTransOffsetY() const
Definition Object.h:690
float GetTransOffsetZ() const
Definition Object.h:691
Transport * GetTransport() const
Definition Object.h:688
float GetTransOffsetO() const
Definition Object.h:692
Player * GetPlayer() const
Definition WorldSession.h:444
Definition CreatureData.h:370
uint32 id1
Definition CreatureData.h:372
float GetPositionZ() const
Definition Position.h:123
float GetOrientation() const
Definition Position.h:124
float GetPositionX() const
Definition Position.h:121
float GetPositionY() const
Definition Position.h:122
float posX
Definition SpawnData.h:66
float posY
Definition SpawnData.h:67
uint32 phaseMask
Definition SpawnData.h:65
float orientation
Definition SpawnData.h:69
float posZ
Definition SpawnData.h:68

References Unit::CleanupsBeforeDelete(), Creature::Create(), Map::GenerateLowGuid(), Map::GetId(), WorldObject::GetMap(), Position::GetOrientation(), Player::GetPhaseMaskForSpawn(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), Creature::GetSpawnId(), Map::GetSpawnMode(), WorldObject::GetTransOffsetO(), WorldObject::GetTransOffsetX(), WorldObject::GetTransOffsetY(), WorldObject::GetTransOffsetZ(), WorldObject::GetTransport(), CreatureData::id1, Creature::LoadCreatureFromDB(), SpawnData::orientation, SpawnData::phaseMask, SpawnData::posX, SpawnData::posY, SpawnData::posZ, Creature::SaveToDB(), sObjectMgr, GameObject::ToMotionTransport(), and Unit.

Referenced by GetCommands().

◆ HandleNpcAddFormationCommand()

static bool npc_commandscript::HandleNpcAddFormationCommand ( ChatHandler handler,
ObjectGuid::LowType  leaderGUID 
)
inlinestatic
1370 {
1371 Creature* creature = handler->getSelectedCreature();
1372
1373 if (!creature || !creature->GetSpawnId())
1374 {
1376 return false;
1377 }
1378
1379 ObjectGuid::LowType lowguid = creature->GetSpawnId();
1380 if (creature->GetFormation())
1381 {
1382 handler->PSendSysMessage("Selected creature is already member of group {}", creature->GetFormation()->GetId());
1383 return false;
1384 }
1385
1386 if (!lowguid)
1387 return false;
1388
1389 Player* chr = handler->GetSession()->GetPlayer();
1390 FormationInfo group_member;
1391 group_member.follow_angle = (creature->GetAngle(chr) - chr->GetOrientation()) * 180 / M_PI;
1392 group_member.follow_dist = sqrtf(pow(chr->GetPositionX() - creature->GetPositionX(), int(2)) + pow(chr->GetPositionY() - creature->GetPositionY(), int(2)));
1393 group_member.leaderGUID = leaderGUID;
1394 group_member.groupAI = 0;
1395
1396 sFormationMgr->CreatureGroupMap[lowguid] = group_member;
1397 creature->SearchFormation();
1398
1400 stmt->SetData(0, leaderGUID);
1401 stmt->SetData(1, lowguid);
1402 stmt->SetData(2, group_member.follow_dist);
1403 stmt->SetData(3, group_member.follow_angle);
1404 stmt->SetData(4, uint32(group_member.groupAI));
1405
1406 WorldDatabase.Execute(stmt);
1407
1408 handler->PSendSysMessage("Creature {} added to formation with leader {}", lowguid, leaderGUID);
1409
1410 return true;
1411 }
#define sFormationMgr
Definition CreatureGroups.h:130
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition DatabaseEnv.cpp:20
std::uint32_t uint32
Definition Define.h:107
@ LANG_SELECT_CREATURE
Definition Language.h:32
@ WORLD_INS_CREATURE_FORMATION
Definition WorldDatabase.h:52
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:211
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:216
Creature * getSelectedCreature() const
Definition Chat.cpp:410
uint32 GetId() const
Definition CreatureGroups.h:100
CreatureGroup const * GetFormation() const
Definition Creature.h:362
void SearchFormation()
Definition Creature.cpp:371
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157
Definition CreatureGroups.h:52
float follow_dist
Definition CreatureGroups.h:64
float follow_angle
Definition CreatureGroups.h:65
ObjectGuid::LowType leaderGUID
Definition CreatureGroups.h:63
uint16 groupAI
Definition CreatureGroups.h:66
float GetAngle(const Position *pos) const
Definition Position.cpp:85

References FormationInfo::follow_angle, FormationInfo::follow_dist, Position::GetAngle(), Creature::GetFormation(), CreatureGroup::GetId(), Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Creature::GetSpawnId(), FormationInfo::groupAI, LANG_SELECT_CREATURE, FormationInfo::leaderGUID, ChatHandler::PSendSysMessage(), Creature::SearchFormation(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), sFormationMgr, WORLD_INS_CREATURE_FORMATION, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcAddMoveCommand()

static bool npc_commandscript::HandleNpcAddMoveCommand ( ChatHandler handler,
CreatureSpawnId  lowGuid 
)
inlinestatic
357 {
358 // attempt check creature existence by DB data
359 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
360 if (!data)
361 {
363 return false;
364 }
365
366 // Update movement type
369 stmt->SetData(1, uint32(lowGuid));
370 WorldDatabase.Execute(stmt);
371
373
374 return true;
375 }
std::uint8_t uint8
Definition Define.h:109
@ LANG_WAYPOINT_ADDED
Definition Language.h:280
@ LANG_COMMAND_CREATGUIDNOTFOUND
Definition Language.h:337
@ WAYPOINT_MOTION_TYPE
Definition MotionMaster.h:41
@ WORLD_UPD_CREATURE_MOVEMENT_TYPE
Definition WorldDatabase.h:46
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:160

References LANG_COMMAND_CREATGUIDNOTFOUND, LANG_WAYPOINT_ADDED, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), sObjectMgr, WAYPOINT_MOTION_TYPE, WORLD_UPD_CREATURE_MOVEMENT_TYPE, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcAddTempSpawnCommand()

static bool npc_commandscript::HandleNpcAddTempSpawnCommand ( ChatHandler handler,
CreatureEntry  id 
)
inlinestatic
1307 {
1308 Player* chr = handler->GetSession()->GetPlayer();
1309
1310 if (!id)
1311 return false;
1312
1313 chr->SummonCreature(id, *chr, TEMPSUMMON_CORPSE_DESPAWN, 120);
1314
1315 return true;
1316 }
@ TEMPSUMMON_CORPSE_DESPAWN
Definition Object.h:53
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0, uint32 vehId=0, SummonPropertiesEntry const *properties=nullptr, bool visibleBySummonerOnly=false) const
Definition Object.cpp:2394

References WorldSession::GetPlayer(), ChatHandler::GetSession(), WorldObject::SummonCreature(), and TEMPSUMMON_CORPSE_DESPAWN.

Referenced by GetCommands().

◆ HandleNpcAddVendorItemCommand()

static bool npc_commandscript::HandleNpcAddVendorItemCommand ( ChatHandler handler,
ItemTemplate const *  item,
Optional< uint32 mc,
Optional< uint32 it,
Optional< uint32 ec,
Optional< bool >  addMulti 
)
inlinestatic
323 {
324 if (!item)
325 {
327 return false;
328 }
329
330 Creature* vendor = handler->getSelectedCreature();
331 if (!vendor)
332 {
334 return false;
335 }
336
337 uint32 itemId = item->ItemId;
338 uint32 maxcount = mc.value_or(0);
339 uint32 incrtime = it.value_or(0);
340 uint32 extendedcost = ec.value_or(0);
341 uint32 vendor_entry = addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry();
342
343 if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
344 {
345 handler->SetSentErrorMessage(true);
346 return false;
347 }
348
349 sObjectMgr->AddVendorItem(vendor_entry, itemId, maxcount, incrtime, extendedcost);
350
351 handler->PSendSysMessage(LANG_ITEM_ADDED_TO_LIST, itemId, item->Name1, maxcount, incrtime, extendedcost);
352 return true;
353 }
@ LANG_COMMAND_NEEDITEMSEND
Definition Language.h:329
@ LANG_ITEM_ADDED_TO_LIST
Definition Language.h:249
void SetSentErrorMessage(bool val)
Definition Chat.h:238
uint32 GetEntry() const
Definition Object.h:117
uint32 GetCurrentVendor() const
Definition WorldSession.h:448

References WorldSession::GetCurrentVendor(), Object::GetEntry(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), ItemTemplate::ItemId, LANG_COMMAND_NEEDITEMSEND, LANG_ITEM_ADDED_TO_LIST, LANG_SELECT_CREATURE, ItemTemplate::Name1, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), ChatHandler::SetSentErrorMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandleNpcDeleteCommand()

static bool npc_commandscript::HandleNpcDeleteCommand ( ChatHandler handler,
Optional< ObjectGuid::LowType lowGuid 
)
inlinestatic
436 {
437 Creature* creature;
438 if (lowGuid.has_value())
439 creature = handler->GetCreatureFromPlayerMapByDbGuid(*lowGuid);
440 else
441 creature = handler->getSelectedCreature();
442
443 if (!creature || creature->IsPet() || creature->IsTotem())
444 {
446 return false;
447 }
448
449 // Delete the creature
450 creature->CombatStop();
451 creature->DeleteFromDB();
452 creature->AddObjectToRemoveList();
453
455
456 return true;
457 }
@ LANG_COMMAND_DELCREATMESSAGE
Definition Language.h:320
Creature * GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
Definition Chat.cpp:578
virtual void DeleteFromDB()
Definition Creature.cpp:1777
bool IsPet() const
Definition Unit.h:797
void CombatStop(bool includingCast=false, bool mutualPvP=true)
Definition Unit.cpp:7450
bool IsTotem() const
Definition Unit.h:799
void AddObjectToRemoveList()
Definition Object.cpp:2174

References WorldObject::AddObjectToRemoveList(), Unit::CombatStop(), Creature::DeleteFromDB(), ChatHandler::GetCreatureFromPlayerMapByDbGuid(), ChatHandler::getSelectedCreature(), Unit::IsPet(), Unit::IsTotem(), LANG_COMMAND_DELCREATMESSAGE, LANG_SELECT_CREATURE, ChatHandler::SendErrorMessage(), and ChatHandler::SendSysMessage().

Referenced by GetCommands().

◆ HandleNpcDeleteVendorItemCommand()

static bool npc_commandscript::HandleNpcDeleteVendorItemCommand ( ChatHandler handler,
ItemTemplate const *  item,
Optional< bool >  addMulti 
)
inlinestatic
461 {
462 Creature* vendor = handler->getSelectedCreature();
463 if (!vendor || !vendor->IsVendor())
464 {
466 return false;
467 }
468
469 if (!item)
470 {
472 return false;
473 }
474
475 uint32 itemId = item->ItemId;
476 if (!sObjectMgr->RemoveVendorItem(addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry(), itemId))
477 {
478 handler->SendErrorMessage(LANG_ITEM_NOT_IN_LIST, itemId);
479 return false;
480 }
481
482 handler->PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST, itemId, item->Name1);
483 return true;
484 }
@ LANG_COMMAND_VENDORSELECTION
Definition Language.h:328
@ LANG_ITEM_DELETED_FROM_LIST
Definition Language.h:251
@ LANG_ITEM_NOT_IN_LIST
Definition Language.h:252
bool IsVendor() const
Definition Unit.h:803

References WorldSession::GetCurrentVendor(), Object::GetEntry(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Unit::IsVendor(), ItemTemplate::ItemId, LANG_COMMAND_NEEDITEMSEND, LANG_COMMAND_VENDORSELECTION, LANG_ITEM_DELETED_FROM_LIST, LANG_ITEM_NOT_IN_LIST, ItemTemplate::Name1, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandleNpcDoActionCommand()

static bool npc_commandscript::HandleNpcDoActionCommand ( ChatHandler handler,
uint32  actionId 
)
inlinestatic
1356 {
1357 Creature* creature = handler->getSelectedCreature();
1358 if (!creature)
1359 {
1361 return false;
1362 }
1363
1364 creature->AI()->DoAction(actionId);
1365 handler->PSendSysMessage(LANG_NPC_DO_ACTION, creature->GetGUID().ToString(), creature->GetEntry(), creature->GetName(), actionId);
1366 return true;
1367 }
@ LANG_NPC_DO_ACTION
Definition Language.h:674
CreatureAI * AI() const
Definition Creature.h:143
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:114
virtual void DoAction(int32)
Definition UnitAI.h:217
std::string const & GetName() const
Definition Object.h:528

References Creature::AI(), UnitAI::DoAction(), Object::GetEntry(), Object::GetGUID(), WorldObject::GetName(), ChatHandler::getSelectedCreature(), LANG_NPC_DO_ACTION, LANG_SELECT_CREATURE, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleNpcFollowCommand()

static bool npc_commandscript::HandleNpcFollowCommand ( ChatHandler handler)
inlinestatic
606 {
607 Player* player = handler->GetSession()->GetPlayer();
608 Creature* creature = handler->getSelectedCreature();
609
610 if (!creature)
611 {
613 return false;
614 }
615
616 // Follow player - Using pet's default dist and angle
617 creature->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, creature->GetFollowAngle());
618
620 return true;
621 }
@ LANG_CREATURE_FOLLOW_YOU_NOW
Definition Language.h:387
constexpr float PET_FOLLOW_DIST
Definition PetDefines.h:206
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE, bool inheritWalkState=true, bool inheritSpeed=true)
The unit will follow this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition MotionMaster.cpp:447
MotionMaster * GetMotionMaster()
Definition Unit.h:1758
virtual float GetFollowAngle() const
Definition Unit.h:1895

References Unit::GetFollowAngle(), Unit::GetMotionMaster(), WorldObject::GetName(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), LANG_CREATURE_FOLLOW_YOU_NOW, LANG_SELECT_CREATURE, MotionMaster::MoveFollow(), PET_FOLLOW_DIST, ChatHandler::PSendSysMessage(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleNpcGuidCommand()

static bool npc_commandscript::HandleNpcGuidCommand ( ChatHandler handler)
inlinestatic
744 {
745 Creature* target = handler->getSelectedCreature();
746
747 if (!target)
748 {
750 return false;
751 }
752
753 uint32 faction = target->GetFaction();
754 uint32 npcflags = target->GetNpcFlags();
755 uint32 displayid = target->GetDisplayId();
756 uint32 nativeid = target->GetNativeDisplayId();
757 uint32 entry = target->GetEntry();
758 uint32 id1 = 0;
759 uint32 id2 = 0;
760 uint32 id3 = 0;
761 if (CreatureData const* cData = target->GetCreatureData())
762 {
763 id1 = cData->id1;
764 id2 = cData->id2;
765 id3 = cData->id3;
766 }
767
768 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
769
770 return true;
771 }
@ LANG_NPCINFO_CHAR
Definition Language.h:592
CreatureData const * GetCreatureData() const
Definition Creature.h:207
NPCFlags GetNpcFlags() const
Clears emote state (looping emote)
Definition Unit.h:762
uint32 GetFaction() const
Definition Unit.h:851
uint32 GetDisplayId() const
Definition Unit.h:1974
uint32 GetNativeDisplayId() const
Definition Unit.h:1976

References Creature::GetCreatureData(), Unit::GetDisplayId(), Object::GetEntry(), Unit::GetFaction(), Object::GetGUID(), Unit::GetNativeDisplayId(), Unit::GetNpcFlags(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), LANG_NPCINFO_CHAR, LANG_SELECT_CREATURE, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleNpcInfoCommand()

static bool npc_commandscript::HandleNpcInfoCommand ( ChatHandler handler,
Optional< CreatureSpawnId spawnIdArg 
)
inlinestatic
624 {
625 Creature* target = handler->getSelectedCreature();
626 ObjectGuid::LowType lowGuid = 0;
627
628 if (spawnIdArg)
629 lowGuid = *spawnIdArg;
630
631 if (!target && lowGuid)
632 target = handler->GetCreatureFromPlayerMapByDbGuid(lowGuid);
633
634 if (target)
635 return HandleNpcInfoCommandShowCreature(handler, target);
636
637 if (!lowGuid)
638 {
640 return false;
641 }
642
643 CreatureData const* cData = sObjectMgr->GetCreatureData(lowGuid);
644 if (!cData)
645 cData = sObjectMgr->LoadCreatureDataFromDB(lowGuid);
646 if (cData)
647 return HandleNpcInfoCommandShowFromDB(handler, lowGuid, cData);
648
650 return false;
651 }
static bool HandleNpcInfoCommandShowFromDB(ChatHandler *handler, ObjectGuid::LowType lowGuid, CreatureData const *cData)
Definition cs_npc.cpp:719
static bool HandleNpcInfoCommandShowCreature(ChatHandler *handler, Creature *target)
Definition cs_npc.cpp:653

References ChatHandler::GetCreatureFromPlayerMapByDbGuid(), ChatHandler::getSelectedCreature(), HandleNpcInfoCommandShowCreature(), HandleNpcInfoCommandShowFromDB(), LANG_COMMAND_CREATGUIDNOTFOUND, LANG_SELECT_CREATURE, ChatHandler::SendErrorMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandleNpcInfoCommandShowCreature()

static bool npc_commandscript::HandleNpcInfoCommandShowCreature ( ChatHandler handler,
Creature target 
)
inlinestatic
654 {
655 CreatureTemplate const* cInfo = target->GetCreatureTemplate();
656 uint32 faction = target->GetFaction();
657 uint32 npcflags = target->GetNpcFlags();
658 uint64 mechanicImmuneMask = 0;
659 uint32 spellSchoolImmuneMask = 0;
660
661 if (CreatureImmunities const* immunities = sSpellMgr->GetCreatureImmunities(cInfo->CreatureImmunitiesId))
662 {
663 mechanicImmuneMask = immunities->Mechanic.to_ullong();
664 for (std::size_t j = 0; j < immunities->School.size(); ++j)
665 if (immunities->School[j])
666 spellSchoolImmuneMask |= (1u << j);
667 }
668
669 uint32 displayid = target->GetDisplayId();
670 uint32 nativeid = target->GetNativeDisplayId();
671 uint32 entry = target->GetEntry();
672 uint32 id1 = 0;
673 uint32 id2 = 0;
674 uint32 id3 = 0;
675 if (CreatureData const* cData = target->GetCreatureData())
676 {
677 id1 = cData->id1;
678 id2 = cData->id2;
679 id3 = cData->id3;
680 }
681
682 int64 curRespawnDelay = target->GetRespawnTimeEx() - GameTime::GetGameTime().count();
683 if (curRespawnDelay < 0)
684 curRespawnDelay = 0;
685
686 std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
687 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
688
689 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
690 handler->PSendSysMessage(LANG_NPCINFO_LEVEL, target->GetLevel());
692 handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
693 handler->PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUnitFlags(), target->GetUnitFlags2(), target->GetDynamicFlags(), target->GetFaction());
694 handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr, curRespawnDelayStr);
695 handler->PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid, cInfo->pickpocketLootId, cInfo->SkinLootId);
698 handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor());
699 handler->PSendSysMessage(LANG_NPCINFO_POSITION, float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
700 handler->PSendSysMessage(LANG_NPCINFO_AIINFO, target->GetAIName(), target->GetScriptName());
701
702 for (auto npcFlagText : npcFlagTexts)
703 if (npcflags & npcFlagText.flag)
704 handler->PSendSysMessage(npcFlagText.text, npcFlagText.flag);
705
706 handler->PSendSysMessage(LANG_NPCINFO_MECHANIC_IMMUNE, Acore::StringFormat("0x{:X}", mechanicImmuneMask).c_str());
707 for (uint8 i = 1; i < MAX_MECHANIC; ++i)
708 if (mechanicImmuneMask & (UI64LIT(1) << i))
709 handler->PSendSysMessage(mechanicImmunes[i].text, mechanicImmunes[i].flag);
710
711 handler->PSendSysMessage(LANG_NPCINFO_SPELL_SCHOOL_IMMUNE, spellSchoolImmuneMask);
712 for (auto spellSchoolImmune : spellSchoolImmunes)
713 if (spellSchoolImmuneMask & (1 << spellSchoolImmune.flag))
714 handler->PSendSysMessage(spellSchoolImmune.text, spellSchoolImmune.flag);
715
716 return true;
717 }
#define UI64LIT(N)
Definition Define.h:97
std::uint64_t uint64
Definition Define.h:106
std::int64_t int64
Definition Define.h:102
@ LANG_NPCINFO_EQUIPMENT
Definition Language.h:1095
@ LANG_NPCINFO_LOOT
Definition Language.h:596
@ LANG_NPCINFO_POSITION
Definition Language.h:597
@ LANG_NPCINFO_FLAGS
Definition Language.h:595
@ LANG_NPCINFO_AIINFO
Definition Language.h:1090
@ LANG_NPCINFO_SPELL_SCHOOL_IMMUNE
Definition Language.h:1126
@ LANG_NPCINFO_HEALTH
Definition Language.h:594
@ LANG_NPCINFO_PHASEMASK
Definition Language.h:1079
@ LANG_NPCINFO_LEVEL
Definition Language.h:593
@ LANG_COMMAND_RAWPAWNTIMES
Definition Language.h:647
@ LANG_NPCINFO_ARMOR
Definition Language.h:1080
@ LANG_NPCINFO_DUNGEON_ID
Definition Language.h:600
@ LANG_NPCINFO_MECHANIC_IMMUNE
Definition Language.h:1096
@ MAX_MECHANIC
Definition SharedDefines.h:1350
#define sSpellMgr
Definition SpellMgr.h:836
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
int8 GetOriginalEquipmentId() const
Definition Creature.h:196
uint8 GetCurrentEquipmentId()
Definition Creature.h:197
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:206
uint32 GetRespawnDelay() const
Definition Creature.h:294
std::string GetScriptName() const
Definition Creature.cpp:3059
time_t GetRespawnTimeEx() const
Definition Creature.cpp:2951
std::string const & GetAIName() const
Definition Creature.cpp:3054
uint32 GetMaxHealth() const
Definition Unit.h:1109
UnitFlags GetUnitFlags() const
Definition Unit.h:746
uint32 GetHealth() const
Definition Unit.h:1108
uint32 GetCreateHealth() const
Definition Unit.h:1112
uint32 GetArmor() const
Definition Unit.h:1157
uint8 GetLevel() const
Definition Unit.h:1103
UnitFlags2 GetUnitFlags2() const
Remove all UnitFlags and set new ones. UnitFlags available in UnitDefines.h.
Definition Unit.h:752
uint32 GetDynamicFlags() const override
Definition Unit.h:768
uint32 GetPhaseMask() const
Definition Object.h:516
uint32 GetInstanceId() const
Definition Object.h:513
NpcFlagText const npcFlagTexts[NPCFLAG_COUNT]
Definition cs_npc.cpp:50
SpellSchoolImmune const spellSchoolImmunes[MAX_SPELL_SCHOOL]
Definition cs_npc.cpp:126
MechanicImmune const mechanicImmunes[MAX_MECHANIC]
Definition cs_npc.cpp:84
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition StringFormat.h:44
Seconds GetGameTime()
Definition GameTime.cpp:38
Definition SpellMgr.h:564
Definition CreatureData.h:187
int32 CreatureImmunitiesId
Definition CreatureData.h:240
uint32 SkinLootId
Definition CreatureData.h:222
uint32 pickpocketLootId
Definition CreatureData.h:221
uint32 lootid
Definition CreatureData.h:220

References CreatureTemplate::CreatureImmunitiesId, MechanicImmune::flag, Creature::GetAIName(), Unit::GetArmor(), Unit::GetCreateHealth(), Creature::GetCreatureData(), Creature::GetCreatureTemplate(), Creature::GetCurrentEquipmentId(), Unit::GetDisplayId(), Unit::GetDynamicFlags(), Object::GetEntry(), Unit::GetFaction(), GameTime::GetGameTime(), Object::GetGUID(), Unit::GetHealth(), WorldObject::GetInstanceId(), Unit::GetLevel(), Unit::GetMaxHealth(), Unit::GetNativeDisplayId(), Unit::GetNpcFlags(), Creature::GetOriginalEquipmentId(), WorldObject::GetPhaseMask(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), Creature::GetRespawnDelay(), Creature::GetRespawnTimeEx(), Creature::GetScriptName(), Creature::GetSpawnId(), Unit::GetUnitFlags(), Unit::GetUnitFlags2(), LANG_COMMAND_RAWPAWNTIMES, LANG_NPCINFO_AIINFO, LANG_NPCINFO_ARMOR, LANG_NPCINFO_CHAR, LANG_NPCINFO_DUNGEON_ID, LANG_NPCINFO_EQUIPMENT, LANG_NPCINFO_FLAGS, LANG_NPCINFO_HEALTH, LANG_NPCINFO_LEVEL, LANG_NPCINFO_LOOT, LANG_NPCINFO_MECHANIC_IMMUNE, LANG_NPCINFO_PHASEMASK, LANG_NPCINFO_POSITION, LANG_NPCINFO_SPELL_SCHOOL_IMMUNE, CreatureTemplate::lootid, MAX_MECHANIC, mechanicImmunes, npcFlagTexts, CreatureTemplate::pickpocketLootId, ChatHandler::PSendSysMessage(), secsToTimeString(), CreatureTemplate::SkinLootId, spellSchoolImmunes, sSpellMgr, Acore::StringFormat(), MechanicImmune::text, ObjectGuid::ToString(), and UI64LIT.

Referenced by HandleNpcInfoCommand().

◆ HandleNpcInfoCommandShowFromDB()

static bool npc_commandscript::HandleNpcInfoCommandShowFromDB ( ChatHandler handler,
ObjectGuid::LowType  lowGuid,
CreatureData const *  cData 
)
inlinestatic
720 {
721 CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(cData->id1);
722 if (!cInfo)
723 {
725 return false;
726 }
727
728 handler->PSendSysMessage("(Not in world - showing DB data)");
729 uint32 scriptId = cData->ScriptId ? cData->ScriptId : cInfo->ScriptID;
730 handler->PSendSysMessage(LANG_NPCINFO_CHAR, lowGuid, ObjectGuid::Create<HighGuid::Unit>(cData->id1, lowGuid).ToString(), cData->id1,
731 cData->id2, cData->id3, cData->displayid, cData->displayid, cInfo->faction,
732 cData->npcflag);
733 handler->PSendSysMessage(LANG_NPCINFO_PHASEMASK, cData->phaseMask);
734 handler->PSendSysMessage(LANG_NPCINFO_POSITION, cData->posX, cData->posY, cData->posZ);
735 handler->PSendSysMessage("Map: {} Spawn time: {}s", cData->mapid,
736 cData->spawntimesecs);
737 handler->PSendSysMessage(LANG_NPCINFO_EQUIPMENT, cData->equipmentId, cData->equipmentId);
739 sObjectMgr->GetScriptName(scriptId));
740 return true;
741 }
uint32 ScriptID
Definition CreatureData.h:242
uint32 faction
Definition CreatureData.h:199
std::string AIName
Definition CreatureData.h:229

References CreatureTemplate::AIName, CreatureData::displayid, CreatureData::equipmentId, CreatureTemplate::faction, CreatureData::id1, CreatureData::id2, CreatureData::id3, LANG_COMMAND_CREATGUIDNOTFOUND, LANG_NPCINFO_AIINFO, LANG_NPCINFO_CHAR, LANG_NPCINFO_EQUIPMENT, LANG_NPCINFO_PHASEMASK, LANG_NPCINFO_POSITION, SpawnData::mapid, CreatureData::npcflag, SpawnData::phaseMask, SpawnData::posX, SpawnData::posY, SpawnData::posZ, ChatHandler::PSendSysMessage(), CreatureTemplate::ScriptID, SpawnData::ScriptId, ChatHandler::SendErrorMessage(), sObjectMgr, and CreatureData::spawntimesecs.

Referenced by HandleNpcInfoCommand().

◆ HandleNpcLoadCommand()

static bool npc_commandscript::HandleNpcLoadCommand ( ChatHandler handler,
CreatureSpawnId  spawnId 
)
inlinestatic
271 {
272 if (!spawnId)
273 return false;
274
275 if (sObjectMgr->GetCreatureData(spawnId))
276 {
277 handler->SendErrorMessage("Creature spawn {} is already loaded.", uint32(spawnId));
278 return false;
279 }
280
281 CreatureData const* data = sObjectMgr->LoadCreatureDataFromDB(spawnId);
282 if (!data)
283 {
284 handler->SendErrorMessage("Creature spawn {} not found in the database.", uint32(spawnId));
285 return false;
286 }
287
288 if (sPoolMgr->IsPartOfAPool<Creature>(spawnId))
289 {
290 handler->SendErrorMessage("Creature spawn {} is part of a pool and cannot be manually loaded.", uint32(spawnId));
291 return false;
292 }
293
294 QueryResult eventResult = WorldDatabase.Query("SELECT guid FROM game_event_creature WHERE guid = {}", uint32(spawnId));
295 if (eventResult)
296 {
297 handler->SendErrorMessage("Creature spawn {} is managed by the game event system and cannot be manually loaded.", uint32(spawnId));
298 return false;
299 }
300
301 Map* map = sMapMgr->FindBaseNonInstanceMap(data->mapid);
302 if (!map)
303 {
304 handler->SendErrorMessage("Creature spawn {} is on a non-continent map (ID: {}). Only continent maps are supported.", uint32(spawnId), data->mapid);
305 return false;
306 }
307
308 Creature* creature = new Creature();
309 if (!creature->LoadCreatureFromDB(spawnId, map, true, true))
310 {
311 delete creature;
312 handler->SendErrorMessage("Failed to load creature spawn {}.", uint32(spawnId));
313 return false;
314 }
315
316 sObjectMgr->AddCreatureToGrid(spawnId, data);
317 handler->PSendSysMessage("Creature spawn {} loaded successfully.", uint32(spawnId));
318 return true;
319 }
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
#define sMapMgr
Definition MapMgr.h:220
#define sPoolMgr
Definition PoolMgr.h:165
uint16 mapid
Definition SpawnData.h:64

References Creature::LoadCreatureFromDB(), SpawnData::mapid, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), sMapMgr, sObjectMgr, sPoolMgr, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcMoveCommand()

static bool npc_commandscript::HandleNpcMoveCommand ( ChatHandler handler,
Optional< ObjectGuid::LowType guid 
)
inlinestatic
859 {
860 Creature* creature;
861 if (guid.has_value())
862 creature = handler->GetCreatureFromPlayerMapByDbGuid(*guid);
863 else
864 creature = handler->getSelectedCreature();
865
866 if (!creature)
867 return false;
868
869 ObjectGuid::LowType lowGuid;
870 if (guid.has_value())
871 lowGuid = *guid;
872 else
873 lowGuid = creature->GetSpawnId();
874
875 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
876 if (!data)
877 {
879 return false;
880 }
881
882 if (handler->GetSession()->GetPlayer()->GetMapId() != data->mapid)
883 {
885 return false;
886 }
887
888 float x = handler->GetSession()->GetPlayer()->GetPositionX();
889 float y = handler->GetSession()->GetPlayer()->GetPositionY();
890 float z = handler->GetSession()->GetPlayer()->GetPositionZ();
891 float o = handler->GetSession()->GetPlayer()->GetOrientation();
892
893 if (creature)
894 {
895 if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetSpawnId()))
896 {
897 const_cast<CreatureData*>(data)->posX = x;
898 const_cast<CreatureData*>(data)->posY = y;
899 const_cast<CreatureData*>(data)->posZ = z;
900 const_cast<CreatureData*>(data)->orientation = o;
901 }
902
903 creature->SetPosition(x, y, z, o);
904 creature->GetMotionMaster()->Initialize();
905
906 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
907 {
909 creature->Respawn();
910 }
911 }
912
914 stmt->SetData(0, x);
915 stmt->SetData(1, y);
916 stmt->SetData(2, z);
917 stmt->SetData(3, o);
918 stmt->SetData(4, lowGuid);
919
920 WorldDatabase.Execute(stmt);
921
923 return true;
924 }
@ LANG_COMMAND_CREATUREMOVED
Definition Language.h:321
@ LANG_COMMAND_CREATUREATSAMEMAP
Definition Language.h:322
@ WORLD_UPD_CREATURE_POSITION
Definition WorldDatabase.h:49
void setDeathState(DeathState s, bool despawn=false) override
A creature can be in 4 different states: Alive, JustDied, Corpse, and JustRespawned....
Definition Creature.cpp:1889
void Respawn(bool force=false)
Definition Creature.cpp:1960
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3170
void Initialize()
Definition MotionMaster.cpp:75
bool IsAlive() const
Definition Unit.h:1793
uint32 GetMapId() const
Definition Position.h:281

References ChatHandler::GetCreatureFromPlayerMapByDbGuid(), WorldLocation::GetMapId(), Unit::GetMotionMaster(), Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Creature::GetSpawnId(), MotionMaster::Initialize(), Unit::IsAlive(), JustDied, LANG_COMMAND_CREATGUIDNOTFOUND, LANG_COMMAND_CREATUREATSAMEMAP, LANG_COMMAND_CREATUREMOVED, SpawnData::mapid, ChatHandler::PSendSysMessage(), Creature::Respawn(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), Creature::setDeathState(), Creature::SetPosition(), sObjectMgr, WORLD_UPD_CREATURE_POSITION, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcNearCommand()

static bool npc_commandscript::HandleNpcNearCommand ( ChatHandler handler,
Optional< float >  dist 
)
inlinestatic
774 {
775 float distance = dist.value_or(10.0f);
776 uint32 count = 0;
777
778 Player* player = handler->GetSession()->GetPlayer();
779
780 // Grid search - finds all creatures including temporary spawns
781 std::list<Creature*> creatures;
782 Acore::AllWorldObjectsInRange check(player, distance);
784 Cell::VisitObjects(player, searcher, distance);
785
786 std::unordered_set<ObjectGuid::LowType> gridSpawnIds;
787
788 for (Creature* creature : creatures)
789 {
790 CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(creature->GetEntry());
791 if (!creatureTemplate)
792 continue;
793
794 handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, creature->GetSpawnId(), creature->GetEntry(),
795 creature->GetSpawnId(), creatureTemplate->Name,
796 creature->GetPositionX(), creature->GetPositionY(), creature->GetPositionZ(),
797 creature->GetMapId(), "", "");
798
799 if (creature->GetSpawnId())
800 gridSpawnIds.insert(creature->GetSpawnId());
801 ++count;
802 }
803
804 if (count > 0 && distance <= SIZE_OF_GRIDS)
805 {
806 handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
807 return true;
808 }
809
810 // Fallback to DB query
812 stmt->SetData(0, player->GetPositionX());
813 stmt->SetData(1, player->GetPositionY());
814 stmt->SetData(2, player->GetPositionZ());
815 stmt->SetData(3, player->GetMapId());
816 stmt->SetData(4, player->GetPositionX());
817 stmt->SetData(5, player->GetPositionY());
818 stmt->SetData(6, player->GetPositionZ());
819 stmt->SetData(7, distance * distance);
820 stmt->SetData(8, player->GetPhaseMask());
821 PreparedQueryResult result = WorldDatabase.Query(stmt);
822
823 if (result)
824 {
825 do
826 {
827 Field* fields = result->Fetch();
828 ObjectGuid::LowType guid = fields[0].Get<uint32>();
829
830 // Skip entries already emitted via grid search
831 if (gridSpawnIds.count(guid))
832 continue;
833
834 uint32 entry = fields[1].Get<uint32>();
835 //uint32 entry2 = fields[2].Get<uint32>();
836 //uint32 entry3 = fields[3].Get<uint32>();
837 float x = fields[4].Get<float>();
838 float y = fields[5].Get<float>();
839 float z = fields[6].Get<float>();
840 uint16 mapId = fields[7].Get<uint16>();
841
842 CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
843 if (!creatureTemplate)
844 continue;
845
846 handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, entry, guid, creatureTemplate->Name, x, y, z, mapId, "", "");
847
848 ++count;
849 } while (result->NextRow());
850 }
851
852 handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
853
854 return true;
855 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition DatabaseEnvFwd.h:45
std::uint16_t uint16
Definition Define.h:108
@ LANG_COMMAND_NEAR_NPC_MESSAGE
Old ones now free:
Definition Language.h:617
@ LANG_CREATURE_LIST_CHAT
Definition Language.h:564
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
@ WORLD_SEL_CREATURE_NEAREST
Definition WorldDatabase.h:90
creatures
Definition boss_prince_malchezaar.cpp:51
Definition GridNotifiers.h:1616
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
Definition GridNotifiers.h:464
static void VisitObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:165
std::string Name
Definition CreatureData.h:192

References Field::Get(), WorldLocation::GetMapId(), WorldObject::GetPhaseMask(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::GetSession(), LANG_COMMAND_NEAR_NPC_MESSAGE, LANG_CREATURE_LIST_CHAT, CreatureTemplate::Name, ChatHandler::PSendSysMessage(), PreparedStatementBase::SetData(), SIZE_OF_GRIDS, sObjectMgr, Cell::VisitObjects(), WORLD_SEL_CREATURE_NEAREST, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcPlayEmoteCommand()

static bool npc_commandscript::HandleNpcPlayEmoteCommand ( ChatHandler handler,
uint32  emote 
)
inlinestatic
928 {
929 Creature* target = handler->getSelectedCreature();
930 if (!target)
931 {
933 return false;
934 }
935
936 target->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote);
937
938 return true;
939 }
@ UNIT_NPC_EMOTESTATE
Definition UpdateFields.h:140
void SetUInt32Value(uint16 index, uint32 value)
Definition Unit.cpp:17304

References ChatHandler::getSelectedCreature(), LANG_SELECT_CREATURE, ChatHandler::SendErrorMessage(), Unit::SetUInt32Value(), and UNIT_NPC_EMOTESTATE.

Referenced by GetCommands().

◆ HandleNpcSayCommand()

static bool npc_commandscript::HandleNpcSayCommand ( ChatHandler handler,
Tail  text 
)
inlinestatic
1186 {
1187 if (text.empty())
1188 return false;
1189
1190 Creature* creature = handler->getSelectedCreature();
1191 if (!creature)
1192 {
1194 return false;
1195 }
1196
1197 creature->Say(text, LANG_UNIVERSAL);
1198
1199 // make some emotes
1200 switch (text.back())
1201 {
1202 case '?': creature->HandleEmoteCommand(EMOTE_ONESHOT_QUESTION); break;
1203 case '!': creature->HandleEmoteCommand(EMOTE_ONESHOT_EXCLAMATION); break;
1204 default: creature->HandleEmoteCommand(EMOTE_ONESHOT_TALK); break;
1205 }
1206
1207 return true;
1208 }
@ EMOTE_ONESHOT_EXCLAMATION
Definition SharedDefines.h:1905
@ EMOTE_ONESHOT_QUESTION
Definition SharedDefines.h:1906
@ EMOTE_ONESHOT_TALK
Definition SharedDefines.h:1901
@ LANG_UNIVERSAL
Definition SharedDefines.h:723
virtual void Say(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:17121
void HandleEmoteCommand(uint32 emoteId)
Definition Unit.cpp:2153

References EMOTE_ONESHOT_EXCLAMATION, EMOTE_ONESHOT_QUESTION, EMOTE_ONESHOT_TALK, ChatHandler::getSelectedCreature(), Unit::HandleEmoteCommand(), LANG_SELECT_CREATURE, LANG_UNIVERSAL, Unit::Say(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().

◆ HandleNpcSetAllowMovementCommand()

static bool npc_commandscript::HandleNpcSetAllowMovementCommand ( ChatHandler handler)
inlinestatic
378 {
379 if (sWorld->getAllowMovement())
380 {
381 sWorld->SetAllowMovement(false);
383 }
384 else
385 {
386 sWorld->SetAllowMovement(true);
388 }
389 return true;
390 }
@ LANG_CREATURE_MOVE_ENABLED
Definition Language.h:437
@ LANG_CREATURE_MOVE_DISABLED
Definition Language.h:436
#define sWorld
Definition World.h:316

References LANG_CREATURE_MOVE_DISABLED, LANG_CREATURE_MOVE_ENABLED, ChatHandler::SendSysMessage(), and sWorld.

Referenced by GetCommands().

◆ HandleNpcSetDataCommand()

static bool npc_commandscript::HandleNpcSetDataCommand ( ChatHandler handler,
uint32  data_1,
uint32  data_2 
)
inlinestatic
589 {
590 Creature* creature = handler->getSelectedCreature();
591
592 if (!creature)
593 {
595 return false;
596 }
597
598 creature->AI()->SetData(data_1, data_2);
599 std::string AIorScript = !creature->GetAIName().empty() ? "AI type: " + creature->GetAIName() : (!creature->GetScriptName().empty() ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set");
600 handler->PSendSysMessage(LANG_NPC_SETDATA, creature->GetGUID().ToString(), creature->GetEntry(), creature->GetName(), data_1, data_2, AIorScript);
601 return true;
602 }
@ LANG_NPC_SETDATA
Definition Language.h:614
virtual void SetData(uint32, uint32)
Definition UnitAI.h:219

References Creature::AI(), Creature::GetAIName(), Object::GetEntry(), Object::GetGUID(), WorldObject::GetName(), Creature::GetScriptName(), ChatHandler::getSelectedCreature(), LANG_NPC_SETDATA, LANG_SELECT_CREATURE, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), UnitAI::SetData(), and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleNpcSetEntryCommand()

static bool npc_commandscript::HandleNpcSetEntryCommand ( ChatHandler handler,
CreatureEntry  newEntryNum 
)
inlinestatic
393 {
394 if (!newEntryNum)
395 return false;
396
397 Unit* unit = handler->getSelectedUnit();
398 if (!unit || !unit->IsCreature())
399 {
401 return false;
402 }
403 Creature* creature = unit->ToCreature();
404 if (creature->UpdateEntry(newEntryNum))
405 handler->SendSysMessage(LANG_DONE);
406 else
407 handler->SendSysMessage(LANG_ERROR);
408 return true;
409 }
@ LANG_ERROR
Definition Language.h:78
@ LANG_DONE
Definition Language.h:75
Unit * getSelectedUnit() const
Definition Chat.cpp:386
bool UpdateEntry(uint32 entry, const CreatureData *data=nullptr, bool changelevel=true, bool updateAI=false)
Definition Creature.cpp:533
bool IsCreature() const
Definition Object.h:205
Creature * ToCreature()
Definition Object.h:206
Definition Unit.h:664

References ChatHandler::getSelectedUnit(), Object::IsCreature(), LANG_DONE, LANG_ERROR, LANG_SELECT_CREATURE, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), Object::ToCreature(), and Creature::UpdateEntry().

Referenced by GetCommands().

◆ HandleNpcSetFactionIdCommand()

static bool npc_commandscript::HandleNpcSetFactionIdCommand ( ChatHandler handler,
uint32  factionId 
)
inlinestatic
488 {
489 if (!sFactionTemplateStore.LookupEntry(factionId))
490 {
491 handler->SendErrorMessage(LANG_WRONG_FACTION, factionId);
492 return false;
493 }
494
495 Creature* creature = handler->getSelectedCreature();
496
497 if (!creature)
498 {
500 return false;
501 }
502
503 creature->SetFaction(factionId);
504
505 // Faction is set in creature_template - not inside creature
506
507 // Update in memory..
508 if (CreatureTemplate const* cinfo = creature->GetCreatureTemplate())
509 const_cast<CreatureTemplate*>(cinfo)->faction = factionId;
510
511 // ..and DB
513
514 stmt->SetData(0, uint16(factionId));
515 stmt->SetData(1, creature->GetEntry());
516
517 WorldDatabase.Execute(stmt);
518
519 return true;
520 }
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
@ LANG_WRONG_FACTION
Definition Language.h:164
@ WORLD_UPD_CREATURE_FACTION
Definition WorldDatabase.h:47
void SetFaction(uint32 faction)
Definition Unit.cpp:7037

References Creature::GetCreatureTemplate(), Object::GetEntry(), ChatHandler::getSelectedCreature(), LANG_SELECT_CREATURE, LANG_WRONG_FACTION, ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), Unit::SetFaction(), sFactionTemplateStore, WORLD_UPD_CREATURE_FACTION, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcSetFactionTempIdCommand()

static bool npc_commandscript::HandleNpcSetFactionTempIdCommand ( ChatHandler handler,
uint32  tempfaction 
)
inlinestatic
524 {
525 Player* player = handler->GetSession()->GetPlayer();
526 Unit* unit = player->GetSelectedUnit();
527
528 if (!unit)
529 return false;
530
531 Creature* creature = unit->ToCreature();
532
533 if (!creature)
534 return false;
535
536 creature->SetFaction(tempfaction);
537
538 return true;
539 }
Unit * GetSelectedUnit() const
Definition Player.cpp:11446

References WorldSession::GetPlayer(), Player::GetSelectedUnit(), ChatHandler::GetSession(), Unit::SetFaction(), and Object::ToCreature().

Referenced by GetCommands().

◆ HandleNpcSetFlagCommand()

static bool npc_commandscript::HandleNpcSetFlagCommand ( ChatHandler handler,
uint32  npcFlags 
)
inlinestatic
564 {
565 Creature* creature = handler->getSelectedCreature();
566
567 if (!creature)
568 {
570 return false;
571 }
572
573 creature->ReplaceAllNpcFlags(NPCFlags(npcFlags));
574
576
577 stmt->SetData(0, NPCFlags(npcFlags));
578 stmt->SetData(1, creature->GetEntry());
579
580 WorldDatabase.Execute(stmt);
581
583
584 return true;
585 }
@ LANG_VALUE_SAVED_REJOIN
Definition Language.h:310
NPCFlags
Non Player Character flags.
Definition UnitDefines.h:320
@ WORLD_UPD_CREATURE_NPCFLAG
Definition WorldDatabase.h:48
void ReplaceAllNpcFlags(NPCFlags flags)
Definition Unit.h:766

References Object::GetEntry(), ChatHandler::getSelectedCreature(), LANG_SELECT_CREATURE, LANG_VALUE_SAVED_REJOIN, Unit::ReplaceAllNpcFlags(), ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), WORLD_UPD_CREATURE_NPCFLAG, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcSetLevelCommand()

static bool npc_commandscript::HandleNpcSetLevelCommand ( ChatHandler handler,
uint8  lvl 
)
inlinestatic
413 {
414 if (lvl < 1 || lvl > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL) + 3)
415 {
417 return false;
418 }
419
420 Creature* creature = handler->getSelectedCreature();
421 if (!creature || creature->IsPet())
422 {
424 return false;
425 }
426
427 creature->SetMaxHealth(100 + 30*lvl);
428 creature->SetHealth(100 + 30*lvl);
429 creature->SetLevel(lvl);
430 creature->SaveToDB();
431
432 return true;
433 }
@ LANG_BAD_VALUE
Definition Language.h:148
@ CONFIG_MAX_PLAYER_LEVEL
Definition WorldConfig.h:193
void SetHealth(uint32 val)
Definition Unit.cpp:12296
void SetLevel(uint8 lvl, bool showLevelChange=true)
Definition Unit.cpp:12278
void SetMaxHealth(uint32 val)
Definition Unit.cpp:12346

References CONFIG_MAX_PLAYER_LEVEL, ChatHandler::getSelectedCreature(), Unit::IsPet(), LANG_BAD_VALUE, LANG_SELECT_CREATURE, Creature::SaveToDB(), ChatHandler::SendErrorMessage(), Unit::SetHealth(), Unit::SetLevel(), Unit::SetMaxHealth(), and sWorld.

Referenced by GetCommands().

◆ HandleNpcSetLinkCommand()

static bool npc_commandscript::HandleNpcSetLinkCommand ( ChatHandler handler,
ObjectGuid::LowType  linkguid 
)
inlinestatic
1414 {
1415 Creature* creature = handler->getSelectedCreature();
1416
1417 if (!creature)
1418 {
1420 return false;
1421 }
1422
1423 if (!creature->GetSpawnId())
1424 {
1425 handler->SendErrorMessage("Selected creature {} isn't in creature table", creature->GetGUID().ToString());
1426 return false;
1427 }
1428
1429 if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetSpawnId(), linkguid))
1430 {
1431 handler->SendErrorMessage("Selected creature can't link with guid '{}'", linkguid);
1432 return false;
1433 }
1434
1435 handler->PSendSysMessage("LinkGUID '{}' added to creature with DBTableGUID: '{}'", linkguid, creature->GetSpawnId());
1436 return true;
1437 }

References Object::GetGUID(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), LANG_SELECT_CREATURE, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), sObjectMgr, and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleNpcSetModelCommand()

static bool npc_commandscript::HandleNpcSetModelCommand ( ChatHandler handler,
uint32  displayId 
)
inlinestatic
943 {
944 Creature* creature = handler->getSelectedCreature();
945
946 if (!creature || creature->IsPet())
947 {
949 return false;
950 }
951
952 if (!sCreatureDisplayInfoStore.LookupEntry(displayId))
953 {
955 return false;
956 }
957
958 creature->SetDisplayId(displayId);
959 creature->SetNativeDisplayId(displayId);
960 creature->SaveToDB();
961
962 return true;
963 }
DBCStorage< CreatureDisplayInfoEntry > sCreatureDisplayInfoStore(CreatureDisplayInfofmt)
@ LANG_COMMAND_FACTION_INVPARAM
Definition Language.h:356
void SetDisplayId(uint32 displayId, float displayScale=1.f) override
Definition Creature.cpp:3410
void SetNativeDisplayId(uint32 displayId)
Definition Unit.h:1978
std::string ToString(Type &&val, Params &&... params)
Definition StringConvert.h:250

References ChatHandler::getSelectedCreature(), Unit::IsPet(), LANG_COMMAND_FACTION_INVPARAM, LANG_SELECT_CREATURE, Creature::SaveToDB(), sCreatureDisplayInfoStore, ChatHandler::SendErrorMessage(), Creature::SetDisplayId(), Unit::SetNativeDisplayId(), and Acore::ToString().

Referenced by GetCommands().

◆ HandleNpcSetMoveTypeCommand()

static bool npc_commandscript::HandleNpcSetMoveTypeCommand ( ChatHandler handler,
Optional< CreatureSpawnId lowGuid,
Variant< EXACT_SEQUENCE("stay"), EXACT_SEQUENCE("random"), EXACT_SEQUENCE("way")>  type,
Optional< EXACT_SEQUENCE("nodel")>  nodel 
)
inlinestatic

HandleNpcSetMoveTypeCommand Set the movement type for an NPC.

Valid movement types are:

  • stay - NPC wont move
  • random - NPC will move randomly according to the wander_distance
  • way - NPC will move with given waypoints set

additional parameter: NODEL - so no waypoints are deleted, if you change the movement type

978 {
979 // 3 arguments:
980 // GUID (optional - you can also select the creature)
981 // stay|random|way (determines the kind of movement)
982 // NODEL (optional - tells the system NOT to delete any waypoints)
983 // this is very handy if you want to do waypoints, that are
984 // later switched on/off according to special events (like escort
985 // quests, etc)
986
987 bool doNotDelete = nodel.has_value();
988
989 ObjectGuid::LowType lowguid = 0;
990 Creature* creature = nullptr;
991
992 if (!lowGuid) // case .setmovetype $move_type (with selected creature)
993 {
994 creature = handler->getSelectedCreature();
995 if (!creature || creature->IsPet())
996 return false;
997 lowguid = creature->GetSpawnId();
998 }
999 else // case .setmovetype #creature_guid $move_type (with selected creature)
1000 {
1001 lowguid = *lowGuid;
1002
1003 if (lowguid)
1004 creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
1005
1006 // attempt check creature existence by DB data
1007 if (!creature)
1008 {
1009 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
1010 if (!data)
1011 {
1013 return false;
1014 }
1015 }
1016 else
1017 {
1018 lowguid = creature->GetSpawnId();
1019 }
1020 }
1021
1022 // now lowguid is low guid really existed creature
1023 // and creature point (maybe) to this creature or nullptr
1024
1025 MovementGeneratorType move_type;
1026 switch (type.index())
1027 {
1028 case 0:
1029 move_type = IDLE_MOTION_TYPE;
1030 break;
1031 case 1:
1032 move_type = RANDOM_MOTION_TYPE;
1033 break;
1034 case 2:
1035 move_type = WAYPOINT_MOTION_TYPE;
1036 break;
1037 default:
1038 return false;
1039 }
1040
1041 // update movement type
1042 //if (doNotDelete == false)
1043 // WaypointMgr.DeletePath(lowguid);
1044
1045 if (creature)
1046 {
1047 // update movement type
1048 if (!doNotDelete)
1049 creature->LoadPath(0);
1050
1051 creature->SetDefaultMovementType(move_type);
1052 creature->GetMotionMaster()->Initialize();
1053
1054 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
1055 {
1057 creature->Respawn();
1058 }
1059
1060 creature->SaveToDB();
1061 }
1062
1063 if (!doNotDelete)
1064 {
1065 handler->PSendSysMessage(LANG_MOVE_TYPE_SET, move_type);
1066 }
1067 else
1068 {
1069 handler->PSendSysMessage(LANG_MOVE_TYPE_SET_NODEL, move_type);
1070 }
1071
1072 return true;
1073 }
@ LANG_MOVE_TYPE_SET
Definition Language.h:306
@ LANG_MOVE_TYPE_SET_NODEL
Definition Language.h:307
MovementGeneratorType
Definition MotionMaster.h:38
@ IDLE_MOTION_TYPE
Definition MotionMaster.h:39
@ RANDOM_MOTION_TYPE
Definition MotionMaster.h:40
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition Creature.h:91
void LoadPath(uint32 pathid)
Definition Creature.h:356

References ChatHandler::GetCreatureFromPlayerMapByDbGuid(), Unit::GetMotionMaster(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), IDLE_MOTION_TYPE, MotionMaster::Initialize(), Unit::IsAlive(), Unit::IsPet(), JustDied, LANG_COMMAND_CREATGUIDNOTFOUND, LANG_MOVE_TYPE_SET, LANG_MOVE_TYPE_SET_NODEL, Creature::LoadPath(), ChatHandler::PSendSysMessage(), RANDOM_MOTION_TYPE, Creature::Respawn(), Creature::SaveToDB(), ChatHandler::SendErrorMessage(), Creature::setDeathState(), Creature::SetDefaultMovementType(), sObjectMgr, and WAYPOINT_MOTION_TYPE.

Referenced by GetCommands().

◆ HandleNpcSetOriginalFaction()

static bool npc_commandscript::HandleNpcSetOriginalFaction ( ChatHandler handler)
inlinestatic
543 {
544 Player* player = handler->GetSession()->GetPlayer();
545
546 if (!player)
547 return false;
548
549 if (!player->GetSelectedUnit())
550 return false;
551
552 Creature* creature = player->GetSelectedUnit()->ToCreature();
553
554 if (!creature)
555 return false;
556
557 creature->RestoreFaction();
558
559 return true;
560 }
void RestoreFaction()
Definition Unit.cpp:14901

References WorldSession::GetPlayer(), Player::GetSelectedUnit(), ChatHandler::GetSession(), Unit::RestoreFaction(), and Object::ToCreature().

Referenced by GetCommands().

◆ HandleNpcSetPhaseCommand()

static bool npc_commandscript::HandleNpcSetPhaseCommand ( ChatHandler handler,
uint32  phasemask 
)
inlinestatic
1078 {
1079 if (phasemask == 0)
1080 {
1082 return false;
1083 }
1084
1085 Creature* creature = handler->getSelectedCreature();
1086 if (!creature)
1087 {
1089 return false;
1090 }
1091
1092 creature->SetPhaseMask(phasemask, true);
1093
1094 if (!creature->IsPet())
1095 creature->SaveToDB();
1096
1097 return true;
1098 }
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:15255

References ChatHandler::getSelectedCreature(), Unit::IsPet(), LANG_BAD_VALUE, LANG_SELECT_CREATURE, Creature::SaveToDB(), ChatHandler::SendErrorMessage(), and Unit::SetPhaseMask().

Referenced by GetCommands().

◆ HandleNpcSetSpawnTimeCommand()

static bool npc_commandscript::HandleNpcSetSpawnTimeCommand ( ChatHandler handler,
std::string  spawnTimeStr 
)
inlinestatic
1146 {
1147 if (spawnTimeStr.empty())
1148 {
1149 return false;
1150 }
1151
1152 if (Acore::StringTo<int32>(spawnTimeStr).value_or(0) < 0)
1153 {
1155 return false;
1156 }
1157
1158 Creature* creature = handler->getSelectedCreature();
1159 if (!creature)
1160 return false;
1161
1162 int32 spawnTime = TimeStringToSecs(spawnTimeStr);
1163 if (spawnTime <= 0)
1164 {
1165 spawnTime = Acore::StringTo<int32>(spawnTimeStr).value_or(0);
1166 }
1167
1168 if (spawnTime <= 0)
1169 {
1171 return false;
1172 }
1173
1175 stmt->SetData(0, spawnTime);
1176 stmt->SetData(1, creature->GetSpawnId());
1177 WorldDatabase.Execute(stmt);
1178
1179 creature->SetRespawnDelay(spawnTime);
1180 handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, secsToTimeString(spawnTime, true));
1181
1182 return true;
1183 }
std::int32_t int32
Definition Define.h:103
@ LANG_COMMAND_SPAWNTIME
Definition Language.h:343
uint32 TimeStringToSecs(const std::string &timestring)
Definition Util.cpp:163
@ WORLD_UPD_CREATURE_SPAWN_TIME_SECS
Definition WorldDatabase.h:51
void SetRespawnDelay(uint32 delay)
Definition Creature.h:295

References ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), LANG_BAD_VALUE, LANG_COMMAND_SPAWNTIME, ChatHandler::PSendSysMessage(), secsToTimeString(), ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), Creature::SetRespawnDelay(), TimeStringToSecs(), WORLD_UPD_CREATURE_SPAWN_TIME_SECS, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcSetWanderDistanceCommand()

static bool npc_commandscript::HandleNpcSetWanderDistanceCommand ( ChatHandler handler,
float  option 
)
inlinestatic
1102 {
1103 if (option < 0.0f)
1104 {
1106 return false;
1107 }
1108
1110
1111 if (option > 0.0f)
1112 mtype = RANDOM_MOTION_TYPE;
1113
1114 Creature* creature = handler->getSelectedCreature();
1115 ObjectGuid::LowType guidLow = 0;
1116
1117 if (creature)
1118 guidLow = creature->GetSpawnId();
1119 else
1120 return false;
1121
1122 creature->SetWanderDistance((float)option);
1123 creature->SetDefaultMovementType(mtype);
1124 creature->GetMotionMaster()->Initialize();
1125
1126 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
1127 {
1129 creature->Respawn();
1130 }
1131
1133
1134 stmt->SetData(0, option);
1135 stmt->SetData(1, uint8(mtype));
1136 stmt->SetData(2, guidLow);
1137
1138 WorldDatabase.Execute(stmt);
1139
1141 return true;
1142 }
@ LANG_COMMAND_WANDER_DISTANCE
Definition Language.h:342
@ WORLD_UPD_CREATURE_WANDER_DISTANCE
Definition WorldDatabase.h:50
void SetWanderDistance(float dist)
Definition Creature.h:306

References Unit::GetMotionMaster(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), IDLE_MOTION_TYPE, MotionMaster::Initialize(), Unit::IsAlive(), JustDied, LANG_BAD_VALUE, LANG_COMMAND_WANDER_DISTANCE, ChatHandler::PSendSysMessage(), RANDOM_MOTION_TYPE, Creature::Respawn(), ChatHandler::SendSysMessage(), PreparedStatementBase::SetData(), Creature::setDeathState(), Creature::SetDefaultMovementType(), Creature::SetWanderDistance(), WORLD_UPD_CREATURE_WANDER_DISTANCE, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcTameCommand()

static bool npc_commandscript::HandleNpcTameCommand ( ChatHandler handler)
inlinestatic
1320 {
1321 Creature* creatureTarget = handler->getSelectedCreature();
1322 if (!creatureTarget || creatureTarget->IsPet())
1323 {
1325 handler->SetSentErrorMessage(true);
1326 return false;
1327 }
1328
1329 Player* player = handler->GetSession()->GetPlayer();
1330
1331 if (player->IsExistPet())
1332 {
1334 return false;
1335 }
1336
1337 CreatureTemplate const* cInfo = creatureTarget->GetCreatureTemplate();
1338
1339 if (!cInfo->IsTameable(player->CanTameExoticPets()))
1340 {
1342 handler->SetSentErrorMessage (true);
1343 return false;
1344 }
1345
1346 if (!player->CreatePet(creatureTarget))
1347 {
1349 return false;
1350 }
1351
1352 return true;
1353 }
@ LANG_CREATURE_NON_TAMEABLE
Definition Language.h:390
@ LANG_YOU_ALREADY_HAVE_PET
Definition Language.h:391
bool IsExistPet()
Definition Player.cpp:9225
bool CanTameExoticPets() const
Definition Player.h:2208
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition Player.cpp:9231
uint32 Entry
Definition CreatureData.h:188
bool IsTameable(bool exotic) const
Definition CreatureData.h:269

References Player::CanTameExoticPets(), Player::CreatePet(), CreatureTemplate::Entry, Creature::GetCreatureTemplate(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Player::IsExistPet(), Unit::IsPet(), CreatureTemplate::IsTameable(), LANG_CREATURE_NON_TAMEABLE, LANG_SELECT_CREATURE, LANG_YOU_ALREADY_HAVE_PET, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and ChatHandler::SetSentErrorMessage().

Referenced by GetCommands().

◆ HandleNpcTextEmoteCommand()

static bool npc_commandscript::HandleNpcTextEmoteCommand ( ChatHandler handler,
Tail  text 
)
inlinestatic
1212 {
1213 if (text.empty())
1214 return false;
1215
1216 Creature* creature = handler->getSelectedCreature();
1217
1218 if (!creature)
1219 {
1221 return false;
1222 }
1223
1224 creature->TextEmote(text);
1225
1226 return true;
1227 }
virtual void TextEmote(std::string_view text, WorldObject const *target=nullptr, bool isBossEmote=false)
Definition Unit.cpp:17131

References ChatHandler::getSelectedCreature(), LANG_SELECT_CREATURE, ChatHandler::SendErrorMessage(), and Unit::TextEmote().

Referenced by GetCommands().

◆ HandleNpcUnFollowCommand()

static bool npc_commandscript::HandleNpcUnFollowCommand ( ChatHandler handler)
inlinestatic
1231 {
1232 Player* player = handler->GetSession()->GetPlayer();
1233 Creature* creature = handler->getSelectedCreature();
1234
1235 if (!creature)
1236 {
1238 return false;
1239 }
1240
1241 if (/*creature->GetMotionMaster()->empty() ||*/
1243 {
1244 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1245 return false;
1246 }
1247
1248 FollowMovementGenerator<Creature> const* mgen = static_cast<FollowMovementGenerator<Creature> const*>((creature->GetMotionMaster()->top()));
1249
1250 if (mgen->GetTarget() != player)
1251 {
1252 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1253 return false;
1254 }
1255
1256 // reset movement
1257 creature->GetMotionMaster()->MovementExpired(true);
1258
1260 return true;
1261 }
@ LANG_CREATURE_NOT_FOLLOW_YOU
Definition Language.h:388
@ LANG_CREATURE_NOT_FOLLOW_YOU_NOW
Definition Language.h:389
@ FOLLOW_MOTION_TYPE
Definition MotionMaster.h:54
Definition TargetedMovementGenerator.h:82
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:96
_Ty top() const
Definition MotionMaster.h:176
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:961
void MovementExpired(bool reset=true)
Definition MotionMaster.h:206

References FOLLOW_MOTION_TYPE, MotionMaster::GetCurrentMovementGeneratorType(), Unit::GetMotionMaster(), WorldObject::GetName(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), FollowMovementGenerator< T >::GetTarget(), LANG_CREATURE_NOT_FOLLOW_YOU, LANG_CREATURE_NOT_FOLLOW_YOU_NOW, LANG_SELECT_CREATURE, MotionMaster::MovementExpired(), ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and MotionMaster::top().

Referenced by GetCommands().

◆ HandleNpcWhisperCommand()

static bool npc_commandscript::HandleNpcWhisperCommand ( ChatHandler handler,
std::string const &  recv,
Tail  text 
)
inlinestatic
1265 {
1266 if (text.empty())
1267 return false;
1268
1269 Creature* creature = handler->getSelectedCreature();
1270 if (!creature)
1271 {
1273 return false;
1274 }
1275
1276 // check online security
1277 Player* receiver = ObjectAccessor::FindPlayerByName(recv);
1278 if (handler->HasLowerSecurity(receiver, ObjectGuid::Empty))
1279 return false;
1280
1281 creature->Whisper(text, LANG_UNIVERSAL, receiver);
1282 return true;
1283 }
bool HasLowerSecurity(Player *target, ObjectGuid guid=ObjectGuid::Empty, bool strong=false)
Definition Chat.cpp:57
static ObjectGuid const Empty
Definition ObjectGuid.h:120
virtual void Whisper(std::string_view text, Language language, Player *target, bool isBossWhisper=false)
Definition Unit.cpp:17136
Player * FindPlayerByName(std::string const &name, bool checkInWorld=true)
Definition ObjectAccessor.cpp:271

References ObjectGuid::Empty, ObjectAccessor::FindPlayerByName(), ChatHandler::getSelectedCreature(), ChatHandler::HasLowerSecurity(), LANG_SELECT_CREATURE, LANG_UNIVERSAL, ChatHandler::SendErrorMessage(), and Unit::Whisper().

Referenced by GetCommands().

◆ HandleNpcYellCommand()

static bool npc_commandscript::HandleNpcYellCommand ( ChatHandler handler,
Tail  text 
)
inlinestatic
1286 {
1287 if (text.empty())
1288 return false;
1289
1290 Creature* creature = handler->getSelectedCreature();
1291 if (!creature)
1292 {
1294 return false;
1295 }
1296
1297 creature->Yell(text, LANG_UNIVERSAL);
1298
1299 // make an emote
1301
1302 return true;
1303 }
@ EMOTE_ONESHOT_SHOUT
Definition SharedDefines.h:1920
virtual void Yell(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:17126

References EMOTE_ONESHOT_SHOUT, ChatHandler::getSelectedCreature(), Unit::HandleEmoteCommand(), LANG_SELECT_CREATURE, LANG_UNIVERSAL, ChatHandler::SendErrorMessage(), and Unit::Yell().

Referenced by GetCommands().


The documentation for this class was generated from the following file: