diff --git a/include/aoclient.h b/include/aoclient.h index 14c6f84..5156055 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1735,7 +1735,7 @@ class AOClient : public QObject { * See @ref commandArgv "CommandInfo's `action`'s second parameter". * @param Type The type of the dice-rolling being done. */ - void diceThrower(int argc, QStringList argv, RollType Type); + void diceThrower(int argc, QStringList argv, bool p_roll); /** * @brief Interprets an expression of time into amount of seconds. diff --git a/include/server.h b/include/server.h index 0017621..1eece71 100644 --- a/include/server.h +++ b/include/server.h @@ -225,7 +225,7 @@ class Server : public QObject { /** * @brief The highest value dice can have. */ - uint dice_value; + int dice_value; /** * @brief The max amount of dice that can be rolled at once. diff --git a/src/commands/command_helper.cpp b/src/commands/command_helper.cpp index f295037..6fb8665 100644 --- a/src/commands/command_helper.cpp +++ b/src/commands/command_helper.cpp @@ -74,62 +74,24 @@ int AOClient::genRand(int min, int max) #endif } -void AOClient::diceThrower(int argc, QStringList argv, RollType type) +void AOClient::diceThrower(int argc, QStringList argv, bool p_roll) { - QString sender_name = ooc_name; - int max_value = server->dice_value; - int max_dice = server->max_dice; - int bounded_value; - int bounded_amount; - QString dice_results; - - if (argc == 0) { - dice_results = QString::number(genRand(1, 6)); // Self-explanatory + int sides = 6; + int dice = 1; + QStringList results; + if (argc >= 1) + sides = qBound(1, argv[0].toInt(), server->dice_value); + if (argc == 2) + dice = qBound(1, argv[1].toInt(), server->max_dice); + for (int i = 1; i <= dice; i++) { + results.append(QString::number(AOClient::genRand(1, sides))); } - else if (argc == 1) { - bounded_value = qBound(1, argv[0].toInt(), max_value); // faces, max faces - dice_results = QString::number(genRand(1, bounded_value)); - } - else if (argc == 2) { - 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 - - for (int i = 1; i <= bounded_amount ; i++) // Loop as multiple dices are thrown - { - QString dice_result = QString::number(genRand(1, bounded_value)); - if (i == bounded_amount) { - dice_results = dice_results.append(dice_result); - } - else { - 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(type) - { - case ROLL: - if (argv.isEmpty()) { - sendServerMessageArea(sender_name + " rolled " + dice_results + " out of 6"); - } - else { - sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value)); - } - break; - case ROLLP: - if (argv.isEmpty()) { - sendServerMessage(sender_name + " rolled " + dice_results + " out of 6"); - sendServerMessageArea((sender_name + " rolled in secret.")); - } - else { - sendServerMessageArea(sender_name + " rolled " + dice_results + " out of " + QString::number(bounded_value)); - sendServerMessageArea((sender_name + " rolled in secret.")); - } - break; - case ROLLA: - //Not implemented yet - default : break; + QString total_results = results.join(" "); + if (p_roll) { + sendServerMessage("You rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results); + return; } + sendServerMessageArea(ooc_name + " rolled a " + QString::number(dice) + "d" + QString::number(sides) + ". Results: " + total_results); } QString AOClient::getAreaTimer(int area_idx, int timer_idx) diff --git a/src/commands/roleplay.cpp b/src/commands/roleplay.cpp index ea31a64..ef27f72 100644 --- a/src/commands/roleplay.cpp +++ b/src/commands/roleplay.cpp @@ -30,12 +30,12 @@ void AOClient::cmdFlip(int argc, QStringList argv) void AOClient::cmdRoll(int argc, QStringList argv) { - diceThrower(argc, argv, RollType::ROLL); + diceThrower(argc, argv, false); } void AOClient::cmdRollP(int argc, QStringList argv) { - diceThrower(argc, argv, RollType::ROLLP); + diceThrower(argc, argv, true); } void AOClient::cmdTimer(int argc, QStringList argv)