I am making a classic rpg. I believe that I may be overcomplicating my approach to the damage dealt by weapons. I want to ask you two things:
1) Is there a simpler way to accomplish this type of weighting probabilities?
2) I currently use a procedural approach of summing the weights for each value in the damage range to reverse map the number returned by my random number generator. Is there a mathematical formula do accomplish this?
Each weapon has a damage range (e.g. 4-11) and a weapon class (e.g. slicing, piercing). Each character has a profiency rating for each weapon class, ranging from 0 to 1. I want to "randomly" select the values in this range based on the character's profiency with the weapon that he has equiped. My approach is to generate two line segments to form a peak at the (max-min)*profiency area of the damage range, then weighting the probability of selecting each number in the damage range based on where the vertical line at that damage value intersects the line segment on that side of the peak.
For example, with a range of 4-11 and a weapon proficiency of 0.65, the two line segments will form a peak at X=8.55 (which is calculated as ((11-4)*.65]+4). The Y coordinate of the peak will be equal to (max-min)/2, or, in this case, (11-4)/2) = 3.5. So our line segments are (4, 1)-(8.55, 3.5) and (8.55, 3.5)-(11, 1) -- the 1 ensuring that all values have at least some chance of being selected. Calculating the line segment intersections for each damage value, you get the following weights: 4=>1.0, 5=>1.55, 6=>2.1, 7=2.65, 8=>3.2, 9=>3.0, 10=>2.0, 11=>1.0. I then generate a random number between 0 and the sum of the values (in this case the range would be 0 to 16.5) e.g. If the random number generator returns the value 5, I would use the damage value of 7 because 5<=1.0+1.55+2.1+2.65.
Note: When I implement it, I will scale the range up by a factor of 100 in order to use the integers returned by the random number generator.