Cockatrice 2026-06-27-Development-3.1.0-beta.3
A 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
163 [[nodiscard]] bool setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
173 [[nodiscard]] bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event = nullptr);
174 void setTapped(bool _tapped)
175 {
176 tapped = _tapped;
177 }
178 void setAttacking(bool _attacking)
179 {
180 attacking = _attacking;
181 }
182 void setFaceDown(bool _facedown)
183 {
184 facedown = _facedown;
185 }
186 void setColor(const QString &_color)
187 {
188 color = _color;
189 }
190 void setPT(const QString &_pt)
191 {
192 ptString = _pt;
193 }
194 void setAnnotation(const QString &_annotation)
195 {
196 annotation = _annotation;
197 }
198 void setDestroyOnZoneChange(bool _destroy)
199 {
200 destroyOnZoneChange = _destroy;
201 }
202 void setDoesntUntap(bool _doesntUntap)
203 {
204 doesntUntap = _doesntUntap;
205 }
206 void setParentCard(Server_Card *_parentCard);
208 {
209 attachedCards.append(card);
210 }
212 {
213 attachedCards.removeOne(card);
214 }
216 {
217 // setStashedCard should only be called on creation of a new card, so
218 // there should never be an already existing stashed card.
219 Q_ASSERT(!stashedCard);
220
221 // Stashed cards can't themselves have stashed cards, and tokens can't
222 // be stashed.
223 if (card->stashedCard || card->getDestroyOnZoneChange()) {
225 card->deleteLater();
226 } else {
227 stashedCard = card;
228 }
229 }
231 {
232 Server_Card *oldStashedCard = stashedCard;
233 stashedCard = nullptr;
234 return oldStashedCard;
235 }
236
237 void resetState(bool keepAnnotations = false);
238 QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
239 QString setAttribute(CardAttribute attribute, const QString &avalue, Event_SetCardAttr *event = nullptr);
240
241 void getInfo(ServerInfo_Card *info);
242};
243
244#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:38
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:215
bool getFaceDown() const
Definition server_card.h:110
bool destroyOnZoneChange
Definition server_card.h:50
void setParentCard(Server_Card *_parentCard)
Definition server_card.cpp:165
void getInfo(ServerInfo_Card *info)
Definition server_card.cpp:176
bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event=nullptr)
Increments a card counter with overflow-safe arithmetic.
Definition server_card.cpp:139
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:190
Server_Card * takeStashedCard()
Definition server_card.h:230
Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone=nullptr)
Definition server_card.cpp:32
CardRef cardRef
Definition server_card.h:42
void setTapped(bool _tapped)
Definition server_card.h:174
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:55
bool getDestroyOnZoneChange() const
Definition server_card.h:130
bool setCounter(int _id, int value, Event_SetCardCounter *event=nullptr)
Sets a card counter to an exact value with clamping.
Definition server_card.cpp:115
void setAttacking(bool _attacking)
Definition server_card.h:178
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:207
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:211
void setFaceDown(bool _facedown)
Definition server_card.h:182
QMap< int, int > counters
Definition server_card.h:43
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
Definition server_card.cpp:67
QString getColor() const
Definition server_card.h:114
void setDoesntUntap(bool _doesntUntap)
Definition server_card.h:202
int getX() const
Definition server_card.h:82
void setDestroyOnZoneChange(bool _destroy)
Definition server_card.h:198
int id
Definition server_card.h:40
void setColor(const QString &_color)
Definition server_card.h:186
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:194
int coord_y
Definition server_card.h:41
Definition card_ref.h:14