diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 8fd40bb4..76015af4 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -347,7 +347,6 @@ resources/userlevels/admin_vip_buddy.svg - resources/tips/tips_of_the_day.xml resources/tips/images/accounts_tab.png resources/tips/images/arrows.png resources/tips/images/cockatrice_register.png @@ -358,8 +357,11 @@ resources/tips/images/filter_games.png resources/tips/images/github_logo.png resources/tips/images/gitter.png + resources/tips/images/setpt.png + resources/tips/images/shortcuts.png resources/tips/images/themes.png resources/tips/images/tip_of_the_day.png + resources/tips/tips_of_the_day.xml resources/help/search.md diff --git a/cockatrice/resources/tips/images/setpt.png b/cockatrice/resources/tips/images/setpt.png new file mode 100644 index 00000000..974c0224 Binary files /dev/null and b/cockatrice/resources/tips/images/setpt.png differ diff --git a/cockatrice/resources/tips/images/shortcuts.png b/cockatrice/resources/tips/images/shortcuts.png new file mode 100644 index 00000000..2034fdfd Binary files /dev/null and b/cockatrice/resources/tips/images/shortcuts.png differ diff --git a/cockatrice/resources/tips/tips_of_the_day.xml b/cockatrice/resources/tips/tips_of_the_day.xml index aa2cb463..786391c9 100644 --- a/cockatrice/resources/tips/tips_of_the_day.xml +++ b/cockatrice/resources/tips/tips_of_the_day.xml @@ -63,6 +63,7 @@ <br>Change Life: CTRL + L <br>All shortcuts can be customized via Settings->Shortcuts! + shortcuts.png 2018-03-01 @@ -89,4 +90,10 @@ counter_expression.png 2019-02-02 - \ No newline at end of file + + Power and Toughness + You can add and subtract to a creature's stats.<br>With a card selected, set the power and toughness ( default: ctrl + p ) and enter +3/-1 to increase power by three while decreasing toughness by one.<br>You can also reset it to the original value ( default: ctrl + alt + 0 ). + setpt.png + 2019-03-02 + + diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index 00b42bd9..20bf2fe1 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -106,17 +106,12 @@ void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, painter->save(); transformPainter(painter, translatedSize, tapAngle); - if (info) { - QStringList ptSplit = pt.split("/"); - QStringList ptDbSplit = info->getPowTough().split("/"); - - if (getFaceDown() || ptDbSplit.at(0) != ptSplit.at(0) || ptDbSplit.at(1) != ptSplit.at(1)) - painter->setPen(QColor(255, 150, 0)); - else - painter->setPen(Qt::white); - } else { + if (!getFaceDown() && info && pt == info->getPowTough()) { painter->setPen(Qt::white); + } else { + painter->setPen(QColor(255, 150, 0)); // dark orange } + painter->setBackground(Qt::black); painter->setBackgroundMode(Qt::OpaqueMode); diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 14e705f1..8ae75595 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -68,54 +68,61 @@ MessageLogWidget::getFromStr(CardZone *zone, QString cardName, int position, boo QString fromStr; QString zoneName = zone->getName(); - if (zoneName == tableConstant()) + if (zoneName == tableConstant()) { fromStr = tr(" from play"); - else if (zoneName == graveyardConstant()) + } else if (zoneName == graveyardConstant()) { fromStr = tr(" from their graveyard"); - else if (zoneName == exileConstant()) + } else if (zoneName == exileConstant()) { fromStr = tr(" from exile"); - else if (zoneName == handConstant()) + } else if (zoneName == handConstant()) { fromStr = tr(" from their hand"); - else if (zoneName == deckConstant()) { + } else if (zoneName == deckConstant()) { if (position == 0) { if (cardName.isEmpty()) { - if (ownerChange) + if (ownerChange) { cardName = tr("the top card of %1's library").arg(zone->getPlayer()->getName()); - else + } else { cardName = tr("the top card of their library"); + } cardNameContainsStartZone = true; } else { - if (ownerChange) + if (ownerChange) { fromStr = tr(" from the top of %1's library").arg(zone->getPlayer()->getName()); - else + } else { fromStr = tr(" from the top of their library"); + } } } else if (position >= zone->getCards().size() - 1) { if (cardName.isEmpty()) { - if (ownerChange) + if (ownerChange) { cardName = tr("the bottom card of %1's library").arg(zone->getPlayer()->getName()); - else + } else { cardName = tr("the bottom card of their library"); + } cardNameContainsStartZone = true; } else { - if (ownerChange) + if (ownerChange) { fromStr = tr(" from the bottom of %1's library").arg(zone->getPlayer()->getName()); - else + } else { fromStr = tr(" from the bottom of their library"); + } } } else { - if (ownerChange) + if (ownerChange) { fromStr = tr(" from %1's library").arg(zone->getPlayer()->getName()); - else + } else { fromStr = tr(" from their library"); + } } - } else if (zoneName == sideboardConstant()) + } else if (zoneName == sideboardConstant()) { fromStr = tr(" from sideboard"); - else if (zoneName == stackConstant()) + } else if (zoneName == stackConstant()) { fromStr = tr(" from the stack"); + } - if (!cardNameContainsStartZone) + if (!cardNameContainsStartZone) { cardName.clear(); + } return QPair(cardName, fromStr); } @@ -123,9 +130,9 @@ void MessageLogWidget::containerProcessingDone() { if (currentContext == MessageContext_MoveCard) { - for (auto &i : moveCardQueue) + for (auto &i : moveCardQueue) { logDoMoveCard(i); - + } moveCardQueue.clear(); moveCardTapped.clear(); moveCardExtras.clear(); @@ -141,9 +148,9 @@ void MessageLogWidget::containerProcessingDone() void MessageLogWidget::containerProcessingStarted(const GameEventContext &context) { - if (context.HasExtension(Context_MoveCard::ext)) + if (context.HasExtension(Context_MoveCard::ext)) { currentContext = MessageContext_MoveCard; - else if (context.HasExtension(Context_Mulligan::ext)) { + } else if (context.HasExtension(Context_Mulligan::ext)) { const Context_Mulligan &contextMulligan = context.GetExtension(Context_Mulligan::ext); currentContext = MessageContext_Mulligan; mulliganPlayer = nullptr; @@ -258,13 +265,14 @@ void MessageLogWidget::logCreateToken(Player *player, QString cardName, QString void MessageLogWidget::logDeckSelect(Player *player, QString deckHash, int sideboardSize) { - if (sideboardSize < 0) + if (sideboardSize < 0) { appendHtmlServerMessage(tr("%1 has loaded a deck (%2).").arg(sanitizeHtml(player->getName())).arg(deckHash)); - else + } else { appendHtmlServerMessage(tr("%1 has loaded a deck with %2 sideboard cards (%3).") .arg(sanitizeHtml(player->getName())) .arg("" + QString::number(sideboardSize) + "") .arg(deckHash)); + } } void MessageLogWidget::logDestroyCard(Player *player, QString cardName) @@ -282,21 +290,24 @@ void MessageLogWidget::logDoMoveCard(LogMoveCard &lmc) // do not log if moved within the same zone if ((startZone == tableConstant() && targetZone == tableConstant() && !ownerChanged) || (startZone == handConstant() && targetZone == handConstant()) || - (startZone == exileConstant() && targetZone == exileConstant())) + (startZone == exileConstant() && targetZone == exileConstant())) { return; + } QString cardName = lmc.cardName; QPair nameFrom = getFromStr(lmc.startZone, cardName, lmc.oldX, ownerChanged); - if (!nameFrom.first.isEmpty()) + if (!nameFrom.first.isEmpty()) { cardName = nameFrom.first; + } QString cardStr; - if (!nameFrom.first.isEmpty()) + if (!nameFrom.first.isEmpty()) { cardStr = cardName; - else if (cardName.isEmpty()) + } else if (cardName.isEmpty()) { cardStr = tr("a card"); - else + } else { cardStr = cardLink(cardName); + } if (ownerChanged && (lmc.startZone->getPlayer() == lmc.player)) { appendHtmlServerMessage(tr("%1 gives %2 control over %3.") @@ -310,17 +321,18 @@ void MessageLogWidget::logDoMoveCard(LogMoveCard &lmc) bool usesNewX = false; if (targetZone == tableConstant()) { soundEngine->playSound("play_card"); - if (moveCardTapped.value(lmc.card)) + if (moveCardTapped.value(lmc.card)) { finalStr = tr("%1 puts %2 into play tapped%3."); - else + } else { finalStr = tr("%1 puts %2 into play%3."); - } else if (targetZone == graveyardConstant()) + } + } else if (targetZone == graveyardConstant()) { finalStr = tr("%1 puts %2%3 into their graveyard."); - else if (targetZone == exileConstant()) + } else if (targetZone == exileConstant()) { finalStr = tr("%1 exiles %2%3."); - else if (targetZone == handConstant()) + } else if (targetZone == handConstant()) { finalStr = tr("%1 moves %2%3 to their hand."); - else if (targetZone == deckConstant()) { + } else if (targetZone == deckConstant()) { if (moveCardExtras.contains("shuffle_partial")) { finalStr = tr("%1 puts %2%3 on bottom of their library randomly."); } else if (lmc.newX == -1) { @@ -330,13 +342,13 @@ void MessageLogWidget::logDoMoveCard(LogMoveCard &lmc) } else if (lmc.newX == 0) { finalStr = tr("%1 puts %2%3 on top of their library."); } else { - lmc.newX++; + ++lmc.newX; usesNewX = true; finalStr = tr("%1 puts %2%3 into their library %4 cards from the top."); } - } else if (targetZone == sideboardConstant()) + } else if (targetZone == sideboardConstant()) { finalStr = tr("%1 moves %2%3 to sideboard."); - else if (targetZone == stackConstant()) { + } else if (targetZone == stackConstant()) { soundEngine->playSound("play_card"); finalStr = tr("%1 plays %2%3."); } @@ -351,9 +363,9 @@ void MessageLogWidget::logDoMoveCard(LogMoveCard &lmc) void MessageLogWidget::logDrawCards(Player *player, int number) { - if (currentContext == MessageContext_Mulligan) + if (currentContext == MessageContext_Mulligan) { mulliganPlayer = player; - else { + } else { soundEngine->playSound("draw_card"); appendHtmlServerMessage(tr("%1 draws %2 card(s).", "", number) .arg(sanitizeHtml(player->getName())) @@ -363,16 +375,17 @@ void MessageLogWidget::logDrawCards(Player *player, int number) void MessageLogWidget::logDumpZone(Player *player, CardZone *zone, int numberCards) { - if (numberCards == -1) + if (numberCards == -1) { appendHtmlServerMessage(tr("%1 is looking at %2.") .arg(sanitizeHtml(player->getName())) .arg(zone->getTranslatedName(zone->getPlayer() == player, CaseLookAtZone))); - else + } else { appendHtmlServerMessage( tr("%1 is looking at the top %3 card(s) %2.", "top card for singular, top %3 cards for plural", numberCards) .arg(sanitizeHtml(player->getName())) .arg(zone->getTranslatedName(zone->getPlayer() == player, CaseTopCardsOfZone)) .arg("" + QString::number(numberCards) + "")); + } } void MessageLogWidget::logFlipCard(Player *player, QString cardName, bool faceDown) @@ -438,22 +451,25 @@ void MessageLogWidget::logMoveCard(Player *player, int newX) { LogMoveCard attributes = {player, card, card->getName(), startZone, oldX, targetZone, newX}; - if (currentContext == MessageContext_MoveCard) + if (currentContext == MessageContext_MoveCard) { moveCardQueue.append(attributes); - else if (currentContext == MessageContext_Mulligan) + } else if (currentContext == MessageContext_Mulligan) { mulliganPlayer = player; - else + } else { logDoMoveCard(attributes); + } } void MessageLogWidget::logMulligan(Player *player, int number) { - if (!player) + if (!player) { return; - if (number > -1) + } + if (number > -1) { appendHtmlServerMessage(tr("%1 takes a mulligan to %2.").arg(sanitizeHtml(player->getName())).arg(number)); - else + } else { appendHtmlServerMessage(tr("%1 draws their initial hand.").arg(sanitizeHtml(player->getName()))); + } } void MessageLogWidget::logReplayStarted(int gameId) @@ -549,11 +565,12 @@ void MessageLogWidget::logRollDie(Player *player, int sides, int roll) appendHtmlServerMessage(tr("%1 flipped a coin. It landed as %2.") .arg(sanitizeHtml(player->getName())) .arg("" + coinOptions[roll - 1] + "")); - } else + } else { appendHtmlServerMessage(tr("%1 rolls a %2 with a %3-sided die.") .arg(sanitizeHtml(player->getName())) .arg("" + QString::number(roll) + "") .arg("" + QString::number(sides) + "")); + } soundEngine->playSound("roll_dice"); } @@ -567,7 +584,7 @@ void MessageLogWidget::logSetActivePhase(int phase) { QString phaseName; QString color; - switch (phase) { + switch (phase) { // TODO: define phases case 0: phaseName = tr("Untap"); soundEngine->playSound("untap_step"); @@ -651,10 +668,11 @@ void MessageLogWidget::logSetCardCounter(Player *player, QString cardName, int c { QString finalStr; int delta = abs(oldValue - value); - if (value > oldValue) + if (value > oldValue) { finalStr = tr("%1 places %2 %3 on %4 (now %5)."); - else + } else { finalStr = tr("%1 removes %2 %3 from %4 (now %5)."); + } QString colorStr; switch (counterId) { @@ -679,8 +697,9 @@ void MessageLogWidget::logSetCardCounter(Player *player, QString cardName, int c void MessageLogWidget::logSetCounter(Player *player, QString counterName, int value, int oldValue) { - if (counterName == "life") + if (counterName == "life") { soundEngine->playSound("life_change"); + } appendHtmlServerMessage(tr("%1 sets counter %2 to %3 (%4%5).") .arg(sanitizeHtml(player->getName())) @@ -693,10 +712,11 @@ void MessageLogWidget::logSetCounter(Player *player, QString counterName, int va void MessageLogWidget::logSetDoesntUntap(Player *player, CardItem *card, bool doesntUntap) { QString str; - if (doesntUntap) + if (doesntUntap) { str = tr("%1 sets %2 to not untap normally."); - else + } else { str = tr("%1 sets %2 to untap normally."); + } appendHtmlServerMessage(str.arg(sanitizeHtml(player->getName())).arg(cardLink(card->getName()))); } @@ -712,40 +732,50 @@ void MessageLogWidget::logSetPT(Player *player, CardItem *card, QString newPT) } else { name = cardLink(name); } + QString playerName = sanitizeHtml(player->getName()); if (newPT.isEmpty()) { - appendHtmlServerMessage(tr("%1 removes the PT of %2.").arg(sanitizeHtml(player->getName())).arg(name)); + appendHtmlServerMessage(tr("%1 removes the PT of %2.").arg(playerName).arg(name)); } else { - appendHtmlServerMessage( - tr("%1 sets PT of %2 to %3.").arg(sanitizeHtml(player->getName())).arg(name).arg(newPT)); + QString oldPT = card->getPT(); + if (oldPT.isEmpty()) { + appendHtmlServerMessage( + tr("%1 changes the PT of %2 from nothing to %4.").arg(playerName).arg(name).arg(newPT)); + } else { + appendHtmlServerMessage( + tr("%1 changes the PT of %2 from %3 to %4.").arg(playerName).arg(name).arg(oldPT).arg(newPT)); + } } } void MessageLogWidget::logSetSideboardLock(Player *player, bool locked) { - if (locked) + if (locked) { appendHtmlServerMessage(tr("%1 has locked their sideboard.").arg(sanitizeHtml(player->getName()))); - else + } else { appendHtmlServerMessage(tr("%1 has unlocked their sideboard.").arg(sanitizeHtml(player->getName()))); + } } void MessageLogWidget::logSetTapped(Player *player, CardItem *card, bool tapped) { - if (tapped) + if (tapped) { soundEngine->playSound("tap_card"); - else + } else { soundEngine->playSound("untap_card"); + } - if (currentContext == MessageContext_MoveCard) + if (currentContext == MessageContext_MoveCard) { moveCardTapped.insert(card, tapped); - else { + } else { QString str; - if (!card) + if (!card) { appendHtmlServerMessage((tapped ? tr("%1 taps their permanents.") : tr("%1 untaps their permanents.")) .arg(sanitizeHtml(player->getName()))); - else + } else { appendHtmlServerMessage((tapped ? tr("%1 taps %2.") : tr("%1 untaps %2.")) .arg(sanitizeHtml(player->getName())) .arg(cardLink(card->getName()))); + } } } @@ -809,13 +839,14 @@ void MessageLogWidget::logUnattachCard(Player *player, QString cardName) void MessageLogWidget::logUndoDraw(Player *player, QString cardName) { - if (cardName.isEmpty()) + if (cardName.isEmpty()) { appendHtmlServerMessage(tr("%1 undoes their last draw.").arg(sanitizeHtml(player->getName()))); - else + } else { appendHtmlServerMessage( tr("%1 undoes their last draw (%2).") .arg(sanitizeHtml(player->getName())) .arg(QString("%2").arg(sanitizeHtml(cardName)).arg(sanitizeHtml(cardName)))); + } } void MessageLogWidget::setContextJudgeName(QString name) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index f6e7509e..75e6d713 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -410,6 +410,10 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T connect(aIncPT, SIGNAL(triggered()), this, SLOT(actIncPT())); aDecPT = new QAction(this); connect(aDecPT, SIGNAL(triggered()), this, SLOT(actDecPT())); + aFlowP = new QAction(this); + connect(aFlowP, SIGNAL(triggered()), this, SLOT(actFlowP())); + aFlowT = new QAction(this); + connect(aFlowT, SIGNAL(triggered()), this, SLOT(actFlowT())); aSetPT = new QAction(this); connect(aSetPT, SIGNAL(triggered()), this, SLOT(actSetPT())); aResetPT = new QAction(this); @@ -466,8 +470,9 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T } const QList &players = game->getPlayers().values(); - for (auto player : players) + for (const auto player : players) { addPlayer(player); + } rearrangeZones(); retranslateUi(); @@ -706,8 +711,9 @@ void Player::retranslateUi() aCardMenu->setText(tr("C&ard")); - for (auto &allPlayersAction : allPlayersActions) + for (auto &allPlayersAction : allPlayersActions) { allPlayersAction->setText(tr("&All players")); + } } if (local) { @@ -735,6 +741,8 @@ void Player::retranslateUi() aDecT->setText(tr("D&ecrease toughness")); aIncPT->setText(tr("In&crease power and toughness")); aDecPT->setText(tr("Dec&rease power and toughness")); + aFlowP->setText(tr("Increase power and decrease toughness")); + aFlowT->setText(tr("Decrease power and increase toughness")); aSetPT->setText(tr("Set &power and toughness...")); aResetPT->setText(tr("Reset p&ower and toughness")); aSetAnnotation->setText(tr("&Set annotation...")); @@ -787,6 +795,8 @@ void Player::setShortcutsActive() aDecT->setShortcuts(shortcuts.getShortcut("Player/aDecT")); aIncPT->setShortcuts(shortcuts.getShortcut("Player/aIncPT")); aDecPT->setShortcuts(shortcuts.getShortcut("Player/aDecPT")); + aFlowP->setShortcuts(shortcuts.getShortcut("Player/aFlowP")); + aFlowT->setShortcuts(shortcuts.getShortcut("Player/aFlowT")); aSetPT->setShortcuts(shortcuts.getShortcut("Player/aSetPT")); aResetPT->setShortcuts(shortcuts.getShortcut("Player/aResetPT")); aSetAnnotation->setShortcuts(shortcuts.getShortcut("Player/aSetAnnotation")); @@ -1849,7 +1859,7 @@ void Player::eventRevealCards(const Event_RevealCards &event) } if (peeking) { - for (auto &card : cardList) { + for (const auto &card : cardList) { QString cardName = QString::fromStdString(card->name()); CardItem *cardItem = zone->getCard(card->id(), QString()); if (!cardItem) { @@ -2245,11 +2255,9 @@ void Player::rearrangeCounters() // Determine total height of bounding rectangles qreal totalHeight = 0; - QMapIterator counterIterator(counters); - while (counterIterator.hasNext()) { - counterIterator.next(); - if (counterIterator.value()->getShownInCounterArea()) { - totalHeight += counterIterator.value()->boundingRect().height(); + for (const auto &counter : counters) { + if (counter->getShownInCounterArea()) { + totalHeight += counter->boundingRect().height(); } } @@ -2257,8 +2265,8 @@ void Player::rearrangeCounters() qreal ySize = boundingRect().y() + marginTop; // Place objects - for (counterIterator.toFront(); counterIterator.hasNext();) { - AbstractCounter *ctr = counterIterator.next().value(); + for (const auto &counter : counters) { + AbstractCounter *ctr = counter; if (!ctr->getShownInCounterArea()) { continue; @@ -2351,6 +2359,10 @@ void Player::actMoveCardXCardsFromTop() defaultNumberTopCardsToPlaceBelow = number; QList sel = scene()->selectedItems(); + if (sel.isEmpty()) { + return; + } + QList cardList; while (!sel.isEmpty()) { cardList.append(qgraphicsitem_cast(sel.takeFirst())); @@ -2358,14 +2370,10 @@ void Player::actMoveCardXCardsFromTop() QList commandList; ListOfCardsToMove idList; - for (auto &i : cardList) { + for (const auto &i : cardList) { idList.add_card()->set_card_id(i->getId()); } - if (cardList.isEmpty()) { - return; - } - int startPlayerId = cardList[0]->getZone()->getPlayer()->getId(); QString startZone = cardList[0]->getZone()->getName(); @@ -2397,7 +2405,7 @@ void Player::cardMenuAction() QList commandList; if (a->data().toInt() <= (int)cmClone) { - for (auto card : cardList) { + for (const auto &card : cardList) { switch (static_cast(a->data().toInt())) { // Leaving both for compatibility with server case cmUntap: @@ -2461,7 +2469,7 @@ void Player::cardMenuAction() } } else { ListOfCardsToMove idList; - for (auto &i : cardList) { + for (const auto &i : cardList) { idList.add_card()->set_card_id(i->getId()); } int startPlayerId = cardList[0]->getZone()->getPlayer()->getId(); @@ -2552,18 +2560,28 @@ void Player::cardMenuAction() void Player::actIncPT(int deltaP, int deltaT) { - QString ptString = "+" + QString::number(deltaP) + "/+" + QString::number(deltaT); int playerid = id; QList commandList; - QListIterator j(scene()->selectedItems()); - while (j.hasNext()) { - auto *card = static_cast(j.next()); + for (const auto &item : scene()->selectedItems()) { + auto *card = static_cast(item); + QString pt = card->getPT(); + const auto ptList = parsePT(pt); + QString newpt; + if (ptList.isEmpty()) { + newpt = QString::number(deltaP) + (deltaT ? "/" + QString::number(deltaT) : ""); + } else if (ptList.size() == 1) { + newpt = QString::number(ptList.at(0).toInt() + deltaP) + (deltaT ? "/" + QString::number(deltaT) : ""); + } else { + newpt = + QString::number(ptList.at(0).toInt() + deltaP) + "/" + QString::number(ptList.at(1).toInt() + deltaT); + } + auto *cmd = new Command_SetCardAttr; cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId()); cmd->set_attribute(AttrPT); - cmd->set_attr_value(ptString.toStdString()); + cmd->set_attr_value(newpt.toStdString()); commandList.append(cmd); if (local) { @@ -2578,9 +2596,8 @@ void Player::actResetPT() { int playerid = id; QList commandList; - QListIterator selected(scene()->selectedItems()); - while (selected.hasNext()) { - auto *card = static_cast(selected.next()); + for (const auto &item : scene()->selectedItems()) { + auto *card = static_cast(item); QString ptString; if (!card->getFaceDown()) { // leave the pt empty if the card is face down CardInfoPtr info = card->getInfo(); @@ -2607,39 +2624,85 @@ void Player::actResetPT() game->sendGameCommand(prepareGameCommand(commandList), playerid); } +QVariantList Player::parsePT(const QString &pt) +{ + QVariantList ptList = QVariantList(); + if (!pt.isEmpty()) { + int sep = pt.indexOf('/'); + if (sep == 0) { + ptList.append(QVariant(pt.mid(1))); // cut off starting '/' and take full string + } else { + int start = 0; + for (;;) { + QString item = pt.mid(start, sep - start); + if (item.isEmpty()) { + ptList.append(QVariant(QString())); + } else if (item[0] == '+') { + ptList.append(QVariant(item.mid(1).toInt())); // add as int + } else if (item[0] == '-') { + ptList.append(QVariant(item.toInt())); // add as int + } else { + ptList.append(QVariant(item)); // add as qstring + } + if (sep == -1) { + break; + } + start = sep + 1; + sep = pt.indexOf('/', start); + } + } + } + return ptList; +} + void Player::actSetPT() { QString oldPT; int playerid = id; - QListIterator i(scene()->selectedItems()); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + auto sel = scene()->selectedItems(); + for (const auto &item : sel) { + auto *card = static_cast(item); if (!card->getPT().isEmpty()) { oldPT = card->getPT(); } } bool ok; dialogSemaphore = true; - QString pt = QInputDialog::getText(nullptr, tr("Set power/toughness"), tr("Please enter the new PT:"), - QLineEdit::Normal, oldPT, &ok); + QString pt = QInputDialog::getText(nullptr, tr("Change power/toughness"), tr("Change stats to:"), QLineEdit::Normal, + oldPT, &ok); dialogSemaphore = false; - if (clearCardsToDelete()) { - return; - } - if (!ok) { + if (clearCardsToDelete() || !ok) { return; } + const auto ptList = parsePT(pt); + bool empty = ptList.isEmpty(); + QList commandList; - QListIterator j(scene()->selectedItems()); - while (j.hasNext()) { - auto *card = static_cast(j.next()); + for (const auto &item : sel) { + auto *card = static_cast(item); auto *cmd = new Command_SetCardAttr; + QString newpt = QString(); + if (!empty) { + const auto oldpt = parsePT(card->getPT()); + int ptIter = 0; + for (const auto &item : ptList) { + if (item.type() == QVariant::Int) { + int oldItem = ptIter < oldpt.size() ? oldpt.at(ptIter).toInt() : 0; + newpt += '/' + QString::number(oldItem + item.toInt()); + } else { + newpt += '/' + item.toString(); + } + ++ptIter; + } + newpt = newpt.mid(1); + } + cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId()); cmd->set_attribute(AttrPT); - cmd->set_attr_value(pt.toStdString()); + cmd->set_attr_value(newpt.toStdString()); commandList.append(cmd); if (local) { @@ -2689,12 +2752,22 @@ void Player::actDecPT() actIncPT(-1, -1); } +void Player::actFlowP() +{ + actIncPT(1, -1); +} + +void Player::actFlowT() +{ + actIncPT(-1, 1); +} + void Player::actSetAnnotation() { QString oldAnnotation; - QListIterator i(scene()->selectedItems()); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + auto sel = scene()->selectedItems(); + for (const auto &item : sel) { + auto *card = static_cast(item); if (!card->getAnnotation().isEmpty()) { oldAnnotation = card->getAnnotation(); } @@ -2705,17 +2778,13 @@ void Player::actSetAnnotation() QString annotation = QInputDialog::getText(nullptr, tr("Set annotation"), tr("Please enter the new annotation:"), QLineEdit::Normal, oldAnnotation, &ok); dialogSemaphore = false; - if (clearCardsToDelete()) { - return; - } - if (!ok) { + if (clearCardsToDelete() || !ok) { return; } QList commandList; - i.toFront(); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + for (const auto &item : sel) { + auto *card = static_cast(item); auto *cmd = new Command_SetCardAttr; cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId()); @@ -2728,11 +2797,12 @@ void Player::actSetAnnotation() void Player::actAttach() { - if (!game->getActiveCard()) { + auto *card = game->getActiveCard(); + if (!card) { return; } - auto *arrow = new ArrowAttachItem(game->getActiveCard()); + auto *arrow = new ArrowAttachItem(card); scene()->addItem(arrow); arrow->grabMouse(); } @@ -2754,11 +2824,10 @@ void Player::actCardCounterTrigger() auto *action = static_cast(sender()); int counterId = action->data().toInt() / 1000; QList commandList; - switch (action->data().toInt() % 1000) { // TODO: define case numbers - case 9: { - QListIterator i(scene()->selectedItems()); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + switch (action->data().toInt() % 1000) { + case 9: { // increment counter + for (const auto &item : scene()->selectedItems()) { + auto *card = static_cast(item); if (card->getCounters().value(counterId, 0) < MAX_COUNTERS_ON_CARD) { auto *cmd = new Command_SetCardCounter; cmd->set_zone(card->getZone()->getName().toStdString()); @@ -2770,10 +2839,9 @@ void Player::actCardCounterTrigger() } break; } - case 10: { - QListIterator i(scene()->selectedItems()); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + case 10: { // decrement counter + for (const auto &item : scene()->selectedItems()) { + auto *card = static_cast(item); if (card->getCounters().value(counterId, 0)) { auto *cmd = new Command_SetCardCounter; cmd->set_zone(card->getZone()->getName().toStdString()); @@ -2785,7 +2853,7 @@ void Player::actCardCounterTrigger() } break; } - case 11: { + case 11: { // set counter with dialog bool ok; dialogSemaphore = true; int number = @@ -2795,9 +2863,8 @@ void Player::actCardCounterTrigger() return; } - QListIterator i(scene()->selectedItems()); - while (i.hasNext()) { - auto *card = static_cast(i.next()); + for (const auto &item : scene()->selectedItems()) { + auto *card = static_cast(item); auto *cmd = new Command_SetCardCounter; cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId()); @@ -2900,9 +2967,11 @@ void Player::updateCardMenu(const CardItem *card) if (ptMenu->isEmpty()) { ptMenu->addAction(aIncP); ptMenu->addAction(aDecP); + ptMenu->addAction(aFlowP); ptMenu->addSeparator(); ptMenu->addAction(aIncT); ptMenu->addAction(aDecT); + ptMenu->addAction(aFlowT); ptMenu->addSeparator(); ptMenu->addAction(aIncPT); ptMenu->addAction(aDecPT); @@ -2986,11 +3055,15 @@ void Player::updateCardMenu(const CardItem *card) void Player::addRelatedCardView(const CardItem *card, QMenu *cardMenu) { - if (card == nullptr || cardMenu == nullptr || card->getInfo() == nullptr) { + if (!card || !cardMenu) { + return; + } + auto cardInfo = card->getInfo(); + if (!cardInfo) { return; } - QList relatedCards = card->getInfo()->getRelatedCards(); + QList relatedCards = cardInfo->getRelatedCards(); if (relatedCards.isEmpty()) { return; } @@ -3009,13 +3082,16 @@ void Player::addRelatedCardView(const CardItem *card, QMenu *cardMenu) void Player::addRelatedCardActions(const CardItem *card, QMenu *cardMenu) { - if (card == nullptr || cardMenu == nullptr || card->getInfo() == nullptr) { + if (!card || !cardMenu) { + return; + } + auto cardInfo = card->getInfo(); + if (!cardInfo) { return; } - QList relatedCards(card->getInfo()->getRelatedCards()); - relatedCards.append(card->getInfo()->getReverseRelatedCards2Me()); - if (relatedCards.empty()) { + QList relatedCards = cardInfo->getRelatedCards(); + if (relatedCards.isEmpty()) { return; } diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index f8a5b2fa..e5f06693 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -192,6 +192,8 @@ private slots: void actDecT(); void actIncPT(); void actDecPT(); + void actFlowP(); + void actFlowT(); void actSetAnnotation(); void actPlay(); void actHide(); @@ -215,8 +217,9 @@ private: QList aAddCounter, aSetCounter, aRemoveCounter; QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT, - *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aSetAnnotation, *aFlip, *aPeek, *aClone, *aMoveToTopLibrary, - *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile, *aMoveToXfromTopOfLibrary; + *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone, + *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile, + *aMoveToXfromTopOfLibrary; bool shortcutsActive; int defaultNumberTopCards; @@ -288,6 +291,8 @@ private: void eventRevealCards(const Event_RevealCards &event); void eventChangeZoneProperties(const Event_ChangeZoneProperties &event); + QVariantList parsePT(const QString &pt); + public: static const int counterAreaWidth = 55; enum CardMenuActionType diff --git a/cockatrice/src/sequenceEdit/ui_shortcutstab.h b/cockatrice/src/sequenceEdit/ui_shortcutstab.h index 4fb14772..2bafe80d 100644 --- a/cockatrice/src/sequenceEdit/ui_shortcutstab.h +++ b/cockatrice/src/sequenceEdit/ui_shortcutstab.h @@ -199,26 +199,30 @@ public: QVBoxLayout *verticalLayout; QGroupBox *groupBox_12; QGridLayout *gridLayout_12; - SequenceEdit *Player_aDecPT; - SequenceEdit *Player_aIncPT; QLabel *lbl_Player_aIncPT; + SequenceEdit *Player_aIncPT; QLabel *lbl_Player_aDecPT; - SequenceEdit *Player_aSetPT; + SequenceEdit *Player_aDecPT; QLabel *lbl_Player_aSetPT; - SequenceEdit *Player_aResetPT; + SequenceEdit *Player_aSetPT; QLabel *lbl_Player_aResetPT; + SequenceEdit *Player_aResetPT; QGroupBox *groupBox_11; QGridLayout *gridLayout_11; QLabel *lbl_Player_aDecT; SequenceEdit *Player_aDecT; QLabel *lbl_Player_aIncT; SequenceEdit *Player_aIncT; + QLabel *lbl_Player_aFlowT; + SequenceEdit *Player_aFlowT; QGroupBox *groupBox_10; QGridLayout *gridLayout_10; QLabel *lbl_Player_aDecP; SequenceEdit *Player_aDecP; - SequenceEdit *Player_aIncP; QLabel *lbl_Player_aIncP; + SequenceEdit *Player_aIncP; + QLabel *lbl_Player_aFlowP; + SequenceEdit *Player_aFlowP; QGroupBox *groupBox_8; QGridLayout *gridLayout_5; QLabel *lbl_TabGame_phase0; @@ -1083,36 +1087,20 @@ public: verticalLayout->addWidget(groupBox_12); - groupBox_11 = new QGroupBox(groupBox_9); - groupBox_11->setObjectName("groupBox_11"); - gridLayout_11 = new QGridLayout(groupBox_11); - gridLayout_11->setObjectName("gridLayout_11"); - lbl_Player_aDecT = new QLabel(groupBox_11); - lbl_Player_aDecT->setObjectName("lbl_Player_aDecT"); - - gridLayout_11->addWidget(lbl_Player_aDecT, 1, 0, 1, 1); - - Player_aDecT = new SequenceEdit("Player/aDecT", groupBox_11); - Player_aDecT->setObjectName("Player_aDecT"); - - gridLayout_11->addWidget(Player_aDecT, 1, 1, 1, 1); - - lbl_Player_aIncT = new QLabel(groupBox_11); - lbl_Player_aIncT->setObjectName("lbl_Player_aIncT"); - - gridLayout_11->addWidget(lbl_Player_aIncT, 0, 0, 1, 1); - - Player_aIncT = new SequenceEdit("Player/aIncT", groupBox_11); - Player_aIncT->setObjectName("Player_aIncT"); - - gridLayout_11->addWidget(Player_aIncT, 0, 1, 1, 1); - - verticalLayout->addWidget(groupBox_11); - groupBox_10 = new QGroupBox(groupBox_9); groupBox_10->setObjectName("groupBox_10"); gridLayout_10 = new QGridLayout(groupBox_10); gridLayout_10->setObjectName("gridLayout_10"); + lbl_Player_aIncP = new QLabel(groupBox_10); + lbl_Player_aIncP->setObjectName("lbl_Player_aIncP"); + + gridLayout_10->addWidget(lbl_Player_aIncP, 0, 0, 1, 1); + + Player_aIncP = new SequenceEdit("Player/aIncP", groupBox_10); + Player_aIncP->setObjectName("Player_aIncP"); + + gridLayout_10->addWidget(Player_aIncP, 0, 1, 1, 1); + lbl_Player_aDecP = new QLabel(groupBox_10); lbl_Player_aDecP->setObjectName("lbl_Player_aDecP"); @@ -1123,18 +1111,54 @@ public: gridLayout_10->addWidget(Player_aDecP, 1, 1, 1, 1); - Player_aIncP = new SequenceEdit("Player/aIncP", groupBox_10); - Player_aIncP->setObjectName("Player_aIncP"); + lbl_Player_aFlowP = new QLabel(groupBox_10); + lbl_Player_aFlowP->setObjectName("lbl_Player_aFlowP"); - gridLayout_10->addWidget(Player_aIncP, 0, 1, 1, 1); + gridLayout_10->addWidget(lbl_Player_aFlowP, 2, 0, 1, 1); - lbl_Player_aIncP = new QLabel(groupBox_10); - lbl_Player_aIncP->setObjectName("lbl_Player_aIncP"); + Player_aFlowP = new SequenceEdit("Player/aFlowP", groupBox_10); + Player_aFlowP->setObjectName("Player_aFlowP"); - gridLayout_10->addWidget(lbl_Player_aIncP, 0, 0, 1, 1); + gridLayout_10->addWidget(Player_aFlowP, 2, 1, 1, 1); verticalLayout->addWidget(groupBox_10); + groupBox_11 = new QGroupBox(groupBox_9); + groupBox_11->setObjectName("groupBox_11"); + gridLayout_11 = new QGridLayout(groupBox_11); + gridLayout_11->setObjectName("gridLayout_11"); + lbl_Player_aIncT = new QLabel(groupBox_11); + lbl_Player_aIncT->setObjectName("lbl_Player_aIncT"); + + gridLayout_11->addWidget(lbl_Player_aIncT, 0, 0, 1, 1); + + Player_aIncT = new SequenceEdit("Player/aIncT", groupBox_11); + Player_aIncT->setObjectName("Player_aIncT"); + + gridLayout_11->addWidget(Player_aIncT, 0, 1, 1, 1); + + lbl_Player_aDecT = new QLabel(groupBox_11); + lbl_Player_aDecT->setObjectName("lbl_Player_aDecT"); + + gridLayout_11->addWidget(lbl_Player_aDecT, 1, 0, 1, 1); + + Player_aDecT = new SequenceEdit("Player/aDecT", groupBox_11); + Player_aDecT->setObjectName("Player_aDecT"); + + gridLayout_11->addWidget(Player_aDecT, 1, 1, 1, 1); + + lbl_Player_aFlowT = new QLabel(groupBox_11); + lbl_Player_aFlowT->setObjectName("lbl_Player_aFlowT"); + + gridLayout_11->addWidget(lbl_Player_aFlowT, 2, 0, 1, 1); + + Player_aFlowT = new SequenceEdit("Player/aFlowT", groupBox_11); + Player_aFlowT->setObjectName("Player_aFlowT"); + + gridLayout_11->addWidget(Player_aFlowT, 2, 1, 1, 1); + + verticalLayout->addWidget(groupBox_11); + gridLayout_17->addWidget(groupBox_9, 0, 1, 1, 1); groupBox_8 = new QGroupBox(tab_2); @@ -1929,9 +1953,11 @@ public: groupBox_11->setTitle(QApplication::translate("shortcutsTab", "Toughness")); lbl_Player_aDecT->setText(QApplication::translate("shortcutsTab", "Remove (-0/-1)")); lbl_Player_aIncT->setText(QApplication::translate("shortcutsTab", "Add (+0/+1)")); + lbl_Player_aFlowT->setText(QApplication::translate("shortcutsTab", "Move (-1/+1)")); groupBox_10->setTitle(QApplication::translate("shortcutsTab", "Power")); - lbl_Player_aDecP->setText(QApplication::translate("shortcutsTab", "Remove (-1/-nullptr)")); - lbl_Player_aIncP->setText(QApplication::translate("shortcutsTab", "Add (+1/+nullptr)")); + lbl_Player_aDecP->setText(QApplication::translate("shortcutsTab", "Remove (-1/-0)")); + lbl_Player_aIncP->setText(QApplication::translate("shortcutsTab", "Add (+1/+0)")); + lbl_Player_aFlowP->setText(QApplication::translate("shortcutsTab", "Move (+1/-1)")); groupBox_8->setTitle(QApplication::translate("shortcutsTab", "Game Phases")); lbl_TabGame_phase0->setText(QApplication::translate("shortcutsTab", "Untap")); lbl_TabGame_phase1->setText(QApplication::translate("shortcutsTab", "Upkeep")); diff --git a/cockatrice/src/shortcutssettings.h b/cockatrice/src/shortcutssettings.h index 6887cf75..954cd5ed 100644 --- a/cockatrice/src/shortcutssettings.h +++ b/cockatrice/src/shortcutssettings.h @@ -139,6 +139,8 @@ private: {"Player/aIncT", parseSequenceString("Alt++")}, {"Player/aSetPT", parseSequenceString("Ctrl+P")}, {"Player/aResetPT", parseSequenceString("Ctrl+Alt+0")}, + {"Player/aFlowP", parseSequenceString("")}, + {"Player/aFlowT", parseSequenceString("")}, {"Player/aConcede", parseSequenceString("F2")}, {"Player/aLeaveGame", parseSequenceString("Ctrl+Q")}, diff --git a/common/server_card.cpp b/common/server_card.cpp index b1af9d5b..a8b5f1f1 100644 --- a/common/server_card.cpp +++ b/common/server_card.cpp @@ -24,8 +24,7 @@ Server_Card::Server_Card(QString _name, int _id, int _coord_x, int _coord_y, Server_CardZone *_zone) : zone(_zone), id(_id), coord_x(_coord_x), coord_y(_coord_y), name(_name), tapped(false), attacking(false), - facedown(false), color(QString()), power(-1), toughness(-1), annotation(QString()), destroyOnZoneChange(false), - doesntUntap(false), parentCard(0) + facedown(false), color(), ptString(), annotation(), destroyOnZoneChange(false), doesntUntap(false), parentCard(0) { } @@ -44,8 +43,7 @@ void Server_Card::resetState() counters.clear(); setTapped(false); setAttacking(false); - power = -1; - toughness = -1; + setPT(QString()); setAnnotation(QString()); setDoesntUntap(false); } @@ -89,40 +87,6 @@ void Server_Card::setCounter(int id, int value) counters.remove(id); } -void Server_Card::setPT(const QString &_pt) -{ - if (_pt.isEmpty()) { - power = 0; - toughness = -1; - } else { - int sep = _pt.indexOf('/'); - QString p1 = _pt.left(sep); - QString p2 = _pt.mid(sep + 1); - if (p1.isEmpty() || p2.isEmpty()) - return; - - if ((p1[0] == '+') || (p2[0] == '+')) - if (toughness < 0) - toughness = 0; - if (p1[0] == '+') - power += p1.mid(1).toInt(); - else - power = p1.toInt(); - - if (p2[0] == '+') - toughness += p2.mid(1).toInt(); - else - toughness = p2.toInt(); - } -} - -QString Server_Card::getPT() const -{ - if (toughness < 0) - return QString(""); - return QString::number(power) + "/" + QString::number(toughness); -} - void Server_Card::setParentCard(Server_Card *_parentCard) { if (parentCard) @@ -140,24 +104,28 @@ void Server_Card::getInfo(ServerInfo_Card *info) info->set_name(displayedName.toStdString()); info->set_x(coord_x); info->set_y(coord_y); - QString ptStr = getPT(); if (facedown) { info->set_face_down(true); - ptStr = getPT(); } info->set_tapped(tapped); - if (attacking) + if (attacking) { info->set_attacking(true); - if (!color.isEmpty()) + } + if (!color.isEmpty()) { info->set_color(color.toStdString()); - if (!ptStr.isEmpty()) - info->set_pt(ptStr.toStdString()); - if (!annotation.isEmpty()) + } + if (!ptString.isEmpty()) { + info->set_pt(ptString.toStdString()); + } + if (!annotation.isEmpty()) { info->set_annotation(annotation.toStdString()); - if (destroyOnZoneChange) + } + if (destroyOnZoneChange) { info->set_destroy_on_zone_change(true); - if (doesntUntap) + } + if (doesntUntap) { info->set_doesnt_untap(true); + } QMapIterator cardCounterIterator(counters); while (cardCounterIterator.hasNext()) { @@ -172,4 +140,4 @@ void Server_Card::getInfo(ServerInfo_Card *info) info->set_attach_zone(parentCard->getZone()->getName().toStdString()); info->set_attach_card_id(parentCard->getId()); } -} \ No newline at end of file +} diff --git a/common/server_card.h b/common/server_card.h index a3564bbc..b397e555 100644 --- a/common/server_card.h +++ b/common/server_card.h @@ -41,7 +41,7 @@ private: bool attacking; bool facedown; QString color; - int power, toughness; + QString ptString; QString annotation; bool destroyOnZoneChange; bool doesntUntap; @@ -102,7 +102,10 @@ public: { return color; } - QString getPT() const; + QString getPT() const + { + return ptString; + } QString getAnnotation() const { return annotation; @@ -154,7 +157,10 @@ public: { color = _color; } - void setPT(const QString &_pt); + void setPT(const QString &_pt) + { + ptString = _pt; + } void setAnnotation(const QString &_annotation) { annotation = _annotation; diff --git a/common/server_player.cpp b/common/server_player.cpp index 8289c640..28acf518 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -102,8 +102,9 @@ void Server_Player::prepareDestroy() delete deck; playerMutex.lock(); - if (userInterface) + if (userInterface) { userInterface->playerRemovedFromGame(game); + } playerMutex.unlock(); clearZones(); @@ -122,8 +123,9 @@ int Server_Player::newCounterId() const QMapIterator i(counters); while (i.hasNext()) { Server_Counter *c = i.next().value(); - if (c->getId() > id) + if (c->getId() > id) { id = c->getId(); + } } return id + 1; } @@ -131,11 +133,10 @@ int Server_Player::newCounterId() const int Server_Player::newArrowId() const { int id = 0; - QMapIterator i(arrows); - while (i.hasNext()) { - Server_Arrow *a = i.next().value(); - if (a->getId() > id) + for (Server_Arrow *a : arrows) { + if (a->getId() > id) { id = a->getId(); + } } return id + 1; } @@ -175,19 +176,22 @@ void Server_Player::setupZones() for (int i = 0; i < listRoot->size(); ++i) { auto *currentZone = dynamic_cast(listRoot->at(i)); Server_CardZone *z; - if (currentZone->getName() == DECK_ZONE_MAIN) + if (currentZone->getName() == DECK_ZONE_MAIN) { z = deckZone; - else if (currentZone->getName() == DECK_ZONE_SIDE) + } else if (currentZone->getName() == DECK_ZONE_SIDE) { z = sbZone; - else + } else { continue; + } for (int j = 0; j < currentZone->size(); ++j) { auto *currentCard = dynamic_cast(currentZone->at(j)); - if (!currentCard) + if (!currentCard) { continue; - for (int k = 0; k < currentCard->getNumber(); ++k) + } + for (int k = 0; k < currentCard->getNumber(); ++k) { z->insertCard(new Server_Card(currentCard->getName(), nextCardId++, 0, 0, z), -1, 0); + } } } @@ -197,25 +201,28 @@ void Server_Player::setupZones() const QString targetZone = QString::fromStdString(m.target_zone()); Server_CardZone *start, *target; - if (startZone == DECK_ZONE_MAIN) + if (startZone == DECK_ZONE_MAIN) { start = deckZone; - else if (startZone == DECK_ZONE_SIDE) + } else if (startZone == DECK_ZONE_SIDE) { start = sbZone; - else + } else { continue; - if (targetZone == DECK_ZONE_MAIN) + } + if (targetZone == DECK_ZONE_MAIN) { target = deckZone; - else if (targetZone == DECK_ZONE_SIDE) + } else if (targetZone == DECK_ZONE_SIDE) { target = sbZone; - else + } else { continue; + } - for (int j = 0; j < start->getCards().size(); ++j) + for (int j = 0; j < start->getCards().size(); ++j) { if (start->getCards()[j]->getName() == QString::fromStdString(m.card_name())) { Server_Card *card = start->getCard(j, nullptr, true); target->insertCard(card, -1, 0); break; } + } } deckZone->shuffle(); @@ -223,19 +230,19 @@ void Server_Player::setupZones() void Server_Player::clearZones() { - QMapIterator zoneIterator(zones); - while (zoneIterator.hasNext()) - delete zoneIterator.next().value(); + for (Server_CardZone *zone : zones) { + delete zone; + } zones.clear(); - QMapIterator counterIterator(counters); - while (counterIterator.hasNext()) - delete counterIterator.next().value(); + for (Server_Counter *counter : counters) { + delete counter; + } counters.clear(); - QMapIterator arrowIterator(arrows); - while (arrowIterator.hasNext()) - delete arrowIterator.next().value(); + for (Server_Arrow *arrow : arrows) { + delete arrow; + } arrows.clear(); lastDrawList.clear(); @@ -244,8 +251,9 @@ void Server_Player::clearZones() void Server_Player::getProperties(ServerInfo_PlayerProperties &result, bool withUserInfo) { result.set_player_id(playerId); - if (withUserInfo) + if (withUserInfo) { copyUserInfo(*(result.mutable_user_info()), true); + } result.set_spectator(spectator); if (!spectator) { result.set_conceded(conceded); @@ -253,8 +261,9 @@ void Server_Player::getProperties(ServerInfo_PlayerProperties &result, bool with result.set_ready_start(readyStart); } result.set_judge(judge); - if (deck) + if (deck) { result.set_deck_hash(deck->getDeckHash().toStdString()); + } result.set_ping_seconds(pingTime); } @@ -271,8 +280,9 @@ void Server_Player::addArrow(Server_Arrow *arrow) bool Server_Player::deleteArrow(int arrowId) { Server_Arrow *arrow = arrows.value(arrowId, 0); - if (!arrow) + if (!arrow) { return false; + } arrows.remove(arrowId); delete arrow; return true; @@ -287,8 +297,9 @@ Response::ResponseCode Server_Player::drawCards(GameEventStorage &ges, int numbe { Server_CardZone *deckZone = zones.value("deck"); Server_CardZone *handZone = zones.value("hand"); - if (deckZone->getCards().size() < number) + if (deckZone->getCards().size() < number) { number = deckZone->getCards().size(); + } Event_DrawCards eventOthers; eventOthers.set_number(number); @@ -331,15 +342,17 @@ public: inline bool operator()(QPair a, QPair b) { if (a.second < x) { - if (b.second >= x) + if (b.second >= x) { return false; - else + } else { return (a.second > b.second); + } } else { - if (b.second < x) + if (b.second < x) { return true; - else + } else { return (a.second < b.second); + } } } }; @@ -355,36 +368,43 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, { // Disallow controller change to other zones than the table. if (((targetzone->getType() != ServerInfo_Zone::PublicZone) || !targetzone->hasCoords()) && - (startzone->getPlayer() != targetzone->getPlayer()) && !judge) + (startzone->getPlayer() != targetzone->getPlayer()) && !judge) { return Response::RespContextError; + } - if (!targetzone->hasCoords() && (x <= -1)) + if (!targetzone->hasCoords() && (x <= -1)) { x = targetzone->getCards().size(); + } QList> cardsToMove; QMap cardProperties; QSet cardIdsToMove; for (auto _card : _cards) { // The same card being moved twice would lead to undefined behaviour. - if (cardIdsToMove.contains(_card->card_id())) + if (cardIdsToMove.contains(_card->card_id())) { continue; + } cardIdsToMove.insert(_card->card_id()); // Consistency checks. In case the command contains illegal moves, try to resolve the legal ones still. int position; Server_Card *card = startzone->getCard(_card->card_id(), &position); - if (!card) + if (!card) { return Response::RespNameNotFound; - if (card->getParentCard()) + } + if (card->getParentCard()) { continue; - if (!card->getAttachedCards().isEmpty() && !targetzone->isColumnEmpty(x, y)) + } + if (!card->getAttachedCards().isEmpty() && !targetzone->isColumnEmpty(x, y)) { continue; + } cardsToMove.append(QPair(card, position)); cardProperties.insert(card, _card); } // In case all moves were filtered out, abort. - if (cardsToMove.isEmpty()) + if (cardsToMove.isEmpty()) { return Response::RespContextError; + } // 0 performs no sorting // 1 reverses the sorting @@ -398,40 +418,46 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, Server_Card *card = cardsToMove[cardIndex].first; const CardToMove *thisCardProperties = cardProperties.value(card); bool faceDown = thisCardProperties->has_face_down() ? thisCardProperties->face_down() : card->getFaceDown(); - if (!targetzone->hasCoords()) + if (!targetzone->hasCoords()) { faceDown = false; + } int originalPosition = cardsToMove[cardIndex].second; int position = startzone->removeCard(card); if (startzone->getName() == "hand") { - if (undoingDraw) + if (undoingDraw) { lastDrawList.removeAt(lastDrawList.indexOf(card->getId())); - else if (lastDrawList.contains(card->getId())) + } else if (lastDrawList.contains(card->getId())) { lastDrawList.clear(); + } } if ((startzone == targetzone) && !startzone->hasCoords()) { if (!secondHalf && (originalPosition < x)) { xIndex = -1; secondHalf = true; - } else if (secondHalf) + } else if (secondHalf) { --xIndex; - else + } else { ++xIndex; - } else + } + } else { ++xIndex; + } int newX = x + xIndex; // Attachment relationships can be retained when moving a card onto the opponent's table if (startzone->getName() != targetzone->getName()) { // Delete all attachment relationships - if (card->getParentCard()) + if (card->getParentCard()) { card->setParentCard(nullptr); + } // Make a copy of the list because the original one gets modified during the loop QList attachedCards = card->getAttachedCards(); - for (auto &attachedCard : attachedCards) + for (auto &attachedCard : attachedCards) { attachedCard->getZone()->getPlayer()->unattachCard(ges, attachedCard); + } } if (startzone != targetzone) { @@ -445,8 +471,9 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, if ((arrow->getStartCard() == card) || (arrow->getTargetItem() == card)) arrowsToDelete.append(arrow->getId()); } - for (int j : arrowsToDelete) + for (int j : arrowsToDelete) { player->deleteArrow(j); + } } } @@ -461,8 +488,9 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, if (!targetzone->hasCoords()) { y = 0; card->resetState(); - } else + } else { newX = targetzone->getFreeGridColumn(newX, y, card->getName(), faceDown); + } targetzone->insertCard(card, newX, y); @@ -479,14 +507,17 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, bool sourceHiddenToOthers = card->getFaceDown() || (startzone->getType() != ServerInfo_Zone::PublicZone); QString privateCardName, publicCardName; - if (!(sourceHiddenToPlayer && targetHiddenToPlayer)) + if (!(sourceHiddenToPlayer && targetHiddenToPlayer)) { privateCardName = card->getName(); - if (!(sourceHiddenToOthers && targetHiddenToOthers)) + } + if (!(sourceHiddenToOthers && targetHiddenToOthers)) { publicCardName = card->getName(); + } int oldCardId = card->getId(); - if ((faceDown && (startzone != targetzone)) || (targetzone->getPlayer() != startzone->getPlayer())) + if ((faceDown && (startzone != targetzone)) || (targetzone->getPlayer() != startzone->getPlayer())) { card->setId(targetzone->getPlayer()->newCardId()); + } card->setFaceDown(faceDown); // The player does not get to see which card he moved if it moves between two parts of hidden zones which @@ -499,8 +530,9 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, privateCardName = QString(); } int privatePosition = -1; - if (startzone->getType() == ServerInfo_Zone::HiddenZone) + if (startzone->getType() == ServerInfo_Zone::HiddenZone) { privatePosition = position; + } int publicNewX = newX; @@ -508,15 +540,17 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, eventOthers.set_start_player_id(startzone->getPlayer()->getPlayerId()); eventOthers.set_start_zone(startzone->getName().toStdString()); eventOthers.set_target_player_id(targetzone->getPlayer()->getPlayerId()); - if (startzone != targetzone) + if (startzone != targetzone) { eventOthers.set_target_zone(targetzone->getName().toStdString()); + } eventOthers.set_y(y); eventOthers.set_face_down(faceDown); Event_MoveCard eventPrivate(eventOthers); eventPrivate.set_card_id(privateOldCardId); - if (!privateCardName.isEmpty()) + if (!privateCardName.isEmpty()) { eventPrivate.set_card_name(privateCardName.toStdString()); + } eventPrivate.set_position(privatePosition); eventPrivate.set_new_card_id(privateNewCardId); eventPrivate.set_x(newX); @@ -526,32 +560,38 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, // all cards are equal. if (((startzone->getType() == ServerInfo_Zone::HiddenZone) && ((startzone->getCardsBeingLookedAt() > position) || (startzone->getCardsBeingLookedAt() == -1))) || - (startzone->getType() == ServerInfo_Zone::PublicZone)) + (startzone->getType() == ServerInfo_Zone::PublicZone)) { position = -1; + } if ((targetzone->getType() == ServerInfo_Zone::HiddenZone) && - ((targetzone->getCardsBeingLookedAt() > newX) || (targetzone->getCardsBeingLookedAt() == -1))) + ((targetzone->getCardsBeingLookedAt() > newX) || (targetzone->getCardsBeingLookedAt() == -1))) { publicNewX = -1; + } eventOthers.set_x(publicNewX); eventOthers.set_position(position); if ((startzone->getType() == ServerInfo_Zone::PublicZone) || (targetzone->getType() == ServerInfo_Zone::PublicZone)) { eventOthers.set_card_id(oldCardId); - if (!publicCardName.isEmpty()) + if (!publicCardName.isEmpty()) { eventOthers.set_card_name(publicCardName.toStdString()); + } eventOthers.set_new_card_id(card->getId()); } ges.enqueueGameEvent(eventPrivate, playerId, GameEventStorageItem::SendToPrivate, playerId); ges.enqueueGameEvent(eventOthers, playerId, GameEventStorageItem::SendToOthers); - if (thisCardProperties->tapped()) + if (thisCardProperties->tapped()) { setCardAttrHelper(ges, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), card->getId(), AttrTapped, "1"); + } QString ptString = QString::fromStdString(thisCardProperties->pt()); - if (!ptString.isEmpty() && !faceDown) - setCardAttrHelper(ges, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), card->getId(), - AttrPT, ptString); + if (!faceDown) { + ptString = QString::fromStdString(thisCardProperties->pt()); + } + setCardAttrHelper(ges, targetzone->getPlayer()->getPlayerId(), targetzone->getName(), card->getId(), AttrPT, + ptString); } if (startzone->getAlwaysRevealTopCard() && !startzone->getCards().isEmpty() && (originalPosition == 0)) { Event_RevealCards revealEvent; @@ -570,13 +610,15 @@ Response::ResponseCode Server_Player::moveCard(GameEventStorage &ges, ges.enqueueGameEvent(revealEvent, playerId); } } - if (undoingDraw) + if (undoingDraw) { ges.setGameEventContext(Context_UndoDraw()); - else + } else { ges.setGameEventContext(Context_MoveCard()); + } - if (startzone->hasCoords() && fixFreeSpaces) + if (startzone->hasCoords() && fixFreeSpaces) { startzone->fixFreeSpaces(ges); + } return Response::RespOk; } @@ -597,8 +639,9 @@ void Server_Player::unattachCard(GameEventStorage &ges, Server_Card *card) moveCard(ges, zone, QList() << cardToMove, zone, -1, card->getY(), card->getFaceDown()); delete cardToMove; - if (parentCard->getZone()) + if (parentCard->getZone()) { parentCard->getZone()->updateCardCoordinates(parentCard, parentCard->getX(), parentCard->getY()); + } } Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, @@ -609,32 +652,38 @@ Response::ResponseCode Server_Player::setCardAttrHelper(GameEventStorage &ges, const QString &attrValue) { Server_CardZone *zone = getZones().value(zoneName); - if (!zone) + if (!zone) { return Response::RespNameNotFound; - if (!zone->hasCoords()) + } + if (!zone->hasCoords()) { return Response::RespContextError; + } QString result; if (cardId == -1) { QListIterator CardIterator(zone->getCards()); while (CardIterator.hasNext()) { result = CardIterator.next()->setAttribute(attribute, attrValue, true); - if (result.isNull()) + if (result.isNull()) { return Response::RespInvalidCommand; + } } } else { Server_Card *card = zone->getCard(cardId); - if (!card) + if (!card) { return Response::RespNameNotFound; + } result = card->setAttribute(attribute, attrValue, false); - if (result.isNull()) + if (result.isNull()) { return Response::RespInvalidCommand; + } } Event_SetCardAttr event; event.set_zone_name(zone->getName().toStdString()); - if (cardId != -1) + if (cardId != -1) { event.set_card_id(cardId); + } event.set_attribute(attribute); event.set_attr_value(result.toStdString()); ges.enqueueGameEvent(event, targetPlayerId); @@ -652,11 +701,13 @@ Server_Player::cmdLeaveGame(const Command_LeaveGame & /*cmd*/, ResponseContainer Response::ResponseCode Server_Player::cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContainer & /*rc*/, GameEventStorage & /*ges*/) { - if ((game->getHostId() != playerId) && !(userInfo->user_level() & ServerInfo_User::IsModerator)) + if ((game->getHostId() != playerId) && !(userInfo->user_level() & ServerInfo_User::IsModerator)) { return Response::RespFunctionNotAllowed; + } - if (!game->kickPlayer(cmd.player_id())) + if (!game->kickPlayer(cmd.player_id())) { return Response::RespNameNotFound; + } return Response::RespOk; } @@ -664,8 +715,9 @@ Server_Player::cmdKickFromGame(const Command_KickFromGame &cmd, ResponseContaine Response::ResponseCode Server_Player::cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &rc, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } DeckList *newDeck; if (cmd.has_deck_id()) { @@ -675,11 +727,13 @@ Server_Player::cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &r } catch (Response::ResponseCode &r) { return r; } - } else + } else { newDeck = new DeckList(QString::fromStdString(cmd.deck())); + } - if (!newDeck) + if (!newDeck) { return Response::RespInternalError; + } delete deck; deck = newDeck; @@ -706,18 +760,23 @@ Response::ResponseCode Server_Player::cmdSetSideboardPlan(const Command_SetSideb ResponseContainer & /*rc*/, GameEventStorage & /*ges*/) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; - if (readyStart) + } + if (readyStart) { return Response::RespContextError; - if (!deck) + } + if (!deck) { return Response::RespContextError; - if (sideboardLocked) + } + if (sideboardLocked) { return Response::RespContextError; + } QList sideboardPlan; - for (int i = 0; i < cmd.move_list_size(); ++i) + for (int i = 0; i < cmd.move_list_size(); ++i) { sideboardPlan.append(cmd.move_list(i)); + } deck->setCurrentSideboardPlan(sideboardPlan); return Response::RespOk; @@ -727,18 +786,23 @@ Response::ResponseCode Server_Player::cmdSetSideboardLock(const Command_SetSideb ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; - if (readyStart) + } + if (readyStart) { return Response::RespContextError; - if (!deck) + } + if (!deck) { return Response::RespContextError; - if (sideboardLocked == cmd.locked()) + } + if (sideboardLocked == cmd.locked()) { return Response::RespContextError; + } sideboardLocked = cmd.locked(); - if (sideboardLocked) + if (sideboardLocked) { deck->setCurrentSideboardPlan(QList()); + } Event_PlayerPropertiesChanged event; event.mutable_player_properties()->set_sideboard_locked(sideboardLocked); @@ -751,12 +815,15 @@ Response::ResponseCode Server_Player::cmdSetSideboardLock(const Command_SetSideb Response::ResponseCode Server_Player::cmdConcede(const Command_Concede & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; - if (!game->getGameStarted()) + } + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } setConceded(true); game->removeArrowsRelatedToPlayer(ges, this); @@ -769,8 +836,9 @@ Server_Player::cmdConcede(const Command_Concede & /*cmd*/, ResponseContainer & / ges.setGameEventContext(Context_Concede()); game->stopGameIfFinished(); - if (game->getGameStarted() && (game->getActivePlayer() == playerId)) + if (game->getGameStarted() && (game->getActivePlayer() == playerId)) { game->nextTurn(); + } return Response::RespOk; } @@ -778,12 +846,15 @@ Server_Player::cmdConcede(const Command_Concede & /*cmd*/, ResponseContainer & / Response::ResponseCode Server_Player::cmdUnconcede(const Command_Unconcede & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; - if (!game->getGameStarted()) + } + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (!conceded) + } + if (!conceded) { return Response::RespContextError; + } setConceded(false); @@ -820,14 +891,17 @@ Response::ResponseCode Server_Player::cmdJudge(const Command_Judge &cmd, Respons Response::ResponseCode Server_Player::cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!deck || game->getGameStarted()) + if (!deck || game->getGameStarted()) { return Response::RespContextError; + } - if (readyStart == cmd.ready()) + if (readyStart == cmd.ready()) { return Response::RespContextError; + } setReadyStart(cmd.ready()); @@ -836,8 +910,9 @@ Server_Player::cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer & ges.enqueueGameEvent(event, playerId); ges.setGameEventContext(Context_ReadyStart()); - if (cmd.ready()) + if (cmd.ready()) { game->startGameIfReady(); + } return Response::RespOk; } @@ -845,8 +920,9 @@ Server_Player::cmdReadyStart(const Command_ReadyStart &cmd, ResponseContainer & Response::ResponseCode Server_Player::cmdGameSay(const Command_GameSay &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator && !game->getSpectatorsCanTalk() && !(userInfo->user_level() & ServerInfo_User::IsModerator)) + if (spectator && !game->getSpectatorsCanTalk() && !(userInfo->user_level() & ServerInfo_User::IsModerator)) { return Response::RespFunctionNotAllowed; + } Event_GameSay event; event.set_message(cmd.message()); @@ -863,21 +939,26 @@ Server_Player::cmdGameSay(const Command_GameSay &cmd, ResponseContainer & /*rc*/ Response::ResponseCode Server_Player::cmdShuffle(const Command_Shuffle &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; + } - if (conceded) + if (conceded) { return Response::RespContextError; + } - if (cmd.has_zone_name() && cmd.zone_name() != "deck") + if (cmd.has_zone_name() && cmd.zone_name() != "deck") { return Response::RespFunctionNotAllowed; + } Server_CardZone *zone = zones.value("deck"); - if (!zone) + if (!zone) { return Response::RespNameNotFound; + } zone->shuffle(cmd.start(), cmd.end()); @@ -902,13 +983,16 @@ Server_Player::cmdShuffle(const Command_Shuffle &cmd, ResponseContainer & /*rc*/ Response::ResponseCode Server_Player::cmdMulligan(const Command_Mulligan & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *hand = zones.value("hand"); int number = (hand->getCards().size() <= 1) ? initialCards : hand->getCards().size() - 1; @@ -926,8 +1010,9 @@ Server_Player::cmdMulligan(const Command_Mulligan & /*cmd*/, ResponseContainer & drawCards(ges, number); - if (number == initialCards) + if (number == initialCards) { number = -1; + } Context_Mulligan context; context.set_number(static_cast(number)); @@ -939,10 +1024,12 @@ Server_Player::cmdMulligan(const Command_Mulligan & /*cmd*/, ResponseContainer & Response::ResponseCode Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Event_RollDie event; event.set_sides(cmd.sides()); @@ -955,13 +1042,16 @@ Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/ Response::ResponseCode Server_Player::cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } return drawCards(ges, cmd.number()); } @@ -969,16 +1059,20 @@ Server_Player::cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer & /* Response::ResponseCode Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } - if (lastDrawList.isEmpty()) + if (lastDrawList.isEmpty()) { return Response::RespContextError; + } Response::ResponseCode retVal; auto *cardToMove = new CardToMove; @@ -993,37 +1087,47 @@ Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer & Response::ResponseCode Server_Player::cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Player *startPlayer = game->getPlayers().value(cmd.has_start_player_id() ? cmd.start_player_id() : playerId); - if (!startPlayer) + if (!startPlayer) { return Response::RespNameNotFound; + } Server_CardZone *startZone = startPlayer->getZones().value(QString::fromStdString(cmd.start_zone())); - if (!startZone) + if (!startZone) { return Response::RespNameNotFound; + } - if ((startPlayer != this) && (!startZone->getPlayersWithWritePermission().contains(playerId)) && !judge) + if ((startPlayer != this) && (!startZone->getPlayersWithWritePermission().contains(playerId)) && !judge) { return Response::RespContextError; + } Server_Player *targetPlayer = game->getPlayers().value(cmd.target_player_id()); - if (!targetPlayer) + if (!targetPlayer) { return Response::RespNameNotFound; + } Server_CardZone *targetZone = targetPlayer->getZones().value(QString::fromStdString(cmd.target_zone())); - if (!targetZone) + if (!targetZone) { return Response::RespNameNotFound; + } - if ((startPlayer != this) && (targetPlayer != this) && !judge) + if ((startPlayer != this) && (targetPlayer != this) && !judge) { return Response::RespContextError; + } QList cardsToMove; - for (int i = 0; i < cmd.cards_to_move().card_size(); ++i) + for (int i = 0; i < cmd.cards_to_move().card_size(); ++i) { cardsToMove.append(&cmd.cards_to_move().card(i)); + } return moveCard(ges, startZone, cardsToMove, targetZone, cmd.x(), cmd.y()); } @@ -1031,41 +1135,50 @@ Server_Player::cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer & /*rc Response::ResponseCode Server_Player::cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; - if (!zone->hasCoords()) + } + if (!zone->hasCoords()) { return Response::RespContextError; + } Server_Card *card = zone->getCard(cmd.card_id()); - if (!card) + if (!card) { return Response::RespNameNotFound; + } const bool faceDown = cmd.face_down(); - if (faceDown == card->getFaceDown()) + if (faceDown == card->getFaceDown()) { return Response::RespContextError; + } card->setFaceDown(faceDown); Event_FlipCard event; event.set_zone_name(zone->getName().toStdString()); event.set_card_id(card->getId()); - if (!faceDown) + if (!faceDown) { event.set_card_name(card->getName().toStdString()); + } event.set_face_down(faceDown); ges.enqueueGameEvent(event, playerId); QString ptString = QString::fromStdString(cmd.pt()); - if (!ptString.isEmpty() && !faceDown) + if (!ptString.isEmpty() && !faceDown) { setCardAttrHelper(ges, playerId, zone->getName(), card->getId(), AttrPT, ptString); + } return Response::RespOk; } @@ -1073,21 +1186,26 @@ Server_Player::cmdFlipCard(const Command_FlipCard &cmd, ResponseContainer & /*rc Response::ResponseCode Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *startzone = zones.value(QString::fromStdString(cmd.start_zone())); - if (!startzone) + if (!startzone) { return Response::RespNameNotFound; + } Server_Card *card = startzone->getCard(cmd.card_id()); - if (!card) + if (!card) { return Response::RespNameNotFound; + } Server_Player *targetPlayer = nullptr; Server_CardZone *targetzone = nullptr; @@ -1095,27 +1213,35 @@ Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & if (cmd.has_target_player_id()) { targetPlayer = game->getPlayers().value(cmd.target_player_id()); - if (!targetPlayer) + if (!targetPlayer) { return Response::RespNameNotFound; - } else if (!card->getParentCard()) + } + } else if (!card->getParentCard()) { return Response::RespContextError; - if (targetPlayer) + } + if (targetPlayer) { targetzone = targetPlayer->getZones().value(QString::fromStdString(cmd.target_zone())); + } if (targetzone) { // This is currently enough to make sure cards don't get attached to a card that is not on the table. // Possibly a flag will have to be introduced for this sometime. - if (!targetzone->hasCoords()) + if (!targetzone->hasCoords()) { return Response::RespContextError; - if (cmd.has_target_card_id()) + } + if (cmd.has_target_card_id()) { targetCard = targetzone->getCard(cmd.target_card_id()); + } if (targetCard) { - if (targetCard->getParentCard()) + if (targetCard->getParentCard()) { return Response::RespContextError; - } else + } + } else { return Response::RespNameNotFound; + } } - if (!startzone->hasCoords()) + if (!startzone->hasCoords()) { return Response::RespContextError; + } // Get all arrows pointing to or originating from the card being attached and delete them. QMapIterator playerIterator(game->getPlayers()); @@ -1125,8 +1251,9 @@ Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & QList toDelete; for (auto a : arrows) { auto *tCard = qobject_cast(a->getTargetItem()); - if ((tCard == card) || (a->getStartCard() == card)) + if ((tCard == card) || (a->getStartCard() == card)) { toDelete.append(a); + } } for (auto &i : toDelete) { Event_DeleteArrow event; @@ -1140,8 +1267,9 @@ Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & // Unattach all cards attached to the card being attached. // Make a copy of the list because its contents change during the loop otherwise. QList attachedList = card->getAttachedCards(); - for (auto &i : attachedList) + for (const auto &i : attachedList) { i->getZone()->getPlayer()->unattachCard(ges, i); + } card->setParentCard(targetCard); const int oldX = card->getX(); @@ -1166,8 +1294,9 @@ Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & ges.enqueueGameEvent(event, playerId); startzone->fixFreeSpaces(ges); - } else + } else { unattachCard(ges, card); + } return Response::RespOk; } @@ -1175,27 +1304,34 @@ Server_Player::cmdAttachCard(const Command_AttachCard &cmd, ResponseContainer & Response::ResponseCode Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer &rc, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; + } QString cardName = QString::fromStdString(cmd.card_name()); int x = cmd.x(); int y = cmd.y(); - if (zone->hasCoords()) + if (zone->hasCoords()) { x = zone->getFreeGridColumn(x, y, cardName, false); - if (x < 0) + } + if (x < 0) { x = 0; - if (y < 0) + } + if (y < 0) { y = 0; + } Server_Card *card = new Server_Card(cardName, newCardId(), x, y); card->moveToThread(thread()); @@ -1219,8 +1355,9 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer ges.enqueueGameEvent(event, playerId); // check if the token is a replacement for an existing card - if (cmd.target_card_id() < 0) + if (cmd.target_card_id() < 0) { return Response::RespOk; + } Command_AttachCard cmd2; cmd2.set_start_zone(cmd.target_zone()); @@ -1236,51 +1373,63 @@ Server_Player::cmdCreateToken(const Command_CreateToken &cmd, ResponseContainer Response::ResponseCode Server_Player::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Player *startPlayer = game->getPlayers().value(cmd.start_player_id()); Server_Player *targetPlayer = game->getPlayers().value(cmd.target_player_id()); - if (!startPlayer || !targetPlayer) + if (!startPlayer || !targetPlayer) { return Response::RespNameNotFound; + } QString startZoneName = QString::fromStdString(cmd.start_zone()); Server_CardZone *startZone = startPlayer->getZones().value(startZoneName); bool playerTarget = !cmd.has_target_zone(); Server_CardZone *targetZone = nullptr; - if (!playerTarget) + if (!playerTarget) { targetZone = targetPlayer->getZones().value(QString::fromStdString(cmd.target_zone())); - if (!startZone || (!targetZone && !playerTarget)) + } + if (!startZone || (!targetZone && !playerTarget)) { return Response::RespNameNotFound; - if (startZone->getType() != ServerInfo_Zone::PublicZone) + } + if (startZone->getType() != ServerInfo_Zone::PublicZone) { return Response::RespContextError; + } Server_Card *startCard = startZone->getCard(cmd.start_card_id()); - if (!startCard) + if (!startCard) { return Response::RespNameNotFound; + } Server_Card *targetCard = nullptr; if (!playerTarget) { - if (targetZone->getType() != ServerInfo_Zone::PublicZone) + if (targetZone->getType() != ServerInfo_Zone::PublicZone) { return Response::RespContextError; + } targetCard = targetZone->getCard(cmd.target_card_id()); } Server_ArrowTarget *targetItem; - if (playerTarget) + if (playerTarget) { targetItem = targetPlayer; - else + } else { targetItem = targetCard; - if (!targetItem) + } + if (!targetItem) { return Response::RespNameNotFound; + } QMapIterator arrowIterator(arrows); while (arrowIterator.hasNext()) { Server_Arrow *temp = arrowIterator.next().value(); - if ((temp->getStartCard() == startCard) && (temp->getTargetItem() == targetItem)) + if ((temp->getStartCard() == startCard) && (temp->getTargetItem() == targetItem)) { return Response::RespContextError; + } } auto arrow = new Server_Arrow(newArrowId(), startCard, targetItem, cmd.arrow_color()); @@ -1306,16 +1455,20 @@ Server_Player::cmdCreateArrow(const Command_CreateArrow &cmd, ResponseContainer Response::ResponseCode Server_Player::cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } - if (!deleteArrow(cmd.arrow_id())) + if (!deleteArrow(cmd.arrow_id())) { return Response::RespNameNotFound; + } Event_DeleteArrow event; event.set_arrow_id(cmd.arrow_id()); @@ -1327,13 +1480,16 @@ Server_Player::cmdDeleteArrow(const Command_DeleteArrow &cmd, ResponseContainer Response::ResponseCode Server_Player::cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } return setCardAttrHelper(ges, playerId, QString::fromStdString(cmd.zone()), cmd.card_id(), cmd.attribute(), QString::fromStdString(cmd.attr_value())); @@ -1342,23 +1498,29 @@ Server_Player::cmdSetCardAttr(const Command_SetCardAttr &cmd, ResponseContainer Response::ResponseCode Server_Player::cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; - if (!zone->hasCoords()) + } + if (!zone->hasCoords()) { return Response::RespContextError; + } Server_Card *card = zone->getCard(cmd.card_id()); - if (!card) + if (!card) { return Response::RespNameNotFound; + } card->setCounter(cmd.counter_id(), cmd.counter_value()); @@ -1375,23 +1537,29 @@ Server_Player::cmdSetCardCounter(const Command_SetCardCounter &cmd, ResponseCont Response::ResponseCode Server_Player::cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; - if (!zone->hasCoords()) + } + if (!zone->hasCoords()) { return Response::RespContextError; + } Server_Card *card = zone->getCard(cmd.card_id()); - if (!card) + if (!card) { return Response::RespNameNotFound; + } int newValue = card->getCounter(cmd.counter_id()) + cmd.counter_delta(); card->setCounter(cmd.counter_id(), newValue); @@ -1409,17 +1577,21 @@ Server_Player::cmdIncCardCounter(const Command_IncCardCounter &cmd, ResponseCont Response::ResponseCode Server_Player::cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Counter *c = counters.value(cmd.counter_id(), 0); - if (!c) + if (!c) { return Response::RespNameNotFound; + } c->setCount(c->getCount() + cmd.delta()); @@ -1434,13 +1606,16 @@ Server_Player::cmdIncCounter(const Command_IncCounter &cmd, ResponseContainer & Response::ResponseCode Server_Player::cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Counter *c = new Server_Counter(newCounterId(), QString::fromStdString(cmd.counter_name()), cmd.counter_color(), cmd.radius(), cmd.value()); @@ -1461,18 +1636,21 @@ Server_Player::cmdCreateCounter(const Command_CreateCounter &cmd, ResponseContai Response::ResponseCode Server_Player::cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Counter *c = counters.value(cmd.counter_id(), 0); - ; - if (!c) + if (!c) { return Response::RespNameNotFound; + } c->setCount(cmd.value()); @@ -1487,17 +1665,21 @@ Server_Player::cmdSetCounter(const Command_SetCounter &cmd, ResponseContainer & Response::ResponseCode Server_Player::cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Counter *counter = counters.value(cmd.counter_id(), 0); - if (!counter) + if (!counter) { return Response::RespNameNotFound; + } counters.remove(cmd.counter_id()); delete counter; @@ -1511,15 +1693,18 @@ Server_Player::cmdDelCounter(const Command_DelCounter &cmd, ResponseContainer & Response::ResponseCode Server_Player::cmdNextTurn(const Command_NextTurn & /*cmd*/, ResponseContainer & /*rc*/, GameEventStorage & /*ges*/) { - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; + } if (!judge) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (conceded) + if (conceded) { return Response::RespContextError; + } } game->nextTurn(); @@ -1530,18 +1715,22 @@ Response::ResponseCode Server_Player::cmdSetActivePhase(const Command_SetActiveP ResponseContainer & /*rc*/, GameEventStorage & /*ges*/) { - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; + } if (!judge) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (conceded) + if (conceded) { return Response::RespContextError; + } - if (game->getActivePlayer() != playerId) + if (game->getActivePlayer() != playerId) { return Response::RespContextError; + } } game->setActivePhase(cmd.phase()); @@ -1552,17 +1741,21 @@ Response::ResponseCode Server_Player::cmdSetActivePhase(const Command_SetActiveP Response::ResponseCode Server_Player::cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, GameEventStorage &ges) { - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; + } Server_Player *otherPlayer = game->getPlayers().value(cmd.player_id()); - if (!otherPlayer) + if (!otherPlayer) { return Response::RespNameNotFound; + } Server_CardZone *zone = otherPlayer->getZones().value(QString::fromStdString(cmd.zone_name())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; - if (!((zone->getType() == ServerInfo_Zone::PublicZone) || (this == otherPlayer))) + } + if (!((zone->getType() == ServerInfo_Zone::PublicZone) || (this == otherPlayer))) { return Response::RespContextError; + } int numberCards = cmd.number_cards(); const QList &cards = zone->getCards(); @@ -1579,9 +1772,9 @@ Server_Player::cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, G QString displayedName = card->getFaceDown() ? QString() : card->getName(); ServerInfo_Card *cardInfo = zoneInfo->add_card_list(); cardInfo->set_name(displayedName.toStdString()); - if (zone->getType() == ServerInfo_Zone::HiddenZone) + if (zone->getType() == ServerInfo_Zone::HiddenZone) { cardInfo->set_id(i); - else { + } else { cardInfo->set_id(card->getId()); cardInfo->set_x(card->getX()); cardInfo->set_y(card->getY()); @@ -1625,17 +1818,21 @@ Server_Player::cmdDumpZone(const Command_DumpZone &cmd, ResponseContainer &rc, G Response::ResponseCode Server_Player::cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } Server_Player *otherPlayer = game->getPlayers().value(cmd.player_id()); - if (!otherPlayer) + if (!otherPlayer) { return Response::RespNameNotFound; + } Server_CardZone *zone = otherPlayer->getZones().value(QString::fromStdString(cmd.zone_name())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; + } if (zone->getType() == ServerInfo_Zone::HiddenZone) { zone->setCardsBeingLookedAt(0); @@ -1651,13 +1848,16 @@ Server_Player::cmdStopDumpZone(const Command_StopDumpZone &cmd, ResponseContaine Response::ResponseCode Server_Player::cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) { - if (spectator) + if (spectator) { return Response::RespFunctionNotAllowed; + } - if (!game->getGameStarted()) + if (!game->getGameStarted()) { return Response::RespGameNotStarted; - if (conceded) + } + if (conceded) { return Response::RespContextError; + } if (cmd.has_player_id()) { Server_Player *otherPlayer = game->getPlayers().value(cmd.player_id()); @@ -1665,27 +1865,31 @@ Server_Player::cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer return Response::RespNameNotFound; } Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone_name())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; + } QList cardsToReveal; if (cmd.top_cards() != -1) { for (int i = 0; i < cmd.top_cards(); i++) { Server_Card *card = zone->getCard(i); - if (!card) + if (!card) { return Response::RespNameNotFound; + } cardsToReveal.append(card); } - } else if (!cmd.has_card_id()) + } else if (!cmd.has_card_id()) { cardsToReveal = zone->getCards(); - else if (cmd.card_id() == -2) { - if (zone->getCards().isEmpty()) + } else if (cmd.card_id() == -2) { + if (zone->getCards().isEmpty()) { return Response::RespContextError; + } cardsToReveal.append(zone->getCards().at(rng->rand(0, zone->getCards().size() - 1))); } else { Server_Card *card = zone->getCard(cmd.card_id()); - if (!card) + if (!card) { return Response::RespNameNotFound; + } cardsToReveal.append(card); } @@ -1693,10 +1897,12 @@ Server_Player::cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer eventOthers.set_grant_write_access(cmd.grant_write_access()); eventOthers.set_zone_name(zone->getName().toStdString()); eventOthers.set_number_of_cards(cardsToReveal.size()); - if (cmd.has_card_id()) + if (cmd.has_card_id()) { eventOthers.set_card_id(cmd.card_id()); - if (cmd.has_player_id()) + } + if (cmd.has_player_id()) { eventOthers.set_other_player_id(cmd.player_id()); + } Event_RevealCards eventPrivate(eventOthers); @@ -1732,16 +1938,18 @@ Server_Player::cmdRevealCards(const Command_RevealCards &cmd, ResponseContainer } if (cmd.has_player_id()) { - if (cmd.grant_write_access()) + if (cmd.grant_write_access()) { zone->addWritePermission(cmd.player_id()); + } ges.enqueueGameEvent(eventPrivate, playerId, GameEventStorageItem::SendToPrivate, cmd.player_id()); ges.enqueueGameEvent(eventOthers, playerId, GameEventStorageItem::SendToOthers); } else { if (cmd.grant_write_access()) { const QList &playerIds = game->getPlayers().keys(); - for (int playerId : playerIds) + for (int playerId : playerIds) { zone->addWritePermission(playerId); + } } ges.enqueueGameEvent(eventPrivate, playerId); @@ -1755,15 +1963,17 @@ Response::ResponseCode Server_Player::cmdChangeZoneProperties(const Command_Chan GameEventStorage &ges) { Server_CardZone *zone = zones.value(QString::fromStdString(cmd.zone_name())); - if (!zone) + if (!zone) { return Response::RespNameNotFound; + } Event_ChangeZoneProperties event; event.set_zone_name(cmd.zone_name()); if (cmd.has_always_reveal_top_card()) { - if (zone->getAlwaysRevealTopCard() == cmd.always_reveal_top_card()) + if (zone->getAlwaysRevealTopCard() == cmd.always_reveal_top_card()) { return Response::RespContextError; + } zone->setAlwaysRevealTopCard(cmd.always_reveal_top_card()); event.set_always_reveal_top_card(cmd.always_reveal_top_card()); @@ -1778,8 +1988,9 @@ Response::ResponseCode Server_Player::cmdChangeZoneProperties(const Command_Chan ges.enqueueGameEvent(revealEvent, playerId); } return Response::RespOk; - } else + } else { return Response::RespContextError; + } } Response::ResponseCode @@ -1898,8 +2109,9 @@ void Server_Player::sendGameEvent(const GameEventContainer &cont) { QMutexLocker locker(&playerMutex); - if (userInterface) + if (userInterface) { userInterface->sendProtocolItem(cont); + } } void Server_Player::setUserInterface(Server_AbstractUserInterface *_userInterface) @@ -1921,10 +2133,11 @@ void Server_Player::setUserInterface(Server_AbstractUserInterface *_userInterfac void Server_Player::disconnectClient() { - if (!(userInfo->user_level() & ServerInfo_User::IsRegistered) || spectator) + if (!(userInfo->user_level() & ServerInfo_User::IsRegistered) || spectator) { game->removePlayer(this, Event_Leave::USER_DISCONNECTED); - else + } else { setUserInterface(nullptr); + } } void Server_Player::getInfo(ServerInfo_Player *info, @@ -1933,19 +2146,21 @@ void Server_Player::getInfo(ServerInfo_Player *info, bool withUserInfo) { getProperties(*info->mutable_properties(), withUserInfo); - if (playerWhosAsking == this) - if (deck) + if (playerWhosAsking == this) { + if (deck) { info->set_deck_list(deck->writeToString_Native().toStdString()); + } + } - QMapIterator arrowIterator(arrows); - while (arrowIterator.hasNext()) - arrowIterator.next().value()->getInfo(info->add_arrow_list()); + for (Server_Arrow *arrow : arrows) { + arrow->getInfo(info->add_arrow_list()); + } - QMapIterator counterIterator(counters); - while (counterIterator.hasNext()) - counterIterator.next().value()->getInfo(info->add_counter_list()); + for (Server_Counter *counter : counters) { + counter->getInfo(info->add_counter_list()); + } - QMapIterator zoneIterator(zones); - while (zoneIterator.hasNext()) - zoneIterator.next().value()->getInfo(info->add_zone_list(), playerWhosAsking, omniscient); + for (Server_CardZone *zone : zones) { + zone->getInfo(info->add_zone_list(), playerWhosAsking, omniscient); + } }