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
 

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)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ pet_commandscript()

pet_commandscript::pet_commandscript ( )
inline
34: CommandScript("pet_commandscript") { }
Definition: ScriptMgr.h:850

Member Function Documentation

◆ GetCommands()

ChatCommandTable pet_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

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

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

◆ HandlePetCreateCommand()

static bool pet_commandscript::HandlePetCreateCommand ( ChatHandler handler)
inlinestatic
54 {
55 Player* player = handler->GetSession()->GetPlayer();
56 Creature* creatureTarget = handler->getSelectedCreature();
57
58 if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
59 {
61 handler->SetSentErrorMessage(true);
62 return false;
63 }
64
65 CreatureTemplate const* creatrueTemplate = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry());
66 // Creatures with family 0 crashes the server
67 if (!creatrueTemplate->family)
68 {
69 handler->PSendSysMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
70 handler->SetSentErrorMessage(true);
71 return false;
72 }
73
74 if (player->IsExistPet())
75 {
77 handler->SetSentErrorMessage(true);
78 return false;
79 }
80
81 if (!player->CreatePet(creatureTarget))
82 {
83 handler->PSendSysMessage(LANG_CREATURE_NON_TAMEABLE, creatrueTemplate->Entry);
84 handler->SetSentErrorMessage(true);
85 return false;
86 }
87
88 return true;
89 }
@ TYPEID_PLAYER
Definition: ObjectGuid.h:38
#define sObjectMgr
Definition: ObjectMgr.h:1640
@ 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:122
void SetSentErrorMessage(bool val)
Definition: Chat.h:118
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:103
Creature * getSelectedCreature() const
Definition: Chat.cpp:337
Definition: Creature.h:46
Definition: CreatureData.h:176
uint32 Entry
Definition: CreatureData.h:177
uint32 family
Definition: CreatureData.h:210
TypeID GetTypeId() const
Definition: Object.h:121
uint32 GetEntry() const
Definition: Object.h:109
Definition: Player.h:1046
bool IsExistPet()
Definition: Player.cpp:9087
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition: Player.cpp:9093
bool IsPet() const
Definition: Unit.h:1413
Player * GetPlayer() const
Definition: WorldSession.h:361

References Player::CreatePet(), CreatureTemplate::Entry, CreatureTemplate::family, Object::GetEntry(), WorldSession::GetPlayer(), ChatHandler::getSelectedCreature(), ChatHandler::GetSession(), Object::GetTypeId(), Player::IsExistPet(), Unit::IsPet(), LANG_CREATURE_NON_TAMEABLE, LANG_SELECT_CREATURE, LANG_YOU_ALREADY_HAVE_PET, ChatHandler::PSendSysMessage(), ChatHandler::SendSysMessage(), ChatHandler::SetSentErrorMessage(), sObjectMgr, and TYPEID_PLAYER.

Referenced by GetCommands().

◆ HandlePetLearnCommand()

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

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::SetSentErrorMessage(), sObjectMgr, and sSpellMgr.

Referenced by GetCommands().

◆ HandlePetUnlearnCommand()

static bool pet_commandscript::HandlePetUnlearnCommand ( ChatHandler handler,
SpellInfo const *  spell 
)
inlinestatic
139 {
140 if (!spell)
141 {
143 handler->SetSentErrorMessage(true);
144 return false;
145 }
146
147 if (!SpellMgr::IsSpellValid(spell))
148 {
149 handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell->Id);
150 handler->SetSentErrorMessage(true);
151 return false;
152 }
153
154 Pet* pet = handler->GetSession()->GetPlayer()->GetPet();
155 if (!pet)
156 {
157 handler->PSendSysMessage("You have no pet");
158 handler->SetSentErrorMessage(true);
159 return false;
160 }
161
162 if (pet->HasSpell(spell->Id))
163 {
164 pet->removeSpell(spell->Id, false);
165 }
166 else
167 {
168 handler->PSendSysMessage("Pet doesn't have that spell");
169 }
170
171 return true;
172 }
bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab=true)
Definition: Pet.cpp:1947

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

Referenced by GetCommands().