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
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:61
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
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->GetTypeId() == TYPEID_PLAYER)
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 }
@ 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:139
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:152
Creature * getSelectedCreature() const
Definition: Chat.cpp:346
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:1056
bool IsExistPet()
Definition: Player.cpp:9108
Pet * CreatePet(Creature *creatureTarget, uint32 spellID=0)
Definition: Player.cpp:9114
bool IsPet() const
Definition: Unit.h:1425
Player * GetPlayer() const
Definition: WorldSession.h:364

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::SendErrorMessage(), sObjectMgr, and TYPEID_PLAYER.

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 %u 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: %u", spell->Id);
119 return false;
120 }
121
122 pet->learnSpell(spell->Id);
123 handler->PSendSysMessage("Pet has learned spell %u", spell->Id);
124
125 return true;
126 }
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:825
void PSendSysMessage(char const *fmt, Args &&... args)
Definition: Chat.h:60
Definition: Pet.h:40
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:2334
bool learnSpell(uint32 spell_id)
Definition: Pet.cpp:1903
Pet * GetPet() const
Definition: Player.cpp:8819
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::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:1976

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