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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int countByName(String cardName, boolean isCommonCard) {
|
public int countByName(String cardName) {
|
||||||
PaperCard pc = isCommonCard
|
return this.countAll((c) -> c.getName().equals(cardName));
|
||||||
? StaticData.instance().getCommonCards().getCard(cardName)
|
}
|
||||||
: StaticData.instance().getVariantCards().getCard(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;
|
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) {
|
public void setAiHints(String aiHintsInfo) {
|
||||||
if (aiHintsInfo == null || aiHintsInfo.trim().equals("")) {
|
if (aiHintsInfo == null || aiHintsInfo.trim().equals("")) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -217,8 +217,8 @@ public enum DeckFormat {
|
|||||||
// Adjust minimum base on number of Advantageous Proclamation or similar cards
|
// Adjust minimum base on number of Advantageous Proclamation or similar cards
|
||||||
CardPool conspiracies = deck.get(DeckSection.Conspiracy);
|
CardPool conspiracies = deck.get(DeckSection.Conspiracy);
|
||||||
if (conspiracies != null) {
|
if (conspiracies != null) {
|
||||||
min -= (5 * conspiracies.countByName(ADVPROCLAMATION, false));
|
min -= (5 * conspiracies.countByName(ADVPROCLAMATION));
|
||||||
noBasicLands = conspiracies.countByName(SOVREALM, false) > 0;
|
noBasicLands = conspiracies.countByName(SOVREALM) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCommander()) {
|
if (hasCommander()) {
|
||||||
@@ -361,7 +361,7 @@ public enum DeckFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Integer cardCopies = canHaveSpecificNumberInDeck(simpleCard);
|
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());
|
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";
|
return "must contain at least 10 attractions, or none at all";
|
||||||
for (Entry<PaperCard, Integer> cp : attractionDeck) {
|
for (Entry<PaperCard, Integer> cp : attractionDeck) {
|
||||||
//Constructed Attraction deck must be singleton
|
//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 TextUtil.concatWithSpace("contains more than 1 copy of the attraction", cp.getKey().getName());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user