diff --git a/forge-core/src/main/java/forge/deck/CardPool.java b/forge-core/src/main/java/forge/deck/CardPool.java index 3e27cb17ed7..40678c44dd6 100644 --- a/forge-core/src/main/java/forge/deck/CardPool.java +++ b/forge-core/src/main/java/forge/deck/CardPool.java @@ -78,10 +78,21 @@ public class CardPool extends ItemPool { PaperCard paperCard = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex); final boolean isCommonCard = paperCard != null; + boolean isCustomCard = !(isCommonCard); if (!isCommonCard) { - paperCard = StaticData.instance().getVariantCards().getCard(cardName, setCode); - if (paperCard == null) { + paperCard = StaticData.instance().getCustomCards().getCard(cardName, setCode); + isCustomCard = paperCard != null; + if (isCustomCard && !StaticData.instance().isEnableCustomCardsInDecks()) { + String errMsg = String.format("Custom Card \"%s\" from Set \"%s\" was found but could not be loaded. Please enable the use of Custom Cards in Forge Preferences to use this card.", paperCard.getName(), paperCard.getEdition()); + System.err.println(errMsg); + paperCard = null; + } + + if (!isCustomCard) + paperCard = StaticData.instance().getVariantCards().getCard(cardName, setCode); + + if (paperCard == null && !isCustomCard) { StaticData.instance().attemptToLoadCard(cardName, setCode); paperCard = StaticData.instance().getVariantCards().getCard(cardName, setCode); } @@ -91,10 +102,16 @@ public class CardPool extends ItemPool { if (paperCard != null) { setCode = paperCard.getEdition(); cardName = paperCard.getName(); - artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1; + if (isCommonCard) + artCount = StaticData.instance().getCommonCards().getArtCount(cardName, setCode); + else if (isCustomCard) + artCount = StaticData.instance().getCustomCards().getArtCount(cardName, setCode); } else { - System.err.print("An unsupported card was requested: \"" + cardName + "\" from \"" + setCode + "\". "); + System.err.println("An unsupported card was requested: \"" + cardName + "\" from \"" + setCode + "\". \n"); paperCard = StaticData.instance().getCommonCards().createUnsupportedCard(cardName); + // the unsupported card will be temporarily added to common cards (for no use, really) + // this would happen only if custom cards has been found but option is disabled! + isCustomCard = false; } boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length() - 1)) && cardName.charAt(cardName.length() - 2) == CardDb.NameSetSeparator; @@ -105,24 +122,23 @@ public class CardPool extends ItemPool { } else { // random art index specified, make sure we get different groups of cards with different art int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount); + CardDb cardDb = isCustomCard ? StaticData.instance().getCustomCards() : StaticData.instance().getCommonCards(); for (int i = 1; i <= artGroups.length; i++) { int cnt = artGroups[i - 1]; if (cnt <= 0) { continue; } - PaperCard randomCard = StaticData.instance().getCommonCards().getCard(cardName, setCode, i); + PaperCard randomCard = cardDb.getCard(cardName, setCode, i); this.add(randomCard, cnt); } } } - /** * Add all from a List of CardPrinted. * - * @param list - * CardPrinteds to add + * @param list CardPrinteds to add */ public void add(final Iterable list) { for (PaperCard cp : list) { @@ -132,13 +148,14 @@ public class CardPool extends ItemPool { /** * returns n-th card from this DeckSection. LINEAR time. No fixed order between changes + * * @param n * @return */ public PaperCard get(int n) { for (Entry e : this) { n -= e.getValue(); - if ( n <= 0 ) return e.getKey(); + if (n <= 0) return e.getKey(); } return null; } @@ -153,7 +170,9 @@ public class CardPool extends ItemPool { @Override public String toString() { - if (this.isEmpty()) { return "[]"; } + if (this.isEmpty()) { + return "[]"; + } boolean isFirst = true; StringBuilder sb = new StringBuilder(); @@ -161,8 +180,7 @@ public class CardPool extends ItemPool { for (Entry e : this) { if (isFirst) { isFirst = false; - } - else { + } else { sb.append(", "); } sb.append(e.getValue()).append(" x ").append(e.getKey().getName()); @@ -171,6 +189,7 @@ public class CardPool extends ItemPool { } private final static Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)"); + public static CardPool fromCardList(final Iterable lines) { CardPool pool = new CardPool(); @@ -182,7 +201,9 @@ public class CardPool extends ItemPool { final Iterator lineIterator = lines.iterator(); while (lineIterator.hasNext()) { final String line = lineIterator.next(); - if (line.startsWith(";") || line.startsWith("#")) { continue; } // that is a comment or not-yet-supported card + if (line.startsWith(";") || line.startsWith("#")) { + continue; + } // that is a comment or not-yet-supported card final Matcher m = p.matcher(line.trim()); m.matches(); @@ -207,7 +228,7 @@ public class CardPool extends ItemPool { boolean isFirst = true; for (final Entry e : main2sort) { - if(!isFirst) + if (!isFirst) sb.append(separator); else isFirst = false; @@ -222,13 +243,14 @@ public class CardPool extends ItemPool { /** * Applies a predicate to this CardPool's cards. + * * @param predicate the Predicate to apply to this CardPool * @return a new CardPool made from this CardPool with only the cards that agree with the provided Predicate */ - public CardPool getFilteredPool(Predicate predicate){ + public CardPool getFilteredPool(Predicate predicate) { CardPool filteredPool = new CardPool(); - for(PaperCard pc : this.items.keySet()){ - if(predicate.apply(pc)) filteredPool.add(pc); + for (PaperCard pc : this.items.keySet()) { + if (predicate.apply(pc)) filteredPool.add(pc); } return filteredPool; }