move_card improvement, unfinished
This commit is contained in:
parent
565384d083
commit
536c77f760
18 changed files with 129 additions and 55 deletions
|
@ -350,3 +350,8 @@ PendingCommand *Client::dumpZone(int player, const QString &zone, int numberCard
|
||||||
{
|
{
|
||||||
return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards));
|
return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PendingCommand *Client::stopDumpZone(int player, const QString &zone)
|
||||||
|
{
|
||||||
|
return cmd(QString("stop_dump_zone|%1|%2").arg(player).arg(zone));
|
||||||
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ public:
|
||||||
PendingCommand *setActivePlayer(int player);
|
PendingCommand *setActivePlayer(int player);
|
||||||
PendingCommand *setActivePhase(int phase);
|
PendingCommand *setActivePhase(int phase);
|
||||||
PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
|
PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
|
||||||
|
PendingCommand *stopDumpZone(int player, const QString &zone);
|
||||||
public slots:
|
public slots:
|
||||||
void submitDeck(const QStringList &deck);
|
void submitDeck(const QStringList &deck);
|
||||||
};
|
};
|
||||||
|
|
|
@ -137,7 +137,7 @@ Player *Game::addPlayer(int playerId, const QString &playerName, QPointF base, b
|
||||||
Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene, this);
|
Player *newPlayer = new Player(playerName, playerId, base, local, db, client, scene, this);
|
||||||
|
|
||||||
connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint)));
|
connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint)));
|
||||||
connect(newPlayer, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SIGNAL(logMoveCard(Player *, QString, QString, QString)));
|
connect(newPlayer, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int)), this, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int)));
|
||||||
connect(newPlayer, SIGNAL(logCreateToken(Player *, QString)), this, SIGNAL(logCreateToken(Player *, QString)));
|
connect(newPlayer, SIGNAL(logCreateToken(Player *, QString)), this, SIGNAL(logCreateToken(Player *, QString)));
|
||||||
connect(newPlayer, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SIGNAL(logSetCardCounters(Player *, QString, int, int)));
|
connect(newPlayer, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SIGNAL(logSetCardCounters(Player *, QString, int, int)));
|
||||||
connect(newPlayer, SIGNAL(logSetTapped(Player *, QString, bool)), this, SIGNAL(logSetTapped(Player *, QString, bool)));
|
connect(newPlayer, SIGNAL(logSetTapped(Player *, QString, bool)), this, SIGNAL(logSetTapped(Player *, QString, bool)));
|
||||||
|
@ -245,6 +245,11 @@ void Game::gameEvent(const ServerEventData &msg)
|
||||||
emit logDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName(), data[2].toInt());
|
emit logDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName(), data[2].toInt());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case eventStopDumpZone: {
|
||||||
|
QStringList data = msg.getEventData();
|
||||||
|
emit logStopDumpZone(p, data[1], players.findPlayer(data[0].toInt())->getName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case eventMoveCard: {
|
case eventMoveCard: {
|
||||||
if (msg.getPlayerId() == localPlayer->getId())
|
if (msg.getPlayerId() == localPlayer->getId())
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -70,13 +70,14 @@ signals:
|
||||||
void logShuffle(Player *player);
|
void logShuffle(Player *player);
|
||||||
void logRollDice(Player *player, int sides, int roll);
|
void logRollDice(Player *player, int sides, int roll);
|
||||||
void logDraw(Player *player, int number);
|
void logDraw(Player *player, int number);
|
||||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX);
|
||||||
void logCreateToken(Player *player, QString cardName);
|
void logCreateToken(Player *player, QString cardName);
|
||||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||||
|
void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner);
|
||||||
public:
|
public:
|
||||||
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
|
Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0);
|
||||||
~Game();
|
~Game();
|
||||||
|
|
|
@ -94,7 +94,7 @@ void MessageLogWidget::logDraw(Player *player, int number)
|
||||||
append(tr("%1 draws %2 cards").arg(sanitizeHtml(player->getName())).arg(number));
|
append(tr("%1 draws %2 cards").arg(sanitizeHtml(player->getName())).arg(number));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone)
|
void MessageLogWidget::logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX)
|
||||||
{
|
{
|
||||||
if ((startZone == "table") && (targetZone == "table"))
|
if ((startZone == "table") && (targetZone == "table"))
|
||||||
return;
|
return;
|
||||||
|
@ -176,6 +176,10 @@ void MessageLogWidget::logDumpZone(Player *player, QString zoneName, QString zon
|
||||||
append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
append(tr("%1 is looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessageLogWidget::logStopDumpZone(Player *player, QString zoneName, QString zoneOwner)
|
||||||
|
{
|
||||||
|
append(tr("%1 stops looking at %2's %3").arg(sanitizeHtml(player->getName())).arg(zoneOwner).arg(zoneName));
|
||||||
|
}
|
||||||
|
|
||||||
void MessageLogWidget::connectToGame(Game *game)
|
void MessageLogWidget::connectToGame(Game *game)
|
||||||
{
|
{
|
||||||
|
@ -188,13 +192,14 @@ void MessageLogWidget::connectToGame(Game *game)
|
||||||
connect(game, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
connect(game, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
||||||
connect(game, SIGNAL(logRollDice(Player *, int, int)), this, SLOT(logRollDice(Player *, int, int)));
|
connect(game, SIGNAL(logRollDice(Player *, int, int)), this, SLOT(logRollDice(Player *, int, int)));
|
||||||
connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(logDraw(Player *, int)));
|
connect(game, SIGNAL(logDraw(Player *, int)), this, SLOT(logDraw(Player *, int)));
|
||||||
connect(game, SIGNAL(logMoveCard(Player *, QString, QString, QString)), this, SLOT(logMoveCard(Player *, QString, QString, QString)));
|
connect(game, SIGNAL(logMoveCard(Player *, QString, QString, int, QString, int)), this, SLOT(logMoveCard(Player *, QString, QString, int, QString, int)));
|
||||||
connect(game, SIGNAL(logCreateToken(Player *, QString)), this, SLOT(logCreateToken(Player *, QString)));
|
connect(game, SIGNAL(logCreateToken(Player *, QString)), this, SLOT(logCreateToken(Player *, QString)));
|
||||||
connect(game, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SLOT(logSetCardCounters(Player *, QString, int, int)));
|
connect(game, SIGNAL(logSetCardCounters(Player *, QString, int, int)), this, SLOT(logSetCardCounters(Player *, QString, int, int)));
|
||||||
connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool)));
|
connect(game, SIGNAL(logSetTapped(Player *, QString, bool)), this, SLOT(logSetTapped(Player *, QString, bool)));
|
||||||
connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int)));
|
connect(game, SIGNAL(logSetCounter(Player *, QString, int, int)), this, SLOT(logSetCounter(Player *, QString, int, int)));
|
||||||
connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool)));
|
connect(game, SIGNAL(logSetDoesntUntap(Player *, QString, bool)), this, SLOT(logSetDoesntUntap(Player *, QString, bool)));
|
||||||
connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int)));
|
connect(game, SIGNAL(logDumpZone(Player *, QString, QString, int)), this, SLOT(logDumpZone(Player *, QString, QString, int)));
|
||||||
|
connect(game, SIGNAL(logStopDumpZone(Player *, QString, QString)), this, SLOT(logStopDumpZone(Player *, QString, QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
MessageLogWidget::MessageLogWidget(QWidget *parent)
|
||||||
|
|
|
@ -28,13 +28,14 @@ private slots:
|
||||||
void logShuffle(Player *player);
|
void logShuffle(Player *player);
|
||||||
void logRollDice(Player *player, int sides, int roll);
|
void logRollDice(Player *player, int sides, int roll);
|
||||||
void logDraw(Player *player, int number);
|
void logDraw(Player *player, int number);
|
||||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX);
|
||||||
void logCreateToken(Player *player, QString cardName);
|
void logCreateToken(Player *player, QString cardName);
|
||||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||||
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
void logSetCounter(Player *player, QString counterName, int value, int oldValue);
|
||||||
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap);
|
||||||
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
void logDumpZone(Player *player, QString zoneName, QString zoneOwner, int numberCards);
|
||||||
|
void logStopDumpZone(Player *player, QString zoneName, QString zoneOwner);
|
||||||
public:
|
public:
|
||||||
void connectToGame(Game *game);
|
void connectToGame(Game *game);
|
||||||
MessageLogWidget(QWidget *parent = 0);
|
MessageLogWidget(QWidget *parent = 0);
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include "carddragitem.h"
|
#include "carddragitem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
|
|
||||||
PileZone::PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent)
|
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
||||||
: CardZone(_p, _name, false, false, _contentsKnown, parent)
|
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
||||||
{
|
{
|
||||||
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
class PileZone : public CardZone {
|
class PileZone : public CardZone {
|
||||||
public:
|
public:
|
||||||
PileZone(Player *_p, const QString &_name, bool _contentsKnown, QGraphicsItem *parent = 0);
|
PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
|
|
|
@ -220,6 +220,12 @@ void Player::gameEvent(const ServerEventData &event)
|
||||||
bool facedown = data[7].toInt();
|
bool facedown = data[7].toInt();
|
||||||
// XXX Mehr Fehlerbehandlung
|
// XXX Mehr Fehlerbehandlung
|
||||||
|
|
||||||
|
int logPosition = position;
|
||||||
|
int logX = x;
|
||||||
|
if (position == -1)
|
||||||
|
position = 0;
|
||||||
|
if (x == -1)
|
||||||
|
x = 0;
|
||||||
CardItem *card = startZone->takeCard(position, cardId, cardName);
|
CardItem *card = startZone->takeCard(position, cardId, cardName);
|
||||||
if (!card) // XXX
|
if (!card) // XXX
|
||||||
qDebug("moveCard: card not found");
|
qDebug("moveCard: card not found");
|
||||||
|
@ -230,7 +236,7 @@ void Player::gameEvent(const ServerEventData &event)
|
||||||
|
|
||||||
// The log event has to be sent before the card is added to the target zone
|
// The log event has to be sent before the card is added to the target zone
|
||||||
// because the addCard function can modify the card object.
|
// because the addCard function can modify the card object.
|
||||||
emit logMoveCard(this, card->getName(), startZone->getName(), targetZone->getName());
|
emit logMoveCard(this, card->getName(), startZone->getName(), logPosition, targetZone->getName(), logX);
|
||||||
|
|
||||||
targetZone->addCard(card, true, x, y);
|
targetZone->addCard(card, true, x, y);
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ signals:
|
||||||
void toggleZoneView(Player *player, QString zoneName, int number);
|
void toggleZoneView(Player *player, QString zoneName, int number);
|
||||||
void sigShowCardMenu(QPoint p);
|
void sigShowCardMenu(QPoint p);
|
||||||
// Log events
|
// Log events
|
||||||
void logMoveCard(Player *player, QString cardName, QString startZone, QString targetZone);
|
void logMoveCard(Player *player, QString cardName, QString startZone, int oldX, QString targetZone, int newX);
|
||||||
void logCreateToken(Player *player, QString cardName);
|
void logCreateToken(Player *player, QString cardName);
|
||||||
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
void logSetCardCounters(Player *player, QString cardName, int value, int oldValue);
|
||||||
void logSetTapped(Player *player, QString cardName, bool tapped);
|
void logSetTapped(Player *player, QString cardName, bool tapped);
|
||||||
|
|
|
@ -13,18 +13,18 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
||||||
|
|
||||||
QPointF base = QPointF(55, 50);
|
QPointF base = QPointF(55, 50);
|
||||||
|
|
||||||
PileZone *deck = new PileZone(_player, "deck", false, this);
|
PileZone *deck = new PileZone(_player, "deck", true, false, this);
|
||||||
deck->setPos(base);
|
deck->setPos(base);
|
||||||
|
|
||||||
qreal h = deck->boundingRect().height() + 20;
|
qreal h = deck->boundingRect().height() + 20;
|
||||||
|
|
||||||
PileZone *grave = new PileZone(_player, "grave", true, this);
|
PileZone *grave = new PileZone(_player, "grave", false, true, this);
|
||||||
grave->setPos(base + QPointF(0, h));
|
grave->setPos(base + QPointF(0, h));
|
||||||
|
|
||||||
PileZone *rfg = new PileZone(_player, "rfg", true, this);
|
PileZone *rfg = new PileZone(_player, "rfg", false, true, this);
|
||||||
rfg->setPos(base + QPointF(0, 2 * h));
|
rfg->setPos(base + QPointF(0, 2 * h));
|
||||||
|
|
||||||
PileZone *sb = new PileZone(_player, "sb", true, this);
|
PileZone *sb = new PileZone(_player, "sb", false, true, this);
|
||||||
sb->setVisible(false);
|
sb->setVisible(false);
|
||||||
|
|
||||||
base = QPointF(deck->boundingRect().width() + 60, 0);
|
base = QPointF(deck->boundingRect().width() + 60, 0);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// Message structure for server events:
|
// Message structure for server events:
|
||||||
// {"private","public"}|PlayerId|PlayerName|EventType|EventData
|
// {"private","public"}|PlayerId|PlayerName|EventType|EventData
|
||||||
|
|
||||||
const int event_count = 20;
|
const int event_count = 21;
|
||||||
const event_string event_strings[event_count] = {
|
const event_string event_strings[event_count] = {
|
||||||
{eventPlayerId, "player_id"},
|
{eventPlayerId, "player_id"},
|
||||||
{eventSay, "say"},
|
{eventSay, "say"},
|
||||||
|
@ -24,7 +24,8 @@ const event_string event_strings[event_count] = {
|
||||||
{eventDelCounter, "del_counter"},
|
{eventDelCounter, "del_counter"},
|
||||||
{eventSetActivePlayer, "set_active_player"},
|
{eventSetActivePlayer, "set_active_player"},
|
||||||
{eventSetActivePhase, "set_active_phase"},
|
{eventSetActivePhase, "set_active_phase"},
|
||||||
{eventDumpZone, "dump_zone"}
|
{eventDumpZone, "dump_zone"},
|
||||||
|
{eventStopDumpZone, "stop_dump_zone"}
|
||||||
};
|
};
|
||||||
|
|
||||||
ServerEventData::ServerEventData(const QString &line)
|
ServerEventData::ServerEventData(const QString &line)
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
enum ServerEventType {
|
enum ServerEventType {
|
||||||
eventInvalid,
|
eventInvalid,
|
||||||
eventPlayerId,
|
eventPlayerId,
|
||||||
|
@ -25,7 +24,8 @@ enum ServerEventType {
|
||||||
eventDelCounter,
|
eventDelCounter,
|
||||||
eventSetActivePlayer,
|
eventSetActivePlayer,
|
||||||
eventSetActivePhase,
|
eventSetActivePhase,
|
||||||
eventDumpZone
|
eventDumpZone,
|
||||||
|
eventStopDumpZone
|
||||||
};
|
};
|
||||||
|
|
||||||
struct event_string {
|
struct event_string {
|
||||||
|
|
|
@ -14,6 +14,7 @@ ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_or
|
||||||
|
|
||||||
qreal y = 10;
|
qreal y = 10;
|
||||||
if (_origZone->getIsShufflable() && (numberCards == 0)) {
|
if (_origZone->getIsShufflable() && (numberCards == 0)) {
|
||||||
|
qDebug(QString("ZoneViewWidget: bla!").toLatin1());
|
||||||
shuffleCheckBox = new QCheckBox("shuffle when closing");
|
shuffleCheckBox = new QCheckBox("shuffle when closing");
|
||||||
shuffleCheckBox->setChecked(true);
|
shuffleCheckBox->setChecked(true);
|
||||||
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget(this);
|
QGraphicsProxyWidget *shuffleProxy = new QGraphicsProxyWidget(this);
|
||||||
|
@ -65,6 +66,7 @@ void ZoneViewWidget::zoneDumpReceived(int commandId, QList<ServerZoneCard *> car
|
||||||
|
|
||||||
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
|
player->client->stopDumpZone(player->getId(), zone->getName());
|
||||||
if (shuffleCheckBox)
|
if (shuffleCheckBox)
|
||||||
if (shuffleCheckBox->isChecked())
|
if (shuffleCheckBox->isChecked())
|
||||||
player->client->shuffle();
|
player->client->shuffle();
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "abstractrng.h"
|
#include "abstractrng.h"
|
||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
|
||||||
PlayerZone::PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access)
|
PlayerZone::PlayerZone(const QString &_name, bool _has_coords, ZoneType _type)
|
||||||
: name(_name), has_coords(_has_coords), is_public(_is_public), is_private(_is_private), id_access(_id_access)
|
: name(_name), has_coords(_has_coords), type(_type), cardsBeingLookedAt(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ void PlayerZone::shuffle(AbstractRNG *rnd)
|
||||||
|
|
||||||
Card *PlayerZone::getCard(int id, bool remove, int *position)
|
Card *PlayerZone::getCard(int id, bool remove, int *position)
|
||||||
{
|
{
|
||||||
if (hasIdAccess()) {
|
if (type != HiddenZone) {
|
||||||
QListIterator<Card *> CardIterator(cards);
|
QListIterator<Card *> CardIterator(cards);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (CardIterator.hasNext()) {
|
while (CardIterator.hasNext()) {
|
||||||
|
|
|
@ -27,28 +27,32 @@ class Card;
|
||||||
class AbstractRNG;
|
class AbstractRNG;
|
||||||
|
|
||||||
class PlayerZone {
|
class PlayerZone {
|
||||||
|
public:
|
||||||
|
// PrivateZone: Contents of the zone are always visible to the owner,
|
||||||
|
// but not to anyone else.
|
||||||
|
// PublicZone: Contents of the zone are always visible to anyone.
|
||||||
|
// HiddenZone: Contents of the zone are never visible to anyone.
|
||||||
|
// However, the owner of the zone can issue a dump_zone command,
|
||||||
|
// setting beingLookedAt to true.
|
||||||
|
// Cards in a zone with the type HiddenZone are referenced by their
|
||||||
|
// list index, whereas cards in any other zone are referenced by their ids.
|
||||||
|
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
bool has_coords;
|
bool has_coords;
|
||||||
bool is_public; // Contents of the zone are always visible to anyone
|
ZoneType type;
|
||||||
bool is_private; // Contents of the zone are always visible to the owner
|
int cardsBeingLookedAt;
|
||||||
bool id_access; // getCard() finds by id, not by list index
|
|
||||||
// Example: When moving a card from the library to the table,
|
|
||||||
// the card has to be found by list index because the client
|
|
||||||
// does not know the id. But when moving a card from the hand
|
|
||||||
// to the table, the card can be found by id because the client
|
|
||||||
// knows the id and the hand does not need to have a specific order.
|
|
||||||
public:
|
public:
|
||||||
PlayerZone(QString _name, bool _has_coords, bool _is_public, bool _is_private, bool _id_access);
|
PlayerZone(const QString &_name, bool _has_coords, ZoneType _type);
|
||||||
~PlayerZone();
|
~PlayerZone();
|
||||||
|
|
||||||
Card *getCard(int id, bool remove, int *position = NULL);
|
Card *getCard(int id, bool remove, int *position = NULL);
|
||||||
|
|
||||||
bool isPublic() { return is_public; }
|
int getCardsBeingLookedAt() const { return cardsBeingLookedAt; }
|
||||||
bool isPrivate() { return is_private; }
|
void setCardsBeingLookedAt(bool _cardsBeingLookedAt) { cardsBeingLookedAt = _cardsBeingLookedAt; }
|
||||||
bool hasCoords() { return has_coords; }
|
bool hasCoords() const { return has_coords; }
|
||||||
bool hasIdAccess() { return id_access; }
|
ZoneType getType() const { return type; }
|
||||||
QString getName() { return name; }
|
QString getName() const { return name; }
|
||||||
|
|
||||||
QList<Card *> cards;
|
QList<Card *> cards;
|
||||||
void insertCard(Card *card, int x, int y);
|
void insertCard(Card *card, int x, int y);
|
||||||
|
|
|
@ -85,14 +85,14 @@ void ServerSocket::setupZones()
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
// Create zones
|
// Create zones
|
||||||
PlayerZone *deck = new PlayerZone("deck", false, false, false, false);
|
PlayerZone *deck = new PlayerZone("deck", false, PlayerZone::HiddenZone);
|
||||||
zones << deck;
|
zones << deck;
|
||||||
PlayerZone *sb = new PlayerZone("sb", false, false, false, false);
|
PlayerZone *sb = new PlayerZone("sb", false, PlayerZone::HiddenZone);
|
||||||
zones << sb;
|
zones << sb;
|
||||||
zones << new PlayerZone("table", true, true, false, true);
|
zones << new PlayerZone("table", true, PlayerZone::PublicZone);
|
||||||
zones << new PlayerZone("hand", false, false, true, true);
|
zones << new PlayerZone("hand", false, PlayerZone::PrivateZone);
|
||||||
zones << new PlayerZone("grave", false, true, false, true);
|
zones << new PlayerZone("grave", false, PlayerZone::PublicZone);
|
||||||
zones << new PlayerZone("rfg", false, true, false, true);
|
zones << new PlayerZone("rfg", false, PlayerZone::PublicZone);
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -209,6 +209,8 @@ const ServerSocket::CommandProperties ServerSocket::commandList[ServerSocket::nu
|
||||||
{"dump_zone", true, true, true, QList<QVariant::Type>() << QVariant::Int
|
{"dump_zone", true, true, true, QList<QVariant::Type>() << QVariant::Int
|
||||||
<< QVariant::String
|
<< QVariant::String
|
||||||
<< QVariant::Int, &ServerSocket::cmdDumpZone},
|
<< QVariant::Int, &ServerSocket::cmdDumpZone},
|
||||||
|
{"stop_dump_zone", true, true, true, QList<QVariant::Type>() << QVariant::Int
|
||||||
|
<< QVariant::String, &ServerSocket::cmdStopDumpZone},
|
||||||
{"roll_dice", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdRollDice},
|
{"roll_dice", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdRollDice},
|
||||||
{"set_active_player", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePlayer},
|
{"set_active_player", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePlayer},
|
||||||
{"set_active_phase", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePhase}
|
{"set_active_phase", true, true, true, QList<QVariant::Type>() << QVariant::Int, &ServerSocket::cmdSetActivePhase}
|
||||||
|
@ -364,15 +366,28 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList<QVariant> ¶m
|
||||||
if (facedown)
|
if (facedown)
|
||||||
card->setId(newCardId());
|
card->setId(newCardId());
|
||||||
if ((!facedown && !card->getFaceDown())
|
if ((!facedown && !card->getFaceDown())
|
||||||
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic()))
|
|| (card->getFaceDown() && !facedown && (startzone->getType() == PlayerZone::PublicZone) && (targetzone->getType() == PlayerZone::PublicZone)))
|
||||||
publicCardName = card->getName();
|
publicCardName = card->getName();
|
||||||
if ((!facedown && !card->getFaceDown())
|
if ((!facedown && !card->getFaceDown())
|
||||||
|| (card->getFaceDown() && !facedown && startzone->isPublic() && targetzone->isPublic())
|
|| (card->getFaceDown() && !facedown && (startzone->getType() == PlayerZone::PublicZone) && (targetzone->getType() == PlayerZone::PublicZone))
|
||||||
|| (!facedown && targetzone->isPrivate()))
|
|| (!facedown && (targetzone->getType() != PlayerZone::PublicZone)))
|
||||||
privateCardName = card->getName();
|
privateCardName = card->getName();
|
||||||
|
|
||||||
card->setFaceDown(facedown);
|
card->setFaceDown(facedown);
|
||||||
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
|
|
||||||
|
// 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.
|
||||||
|
QString privateCardId = QString::number(card->getId());
|
||||||
|
if ((targetzone->getType() == PlayerZone::HiddenZone)
|
||||||
|
&& (startzone->getType() == PlayerZone::HiddenZone)
|
||||||
|
&& (startzone->getCardsBeingLookedAt() <= position)
|
||||||
|
&& (startzone->getCardsBeingLookedAt() != 0)
|
||||||
|
&& (targetzone->getCardsBeingLookedAt() <= x)
|
||||||
|
&& (targetzone->getCardsBeingLookedAt() != 0)) {
|
||||||
|
privateCardId = QString();
|
||||||
|
privateCardName = QString();
|
||||||
|
}
|
||||||
|
msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId)
|
||||||
.arg(privateCardName)
|
.arg(privateCardName)
|
||||||
.arg(startzone->getName())
|
.arg(startzone->getName())
|
||||||
.arg(position)
|
.arg(position)
|
||||||
|
@ -380,7 +395,16 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList<QVariant> ¶m
|
||||||
.arg(x)
|
.arg(x)
|
||||||
.arg(y)
|
.arg(y)
|
||||||
.arg(facedown ? 1 : 0));
|
.arg(facedown ? 1 : 0));
|
||||||
if ((startzone->isPublic()) || (targetzone->isPublic()))
|
|
||||||
|
// 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,
|
||||||
|
// all cards are equal.
|
||||||
|
if ((startzone->getType() == PlayerZone::HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == 0)))
|
||||||
|
position = -1;
|
||||||
|
if ((targetzone->getType() == PlayerZone::HiddenZone) && ((targetzone->getCardsBeingLookedAt() > position) || (targetzone->getCardsBeingLookedAt() == 0)))
|
||||||
|
x = -1;
|
||||||
|
|
||||||
|
if ((startzone->getType() == PlayerZone::PublicZone) || (targetzone->getType() == PlayerZone::PublicZone))
|
||||||
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
|
emit broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
|
||||||
.arg(publicCardName)
|
.arg(publicCardName)
|
||||||
.arg(startzone->getName())
|
.arg(startzone->getName())
|
||||||
|
@ -529,7 +553,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
|
||||||
PlayerZone *zone = player->getZone(params[1].toString());
|
PlayerZone *zone = player->getZone(params[1].toString());
|
||||||
if (!zone)
|
if (!zone)
|
||||||
return ReturnMessage::ReturnContextError;
|
return ReturnMessage::ReturnContextError;
|
||||||
if (!(zone->isPublic() || (player_id == playerId)))
|
if (!((zone->getType() == PlayerZone::PublicZone) || (player_id == playerId)))
|
||||||
return ReturnMessage::ReturnContextError;
|
return ReturnMessage::ReturnContextError;
|
||||||
|
|
||||||
QListIterator<Card *> card_iterator(zone->cards);
|
QListIterator<Card *> card_iterator(zone->cards);
|
||||||
|
@ -537,7 +561,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
|
||||||
for (int i = 0; card_iterator.hasNext() && (i < number_cards || number_cards == 0); i++) {
|
for (int i = 0; card_iterator.hasNext() && (i < number_cards || number_cards == 0); i++) {
|
||||||
Card *tmp = card_iterator.next();
|
Card *tmp = card_iterator.next();
|
||||||
// XXX Face down cards
|
// XXX Face down cards
|
||||||
if (zone->hasIdAccess())
|
if (zone->getType() != PlayerZone::HiddenZone)
|
||||||
result << QString("%1|%2|%3|%4|%5|%6|%7|%8").arg(tmp->getId())
|
result << QString("%1|%2|%3|%4|%5|%6|%7|%8").arg(tmp->getId())
|
||||||
.arg(tmp->getName())
|
.arg(tmp->getName())
|
||||||
.arg(tmp->getX())
|
.arg(tmp->getX())
|
||||||
|
@ -546,14 +570,32 @@ ReturnMessage::ReturnCode ServerSocket::cmdDumpZone(const QList<QVariant> ¶m
|
||||||
.arg(tmp->getTapped())
|
.arg(tmp->getTapped())
|
||||||
.arg(tmp->getAttacking())
|
.arg(tmp->getAttacking())
|
||||||
.arg(tmp->getAnnotation());
|
.arg(tmp->getAnnotation());
|
||||||
else
|
else {
|
||||||
|
zone->setCardsBeingLookedAt(number_cards);
|
||||||
result << QString("%1|%2||||||").arg(i).arg(tmp->getName());
|
result << QString("%1|%2||||||").arg(i).arg(tmp->getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
remsg->sendList(result);
|
remsg->sendList(result);
|
||||||
emit broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), this);
|
emit broadcastEvent(QString("dump_zone|%1|%2|%3").arg(player_id).arg(zone->getName()).arg(number_cards), this);
|
||||||
return ReturnMessage::ReturnOk;
|
return ReturnMessage::ReturnOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnMessage::ReturnCode ServerSocket::cmdStopDumpZone(const QList<QVariant> ¶ms)
|
||||||
|
{
|
||||||
|
ServerSocket *player = game->getPlayer(params[0].toInt());
|
||||||
|
if (!player)
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
PlayerZone *zone = player->getZone(params[1].toString());
|
||||||
|
if (!zone)
|
||||||
|
return ReturnMessage::ReturnContextError;
|
||||||
|
|
||||||
|
if (zone->getType() == PlayerZone::HiddenZone) {
|
||||||
|
zone->setCardsBeingLookedAt(-1);
|
||||||
|
emit broadcastEvent(QString("stop_dump_zone|%1|%2").arg(player->getPlayerId()).arg(zone->getName()), this);
|
||||||
|
}
|
||||||
|
return ReturnMessage::ReturnOk;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnMessage::ReturnCode ServerSocket::cmdRollDice(const QList<QVariant> ¶ms)
|
ReturnMessage::ReturnCode ServerSocket::cmdRollDice(const QList<QVariant> ¶ms)
|
||||||
{
|
{
|
||||||
int sides = params[0].toInt();
|
int sides = params[0].toInt();
|
||||||
|
@ -662,7 +704,7 @@ void ServerSocket::setGame(ServerGame *g)
|
||||||
game = g;
|
game = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ServerSocket::listCounters()
|
QStringList ServerSocket::listCounters() const
|
||||||
{
|
{
|
||||||
QStringList counter_list;
|
QStringList counter_list;
|
||||||
QListIterator<Counter *> i(counters);
|
QListIterator<Counter *> i(counters);
|
||||||
|
@ -673,13 +715,13 @@ QStringList ServerSocket::listCounters()
|
||||||
return counter_list;
|
return counter_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ServerSocket::listZones()
|
QStringList ServerSocket::listZones() const
|
||||||
{
|
{
|
||||||
QStringList zone_list;
|
QStringList zone_list;
|
||||||
QListIterator<PlayerZone *> i(zones);
|
QListIterator<PlayerZone *> i(zones);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
PlayerZone *tmp = i.next();
|
PlayerZone *tmp = i.next();
|
||||||
zone_list << QString("%1|%2|%3|%4").arg(tmp->getName()).arg(tmp->isPublic()).arg(tmp->hasCoords()).arg(tmp->cards.size());
|
zone_list << QString("%1|%2|%3|%4").arg(tmp->getName()).arg(tmp->getType() == PlayerZone::PublicZone ? 1 : 0).arg(tmp->hasCoords()).arg(tmp->cards.size());
|
||||||
}
|
}
|
||||||
return zone_list;
|
return zone_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ private:
|
||||||
QList<QVariant::Type> paramTypes;
|
QList<QVariant::Type> paramTypes;
|
||||||
CommandHandler handler;
|
CommandHandler handler;
|
||||||
};
|
};
|
||||||
static const int numberCommands = 26;
|
static const int numberCommands = 27;
|
||||||
static const CommandProperties commandList[numberCommands];
|
static const CommandProperties commandList[numberCommands];
|
||||||
|
|
||||||
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdPing(const QList<QVariant> ¶ms);
|
||||||
|
@ -81,6 +81,7 @@ private:
|
||||||
ReturnMessage::ReturnCode cmdListCounters(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdListCounters(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdListZones(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdListZones(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdDumpZone(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdDumpZone(const QList<QVariant> ¶ms);
|
||||||
|
ReturnMessage::ReturnCode cmdStopDumpZone(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdRollDice(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdRollDice(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdSetActivePlayer(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdSetActivePlayer(const QList<QVariant> ¶ms);
|
||||||
ReturnMessage::ReturnCode cmdSetActivePhase(const QList<QVariant> ¶ms);
|
ReturnMessage::ReturnCode cmdSetActivePhase(const QList<QVariant> ¶ms);
|
||||||
|
@ -116,8 +117,8 @@ public:
|
||||||
void setPlayerId(int _id) { playerId = _id; }
|
void setPlayerId(int _id) { playerId = _id; }
|
||||||
QString getPlayerName() const { return playerName; }
|
QString getPlayerName() const { return playerName; }
|
||||||
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
bool getAcceptsGameListChanges() const { return acceptsGameListChanges; }
|
||||||
QStringList listCounters();
|
QStringList listCounters() const;
|
||||||
QStringList listZones();
|
QStringList listZones() const;
|
||||||
void setupZones();
|
void setupZones();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue