implemented conceding
This commit is contained in:
parent
207d10d3e2
commit
78c1851c52
18 changed files with 168 additions and 51 deletions
|
@ -92,6 +92,11 @@ void MessageLogWidget::logReadyStart(Player *player)
|
|||
append(tr("%1 is ready to start the game.").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logConcede(Player *player)
|
||||
{
|
||||
append(tr("%1 has conceded the game.").arg(sanitizeHtml(player->getName())));
|
||||
}
|
||||
|
||||
void MessageLogWidget::logGameStart()
|
||||
{
|
||||
append(tr("The game has started."));
|
||||
|
@ -283,6 +288,7 @@ void MessageLogWidget::connectToPlayer(Player *player)
|
|||
connect(player, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));
|
||||
connect(player, SIGNAL(logDeckSelect(Player *, int)), this, SLOT(logDeckSelect(Player *, int)));
|
||||
connect(player, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *)));
|
||||
connect(player, SIGNAL(logConcede(Player *)), this, SLOT(logConcede(Player *)));
|
||||
connect(player, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
||||
connect(player, SIGNAL(logRollDie(Player *, int, int)), this, SLOT(logRollDie(Player *, int, int)));
|
||||
connect(player, SIGNAL(logCreateArrow(Player *, Player *, QString, Player *, QString)), this, SLOT(logCreateArrow(Player *, Player *, QString, Player *, QString)));
|
||||
|
|
|
@ -30,6 +30,7 @@ public slots:
|
|||
void logLeaveSpectator(QString name);
|
||||
void logDeckSelect(Player *player, int deckId);
|
||||
void logReadyStart(Player *player);
|
||||
void logConcede(Player *player);
|
||||
void logGameStart();
|
||||
void logSay(Player *player, QString message);
|
||||
void logShuffle(Player *player);
|
||||
|
|
|
@ -438,6 +438,11 @@ void Player::eventReadyStart(Event_ReadyStart * /*event*/)
|
|||
emit logReadyStart(this);
|
||||
}
|
||||
|
||||
void Player::eventConcede(Event_Concede * /*event*/)
|
||||
{
|
||||
emit logConcede(this);
|
||||
}
|
||||
|
||||
void Player::eventShuffle(Event_Shuffle * /*event*/)
|
||||
{
|
||||
emit logShuffle(this);
|
||||
|
@ -619,6 +624,7 @@ void Player::processGameEvent(GameEvent *event)
|
|||
case ItemId_Event_DeckSelect: eventDeckSelect(qobject_cast<Event_DeckSelect *>(event)); break;
|
||||
case ItemId_Event_Say: eventSay(qobject_cast<Event_Say *>(event)); break;
|
||||
case ItemId_Event_ReadyStart: eventReadyStart(qobject_cast<Event_ReadyStart *>(event)); break;
|
||||
case ItemId_Event_Concede: eventConcede(qobject_cast<Event_Concede *>(event)); break;
|
||||
case ItemId_Event_Shuffle: eventShuffle(qobject_cast<Event_Shuffle *>(event)); break;
|
||||
case ItemId_Event_RollDie: eventRollDie(qobject_cast<Event_RollDie *>(event)); break;
|
||||
case ItemId_Event_CreateArrows: eventCreateArrows(qobject_cast<Event_CreateArrows *>(event)); break;
|
||||
|
|
|
@ -25,6 +25,7 @@ class GameEvent;
|
|||
class Event_DeckSelect;
|
||||
class Event_Say;
|
||||
class Event_ReadyStart;
|
||||
class Event_Concede;
|
||||
class Event_Shuffle;
|
||||
class Event_RollDie;
|
||||
class Event_CreateArrows;
|
||||
|
@ -50,6 +51,7 @@ signals:
|
|||
void logDeckSelect(Player *player, int deckId);
|
||||
void logSay(Player *player, QString message);
|
||||
void logReadyStart(Player *player);
|
||||
void logConcede(Player *player);
|
||||
void logShuffle(Player *player);
|
||||
void logRollDie(Player *player, int sides, int roll);
|
||||
void logCreateArrow(Player *player, Player *startPlayer, QString startCard, Player *targetPlayer, QString targetCard);
|
||||
|
@ -116,6 +118,7 @@ private:
|
|||
void eventDeckSelect(Event_DeckSelect *event);
|
||||
void eventSay(Event_Say *event);
|
||||
void eventReadyStart(Event_ReadyStart *event);
|
||||
void eventConcede(Event_Concede *event);
|
||||
void eventShuffle(Event_Shuffle *event);
|
||||
void eventRollDie(Event_RollDie *event);
|
||||
void eventCreateArrows(Event_CreateArrows *event);
|
||||
|
|
|
@ -33,6 +33,7 @@ void RemoteDeckList_TreeWidget::addFileToTree(DeckList_File *file, QTreeWidgetIt
|
|||
newDeck->setData(2, Qt::DisplayRole, file->getUploadTime());
|
||||
|
||||
parent->addChild(newDeck);
|
||||
sortItems(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTreeWidgetItem *parent)
|
||||
|
@ -62,6 +63,7 @@ void RemoteDeckList_TreeWidget::addFolderToTree(DeckList_Directory *folder, QTre
|
|||
else
|
||||
addFileToTree(dynamic_cast<DeckList_File *>(folderItems[i]), newItem);
|
||||
}
|
||||
sortItems(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void RemoteDeckList_TreeWidget::refreshTree()
|
||||
|
|
|
@ -88,6 +88,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
|||
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
|
||||
aRemoveLocalArrows = new QAction(this);
|
||||
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
|
||||
aConcede = new QAction(this);
|
||||
connect(aConcede, SIGNAL(triggered()), this, SLOT(actConcede()));
|
||||
aLeaveGame = new QAction(this);
|
||||
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
|
||||
|
||||
|
@ -98,6 +100,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
|
|||
tabMenu->addSeparator();
|
||||
tabMenu->addAction(aRemoveLocalArrows);
|
||||
tabMenu->addSeparator();
|
||||
tabMenu->addAction(aConcede);
|
||||
tabMenu->addAction(aLeaveGame);
|
||||
|
||||
retranslateUi();
|
||||
|
@ -120,6 +123,8 @@ void TabGame::retranslateUi()
|
|||
aNextTurn->setShortcuts(QList<QKeySequence>() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter")));
|
||||
aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
|
||||
aRemoveLocalArrows->setShortcut(tr("Ctrl+R"));
|
||||
aConcede->setText(tr("&Concede"));
|
||||
aConcede->setShortcut(tr("F2"));
|
||||
aLeaveGame->setText(tr("&Leave game"));
|
||||
|
||||
loadLocalButton->setText(tr("Load &local deck"));
|
||||
|
@ -136,6 +141,14 @@ void TabGame::retranslateUi()
|
|||
i.next().value()->retranslateUi();
|
||||
}
|
||||
|
||||
void TabGame::actConcede()
|
||||
{
|
||||
if (QMessageBox::question(this, tr("Concede"), tr("Are you sure you want to concede this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
sendGameCommand(new Command_Concede);
|
||||
}
|
||||
|
||||
void TabGame::actLeaveGame()
|
||||
{
|
||||
if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes)
|
||||
|
@ -235,6 +248,15 @@ void TabGame::startGame()
|
|||
phasesToolbar->show();
|
||||
}
|
||||
|
||||
void TabGame::stopGame()
|
||||
{
|
||||
currentPhase = -1;
|
||||
started = false;
|
||||
gameView->hide();
|
||||
phasesToolbar->hide();
|
||||
deckViewContainer->show();
|
||||
}
|
||||
|
||||
void TabGame::eventGameStart(Event_GameStart * /*event*/)
|
||||
{
|
||||
startGame();
|
||||
|
@ -256,11 +278,18 @@ void TabGame::eventGameStateChanged(Event_GameStateChanged *event)
|
|||
playerListWidget->addPlayer(pl);
|
||||
}
|
||||
player->processPlayerInfo(pl);
|
||||
if (player->getLocal() && pl->getDeck()) {
|
||||
Deck_PictureCacher::cachePictures(pl->getDeck(), this);
|
||||
deckView->setDeck(new DeckList(pl->getDeck()));
|
||||
}
|
||||
}
|
||||
if (event->getGameStarted() && !started) {
|
||||
startGame();
|
||||
setActivePlayer(event->getActivePlayer());
|
||||
setActivePhase(event->getActivePhase());
|
||||
} else if (!event->getGameStarted() && started) {
|
||||
stopGame();
|
||||
zoneLayout->clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,13 @@ private:
|
|||
QAction *playersSeparator;
|
||||
QMenu *playersMenu;
|
||||
QAction *aCloseMostRecentZoneView,
|
||||
*aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
||||
*aConcede, *aLeaveGame, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
||||
|
||||
Player *addPlayer(int playerId, const QString &playerName);
|
||||
|
||||
void startGame();
|
||||
void stopGame();
|
||||
|
||||
void eventGameStart(Event_GameStart *event);
|
||||
void eventGameStateChanged(Event_GameStateChanged *event);
|
||||
void eventJoin(Event_Join *event);
|
||||
|
@ -84,6 +86,7 @@ private slots:
|
|||
void deckSelectFinished(ProtocolResponse *r);
|
||||
void newCardAdded(CardItem *card);
|
||||
|
||||
void actConcede();
|
||||
void actLeaveGame();
|
||||
void actRemoveLocalArrows();
|
||||
void actSay();
|
||||
|
|
|
@ -108,12 +108,13 @@ ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_
|
|||
insertItem(new SerializableItem_Color("color", _color));
|
||||
}
|
||||
|
||||
ServerInfo_Player::ServerInfo_Player(int _playerId, const QString &_name, bool _spectator, DeckList *_deck, const QList<ServerInfo_Zone *> &_zoneList, const QList<ServerInfo_Counter *> &_counterList, const QList<ServerInfo_Arrow *> &_arrowList)
|
||||
ServerInfo_Player::ServerInfo_Player(int _playerId, const QString &_name, bool _spectator, bool _conceded, DeckList *_deck, const QList<ServerInfo_Zone *> &_zoneList, const QList<ServerInfo_Counter *> &_counterList, const QList<ServerInfo_Arrow *> &_arrowList)
|
||||
: SerializableItem_Map("player"), zoneList(_zoneList), counterList(_counterList), arrowList(_arrowList)
|
||||
{
|
||||
insertItem(new SerializableItem_Int("player_id", _playerId));
|
||||
insertItem(new SerializableItem_String("name", _name));
|
||||
insertItem(new SerializableItem_Bool("spectator", _spectator));
|
||||
insertItem(new SerializableItem_Bool("conceded", _conceded));
|
||||
if (!_deck)
|
||||
insertItem(new DeckList);
|
||||
else
|
||||
|
|
|
@ -112,11 +112,12 @@ private:
|
|||
protected:
|
||||
void extractData();
|
||||
public:
|
||||
ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), bool _spectator = false, DeckList *_deck = 0, const QList<ServerInfo_Zone *> &_zoneList = QList<ServerInfo_Zone *>(), const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>(), const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
|
||||
ServerInfo_Player(int _playerId = -1, const QString &_name = QString(), bool _spectator = false, bool _conceded = false, DeckList *_deck = 0, const QList<ServerInfo_Zone *> &_zoneList = QList<ServerInfo_Zone *>(), const QList<ServerInfo_Counter *> &_counterList = QList<ServerInfo_Counter *>(), const QList<ServerInfo_Arrow *> &_arrowList = QList<ServerInfo_Arrow *>());
|
||||
static SerializableItem *newItem() { return new ServerInfo_Player; }
|
||||
int getPlayerId() const { return static_cast<SerializableItem_Int *>(itemMap.value("player_id"))->getData(); }
|
||||
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
|
||||
bool getSpectator() const { return static_cast<SerializableItem_Bool *>(itemMap.value("spectator"))->getData(); }
|
||||
bool getConceded() const { return static_cast<SerializableItem_Bool *>(itemMap.value("conceded"))->getData(); }
|
||||
DeckList *getDeck() const;
|
||||
const QList<ServerInfo_Zone *> &getZoneList() const { return zoneList; }
|
||||
const QList<ServerInfo_Counter *> &getCounterList() const { return counterList; }
|
||||
|
|
|
@ -24,36 +24,38 @@ ItemId_Command_CreateArrow = 1022,
|
|||
ItemId_Command_DeleteArrow = 1023,
|
||||
ItemId_Command_SetCardAttr = 1024,
|
||||
ItemId_Command_ReadyStart = 1025,
|
||||
ItemId_Command_IncCounter = 1026,
|
||||
ItemId_Command_CreateCounter = 1027,
|
||||
ItemId_Command_SetCounter = 1028,
|
||||
ItemId_Command_DelCounter = 1029,
|
||||
ItemId_Command_NextTurn = 1030,
|
||||
ItemId_Command_SetActivePhase = 1031,
|
||||
ItemId_Command_DumpZone = 1032,
|
||||
ItemId_Command_StopDumpZone = 1033,
|
||||
ItemId_Event_Say = 1034,
|
||||
ItemId_Event_Leave = 1035,
|
||||
ItemId_Event_DeckSelect = 1036,
|
||||
ItemId_Event_GameClosed = 1037,
|
||||
ItemId_Event_ReadyStart = 1038,
|
||||
ItemId_Event_GameStart = 1039,
|
||||
ItemId_Event_Shuffle = 1040,
|
||||
ItemId_Event_RollDie = 1041,
|
||||
ItemId_Event_MoveCard = 1042,
|
||||
ItemId_Event_CreateToken = 1043,
|
||||
ItemId_Event_DeleteArrow = 1044,
|
||||
ItemId_Event_SetCardAttr = 1045,
|
||||
ItemId_Event_SetCounter = 1046,
|
||||
ItemId_Event_DelCounter = 1047,
|
||||
ItemId_Event_SetActivePlayer = 1048,
|
||||
ItemId_Event_SetActivePhase = 1049,
|
||||
ItemId_Event_DumpZone = 1050,
|
||||
ItemId_Event_StopDumpZone = 1051,
|
||||
ItemId_Event_ServerMessage = 1052,
|
||||
ItemId_Event_GameJoined = 1053,
|
||||
ItemId_Event_ChatJoinChannel = 1054,
|
||||
ItemId_Event_ChatLeaveChannel = 1055,
|
||||
ItemId_Event_ChatSay = 1056,
|
||||
ItemId_Other = 1057
|
||||
ItemId_Command_Concede = 1026,
|
||||
ItemId_Command_IncCounter = 1027,
|
||||
ItemId_Command_CreateCounter = 1028,
|
||||
ItemId_Command_SetCounter = 1029,
|
||||
ItemId_Command_DelCounter = 1030,
|
||||
ItemId_Command_NextTurn = 1031,
|
||||
ItemId_Command_SetActivePhase = 1032,
|
||||
ItemId_Command_DumpZone = 1033,
|
||||
ItemId_Command_StopDumpZone = 1034,
|
||||
ItemId_Event_Say = 1035,
|
||||
ItemId_Event_Leave = 1036,
|
||||
ItemId_Event_DeckSelect = 1037,
|
||||
ItemId_Event_GameClosed = 1038,
|
||||
ItemId_Event_ReadyStart = 1039,
|
||||
ItemId_Event_Concede = 1040,
|
||||
ItemId_Event_GameStart = 1041,
|
||||
ItemId_Event_Shuffle = 1042,
|
||||
ItemId_Event_RollDie = 1043,
|
||||
ItemId_Event_MoveCard = 1044,
|
||||
ItemId_Event_CreateToken = 1045,
|
||||
ItemId_Event_DeleteArrow = 1046,
|
||||
ItemId_Event_SetCardAttr = 1047,
|
||||
ItemId_Event_SetCounter = 1048,
|
||||
ItemId_Event_DelCounter = 1049,
|
||||
ItemId_Event_SetActivePlayer = 1050,
|
||||
ItemId_Event_SetActivePhase = 1051,
|
||||
ItemId_Event_DumpZone = 1052,
|
||||
ItemId_Event_StopDumpZone = 1053,
|
||||
ItemId_Event_ServerMessage = 1054,
|
||||
ItemId_Event_GameJoined = 1055,
|
||||
ItemId_Event_ChatJoinChannel = 1056,
|
||||
ItemId_Event_ChatLeaveChannel = 1057,
|
||||
ItemId_Event_ChatSay = 1058,
|
||||
ItemId_Other = 1059
|
||||
};
|
||||
|
|
|
@ -143,6 +143,10 @@ Command_ReadyStart::Command_ReadyStart(int _gameId)
|
|||
: GameCommand("ready_start", _gameId)
|
||||
{
|
||||
}
|
||||
Command_Concede::Command_Concede(int _gameId)
|
||||
: GameCommand("concede", _gameId)
|
||||
{
|
||||
}
|
||||
Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta)
|
||||
: GameCommand("inc_counter", _gameId)
|
||||
{
|
||||
|
@ -212,6 +216,10 @@ Event_ReadyStart::Event_ReadyStart(int _gameId, int _playerId)
|
|||
: GameEvent("ready_start", _gameId, _playerId)
|
||||
{
|
||||
}
|
||||
Event_Concede::Event_Concede(int _gameId, int _playerId)
|
||||
: GameEvent("concede", _gameId, _playerId)
|
||||
{
|
||||
}
|
||||
Event_GameStart::Event_GameStart(int _gameId, int _playerId)
|
||||
: GameEvent("game_start", _gameId, _playerId)
|
||||
{
|
||||
|
@ -350,6 +358,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("cmddelete_arrow", Command_DeleteArrow::newItem);
|
||||
itemNameHash.insert("cmdset_card_attr", Command_SetCardAttr::newItem);
|
||||
itemNameHash.insert("cmdready_start", Command_ReadyStart::newItem);
|
||||
itemNameHash.insert("cmdconcede", Command_Concede::newItem);
|
||||
itemNameHash.insert("cmdinc_counter", Command_IncCounter::newItem);
|
||||
itemNameHash.insert("cmdcreate_counter", Command_CreateCounter::newItem);
|
||||
itemNameHash.insert("cmdset_counter", Command_SetCounter::newItem);
|
||||
|
@ -363,6 +372,7 @@ void ProtocolItem::initializeHashAuto()
|
|||
itemNameHash.insert("game_eventdeck_select", Event_DeckSelect::newItem);
|
||||
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
||||
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
|
||||
itemNameHash.insert("game_eventconcede", Event_Concede::newItem);
|
||||
itemNameHash.insert("game_eventgame_start", Event_GameStart::newItem);
|
||||
itemNameHash.insert("game_eventshuffle", Event_Shuffle::newItem);
|
||||
itemNameHash.insert("game_eventroll_die", Event_RollDie::newItem);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
2:delete_arrow:i,arrow_id
|
||||
2:set_card_attr:s,zone:i,card_id:s,attr_name:s,attr_value
|
||||
2:ready_start
|
||||
2:concede
|
||||
2:inc_counter:i,counter_id:i,delta
|
||||
2:create_counter:s,counter_name:c,color:i,radius:i,value
|
||||
2:set_counter:i,counter_id:i,value
|
||||
|
@ -36,6 +37,7 @@
|
|||
3:deck_select:i,deck_id
|
||||
3:game_closed
|
||||
3:ready_start
|
||||
3:concede
|
||||
3:game_start
|
||||
3:shuffle
|
||||
3:roll_die:i,sides:i,value
|
||||
|
|
|
@ -220,6 +220,13 @@ public:
|
|||
static SerializableItem *newItem() { return new Command_ReadyStart; }
|
||||
int getItemId() const { return ItemId_Command_ReadyStart; }
|
||||
};
|
||||
class Command_Concede : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Command_Concede(int _gameId = -1);
|
||||
static SerializableItem *newItem() { return new Command_Concede; }
|
||||
int getItemId() const { return ItemId_Command_Concede; }
|
||||
};
|
||||
class Command_IncCounter : public GameCommand {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -328,6 +335,13 @@ public:
|
|||
static SerializableItem *newItem() { return new Event_ReadyStart; }
|
||||
int getItemId() const { return ItemId_Event_ReadyStart; }
|
||||
};
|
||||
class Event_Concede : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Event_Concede(int _gameId = -1, int _playerId = -1);
|
||||
static SerializableItem *newItem() { return new Event_Concede; }
|
||||
int getItemId() const { return ItemId_Event_Concede; }
|
||||
};
|
||||
class Event_GameStart : public GameEvent {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -64,6 +64,8 @@ void Server_Game::startGameIfReady()
|
|||
playerIterator.toFront();
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *player = playerIterator.next().value();
|
||||
player->setConceded(false);
|
||||
player->setReadyStart(false);
|
||||
player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, 0, 0, getGameState(player)));
|
||||
}
|
||||
|
||||
|
@ -87,6 +89,27 @@ void Server_Game::startGameIfReady()
|
|||
setActivePlayer(0);
|
||||
}
|
||||
|
||||
void Server_Game::stopGameIfFinished()
|
||||
{
|
||||
QMapIterator<int, Server_Player *> playerIterator(players);
|
||||
int playing = 0;
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *p = playerIterator.next().value();
|
||||
if (!p->getConceded() && !p->getSpectator())
|
||||
++playing;
|
||||
}
|
||||
if (playing > 1)
|
||||
return;
|
||||
|
||||
gameStarted = false;
|
||||
playerIterator.toFront();
|
||||
while (playerIterator.hasNext()) {
|
||||
Server_Player *player = playerIterator.next().value();
|
||||
player->sendProtocolItem(new Event_GameStateChanged(gameId, gameStarted, -1, -1, getGameState(player)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
|
||||
{
|
||||
if (_password != password)
|
||||
|
@ -215,7 +238,7 @@ QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAs
|
|||
zoneList.append(new ServerInfo_Zone(zone->getName(), zone->getType(), zone->hasCoords(), zone->cards.size(), cardList));
|
||||
}
|
||||
|
||||
result.append(new ServerInfo_Player(player->getPlayerId(), player->getPlayerName(), player->getSpectator(), player->getDeck(), zoneList, counterList, arrowList));
|
||||
result.append(new ServerInfo_Player(player->getPlayerId(), player->getPlayerName(), player->getSpectator(), player->getConceded(), player == playerWhosAsking ? player->getDeck() : 0, zoneList, counterList, arrowList));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true);
|
||||
void removePlayer(Server_Player *player);
|
||||
void startGameIfReady();
|
||||
void stopGameIfFinished();
|
||||
int getActivePlayer() const { return activePlayer; }
|
||||
int getActivePhase() const { return activePhase; }
|
||||
void setActivePlayer(int _activePlayer);
|
||||
|
|
|
@ -29,6 +29,7 @@ private:
|
|||
int nextCardId;
|
||||
void clearZones();
|
||||
bool readyStart;
|
||||
bool conceded;
|
||||
public:
|
||||
Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler);
|
||||
void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; }
|
||||
|
@ -38,6 +39,8 @@ public:
|
|||
void setReadyStart(bool _readyStart) { readyStart = _readyStart; }
|
||||
int getPlayerId() const { return playerId; }
|
||||
bool getSpectator() const { return spectator; }
|
||||
bool getConceded() const { return conceded; }
|
||||
void setConceded(bool _conceded) { conceded = _conceded; }
|
||||
QString getPlayerName() const { return playerName; }
|
||||
void setDeck(DeckList *_deck);
|
||||
DeckList *getDeck() const { return deck; }
|
||||
|
|
|
@ -80,6 +80,8 @@ void Server_ProtocolHandler::processCommand(Command *command)
|
|||
switch (command->getItemId()) {
|
||||
case ItemId_Command_DeckSelect: response = cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), game, player); break;
|
||||
case ItemId_Command_LeaveGame: response = cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), game, player); break;
|
||||
case ItemId_Command_ReadyStart: response = cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), game, player); break;
|
||||
case ItemId_Command_Concede: response = cmdConcede(qobject_cast<Command_Concede *>(command), game, player); break;
|
||||
case ItemId_Command_Say: response = cmdSay(qobject_cast<Command_Say *>(command), game, player); break;
|
||||
case ItemId_Command_Shuffle: response = cmdShuffle(qobject_cast<Command_Shuffle *>(command), game, player); break;
|
||||
case ItemId_Command_RollDie: response = cmdRollDie(qobject_cast<Command_RollDie *>(command), game, player); break;
|
||||
|
@ -89,7 +91,6 @@ void Server_ProtocolHandler::processCommand(Command *command)
|
|||
case ItemId_Command_CreateArrow: response = cmdCreateArrow(qobject_cast<Command_CreateArrow *>(command), game, player); break;
|
||||
case ItemId_Command_DeleteArrow: response = cmdDeleteArrow(qobject_cast<Command_DeleteArrow *>(command), game, player); break;
|
||||
case ItemId_Command_SetCardAttr: response = cmdSetCardAttr(qobject_cast<Command_SetCardAttr *>(command), game, player); break;
|
||||
case ItemId_Command_ReadyStart: response = cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), game, player); break;
|
||||
case ItemId_Command_IncCounter: response = cmdIncCounter(qobject_cast<Command_IncCounter *>(command), game, player); break;
|
||||
case ItemId_Command_CreateCounter: response = cmdCreateCounter(qobject_cast<Command_CreateCounter *>(command), game, player); break;
|
||||
case ItemId_Command_SetCounter: response = cmdSetCounter(qobject_cast<Command_SetCounter *>(command), game, player); break;
|
||||
|
@ -297,6 +298,25 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Serv
|
|||
return RespNothing;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
player->setConceded(true);
|
||||
game->sendGameEvent(new Event_Concede(-1, player->getPlayerId()));
|
||||
game->stopGameIfFinished();
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!player->getDeck())
|
||||
return RespContextError;
|
||||
|
||||
player->setReadyStart(true);
|
||||
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
||||
game->startGameIfReady();
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
|
||||
|
@ -504,17 +524,6 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Se
|
|||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
if (!player->getDeck())
|
||||
return RespContextError;
|
||||
|
||||
player->setReadyStart(true);
|
||||
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
||||
game->startGameIfReady();
|
||||
return RespOk;
|
||||
}
|
||||
|
||||
ResponseCode Server_ProtocolHandler::cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player)
|
||||
{
|
||||
const QMap<int, Server_Counter *> counters = player->getCounters();
|
||||
|
|
|
@ -45,6 +45,8 @@ private:
|
|||
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
|
||||
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
|
||||
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdConcede(Command_Concede *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
|
||||
|
@ -55,7 +57,6 @@ private:
|
|||
ResponseCode cmdCreateArrow(Command_CreateArrow *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdDeleteArrow(Command_DeleteArrow *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCardAttr(Command_SetCardAttr *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdIncCounter(Command_IncCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdCreateCounter(Command_CreateCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
ResponseCode cmdSetCounter(Command_SetCounter *cmd, Server_Game *game, Server_Player *player);
|
||||
|
|
Loading…
Reference in a new issue