aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorn0n4m3 <none@none>2009-12-19 18:46:51 +0100
committern0n4m3 <none@none>2009-12-19 18:46:51 +0100
commit1d79bc51ea857070c5f23782c84dca5892c9edb2 (patch)
tree63d5c441e5517cff0403f38cab0cf282b7d8cbaf
parent5f0c623f8aaa7a2fc8b6b8a51f35c4370ece7b86 (diff)
Implement player's pet resilience, also fix DoT case. by VladimirMangos and thx tali
--HG-- branch : trunk
-rw-r--r--src/game/Player.cpp50
-rw-r--r--src/game/Player.h6
-rw-r--r--src/game/SpellAuras.cpp14
-rw-r--r--src/game/SpellEffects.cpp8
-rw-r--r--src/game/Unit.cpp72
-rw-r--r--src/game/Unit.h24
6 files changed, 81 insertions, 93 deletions
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 2729e40aeb1..5887d3e24bc 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -5124,56 +5124,6 @@ float Player::GetRatingBonusValue(CombatRating cr) const
return float(GetUInt32Value(PLAYER_FIELD_COMBAT_RATING_1 + cr)) / GetRatingCoefficient(cr);
}
-uint32 Player::GetMeleeCritDamageReduction(uint32 damage) const
-{
- float melee = GetRatingBonusValue(CR_CRIT_TAKEN_MELEE)*2.2f;
- if (melee>33.0f) melee = 33.0f;
- return uint32 (melee * damage /100.0f);
-}
-
-uint32 Player::GetMeleeDamageReduction(uint32 damage) const
-{
- float rate = GetRatingBonusValue(CR_CRIT_TAKEN_MELEE);
- // Resilience not limited (limit it by 100%)
- if (rate > 100.0f)
- rate = 100.0f;
- return uint32 (rate * damage / 100.0f);
-}
-
-uint32 Player::GetRangedCritDamageReduction(uint32 damage) const
-{
- float ranged = GetRatingBonusValue(CR_CRIT_TAKEN_RANGED)*2.2f;
- if (ranged>33.0f) ranged=33.0f;
- return uint32 (ranged * damage /100.0f);
-}
-
-uint32 Player::GetRangedDamageReduction(uint32 damage) const
-{
- float rate = GetRatingBonusValue(CR_CRIT_TAKEN_RANGED);
- // Resilience not limited (limit it by 100%)
- if (rate > 100.0f)
- rate = 100.0f;
- return uint32 (rate * damage / 100.0f);
-}
-
-uint32 Player::GetSpellCritDamageReduction(uint32 damage) const
-{
- float spell = GetRatingBonusValue(CR_CRIT_TAKEN_SPELL)*2.2f;
- // In wow script resilience limited to 33%
- if (spell>33.0f)
- spell = 33.0f;
- return uint32 (spell * damage / 100.0f);
-}
-
-uint32 Player::GetSpellDamageReduction(uint32 damage) const
-{
- float rate = GetRatingBonusValue(CR_CRIT_TAKEN_SPELL);
- // Resilience not limited (limit it by 100%)
- if (rate > 100.0f)
- rate = 100.0f;
- return uint32 (rate * damage / 100.0f);
-}
-
float Player::GetExpertiseDodgeOrParryReduction(WeaponAttackType attType) const
{
switch (attType)
diff --git a/src/game/Player.h b/src/game/Player.h
index 8eddb4b0881..54cea12b52b 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -1722,12 +1722,6 @@ class MANGOS_DLL_SPEC Player : public Unit
float OCTRegenMPPerSpirit();
float GetRatingCoefficient(CombatRating cr) const;
float GetRatingBonusValue(CombatRating cr) const;
- uint32 GetMeleeCritDamageReduction(uint32 damage) const;
- uint32 GetMeleeDamageReduction(uint32 damage) const;
- uint32 GetRangedCritDamageReduction(uint32 damage) const;
- uint32 GetRangedDamageReduction(uint32 damage) const;
- uint32 GetSpellCritDamageReduction(uint32 damage) const;
- uint32 GetSpellDamageReduction(uint32 damage) const;
uint32 GetBaseSpellPowerBonus() { return m_baseSpellPower; }
float GetExpertiseDodgeOrParryReduction(WeaponAttackType attType) const;
diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp
index 99b8876b6e8..0b2089da7e3 100644
--- a/src/game/SpellAuras.cpp
+++ b/src/game/SpellAuras.cpp
@@ -6056,9 +6056,9 @@ void AuraEffect::PeriodicTick()
if (crit)
pdamage = pCaster->SpellCriticalDamageBonus(m_spellProto, pdamage, m_target);
- // Reduce dot damage from resilience for players.
- if (m_target->GetTypeId() == TYPEID_PLAYER)
- pdamage-=((Player*)m_target)->GetSpellDamageReduction(pdamage);
+ // only from players
+ if (IS_PLAYER_GUID(GetCasterGUID()))
+ pdamage -= m_target->GetSpellDamageReduction(pdamage);
pCaster->CalcAbsorbResist(m_target, GetSpellSchoolMask(GetSpellProto()), DOT, pdamage, &absorb, &resist, m_spellProto);
@@ -6330,8 +6330,8 @@ void AuraEffect::PeriodicTick()
int32 drain_amount = m_target->GetPower(power) > pdamage ? pdamage : m_target->GetPower(power);
// resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
- if (power == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
- drain_amount -= ((Player*)m_target)->GetSpellCritDamageReduction(drain_amount);
+ if (power == POWER_MANA)
+ drain_amount -= m_target->GetSpellCritDamageReduction(drain_amount);
m_target->ModifyPower(power, -drain_amount);
@@ -6469,8 +6469,8 @@ void AuraEffect::PeriodicTick()
return;
// resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
- if (powerType == POWER_MANA && m_target->GetTypeId() == TYPEID_PLAYER)
- pdamage -= ((Player*)m_target)->GetSpellCritDamageReduction(pdamage);
+ if (powerType == POWER_MANA)
+ pdamage -= m_target->GetSpellCritDamageReduction(pdamage);
uint32 gain = uint32(-m_target->ModifyPower(powerType, -pdamage));
diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
index 709aefa2b4e..217497820c4 100644
--- a/src/game/SpellEffects.cpp
+++ b/src/game/SpellEffects.cpp
@@ -2646,8 +2646,8 @@ void Spell::EffectPowerDrain(uint32 i)
// resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
uint32 power = damage;
- if ( drain_power == POWER_MANA && unitTarget->GetTypeId() == TYPEID_PLAYER )
- power -= ((Player*)unitTarget)->GetSpellCritDamageReduction(power);
+ if (drain_power == POWER_MANA)
+ power -= unitTarget->GetSpellCritDamageReduction(power);
int32 new_damage;
if(curPower < power)
@@ -2712,8 +2712,8 @@ void Spell::EffectPowerBurn(uint32 i)
uint32 power = damage;
// resilience reduce mana draining effect at spell crit damage reduction (added in 2.4)
- if ( powertype == POWER_MANA && unitTarget->GetTypeId() == TYPEID_PLAYER )
- power -= ((Player*)unitTarget)->GetSpellCritDamageReduction(power);
+ if (powertype == POWER_MANA)
+ power -= unitTarget->GetSpellCritDamageReduction(power);
int32 new_damage = (curPower < power) ? curPower : power;
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index e0cda1b56a9..718fbae1e4d 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -1205,8 +1205,10 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 dama
damage = int32(damage * float((100.0f + critPctDamageMod)/100.0f));
// Resilience - reduce crit damage
- if (pVictim->GetTypeId() == TYPEID_PLAYER)
- damage -= ((Player*)pVictim)->GetMeleeCritDamageReduction(damage);
+ if (attackType != RANGED_ATTACK)
+ damage -= pVictim->GetMeleeCritDamageReduction(damage);
+ else
+ damage -= pVictim->GetRangedCritDamageReduction(damage);
}
// Spell weapon based damage CAN BE crit & blocked at same time
if (blocked)
@@ -1231,8 +1233,7 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 dama
damageInfo->HitInfo|= SPELL_HIT_TYPE_CRIT;
damage = SpellCriticalDamageBonus(spellInfo, damage, pVictim);
// Resilience - reduce crit damage
- if (pVictim->GetTypeId() == TYPEID_PLAYER)
- damage -= ((Player*)pVictim)->GetSpellCritDamageReduction(damage);
+ damage -= pVictim->GetSpellCritDamageReduction(damage);
}
}
break;
@@ -1241,8 +1242,9 @@ void Unit::CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 dama
if (damageSchoolMask & SPELL_SCHOOL_MASK_NORMAL)
damage = CalcArmorReducedDamage(pVictim, damage, spellInfo, attackType);
- if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER)
- damage -= ((Player*)pVictim)->GetSpellDamageReduction(damage);
+ // only from players
+ if (GetTypeId() == TYPEID_PLAYER)
+ damage -= pVictim->GetSpellDamageReduction(damage);
// Calculate absorb resist
if (damage > 0)
@@ -1425,12 +1427,14 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da
damageInfo->damage = int32((damageInfo->damage) * float((100.0f + mod)/100.0f));
// Resilience - reduce crit damage
- if (pVictim->GetTypeId() == TYPEID_PLAYER)
- {
- uint32 resilienceReduction = ((Player*)pVictim)->GetMeleeCritDamageReduction(damageInfo->damage);
- damageInfo->damage -= resilienceReduction;
- damageInfo->cleanDamage += resilienceReduction;
- }
+ uint32 resilienceReduction;
+ if (attackType != RANGED_ATTACK)
+ resilienceReduction = pVictim->GetMeleeCritDamageReduction(damageInfo->damage);
+ else
+ resilienceReduction = pVictim->GetRangedCritDamageReduction(damageInfo->damage);
+
+ damageInfo->damage -= resilienceReduction;
+ damageInfo->cleanDamage += resilienceReduction;
break;
}
case MELEE_HIT_PARRY:
@@ -1491,12 +1495,13 @@ void Unit::CalculateMeleeDamage(Unit *pVictim, uint32 damage, CalcDamageInfo *da
break;
}
- if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER)
+ // only from players
+ if (GetTypeId() == TYPEID_PLAYER)
{
if (attackType != RANGED_ATTACK)
- damage-=((Player*)pVictim)->GetMeleeDamageReduction(damage);
+ damage -= pVictim->GetMeleeDamageReduction(damage);
else
- damage-=((Player*)pVictim)->GetRangedDamageReduction(damage);
+ damage -= pVictim->GetRangedDamageReduction(damage);
}
// Calculate absorb resist
@@ -3186,13 +3191,10 @@ float Unit::GetUnitCriticalChance(WeaponAttackType attackType, const Unit *pVict
crit += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE);
// reduce crit chance from Rating for players
- if (pVictim->GetTypeId() == TYPEID_PLAYER)
- {
- if (attackType==RANGED_ATTACK)
- crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_RANGED);
- else
- crit -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_MELEE);
- }
+ if (attackType != RANGED_ATTACK)
+ crit -= pVictim->GetMeleeCritChanceReduction();
+ else
+ crit -= pVictim->GetRangedCritChanceReduction();
// Apply crit chance from defence skill
crit += (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f;
@@ -9850,8 +9852,7 @@ bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolM
// Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE);
// Modify by player victim resilience
- if (pVictim->GetTypeId() == TYPEID_PLAYER)
- crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL);
+ crit_chance -= pVictim->GetSpellCritChanceReduction();
}
// scripted (increase crit chance ... against ... target by x%
AuraEffectList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
@@ -15088,6 +15089,29 @@ void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
}
}
+float Unit::GetCombatRatingReduction(CombatRating cr) const
+{
+ if (GetTypeId() == TYPEID_PLAYER)
+ return ((Player const*)this)->GetRatingBonusValue(cr);
+ else if (((Creature const*)this)->isPet())
+ {
+ // Player's pet have 0.4 resilience from owner
+ if (Unit* owner = GetOwner())
+ if(owner->GetTypeId() == TYPEID_PLAYER)
+ return ((Player*)owner)->GetRatingBonusValue(cr) * 0.4f;
+ }
+
+ return 0.0f;
+}
+
+uint32 Unit::GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const
+{
+ float percent = GetCombatRatingReduction(cr) * rate;
+ if (percent > cap)
+ percent = cap;
+ return uint32 (percent * damage / 100.0f);
+}
+
uint32 Unit::GetModelForForm(ShapeshiftForm form)
{
switch(form)
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 84a526f2cfb..86db0262a06 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1284,6 +1284,22 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void CalculateSpellDamageTaken(SpellNonMeleeDamage *damageInfo, int32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType = BASE_ATTACK, bool crit = false);
void DealSpellDamage(SpellNonMeleeDamage *damageInfo, bool durabilityLoss);
+
+ // player or player's pet resilience (-1%)
+ float GetMeleeCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_MELEE); }
+ float GetRangedCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_RANGED); }
+ float GetSpellCritChanceReduction() const { return GetCombatRatingReduction(CR_CRIT_TAKEN_SPELL); }
+
+ // player or player's pet resilience (-1%)
+ uint32 GetMeleeCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 2.2f, 33.0f, damage); }
+ uint32 GetRangedCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_RANGED, 2.2f, 33.0f, damage); }
+ uint32 GetSpellCritDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_SPELL, 2.2f, 33.0f, damage); }
+
+ // player or player's pet resilience (-1%), cap 100%
+ uint32 GetMeleeDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
+ uint32 GetRangedDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
+ uint32 GetSpellDamageReduction(uint32 damage) const { return GetCombatRatingDamageReduction(CR_CRIT_TAKEN_MELEE, 1.0f, 100.0f, damage); }
+
float MeleeSpellMissChance(const Unit *pVictim, WeaponAttackType attType, int32 skillDiff, uint32 spellId) const;
SpellMissInfo MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell);
SpellMissInfo MagicSpellHitResult(Unit *pVictim, SpellEntry const *spell);
@@ -1760,8 +1776,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool IsImmunedToDamage(SpellSchoolMask meleeSchoolMask);
bool IsImmunedToDamage(SpellEntry const* spellInfo);
virtual bool IsImmunedToSpellEffect(SpellEntry const* spellInfo, uint32 index) const;
- // redefined in Creature
-
+ // redefined in Creature
+ uint32 CalcNotIgnoreDamageRedunction( uint32 damage, SpellSchoolMask damageSchoolMask);
uint32 CalcArmorReducedDamage(Unit* pVictim, const uint32 damage, SpellEntry const *spellInfo, WeaponAttackType attackType=MAX_ATTACK);
void CalcAbsorbResist(Unit *pVictim, SpellSchoolMask schoolMask, DamageEffectType damagetype, const uint32 damage, uint32 *absorb, uint32 *resist, SpellEntry const *spellInfo = NULL);
@@ -1980,6 +1996,10 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool HandleAuraRaidProcFromChargeWithValue(AuraEffect* triggeredByAura);
bool HandleAuraRaidProcFromCharge(AuraEffect* triggeredByAura);
+ // player or player's pet
+ float GetCombatRatingReduction(CombatRating cr) const;
+ uint32 GetCombatRatingDamageReduction(CombatRating cr, float rate, float cap, uint32 damage) const;
+
void SetFeared(bool apply);
void SetConfused(bool apply);
void SetStunned(bool apply);