From 239735eaca13b17ddbefe8a9cf7c7b628dd2b26c Mon Sep 17 00:00:00 2001 From: Jetz Date: Sat, 15 Jun 2024 12:39:38 -0400 Subject: [PATCH] Make countByName work for cards with multiple prints. Add countByName to Deck --- forge-core/src/main/java/forge/deck/CardPool.java | 10 +++++----- forge-core/src/main/java/forge/deck/Deck.java | 11 +++++++++++ forge-core/src/main/java/forge/deck/DeckFormat.java | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/forge-core/src/main/java/forge/deck/CardPool.java b/forge-core/src/main/java/forge/deck/CardPool.java index e1029521e9f..8e7d9a531e4 100644 --- a/forge-core/src/main/java/forge/deck/CardPool.java +++ b/forge-core/src/main/java/forge/deck/CardPool.java @@ -155,12 +155,12 @@ public class CardPool extends ItemPool { return null; } - public int countByName(String cardName, boolean isCommonCard) { - PaperCard pc = isCommonCard - ? StaticData.instance().getCommonCards().getCard(cardName) - : StaticData.instance().getVariantCards().getCard(cardName); + public int countByName(String cardName) { + return this.countAll((c) -> c.getName().equals(cardName)); + } - return this.count(pc); + public int countByName(PaperCard card) { + return this.countAll((c) -> c.getName().equals(card.getName())); } /** diff --git a/forge-core/src/main/java/forge/deck/Deck.java b/forge-core/src/main/java/forge/deck/Deck.java index 7c8fa7ed594..913a2c5a264 100644 --- a/forge-core/src/main/java/forge/deck/Deck.java +++ b/forge-core/src/main/java/forge/deck/Deck.java @@ -537,6 +537,17 @@ public class Deck extends DeckBase implements Iterable section : this) { + sum += section.getValue().countByName(cardName); + } + return sum; + } + public void setAiHints(String aiHintsInfo) { if (aiHintsInfo == null || aiHintsInfo.trim().equals("")) { return; diff --git a/forge-core/src/main/java/forge/deck/DeckFormat.java b/forge-core/src/main/java/forge/deck/DeckFormat.java index 4302e19604b..6dedb34888f 100644 --- a/forge-core/src/main/java/forge/deck/DeckFormat.java +++ b/forge-core/src/main/java/forge/deck/DeckFormat.java @@ -217,8 +217,8 @@ public enum DeckFormat { // Adjust minimum base on number of Advantageous Proclamation or similar cards CardPool conspiracies = deck.get(DeckSection.Conspiracy); if (conspiracies != null) { - min -= (5 * conspiracies.countByName(ADVPROCLAMATION, false)); - noBasicLands = conspiracies.countByName(SOVREALM, false) > 0; + min -= (5 * conspiracies.countByName(ADVPROCLAMATION)); + noBasicLands = conspiracies.countByName(SOVREALM) > 0; } if (hasCommander()) { @@ -361,7 +361,7 @@ public enum DeckFormat { } Integer cardCopies = canHaveSpecificNumberInDeck(simpleCard); - if (cardCopies != null && deck.getMain().countByName(cp.getKey(), true) > cardCopies) { + if (cardCopies != null && deck.getMain().countByName(cp.getKey()) > cardCopies) { return TextUtil.concatWithSpace("must not contain more than", String.valueOf(cardCopies), "copies of the card", cp.getKey()); } @@ -388,7 +388,7 @@ public enum DeckFormat { return "must contain at least 10 attractions, or none at all"; for (Entry cp : attractionDeck) { //Constructed Attraction deck must be singleton - if (attractionDeck.countByName(cp.getKey().getName(), false) > 1) + if (attractionDeck.countByName(cp.getKey()) > 1) return TextUtil.concatWithSpace("contains more than 1 copy of the attraction", cp.getKey().getName()); } return null;