[10671] Convert some Unit owner/etc guids to ObjectGuid way.

This commit is contained in:
VladimirMangos 2010-11-01 12:11:23 +03:00
parent 92d98b9fb2
commit a32d68febd
18 changed files with 154 additions and 149 deletions

View file

@ -600,7 +600,7 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
if(pVictim->GetTypeId() == TYPEID_PLAYER && ((Player*)pVictim)->duel && damage >= (health-1))
{
// prevent kill only if killed in duel and killed by opponent or opponent controlled creature
if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetGUID() == GetOwnerGUID())
if(((Player*)pVictim)->duel->opponent==this || ((Player*)pVictim)->duel->opponent->GetObjectGuid() == GetOwnerGuid())
damage = health-1;
duel_hasEnded = true;
@ -1709,7 +1709,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo *damageInfo, bool durabilityLoss)
// If this is a creature and it attacks from behind it has a probability to daze it's victim
if( (damageInfo->hitOutCome==MELEE_HIT_CRIT || damageInfo->hitOutCome==MELEE_HIT_CRUSHING || damageInfo->hitOutCome==MELEE_HIT_NORMAL || damageInfo->hitOutCome==MELEE_HIT_GLANCING) &&
GetTypeId() != TYPEID_PLAYER && !((Creature*)this)->GetCharmerOrOwnerGUID() && !pVictim->HasInArc(M_PI_F, this) )
GetTypeId() != TYPEID_PLAYER && ((Creature*)this)->GetCharmerOrOwnerGuid().IsEmpty() && !pVictim->HasInArc(M_PI_F, this) )
{
// -probability is between 0% and 40%
// 20% base chance
@ -2695,7 +2695,7 @@ MeleeHitOutcome Unit::RollMeleeOutcomeAgainst (const Unit *pVictim, WeaponAttack
// can be from by creature (if can) or from controlled player that considered as creature
(GetTypeId()!=TYPEID_PLAYER && !((Creature*)this)->IsPet() &&
!(((Creature*)this)->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_NO_CRUSH) ||
GetTypeId()==TYPEID_PLAYER && GetCharmerOrOwnerGUID()))
GetTypeId()==TYPEID_PLAYER && !GetCharmerOrOwnerGuid().IsEmpty()))
{
// when their weapon skill is 15 or more above victim's defense skill
tmp = victimDefenseSkill;
@ -5788,14 +5788,16 @@ void Unit::ModifyAuraState(AuraState flag, bool apply)
Unit *Unit::GetOwner() const
{
if(uint64 ownerid = GetOwnerGUID())
ObjectGuid ownerid = GetOwnerGuid();
if (!ownerid.IsEmpty())
return ObjectAccessor::GetUnit(*this, ownerid);
return NULL;
}
Unit *Unit::GetCharmer() const
{
if(uint64 charmerid = GetCharmerGUID())
ObjectGuid charmerid = GetCharmerGuid();
if (!charmerid.IsEmpty())
return ObjectAccessor::GetUnit(*this, charmerid);
return NULL;
}
@ -5805,13 +5807,13 @@ bool Unit::IsCharmerOrOwnerPlayerOrPlayerItself() const
if (GetTypeId()==TYPEID_PLAYER)
return true;
return IS_PLAYER_GUID(GetCharmerOrOwnerGUID());
return GetCharmerOrOwnerGuid().IsPlayer();
}
Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
{
uint64 guid = GetCharmerOrOwnerGUID();
if(IS_PLAYER_GUID(guid))
ObjectGuid guid = GetCharmerOrOwnerGuid();
if (guid.IsPlayer())
return ObjectAccessor::FindPlayer(guid);
return GetTypeId()==TYPEID_PLAYER ? (Player*)this : NULL;
@ -5819,12 +5821,13 @@ Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself()
Pet* Unit::GetPet() const
{
if(uint64 pet_guid = GetPetGUID())
ObjectGuid pet_guid = GetPetGuid();
if (!pet_guid.IsEmpty())
{
if(Pet* pet = GetMap()->GetPet(pet_guid))
return pet;
sLog.outError("Unit::GetPet: Pet %u not exist.",GUID_LOPART(pet_guid));
sLog.outError("Unit::GetPet: %s not exist.", pet_guid.GetString().c_str());
const_cast<Unit*>(this)->SetPet(0);
}
@ -5838,12 +5841,13 @@ Pet* Unit::_GetPet(ObjectGuid guid) const
Unit* Unit::GetCharm() const
{
if (uint64 charm_guid = GetCharmGUID())
ObjectGuid charm_guid = GetCharmGuid();
if (!charm_guid.IsEmpty())
{
if(Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid))
if (Unit* pet = ObjectAccessor::GetUnit(*this, charm_guid))
return pet;
sLog.outError("Unit::GetCharm: Charmed creature %u not exist.",GUID_LOPART(charm_guid));
sLog.outError("Unit::GetCharm: Charmed %s not exist.", charm_guid.GetString().c_str());
const_cast<Unit*>(this)->SetCharm(NULL);
}
@ -5871,7 +5875,7 @@ float Unit::GetCombatDistance( const Unit* target ) const
void Unit::SetPet(Pet* pet)
{
SetPetGUID(pet ? pet->GetGUID() : 0);
SetPetGuid(pet ? pet->GetObjectGuid() : ObjectGuid());
if(pet && GetTypeId() == TYPEID_PLAYER)
((Player*)this)->SendPetGUIDs();
@ -5879,7 +5883,7 @@ void Unit::SetPet(Pet* pet)
void Unit::SetCharm(Unit* pet)
{
SetCharmGUID(pet ? pet->GetGUID() : 0);
SetCharmGuid(pet ? pet->GetObjectGuid() : ObjectGuid());
}
void Unit::AddGuardian( Pet* pet )
@ -7797,7 +7801,7 @@ bool Unit::isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, boo
return false;
}
}
else if(GetCharmerOrOwnerGUID()) // distance for show pet/charmed
else if (!GetCharmerOrOwnerGuid().IsEmpty()) // distance for show pet/charmed
{
// Pet/charmed far than max visible distance for player or not in our map are not visible too
if (!IsWithinDistInMap(viewPoint, _map.GetVisibilityDistance() + (inVisibleList ? World::GetVisibleUnitGreyDistance() : 0.0f), is3dDistance))
@ -7811,7 +7815,7 @@ bool Unit::isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, boo
}
// always seen by owner
if (GetCharmerOrOwnerGUID()==u->GetGUID())
if (GetCharmerOrOwnerGuid() == u->GetObjectGuid())
return true;
// isInvisibleForAlive() those units can only be seen by dead or if other
@ -8409,11 +8413,11 @@ bool Unit::CanHaveThreatList() const
return false;
// pets can not have a threat list, unless they are controlled by a creature
if (creature->IsPet() && IS_PLAYER_GUID(((Pet const*)creature)->GetOwnerGUID()))
if (creature->IsPet() && creature->GetOwnerGuid().IsPlayer())
return false;
// charmed units can not have a threat list if charmed by player
if (creature->isCharmed() && IS_PLAYER_GUID(creature->GetCharmerGUID()))
if (creature->GetCharmerGuid().IsPlayer())
return false;
return true;
@ -10307,8 +10311,8 @@ Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget,uint32 spell_id)
return NULL;
}
pet->SetOwnerGUID(GetGUID());
pet->SetCreatorGUID(GetGUID());
pet->SetOwnerGuid(GetObjectGuid());
pet->SetCreatorGuid(GetObjectGuid());
pet->setFaction(getFaction());
pet->SetUInt32Value(UNIT_CREATED_BY_SPELL, spell_id);