Core/Misc: replace (Player*) casts with ToPlayer()

This commit is contained in:
joschiwald committed 2013-07-21 01:38:21 +02:00
1 parent 1ac4f0a9c1
commit 380cf5d241
15 files changed
+189 -186

No files matched your search

+21 -18
View File
@@ -9264,16 +9264,17 @@ Player* Unit::GetCharmerOrOwnerPlayerOrPlayerItself() const
if (IS_PLAYER_GUID(guid))
return ObjectAccessor::GetPlayer(*this, guid);
return GetTypeId() == TYPEID_PLAYER ? (Player*)this : NULL;
return const_cast<Unit*>(this)->ToPlayer();
}
Player* Unit::GetAffectingPlayer() const
{
if (!GetCharmerOrOwnerGUID())
return GetTypeId() == TYPEID_PLAYER ? (Player*)this : NULL;
return const_cast<Unit*>(this)->ToPlayer();
if (Unit* owner = GetCharmerOrOwner())
return owner->GetCharmerOrOwnerPlayerOrPlayerItself();
return NULL;
}
@@ -14386,13 +14387,14 @@ uint64 Unit::GetCharmerOrOwnerOrOwnGUID() const
Player* Unit::GetSpellModOwner() const
{
if (GetTypeId() == TYPEID_PLAYER)
return (Player*)this;
if (Player* player = const_cast<Unit*>(this)->ToPlayer())
return player;
if (ToCreature()->IsPet() || ToCreature()->IsTotem())
{
Unit* owner = GetOwner();
if (owner && owner->GetTypeId() == TYPEID_PLAYER)
return (Player*)owner;
if (Unit* owner = GetOwner())
if (Player* player = owner->ToPlayer())
return player;
}
return NULL;
}
@@ -14904,7 +14906,7 @@ Pet* Unit::CreateTamedPetFrom(Creature* creatureTarget, uint32 spell_id)
if (GetTypeId() != TYPEID_PLAYER)
return NULL;
Pet* pet = new Pet((Player*)this, HUNTER_PET);
Pet* pet = new Pet(ToPlayer(), HUNTER_PET);
if (!pet->CreateBaseAtCreature(creatureTarget))
{
@@ -14928,7 +14930,7 @@ Pet* Unit::CreateTamedPetFrom(uint32 creatureEntry, uint32 spell_id)
if (!creatureInfo)
return NULL;
Pet* pet = new Pet((Player*)this, HUNTER_PET);
Pet* pet = new Pet(ToPlayer(), HUNTER_PET);
if (!pet->CreateBaseAtCreatureInfo(creatureInfo, this) || !InitTamedPet(pet, getLevel(), spell_id))
{
@@ -15404,8 +15406,8 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
{
if (Battleground* bg = player->GetBattleground())
{
if (victim->GetTypeId() == TYPEID_PLAYER)
bg->HandleKillPlayer((Player*)victim, player);
if (Player* playerVictim = victim->ToPlayer())
bg->HandleKillPlayer(playerVictim, player);
else
bg->HandleKillUnit(victim->ToCreature(), player);
}
@@ -16368,14 +16370,15 @@ void Unit::UpdateObjectVisibility(bool forced)
void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
{
Player* player = NULL;
if (GetTypeId() == TYPEID_PLAYER)
player = (Player*)this;
else if (Unit* charmer = GetCharmer())
Player* player = ToPlayer();
if (!player)
{
player = charmer->ToPlayer();
if (player && player->m_mover != this)
player = NULL;
if (Unit* charmer = GetCharmer())
{
player = charmer->ToPlayer();
if (player && player->m_mover != this)
player = NULL;
}
}
if (!player)