Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rolla #385

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

rolla #385

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bin_tests/config/dice.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[default]
max = 6
1 = Stomach ulcer
2 = Small loan of a million dollars
3 = Nothing happens
4 = Nothing happens
5 = Nothing happens
6 = Critical hit

[8ball]
max = 20
1 = It is certain
2 = It is decidedly so
3 = Without a doubt
4 = Yes - definitely
5 = You may rely on it
6 = As I see it, yes
7 = Most likely
8 = Outlook good
9 = Yes
10 = Signs point to yes
11 = Reply hazy, try again
12 = Ask again later
13 = Better not tell you now
14 = Cannot predict now
15 = Concentrate and ask again
16 = Don't count on it
17 = My reply is no
18 = My sources say no
19 = Outlook not so good
20 = Very doubtful
1 change: 1 addition & 0 deletions src/aoclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const QMap<QString, AOClient::CommandInfo> AOClient::COMMANDS{
{"need", {{ACLRole::NONE}, 1, &AOClient::cmdNeed}},
{"coinflip", {{ACLRole::NONE}, 0, &AOClient::cmdFlip}},
{"roll", {{ACLRole::NONE}, 0, &AOClient::cmdRoll}},
{"rolla", {{ACLRole::NONE}, 0, &AOClient::cmdRollA}},
{"rollp", {{ACLRole::NONE}, 0, &AOClient::cmdRollP}},
{"doc", {{ACLRole::NONE}, 0, &AOClient::cmdDoc}},
{"cleardoc", {{ACLRole::NONE}, 0, &AOClient::cmdClearDoc}},
Expand Down
9 changes: 9 additions & 0 deletions src/aoclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,15 @@ class AOClient : public QObject
*/
void cmdRoll(int argc, QStringList argv);

/**
* @brief Rolls custom dice and sends the results.
*
* @details The first argument is which dice to roll.
*
* @copydetails AOClient::cmdRollA
*/
void cmdRollA(int argc, QStringList argv);

/**
* @brief Rolls dice, but sends the results in private to the roller.
*
Expand Down
18 changes: 18 additions & 0 deletions src/commands/roleplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ void AOClient::cmdRoll(int argc, QStringList argv)
diceThrower(l_sides, l_dice, false);
}

void AOClient::cmdRollA(int argc, QStringList argv)
{
Q_UNUSED(argc);

QString l_dice_name = argv.join(" ");

if (ConfigManager::diceFaces(l_dice_name).isEmpty()) {
qWarning() << "Unknown dice.";
sendServerMessage("Unknown dice.");
}
else {
QString l_response = ConfigManager::diceFaces(l_dice_name).at((genRand(0, ConfigManager::diceFaces(l_dice_name).size() - 1)));
QString l_sender_name = name();

sendServerMessageArea(l_sender_name + " rolled from the \"" + l_dice_name + "\" set and got: " + l_response);
}
}

void AOClient::cmdRollP(int argc, QStringList argv)
{
int l_sides = 6;
Expand Down
29 changes: 29 additions & 0 deletions src/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ bool ConfigManager::verifyServerConfig()
return false;
}

// Read dices
QSettings l_dice_ini("config/dice.ini", QSettings::IniFormat);
QStringList dices = l_dice_ini.childGroups();

for (const QString &dice : dices) {
l_dice_ini.beginGroup(dice);

int max = l_dice_ini.value("max").toInt();
QStringList faces;

for (int i = 1; i <= max; ++i) {
QString key = QString::number(i);
if (l_dice_ini.contains(key)) {
faces.append(l_dice_ini.value(key).toString());
}
else {
qCritical() << "dice.ini max mismatch!";
break;
}
}
m_commands->dice_faces[dice] = faces;
l_dice_ini.endGroup();
}

// Verify config settings
m_settings->beginGroup("Options");
bool ok;
Expand Down Expand Up @@ -583,6 +607,11 @@ void ConfigManager::setAuthType(const DataTypes::AuthType f_auth)
m_settings->setValue("Options/auth", fromDataType<DataTypes::AuthType>(f_auth).toLower());
}

QStringList ConfigManager::diceFaces(const QString f_name)
{
return m_commands->dice_faces[f_name];
}

QStringList ConfigManager::magic8BallAnswers()
{
return m_commands->magic_8ball;
Expand Down
20 changes: 14 additions & 6 deletions src/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ class ConfigManager
*/
static int afkTimeout();

/**
* @brief Returns a list of dice faces.
*
* @return See short description.
*/
static QStringList diceFaces(const QString f_name);

/**
* @brief Returns a list of magic 8 ball answers.
*
Expand Down Expand Up @@ -514,12 +521,13 @@ class ConfigManager
*/
struct CommandSettings
{
QStringList magic_8ball; //!< Contains answers for /8ball, found in config/text/8ball.txt
QStringList praises; //!< Contains command praises, found in config/text/praises.txt
QStringList reprimands; //!< Contains command reprimands, found in config/text/reprimands.txt
QStringList gimps; //!< Contains phrases for /gimp, found in config/text/gimp.txt
QStringList filters; //!< Contains filter regex, found in config/text/filter.txt
QStringList cdns; // !< Contains domains for custom song validation, found in config/text/cdns.txt
QHash<QString, QStringList> dice_faces; //!< Contains customizable dices, found in config/dice.ini
QStringList magic_8ball; //!< Contains answers for /8ball, found in config/text/8ball.txt
QStringList praises; //!< Contains command praises, found in config/text/praises.txt
QStringList reprimands; //!< Contains command reprimands, found in config/text/reprimands.txt
QStringList gimps; //!< Contains phrases for /gimp, found in config/text/gimp.txt
QStringList filters; //!< Contains filter regex, found in config/text/filter.txt
QStringList cdns; //!< Contains domains for custom song validation, found in config/text/cdns.txt
};

/**
Expand Down
Loading