Commit 7417236c authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

preliminary AlwaysRevealTopCard support related to issue #31, server code...

preliminary AlwaysRevealTopCard support related to issue #31, server code cleanup (finally removed getGameState)
parent 75bac4a5
...@@ -25,6 +25,7 @@ protected: ...@@ -25,6 +25,7 @@ protected:
bool hasCardAttr; bool hasCardAttr;
bool isShufflable; bool isShufflable;
bool isView; bool isView;
bool alwaysRevealTopCard;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void addCardImpl(CardItem *card, int x, int y) = 0; virtual void addCardImpl(CardItem *card, int x, int y) = 0;
...@@ -61,6 +62,8 @@ public: ...@@ -61,6 +62,8 @@ public:
virtual void reorganizeCards() = 0; virtual void reorganizeCards() = 0;
virtual QPointF closestGridPoint(const QPointF &point); virtual QPointF closestGridPoint(const QPointF &point);
bool getIsView() const { return isView; } bool getIsView() const { return isView; }
bool getAlwaysRevealTopCard() const { return alwaysRevealTopCard; }
void setAlwaysRevealTopCard(bool _alwaysRevealTopCard) { alwaysRevealTopCard = _alwaysRevealTopCard; }
}; };
#endif #endif
...@@ -760,6 +760,17 @@ void MessageLogWidget::logRevealCards(Player *player, CardZone *zone, int cardId ...@@ -760,6 +760,17 @@ void MessageLogWidget::logRevealCards(Player *player, CardZone *zone, int cardId
} }
} }
void MessageLogWidget::logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal)
{
QString str;
if (reveal)
str = tr("%1 is now keeping the top card %2 revealed.");
else
str = tr("%1 is not revealing the top card %2 any longer.");
appendHtml(str.arg(sanitizeHtml(player->getName())).arg(zone->getTranslatedName(true, CaseGenitive)));
}
void MessageLogWidget::logSetActivePlayer(Player *player) void MessageLogWidget::logSetActivePlayer(Player *player)
{ {
soundEngine->notification(); soundEngine->notification();
...@@ -844,6 +855,7 @@ void MessageLogWidget::connectToPlayer(Player *player) ...@@ -844,6 +855,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
connect(player, SIGNAL(logDrawCards(Player *, int)), this, SLOT(logDrawCards(Player *, int))); connect(player, SIGNAL(logDrawCards(Player *, int)), this, SLOT(logDrawCards(Player *, int)));
connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString))); connect(player, SIGNAL(logUndoDraw(Player *, QString)), this, SLOT(logUndoDraw(Player *, QString)));
connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool)), this, SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool))); connect(player, SIGNAL(logRevealCards(Player *, CardZone *, int, QString, Player *, bool)), this, SLOT(logRevealCards(Player *, CardZone *, int, QString, Player *, bool)));
connect(player, SIGNAL(logAlwaysRevealTopCard(Player *, CardZone *, bool)), this, SLOT(logAlwaysRevealTopCard(Player *, CardZone *, bool)));
} }
MessageLogWidget::MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent) MessageLogWidget::MessageLogWidget(const QString &_ownName, bool _female, QWidget *parent)
......
...@@ -78,6 +78,7 @@ public slots: ...@@ -78,6 +78,7 @@ public slots:
void logDumpZone(Player *player, CardZone *zone, int numberCards); void logDumpZone(Player *player, CardZone *zone, int numberCards);
void logStopDumpZone(Player *player, CardZone *zone); void logStopDumpZone(Player *player, CardZone *zone);
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown); void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
void logSetActivePlayer(Player *player); void logSetActivePlayer(Player *player);
void logSetActivePhase(int phase); void logSetActivePhase(int phase);
void containerProcessingStarted(const GameEventContext &context); void containerProcessingStarted(const GameEventContext &context);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <QMenu> #include <QMenu>
#include <QDebug> #include <QDebug>
#include "pb/command_change_zone_properties.pb.h"
#include "pb/command_reveal_cards.pb.h" #include "pb/command_reveal_cards.pb.h"
#include "pb/command_shuffle.pb.h" #include "pb/command_shuffle.pb.h"
#include "pb/command_attach_card.pb.h" #include "pb/command_attach_card.pb.h"
...@@ -60,6 +61,7 @@ ...@@ -60,6 +61,7 @@
#include "pb/event_attach_card.pb.h" #include "pb/event_attach_card.pb.h"
#include "pb/event_draw_cards.pb.h" #include "pb/event_draw_cards.pb.h"
#include "pb/event_reveal_cards.pb.h" #include "pb/event_reveal_cards.pb.h"
#include "pb/event_change_zone_properties.pb.h"
PlayerArea::PlayerArea(QGraphicsItem *parentItem) PlayerArea::PlayerArea(QGraphicsItem *parentItem)
: QObject(), QGraphicsItem(parentItem) : QObject(), QGraphicsItem(parentItem)
...@@ -186,6 +188,9 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare ...@@ -186,6 +188,9 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary())); connect(aViewLibrary, SIGNAL(triggered()), this, SLOT(actViewLibrary()));
aViewTopCards = new QAction(this); aViewTopCards = new QAction(this);
connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards())); connect(aViewTopCards, SIGNAL(triggered()), this, SLOT(actViewTopCards()));
aAlwaysRevealTopCard = new QAction(this);
aAlwaysRevealTopCard->setCheckable(true);
connect(aAlwaysRevealTopCard, SIGNAL(triggered()), this, SLOT(actAlwaysRevealTopCard()));
} }
aViewGraveyard = new QAction(this); aViewGraveyard = new QAction(this);
...@@ -242,6 +247,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare ...@@ -242,6 +247,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, TabGame *_pare
libraryMenu->addSeparator(); libraryMenu->addSeparator();
playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString()));
playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString()));
libraryMenu->addAction(aAlwaysRevealTopCard);
libraryMenu->addSeparator(); libraryMenu->addSeparator();
libraryMenu->addAction(aMoveTopCardsToGrave); libraryMenu->addAction(aMoveTopCardsToGrave);
libraryMenu->addAction(aMoveTopCardsToExile); libraryMenu->addAction(aMoveTopCardsToExile);
...@@ -571,6 +577,7 @@ void Player::retranslateUi() ...@@ -571,6 +577,7 @@ void Player::retranslateUi()
aViewTopCards->setText(tr("View &top cards of library...")); aViewTopCards->setText(tr("View &top cards of library..."));
mRevealLibrary->setTitle(tr("Reveal &library to")); mRevealLibrary->setTitle(tr("Reveal &library to"));
mRevealTopCard->setTitle(tr("Reveal t&op card to")); mRevealTopCard->setTitle(tr("Reveal t&op card to"));
aAlwaysRevealTopCard->setText(tr("&Always reveal top card"));
aViewSideboard->setText(tr("&View sideboard")); aViewSideboard->setText(tr("&View sideboard"));
aDrawCard->setText(tr("&Draw card")); aDrawCard->setText(tr("&Draw card"));
aDrawCards->setText(tr("D&raw cards...")); aDrawCards->setText(tr("D&raw cards..."));
...@@ -731,6 +738,15 @@ void Player::actViewTopCards() ...@@ -731,6 +738,15 @@ void Player::actViewTopCards()
} }
} }
void Player::actAlwaysRevealTopCard()
{
Command_ChangeZoneProperties cmd;
cmd.set_zone_name("deck");
cmd.set_always_reveal_top_card(aAlwaysRevealTopCard->isChecked());
sendGameCommand(cmd);
}
void Player::actViewGraveyard() void Player::actViewGraveyard()
{ {
static_cast<GameScene *>(scene())->toggleZoneView(this, "grave", -1); static_cast<GameScene *>(scene())->toggleZoneView(this, "grave", -1);
...@@ -1291,6 +1307,18 @@ void Player::eventRevealCards(const Event_RevealCards &event) ...@@ -1291,6 +1307,18 @@ void Player::eventRevealCards(const Event_RevealCards &event)
} }
} }
void Player::eventChangeZoneProperties(const Event_ChangeZoneProperties &event)
{
CardZone *zone = zones.value(QString::fromStdString(event.zone_name()));
if (!zone)
return;
if (event.has_always_reveal_top_card()) {
zone->setAlwaysRevealTopCard(event.always_reveal_top_card());
emit logAlwaysRevealTopCard(this, zone, event.always_reveal_top_card());
}
}
void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context) void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context)
{ {
switch (type) { switch (type) {
...@@ -1313,6 +1341,7 @@ void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &ev ...@@ -1313,6 +1341,7 @@ void Player::processGameEvent(GameEvent::GameEventType type, const GameEvent &ev
case GameEvent::ATTACH_CARD: eventAttachCard(event.GetExtension(Event_AttachCard::ext)); break; case GameEvent::ATTACH_CARD: eventAttachCard(event.GetExtension(Event_AttachCard::ext)); break;
case GameEvent::DRAW_CARDS: eventDrawCards(event.GetExtension(Event_DrawCards::ext)); break; case GameEvent::DRAW_CARDS: eventDrawCards(event.GetExtension(Event_DrawCards::ext)); break;
case GameEvent::REVEAL_CARDS: eventRevealCards(event.GetExtension(Event_RevealCards::ext)); break; case GameEvent::REVEAL_CARDS: eventRevealCards(event.GetExtension(Event_RevealCards::ext)); break;
case GameEvent::CHANGE_ZONE_PROPERTIES: eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext)); break;
default: { default: {
qDebug() << "unhandled game event"; qDebug() << "unhandled game event";
} }
...@@ -1363,6 +1392,9 @@ void Player::processPlayerInfo(const ServerInfo_Player &info) ...@@ -1363,6 +1392,9 @@ void Player::processPlayerInfo(const ServerInfo_Player &info)
zone->addCard(card, false, cardInfo.x(), cardInfo.y()); zone->addCard(card, false, cardInfo.x(), cardInfo.y());
} }
} }
if (zoneInfo.has_always_reveal_top_card())
zone->setAlwaysRevealTopCard(zoneInfo.always_reveal_top_card());
zone->reorganizeCards(); zone->reorganizeCards();
} }
...@@ -1370,10 +1402,6 @@ void Player::processPlayerInfo(const ServerInfo_Player &info) ...@@ -1370,10 +1402,6 @@ void Player::processPlayerInfo(const ServerInfo_Player &info)
for (int i = 0; i < counterListSize; ++i) for (int i = 0; i < counterListSize; ++i)
addCounter(info.counter_list(i)); addCounter(info.counter_list(i));
const int arrowListSize = info.arrow_list_size();
for (int i = 0; i < arrowListSize; ++i)
addArrow(info.arrow_list(i));
setConceded(info.properties().conceded()); setConceded(info.properties().conceded());
} }
...@@ -1399,6 +1427,10 @@ void Player::processCardAttachment(const ServerInfo_Player &info) ...@@ -1399,6 +1427,10 @@ void Player::processCardAttachment(const ServerInfo_Player &info)
} }
} }
} }
const int arrowListSize = info.arrow_list_size();
for (int i = 0; i < arrowListSize; ++i)
addArrow(info.arrow_list(i));
} }
void Player::playCard(CardItem *c, bool faceDown, bool tapped) void Player::playCard(CardItem *c, bool faceDown, bool tapped)
......
...@@ -52,6 +52,7 @@ class Event_DestroyCard; ...@@ -52,6 +52,7 @@ class Event_DestroyCard;
class Event_AttachCard; class Event_AttachCard;
class Event_DrawCards; class Event_DrawCards;
class Event_RevealCards; class Event_RevealCards;
class Event_ChangeZoneProperties;
class PendingCommand; class PendingCommand;
class PlayerArea : public QObject, public QGraphicsItem { class PlayerArea : public QObject, public QGraphicsItem {
...@@ -98,6 +99,7 @@ signals: ...@@ -98,6 +99,7 @@ signals:
void logDumpZone(Player *player, CardZone *zone, int numberCards); void logDumpZone(Player *player, CardZone *zone, int numberCards);
void logStopDumpZone(Player *player, CardZone *zone); void logStopDumpZone(Player *player, CardZone *zone);
void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown); void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer, bool faceDown);
void logAlwaysRevealTopCard(Player *player, CardZone *zone, bool reveal);
void sizeChanged(); void sizeChanged();
void gameConceded(); void gameConceded();
...@@ -117,6 +119,7 @@ public slots: ...@@ -117,6 +119,7 @@ public slots:
void actViewLibrary(); void actViewLibrary();
void actViewTopCards(); void actViewTopCards();
void actAlwaysRevealTopCard();
void actViewGraveyard(); void actViewGraveyard();
void actViewRfg(); void actViewRfg();
void actViewSideboard(); void actViewSideboard();
...@@ -156,7 +159,7 @@ private: ...@@ -156,7 +159,7 @@ private:
QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg, QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg,
*aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg, *aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg,
*aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave, *aMoveRfgToTopLibrary, *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave,
*aViewLibrary, *aViewTopCards, *aMoveTopCardsToGrave, *aMoveTopCardsToExile, *aMoveTopCardToBottom, *aViewLibrary, *aViewTopCards, *aAlwaysRevealTopCard, *aMoveTopCardsToGrave, *aMoveTopCardsToExile, *aMoveTopCardToBottom,
*aViewGraveyard, *aViewRfg, *aViewSideboard, *aViewGraveyard, *aViewRfg, *aViewSideboard,
*aDrawCard, *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle, *aDrawCard, *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle,
*aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken,
...@@ -221,6 +224,7 @@ private: ...@@ -221,6 +224,7 @@ private:
void eventAttachCard(const Event_AttachCard &event); void eventAttachCard(const Event_AttachCard &event);
void eventDrawCards(const Event_DrawCards &event); void eventDrawCards(const Event_DrawCards &event);
void eventRevealCards(const Event_RevealCards &event); void eventRevealCards(const Event_RevealCards &event);
void eventChangeZoneProperties(const Event_ChangeZoneProperties &event);
public: public:
static const int counterAreaWidth = 55; static const int counterAreaWidth = 55;
enum CardMenuActionType { cmTap, cmUntap, cmDoesntUntap, cmFlip, cmPeek, cmClone, cmMoveToTopLibrary, cmMoveToBottomLibrary, cmMoveToGraveyard, cmMoveToExile }; enum CardMenuActionType { cmTap, cmUntap, cmDoesntUntap, cmFlip, cmPeek, cmClone, cmMoveToTopLibrary, cmMoveToBottomLibrary, cmMoveToGraveyard, cmMoveToExile };
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "userlist.h" #include "userlist.h"
#include "userinfobox.h" #include "userinfobox.h"
#include "abstractclient.h" #include "abstractclient.h"
#include <QDebug>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
...@@ -107,7 +106,6 @@ void TabUserLists::processUserLeftEvent(const Event_UserLeft &event) ...@@ -107,7 +106,6 @@ void TabUserLists::processUserLeftEvent(const Event_UserLeft &event)
void TabUserLists::buddyListReceived(const QList<ServerInfo_User> &_buddyList) void TabUserLists::buddyListReceived(const QList<ServerInfo_User> &_buddyList)
{ {
qDebug() << "BUDDY LIST" << _buddyList.size();
for (int i = 0; i < _buddyList.size(); ++i) for (int i = 0; i < _buddyList.size(); ++i)
buddyList->processUserInfo(_buddyList[i], false); buddyList->processUserInfo(_buddyList[i], false);
buddyList->sortItems(); buddyList->sortItems();
......
...@@ -9,8 +9,10 @@ SET(common_SOURCES ...@@ -9,8 +9,10 @@ SET(common_SOURCES
rng_sfmt.cpp rng_sfmt.cpp
server.cpp server.cpp
server_abstractuserinterface.cpp server_abstractuserinterface.cpp
server_arrow.cpp
server_card.cpp server_card.cpp
server_cardzone.cpp server_cardzone.cpp
server_counter.cpp
server_game.cpp server_game.cpp
server_player.cpp server_player.cpp
server_protocolhandler.cpp server_protocolhandler.cpp
......
...@@ -5,6 +5,7 @@ SET(PROTO_FILES ...@@ -5,6 +5,7 @@ SET(PROTO_FILES
card_attributes.proto card_attributes.proto
color.proto color.proto
command_attach_card.proto command_attach_card.proto
command_change_zone_properties.proto
command_concede.proto command_concede.proto
command_create_arrow.proto command_create_arrow.proto
command_create_counter.proto command_create_counter.proto
...@@ -56,6 +57,7 @@ SET(PROTO_FILES ...@@ -56,6 +57,7 @@ SET(PROTO_FILES
context_undo_draw.proto context_undo_draw.proto
event_add_to_list.proto event_add_to_list.proto
event_attach_card.proto event_attach_card.proto
event_change_zone_properties.proto
event_connection_closed.proto event_connection_closed.proto
event_create_arrow.proto event_create_arrow.proto
event_create_counter.proto event_create_counter.proto
......
import "game_commands.proto";
message Command_ChangeZoneProperties {
extend GameCommand {
optional Command_ChangeZoneProperties ext = 1031;
}
optional string zone_name = 1;
optional bool always_reveal_top_card = 10;
}
import "game_event.proto";
message Event_ChangeZoneProperties {
extend GameEvent {
optional Event_ChangeZoneProperties ext = 2020;
}
optional string zone_name = 1;
optional bool always_reveal_top_card = 10;
}
...@@ -31,6 +31,7 @@ message GameCommand { ...@@ -31,6 +31,7 @@ message GameCommand {
SET_SIDEBOARD_PLAN = 1028; SET_SIDEBOARD_PLAN = 1028;
DECK_SELECT = 1029; DECK_SELECT = 1029;
SET_SIDEBOARD_LOCK = 1030; SET_SIDEBOARD_LOCK = 1030;
CHANGE_ZONE_PROPERTIES = 1031;
} }
extensions 100 to max; extensions 100 to max;
} }
...@@ -28,6 +28,7 @@ message GameEvent { ...@@ -28,6 +28,7 @@ message GameEvent {
SET_ACTIVE_PHASE = 2017; SET_ACTIVE_PHASE = 2017;
DUMP_ZONE = 2018; DUMP_ZONE = 2018;
STOP_DUMP_ZONE = 2019; STOP_DUMP_ZONE = 2019;
CHANGE_ZONE_PROPERTIES = 2020;
} }
optional sint32 player_id = 1 [default = -1]; optional sint32 player_id = 1 [default = -1];
extensions 100 to max; extensions 100 to max;
......
...@@ -20,4 +20,5 @@ message ServerInfo_Zone { ...@@ -20,4 +20,5 @@ message ServerInfo_Zone {
optional bool with_coords = 3; optional bool with_coords = 3;
optional sint32 card_count = 4; optional sint32 card_count = 4;
repeated ServerInfo_Card card_list = 5; repeated ServerInfo_Card card_list = 5;
optional bool always_reveal_top_card = 10;
} }
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
***************************************************************************/ ***************************************************************************/
#include "server.h" #include "server.h"
#include "server_game.h" #include "server_game.h"
#include "server_player.h"
#include "server_counter.h" #include "server_counter.h"
#include "server_room.h" #include "server_room.h"
#include "server_protocolhandler.h" #include "server_protocolhandler.h"
...@@ -358,7 +359,7 @@ void Server::externalGameCommandContainerReceived(const CommandContainer &cont, ...@@ -358,7 +359,7 @@ void Server::externalGameCommandContainerReceived(const CommandContainer &cont,
} }
QMutexLocker gameLocker(&game->gameMutex); QMutexLocker gameLocker(&game->gameMutex);
Server_Player *player = game->getPlayer(playerId); Server_Player *player = game->getPlayers().value(playerId);
if (!player) { if (!player) {
qDebug() << "externalGameCommandContainerReceived: player id=" << playerId << "not found"; qDebug() << "externalGameCommandContainerReceived: player id=" << playerId << "not found";
throw Response::RespNotInRoom; throw Response::RespNotInRoom;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "server.h" #include "server.h"
#include "server_room.h" #include "server_room.h"
#include "server_game.h" #include "server_game.h"
#include "server_player.h"
#include "pb/event_game_joined.pb.h" #include "pb/event_game_joined.pb.h"
#include "pb/event_game_state_changed.pb.h" #include "pb/event_game_state_changed.pb.h"
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
......
#include "server_arrow.h"
#include "server_player.h"
#include "server_card.h"
#include "server_cardzone.h"
#include "pb/serverinfo_arrow.pb.h"
Server_Arrow::Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor)
: id(_id),
startCard(_startCard),
targetItem(_targetItem),
arrowColor(_arrowColor)
{
}
void Server_Arrow::getInfo(ServerInfo_Arrow *info)
{
info->set_id(id);
info->set_start_player_id(startCard->getZone()->getPlayer()->getPlayerId());
info->set_start_zone(startCard->getZone()->getName().toStdString());
info->set_start_card_id(startCard->getId());
info->mutable_arrow_color()->CopyFrom(arrowColor);
Server_Card *targetCard = qobject_cast<Server_Card *>(targetItem);
if (targetCard) {
info->set_target_player_id(targetCard->getZone()->getPlayer()->getPlayerId());
info->set_target_zone(targetCard->getZone()->getName().toStdString());
info->set_target_card_id(targetCard->getId());
} else
info->set_target_player_id(static_cast<Server_Player *>(targetItem)->getPlayerId());
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
class Server_Card; class Server_Card;
class Server_ArrowTarget; class Server_ArrowTarget;
class ServerInfo_Arrow;
class Server_Arrow { class Server_Arrow {
private: private:
...@@ -13,12 +14,13 @@ private: ...@@ -13,12 +14,13 @@ private:
Server_ArrowTarget *targetItem; Server_ArrowTarget *targetItem;
color arrowColor; color arrowColor;
public: public:
Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor) Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const color &_arrowColor);
: id(_id), startCard(_startCard), targetItem(_targetItem), arrowColor(_arrowColor) { }
int getId() const { return id; } int getId() const { return id; }
Server_Card *getStartCard() const { return startCard; } Server_Card *getStartCard() const { return startCard; }
Server_ArrowTarget *getTargetItem() const { return targetItem; } Server_ArrowTarget *getTargetItem() const { return targetItem; }
const color &getColor() const { return arrowColor; } const color &getColor() const { return arrowColor; }
void getInfo(ServerInfo_Arrow *info);
}; };
#endif #endif
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "server_card.h" #include "server_card.h"
#include "server_cardzone.h"
#include "server_player.h"
#include "pb/serverinfo_card.pb.h"
Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone) Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone)
: zone(_zone), 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) : zone(_zone), 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)
...@@ -115,3 +118,43 @@ void Server_Card::setParentCard(Server_Card *_parentCard) ...@@ -115,3 +118,43 @@ void Server_Card::setParentCard(Server_Card *_parentCard)
if (parentCard) if (parentCard)
parentCard->addAttachedCard(this); parentCard->addAttachedCard(this);
} }
void Server_Card::getInfo(ServerInfo_Card *info)
{
QString displayedName = facedown ? QString() : name;
info->set_id(id);
info->set_name(displayedName.toStdString());
info->set_x(coord_x);
info->set_y(coord_y);
if (facedown)
info->set_face_down(true);
info->set_tapped(tapped);
if (attacking)
info->set_attacking(true);
if (!color.isEmpty())
info->set_color(color.toStdString());
const QString ptStr = getPT();
if (!ptStr.isEmpty())
info->set_pt(ptStr.toStdString());
if (!annotation.isEmpty())
info->set_annotation(annotation.toStdString());
if (destroyOnZoneChange)
info->set_destroy_on_zone_change(true);
if (doesntUntap)
info->set_doesnt_untap(true);
QMapIterator<int, int> cardCounterIterator(counters);
while (cardCounterIterator.hasNext()) {
cardCounterIterator.next();
ServerInfo_CardCounter *counterInfo = info->add_counter_list();
counterInfo->set_id(cardCounterIterator.key());
counterInfo->set_value(cardCounterIterator.value());
}
if (parentCard) {
info->set_attach_player_id(parentCard->getZone()->getPlayer()->getPlayerId());
info->set_attach_zone(parentCard->getZone()->getName().toStdString());
info->set_attach_card_id(parentCard->getId());
}
}
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QMap> #include <QMap>
class Server_CardZone; class Server_CardZone;
class ServerInfo_Card;
class Server_Card : public Server_ArrowTarget { class Server_Card : public Server_ArrowTarget {
Q_OBJECT Q_OBJECT
...@@ -88,6 +89,8 @@ public: ...@@ -88,6 +89,8 @@ public:
void resetState(); void resetState();
QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards); QString setAttribute(CardAttribute attribute, const QString &avalue, bool allCards);
void getInfo(ServerInfo_Card *info);
}; };
#endif #endif
...@@ -23,11 +23,15 @@ ...@@ -23,11 +23,15 @@
#include "rng_abstract.h" #include "rng_abstract.h"
#include <QSet> #include <QSet>
#include <QDebug> #include <QDebug>
#include "server_game.h"
#include "pb/command_move_card.pb.h" #include "pb/command_move_card.pb.h"
Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type) Server_CardZone::Server_CardZone(Server_Player *_player, const QString &_name, bool _has_coords, ServerInfo_Zone::ZoneType _type)
: player(_player), name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(0) : player(_player),
name(_name),
has_coords(_has_coords),
type(_type),
cardsBeingLookedAt(0),
alwaysRevealTopCard(false)
{ {
} }
...@@ -215,3 +219,20 @@ void Server_CardZone::addWritePermission(int playerId) ...@@ -215,3 +219,20 @@ void Server_CardZone::addWritePermission(int playerId)
{ {
playersWithWritePermission.insert(playerId); playersWithWritePermission.insert(playerId);
} }
void Server_CardZone::getInfo(ServerInfo_Zone *info, Server_Player *playerWhosAsking, bool omniscient)
{
info->set_name(name.toStdString());
info->set_type(type);
info->set_with_coords(has_coords);
info->set_card_count(cards.size());
info->set_always_reveal_top_card(alwaysRevealTopCard);
if (
(((playerWhosAsking == player) || omniscient) && (type != ServerInfo_Zone::HiddenZone))
|| ((playerWhosAsking != player) && (type == ServerInfo_Zone::PublicZone))
) {
QListIterator<Server_Card *> cardIterator(cards);
while (cardIterator.hasNext())
cardIterator.next()->getInfo(info->add_card_list());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment