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)
 
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
136: CommandScript("npc_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable npc_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

139 {
140 static ChatCommandTable npcAddCommandTable =
141 {
142 { "formation", HandleNpcAddFormationCommand, SEC_ADMINISTRATOR, Console::No },
143 { "item", HandleNpcAddVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
144 { "move", HandleNpcAddMoveCommand, SEC_ADMINISTRATOR, Console::No },
145 { "temp", HandleNpcAddTempSpawnCommand, SEC_ADMINISTRATOR, Console::No },
146 { "", HandleNpcAddCommand, SEC_ADMINISTRATOR, Console::No }
147 };
148 static ChatCommandTable npcDeleteCommandTable =
149 {
150 { "item", HandleNpcDeleteVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
151 { "", HandleNpcDeleteCommand, SEC_ADMINISTRATOR, Console::No }
152 };
153 static ChatCommandTable npcFollowCommandTable =
154 {
155 { "stop", HandleNpcUnFollowCommand, SEC_GAMEMASTER, Console::No },
156 { "", HandleNpcFollowCommand, SEC_GAMEMASTER, Console::No }
157 };
158
159 static ChatCommandTable npcFactionCommandTable =
160 {
161 { "permanent", HandleNpcSetFactionIdCommand, SEC_ADMINISTRATOR, Console::No },
162 { "temp", HandleNpcSetFactionTempIdCommand, SEC_ADMINISTRATOR, Console::No },
163 { "original", HandleNpcSetOriginalFaction, SEC_ADMINISTRATOR, Console::No }
164 };
165
166 static ChatCommandTable npcSetCommandTable =
167 {
168 { "allowmove", HandleNpcSetAllowMovementCommand, SEC_ADMINISTRATOR, Console::No },
169 { "entry", HandleNpcSetEntryCommand, SEC_ADMINISTRATOR, Console::No },
170 { "faction", npcFactionCommandTable},
171 { "flag", HandleNpcSetFlagCommand, SEC_ADMINISTRATOR, Console::No },
172 { "level", HandleNpcSetLevelCommand, SEC_ADMINISTRATOR, Console::No },
173 { "link", HandleNpcSetLinkCommand, SEC_ADMINISTRATOR, Console::No },
174 { "model", HandleNpcSetModelCommand, SEC_ADMINISTRATOR, Console::No },
175 { "movetype", HandleNpcSetMoveTypeCommand, SEC_ADMINISTRATOR, Console::No },
176 { "phase", HandleNpcSetPhaseCommand, SEC_ADMINISTRATOR, Console::No },
177 { "wanderdistance", HandleNpcSetWanderDistanceCommand, SEC_ADMINISTRATOR, Console::No },
178 { "spawntime", HandleNpcSetSpawnTimeCommand, SEC_ADMINISTRATOR, Console::No },
179 { "data", HandleNpcSetDataCommand, SEC_ADMINISTRATOR, Console::No }
180 };
181 static ChatCommandTable npcCommandTable =
182 {
183 { "info", HandleNpcInfoCommand, SEC_GAMEMASTER, Console::No },
184 { "guid", HandleNpcGuidCommand, SEC_GAMEMASTER, Console::No },
185 { "near", HandleNpcNearCommand, SEC_GAMEMASTER, Console::No },
186 { "move", HandleNpcMoveCommand, SEC_GAMEMASTER, Console::No },
187 { "playemote", HandleNpcPlayEmoteCommand, SEC_GAMEMASTER, Console::No },
188 { "say", HandleNpcSayCommand, SEC_GAMEMASTER, Console::No },
189 { "textemote", HandleNpcTextEmoteCommand, SEC_GAMEMASTER, Console::No },
190 { "whisper", HandleNpcWhisperCommand, SEC_GAMEMASTER, Console::No },
191 { "yell", HandleNpcYellCommand, SEC_GAMEMASTER, Console::No },
192 { "tame", HandleNpcTameCommand, SEC_GAMEMASTER, Console::No },
193 { "do", HandleNpcDoActionCommand, SEC_GAMEMASTER, Console::No },
194 { "add", npcAddCommandTable },
195 { "delete", npcDeleteCommandTable },
196 { "follow", npcFollowCommandTable },
197 { "load", HandleNpcLoadCommand, SEC_ADMINISTRATOR, Console::Yes },
198 { "set", npcSetCommandTable }
199 };
200 static ChatCommandTable commandTable =
201 {
202 { "npc", npcCommandTable }
203 };
204 return commandTable;
205 }
@ 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:1179
static bool HandleNpcAddFormationCommand(ChatHandler *handler, ObjectGuid::LowType leaderGUID)
Definition cs_npc.cpp:1284
static bool HandleNpcAddTempSpawnCommand(ChatHandler *handler, CreatureEntry id)
Definition cs_npc.cpp:1221
static bool HandleNpcSetFactionTempIdCommand(ChatHandler *handler, uint32 tempfaction)
Definition cs_npc.cpp:519
static bool HandleNpcSetWanderDistanceCommand(ChatHandler *handler, float option)
Definition cs_npc.cpp:1016
static bool HandleNpcAddCommand(ChatHandler *handler, CreatureEntry id)
Definition cs_npc.cpp:208
static bool HandleNpcSetOriginalFaction(ChatHandler *handler)
Definition cs_npc.cpp:538
static bool HandleNpcTameCommand(ChatHandler *handler)
Definition cs_npc.cpp:1234
static bool HandleNpcTextEmoteCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1126
static bool HandleNpcSetModelCommand(ChatHandler *handler, uint32 displayId)
Definition cs_npc.cpp:857
static bool HandleNpcYellCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1200
static bool HandleNpcGuidCommand(ChatHandler *handler)
Definition cs_npc.cpp:694
static bool HandleNpcSetPhaseCommand(ChatHandler *handler, uint32 phasemask)
Definition cs_npc.cpp:992
static bool HandleNpcFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:601
static bool HandleNpcMoveCommand(ChatHandler *handler, Optional< ObjectGuid::LowType > guid)
Definition cs_npc.cpp:773
static bool HandleNpcPlayEmoteCommand(ChatHandler *handler, uint32 emote)
Definition cs_npc.cpp:842
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:892
static bool HandleNpcUnFollowCommand(ChatHandler *handler)
Definition cs_npc.cpp:1145
static bool HandleNpcSetLevelCommand(ChatHandler *handler, uint8 lvl)
Definition cs_npc.cpp:408
static bool HandleNpcSetAllowMovementCommand(ChatHandler *handler)
Definition cs_npc.cpp:373
static bool HandleNpcDeleteCommand(ChatHandler *handler, Optional< ObjectGuid::LowType > lowGuid)
Definition cs_npc.cpp:431
static bool HandleNpcSayCommand(ChatHandler *handler, Tail text)
Definition cs_npc.cpp:1100
static bool HandleNpcInfoCommand(ChatHandler *handler)
Definition cs_npc.cpp:619
static bool HandleNpcNearCommand(ChatHandler *handler, Optional< float > dist)
Definition cs_npc.cpp:724
static bool HandleNpcSetSpawnTimeCommand(ChatHandler *handler, std::string spawnTimeStr)
Definition cs_npc.cpp:1060
static bool HandleNpcSetDataCommand(ChatHandler *handler, uint32 data_1, uint32 data_2)
Definition cs_npc.cpp:584
static bool HandleNpcAddVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< uint32 > mc, Optional< uint32 > it, Optional< uint32 > ec, Optional< bool > addMulti)
Definition cs_npc.cpp:318
static bool HandleNpcDeleteVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< bool > addMulti)
Definition cs_npc.cpp:456
static bool HandleNpcSetFlagCommand(ChatHandler *handler, uint32 npcFlags)
Definition cs_npc.cpp:559
static bool HandleNpcSetLinkCommand(ChatHandler *handler, ObjectGuid::LowType linkguid)
Definition cs_npc.cpp:1328
static bool HandleNpcLoadCommand(ChatHandler *handler, CreatureSpawnId spawnId)
Definition cs_npc.cpp:266
static bool HandleNpcSetFactionIdCommand(ChatHandler *handler, uint32 factionId)
Definition cs_npc.cpp:483
static bool HandleNpcSetEntryCommand(ChatHandler *handler, CreatureEntry newEntryNum)
Definition cs_npc.cpp:388
static bool HandleNpcAddMoveCommand(ChatHandler *handler, CreatureSpawnId lowGuid)
Definition cs_npc.cpp:352
static bool HandleNpcDoActionCommand(ChatHandler *handler, uint32 actionId)
Definition cs_npc.cpp:1270
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
209 {
210 if (!sObjectMgr->GetCreatureTemplate(id))
211 return false;
212
213 Player* chr = handler->GetSession()->GetPlayer();
214 float x = chr->GetPositionX();
215 float y = chr->GetPositionY();
216 float z = chr->GetPositionZ();
217 float o = chr->GetOrientation();
218 Map* map = chr->GetMap();
219
220 if (Transport* tt = chr->GetTransport())
221 if (MotionTransport* trans = tt->ToMotionTransport())
222 {
223 ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
224 CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
225 data.id1 = id;
226 data.phaseMask = chr->GetPhaseMaskForSpawn();
227 data.posX = chr->GetTransOffsetX();
228 data.posY = chr->GetTransOffsetY();
229 data.posZ = chr->GetTransOffsetZ();
230 data.orientation = chr->GetTransOffsetO();
231
232 Creature* creature = trans->CreateNPCPassenger(guid, &data);
233
234 creature->SaveToDB(trans->GetGOInfo()->moTransport.mapID, 1 << map->GetSpawnMode(), chr->GetPhaseMaskForSpawn());
235
236 sObjectMgr->AddCreatureToGrid(guid, &data);
237 return true;
238 }
239
240 Creature* creature = new Creature();
241 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
242 {
243 delete creature;
244 return false;
245 }
246
247 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
248
249 ObjectGuid::LowType spawnId = creature->GetSpawnId();
250
251 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
252 // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
253 creature->CleanupsBeforeDelete();
254 delete creature;
255 creature = new Creature();
256 if (!creature->LoadCreatureFromDB(spawnId, map, true, true))
257 {
258 delete creature;
259 return false;
260 }
261
262 sObjectMgr->AddCreatureToGrid(spawnId, sObjectMgr->GetCreatureData(spawnId));
263 return true;
264 }
#define sObjectMgr
Definition ObjectMgr.h:1686
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:1653
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:1125
void SaveToDB()
Definition Creature.cpp:1354
MotionTransport * ToMotionTransport()
Definition GameObject.h:326
Definition Map.h:163
uint8 GetSpawnMode() const
Definition Map.h:267
ObjectGuid::LowType GenerateLowGuid()
Definition Map.h:480
uint32 GetId() const
Definition Map.h:229
Definition Transport.h:51
uint32 LowType
Definition ObjectGuid.h:122
Definition Player.h:1066
uint32 GetPhaseMaskForSpawn() const
Definition Player.cpp:13776
Definition Transport.h:30
void CleanupsBeforeDelete(bool finalCleanup=true) override
Definition Unit.cpp:16005
Map * GetMap() const
Definition Object.h:620
float GetTransOffsetX() const
Definition Object.h:683
float GetTransOffsetY() const
Definition Object.h:684
float GetTransOffsetZ() const
Definition Object.h:685
Transport * GetTransport() const
Definition Object.h:682
float GetTransOffsetO() const
Definition Object.h:686
Player * GetPlayer() const
Definition WorldSession.h:435
Definition CreatureData.h:366
uint32 phaseMask
Definition CreatureData.h:372
float orientation
Definition CreatureData.h:378
float posY
Definition CreatureData.h:376
float posX
Definition CreatureData.h:375
float posZ
Definition CreatureData.h:377
uint32 id1
Definition CreatureData.h:368
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

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(), CreatureData::orientation, CreatureData::phaseMask, CreatureData::posX, CreatureData::posY, CreatureData::posZ, Creature::SaveToDB(), sObjectMgr, GameObject::ToMotionTransport(), and Unit.

Referenced by GetCommands().

◆ HandleNpcAddFormationCommand()

static bool npc_commandscript::HandleNpcAddFormationCommand ( ChatHandler handler,
ObjectGuid::LowType  leaderGUID 
)
inlinestatic
1285 {
1286 Creature* creature = handler->getSelectedCreature();
1287
1288 if (!creature || !creature->GetSpawnId())
1289 {
1291 return false;
1292 }
1293
1294 ObjectGuid::LowType lowguid = creature->GetSpawnId();
1295 if (creature->GetFormation())
1296 {
1297 handler->PSendSysMessage("Selected creature is already member of group {}", creature->GetFormation()->GetId());
1298 return false;
1299 }
1300
1301 if (!lowguid)
1302 return false;
1303
1304 Player* chr = handler->GetSession()->GetPlayer();
1305 FormationInfo group_member;
1306 group_member.follow_angle = (creature->GetAngle(chr) - chr->GetOrientation()) * 180 / M_PI;
1307 group_member.follow_dist = sqrtf(pow(chr->GetPositionX() - creature->GetPositionX(), int(2)) + pow(chr->GetPositionY() - creature->GetPositionY(), int(2)));
1308 group_member.leaderGUID = leaderGUID;
1309 group_member.groupAI = 0;
1310
1311 sFormationMgr->CreatureGroupMap[lowguid] = group_member;
1312 creature->SearchFormation();
1313
1315 stmt->SetData(0, leaderGUID);
1316 stmt->SetData(1, lowguid);
1317 stmt->SetData(2, group_member.follow_dist);
1318 stmt->SetData(3, group_member.follow_angle);
1319 stmt->SetData(4, uint32(group_member.groupAI));
1320
1321 WorldDatabase.Execute(stmt);
1322
1323 handler->PSendSysMessage("Creature {} added to formation with leader {}", lowguid, leaderGUID);
1324
1325 return true;
1326 }
#define sFormationMgr
Definition CreatureGroups.h:128
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:355
void SearchFormation()
Definition Creature.cpp:374
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
353 {
354 // attempt check creature existence by DB data
355 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
356 if (!data)
357 {
359 return false;
360 }
361
362 // Update movement type
365 stmt->SetData(1, uint32(lowGuid));
366 WorldDatabase.Execute(stmt);
367
369
370 return true;
371 }
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
1222 {
1223 Player* chr = handler->GetSession()->GetPlayer();
1224
1225 if (!id)
1226 return false;
1227
1228 chr->SummonCreature(id, *chr, TEMPSUMMON_CORPSE_DESPAWN, 120);
1229
1230 return true;
1231 }
@ TEMPSUMMON_CORPSE_DESPAWN
Definition Object.h:52
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:2352

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
319 {
320 if (!item)
321 {
323 return false;
324 }
325
326 Creature* vendor = handler->getSelectedCreature();
327 if (!vendor)
328 {
330 return false;
331 }
332
333 uint32 itemId = item->ItemId;
334 uint32 maxcount = mc.value_or(0);
335 uint32 incrtime = it.value_or(0);
336 uint32 extendedcost = ec.value_or(0);
337 uint32 vendor_entry = addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry();
338
339 if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
340 {
341 handler->SetSentErrorMessage(true);
342 return false;
343 }
344
345 sObjectMgr->AddVendorItem(vendor_entry, itemId, maxcount, incrtime, extendedcost);
346
347 handler->PSendSysMessage(LANG_ITEM_ADDED_TO_LIST, itemId, item->Name1, maxcount, incrtime, extendedcost);
348 return true;
349 }
@ 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:116
uint32 GetCurrentVendor() const
Definition WorldSession.h:439

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
432 {
433 Creature* creature;
434 if (lowGuid.has_value())
435 creature = handler->GetCreatureFromPlayerMapByDbGuid(*lowGuid);
436 else
437 creature = handler->getSelectedCreature();
438
439 if (!creature || creature->IsPet() || creature->IsTotem())
440 {
442 return false;
443 }
444
445 // Delete the creature
446 creature->CombatStop();
447 creature->DeleteFromDB();
448 creature->AddObjectToRemoveList();
449
451
452 return true;
453 }
@ LANG_COMMAND_DELCREATMESSAGE
Definition Language.h:320
Creature * GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
Definition Chat.cpp:578
virtual void DeleteFromDB()
Definition Creature.cpp:1803
void CombatStop(bool includingCast=false)
Definition Unit.cpp:10651
bool IsPet() const
Definition Unit.h:787
bool IsTotem() const
Definition Unit.h:789
void AddObjectToRemoveList()
Definition Object.cpp:2144

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
457 {
458 Creature* vendor = handler->getSelectedCreature();
459 if (!vendor || !vendor->IsVendor())
460 {
462 return false;
463 }
464
465 if (!item)
466 {
468 return false;
469 }
470
471 uint32 itemId = item->ItemId;
472 if (!sObjectMgr->RemoveVendorItem(addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry(), itemId))
473 {
474 handler->SendErrorMessage(LANG_ITEM_NOT_IN_LIST, itemId);
475 return false;
476 }
477
478 handler->PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST, itemId, item->Name1);
479 return true;
480 }
@ 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:793

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
1271 {
1272 Creature* creature = handler->getSelectedCreature();
1273 if (!creature)
1274 {
1276 return false;
1277 }
1278
1279 creature->AI()->DoAction(actionId);
1280 handler->PSendSysMessage(LANG_NPC_DO_ACTION, creature->GetGUID().ToString(), creature->GetEntry(), creature->GetName(), actionId);
1281 return true;
1282 }
@ LANG_NPC_DO_ACTION
Definition Language.h:674
CreatureAI * AI() const
Definition Creature.h:144
std::string ToString() const
Definition ObjectGuid.cpp:47
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:113
virtual void DoAction(int32)
Definition UnitAI.h:217
std::string const & GetName() const
Definition Object.h:524

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
602 {
603 Player* player = handler->GetSession()->GetPlayer();
604 Creature* creature = handler->getSelectedCreature();
605
606 if (!creature)
607 {
609 return false;
610 }
611
612 // Follow player - Using pet's default dist and angle
613 creature->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, creature->GetFollowAngle());
614
616 return true;
617 }
@ 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:446
MotionMaster * GetMotionMaster()
Definition Unit.h:1738
virtual float GetFollowAngle() const
Definition Unit.h:1875

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
695 {
696 Creature* target = handler->getSelectedCreature();
697
698 if (!target)
699 {
701 return false;
702 }
703
704 uint32 faction = target->GetFaction();
705 uint32 npcflags = target->GetNpcFlags();
706 uint32 displayid = target->GetDisplayId();
707 uint32 nativeid = target->GetNativeDisplayId();
708 uint32 entry = target->GetEntry();
709 uint32 id1 = 0;
710 uint32 id2 = 0;
711 uint32 id3 = 0;
712 if (CreatureData const* cData = target->GetCreatureData())
713 {
714 id1 = cData->id1;
715 id2 = cData->id2;
716 id3 = cData->id3;
717 }
718
719 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
720
721 return true;
722 }
@ LANG_NPCINFO_CHAR
Definition Language.h:592
CreatureData const * GetCreatureData() const
Definition Creature.h:206
NPCFlags GetNpcFlags() const
Clears emote state (looping emote)
Definition Unit.h:752
uint32 GetFaction() const
Definition Unit.h:841
uint32 GetDisplayId() const
Definition Unit.h:1953
uint32 GetNativeDisplayId() const
Definition Unit.h:1955

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)
inlinestatic
620 {
621 Creature* target = handler->getSelectedCreature();
622
623 if (!target)
624 {
626 return false;
627 }
628
629 CreatureTemplate const* cInfo = target->GetCreatureTemplate();
630 uint32 faction = target->GetFaction();
631 uint32 npcflags = target->GetNpcFlags();
632 uint32 mechanicImmuneMask = cInfo->MechanicImmuneMask;
633 uint32 spellSchoolImmuneMask = cInfo->SpellSchoolImmuneMask;
634 uint32 displayid = target->GetDisplayId();
635 uint32 nativeid = target->GetNativeDisplayId();
636 uint32 entry = target->GetEntry();
637 uint32 id1 = 0;
638 uint32 id2 = 0;
639 uint32 id3 = 0;
640 if (CreatureData const* cData = target->GetCreatureData())
641 {
642 id1 = cData->id1;
643 id2 = cData->id2;
644 id3 = cData->id3;
645 }
646
647 int64 curRespawnDelay = target->GetRespawnTimeEx() - GameTime::GetGameTime().count();
648 if (curRespawnDelay < 0)
649 curRespawnDelay = 0;
650 std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
651 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
652
653 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
654 handler->PSendSysMessage(LANG_NPCINFO_LEVEL, target->GetLevel());
656 handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
657 handler->PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUnitFlags(), target->GetUnitFlags2(), target->GetDynamicFlags(), target->GetFaction());
658 handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr, curRespawnDelayStr);
659 handler->PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid, cInfo->pickpocketLootId, cInfo->SkinLootId);
662 handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor());
663 handler->PSendSysMessage(LANG_NPCINFO_POSITION, float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
664 handler->PSendSysMessage(LANG_NPCINFO_AIINFO, target->GetAIName(), target->GetScriptName());
665
666 for (uint8 i = 0; i < NPCFLAG_COUNT; i++)
667 {
668 if (npcflags & npcFlagTexts[i].flag)
669 {
670 handler->PSendSysMessage(npcFlagTexts[i].text, npcFlagTexts[i].flag);
671 }
672 }
673
674 handler->PSendSysMessage(LANG_NPCINFO_MECHANIC_IMMUNE, mechanicImmuneMask);
675 for (uint8 i = 1; i < MAX_MECHANIC; ++i)
676 {
677 if (mechanicImmuneMask & (1 << (mechanicImmunes[i].flag - 1)))
678 {
679 handler->PSendSysMessage(mechanicImmunes[i].text, mechanicImmunes[i].flag);
680 }
681 }
682
683 handler->PSendSysMessage(LANG_NPCINFO_SPELL_SCHOOL_IMMUNE, spellSchoolImmuneMask);
684 for (uint8 i = 0; i < MAX_SPELL_SCHOOL; ++i)
685 {
686 if (spellSchoolImmuneMask & (1 << spellSchoolImmunes[i].flag))
687 {
688 handler->PSendSysMessage(spellSchoolImmunes[i].text, spellSchoolImmunes[i].flag);
689 }
690 }
691
692 return true;
693 }
std::uint64_t uint64
Definition Define.h:106
std::int64_t int64
Definition Define.h:102
@ LANG_NPCINFO_EQUIPMENT
Definition Language.h:1094
@ 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:1089
@ LANG_NPCINFO_SPELL_SCHOOL_IMMUNE
Definition Language.h:1125
@ LANG_NPCINFO_HEALTH
Definition Language.h:594
@ LANG_NPCINFO_PHASEMASK
Definition Language.h:1078
@ LANG_NPCINFO_LEVEL
Definition Language.h:593
@ LANG_COMMAND_RAWPAWNTIMES
Definition Language.h:647
@ LANG_NPCINFO_ARMOR
Definition Language.h:1079
@ LANG_NPCINFO_DUNGEON_ID
Definition Language.h:600
@ LANG_NPCINFO_MECHANIC_IMMUNE
Definition Language.h:1095
constexpr auto MAX_SPELL_SCHOOL
Definition SharedDefines.h:303
@ MAX_MECHANIC
Definition SharedDefines.h:1368
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
int8 GetOriginalEquipmentId() const
Definition Creature.h:195
uint8 GetCurrentEquipmentId()
Definition Creature.h:196
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:205
uint32 GetRespawnDelay() const
Definition Creature.h:293
std::string GetScriptName() const
Definition Creature.cpp:3004
time_t GetRespawnTimeEx() const
Definition Creature.cpp:2896
std::string const & GetAIName() const
Definition Creature.cpp:2999
uint32 GetMaxHealth() const
Definition Unit.h:1094
UnitFlags GetUnitFlags() const
Definition Unit.h:736
uint32 GetHealth() const
Definition Unit.h:1093
uint32 GetCreateHealth() const
Definition Unit.h:1097
uint32 GetArmor() const
Definition Unit.h:1142
uint8 GetLevel() const
Definition Unit.h:1088
UnitFlags2 GetUnitFlags2() const
Remove all UnitFlags and set new ones. UnitFlags available in UnitDefines.h.
Definition Unit.h:742
uint32 GetDynamicFlags() const override
Definition Unit.h:758
uint32 GetPhaseMask() const
Definition Object.h:512
uint32 GetInstanceId() const
Definition Object.h:509
NpcFlagText const npcFlagTexts[NPCFLAG_COUNT]
Definition cs_npc.cpp:46
SpellSchoolImmune const spellSchoolImmunes[MAX_SPELL_SCHOOL]
Definition cs_npc.cpp:122
MechanicImmune const mechanicImmunes[MAX_MECHANIC]
Definition cs_npc.cpp:80
#define NPCFLAG_COUNT
Definition cs_npc.cpp:44
Seconds GetGameTime()
Definition GameTime.cpp:38
Definition CreatureData.h:186
uint32 SkinLootId
Definition CreatureData.h:222
uint32 MechanicImmuneMask
Definition CreatureData.h:240
uint32 pickpocketLootId
Definition CreatureData.h:221
uint32 lootid
Definition CreatureData.h:220
uint8 SpellSchoolImmuneMask
Definition CreatureData.h:241

References 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(), ChatHandler::getSelectedCreature(), 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, LANG_SELECT_CREATURE, CreatureTemplate::lootid, MAX_MECHANIC, MAX_SPELL_SCHOOL, CreatureTemplate::MechanicImmuneMask, mechanicImmunes, NPCFLAG_COUNT, npcFlagTexts, CreatureTemplate::pickpocketLootId, ChatHandler::PSendSysMessage(), secsToTimeString(), ChatHandler::SendErrorMessage(), CreatureTemplate::SkinLootId, CreatureTemplate::SpellSchoolImmuneMask, spellSchoolImmunes, and ObjectGuid::ToString().

Referenced by GetCommands().

◆ HandleNpcLoadCommand()

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

References Creature::LoadCreatureFromDB(), CreatureData::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
774 {
775 Creature* creature;
776 if (guid.has_value())
777 creature = handler->GetCreatureFromPlayerMapByDbGuid(*guid);
778 else
779 creature = handler->getSelectedCreature();
780
781 if (!creature)
782 return false;
783
784 ObjectGuid::LowType lowGuid;
785 if (guid.has_value())
786 lowGuid = *guid;
787 else
788 lowGuid = creature->GetSpawnId();
789
790 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
791 if (!data)
792 {
794 return false;
795 }
796
797 if (handler->GetSession()->GetPlayer()->GetMapId() != data->mapid)
798 {
800 return false;
801 }
802
803 float x = handler->GetSession()->GetPlayer()->GetPositionX();
804 float y = handler->GetSession()->GetPlayer()->GetPositionY();
805 float z = handler->GetSession()->GetPlayer()->GetPositionZ();
806 float o = handler->GetSession()->GetPlayer()->GetOrientation();
807
808 if (creature)
809 {
810 if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetSpawnId()))
811 {
812 const_cast<CreatureData*>(data)->posX = x;
813 const_cast<CreatureData*>(data)->posY = y;
814 const_cast<CreatureData*>(data)->posZ = z;
815 const_cast<CreatureData*>(data)->orientation = o;
816 }
817
818 creature->SetPosition(x, y, z, o);
819 creature->GetMotionMaster()->Initialize();
820
821 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
822 {
824 creature->Respawn();
825 }
826 }
827
829 stmt->SetData(0, x);
830 stmt->SetData(1, y);
831 stmt->SetData(2, z);
832 stmt->SetData(3, o);
833 stmt->SetData(4, lowGuid);
834
835 WorldDatabase.Execute(stmt);
836
838 return true;
839 }
@ 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:1920
void Respawn(bool force=false)
Definition Creature.cpp:1991
void SetPosition(float x, float y, float z, float o)
Definition Creature.cpp:3115
void Initialize()
Definition MotionMaster.cpp:74
bool IsAlive() const
Definition Unit.h:1773
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, CreatureData::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
725 {
726 float distance = dist.value_or(10.0f);
727 uint32 count = 0;
728
729 Player* player = handler->GetSession()->GetPlayer();
730
732 stmt->SetData(0, player->GetPositionX());
733 stmt->SetData(1, player->GetPositionY());
734 stmt->SetData(2, player->GetPositionZ());
735 stmt->SetData(3, player->GetMapId());
736 stmt->SetData(4, player->GetPositionX());
737 stmt->SetData(5, player->GetPositionY());
738 stmt->SetData(6, player->GetPositionZ());
739 stmt->SetData(7, distance * distance);
740 stmt->SetData(8, player->GetPhaseMask());
741 PreparedQueryResult result = WorldDatabase.Query(stmt);
742
743 if (result)
744 {
745 do
746 {
747 Field* fields = result->Fetch();
748 ObjectGuid::LowType guid = fields[0].Get<uint32>();
749 uint32 entry = fields[1].Get<uint32>();
750 //uint32 entry2 = fields[2].Get<uint32>();
751 //uint32 entry3 = fields[3].Get<uint32>();
752 float x = fields[4].Get<float>();
753 float y = fields[5].Get<float>();
754 float z = fields[6].Get<float>();
755 uint16 mapId = fields[7].Get<uint16>();
756
757 CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
758 if (!creatureTemplate)
759 continue;
760
761 handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, entry, guid, creatureTemplate->Name, x, y, z, mapId, "", "");
762
763 ++count;
764 } while (result->NextRow());
765 }
766
767 handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
768
769 return true;
770 }
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
@ WORLD_SEL_CREATURE_NEAREST
Definition WorldDatabase.h:90
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

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, ChatHandler::PSendSysMessage(), PreparedStatementBase::SetData(), sObjectMgr, WORLD_SEL_CREATURE_NEAREST, and WorldDatabase.

Referenced by GetCommands().

◆ HandleNpcPlayEmoteCommand()

static bool npc_commandscript::HandleNpcPlayEmoteCommand ( ChatHandler handler,
uint32  emote 
)
inlinestatic
843 {
844 Creature* target = handler->getSelectedCreature();
845 if (!target)
846 {
848 return false;
849 }
850
851 target->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote);
852
853 return true;
854 }
@ UNIT_NPC_EMOTESTATE
Definition UpdateFields.h:140
void SetUInt32Value(uint16 index, uint32 value)
Definition Unit.cpp:21429

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
1101 {
1102 if (text.empty())
1103 return false;
1104
1105 Creature* creature = handler->getSelectedCreature();
1106 if (!creature)
1107 {
1109 return false;
1110 }
1111
1112 creature->Say(text, LANG_UNIVERSAL);
1113
1114 // make some emotes
1115 switch (text.back())
1116 {
1117 case '?': creature->HandleEmoteCommand(EMOTE_ONESHOT_QUESTION); break;
1118 case '!': creature->HandleEmoteCommand(EMOTE_ONESHOT_EXCLAMATION); break;
1119 default: creature->HandleEmoteCommand(EMOTE_ONESHOT_TALK); break;
1120 }
1121
1122 return true;
1123 }
@ EMOTE_ONESHOT_EXCLAMATION
Definition SharedDefines.h:1910
@ EMOTE_ONESHOT_QUESTION
Definition SharedDefines.h:1911
@ EMOTE_ONESHOT_TALK
Definition SharedDefines.h:1906
@ LANG_UNIVERSAL
Definition SharedDefines.h:746
virtual void Say(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:21246
void HandleEmoteCommand(uint32 emoteId)
Definition Unit.cpp:2036

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
374 {
375 if (sWorld->getAllowMovement())
376 {
377 sWorld->SetAllowMovement(false);
379 }
380 else
381 {
382 sWorld->SetAllowMovement(true);
384 }
385 return true;
386 }
@ 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
585 {
586 Creature* creature = handler->getSelectedCreature();
587
588 if (!creature)
589 {
591 return false;
592 }
593
594 creature->AI()->SetData(data_1, data_2);
595 std::string AIorScript = !creature->GetAIName().empty() ? "AI type: " + creature->GetAIName() : (!creature->GetScriptName().empty() ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set");
596 handler->PSendSysMessage(LANG_NPC_SETDATA, creature->GetGUID().ToString(), creature->GetEntry(), creature->GetName(), data_1, data_2, AIorScript);
597 return true;
598 }
@ 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
389 {
390 if (!newEntryNum)
391 return false;
392
393 Unit* unit = handler->getSelectedUnit();
394 if (!unit || !unit->IsCreature())
395 {
397 return false;
398 }
399 Creature* creature = unit->ToCreature();
400 if (creature->UpdateEntry(newEntryNum))
401 handler->SendSysMessage(LANG_DONE);
402 else
403 handler->SendSysMessage(LANG_ERROR);
404 return true;
405 }
@ 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:534
bool IsCreature() const
Definition Object.h:204
Creature * ToCreature()
Definition Object.h:205
Definition Unit.h:655

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
484 {
485 if (!sFactionTemplateStore.LookupEntry(factionId))
486 {
487 handler->SendErrorMessage(LANG_WRONG_FACTION, factionId);
488 return false;
489 }
490
491 Creature* creature = handler->getSelectedCreature();
492
493 if (!creature)
494 {
496 return false;
497 }
498
499 creature->SetFaction(factionId);
500
501 // Faction is set in creature_template - not inside creature
502
503 // Update in memory..
504 if (CreatureTemplate const* cinfo = creature->GetCreatureTemplate())
505 const_cast<CreatureTemplate*>(cinfo)->faction = factionId;
506
507 // ..and DB
509
510 stmt->SetData(0, uint16(factionId));
511 stmt->SetData(1, creature->GetEntry());
512
513 WorldDatabase.Execute(stmt);
514
515 return true;
516 }
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:10246

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
520 {
521 Player* player = handler->GetSession()->GetPlayer();
522 Unit* unit = player->GetSelectedUnit();
523
524 if (!unit)
525 return false;
526
527 Creature* creature = unit->ToCreature();
528
529 if (!creature)
530 return false;
531
532 creature->SetFaction(tempfaction);
533
534 return true;
535 }
Unit * GetSelectedUnit() const
Definition Player.cpp:11496

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
560 {
561 Creature* creature = handler->getSelectedCreature();
562
563 if (!creature)
564 {
566 return false;
567 }
568
569 creature->ReplaceAllNpcFlags(NPCFlags(npcFlags));
570
572
573 stmt->SetData(0, NPCFlags(npcFlags));
574 stmt->SetData(1, creature->GetEntry());
575
576 WorldDatabase.Execute(stmt);
577
579
580 return true;
581 }
@ LANG_VALUE_SAVED_REJOIN
Definition Language.h:310
NPCFlags
Non Player Character flags.
Definition UnitDefines.h:317
@ WORLD_UPD_CREATURE_NPCFLAG
Definition WorldDatabase.h:48
void ReplaceAllNpcFlags(NPCFlags flags)
Definition Unit.h:756

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
409 {
410 if (lvl < 1 || lvl > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL) + 3)
411 {
413 return false;
414 }
415
416 Creature* creature = handler->getSelectedCreature();
417 if (!creature || creature->IsPet())
418 {
420 return false;
421 }
422
423 creature->SetMaxHealth(100 + 30*lvl);
424 creature->SetHealth(100 + 30*lvl);
425 creature->SetLevel(lvl);
426 creature->SaveToDB();
427
428 return true;
429 }
@ LANG_BAD_VALUE
Definition Language.h:148
@ CONFIG_MAX_PLAYER_LEVEL
Definition WorldConfig.h:190
void SetHealth(uint32 val)
Definition Unit.cpp:15726
void SetLevel(uint8 lvl, bool showLevelChange=true)
Definition Unit.cpp:15708
void SetMaxHealth(uint32 val)
Definition Unit.cpp:15776

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
1329 {
1330 Creature* creature = handler->getSelectedCreature();
1331
1332 if (!creature)
1333 {
1335 return false;
1336 }
1337
1338 if (!creature->GetSpawnId())
1339 {
1340 handler->SendErrorMessage("Selected creature {} isn't in creature table", creature->GetGUID().ToString());
1341 return false;
1342 }
1343
1344 if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetSpawnId(), linkguid))
1345 {
1346 handler->SendErrorMessage("Selected creature can't link with guid '{}'", linkguid);
1347 return false;
1348 }
1349
1350 handler->PSendSysMessage("LinkGUID '{}' added to creature with DBTableGUID: '{}'", linkguid, creature->GetSpawnId());
1351 return true;
1352 }

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
858 {
859 Creature* creature = handler->getSelectedCreature();
860
861 if (!creature || creature->IsPet())
862 {
864 return false;
865 }
866
867 if (!sCreatureDisplayInfoStore.LookupEntry(displayId))
868 {
870 return false;
871 }
872
873 creature->SetDisplayId(displayId);
874 creature->SetNativeDisplayId(displayId);
875 creature->SaveToDB();
876
877 return true;
878 }
DBCStorage< CreatureDisplayInfoEntry > sCreatureDisplayInfoStore(CreatureDisplayInfofmt)
@ LANG_COMMAND_FACTION_INVPARAM
Definition Language.h:356
void SetDisplayId(uint32 displayId, float displayScale=1.f) override
Definition Creature.cpp:3355
void SetNativeDisplayId(uint32 displayId)
Definition Unit.h:1957
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

893 {
894 // 3 arguments:
895 // GUID (optional - you can also select the creature)
896 // stay|random|way (determines the kind of movement)
897 // NODEL (optional - tells the system NOT to delete any waypoints)
898 // this is very handy if you want to do waypoints, that are
899 // later switched on/off according to special events (like escort
900 // quests, etc)
901
902 bool doNotDelete = nodel.has_value();
903
904 ObjectGuid::LowType lowguid = 0;
905 Creature* creature = nullptr;
906
907 if (!lowGuid) // case .setmovetype $move_type (with selected creature)
908 {
909 creature = handler->getSelectedCreature();
910 if (!creature || creature->IsPet())
911 return false;
912 lowguid = creature->GetSpawnId();
913 }
914 else // case .setmovetype #creature_guid $move_type (with selected creature)
915 {
916 lowguid = *lowGuid;
917
918 if (lowguid)
919 creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
920
921 // attempt check creature existence by DB data
922 if (!creature)
923 {
924 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
925 if (!data)
926 {
928 return false;
929 }
930 }
931 else
932 {
933 lowguid = creature->GetSpawnId();
934 }
935 }
936
937 // now lowguid is low guid really existed creature
938 // and creature point (maybe) to this creature or nullptr
939
940 MovementGeneratorType move_type;
941 switch (type.index())
942 {
943 case 0:
944 move_type = IDLE_MOTION_TYPE;
945 break;
946 case 1:
947 move_type = RANDOM_MOTION_TYPE;
948 break;
949 case 2:
950 move_type = WAYPOINT_MOTION_TYPE;
951 break;
952 default:
953 return false;
954 }
955
956 // update movement type
957 //if (doNotDelete == false)
958 // WaypointMgr.DeletePath(lowguid);
959
960 if (creature)
961 {
962 // update movement type
963 if (!doNotDelete)
964 creature->LoadPath(0);
965
966 creature->SetDefaultMovementType(move_type);
967 creature->GetMotionMaster()->Initialize();
968
969 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
970 {
972 creature->Respawn();
973 }
974
975 creature->SaveToDB();
976 }
977
978 if (!doNotDelete)
979 {
980 handler->PSendSysMessage(LANG_MOVE_TYPE_SET, move_type);
981 }
982 else
983 {
984 handler->PSendSysMessage(LANG_MOVE_TYPE_SET_NODEL, move_type);
985 }
986
987 return true;
988 }
@ 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:349

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
539 {
540 Player* player = handler->GetSession()->GetPlayer();
541
542 if (!player)
543 return false;
544
545 if (!player->GetSelectedUnit())
546 return false;
547
548 Creature* creature = player->GetSelectedUnit()->ToCreature();
549
550 if (!creature)
551 return false;
552
553 creature->RestoreFaction();
554
555 return true;
556 }
void RestoreFaction()
Definition Unit.cpp:18957

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
993 {
994 if (phasemask == 0)
995 {
997 return false;
998 }
999
1000 Creature* creature = handler->getSelectedCreature();
1001 if (!creature)
1002 {
1004 return false;
1005 }
1006
1007 creature->SetPhaseMask(phasemask, true);
1008
1009 if (!creature->IsPet())
1010 creature->SaveToDB();
1011
1012 return true;
1013 }
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition Unit.cpp:19311

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
1061 {
1062 if (spawnTimeStr.empty())
1063 {
1064 return false;
1065 }
1066
1067 if (Acore::StringTo<int32>(spawnTimeStr).value_or(0) < 0)
1068 {
1070 return false;
1071 }
1072
1073 Creature* creature = handler->getSelectedCreature();
1074 if (!creature)
1075 return false;
1076
1077 int32 spawnTime = TimeStringToSecs(spawnTimeStr);
1078 if (spawnTime <= 0)
1079 {
1080 spawnTime = Acore::StringTo<int32>(spawnTimeStr).value_or(0);
1081 }
1082
1083 if (spawnTime <= 0)
1084 {
1086 return false;
1087 }
1088
1090 stmt->SetData(0, spawnTime);
1091 stmt->SetData(1, creature->GetSpawnId());
1092 WorldDatabase.Execute(stmt);
1093
1094 creature->SetRespawnDelay(spawnTime);
1095 handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, secsToTimeString(spawnTime, true));
1096
1097 return true;
1098 }
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:294

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
1017 {
1018 if (option < 0.0f)
1019 {
1021 return false;
1022 }
1023
1025
1026 if (option > 0.0f)
1027 mtype = RANDOM_MOTION_TYPE;
1028
1029 Creature* creature = handler->getSelectedCreature();
1030 ObjectGuid::LowType guidLow = 0;
1031
1032 if (creature)
1033 guidLow = creature->GetSpawnId();
1034 else
1035 return false;
1036
1037 creature->SetWanderDistance((float)option);
1038 creature->SetDefaultMovementType(mtype);
1039 creature->GetMotionMaster()->Initialize();
1040
1041 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
1042 {
1044 creature->Respawn();
1045 }
1046
1048
1049 stmt->SetData(0, option);
1050 stmt->SetData(1, uint8(mtype));
1051 stmt->SetData(2, guidLow);
1052
1053 WorldDatabase.Execute(stmt);
1054
1056 return true;
1057 }
@ LANG_COMMAND_WANDER_DISTANCE
Definition Language.h:342
@ WORLD_UPD_CREATURE_WANDER_DISTANCE
Definition WorldDatabase.h:50
void SetWanderDistance(float dist)
Definition Creature.h:305

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
1235 {
1236 Creature* creatureTarget = handler->getSelectedCreature();
1237 if (!creatureTarget || creatureTarget->IsPet())
1238 {
1240 handler->SetSentErrorMessage(true);
1241 return false;
1242 }
1243
1244 Player* player = handler->GetSession()->GetPlayer();
1245
1246 if (player->IsExistPet())
1247 {
1249 return false;
1250 }
1251
1252 CreatureTemplate const* cInfo = creatureTarget->GetCreatureTemplate();
1253
1254 if (!cInfo->IsTameable(player->CanTameExoticPets()))
1255 {
1257 handler->SetSentErrorMessage (true);
1258 return false;
1259 }
1260
1261 if (!player->CreatePet(creatureTarget))
1262 {
1264 return false;
1265 }
1266
1267 return true;
1268 }
@ LANG_CREATURE_NON_TAMEABLE
Definition Language.h:390
@ LANG_YOU_ALREADY_HAVE_PET
Definition Language.h:391
bool IsExistPet()
Definition Player.cpp:9228
bool CanTameExoticPets() const
Definition Player.h:2182
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition Player.cpp:9234
uint32 Entry
Definition CreatureData.h:187
bool IsTameable(bool exotic) const
Definition CreatureData.h:270

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
1127 {
1128 if (text.empty())
1129 return false;
1130
1131 Creature* creature = handler->getSelectedCreature();
1132
1133 if (!creature)
1134 {
1136 return false;
1137 }
1138
1139 creature->TextEmote(text);
1140
1141 return true;
1142 }
virtual void TextEmote(std::string_view text, WorldObject const *target=nullptr, bool isBossEmote=false)
Definition Unit.cpp:21256

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

Referenced by GetCommands().

◆ HandleNpcUnFollowCommand()

static bool npc_commandscript::HandleNpcUnFollowCommand ( ChatHandler handler)
inlinestatic
1146 {
1147 Player* player = handler->GetSession()->GetPlayer();
1148 Creature* creature = handler->getSelectedCreature();
1149
1150 if (!creature)
1151 {
1153 return false;
1154 }
1155
1156 if (/*creature->GetMotionMaster()->empty() ||*/
1158 {
1159 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1160 return false;
1161 }
1162
1163 FollowMovementGenerator<Creature> const* mgen = static_cast<FollowMovementGenerator<Creature> const*>((creature->GetMotionMaster()->top()));
1164
1165 if (mgen->GetTarget() != player)
1166 {
1167 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1168 return false;
1169 }
1170
1171 // reset movement
1172 creature->GetMotionMaster()->MovementExpired(true);
1173
1175 return true;
1176 }
@ 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:91
Unit * GetTarget() const
Definition TargetedMovementGenerator.h:105
_Ty top() const
Definition MotionMaster.h:175
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition MotionMaster.cpp:949
void MovementExpired(bool reset=true)
Definition MotionMaster.h:205

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
1180 {
1181 if (text.empty())
1182 return false;
1183
1184 Creature* creature = handler->getSelectedCreature();
1185 if (!creature)
1186 {
1188 return false;
1189 }
1190
1191 // check online security
1192 Player* receiver = ObjectAccessor::FindPlayerByName(recv);
1193 if (handler->HasLowerSecurity(receiver, ObjectGuid::Empty))
1194 return false;
1195
1196 creature->Whisper(text, LANG_UNIVERSAL, receiver);
1197 return true;
1198 }
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:21261
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
1201 {
1202 if (text.empty())
1203 return false;
1204
1205 Creature* creature = handler->getSelectedCreature();
1206 if (!creature)
1207 {
1209 return false;
1210 }
1211
1212 creature->Yell(text, LANG_UNIVERSAL);
1213
1214 // make an emote
1216
1217 return true;
1218 }
@ EMOTE_ONESHOT_SHOUT
Definition SharedDefines.h:1925
virtual void Yell(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition Unit.cpp:21251

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: