Hey guys so Im building a text-based game that has enemies you create through OOP. The enemies attacks are in an array of 4 attacks and I create them like such
Enemy e;
e.setLevel(1); // sets enemy level 1 that sets its health, dmg, ect..
anyways so the enemy abilities has a variety of attacks like, dodge and slash.
Of course the dodge attacks output 0 damage, but I want this to be % based so when player.attacks(); I want the % that the enemy will choose their dodge attack much higher than their attack ability. But I don't want them to dodge every attack the player throws at them. Remember all the attacks are in an array. Thanks gys.
double p = /*...*/;
//p is the probability that the defender will dodge
assert(p >= 0 && p <= 1);
bool dodge_successful;
if (p == 0)
dodge_successful = false;
elseif (p == 1)
dodge_successful = true;
else{
double roll = prng();
assert(roll >= 0 && roll <= 1);
//dodge_successful = roll > p; //EDIT: This is incorrect given the above statements.
dodge_successful = roll < p;
}