aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--diceparser.cpp5
-rw-r--r--node/helpnode.cpp47
-rw-r--r--node/rerolldicenode.cpp26
3 files changed, 72 insertions, 6 deletions
diff --git a/diceparser.cpp b/diceparser.cpp
index 641cf21..c160df4 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -1065,6 +1065,11 @@ bool DiceParser::readOption(QString& str,ExecutionNode* previous)//,
auto reroll = (operatorName==RerollAndAdd || operatorName==Reroll);
auto addingMode = (operatorName==RerollAndAdd);
RerollDiceNode* rerollNode = new RerollDiceNode(reroll, addingMode);
+ ExecutionNode* nodeParam = nullptr;
+ if(readParameterNode(str,nodeParam))
+ {
+ rerollNode->setInstruction(nodeParam);
+ }
rerollNode->setValidator(validator);
previous->setNextNode(rerollNode);
node = rerollNode;
diff --git a/node/helpnode.cpp b/node/helpnode.cpp
index bdaf90e..1cefea8 100644
--- a/node/helpnode.cpp
+++ b/node/helpnode.cpp
@@ -35,12 +35,53 @@ void HelpNode::run(ExecutionNode* previous)
txtResult->setText(QObject::tr("Rolisteam Dice Parser:\n"
"\n"
"Example (with ! as prefix):\n"
- "!2d6"
- "!1d20"
+ "!2d6\n"
+ "!1d20\n"
"\n"
"Operator list:\n"
"\n"
- "Full documentation at: %1").arg(m_path));
+ "k : Keep : 2d10k1 => roll two 10-sided dice and keep the higher one (kl1 for smaller one)\n"
+ "K : Keep And Explode : 2d10K1 => Equivalent of 2d10e10k1\n"
+ "s : Sort : 8d10 => roll eight 10-sided dice and sort the result list\n"
+ "c : Count : 8d10c[>7] => roll eight 10-sided dice and count how many dice are higher than 7\n"
+ "r : Reroll : 8d6r1 => roll eight 6-sided dice and reroll dice once if its result is 1. (result of the reroll can be 1)\n"
+ "e : Explode : 8d10e10 => roll eight 10-sided dice and while dice makes a 10 it is reroll. The result is added to those dice.\n"
+ "a : Reroll and add : 8d6a1 => roll eight 6-sided dice and reroll dice once and the result is added at 1\n"
+ "m : Merge : 1d20;1d10mk1 => roll one 20-side die and one 10-sided die and keep the higher die\n"
+ "i : if : 1d100i[=100]{\"jackpot\"} => Roll one 100-side die and display \"jackpot\" if the die result is 100.\n"
+ "f : filter : 4d10f[!=4] => roll four 10-sided dice and ignore all dice with 4 as result"
+ "; : Next instruction : 1d20;2d10;3d8 => roll one 20-sided die, two 10-sided dice and three 8-sided dice \n"
+ "g : Group : 8d10g10 => count how many group of 10 it is possible to do (according to rule of 7th sea).\n"
+ "# : Comment : 1d2 #flip coin=> display flip coin as comment of 1 or 2 result.\n"
+ "\n"
+ "Validator:\n"
+ "\n"
+ "Supported conditions: >,<,=,>=,<=,!=\n"
+ "Supported operators: % (modulo), &,^,| \n"
+ "\n"
+ " Examples:\n"
+ "\n"
+ "c[>7 & %2=0] : count how many dice are higher than 7 and even\n"
+ "c[>7 | %2=0] : count how many dice are higher than 7 or even\n"
+ "c[>7 ^ %2=0] : count how many dice are higher than 7 or even but not higher than 7 and even\n"
+ "\n"
+ "List:\n"
+ "\n"
+ "1L[green,blue] => pick value from the list (green or blue)\n"
+ "2L[green,blue] => pick two values from the list (green,green | green,blue | blue,green | blue,blue)\n"
+ "2Lu[green,blue] => pick two unique values from the list (green,blue | blue,green)\n"
+ "\n"
+ "Arithmetic\n"
+ "\n"
+ "8+8+8 => 24\n"
+ "24-4 => 20\n"
+ "(3+4)*2 => 14\n"
+ "7/2 => 3.5\n"
+ "2^4 => 16\n"
+ "1d6+6 => roll one 6-sided die and add 6 to its result\n"
+ "(2d4+2)d10 => roll two 4-sided dice, add 2 to the result[2;8] then roll from four to ten 10-sided dice\n"
+ "\n"
+ "Full documentation at: %1").arg(m_path));
m_result->setPrevious(nullptr);
}
else if(nullptr != previous)
diff --git a/node/rerolldicenode.cpp b/node/rerolldicenode.cpp
index f7df0fa..21e0dbf 100644
--- a/node/rerolldicenode.cpp
+++ b/node/rerolldicenode.cpp
@@ -41,12 +41,32 @@ void RerollDiceNode::run(ExecutionNode* previous)
for(int i = 0; i < list.size() ; ++i)
{
auto die = list.at(i);
- while(m_validator->hasValid(die,false))
+ bool finished = false;
+ while(m_validator->hasValid(die,false) && !finished)
{
- die->roll(m_adding);
+ qDebug() << "reroll"<< die->getValue() << m_instruction;
+ if(m_instruction != nullptr)
+ {
+ m_instruction->run(this);
+ auto lastNode = ParsingToolBox::getLatestNode(m_instruction);
+ if(lastNode != nullptr)
+ {
+ auto lastResult = dynamic_cast<DiceResult*>(lastNode->getResult());
+ if(lastResult != nullptr)
+ {
+ toRemove.append(die);
+ list.append(lastResult->getResultList());
+ }
+ lastResult->clear();
+ }
+ }
+ else
+ {
+ die->roll(m_adding);
+ }
if(m_reroll)
{
- break;
+ finished = true;
}
}
}