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
 
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 HandlePetCreateCommand (ChatHandler *handler)
 
static bool HandlePetLearnCommand (ChatHandler *handler, SpellInfo const *spell)
 
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
33: CommandScript("pet_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable pet_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

36 {
37 static ChatCommandTable petCommandTable =
38 {
39 { "create", HandlePetCreateCommand, SEC_GAMEMASTER, Console::No },
40 { "learn", HandlePetLearnCommand, SEC_GAMEMASTER, Console::No },
41 { "unlearn", HandlePetUnlearnCommand, SEC_GAMEMASTER, Console::No }
42 };
43
44 static ChatCommandTable commandTable =
45 {
46 { "pet", petCommandTable }
47 };
48
49 return commandTable;
50 }
@ SEC_GAMEMASTER
Definition: Common.h:59
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandlePetLearnCommand(ChatHandler *handler, SpellInfo const *spell)
Definition: cs_pet.cpp:86
static bool HandlePetCreateCommand(ChatHandler *handler)
Definition: cs_pet.cpp:52
static bool HandlePetUnlearnCommand(ChatHandler *handler, SpellInfo const *spell)
Definition: cs_pet.cpp:128

References HandlePetCreateCommand(), HandlePetLearnCommand(), HandlePetUnlearnCommand(), and SEC_GAMEMASTER.

◆ HandlePetCreateCommand()

static bool pet_commandscript::HandlePetCreateCommand ( ChatHandler handler)
inlinestatic
53 {
54 Player* player = handler->GetSession()->GetPlayer();
55 Creature* creatureTarget = handler->getSelectedCreature();
56
57 if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->IsPlayer())
58 {
60 return false;
61 }
62
63 CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
64 // Creatures with family 0 crashes the server
65 if (!creatrueTemplate->family)
66 {
67 handler->SendErrorMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
68 return false;
69 }
70
71 if (player->IsExistPet())
72 {
74 return false;
75 }
76
77 if (!player->CreatePet(creatureTarget))
78 {
79 handler->SendErrorMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
80 return false;
81 }
82
83 return true;
84 }
#define sObjectMgr
Definition: ObjectMgr.h:1635
@ LANG_SELECT_CREATURE
Definition: Language.h:32
@ LANG_CREATURE_NON_TAMEABLE
Definition: Language.h:384
@ LANG_YOU_ALREADY_HAVE_PET
Definition: Language.h:385
WorldSession * GetSession()
Definition: Chat.h:242
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215
Creature * getSelectedCreature() const
Definition: Chat.cpp:409
Definition: Creature.h:43
Definition: CreatureData.h:186
uint32 Entry
Definition: CreatureData.h:187
uint32 family
Definition: CreatureData.h:217
bool IsPlayer() const
Definition: Object.h:200
uint32 GetEntry() const
Definition: Object.h:115
Definition: Player.h:1081
bool IsExistPet()
Definition: Player.cpp:9227
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition: Player.cpp:9233
bool IsPet() const
Definition: Unit.h:754
Player * GetPlayer() const
Definition: WorldSession.h:362

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

◆ HandlePetLearnCommand()

static bool pet_commandscript::HandlePetLearnCommand ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
87 {
88 if (!spell)
89 {
91 return false;
92 }
93
94 if (!SpellMgr::IsSpellValid(spell))
95 {
97 return false;
98 }
99
100 Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
101 if (!pet)
102 {
103 handler->SendErrorMessage("You have no pet");
104 return false;
105 }
106
107 SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell->Id);
108 uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell->Id);
109 if (bounds.first != bounds.second || spellDifficultyId)
110 {
111 handler->SendErrorMessage("Spell {} cannot be learnt using a command!", spell->Id);
112 return false;
113 }
114
115 // Check if pet already has it
116 if (pet->HasSpell(spell->Id))
117 {
118 handler->SendErrorMessage("Pet already has spell: {}", spell->Id);
119 return false;
120 }
121
122 pet->learnSpell(spell->Id);
123 handler->PSendSysMessage("Pet has learned spell {}", spell->Id);
124
125 return true;
126 }
std::uint32_t uint32
Definition: Define.h:107
std::pair< SpellScriptsContainer::iterator, SpellScriptsContainer::iterator > SpellScriptsBounds
Definition: ObjectMgr.h:388
#define sSpellMgr
Definition: SpellMgr.h:825
@ LANG_COMMAND_NOSPELLFOUND
Definition: Language.h:477
@ LANG_COMMAND_SPELL_BROKEN
Definition: Language.h:520
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
Definition: Pet.h:41
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:2334
bool learnSpell(uint32 spell_id)
Definition: Pet.cpp:1906
Pet * GetPet() const
Definition: Player.cpp:8939
static bool IsSpellValid(SpellInfo const *spellInfo)
Definition: SpellMgr.cpp:441

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

◆ HandlePetUnlearnCommand()

static bool pet_commandscript::HandlePetUnlearnCommand ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
129 {
130 if (!spell)
131 {
133 return false;
134 }
135
136 if (!SpellMgr::IsSpellValid(spell))
137 {
138 handler->SendErrorMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
139 return false;
140 }
141
142 Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
143 if (!pet)
144 {
145 handler->SendErrorMessage("You have no pet");
146 return false;
147 }
148
149 if (pet->HasSpell(spell->Id))
150 {
151 pet->removeSpell(spell->Id, false);
152 }
153 else
154 {
155 handler->PSendSysMessage("Pet doesn't have that spell");
156 }
157
158 return true;
159 }
bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab=true)
Definition: Pet.cpp:1979

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