diff options
| author | 2018-01-25 01:06:07 +0100 | |
|---|---|---|
| committer | 2018-01-25 01:06:07 +0100 | |
| commit | bb9eeae7d5798d5c2c8579949c544b55be1bcbca (patch) | |
| tree | 768c7da75e6611fd0bc128b659255dcfc7cd1f84 /node/dicerollernode.cpp | |
| parent | 8904bc61ad71f407fbefa4b80793ba424f2ce88b (diff) | |
| download | OneRoll-bb9eeae7d5798d5c2c8579949c544b55be1bcbca.tar.gz OneRoll-bb9eeae7d5798d5c2c8579949c544b55be1bcbca.zip | |
-Add management of unique for dice and list.
Diffstat (limited to 'node/dicerollernode.cpp')
| -rw-r--r-- | node/dicerollernode.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/node/dicerollernode.cpp b/node/dicerollernode.cpp index 5a2ea04..1f501e5 100644 --- a/node/dicerollernode.cpp +++ b/node/dicerollernode.cpp @@ -29,6 +29,13 @@ void DiceRollerNode::run(ExecutionNode* previous) { m_errors.insert(NO_DICE_TO_ROLL,QObject::tr("No dice to roll")); } + auto possibleValue = (m_max-m_min)+1; + //qDebug() << possibleValue; + if( possibleValue < m_diceCount && m_unique) + { + m_errors.insert(TOO_MANY_DICE,QObject::tr("More unique values asked than possible values (D operator)")); + return; + } for(quint64 i=0; i < m_diceCount ; ++i) { @@ -37,7 +44,16 @@ void DiceRollerNode::run(ExecutionNode* previous) die->setBase(m_min); die->setMaxValue(m_max); die->roll(); - //qDebug() << die->getValue() << "value"; + if(m_unique) + { + const auto& equal = [](const Die* a,const Die* b){ + return a->getValue() == b->getValue(); + }; + while(m_diceResult->contains(die,equal)) + { + die->roll(false); + } + } m_diceResult->insertResult(die); } if(nullptr!=m_nextNode) @@ -94,3 +110,13 @@ void DiceRollerNode::setOperator(const Die::ArithmeticOperator &dieOperator) m_operator = dieOperator; m_diceResult->setOperator(dieOperator); } + +bool DiceRollerNode::getUnique() const +{ + return m_unique; +} + +void DiceRollerNode::setUnique(bool unique) +{ + m_unique = unique; +} |