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
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- 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 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)
 
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)
 
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 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
134: CommandScript("npc_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable npc_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

137 {
138 static ChatCommandTable npcAddCommandTable =
139 {
140 { "formation", HandleNpcAddFormationCommand, SEC_ADMINISTRATOR, Console::No },
141 { "item", HandleNpcAddVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
142 { "move", HandleNpcAddMoveCommand, SEC_ADMINISTRATOR, Console::No },
143 { "temp", HandleNpcAddTempSpawnCommand, SEC_ADMINISTRATOR, Console::No },
144 { "", HandleNpcAddCommand, SEC_ADMINISTRATOR, Console::No }
145 };
146 static ChatCommandTable npcDeleteCommandTable =
147 {
148 { "item", HandleNpcDeleteVendorItemCommand, SEC_ADMINISTRATOR, Console::No },
149 { "", HandleNpcDeleteCommand, SEC_ADMINISTRATOR, Console::No }
150 };
151 static ChatCommandTable npcFollowCommandTable =
152 {
153 { "stop", HandleNpcUnFollowCommand, SEC_GAMEMASTER, Console::No },
154 { "", HandleNpcFollowCommand, SEC_GAMEMASTER, Console::No }
155 };
156
157 static ChatCommandTable npcFactionCommandTable =
158 {
159 { "permanent", HandleNpcSetFactionIdCommand, SEC_ADMINISTRATOR, Console::No },
160 { "temp", HandleNpcSetFactionTempIdCommand, SEC_ADMINISTRATOR, Console::No },
161 { "original", HandleNpcSetOriginalFaction, SEC_ADMINISTRATOR, Console::No }
162 };
163
164 static ChatCommandTable npcSetCommandTable =
165 {
166 { "allowmove", HandleNpcSetAllowMovementCommand, SEC_ADMINISTRATOR, Console::No },
167 { "entry", HandleNpcSetEntryCommand, SEC_ADMINISTRATOR, Console::No },
168 { "faction", npcFactionCommandTable},
169 { "flag", HandleNpcSetFlagCommand, SEC_ADMINISTRATOR, Console::No },
170 { "level", HandleNpcSetLevelCommand, SEC_ADMINISTRATOR, Console::No },
171 { "link", HandleNpcSetLinkCommand, SEC_ADMINISTRATOR, Console::No },
172 { "model", HandleNpcSetModelCommand, SEC_ADMINISTRATOR, Console::No },
173 { "movetype", HandleNpcSetMoveTypeCommand, SEC_ADMINISTRATOR, Console::No },
174 { "phase", HandleNpcSetPhaseCommand, SEC_ADMINISTRATOR, Console::No },
175 { "wanderdistance", HandleNpcSetWanderDistanceCommand, SEC_ADMINISTRATOR, Console::No },
176 { "spawntime", HandleNpcSetSpawnTimeCommand, SEC_ADMINISTRATOR, Console::No },
177 { "data", HandleNpcSetDataCommand, SEC_ADMINISTRATOR, Console::No }
178 };
179 static ChatCommandTable npcCommandTable =
180 {
181 { "info", HandleNpcInfoCommand, SEC_GAMEMASTER, Console::No },
182 { "guid", HandleNpcGuidCommand, SEC_GAMEMASTER, Console::No },
183 { "near", HandleNpcNearCommand, SEC_GAMEMASTER, Console::No },
184 { "move", HandleNpcMoveCommand, SEC_GAMEMASTER, Console::No },
185 { "playemote", HandleNpcPlayEmoteCommand, SEC_GAMEMASTER, Console::No },
186 { "say", HandleNpcSayCommand, SEC_GAMEMASTER, Console::No },
187 { "textemote", HandleNpcTextEmoteCommand, SEC_GAMEMASTER, Console::No },
188 { "whisper", HandleNpcWhisperCommand, SEC_GAMEMASTER, Console::No },
189 { "yell", HandleNpcYellCommand, SEC_GAMEMASTER, Console::No },
190 { "tame", HandleNpcTameCommand, SEC_GAMEMASTER, Console::No },
191 { "add", npcAddCommandTable },
192 { "delete", npcDeleteCommandTable },
193 { "follow", npcFollowCommandTable },
194 { "set", npcSetCommandTable }
195 };
196 static ChatCommandTable commandTable =
197 {
198 { "npc", npcCommandTable }
199 };
200 return commandTable;
201 }
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleNpcDeleteCommand(ChatHandler *handler)
Definition: cs_npc.cpp:376
static bool HandleNpcMoveCommand(ChatHandler *handler)
Definition: cs_npc.cpp:714
static bool HandleNpcWhisperCommand(ChatHandler *handler, std::string const &recv, Tail text)
Definition: cs_npc.cpp:1112
static bool HandleNpcAddFormationCommand(ChatHandler *handler, ObjectGuid::LowType leaderGUID)
Definition: cs_npc.cpp:1203
static bool HandleNpcAddTempSpawnCommand(ChatHandler *handler, CreatureEntry id)
Definition: cs_npc.cpp:1154
static bool HandleNpcSetFactionTempIdCommand(ChatHandler *handler, uint32 tempfaction)
Definition: cs_npc.cpp:460
static bool HandleNpcSetWanderDistanceCommand(ChatHandler *handler, float option)
Definition: cs_npc.cpp:949
static bool HandleNpcAddCommand(ChatHandler *handler, CreatureEntry id)
Definition: cs_npc.cpp:204
static bool HandleNpcSetOriginalFaction(ChatHandler *handler)
Definition: cs_npc.cpp:479
static bool HandleNpcTameCommand(ChatHandler *handler)
Definition: cs_npc.cpp:1167
static bool HandleNpcTextEmoteCommand(ChatHandler *handler, Tail text)
Definition: cs_npc.cpp:1059
static bool HandleNpcSetModelCommand(ChatHandler *handler, uint32 displayId)
Definition: cs_npc.cpp:790
static bool HandleNpcYellCommand(ChatHandler *handler, Tail text)
Definition: cs_npc.cpp:1133
static bool HandleNpcGuidCommand(ChatHandler *handler)
Definition: cs_npc.cpp:635
static bool HandleNpcSetPhaseCommand(ChatHandler *handler, uint32 phasemask)
Definition: cs_npc.cpp:925
static bool HandleNpcFollowCommand(ChatHandler *handler)
Definition: cs_npc.cpp:542
static bool HandleNpcPlayEmoteCommand(ChatHandler *handler, uint32 emote)
Definition: cs_npc.cpp:775
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:825
static bool HandleNpcUnFollowCommand(ChatHandler *handler)
Definition: cs_npc.cpp:1078
static bool HandleNpcSetLevelCommand(ChatHandler *handler, uint8 lvl)
Definition: cs_npc.cpp:353
static bool HandleNpcSetAllowMovementCommand(ChatHandler *handler)
Definition: cs_npc.cpp:318
static bool HandleNpcSayCommand(ChatHandler *handler, Tail text)
Definition: cs_npc.cpp:1033
static bool HandleNpcInfoCommand(ChatHandler *handler)
Definition: cs_npc.cpp:560
static bool HandleNpcNearCommand(ChatHandler *handler, Optional< float > dist)
Definition: cs_npc.cpp:665
static bool HandleNpcSetSpawnTimeCommand(ChatHandler *handler, std::string spawnTimeStr)
Definition: cs_npc.cpp:993
static bool HandleNpcSetDataCommand(ChatHandler *handler, uint32 data_1, uint32 data_2)
Definition: cs_npc.cpp:525
static bool HandleNpcAddVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< uint32 > mc, Optional< uint32 > it, Optional< uint32 > ec, Optional< bool > addMulti)
Definition: cs_npc.cpp:263
static bool HandleNpcDeleteVendorItemCommand(ChatHandler *handler, ItemTemplate const *item, Optional< bool > addMulti)
Definition: cs_npc.cpp:397
static bool HandleNpcSetFlagCommand(ChatHandler *handler, uint32 npcFlags)
Definition: cs_npc.cpp:500
static bool HandleNpcSetLinkCommand(ChatHandler *handler, ObjectGuid::LowType linkguid)
Definition: cs_npc.cpp:1247
static bool HandleNpcSetFactionIdCommand(ChatHandler *handler, uint32 factionId)
Definition: cs_npc.cpp:424
static bool HandleNpcSetEntryCommand(ChatHandler *handler, CreatureEntry newEntryNum)
Definition: cs_npc.cpp:333
static bool HandleNpcAddMoveCommand(ChatHandler *handler, CreatureSpawnId lowGuid)
Definition: cs_npc.cpp:297

References HandleNpcAddCommand(), HandleNpcAddFormationCommand(), HandleNpcAddMoveCommand(), HandleNpcAddTempSpawnCommand(), HandleNpcAddVendorItemCommand(), HandleNpcDeleteCommand(), HandleNpcDeleteVendorItemCommand(), HandleNpcFollowCommand(), HandleNpcGuidCommand(), HandleNpcInfoCommand(), 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
205 {
206 if (!sObjectMgr->GetCreatureTemplate(id))
207 return false;
208
209 Player* chr = handler->GetSession()->GetPlayer();
210 float x = chr->GetPositionX();
211 float y = chr->GetPositionY();
212 float z = chr->GetPositionZ();
213 float o = chr->GetOrientation();
214 Map* map = chr->GetMap();
215
216 if (Transport* tt = chr->GetTransport())
217 if (MotionTransport* trans = tt->ToMotionTransport())
218 {
219 ObjectGuid::LowType guid = sObjectMgr->GenerateCreatureSpawnId();
220 CreatureData& data = sObjectMgr->NewOrExistCreatureData(guid);
221 data.id1 = id;
222 data.phaseMask = chr->GetPhaseMaskForSpawn();
223 data.posX = chr->GetTransOffsetX();
224 data.posY = chr->GetTransOffsetY();
225 data.posZ = chr->GetTransOffsetZ();
226 data.orientation = chr->GetTransOffsetO();
227
228 Creature* creature = trans->CreateNPCPassenger(guid, &data);
229
230 creature->SaveToDB(trans->GetGOInfo()->moTransport.mapID, 1 << map->GetSpawnMode(), chr->GetPhaseMaskForSpawn());
231
232 sObjectMgr->AddCreatureToGrid(guid, &data);
233 return true;
234 }
235
236 Creature* creature = new Creature();
237 if (!creature->Create(map->GenerateLowGuid<HighGuid::Unit>(), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
238 {
239 delete creature;
240 return false;
241 }
242
243 creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
244
245 ObjectGuid::LowType spawnId = creature->GetSpawnId();
246
247 // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells()
248 // current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
249 creature->CleanupsBeforeDelete();
250 delete creature;
251 creature = new Creature();
252 if (!creature->LoadCreatureFromDB(spawnId, map, true, true))
253 {
254 delete creature;
255 return false;
256 }
257
258 sObjectMgr->AddCreatureToGrid(spawnId, sObjectMgr->GetCreatureData(spawnId));
259 return true;
260 }
#define sObjectMgr
Definition: ObjectMgr.h:1635
WorldSession * GetSession()
Definition: Chat.h:242
Definition: Creature.h:43
bool LoadCreatureFromDB(ObjectGuid::LowType guid, Map *map, bool addToMap=true, bool allowDuplicate=false)
Definition: Creature.cpp:1692
ObjectGuid::LowType GetSpawnId() const
Definition: Creature.h:65
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:1126
void SaveToDB()
Definition: Creature.cpp:1393
Definition: CreatureData.h:370
uint32 phaseMask
Definition: CreatureData.h:376
float orientation
Definition: CreatureData.h:382
float posY
Definition: CreatureData.h:380
float posX
Definition: CreatureData.h:379
float posZ
Definition: CreatureData.h:381
uint32 id1
Definition: CreatureData.h:372
MotionTransport * ToMotionTransport()
Definition: GameObject.h:327
Map * GetMap() const
Definition: Object.h:531
float GetTransOffsetX() const
Definition: Object.h:600
float GetTransOffsetY() const
Definition: Object.h:601
float GetTransOffsetZ() const
Definition: Object.h:602
Transport * GetTransport() const
Definition: Object.h:599
float GetTransOffsetO() const
Definition: Object.h:603
uint32 LowType
Definition: ObjectGuid.h:122
float GetPositionZ() const
Definition: Position.h:118
float GetOrientation() const
Definition: Position.h:119
float GetPositionX() const
Definition: Position.h:116
float GetPositionY() const
Definition: Position.h:117
Definition: Player.h:1064
uint32 GetPhaseMaskForSpawn() const
Definition: Player.cpp:13780
Definition: Transport.h:29
Definition: Transport.h:48
void CleanupsBeforeDelete(bool finalCleanup=true) override
Definition: Unit.cpp:15772
Definition: Map.h:311
uint8 GetSpawnMode() const
Definition: Map.h:418
ObjectGuid::LowType GenerateLowGuid()
Definition: Map.h:636
uint32 GetId() const
Definition: Map.h:377
Player * GetPlayer() const
Definition: WorldSession.h:362

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, and GameObject::ToMotionTransport().

Referenced by GetCommands().

◆ HandleNpcAddFormationCommand()

static bool npc_commandscript::HandleNpcAddFormationCommand ( ChatHandler handler,
ObjectGuid::LowType  leaderGUID 
)
inlinestatic
1204 {
1205 Creature* creature = handler->getSelectedCreature();
1206
1207 if (!creature || !creature->GetSpawnId())
1208 {
1210 return false;
1211 }
1212
1213 ObjectGuid::LowType lowguid = creature->GetSpawnId();
1214 if (creature->GetFormation())
1215 {
1216 handler->PSendSysMessage("Selected creature is already member of group {}", creature->GetFormation()->GetId());
1217 return false;
1218 }
1219
1220 if (!lowguid)
1221 return false;
1222
1223 Player* chr = handler->GetSession()->GetPlayer();
1224 FormationInfo group_member;
1225 group_member.follow_angle = (creature->GetAngle(chr) - chr->GetOrientation()) * 180 / M_PI;
1226 group_member.follow_dist = sqrtf(pow(chr->GetPositionX() - creature->GetPositionX(), int(2)) + pow(chr->GetPositionY() - creature->GetPositionY(), int(2)));
1227 group_member.leaderGUID = leaderGUID;
1228 group_member.groupAI = 0;
1229
1230 sFormationMgr->CreatureGroupMap[lowguid] = group_member;
1231 creature->SearchFormation();
1232
1234 stmt->SetData(0, leaderGUID);
1235 stmt->SetData(1, lowguid);
1236 stmt->SetData(2, group_member.follow_dist);
1237 stmt->SetData(3, group_member.follow_angle);
1238 stmt->SetData(4, uint32(group_member.groupAI));
1239
1240 WorldDatabase.Execute(stmt);
1241
1242 handler->PSendSysMessage("Creature {} added to formation with leader {}", lowguid, leaderGUID);
1243
1244 return true;
1245 }
std::uint32_t uint32
Definition: Define.h:107
@ LANG_SELECT_CREATURE
Definition: Language.h:32
#define sFormationMgr
Definition: CreatureGroups.h:127
@ WORLD_INS_CREATURE_FORMATION
Definition: WorldDatabase.h:52
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
Creature * getSelectedCreature() const
Definition: Chat.cpp:409
CreatureGroup const * GetFormation() const
Definition: Creature.h:353
void SearchFormation()
Definition: Creature.cpp:380
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
uint32 GetId() const
Definition: CreatureGroups.h:100
float GetAngle(const Position *pos) const
Definition: Position.cpp:78

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
298 {
299 // attempt check creature existence by DB data
300 CreatureData const* data = sObjectMgr->GetCreatureData(lowGuid);
301 if (!data)
302 {
304 return false;
305 }
306
307 // Update movement type
310 stmt->SetData(1, uint32(lowGuid));
311 WorldDatabase.Execute(stmt);
312
314
315 return true;
316 }
std::uint8_t uint8
Definition: Define.h:109
@ LANG_WAYPOINT_ADDED
Definition: Language.h:275
@ LANG_COMMAND_CREATGUIDNOTFOUND
Definition: Language.h:332
@ 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:159

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
1155 {
1156 Player* chr = handler->GetSession()->GetPlayer();
1157
1158 if (!id)
1159 return false;
1160
1161 chr->SummonCreature(id, *chr, TEMPSUMMON_CORPSE_DESPAWN, 120);
1162
1163 return true;
1164 }
@ TEMPSUMMON_CORPSE_DESPAWN
Definition: Object.h:49
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:2355

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
264 {
265 if (!item)
266 {
268 return false;
269 }
270
271 Creature* vendor = handler->getSelectedCreature();
272 if (!vendor)
273 {
275 return false;
276 }
277
278 uint32 itemId = item->ItemId;
279 uint32 maxcount = mc.value_or(0);
280 uint32 incrtime = it.value_or(0);
281 uint32 extendedcost = ec.value_or(0);
282 uint32 vendor_entry = addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry();
283
284 if (!sObjectMgr->IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, handler->GetSession()->GetPlayer()))
285 {
286 handler->SetSentErrorMessage(true);
287 return false;
288 }
289
290 sObjectMgr->AddVendorItem(vendor_entry, itemId, maxcount, incrtime, extendedcost);
291
292 handler->PSendSysMessage(LANG_ITEM_ADDED_TO_LIST, itemId, item->Name1, maxcount, incrtime, extendedcost);
293 return true;
294 }
@ LANG_COMMAND_NEEDITEMSEND
Definition: Language.h:324
@ LANG_ITEM_ADDED_TO_LIST
Definition: Language.h:244
void SetSentErrorMessage(bool val)
Definition: Chat.h:238
uint32 GetEntry() const
Definition: Object.h:112
uint32 GetCurrentVendor() const
Definition: WorldSession.h:366

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)
inlinestatic
377 {
378 Creature* unit = handler->getSelectedCreature();
379
380 if (!unit || unit->IsPet() || unit->IsTotem())
381 {
383 return false;
384 }
385
386 // Delete the creature
387 unit->CombatStop();
388 unit->DeleteFromDB();
389 unit->AddObjectToRemoveList();
390
392
393 return true;
394 }
@ LANG_COMMAND_DELCREATMESSAGE
Definition: Language.h:315
virtual void DeleteFromDB()
Definition: Creature.cpp:1842
void AddObjectToRemoveList()
Definition: Object.cpp:2149
void CombatStop(bool includingCast=false)
Definition: Unit.cpp:10436
bool IsPet() const
Definition: Unit.h:754
bool IsTotem() const
Definition: Unit.h:756

References WorldObject::AddObjectToRemoveList(), Unit::CombatStop(), Creature::DeleteFromDB(), 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
398 {
399 Creature* vendor = handler->getSelectedCreature();
400 if (!vendor || !vendor->IsVendor())
401 {
403 return false;
404 }
405
406 if (!item)
407 {
409 return false;
410 }
411
412 uint32 itemId = item->ItemId;
413 if (!sObjectMgr->RemoveVendorItem(addMulti.value_or(false) ? handler->GetSession()->GetCurrentVendor() : vendor->GetEntry(), itemId))
414 {
415 handler->SendErrorMessage(LANG_ITEM_NOT_IN_LIST, itemId);
416 return false;
417 }
418
419 handler->PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST, itemId, item->Name1);
420 return true;
421 }
@ LANG_COMMAND_VENDORSELECTION
Definition: Language.h:323
@ LANG_ITEM_DELETED_FROM_LIST
Definition: Language.h:246
@ LANG_ITEM_NOT_IN_LIST
Definition: Language.h:247
bool IsVendor() const
Definition: Unit.h:760

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().

◆ HandleNpcFollowCommand()

static bool npc_commandscript::HandleNpcFollowCommand ( ChatHandler handler)
inlinestatic
543 {
544 Player* player = handler->GetSession()->GetPlayer();
545 Creature* creature = handler->getSelectedCreature();
546
547 if (!creature)
548 {
550 return false;
551 }
552
553 // Follow player - Using pet's default dist and angle
554 creature->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, creature->GetFollowAngle());
555
557 return true;
558 }
@ LANG_CREATURE_FOLLOW_YOU_NOW
Definition: Language.h:381
#define PET_FOLLOW_DIST
Definition: PetDefines.h:198
std::string const & GetName() const
Definition: Object.h:458
MotionMaster * GetMotionMaster()
Definition: Unit.h:1620
virtual float GetFollowAngle() const
Definition: Unit.h:1756
void MoveFollow(Unit *target, float dist, float angle, MovementSlot slot=MOTION_SLOT_ACTIVE, bool inheritWalkState=true)
The unit will follow this target. Doesn't work with UNIT_FLAG_DISABLE_MOVE.
Definition: MotionMaster.cpp:409

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
636 {
637 Creature* target = handler->getSelectedCreature();
638
639 if (!target)
640 {
642 return false;
643 }
644
645 uint32 faction = target->GetFaction();
646 uint32 npcflags = target->GetNpcFlags();
647 uint32 displayid = target->GetDisplayId();
648 uint32 nativeid = target->GetNativeDisplayId();
649 uint32 entry = target->GetEntry();
650 uint32 id1 = 0;
651 uint32 id2 = 0;
652 uint32 id3 = 0;
653 if (CreatureData const* cData = target->GetCreatureData())
654 {
655 id1 = cData->id1;
656 id2 = cData->id2;
657 id3 = cData->id3;
658 }
659
660 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
661
662 return true;
663 }
@ LANG_NPCINFO_CHAR
Definition: Language.h:586
CreatureData const * GetCreatureData() const
Definition: Creature.h:206
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109
std::string ToString() const
Definition: ObjectGuid.cpp:47
NPCFlags GetNpcFlags() const
Definition: Unit.h:724
uint32 GetFaction() const
Definition: Unit.h:808
uint32 GetDisplayId() const
Definition: Unit.h:1837
uint32 GetNativeDisplayId() const
Definition: Unit.h:1839

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
561 {
562 Creature* target = handler->getSelectedCreature();
563
564 if (!target)
565 {
567 return false;
568 }
569
570 CreatureTemplate const* cInfo = target->GetCreatureTemplate();
571 uint32 faction = target->GetFaction();
572 uint32 npcflags = target->GetNpcFlags();
573 uint32 mechanicImmuneMask = cInfo->MechanicImmuneMask;
574 uint32 spellSchoolImmuneMask = cInfo->SpellSchoolImmuneMask;
575 uint32 displayid = target->GetDisplayId();
576 uint32 nativeid = target->GetNativeDisplayId();
577 uint32 entry = target->GetEntry();
578 uint32 id1 = 0;
579 uint32 id2 = 0;
580 uint32 id3 = 0;
581 if (CreatureData const* cData = target->GetCreatureData())
582 {
583 id1 = cData->id1;
584 id2 = cData->id2;
585 id3 = cData->id3;
586 }
587
588 int64 curRespawnDelay = target->GetRespawnTimeEx() - GameTime::GetGameTime().count();
589 if (curRespawnDelay < 0)
590 curRespawnDelay = 0;
591 std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
592 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
593
594 handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetSpawnId(), target->GetGUID().ToString(), entry, id1, id2, id3, displayid, nativeid, faction, npcflags);
595 handler->PSendSysMessage(LANG_NPCINFO_LEVEL, target->GetLevel());
597 handler->PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
598 handler->PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUnitFlags(), target->GetUnitFlags2(), target->GetDynamicFlags(), target->GetFaction());
599 handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr, curRespawnDelayStr);
600 handler->PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid, cInfo->pickpocketLootId, cInfo->SkinLootId);
603 handler->PSendSysMessage(LANG_NPCINFO_ARMOR, target->GetArmor());
604 handler->PSendSysMessage(LANG_NPCINFO_POSITION, float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
605 handler->PSendSysMessage(LANG_NPCINFO_AIINFO, target->GetAIName(), target->GetScriptName());
606
607 for (uint8 i = 0; i < NPCFLAG_COUNT; i++)
608 {
609 if (npcflags & npcFlagTexts[i].flag)
610 {
611 handler->PSendSysMessage(npcFlagTexts[i].text, npcFlagTexts[i].flag);
612 }
613 }
614
615 handler->PSendSysMessage(LANG_NPCINFO_MECHANIC_IMMUNE, mechanicImmuneMask);
616 for (uint8 i = 1; i < MAX_MECHANIC; ++i)
617 {
618 if (mechanicImmuneMask & (1 << (mechanicImmunes[i].flag - 1)))
619 {
620 handler->PSendSysMessage(mechanicImmunes[i].text, mechanicImmunes[i].flag);
621 }
622 }
623
624 handler->PSendSysMessage(LANG_NPCINFO_SPELL_SCHOOL_IMMUNE, spellSchoolImmuneMask);
625 for (uint8 i = 0; i < MAX_SPELL_SCHOOL; ++i)
626 {
627 if (spellSchoolImmuneMask & (1 << spellSchoolImmunes[i].flag))
628 {
629 handler->PSendSysMessage(spellSchoolImmunes[i].text, spellSchoolImmunes[i].flag);
630 }
631 }
632
633 return true;
634 }
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
std::uint64_t uint64
Definition: Define.h:106
std::int64_t int64
Definition: Define.h:102
NpcFlagText const npcFlagTexts[NPCFLAG_COUNT]
Definition: cs_npc.cpp:44
SpellSchoolImmune const spellSchoolImmunes[MAX_SPELL_SCHOOL]
Definition: cs_npc.cpp:120
MechanicImmune const mechanicImmunes[MAX_MECHANIC]
Definition: cs_npc.cpp:78
#define NPCFLAG_COUNT
Definition: cs_npc.cpp:42
constexpr auto MAX_SPELL_SCHOOL
Definition: SharedDefines.h:292
@ MAX_MECHANIC
Definition: SharedDefines.h:1357
@ LANG_NPCINFO_EQUIPMENT
Definition: Language.h:1083
@ LANG_NPCINFO_LOOT
Definition: Language.h:590
@ LANG_NPCINFO_POSITION
Definition: Language.h:591
@ LANG_NPCINFO_FLAGS
Definition: Language.h:589
@ LANG_NPCINFO_AIINFO
Definition: Language.h:1078
@ LANG_NPCINFO_SPELL_SCHOOL_IMMUNE
Definition: Language.h:1114
@ LANG_NPCINFO_HEALTH
Definition: Language.h:588
@ LANG_NPCINFO_PHASEMASK
Definition: Language.h:1067
@ LANG_NPCINFO_LEVEL
Definition: Language.h:587
@ LANG_COMMAND_RAWPAWNTIMES
Definition: Language.h:641
@ LANG_NPCINFO_ARMOR
Definition: Language.h:1068
@ LANG_NPCINFO_DUNGEON_ID
Definition: Language.h:594
@ LANG_NPCINFO_MECHANIC_IMMUNE
Definition: Language.h:1084
Seconds GetGameTime()
Definition: GameTime.cpp:38
int8 GetOriginalEquipmentId() const
Definition: Creature.h:193
uint8 GetCurrentEquipmentId()
Definition: Creature.h:194
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:205
uint32 GetRespawnDelay() const
Definition: Creature.h:291
std::string GetScriptName() const
Definition: Creature.cpp:3038
time_t GetRespawnTimeEx() const
Definition: Creature.cpp:2930
std::string const & GetAIName() const
Definition: Creature.cpp:3033
Definition: CreatureData.h:186
uint32 SkinLootId
Definition: CreatureData.h:226
uint32 MechanicImmuneMask
Definition: CreatureData.h:244
uint32 pickpocketLootId
Definition: CreatureData.h:225
uint32 lootid
Definition: CreatureData.h:224
uint8 SpellSchoolImmuneMask
Definition: CreatureData.h:245
uint32 GetPhaseMask() const
Definition: Object.h:446
uint32 GetInstanceId() const
Definition: Object.h:443
uint32 GetMaxHealth() const
Definition: Unit.h:1030
UnitFlags GetUnitFlags() const
Definition: Unit.h:711
uint32 GetHealth() const
Definition: Unit.h:1029
uint32 GetCreateHealth() const
Definition: Unit.h:1033
uint32 GetArmor() const
Definition: Unit.h:1079
uint8 GetLevel() const
Definition: Unit.h:1024
UnitFlags2 GetUnitFlags2() const
Remove all UnitFlags and set new ones. UnitFlags available in UnitDefines.h.
Definition: Unit.h:717
uint32 GetDynamicFlags() const override
Definition: Unit.h:730

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().

◆ HandleNpcMoveCommand()

static bool npc_commandscript::HandleNpcMoveCommand ( ChatHandler handler)
inlinestatic
715 {
716 Creature* creature = handler->getSelectedCreature();
717
718 if (!creature)
719 return false;
720
721 ObjectGuid::LowType lowguid = creature->GetSpawnId();
722
723 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
724 if (!data)
725 {
727 return false;
728 }
729
730 if (handler->GetSession()->GetPlayer()->GetMapId() != data->mapid)
731 {
733 return false;
734 }
735
736 float x = handler->GetSession()->GetPlayer()->GetPositionX();
737 float y = handler->GetSession()->GetPlayer()->GetPositionY();
738 float z = handler->GetSession()->GetPlayer()->GetPositionZ();
739 float o = handler->GetSession()->GetPlayer()->GetOrientation();
740
741 if (creature)
742 {
743 if (CreatureData const* data = sObjectMgr->GetCreatureData(creature->GetSpawnId()))
744 {
745 const_cast<CreatureData*>(data)->posX = x;
746 const_cast<CreatureData*>(data)->posY = y;
747 const_cast<CreatureData*>(data)->posZ = z;
748 const_cast<CreatureData*>(data)->orientation = o;
749 }
750
751 creature->SetPosition(x, y, z, o);
752 creature->GetMotionMaster()->Initialize();
753
754 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
755 {
756 creature->setDeathState(DeathState::JustDied);
757 creature->Respawn();
758 }
759 }
760
762 stmt->SetData(0, x);
763 stmt->SetData(1, y);
764 stmt->SetData(2, z);
765 stmt->SetData(3, o);
766 stmt->SetData(4, lowguid);
767
768 WorldDatabase.Execute(stmt);
769
771 return true;
772 }
@ LANG_COMMAND_CREATUREMOVED
Definition: Language.h:316
@ LANG_COMMAND_CREATUREATSAMEMAP
Definition: Language.h:317
@ 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:1965
void Respawn(bool force=false)
Definition: Creature.cpp:2035
void SetPosition(float x, float y, float z, float o)
Definition: Creature.cpp:3154
uint16 mapid
Definition: CreatureData.h:375
uint32 GetMapId() const
Definition: Position.h:275
bool IsAlive() const
Definition: Unit.h:1654
void Initialize()
Definition: MotionMaster.cpp:73

References WorldLocation::GetMapId(), Unit::GetMotionMaster(), Position::GetOrientation(), WorldSession::GetPlayer(), Position::GetPositionX(), Position::GetPositionY(), Position::GetPositionZ(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Creature::GetSpawnId(), MotionMaster::Initialize(), Unit::IsAlive(), 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
666 {
667 float distance = dist.value_or(10.0f);
668 uint32 count = 0;
669
670 Player* player = handler->GetSession()->GetPlayer();
671
673 stmt->SetData(0, player->GetPositionX());
674 stmt->SetData(1, player->GetPositionY());
675 stmt->SetData(2, player->GetPositionZ());
676 stmt->SetData(3, player->GetMapId());
677 stmt->SetData(4, player->GetPositionX());
678 stmt->SetData(5, player->GetPositionY());
679 stmt->SetData(6, player->GetPositionZ());
680 stmt->SetData(7, distance * distance);
681 stmt->SetData(8, player->GetPhaseMask());
682 PreparedQueryResult result = WorldDatabase.Query(stmt);
683
684 if (result)
685 {
686 do
687 {
688 Field* fields = result->Fetch();
689 ObjectGuid::LowType guid = fields[0].Get<uint32>();
690 uint32 entry = fields[1].Get<uint32>();
691 //uint32 entry2 = fields[2].Get<uint32>();
692 //uint32 entry3 = fields[3].Get<uint32>();
693 float x = fields[4].Get<float>();
694 float y = fields[5].Get<float>();
695 float z = fields[6].Get<float>();
696 uint16 mapId = fields[7].Get<uint16>();
697
698 CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(entry);
699 if (!creatureTemplate)
700 continue;
701
702 handler->PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, entry, guid, creatureTemplate->Name, x, y, z, mapId, "", "");
703
704 ++count;
705 } while (result->NextRow());
706 }
707
708 handler->PSendSysMessage(LANG_COMMAND_NEAR_NPC_MESSAGE, distance, count);
709
710 return true;
711 }
std::uint16_t uint16
Definition: Define.h:108
@ LANG_COMMAND_NEAR_NPC_MESSAGE
Old ones now free:
Definition: Language.h:611
@ LANG_CREATURE_LIST_CHAT
Definition: Language.h:558
@ WORLD_SEL_CREATURE_NEAREST
Definition: WorldDatabase.h:90
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:45
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
776 {
777 Creature* target = handler->getSelectedCreature();
778 if (!target)
779 {
781 return false;
782 }
783
784 target->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote);
785
786 return true;
787 }
@ UNIT_NPC_EMOTESTATE
Definition: UpdateFields.h:140
void SetUInt32Value(uint16 index, uint32 value)
Definition: Unit.cpp:21317

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
1034 {
1035 if (text.empty())
1036 return false;
1037
1038 Creature* creature = handler->getSelectedCreature();
1039 if (!creature)
1040 {
1042 return false;
1043 }
1044
1045 creature->Say(text, LANG_UNIVERSAL);
1046
1047 // make some emotes
1048 switch (text.back())
1049 {
1050 case '?': creature->HandleEmoteCommand(EMOTE_ONESHOT_QUESTION); break;
1051 case '!': creature->HandleEmoteCommand(EMOTE_ONESHOT_EXCLAMATION); break;
1052 default: creature->HandleEmoteCommand(EMOTE_ONESHOT_TALK); break;
1053 }
1054
1055 return true;
1056 }
@ EMOTE_ONESHOT_EXCLAMATION
Definition: SharedDefines.h:1899
@ EMOTE_ONESHOT_QUESTION
Definition: SharedDefines.h:1900
@ EMOTE_ONESHOT_TALK
Definition: SharedDefines.h:1895
@ LANG_UNIVERSAL
Definition: SharedDefines.h:735
virtual void Say(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition: Unit.cpp:21140
void HandleEmoteCommand(uint32 emoteId)
Definition: Unit.cpp:2000

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
319 {
320 if (sWorld->getAllowMovement())
321 {
322 sWorld->SetAllowMovement(false);
324 }
325 else
326 {
327 sWorld->SetAllowMovement(true);
329 }
330 return true;
331 }
@ LANG_CREATURE_MOVE_ENABLED
Definition: Language.h:431
@ LANG_CREATURE_MOVE_DISABLED
Definition: Language.h:430
#define sWorld
Definition: World.h:443

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
526 {
527 Creature* creature = handler->getSelectedCreature();
528
529 if (!creature)
530 {
532 return false;
533 }
534
535 creature->AI()->SetData(data_1, data_2);
536 std::string AIorScript = !creature->GetAIName().empty() ? "AI type: " + creature->GetAIName() : (!creature->GetScriptName().empty() ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set");
537 handler->PSendSysMessage(LANG_NPC_SETDATA, creature->GetGUID().ToString(), creature->GetEntry(), creature->GetName(), data_1, data_2, AIorScript);
538 return true;
539 }
@ LANG_NPC_SETDATA
Definition: Language.h:608
virtual void SetData(uint32, uint32)
Definition: UnitAI.h:214
CreatureAI * AI() const
Definition: Creature.h:140

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
334 {
335 if (!newEntryNum)
336 return false;
337
338 Unit* unit = handler->getSelectedUnit();
339 if (!unit || !unit->IsCreature())
340 {
342 return false;
343 }
344 Creature* creature = unit->ToCreature();
345 if (creature->UpdateEntry(newEntryNum))
346 handler->SendSysMessage(LANG_DONE);
347 else
348 handler->SendSysMessage(LANG_ERROR);
349 return true;
350 }
@ LANG_ERROR
Definition: Language.h:78
@ LANG_DONE
Definition: Language.h:75
Unit * getSelectedUnit() const
Definition: Chat.cpp:385
bool UpdateEntry(uint32 entry, const CreatureData *data=nullptr, bool changelevel=true, bool updateAI=false)
Definition: Creature.cpp:539
bool IsCreature() const
Definition: Object.h:201
Creature * ToCreature()
Definition: Object.h:202
Definition: Unit.h:630

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
425 {
426 if (!sFactionTemplateStore.LookupEntry(factionId))
427 {
428 handler->SendErrorMessage(LANG_WRONG_FACTION, factionId);
429 return false;
430 }
431
432 Creature* creature = handler->getSelectedCreature();
433
434 if (!creature)
435 {
437 return false;
438 }
439
440 creature->SetFaction(factionId);
441
442 // Faction is set in creature_template - not inside creature
443
444 // Update in memory..
445 if (CreatureTemplate const* cinfo = creature->GetCreatureTemplate())
446 const_cast<CreatureTemplate*>(cinfo)->faction = factionId;
447
448 // ..and DB
450
451 stmt->SetData(0, uint16(factionId));
452 stmt->SetData(1, creature->GetEntry());
453
454 WorldDatabase.Execute(stmt);
455
456 return true;
457 }
@ LANG_WRONG_FACTION
Definition: Language.h:163
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
@ WORLD_UPD_CREATURE_FACTION
Definition: WorldDatabase.h:47
void SetFaction(uint32 faction)
Definition: Unit.cpp:10056

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
461 {
462 Player* player = handler->GetSession()->GetPlayer();
463 Unit* unit = player->GetSelectedUnit();
464
465 if (!unit)
466 return false;
467
468 Creature* creature = unit->ToCreature();
469
470 if (!creature)
471 return false;
472
473 creature->SetFaction(tempfaction);
474
475 return true;
476 }
Unit * GetSelectedUnit() const
Definition: Player.cpp:11546

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
501 {
502 Creature* creature = handler->getSelectedCreature();
503
504 if (!creature)
505 {
507 return false;
508 }
509
510 creature->ReplaceAllNpcFlags(NPCFlags(npcFlags));
511
513
514 stmt->SetData(0, NPCFlags(npcFlags));
515 stmt->SetData(1, creature->GetEntry());
516
517 WorldDatabase.Execute(stmt);
518
520
521 return true;
522 }
@ LANG_VALUE_SAVED_REJOIN
Definition: Language.h:305
NPCFlags
Non Player Character flags.
Definition: UnitDefines.h:292
@ WORLD_UPD_CREATURE_NPCFLAG
Definition: WorldDatabase.h:48
void ReplaceAllNpcFlags(NPCFlags flags)
Definition: Unit.h:728

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
354 {
355 if (lvl < 1 || lvl > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL) + 3)
356 {
358 return false;
359 }
360
361 Creature* creature = handler->getSelectedCreature();
362 if (!creature || creature->IsPet())
363 {
365 return false;
366 }
367
368 creature->SetMaxHealth(100 + 30*lvl);
369 creature->SetHealth(100 + 30*lvl);
370 creature->SetLevel(lvl);
371 creature->SaveToDB();
372
373 return true;
374 }
@ LANG_BAD_VALUE
Definition: Language.h:147
@ CONFIG_MAX_PLAYER_LEVEL
Definition: IWorld.h:235
void SetHealth(uint32 val)
Definition: Unit.cpp:15478
void SetLevel(uint8 lvl, bool showLevelChange=true)
Definition: Unit.cpp:15460
void SetMaxHealth(uint32 val)
Definition: Unit.cpp:15528

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
1248 {
1249 Creature* creature = handler->getSelectedCreature();
1250
1251 if (!creature)
1252 {
1254 return false;
1255 }
1256
1257 if (!creature->GetSpawnId())
1258 {
1259 handler->SendErrorMessage("Selected creature {} isn't in creature table", creature->GetGUID().ToString());
1260 return false;
1261 }
1262
1263 if (!sObjectMgr->SetCreatureLinkedRespawn(creature->GetSpawnId(), linkguid))
1264 {
1265 handler->SendErrorMessage("Selected creature can't link with guid '%u'", linkguid);
1266 return false;
1267 }
1268
1269 handler->PSendSysMessage("LinkGUID '{}' added to creature with DBTableGUID: '{}'", linkguid, creature->GetSpawnId());
1270 return true;
1271 }

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
791 {
792 Creature* creature = handler->getSelectedCreature();
793
794 if (!creature || creature->IsPet())
795 {
797 return false;
798 }
799
800 if (!sCreatureDisplayInfoStore.LookupEntry(displayId))
801 {
803 return false;
804 }
805
806 creature->SetDisplayId(displayId);
807 creature->SetNativeDisplayId(displayId);
808 creature->SaveToDB();
809
810 return true;
811 }
@ LANG_COMMAND_FACTION_INVPARAM
Definition: Language.h:350
DBCStorage< CreatureDisplayInfoEntry > sCreatureDisplayInfoStore(CreatureDisplayInfofmt)
std::string ToString(Type &&val, Params &&... params)
Definition: StringConvert.h:250
void SetDisplayId(uint32 displayId, float displayScale=1.f) override
Definition: Creature.cpp:3518
void SetNativeDisplayId(uint32 displayId)
Definition: Unit.h:1841

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

826 {
827 // 3 arguments:
828 // GUID (optional - you can also select the creature)
829 // stay|random|way (determines the kind of movement)
830 // NODEL (optional - tells the system NOT to delete any waypoints)
831 // this is very handy if you want to do waypoints, that are
832 // later switched on/off according to special events (like escort
833 // quests, etc)
834
835 bool doNotDelete = nodel.has_value();
836
837 ObjectGuid::LowType lowguid = 0;
838 Creature* creature = nullptr;
839
840 if (!lowGuid) // case .setmovetype $move_type (with selected creature)
841 {
842 creature = handler->getSelectedCreature();
843 if (!creature || creature->IsPet())
844 return false;
845 lowguid = creature->GetSpawnId();
846 }
847 else // case .setmovetype #creature_guid $move_type (with selected creature)
848 {
849 lowguid = *lowGuid;
850
851 if (lowguid)
852 creature = handler->GetCreatureFromPlayerMapByDbGuid(lowguid);
853
854 // attempt check creature existence by DB data
855 if (!creature)
856 {
857 CreatureData const* data = sObjectMgr->GetCreatureData(lowguid);
858 if (!data)
859 {
861 return false;
862 }
863 }
864 else
865 {
866 lowguid = creature->GetSpawnId();
867 }
868 }
869
870 // now lowguid is low guid really existed creature
871 // and creature point (maybe) to this creature or nullptr
872
873 MovementGeneratorType move_type;
874 switch (type.index())
875 {
876 case 0:
877 move_type = IDLE_MOTION_TYPE;
878 break;
879 case 1:
880 move_type = RANDOM_MOTION_TYPE;
881 break;
882 case 2:
883 move_type = WAYPOINT_MOTION_TYPE;
884 break;
885 default:
886 return false;
887 }
888
889 // update movement type
890 //if (doNotDelete == false)
891 // WaypointMgr.DeletePath(lowguid);
892
893 if (creature)
894 {
895 // update movement type
896 if (!doNotDelete)
897 creature->LoadPath(0);
898
899 creature->SetDefaultMovementType(move_type);
900 creature->GetMotionMaster()->Initialize();
901
902 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
903 {
904 creature->setDeathState(DeathState::JustDied);
905 creature->Respawn();
906 }
907
908 creature->SaveToDB();
909 }
910
911 if (!doNotDelete)
912 {
913 handler->PSendSysMessage(LANG_MOVE_TYPE_SET, move_type);
914 }
915 else
916 {
917 handler->PSendSysMessage(LANG_MOVE_TYPE_SET_NODEL, move_type);
918 }
919
920 return true;
921 }
@ LANG_MOVE_TYPE_SET
Definition: Language.h:301
@ LANG_MOVE_TYPE_SET_NODEL
Definition: Language.h:302
MovementGeneratorType
Definition: MotionMaster.h:38
@ IDLE_MOTION_TYPE
Definition: MotionMaster.h:39
@ RANDOM_MOTION_TYPE
Definition: MotionMaster.h:40
Creature * GetCreatureFromPlayerMapByDbGuid(ObjectGuid::LowType lowguid)
Definition: Chat.cpp:577
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:86
void LoadPath(uint32 pathid)
Definition: Creature.h:347

References ChatHandler::GetCreatureFromPlayerMapByDbGuid(), Unit::GetMotionMaster(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), IDLE_MOTION_TYPE, MotionMaster::Initialize(), Unit::IsAlive(), Unit::IsPet(), 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
480 {
481 Player* player = handler->GetSession()->GetPlayer();
482
483 if (!player)
484 return false;
485
486 if (!player->GetSelectedUnit())
487 return false;
488
489 Creature* creature = player->GetSelectedUnit()->ToCreature();
490
491 if (!creature)
492 return false;
493
494 creature->RestoreFaction();
495
496 return true;
497 }
void RestoreFaction()
Definition: Unit.cpp:18696

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
926 {
927 if (phasemask == 0)
928 {
930 return false;
931 }
932
933 Creature* creature = handler->getSelectedCreature();
934 if (!creature)
935 {
937 return false;
938 }
939
940 creature->SetPhaseMask(phasemask, true);
941
942 if (!creature->IsPet())
943 creature->SaveToDB();
944
945 return true;
946 }
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition: Unit.cpp:19050

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
994 {
995 if (spawnTimeStr.empty())
996 {
997 return false;
998 }
999
1000 if (Acore::StringTo<int32>(spawnTimeStr).value_or(0) < 0)
1001 {
1003 return false;
1004 }
1005
1006 Creature* creature = handler->getSelectedCreature();
1007 if (!creature)
1008 return false;
1009
1010 int32 spawnTime = TimeStringToSecs(spawnTimeStr);
1011 if (spawnTime <= 0)
1012 {
1013 spawnTime = Acore::StringTo<int32>(spawnTimeStr).value_or(0);
1014 }
1015
1016 if (spawnTime <= 0)
1017 {
1019 return false;
1020 }
1021
1023 stmt->SetData(0, spawnTime);
1024 stmt->SetData(1, creature->GetSpawnId());
1025 WorldDatabase.Execute(stmt);
1026
1027 creature->SetRespawnDelay(spawnTime);
1028 handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, secsToTimeString(spawnTime, true));
1029
1030 return true;
1031 }
uint32 TimeStringToSecs(const std::string &timestring)
Definition: Util.cpp:163
std::int32_t int32
Definition: Define.h:103
@ LANG_COMMAND_SPAWNTIME
Definition: Language.h:337
@ WORLD_UPD_CREATURE_SPAWN_TIME_SECS
Definition: WorldDatabase.h:51
void SetRespawnDelay(uint32 delay)
Definition: Creature.h:292

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
950 {
951 if (option < 0.0f)
952 {
954 return false;
955 }
956
958
959 if (option > 0.0f)
960 mtype = RANDOM_MOTION_TYPE;
961
962 Creature* creature = handler->getSelectedCreature();
963 ObjectGuid::LowType guidLow = 0;
964
965 if (creature)
966 guidLow = creature->GetSpawnId();
967 else
968 return false;
969
970 creature->SetWanderDistance((float)option);
971 creature->SetDefaultMovementType(mtype);
972 creature->GetMotionMaster()->Initialize();
973
974 if (creature->IsAlive()) // dead creature will reset movement generator at respawn
975 {
976 creature->setDeathState(DeathState::JustDied);
977 creature->Respawn();
978 }
979
981
982 stmt->SetData(0, option);
983 stmt->SetData(1, uint8(mtype));
984 stmt->SetData(2, guidLow);
985
986 WorldDatabase.Execute(stmt);
987
989 return true;
990 }
@ LANG_COMMAND_WANDER_DISTANCE
Definition: Language.h:336
@ WORLD_UPD_CREATURE_WANDER_DISTANCE
Definition: WorldDatabase.h:50
void SetWanderDistance(float dist)
Definition: Creature.h:303

References Unit::GetMotionMaster(), ChatHandler::getSelectedCreature(), Creature::GetSpawnId(), IDLE_MOTION_TYPE, MotionMaster::Initialize(), Unit::IsAlive(), 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
1168 {
1169 Creature* creatureTarget = handler->getSelectedCreature();
1170 if (!creatureTarget || creatureTarget->IsPet())
1171 {
1173 handler->SetSentErrorMessage(true);
1174 return false;
1175 }
1176
1177 Player* player = handler->GetSession()->GetPlayer();
1178
1179 if (player->IsExistPet())
1180 {
1182 return false;
1183 }
1184
1185 CreatureTemplate const* cInfo = creatureTarget->GetCreatureTemplate();
1186
1187 if (!cInfo->IsTameable(player->CanTameExoticPets()))
1188 {
1190 handler->SetSentErrorMessage (true);
1191 return false;
1192 }
1193
1194 if (!player->CreatePet(creatureTarget))
1195 {
1197 return false;
1198 }
1199
1200 return true;
1201 }
@ LANG_CREATURE_NON_TAMEABLE
Definition: Language.h:384
@ LANG_YOU_ALREADY_HAVE_PET
Definition: Language.h:385
uint32 Entry
Definition: CreatureData.h:187
bool IsTameable(bool exotic) const
Definition: CreatureData.h:274
bool IsExistPet()
Definition: Player.cpp:9205
bool CanTameExoticPets() const
Definition: Player.h:2172
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition: Player.cpp:9211

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
1060 {
1061 if (text.empty())
1062 return false;
1063
1064 Creature* creature = handler->getSelectedCreature();
1065
1066 if (!creature)
1067 {
1069 return false;
1070 }
1071
1072 creature->TextEmote(text);
1073
1074 return true;
1075 }
virtual void TextEmote(std::string_view text, WorldObject const *target=nullptr, bool isBossEmote=false)
Definition: Unit.cpp:21150

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

Referenced by GetCommands().

◆ HandleNpcUnFollowCommand()

static bool npc_commandscript::HandleNpcUnFollowCommand ( ChatHandler handler)
inlinestatic
1079 {
1080 Player* player = handler->GetSession()->GetPlayer();
1081 Creature* creature = handler->getSelectedCreature();
1082
1083 if (!creature)
1084 {
1086 return false;
1087 }
1088
1089 if (/*creature->GetMotionMaster()->empty() ||*/
1091 {
1092 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1093 return false;
1094 }
1095
1096 FollowMovementGenerator<Creature> const* mgen = static_cast<FollowMovementGenerator<Creature> const*>((creature->GetMotionMaster()->top()));
1097
1098 if (mgen->GetTarget() != player)
1099 {
1100 handler->SendErrorMessage(LANG_CREATURE_NOT_FOLLOW_YOU, creature->GetName().c_str());
1101 return false;
1102 }
1103
1104 // reset movement
1105 creature->GetMotionMaster()->MovementExpired(true);
1106
1108 return true;
1109 }
@ LANG_CREATURE_NOT_FOLLOW_YOU
Definition: Language.h:382
@ LANG_CREATURE_NOT_FOLLOW_YOU_NOW
Definition: Language.h:383
@ FOLLOW_MOTION_TYPE
Definition: MotionMaster.h:54
_Ty top() const
Definition: MotionMaster.h:150
MovementGeneratorType GetCurrentMovementGeneratorType() const
Definition: MotionMaster.cpp:913
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:180
Definition: TargetedMovementGenerator.h:76
Unit * GetTarget() const
Definition: TargetedMovementGenerator.h:90

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
1113 {
1114 if (text.empty())
1115 return false;
1116
1117 Creature* creature = handler->getSelectedCreature();
1118 if (!creature)
1119 {
1121 return false;
1122 }
1123
1124 // check online security
1125 Player* receiver = ObjectAccessor::FindPlayerByName(recv);
1126 if (handler->HasLowerSecurity(receiver, ObjectGuid::Empty))
1127 return false;
1128
1129 creature->Whisper(text, LANG_UNIVERSAL, receiver);
1130 return true;
1131 }
Player * FindPlayerByName(std::string const &name, bool checkInWorld=true)
Definition: ObjectAccessor.cpp:271
bool HasLowerSecurity(Player *target, ObjectGuid guid=ObjectGuid::Empty, bool strong=false)
Definition: Chat.cpp:56
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:21155

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
1134 {
1135 if (text.empty())
1136 return false;
1137
1138 Creature* creature = handler->getSelectedCreature();
1139 if (!creature)
1140 {
1142 return false;
1143 }
1144
1145 creature->Yell(text, LANG_UNIVERSAL);
1146
1147 // make an emote
1149
1150 return true;
1151 }
@ EMOTE_ONESHOT_SHOUT
Definition: SharedDefines.h:1914
virtual void Yell(std::string_view text, Language language, WorldObject const *target=nullptr)
Definition: Unit.cpp:21145

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

Referenced by GetCommands().