mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-09 03:23:24 -08:00
Honor finite deck copy limits across printings and deck zones [skip ci]
This commit is contained in:
parent
e08402ac94
commit
142341bc3c
9 changed files with 438 additions and 48 deletions
|
|
@ -45,12 +45,23 @@ bool exceptionAppliesToCard(const CardInfo &card, const ExceptionRule &rule)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool cardHasAnyException(const CardInfo &card, const FormatRules &format)
|
||||
std::optional<int> cardCopyLimitException(const CardInfo &card, const FormatRules &format)
|
||||
{
|
||||
std::optional<int> limit;
|
||||
for (const ExceptionRule &rule : format.exceptions) {
|
||||
if (exceptionAppliesToCard(card, rule)) {
|
||||
return true;
|
||||
if (rule.maxCopies == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (rule.maxCopies >= 0 && (!limit || rule.maxCopies > *limit)) {
|
||||
limit = rule.maxCopies;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return limit;
|
||||
}
|
||||
|
||||
bool cardHasAnyException(const CardInfo &card, const FormatRules &format)
|
||||
{
|
||||
return cardCopyLimitException(card, format).has_value();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <QList>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <optional>
|
||||
|
||||
class CardInfo;
|
||||
|
||||
|
|
@ -74,6 +75,9 @@ bool cardMatchesCondition(const CardInfo &card, const CardCondition &cond);
|
|||
|
||||
bool exceptionAppliesToCard(const CardInfo &card, const ExceptionRule &rule);
|
||||
|
||||
/** @brief Most permissive matching copy-count exception, or no value when none applies. */
|
||||
std::optional<int> cardCopyLimitException(const CardInfo &card, const FormatRules &format);
|
||||
|
||||
bool cardHasAnyException(const CardInfo &card, const FormatRules &format);
|
||||
|
||||
#endif // COCKATRICE_FORMAT_LEGALITY_RULES_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue