bool ChatHandler::HandleCreatePetCommand(const char* /*args*/) { Player* player = m_session->GetPlayer(); Creature* creatureTarget = getSelectedCreature(); if (!creatureTarget || creatureTarget->isPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER) { PSendSysMessage(LANG_SELECT_CREATURE); SetSentErrorMessage(true); return false; } CreatureTemplate const* cInfo = sObjectMgr->GetCreatureTemplate(creatureTarget->GetEntry()); // Creatures with family 0 crashes the server if (cInfo->family == 0) { PSendSysMessage("This creature cannot be tamed. (family id: 0)."); SetSentErrorMessage(true); return false; } if (player->GetPetGUID()) { PSendSysMessage("You already have a pet"); SetSentErrorMessage(true); return false; } // Everything looks OK, create new pet Pet* pet = new Pet(player, HUNTER_PET); if (!pet->CreateBaseAtCreature(creatureTarget)) { delete pet; PSendSysMessage("Error 1"); return false; } creatureTarget->setDeathState(JUST_DIED); creatureTarget->RemoveCorpse(); creatureTarget->SetHealth(0); // just for nice GM-mode view pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID()); pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, player->getFaction()); if (!pet->InitStatsForLevel(creatureTarget->getLevel())) { sLog->outError("InitStatsForLevel() in EffectTameCreature failed! Pet deleted."); PSendSysMessage("Error 2"); delete pet; return false; } // prepare visual effect for levelup pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()-1); pet->GetCharmInfo()->SetPetNumber(sObjectMgr->GeneratePetNumber(), true); // this enables pet details window (Shift+P) pet->InitPetCreateSpells(); pet->SetFullHealth(); pet->GetMap()->AddToMap(pet->ToCreature()); // visual effect for levelup pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel()); player->SetMinion(pet, true); pet->SavePetToDB(PET_SAVE_AS_CURRENT); player->PetSpellInitialize(); return true; }
void CPlayer::CreatePet(uint32 entry, bool classcheck) { if (classcheck && getClass() != CLASS_HUNTER) return; CreatureInfo const *cinfo = sObjectMgr.GetCreatureTemplate(entry); if (!cinfo) { BoxChat << MSG_COLOR_WHITE << " This pet doesn't exist in our database. Please report that creature " << entry << " is missing." << std::endl; return; } CreatureCreatePos pos(GetSession()->GetPlayer(), GetOrientation()); Creature* pCreature = new Creature; // used guids from specially reserved range (can be 0 if no free values) uint32 lowguid = sObjectMgr.GenerateStaticCreatureLowGuid(); if (!lowguid) return; if (!pCreature->Create(lowguid, pos, cinfo)) { delete pCreature; return; } //-------------------------------------------------- if (GetPetGuid()) UnsummonPetTemporaryIfAny(); Pet* pet = new Pet(HUNTER_PET); if (!pet->CreateBaseAtCreature(pCreature)) { delete pet; return; } pet->SetOwnerGuid(GetObjectGuid()); pet->SetCreatorGuid(GetObjectGuid()); pet->setFaction(getFaction()); pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, 13481); if (IsPvP()) pet->SetPvP(true); if (!pet->InitStatsForLevel(pCreature->getLevel())) { sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!", pCreature->GetEntry()); delete pet; return; } pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true); // this enables pet details window (Shift+P) pet->AIM_Initialize(); pet->InitPetCreateSpells(); pet->SetHealth(pet->GetMaxHealth()); // add to world pet->GetMap()->Add((Creature*)pet); // visual effect for levelup pet->SetUInt32Value(UNIT_FIELD_LEVEL, 70); for (auto x = 0; x < 6; x++) { pet->SetPower(POWER_HAPPINESS, 66600000); pet->ModifyLoyalty(150000); pet->TickLoyaltyChange(); pet->SetTP(350); } // caster have pet now SetPet(pet); pet->SavePetToDB(PET_SAVE_AS_CURRENT); PetSpellInitialize(); pet->learnSpell(27052); pet->learnSpell(35698); pet->learnSpell(25076); pet->learnSpell(27048); pet->learnSpell(27053); pet->learnSpell(27054); pet->learnSpell(27062); pet->learnSpell(27047); pet->learnSpell(24551); delete pCreature; }