mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 19:43:55 -07:00
Return Tagged Cards to Owner, if possible, on concede/leave
This commit is contained in:
parent
4f798286af
commit
a8bac1e468
1 changed files with 41 additions and 0 deletions
|
|
@ -886,6 +886,47 @@ Server_Player::cmdConcede(const Command_Concede & /*cmd*/, ResponseContainer & /
|
||||||
setConceded(true);
|
setConceded(true);
|
||||||
game->removeArrowsRelatedToPlayer(ges, this);
|
game->removeArrowsRelatedToPlayer(ges, this);
|
||||||
game->unattachCards(ges, this);
|
game->unattachCards(ges, this);
|
||||||
|
|
||||||
|
// Return cards to their rightful owners before conceding the game
|
||||||
|
static const QRegularExpression ownerRegex{"Owner: ?([^\n]+)"};
|
||||||
|
for (const auto &card : zones.value("table")->getCards()) {
|
||||||
|
if (card == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto ®exResult = ownerRegex.match(card->getAnnotation());
|
||||||
|
if (!regexResult.hasMatch()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
CardToMove cardToMove;
|
||||||
|
cardToMove.set_card_id(card->getId());
|
||||||
|
|
||||||
|
for (const auto &player : game->getPlayers()) {
|
||||||
|
if (player == nullptr || player->getUserInfo() == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &ownerToReturnTo = regexResult.captured(1);
|
||||||
|
const auto &correctOwner = QString::compare(QString::fromStdString(player->getUserInfo()->name()),
|
||||||
|
ownerToReturnTo, Qt::CaseInsensitive) == 0;
|
||||||
|
if (!correctOwner) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto &startZone = zones.value("table");
|
||||||
|
const auto &targetZone = player->getZones().value("table");
|
||||||
|
|
||||||
|
if (startZone == nullptr || targetZone == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
moveCard(ges, startZone, QList<const CardToMove *>() << &cardToMove, targetZone, 0, 0, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All borrowed cards have been returned, can now continue cleanup process
|
||||||
clearZones();
|
clearZones();
|
||||||
|
|
||||||
Event_PlayerPropertiesChanged event;
|
Event_PlayerPropertiesChanged event;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue