Skip to content

Commit

Permalink
Merge pull request Card-Forge#3462 from kevlahnota/newmaster2
Browse files Browse the repository at this point in the history
update Card.java getPaperCard
kevlahnota authored Jul 11, 2023
2 parents 939b630 + 2771668 commit e5a09f7
Showing 2 changed files with 37 additions and 13 deletions.
27 changes: 16 additions & 11 deletions forge-ai/src/main/java/forge/ai/AIDeckStatistics.java
Original file line number Diff line number Diff line change
@@ -35,14 +35,19 @@ public AIDeckStatistics(float averageCMC, float stddevCMC, int maxCost, int maxC
this.numLands = numLands;
}

public static AIDeckStatistics fromCardList(List<CardRules> cards) {
public static AIDeckStatistics fromCards(List<Card> cards) {
int totalCMC = 0;
int totalCount = 0;
int numLands = 0;
int maxCost = 0;
int[] maxPips = new int[6];
int maxColoredCost = 0;
for (CardRules rules : cards) {
for (Card c : cards) {
CardRules rules = c.getRules();
if (rules == null) {
System.err.println(c + " CardRules is null" + (c.isToken() ? "/token" : "."));
continue;
}
CardType type = rules.getType();
if (type.isLand()) {
numLands += 1;
@@ -80,41 +85,41 @@ public static AIDeckStatistics fromCardList(List<CardRules> cards) {
}


public static AIDeckStatistics fromDeck(Deck deck) {
List<CardRules> rules_list = new ArrayList<>();
public static AIDeckStatistics fromDeck(Deck deck, Player player) {
List<Card> cardlist = new ArrayList<>();
for (final Map.Entry<DeckSection, CardPool> deckEntry : deck) {
switch (deckEntry.getKey()) {
case Main:
case Commander:
for (final Map.Entry<PaperCard, Integer> poolEntry : deckEntry.getValue()) {
CardRules rules = poolEntry.getKey().getRules();
rules_list.add(rules);
Card card = Card.fromPaperCard(poolEntry.getKey(), player);
cardlist.add(card);
}
break;
default:
break; //ignore other sections
}
}

return fromCardList(rules_list);
return fromCards(cardlist);
}

public static AIDeckStatistics fromPlayer(Player player) {
Deck deck = player.getRegisteredPlayer().getDeck();
if (deck.isEmpty()) {
// we're in a test or some weird match, search through the hand and library and build the decklist
List<CardRules> rules_list = new ArrayList<>();
List<Card> cardlist = new ArrayList<>();
for (Card c : player.getAllCards()) {
if (c.getPaperCard() == null) {
continue;
}
rules_list.add(c.getRules());
cardlist.add(c);
}

return fromCardList(rules_list);
return fromCards(cardlist);
}

return fromDeck(deck);
return fromDeck(deck, player);

}

23 changes: 21 additions & 2 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
@@ -6941,10 +6941,29 @@ public IPaperCard getPaperCard() {

if (StringUtils.isNotBlank(set)) {
cp = StaticData.instance().getVariantCards().getCard(name, set);
return cp == null ? StaticData.instance().getCommonCards().getCard(name, set) : cp;
if (cp != null) {
return cp;
}
cp = StaticData.instance().getCommonCards().getCard(name, set);
if (cp != null) {
return cp;
}
}
//no specific set for variant
cp = StaticData.instance().getVariantCards().getCard(name);
return cp != null ? cp : StaticData.instance().getCommonCards().getCardFromEditions(name, CardArtPreference.LATEST_ART_ALL_EDITIONS);
if (cp != null) {
return cp;
}
//try to get from user preference if available
CardDb.CardArtPreference cardArtPreference = StaticData.instance().getCardArtPreference();
if (cardArtPreference == null) //fallback
cardArtPreference = CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY;
cp = StaticData.instance().getCommonCards().getCardFromEditions(name, cardArtPreference);
if (cp != null) {
return cp;
}
//lastoption
return StaticData.instance().getCommonCards().getCard(name);
}

/**

0 comments on commit e5a09f7

Please sign in to comment.