So I'm working on developing an online game, and one of the features of this game (like many other MMORPG's) is the drop system & upgrade system.
The drop system decides what items will drop from monsters when they are killed. The upgrade system decides if an item will successfully upgrade to the next level or not.
They both need to be able to use probability to determine if:
- An item Drops
- An item upgrades successfully.
I've developed a system that generates a random number between 0 and 100000. In this system a 1% probability of either of the above happening would be represented by 1000. Similarly, a 0.5% would be 500... and 50% would be 50000.
Here is the guts of this code...
int RandomValueInRange(const int start, const int end)
{
std::random_device rd;
std::mt19937 generator(rd());
const int stable_end = ((end < start) ? start : end);
std::uniform_int_distribution<int> distribution(start, stable_end);
return distribution(generator);
}
Now in order to dermine if an item drops or upgrades sucecsfully, all I have to do is this...
const int random_value = RandomValueInRange(0, 100000);
const int probability = item.GetProbability();//This simply returns an integer stored in a config file which represents the probability of this item being dropped/upgraded.
if(random_value <= probability)
{
std::cout << "Probability Success!" << endl;
}
else
{
std::cout << "Probability Failed!" << endl;
}
I would expect the above to work, but for whatever reason it seems faulty... Players are able to get items that have a 0.1% probability with ease (something that should almost never happen!).
Does anyone know of a better system or how I can improve this system to truly follow the probability guidelines....
Aucun commentaire:
Enregistrer un commentaire