File indexing completed on 2024-05-12 05:39:29

0001 /***************************************************************************
0002  * Copyright (C) 2014 by Renaud Guezennec                                   *
0003  * https://rolisteam.org/contact                      *
0004  *                                                                          *
0005  *  This file is part of DiceParser                                         *
0006  *                                                                          *
0007  * DiceParser is free software; you can redistribute it and/or modify       *
0008  * it under the terms of the GNU General Public License as published by     *
0009  * the Free Software Foundation; either version 2 of the License, or        *
0010  * (at your option) any later version.                                      *
0011  *                                                                          *
0012  * This program is distributed in the hope that it will be useful,          *
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of           *
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
0015  * GNU General Public License for more details.                             *
0016  *                                                                          *
0017  * You should have received a copy of the GNU General Public License        *
0018  * along with this program; if not, write to the                            *
0019  * Free Software Foundation, Inc.,                                          *
0020  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.                 *
0021  ***************************************************************************/
0022 #include "splitnode.h"
0023 
0024 SplitNode::SplitNode() : m_diceResult(new DiceResult())
0025 {
0026     m_result= m_diceResult;
0027 }
0028 void SplitNode::run(ExecutionNode* previous)
0029 {
0030     m_previousNode= previous;
0031     if(nullptr != previous)
0032     {
0033         m_result->setPrevious(previous->getResult());
0034 
0035         Result* tmpResult= previous->getResult();
0036         if(nullptr != tmpResult)
0037         {
0038             DiceResult* dice= dynamic_cast<DiceResult*>(tmpResult);
0039             if(nullptr != dice)
0040             {
0041                 for(auto& oldDie : dice->getResultList())
0042                 {
0043                     oldDie->displayed();
0044                     m_diceResult->setOperator(oldDie->getOp());
0045                     for(qint64& value : oldDie->getListValue())
0046                     {
0047                         Die* tmpdie= new Die();
0048                         tmpdie->insertRollValue(value);
0049                         tmpdie->setBase(oldDie->getBase());
0050                         tmpdie->setMaxValue(oldDie->getMaxValue());
0051                         tmpdie->setValue(value);
0052                         tmpdie->setOp(oldDie->getOp());
0053                         m_diceResult->insertResult(tmpdie);
0054                     }
0055                 }
0056             }
0057         }
0058     }
0059     if(nullptr != m_nextNode)
0060     {
0061         m_nextNode->run(this);
0062     }
0063 }
0064 
0065 QString SplitNode::toString(bool withLabel) const
0066 {
0067     if(withLabel)
0068     {
0069         return QString("%1 [label=\"SplitNode Node\"]").arg(m_id);
0070     }
0071     else
0072     {
0073         return m_id;
0074     }
0075 }
0076 qint64 SplitNode::getPriority() const
0077 {
0078     qint64 priority= 0;
0079     if(nullptr != m_nextNode)
0080     {
0081         priority= m_nextNode->getPriority();
0082     }
0083     return priority;
0084 }
0085 ExecutionNode* SplitNode::getCopy() const
0086 {
0087     SplitNode* node= new SplitNode();
0088     if(nullptr != m_nextNode)
0089     {
0090         node->setNextNode(m_nextNode->getCopy());
0091     }
0092     return node;
0093 }