[10754] Use UNIT_FIELD_CRITTER for store minipet guid.

Also move related code to Unit and allow summon minipets by creatures.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>

Also fix creature's totems unsummon at owner remove from world.
This commit is contained in:
rsa 2010-11-20 04:23:47 +03:00 committed by VladimirMangos
parent f671f09950
commit 92ed528eb9
7 changed files with 35 additions and 45 deletions

View file

@ -720,7 +720,7 @@ void Pet::Unsummon(PetSaveMode mode, Unit* owner /*= NULL*/)
{ {
case MINI_PET: case MINI_PET:
if (p_owner) if (p_owner)
p_owner->_SetMiniPet(NULL); p_owner->SetMiniPet(NULL);
break; break;
case PROTECTOR_PET: case PROTECTOR_PET:
case GUARDIAN_PET: case GUARDIAN_PET:

View file

@ -1489,9 +1489,6 @@ void Player::SetDeathState(DeathState s)
//FIXME: is pet dismissed at dying or releasing spirit? if second, add SetDeathState(DEAD) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD) //FIXME: is pet dismissed at dying or releasing spirit? if second, add SetDeathState(DEAD) to HandleRepopRequestOpcode and define pet unsummon here with (s == DEAD)
RemovePet(PET_SAVE_REAGENTS); RemovePet(PET_SAVE_REAGENTS);
// remove uncontrolled pets
RemoveMiniPet();
// save value before aura remove in Unit::SetDeathState // save value before aura remove in Unit::SetDeathState
ressSpellId = GetUInt32Value(PLAYER_SELF_RES_SPELL); ressSpellId = GetUInt32Value(PLAYER_SELF_RES_SPELL);
@ -2015,14 +2012,6 @@ void Player::AddToWorld()
void Player::RemoveFromWorld() void Player::RemoveFromWorld()
{ {
// cleanup
if(IsInWorld())
{
///- Release charmed creatures, unsummon totems and remove pets/guardians
UnsummonAllTotems();
RemoveMiniPet();
}
for(int i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i) for(int i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i)
{ {
if(m_items[i]) if(m_items[i])
@ -17788,20 +17777,6 @@ void Player::RemovePet(PetSaveMode mode)
pet->Unsummon(mode, this); pet->Unsummon(mode, this);
} }
void Player::RemoveMiniPet()
{
if (Pet* pet = GetMiniPet())
pet->Unsummon(PET_SAVE_AS_DELETED);
}
Pet* Player::GetMiniPet() const
{
if (m_miniPetGuid.IsEmpty())
return NULL;
return GetMap()->GetPet(m_miniPetGuid);
}
void Player::BuildPlayerChat(WorldPacket *data, uint8 msgtype, const std::string& text, uint32 language) const void Player::BuildPlayerChat(WorldPacket *data, uint8 msgtype, const std::string& text, uint32 language) const
{ {
*data << (uint8)msgtype; *data << (uint8)msgtype;

View file

@ -1214,11 +1214,6 @@ class MANGOS_DLL_SPEC Player : public Unit
void UpdateInnerTime (time_t time) { time_inn_enter = time; } void UpdateInnerTime (time_t time) { time_inn_enter = time; }
void RemovePet(PetSaveMode mode); void RemovePet(PetSaveMode mode);
void RemoveMiniPet();
Pet* GetMiniPet() const;
// use only in Pet::Unsummon/Spell::DoSummon
void _SetMiniPet(Pet* pet) { m_miniPetGuid = pet ? pet->GetObjectGuid() : ObjectGuid(); }
template<typename Func> template<typename Func>
void CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms, bool withMiniPet); void CallForAllControlledUnits(Func const& func, bool withTotems, bool withGuardians, bool withCharms, bool withMiniPet);
@ -2626,8 +2621,6 @@ class MANGOS_DLL_SPEC Player : public Unit
uint32 m_groupUpdateMask; uint32 m_groupUpdateMask;
uint64 m_auraUpdateMask; uint64 m_auraUpdateMask;
ObjectGuid m_miniPetGuid;
// Player summoning // Player summoning
time_t m_summon_expire; time_t m_summon_expire;
uint32 m_summon_mapid; uint32 m_summon_mapid;

View file

@ -7521,26 +7521,22 @@ void Spell::EffectCharge2(SpellEffectIndex /*eff_idx*/)
void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction) void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction)
{ {
if(m_caster->GetTypeId() != TYPEID_PLAYER)
return;
Player* player = (Player*)m_caster;
uint32 pet_entry = m_spellInfo->EffectMiscValue[eff_idx]; uint32 pet_entry = m_spellInfo->EffectMiscValue[eff_idx];
if(!pet_entry) if(!pet_entry)
return; return;
Pet* old_critter = player->GetMiniPet(); Pet* old_critter = m_caster->GetMiniPet();
// for same pet just despawn // for same pet just despawn (player unsummon command)
if(old_critter && old_critter->GetEntry() == pet_entry) if (m_caster->GetTypeId() == TYPEID_PLAYER && old_critter && old_critter->GetEntry() == pet_entry)
{ {
player->RemoveMiniPet(); m_caster->RemoveMiniPet();
return; return;
} }
// despawn old pet before summon new // despawn old pet before summon new
if (old_critter) if (old_critter)
player->RemoveMiniPet(); m_caster->RemoveMiniPet();
// summon new pet // summon new pet
Pet* critter = new Pet(MINI_PET); Pet* critter = new Pet(MINI_PET);
@ -7596,7 +7592,7 @@ void Spell::DoSummonCritter(SpellEffectIndex eff_idx, uint32 forceFaction)
if(duration > 0) if(duration > 0)
critter->SetDuration(duration); critter->SetDuration(duration);
player->_SetMiniPet(critter); m_caster->SetMiniPet(critter);
map->Add((Creature*)critter); map->Add((Creature*)critter);
} }

View file

@ -5849,6 +5849,22 @@ Pet* Unit::_GetPet(ObjectGuid guid) const
return GetMap()->GetPet(guid); return GetMap()->GetPet(guid);
} }
void Unit::RemoveMiniPet()
{
if (Pet* pet = GetMiniPet())
pet->Unsummon(PET_SAVE_AS_DELETED, this);
else
SetCritterGuid(ObjectGuid());
}
Pet* Unit::GetMiniPet() const
{
if (GetCritterGuid().IsEmpty())
return NULL;
return GetMap()->GetPet(GetCritterGuid());
}
Unit* Unit::GetCharm() const Unit* Unit::GetCharm() const
{ {
ObjectGuid charm_guid = GetCharmGuid(); ObjectGuid charm_guid = GetCharmGuid();
@ -8365,6 +8381,7 @@ void Unit::SetDeathState(DeathState s)
{ {
RemoveAllAurasOnDeath(); RemoveAllAurasOnDeath();
RemoveGuardians(); RemoveGuardians();
RemoveMiniPet();
UnsummonAllTotems(); UnsummonAllTotems();
// after removing a Fearaura (in RemoveAllAurasOnDeath) // after removing a Fearaura (in RemoveAllAurasOnDeath)
@ -9287,6 +9304,8 @@ void Unit::RemoveFromWorld()
Uncharm(); Uncharm();
RemoveNotOwnSingleTargetAuras(); RemoveNotOwnSingleTargetAuras();
RemoveGuardians(); RemoveGuardians();
RemoveMiniPet();
UnsummonAllTotems();
RemoveAllGameObjects(); RemoveAllGameObjects();
RemoveAllDynObjects(); RemoveAllDynObjects();
CleanupDeletedAuras(); CleanupDeletedAuras();

View file

@ -1496,6 +1496,13 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
ObjectGuid const& GetChannelObjectGuid() const { return GetGuidValue(UNIT_FIELD_CHANNEL_OBJECT); } ObjectGuid const& GetChannelObjectGuid() const { return GetGuidValue(UNIT_FIELD_CHANNEL_OBJECT); }
void SetChannelObjectGuid(ObjectGuid targetGuid) { SetGuidValue(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); } void SetChannelObjectGuid(ObjectGuid targetGuid) { SetGuidValue(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }
void SetCritterGuid(ObjectGuid critterGuid) { SetGuidValue(UNIT_FIELD_CRITTER, critterGuid); }
ObjectGuid const& GetCritterGuid() const { return GetGuidValue(UNIT_FIELD_CRITTER); }
void RemoveMiniPet();
Pet* GetMiniPet() const;
void SetMiniPet(Unit* pet) { SetCritterGuid(pet ? pet->GetObjectGuid() : ObjectGuid()); }
ObjectGuid const& GetCharmerOrOwnerGuid() const { return !GetCharmerGuid().IsEmpty() ? GetCharmerGuid() : GetOwnerGuid(); } ObjectGuid const& GetCharmerOrOwnerGuid() const { return !GetCharmerGuid().IsEmpty() ? GetCharmerGuid() : GetOwnerGuid(); }
ObjectGuid const& GetCharmerOrOwnerOrOwnGuid() const ObjectGuid const& GetCharmerOrOwnerOrOwnGuid() const
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10753" #define REVISION_NR "10754"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__