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

Public Member Functions

 pet_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 HandlePetCreateCommand (ChatHandler *handler)
 
static bool HandlePetLearnCommand (ChatHandler *handler, SpellInfo const *spell)
 
static bool HandlePetDeleteCommand (ChatHandler *handler, PlayerIdentifier owner, uint32 petNumber)
 
static bool HandlePetListCommand (ChatHandler *handler, PlayerIdentifier owner)
 
static bool HandlePetUnlearnCommand (ChatHandler *handler, SpellInfo const *spell)
 

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

◆ pet_commandscript()

pet_commandscript::pet_commandscript ( )
inline
36: CommandScript("pet_commandscript") { }
Definition CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable pet_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

39 {
40 static ChatCommandTable petCommandTable =
41 {
47 };
48
49 static ChatCommandTable commandTable =
50 {
51 { "pet", petCommandTable }
52 };
53
54 return commandTable;
55 }
static bool HandlePetLearnCommand(ChatHandler *handler, SpellInfo const *spell)
Definition cs_pet.cpp:91
static bool HandlePetDeleteCommand(ChatHandler *handler, PlayerIdentifier owner, uint32 petNumber)
Definition cs_pet.cpp:133
static bool HandlePetCreateCommand(ChatHandler *handler)
Definition cs_pet.cpp:57
static bool HandlePetUnlearnCommand(ChatHandler *handler, SpellInfo const *spell)
Definition cs_pet.cpp:230
static bool HandlePetListCommand(ChatHandler *handler, PlayerIdentifier owner)
Definition cs_pet.cpp:192
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_PET_DELETE
Definition RBAC.h:679
@ RBAC_PERM_COMMAND_PET_LEARN
Definition RBAC.h:312
@ RBAC_PERM_COMMAND_PET_CREATE
Definition RBAC.h:311
@ RBAC_PERM_COMMAND_PET_LIST
Definition RBAC.h:678
@ RBAC_PERM_COMMAND_PET_UNLEARN
Definition RBAC.h:313

References HandlePetCreateCommand(), HandlePetDeleteCommand(), HandlePetLearnCommand(), HandlePetListCommand(), HandlePetUnlearnCommand(), rbac::RBAC_PERM_COMMAND_PET_CREATE, rbac::RBAC_PERM_COMMAND_PET_DELETE, rbac::RBAC_PERM_COMMAND_PET_LEARN, rbac::RBAC_PERM_COMMAND_PET_LIST, and rbac::RBAC_PERM_COMMAND_PET_UNLEARN.

◆ HandlePetCreateCommand()

static bool pet_commandscript::HandlePetCreateCommand ( ChatHandler handler)
inlinestatic
58 {
59 Player* player = handler->GetSession()->GetPlayer();
60 Creature* creatureTarget = handler->getSelectedCreature();
61
62 if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->IsPlayer())
63 {
65 return false;
66 }
67
68 CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
69 // Creatures with family 0 crashes the server
70 if (!creatrueTemplate->family)
71 {
72 handler->SendErrorMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
73 return false;
74 }
75
76 if (player->IsExistPet())
77 {
79 return false;
80 }
81
82 if (!player->CreatePet(creatureTarget))
83 {
84 handler->SendErrorMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
85 return false;
86 }
87
88 return true;
89 }
@ LANG_SELECT_CREATURE
Definition Language.h:32
@ LANG_CREATURE_NON_TAMEABLE
Definition Language.h:393
@ LANG_YOU_ALREADY_HAVE_PET
Definition Language.h:394
#define sObjectMgr
Definition ObjectMgr.h:1723
WorldSession * GetSession()
Definition Chat.h:242
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
Creature * getSelectedCreature() const
Definition Chat.cpp:418
Definition Creature.h:47
bool IsPlayer() const
Definition Object.h:201
uint32 GetEntry() const
Definition Object.h:117
Definition Player.h:1084
bool IsExistPet()
Definition Player.cpp:9242
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition Player.cpp:9248
bool IsPet() const
Definition Unit.h:797
Player * GetPlayer() const
Definition WorldSession.h:454
Definition CreatureData.h:187
uint32 Entry
Definition CreatureData.h:188
uint32 family
Definition CreatureData.h:217

References Player::CreatePet(), CreatureTemplate::Entry, CreatureTemplate::family, Object::GetEntry(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Player::IsExistPet(), Unit::IsPet(), Object::IsPlayer(), LANG_CREATURE_NON_TAMEABLE, LANG_SELECT_CREATURE, LANG_YOU_ALREADY_HAVE_PET, ChatHandler::SendErrorMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandlePetDeleteCommand()

static bool pet_commandscript::HandlePetDeleteCommand ( ChatHandler handler,
PlayerIdentifier  owner,
uint32  petNumber 
)
inlinestatic
134 {
135 ObjectGuid ownerGuid = owner.GetGUID();
136
137 QueryResult result = CharacterDatabase.Query(
138 "SELECT entry, name FROM character_pet WHERE id = {} AND owner = {}",
139 petNumber, ownerGuid.GetCounter());
140
141 if (!result)
142 {
143 handler->SendErrorMessage(LANG_PET_DELETE_NOT_FOUND, petNumber, owner.GetName(),
144 ownerGuid.GetCounter());
145 return false;
146 }
147
148 if (Player* online = owner.GetConnectedPlayer())
149 {
150 if (Pet* activePet = online->GetPet())
151 {
152 if (activePet->GetCharmInfo() &&
153 activePet->GetCharmInfo()->GetPetNumber() == petNumber)
154 {
155 online->RemovePet(activePet, PET_SAVE_AS_DELETED);
156 }
157 }
158
159 // Drop the pet from the in-memory PetStable so the stable UI / call-pet
160 // logic does not reference a row that no longer exists in the database.
161 if (PetStable* stable = online->GetPetStable())
162 {
163 if (stable->CurrentPet && stable->CurrentPet->PetNumber == petNumber)
164 stable->CurrentPet.reset();
165
166 for (Optional<PetStable::PetInfo>& stabled : stable->StabledPets)
167 if (stabled && stabled->PetNumber == petNumber)
168 stabled.reset();
169
170 stable->UnslottedPets.erase(
171 std::remove_if(stable->UnslottedPets.begin(), stable->UnslottedPets.end(),
172 [petNumber](PetStable::PetInfo const& p) { return p.PetNumber == petNumber; }),
173 stable->UnslottedPets.end());
174 }
175 }
176
177 Field* fields = result->Fetch();
178 uint32 entry = fields[0].Get<uint32>();
179 std::string name = fields[1].Get<std::string>();
180
181 std::string creatureName = "<unknown>";
182 if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(entry))
183 creatureName = cInfo->Name;
184
185 Pet::DeleteFromDB(petNumber);
186
187 handler->PSendSysMessage(LANG_PET_DELETE_SUCCESS, petNumber, name, entry, creatureName,
188 owner.GetName(), ownerGuid.GetCounter());
189 return true;
190 }
std::shared_ptr< ResultSet > QueryResult
Definition DatabaseEnvFwd.h:27
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition DatabaseEnv.cpp:21
std::uint32_t uint32
Definition Define.h:107
@ LANG_PET_DELETE_SUCCESS
Definition Language.h:1490
@ LANG_PET_DELETE_NOT_FOUND
Definition Language.h:1489
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
@ PET_SAVE_AS_DELETED
Definition PetDefines.h:42
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:219
Class used to access individual fields of database query result.
Definition Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition Field.h:112
Definition ObjectGuid.h:118
LowType GetCounter() const
Definition ObjectGuid.h:145
Definition PetDefines.h:212
Definition Pet.h:41
void DeleteFromDB() override
Definition Pet.h:171
ObjectGuid GetGUID() const
Definition ChatCommandTags.h:181
std::string const & GetName() const
Definition ChatCommandTags.h:180
Player * GetConnectedPlayer() const
Definition ChatCommandTags.h:183
Definition PetDefines.h:215

References CharacterDatabase, Pet::DeleteFromDB(), Field::Get(), Acore::ChatCommands::PlayerIdentifier::GetConnectedPlayer(), ObjectGuid::GetCounter(), Acore::ChatCommands::PlayerIdentifier::GetGUID(), Acore::ChatCommands::PlayerIdentifier::GetName(), LANG_PET_DELETE_NOT_FOUND, LANG_PET_DELETE_SUCCESS, PET_SAVE_AS_DELETED, ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandlePetLearnCommand()

static bool pet_commandscript::HandlePetLearnCommand ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
92 {
93 if (!spell)
94 {
96 return false;
97 }
98
99 if (!SpellMgr::IsSpellValid(spell))
100 {
101 handler->SendErrorMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
102 return false;
103 }
104
105 Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
106 if (!pet)
107 {
108 handler->SendErrorMessage("You have no pet");
109 return false;
110 }
111
112 SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell->Id);
113 uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell->Id);
114 if (bounds.first != bounds.second || spellDifficultyId)
115 {
116 handler->SendErrorMessage("Spell {} cannot be learnt using a command!", spell->Id);
117 return false;
118 }
119
120 // Check if pet already has it
121 if (pet->HasSpell(spell->Id))
122 {
123 handler->SendErrorMessage("Pet already has spell: {}", spell->Id);
124 return false;
125 }
126
127 pet->learnSpell(spell->Id);
128 handler->PSendSysMessage("Pet has learned spell {}", spell->Id);
129
130 return true;
131 }
@ LANG_COMMAND_NOSPELLFOUND
Definition Language.h:486
@ LANG_COMMAND_SPELL_BROKEN
Definition Language.h:529
std::pair< SpellScriptsContainer::iterator, SpellScriptsContainer::iterator > SpellScriptsBounds
Definition ObjectMgr.h:389
#define sSpellMgr
Definition SpellMgr.h:836
bool HasSpell(uint32 spell) const override
Definition Pet.cpp:2326
bool learnSpell(uint32 spell_id)
Definition Pet.cpp:1897
Pet * GetPet() const
Definition Player.cpp:8961
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition SpellMgr.cpp:488

References Player::GetPet(), WorldSession::GetPlayer(), ChatHandler::GetSession(), Pet::HasSpell(), SpellInfo::Id, SpellMgr::IsSpellValid(), LANG_COMMAND_NOSPELLFOUND, LANG_COMMAND_SPELL_BROKEN, Pet::learnSpell(), ChatHandler::PSendSysMessage(), ChatHandler::SendErrorMessage(), sObjectMgr, and sSpellMgr.

Referenced by GetCommands().

◆ HandlePetListCommand()

static bool pet_commandscript::HandlePetListCommand ( ChatHandler handler,
PlayerIdentifier  owner 
)
inlinestatic
193 {
194 ObjectGuid ownerGuid = owner.GetGUID();
195
196 QueryResult result = CharacterDatabase.Query(
197 "SELECT id, entry, level, slot, name, PetType FROM character_pet "
198 "WHERE owner = {} ORDER BY slot, id",
199 ownerGuid.GetCounter());
200
201 if (!result)
202 {
203 handler->PSendSysMessage(LANG_PET_LIST_EMPTY, owner.GetName(), ownerGuid.GetCounter());
204 return true;
205 }
206
207 handler->PSendSysMessage(LANG_PET_LIST_HEADER, owner.GetName(), ownerGuid.GetCounter());
208
209 do
210 {
211 Field* fields = result->Fetch();
212 uint32 petNumber = fields[0].Get<uint32>();
213 uint32 entry = fields[1].Get<uint32>();
214 uint8 level = fields[2].Get<uint8>();
215 uint8 slot = fields[3].Get<uint8>();
216 std::string name = fields[4].Get<std::string>();
217 uint8 petType = fields[5].Get<uint8>();
218
219 std::string creatureName = "<unknown>";
220 if (CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(entry))
221 creatureName = cInfo->Name;
222
223 handler->PSendSysMessage(LANG_PET_LIST_ENTRY, petNumber, uint32(slot), entry,
224 creatureName, name, uint32(level), uint32(petType));
225 } while (result->NextRow());
226
227 return true;
228 }
std::uint8_t uint8
Definition Define.h:109
@ LANG_PET_LIST_EMPTY
Definition Language.h:1486
@ LANG_PET_LIST_ENTRY
Definition Language.h:1485
@ LANG_PET_LIST_HEADER
Definition Language.h:1484

References CharacterDatabase, Field::Get(), ObjectGuid::GetCounter(), Acore::ChatCommands::PlayerIdentifier::GetGUID(), Acore::ChatCommands::PlayerIdentifier::GetName(), LANG_PET_LIST_EMPTY, LANG_PET_LIST_ENTRY, LANG_PET_LIST_HEADER, ChatHandler::PSendSysMessage(), and sObjectMgr.

Referenced by GetCommands().

◆ HandlePetUnlearnCommand()

static bool pet_commandscript::HandlePetUnlearnCommand ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
231 {
232 if (!spell)
233 {
235 return false;
236 }
237
238 if (!SpellMgr::IsSpellValid(spell))
239 {
240 handler->SendErrorMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
241 return false;
242 }
243
244 Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
245 if (!pet)
246 {
247 handler->SendErrorMessage("You have no pet");
248 return false;
249 }
250
251 if (pet->HasSpell(spell->Id))
252 {
253 pet->removeSpell(spell->Id, false);
254 }
255 else
256 {
257 handler->PSendSysMessage("Pet doesn't have that spell");
258 }
259
260 return true;
261 }
bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab=true)
Definition Pet.cpp:1970

References Player::GetPet(), WorldSession::GetPlayer(), ChatHandler::GetSession(), Pet::HasSpell(), SpellInfo::Id, SpellMgr::IsSpellValid(), LANG_COMMAND_NOSPELLFOUND, LANG_COMMAND_SPELL_BROKEN, ChatHandler::PSendSysMessage(), Pet::removeSpell(), and ChatHandler::SendErrorMessage().

Referenced by GetCommands().


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