Cockatrice 2026-10-19-Development-3.1.2-beta.2
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 <QList>
26#include <QMap>
27#include <QString>
28#include <QtGlobal>
30#include <qtmetamacros.h>
31
32class Server_CardZone;
35class ServerInfo_Card;
36enum CardAttribute : int;
37
39{
40 Q_OBJECT
41private:
43 int id;
47 bool tapped;
50 QString color;
51 QString ptString;
52 QString annotation;
55
59
60public:
61 Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone = nullptr);
62 ~Server_Card() override;
63
65 {
66 return zone;
67 }
69 {
70 zone = _zone;
71 }
72
73 int getId() const
74 {
75 return id;
76 }
78 {
79 return cardRef;
80 }
81 QString getProviderId() const
82 {
83 return cardRef.providerId;
84 }
85 int getX() const
86 {
87 return coord_x;
88 }
89 int getY() const
90 {
91 return coord_y;
92 }
93 QString getName() const
94 {
95 return cardRef.name;
96 }
98 {
99 return counters;
100 }
101 int getCounter(int counter_id) const
102 {
103 return counters.value(counter_id, 0);
104 }
105 bool getTapped() const
106 {
107 return tapped;
108 }
109 bool getAttacking() const
110 {
111 return attacking;
112 }
113 bool getFaceDown() const
114 {
115 return facedown;
116 }
117 QString getColor() const
118 {
119 return color;
120 }
121 QString getPT() const
122 {
123 return ptString;
124 }
125 QString getAnnotation() const
126 {
127 return annotation;
128 }
129 bool getDoesntUntap() const
130 {
131 return doesntUntap;
132 }
134 {
135 return destroyOnZoneChange;
136 }
138 {
139 return parentCard;
140 }
142 {
143 return attachedCards;
144 }
145
146 void setId(int _id)
147 {
148 id = _id;
149 }
150 void setCoords(int x, int y)
151 {
152 coord_x = x;
153 coord_y = y;
154 }
155 void setCardRef(const CardRef &_cardRef)
156 {
157 cardRef = _cardRef;
158 }
159
166 [[nodiscard]] bool setCounter(int _id, int value, Event_SetCardCounter *event = nullptr);
176 [[nodiscard]] bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event = nullptr);
177 void setTapped(bool _tapped)
178 {
179 tapped = _tapped;
180 }
181 void setAttacking(bool _attacking)
182 {
183 attacking = _attacking;
184 }
185 void setFaceDown(bool _facedown)
186 {
187 facedown = _facedown;
188 }
189 void setColor(const QString &_color)
190 {
191 color = _color;
192 }
193 void setPT(const QString &_pt)
194 {
195 ptString = _pt;
196 }
197 void setAnnotation(const QString &_annotation)
198 {
199 annotation = _annotation;
200 }
201 void setDestroyOnZoneChange(bool _destroy)
202 {
203 destroyOnZoneChange = _destroy;
204 }
205 void setDoesntUntap(bool _doesntUntap)
206 {
207 doesntUntap = _doesntUntap;
208 }
209 void setParentCard(Server_Card *_parentCard);
211 {
212 attachedCards.append(card);
213 }
215 {
216 attachedCards.removeOne(card);
217 }
219 {
220 // setStashedCard should only be called on creation of a new card, so
221 // there should never be an already existing stashed card.
222 Q_ASSERT(!stashedCard);
223
224 // Stashed cards can't themselves have stashed cards, and tokens can't
225 // be stashed.
226 if (card->stashedCard || card->getDestroyOnZoneChange()) {
228 card->deleteLater();
229 } else {
230 stashedCard = card;
231 }
232 }
234 {
235 Server_Card *oldStashedCard = stashedCard;
236 stashedCard = nullptr;
237 return oldStashedCard;
238 }
239
240 void resetState(bool keepAnnotations = false);
241 QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
242 QString setAttribute(CardAttribute attribute, const QString &avalue, Event_SetCardAttr *event = nullptr);
243
244 void getInfo(ServerInfo_Card *info);
245};
246
247#endif
CardAttribute
Definition card_attributes.proto:2
Definition remote_connection_controller.h:20
Definition game.h:18
Definition server_arrowtarget.h:8
Definition server_cardzone.h:36
Definition server_card.h:39
bool getTapped() const
Definition server_card.h:105
Server_Card * stashedCard
Definition server_card.h:58
bool facedown
Definition server_card.h:49
Server_Card * getParentCard() const
Definition server_card.h:137
QString getProviderId() const
Definition server_card.h:81
void setStashedCard(Server_Card *card)
Definition server_card.h:218
bool getFaceDown() const
Definition server_card.h:113
bool destroyOnZoneChange
Definition server_card.h:53
void setParentCard(Server_Card *_parentCard)
Definition server_card.cpp:170
void getInfo(ServerInfo_Card *info)
Definition server_card.cpp:181
bool incrementCounter(int counterId, int delta, Event_SetCardCounter *event=nullptr)
Increments a card counter with overflow-safe arithmetic.
Definition server_card.cpp:146
Server_Card * parentCard
Definition server_card.h:56
int getCounter(int counter_id) const
Definition server_card.h:101
QString getPT() const
Definition server_card.h:121
const QList< Server_Card * > & getAttachedCards() const
Definition server_card.h:141
bool attacking
Definition server_card.h:48
void setPT(const QString &_pt)
Definition server_card.h:193
Server_Card * takeStashedCard()
Definition server_card.h:233
Server_Card(const CardRef &cardRef, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone=nullptr)
Definition server_card.cpp:39
CardRef cardRef
Definition server_card.h:45
void setTapped(bool _tapped)
Definition server_card.h:177
CardRef getCardRef() const
Definition server_card.h:77
QString annotation
Definition server_card.h:52
void setCoords(int x, int y)
Definition server_card.h:150
QList< Server_Card * > attachedCards
Definition server_card.h:57
QString color
Definition server_card.h:50
QString ptString
Definition server_card.h:51
QString getAnnotation() const
Definition server_card.h:125
int coord_x
Definition server_card.h:44
QString getName() const
Definition server_card.h:93
void resetState(bool keepAnnotations=false)
Definition server_card.cpp:62
bool getDestroyOnZoneChange() const
Definition server_card.h:133
bool setCounter(int _id, int value, Event_SetCardCounter *event=nullptr)
Sets a card counter to an exact value with clamping.
Definition server_card.cpp:122
void setAttacking(bool _attacking)
Definition server_card.h:181
bool getDoesntUntap() const
Definition server_card.h:129
void setZone(Server_CardZone *_zone)
Definition server_card.h:68
int getY() const
Definition server_card.h:89
Server_CardZone * getZone() const
Definition server_card.h:64
bool tapped
Definition server_card.h:47
void addAttachedCard(Server_Card *card)
Definition server_card.h:210
bool getAttacking() const
Definition server_card.h:109
Server_CardZone * zone
Definition server_card.h:42
int getId() const
Definition server_card.h:73
void setId(int _id)
Definition server_card.h:146
void removeAttachedCard(Server_Card *card)
Definition server_card.h:214
void setFaceDown(bool _facedown)
Definition server_card.h:185
QMap< int, int > counters
Definition server_card.h:46
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards)
Definition server_card.cpp:74
QString getColor() const
Definition server_card.h:117
void setDoesntUntap(bool _doesntUntap)
Definition server_card.h:205
int getX() const
Definition server_card.h:85
void setDestroyOnZoneChange(bool _destroy)
Definition server_card.h:201
int id
Definition server_card.h:43
void setColor(const QString &_color)
Definition server_card.h:189
const QMap< int, int > & getCounters() const
Definition server_card.h:97
void setCardRef(const CardRef &_cardRef)
Definition server_card.h:155
bool doesntUntap
Definition server_card.h:54
void setAnnotation(const QString &_annotation)
Definition server_card.h:197
int coord_y
Definition server_card.h:44
Definition card_ref.h:14
QString providerId
Definition card_ref.h:16
QString name
Definition card_ref.h:15
Definition event_set_card_attr.proto:4
Definition event_set_card_counter.proto:3
Definition serverinfo_card.proto:5