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

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 #ifndef GROUPNODE_H
0023 #define GROUPNODE_H
0024 
0025 #include "node/executionnode.h"
0026 #include "result/scalarresult.h"
0027 #include "result/stringresult.h"
0028 #include <QList>
0029 
0030 class DieGroup : public QList<qint64>
0031 {
0032 public:
0033     int getSum() const;
0034     void removeValue(DieGroup);
0035 
0036     int getLost() const;
0037 
0038     qint64 getExceptedValue() const;
0039     void setExceptedValue(qint64 exceptedValue);
0040 
0041 private:
0042     qint64 m_exceptedValue= 0;
0043 };
0044 /**
0045  * @brief The GroupNode class is an ExecutionNode.
0046  */
0047 class GroupNode : public ExecutionNode
0048 {
0049 public:
0050     GroupNode(bool complexOutput= false);
0051     void run(ExecutionNode* previous) override;
0052     virtual QString toString(bool withLabel) const override;
0053     virtual qint64 getPriority() const override;
0054     virtual ExecutionNode* getCopy() const override;
0055 
0056     int getGroupValue() const;
0057     void setGroupValue(qint64 groupValue);
0058 
0059     QList<DieGroup> getGroup(DieGroup);
0060 
0061 protected:
0062     bool composeWithPrevious(DieGroup previous, qint64 first, qint64 current, DieGroup& addValue);
0063 
0064 private:
0065     ScalarResult* m_scalarResult;
0066     StringResult* m_stringResult;
0067     qint64 m_groupValue;
0068     QList<DieGroup> m_groupsList;
0069     bool m_complexOutput= false;
0070 };
0071 
0072 #endif // GROUPNODE_H