public virtual bool CheckHit(Mobile attacker, Mobile defender)
{
BaseWeapon atkWeapon = attacker.Weapon as BaseWeapon;
BaseWeapon defWeapon = defender.Weapon as BaseWeapon;
Skill atkSkill = attacker.Skills[atkWeapon.Skill];
Skill defSkill = defender.Skills[defWeapon.Skill];
double atkValue = atkWeapon.GetAttackSkillValue(attacker, defender);
double defValue = defWeapon.GetDefendSkillValue(attacker, defender);
double ourValue, theirValue;
int bonus = GetHitChanceBonus();
#region SA
if (atkWeapon is BaseThrown)
{
int min = ((BaseThrown)atkWeapon).MinThrowRange;
int throwchances = 0;
if (attacker.InRange(defender, 1))
throwchances -= 12 - (int)(attacker.Skills[SkillName.Swords].Value / 10);
else if (!attacker.InRange(defender, min - 1))
throwchances -= 12;
BaseShield shield = attacker.FindItemOnLayer(Layer.TwoHanded) as BaseShield;
if (shield != null)
{
throwchances -= 12 - (int)(attacker.Skills[SkillName.Parry].Value / 10);
throwchances -= Math.Max(0, (10 - (attacker.Dex / 10)));
}
if (throwchances < 0)
throwchances = 0;
bonus += throwchances;
}
#endregion
if (Core.AOS)
{
if (atkValue <= -20.0)
atkValue = -19.9;
if (defValue <= -20.0)
defValue = -19.9;
// Hit Chance Increase = 45%
int atkChance = AosAttributes.GetValue(attacker, AosAttribute.AttackChance);
if (atkChance > 45)
atkChance = 45;
bonus += atkChance;
if (Spells.Chivalry.DivineFurySpell.UnderEffect(attacker))
bonus += 10; // attacker gets 10% bonus when they're under divine fury
if (CheckAnimal(attacker, typeof(GreyWolf)) || CheckAnimal(attacker, typeof(BakeKitsune)))
bonus += 20; // attacker gets 20% bonus when under Wolf or Bake Kitsune form
if (HitLower.IsUnderAttackEffect(attacker))
bonus -= 25; // Under Hit Lower Attack effect -> 25% malus
WeaponAbility ability = WeaponAbility.GetCurrentAbility(attacker);
if (ability != null)
bonus += ability.AccuracyBonus;
SpecialMove move = SpecialMove.GetCurrentMove(attacker);
if (move != null)
bonus += move.GetAccuracyBonus(attacker);
// Max Hit Chance Increase = 45%
if (bonus > 45)
bonus = 45;
ourValue = (atkValue + 20.0) * (100 + bonus);
bonus = AosAttributes.GetValue(defender, AosAttribute.DefendChance);
if (Spells.Chivalry.DivineFurySpell.UnderEffect(defender))
bonus -= 20; // defender loses 20% bonus when they're under divine fury
if (HitLower.IsUnderDefenseEffect(defender))
bonus -= 25; // Under Hit Lower Defense effect -> 25% malus
int blockBonus = 0;
if (Block.GetBonus(defender, ref blockBonus))
bonus += blockBonus;
int surpriseMalus = 0;
if (SurpriseAttack.GetMalus(defender, ref surpriseMalus))
bonus -= surpriseMalus;
int discordanceEffect = 0;
// Defender loses -0/-28% if under the effect of Discordance.
if (SkillHandlers.Discordance.GetEffect(attacker, ref discordanceEffect))
bonus -= discordanceEffect;
// Defense Chance Increase = 45%
if (bonus > 45)
bonus = 45;
theirValue = (defValue + 20.0) * (100 + bonus);
bonus = 0;
}
else
{
if (atkValue <= -50.0)
atkValue = -49.9;
if (defValue <= -50.0)
defValue = -49.9;
ourValue = (atkValue + 50.0);
theirValue = (defValue + 50.0);
}
double chance = ourValue / (theirValue * 2.0);
chance *= 1.0 + ((double)bonus / 100);
if (Core.AOS && chance < 0.02)
chance = 0.02;
return attacker.CheckSkill(atkSkill.SkillName, chance);
}