Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
server_card.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2008 by Max-Wilhelm Bruker *
3 * brukie@laptop *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20#ifndef SERVER_CARD_H
21#define SERVER_CARD_H
22
23#include "server_arrowtarget.h"
24
25#include <QMap>
26#include <QString>
27#include <libcockatrice/protocol/pb/card_attributes.pb.h>
28#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
30
31class Server_CardZone;
32class Event_SetCardCounter;
33class Event_SetCardAttr;
34
36{
37 Q_OBJECT
38private:
40 int id;
43 QMap<int, int> counters;
44 bool tapped;
47 QString color;
48 QString ptString;
49 QString annotation;
52
54 QList<Server_Card *> attachedCards;
56
57public:
58 Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = nullptr);
59 ~Server_Card() override;
60
62 {
63 return zone;
64 }
66 {
67 zone = _zone;
68 }
69
70 int getId() const
71 {
72 return id;
73 }
75 {
76 return cardRef;
77 }
78 QString getProviderId() const
79 {
80 return cardRef.providerId;
81 }
82 int getX() const
83 {
84 return coord_x;
85 }
86 int getY() const
87 {
88 return coord_y;
89 }
90 QString getName() const
91 {
92 return cardRef.name;
93 }
94 const QMap<int, int> &getCounters() const
95 {
96 return counters;
97 }
98 int getCounter(int counter_id) const
99 {
100 return counters.value(counter_id, 0);
101 }
102 bool getTapped() const
103 {
104 return tapped;
105 }
106 bool getAttacking() const
107 {
108 return attacking;
109 }
110 bool getFaceDown() const
111 {
112 return facedown;
113 }
114 QString getColor() const
115 {
116 return color;
117 }
118 QString getPT() const
119 {
120 return ptString;
121 }
122 QString getAnnotation() const
123 {
124 return annotation;
125 }
126 bool getDoesntUntap() const
127 {
128 return doesntUntap;
129 }
131 {
132 return destroyOnZoneChange;
133 }
135 {
136 return parentCard;
137 }
138 const QList<Server_Card *> &getAttachedCards() const
139 {
140 return attachedCards;
141 }
142
143 void setId(int _id)
144 {
145 id = _id;
146 }
147 void setCoords(int x, int y)
148 {
149 coord_x = x;
150 coord_y = y;
151 }
152 void setCardRef(const CardRef &_cardRef)
153 {
154 cardRef = _cardRef;
155 }
156 void setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
157 void setTapped(bool _tapped)
158 {
159 tapped = _tapped;
160 }
161 void setAttacking(bool _attacking)
162 {
163 attacking = _attacking;
164 }
165 void setFaceDown(bool _facedown)
166 {
167 facedown = _facedown;
168 }
169 void setColor(const QString &_color)
170 {
171 color = _color;
172 }
173 void setPT(const QString &_pt)
174 {
175 ptString = _pt;
176 }
177 void setAnnotation(const QString &_annotation)
178 {
179 annotation = _annotation;
180 }
181 void setDestroyOnZoneChange(bool _destroy)
182 {
183 destroyOnZoneChange = _destroy;
184 }
185 void setDoesntUntap(bool _doesntUntap)
186 {
187 doesntUntap = _doesntUntap;
188 }
189 void setParentCard(Server_Card *_parentCard);
191 {
192 attachedCards.append(card);
193 }
195 {
196 attachedCards.removeOne(card);
197 }
199 {
200 // setStashedCard should only be called on creation of a new card, so
201 // there should never be an already existing stashed card.
202 Q_ASSERT(!stashedCard);
203
204 // Stashed cards can't themselves have stashed cards, and tokens can't
205 // be stashed.
206 if (card->stashedCard || card->getDestroyOnZoneChange()) {
208 card->deleteLater();
209 } else {
210 stashedCard = card;
211 }
212 }
214 {
215 Server_Card *oldStashedCard = stashedCard;
216 stashedCard = nullptr;
217 return oldStashedCard;
218 }
219
220 void resetState(bool keepAnnotations = false);
221 QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
222 QString setAttribute(CardAttribute attribute, const QString &avalue, Event_SetCardAttr *event = nullptr);
223
224 void getInfo(ServerInfo_Card *info);
225};
226
227#endif
Definition server_arrowtarget.h:7
Definition server_cardzone.h:35
Definition server_card.h:36
bool getTapped() const
Definition server_card.h:102
~Server_Card() override
Definition server_card.cpp:36
Server_Card * stashedCard
Definition server_card.h:55
bool facedown
Definition server_card.h:46
Server_Card * getParentCard() const
Definition server_card.h:134
QString getProviderId() const
Definition server_card.h:78
void setStashedCard(Server_Card *card)
Definition server_card.h:198
bool getFaceDown() const
Definition server_card.h:110
bool destroyOnZoneChange
Definition server_card.h:50
void setParentCard(Server_Card *_parentCard)
Definition server_card.cpp:120
void getInfo(ServerInfo_Card *info)
Definition server_card.cpp:129
Server_Card * parentCard
Definition server_card.h:53
int getCounter(int counter_id) const
Definition server_card.h:98
QString getPT() const
Definition server_card.h:118
const QList< Server_Card * > & getAttachedCards() const
Definition server_card.h:138
bool attacking
Definition server_card.h:45
void setPT(const QString &_pt)
Definition server_card.h:173
Server_Card * takeStashedCard()
Definition server_card.h:213
void setCounter(int _id, int value, Event_SetCardCounter *event=nullptr)
Definition server_card.cpp:107
Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone=nullptr)
Definition server_card.cpp:30
CardRef cardRef
Definition server_card.h:42
void setTapped(bool _tapped)
Definition server_card.h:157
CardRef getCardRef() const
Definition server_card.h:74
QString annotation
Definition server_card.h:49
void setCoords(int x, int y)
Definition server_card.h:147
QList< Server_Card * > attachedCards
Definition server_card.h:54
QString color
Definition server_card.h:47
QString ptString
Definition server_card.h:48
QString getAnnotation() const
Definition server_card.h:122
int coord_x
Definition server_card.h:41
QString getName() const
Definition server_card.h:90
void resetState(bool keepAnnotations=false)
Definition server_card.cpp:51
bool getDestroyOnZoneChange() const
Definition server_card.h:130
void setAttacking(bool _attacking)
Definition server_card.h:161
bool getDoesntUntap() const
Definition server_card.h:126
void setZone(Server_CardZone *_zone)
Definition server_card.h:65
int getY() const
Definition server_card.h:86
Server_CardZone * getZone() const
Definition server_card.h:61
bool tapped
Definition server_card.h:44
void addAttachedCard(Server_Card *card)
Definition server_card.h:190
bool getAttacking() const
Definition server_card.h:106
Server_CardZone * zone
Definition server_card.h:39
int getId() const
Definition server_card.h:70
void setId(int _id)
Definition server_card.h:143
void removeAttachedCard(Server_Card *card)
Definition server_card.h:194
void setFaceDown(bool _facedown)
Definition server_card.h:165
QMap< int, int > counters
Definition server_card.h:43
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
Definition server_card.cpp:63
QString getColor() const
Definition server_card.h:114
void setDoesntUntap(bool _doesntUntap)
Definition server_card.h:185
int getX() const
Definition server_card.h:82
void setDestroyOnZoneChange(bool _destroy)
Definition server_card.h:181
int id
Definition server_card.h:40
void setColor(const QString &_color)
Definition server_card.h:169
const QMap< int, int > & getCounters() const
Definition server_card.h:94
void setCardRef(const CardRef &_cardRef)
Definition server_card.h:152
bool doesntUntap
Definition server_card.h:51
void setAnnotation(const QString &_annotation)
Definition server_card.h:177
int coord_y
Definition server_card.h:41
Definition card_ref.h:14