[2008_10_31_01_mangos_creature_template.sql] Creature related code and DB cleanups.

* Rename 2 creature_template fields to more clean names and related code update also.
* Use enum values instead raw values for type_flags, use halper functions instead code repeating.
* Move tamed pet creating code to new function.
This commit is contained in:
VladimirMangos 2008-10-31 20:45:22 +03:00
parent c7ac8577ae
commit 41b876b395
11 changed files with 103 additions and 76 deletions

View file

@ -3884,56 +3884,36 @@ void Spell::EffectTameCreature(uint32 /*i*/)
if(creatureTarget->isPet())
return;
if(m_caster->getClass() == CLASS_HUNTER)
if(m_caster->getClass() != CLASS_HUNTER)
return;
// cast finish successfully
//SendChannelUpdate(0);
finish();
Pet* pet = m_caster->CreateTamedPetFrom(creatureTarget,m_spellInfo->Id);
// kill original creature
creatureTarget->setDeathState(JUST_DIED);
creatureTarget->RemoveCorpse();
creatureTarget->SetHealth(0); // just for nice GM-mode view
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1);
// add to world
MapManager::Instance().GetMap(pet->GetMapId(), pet)->Add((Creature*)pet);
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel());
// caster have pet now
m_caster->SetPet(pet);
if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
// cast finish successfully
//SendChannelUpdate(0);
finish();
Pet* pet = new Pet(HUNTER_PET);
if(!pet->CreateBaseAtCreature(creatureTarget))
{
delete pet;
return;
}
creatureTarget->setDeathState(JUST_DIED);
creatureTarget->RemoveCorpse();
creatureTarget->SetHealth(0); // just for nice GM-mode view
pet->SetUInt64Value(UNIT_FIELD_SUMMONEDBY, m_caster->GetGUID());
pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, m_caster->GetGUID());
pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE,m_caster->getFaction());
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, m_spellInfo->Id);
if(!pet->InitStatsForLevel(creatureTarget->getLevel()))
{
sLog.outError("ERROR: InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
delete pet;
return;
}
// prepare visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel()-1);
pet->GetCharmInfo()->SetPetNumber(objmgr.GeneratePetNumber(), true);
// this enables pet details window (Shift+P)
pet->AIM_Initialize();
pet->InitPetCreateSpells();
pet->SetHealth(pet->GetMaxHealth());
MapManager::Instance().GetMap(pet->GetMapId(), pet)->Add((Creature*)pet);
// visual effect for levelup
pet->SetUInt32Value(UNIT_FIELD_LEVEL,creatureTarget->getLevel());
if(m_caster->GetTypeId() == TYPEID_PLAYER)
{
m_caster->SetPet(pet);
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
((Player*)m_caster)->PetSpellInitialize();
}
pet->SavePetToDB(PET_SAVE_AS_CURRENT);
((Player*)m_caster)->PetSpellInitialize();
}
}
@ -5537,13 +5517,7 @@ void Spell::EffectSkinning(uint32 /*i*/)
Creature* creature = (Creature*) unitTarget;
int32 targetLevel = creature->getLevel();
uint32 skill;
if(creature->GetCreatureInfo()->flag1 & 256)
skill = SKILL_HERBALISM; // special case
else if(creature->GetCreatureInfo()->flag1 & 512)
skill = SKILL_MINING; // special case
else
skill = SKILL_SKINNING; // normal case
uint32 skill = creature->GetCreatureInfo()->GetRequiredLootSkill();
((Player*)m_caster)->SendLoot(creature->GetGUID(),LOOT_SKINNING);
creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE);