Jump to content

Unit::MeleeSpellHitResult


Guest laise

Recommended Posts

can some1 explain why there are strange calculations like urand(0,10000) there instead of something looking like this :

diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 11b89dc..2fbda5c 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -2638,15 +2638,13 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell)
    int32 skillDiff = attackerWeaponSkill - int32(pVictim->GetMaxSkillValueForLevel(this));
    int32 fullSkillDiff = attackerWeaponSkill - int32(pVictim->GetDefenseSkillValue(this));

-    uint32 roll = urand (0, 10000);
-
-    uint32 missChance = uint32(MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell)*100.0f);
+    float missChance = MeleeSpellMissChance(pVictim, attType, fullSkillDiff, spell);
+    
    // Roll miss
-    uint32 tmp = missChance;
-    if (roll < tmp)
+    if (roll_chance_f(missChance))
        return SPELL_MISS_MISS;

-    // Chance resist mechanic (select max value from every mechanic spell effect)
+    // Chance resist mechanic (select max value from every mechanic spell effect
    int32 resist_mech = 0;
    // Get effects mechanic and chance
    for(int eff = 0; eff < 3; ++eff)
@@ -2655,13 +2653,12 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell)
        if (effect_mech)
        {
            int32 temp = pVictim->GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_MECHANIC_RESISTANCE, effect_mech);
-            if (resist_mech < temp*100)
-                resist_mech = temp*100;
+            if (resist_mech < temp)
+                resist_mech = temp;
        }
    }
    // Roll chance
-    tmp += resist_mech;
-    if (roll < tmp)
+    if (roll_chance_i(resist_mech))
        return SPELL_MISS_RESIST;

    bool canDodge = true;
@@ -2677,9 +2674,8 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell)
        // only if in front
        if (pVictim->HasInArc(M_PI,this))
        {
-            int32 deflect_chance = pVictim->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS)*100;
-            tmp+=deflect_chance;
-            if (roll < tmp)
+            int32 deflect_chance = pVictim->GetTotalAuraModifier(SPELL_AURA_DEFLECT_SPELLS);
+            if (roll_chance_i(deflect_chance))
                return SPELL_MISS_DEFLECT;
        }
        return SPELL_MISS_NONE;
@@ -2721,36 +2717,34 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit *pVictim, SpellEntry const *spell)
    if (canDodge)
    {
        // Roll dodge
-        int32 dodgeChance = int32(pVictim->GetUnitDodgeChance()*100.0f) - skillDiff * 4;
+        float dodgeChance = pVictim->GetUnitDodgeChance() - skillDiff * 0.04f;
        // Reduce enemy dodge chance by SPELL_AURA_MOD_COMBAT_RESULT_CHANCE
-        dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE)*100;
+        dodgeChance+= GetTotalAuraModifierByMiscValue(SPELL_AURA_MOD_COMBAT_RESULT_CHANCE, VICTIMSTATE_DODGE);
        // Reduce dodge chance by attacker expertise rating
        if (GetTypeId() == TYPEID_PLAYER)
-            dodgeChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f);
+            dodgeChance-= ((Player*)this)->GetExpertiseDodgeOrParryReduction(attType);
        else
-            dodgeChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25;
+            dodgeChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE) * 0.25f;
        if (dodgeChance < 0)
            dodgeChance = 0;

-        tmp += dodgeChance;
-        if (roll < tmp)
+        if (roll_chance_f(dodgeChance))
            return SPELL_MISS_DODGE;
    }

    if (canParry)
    {
        // Roll parry
-        int32 parryChance = int32(pVictim->GetUnitParryChance()*100.0f)  - skillDiff * 4;
+        float parryChance = pVictim->GetUnitParryChance() - skillDiff * 0.04f;
        // Reduce parry chance by attacker expertise rating
        if (GetTypeId() == TYPEID_PLAYER)
-            parryChance-=int32(((Player*)this)->GetExpertiseDodgeOrParryReduction(attType) * 100.0f);
+            parryChance-=((Player*)this)->GetExpertiseDodgeOrParryReduction(attType);
        else
-            parryChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE)*25;
+            parryChance -= GetTotalAuraModifier(SPELL_AURA_MOD_EXPERTISE) * 0.25f;
        if (parryChance < 0)
            parryChance = 0;

-        tmp += parryChance;
-        if (roll < tmp)
+        if (roll_chance_f(parryChance))
            return SPELL_MISS_PARRY;
    }

Link to comment
Share on other sites

×
×
  • 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