game is almost playable again
This commit is contained in:
parent
0d4717f40b
commit
e796af2b89
34 changed files with 309 additions and 320 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QGraphicsSceneMouseEvent>
|
#include <QGraphicsSceneMouseEvent>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
@ -76,7 +77,7 @@ void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
if (event->button() == Qt::RightButton)
|
if (event->button() == Qt::RightButton)
|
||||||
player->client->deleteArrow(id);
|
player->sendGameCommand(new Command_DeleteArrow(-1, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrowDragItem::ArrowDragItem(CardItem *_startItem, const QColor &_color)
|
ArrowDragItem::ArrowDragItem(CardItem *_startItem, const QColor &_color)
|
||||||
|
@ -110,7 +111,8 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||||
if (targetItem && (targetItem != startItem)) {
|
if (targetItem && (targetItem != startItem)) {
|
||||||
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
CardZone *startZone = static_cast<CardZone *>(startItem->parentItem());
|
||||||
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
CardZone *targetZone = static_cast<CardZone *>(targetItem->parentItem());
|
||||||
player->client->createArrow(
|
player->sendGameCommand(new Command_CreateArrow(
|
||||||
|
-1,
|
||||||
startZone->getPlayer()->getId(),
|
startZone->getPlayer()->getId(),
|
||||||
startZone->getName(),
|
startZone->getName(),
|
||||||
startItem->getId(),
|
startItem->getId(),
|
||||||
|
@ -118,7 +120,7 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
|
||||||
targetZone->getName(),
|
targetZone->getName(),
|
||||||
targetItem->getId(),
|
targetItem->getId(),
|
||||||
color
|
color
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,18 @@ void CardItem::resetState()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardItem::processCardInfo(ServerInfo_Card *info)
|
||||||
|
{
|
||||||
|
id = info->getId();
|
||||||
|
name = info->getName();
|
||||||
|
attacking = info->getAttacking();
|
||||||
|
counters = info->getCounters();
|
||||||
|
annotation = info->getAnnotation();
|
||||||
|
tapped = info->getTapped();
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
CardDragItem *CardItem::createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown)
|
||||||
{
|
{
|
||||||
deleteDragItem();
|
deleteDragItem();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class CardDragItem;
|
class CardDragItem;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
class ServerInfo_Card;
|
||||||
|
|
||||||
const int MAX_COUNTERS_ON_CARD = 999;
|
const int MAX_COUNTERS_ON_CARD = 999;
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ public:
|
||||||
bool getDoesntUntap() const { return doesntUntap; }
|
bool getDoesntUntap() const { return doesntUntap; }
|
||||||
void setDoesntUntap(bool _doesntUntap);
|
void setDoesntUntap(bool _doesntUntap);
|
||||||
void resetState();
|
void resetState();
|
||||||
|
void processCardInfo(ServerInfo_Card *info);
|
||||||
|
|
||||||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||||
void deleteDragItem();
|
void deleteDragItem();
|
||||||
|
|
|
@ -128,9 +128,9 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName,
|
||||||
|
|
||||||
void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue)
|
void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue)
|
||||||
{
|
{
|
||||||
if (hasCardAttr)
|
/* if (hasCardAttr)
|
||||||
player->client->setCardAttr(name, cardId, aname, avalue);
|
player->client->setCardAttr(name, cardId, aname, avalue);
|
||||||
}
|
*/}
|
||||||
|
|
||||||
void CardZone::moveAllToZone()
|
void CardZone::moveAllToZone()
|
||||||
{
|
{
|
||||||
|
@ -140,8 +140,8 @@ void CardZone::moveAllToZone()
|
||||||
|
|
||||||
// Cards need to be moved in reverse order so that the other
|
// Cards need to be moved in reverse order so that the other
|
||||||
// cards' list index doesn't change
|
// cards' list index doesn't change
|
||||||
for (int i = cards.size() - 1; i >= 0; i--)
|
// for (int i = cards.size() - 1; i >= 0; i--)
|
||||||
player->client->moveCard(cards.at(i)->getId(), getName(), targetZone, targetX);
|
// player->client->moveCard(cards.at(i)->getId(), getName(), targetZone, targetX);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPointF CardZone::closestGridPoint(const QPointF &point)
|
QPointF CardZone::closestGridPoint(const QPointF &point)
|
||||||
|
|
|
@ -33,7 +33,6 @@ class Client : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void statusChanged(ClientStatus _status);
|
void statusChanged(ClientStatus _status);
|
||||||
// void playerIdReceived(int id, QString name);
|
|
||||||
void maxPingTime(int seconds, int maxSeconds);
|
void maxPingTime(int seconds, int maxSeconds);
|
||||||
void serverTimeout();
|
void serverTimeout();
|
||||||
void logSocketError(const QString &errorString);
|
void logSocketError(const QString &errorString);
|
||||||
|
@ -79,40 +78,6 @@ public:
|
||||||
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
void connectToServer(const QString &hostname, unsigned int port, const QString &_userName, const QString &_password);
|
||||||
void disconnectFromServer();
|
void disconnectFromServer();
|
||||||
void sendCommand(Command *cmd);
|
void sendCommand(Command *cmd);
|
||||||
public slots:
|
|
||||||
|
|
||||||
void chatListChannels() { }
|
|
||||||
void chatJoinChannel(const QString &name) { }
|
|
||||||
void chatLeaveChannel(const QString &name) { }
|
|
||||||
void chatSay(const QString &name, const QString &s) { }
|
|
||||||
void listGames() { }
|
|
||||||
void listPlayers() { }
|
|
||||||
void createGame(const QString &description, const QString &password, unsigned int maxPlayers, bool spectatorsAllowed) { }
|
|
||||||
void joinGame(int gameId, const QString &password, bool spectator) { }
|
|
||||||
void leaveGame() { }
|
|
||||||
void login(const QString &name, const QString &pass) { }
|
|
||||||
void say(const QString &s) { }
|
|
||||||
void shuffle() { }
|
|
||||||
void rollDie(unsigned int sides) { }
|
|
||||||
void drawCard() { return drawCards(1); }
|
|
||||||
void drawCards(unsigned int number) { }
|
|
||||||
void moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false) { }
|
|
||||||
void createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y) { }
|
|
||||||
void createArrow(int startPlayerId, const QString &startZone, int startCardId, int targetPlayerId, const QString &targetPlayerZone, int targetCardId, const QColor &color) { }
|
|
||||||
void deleteArrow(int arrowId) { }
|
|
||||||
void setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue) { }
|
|
||||||
void readyStart() { }
|
|
||||||
void incCounter(int counterId, int delta) { }
|
|
||||||
void addCounter(const QString &counterName, QColor color, int radius, int value) { }
|
|
||||||
void setCounter(int counterId, int value) { }
|
|
||||||
void delCounter(int counterId) { }
|
|
||||||
void nextTurn() { }
|
|
||||||
void setActivePhase(int phase) { }
|
|
||||||
void dumpZone(int player, const QString &zone, int numberCards) { }
|
|
||||||
void stopDumpZone(int player, const QString &zone) { }
|
|
||||||
void dumpAll() { }
|
|
||||||
void submitDeck(const QStringList &deck) { }
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "counter.h"
|
#include "counter.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent)
|
Counter::Counter(Player *_player, int _id, const QString &_name, QColor _color, int _radius, int _value, QGraphicsItem *parent)
|
||||||
|
@ -77,10 +78,10 @@ void Counter::setValue(int _value)
|
||||||
void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
player->client->incCounter(id, 1);
|
player->sendGameCommand(new Command_IncCounter(-1, id, 1));
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->button() == Qt::RightButton) {
|
} else if (event->button() == Qt::RightButton) {
|
||||||
player->client->incCounter(id, -1);
|
player->sendGameCommand(new Command_IncCounter(-1, id, -1));
|
||||||
event->accept();
|
event->accept();
|
||||||
} else if (event->button() == Qt::MidButton) {
|
} else if (event->button() == Qt::MidButton) {
|
||||||
if (menu)
|
if (menu)
|
||||||
|
@ -93,7 +94,7 @@ void Counter::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
void Counter::incrementCounter()
|
void Counter::incrementCounter()
|
||||||
{
|
{
|
||||||
int delta = static_cast<QAction *>(sender())->data().toInt();
|
int delta = static_cast<QAction *>(sender())->data().toInt();
|
||||||
player->client->incCounter(id, delta);
|
player->sendGameCommand(new Command_IncCounter(-1, id, delta));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Counter::setCounter()
|
void Counter::setCounter()
|
||||||
|
@ -101,5 +102,5 @@ void Counter::setCounter()
|
||||||
bool ok;
|
bool ok;
|
||||||
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, 0, 2000000000, 1, &ok);
|
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, 0, 2000000000, 1, &ok);
|
||||||
if (ok)
|
if (ok)
|
||||||
player->client->setCounter(id, newValue);
|
player->sendGameCommand(new Command_SetCounter(-1, id, newValue));
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,49 +129,6 @@ void Game::retranslateUi()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void Game::cardListReceived(QList<ServerZoneCard> list)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
|
||||||
Player *p = players.value(list[i].getPlayerId(), 0);
|
|
||||||
if (!p)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CardZone *zone = p->getZones().value(list[i].getZoneName(), 0);
|
|
||||||
if (!zone)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CardItem *card = new CardItem(db, list[i].getName(), list[i].getId());
|
|
||||||
zone->addCard(card, false, list[i].getX(), list[i].getY());
|
|
||||||
|
|
||||||
card->setCounters(list[i].getCounters());
|
|
||||||
card->setTapped(list[i].getTapped());
|
|
||||||
card->setAttacking(list[i].getAttacking());
|
|
||||||
card->setAnnotation(list[i].getAnnotation());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::zoneListReceived(QList<ServerZone> list)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
|
||||||
Player *p = players.value(list[i].getPlayerId(), 0);
|
|
||||||
if (!p)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CardZone *zone = p->getZones().value(list[i].getName(), 0);
|
|
||||||
if (!zone)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
zone->clearContents();
|
|
||||||
if (
|
|
||||||
(list[i].getType() != ServerZone::PublicZone)
|
|
||||||
&& !((list[i].getType() == ServerZone::PrivateZone) && p->getLocal())
|
|
||||||
) {
|
|
||||||
for (int j = 0; j < list[i].getCardCount(); ++j)
|
|
||||||
zone->addCard(new CardItem(db), false, -1);
|
|
||||||
zone->reorganizeCards();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::counterListReceived(QList<ServerCounter> list)
|
void Game::counterListReceived(QList<ServerCounter> list)
|
||||||
{
|
{
|
||||||
|
@ -228,11 +185,6 @@ void Game::playerListReceived(QList<ServerPlayer> playerList)
|
||||||
restartGameDialog();
|
restartGameDialog();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void Game::readyStart()
|
|
||||||
{
|
|
||||||
client->readyStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Game::restartGameDialog()
|
void Game::restartGameDialog()
|
||||||
{
|
{
|
||||||
// dlgStartGame->show();
|
// dlgStartGame->show();
|
||||||
|
@ -393,12 +345,12 @@ void Game::actNextPhase()
|
||||||
int phase = currentPhase;
|
int phase = currentPhase;
|
||||||
if (++phase >= phaseCount)
|
if (++phase >= phaseCount)
|
||||||
phase = 0;
|
phase = 0;
|
||||||
client->setActivePhase(phase);
|
// client->setActivePhase(phase);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actNextTurn()
|
void Game::actNextTurn()
|
||||||
{
|
{
|
||||||
client->nextTurn();
|
// client->nextTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actRemoveLocalArrows()
|
void Game::actRemoveLocalArrows()
|
||||||
|
@ -409,7 +361,7 @@ void Game::actRemoveLocalArrows()
|
||||||
QMapIterator<int, ArrowItem *> arrowIterator(players[i]->getArrows());
|
QMapIterator<int, ArrowItem *> arrowIterator(players[i]->getArrows());
|
||||||
while (arrowIterator.hasNext()) {
|
while (arrowIterator.hasNext()) {
|
||||||
ArrowItem *a = arrowIterator.next().value();
|
ArrowItem *a = arrowIterator.next().value();
|
||||||
players[i]->client->deleteArrow(a->getId());
|
// players[i]->client->deleteArrow(a->getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,37 +388,37 @@ void Game::cardMenuAction()
|
||||||
|
|
||||||
void Game::actTap(CardItem *card)
|
void Game::actTap(CardItem *card)
|
||||||
{
|
{
|
||||||
if (!card->getTapped())
|
// if (!card->getTapped())
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "1");
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actUntap(CardItem *card)
|
void Game::actUntap(CardItem *card)
|
||||||
{
|
{
|
||||||
if (card->getTapped())
|
// if (card->getTapped())
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "0");
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "tapped", "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actDoesntUntap(CardItem *card)
|
void Game::actDoesntUntap(CardItem *card)
|
||||||
{
|
{
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()));
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "doesnt_untap", QString::number(!card->getDoesntUntap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actFlip(CardItem *card)
|
void Game::actFlip(CardItem *card)
|
||||||
{
|
{
|
||||||
QString zone = qgraphicsitem_cast<CardZone *>(card->parentItem())->getName();
|
// QString zone = qgraphicsitem_cast<CardZone *>(card->parentItem())->getName();
|
||||||
client->moveCard(card->getId(), zone, zone, card->getGridPoint().x(), card->getGridPoint().y(), !card->getFaceDown());
|
// client->moveCard(card->getId(), zone, zone, card->getGridPoint().x(), card->getGridPoint().y(), !card->getFaceDown());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actAddCounter(CardItem *card)
|
void Game::actAddCounter(CardItem *card)
|
||||||
{
|
{
|
||||||
if (card->getCounters() < MAX_COUNTERS_ON_CARD)
|
// if (card->getCounters() < MAX_COUNTERS_ON_CARD)
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() + 1));
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actRemoveCounter(CardItem *card)
|
void Game::actRemoveCounter(CardItem *card)
|
||||||
{
|
{
|
||||||
if (card->getCounters())
|
// if (card->getCounters())
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() - 1));
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(card->parentItem())->getName(), card->getId(), "counters", QString::number(card->getCounters() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actSetCounters()
|
void Game::actSetCounters()
|
||||||
|
@ -479,32 +431,32 @@ void Game::actSetCounters()
|
||||||
QListIterator<QGraphicsItem *> i(scene->selectedItems());
|
QListIterator<QGraphicsItem *> i(scene->selectedItems());
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
CardItem *temp = (CardItem *) i.next();
|
CardItem *temp = (CardItem *) i.next();
|
||||||
client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(number));
|
// client->setCardAttr(qgraphicsitem_cast<CardZone *>(temp->parentItem())->getName(), temp->getId(), "counters", QString::number(number));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actMoveToTopLibrary(CardItem *card)
|
void Game::actMoveToTopLibrary(CardItem *card)
|
||||||
{
|
{
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
// CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||||
client->moveCard(card->getId(), startZone->getName(), "deck", 0, 0, false);
|
// client->moveCard(card->getId(), startZone->getName(), "deck", 0, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actMoveToBottomLibrary(CardItem *card)
|
void Game::actMoveToBottomLibrary(CardItem *card)
|
||||||
{
|
{
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
// CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||||
client->moveCard(card->getId(), startZone->getName(), "deck", -1, 0, false);
|
// client->moveCard(card->getId(), startZone->getName(), "deck", -1, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actMoveToGraveyard(CardItem *card)
|
void Game::actMoveToGraveyard(CardItem *card)
|
||||||
{
|
{
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
// CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||||
client->moveCard(card->getId(), startZone->getName(), "grave", 0, 0, false);
|
// client->moveCard(card->getId(), startZone->getName(), "grave", 0, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::actMoveToExile(CardItem *card)
|
void Game::actMoveToExile(CardItem *card)
|
||||||
{
|
{
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
// CardZone *startZone = qgraphicsitem_cast<CardZone *>(card->parentItem());
|
||||||
client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false);
|
// client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::hoverCardEvent(CardItem *card)
|
void Game::hoverCardEvent(CardItem *card)
|
||||||
|
|
|
@ -66,7 +66,6 @@ private slots:
|
||||||
void counterListReceived(QList<ServerCounter> list);
|
void counterListReceived(QList<ServerCounter> list);
|
||||||
void arrowListReceived(QList<ServerArrow> list);
|
void arrowListReceived(QList<ServerArrow> list);
|
||||||
*/
|
*/
|
||||||
void readyStart();
|
|
||||||
signals:
|
signals:
|
||||||
void submitDecklist();
|
void submitDecklist();
|
||||||
void hoverCard(QString name);
|
void hoverCard(QString name);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "handzone.h"
|
#include "handzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
HandZone::HandZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
|
HandZone::HandZone(Player *_p, int _zoneHeight, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "hand", false, false, _p->getLocal(), parent), zoneHeight(_zoneHeight)
|
: CardZone(_p, "hand", false, false, _p->getLocal(), parent), zoneHeight(_zoneHeight)
|
||||||
|
@ -73,5 +74,5 @@ void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
|
|
||||||
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), cards.size(), 0);
|
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), cards.size(), -1, false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "carddragitem.h"
|
#include "carddragitem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
PileZone::PileZone(Player *_p, const QString &_name, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent)
|
||||||
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
: CardZone(_p, _name, false, _isShufflable, _contentsKnown, parent)
|
||||||
|
@ -47,7 +48,7 @@ void PileZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
|
|
||||||
void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
void PileZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::reorganizeCards()
|
void PileZone::reorganizeCards()
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "handzone.h"
|
#include "handzone.h"
|
||||||
#include "cardlist.h"
|
#include "cardlist.h"
|
||||||
#include "tab_game.h"
|
#include "tab_game.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
@ -327,12 +328,12 @@ void Player::actViewSideboard()
|
||||||
|
|
||||||
void Player::actShuffle()
|
void Player::actShuffle()
|
||||||
{
|
{
|
||||||
client->shuffle();
|
sendGameCommand(new Command_Shuffle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actDrawCard()
|
void Player::actDrawCard()
|
||||||
{
|
{
|
||||||
client->drawCards(1);
|
sendGameCommand(new Command_DrawCards(-1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actMulligan()
|
void Player::actMulligan()
|
||||||
|
@ -342,21 +343,21 @@ void Player::actMulligan()
|
||||||
|
|
||||||
const CardList &handCards = hand->getCards();
|
const CardList &handCards = hand->getCards();
|
||||||
for (int i = 0; i < handCards.size(); i++)
|
for (int i = 0; i < handCards.size(); i++)
|
||||||
client->moveCard(handCards.at(i)->getId(), "hand", "deck", 0);
|
sendGameCommand(new Command_MoveCard(-1, "hand", handCards.at(i)->getId(), "deck", 0, -1, false));
|
||||||
client->shuffle();
|
sendGameCommand(new Command_Shuffle);
|
||||||
client->drawCards(mulliganCards--);
|
sendGameCommand(new Command_DrawCards(-1, mulliganCards--));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actDrawCards()
|
void Player::actDrawCards()
|
||||||
{
|
{
|
||||||
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
|
int number = QInputDialog::getInteger(0, tr("Draw cards"), tr("Number:"));
|
||||||
if (number)
|
if (number)
|
||||||
client->drawCards(number);
|
sendGameCommand(new Command_DrawCards(-1, number));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actUntapAll()
|
void Player::actUntapAll()
|
||||||
{
|
{
|
||||||
client->setCardAttr("table", -1, "tapped", "false");
|
// client->setCardAttr("table", -1, "tapped", "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actRollDie()
|
void Player::actRollDie()
|
||||||
|
@ -364,25 +365,20 @@ void Player::actRollDie()
|
||||||
bool ok;
|
bool ok;
|
||||||
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
|
int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok);
|
||||||
if (ok)
|
if (ok)
|
||||||
client->rollDie(sides);
|
sendGameCommand(new Command_RollDie(-1, sides));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actCreateToken()
|
void Player::actCreateToken()
|
||||||
{
|
{
|
||||||
QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:"));
|
QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:"));
|
||||||
if (!cardname.isEmpty())
|
if (!cardname.isEmpty())
|
||||||
client->createToken("table", cardname, QString(), 0, 0);
|
sendGameCommand(new Command_CreateToken(-1, "table", cardname, QString(), 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::actSayMessage()
|
void Player::actSayMessage()
|
||||||
{
|
{
|
||||||
QAction *a = qobject_cast<QAction *>(sender());
|
QAction *a = qobject_cast<QAction *>(sender());
|
||||||
client->say(a->text());
|
sendGameCommand(new Command_Say(-1, a->text()));
|
||||||
}
|
|
||||||
|
|
||||||
void Player::addZone(CardZone *z)
|
|
||||||
{
|
|
||||||
zones.insert(z->getName(), z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards)
|
void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards)
|
||||||
|
@ -699,6 +695,56 @@ void Player::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/
|
||||||
|
|
||||||
void Player::processPlayerInfo(ServerInfo_Player *info)
|
void Player::processPlayerInfo(ServerInfo_Player *info)
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < info->getZoneList().size(); ++i) {
|
||||||
|
ServerInfo_Zone *zoneInfo = info->getZoneList()[i];
|
||||||
|
CardZone *zone = zones.value(zoneInfo->getName(), 0);
|
||||||
|
if (!zone)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
zone->clearContents();
|
||||||
|
const QList<ServerInfo_Card *> &cardList = zoneInfo->getCardList();
|
||||||
|
if (cardList.isEmpty()) {
|
||||||
|
for (int j = 0; j < zoneInfo->getCardCount(); ++j)
|
||||||
|
zone->addCard(new CardItem, false, -1);
|
||||||
|
} else {
|
||||||
|
for (int j = 0; j < cardList.size(); ++j) {
|
||||||
|
CardItem *card = new CardItem;
|
||||||
|
card->processCardInfo(cardList[i]);
|
||||||
|
zone->addCard(card, false, cardList[i]->getX(), cardList[i]->getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zone->reorganizeCards();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearCounters();
|
||||||
|
for (int i = 0; i < info->getCounterList().size(); ++i) {
|
||||||
|
ServerInfo_Counter *counterInfo = info->getCounterList().at(i);
|
||||||
|
addCounter(counterInfo->getId(), counterInfo->getName(), counterInfo->getColor(), counterInfo->getRadius(), counterInfo->getCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
clearArrows();
|
||||||
|
for (int i = 0; i < info->getArrowList().size(); ++i) {
|
||||||
|
ServerInfo_Arrow *arrowInfo = info->getArrowList().at(i);
|
||||||
|
const QMap<int, Player *> &playerList = static_cast<TabGame *>(parent())->getPlayers();
|
||||||
|
Player *startPlayer = playerList.value(arrowInfo->getStartPlayerId(), 0);
|
||||||
|
Player *targetPlayer = playerList.value(arrowInfo->getTargetPlayerId(), 0);
|
||||||
|
if (!startPlayer || !targetPlayer)
|
||||||
|
continue;
|
||||||
|
CardZone *startZone = startPlayer->getZones().value(arrowInfo->getStartZone(), 0);
|
||||||
|
CardZone *targetZone = targetPlayer->getZones().value(arrowInfo->getTargetZone(), 0);
|
||||||
|
if (!startZone || !targetZone)
|
||||||
|
continue;
|
||||||
|
CardItem *startCard = startZone->getCard(arrowInfo->getStartCardId(), QString());
|
||||||
|
CardItem *targetCard = targetZone->getCard(arrowInfo->getTargetCardId(), QString());
|
||||||
|
if (!startCard || !targetCard)
|
||||||
|
continue;
|
||||||
|
addArrow(arrowInfo->getId(), startCard, targetCard, arrowInfo->getColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::addZone(CardZone *z)
|
||||||
|
{
|
||||||
|
zones.insert(z->getName(), z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value)
|
void Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value)
|
||||||
|
@ -783,3 +829,8 @@ void Player::rearrangeCounters()
|
||||||
y += br.height() + padding;
|
y += br.height() + padding;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::sendGameCommand(GameCommand *command)
|
||||||
|
{
|
||||||
|
static_cast<TabGame *>(parent())->sendGameCommand(command);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ class CardZone;
|
||||||
class TableZone;
|
class TableZone;
|
||||||
class HandZone;
|
class HandZone;
|
||||||
class ServerInfo_Player;
|
class ServerInfo_Player;
|
||||||
|
class GameCommand;
|
||||||
|
|
||||||
class Player : public QObject, public QGraphicsItem {
|
class Player : public QObject, public QGraphicsItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -94,6 +95,8 @@ public:
|
||||||
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 addZone(CardZone *z);
|
||||||
|
|
||||||
void addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
void addCounter(int counterId, const QString &name, QColor color, int radius, int value);
|
||||||
void delCounter(int counterId);
|
void delCounter(int counterId);
|
||||||
void clearCounters();
|
void clearCounters();
|
||||||
|
@ -103,7 +106,6 @@ public:
|
||||||
void clearArrows();
|
void clearArrows();
|
||||||
|
|
||||||
Client *client;
|
Client *client;
|
||||||
void addZone(CardZone *z);
|
|
||||||
Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent);
|
Player(const QString &_name, int _id, bool _local, Client *_client, TabGame *_parent);
|
||||||
~Player();
|
~Player();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
@ -120,6 +122,7 @@ public:
|
||||||
void setActive(bool _active);
|
void setActive(bool _active);
|
||||||
|
|
||||||
void processPlayerInfo(ServerInfo_Player *info);
|
void processPlayerInfo(ServerInfo_Player *info);
|
||||||
|
void sendGameCommand(GameCommand *command);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "dlg_load_remote_deck.h"
|
#include "dlg_load_remote_deck.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
TabGame::TabGame(Client *_client, int _gameId)
|
TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator)
|
||||||
: client(_client), gameId(_gameId), localPlayerId(-1)
|
: client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator)
|
||||||
{
|
{
|
||||||
zoneLayout = new ZoneViewLayout;
|
zoneLayout = new ZoneViewLayout;
|
||||||
scene = new GameScene(zoneLayout, this);
|
scene = new GameScene(zoneLayout, this);
|
||||||
|
@ -124,20 +124,26 @@ void TabGame::processGameEvent(GameEvent *event)
|
||||||
{
|
{
|
||||||
switch (event->getItemId()) {
|
switch (event->getItemId()) {
|
||||||
case ItemId_Event_GameStart: eventGameStart(qobject_cast<Event_GameStart *>(event)); break;
|
case ItemId_Event_GameStart: eventGameStart(qobject_cast<Event_GameStart *>(event)); break;
|
||||||
|
case ItemId_Event_GameStateChanged: eventGameStateChanged(qobject_cast<Event_GameStateChanged *>(event)); break;
|
||||||
default: qDebug() << "unhandled game event";
|
default: qDebug() << "unhandled game event";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabGame::processGameJoinedEvent(Event_GameJoined *event)
|
void TabGame::sendGameCommand(GameCommand *command)
|
||||||
{
|
{
|
||||||
localPlayerId = event->getPlayerId();
|
command->setGameId(gameId);
|
||||||
spectator = event->getSpectator();
|
client->sendCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
|
||||||
|
{
|
||||||
const QList<ServerInfo_Player *> &plList = event->getPlayerList();
|
const QList<ServerInfo_Player *> &plList = event->getPlayerList();
|
||||||
for (int i = 0; i < plList.size(); ++i) {
|
for (int i = 0; i < plList.size(); ++i) {
|
||||||
ServerInfo_Player *pl = plList[i];
|
ServerInfo_Player *pl = plList[i];
|
||||||
Player *newPlayer = addPlayer(pl->getPlayerId(), pl->getName());
|
Player *player = players.value(pl->getPlayerId(), 0);
|
||||||
newPlayer->processPlayerInfo(pl);
|
if (!player)
|
||||||
|
player = addPlayer(pl->getPlayerId(), pl->getName());
|
||||||
|
player->processPlayerInfo(pl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,8 @@ class ZoneViewWidget;
|
||||||
class PhasesToolbar;
|
class PhasesToolbar;
|
||||||
class ProtocolResponse;
|
class ProtocolResponse;
|
||||||
class GameEvent;
|
class GameEvent;
|
||||||
class Event_GameJoined;
|
class GameCommand;
|
||||||
|
class Event_GameStateChanged;
|
||||||
class Event_GameStart;
|
class Event_GameStart;
|
||||||
class Player;
|
class Player;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
|
@ -51,6 +52,7 @@ private:
|
||||||
|
|
||||||
Player *addPlayer(int playerId, const QString &playerName);
|
Player *addPlayer(int playerId, const QString &playerName);
|
||||||
|
|
||||||
|
void eventGameStateChanged(Event_GameStateChanged *event);
|
||||||
void eventGameStart(Event_GameStart *event);
|
void eventGameStart(Event_GameStart *event);
|
||||||
signals:
|
signals:
|
||||||
void playerAdded(Player *player);
|
void playerAdded(Player *player);
|
||||||
|
@ -86,11 +88,12 @@ private slots:
|
||||||
void readyStart();
|
void readyStart();
|
||||||
void deckSelectFinished(ProtocolResponse *r);
|
void deckSelectFinished(ProtocolResponse *r);
|
||||||
public:
|
public:
|
||||||
TabGame(Client *_client, int _gameId);
|
TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
const QMap<int, Player *> &getPlayers() const { return players; }
|
||||||
|
|
||||||
void processGameEvent(GameEvent *event);
|
void processGameEvent(GameEvent *event);
|
||||||
void processGameJoinedEvent(Event_GameJoined *event);
|
void sendGameCommand(GameCommand *command);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -101,10 +101,9 @@ void TabSupervisor::updatePingTime(int value, int max)
|
||||||
|
|
||||||
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
void TabSupervisor::gameJoined(Event_GameJoined *event)
|
||||||
{
|
{
|
||||||
TabGame *tab = new TabGame(client, event->getGameId());
|
TabGame *tab = new TabGame(client, event->getGameId(), event->getPlayerId(), event->getSpectator());
|
||||||
addTab(tab, tr("Game %1").arg(event->getGameId()));
|
addTab(tab, tr("Game %1").arg(event->getGameId()));
|
||||||
gameTabs.insert(event->getGameId(), tab);
|
gameTabs.insert(event->getGameId(), tab);
|
||||||
tab->processGameJoinedEvent(event);
|
|
||||||
setCurrentWidget(tab);
|
setCurrentWidget(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "tablezone.h"
|
#include "tablezone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
TableZone::TableZone(Player *_p, QGraphicsItem *parent)
|
||||||
: CardZone(_p, "table", true, false, true, parent)
|
: CardZone(_p, "table", true, false, true, parent)
|
||||||
|
@ -67,7 +68,7 @@ void TableZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &d
|
||||||
|
|
||||||
void TableZone::handleDropEventByGrid(int cardId, CardZone *startZone, const QPoint &gridPoint, bool faceDown)
|
void TableZone::handleDropEventByGrid(int cardId, CardZone *startZone, const QPoint &gridPoint, bool faceDown)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), gridPoint.x(), gridPoint.y(), faceDown);
|
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), gridPoint.x(), gridPoint.y(), faceDown));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableZone::reorganizeCards()
|
void TableZone::reorganizeCards()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
||||||
#include "zoneviewwidget.h"
|
#include "zoneviewwidget.h"
|
||||||
#include "carditem.h"
|
#include "carditem.h"
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "gamescene.h"
|
#include "gamescene.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent)
|
ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent)
|
||||||
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
|
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
|
||||||
|
@ -91,10 +91,10 @@ void ZoneViewWidget::resizeToZoneContents()
|
||||||
|
|
||||||
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
void ZoneViewWidget::closeEvent(QCloseEvent *event)
|
||||||
{
|
{
|
||||||
player->client->stopDumpZone(player->getId(), zone->getName());
|
player->sendGameCommand(new Command_StopDumpZone(-1, player->getId(), zone->getName()));
|
||||||
if (shuffleCheckBox)
|
if (shuffleCheckBox)
|
||||||
if (shuffleCheckBox->isChecked())
|
if (shuffleCheckBox->isChecked())
|
||||||
player->client->shuffle();
|
player->sendGameCommand(new Command_Shuffle);
|
||||||
emit closePressed(this);
|
emit closePressed(this);
|
||||||
deleteLater();
|
deleteLater();
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
#include "protocol_items.h"
|
||||||
|
|
||||||
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QGraphicsItem *parent)
|
||||||
: CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone), sortingEnabled(false)
|
: CardZone(_p, _origZone->getName(), false, false, true, parent, true), height(0), numberCards(_numberCards), origZone(_origZone), sortingEnabled(false)
|
||||||
|
@ -105,7 +106,7 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
|
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->sendGameCommand(new Command_MoveCard(-1, startZone->getName(), cardId, getName(), 0, 0, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewZone::removeCard(int position)
|
void ZoneViewZone::removeCard(int position)
|
||||||
|
|
|
@ -76,7 +76,7 @@ void ProtocolItem::initializeHash()
|
||||||
|
|
||||||
itemNameHash.insert("generic_eventlist_games", Event_ListGames::newItem);
|
itemNameHash.insert("generic_eventlist_games", Event_ListGames::newItem);
|
||||||
itemNameHash.insert("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
|
itemNameHash.insert("generic_eventlist_chat_channels", Event_ListChatChannels::newItem);
|
||||||
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
|
itemNameHash.insert("game_eventgame_state_changed", Event_GameStateChanged::newItem);
|
||||||
itemNameHash.insert("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
|
itemNameHash.insert("chat_eventchat_list_players", Event_ChatListPlayers::newItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,29 +421,18 @@ void Event_ListGames::writeElement(QXmlStreamWriter *xml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator, const QList<ServerInfo_Player *> &_playerList)
|
Event_GameStateChanged::Event_GameStateChanged(int _gameId, const QList<ServerInfo_Player *> &_playerList)
|
||||||
: GenericEvent("game_joined"), currentItem(0), readFinished(false), gameId(_gameId), playerId(_playerId), spectator(_spectator), playerList(_playerList)
|
: GameEvent("game_state_changed", _gameId, -1), currentItem(0), readFinished(false), playerList(_playerList)
|
||||||
{
|
{
|
||||||
setParameter("game_id", gameId);
|
|
||||||
setParameter("player_id", playerId);
|
|
||||||
setParameter("spectator", spectator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Event_GameJoined::~Event_GameJoined()
|
Event_GameStateChanged::~Event_GameStateChanged()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < playerList.size(); ++i)
|
for (int i = 0; i < playerList.size(); ++i)
|
||||||
delete playerList[i];
|
delete playerList[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event_GameJoined::extractParameters()
|
bool Event_GameStateChanged::readElement(QXmlStreamReader *xml)
|
||||||
{
|
|
||||||
GenericEvent::extractParameters();
|
|
||||||
gameId = parameters["game_id"].toInt();
|
|
||||||
playerId = parameters["player_id"].toInt();
|
|
||||||
spectator = (parameters["spectator"] == "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Event_GameJoined::readElement(QXmlStreamReader *xml)
|
|
||||||
{
|
{
|
||||||
if (currentItem) {
|
if (currentItem) {
|
||||||
if (currentItem->readElement(xml))
|
if (currentItem->readElement(xml))
|
||||||
|
@ -462,7 +451,7 @@ bool Event_GameJoined::readElement(QXmlStreamReader *xml)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event_GameJoined::writeElement(QXmlStreamWriter *xml)
|
void Event_GameStateChanged::writeElement(QXmlStreamWriter *xml)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < playerList.size(); ++i)
|
for (int i = 0; i < playerList.size(); ++i)
|
||||||
playerList[i]->writeElement(xml);
|
playerList[i]->writeElement(xml);
|
||||||
|
|
|
@ -22,7 +22,7 @@ enum ItemId {
|
||||||
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
||||||
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
||||||
ItemId_Event_ListGames = ItemId_Other + 202,
|
ItemId_Event_ListGames = ItemId_Other + 202,
|
||||||
ItemId_Event_GameJoined = ItemId_Other + 203,
|
ItemId_Event_GameStateChanged = ItemId_Other + 203,
|
||||||
ItemId_Response_DeckList = ItemId_Other + 300,
|
ItemId_Response_DeckList = ItemId_Other + 300,
|
||||||
ItemId_Response_DeckDownload = ItemId_Other + 301,
|
ItemId_Response_DeckDownload = ItemId_Other + 301,
|
||||||
ItemId_Response_DeckUpload = ItemId_Other + 302
|
ItemId_Response_DeckUpload = ItemId_Other + 302
|
||||||
|
@ -41,6 +41,7 @@ protected:
|
||||||
void setParameter(const QString &name, const QString &value) { parameters[name] = value; }
|
void setParameter(const QString &name, const QString &value) { parameters[name] = value; }
|
||||||
void setParameter(const QString &name, bool value) { parameters[name] = (value ? "1" : "0"); }
|
void setParameter(const QString &name, bool value) { parameters[name] = (value ? "1" : "0"); }
|
||||||
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
|
void setParameter(const QString &name, int value) { parameters[name] = QString::number(value); }
|
||||||
|
void setParameter(const QString &name, const QColor &value) { parameters[name] = QString::number(ColorConverter::colorToInt(value)); }
|
||||||
virtual void extractParameters() { }
|
virtual void extractParameters() { }
|
||||||
virtual QString getItemType() const = 0;
|
virtual QString getItemType() const = 0;
|
||||||
|
|
||||||
|
@ -127,6 +128,11 @@ public:
|
||||||
setParameter("game_id", gameId);
|
setParameter("game_id", gameId);
|
||||||
}
|
}
|
||||||
int getGameId() const { return gameId; }
|
int getGameId() const { return gameId; }
|
||||||
|
void setGameId(int _gameId)
|
||||||
|
{
|
||||||
|
gameId = _gameId;
|
||||||
|
setParameter("game_id", gameId);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Command_DeckUpload : public Command {
|
class Command_DeckUpload : public Command {
|
||||||
|
@ -331,26 +337,18 @@ public:
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event_GameJoined : public GenericEvent {
|
class Event_GameStateChanged : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
SerializableItem *currentItem;
|
SerializableItem *currentItem;
|
||||||
bool readFinished;
|
bool readFinished;
|
||||||
int gameId;
|
|
||||||
int playerId;
|
|
||||||
bool spectator;
|
|
||||||
QList<ServerInfo_Player *> playerList;
|
QList<ServerInfo_Player *> playerList;
|
||||||
protected:
|
|
||||||
void extractParameters();
|
|
||||||
public:
|
public:
|
||||||
Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
|
Event_GameStateChanged(int _gameId = -1, const QList<ServerInfo_Player *> &_playerList = QList<ServerInfo_Player *>());
|
||||||
~Event_GameJoined();
|
~Event_GameStateChanged();
|
||||||
int getGameId() const { return gameId; }
|
|
||||||
int getPlayerId() const { return playerId; }
|
|
||||||
bool getSpectator() const { return spectator; }
|
|
||||||
const QList<ServerInfo_Player *> &getPlayerList() const { return playerList; }
|
const QList<ServerInfo_Player *> &getPlayerList() const { return playerList; }
|
||||||
static ProtocolItem *newItem() { return new Event_GameJoined; }
|
static ProtocolItem *newItem() { return new Event_GameStateChanged; }
|
||||||
int getItemId() const { return ItemId_Event_GameJoined; }
|
int getItemId() const { return ItemId_Event_GameStateChanged; }
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
|
|
|
@ -2,18 +2,6 @@
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
|
||||||
class ColorConverter {
|
|
||||||
public:
|
|
||||||
static int colorToInt(const QColor &color)
|
|
||||||
{
|
|
||||||
return color.red() * 65536 + color.green() * 256 + color.blue();
|
|
||||||
}
|
|
||||||
static QColor colorFromInt(int colorValue)
|
|
||||||
{
|
|
||||||
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ServerInfo_Player::~ServerInfo_Player()
|
ServerInfo_Player::~ServerInfo_Player()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < zoneList.size(); ++i)
|
for (int i = 0; i < zoneList.size(); ++i)
|
||||||
|
|
|
@ -20,6 +20,18 @@ enum ResponseCode { RespNothing, RespOk, RespInvalidCommand, RespInvalidData, Re
|
||||||
// list index, whereas cards in any other zone are referenced by their ids.
|
// list index, whereas cards in any other zone are referenced by their ids.
|
||||||
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
enum ZoneType { PrivateZone, PublicZone, HiddenZone };
|
||||||
|
|
||||||
|
class ColorConverter {
|
||||||
|
public:
|
||||||
|
static int colorToInt(const QColor &color)
|
||||||
|
{
|
||||||
|
return color.red() * 65536 + color.green() * 256 + color.blue();
|
||||||
|
}
|
||||||
|
static QColor colorFromInt(int colorValue)
|
||||||
|
{
|
||||||
|
return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class SerializableItem {
|
class SerializableItem {
|
||||||
protected:
|
protected:
|
||||||
SerializableItem *currentItem;
|
SerializableItem *currentItem;
|
||||||
|
|
|
@ -39,23 +39,23 @@ ItemId_Event_Leave = 1037,
|
||||||
ItemId_Event_DeckSelect = 1038,
|
ItemId_Event_DeckSelect = 1038,
|
||||||
ItemId_Event_GameClosed = 1039,
|
ItemId_Event_GameClosed = 1039,
|
||||||
ItemId_Event_ReadyStart = 1040,
|
ItemId_Event_ReadyStart = 1040,
|
||||||
ItemId_Event_SetupZones = 1041,
|
ItemId_Event_GameStart = 1041,
|
||||||
ItemId_Event_GameStart = 1042,
|
ItemId_Event_Shuffle = 1042,
|
||||||
ItemId_Event_Shuffle = 1043,
|
ItemId_Event_RollDie = 1043,
|
||||||
ItemId_Event_RollDie = 1044,
|
ItemId_Event_MoveCard = 1044,
|
||||||
ItemId_Event_MoveCard = 1045,
|
ItemId_Event_CreateToken = 1045,
|
||||||
ItemId_Event_CreateToken = 1046,
|
ItemId_Event_CreateArrow = 1046,
|
||||||
ItemId_Event_CreateArrow = 1047,
|
ItemId_Event_DeleteArrow = 1047,
|
||||||
ItemId_Event_DeleteArrow = 1048,
|
ItemId_Event_SetCardAttr = 1048,
|
||||||
ItemId_Event_SetCardAttr = 1049,
|
ItemId_Event_AddCounter = 1049,
|
||||||
ItemId_Event_AddCounter = 1050,
|
ItemId_Event_SetCounter = 1050,
|
||||||
ItemId_Event_SetCounter = 1051,
|
ItemId_Event_DelCounter = 1051,
|
||||||
ItemId_Event_DelCounter = 1052,
|
ItemId_Event_SetActivePlayer = 1052,
|
||||||
ItemId_Event_SetActivePlayer = 1053,
|
ItemId_Event_SetActivePhase = 1053,
|
||||||
ItemId_Event_SetActivePhase = 1054,
|
ItemId_Event_DumpZone = 1054,
|
||||||
ItemId_Event_DumpZone = 1055,
|
ItemId_Event_StopDumpZone = 1055,
|
||||||
ItemId_Event_StopDumpZone = 1056,
|
ItemId_Event_ServerMessage = 1056,
|
||||||
ItemId_Event_ServerMessage = 1057,
|
ItemId_Event_GameJoined = 1057,
|
||||||
ItemId_Event_ChatJoinChannel = 1058,
|
ItemId_Event_ChatJoinChannel = 1058,
|
||||||
ItemId_Event_ChatLeaveChannel = 1059,
|
ItemId_Event_ChatLeaveChannel = 1059,
|
||||||
ItemId_Event_ChatSay = 1060,
|
ItemId_Event_ChatSay = 1060,
|
||||||
|
|
|
@ -201,7 +201,7 @@ void Command_CreateToken::extractParameters()
|
||||||
x = parameters["x"].toInt();
|
x = parameters["x"].toInt();
|
||||||
y = parameters["y"].toInt();
|
y = parameters["y"].toInt();
|
||||||
}
|
}
|
||||||
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, int _color)
|
Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
|
||||||
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color)
|
: GameCommand("create_arrow", _gameId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color)
|
||||||
{
|
{
|
||||||
setParameter("start_player_id", startPlayerId);
|
setParameter("start_player_id", startPlayerId);
|
||||||
|
@ -221,7 +221,7 @@ void Command_CreateArrow::extractParameters()
|
||||||
targetPlayerId = parameters["target_player_id"].toInt();
|
targetPlayerId = parameters["target_player_id"].toInt();
|
||||||
targetZone = parameters["target_zone"];
|
targetZone = parameters["target_zone"];
|
||||||
targetCardId = parameters["target_card_id"].toInt();
|
targetCardId = parameters["target_card_id"].toInt();
|
||||||
color = parameters["color"].toInt();
|
color = ColorConverter::colorFromInt(parameters["color"].toInt());
|
||||||
}
|
}
|
||||||
Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId)
|
Command_DeleteArrow::Command_DeleteArrow(int _gameId, int _arrowId)
|
||||||
: GameCommand("delete_arrow", _gameId), arrowId(_arrowId)
|
: GameCommand("delete_arrow", _gameId), arrowId(_arrowId)
|
||||||
|
@ -265,7 +265,7 @@ void Command_IncCounter::extractParameters()
|
||||||
counterId = parameters["counter_id"].toInt();
|
counterId = parameters["counter_id"].toInt();
|
||||||
delta = parameters["delta"].toInt();
|
delta = parameters["delta"].toInt();
|
||||||
}
|
}
|
||||||
Command_AddCounter::Command_AddCounter(int _gameId, const QString &_counterName, int _color, int _radius, int _value)
|
Command_AddCounter::Command_AddCounter(int _gameId, const QString &_counterName, const QColor &_color, int _radius, int _value)
|
||||||
: GameCommand("add_counter", _gameId), counterName(_counterName), color(_color), radius(_radius), value(_value)
|
: GameCommand("add_counter", _gameId), counterName(_counterName), color(_color), radius(_radius), value(_value)
|
||||||
{
|
{
|
||||||
setParameter("counter_name", counterName);
|
setParameter("counter_name", counterName);
|
||||||
|
@ -277,7 +277,7 @@ void Command_AddCounter::extractParameters()
|
||||||
{
|
{
|
||||||
GameCommand::extractParameters();
|
GameCommand::extractParameters();
|
||||||
counterName = parameters["counter_name"];
|
counterName = parameters["counter_name"];
|
||||||
color = parameters["color"].toInt();
|
color = ColorConverter::colorFromInt(parameters["color"].toInt());
|
||||||
radius = parameters["radius"].toInt();
|
radius = parameters["radius"].toInt();
|
||||||
value = parameters["value"].toInt();
|
value = parameters["value"].toInt();
|
||||||
}
|
}
|
||||||
|
@ -391,18 +391,6 @@ Event_ReadyStart::Event_ReadyStart(int _gameId, int _playerId)
|
||||||
: GameEvent("ready_start", _gameId, _playerId)
|
: GameEvent("ready_start", _gameId, _playerId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Event_SetupZones::Event_SetupZones(int _gameId, int _playerId, int _deckSize, int _sbSize)
|
|
||||||
: GameEvent("setup_zones", _gameId, _playerId), deckSize(_deckSize), sbSize(_sbSize)
|
|
||||||
{
|
|
||||||
setParameter("deck_size", deckSize);
|
|
||||||
setParameter("sb_size", sbSize);
|
|
||||||
}
|
|
||||||
void Event_SetupZones::extractParameters()
|
|
||||||
{
|
|
||||||
GameEvent::extractParameters();
|
|
||||||
deckSize = parameters["deck_size"].toInt();
|
|
||||||
sbSize = parameters["sb_size"].toInt();
|
|
||||||
}
|
|
||||||
Event_GameStart::Event_GameStart(int _gameId, int _playerId)
|
Event_GameStart::Event_GameStart(int _gameId, int _playerId)
|
||||||
: GameEvent("game_start", _gameId, _playerId)
|
: GameEvent("game_start", _gameId, _playerId)
|
||||||
{
|
{
|
||||||
|
@ -467,7 +455,7 @@ void Event_CreateToken::extractParameters()
|
||||||
x = parameters["x"].toInt();
|
x = parameters["x"].toInt();
|
||||||
y = parameters["y"].toInt();
|
y = parameters["y"].toInt();
|
||||||
}
|
}
|
||||||
Event_CreateArrow::Event_CreateArrow(int _gameId, int _playerId, int _arrowId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, int _color)
|
Event_CreateArrow::Event_CreateArrow(int _gameId, int _playerId, int _arrowId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color)
|
||||||
: GameEvent("create_arrow", _gameId, _playerId), arrowId(_arrowId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color)
|
: GameEvent("create_arrow", _gameId, _playerId), arrowId(_arrowId), startPlayerId(_startPlayerId), startZone(_startZone), startCardId(_startCardId), targetPlayerId(_targetPlayerId), targetZone(_targetZone), targetCardId(_targetCardId), color(_color)
|
||||||
{
|
{
|
||||||
setParameter("arrow_id", arrowId);
|
setParameter("arrow_id", arrowId);
|
||||||
|
@ -489,7 +477,7 @@ void Event_CreateArrow::extractParameters()
|
||||||
targetPlayerId = parameters["target_player_id"].toInt();
|
targetPlayerId = parameters["target_player_id"].toInt();
|
||||||
targetZone = parameters["target_zone"];
|
targetZone = parameters["target_zone"];
|
||||||
targetCardId = parameters["target_card_id"].toInt();
|
targetCardId = parameters["target_card_id"].toInt();
|
||||||
color = parameters["color"].toInt();
|
color = ColorConverter::colorFromInt(parameters["color"].toInt());
|
||||||
}
|
}
|
||||||
Event_DeleteArrow::Event_DeleteArrow(int _gameId, int _playerId, int _arrowId)
|
Event_DeleteArrow::Event_DeleteArrow(int _gameId, int _playerId, int _arrowId)
|
||||||
: GameEvent("delete_arrow", _gameId, _playerId), arrowId(_arrowId)
|
: GameEvent("delete_arrow", _gameId, _playerId), arrowId(_arrowId)
|
||||||
|
@ -517,7 +505,7 @@ void Event_SetCardAttr::extractParameters()
|
||||||
attrName = parameters["attr_name"];
|
attrName = parameters["attr_name"];
|
||||||
attrValue = parameters["attr_value"];
|
attrValue = parameters["attr_value"];
|
||||||
}
|
}
|
||||||
Event_AddCounter::Event_AddCounter(int _gameId, int _playerId, int _counterId, const QString &_counterName, int _color, int _radius, int _value)
|
Event_AddCounter::Event_AddCounter(int _gameId, int _playerId, int _counterId, const QString &_counterName, const QColor &_color, int _radius, int _value)
|
||||||
: GameEvent("add_counter", _gameId, _playerId), counterId(_counterId), counterName(_counterName), color(_color), radius(_radius), value(_value)
|
: GameEvent("add_counter", _gameId, _playerId), counterId(_counterId), counterName(_counterName), color(_color), radius(_radius), value(_value)
|
||||||
{
|
{
|
||||||
setParameter("counter_id", counterId);
|
setParameter("counter_id", counterId);
|
||||||
|
@ -531,7 +519,7 @@ void Event_AddCounter::extractParameters()
|
||||||
GameEvent::extractParameters();
|
GameEvent::extractParameters();
|
||||||
counterId = parameters["counter_id"].toInt();
|
counterId = parameters["counter_id"].toInt();
|
||||||
counterName = parameters["counter_name"];
|
counterName = parameters["counter_name"];
|
||||||
color = parameters["color"].toInt();
|
color = ColorConverter::colorFromInt(parameters["color"].toInt());
|
||||||
radius = parameters["radius"].toInt();
|
radius = parameters["radius"].toInt();
|
||||||
value = parameters["value"].toInt();
|
value = parameters["value"].toInt();
|
||||||
}
|
}
|
||||||
|
@ -613,6 +601,20 @@ void Event_ServerMessage::extractParameters()
|
||||||
GenericEvent::extractParameters();
|
GenericEvent::extractParameters();
|
||||||
message = parameters["message"];
|
message = parameters["message"];
|
||||||
}
|
}
|
||||||
|
Event_GameJoined::Event_GameJoined(int _gameId, int _playerId, bool _spectator)
|
||||||
|
: GenericEvent("game_joined"), gameId(_gameId), playerId(_playerId), spectator(_spectator)
|
||||||
|
{
|
||||||
|
setParameter("game_id", gameId);
|
||||||
|
setParameter("player_id", playerId);
|
||||||
|
setParameter("spectator", spectator);
|
||||||
|
}
|
||||||
|
void Event_GameJoined::extractParameters()
|
||||||
|
{
|
||||||
|
GenericEvent::extractParameters();
|
||||||
|
gameId = parameters["game_id"].toInt();
|
||||||
|
playerId = parameters["player_id"].toInt();
|
||||||
|
spectator = (parameters["spectator"] == "1");
|
||||||
|
}
|
||||||
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
|
Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
|
||||||
: ChatEvent("chat_join_channel", _channel), playerName(_playerName)
|
: ChatEvent("chat_join_channel", _channel), playerName(_playerName)
|
||||||
{
|
{
|
||||||
|
@ -687,7 +689,6 @@ void ProtocolItem::initializeHashAuto()
|
||||||
itemNameHash.insert("game_eventdeck_select", Event_DeckSelect::newItem);
|
itemNameHash.insert("game_eventdeck_select", Event_DeckSelect::newItem);
|
||||||
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
||||||
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
|
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
|
||||||
itemNameHash.insert("game_eventsetup_zones", Event_SetupZones::newItem);
|
|
||||||
itemNameHash.insert("game_eventgame_start", Event_GameStart::newItem);
|
itemNameHash.insert("game_eventgame_start", Event_GameStart::newItem);
|
||||||
itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem);
|
itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem);
|
||||||
itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem);
|
itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem);
|
||||||
|
@ -704,6 +705,7 @@ void ProtocolItem::initializeHashAuto()
|
||||||
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem);
|
||||||
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
|
||||||
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
|
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem);
|
||||||
|
itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem);
|
||||||
itemNameHash.insert("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
|
itemNameHash.insert("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem);
|
||||||
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
|
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
|
||||||
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);
|
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
2:draw_cards:i,number
|
2:draw_cards:i,number
|
||||||
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
|
2:move_card:s,start_zone:i,card_id:s,target_zone:i,x:i,y:b,face_down
|
||||||
2:create_token:s,zone:s,card_name:s,pt:i,x:i,y
|
2:create_token:s,zone:s,card_name:s,pt:i,x:i,y
|
||||||
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:i,color
|
2:create_arrow:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:c,color
|
||||||
2:delete_arrow:i,arrow_id
|
2:delete_arrow:i,arrow_id
|
||||||
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||||
2:ready_start
|
2:ready_start
|
||||||
2:inc_counter:i,counter_id:i,delta
|
2:inc_counter:i,counter_id:i,delta
|
||||||
2:add_counter:s,counter_name:i,color:i,radius:i,value
|
2:add_counter:s,counter_name:c,color:i,radius:i,value
|
||||||
2:set_counter:i,counter_id:i,value
|
2:set_counter:i,counter_id:i,value
|
||||||
2:del_counter:i,counter_id
|
2:del_counter:i,counter_id
|
||||||
2:next_turn
|
2:next_turn
|
||||||
|
@ -38,16 +38,15 @@
|
||||||
3:deck_select:i,deck_id
|
3:deck_select:i,deck_id
|
||||||
3:game_closed
|
3:game_closed
|
||||||
3:ready_start
|
3:ready_start
|
||||||
3:setup_zones:i,deck_size:i,sb_size
|
|
||||||
3:game_start
|
3:game_start
|
||||||
3:shuffle
|
3:shuffle
|
||||||
3:roll_die:i,sides:i,value
|
3:roll_die:i,sides:i,value
|
||||||
3:move_card:i,card_id:s,card_name:s,start_zone:i,position:s,target_zone:i,x:i,y:b,face_down
|
3:move_card:i,card_id:s,card_name:s,start_zone:i,position:s,target_zone:i,x:i,y:b,face_down
|
||||||
3:create_token:s,zone:i,card_id:s,card_name:s,pt:i,x:i,y
|
3:create_token:s,zone:i,card_id:s,card_name:s,pt:i,x:i,y
|
||||||
3:create_arrow:i,arrow_id:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:i,color
|
3:create_arrow:i,arrow_id:i,start_player_id:s,start_zone:i,start_card_id:i,target_player_id:s,target_zone:i,target_card_id:c,color
|
||||||
3:delete_arrow:i,arrow_id
|
3:delete_arrow:i,arrow_id
|
||||||
3:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
3:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||||
3:add_counter:i,counter_id:s,counter_name:i,color:i,radius:i,value
|
3:add_counter:i,counter_id:s,counter_name:c,color:i,radius:i,value
|
||||||
3:set_counter:i,counter_id:i,value
|
3:set_counter:i,counter_id:i,value
|
||||||
3:del_counter:i,counter_id
|
3:del_counter:i,counter_id
|
||||||
3:set_active_player:i,active_player_id
|
3:set_active_player:i,active_player_id
|
||||||
|
@ -55,6 +54,7 @@
|
||||||
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
|
||||||
3:stop_dump_zone:i,zone_owner_id:s,zone
|
3:stop_dump_zone:i,zone_owner_id:s,zone
|
||||||
4:server_message:s,message
|
4:server_message:s,message
|
||||||
|
4:game_joined:i,game_id:i,player_id:b,spectator
|
||||||
5:chat_join_channel:s,player_name
|
5:chat_join_channel:s,player_name
|
||||||
5:chat_leave_channel:s,player_name
|
5:chat_leave_channel:s,player_name
|
||||||
5:chat_say:s,player_name:s,message
|
5:chat_say:s,player_name:s,message
|
|
@ -268,16 +268,16 @@ private:
|
||||||
int targetPlayerId;
|
int targetPlayerId;
|
||||||
QString targetZone;
|
QString targetZone;
|
||||||
int targetCardId;
|
int targetCardId;
|
||||||
int color;
|
QColor color;
|
||||||
public:
|
public:
|
||||||
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, int _color = -1);
|
Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
|
||||||
int getStartPlayerId() const { return startPlayerId; }
|
int getStartPlayerId() const { return startPlayerId; }
|
||||||
QString getStartZone() const { return startZone; }
|
QString getStartZone() const { return startZone; }
|
||||||
int getStartCardId() const { return startCardId; }
|
int getStartCardId() const { return startCardId; }
|
||||||
int getTargetPlayerId() const { return targetPlayerId; }
|
int getTargetPlayerId() const { return targetPlayerId; }
|
||||||
QString getTargetZone() const { return targetZone; }
|
QString getTargetZone() const { return targetZone; }
|
||||||
int getTargetCardId() const { return targetCardId; }
|
int getTargetCardId() const { return targetCardId; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
static ProtocolItem *newItem() { return new Command_CreateArrow; }
|
static ProtocolItem *newItem() { return new Command_CreateArrow; }
|
||||||
int getItemId() const { return ItemId_Command_CreateArrow; }
|
int getItemId() const { return ItemId_Command_CreateArrow; }
|
||||||
protected:
|
protected:
|
||||||
|
@ -339,13 +339,13 @@ class Command_AddCounter : public GameCommand {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
QString counterName;
|
QString counterName;
|
||||||
int color;
|
QColor color;
|
||||||
int radius;
|
int radius;
|
||||||
int value;
|
int value;
|
||||||
public:
|
public:
|
||||||
Command_AddCounter(int _gameId = -1, const QString &_counterName = QString(), int _color = -1, int _radius = -1, int _value = -1);
|
Command_AddCounter(int _gameId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1);
|
||||||
QString getCounterName() const { return counterName; }
|
QString getCounterName() const { return counterName; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Command_AddCounter; }
|
static ProtocolItem *newItem() { return new Command_AddCounter; }
|
||||||
|
@ -499,20 +499,6 @@ public:
|
||||||
static ProtocolItem *newItem() { return new Event_ReadyStart; }
|
static ProtocolItem *newItem() { return new Event_ReadyStart; }
|
||||||
int getItemId() const { return ItemId_Event_ReadyStart; }
|
int getItemId() const { return ItemId_Event_ReadyStart; }
|
||||||
};
|
};
|
||||||
class Event_SetupZones : public GameEvent {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
int deckSize;
|
|
||||||
int sbSize;
|
|
||||||
public:
|
|
||||||
Event_SetupZones(int _gameId = -1, int _playerId = -1, int _deckSize = -1, int _sbSize = -1);
|
|
||||||
int getDeckSize() const { return deckSize; }
|
|
||||||
int getSbSize() const { return sbSize; }
|
|
||||||
static ProtocolItem *newItem() { return new Event_SetupZones; }
|
|
||||||
int getItemId() const { return ItemId_Event_SetupZones; }
|
|
||||||
protected:
|
|
||||||
void extractParameters();
|
|
||||||
};
|
|
||||||
class Event_GameStart : public GameEvent {
|
class Event_GameStart : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
@ -601,9 +587,9 @@ private:
|
||||||
int targetPlayerId;
|
int targetPlayerId;
|
||||||
QString targetZone;
|
QString targetZone;
|
||||||
int targetCardId;
|
int targetCardId;
|
||||||
int color;
|
QColor color;
|
||||||
public:
|
public:
|
||||||
Event_CreateArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, int _color = -1);
|
Event_CreateArrow(int _gameId = -1, int _playerId = -1, int _arrowId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor());
|
||||||
int getArrowId() const { return arrowId; }
|
int getArrowId() const { return arrowId; }
|
||||||
int getStartPlayerId() const { return startPlayerId; }
|
int getStartPlayerId() const { return startPlayerId; }
|
||||||
QString getStartZone() const { return startZone; }
|
QString getStartZone() const { return startZone; }
|
||||||
|
@ -611,7 +597,7 @@ public:
|
||||||
int getTargetPlayerId() const { return targetPlayerId; }
|
int getTargetPlayerId() const { return targetPlayerId; }
|
||||||
QString getTargetZone() const { return targetZone; }
|
QString getTargetZone() const { return targetZone; }
|
||||||
int getTargetCardId() const { return targetCardId; }
|
int getTargetCardId() const { return targetCardId; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
static ProtocolItem *newItem() { return new Event_CreateArrow; }
|
static ProtocolItem *newItem() { return new Event_CreateArrow; }
|
||||||
int getItemId() const { return ItemId_Event_CreateArrow; }
|
int getItemId() const { return ItemId_Event_CreateArrow; }
|
||||||
protected:
|
protected:
|
||||||
|
@ -652,14 +638,14 @@ class Event_AddCounter : public GameEvent {
|
||||||
private:
|
private:
|
||||||
int counterId;
|
int counterId;
|
||||||
QString counterName;
|
QString counterName;
|
||||||
int color;
|
QColor color;
|
||||||
int radius;
|
int radius;
|
||||||
int value;
|
int value;
|
||||||
public:
|
public:
|
||||||
Event_AddCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1, const QString &_counterName = QString(), int _color = -1, int _radius = -1, int _value = -1);
|
Event_AddCounter(int _gameId = -1, int _playerId = -1, int _counterId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1);
|
||||||
int getCounterId() const { return counterId; }
|
int getCounterId() const { return counterId; }
|
||||||
QString getCounterName() const { return counterName; }
|
QString getCounterName() const { return counterName; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getValue() const { return value; }
|
int getValue() const { return value; }
|
||||||
static ProtocolItem *newItem() { return new Event_AddCounter; }
|
static ProtocolItem *newItem() { return new Event_AddCounter; }
|
||||||
|
@ -759,6 +745,22 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void extractParameters();
|
void extractParameters();
|
||||||
};
|
};
|
||||||
|
class Event_GameJoined : public GenericEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
int gameId;
|
||||||
|
int playerId;
|
||||||
|
bool spectator;
|
||||||
|
public:
|
||||||
|
Event_GameJoined(int _gameId = -1, int _playerId = -1, bool _spectator = false);
|
||||||
|
int getGameId() const { return gameId; }
|
||||||
|
int getPlayerId() const { return playerId; }
|
||||||
|
bool getSpectator() const { return spectator; }
|
||||||
|
static ProtocolItem *newItem() { return new Event_GameJoined; }
|
||||||
|
int getItemId() const { return ItemId_Event_GameJoined; }
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
};
|
||||||
class Event_ChatJoinChannel : public ChatEvent {
|
class Event_ChatJoinChannel : public ChatEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -102,6 +102,11 @@ while (<file>) {
|
||||||
$constructorParamsH .= "int _$prettyVarName = -1";
|
$constructorParamsH .= "int _$prettyVarName = -1";
|
||||||
$constructorParamsCpp .= "int _$prettyVarName";
|
$constructorParamsCpp .= "int _$prettyVarName";
|
||||||
$paramStr5 .= "\t$prettyVarName = parameters[\"$value\"].toInt();\n";
|
$paramStr5 .= "\t$prettyVarName = parameters[\"$value\"].toInt();\n";
|
||||||
|
} elsif ($key eq 'c') {
|
||||||
|
$dataType = 'QColor';
|
||||||
|
$constructorParamsH .= "const QColor &_$prettyVarName = QColor()";
|
||||||
|
$constructorParamsCpp .= "const QColor &_$prettyVarName";
|
||||||
|
$paramStr5 .= "\t$prettyVarName = ColorConverter::colorFromInt(parameters[\"$value\"].toInt());\n";
|
||||||
}
|
}
|
||||||
($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
|
($prettyVarName2 = $prettyVarName) =~ s/^(.)/\U$1\E/;
|
||||||
$paramStr4 .= "\t$dataType get$prettyVarName2() const { return $prettyVarName; }\n";
|
$paramStr4 .= "\t$dataType get$prettyVarName2() const { return $prettyVarName; }\n";
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
#ifndef SERVER_ARROW_H
|
#ifndef SERVER_ARROW_H
|
||||||
#define SERVER_ARROW_H
|
#define SERVER_ARROW_H
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
class Server_Card;
|
class Server_Card;
|
||||||
|
|
||||||
class Server_Arrow {
|
class Server_Arrow {
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
Server_Card *startCard, *targetCard;
|
Server_Card *startCard, *targetCard;
|
||||||
int color;
|
QColor color;
|
||||||
public:
|
public:
|
||||||
Server_Arrow(int _id, Server_Card *_startCard, Server_Card *_targetCard, int _color)
|
Server_Arrow(int _id, Server_Card *_startCard, Server_Card *_targetCard, const QColor &_color)
|
||||||
: id(_id), startCard(_startCard), targetCard(_targetCard), color(_color) { }
|
: id(_id), startCard(_startCard), targetCard(_targetCard), color(_color) { }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
Server_Card *getStartCard() const { return startCard; }
|
Server_Card *getStartCard() const { return startCard; }
|
||||||
Server_Card *getTargetCard() const { return targetCard; }
|
Server_Card *getTargetCard() const { return targetCard; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -21,20 +21,21 @@
|
||||||
#define SERVER_COUNTER_H
|
#define SERVER_COUNTER_H
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
class Server_Counter {
|
class Server_Counter {
|
||||||
protected:
|
protected:
|
||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
int color;
|
QColor color;
|
||||||
int radius;
|
int radius;
|
||||||
int count;
|
int count;
|
||||||
public:
|
public:
|
||||||
Server_Counter(int _id, const QString &_name, int _color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
|
Server_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { }
|
||||||
~Server_Counter() { }
|
~Server_Counter() { }
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
int getColor() const { return color; }
|
QColor getColor() const { return color; }
|
||||||
int getRadius() const { return radius; }
|
int getRadius() const { return radius; }
|
||||||
int getCount() const { return count; }
|
int getCount() const { return count; }
|
||||||
void setCount(int _count) { count = _count; }
|
void setCount(int _count) { count = _count; }
|
||||||
|
|
|
@ -54,8 +54,16 @@ void Server_Game::startGameIfReady()
|
||||||
return;
|
return;
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
while (playerIterator.hasNext())
|
while (playerIterator.hasNext())
|
||||||
if (playerIterator.next().value()->getStatus() != StatusReadyStart)
|
if (!playerIterator.next().value()->getReadyStart())
|
||||||
return;
|
return;
|
||||||
|
playerIterator.toFront();
|
||||||
|
while (playerIterator.hasNext())
|
||||||
|
playerIterator.next().value()->setupZones();
|
||||||
|
playerIterator.toFront();
|
||||||
|
while (playerIterator.hasNext()) {
|
||||||
|
Server_Player *player = playerIterator.next().value();
|
||||||
|
player->sendProtocolItem(new Event_GameStateChanged(gameId, getGameState(player)));
|
||||||
|
}
|
||||||
|
|
||||||
/* QSqlQuery query;
|
/* QSqlQuery query;
|
||||||
query.prepare("insert into games (id, descr, password, time_started) values(:id, :descr, :password, now())");
|
query.prepare("insert into games (id, descr, password, time_started) values(:id, :descr, :password, now())");
|
||||||
|
@ -71,8 +79,6 @@ void Server_Game::startGameIfReady()
|
||||||
query.bindValue(":id", gameId);
|
query.bindValue(":id", gameId);
|
||||||
query.bindValue(":player", player->getPlayerName());
|
query.bindValue(":player", player->getPlayerName());
|
||||||
query.exec();
|
query.exec();
|
||||||
|
|
||||||
player->setupZones();
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
gameStarted = true;
|
gameStarted = true;
|
||||||
|
@ -160,7 +166,7 @@ void Server_Game::setActivePhase(int _activePhase)
|
||||||
sendGameEvent(new Event_SetActivePhase(-1, -1, activePhase));
|
sendGameEvent(new Event_SetActivePhase(-1, -1, activePhase));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ServerInfo_Player *> Server_Game::getGameState() const
|
QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAsking) const
|
||||||
{
|
{
|
||||||
QList<ServerInfo_Player *> result;
|
QList<ServerInfo_Player *> result;
|
||||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||||
|
@ -195,11 +201,16 @@ QList<ServerInfo_Player *> Server_Game::getGameState() const
|
||||||
while (zoneIterator.hasNext()) {
|
while (zoneIterator.hasNext()) {
|
||||||
Server_CardZone *zone = zoneIterator.next().value();
|
Server_CardZone *zone = zoneIterator.next().value();
|
||||||
QList<ServerInfo_Card *> cardList;
|
QList<ServerInfo_Card *> cardList;
|
||||||
|
if (
|
||||||
|
((playerWhosAsking == player) && (zone->getType() != HiddenZone))
|
||||||
|
|| ((playerWhosAsking != player) && (zone->getType() == PublicZone))
|
||||||
|
) {
|
||||||
QListIterator<Server_Card *> cardIterator(zone->cards);
|
QListIterator<Server_Card *> cardIterator(zone->cards);
|
||||||
while (cardIterator.hasNext()) {
|
while (cardIterator.hasNext()) {
|
||||||
Server_Card *card = cardIterator.next();
|
Server_Card *card = cardIterator.next();
|
||||||
cardList.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getCounters(), card->getTapped(), card->getAttacking(), card->getAnnotation()));
|
cardList.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getCounters(), card->getTapped(), card->getAttacking(), card->getAnnotation()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList));
|
zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
void setActivePlayer(int _activePlayer);
|
void setActivePlayer(int _activePlayer);
|
||||||
void setActivePhase(int _activePhase);
|
void setActivePhase(int _activePhase);
|
||||||
|
|
||||||
QList<ServerInfo_Player *> getGameState() const;
|
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
|
||||||
void sendGameEvent(GameEvent *event);
|
void sendGameEvent(GameEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler)
|
Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler)
|
||||||
: game(_game), handler(_handler), deck(0), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0), PlayerStatus(StatusNormal)
|
: game(_game), handler(_handler), deck(0), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,6 @@ void Server_Player::setupZones()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deckZone->shuffle();
|
deckZone->shuffle();
|
||||||
|
|
||||||
PlayerStatus = StatusPlaying;
|
|
||||||
game->sendGameEvent(new Event_SetupZones(-1, playerId, deckZone->cards.size(), sbZone->cards.size()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Player::clearZones()
|
void Server_Player::clearZones()
|
||||||
|
|
|
@ -14,8 +14,6 @@ class Server_Arrow;
|
||||||
class Server_ProtocolHandler;
|
class Server_ProtocolHandler;
|
||||||
class ProtocolItem;
|
class ProtocolItem;
|
||||||
|
|
||||||
enum PlayerStatusEnum { StatusNormal, StatusSubmitDeck, StatusReadyStart, StatusPlaying };
|
|
||||||
|
|
||||||
class Server_Player : public QObject {
|
class Server_Player : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
@ -30,14 +28,14 @@ private:
|
||||||
bool spectator;
|
bool spectator;
|
||||||
int nextCardId;
|
int nextCardId;
|
||||||
void clearZones();
|
void clearZones();
|
||||||
PlayerStatusEnum PlayerStatus;
|
bool readyStart;
|
||||||
public:
|
public:
|
||||||
Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler);
|
Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler);
|
||||||
void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; }
|
void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; }
|
||||||
|
|
||||||
void setStatus(PlayerStatusEnum _status) { PlayerStatus = _status; }
|
|
||||||
void setPlayerId(int _id) { playerId = _id; }
|
void setPlayerId(int _id) { playerId = _id; }
|
||||||
PlayerStatusEnum getStatus() { return PlayerStatus; }
|
bool getReadyStart() const { return readyStart; }
|
||||||
|
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
||||||
int getPlayerId() const { return playerId; }
|
int getPlayerId() const { return playerId; }
|
||||||
bool getSpectator() const { return spectator; }
|
bool getSpectator() const { return spectator; }
|
||||||
QString getPlayerName() const { return playerName; }
|
QString getPlayerName() const { return playerName; }
|
||||||
|
|
|
@ -218,9 +218,11 @@ ResponseCode Server_ProtocolHandler::cmdListGames(Command_ListGames * /*cmd*/)
|
||||||
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
|
ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd)
|
||||||
{
|
{
|
||||||
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
|
Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
|
||||||
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
|
Server_Player *creator = game->getCreator();
|
||||||
|
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, creator));
|
||||||
|
|
||||||
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), game->getCreator()->getPlayerId(), false, game->getGameState()));
|
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), creator->getPlayerId(), false));
|
||||||
|
enqueueProtocolItem(new Event_GameStateChanged(game->getGameId(), game->getGameState(creator)));
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +236,8 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
|
||||||
if (result == RespOk) {
|
if (result == RespOk) {
|
||||||
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
|
Server_Player *player = g->addPlayer(this, cmd->getSpectator());
|
||||||
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
|
||||||
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), player->getPlayerId(), cmd->getSpectator(), g->getGameState()));
|
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), player->getPlayerId(), cmd->getSpectator()));
|
||||||
|
enqueueProtocolItem(new Event_GameStateChanged(cmd->getGameId(), g->getGameState(player)));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -346,20 +349,13 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_G
|
||||||
|
|
||||||
// The player does not get to see which card he moved if it moves between two parts of hidden zones which
|
// 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.
|
// are not being looked at.
|
||||||
QString privateCardId = QString::number(card->getId());
|
int privateCardId = card->getId();
|
||||||
if (!targetBeingLookedAt && !sourceBeingLookedAt) {
|
if (!targetBeingLookedAt && !sourceBeingLookedAt) {
|
||||||
privateCardId = QString();
|
privateCardId = -1;
|
||||||
privateCardName = QString();
|
privateCardName = QString();
|
||||||
}
|
}
|
||||||
/* player->privateEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId)
|
player->sendProtocolItem(new Event_MoveCard(game->getGameId(), player->getPlayerId(), privateCardId, privateCardName, startzone->getName(), position, targetzone->getName(), x, y, facedown));
|
||||||
.arg(privateCardName)
|
|
||||||
.arg(startzone->getName())
|
|
||||||
.arg(position)
|
|
||||||
.arg(targetzone->getName())
|
|
||||||
.arg(x)
|
|
||||||
.arg(y)
|
|
||||||
.arg(facedown ? 1 : 0));
|
|
||||||
*/
|
|
||||||
// Other players do not get to see the start and/or target position of the card if the respective
|
// 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,
|
// part of the zone is being looked at. The information is not needed anyway because in hidden zones,
|
||||||
// all cards are equal.
|
// all cards are equal.
|
||||||
|
@ -368,22 +364,11 @@ ResponseCode Server_ProtocolHandler::cmdMoveCard(Command_MoveCard *cmd, Server_G
|
||||||
if ((targetzone->getType() == HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1)))
|
if ((targetzone->getType() == HiddenZone) && ((targetzone->getCardsBeingLookedAt() > x) || (targetzone->getCardsBeingLookedAt() == -1)))
|
||||||
x = -1;
|
x = -1;
|
||||||
|
|
||||||
/* if ((startzone->getType() == Server_CardZone::PublicZone) || (targetzone->getType() == Server_CardZone::PublicZone))
|
if ((startzone->getType() == PublicZone) || (targetzone->getType() == PublicZone))
|
||||||
game->broadcastEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(card->getId())
|
game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), card->getId(), publicCardName, startzone->getName(), position, targetzone->getName(), x, y, facedown));
|
||||||
.arg(publicCardName)
|
|
||||||
.arg(startzone->getName())
|
|
||||||
.arg(position)
|
|
||||||
.arg(targetzone->getName())
|
|
||||||
.arg(x)
|
|
||||||
.arg(y)
|
|
||||||
.arg(facedown ? 1 : 0), player);
|
|
||||||
else
|
else
|
||||||
game->broadcastEvent(QString("move_card|||%1|%2|%3|%4|%5|0").arg(startzone->getName())
|
game->sendGameEvent(new Event_MoveCard(-1, player->getPlayerId(), -1, QString(), startzone->getName(), position, targetzone->getName(), x, y, false));
|
||||||
.arg(position)
|
|
||||||
.arg(targetzone->getName())
|
|
||||||
.arg(x)
|
|
||||||
.arg(y), player);
|
|
||||||
*/
|
|
||||||
// If the card was moved to another zone, delete all arrows from and to the card
|
// If the card was moved to another zone, delete all arrows from and to the card
|
||||||
if (startzone != targetzone) {
|
if (startzone != targetzone) {
|
||||||
const QList<Server_Player *> &players = game->getPlayers();
|
const QList<Server_Player *> &players = game->getPlayers();
|
||||||
|
@ -493,7 +478,7 @@ ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/,
|
||||||
if (!player->getDeck())
|
if (!player->getDeck())
|
||||||
return RespContextError;
|
return RespContextError;
|
||||||
|
|
||||||
player->setStatus(StatusReadyStart);
|
player->setReadyStart(true);
|
||||||
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
||||||
game->startGameIfReady();
|
game->startGameIfReady();
|
||||||
return RespOk;
|
return RespOk;
|
||||||
|
|
Loading…
Reference in a new issue