mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 07:40:30 -08:00
Add a guard in case the printing info is empty for a related card. (#6087)
Took 4 hours 19 minutes Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
@@ -460,8 +460,21 @@ bool CardDatabase::isPreferredPrinting(const CardRef &cardRef) const
|
||||
|
||||
ExactCard CardDatabase::getCardFromSameSet(const QString &cardName, const PrintingInfo &otherPrinting) const
|
||||
{
|
||||
// The source card does not have a printing defined, which means we can't get a card from the same set.
|
||||
if (otherPrinting == PrintingInfo()) {
|
||||
return getCard({cardName});
|
||||
}
|
||||
|
||||
// The source card does have a printing defined, which means we can attempt to get a card from the same set.
|
||||
PrintingInfo relatedPrinting = getSpecificPrinting(cardName, otherPrinting.getSet()->getCorrectedShortName(), "");
|
||||
return ExactCard(guessCard({cardName}).getCardPtr(), relatedPrinting);
|
||||
ExactCard relatedCard = ExactCard(guessCard({cardName}).getCardPtr(), relatedPrinting);
|
||||
|
||||
// We didn't find a card from the same set, just try to find any card with the same name.
|
||||
if (!relatedCard) {
|
||||
return getCard({cardName});
|
||||
}
|
||||
|
||||
return relatedCard;
|
||||
}
|
||||
|
||||
void CardDatabase::refreshCachedReverseRelatedCards()
|
||||
|
||||
@@ -1899,6 +1899,11 @@ void Player::actCreateRelatedCard()
|
||||
if (createRelatedFromRelation(sourceCard, cardRelation) && cardRelation->getCanCreateAnother()) {
|
||||
ExactCard relatedCard = CardDatabaseManager::getInstance()->getCardFromSameSet(
|
||||
cardRelation->getName(), sourceCard->getCard().getPrinting());
|
||||
|
||||
if (!relatedCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLastToken(relatedCard.getCardPtr());
|
||||
}
|
||||
}
|
||||
@@ -2064,6 +2069,10 @@ void Player::createCard(const CardItem *sourceCard,
|
||||
ExactCard relatedCard = CardDatabaseManager::getInstance()->getCardFromSameSet(cardInfo->getName(),
|
||||
sourceCard->getCard().getPrinting());
|
||||
|
||||
if (!relatedCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (attachType) {
|
||||
case CardRelation::DoesNotAttach:
|
||||
cmd.set_target_zone("table");
|
||||
@@ -4169,9 +4178,7 @@ void Player::addRelatedCardActions(const CardItem *card, QMenu *cardMenu)
|
||||
for (const CardRelation *cardRelation : relatedCards) {
|
||||
ExactCard relatedCard = CardDatabaseManager::getInstance()->getCardFromSameSet(cardRelation->getName(),
|
||||
card->getCard().getPrinting());
|
||||
if (!relatedCard) {
|
||||
relatedCard = CardDatabaseManager::getInstance()->getCard({cardRelation->getName()});
|
||||
}
|
||||
|
||||
if (!relatedCard) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user