[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

@ -2172,50 +2172,7 @@ bool ChatHandler::HandleNpcTameCommand(char* /*args*/)
return false;
}
CreatureInfo const* cInfo = creatureTarget->GetCreatureInfo();
if (!cInfo->isTameable(player->CanTameExoticPets()))
{
PSendSysMessage(LANG_CREATURE_NON_TAMEABLE,cInfo->Entry);
SetSentErrorMessage(true);
return false;
}
// Everything looks OK, create new pet
Pet* pet = player->CreateTamedPetFrom (creatureTarget);
if (!pet)
{
PSendSysMessage (LANG_CREATURE_NON_TAMEABLE,cInfo->Entry);
SetSentErrorMessage (true);
return false;
}
// place pet before player
float x,y,z;
player->GetClosePoint(x, y, z, creatureTarget->GetObjectBoundingRadius(), CONTACT_DISTANCE);
pet->Relocate (x,y,z,M_PI_F-player->GetOrientation ());
// set pet to defensive mode by default (some classes can't control controlled pets in fact).
pet->GetCharmInfo()->SetReactState(REACT_DEFENSIVE);
// calculate proper level
uint32 level = (creatureTarget->getLevel() < (player->getLevel() - 5)) ? (player->getLevel() - 5) : creatureTarget->getLevel();
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level - 1);
// add to world
pet->GetMap()->Add((Creature*)pet);
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL, level);
// caster have pet now
player->SetPet(pet);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
player->PetSpellInitialize();
player->CastSpell(creatureTarget, 13481, true); // Tame Beast, triggered effect
return true;
}
//npc phasemask handling