Weapon accuracy equation

As you might guess, modifiers like Carbine Accuracy increase your chances of hitting an opponent with an attack. How is this to-hit chance determined? How do your opponent's defense modifiers, posture, and secondary defenses affect your chance to hit him or her?

Variables
Your weapon accuracy depends on 8 variables (values that affect the outcome of an equation):
 * Weapon accuracy mod ("Accuracy"); i.e. the numerical value of your Carbine Accuracy mod.
 * Individual weapon accuracy ("Weapon"); i.e. your weapon's accuracy value at your current range from your target. More on determing this value below.
 * Aiming mod ("Aiming"); the sum of your General Ranged Aiming and weapon-specific Aiming mods. Only applies if you use Aim prior to your attack.
 * Player posture mod ("Player"); your posture determines how accurate you are. Details below.
 * Ability accuracy mod ("Ability"); each special ability has an inherent modifier on your accuracy. These exact modifiers are unknown, but generally believed to be positive (adding to your to-hit chance).
 * Target's primary defense ("Defense"); i.e. the numerical value of your target's Ranged Defense or Melee Defense mods, depending on if your weapon is ranged or melee.
 * Target's posture mod ("Target"); your target's posture can make him or her harder for you to hit.
 * Target's state effects ("State"); some states mae your target easier to hit. Details below.

Accuracy equation
The percent chance of a given attack hitting your target, "ToHit," is calculated as follow:



Calculating weapon accuracy mod
The complex nature of weapon accuracies in Star Wars Galaxies makes it difficult to calculate your weapon's accuracy at a given range. But we'll try, anyway.

Weapon accuracies have three main components:
 * Point-blank range specifies the minimum range of your weapon.
 * Ideal range specifies the "sweetspot" range for your weapon; this range is specific to each type of weapon (i.e. all DH17 Carbines have the same ideal range). You will always fire with maximum accuracy at your ideal range.
 * Maximum range specifies the furthest you can be from your target and still be able to fire. For ranged weapons, this is usually 64m.

Each range value also has a modifier associated with it. This modifier gives the Accuracy mod we need in the above equation whenever your character is firing from exactly that range. Unfortunately, we are rarely so precise, and so we need a way to determine what our real accuracy value is. This requires two steps.

First, imagine your current range from your target as a slider that moves back and forth on a line, where the line has markers for your point-blank, ideal, and maximum ranges. Here is such a slider for an imaginary weapon:



Now, determine where on this slider your current range lies. Let's imagine our target is 33m away; thus, we are between our minimum and ideal ranges. Were our target 58m away, we would be between ideal and maximum ranges. In both cases, we refer to the lower range value (minimum range in the first example) as the "small range", and the higher range value (ideal range in the first example) as "big range." To determine our final accuracy, we must interpolate between the small range and big range based on where our current range lies on the above slider. To do so, use the following equation, where "Current" is your current range from the target, and "BigRange," "SmallRange," "BigMod," and "SmallMod" all refer to the distance and modifier values at your small and big ranges.



As a quick example, let's go back to the above imaginary weapon, with our target at 35m. Our calcualation comes out thus:



So our weapon accuracy at 35m is +40.