Core/Units: Removed unneeded casts in ApplyResilience

This commit is contained in:
Shauren
2011-03-14 21:39:53 +01:00
parent 6a4ffb4be1
commit cd5744f2c5
+28 -41
View File
@@ -15963,34 +15963,23 @@ void Unit::SetAuraStack(uint32 spellId, Unit *target, uint32 stack)
aura->SetStackAmount(stack); aura->SetStackAmount(stack);
} }
void Unit::ApplyResilience(const Unit *pVictim, float *crit, int32 *damage, bool isCrit, CombatRating type) const void Unit::ApplyResilience(Unit const* victim, float* crit, int32* damage, bool isCrit, CombatRating type) const
{ {
if (IsVehicle() || pVictim->IsVehicle()) // player mounted on multi-passenger mount is also classified as vehicle
if (IsVehicle() || (victim->IsVehicle() && victim->GetTypeId() != TYPEID_PLAYER))
return; return;
const Unit *source = ToPlayer(); Unit const* source = NULL;
if (!source) if (GetTypeId() == TYPEID_PLAYER)
{ source = this;
source = ToCreature(); else if (GetTypeId() == TYPEID_UNIT && GetOwner() && GetOwner()->GetTypeId() == TYPEID_PLAYER)
if (source) source = GetOwner();
{
source = source->ToCreature()->GetOwner();
if (source)
source = source->ToPlayer();
}
}
const Unit *target = pVictim->ToPlayer(); Unit const* target = NULL;
if (!target) if (victim->GetTypeId() == TYPEID_PLAYER)
{ target = victim;
target = pVictim->ToCreature(); else if (victim->GetTypeId() == TYPEID_UNIT && victim->GetOwner() && victim->GetOwner()->GetTypeId() == TYPEID_PLAYER)
if (target) target = victim->GetOwner();
{
target = target->ToCreature()->GetOwner();
if (target)
target = target->ToPlayer();
}
}
if (!target) if (!target)
return; return;
@@ -16000,34 +15989,34 @@ void Unit::ApplyResilience(const Unit *pVictim, float *crit, int32 *damage, bool
case CR_CRIT_TAKEN_MELEE: case CR_CRIT_TAKEN_MELEE:
// Crit chance reduction works against nonpets // Crit chance reduction works against nonpets
if (crit) if (crit)
*crit -= target->ToPlayer()->GetMeleeCritChanceReduction(); *crit -= target->GetMeleeCritChanceReduction();
if (source && damage) if (source && damage)
{ {
if (isCrit) if (isCrit)
*damage -= target->ToPlayer()->GetMeleeCritDamageReduction(*damage); *damage -= target->GetMeleeCritDamageReduction(*damage);
*damage -= target->ToPlayer()->GetMeleeDamageReduction(*damage); *damage -= target->GetMeleeDamageReduction(*damage);
} }
break; break;
case CR_CRIT_TAKEN_RANGED: case CR_CRIT_TAKEN_RANGED:
// Crit chance reduction works against nonpets // Crit chance reduction works against nonpets
if (crit) if (crit)
*crit -= target->ToPlayer()->GetRangedCritChanceReduction(); *crit -= target->GetRangedCritChanceReduction();
if (source && damage) if (source && damage)
{ {
if (isCrit) if (isCrit)
*damage -= target->ToPlayer()->GetRangedCritDamageReduction(*damage); *damage -= target->GetRangedCritDamageReduction(*damage);
*damage -= target->ToPlayer()->GetRangedDamageReduction(*damage); *damage -= target->GetRangedDamageReduction(*damage);
} }
break; break;
case CR_CRIT_TAKEN_SPELL: case CR_CRIT_TAKEN_SPELL:
// Crit chance reduction works against nonpets // Crit chance reduction works against nonpets
if (crit) if (crit)
*crit -= target->ToPlayer()->GetSpellCritChanceReduction(); *crit -= target->GetSpellCritChanceReduction();
if (source && damage) if (source && damage)
{ {
if (isCrit) if (isCrit)
*damage -= target->ToPlayer()->GetSpellCritDamageReduction(*damage); *damage -= target->GetSpellCritDamageReduction(*damage);
*damage -= target->ToPlayer()->GetSpellDamageReduction(*damage); *damage -= target->GetSpellDamageReduction(*damage);
} }
break; break;
default: default:
@@ -16157,15 +16146,13 @@ void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
float Unit::GetCombatRatingReduction(CombatRating cr) const float Unit::GetCombatRatingReduction(CombatRating cr) const
{ {
if (GetTypeId() == TYPEID_PLAYER) if (Player const* player = ToPlayer())
return ((Player const*)this)->GetRatingBonusValue(cr); return player->GetRatingBonusValue(cr);
else if (((Creature const*)this)->isPet()) // Player's pet get resilience from owner
{ else if (isPet())
// Player's pet get resilience from owner
if (Unit* owner = GetOwner()) if (Unit* owner = GetOwner())
if (owner->GetTypeId() == TYPEID_PLAYER) if (Player* player = owner->ToPlayer())
return ((Player*)owner)->GetRatingBonusValue(cr); return player->GetRatingBonusValue(cr);
}
return 0.0f; return 0.0f;
} }