mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Make countByName work for cards with multiple prints.
Add countByName to Deck
This commit is contained in:
@@ -155,12 +155,12 @@ public class CardPool extends ItemPool<PaperCard> {
|
||||
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()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -537,6 +537,17 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
||||
return allCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of cards with the given name across all deck sections.
|
||||
*/
|
||||
public int countByName(String cardName) {
|
||||
int sum = 0;
|
||||
for (Entry<DeckSection, CardPool> section : this) {
|
||||
sum += section.getValue().countByName(cardName);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void setAiHints(String aiHintsInfo) {
|
||||
if (aiHintsInfo == null || aiHintsInfo.trim().equals("")) {
|
||||
return;
|
||||
|
||||
@@ -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<PaperCard, Integer> 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;
|
||||
|
||||
Reference in New Issue
Block a user