mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-29 01:53:54 -07:00
p/t changes
This commit is contained in:
parent
713ebece78
commit
d05603f83b
8 changed files with 157 additions and 24 deletions
|
|
@ -20,7 +20,7 @@
|
|||
#include "server_card.h"
|
||||
|
||||
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y)
|
||||
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), pt(QString()), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
: id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), doesntUntap(false), parentCard(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -39,12 +39,13 @@ void Server_Card::resetState()
|
|||
counters.clear();
|
||||
setTapped(false);
|
||||
setAttacking(false);
|
||||
setPT(QString());
|
||||
power = 0;
|
||||
toughness = 0;
|
||||
setAnnotation(QString());
|
||||
setDoesntUntap(false);
|
||||
}
|
||||
|
||||
bool Server_Card::setAttribute(const QString &aname, const QString &avalue, bool allCards)
|
||||
QString Server_Card::setAttribute(const QString &aname, const QString &avalue, bool allCards)
|
||||
{
|
||||
if (aname == "tapped") {
|
||||
bool value = avalue == "1";
|
||||
|
|
@ -58,14 +59,15 @@ bool Server_Card::setAttribute(const QString &aname, const QString &avalue, bool
|
|||
setColor(avalue);
|
||||
} else if (aname == "pt") {
|
||||
setPT(avalue);
|
||||
return getPT();
|
||||
} else if (aname == "annotation") {
|
||||
setAnnotation(avalue);
|
||||
} else if (aname == "doesnt_untap") {
|
||||
setDoesntUntap(avalue == "1");
|
||||
} else
|
||||
return false;
|
||||
return QString();
|
||||
|
||||
return true;
|
||||
return avalue;
|
||||
}
|
||||
|
||||
void Server_Card::setCounter(int id, int value)
|
||||
|
|
@ -76,6 +78,36 @@ void Server_Card::setCounter(int id, int value)
|
|||
counters.remove(id);
|
||||
}
|
||||
|
||||
void Server_Card::setPT(const QString &_pt)
|
||||
{
|
||||
int sep = _pt.indexOf('/');
|
||||
QString p1 = _pt.left(sep);
|
||||
QString p2 = _pt.mid(sep + 1);
|
||||
if (p1.isEmpty() || p2.isEmpty())
|
||||
return;
|
||||
if ((p1[0] == '+') || (p2[0] == '+')) {
|
||||
if (power < 0)
|
||||
power = 0;
|
||||
if (toughness < 0)
|
||||
toughness = 0;
|
||||
}
|
||||
if (p1[0] == '+')
|
||||
power += p1.mid(1).toInt();
|
||||
else
|
||||
power = p1.toInt();
|
||||
if (p2[0] == '+')
|
||||
toughness += p2.mid(1).toInt();
|
||||
else
|
||||
toughness = p2.toInt();
|
||||
}
|
||||
|
||||
QString Server_Card::getPT() const
|
||||
{
|
||||
if (toughness < 0)
|
||||
return QString("");
|
||||
return QString::number(power) + "/" + QString::number(toughness);
|
||||
}
|
||||
|
||||
void Server_Card::setParentCard(Server_Card *_parentCard)
|
||||
{
|
||||
if (parentCard)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ private:
|
|||
bool attacking;
|
||||
bool facedown;
|
||||
QString color;
|
||||
QString pt;
|
||||
int power, toughness;
|
||||
QString annotation;
|
||||
bool destroyOnZoneChange;
|
||||
bool doesntUntap;
|
||||
|
|
@ -62,7 +62,7 @@ public:
|
|||
bool getAttacking() const { return attacking; }
|
||||
bool getFaceDown() const { return facedown; }
|
||||
QString getColor() const { return color; }
|
||||
QString getPT() const { return pt; }
|
||||
QString getPT() const;
|
||||
QString getAnnotation() const { return annotation; }
|
||||
bool getDoesntUntap() const { return doesntUntap; }
|
||||
bool getDestroyOnZoneChange() const { return destroyOnZoneChange; }
|
||||
|
|
@ -77,7 +77,7 @@ public:
|
|||
void setAttacking(bool _attacking) { attacking = _attacking; }
|
||||
void setFaceDown(bool _facedown) { facedown = _facedown; }
|
||||
void setColor(const QString &_color) { color = _color; }
|
||||
void setPT(const QString &_pt) { pt = _pt; }
|
||||
void setPT(const QString &_pt);
|
||||
void setAnnotation(const QString &_annotation) { annotation = _annotation; }
|
||||
void setDestroyOnZoneChange(bool _destroy) { destroyOnZoneChange = _destroy; }
|
||||
void setDoesntUntap(bool _doesntUntap) { doesntUntap = _doesntUntap; }
|
||||
|
|
@ -86,7 +86,7 @@ public:
|
|||
void removeAttachedCard(Server_Card *card) { attachedCards.removeAt(attachedCards.indexOf(card)); }
|
||||
|
||||
void resetState();
|
||||
bool setAttribute(const QString &aname, const QString &avalue, bool allCards);
|
||||
QString setAttribute(const QString &aname, const QString &avalue, bool allCards);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -436,21 +436,25 @@ ResponseCode Server_Player::setCardAttrHelper(CommandContainer *cont, const QStr
|
|||
if (!zone->hasCoords())
|
||||
return RespContextError;
|
||||
|
||||
QString result;
|
||||
if (cardId == -1) {
|
||||
QListIterator<Server_Card *> CardIterator(zone->cards);
|
||||
while (CardIterator.hasNext())
|
||||
if (!CardIterator.next()->setAttribute(attrName, attrValue, true))
|
||||
while (CardIterator.hasNext()) {
|
||||
result = CardIterator.next()->setAttribute(attrName, attrValue, true);
|
||||
if (result.isNull())
|
||||
return RespInvalidCommand;
|
||||
}
|
||||
} else {
|
||||
Server_Card *card = zone->getCard(cardId, false);
|
||||
if (!card)
|
||||
return RespNameNotFound;
|
||||
if (!card->setAttribute(attrName, attrValue, false))
|
||||
result = card->setAttribute(attrName, attrValue, false);
|
||||
if (result.isNull())
|
||||
return RespInvalidCommand;
|
||||
}
|
||||
cont->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId());
|
||||
cont->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId());
|
||||
cont->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, attrValue), game->getGameId());
|
||||
cont->enqueueGameEventPrivate(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
|
||||
cont->enqueueGameEventPublic(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
|
||||
cont->enqueueGameEventOmniscient(new Event_SetCardAttr(getPlayerId(), zone->getName(), cardId, attrName, result), game->getGameId());
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue