diff --git a/include/aoclient.h b/include/aoclient.h index bcd63f0..fd1775a 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -174,6 +174,7 @@ class AOClient : public QObject { void cmdG(int argc, QStringList argv); void cmdNeed(int argc, QStringList argv); void cmdFlip(int argc, QStringList argv); + void cmdRoll(int argc, QStringList argv); // Command helper functions QStringList buildAreaList(int area_idx); @@ -209,7 +210,8 @@ class AOClient : public QObject { {"pos", {ACLFlags.value("NONE"), 1, &AOClient::cmdPos}}, {"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}}, {"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}}, - {"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}} + {"flip", {ACLFlags.value("NONE"), 0, &AOClient::cmdFlip}}, + {"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}} }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index aa84f9f..666e200 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -394,6 +394,58 @@ void AOClient::cmdFlip(int argc, QStringList argv) sendServerMessage(sender_name + " flipped a coin and got " + face + "."); } +void AOClient::cmdRoll(int argc, QStringList argv) +{ + int max_roll_amount = 20; + int max_roll_faces = 11037; + QString sender_name = ooc_name; + + if (argc == 0) + { + QString dice_result = QString::number(AOClient::genRand(1, 6)); + server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled " + dice_result + " out of 6"}), current_area); + } + else if (argc == 1) + { + int amount_faces = argv[0].toInt(); + if (1 <= amount_faces and amount_faces <= max_roll_faces) + { + QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); + server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled " + dice_result + " out of " + argv[0]}), current_area); + } + else + { + sendServerMessage("Invalid Range."); + } + } + else if (argc == 2) + { + int amount_faces = argv[0].toInt(); + int amount_rolls = argv[1].toInt(); + QString dice_results; + if (1 <= amount_faces and amount_faces <= max_roll_faces and 1 <= amount_rolls and amount_rolls <= max_roll_amount) + { + for (int i = 1; i <= amount_rolls ; i++) + { + QString dice_result = QString::number(AOClient::genRand(1, amount_faces)); + if (i == amount_rolls) + { + dice_results = dice_results.append(dice_result); + } + else + { + dice_results = dice_results.append(dice_result + ","); + } + } + server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled (" + dice_results + ") out of " + argv[0]}), current_area); + } + else + { + sendServerMessage("Invalid Range."); + } + } +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries;