| 4130 | |
| 4131 | bool ChatHandler::HandleCreatePetCommand(const char* args) |
| 4132 | { |
| 4133 | Player *player = m_session->GetPlayer(); |
| 4134 | Creature *creatureTarget = getSelectedCreature(); |
| 4135 | |
| 4136 | CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(creatureTarget->GetEntry()); |
| 4137 | // Creatures with family 0 crashes the server |
| 4138 | if(cInfo->family == 0) |
| 4139 | { |
| 4140 | PSendSysMessage("This creature cannot be tamed. (family id: 0)."); |
| 4141 | SetSentErrorMessage(true); |
| 4142 | return false; |
| 4143 | } |
| 4144 | |
| 4145 | if(player->GetPetGUID()) |
| 4146 | { |
| 4147 | PSendSysMessage("You already have a pet"); |
| 4148 | SetSentErrorMessage(true); |
| 4149 | return false; |
| 4150 | } |
| 4151 | |
| 4152 | if(!creatureTarget || creatureTarget->isPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER) |
| 4153 | { |
| 4154 | PSendSysMessage(LANG_SELECT_CREATURE); |
| 4155 | SetSentErrorMessage(true); |
| 4156 | return false; |
| 4157 | } |
| 4158 | |
| 4159 | // Everything looks OK, create new pet |
| 4160 | Pet* pet = new Pet(HUNTER_PET); |
| 4161 | |
| 4162 | if(!pet->CreateBaseAtCreature(creatureTarget)) |
| 4163 | { |
| 4164 | delete pet; |
| 4165 | PSendSysMessage("Error 1"); |
| 4166 | return false; |
| 4167 | } |
| 4168 | |
| 4169 | creatureTarget->setDeathState(JUST_DIED); |
| 4170 | creatureTarget->RemoveCorpse(); |
| 4171 | creatureTarget->SetHealth(0); // just for nice GM-mode view |
| 4172 | |
| 4173 | pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, player->GetGUID()); |
| 4174 | pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID()); |
| 4175 | pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction()); |
| 4176 | |
| 4177 | if(!pet->InitStatsForLevel(creatureTarget->getLevel())) |
| 4178 | { |
| 4179 | sLog.outError("ERROR: InitStatsForLevel() in EffectTameCreature failed! Pet deleted."); |
| 4180 | PSendSysMessage("Error 2"); |
| 4181 | return false; |
| 4182 | } |
| 4183 | |
| 4184 | // prepare visual effect for levelup |
| 4185 | pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1); |
| 4186 | |
| 4187 | pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true); |
| 4188 | // this enables pet details window (Shift+P) |
| 4189 | pet->AIM_Initialize(); |
| 4190 | pet->InitPetCreateSpells(); |
| 4191 | pet->SetHealth(pet->GetMaxHealth()); |
| 4192 | |
| 4193 | MapManager::Instance().GetMap(pet->GetMapId(), pet)->Add((Creature*)pet); |
| 4194 | |
| 4195 | // visual effect for levelup |
| 4196 | pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()); |
| 4197 | |
| 4198 | player->SetPet(pet); |
| 4199 | pet->SavePetToDB(PET_SAVE_AS_CURRENT); |
| 4200 | player->PetSpellInitialize(); |
| 4201 | |
| 4202 | return true; |
| 4203 | } |
| 4204 | |
| 4205 | bool ChatHandler::HandlePetLearnCommand(const char* args) |
| 4206 | { |
| 4207 | if(!*args) |
| 4208 | return false; |
| 4209 | |
| 4210 | Player *plr = m_session->GetPlayer(); |
| 4211 | Pet *pet = plr->GetPet(); |
| 4212 | |
| 4213 | if(!pet) |
| 4214 | { |
| 4215 | PSendSysMessage("You have no pet"); |
| 4216 | SetSentErrorMessage(true); |
| 4217 | return false; |
| 4218 | } |
| 4219 | |
| 4220 | uint32 spellId = extractSpellIdFromLink((char*)args); |
| 4221 | |
| 4222 | if(!spellId || !sSpellStore.LookupEntry(spellId)) |
| 4223 | return false; |
| 4224 | |
| 4225 | // Check if pet already has it |
| 4226 | if(pet->HasSpell(spellId)) |
| 4227 | { |
| 4228 | PSendSysMessage("Pet already has spell: %u", spellId); |
| 4229 | SetSentErrorMessage(true); |
| 4230 | return false; |
| 4231 | } |
| 4232 | |
| 4233 | // Check if spell is valid |
| 4234 | SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId); |
| 4235 | if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo)) |
| 4236 | { |
| 4237 | PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spellId); |
| 4238 | SetSentErrorMessage(true); |
| 4239 | return false; |
| 4240 | } |
| 4241 | |
| 4242 | pet->learnSpell(spellId); |
| 4243 | |
| 4244 | PSendSysMessage("Pet has learned spell %u", spellId); |
| 4245 | return true; |
| 4246 | } |
| 4247 | |
| 4248 | bool ChatHandler::HandlePetUnlearnCommand(const char *args) |
| 4249 | { |
| 4250 | if(!*args) |
| 4251 | return false; |
| 4252 | |
| 4253 | Player *plr = m_session->GetPlayer(); |
| 4254 | Pet *pet = plr->GetPet(); |
| 4255 | |
| 4256 | if(!pet) |
| 4257 | { |
| 4258 | PSendSysMessage("You have no pet"); |
| 4259 | SetSentErrorMessage(true); |
| 4260 | return false; |
| 4261 | } |
| 4262 | |
| 4263 | uint32 spellId = extractSpellIdFromLink((char*)args); |
| 4264 | |
| 4265 | if(pet->HasSpell(spellId)) |
| 4266 | pet->removeSpell(spellId); |
| 4267 | else |
| 4268 | PSendSysMessage("Pet doesn't have that spell"); |
| 4269 | |
| 4270 | return true; |
| 4271 | } |
| 4272 | |
| 4273 | bool ChatHandler::HandlePetTpCommand(const char *args) |
| 4274 | { |
| 4275 | if(!*args) |
| 4276 | return false; |
| 4277 | |
| 4278 | Player *plr = m_session->GetPlayer(); |
| 4279 | Pet *pet = plr->GetPet(); |
| 4280 | |
| 4281 | if(!pet) |
| 4282 | { |
| 4283 | PSendSysMessage("You have no pet"); |
| 4284 | SetSentErrorMessage(true); |
| 4285 | return false; |
| 4286 | } |
| 4287 | |
| 4288 | uint32 tp = atol(args); |
| 4289 | |
| 4290 | pet->SetTP(tp); |
| 4291 | |
| 4292 | PSendSysMessage("Pet's tp changed to %u", tp); |
| 4293 | return true; |
| 4294 | } |
| 4295 | |
| 4296 | bool ChatHandler::HandleActivateObjectCommand(const char *args) |
| 4297 | { |
| 4298 | if(!*args) |
| 4299 | return false; |
| 4300 | |
| 4301 | char* cId = extractKeyFromLink((char*)args,"Hgameobject"); |
| 4302 | if(!cId) |
| 4303 | return false; |
| 4304 | |
| 4305 | uint32 lowguid = atoi(cId); |
| 4306 | if(!lowguid) |
| 4307 | return false; |
| 4308 | |
| 4309 | GameObject* obj = NULL; |
| 4310 | |
| 4311 | // by DB guid |
| 4312 | if (GameObjectData const* go_data = objmgr.GetGOData(lowguid)) |
| 4313 | obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid,go_data->id); |
| 4314 | |
| 4315 | if(!obj) |
| 4316 | { |
| 4317 | PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, lowguid); |
| 4318 | SetSentErrorMessage(true); |
| 4319 | return false; |
| 4320 | } |
| 4321 | |
| 4322 | // Activate |
| 4323 | obj->SetLootState(GO_READY); |
| 4324 | obj->UseDoorOrButton(10000); |
| 4325 | |
| 4326 | PSendSysMessage("Object activated!"); |
| 4327 | |
| 4328 | return true; |
| 4329 | } |