I'm looking to make attacks work something like D&D attacks, following this procedure:
1) A random number is given, it is added the actor or enemy's attack stat, and if it surpasses the target's defense stat, it deals normal damage.
2) If the random number + the attacker's attack stat does not equal or surpass the target's defense score, the attack misses, dealing no damage.
3) Also, if the given number is between the 5% highest possible (191 to 200 in this case), the attack is a critical, hitting regardless of attack and defense stats and dealing additional damage.
While researching about damage formulas I managed to achieve the first 2 goals by the following formula:
Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage formula" : 0
I'm now trying to add the critical hit mechanic, and tried the following:
Math.floor(Math.random()*200)+0 >= 191 ? "Critical damage formula" : Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage Formula" : 0
This way it works good, but I think what the formula is doing is giving a number to see if it's a critical hit, and if it isn't, it gives another to check if the attack landed in the first place.
Is there a way for the if-else statement to apply to the first Math.floor? Meaning, is there a way to ask two different questions to the same value?
1) A random number is given, it is added the actor or enemy's attack stat, and if it surpasses the target's defense stat, it deals normal damage.
2) If the random number + the attacker's attack stat does not equal or surpass the target's defense score, the attack misses, dealing no damage.
3) Also, if the given number is between the 5% highest possible (191 to 200 in this case), the attack is a critical, hitting regardless of attack and defense stats and dealing additional damage.
While researching about damage formulas I managed to achieve the first 2 goals by the following formula:
Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage formula" : 0
I'm now trying to add the critical hit mechanic, and tried the following:
Math.floor(Math.random()*200)+0 >= 191 ? "Critical damage formula" : Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage Formula" : 0
This way it works good, but I think what the formula is doing is giving a number to see if it's a critical hit, and if it isn't, it gives another to check if the attack landed in the first place.
Is there a way for the if-else statement to apply to the first Math.floor? Meaning, is there a way to ask two different questions to the same value?