Return Tagged Cards to Owner, if possible, on concede/leave

This commit is contained in:
ZeldaZach 2024-12-27 18:23:39 -05:00
parent 4f798286af
commit a8bac1e468
No known key found for this signature in database

View file

@ -886,6 +886,47 @@ Server_Player::cmdConcede(const Command_Concede & /*cmd*/, ResponseContainer & /
setConceded(true);
game->removeArrowsRelatedToPlayer(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 &regexResult = 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();
Event_PlayerPropertiesChanged event;