Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.35 KB | None | 0 0
  1. bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType)
  2. {
  3.     if (IS_CREATURE_GUID(GetGUID()))
  4.         false;
  5.  
  6.     // not critting spell
  7.     if ((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT))
  8.         return false;
  9.  
  10.     for (int i=0;i<3;++i)
  11.     {
  12.         switch (spellProto->Effect[i])
  13.         {
  14.             // NPCs cannot crit with school damage spells
  15.             case SPELL_EFFECT_SCHOOL_DAMAGE:
  16.             {
  17.                 if (!GetCharmerOrOwnerPlayerOrPlayerItself())
  18.                     return false;
  19.                 break;
  20.             }
  21.             // Leech spells are not considered as direct spell damage ( they cannot crit )
  22.             case SPELL_EFFECT_HEALTH_LEECH:
  23.                 return false;
  24.         }
  25.     }
  26.  
  27.     float crit_chance = 0.0f;
  28.     switch (spellProto->DmgClass)
  29.     {
  30.         case SPELL_DAMAGE_CLASS_NONE: // Exception for Earth Shield and Lifebloom Final Bloom
  31.             if (spellProto->Id != 379 && spellProto->Id != 33778)
  32.                 return false;
  33.         case SPELL_DAMAGE_CLASS_MAGIC:
  34.         {
  35.             if (GetTypeId() == TYPEID_PLAYER)
  36.                 crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask));
  37.             else
  38.             {
  39.                 crit_chance = m_baseSpellCritChance;
  40.                 crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask);
  41.             }
  42.             // taken
  43.             if (pVictim && !IsPositiveSpell(spellProto->Id))
  44.             {
  45.                 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
  46.                 crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask);
  47.                 // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE
  48.                 crit_chance += pVictim->GetTotalAuraModifier(SPELL_AURA_MOD_ATTACKER_SPELL_AND_WEAPON_CRIT_CHANCE);
  49.                 // Modify by player victim resilience
  50.                 if (pVictim->GetTypeId() == TYPEID_PLAYER)
  51.                     crit_chance -= ((Player*)pVictim)->GetRatingBonusValue(CR_CRIT_TAKEN_SPELL);
  52.                 // scripted (increase crit chance ... against ... target by x%
  53.                 if(pVictim->isFrozen()) // Shatter
  54.                 {
  55.                     AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
  56.                     for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i)
  57.                     {
  58.                         switch((*i)->GetModifier()->m_miscvalue)
  59.                         {
  60.                             case 849: crit_chance+= 10.0f; break; //Shatter Rank 1
  61.                             case 910: crit_chance+= 20.0f; break; //Shatter Rank 2
  62.                             case 911: crit_chance+= 30.0f; break; //Shatter Rank 3
  63.                             case 912: crit_chance+= 40.0f; break; //Shatter Rank 4
  64.                             case 913: crit_chance+= 50.0f; break; //Shatter Rank 5
  65.                         }
  66.                     }
  67.                 }
  68.             }
  69.             break;
  70.         }
  71.         case SPELL_DAMAGE_CLASS_MELEE:
  72.         case SPELL_DAMAGE_CLASS_RANGED:
  73.         {
  74.             if (pVictim)
  75.             {
  76.                 crit_chance = GetUnitCriticalChance(attackType, pVictim);
  77.                 crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f;
  78.                 crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask);
  79.                 // always crit against a sitting target (except 0 crit chance)
  80.                 if(crit_chance > 0 && !pVictim->IsStandState())
  81.                 {
  82.                    return true;
  83.                 }
  84.             }
  85.             break;
  86.         }
  87.         default:
  88.             return false;
  89.     }
  90.     // percent done
  91.     // only players use intelligence for critical chance computations
  92.     if(Player* modOwner = GetSpellModOwner())
  93.         modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance);
  94.  
  95.     crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f;
  96.     if (roll_chance_f(crit_chance))
  97.         return true;
  98.     return false;
  99. }
  100.  
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement