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

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef PLAYER_H
0022 #define PLAYER_H
0023 #include "person.h"
0024 
0025 #include "network_global.h"
0026 #include <QMetaType>
0027 #include <memory>
0028 
0029 class NetworkLink;
0030 /**
0031  * @brief Represents a player.
0032  *
0033  * Players are stored in PlayersList. A player may have some characters.
0034  */
0035 class NETWORK_EXPORT Player : public Person
0036 {
0037     Q_OBJECT
0038     Q_PROPERTY(bool isGM READ isGM WRITE setGM NOTIFY gmChanged FINAL)
0039     Q_PROPERTY(QString userVersion READ userVersion WRITE setUserVersion NOTIFY userVersionChanged FINAL)
0040     Q_PROPERTY(int characterCount READ characterCount NOTIFY characterCountChanged FINAL)
0041 public:
0042     Player();
0043     Player(const QString& getName, const QColor& getColor, bool master= false);
0044     Player(const QString& uuid, const QString& getName, const QColor& getColor, bool master= false);
0045     virtual ~Player() override;
0046 
0047     Character* getCharacterByIndex(int index) const;
0048     Character* characterById(const QString& id) const;
0049     const std::vector<std::unique_ptr<Character>>& children();
0050 
0051     virtual int characterCount() const;
0052     QString userVersion() const;
0053     bool isGM() const;
0054 
0055     // Children
0056     int indexOf(Character* character) const;
0057     void addCharacter(const QString& uuid, const QString& name, const QColor& color, const QByteArray& data,
0058                       const QHash<QString, QVariant>&, bool Npc);
0059     void addCharacter(Character* character);
0060     virtual bool removeChild(Character*);
0061     void clearCharacterList();
0062 
0063     virtual bool isLeaf() const override;
0064     virtual QHash<QString, QString> getVariableDictionnary() override;
0065     bool isFullyDefined();
0066     void copyPlayer(Player* player);
0067 
0068 public slots:
0069     void setUserVersion(QString softV);
0070     void setGM(bool value);
0071 
0072 signals:
0073     void gmChanged();
0074     void userVersionChanged();
0075     void characterCountChanged();
0076     void characterChanged();
0077 
0078 private:
0079     std::vector<std::unique_ptr<Character>> m_characters;
0080     bool m_gameMaster= false;
0081     QString m_softVersion;
0082 };
0083 
0084 #endif // PLAYER_H