Core/Pets: Remove unnecesary member variable (m_owner)

This commit is contained in:
Spp committed 2013-03-21 15:00:43 +01:00
1 parent 156fb824a4
commit 1496e4df84
4 files changed
+66 -53

No files matched your search

@@ -37,6 +37,11 @@ Unit* TempSummon::GetSummoner() const
return m_summonerGUID ? ObjectAccessor::GetUnit(*this, m_summonerGUID) : NULL;
}
Creature* TempSummon::GetSummonerCreatureBase() const
{
return m_summonerGUID ? ObjectAccessor::GetCreature(*this, m_summonerGUID) : NULL;
}
void TempSummon::Update(uint32 diff)
{
Creature::Update(diff);
@@ -274,8 +279,9 @@ void TempSummon::RemoveFromWorld()
Creature::RemoveFromWorld();
}
Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : TempSummon(properties, owner, isWorldObject)
, m_owner(owner)
Minion::Minion(SummonPropertiesEntry const* properties, Unit* owner,
bool isWorldObject)
: TempSummon(properties, owner, isWorldObject), m_owner(owner)
{
ASSERT(m_owner);
m_unitTypeMask |= UNIT_MASK_MINION;
@@ -288,10 +294,10 @@ void Minion::InitStats(uint32 duration)
SetReactState(REACT_PASSIVE);
SetCreatorGUID(m_owner->GetGUID());
setFaction(m_owner->getFaction());
SetCreatorGUID(GetOwner()->GetGUID());
setFaction(GetOwner()->getFaction());
m_owner->SetMinion(this, true);
GetOwner()->SetMinion(this, true);
}
void Minion::RemoveFromWorld()
@@ -299,7 +305,7 @@ void Minion::RemoveFromWorld()
if (!IsInWorld())
return;
m_owner->SetMinion(this, false);
GetOwner()->SetMinion(this, false);
TempSummon::RemoveFromWorld();
}
@@ -324,9 +330,9 @@ void Guardian::InitStats(uint32 duration)
{
Minion::InitStats(duration);
InitStatsForLevel(m_owner->getLevel());
InitStatsForLevel(GetOwner()->getLevel());
if (m_owner->GetTypeId() == TYPEID_PLAYER && HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
if (GetOwner()->GetTypeId() == TYPEID_PLAYER && HasUnitTypeMask(UNIT_MASK_CONTROLABLE_GUARDIAN))
m_charmInfo->InitCharmCreateSpells();
SetReactState(REACT_AGGRESSIVE);
@@ -336,30 +342,32 @@ void Guardian::InitSummon()
{
TempSummon::InitSummon();
if (m_owner->GetTypeId() == TYPEID_PLAYER
&& m_owner->GetMinionGUID() == GetGUID()
&& !m_owner->GetCharmGUID())
m_owner->ToPlayer()->CharmSpellInitialize();
if (GetOwner()->GetTypeId() == TYPEID_PLAYER
&& GetOwner()->GetMinionGUID() == GetGUID()
&& !GetOwner()->GetCharmGUID())
{
GetOwner()->ToPlayer()->CharmSpellInitialize();
}
}
Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false) //maybe true?
Puppet::Puppet(SummonPropertiesEntry const* properties, Unit* owner)
: Minion(properties, owner, false) //maybe true?
{
ASSERT(owner->GetTypeId() == TYPEID_PLAYER);
m_owner = (Player*)owner;
ASSERT(m_owner->GetTypeId() == TYPEID_PLAYER);
m_unitTypeMask |= UNIT_MASK_PUPPET;
}
void Puppet::InitStats(uint32 duration)
{
Minion::InitStats(duration);
SetLevel(m_owner->getLevel());
SetLevel(GetOwner()->getLevel());
SetReactState(REACT_PASSIVE);
}
void Puppet::InitSummon()
{
Minion::InitSummon();
if (!SetCharmedBy(m_owner, CHARM_TYPE_POSSESS))
if (!SetCharmedBy(GetOwner(), CHARM_TYPE_POSSESS))
ASSERT(false);
}
@@ -50,6 +50,7 @@ class TempSummon : public Creature
void SetTempSummonType(TempSummonType type);
void SaveToDB(uint32 /*mapid*/, uint8 /*spawnMask*/, uint32 /*phaseMask*/) {}
Unit* GetSummoner() const;
Creature* GetSummonerCreatureBase() const;
uint64 GetSummonerGUID() const { return m_summonerGUID; }
TempSummonType const& GetSummonType() { return m_type; }
uint32 GetTimer() { return m_timer; }
@@ -68,7 +69,7 @@ class Minion : public TempSummon
Minion(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject);
void InitStats(uint32 duration);
void RemoveFromWorld();
Unit* GetOwner() { return m_owner; }
Unit* GetOwner() const { return m_owner; }
float GetFollowAngle() const { return m_followAngle; }
void SetFollowAngle(float angle) { m_followAngle = angle; }
bool IsPetGhoul() const {return GetEntry() == 26125;} // Ghoul may be guardian or pet
@@ -96,7 +97,7 @@ class Guardian : public Minion
void UpdateAttackPowerAndDamage(bool ranged = false);
void UpdateDamagePhysical(WeaponAttackType attType);
int32 GetBonusDamage() { return m_bonusSpellDamage; }
int32 GetBonusDamage() const { return m_bonusSpellDamage; }
void SetBonusDamage(int32 damage);
protected:
int32 m_bonusSpellDamage;
@@ -111,8 +112,6 @@ class Puppet : public Minion
void InitSummon();
void Update(uint32 time);
void RemoveFromWorld();
protected:
Player* m_owner;
};
class ForcedUnsummonDelayEvent : public BasicEvent
+36 -31
View File
@@ -35,10 +35,12 @@
#define PET_XP_FACTOR 0.05f
Pet::Pet(Player* owner, PetType type) : Guardian(NULL, owner, true),
m_usedTalentCount(0), m_removed(false), m_owner(owner),
m_usedTalentCount(0), m_removed(false),
m_happinessTimer(7500), m_petType(type), m_duration(0),
m_auraRaidUpdateMask(0), m_loading(false), m_declinedname(NULL)
{
ASSERT(m_owner->GetTypeId() == TYPEID_PLAYER);
m_unitTypeMask |= UNIT_MASK_PET;
if (type == HUNTER_PET)
m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
@@ -92,7 +94,7 @@ void Pet::RemoveFromWorld()
}
}
bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool current)
bool Pet::LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool current)
{
m_loading = true;
@@ -115,12 +117,12 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
stmt->setUInt32(0, ownerid);
stmt->setUInt8(1, uint8(PET_SAVE_AS_CURRENT));
}
else if (petentry)
else if (petEntry)
{
// known petentry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets)
// known petEntry entry (unique for summoned pet, but non unique for hunter pet (only from current or not stabled pets)
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_PET_BY_ENTRY_AND_SLOT_2);
stmt->setUInt32(0, ownerid);
stmt->setUInt32(1, petentry);
stmt->setUInt32(1, petEntry);
stmt->setUInt8(2, uint8(PET_SAVE_AS_CURRENT));
stmt->setUInt8(3, uint8(PET_SAVE_LAST_STABLE_SLOT));
}
@@ -144,38 +146,36 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
Field* fields = result->Fetch();
// update for case of current pet "slot = 0"
petentry = fields[1].GetUInt32();
if (!petentry)
petEntry = fields[1].GetUInt32();
if (!petEntry)
return false;
uint32 summon_spell_id = fields[15].GetUInt32();
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summon_spell_id);
uint32 summonSpellId = fields[15].GetUInt32();
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(summonSpellId);
bool is_temporary_summoned = spellInfo && spellInfo->GetDuration() > 0;
// check temporary summoned pets like mage water elemental
if (current && is_temporary_summoned)
bool isTemporarySummon = spellInfo && spellInfo->GetDuration() > 0;
if (current && isTemporarySummon)
return false;
PetType pet_type = PetType(fields[16].GetUInt8());
if (pet_type == HUNTER_PET)
PetType petType = PetType(fields[16].GetUInt8());
if (petType == HUNTER_PET)
{
CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petentry);
CreatureTemplate const* creatureInfo = sObjectMgr->GetCreatureTemplate(petEntry);
if (!creatureInfo || !creatureInfo->isTameable(owner->CanTameExoticPets()))
return false;
}
uint32 pet_number = fields[0].GetUInt32();
uint32 petId = fields[0].GetUInt32();
if (current && owner->IsPetNeedBeTemporaryUnsummoned())
{
owner->SetTemporaryUnsummonedPetNumber(pet_number);
owner->SetTemporaryUnsummonedPetNumber(petId);
return false;
}
Map* map = owner->GetMap();
uint32 guid = sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
if (!Create(guid, map, owner->GetPhaseMask(), petentry, pet_number))
if (!Create(guid, map, owner->GetPhaseMask(), petEntry, petId))
return false;
float px, py, pz;
@@ -189,9 +189,9 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
return false;
}
setPetType(pet_type);
setPetType(petType);
setFaction(owner->getFaction());
SetUInt32Value(UNIT_CREATED_BY_SPELL, summon_spell_id);
SetUInt32Value(UNIT_CREATED_BY_SPELL, summonSpellId);
CreatureTemplate const* cinfo = GetCreatureTemplate();
if (cinfo->type == CREATURE_TYPE_CRITTER)
@@ -200,7 +200,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
return true;
}
m_charmInfo->SetPetNumber(pet_number, IsPermanentPetFor(owner));
m_charmInfo->SetPetNumber(petId, IsPermanentPetFor(owner));
SetDisplayId(fields[3].GetUInt32());
SetNativeDisplayId(fields[3].GetUInt32());
@@ -287,13 +287,13 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
// Send fake summon spell cast - this is needed for correct cooldown application for spells
// Example: 46584 - without this cooldown (which should be set always when pet is loaded) isn't set clientside
/// @todo pets should be summoned from real cast instead of just faking it?
if (summon_spell_id)
if (summonSpellId)
{
WorldPacket data(SMSG_SPELL_GO, (8+8+4+4+2));
data.append(owner->GetPackGUID());
data.append(owner->GetPackGUID());
data << uint8(0);
data << uint32(summon_spell_id);
data << uint32(summonSpellId);
data << uint32(256); // CAST_FLAG_UNKNOWN3
data << uint32(0);
owner->SendMessageToSet(&data, true);
@@ -308,7 +308,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
_LoadAuras(timediff);
// load action bar, if data broken will fill later by default spells.
if (!is_temporary_summoned)
if (!isTemporarySummon)
{
m_charmInfo->LoadPetActionBar(fields[13].GetString());
@@ -333,7 +333,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
if (getPetType() == HUNTER_PET)
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PET_DECLINED_NAME);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PET_DECLINED_NAME);
stmt->setUInt32(0, owner->GetGUIDLow());
stmt->setUInt32(1, GetCharmInfo()->GetPetNumber());
PreparedQueryResult result = CharacterDatabase.Query(stmt);
@@ -352,7 +352,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
//set last used pet number (for use in BG's)
if (owner->GetTypeId() == TYPEID_PLAYER && isControlled() && !isTemporarySummoned() && (getPetType() == SUMMON_PET || getPetType() == HUNTER_PET))
owner->ToPlayer()->SetLastPetNumber(pet_number);
owner->ToPlayer()->SetLastPetNumber(petId);
m_loading = false;
@@ -800,8 +800,8 @@ bool Pet::CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phas
{
sLog->outDebug(LOG_FILTER_PETS, "Pet::CreateBaseForTamed");
uint32 guid=sObjectMgr->GenerateLowGuid(HIGHGUID_PET);
uint32 pet_number = sObjectMgr->GeneratePetNumber();
if (!Create(guid, map, phaseMask, cinfo->Entry, pet_number))
uint32 petId = sObjectMgr->GeneratePetNumber();
if (!Create(guid, map, phaseMask, cinfo->Entry, petId))
return false;
SetMaxPower(POWER_HAPPINESS, GetCreatePowers(POWER_HAPPINESS));
@@ -1899,13 +1899,13 @@ bool Pet::IsPermanentPetFor(Player* owner) const
}
}
bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number)
bool Pet::Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 petId)
{
ASSERT(map);
SetMap(map);
SetPhaseMask(phaseMask, false);
Object::_Create(guidlow, pet_number, HIGHGUID_PET);
Object::_Create(guidlow, petId, HIGHGUID_PET);
m_DBTableGuid = guidlow;
m_originalEntry = Entry;
@@ -2066,3 +2066,8 @@ void Pet::ProhibitSpellSchool(SpellSchoolMask idSchoolMask, uint32 unTimeMs)
if (Player* owner = GetOwner())
owner->GetSession()->SendPacket(&data);
}
Player* Pet::GetOwner() const
{
return Minion::GetOwner()->ToPlayer();
}
+2 -1
View File
@@ -144,7 +144,8 @@ class Pet : public Guardian
bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
Player* GetOwner() const { return m_owner; }
Player* GetOwner() const;
protected:
Player* m_owner;
uint32 m_happinessTimer;