Jump to content

[Fix] Unit::MeleeMissChanceCalc


Auntie Mangos

Recommended Posts

What bug does the patch fix? What features does the patch add?

replaces absolete melee miss chance calculation with current one.

better variable name ( misschance -> missChance )

For which repository revision was the patch created?

9100

Is there a thread in the bug report section or at lighthouse?

http://getmangos.eu/community/showthread.php?11912-[bUG]-miss-chance-for-melee-damage

Who has been writing this patch? Please include either forum user names or email addresses.

Me

http://pastebin.com/m23d00a18

diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 98c4f94..036b052 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
-2843,7 +2840,7 @@ float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) c
        return 0.0f;

    // Base misschance 5%
-    float misschance = 5.0f;
+    float missChance = 5.0f;

    // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
    if (haveOffhandWeapon() && attType != RANGED_ATTACK)
-2858,56 +2855,39 @@ float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) c
            }
        }
        if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL])
-            misschance = 5.0f;
+            missChance = 5.0f;
        else
-            misschance = 24.0f;
+            missChance = 24.0f;
    }

-    // PvP : PvE melee misschances per leveldif > 2
-    int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7;
-
-    int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim));
-    if(leveldif < 0)
-        leveldif = 0;
-
-    // Hit chance from attacker based on ratings and auras
-    float m_modHitChance;
-    if (attType == RANGED_ATTACK)
-        m_modHitChance = m_modRangedHitChance;
-    else
-        m_modHitChance = m_modMeleeHitChance;
-
-    if(leveldif < 3)
-        misschance += (leveldif - m_modHitChance);
-    else
-        misschance += ((leveldif - 2) * chance - m_modHitChance);
-
-    // Hit chance for victim based on ratings
-    if (pVictim->GetTypeId()==TYPEID_PLAYER)
-    {
-        if (attType == RANGED_ATTACK)
-            misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED);
-        else
-            misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE);
-    }
+	int32 skillDiff = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this));
+    // PvP - PvE melee chances
+	if ( pVictim->GetTypeId() == TYPEID_PLAYER )
+		 missChance -= skillDiff * (skillDiff > 0 ? 0.02f : 0.04f);
+	else if ( skillDiff < -10 )
+		 missChance -= (skillDiff + 10) * 0.4f - 1.0f;
+	else
+		 missChance -=  skillDiff * 0.1f;

    // Modify miss chance by victim auras
    if(attType == RANGED_ATTACK)
-        misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE);
+        missChance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE);
    else
-        misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE);
+        missChance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE);

-    // Modify miss chance from skill difference ( bonus from skills is 0.04% )
-    int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this));
-    misschance -= skillBonus * 0.04f;
+	// Bonuses from attacker aura and ratings
+	if (attType == RANGED_ATTACK)
+		missChance -= m_modRangedHitChance;
+	else
+		missChance -= m_modMeleeHitChance;

    // Limit miss chance from 0 to 60%
-    if ( misschance < 0.0f)
+    if ( missChance < 0.0f)
        return 0.0f;
-    if ( misschance > 60.0f)
+    if ( missChance > 60.0f)
        return 60.0f;

-    return misschance;
+    return missChance;
}

uint32 Unit::GetDefenseSkillValue(Unit const* target) const

Link to comment
Share on other sites

  • 40 years later...
Same as in MeleeSpellMissChance topic, dosen't work as intended.

Moob miss very very mutch on level 80.

Could you be more specific, please? :)

//edit

I can see a problem now ( I think ), mobs can have low weapon skill thus they miss a lot. I didn't find this because I tested only between players or player'S hit chance against mob but not the other way.

Thanks

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) const
{
   if(!pVictim)
       return 0.0f;

   // Base misschance 5%
   float misschance = 5.0f;

   // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
   if (haveOffhandWeapon() && attType != RANGED_ATTACK)
   {
       bool isNormal = false;
       for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
       {
           if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) )
           {
               isNormal = true;
               break;
           }
       }
       if (!isNormal && !m_currentSpells[CURRENT_MELEE_SPELL])
           misschance += 19.0f;
   }

   int32 skillBonus = int32(pVictim->GetDefenseSkillValue(this)) - int32(this->GetWeaponSkillValue(attType, pVictim));

   if (abs(skillBonus) <= 10)
       misschance += skillBonus * 0.1f;
   else
       misschance += 1.0f + (skillBonus - 10) * 0.4f;

   // Hit chance from attacker based on ratings and auras
   if (attType == RANGED_ATTACK)
       misschance -= m_modRangedHitChance;
   else
       misschance  -= m_modMeleeHitChance;

   // Hit chance for victim based on ratings
   if (pVictim->GetTypeId()==TYPEID_PLAYER)
   {
       if (attType == RANGED_ATTACK)
           misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED);
       else
           misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE);
   }

   // Modify miss chance by victim auras
   if(attType == RANGED_ATTACK)
       misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE);
   else
       misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE);

   // Limit miss chance from 0 to 60%
   if ( misschance < 0.0f)
       return 0.0f;
   if ( misschance > 60.0f)
       return 60.0f;

   return misschance;
}

whole MeleeMissChanceCalc function with formula accordng to Wowwiki.

Link to comment
Share on other sites

  • 4 months later...

patch updated for 10457

diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 8428cf2..136b759 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -3043,7 +3043,7 @@ float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) c
        return 0.0f;

    // Base misschance 5%
-    float misschance = 5.0f;
+    float missChance = 5.0f;

    // DualWield - Melee spells and physical dmg spells - 5% , white damage 24%
    if (haveOffhandWeapon() && attType != RANGED_ATTACK)
@@ -3051,63 +3051,51 @@ float Unit::MeleeMissChanceCalc(const Unit *pVictim, WeaponAttackType attType) c
        bool isNormal = false;
        for (uint32 i = CURRENT_FIRST_NON_MELEE_SPELL; i < CURRENT_MAX_SPELL; ++i)
        {
-            if( m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL) )
+            if (m_currentSpells[i] && (GetSpellSchoolMask(m_currentSpells[i]->m_spellInfo) & SPELL_SCHOOL_MASK_NORMAL))
            {
                isNormal = true;
                break;
            }
        }
-        if (isNormal || m_currentSpells[CURRENT_MELEE_SPELL])
-            misschance = 5.0f;
-        else
-            misschance = 24.0f;
+        if (!isNormal && !m_currentSpells[CURRENT_MELEE_SPELL])
+            missChance += 19.0f;
    }

-    // PvP : PvE melee misschances per leveldif > 2
-    int32 chance = pVictim->GetTypeId() == TYPEID_PLAYER ? 5 : 7;
+    int32 skillBonus = int32(pVictim->GetDefenseSkillValue(this)) - int32(this->GetWeaponSkillValue(attType, pVictim));

-    int32 leveldif = int32(pVictim->getLevelForTarget(this)) - int32(getLevelForTarget(pVictim));
-    if(leveldif < 0)
-        leveldif = 0;
+    if (abs(skillBonus) <= 10)
+        missChance += skillBonus * 0.1f;
+    else
+        missChance += 1.0f + (skillBonus - 10) * 0.4f;

    // Hit chance from attacker based on ratings and auras
-    float m_modHitChance;
    if (attType == RANGED_ATTACK)
-        m_modHitChance = m_modRangedHitChance;
-    else
-        m_modHitChance = m_modMeleeHitChance;
-
-    if(leveldif < 3)
-        misschance += (leveldif - m_modHitChance);
+        missChance -= m_modRangedHitChance;
    else
-        misschance += ((leveldif - 2) * chance - m_modHitChance);
+        missChance -= m_modMeleeHitChance;

    // Hit chance for victim based on ratings
    if (pVictim->GetTypeId()==TYPEID_PLAYER)
    {
        if (attType == RANGED_ATTACK)
-            misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED);
+            missChance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_RANGED);
        else
-            misschance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE);
+            missChance += ((Player*)pVictim)->GetRatingBonusValue(CR_HIT_TAKEN_MELEE);
    }

    // Modify miss chance by victim auras
    if(attType == RANGED_ATTACK)
-        misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE);
+        missChance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_RANGED_HIT_CHANCE);
    else
-        misschance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE);
-
-    // Modify miss chance from skill difference ( bonus from skills is 0.04% )
-    int32 skillBonus = int32(GetWeaponSkillValue(attType,pVictim)) - int32(pVictim->GetDefenseSkillValue(this));
-    misschance -= skillBonus * 0.04f;
+        missChance -= pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_MELEE_HIT_CHANCE);

    // Limit miss chance from 0 to 60%
-    if ( misschance < 0.0f)
+    if (missChance < 0.0f)
        return 0.0f;
-    if ( misschance > 60.0f)
+    if (missChance > 60.0f)
        return 60.0f;

-    return misschance;
+    return missChance;
}

uint32 Unit::GetDefenseSkillValue(Unit const* target) const

Link to comment
Share on other sites

  • 1 month later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use