1 #ifndef PLAYER_H
2 #define PLAYER_H
3 
4 #include "pb/card_attributes.pb.h"
5 #include "pb/response.pb.h"
6 #include "server_arrowtarget.h"
7 #include "serverinfo_user_container.h"
8 
9 #include <QList>
10 #include <QMap>
11 #include <QMutex>
12 #include <QString>
13 
14 class DeckList;
15 class Server_Game;
16 class Server_CardZone;
17 class Server_Counter;
18 class Server_Arrow;
19 class Server_Card;
20 class Server_AbstractUserInterface;
21 class ServerInfo_User;
22 class ServerInfo_Player;
23 class ServerInfo_PlayerProperties;
24 class CommandContainer;
25 class CardToMove;
26 class GameEventContainer;
27 class GameEventStorage;
28 class ResponseContainer;
29 class GameCommand;
30 
31 class Command_KickFromGame;
32 class Command_LeaveGame;
33 class Command_GameSay;
34 class Command_Shuffle;
35 class Command_Mulligan;
36 class Command_RollDie;
37 class Command_DrawCards;
38 class Command_UndoDraw;
39 class Command_FlipCard;
40 class Command_AttachCard;
41 class Command_CreateToken;
42 class Command_CreateArrow;
43 class Command_DeleteArrow;
44 class Command_SetCardAttr;
45 class Command_SetCardCounter;
46 class Command_IncCardCounter;
47 class Command_ReadyStart;
48 class Command_Concede;
49 class Command_Unconcede;
50 class Command_Judge;
51 class Command_IncCounter;
52 class Command_CreateCounter;
53 class Command_SetCounter;
54 class Command_DelCounter;
55 class Command_NextTurn;
56 class Command_SetActivePhase;
57 class Command_DumpZone;
58 class Command_StopDumpZone;
59 class Command_RevealCards;
60 class Command_ReverseTurn;
61 class Command_MoveCard;
62 class Command_SetSideboardPlan;
63 class Command_DeckSelect;
64 class Command_SetSideboardLock;
65 class Command_ChangeZoneProperties;
66 
67 class Server_Player : public Server_ArrowTarget, public ServerInfo_User_Container
68 {
69     Q_OBJECT
70 private:
71     class MoveCardCompareFunctor;
72     Server_Game *game;
73     Server_AbstractUserInterface *userInterface;
74     DeckList *deck;
75     QMap<QString, Server_CardZone *> zones;
76     QMap<int, Server_Counter *> counters;
77     QMap<int, Server_Arrow *> arrows;
78     QList<int> lastDrawList;
79     int pingTime;
80     int playerId;
81     bool spectator;
82     bool judge;
83     int nextCardId;
84     bool readyStart;
85     bool conceded;
86     bool sideboardLocked;
87 
88 public:
89     mutable QMutex playerMutex;
90     Server_Player(Server_Game *_game,
91                   int _playerId,
92                   const ServerInfo_User &_userInfo,
93                   bool _spectator,
94                   bool _judge,
95                   Server_AbstractUserInterface *_handler);
96     ~Server_Player() override;
97     void prepareDestroy();
getUserInterface()98     Server_AbstractUserInterface *getUserInterface() const
99     {
100         return userInterface;
101     }
102     void setUserInterface(Server_AbstractUserInterface *_userInterface);
103     void disconnectClient();
104 
getReadyStart()105     bool getReadyStart() const
106     {
107         return readyStart;
108     }
setReadyStart(bool _readyStart)109     void setReadyStart(bool _readyStart)
110     {
111         readyStart = _readyStart;
112     }
getPlayerId()113     int getPlayerId() const
114     {
115         return playerId;
116     }
getSpectator()117     bool getSpectator() const
118     {
119         return spectator;
120     }
getJudge()121     bool getJudge() const
122     {
123         return judge;
124     }
getConceded()125     bool getConceded() const
126     {
127         return conceded;
128     }
setConceded(bool _conceded)129     void setConceded(bool _conceded)
130     {
131         conceded = _conceded;
132     }
133 
getGame()134     Server_Game *getGame() const
135     {
136         return game;
137     }
getZones()138     const QMap<QString, Server_CardZone *> &getZones() const
139     {
140         return zones;
141     }
getCounters()142     const QMap<int, Server_Counter *> &getCounters() const
143     {
144         return counters;
145     }
getArrows()146     const QMap<int, Server_Arrow *> &getArrows() const
147     {
148         return arrows;
149     }
150 
getPingTime()151     int getPingTime() const
152     {
153         return pingTime;
154     }
setPingTime(int _pingTime)155     void setPingTime(int _pingTime)
156     {
157         pingTime = _pingTime;
158     }
159     void getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo);
160 
161     int newCardId();
162     int newCounterId() const;
163     int newArrowId() const;
164 
165     void addZone(Server_CardZone *zone);
166     void addArrow(Server_Arrow *arrow);
167     bool deleteArrow(int arrowId);
168     void addCounter(Server_Counter *counter);
169 
170     void clearZones();
171     void setupZones();
172 
173     Response::ResponseCode drawCards(GameEventStorage &ges, int number);
174     Response::ResponseCode moveCard(GameEventStorage &ges,
175                                     Server_CardZone *startzone,
176                                     const QList<const CardToMove *> &_cards,
177                                     Server_CardZone *targetzone,
178                                     int x,
179                                     int y,
180                                     bool fixFreeSpaces = true,
181                                     bool undoingDraw = false);
182     void unattachCard(GameEventStorage &ges, Server_Card *card);
183     Response::ResponseCode setCardAttrHelper(GameEventStorage &ges,
184                                              int targetPlayerId,
185                                              const QString &zone,
186                                              int cardId,
187                                              CardAttribute attribute,
188                                              const QString &attrValue);
189 
190     Response::ResponseCode cmdLeaveGame(const Command_LeaveGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
191     Response::ResponseCode
192     cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer &rc, GameEventStorage &ges);
193     Response::ResponseCode cmdConcede(const Command_Concede &cmd, ResponseContainer &rc, GameEventStorage &ges);
194     Response::ResponseCode cmdUnconcede(const Command_Unconcede &cmd, ResponseContainer &rc, GameEventStorage &ges);
195     Response::ResponseCode cmdJudge(const Command_Judge &cmd, ResponseContainer &rc, GameEventStorage &ges);
196     Response::ResponseCode cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer &rc, GameEventStorage &ges);
197     Response::ResponseCode cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges);
198     Response::ResponseCode
199     cmdSetSideboardPlan(const Command_SetSideboardPlan &cmd, ResponseContainer &rc, GameEventStorage &ges);
200     Response::ResponseCode
201     cmdSetSideboardLock(const Command_SetSideboardLock &cmd, ResponseContainer &rc, GameEventStorage &ges);
202     Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
203     Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
204     Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
205     Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
206     Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
207     Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
208     Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
209     Response::ResponseCode cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
210     Response::ResponseCode cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer &rc, GameEventStorage &ges);
211     Response::ResponseCode cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges);
212     Response::ResponseCode cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
213     Response::ResponseCode cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer &rc, GameEventStorage &ges);
214     Response::ResponseCode cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer &rc, GameEventStorage &ges);
215     Response::ResponseCode
216     cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
217     Response::ResponseCode
218     cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
219     Response::ResponseCode cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
220     Response::ResponseCode
221     cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
222     Response::ResponseCode cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
223     Response::ResponseCode cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer &rc, GameEventStorage &ges);
224     Response::ResponseCode cmdNextTurn(const Command_NextTurn &cmd, ResponseContainer &rc, GameEventStorage &ges);
225     Response::ResponseCode
226     cmdSetActivePhase(const Command_SetActivePhase &cmd, ResponseContainer &rc, GameEventStorage &ges);
227     Response::ResponseCode cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
228     Response::ResponseCode
229     cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges);
230     Response::ResponseCode cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
231     Response::ResponseCode
232     cmdReverseTurn(const Command_ReverseTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges);
233     Response::ResponseCode
234     cmdChangeZoneProperties(const Command_ChangeZoneProperties &cmd, ResponseContainer &rc, GameEventStorage &ges);
235 
236     Response::ResponseCode processGameCommand(const GameCommand &command, ResponseContainer &rc, GameEventStorage &ges);
237     void sendGameEvent(const GameEventContainer &event);
238 
239     void getInfo(ServerInfo_Player *info, Server_Player *playerWhosAsking, bool omniscient, bool withUserInfo);
240 };
241 
242 #endif
243