*Fix a crash caused by pet.

*Make pet class derived from guardian class.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-03-25 21:32:34 -06:00
parent ebf53a4820
commit 1c2eab4110
11 changed files with 130 additions and 141 deletions
+68 -52
View File
@@ -39,8 +39,8 @@ char const* petTypeSuffix[MAX_PET_TYPE] =
"'s Companion" // MINI_PET
};
Pet::Pet(PetType type) :
Creature(), m_petType(type), m_removed(false), m_happinessTimer(7500), m_duration(0), m_bonusdamage(0),
Pet::Pet(Player *owner, PetType type) : Guardian(NULL, owner),
m_petType(type), m_removed(false), m_happinessTimer(7500), m_duration(0),
m_resetTalentsCost(0), m_resetTalentsTime(0), m_usedTalentCount(0), m_auraRaidUpdateMask(0), m_loading(false),
m_declinedname(NULL)
{
@@ -48,9 +48,6 @@ m_declinedname(NULL)
m_name = "Pet";
m_regenTimer = 4000;
// pets always have a charminfo, even if they are not actually charmed
InitCharmInfo();
if(type == POSSESSED_PET) // always passive
SetReactState(REACT_PASSIVE);
}
@@ -181,8 +178,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
else
m_charmInfo->SetPetNumber(pet_number, false);
owner->SetPet(this, true);
SetDisplayId(fields[3].GetUInt32());
SetNativeDisplayId(fields[3].GetUInt32());
uint32 petlevel = fields[4].GetUInt32();
@@ -214,6 +209,10 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
sLog.outError("Pet have incorrect type (%u) for pet loading.", getPetType());
}
owner->SetPet(this, true);
AIM_Initialize();
map->Add((Creature*)this);
InitStatsForLevel(petlevel);
SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, time(NULL));
SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, fields[5].GetUInt32());
@@ -309,9 +308,6 @@ bool Pet::LoadPetFromDB( Player* owner, uint32 petentry, uint32 petnumber, bool
SetPower(POWER_MANA, savedmana > GetMaxPower(POWER_MANA) ? GetMaxPower(POWER_MANA) : savedmana);
}
AIM_Initialize();
map->Add((Creature*)this);
// Spells should be loaded after pet is added to map, because in CheckCast is check on it
_LoadSpells();
_LoadSpellCooldowns();
@@ -772,21 +768,27 @@ bool Pet::CreateBaseAtCreature(Creature* creature)
return true;
}
bool Pet::InitStatsForLevel(uint32 petlevel)
bool Guardian::InitStatsForLevel(uint32 petlevel)
{
CreatureInfo const *cinfo = GetCreatureInfo();
assert(cinfo);
Unit* owner = GetOwner();
if(!owner)
SetLevel(petlevel);
PetType petType = MAX_PET_TYPE;
if(HasSummonMask(SUMMON_MASK_PET) && m_owner->GetTypeId() == TYPEID_PLAYER)
{
sLog.outError("attempt to summon pet (Entry %u) without owner! Attempt terminated.", cinfo->Entry);
return false;
if(m_owner->getClass() == CLASS_WARLOCK)
petType = SUMMON_PET;
else if(m_owner->getClass() == CLASS_HUNTER)
petType = HUNTER_PET;
else
sLog.outError("Unknown type pet %u is summoned by player class %u", GetEntry(), m_owner->getClass());
((Pet*)this)->learnLevelupSpells();
}
uint32 creature_ID = (getPetType() == HUNTER_PET) ? 1 : cinfo->Entry;
SetLevel(petlevel);
uint32 creature_ID = (petType == HUNTER_PET) ? 1 : cinfo->Entry;
SetMeleeDamageSchool(SpellSchools(cinfo->dmgschool));
@@ -799,7 +801,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0);
CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(cinfo->family);
if(cFamily && cFamily->minScale > 0.0f && getPetType()==HUNTER_PET)
if(cFamily && cFamily->minScale > 0.0f && petType==HUNTER_PET)
{
float scale;
if (getLevel() >= cFamily->maxScaleLevel)
@@ -815,7 +817,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
int32 createResistance[MAX_SPELL_SCHOOL] = {0,0,0,0,0,0,0};
if(cinfo && getPetType() != HUNTER_PET)
if(cinfo && petType != HUNTER_PET)
{
createResistance[SPELL_SCHOOL_HOLY] = cinfo->resistance1;
createResistance[SPELL_SCHOOL_FIRE] = cinfo->resistance2;
@@ -825,39 +827,16 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
createResistance[SPELL_SCHOOL_ARCANE] = cinfo->resistance6;
}
switch(getPetType())
switch(petType)
{
case SUMMON_PET:
{
if(owner->GetTypeId() == TYPEID_PLAYER)
{
switch(owner->getClass())
{
case CLASS_WARLOCK:
{
//the damage bonus used for pets is either fire or shadow damage, whatever is higher
uint32 fire = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE);
uint32 shadow = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW);
uint32 val = (fire > shadow) ? fire : shadow;
learnLevelupSpells();
SetBonusDamage(int32 (val * 0.15f));
//bonusAP += val * 0.57;
break;
}
case CLASS_MAGE:
{
//40% damage bonus of mage's frost damage
float val = owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4;
if(val < 0)
val = 0;
SetBonusDamage( int32(val));
break;
}
default:
break;
}
}
//the damage bonus used for pets is either fire or shadow damage, whatever is higher
uint32 fire = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE);
uint32 shadow = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW);
uint32 val = (fire > shadow) ? fire : shadow;
SetBonusDamage(int32 (val * 0.15f));
//bonusAP += val * 0.57;
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) );
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)) );
@@ -897,7 +876,6 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
case HUNTER_PET:
{
SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, objmgr.GetXPForLevel(petlevel)/4);
learnLevelupSpells();
//these formula may not be correct; however, it is designed to be close to what it should be
//this makes dps 0.5 of pets level
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)) );
@@ -934,7 +912,45 @@ bool Pet::InitStatsForLevel(uint32 petlevel)
break;
}
default:
sLog.outError("Pet have incorrect type (%u) for levelup.", getPetType());
switch(GetEntry())
{
case 510: // mage Water Elemental
{
//40% damage bonus of mage's frost damage
float val = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FROST) * 0.4;
if(val < 0)
val = 0;
SetBonusDamage( int32(val));
break;
}
case 1964: //force of nature
SetCreateHealth(30 + 30*petlevel);
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 2.5f - (petlevel / 2)));
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 2.5f + (petlevel / 2)));
break;
case 15352: //earth elemental 36213
SetCreateHealth(100 + 120*petlevel);
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));
break;
case 15438: //fire elemental
SetCreateHealth(40*petlevel);
SetCreateMana(28 + 10*petlevel);
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 4 - petlevel));
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 4 + petlevel));
break;
default:
SetCreateMana(28 + 10*petlevel);
SetCreateHealth(28 + 30*petlevel);
// FIXME: this is wrong formula, possible each guardian pet have own damage formula
//these formula may not be correct; however, it is designed to be close to what it should be
//this makes dps 0.5 of pets level
SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4)));
//damage range is then petlevel / 2
SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4)));
break;
}
//sLog.outError("Pet have incorrect type (%u) for levelup.", petType);
break;
}