Formatting if-else, Minor Nitpick

This commit is contained in:
Salanto 2021-03-03 18:36:20 +01:00
parent 778153c94c
commit f2fe5227d6
2 changed files with 12 additions and 21 deletions

View File

@ -439,7 +439,7 @@ int AOClient::genRand(int min, int max)
#endif #endif
} }
void AOClient::diceThrower(int argc, QStringList argv, RollType Type) void AOClient::diceThrower(int argc, QStringList argv, RollType type)
{ {
QString sender_name = ooc_name; QString sender_name = ooc_name;
int max_value = server->getDiceValue("max_value"); int max_value = server->getDiceValue("max_value");
@ -448,54 +448,45 @@ void AOClient::diceThrower(int argc, QStringList argv, RollType Type)
int bounded_amount; int bounded_amount;
QString dice_results; QString dice_results;
if (argc == 0) if (argc == 0) {
{
dice_results = QString::number(genRand(1, 6)); // Self-explanatory dice_results = QString::number(genRand(1, 6)); // Self-explanatory
} }
else if (argc == 1) else if (argc == 1) {
{
bounded_value = qBound(1, argv[0].toInt(), max_value); // faces, max faces bounded_value = qBound(1, argv[0].toInt(), max_value); // faces, max faces
dice_results = QString::number(genRand(1, bounded_value)); dice_results = QString::number(genRand(1, bounded_value));
} }
else if (argc == 2) else if (argc == 2) {
{
bounded_value = qBound(1, argv[0].toInt(), max_value); // 1, faces, max faces bounded_value = qBound(1, argv[0].toInt(), max_value); // 1, faces, max faces
bounded_amount = qBound(1, argv[1].toInt(), max_dice); // 1, amount, max amount bounded_amount = qBound(1, argv[1].toInt(), max_dice); // 1, amount, max amount
for (int i = 1; i <= bounded_amount ; i++) // Loop as multiple dices are thrown for (int i = 1; i <= bounded_amount ; i++) // Loop as multiple dices are thrown
{ {
QString dice_result = QString::number(genRand(1, bounded_value)); QString dice_result = QString::number(genRand(1, bounded_value));
if (i == bounded_amount) if (i == bounded_amount) {
{
dice_results = dice_results.append(dice_result); dice_results = dice_results.append(dice_result);
} }
else else {
{
dice_results = dice_results.append(dice_result + ","); dice_results = dice_results.append(dice_result + ",");
} }
} }
} }
// Switch to change message behaviour, isEmpty check or the entire server crashes due to an out of range issue in the QStringList // Switch to change message behaviour, isEmpty check or the entire server crashes due to an out of range issue in the QStringList
switch(Type) switch(type)
{ {
case ROLL: case ROLL:
if (argv.isEmpty()) if (argv.isEmpty()){
{
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of 6"); sendServerMessageArea(sender_name + " rolled " + dice_results + " out of 6");
} }
else else {
{
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value)); sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value));
} }
break; break;
case ROLLP: case ROLLP:
if (argv.isEmpty()) if (argv.isEmpty()){
{
sendServerMessage(sender_name + " rolled " + dice_results + " out of 6"); sendServerMessage(sender_name + " rolled " + dice_results + " out of 6");
sendServerMessageArea((sender_name + " rolled in secret.")); sendServerMessageArea((sender_name + " rolled in secret."));
} }
else else {
{
sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value)); sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value));
sendServerMessageArea((sender_name + " rolled in secret.")); sendServerMessageArea((sender_name + " rolled in secret."));
} }

View File

@ -161,7 +161,7 @@ int Server::getDiceValue(QString value_type)
settings.beginGroup("Dice"); settings.beginGroup("Dice");
int value = settings.value(value_type, "100").toUInt(); int value = settings.value(value_type, "100").toUInt();
settings.endGroup();
return value; return value;
} }