diff --git a/.gitattributes b/.gitattributes index 8a0308c9134..5df7240f7c7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -22,12 +22,10 @@ forge-core/pom.xml -text forge-core/src/main/java/forge/ICardStorageReader.java -text forge-core/src/main/java/forge/IProgressObserver.java -text forge-core/src/main/java/forge/StaticData.java -text -forge-core/src/main/java/forge/card/AggregationMethod.java -text forge-core/src/main/java/forge/card/BoosterGenerator.java svneol=native#text/plain forge-core/src/main/java/forge/card/BoosterSlots.java -text forge-core/src/main/java/forge/card/CardAiHints.java -text forge-core/src/main/java/forge/card/CardCharacteristicName.java -text -forge-core/src/main/java/forge/card/CardCoreType.java -text forge-core/src/main/java/forge/card/CardDb.java -text forge-core/src/main/java/forge/card/CardEdition.java -text forge-core/src/main/java/forge/card/CardFace.java -text @@ -35,12 +33,9 @@ forge-core/src/main/java/forge/card/CardRarity.java -text forge-core/src/main/java/forge/card/CardRules.java -text forge-core/src/main/java/forge/card/CardRulesPredicates.java -text forge-core/src/main/java/forge/card/CardSplitType.java -text -forge-core/src/main/java/forge/card/CardSuperType.java -text forge-core/src/main/java/forge/card/CardType.java -text forge-core/src/main/java/forge/card/ColorSet.java -text forge-core/src/main/java/forge/card/DeckHints.java -text -forge-core/src/main/java/forge/card/EditionCollection.java svneol=native#text/plain -forge-core/src/main/java/forge/card/FatPackTemplate.java -text forge-core/src/main/java/forge/card/FormatCollection.java -text forge-core/src/main/java/forge/card/ICardCharacteristics.java -text forge-core/src/main/java/forge/card/ICardDatabase.java -text @@ -74,18 +69,16 @@ forge-core/src/main/java/forge/deck/io/DeckSerializer.java -text forge-core/src/main/java/forge/deck/io/OldDeckFileFormatException.java -text forge-core/src/main/java/forge/deck/io/package-info.java -text forge-core/src/main/java/forge/deck/package-info.java -text -forge-core/src/main/java/forge/game/GameFormat.java -text -forge-core/src/main/java/forge/game/package-info.java -text forge-core/src/main/java/forge/item/BoosterPack.java -text forge-core/src/main/java/forge/item/FatPack.java -text forge-core/src/main/java/forge/item/IPaperCard.java -text forge-core/src/main/java/forge/item/InventoryItem.java -text forge-core/src/main/java/forge/item/InventoryItemFromSet.java -text forge-core/src/main/java/forge/item/ItemPredicate.java -text -forge-core/src/main/java/forge/item/OpenablePack.java -text forge-core/src/main/java/forge/item/PaperCard.java -text forge-core/src/main/java/forge/item/PaperToken.java -text forge-core/src/main/java/forge/item/PreconDeck.java -text +forge-core/src/main/java/forge/item/SealedProduct.java -text forge-core/src/main/java/forge/item/TournamentPack.java -text forge-core/src/main/java/forge/item/package-info.java -text forge-core/src/main/java/forge/package-info.java -text @@ -120,6 +113,9 @@ forge-game/.settings/org.eclipse.core.resources.prefs -text forge-game/.settings/org.eclipse.jdt.core.prefs -text forge-game/.settings/org.eclipse.m2e.core.prefs -text forge-game/pom.xml -text +forge-game/src/main/java/forge/game/FormatCollection.java -text +forge-game/src/main/java/forge/game/GameFormat.java -text +forge-game/src/main/java/forge/game/package-info.java -text forge-gui/.classpath -text forge-gui/.project -text forge-gui/.settings/org.eclipse.core.resources.prefs -text @@ -128,6 +124,7 @@ forge-gui/.settings/org.eclipse.m2e.core.prefs -text forge-gui/CHANGES.txt -text forge-gui/LICENSE.txt -text forge-gui/README.txt -text +forge-gui/forge.profile.properties -text forge-gui/forge.profile.properties.example -text forge-gui/pom.xml -text forge-gui/res/ai/Default.ai -text diff --git a/.gitignore b/.gitignore index b046d87b7f5..7d4ba2931ad 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ forge-ai/forge-ai.iml forge-ai/target forge-core/forge-core.iml forge-core/target +forge-game/target forge-gui/forge-gui.iml forge-gui/res/*.log forge-gui/res/PerSetTrackingResults diff --git a/forge-core/src/main/java/forge/StaticData.java b/forge-core/src/main/java/forge/StaticData.java index 7331f1a1088..84b5bcbd6fd 100644 --- a/forge-core/src/main/java/forge/StaticData.java +++ b/forge-core/src/main/java/forge/StaticData.java @@ -8,12 +8,9 @@ import java.util.TreeMap; import forge.card.CardDb; import forge.card.CardEdition; import forge.card.CardRules; -import forge.card.EditionCollection; -import forge.card.FatPackTemplate; -import forge.card.FormatCollection; import forge.card.PrintSheet; -import forge.card.SealedProductTemplate; -import forge.game.GameFormat; +import forge.item.FatPack; +import forge.item.SealedProduct; import forge.util.storage.IStorage; import forge.util.storage.StorageBase; @@ -27,12 +24,11 @@ public class StaticData { private final CardDb commonCards; private final CardDb variantCards; - private final EditionCollection editions; - private final FormatCollection formats; - private final IStorage boosters; - private final IStorage specialBoosters; - private final IStorage tournaments; - private final IStorage fatPacks; + private final CardEdition.Collection editions; + private final IStorage boosters; + private final IStorage specialBoosters; + private final IStorage tournaments; + private final IStorage fatPacks; private final IStorage printSheets; private static StaticData lastInstance = null; @@ -40,7 +36,7 @@ public class StaticData { public StaticData(ICardStorageReader reader, String editionFolder, String blockDataFolder) { - this.editions = new EditionCollection(new CardEdition.Reader(new File(editionFolder))); + this.editions = new CardEdition.Collection(new CardEdition.Reader(new File(editionFolder))); lastInstance = this; final Map regularCards = new TreeMap(String.CASE_INSENSITIVE_ORDER); @@ -62,12 +58,10 @@ public class StaticData { variantCards = new CardDb(variantsCards, editions, false); - - this.formats = new FormatCollection(new GameFormat.Reader(new File(blockDataFolder, "formats.txt"))); - this.boosters = new StorageBase("Boosters", editions.getBoosterGenerator()); - this.specialBoosters = new StorageBase("Special boosters", new SealedProductTemplate.Reader(new File(blockDataFolder, "boosters-special.txt"))); - this.tournaments = new StorageBase("Starter sets", new SealedProductTemplate.Reader(new File(blockDataFolder, "starters.txt"))); - this.fatPacks = new StorageBase("Fat packs", new FatPackTemplate.Reader("res/blockdata/fatpacks.txt")); + this.boosters = new StorageBase("Boosters", editions.getBoosterGenerator()); + this.specialBoosters = new StorageBase("Special boosters", new SealedProduct.Template.Reader(new File(blockDataFolder, "boosters-special.txt"))); + this.tournaments = new StorageBase("Starter sets", new SealedProduct.Template.Reader(new File(blockDataFolder, "starters.txt"))); + this.fatPacks = new StorageBase("Fat packs", new FatPack.Template.Reader("res/blockdata/fatpacks.txt")); this.printSheets = new StorageBase("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt"))); } @@ -76,30 +70,26 @@ public class StaticData { } - public final EditionCollection getEditions() { + public final CardEdition.Collection getEditions() { return this.editions; } - public final FormatCollection getFormats() { - return this.formats; - } - - /** @return {@link forge.util.storage.IStorageView}<{@link forge.card.FatPackTemplate}> */ - public IStorage getFatPacks() { + /** @return {@link forge.util.storage.IStorageView}<{@link forge.item.FatPackTemplate}> */ + public IStorage getFatPacks() { return fatPacks; } /** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */ - public final IStorage getTournamentPacks() { + public final IStorage getTournamentPacks() { return tournaments; } /** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */ - public final IStorage getBoosters() { + public final IStorage getBoosters() { return boosters; } - public final IStorage getSpecialBoosters() { + public final IStorage getSpecialBoosters() { return specialBoosters; } diff --git a/forge-core/src/main/java/forge/card/AggregationMethod.java b/forge-core/src/main/java/forge/card/AggregationMethod.java deleted file mode 100644 index f75c788e627..00000000000 --- a/forge-core/src/main/java/forge/card/AggregationMethod.java +++ /dev/null @@ -1,7 +0,0 @@ -package forge.card; - -public enum AggregationMethod { - USE_ACTIVE_FACE, - USE_PRIMARY_FACE, - AGGREGATE; -} diff --git a/forge-core/src/main/java/forge/card/BoosterGenerator.java b/forge-core/src/main/java/forge/card/BoosterGenerator.java index e97f6a8c5c6..40cd88bc2fd 100644 --- a/forge-core/src/main/java/forge/card/BoosterGenerator.java +++ b/forge-core/src/main/java/forge/card/BoosterGenerator.java @@ -37,6 +37,7 @@ import com.google.common.collect.Lists; import forge.StaticData; import forge.item.PaperCard; import forge.item.IPaperCard; +import forge.item.SealedProduct; import forge.util.TextUtil; /** @@ -57,7 +58,7 @@ public class BoosterGenerator { return cachedSheets.get(key); } - public static final List getBoosterPack(SealedProductTemplate booster) { + public static final List getBoosterPack(SealedProduct.Template booster) { List result = new ArrayList(); for(Pair slot : booster.getSlots()) { String slotType = slot.getLeft(); // add expansion symbol here? diff --git a/forge-core/src/main/java/forge/card/CardCoreType.java b/forge-core/src/main/java/forge/card/CardCoreType.java deleted file mode 100644 index 7d038a5b817..00000000000 --- a/forge-core/src/main/java/forge/card/CardCoreType.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * 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 . - */ -package forge.card; - -/** - * The Enum CardCoreType. - */ -public enum CardCoreType { - - /** The Artifact. */ - Artifact, - /** The Creature. */ - Creature, - /** The Enchantment. */ - Enchantment, - /** The Instant. */ - Instant, - /** The Land. */ - Land, - /** The Plane. */ - Plane, - /** The Planeswalker. */ - Planeswalker, - /** The Scheme. */ - Scheme, - /** The Sorcery. */ - Sorcery, - /** The Tribal. */ - Tribal, - /** The Vanguard. */ - Vanguard, - /** The Phenomenon. */ - Phenomenon -} diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index be51905e35f..05364cbe9b1 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -54,10 +54,10 @@ public final class CardDb implements ICardDatabase { private final List allCards = new ArrayList(); private final List roAllCards = Collections.unmodifiableList(allCards); private final Collection roUniqueCards = Collections.unmodifiableCollection(uniqueCardsByName.values()); - private final EditionCollection editions; + private final CardEdition.Collection editions; - public CardDb(Map rules, EditionCollection editions0, boolean logMissingCards) { + public CardDb(Map rules, CardEdition.Collection editions0, boolean logMissingCards) { this.rulesByName = rules; this.editions = editions0; List missingCards = new ArrayList(); diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index eeb464ee9f8..b5df5dee696 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -22,17 +22,25 @@ import java.io.FilenameFilter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.TreeMap; import org.apache.commons.lang3.StringUtils; import com.google.common.base.Function; +import com.google.common.collect.Lists; + +import forge.item.SealedProduct; import forge.util.FileSection; import forge.util.FileUtil; +import forge.util.IItemReader; +import forge.util.storage.StorageBase; +import forge.util.storage.StorageReaderBase; import forge.util.storage.StorageReaderFolder; @@ -98,7 +106,7 @@ public final class CardEdition implements Comparable { // immutable private int boosterArts = 1; - private SealedProductTemplate boosterTpl = null; + private SealedProduct.Template boosterTpl = null; private CardEdition(CardInSet[] cards) { this.cards = cards; @@ -202,7 +210,7 @@ public final class CardEdition implements Comparable { // immutable return boosterArts; } - public SealedProductTemplate getBoosterTemplate() { + public SealedProduct.Template getBoosterTemplate() { return boosterTpl; } @@ -247,7 +255,7 @@ public final class CardEdition implements Comparable { // immutable res.boosterArts = section.getInt("BoosterCovers", 1); String boosterDesc = section.get("Booster"); - res.boosterTpl = boosterDesc == null ? null : new SealedProductTemplate(res.code, SealedProductTemplate.Reader.parseSlots(boosterDesc)); + 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")); @@ -299,4 +307,100 @@ public final class CardEdition implements Comparable { // immutable }; } + public static class Collection extends StorageBase { + + private final Map aliasToEdition = new TreeMap(String.CASE_INSENSITIVE_ORDER); + + public Collection(IItemReader reader) { + super("Card editions", reader); + + for (CardEdition ee : this) { + String alias = ee.getAlias(); + if (null != alias) { + aliasToEdition.put(alias, ee); + } + aliasToEdition.put(ee.getCode2(), ee); + } + } + + /** + * 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 + */ + @Override + public CardEdition get(final String code) { + CardEdition baseResult = super.get(code); + return baseResult == null ? aliasToEdition.get(code) : baseResult; + } + + + public Iterable getOrderedEditions() { + List res = Lists.newArrayList(this); + Collections.sort(res); + Collections.reverse(res); + return res; + } + + /** + * Gets the sets by code or throw. + * + * @param code + * the code + * @return the sets the by code or throw + */ + public CardEdition getEditionByCodeOrThrow(final String code) { + final CardEdition set = this.get(code); + if (null == set) { + throw new RuntimeException(String.format("Edition with code '%s' not found", code)); + } + return set; + } + + // used by image generating code + /** + * Gets the code2 by code. + * + * @param code + * the code + * @return the code2 by code + */ + public String getCode2ByCode(final String code) { + final CardEdition set = this.get(code); + return set == null ? "" : set.getCode2(); + } + + public final Function FN_EDITION_BY_CODE = new Function() { + @Override + public CardEdition apply(String code) { + return Collection.this.get(code); + }; + }; + + /** + * TODO: Write javadoc for this method. + * @return + */ + public IItemReader getBoosterGenerator() { + // TODO Auto-generated method stub + return new StorageReaderBase(null) { + + @Override + public Map readAll() { + 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(); + } + }; + } + } } diff --git a/forge-core/src/main/java/forge/card/CardFace.java b/forge-core/src/main/java/forge/card/CardFace.java index dd2d75df76b..4e3545ee620 100644 --- a/forge-core/src/main/java/forge/card/CardFace.java +++ b/forge-core/src/main/java/forge/card/CardFace.java @@ -22,6 +22,13 @@ import forge.card.mana.ManaCost; */ final class CardFace implements ICardFace { + public enum FaceSelectionMethod { // + USE_ACTIVE_FACE, + USE_PRIMARY_FACE, + COMBINE; + } + + private final static List emptyList = Collections.unmodifiableList(new ArrayList()); private final static Map emptyMap = Collections.unmodifiableMap(new TreeMap()); diff --git a/forge-core/src/main/java/forge/card/CardRules.java b/forge-core/src/main/java/forge/card/CardRules.java index 84beb4bff8a..35c7381a500 100644 --- a/forge-core/src/main/java/forge/card/CardRules.java +++ b/forge-core/src/main/java/forge/card/CardRules.java @@ -120,7 +120,7 @@ public final class CardRules implements ICardCharacteristics { public String getName() { switch(splitType.getAggregationMethod()) { - case AGGREGATE: + case COMBINE: return mainPart.getName() + " // " + otherPart.getName(); default: return mainPart.getName(); @@ -134,7 +134,7 @@ public final class CardRules implements ICardCharacteristics { @Override public CardType getType() { switch(splitType.getAggregationMethod()) { - case AGGREGATE: // no cards currently have different types + case COMBINE: // no cards currently have different types return CardType.combine(mainPart.getType(), otherPart.getType()); default: return mainPart.getType(); @@ -145,7 +145,7 @@ public final class CardRules implements ICardCharacteristics { @Override public ManaCost getManaCost() { switch(splitType.getAggregationMethod()) { - case AGGREGATE: + case COMBINE: return ManaCost.combine(mainPart.getManaCost(), otherPart.getManaCost()); default: return mainPart.getManaCost(); @@ -155,7 +155,7 @@ public final class CardRules implements ICardCharacteristics { @Override public ColorSet getColor() { switch(splitType.getAggregationMethod()) { - case AGGREGATE: + case COMBINE: return ColorSet.fromMask(mainPart.getColor().getColor() | otherPart.getColor().getColor()); default: return mainPart.getColor(); @@ -171,7 +171,7 @@ public final class CardRules implements ICardCharacteristics { @Override public String getOracleText() { switch(splitType.getAggregationMethod()) { - case AGGREGATE: + case COMBINE: return mainPart.getOracleText() + "\r\n\r\n" + otherPart.getOracleText(); default: return mainPart.getOracleText(); diff --git a/forge-core/src/main/java/forge/card/CardRulesPredicates.java b/forge-core/src/main/java/forge/card/CardRulesPredicates.java index a67aa6793d8..78b4e475ef4 100644 --- a/forge-core/src/main/java/forge/card/CardRulesPredicates.java +++ b/forge-core/src/main/java/forge/card/CardRulesPredicates.java @@ -170,7 +170,7 @@ public final class CardRulesPredicates { */ public static Predicate coreType(final boolean isEqual, final String what) { try { - return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardCoreType.class, what)); + return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardType.CoreType.class, what)); } catch (final Exception e) { return com.google.common.base.Predicates.alwaysFalse(); } @@ -185,7 +185,7 @@ public final class CardRulesPredicates { * the type * @return the predicate */ - public static Predicate coreType(final boolean isEqual, final CardCoreType type) { + public static Predicate coreType(final boolean isEqual, final CardType.CoreType type) { return new PredicateCoreType(type, isEqual); } @@ -200,7 +200,7 @@ public final class CardRulesPredicates { */ public static Predicate superType(final boolean isEqual, final String what) { try { - return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardSuperType.class, what)); + return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardType.SuperType.class, what)); } catch (final Exception e) { return com.google.common.base.Predicates.alwaysFalse(); } @@ -215,7 +215,7 @@ public final class CardRulesPredicates { * the type * @return the predicate */ - public static Predicate superType(final boolean isEqual, final CardSuperType type) { + public static Predicate superType(final boolean isEqual, final CardType.SuperType type) { return new PredicateSuperType(type, isEqual); } @@ -396,7 +396,7 @@ public final class CardRulesPredicates { } private static class PredicateCoreType implements Predicate { - private final CardCoreType operand; + private final CardType.CoreType operand; private final boolean shouldBeEqual; @Override @@ -407,14 +407,14 @@ public final class CardRulesPredicates { return this.shouldBeEqual == card.getType().typeContains(this.operand); } - public PredicateCoreType(final CardCoreType type, final boolean wantEqual) { + public PredicateCoreType(final CardType.CoreType type, final boolean wantEqual) { this.operand = type; this.shouldBeEqual = wantEqual; } } private static class PredicateSuperType implements Predicate { - private final CardSuperType operand; + private final CardType.SuperType operand; private final boolean shouldBeEqual; @Override @@ -422,7 +422,7 @@ public final class CardRulesPredicates { return this.shouldBeEqual == card.getType().superTypeContains(this.operand); } - public PredicateSuperType(final CardSuperType type, final boolean wantEqual) { + public PredicateSuperType(final CardType.SuperType type, final boolean wantEqual) { this.operand = type; this.shouldBeEqual = wantEqual; } @@ -448,21 +448,21 @@ public final class CardRulesPredicates { /** The Constant isCreature. */ public static final Predicate IS_CREATURE = CardRulesPredicates - .coreType(true, CardCoreType.Creature); + .coreType(true, CardType.CoreType.Creature); public static final Predicate IS_LEGENDARY = CardRulesPredicates - .superType(true, CardSuperType.Legendary); + .superType(true, CardType.SuperType.Legendary); /** The Constant isArtifact. */ public static final Predicate IS_ARTIFACT = CardRulesPredicates - .coreType(true, CardCoreType.Artifact); + .coreType(true, CardType.CoreType.Artifact); /** The Constant isEquipment. */ public static final Predicate IS_EQUIPMENT = CardRulesPredicates .subType("Equipment"); /** The Constant isLand. */ - public static final Predicate IS_LAND = CardRulesPredicates.coreType(true, CardCoreType.Land); + public static final Predicate IS_LAND = CardRulesPredicates.coreType(true, CardType.CoreType.Land); /** The Constant isBasicLand. */ public static final Predicate IS_BASIC_LAND = new Predicate() { @@ -480,31 +480,17 @@ public final class CardRulesPredicates { } }; - /** The Constant isPlaneswalker. */ - public static final Predicate IS_PLANESWALKER = CardRulesPredicates.coreType(true, - CardCoreType.Planeswalker); - - /** The Constant isInstant. */ - public static final Predicate IS_INSTANT = CardRulesPredicates.coreType(true, CardCoreType.Instant); - - /** The Constant isSorcery. */ - public static final Predicate IS_SORCERY = CardRulesPredicates.coreType(true, CardCoreType.Sorcery); - - /** The Constant isEnchantment. */ - public static final Predicate IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardCoreType.Enchantment); - - public static final Predicate IS_PLANE = CardRulesPredicates.coreType(true, CardCoreType.Plane); - public static final Predicate IS_PHENOMENON = CardRulesPredicates.coreType(true, CardCoreType.Phenomenon); + public static final Predicate IS_PLANESWALKER = CardRulesPredicates.coreType(true, CardType.CoreType.Planeswalker); + public static final Predicate IS_INSTANT = CardRulesPredicates.coreType(true, CardType.CoreType.Instant); + public static final Predicate IS_SORCERY = CardRulesPredicates.coreType(true, CardType.CoreType.Sorcery); + public static final Predicate IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardType.CoreType.Enchantment); + public static final Predicate IS_PLANE = CardRulesPredicates.coreType(true, CardType.CoreType.Plane); + public static final Predicate IS_PHENOMENON = CardRulesPredicates.coreType(true, CardType.CoreType.Phenomenon); public static final Predicate IS_PLANE_OR_PHENOMENON = Predicates.or(IS_PLANE, IS_PHENOMENON); - public static final Predicate IS_SCHEME = CardRulesPredicates.coreType(true, CardCoreType.Scheme); - public static final Predicate IS_VANGUARD = CardRulesPredicates.coreType(true, CardCoreType.Vanguard); - - /** The Constant isNonLand. */ - public static final Predicate IS_NON_LAND = CardRulesPredicates.coreType(false, CardCoreType.Land); - - /** The Constant isNonCreatureSpell. */ - public static final Predicate IS_NON_CREATURE_SPELL = Predicates.not(Predicates.or( - Presets.IS_CREATURE, Presets.IS_LAND)); + public static final Predicate IS_SCHEME = CardRulesPredicates.coreType(true, CardType.CoreType.Scheme); + public static final Predicate IS_VANGUARD = CardRulesPredicates.coreType(true, CardType.CoreType.Vanguard); + public static final Predicate IS_NON_LAND = CardRulesPredicates.coreType(false, CardType.CoreType.Land); + public static final Predicate IS_NON_CREATURE_SPELL = Predicates.not(Predicates.or(Presets.IS_CREATURE, Presets.IS_LAND)); /** The Constant IS_NONCREATURE_SPELL_FOR_GENERATOR. **/ @SuppressWarnings("unchecked") diff --git a/forge-core/src/main/java/forge/card/CardSplitType.java b/forge-core/src/main/java/forge/card/CardSplitType.java index 9811ed04669..37855204fcc 100644 --- a/forge-core/src/main/java/forge/card/CardSplitType.java +++ b/forge-core/src/main/java/forge/card/CardSplitType.java @@ -1,24 +1,26 @@ package forge.card; +import forge.card.CardFace.FaceSelectionMethod; + public enum CardSplitType { - None(AggregationMethod.USE_PRIMARY_FACE, null), - Transform(AggregationMethod.USE_ACTIVE_FACE, CardCharacteristicName.Transformed), - Split(AggregationMethod.AGGREGATE, CardCharacteristicName.RightSplit), - Flip(AggregationMethod.USE_PRIMARY_FACE, CardCharacteristicName.Flipped), + None(FaceSelectionMethod.USE_PRIMARY_FACE, null), + Transform(FaceSelectionMethod.USE_ACTIVE_FACE, CardCharacteristicName.Transformed), + Split(FaceSelectionMethod.COMBINE, CardCharacteristicName.RightSplit), + Flip(FaceSelectionMethod.USE_PRIMARY_FACE, CardCharacteristicName.Flipped), // used by 12 licid creatures to switch type into enchantment aura - Licid(AggregationMethod.USE_PRIMARY_FACE, CardCharacteristicName.Licid); + Licid(FaceSelectionMethod.USE_PRIMARY_FACE, CardCharacteristicName.Licid); - private CardSplitType(AggregationMethod calcMode, CardCharacteristicName stateName) { + private CardSplitType(FaceSelectionMethod calcMode, CardCharacteristicName stateName) { method = calcMode; this.changedStateName = stateName; } - public AggregationMethod getAggregationMethod() { + public FaceSelectionMethod getAggregationMethod() { return method; } - private final AggregationMethod method; + private final FaceSelectionMethod method; private final CardCharacteristicName changedStateName; public static CardSplitType smartValueOf(String text) { diff --git a/forge-core/src/main/java/forge/card/CardType.java b/forge-core/src/main/java/forge/card/CardType.java index 1100321685e..df1b3e8fcc1 100644 --- a/forge-core/src/main/java/forge/card/CardType.java +++ b/forge-core/src/main/java/forge/card/CardType.java @@ -34,20 +34,64 @@ import org.apache.commons.lang3.StringUtils; */ public final class CardType implements Comparable { + + public enum CoreType { + + /** The Artifact. */ + Artifact, + /** The Creature. */ + Creature, + /** The Enchantment. */ + Enchantment, + /** The Instant. */ + Instant, + /** The Land. */ + Land, + /** The Plane. */ + Plane, + /** The Planeswalker. */ + Planeswalker, + /** The Scheme. */ + Scheme, + /** The Sorcery. */ + Sorcery, + /** The Tribal. */ + Tribal, + /** The Vanguard. */ + Vanguard, + /** The Phenomenon. */ + Phenomenon + } + + public enum SuperType { + + /** The Basic. */ + Basic, + /** The Legendary. */ + Legendary, + /** The Snow. */ + Snow, + /** The Ongoing. */ + Ongoing, + /** The World. */ + World + } + + private final List subType = new ArrayList(); - private final EnumSet coreType = EnumSet.noneOf(CardCoreType.class); - private final EnumSet superType = EnumSet.noneOf(CardSuperType.class); + private final EnumSet coreType = EnumSet.noneOf(CardType.CoreType.class); + private final EnumSet superType = EnumSet.noneOf(CardType.SuperType.class); private String calculatedType = null; // since obj is immutable, this is // calc'd once // This will be useful for faster parses - private static HashMap stringToCoreType = new HashMap(); - private static HashMap stringToSuperType = new HashMap(); + private static HashMap stringToCoreType = new HashMap(); + private static HashMap stringToSuperType = new HashMap(); static { - for (final CardSuperType st : CardSuperType.values()) { + for (final CardType.SuperType st : CardType.SuperType.values()) { CardType.stringToSuperType.put(st.name(), st); } - for (final CardCoreType ct : CardCoreType.values()) { + for (final CardType.CoreType ct : CardType.CoreType.values()) { CardType.stringToCoreType.put(ct.name(), ct); } } @@ -104,13 +148,13 @@ public final class CardType implements Comparable { return; } - final CardCoreType ct = CardType.stringToCoreType.get(type); + final CardType.CoreType ct = CardType.stringToCoreType.get(type); if (ct != null) { this.coreType.add(ct); return; } - final CardSuperType st = CardType.stringToSuperType.get(type); + final CardType.SuperType st = CardType.stringToSuperType.get(type); if (st != null) { this.superType.add(st); return; @@ -124,56 +168,56 @@ public final class CardType implements Comparable { return this.subType.contains(operand); } - public boolean typeContains(final CardCoreType operand) { + public boolean typeContains(final CardType.CoreType operand) { return this.coreType.contains(operand); } - public boolean superTypeContains(final CardSuperType operand) { + public boolean superTypeContains(final CardType.SuperType operand) { return this.superType.contains(operand); } public boolean isCreature() { - return this.coreType.contains(CardCoreType.Creature); + return this.coreType.contains(CardType.CoreType.Creature); } public boolean isPlaneswalker() { - return this.coreType.contains(CardCoreType.Planeswalker); + return this.coreType.contains(CardType.CoreType.Planeswalker); } public boolean isLand() { - return this.coreType.contains(CardCoreType.Land); + return this.coreType.contains(CardType.CoreType.Land); } public boolean isArtifact() { - return this.coreType.contains(CardCoreType.Artifact); + return this.coreType.contains(CardType.CoreType.Artifact); } public boolean isInstant() { - return this.coreType.contains(CardCoreType.Instant); + return this.coreType.contains(CardType.CoreType.Instant); } public boolean isSorcery() { - return this.coreType.contains(CardCoreType.Sorcery); + return this.coreType.contains(CardType.CoreType.Sorcery); } public boolean isVanguard() { - return this.coreType.contains(CardCoreType.Vanguard); + return this.coreType.contains(CardType.CoreType.Vanguard); } public boolean isScheme() { - return this.coreType.contains(CardCoreType.Scheme); + return this.coreType.contains(CardType.CoreType.Scheme); } public boolean isEnchantment() { - return this.coreType.contains(CardCoreType.Enchantment); + return this.coreType.contains(CardType.CoreType.Enchantment); } public boolean isBasic() { - return this.superType.contains(CardSuperType.Basic); + return this.superType.contains(CardType.SuperType.Basic); } public boolean isLegendary() { - return this.superType.contains(CardSuperType.Legendary); + return this.superType.contains(CardType.SuperType.Legendary); } public boolean isBasicLand() { @@ -198,10 +242,10 @@ public final class CardType implements Comparable { public List getTypesBeforeDash() { final ArrayList types = new ArrayList(); - for (final CardSuperType st : this.superType) { + for (final CardType.SuperType st : this.superType) { types.add(st.name()); } - for (final CardCoreType ct : this.coreType) { + for (final CardType.CoreType ct : this.coreType) { types.add(ct.name()); } return types; @@ -227,11 +271,11 @@ public final class CardType implements Comparable { } public boolean isPlane() { - return this.coreType.contains(CardCoreType.Plane); + return this.coreType.contains(CardType.CoreType.Plane); } public boolean isPhenomenon() { - return this.coreType.contains(CardCoreType.Phenomenon); + return this.coreType.contains(CardType.CoreType.Phenomenon); } diff --git a/forge-core/src/main/java/forge/card/EditionCollection.java b/forge-core/src/main/java/forge/card/EditionCollection.java deleted file mode 100644 index 1db42497cc4..00000000000 --- a/forge-core/src/main/java/forge/card/EditionCollection.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * 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 . - */ -package forge.card; - -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import com.google.common.base.Function; -import com.google.common.collect.Lists; - -import forge.util.IItemReader; -import forge.util.storage.StorageBase; -import forge.util.storage.StorageReaderBase; - -public final class EditionCollection extends StorageBase { - - private final Map aliasToEdition = new TreeMap(String.CASE_INSENSITIVE_ORDER); - - public EditionCollection(IItemReader reader) { - super("Card editions", reader); - - for (CardEdition ee : this) { - String alias = ee.getAlias(); - if (null != alias) { - aliasToEdition.put(alias, ee); - } - aliasToEdition.put(ee.getCode2(), ee); - } - } - - /** - * 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 - */ - @Override - public CardEdition get(final String code) { - CardEdition baseResult = super.get(code); - return baseResult == null ? aliasToEdition.get(code) : baseResult; - } - - - public Iterable getOrderedEditions() { - List res = Lists.newArrayList(this); - Collections.sort(res); - Collections.reverse(res); - return res; - } - - /** - * Gets the sets by code or throw. - * - * @param code - * the code - * @return the sets the by code or throw - */ - public CardEdition getEditionByCodeOrThrow(final String code) { - final CardEdition set = this.get(code); - if (null == set) { - throw new RuntimeException(String.format("Edition with code '%s' not found", code)); - } - return set; - } - - // used by image generating code - /** - * Gets the code2 by code. - * - * @param code - * the code - * @return the code2 by code - */ - public String getCode2ByCode(final String code) { - final CardEdition set = this.get(code); - return set == null ? "" : set.getCode2(); - } - - public final Function FN_EDITION_BY_CODE = new Function() { - @Override - public CardEdition apply(String code) { - return EditionCollection.this.get(code); - }; - }; - - /** - * TODO: Write javadoc for this method. - * @return - */ - public IItemReader getBoosterGenerator() { - // TODO Auto-generated method stub - return new StorageReaderBase(null) { - - @Override - public Map readAll() { - Map map = new TreeMap(String.CASE_INSENSITIVE_ORDER); - for(CardEdition ce : EditionCollection.this) { - map.put(ce.getCode(), ce.getBoosterTemplate()); - } - return map; - } - - @Override - public String getItemKey(SealedProductTemplate item) { - return item.getEdition(); - } - }; - } -} - diff --git a/forge-core/src/main/java/forge/card/FatPackTemplate.java b/forge-core/src/main/java/forge/card/FatPackTemplate.java deleted file mode 100644 index 0ffa82071d4..00000000000 --- a/forge-core/src/main/java/forge/card/FatPackTemplate.java +++ /dev/null @@ -1,75 +0,0 @@ -package forge.card; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; - -import forge.util.TextUtil; -import forge.util.storage.StorageReaderFile; - -/** - * TODO: Write javadoc for this type. - * - */ -public class FatPackTemplate extends SealedProductTemplate { - private final int cntBoosters; - - - public int getCntBoosters() { return cntBoosters; } - - private FatPackTemplate(String edition, int boosters, Iterable> itrSlots) - { - super(edition, itrSlots); - cntBoosters = boosters; - } - - public static final class Reader extends StorageReaderFile { - public Reader(String pathname) { - super(pathname, FatPackTemplate.FN_GET_NAME); - } - - @Override - protected FatPackTemplate read(String line, int i) { - String[] headAndData = TextUtil.split(line, ':', 2); - final String edition = headAndData[0]; - final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ','); - int nBoosters = 6; - - List> slots = new ArrayList>(); - for(String slotDesc : data) { - String[] kv = TextUtil.split(slotDesc, ' ', 2); - if (kv[1].startsWith("Booster")) - nBoosters = Integer.parseInt(kv[0]); - else - slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0]))); - } - - return new FatPackTemplate(edition, nBoosters, slots); - } - } - - @Override - public String toString() { - if (0 >= cntBoosters) { - return "no cards"; - } - - StringBuilder s = new StringBuilder(); - for(Pair p : slots) { - s.append(p.getRight()).append(" ").append(p.getLeft()).append(", "); - } - // trim the last comma and space - if( s.length() > 0 ) - s.replace(s.length() - 2, s.length(), ""); - - if (0 < cntBoosters) { - if( s.length() > 0 ) - s.append(" and "); - - s.append(cntBoosters).append(" booster packs "); - } - return s.toString(); - } -} diff --git a/forge-core/src/main/java/forge/card/UnOpenedProduct.java b/forge-core/src/main/java/forge/card/UnOpenedProduct.java index 56a9ec8d4cf..960779f4f44 100644 --- a/forge-core/src/main/java/forge/card/UnOpenedProduct.java +++ b/forge-core/src/main/java/forge/card/UnOpenedProduct.java @@ -12,12 +12,13 @@ import com.google.common.collect.Iterables; import forge.StaticData; import forge.item.PaperCard; +import forge.item.SealedProduct; import forge.util.ItemPoolView; public class UnOpenedProduct implements IUnOpenedProduct { - private final SealedProductTemplate tpl; + private final SealedProduct.Template tpl; private final Map sheets; private boolean poolLimited = false; // if true after successful generation cards are removed from printsheets. @@ -31,23 +32,23 @@ public class UnOpenedProduct implements IUnOpenedProduct { // Means to select from all unique cards (from base game, ie. no schemes or avatars) - public UnOpenedProduct(SealedProductTemplate template) { + public UnOpenedProduct(SealedProduct.Template template) { tpl = template; sheets = null; } // Invoke this constructor only if you are sure that the pool is not equal to deafult carddb - public UnOpenedProduct(SealedProductTemplate template, ItemPoolView pool) { + public UnOpenedProduct(SealedProduct.Template template, ItemPoolView pool) { this(template, pool.toFlatList()); } - public UnOpenedProduct(SealedProductTemplate template, Iterable cards) { + public UnOpenedProduct(SealedProduct.Template template, Iterable cards) { tpl = template; sheets = new TreeMap(); prebuildSheets(cards); } - public UnOpenedProduct(SealedProductTemplate sealedProductTemplate, Predicate filterPrinted) { + public UnOpenedProduct(SealedProduct.Template sealedProductTemplate, Predicate filterPrinted) { this(sealedProductTemplate, Iterables.filter(StaticData.instance().getCommonCards().getAllCards(), filterPrinted)); } diff --git a/forge-core/src/main/java/forge/deck/DeckFormat.java b/forge-core/src/main/java/forge/deck/DeckFormat.java index c93cda09304..bc4e8b95942 100644 --- a/forge-core/src/main/java/forge/deck/DeckFormat.java +++ b/forge-core/src/main/java/forge/deck/DeckFormat.java @@ -26,7 +26,7 @@ import java.util.Map.Entry; import org.apache.commons.lang3.Range; import forge.StaticData; -import forge.card.CardCoreType; +import forge.card.CardType; import forge.card.ColorSet; import forge.item.PaperCard; import forge.item.IPaperCard; @@ -178,7 +178,7 @@ public enum DeckFormat { int phenoms = 0; for (Entry cp : planes) { - if (cp.getKey().getRules().getType().typeContains(CardCoreType.Phenomenon)) { + if (cp.getKey().getRules().getType().typeContains(CardType.CoreType.Phenomenon)) { phenoms++; } if (cp.getValue() > 1) { diff --git a/forge-core/src/main/java/forge/item/BoosterPack.java b/forge-core/src/main/java/forge/item/BoosterPack.java index 270d5d6e003..031c2a6461e 100644 --- a/forge-core/src/main/java/forge/item/BoosterPack.java +++ b/forge-core/src/main/java/forge/item/BoosterPack.java @@ -22,22 +22,21 @@ import com.google.common.base.Function; import forge.StaticData; import forge.card.CardEdition; -import forge.card.SealedProductTemplate; import forge.util.MyRandom; -public class BoosterPack extends OpenablePack { +public class BoosterPack extends SealedProduct { private final int artIndex; private final int hash; public static final Function FN_FROM_SET = new Function() { @Override public BoosterPack apply(final CardEdition arg1) { - SealedProductTemplate d = StaticData.instance().getBoosters().get(arg1.getCode()); + Template d = StaticData.instance().getBoosters().get(arg1.getCode()); return new BoosterPack(arg1.getName(), d); } }; - public BoosterPack(final String name0, final SealedProductTemplate boosterData) { + 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; @@ -58,7 +57,7 @@ public class BoosterPack extends OpenablePack { return new BoosterPack(name, contents); } - public SealedProductTemplate getBoosterData() { + public Template getBoosterData() { return contents; } diff --git a/forge-core/src/main/java/forge/item/FatPack.java b/forge-core/src/main/java/forge/item/FatPack.java index aef4f71d455..ef6cf1ae969 100644 --- a/forge-core/src/main/java/forge/item/FatPack.java +++ b/forge-core/src/main/java/forge/item/FatPack.java @@ -21,25 +21,29 @@ package forge.item; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + import com.google.common.base.Function; import forge.StaticData; import forge.card.BoosterGenerator; import forge.card.CardEdition; -import forge.card.FatPackTemplate; +import forge.util.TextUtil; +import forge.util.storage.StorageReaderFile; -public class FatPack extends OpenablePack { +public class FatPack extends SealedProduct { public static final Function FN_FROM_SET = new Function() { @Override public FatPack apply(final CardEdition arg1) { - FatPackTemplate d = StaticData.instance().getFatPacks().get(arg1.getCode()); + FatPack.Template d = StaticData.instance().getFatPacks().get(arg1.getCode()); return new FatPack(arg1.getName(), d); } }; - private final FatPackTemplate fpData; + private final FatPack.Template fpData; - public FatPack(final String name0, final FatPackTemplate fpData0) { + public FatPack(final String name0, final FatPack.Template fpData0) { super(name0, StaticData.instance().getBoosters().get(fpData0.getEdition())); fpData = fpData0; } @@ -73,4 +77,65 @@ public class FatPack extends OpenablePack { public int getTotalCards() { return super.getTotalCards() * fpData.getCntBoosters() + fpData.getNumberOfCardsExpected(); } + + public static class Template extends SealedProduct.Template { + private final int cntBoosters; + + + public int getCntBoosters() { return cntBoosters; } + + private Template(String edition, int boosters, Iterable> itrSlots) + { + super(edition, itrSlots); + cntBoosters = boosters; + } + + public static final class Reader extends StorageReaderFile