aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/node/dicerollernode.cpp
blob: 1e2dd883999d0037d0a1d1c63f3f472208b55194 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "dicerollernode.h"
#include "die.h"



#include <QDebug>

DiceRollerNode::DiceRollerNode(quint64 faces)
    : m_faces(faces),m_myDiceResult(new DiceResult())
{

    m_result=m_myDiceResult;

}
void DiceRollerNode::run(ExecutionNode* previous)
{
//       qDebug() << "DiceRollerNode node";
    if(NULL!=previous)
    {
        Result* result=previous->getResult();
        if(NULL!=result)
        {
            m_diceCount = result->getScalar();
            m_result->setPrevious(result);

            for(quint64 i=0; i < m_diceCount ; ++i)
            {
                Die* die = new Die();
                die->setFaces(m_faces);
                die->roll();
                m_myDiceResult->insertResult(die);
            }
            if(NULL!=m_nextNode)
            {
                m_nextNode->run(this);
            }
        }
    }
}

quint64 DiceRollerNode::getFaces()
{
    return m_faces;
}
QString DiceRollerNode::toString() const
{
    return QString("DiceRollerNode");
}
qint64 DiceRollerNode::getPriority() const
{
    qint64 priority=0;
    if(NULL!=m_nextNode)
    {
        priority = m_nextNode->getPriority();
    }


    return priority;
}