[11215] Replace direct code use in .npc tame by spell cast.

Only work different from old way: target creature despawned.
So if this not expected use .respawn to it in gm mode or area respawn.

Code simplification suggested originally by rsa.
This commit is contained in:
VladimirMangos 2011-03-03 21:31:02 +03:00
parent 9312ef7e78
commit 06fe777f82
6 changed files with 50 additions and 99 deletions

View file

@ -5312,15 +5312,47 @@ void Spell::EffectTameCreature(SpellEffectIndex /*eff_idx*/)
//SendChannelUpdate(0);
finish();
Pet* pet = plr->CreateTamedPetFrom(creatureTarget, m_spellInfo->Id);
if(!pet) // in versy specific state like near world end/etc.
Pet* pet = new Pet(HUNTER_PET);
if(!pet->CreateBaseAtCreature(creatureTarget))
{
delete pet;
return;
}
pet->SetOwnerGuid(plr->GetObjectGuid());
pet->SetCreatorGuid(plr->GetObjectGuid());
pet->setFaction(plr->getFaction());
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
pet->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
if (pet->IsPvP())
pet->SetPvP(true);
if (pet->IsFFAPvP())
pet->SetFFAPvP(true);
// level of hunter pet can't be less owner level at 5 levels
uint32 level = creatureTarget->getLevel() + 5 < plr->getLevel() ? (plr->getLevel() - 5) : creatureTarget->getLevel();
if (!pet->InitStatsForLevel(level))
{
sLog.outError("Pet::InitStatsForLevel() failed for creature (Entry: %u)!", creatureTarget->GetEntry());
delete pet;
return;
}
pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->AIM_Initialize();
pet->InitPetCreateSpells();
pet->InitLevelupSpellsForLevel();
pet->InitTalentForLevel();
pet->SetHealth(pet->GetMaxHealth());
// "kill" original creature
creatureTarget->ForcedDespawn();
uint32 level = (creatureTarget->getLevel() < (plr->getLevel() - 5)) ? (plr->getLevel() - 5) : creatureTarget->getLevel();
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);