diff options
| -rw-r--r-- | HelpMe.md | 56 | ||||
| -rw-r--r-- | diceparser.cpp | 6 | ||||
| -rw-r--r-- | node/countexecutenode.cpp | 14 | ||||
| -rw-r--r-- | node/explosedicenode.cpp | 18 | ||||
| -rw-r--r-- | node/filternode.cpp | 16 | ||||
| -rw-r--r-- | node/keepdiceexecnode.cpp | 14 | ||||
| -rw-r--r-- | node/scalaroperatornode.cpp | 121 | ||||
| -rw-r--r-- | node/sortresult.cpp | 11 | ||||
| -rw-r--r-- | node/startingnode.cpp | 6 |
9 files changed, 157 insertions, 105 deletions
@@ -1,4 +1,19 @@ [](http://www.rolisteam.org) + +**Table of Contents** + +* [DiceParser](#diceparser--what-is-it-) +* [Platforms](#roll-dice-on-each-platform) +* [Limitations](#known-limitations) +* [Roll a die](#how-to-roll-a-die) +* [List of operator](#list-of-operator) +* [Arithmetic](#arithmetic) +* [Arithmetic and Dice](#arithmetic-and-dice) +* [Validator](#validator) +* [Value from set](#select-value-from-list) +* [Miscellaneous examples](#examples) +* [Best Practices](#best-practices) + # Documentation: ## DiceParser : What is it ? @@ -9,7 +24,6 @@ Such as: Irc bot, discord bot, included in Rolisteam, web server, on twitter etc Each platform has its own limitations. Let's take a look about it: - ### Roll dice on each platform @@ -18,7 +32,7 @@ Please, remember it is important to prefix all you command by `!`. This will all | platform | start character(s) | more information | |---|---|--- | | Rolisteam |```!```| [Documentation](http://wiki.rolisteam.org/index.php/En:Dice) | -| Discord |```!```| | +| Discord |```!```| To install DiceParser on your server [http://www.rolisteam.org/discord.html](http://www.rolisteam.org/discord.html) | | Twitter | ```#roll``` | Twit any message starting with #roll following by dice command (e.g: ```#roll 2d6```) | | IrcBot |```!```| | | webserver | nothing | No public published yet. Has dedicated text field | @@ -38,6 +52,12 @@ Please, remember it is important to prefix all you command by `!`. This will all We can't set some aliases for any platform but It has to be labelled with game's name. +## Bug report and new features + +Please fulfill a ticket in our [Bug tracker](https://github.com/Rolisteam/DiceParser/issues) system. +Or contact us on [discord](https://discordapp.com/invite/MrMrQwX) or any [other ways](http://www.rolisteam.org/contact.html) + + ## How to roll a die It is real simple. you have to call: @@ -78,6 +98,7 @@ Thanks of several operations and options, you can tune a bit your rolling comman * m : Merge * i : if * g : Group +* \# : Comment ### Keep @@ -217,6 +238,21 @@ If you plan to use if operator to display text message. You must surround text w Roll 5 dice and then try to group them to make group of 10 [7th sea system]. +# Comment (\#) + +> 2D6 # Sword attack + +Display "Sword attack" and the result of the two dice. +DiceParser ignore everything after the \#. The whole part is treated as one comment. +So DiceParser can answer question: + +> 1L[yes,no] # Am I evil ? + +``` +Am I evil ? +yes +``` + ## example: > 1d6i[<4]{3} @@ -315,9 +351,10 @@ or ## Validator There are three kind of Validator: --Scalar --Range --Boolean expression + +* Scalar +* Range +* Boolean expression Any operator which requires validator (such as `a,r,e,c`) can use those three kind. @@ -358,6 +395,15 @@ The L operator (meaning list) can offer you the opportunity to pick up value fro > 1L[sword,bow,knife,gun,shotgun] +With comment + +> 1L[yes,no] # Am I evil ? + +``` +What the answer is ? +yes +``` + ## Examples > 3D100 diff --git a/diceparser.cpp b/diceparser.cpp index b4ea3be..902f6ba 100644 --- a/diceparser.cpp +++ b/diceparser.cpp @@ -567,7 +567,7 @@ QString DiceParser::getDiceCommand() const bool DiceParser::hasIntegerResultNotInFirst() { - bool result; + bool result=false; for(auto node : m_startNodes) { result |= hasResultOfType(Result::SCALAR,node); @@ -577,7 +577,7 @@ bool DiceParser::hasIntegerResultNotInFirst() bool DiceParser::hasDiceResult() { - bool result; + bool result=false; for(auto node : m_startNodes) { result |= hasResultOfType(Result::DICE_LIST,node); @@ -586,7 +586,7 @@ bool DiceParser::hasDiceResult() } bool DiceParser::hasStringResult() { - bool result; + bool result=false; for(auto node : m_startNodes) { result |= hasResultOfType(Result::STRING,node); diff --git a/node/countexecutenode.cpp b/node/countexecutenode.cpp index de5e457..ca2c599 100644 --- a/node/countexecutenode.cpp +++ b/node/countexecutenode.cpp @@ -28,14 +28,14 @@ void CountExecuteNode::run(ExecutionNode *previous) return; } DiceResult* previousResult = dynamic_cast<DiceResult*>(previous->getResult()); - if(nullptr!=previousResult) + if(NULL!=previousResult) { m_result->setPrevious(previousResult); QList<Die*> diceList=previousResult->getResultList(); qint64 sum = 0; - for(Die* dice : diceList) + foreach(Die* dice,diceList) { - if(nullptr!=m_validator) + if(NULL!=m_validator) { sum+=m_validator->hasValid(dice,true,true); } @@ -65,19 +65,21 @@ qint64 CountExecuteNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* CountExecuteNode::getCopy() const { CountExecuteNode* node = new CountExecuteNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/explosedicenode.cpp b/node/explosedicenode.cpp index bdde83b..81e80ee 100644 --- a/node/explosedicenode.cpp +++ b/node/explosedicenode.cpp @@ -8,13 +8,13 @@ ExploseDiceNode::ExploseDiceNode() void ExploseDiceNode::run(ExecutionNode* previous) { m_previousNode = previous; - if((nullptr!=previous)&&(nullptr!=previous->getResult())) + if((NULL!=previous)&&(NULL!=previous->getResult())) { DiceResult* previous_result = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previous_result); - if(nullptr!=previous_result) + if(NULL!=previous_result) { - for(Die* die : previous_result->getResultList()) + foreach(Die* die,previous_result->getResultList()) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -25,7 +25,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) QList<Die*> list = m_diceResult->getResultList(); - for(Die* die : list) + foreach(Die* die, list) { while(m_validator->hasValid(die,false)) { @@ -34,7 +34,7 @@ void ExploseDiceNode::run(ExecutionNode* previous) } // m_diceResult->setResultList(list); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -68,19 +68,21 @@ qint64 ExploseDiceNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* ExploseDiceNode::getCopy() const { ExploseDiceNode* node = new ExploseDiceNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/filternode.cpp b/node/filternode.cpp index 0be2e62..5153c79 100644 --- a/node/filternode.cpp +++ b/node/filternode.cpp @@ -8,7 +8,7 @@ FilterNode::FilterNode() FilterNode::~FilterNode() { - if(nullptr!=m_validator) + if(NULL!=m_validator) { delete m_validator; } @@ -20,13 +20,13 @@ void FilterNode::setValidator(Validator* validator) void FilterNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr==previous) + if(NULL==previous) { return; } DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(NULL!=previousDiceResult) { QList<Die*> diceList=previousDiceResult->getResultList(); QList<Die*> diceList2; @@ -48,7 +48,7 @@ void FilterNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -71,18 +71,20 @@ qint64 FilterNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* FilterNode::getCopy() const { FilterNode* node = new FilterNode(); - if(nullptr!=m_validator) + if(NULL!=m_validator) { node->setValidator(m_validator->getCopy()); } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/keepdiceexecnode.cpp b/node/keepdiceexecnode.cpp index 355a63a..6167632 100644 --- a/node/keepdiceexecnode.cpp +++ b/node/keepdiceexecnode.cpp @@ -36,20 +36,20 @@ KeepDiceExecNode::~KeepDiceExecNode() void KeepDiceExecNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr==previous) + if(NULL==previous) { return; } DiceResult* previousDiceResult = static_cast<DiceResult*>(previous->getResult()); m_result->setPrevious(previousDiceResult); - if(nullptr!=previousDiceResult) + if(NULL!=previousDiceResult) { QList<Die*> diceList=previousDiceResult->getResultList(); QList<Die*> diceList3= diceList.mid(0,m_numberOfDice); QList<Die*> diceList2; - for(Die* die:diceList3) + foreach(Die* die,diceList3) { Die* tmpdie = new Die(); *tmpdie=*die; @@ -70,7 +70,7 @@ void KeepDiceExecNode::run(ExecutionNode* previous) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -96,8 +96,10 @@ qint64 KeepDiceExecNode::getPriority() const qint64 priority=0; if(nullptr!=m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } @@ -105,7 +107,7 @@ ExecutionNode* KeepDiceExecNode::getCopy() const { KeepDiceExecNode* node = new KeepDiceExecNode(); node->setDiceKeepNumber(m_numberOfDice); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/scalaroperatornode.cpp b/node/scalaroperatornode.cpp index b85f23c..f4884c8 100644 --- a/node/scalaroperatornode.cpp +++ b/node/scalaroperatornode.cpp @@ -28,6 +28,12 @@ ScalarOperatorNode::ScalarOperatorNode() : m_internalNode(nullptr),m_scalarResult(new ScalarResult()),m_arithmeticOperator(Die::PLUS) { + /*m_scalarOperationList.insert('+',PLUS); + m_scalarOperationList.insert('-',MINUS); + m_scalarOperationList.insert('x',MULTIPLICATION); + m_scalarOperationList.insert('*',MULTIPLICATION); + m_scalarOperationList.insert('/',DIVIDE);*/ + m_result = m_scalarResult; } ScalarOperatorNode::~ScalarOperatorNode() @@ -42,30 +48,24 @@ ScalarOperatorNode::~ScalarOperatorNode() void ScalarOperatorNode::run(ExecutionNode* previous) { m_previousNode = previous; - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { - m_internalNode->run(this); + m_internalNode->run(this); } - if(nullptr!=previous) + if(NULL!=previous) { DiceResult* previousResult = static_cast<DiceResult*>(previous->getResult()); - if(nullptr!=previousResult) + if(NULL!=previousResult) { ExecutionNode* internal = m_internalNode; - if(nullptr != internal) + if(NULL != internal) { while(nullptr != internal->getNextNode() ) { internal = internal->getNextNode(); - } + } - Result* internalResult = internal->getResult(); - m_result->setPrevious(internalResult); - if(nullptr!=m_internalNode->getResult()) - { - m_internalNode->getResult()->setPrevious(previousResult); - } switch(m_arithmeticOperator) { @@ -81,16 +81,13 @@ void ScalarOperatorNode::run(ExecutionNode* previous) case Die::DIVIDE: m_scalarResult->setValue(divide(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); break; - case Die::POWER: - m_scalarResult->setValue(power(previousResult->getResult(Result::SCALAR).toReal(),internalResult->getResult(Result::SCALAR).toReal())); - break; default: break; - } + } } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -98,6 +95,15 @@ void ScalarOperatorNode::run(ExecutionNode* previous) } } +/*bool ScalarOperatorNode::setOperatorChar(QChar c) +{ + if(m_scalarOperationList.contains(c)) + { + m_operator = m_scalarOperationList.value(c); + return true; + } + return false; +}*/ void ScalarOperatorNode::setInternalNode(ExecutionNode* node) { @@ -120,14 +126,10 @@ qreal ScalarOperatorNode::divide(qint64 a,qint64 b) } return (qreal)a/b; } -qint64 ScalarOperatorNode::multiple(qint64 a, qint64 b) +qint64 ScalarOperatorNode::multiple(qint64 a,qint64 b) { return a*b; } -qint64 ScalarOperatorNode::power(qint64 a, qint64 b) -{ - return std::pow(a,b); -} Die::ArithmeticOperator ScalarOperatorNode::getArithmeticOperator() const { return m_arithmeticOperator; @@ -148,71 +150,64 @@ QString ScalarOperatorNode::toString(bool wl) const break; case Die::MINUS: op="-"; - break; - case Die::MULTIPLICATION: - op="*"; - break; - case Die::DIVIDE: - op="/"; - break; - case Die::POWER: - op="^"; - break; - default: - break; + break; + case Die::MULTIPLICATION: + op="*"; + break; + case Die::DIVIDE: + op="/"; + break; + default: + break; } - if(wl) - { - return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); - } - else - { - return m_id; - } + if(wl) + { + return QString("%1 [label=\"ScalarOperatorNode %2\"]").arg(m_id).arg(op); + } + else + { + return m_id; + } } qint64 ScalarOperatorNode::getPriority() const { if((m_arithmeticOperator==Die::PLUS)||(m_arithmeticOperator==Die::MINUS)) - { + { return 1; - } - else if((m_arithmeticOperator==Die::MULTIPLICATION)||(m_arithmeticOperator==Die::DIVIDE)) - { - return 2; - } + } else - { - return 3; - } + { + return 2; + } } void ScalarOperatorNode::generateDotTree(QString& s) { - s.append(toString(true)); - s.append(";\n"); + s.append(toString(true)); + s.append(";\n"); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); - s.append(m_nextNode->toString(false)); + s.append(m_nextNode->toString(false)); s.append("[label=\"nextNode\"];\n"); m_nextNode->generateDotTree(s); } else { - s.append(toString(false)); + s.append(toString(false)); s.append(" -> "); s.append("nullptr"); s.append(" [label=\"nextNode\"];\n"); } QString str; str.append("\n"); - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { - str.append(toString(false)); + str.append(toString(false)); str.append(" -> "); - str.append(m_internalNode->toString(false)); + str.append(m_internalNode->toString(false)); str.append(" [label=\"internalNode\"];\n"); m_internalNode->generateDotTree(str); } @@ -220,14 +215,14 @@ void ScalarOperatorNode::generateDotTree(QString& s) } QMap<ExecutionNode::DICE_ERROR_CODE,QString> ScalarOperatorNode::getExecutionErrorMap() { - if(nullptr!=m_internalNode) + if(NULL!=m_internalNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_internalNode->getExecutionErrorMap().keys()) { m_errors.insert(key,m_internalNode->getExecutionErrorMap().value(key)); } } - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { for (ExecutionNode::DICE_ERROR_CODE key: m_nextNode->getExecutionErrorMap().keys()) { @@ -241,7 +236,7 @@ ExecutionNode* ScalarOperatorNode::getCopy() const ScalarOperatorNode* node = new ScalarOperatorNode(); node->setInternalNode(m_internalNode->getCopy()); node->setArithmeticOperator(m_arithmeticOperator); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } diff --git a/node/sortresult.cpp b/node/sortresult.cpp index e3d8d1e..062e1d2 100644 --- a/node/sortresult.cpp +++ b/node/sortresult.cpp @@ -57,7 +57,7 @@ void SortResultNode::run(ExecutionNode* node) bool found = false; int start = 0; int end = diceList2.size(); - Die* tmp2 = nullptr; + Die* tmp2 = NULL; while(!found) { int distance = end-start; @@ -92,7 +92,7 @@ void SortResultNode::run(ExecutionNode* node) } m_diceResult->setResultList(diceList2); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { m_nextNode->run(this); } @@ -125,17 +125,20 @@ qint64 SortResultNode::getPriority() const qint64 priority=0; if(nullptr != m_previousNode) { - priority = m_previousNode->getPriority(); + priority = m_nextNode->getPriority(); } + + return priority; } ExecutionNode* SortResultNode::getCopy() const { SortResultNode* node = new SortResultNode(); node->setSortAscending(m_ascending); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } return node; + } diff --git a/node/startingnode.cpp b/node/startingnode.cpp index 3b0d660..43a0dd7 100644 --- a/node/startingnode.cpp +++ b/node/startingnode.cpp @@ -22,7 +22,7 @@ StartingNode::StartingNode() { - m_previousNode = nullptr; + } void StartingNode::run(ExecutionNode*) { @@ -47,7 +47,7 @@ QString StartingNode::toString(bool withlabel) const qint64 StartingNode::getPriority() const { qint64 priority=0; - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { priority = m_nextNode->getPriority(); } @@ -56,7 +56,7 @@ qint64 StartingNode::getPriority() const ExecutionNode* StartingNode::getCopy() const { StartingNode* node = new StartingNode(); - if(nullptr!=m_nextNode) + if(NULL!=m_nextNode) { node->setNextNode(m_nextNode->getCopy()); } |