Ok the first attack is based on your range compared to your enemies range, and also the distance. You get an extra attack per one you are up on this list up to the maximum of the distance you are at.
Anything visible
Medium
Short
Long melee
Melee
Practically touching
From that point on you get an extra attack for every two you are above them on this list for attack speed:
Extremely fast
Very fast
Fast
Medium-fast
Medium
Medium-slow
Slow
Very slow
Extremely slow
How monsters attack is based on their intelligence level:
0 Random attack, random weapon
1 25% retaliation attack, random weapon
2 50% retaliation attack, 25% correct weapon
3 75% retaliation attack, 50% correct weapon
4 Always retaliation attack, 75% correct weapon
5 Always retaliation, Always correct weapon
6 75% retaliation 25% tactical, ACW
7 50% retaliation 50% tactical, ACW
8 25% retaliation 75% tactical, ACW
9 Always tactical, ACW
10 Counter attacks, ACW