TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pet_commandscript Class Reference

Public Member Functions

 pet_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandlePetCreateCommand (ChatHandler *handler, char const *)
 
static bool HandlePetLearnCommand (ChatHandler *handler, char const *args)
 
static bool HandlePetUnlearnCommand (ChatHandler *handler, char const *args)
 

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

Constructor & Destructor Documentation

pet_commandscript::pet_commandscript ( )
inline
28 : CommandScript("pet_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> pet_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

31  {
32  static std::vector<ChatCommand> petCommandTable =
33  {
37  };
38 
39  static std::vector<ChatCommand> commandTable =
40  {
41  { "pet", rbac::RBAC_PERM_COMMAND_PET, false, NULL, "", petCommandTable },
42  };
43  return commandTable;
44  }
static bool HandlePetUnlearnCommand(ChatHandler *handler, char const *args)
Definition: cs_pet.cpp:160
Definition: RBAC.h:388
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: RBAC.h:386
static bool HandlePetLearnCommand(ChatHandler *handler, char const *args)
Definition: cs_pet.cpp:117
static bool HandlePetCreateCommand(ChatHandler *handler, char const *)
Definition: cs_pet.cpp:45

+ Here is the call graph for this function:

static bool pet_commandscript::HandlePetCreateCommand ( ChatHandler handler,
char const  
)
inlinestatic
46  {
47  Player* player = handler->GetSession()->GetPlayer();
48  Creature* creatureTarget = handler->getSelectedCreature();
49 
50  if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
51  {
53  handler->SetSentErrorMessage(true);
54  return false;
55  }
56 
57  CreatureTemplate const* creatrueTemplate = creatureTarget->GetCreatureTemplate();
58  // Creatures with family 0 crashes the server
59  if (!creatrueTemplate->family)
60  {
61  handler->PSendSysMessage("This creature cannot be tamed. (family id: 0).");
62  handler->SetSentErrorMessage(true);
63  return false;
64  }
65 
66  if (!player->GetPetGUID().IsEmpty())
67  {
68  handler->PSendSysMessage("You already have a pet");
69  handler->SetSentErrorMessage(true);
70  return false;
71  }
72 
73  // Everything looks OK, create new pet
74  Pet* pet = new Pet(player, HUNTER_PET);
75  if (!pet->CreateBaseAtCreature(creatureTarget))
76  {
77  delete pet;
78  handler->PSendSysMessage("Error 1");
79  return false;
80  }
81 
82  creatureTarget->setDeathState(JUST_DIED);
83  creatureTarget->RemoveCorpse();
84  creatureTarget->SetHealth(0); // just for nice GM-mode view
85 
86  pet->SetGuidValue(UNIT_FIELD_CREATEDBY, player->GetGUID());
87  pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction());
88 
89  if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
90  {
91  TC_LOG_ERROR("misc", "InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
92  handler->PSendSysMessage("Error 2");
93  delete pet;
94  return false;
95  }
96 
97  // prepare visual effect for levelup
98  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()-1);
99 
100  pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true);
101  // this enables pet details window (Shift+P)
102  pet->InitPetCreateSpells();
103  pet->SetFullHealth();
104 
105  pet->GetMap()->AddToMap(pet->ToCreature());
106 
107  // visual effect for levelup
108  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
109 
110  player->SetMinion(pet, true);
112  player->PetSpellInitialize();
113 
114  return true;
115  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
void SetPetNumber(uint32 petnumber, bool statwindow)
Definition: Unit.cpp:12048
Creature * getSelectedCreature()
Definition: Chat.cpp:615
Map * GetMap() const
Definition: Object.h:543
Definition: Unit.h:542
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:996
Definition: Creature.h:467
bool CreateBaseAtCreature(Creature *creature)
Definition: Pet.cpp:730
Player * GetPlayer() const
Definition: WorldSession.h:927
void SetGuidValue(uint16 index, ObjectGuid const &value)
Definition: Object.cpp:1120
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: UpdateFields.h:105
CharmInfo * GetCharmInfo()
Definition: Unit.h:1748
Definition: PetDefines.h:25
uint8 getLevel() const
Definition: Unit.h:1408
Definition: PetDefines.h:35
TypeID GetTypeId() const
Definition: Object.h:113
void SavePetToDB(PetSaveMode mode)
Definition: Pet.cpp:372
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:558
void setDeathState(DeathState s) override
Definition: Creature.cpp:1624
Definition: Language.h:33
bool AddToMap(T *)
Definition: Map.cpp:566
void InitPetCreateSpells()
Definition: Pet.cpp:1541
bool IsPet() const
Definition: Unit.h:1403
Definition: UpdateFields.h:87
Definition: ObjectGuid.h:33
Creature * ToCreature()
Definition: Object.h:194
WorldSession * GetSession()
Definition: Chat.h:59
void RemoveCorpse(bool setSpawnTime=true)
Definition: Creature.cpp:280
uint32 family
Definition: Creature.h:112
bool InitStatsForLevel(uint8 level)
Definition: Pet.cpp:801
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: UpdateFields.h:107
void SetFullHealth()
Definition: Unit.h:1440
void SetHealth(uint32 val)
Definition: Unit.cpp:11537
Definition: Creature.h:79
Definition: Pet.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool pet_commandscript::HandlePetLearnCommand ( ChatHandler handler,
char const args 
)
inlinestatic
118  {
119  if (!*args)
120  return false;
121 
122  Player* player = handler->GetSession()->GetPlayer();
123  Pet* pet = player->GetPet();
124 
125  if (!pet)
126  {
127  handler->PSendSysMessage("You have no pet");
128  handler->SetSentErrorMessage(true);
129  return false;
130  }
131 
132  uint32 spellId = handler->extractSpellIdFromLink((char*)args);
133 
134  if (!spellId || !sSpellMgr->GetSpellInfo(spellId))
135  return false;
136 
137  // Check if pet already has it
138  if (pet->HasSpell(spellId))
139  {
140  handler->PSendSysMessage("Pet already has spell: %u", spellId);
141  handler->SetSentErrorMessage(true);
142  return false;
143  }
144 
145  // Check if spell is valid
146  SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
147  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
148  {
149  handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spellId);
150  handler->SetSentErrorMessage(true);
151  return false;
152  }
153 
154  pet->learnSpell(spellId);
155 
156  handler->PSendSysMessage("Pet has learned spell %u", spellId);
157  return true;
158  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Language.h:490
Definition: SpellInfo.h:326
Player * GetPlayer() const
Definition: WorldSession.h:927
#define sSpellMgr
Definition: SpellMgr.h:756
uint32_t uint32
Definition: Define.h:150
static bool IsSpellValid(SpellInfo const *spellInfo, Player *player=NULL, bool msg=true)
Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book...
Definition: SpellMgr.cpp:482
uint32 extractSpellIdFromLink(char *text)
Definition: Chat.cpp:806
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:1814
bool learnSpell(uint32 spell_id)
Definition: Pet.cpp:1423
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Pet.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool pet_commandscript::HandlePetUnlearnCommand ( ChatHandler handler,
char const args 
)
inlinestatic
161  {
162  if (!*args)
163  return false;
164 
165  Player* player = handler->GetSession()->GetPlayer();
166  Pet* pet = player->GetPet();
167  if (!pet)
168  {
169  handler->PSendSysMessage("You have no pet");
170  handler->SetSentErrorMessage(true);
171  return false;
172  }
173 
174  uint32 spellId = handler->extractSpellIdFromLink((char*)args);
175 
176  if (pet->HasSpell(spellId))
177  pet->removeSpell(spellId, false);
178  else
179  handler->PSendSysMessage("Pet doesn't have that spell");
180 
181  return true;
182  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Player * GetPlayer() const
Definition: WorldSession.h:927
uint32_t uint32
Definition: Define.h:150
uint32 extractSpellIdFromLink(char *text)
Definition: Chat.cpp:806
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:1814
bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab=true)
Definition: Pet.cpp:1491
WorldSession * GetSession()
Definition: Chat.h:59
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Pet.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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