- Code: Select all
if((currentgold > 400) && (newherochance < 400)) {newherochance = 500;}
// Always a 10% chance - assuming enough gold
if((newherochance > 1150) && (numberofheroes > 0)) {newherochance = 1150;}
// Maximum 75% chance if 1+ heroes
if(rand(400,1000) < newherochance)
{
hero = rand(400, currentgold);
...
In order to have a 10% chance at 500 and 75% at 1150, the generated random value should range between 400 and 1400.
No I have no clue about JavaScript (or whatever that is), but the code "rand(400,1000)" seems suspicious to me:
- If "rand(400,1000)" generates a number between 400 and 1000, then it should be rand(400,1400) instead to get the percentage chances as given in the comments
- If "rand(400,1000)" generates a number between 400 and 400+1000 instead, then surely the next line "hero = rand(400, currentgold)" is buggy, since a hero should never cost more than the player has available.
- Of course, the last possibility is that the comments are just outdated, but then 1150 is a suspiciously specific number, since 1001 would do just as well to yield a 100% chance.