Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Unit::isSpellCrit(Unit *pVictim, SpellEntry const *spellProto, SpellSchoolMask schoolMask, WeaponAttackType attackType)
- {
- if (IS_CREATURE_GUID(GetGUID()))
- false;
- // not critting spell
- if ((spellProto->AttributesEx2 & SPELL_ATTR_EX2_CANT_CRIT))
- return false;
- for (int i=0;i<3;++i)
- {
- switch (spellProto->Effect[i])
- {
- // NPCs cannot crit with school damage spells
- case SPELL_EFFECT_SCHOOL_DAMAGE:
- {
- if (!GetCharmerOrOwnerPlayerOrPlayerItself())
- return false;
- break;
- }
- // Leech spells are not considered as direct spell damage ( they cannot crit )
- case SPELL_EFFECT_HEALTH_LEECH:
- return false;
- }
- }
- float crit_chance = 0.0f;
- switch (spellProto->DmgClass)
- {
- case SPELL_DAMAGE_CLASS_NONE: // Exception for Earth Shield and Lifebloom Final Bloom
- if (spellProto->Id != 379 && spellProto->Id != 33778)
- return false;
- case SPELL_DAMAGE_CLASS_MAGIC:
- {
- if (GetTypeId() == TYPEID_PLAYER)
- crit_chance = GetFloatValue( PLAYER_SPELL_CRIT_PERCENTAGE1 + GetFirstSchoolInMask(schoolMask));
- else
- {
- crit_chance = m_baseSpellCritChance;
- crit_chance += GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask);
- }
- // taken
- if (pVictim && !IsPositiveSpell(spellProto->Id))
- {
- // Modify critical chance by victim SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE
- crit_chance += pVictim->GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_ATTACKER_SPELL_CRIT_CHANCE, schoolMask);
- // 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);
- // scripted (increase crit chance ... against ... target by x%
- if(pVictim->isFrozen()) // Shatter
- {
- AuraList const& mOverrideClassScript = GetAurasByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS);
- for(AuraList::const_iterator i = mOverrideClassScript.begin(); i != mOverrideClassScript.end(); ++i)
- {
- switch((*i)->GetModifier()->m_miscvalue)
- {
- case 849: crit_chance+= 10.0f; break; //Shatter Rank 1
- case 910: crit_chance+= 20.0f; break; //Shatter Rank 2
- case 911: crit_chance+= 30.0f; break; //Shatter Rank 3
- case 912: crit_chance+= 40.0f; break; //Shatter Rank 4
- case 913: crit_chance+= 50.0f; break; //Shatter Rank 5
- }
- }
- }
- }
- break;
- }
- case SPELL_DAMAGE_CLASS_MELEE:
- case SPELL_DAMAGE_CLASS_RANGED:
- {
- if (pVictim)
- {
- crit_chance = GetUnitCriticalChance(attackType, pVictim);
- crit_chance+= (int32(GetMaxSkillValueForLevel(pVictim)) - int32(pVictim->GetDefenseSkillValue(this))) * 0.04f;
- crit_chance+= GetTotalAuraModifierByMiscMask(SPELL_AURA_MOD_SPELL_CRIT_CHANCE_SCHOOL, schoolMask);
- // always crit against a sitting target (except 0 crit chance)
- if(crit_chance > 0 && !pVictim->IsStandState())
- {
- return true;
- }
- }
- break;
- }
- default:
- return false;
- }
- // percent done
- // only players use intelligence for critical chance computations
- if(Player* modOwner = GetSpellModOwner())
- modOwner->ApplySpellMod(spellProto->Id, SPELLMOD_CRITICAL_CHANCE, crit_chance);
- crit_chance = crit_chance > 0.0f ? crit_chance : 0.0f;
- if (roll_chance_f(crit_chance))
- return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement