From 63a73df35f85b6616b2460bd36bddef03f3a5d01 Mon Sep 17 00:00:00 2001 From: Krazy Date: Sat, 13 Jun 2015 02:23:02 +0000 Subject: [PATCH] Added new color-specific booster packs to quests. --- forge-core/src/main/java/forge/ImageKeys.java | 22 +-- .../java/forge/card/BoosterGenerator.java | 29 +++- .../src/main/java/forge/card/CardEdition.java | 100 ++++++------- .../java/forge/card/IUnOpenedProduct.java | 4 +- .../src/main/java/forge/item/BoosterPack.java | 58 ++++++-- .../src/main/java/forge/item/IPaperCard.java | 138 ++++++++++++------ .../main/java/forge/item/SealedProduct.java | 110 ++++++++------ .../home/quest/VSubmenuQuestPrefs.java | 5 + .../forge/screens/quest/QuestPrefsScreen.java | 1 + forge-gui/CHANGES.txt | 54 +++---- forge-gui/res/lists/booster-images.txt | 6 + forge-gui/res/quest/booster-prices.txt | 8 +- .../main/java/forge/quest/QuestSpellShop.java | 7 + .../main/java/forge/quest/QuestUtilCards.java | 54 ++++++- .../forge/quest/QuestWinLoseController.java | 74 +++++++--- .../forge/quest/data/QuestPreferences.java | 3 + .../main/java/forge/quest/io/QuestDataIO.java | 15 +- .../java/forge/quest/io/ReadPriceList.java | 20 +-- 18 files changed, 477 insertions(+), 231 deletions(-) diff --git a/forge-core/src/main/java/forge/ImageKeys.java b/forge-core/src/main/java/forge/ImageKeys.java index c4c9af55932..b5ef2b13b0c 100644 --- a/forge-core/src/main/java/forge/ImageKeys.java +++ b/forge-core/src/main/java/forge/ImageKeys.java @@ -1,17 +1,16 @@ package forge; -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - import forge.card.CardDb; import forge.item.*; import forge.util.FileUtil; import forge.util.ImageUtil; +import org.apache.commons.lang3.StringUtils; -public class ImageKeys { +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +public final class ImageKeys { public static final String CARD_PREFIX = "c:"; public static final String TOKEN_PREFIX = "t:"; public static final String ICON_PREFIX = "i:"; @@ -31,7 +30,7 @@ public class ImageKeys { CACHE_FATPACK_PICS_DIR, CACHE_BOOSTERBOX_PICS_DIR, CACHE_PRECON_PICS_DIR, CACHE_TOURNAMENTPACK_PICS_DIR; private static Map CACHE_CARD_PICS_SUBDIR; - private static Map editionImageLookup = new HashMap(); + private static Map editionImageLookup = new HashMap<>(); /** * Private constructor to prevent instantiation. @@ -60,7 +59,7 @@ public class ImageKeys { return ImageKeys.CARD_PREFIX + pc.getName() + CardDb.NameSetSeparator + pc.getEdition() + CardDb.NameSetSeparator + pc.getArtIndex() + (altState ? BACKFACE_POSTFIX : ""); } - // Inventory items don't have to know how a certain client should draw them. + // Inventory items don't have to know how a certain client should draw them. // That's why this method is not encapsulated and overloaded in the InventoryItem descendants public static String getImageKey(InventoryItem ii, boolean altState) { if (ii instanceof PaperCard) { @@ -71,6 +70,9 @@ public class ImageKeys { } if (ii instanceof BoosterPack) { BoosterPack bp = (BoosterPack)ii; + if (SealedProduct.specialSets.contains(bp.getEdition()) || bp.getEdition().equals("?")) { + return "b:" + bp.getName().substring(0, bp.getName().indexOf(bp.getItemType()) - 1); + } int cntPics = StaticData.instance().getEditions().get(bp.getEdition()).getCntBoosterPictures(); String suffix = (1 >= cntPics) ? "" : ("_" + bp.getArtIndex()); return ImageKeys.BOOSTER_PREFIX + bp.getEdition() + suffix; @@ -145,7 +147,7 @@ public class ImageKeys { } // try without set name - if (dir == CACHE_TOKEN_PICS_DIR) { + if (dir.equals(CACHE_TOKEN_PICS_DIR)) { int index = filename.lastIndexOf('_'); if (index != -1) { String setlessFilename = filename.substring(0, index); diff --git a/forge-core/src/main/java/forge/card/BoosterGenerator.java b/forge-core/src/main/java/forge/card/BoosterGenerator.java index 773cd65c4db..a914f77c65d 100644 --- a/forge-core/src/main/java/forge/card/BoosterGenerator.java +++ b/forge-core/src/main/java/forge/card/BoosterGenerator.java @@ -24,6 +24,7 @@ import com.google.common.collect.Lists; import forge.StaticData; import forge.card.CardEdition.FoilType; import forge.item.IPaperCard; +import forge.item.IPaperCard.Predicates.Presets; import forge.item.PaperCard; import forge.item.SealedProduct; import forge.util.Aggregates; @@ -76,7 +77,7 @@ public class BoosterGenerator { String[] sType = TextUtil.splitWithParenthesis(slotType, ' '); String setCode = sType.length == 1 && template.getEdition() != null ? template.getEdition() : null; - String sheetKey = StaticData.instance().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim(); + String sheetKey = StaticData.instance().getEditions().contains(setCode) ? slotType.trim() + " " + setCode : slotType.trim(); boolean foilInThisSlot = hasFoil && slotType.startsWith(foilSlot); if (foilInThisSlot) @@ -220,6 +221,32 @@ public class BoosterGenerator { operator = StringUtils.strip(operator.substring(4), "() "); String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"'); toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames)); + } else if (operator.startsWith("color(")) { + operator = StringUtils.strip(operator.substring("color(".length() + 1), "()\" "); + switch (operator.toLowerCase()) { + case "black": + toAdd = Presets.IS_BLACK; + break; + case "blue": + toAdd = Presets.IS_BLUE; + break; + case "green": + toAdd = Presets.IS_GREEN; + break; + case "red": + toAdd = Presets.IS_RED; + break; + case "white": + toAdd = Presets.IS_WHITE; + break; + case "colorless": + toAdd = Presets.IS_COLORLESS; + break; + } + } else if (operator.startsWith("fromSets(")) { + operator = StringUtils.strip(operator.substring("fromSets(".length() + 1), "()\" "); + String[] sets = operator.split(","); + toAdd = IPaperCard.Predicates.printedInSets(sets); } else if (operator.startsWith("fromSheet(") && invert) { String sheetName = StringUtils.strip(operator.substring(9), "()\" "); Iterable src = StaticData.instance().getPrintSheets().get(sheetName).toFlatList(); diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index 8c046cd860a..4d552c87acb 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -6,12 +6,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -50,25 +50,25 @@ import java.util.Map.Entry; *

* CardSet class. *

- * + * * @author Forge * @version $Id: CardSet.java 9708 2011-08-09 19:34:12Z jendave $ */ public final class CardEdition implements Comparable { // immutable public enum Type { UNKNOWN, - + CORE, EXPANSION, - + REPRINT, ONLINE, STARTER, - + DUEL_DECKS, PREMIUM_DECK_SERIES, FROM_THE_VAULT, - + OTHER, THIRDPARTY // custom sets } @@ -78,7 +78,7 @@ public final class CardEdition implements Comparable { // immutable OLD_STYLE, // sets between Urza's Legacy and 8th Edition MODERN // 8th Edition and newer } - + public static class CardInSet { public final CardRarity rarity; public final String name; @@ -89,10 +89,10 @@ public final class CardEdition implements Comparable { // immutable } } - + /** The Constant unknown. */ private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - + public static final CardEdition UNKNOWN = new CardEdition("1990-01-01", "??", "???", Type.UNKNOWN, "Undefined", FoilType.NOT_SUPPORTED, new CardInSet[]{}); private Date date; @@ -106,19 +106,19 @@ public final class CardEdition implements Comparable { // immutable private double foilChanceInBooster = 0; private boolean foilAlwaysInCommonSlot = false; private final CardInSet[] cards; - - + + private int boosterArts = 1; private SealedProduct.Template boosterTpl = null; private CardEdition(CardInSet[] cards) { this.cards = cards; } - + /** * Instantiates a new card set. - * - * @param index indicates order of set release date + * + * @param date indicates order of set release date * @param code2 the 2 (usually) letter code used for image filenames/URLs distributed by the HQ pics team that * use Magic Workstation-type edition codes. Older sets only had 2-letter codes, and some of the 3-letter * codes they use now aren't the same as the official list of 3-letter codes. When Forge downloads set-pics, @@ -126,7 +126,7 @@ public final class CardEdition implements Comparable { // immutable * @param code the MTG 3-letter set code * @param type the set type * @param name the name of the set - * @param an optional secondary code alias for the set + * @param cards the cards in the set */ private CardEdition(String date, String code2, String code, Type type, String name, FoilType foil, CardInSet[] cards) { this(cards); @@ -137,9 +137,9 @@ public final class CardEdition implements Comparable { // immutable this.date = parseDate(date); this.foilType = foil; } - + private static Date parseDate(String date) { - if( date.length() <= 7 ) + if( date.length() <= 7 ) date = date + "-01"; try { return formatter.parse(date); @@ -220,19 +220,17 @@ public final class CardEdition implements Comparable { // immutable public boolean hasBoosterTemplate() { return boosterTpl != null; } - + public static class Reader extends StorageReaderFolder { public Reader(File path) { super(path, CardEdition.FN_GET_CODE); } - - public final static CardInSet[] arrCards = new CardInSet[] {}; @Override protected CardEdition read(File file) { final Map> contents = FileSection.parseSections(FileUtil.readFile(file)); - List processedCards = new ArrayList(); + List processedCards = new ArrayList<>(); for(String line : contents.get("cards")) { if (StringUtils.isBlank(line)) continue; @@ -240,26 +238,26 @@ public final class CardEdition implements Comparable { // immutable // You may omit rarity for early development CardRarity r = CardRarity.smartValueOf(line.substring(0, 1)); boolean hadRarity = r != CardRarity.Unknown && line.charAt(1) == ' '; - String cardName = hadRarity ? line.substring(2) : line; + String cardName = hadRarity ? line.substring(2) : line; CardInSet cis = new CardInSet(cardName, r); processedCards.add(cis); } - CardEdition res = new CardEdition(processedCards.toArray(arrCards)); - - + CardEdition res = new CardEdition(processedCards.toArray(new CardInSet[processedCards.size()])); + FileSection section = FileSection.parse(contents.get("metadata"), "="); res.name = section.get("name"); res.date = parseDate(section.get("date")); res.code = section.get("code"); res.code2 = section.get("code2"); - if( res.code2 == null ) + if (res.code2 == null) { res.code2 = res.code; - + } + res.boosterArts = section.getInt("BoosterCovers", 1); String boosterDesc = section.get("Booster"); res.boosterTpl = boosterDesc == null ? null : new SealedProduct.Template(res.code, SealedProduct.Template.Reader.parseSlots(boosterDesc)); - + res.alias = section.get("alias"); res.whiteBorder = "white".equalsIgnoreCase(section.get("border")); String type = section.get("type"); @@ -267,7 +265,7 @@ public final class CardEdition implements Comparable { // immutable if (null != type && !type.isEmpty()) { try { enumType = Type.valueOf(type.toUpperCase(Locale.ENGLISH)); - } catch (IllegalArgumentException e) { + } catch (IllegalArgumentException ignored) { // ignore; type will get UNKNOWN System.err.println(String.format("Ignoring unknown type in set definitions: name: %s; type: %s", res.name, type)); } @@ -292,7 +290,7 @@ public final class CardEdition implements Comparable { // immutable } res.foilChanceInBooster = section.getDouble("FoilChanceInBooster", 21.43F) / 100.0F; res.foilAlwaysInCommonSlot = section.getBoolean("FoilAlwaysInCommonSlot", true); - + return res; } @@ -312,7 +310,7 @@ public final class CardEdition implements Comparable { // immutable public static class Collection extends StorageBase { - private final Map aliasToEdition = new TreeMap(String.CASE_INSENSITIVE_ORDER); + private final Map aliasToEdition = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public Collection(IItemReader reader) { super("Card editions", reader); @@ -328,7 +326,7 @@ public final class CardEdition implements Comparable { // immutable /** * Gets a sets by code. It will search first by three letter codes, then by aliases and two-letter codes. - * + * * @param code * the code * @return the sets the by code @@ -342,9 +340,7 @@ public final class CardEdition implements Comparable { // immutable CardEdition baseResult = super.get(code); return baseResult == null ? aliasToEdition.get(code) : baseResult; } - - - + public Iterable getOrderedEditions() { List res = Lists.newArrayList(this); Collections.sort(res); @@ -354,7 +350,7 @@ public final class CardEdition implements Comparable { // immutable /** * Gets the sets by code or throw. - * + * * @param code * the code * @return the sets the by code or throw @@ -370,7 +366,7 @@ public final class CardEdition implements Comparable { // immutable // used by image generating code /** * Gets the code2 by code. - * + * * @param code * the code * @return the code2 by code @@ -384,38 +380,38 @@ public final class CardEdition implements Comparable { // immutable @Override public CardEdition apply(String code) { return Collection.this.get(code); - }; + } }; /** * TODO: Write javadoc for this method. - * @return + * @return ItemReader */ public IItemReader getBoosterGenerator() { // TODO Auto-generated method stub return new StorageReaderBase(null) { - + @Override public Map readAll() { - Map map = new TreeMap(String.CASE_INSENSITIVE_ORDER); + Map map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for(CardEdition ce : Collection.this) { map.put(ce.getCode(), ce.getBoosterTemplate()); } return map; } - + @Override public String getItemKey(SealedProduct.Template item) { return item.getEdition(); } }; } - + public CardEdition getEarliestEditionWithAllCards(CardPool cards) { - Set minEditions = new HashSet(); - + Set minEditions = new HashSet<>(); + SetPreference strictness = SetPreference.EarliestCoreExp; - + for(Entry k : cards) { PaperCard cp = StaticData.instance().getCommonCards().getCardFromEdition(k.getKey().getName(), strictness); if( cp == null && strictness == SetPreference.EarliestCoreExp) { @@ -424,14 +420,14 @@ public final class CardEdition implements Comparable { // immutable } if ( cp == null ) cp = k.getKey(); // it's unlikely, this code will ever run - + minEditions.add(cp.getEdition()); } for(CardEdition ed : getOrderedEditions()) { if(minEditions.contains(ed.getCode())) return ed; - } + } return UNKNOWN; } } @@ -448,10 +444,10 @@ public final class CardEdition implements Comparable { // immutable } - public final static CardEdition getRandomSetWithAllBasicLands(Iterable allEditions) { + public static CardEdition getRandomSetWithAllBasicLands(Iterable allEditions) { return Aggregates.random(Iterables.filter(allEditions, hasBasicLands)); } - + public static final Predicate HAS_TOURNAMENT_PACK = new CanMakeStarter(); private static class CanMakeStarter implements Predicate { @Override @@ -485,7 +481,7 @@ public final class CardEdition implements Comparable { // immutable return false; } return true; - }; + } }; } diff --git a/forge-core/src/main/java/forge/card/IUnOpenedProduct.java b/forge-core/src/main/java/forge/card/IUnOpenedProduct.java index c2a7eb85b2e..d23abed94fc 100644 --- a/forge-core/src/main/java/forge/card/IUnOpenedProduct.java +++ b/forge-core/src/main/java/forge/card/IUnOpenedProduct.java @@ -5,11 +5,11 @@ import forge.item.PaperCard; import java.util.List; -/** +/** * TODO: Write javadoc for this type. * */ public interface IUnOpenedProduct extends Supplier> { - public List get(); + List get(); } \ No newline at end of file diff --git a/forge-core/src/main/java/forge/item/BoosterPack.java b/forge-core/src/main/java/forge/item/BoosterPack.java index e2ae80aaae9..5441b35d05b 100644 --- a/forge-core/src/main/java/forge/item/BoosterPack.java +++ b/forge-core/src/main/java/forge/item/BoosterPack.java @@ -6,12 +6,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -19,9 +19,12 @@ package forge.item; import com.google.common.base.Function; +import com.google.common.collect.ImmutableList; import forge.StaticData; +import forge.card.BoosterSlots; import forge.card.CardEdition; import forge.util.MyRandom; +import org.apache.commons.lang3.tuple.Pair; public class BoosterPack extends SealedProduct { private final int artIndex; @@ -35,11 +38,30 @@ public class BoosterPack extends SealedProduct { } }; + public static final Function FN_FROM_COLOR = new Function() { + @Override + public BoosterPack apply(final String color) { + return new BoosterPack(color, new Template("?", ImmutableList.of( + Pair.of(BoosterSlots.COMMON + ":color(\"" + color + "\"):!" + BoosterSlots.LAND, 11), + Pair.of(BoosterSlots.UNCOMMON + ":color(\"" + color + "\"):!" + BoosterSlots.LAND, 3), + Pair.of(BoosterSlots.RARE_MYTHIC + ":color(\"" + color + "\"):!" + BoosterSlots.LAND, 1), + Pair.of(BoosterSlots.LAND + ":color(\"" + color + "\")", 1)) + )); + } + }; + public BoosterPack(final String name0, final Template boosterData) { super(name0, boosterData); - int maxIdx = StaticData.instance().getEditions().get(boosterData.getEdition()).getCntBoosterPictures(); - artIndex = MyRandom.getRandom().nextInt(maxIdx) + 1; - hash = super.hashCode() ^ artIndex; + + if (specialSets.contains(boosterData.getEdition()) || boosterData.getEdition().equals("?")) { + artIndex = 1; + } else { + int maxIdx = StaticData.instance().getEditions().get(boosterData.getEdition()).getCntBoosterPictures(); + artIndex = MyRandom.getRandom().nextInt(maxIdx) + 1; + } + + hash = super.hashCode() ^ artIndex; + } public final int getArtIndex() { @@ -51,24 +73,32 @@ public class BoosterPack extends SealedProduct { return "Booster Pack"; } + @Override + public String getDescription() { + if (specialSets.contains(getEdition()) || getEdition().equals("?")) { + String color = getName().substring(0, getName().indexOf(getItemType()) - 1).toLowerCase(); + return "11 " + color + " commons, 3 " + color + " uncommons, 1 " + color + " rare, and 1 " + color + " land."; + } + return super.getDescription(); + } + @Override public final Object clone() { return new BoosterPack(name, contents); } - + public Template getBoosterData() { return contents; } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!super.equals(obj)) { - return false; - } - BoosterPack other = (BoosterPack)obj; + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + + BoosterPack other = (BoosterPack) o; + return artIndex == other.artIndex; } diff --git a/forge-core/src/main/java/forge/item/IPaperCard.java b/forge-core/src/main/java/forge/item/IPaperCard.java index 3f6436cfd29..fe6617ef691 100644 --- a/forge-core/src/main/java/forge/item/IPaperCard.java +++ b/forge-core/src/main/java/forge/item/IPaperCard.java @@ -4,6 +4,8 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import forge.card.CardRarity; import forge.card.CardRules; +import forge.card.CardType.CoreType; +import forge.card.MagicColor; import forge.util.PredicateString; import org.apache.commons.lang3.StringUtils; @@ -18,88 +20,130 @@ public interface IPaperCard extends InventoryItem { /** * Number of filters based on CardPrinted values. */ - public abstract static class Predicates { - + abstract class Predicates { + public static Predicate rarity(final boolean isEqual, final CardRarity value) { return new PredicateRarity(value, isEqual); } + + public static Predicate color(final boolean isEqual, final boolean noColor, final byte value) { + return new PredicateColor(value, noColor, isEqual); + } + public static Predicate printedInSets(final String[] sets) { return printedInSets(Lists.newArrayList(sets), true); } - + public static Predicate printedInSets(final List value, final boolean shouldContain) { if ((value == null) || value.isEmpty()) { return com.google.common.base.Predicates.alwaysTrue(); } return new PredicateSets(value, shouldContain); } - + public static Predicate printedInSet(final String value) { if (StringUtils.isEmpty(value)) { return com.google.common.base.Predicates.alwaysTrue(); } return new PredicateSets(Lists.newArrayList(value), true); } - + public static Predicate name(final String what) { return new PredicateName(PredicateString.StringOp.EQUALS_IC, what); } - + public static Predicate name(final PredicateString.StringOp op, final String what) { return new PredicateName(op, what); } - + public static Predicate names(final List what) { return new PredicateNames(what); } - - private static class PredicateRarity implements Predicate { + + private static final class PredicateColor implements Predicate { + + private final byte operand; + private final boolean noColor; + private final boolean shouldBeEqual; + + private PredicateColor(final byte color, final boolean noColor, final boolean wantEqual) { + this.operand = color; + this.noColor = noColor; + this.shouldBeEqual = wantEqual; + } + + @Override + public boolean apply(final PaperCard card) { + boolean colorFound = false; + if (noColor) { + return card.getRules().getColor().isColorless() == shouldBeEqual; + } + for (final byte color : card.getRules().getColor()) { + if (color == operand) { + colorFound = true; + break; + } + } + if (card.getRules().getType().hasType(CoreType.Land)) { + for (final byte color : card.getRules().getColorIdentity()) { + if (color == operand) { + colorFound = true; + break; + } + } + } + return colorFound == shouldBeEqual; + } + + } + + private static final class PredicateRarity implements Predicate { private final CardRarity operand; private final boolean shouldBeEqual; - + @Override public boolean apply(final PaperCard card) { return (card.getRarity() == this.operand) == this.shouldBeEqual; } - - public PredicateRarity(final CardRarity type, final boolean wantEqual) { + + private PredicateRarity(final CardRarity type, final boolean wantEqual) { this.operand = type; this.shouldBeEqual = wantEqual; } } - - private static class PredicateSets implements Predicate { + + private static final class PredicateSets implements Predicate { private final Set sets; private final boolean mustContain; - + @Override public boolean apply(final PaperCard card) { return this.sets.contains(card.getEdition()) == this.mustContain; } - - public PredicateSets(final List wantSets, final boolean shouldContain) { - this.sets = new HashSet(wantSets); + + private PredicateSets(final List wantSets, final boolean shouldContain) { + this.sets = new HashSet<>(wantSets); this.mustContain = shouldContain; } } - - private static class PredicateName extends PredicateString { + + private static final class PredicateName extends PredicateString { private final String operand; - + @Override public boolean apply(final PaperCard card) { return this.op(card.getName(), this.operand); } - - public PredicateName(final PredicateString.StringOp operator, final String operand) { + + private PredicateName(final PredicateString.StringOp operator, final String operand) { super(operator); this.operand = operand; } } - - private static class PredicateNames extends PredicateString { + + private static final class PredicateNames extends PredicateString { private final List operand; - + @Override public boolean apply(final PaperCard card) { final String cardName = card.getName(); @@ -110,13 +154,13 @@ public interface IPaperCard extends InventoryItem { } return false; } - - public PredicateNames(final List operand) { + + private PredicateNames(final List operand) { super(StringOp.EQUALS); this.operand = operand; } } - + /** * Pre-built predicates are stored here to allow their re-usage and * easier access from code. @@ -126,37 +170,45 @@ public interface IPaperCard extends InventoryItem { // card. /** The Constant isCommon. */ public static final Predicate IS_COMMON = Predicates.rarity(true, CardRarity.Common); - + /** The Constant isUncommon. */ public static final Predicate IS_UNCOMMON = Predicates.rarity(true, CardRarity.Uncommon); - + /** The Constant isRare. */ public static final Predicate IS_RARE = Predicates.rarity(true, CardRarity.Rare); - + /** The Constant isMythicRare. */ public static final Predicate IS_MYTHIC_RARE = Predicates.rarity(true, CardRarity.MythicRare); - + /** The Constant isRareOrMythic. */ public static final Predicate IS_RARE_OR_MYTHIC = com.google.common.base.Predicates.or(Presets.IS_RARE, Presets.IS_MYTHIC_RARE); - + /** The Constant isSpecial. */ public static final Predicate IS_SPECIAL = Predicates.rarity(true, CardRarity.Special); - + /** The Constant exceptLands. */ public static final Predicate IS_BASIC_LAND = Predicates.rarity(true, CardRarity.BasicLand); + + public static final Predicate IS_BLACK = Predicates.color(true, false, MagicColor.BLACK); + public static final Predicate IS_BLUE = Predicates.color(true, false, MagicColor.BLUE); + public static final Predicate IS_GREEN = Predicates.color(true, false, MagicColor.GREEN); + public static final Predicate IS_RED = Predicates.color(true, false, MagicColor.RED); + public static final Predicate IS_WHITE = Predicates.color(true, false, MagicColor.WHITE); + public static final Predicate IS_COLORLESS = Predicates.color(true, true, MagicColor.COLORLESS); + } } - public abstract String getName(); - public abstract String getEdition(); - public abstract int getArtIndex(); - public abstract boolean isFoil(); - public abstract boolean isToken(); - public abstract CardRules getRules(); - public abstract CardRarity getRarity(); + String getName(); + String getEdition(); + int getArtIndex(); + boolean isFoil(); + boolean isToken(); + CardRules getRules(); + CardRarity getRarity(); - public abstract String getItemType(); + String getItemType(); } \ No newline at end of file diff --git a/forge-core/src/main/java/forge/item/SealedProduct.java b/forge-core/src/main/java/forge/item/SealedProduct.java index d6516e40657..12701b63f95 100644 --- a/forge-core/src/main/java/forge/item/SealedProduct.java +++ b/forge-core/src/main/java/forge/item/SealedProduct.java @@ -6,12 +6,12 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -38,11 +38,23 @@ import java.util.ArrayList; import java.util.List; public abstract class SealedProduct implements InventoryItemFromSet { + + public static final List specialSets = new ArrayList<>(); + protected final Template contents; protected final String name; private final int hash; protected List cards = null; + static { + specialSets.add("Black"); + specialSets.add("Blue"); + specialSets.add("Green"); + specialSets.add("Red"); + specialSets.add("White"); + specialSets.add("Colorless"); + } + public SealedProduct(String name0, Template boosterData) { if (null == name0) { throw new IllegalArgumentException("name0 must not be null"); } if (null == boosterData) { throw new IllegalArgumentException("boosterData must not be null"); } @@ -59,37 +71,32 @@ public abstract class SealedProduct implements InventoryItemFromSet { public String getDescription() { return contents.toString(); } - + @Override public final String getEdition() { return contents.getEdition(); } - + public List getCards() { if (null == cards) { cards = generate(); } - + return cards; } - + public int getTotalCards() { return contents.getNumberOfCardsExpected(); } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } - SealedProduct other = (SealedProduct)obj; - return name.equals(other.name) && contents.equals(other.contents); + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SealedProduct other = (SealedProduct) o; + + return contents.equals(other.contents) && name.equals(other.name); } @Override @@ -116,25 +123,23 @@ public abstract class SealedProduct implements InventoryItemFromSet { Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, PaperCard.FN_GET_RULES)); return Aggregates.random(Iterables.filter(StaticData.instance().getCommonCards().getAllCards(), cardsRule), count); } - + public static class Template { - + @SuppressWarnings("unchecked") public final static Template genericBooster = new Template(null, Lists.newArrayList( - Pair.of(BoosterSlots.COMMON, 10), Pair.of(BoosterSlots.UNCOMMON, 3), + Pair.of(BoosterSlots.COMMON, 10), Pair.of(BoosterSlots.UNCOMMON, 3), Pair.of(BoosterSlots.RARE_MYTHIC, 1), Pair.of(BoosterSlots.BASIC_LAND, 1) )); - - + protected final List> slots; protected final String name; - - + public final List> getSlots() { return slots; } - + public final String getEdition() { return name; } @@ -142,75 +147,92 @@ public abstract class SealedProduct implements InventoryItemFromSet { { this(null, itrSlots); } - + public Template(String name0, Iterable> itrSlots) { slots = Lists.newArrayList(itrSlots); name = name0; } - + public Template(String code, String boosterDesc) { this(code, Reader.parseSlots(boosterDesc)); } - + public int getNumberOfCardsExpected() { int sum = 0; for(Pair p : slots) { - sum += p.getRight().intValue(); + sum += p.getRight(); } return sum; } - + public static final Function FN_GET_NAME = new Function() { @Override public String apply(Template arg1) { return arg1.name; } }; - + @Override public String toString() { StringBuilder s = new StringBuilder(); - - + + s.append("consisting of "); for(Pair p : slots) { s.append(p.getRight()).append(" ").append(p.getLeft()).append(", "); } - + // trim the last comma and space s.replace(s.length() - 2, s.length(), ""); - + // put an 'and' before the previous comma - int lastCommaIdx = s.lastIndexOf(","); + int lastCommaIdx = s.lastIndexOf(","); if (0 < lastCommaIdx) { s.replace(lastCommaIdx+1, lastCommaIdx+1, " and"); } - + return s.toString(); } - + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Template template = (Template) o; + + return slots.equals(template.slots) && name.equals(template.name); + } + + @Override + public int hashCode() { + int result = slots.hashCode(); + result = 31 * result + name.hashCode(); + return result; + } + public final static class Reader extends StorageReaderFile