Star Wars: Knights of the Old Republic/Combat

Attack
Attacks with weapons cannot normally hit and subsequently damage an opponent unless an attack roll is equal to or greater than that opponent's defense. An attack roll is the sum of attack bonuses and a d20 roll. According to the Messages - Feedback window, a minimum d20 roll (1) is an automatic miss while a maximum d20 roll (20) is an automatic hit, so chance to hit has a minimum of 5% and a maximum of 95% regardless of whether or not the total attack roll would equal or exceed defense. Maximum 95% chance to hit is achieved when the sum of attack bonuses + 2 (the lowest d20 roll that is not an automatic miss) is equal to or greater than an opponent's defense.

According to the Messages - Feedback window, melee on ranged bonus of +10 is added to attack roll when a melee attacker attacks a ranged opponent. Conversely, Close Proximity Ranged Bonus of +10 is added to attack roll when a ranged attacker attacks any opponent in close proximity.

Base
All characters have a base attack bonus which increases as level increases. Progression varies according to class:

Attribute modifier
Strength modifier is added to attack roll when using melee weapons, or lightsabers when equal to or greater than Dexterity modifier.

Dexterity modifier is added to attack roll when using ranged weapons, or lightsabers when greater than Strength modifier.

Dual Wield Penalty
Using two weapons or a double-bladed weapon normally incurs an attack penalty, which depends on whether or not the attacker has any Two-Weapon Fighting feat and a balanced weapon (which adds a Small Offhand Bonus of +2 to the attacks of the main hand):

Feats
Numerous feats apply a bonus or penalty to the attack roll:

Effect bonus
Various weapons add an attack bonus to the attack roll, while the Dark Side Force power Slow applies a penalty of -2.

Critical threat
As well as resulting in an automatic hit, a maximum d20 roll of 20 results in an automatic critical threat. A critical threat is a second attack roll which can result in a critical hit applying a second damage roll when equal to or greater than an opponent's defense.

Some weapons have a higher critical threat range, increasing the chance of a roll within that range:

Lightsabers and Short Lightsabers all have base critical threat range 19-20 (10%), while Double-Bladed Lightsabers only have 20-20 (5%). The Keen bonus can increase base critical threat range, as can the Critical Strike and Sniper Shot feats. According to the Messages - Feedback window, any Keen bonus is additive with feat bonuses, resulting in the following:

Defense
Characters can only be hit and subsequently damaged by attacks with weapons when an attack roll is equal to or greater than defense. An attack roll is the sum of attack bonuses and a d20 roll. According to the Messages - Feedback window, a minimum d20 roll (1) is an automatic miss while a maximum d20 roll (20) is an automatic hit, so chance to hit has a minimum of 5% and a maximum of 95% regardless of whether or not the total attack roll would equal or exceed defense. Minimum 5% chance to hit is achieved when defense is greater than an opponent's attack roll + 19 (the highest d20 roll that is not an automatic hit).

All characters have base defense 10, to which their Dexterity modifier is added. Maximum Dexterity bonus to defense is restricted when wearing armor: for example, an armor displaying Max Dexterity Bonus: +5 would restrict defense added by the Dexterity modifier to +5, even when it was greater than +5.

However, although the Description windows for Jedi robes display Max Dexterity Bonus as well, according to the Messages - Feedback window this restriction does not actually apply. Even though all Jedi robes display Max Dexterity Bonus: +8, Dexterity modifiers greater than +8 are still added to defense in their entirety.

Many opponents also have a Natural bonus and an Armor bonus. From comparing Defense Bonus displayed in an armor's Description window and the output of the Messages - Feedback window, this bonus is often split between Armor and feats and effects. The Defense Bonus of Jedi robes has no Armor bonus.

Feats and effects
The Messages - Feedback window sums bonuses and penalties from all of the following under feats and effects:

Feats and effects are restricted to a maximum defense bonus of +10. For example, a Jedi wearing a Jedi Master Robe (+3) and using Master Speed (+4) and Force Armor (+6) only receives a defense bonus of +10, not +13.

Feat
One set of feats is separate to feats and effects in the Messages - Feedback window:

Class
Some classes receive a defense bonus from feats they gain at certain levels:

Class bonuses are restricted to a maximum defense bonus of +10. This maximum can only be achieved by a main player character at level 18 with any Jedi class who was a level 6 Scoundrel, but it cannot normally be exceeded (since even a level 12 Scoundrel could only become a level 8 Jedi at most).

Debilitated bonus
Debilitated bonus results in -4 defense whenever a target is debilitated by any of the following:

Being debilitated also results in Dexterity modifier not being added to defense. Characters can avoid being debilitated with a successful saving throw, Immunity: Mind-Affecting or Force Immunity.

Blaster Bolt Deflection
All Jedi classes get the Jedi Defense feat for free.

This feat allows a character with an equipped lightsaber to deflect blaster bolts at any time. When a character is fired upon, an opposed roll is made against the attack. If the result is greater than the attack roll, the blaster bolt is deflected. If the attack is beaten by 10 or more, the bolt is deflected back at the enemy. Jedi classes receive this feat at 1st level.

According to the Messages = Feedback window, the opposed roll is simply the sum of a d20 roll, the Jedi's base attack bonus and any Blaster Bolt Deflection bonuses:

Maximum Blaster Bolt Deflection bonus +35 for Light Side Jedi. Although when a lightsaber has two crystals applying bonuses only the highest is displayed in its Description window, according to the Messages - Feedback window the bonuses from both crystals are actually added.

The roll occurs after an attack roll is made against defense, so Blaster Bolt Deflection becomes less and less useful as defense increases (since blaster bolts are increasingly likely to miss regardless of whether or not they are deflected or returned). Even without high defense and low chance to hit, blaster bolts normally apply damage which can be countered by the Force powers Energy Resistance or Improved Energy Resistance.

While returning blaster bolts is a signature move of the Jedi, their damage pales in comparison to that from other sources.

Blaster Bolt Deflection does not occur when debilitated.