mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
improved facedown moving
This commit is contained in:
parent
1047ab08e8
commit
da467468d5
22 changed files with 54 additions and 53 deletions
|
|
@ -230,7 +230,7 @@ QList<MoveCardToZone *> Command_SetSideboardPlan::getMoveList() const
|
|||
return typecastItemList<MoveCardToZone *>();
|
||||
}
|
||||
|
||||
Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, const QList<CardToMove *> &_cards, int _targetPlayerId, const QString &_targetZone, int _x, int _y, bool _faceDown)
|
||||
Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, const QList<CardToMove *> &_cards, int _targetPlayerId, const QString &_targetZone, int _x, int _y)
|
||||
: GameCommand("move_card", _gameId)
|
||||
{
|
||||
insertItem(new SerializableItem_String("start_zone", _startZone));
|
||||
|
|
@ -238,7 +238,6 @@ Command_MoveCard::Command_MoveCard(int _gameId, const QString &_startZone, const
|
|||
insertItem(new SerializableItem_String("target_zone", _targetZone));
|
||||
insertItem(new SerializableItem_Int("x", _x));
|
||||
insertItem(new SerializableItem_Int("y", _y));
|
||||
insertItem(new SerializableItem_Bool("face_down", _faceDown));
|
||||
|
||||
for (int i = 0; i < _cards.size(); ++i)
|
||||
itemList.append(_cards[i]);
|
||||
|
|
|
|||
|
|
@ -236,14 +236,13 @@ public:
|
|||
class Command_MoveCard : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), const QList<CardToMove *> &_cards = QList<CardToMove *>(), int _targetPlayerId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1, bool _faceDown = false);
|
||||
Command_MoveCard(int _gameId = -1, const QString &_startZone = QString(), const QList<CardToMove *> &_cards = QList<CardToMove *>(), int _targetPlayerId = -1, const QString &_targetZone = QString(), int _x = -1, int _y = -1);
|
||||
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }
|
||||
QList<CardToMove *> getCards() const { return typecastItemList<CardToMove *>(); }
|
||||
int getTargetPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("target_player_id"))->getData(); }
|
||||
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }
|
||||
int getX() const { return static_cast<SerializableItem_Int *>(itemMap.value("x"))->getData(); }
|
||||
int getY() const { return static_cast<SerializableItem_Int *>(itemMap.value("y"))->getData(); }
|
||||
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("face_down"))->getData(); }
|
||||
static SerializableItem *newItem() { return new Command_MoveCard; }
|
||||
int getItemId() const { return ItemId_Command_MoveCard; }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@
|
|||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
CardToMove::CardToMove(int _cardId, const QString &_pt, bool _tapped)
|
||||
CardToMove::CardToMove(int _cardId, bool _faceDown, const QString &_pt, bool _tapped)
|
||||
: SerializableItem_Map("card_to_move")
|
||||
{
|
||||
insertItem(new SerializableItem_Int("card_id", _cardId));
|
||||
insertItem(new SerializableItem_Bool("facedown", _faceDown));
|
||||
insertItem(new SerializableItem_String("pt", _pt));
|
||||
insertItem(new SerializableItem_Bool("tapped", _tapped));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@ enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
|||
|
||||
class CardToMove : public SerializableItem_Map {
|
||||
public:
|
||||
CardToMove(int _cardId = -1, const QString &_pt = QString(), bool _tapped = false);
|
||||
CardToMove(int _cardId = -1, bool _faceDown = false, const QString &_pt = QString(), bool _tapped = false);
|
||||
static SerializableItem *newItem() { return new CardToMove; }
|
||||
int getCardId() const { return static_cast<SerializableItem_Int *>(itemMap.value("card_id"))->getData(); }
|
||||
bool getFaceDown() const { return static_cast<SerializableItem_Bool *>(itemMap.value("facedown"))->getData(); }
|
||||
QString getPT() const { return static_cast<SerializableItem_String *>(itemMap.value("pt"))->getData(); }
|
||||
bool getTapped() const { return static_cast<SerializableItem_Bool *>(itemMap.value("tapped"))->getData(); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -278,12 +278,12 @@ ResponseCode Server_Player::undoDraw(CommandContainer *cont)
|
|||
|
||||
ResponseCode retVal;
|
||||
CardToMove *cardToMove = new CardToMove(lastDrawList.takeLast());
|
||||
retVal = moveCard(cont, zones.value("hand"), QList<CardToMove *>() << cardToMove, zones.value("deck"), 0, 0, false, false, true);
|
||||
retVal = moveCard(cont, zones.value("hand"), QList<CardToMove *>() << cardToMove, zones.value("deck"), 0, 0, false, true);
|
||||
delete cardToMove;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<CardToMove *> &_cards, int targetPlayerId, const QString &_targetZone, int x, int y, bool faceDown)
|
||||
ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_startZone, const QList<CardToMove *> &_cards, int targetPlayerId, const QString &_targetZone, int x, int y)
|
||||
{
|
||||
QMutexLocker locker(&game->gameMutex);
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, const QString &_sta
|
|||
if ((!startzone) || (!targetzone))
|
||||
return RespNameNotFound;
|
||||
|
||||
return moveCard(cont, startzone, _cards, targetzone, x, y, faceDown);
|
||||
return moveCard(cont, startzone, _cards, targetzone, x, y);
|
||||
}
|
||||
|
||||
class Server_Player::MoveCardCompareFunctor {
|
||||
|
|
@ -319,7 +319,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool faceDown, bool fixFreeSpaces, bool undoingDraw)
|
||||
ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces, bool undoingDraw)
|
||||
{
|
||||
QMutexLocker locker(&game->gameMutex);
|
||||
|
||||
|
|
@ -417,8 +417,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
|
|||
bool targetBeingLookedAt = (targetzone->getType() != HiddenZone) || (targetzone->getCardsBeingLookedAt() > newX) || (targetzone->getCardsBeingLookedAt() == -1);
|
||||
bool sourceBeingLookedAt = (startzone->getType() != HiddenZone) || (startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1);
|
||||
|
||||
bool targetHiddenToPlayer = faceDown || !targetBeingLookedAt;
|
||||
bool targetHiddenToOthers = faceDown || (targetzone->getType() != PublicZone);
|
||||
bool targetHiddenToPlayer = thisCardProperties->getFaceDown() || !targetBeingLookedAt;
|
||||
bool targetHiddenToOthers = thisCardProperties->getFaceDown() || (targetzone->getType() != PublicZone);
|
||||
bool sourceHiddenToPlayer = card->getFaceDown() || !sourceBeingLookedAt;
|
||||
bool sourceHiddenToOthers = card->getFaceDown() || (startzone->getType() != PublicZone);
|
||||
|
||||
|
|
@ -429,9 +429,9 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
|
|||
publicCardName = card->getName();
|
||||
|
||||
int oldCardId = card->getId();
|
||||
if (faceDown || (targetzone->getPlayer() != startzone->getPlayer()))
|
||||
if (thisCardProperties->getFaceDown() || (targetzone->getPlayer() != startzone->getPlayer()))
|
||||
card->setId(targetzone->getPlayer()->newCardId());
|
||||
card->setFaceDown(faceDown);
|
||||
card->setFaceDown(thisCardProperties->getFaceDown());
|
||||
|
||||
// The player does not get to see which card he moved if it moves between two parts of hidden zones which
|
||||
// are not being looked at.
|
||||
|
|
@ -445,8 +445,8 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
|
|||
int privatePosition = -1;
|
||||
if (startzone->getType() == HiddenZone)
|
||||
privatePosition = position;
|
||||
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), -1, undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, faceDown), game->getGameId(), undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
cont->enqueueGameEventPrivate(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->getFaceDown()), game->getGameId(), -1, undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
cont->enqueueGameEventOmniscient(new Event_MoveCard(getPlayerId(), privateOldCardId, privateCardName, startzone->getName(), privatePosition, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, privateNewCardId, thisCardProperties->getFaceDown()), game->getGameId(), undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
|
||||
// Other players do not get to see the start and/or target position of the card if the respective
|
||||
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
|
||||
|
|
@ -460,13 +460,13 @@ ResponseCode Server_Player::moveCard(CommandContainer *cont, Server_CardZone *st
|
|||
newX = -1;
|
||||
|
||||
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
|
||||
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), faceDown), game->getGameId(), undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), oldCardId, publicCardName, startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, card->getId(), thisCardProperties->getFaceDown()), game->getGameId(), undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
else
|
||||
cont->enqueueGameEventPublic(new Event_MoveCard(getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), newX, y, -1, false), game->getGameId(), undoingDraw ? static_cast<GameEventContext *>(new Context_UndoDraw) : static_cast<GameEventContext *>(new Context_MoveCard));
|
||||
|
||||
if (thisCardProperties->getTapped())
|
||||
setCardAttrHelper(cont, targetzone->getName(), card->getId(), "tapped", "1");
|
||||
if (!thisCardProperties->getPT().isEmpty() && !faceDown)
|
||||
if (!thisCardProperties->getPT().isEmpty() && !thisCardProperties->getFaceDown())
|
||||
setCardAttrHelper(cont, targetzone->getName(), card->getId(), "pt", thisCardProperties->getPT());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,8 +83,8 @@ public:
|
|||
|
||||
ResponseCode drawCards(CommandContainer *cont, int number);
|
||||
ResponseCode undoDraw(CommandContainer *cont);
|
||||
ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList<CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y, bool _faceDown);
|
||||
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool faceDown, bool fixFreeSpaces = true, bool undoingDraw = false);
|
||||
ResponseCode moveCard(CommandContainer *cont, const QString &_startZone, const QList<CardToMove *> &_cards, int _targetPlayer, const QString &_targetZone, int _x, int _y);
|
||||
ResponseCode moveCard(CommandContainer *cont, Server_CardZone *startzone, const QList<CardToMove *> &_cards, Server_CardZone *targetzone, int x, int y, bool fixFreeSpaces = true, bool undoingDraw = false);
|
||||
void unattachCard(CommandContainer *cont, Server_Card *card);
|
||||
ResponseCode setCardAttrHelper(CommandContainer *cont, const QString &zone, int cardId, const QString &attrName, const QString &attrValue);
|
||||
|
||||
|
|
|
|||
|
|
@ -762,7 +762,7 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, CommandC
|
|||
if (player->getConceded())
|
||||
return RespContextError;
|
||||
|
||||
return player->moveCard(cont, cmd->getStartZone(), cmd->getCards(), cmd->getTargetPlayerId(), cmd->getTargetZone(), cmd->getX(), cmd->getY(), cmd->getFaceDown());
|
||||
return player->moveCard(cont, cmd->getStartZone(), cmd->getCards(), cmd->getTargetPlayerId(), cmd->getTargetZone(), cmd->getX(), cmd->getY());
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdFlipCard(Command_FlipCard *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue