aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--HelpMe.md16
-rw-r--r--cli/CMakeLists.txt1
-rw-r--r--diceparser.cpp10
-rw-r--r--diceparser.pri2
-rw-r--r--include/diceparser.h3
-rw-r--r--node/allsamenode.cpp82
-rw-r--r--node/allsamenode.h33
8 files changed, 147 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f213bc4..319e510 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,7 @@ SET( dice_sources
${CMAKE_CURRENT_SOURCE_DIR}/node/executionnode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/node/explodedicenode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/node/helpnode.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/node/allsamenode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/node/mergenode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/node/jumpbackwardnode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/node/keepdiceexecnode.cpp
diff --git a/HelpMe.md b/HelpMe.md
index d544480..7350271 100644
--- a/HelpMe.md
+++ b/HelpMe.md
@@ -22,6 +22,7 @@
* [Group](#group)
* [Spread](#spread)
* [Unique](#unique)
+ * [All The same](#allsame)
* [Value list](#Value-list)
* [Comment (\#)](#comment-)
* [Arithmetic](#arithmetic)
@@ -304,6 +305,21 @@ First Result: `10 [6, 4], 3, 3, 2`
Result after spead: `6, 4, 3, 2`
Final result: `6+4+3 = 13`
+### All the same
+
+This operator is temporary. It is dedicated to answer issue about Tunnels and Trolls system. It is why the marker operator is `t`.
+Dice explode when all dice has the same value.
+
+> 2d6t
+
+```
+# Explode twice because 2,1
+Result: 12 - details:[2d6t (5 [2,1,2] 7 [2,1,4])]
+
+# Nothing happened
+Result: 10 - details:[2d6t (4 6)]
+```
+
### Unique
It makes exploded dice as new dice.
diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt
index 5b6c840..7fe65a4 100644
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -28,6 +28,7 @@ SET( dice_sources
../node/jumpbackwardnode.cpp
../node/keepdiceexecnode.cpp
../node/listaliasnode.cpp
+ ../node/allsamenode.cpp
../node/listsetrollnode.cpp
../node/numbernode.cpp
../node/parenthesesnode.cpp
diff --git a/diceparser.cpp b/diceparser.cpp
index 83e8ce9..3f346e9 100644
--- a/diceparser.cpp
+++ b/diceparser.cpp
@@ -26,6 +26,7 @@
#include <QStringList>
#include <functional>
+#include "node/allsamenode.h"
#include "node/bind.h"
#include "node/countexecutenode.h"
#include "node/dicerollernode.h"
@@ -86,6 +87,7 @@ DiceParser::DiceParser()
m_OptionOp->insert(QStringLiteral("f"), Filter);
m_OptionOp->insert(QStringLiteral("y"), Split);
m_OptionOp->insert(QStringLiteral("u"), Unique);
+ m_OptionOp->insert(QStringLiteral("t"), AllSameExplode);
m_OptionOp->insert(QStringLiteral("g"), Group);
m_OptionOp->insert(QStringLiteral("b"), Bind);
m_OptionOp->insert(QStringLiteral("o"), Occurences);
@@ -1192,6 +1194,14 @@ bool DiceParser::readOption(QString& str, ExecutionNode* previous) //,
found= true;
}
break;
+ case AllSameExplode:
+ {
+ AllSameNode* allSame = new AllSameNode();
+ previous->setNextNode(allSame);
+ node=allSame;
+ found = true;
+ }
+ break;
case Bind:
{
BindNode* bindNode= new BindNode();
diff --git a/diceparser.pri b/diceparser.pri
index 06aa3ce..082feb2 100644
--- a/diceparser.pri
+++ b/diceparser.pri
@@ -20,6 +20,7 @@ SOURCES += $$PWD/diceparser.cpp \
$$PWD/operationcondition.cpp \
$$PWD/node/stringnode.cpp \
$$PWD/node/filternode.cpp \
+ $$PWD/node/allsamenode.cpp \
$$PWD/node/groupnode.cpp \
$$PWD/node/dicerollernode.cpp \
$$PWD/node/executionnode.cpp \
@@ -66,6 +67,7 @@ HEADERS += \
$$PWD/operationcondition.h \
$$PWD/node/stringnode.h \
$$PWD/node/filternode.h\
+ $$PWD/node/allsamenode.h\
$$PWD/node/groupnode.h \
$$PWD/node/variablenode.h\
$$PWD/node/dicerollernode.h \
diff --git a/include/diceparser.h b/include/diceparser.h
index 32694a3..1926e5f 100644
--- a/include/diceparser.h
+++ b/include/diceparser.h
@@ -91,7 +91,8 @@ public:
Group,
Occurences,
Unique,
- Bind
+ Bind,
+ AllSameExplode
};
/**
* @brief The CommandOperator enum
diff --git a/node/allsamenode.cpp b/node/allsamenode.cpp
new file mode 100644
index 0000000..96f5616
--- /dev/null
+++ b/node/allsamenode.cpp
@@ -0,0 +1,82 @@
+#include "allsamenode.h"
+
+
+AllSameNode::AllSameNode() : m_diceResult(new DiceResult())
+{
+ m_result= m_diceResult;
+}
+
+void AllSameNode::run(ExecutionNode* previous)
+{
+ m_previousNode= previous;
+ if(nullptr != previous)
+ {
+ DiceResult* previous_result= dynamic_cast<DiceResult*>(previous->getResult());
+ if(nullptr != previous_result)
+ {
+ m_result->setPrevious(previous_result);
+ bool allSame=true;
+ int i=0;
+ quint64 previousValue;
+ for(auto& die : previous_result->getResultList())
+ {
+ if(i == 0)
+ previousValue=die->getValue();
+ Die* tmpdie= new Die(*die);
+ m_diceResult->insertResult(tmpdie);
+ die->displayed();
+ if(previousValue != die->getValue())
+ allSame=false;
+ ++i;
+ }
+
+ while(allSame)
+ {
+ QList<Die*> list= m_diceResult->getResultList();
+ qint64 pValue;
+ int i =0;
+ for(auto& die: list)
+ {
+ die->roll(true);
+ if(i==0)
+ pValue=die->getValue();
+ if(pValue != die->getValue())
+ allSame = false;
+ ++i;
+ }
+ }
+ }
+ }
+ if(nullptr != m_nextNode)
+ {
+ m_nextNode->run(this);
+ }
+}
+
+
+QString AllSameNode::toString(bool withLabel) const
+{
+ if(withLabel)
+ {
+ return QString("%1 [label=\"AllSameNode\"]").arg(m_id);
+ }
+ else
+ {
+ return m_id;
+ }
+}
+
+qint64 AllSameNode::getPriority() const
+{
+ qint64 priority= 0;
+ if(nullptr != m_nextNode)
+ {
+ priority= m_nextNode->getPriority();
+ }
+ return priority;
+}
+
+ExecutionNode* AllSameNode::getCopy() const
+{
+ return new AllSameNode();
+}
diff --git a/node/allsamenode.h b/node/allsamenode.h
new file mode 100644
index 0000000..e5c1dc2
--- /dev/null
+++ b/node/allsamenode.h
@@ -0,0 +1,33 @@
+#ifndef ALLSAMENODE_H
+#define ALLSAMENODE_H
+
+#include "executionnode.h"
+
+#include "result/diceresult.h"
+#include "validator.h"
+
+class AllSameNode : public ExecutionNode
+{
+public:
+ AllSameNode();
+// virtual ~AllSameNode();
+
+ virtual void run(ExecutionNode* previous);
+ /**
+ * @brief toString
+ * @return
+ */
+ virtual QString toString(bool withLabel) const;
+ /**
+ * @brief getPriority
+ * @return
+ */
+ virtual qint64 getPriority() const;
+
+ virtual ExecutionNode* getCopy() const;
+
+private:
+ DiceResult* m_diceResult;
+};
+
+#endif // FILTERNODE_H