Hello everyone,
I'm currently fiddling around with the mechanics behind a turn based battle system.
At the moment I'm clueless about how to handle the mechanic of desciding between hits and misses.
The default is to just compare rand(100) with your hit rate.
I was not too fond of this version, as it felt too "binary", literally hit-or-miss.
Need to roll a 95 or less to hit but get a 96? too bad, you get nothing.
The next step was to have multiple partial attack attempts. Depending on the relevant stats the game would basically iterate over 3 to 20 hit rolls and sum the positive results up; 5 confirmed hits would do 100% damage compared to the normal system, 2 hits 40%, etc.
This falls apart with more hit attempts as it becomes statistics instead of some degree of luck.
The third (and current) version... not nearly as easy explained.
First rand(hit_attempts*100) is called.
The result is then compared to expected_hit_rate * 100 and biased towards the expected hit rate via modelling on a square-root function.
maybe the code helps...
values are multiplied by 10 to increase precision
def number_confirmed_hits(hit_rate = 100, max_hits = 10)
n = 1.0 * rand(10 * 100 * max_hits+1)
c = 10.0 * 100 * max_hits
d = 10.0 * hit_rate
if n > d
result = c-(c-d)*(Math.sqrt(1.0*(c - n)/(c-d)))
else
result = d*Math.sqrt(1.0*n/d)
end
return Integer(result/1000)
end
The problem with this version is the real hit chance; a simple test (100k iterations over the function) with hit_rate = 30 and max_hits = 10 only had 3% misses. Which is a problem if I consider that I added some passive abilities that should be triggered on a miss...
What I want is a way that:
-is not binary hit or miss
-allows for a real rate of misses if the hit rate is bad (some passive abilities are triggered on a miss)
Currently I'm clueless as to how to progress towards that goal.