1

im making an rpg game with JS and it's going good till now, i wanted to make combat system a bit more complicated so i gave enemies a range of attacks, so first i wrote down their min and max attacks in the enimieData object, they look like this;

function enemieData(enemie, stat){
var enemies = {
    "Wolf": {"hp":Math.floor(Math.random() * 3 +4), "attackMin":1, 
    "attackMax":4,"speed":Math.floor(Math.random() * 3 +8)},
     Goblin": {"hp":Math.floor(Math.random() * 3 +3), "attackMin":1, "attackMax":4, 
     "speed":Math.floor(Math.random() * 7 + 4)},
    .
    .
    .
    .
    };
var enemieStat= enemies[enemie][stat];
return [enemieStat];

Then i made a function to take random numbers between attackMin and attackMax, it looks like this;

function attackConvert(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

Then in my attack function i have this;

.
.
.
monAttackMin= enemieData(enemie, "attackMin");
monAttackMax= enemieData(enemie, "attackMax");
monAttack= attackConvert(monAttackMin, monAttackMax);
.
.
.

But when i minus monAttack from our character's HP, some how attack values gets out of their range. As i checked from console attackMin and attackMax gets the right values but Sometimes enimies hit 0 damage, i mean my math is not great but isn't it impossible to hit 0 when there is "+ min" at the end, cause attackMin never gets lower than 1. I didn't saw them getting higher than attackMax but they often get lower than attackMin. i think there is something wrong with that attackConvert function.

Abuzer DAG
  • 33
  • 5

0 Answers0