add /rollp command
Code duplication is a crime I am willing to commit.
This commit is contained in:
parent
9693d47515
commit
f43e360c86
@ -175,6 +175,7 @@ class AOClient : public QObject {
|
|||||||
void cmdNeed(int argc, QStringList argv);
|
void cmdNeed(int argc, QStringList argv);
|
||||||
void cmdFlip(int argc, QStringList argv);
|
void cmdFlip(int argc, QStringList argv);
|
||||||
void cmdRoll(int argc, QStringList argv);
|
void cmdRoll(int argc, QStringList argv);
|
||||||
|
void cmdRollP(int argc, QStringList argv);
|
||||||
|
|
||||||
// Command helper functions
|
// Command helper functions
|
||||||
QStringList buildAreaList(int area_idx);
|
QStringList buildAreaList(int area_idx);
|
||||||
@ -211,7 +212,9 @@ class AOClient : public QObject {
|
|||||||
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
|
{"g", {ACLFlags.value("NONE"), 1, &AOClient::cmdG}},
|
||||||
{"need", {ACLFlags.value("NONE"), 1, &AOClient::cmdNeed}},
|
{"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}}
|
{"roll", {ACLFlags.value("NONE"), 0, &AOClient::cmdRoll}},
|
||||||
|
{"rollp", {ACLFlags.value("NONE"), 0, &AOClient::cmdRollP}}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QString partial_packet;
|
QString partial_packet;
|
||||||
|
@ -446,6 +446,61 @@ void AOClient::cmdRoll(int argc, QStringList argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOClient::cmdRollP(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));
|
||||||
|
sendServerMessage(sender_name + " rolled " + dice_result + " out of 6");
|
||||||
|
server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), 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));
|
||||||
|
sendServerMessage(sender_name + " rolled " + dice_result + " out of " + argv[0]);
|
||||||
|
server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), 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 + ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendServerMessage(sender_name + " rolled " + dice_results + " out of " + argv[0]);
|
||||||
|
server->broadcast(AOPacket("CT",{"Roll",sender_name + " rolled in secret."}), current_area);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sendServerMessage("Invalid Range.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QStringList AOClient::buildAreaList(int area_idx)
|
QStringList AOClient::buildAreaList(int area_idx)
|
||||||
{
|
{
|
||||||
QStringList entries;
|
QStringList entries;
|
||||||
|
Loading…
Reference in New Issue
Block a user