Moved cardDb and most of static data to core project. Had to rollback some incompatible changes. Sorry, drdev!

This commit is contained in:
Maxmtg
2013-11-19 07:40:58 +00:00
parent a7fa173e52
commit 9b31032016
169 changed files with 1074 additions and 1126 deletions

90
.gitattributes vendored
View File

@@ -20,27 +20,75 @@ forge-core/.settings/org.eclipse.jdt.core.prefs -text
forge-core/.settings/org.eclipse.m2e.core.prefs -text
forge-core/pom.xml -text
forge-core/src/main/java/forge/Constant.java svneol=native#text/plain
forge-core/src/main/java/forge/ICardStorageReader.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/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/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
forge-core/src/main/java/forge/card/ICardFace.java -text
forge-core/src/main/java/forge/card/ICardRawAbilites.java -text
forge-core/src/main/java/forge/card/IUnOpenedProduct.java -text
forge-core/src/main/java/forge/card/MagicColor.java -text
forge-core/src/main/java/forge/card/PrintSheet.java -text
forge-core/src/main/java/forge/card/mana/IParserManaCost.java -text
forge-core/src/main/java/forge/card/mana/ManaAtom.java -text
forge-core/src/main/java/forge/card/mana/ManaCost.java -text
forge-core/src/main/java/forge/card/mana/ManaCostParser.java -text
forge-core/src/main/java/forge/card/mana/ManaCostShard.java -text
forge-core/src/main/java/forge/card/mana/package-info.java svneol=native#text/plain
forge-core/src/main/java/forge/deck/CardPool.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/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/PaperCard.java -text
forge-core/src/main/java/forge/item/PaperToken.java -text
forge-core/src/main/java/forge/item/package-info.java -text
forge-core/src/main/java/forge/package-info.java -text
forge-core/src/main/java/forge/util/Aggregates.java -text
forge-core/src/main/java/forge/util/BinaryUtil.java -text
forge-core/src/main/java/forge/util/CollectionSuppliers.java -text
forge-core/src/main/java/forge/util/ComparableOp.java -text
forge-core/src/main/java/forge/util/FileSection.java -text
forge-core/src/main/java/forge/util/FileSectionManual.java -text
forge-core/src/main/java/forge/util/FileUtil.java svneol=native#text/plain
forge-core/src/main/java/forge/util/IHasName.java -text
forge-core/src/main/java/forge/util/IItemReader.java -text
forge-core/src/main/java/forge/util/IItemSerializer.java -text
forge-core/src/main/java/forge/util/ItemPool.java -text
forge-core/src/main/java/forge/util/ItemPoolSorter.java -text
forge-core/src/main/java/forge/util/ItemPoolView.java -text
forge-core/src/main/java/forge/util/Lang.java -text
forge-core/src/main/java/forge/util/MyRandom.java svneol=native#text/plain
forge-core/src/main/java/forge/util/PredicateString.java -text
forge-core/src/main/java/forge/util/TextUtil.java -text
forge-core/src/main/java/forge/util/package-info.java -text
forge-core/src/main/java/forge/util/storage/IStorage.java -text
forge-core/src/main/java/forge/util/storage/StorageBase.java -text
forge-core/src/main/java/forge/util/storage/StorageReaderBase.java -text
forge-core/src/main/java/forge/util/storage/StorageReaderFile.java -text
forge-core/src/main/java/forge/util/storage/StorageReaderFileSections.java -text
forge-core/src/main/java/forge/util/storage/StorageReaderFolder.java -text
forge-core/src/main/java/forge/util/storage/package-info.java -text
forge-gui/.classpath -text
forge-gui/.project -text
forge-gui/.settings/org.eclipse.core.resources.prefs -text
@@ -14632,21 +14680,11 @@ forge-gui/src/main/java/forge/Singletons.java svneol=native#text/plain
forge-gui/src/main/java/forge/StaticEffect.java svneol=native#text/plain
forge-gui/src/main/java/forge/StaticEffects.java svneol=native#text/plain
forge-gui/src/main/java/forge/card/BoosterGenerator.java svneol=native#text/plain
forge-gui/src/main/java/forge/card/CardAiHints.java -text
forge-gui/src/main/java/forge/card/CardBlock.java -text
forge-gui/src/main/java/forge/card/CardCharacteristics.java -text
forge-gui/src/main/java/forge/card/CardDb.java -text
forge-gui/src/main/java/forge/card/CardEdition.java -text
forge-gui/src/main/java/forge/card/CardEditionPredicates.java -text
forge-gui/src/main/java/forge/card/CardFace.java -text
forge-gui/src/main/java/forge/card/CardRules.java -text
forge-gui/src/main/java/forge/card/CardRulesPredicates.java -text
forge-gui/src/main/java/forge/card/CardRulesReader.java svneol=native#text/plain
forge-gui/src/main/java/forge/card/DeckHints.java -text
forge-gui/src/main/java/forge/card/EditionCollection.java svneol=native#text/plain
forge-gui/src/main/java/forge/card/FatPackTemplate.java -text
forge-gui/src/main/java/forge/card/FormatCollection.java -text
forge-gui/src/main/java/forge/card/ICardDatabase.java -text
forge-gui/src/main/java/forge/card/IUnOpenedProduct.java -text
forge-gui/src/main/java/forge/card/MetaSet.java -text
forge-gui/src/main/java/forge/card/TriggerReplacementBase.java -text
forge-gui/src/main/java/forge/card/UnOpenedMeta.java -text
@@ -15032,7 +15070,6 @@ forge-gui/src/main/java/forge/control/KeyboardShortcuts.java -text
forge-gui/src/main/java/forge/control/RestartUtil.java -text
forge-gui/src/main/java/forge/control/package-info.java -text
forge-gui/src/main/java/forge/deck/CardCollections.java -text
forge-gui/src/main/java/forge/deck/CardPool.java -text
forge-gui/src/main/java/forge/deck/Deck.java svneol=native#text/plain
forge-gui/src/main/java/forge/deck/DeckBase.java -text
forge-gui/src/main/java/forge/deck/DeckFormat.java -text
@@ -15062,7 +15099,6 @@ forge-gui/src/main/java/forge/game/GameAction.java svneol=native#text/plain
forge-gui/src/main/java/forge/game/GameActionUtil.java svneol=native#text/plain
forge-gui/src/main/java/forge/game/GameAge.java -text
forge-gui/src/main/java/forge/game/GameEndReason.java -text
forge-gui/src/main/java/forge/game/GameFormat.java -text
forge-gui/src/main/java/forge/game/GameNew.java -text
forge-gui/src/main/java/forge/game/GameOutcome.java -text
forge-gui/src/main/java/forge/game/GameType.java -text
@@ -15474,18 +15510,9 @@ forge-gui/src/main/java/forge/gui/workshop/views/VCardScript.java -text
forge-gui/src/main/java/forge/gui/workshop/views/VWorkshopCatalog.java -text
forge-gui/src/main/java/forge/item/BoosterPack.java -text
forge-gui/src/main/java/forge/item/FatPack.java -text
forge-gui/src/main/java/forge/item/IPaperCard.java -text
forge-gui/src/main/java/forge/item/InventoryItem.java -text
forge-gui/src/main/java/forge/item/InventoryItemFromSet.java -text
forge-gui/src/main/java/forge/item/ItemPool.java -text
forge-gui/src/main/java/forge/item/ItemPoolSorter.java -text
forge-gui/src/main/java/forge/item/ItemPoolView.java -text
forge-gui/src/main/java/forge/item/ItemPredicate.java -text
forge-gui/src/main/java/forge/item/OpenablePack.java -text
forge-gui/src/main/java/forge/item/PaperCard.java -text
forge-gui/src/main/java/forge/item/PaperToken.java -text
forge-gui/src/main/java/forge/item/PreconDeck.java -text
forge-gui/src/main/java/forge/item/PrintSheet.java -text
forge-gui/src/main/java/forge/item/TournamentPack.java -text
forge-gui/src/main/java/forge/item/package-info.java -text
forge-gui/src/main/java/forge/model/BuildInfo.java -text
@@ -15587,28 +15614,15 @@ forge-gui/src/main/java/forge/sound/IAudioClip.java -text
forge-gui/src/main/java/forge/sound/NoSoundClip.java -text
forge-gui/src/main/java/forge/sound/SoundEffectType.java -text
forge-gui/src/main/java/forge/sound/SoundSystem.java -text
forge-gui/src/main/java/forge/util/Aggregates.java -text
forge-gui/src/main/java/forge/util/Base64Coder.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/ComparableOp.java -text
forge-gui/src/main/java/forge/util/Expressions.java -text
forge-gui/src/main/java/forge/util/FileSection.java -text
forge-gui/src/main/java/forge/util/FileSectionManual.java -text
forge-gui/src/main/java/forge/util/FileUtil.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/HttpUtil.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/IHasName.java -text
forge-gui/src/main/java/forge/util/IItemReader.java -text
forge-gui/src/main/java/forge/util/IItemSerializer.java -text
forge-gui/src/main/java/forge/util/IgnoringXStream.java -text
forge-gui/src/main/java/forge/util/Lang.java -text
forge-gui/src/main/java/forge/util/LineReader.java -text
forge-gui/src/main/java/forge/util/MultiplexOutputStream.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/MyRandom.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/PredicateString.java -text
forge-gui/src/main/java/forge/util/ReflectionUtil.java -text
forge-gui/src/main/java/forge/util/TextUtil.java -text
forge-gui/src/main/java/forge/util/TypeUtil.java -text
forge-gui/src/main/java/forge/util/XmlUtil.java -text
forge-gui/src/main/java/forge/util/maps/CollectionSuppliers.java -text
forge-gui/src/main/java/forge/util/maps/EnumMapOfLists.java -text
forge-gui/src/main/java/forge/util/maps/EnumMapToAmount.java -text
forge-gui/src/main/java/forge/util/maps/HashMapOfLists.java -text
@@ -15618,14 +15632,8 @@ forge-gui/src/main/java/forge/util/maps/TreeMapOfLists.java -text
forge-gui/src/main/java/forge/util/maps/TreeMapToAmount.java -text
forge-gui/src/main/java/forge/util/maps/package-info.java -text
forge-gui/src/main/java/forge/util/package-info.java -text
forge-gui/src/main/java/forge/util/storage/IStorage.java -text
forge-gui/src/main/java/forge/util/storage/StorageBase.java -text
forge-gui/src/main/java/forge/util/storage/StorageImmediatelySerialized.java svneol=native#text/plain
forge-gui/src/main/java/forge/util/storage/StorageNestedFolders.java -text
forge-gui/src/main/java/forge/util/storage/StorageReaderBase.java -text
forge-gui/src/main/java/forge/util/storage/StorageReaderFile.java -text
forge-gui/src/main/java/forge/util/storage/StorageReaderFileSections.java -text
forge-gui/src/main/java/forge/util/storage/StorageReaderFolder.java -text
forge-gui/src/main/java/forge/util/storage/package-info.java -text
forge-gui/src/main/java/forge/view/ButtonUtil.java svneol=native#text/plain
forge-gui/src/main/java/forge/view/FDialog.java -text

View File

@@ -19,7 +19,6 @@ package forge;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ImmutableList;
/**
* <p>
@@ -54,79 +53,6 @@ public final class Constant {
public static final int HEIGHT = 0;
}
/**
* The Interface Color.
*/
public static class Color {
/** The Black. */
public static final String BLACK = "black";
/** The Blue. */
public static final String BLUE = "blue";
/** The Green. */
public static final String GREEN = "green";
/** The Red. */
public static final String RED = "red";
/** The White. */
public static final String WHITE = "white";
/** The Colorless. */
public static final String COLORLESS = "colorless";
// color order "wubrg"
/** The only colors. */
public static final ImmutableList<String> ONLY_COLORS = ImmutableList.of(Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN);
/** The Snow. */
public static final String SNOW = "snow";
/** The Basic lands. */
public static final List<String> BASIC_LANDS = ImmutableList.of("Plains", "Island", "Swamp", "Mountain", "Forest");
public static final List<String> SNOW_LANDS = ImmutableList.of("Snow-Covered Plains", "Snow-Covered Island", "Snow-Covered Swamp", "Snow-Covered Mountain", "Snow-Covered Forest");
}
/**
* The Interface CardTypes.
*/
public static class CardTypes {
/** The loaded. */
public static final boolean[] LOADED = { false };
/** The card types. */
public static final List<String> CARD_TYPES = new ArrayList<String>();
/** The super types. */
public static final List<String> SUPER_TYPES = new ArrayList<String>();
/** The basic types. */
public static final List<String> BASIC_TYPES = new ArrayList<String>();
/** The land types. */
public static final List<String> LAND_TYPES = new ArrayList<String>();
/** The creature types. */
public static final List<String> CREATURE_TYPES = new ArrayList<String>();
/** The instant types. */
public static final List<String> INSTANT_TYPES = new ArrayList<String>();
/** The sorcery types. */
public static final List<String> SORCERY_TYPES = new ArrayList<String>();
/** The enchantment types. */
public static final List<String> ENCHANTMENT_TYPES = new ArrayList<String>();
/** The artifact types. */
public static final List<String> ARTIFACT_TYPES = new ArrayList<String>();
/** The walker types. */
public static final List<String> WALKER_TYPES = new ArrayList<String>();
}
/**
* The Interface Keywords.

View File

@@ -0,0 +1,9 @@
package forge;
import java.util.List;
import forge.card.CardRules;
public interface ICardStorageReader{
List<CardRules> loadCards();
}

View File

@@ -0,0 +1,120 @@
package forge;
import java.io.File;
import java.util.List;
import java.util.Map;
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.util.storage.IStorage;
import forge.util.storage.StorageBase;
/**
* The class holding game invariants, such as cards, editions, game formats. All that data, which is not supposed to be changed by player
*
* @author Max
*/
public class StaticData {
private final CardDb commonCards;
private final CardDb variantCards;
private final EditionCollection editions;
private final FormatCollection formats;
private final IStorage<SealedProductTemplate> boosters;
private final IStorage<SealedProductTemplate> specialBoosters;
private final IStorage<SealedProductTemplate> tournaments;
private final IStorage<FatPackTemplate> fatPacks;
private final IStorage<PrintSheet> printSheets;
private static StaticData lastInstance = null;
public StaticData(ICardStorageReader reader, String editionFolder, String blockDataFolder) {
this.editions = new EditionCollection(new CardEdition.Reader(new File(editionFolder)));
lastInstance = this;
final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
synchronized (CardDb.class) {
List<CardRules> rules = reader.loadCards();
for (CardRules card : rules) {
if (null == card) continue;
final String cardName = card.getName();
if ( card.isVariant() )
variantsCards.put(cardName, card);
else
regularCards.put(cardName, card);
}
commonCards = new CardDb(regularCards, editions, false);
variantCards = new CardDb(variantsCards, editions, false);
}
this.formats = new FormatCollection(new GameFormat.Reader(new File(blockDataFolder, "formats.txt")));
this.boosters = new StorageBase<SealedProductTemplate>("Boosters", editions.getBoosterGenerator());
this.specialBoosters = new StorageBase<SealedProductTemplate>("Special boosters", new SealedProductTemplate.Reader(new File(blockDataFolder, "boosters-special.txt")));
this.tournaments = new StorageBase<SealedProductTemplate>("Starter sets", new SealedProductTemplate.Reader(new File(blockDataFolder, "starters.txt")));
this.fatPacks = new StorageBase<FatPackTemplate>("Fat packs", new FatPackTemplate.Reader("res/blockdata/fatpacks.txt"));
this.printSheets = new StorageBase<PrintSheet>("Special print runs", new PrintSheet.Reader(new File(blockDataFolder, "printsheets.txt")));
}
public final static StaticData instance() {
return lastInstance;
}
public final EditionCollection getEditions() {
return this.editions;
}
public final FormatCollection getFormats() {
return this.formats;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.FatPackTemplate}> */
public IStorage<FatPackTemplate> getFatPacks() {
return fatPacks;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
public final IStorage<SealedProductTemplate> getTournamentPacks() {
return tournaments;
}
/** @return {@link forge.util.storage.IStorageView}<{@link forge.card.BoosterTemplate}> */
public final IStorage<SealedProductTemplate> getBoosters() {
return boosters;
}
public final IStorage<SealedProductTemplate> getSpecialBoosters() {
return specialBoosters;
}
public IStorage<PrintSheet> getPrintSheets() {
return printSheets;
}
public CardDb getCommonCards() {
return commonCards;
}
public CardDb getVariantCards() {
return variantCards;
}
}

View File

@@ -0,0 +1,14 @@
package forge.card;
public class BoosterSlots {
public static final String LAND = "Land";
public static final String ANY = "Any";
public static final String COMMON = "Common";
public static final String UNCOMMON = "Uncommon";
public static final String UNCOMMON_RARE = "UncommonRare";
public static final String RARE = "Rare";
public static final String RARE_MYTHIC = "RareMythic";
public static final String MYTHIC = "Mythic";
public static final String BASIC_LAND = "BasicLand";
public static final String TIME_SHIFTED = "TimeShifted";
}

View File

@@ -36,49 +36,18 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import forge.Card;
import forge.card.CardEdition.Type;
import forge.item.PaperCard;
import forge.util.Aggregates;
import forge.util.CollectionSuppliers;
import forge.util.Lang;
import forge.util.MyRandom;
import forge.util.maps.CollectionSuppliers;
public final class CardDb implements ICardDatabase {
private static volatile CardDb commonCards = null; // 'volatile' keyword makes this working
private static volatile CardDb variantCards = null; // 'volatile' keyword makes this working
public final static String foilSuffix = "+";
private final static int foilSuffixLength = foilSuffix.length();
public static ICardDatabase instance() {
if (CardDb.commonCards == null) {
throw new NullPointerException("CardDb has not yet been initialized, run setup() first");
}
return CardDb.commonCards;
}
public static ICardDatabase variants() {
if (CardDb.variantCards == null) {
throw new NullPointerException("CardDb has not yet been initialized, run setup() first");
}
return CardDb.variantCards;
}
public static void setup(final Iterable<CardRules> rules, EditionCollection editions) {
if (CardDb.commonCards != null) {
throw new RuntimeException("CardDb has already been initialized, don't do it twice please");
}
synchronized (CardDb.class) {
if (CardDb.commonCards == null) { // It's broken under 1.4 and below, on 1.5+ works again!
CardSorter cs = new CardSorter(rules);
commonCards = new CardDb(cs.regularCards, editions, false);
variantCards = new CardDb(cs.variantsCards, editions, false);
}
}
}
// need this to obtain cardReference by name+set+artindex
private final Multimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
private final Multimap<String, PaperCard> allCardsByName = Multimaps.newListMultimap(new TreeMap<String,Collection<PaperCard>>(String.CASE_INSENSITIVE_ORDER), CollectionSuppliers.<PaperCard>arrayLists());
private final Map<String, PaperCard> uniqueCardsByName = new TreeMap<String, PaperCard>(String.CASE_INSENSITIVE_ORDER);
private final Map<String, CardRules> rulesByName;
@@ -86,37 +55,34 @@ public final class CardDb implements ICardDatabase {
private final List<PaperCard> roAllCards = Collections.unmodifiableList(allCards);
private final Collection<PaperCard> roUniqueCards = Collections.unmodifiableCollection(uniqueCardsByName.values());
private final EditionCollection editions;
private CardDb(Map<String, CardRules> rules, EditionCollection editions0, boolean logMissingCards) {
public CardDb(Map<String, CardRules> rules, EditionCollection editions0, boolean logMissingCards) {
this.rulesByName = rules;
this.editions = editions0;
List<String> missingCards = new ArrayList<String>();
for (CardEdition e : editions.getOrderedEditions()) {
boolean worthLogging = logMissingCards && ( e.getType() == Type.CORE || e.getType() == Type.EXPANSION || e.getType() == Type.REPRINT );
if (worthLogging) {
for(CardEdition e : editions.getOrderedEditions()) {
boolean worthLogging = logMissingCards && ( e.getType() == CardEdition.Type.CORE || e.getType() == CardEdition.Type.EXPANSION || e.getType() == CardEdition.Type.REPRINT );
if(worthLogging)
System.out.print(e.getName() + " (" + e.getCards().length + " cards)");
}
String lastCardName = null;
int artIdx = 0;
for (CardEdition.CardInSet cis : e.getCards()) {
if (cis.name.equals(lastCardName))
for(CardEdition.CardInSet cis : e.getCards()) {
if ( cis.name.equals(lastCardName) )
artIdx++;
else {
artIdx = 0;
lastCardName = cis.name;
}
CardRules cr = rulesByName.get(lastCardName);
if (cr != null) {
if( cr != null )
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx));
}
else if (worthLogging) {
else if (worthLogging)
missingCards.add(cis.name);
}
}
if (worthLogging) {
if (missingCards.isEmpty()) {
if(worthLogging) {
if(missingCards.isEmpty())
System.out.println(" ... 100% ");
}
else {
int missing = (e.getCards().length - missingCards.size()) * 10000 / e.getCards().length;
System.out.printf(" ... %.2f%% (%s missing: %s )%n", missing * 0.01f, Lang.nounWithAmount(missingCards.size(), "card"), StringUtils.join(missingCards, " | ") );
@@ -125,8 +91,9 @@ public final class CardDb implements ICardDatabase {
}
}
for (CardRules cr : rulesByName.values()) {
if (!allCardsByName.containsKey(cr.getName())) {
for(CardRules cr : rulesByName.values()) {
if( !allCardsByName.containsKey(cr.getName()) )
{
System.err.println("The card " + cr.getName() + " was not assigned to any set. Adding it to UNKNOWN set... to fix see res/cardeditions/ folder. ");
addCard(new PaperCard(cr, CardEdition.UNKNOWN.getCode(), CardRarity.Special, 0));
}
@@ -338,21 +305,6 @@ public final class CardDb implements ICardDatabase {
return result;
}
// Fetch from Forge's Card instance. Well, there should be no errors, but
// we'll still check
public static PaperCard getCard(final Card forgeCard) {
final String name = forgeCard.getName();
final String set = forgeCard.getCurSetCode();
if (StringUtils.isNotBlank(set)) {
PaperCard cp = variants().tryGetCard(name, set);
return cp == null ? instance().getCard(name, set) : cp;
}
PaperCard cp = variants().tryGetCard(name, true);
return cp == null ? instance().getCard(name) : cp;
}
// returns a list of all cards from their respective latest editions
@Override
public Collection<PaperCard> getUniqueCards() {
@@ -370,25 +322,6 @@ public final class CardDb implements ICardDatabase {
return Lists.newArrayList(Iterables.filter(this.roAllCards, predicate));
}
private static class CardSorter{
// Here are refs, get them by name
public final Map<String, CardRules> regularCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
public final Map<String, CardRules> variantsCards = new TreeMap<String, CardRules>(String.CASE_INSENSITIVE_ORDER);
CardSorter(final Iterable<CardRules> parser) {
for (CardRules card : parser) {
if (null == card) continue;
final String cardName = card.getName();
if ( card.isVariant() )
variantsCards.put(cardName, card);
else
regularCards.put(cardName, card);
}
}
}
public Predicate<? super PaperCard> wasPrintedInSets(List<String> setCodes) {
return new PredicateExistsInSets(setCodes);
}
@@ -403,7 +336,9 @@ public final class CardDb implements ICardDatabase {
@Override
public boolean apply(final PaperCard subject) {
Collection<PaperCard> cc = allCardsByName.get(subject.getName());
for(PaperCard c : cc) if (sets.contains(c.getEdition())) return true;
for(PaperCard c : cc)
if (sets.contains(c.getEdition()))
return true;
return false;
}
}

View File

@@ -29,14 +29,8 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.Constant;
import forge.Singletons;
import forge.game.GameFormat;
import forge.util.Aggregates;
import com.google.common.base.Function;
import forge.util.FileSection;
import forge.util.FileUtil;
import forge.util.storage.StorageReaderFolder;
@@ -204,76 +198,20 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
return whiteBorder;
}
/**
* The Class Predicates.
*/
public abstract static class Predicates {
/** The Constant canMakeBooster. */
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
private static class CanMakeBooster implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return subject.boosterTpl != null;
}
}
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
private static class CanMakeStarter implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getModel().getTournamentPacks().contains(subject.getCode());
}
}
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
private static class CanMakeFatPack implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getModel().getFatPacks().contains(subject.getCode());
}
}
/**
* Checks if is legal in format.
*
* @param format the format
* @return the predicate
*/
public static final Predicate<CardEdition> isLegalInFormat(final GameFormat format) {
return new LegalInFormat(format);
}
private static class LegalInFormat implements Predicate<CardEdition> {
private final GameFormat format;
public LegalInFormat(final GameFormat fmt) {
this.format = fmt;
}
@Override
public boolean apply(final CardEdition subject) {
return this.format.isSetLegal(subject.getCode());
}
}
public static final Predicate<CardEdition> hasBasicLands = new Predicate<CardEdition>() {
@Override
public boolean apply(CardEdition ed) {
for(String landName : Constant.Color.BASIC_LANDS) {
if (null == CardDb.instance().tryGetCard(landName, ed.getCode(), 0))
return false;
}
return true;
};
};
public int getCntBoosterPictures() {
return boosterArts;
}
public static class EditionReader extends StorageReaderFolder<CardEdition> {
public EditionReader(File path) {
public SealedProductTemplate getBoosterTemplate() {
return boosterTpl;
}
public boolean hasBoosterTemplate() {
return boosterTpl != null;
}
public static class Reader extends StorageReaderFolder<CardEdition> {
public Reader(File path) {
super(path, CardEdition.FN_GET_CODE);
}
@@ -360,16 +298,5 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
};
}
public final static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
return Aggregates.random(Iterables.filter(allEditions, CardEdition.Predicates.hasBasicLands));
}
public int getCntBoosterPictures() {
return boosterArts;
}
public SealedProductTemplate getBoosterTemplate() {
return boosterTpl;
}
}

View File

@@ -17,9 +17,7 @@
*/
package forge.card;
import java.io.File;
import java.util.List;
import forge.card.mana.ManaCost;
/**
@@ -30,19 +28,16 @@ import forge.card.mana.ManaCost;
* @version $Id: CardRules.java 9708 2011-08-09 19:34:12Z jendave $
*/
public final class CardRules implements ICardCharacteristics {
private CardSplitType splitType;
private ICardFace mainPart;
private ICardFace otherPart;
private final CardSplitType splitType;
private final ICardFace mainPart;
private final ICardFace otherPart;
//private final Map<String, CardInSet> setsPrinted = new TreeMap<String, CardInSet>(String.CASE_INSENSITIVE_ORDER);
private CardAiHints aiHints;
private ColorSet colorIdentity = null;
private File sourceFile;
public CardRules() {
}
public void setup(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
private ColorSet colorIdentity = null;
public CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
splitType = altMode;
mainPart = faces[0];
otherPart = faces[1];
@@ -68,15 +63,10 @@ public final class CardRules implements ICardCharacteristics {
colMask |= calculateColorIdentity(otherPart);
}
colorIdentity = ColorSet.fromMask(colMask);
//reset these
this.deltaHand = 0;
this.deltaLife = 0;
this.dlUrl = null;
this.dlUrlOtherSide = null;
}
private byte calculateColorIdentity(ICardFace face) {
private byte calculateColorIdentity(ICardFace face)
{
byte res = face.getColor().getColor();
boolean isReminder = false;
boolean isSymbol = false;
@@ -145,6 +135,7 @@ public final class CardRules implements ICardCharacteristics {
}
}
@Override
public ManaCost getManaCost() {
switch(splitType.getAggregationMethod()) {
@@ -225,14 +216,7 @@ public final class CardRules implements ICardCharacteristics {
}
public ColorSet getColorIdentity() {
return this.colorIdentity;
}
public File getSourceFile() {
return this.sourceFile;
}
public void setSourceFile(File sourceFile0) {
this.sourceFile = sourceFile0;
return colorIdentity;
}
}

View File

@@ -24,8 +24,6 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import forge.Constant;
/**
* <p>
* Immutable Card type. Can be build only from parsing a string.
@@ -236,6 +234,47 @@ public final class CardType implements Comparable<CardType> {
return this.coreType.contains(CardCoreType.Phenomenon);
}
/**
* The Interface CardTypes.
*/
public static class Constant {
/** The loaded. */
public static final boolean[] LOADED = { false };
/** The card types. */
public static final List<String> CARD_TYPES = new ArrayList<String>();
/** The super types. */
public static final List<String> SUPER_TYPES = new ArrayList<String>();
/** The basic types. */
public static final List<String> BASIC_TYPES = new ArrayList<String>();
/** The land types. */
public static final List<String> LAND_TYPES = new ArrayList<String>();
/** The creature types. */
public static final List<String> CREATURE_TYPES = new ArrayList<String>();
/** The instant types. */
public static final List<String> INSTANT_TYPES = new ArrayList<String>();
/** The sorcery types. */
public static final List<String> SORCERY_TYPES = new ArrayList<String>();
/** The enchantment types. */
public static final List<String> ENCHANTMENT_TYPES = new ArrayList<String>();
/** The artifact types. */
public static final List<String> ARTIFACT_TYPES = new ArrayList<String>();
/** The walker types. */
public static final List<String> WALKER_TYPES = new ArrayList<String>();
}
///////// Utility methods
public static boolean isACardType(final String cardType) {
return CardType.getAllCardTypes().contains(cardType);
@@ -245,7 +284,7 @@ public final class CardType implements Comparable<CardType> {
final ArrayList<String> types = new ArrayList<String>();
// types.addAll(getCardTypes());
types.addAll(Constant.CardTypes.CARD_TYPES);
types.addAll(Constant.CARD_TYPES);
// not currently used by Forge
types.add("Plane");
@@ -258,7 +297,7 @@ public final class CardType implements Comparable<CardType> {
public static ArrayList<String> getBasicTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.BASIC_TYPES);
types.addAll(Constant.BASIC_TYPES);
return types;
}
@@ -266,8 +305,8 @@ public final class CardType implements Comparable<CardType> {
public static ArrayList<String> getLandTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.BASIC_TYPES);
types.addAll(Constant.CardTypes.LAND_TYPES);
types.addAll(Constant.BASIC_TYPES);
types.addAll(Constant.LAND_TYPES);
return types;
}
@@ -275,13 +314,13 @@ public final class CardType implements Comparable<CardType> {
public static ArrayList<String> getCreatureTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.CREATURE_TYPES);
types.addAll(Constant.CREATURE_TYPES);
return types;
}
public static boolean isASuperType(final String cardType) {
return (Constant.CardTypes.SUPER_TYPES.contains(cardType));
return (Constant.SUPER_TYPES.contains(cardType));
}
public static boolean isASubType(final String cardType) {
@@ -289,18 +328,18 @@ public final class CardType implements Comparable<CardType> {
}
public static boolean isACreatureType(final String cardType) {
return (Constant.CardTypes.CREATURE_TYPES.contains(cardType));
return (Constant.CREATURE_TYPES.contains(cardType));
}
public static boolean isALandType(final String cardType) {
return (Constant.CardTypes.LAND_TYPES.contains(cardType));
return (Constant.LAND_TYPES.contains(cardType));
}
public static boolean isAPlaneswalkerType(final String cardType) {
return (Constant.CardTypes.WALKER_TYPES.contains(cardType));
return (Constant.WALKER_TYPES.contains(cardType));
}
public static boolean isABasicLandType(final String cardType) {
return (Constant.CardTypes.BASIC_TYPES.contains(cardType));
return (Constant.BASIC_TYPES.contains(cardType));
}
}

View File

@@ -17,7 +17,6 @@
*/
package forge.card;
import forge.Constant;
import forge.card.mana.ManaCost;
import forge.util.BinaryUtil;
@@ -253,7 +252,7 @@ public final class ColorSet implements Comparable<ColorSet> {
return "n/a";
}
String toReturn = MagicColor.toLongString(myColor);
if (toReturn == Constant.Color.COLORLESS && myColor != 0) {
if (toReturn == MagicColor.Constant.COLORLESS && myColor != 0) {
return "multi";
}
return toReturn;

View File

@@ -17,7 +17,6 @@
*/
package forge.card;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -34,8 +33,8 @@ public final class EditionCollection extends StorageBase<CardEdition> {
private final Map<String, CardEdition> aliasToEdition = new TreeMap<String, CardEdition>(String.CASE_INSENSITIVE_ORDER);
public EditionCollection(File folder) {
super("Card editions", new CardEdition.EditionReader(folder));
public EditionCollection(IItemReader<CardEdition> reader) {
super("Card editions", reader);
for (CardEdition ee : this) {
String alias = ee.getAlias();

View File

@@ -17,12 +17,8 @@
*/
package forge.card;
import java.util.Arrays;
import java.util.List;
import forge.game.GameFormat;
import forge.util.FileSection;
import forge.util.storage.StorageReaderFileSections;
import forge.util.storage.StorageReaderBase;
import forge.util.storage.StorageBase;
/**
@@ -36,8 +32,8 @@ public final class FormatCollection extends StorageBase<GameFormat> {
* TODO: Write javadoc for Constructor.
* @param io
*/
public FormatCollection(String filename) {
super("Format collections", new FormatReader(filename));
public FormatCollection(StorageReaderBase<GameFormat> reader) {
super("Format collections", reader);
}
/**
@@ -75,32 +71,6 @@ public final class FormatCollection extends StorageBase<GameFormat> {
return this.map.get(format);
}
/**
* Instantiates a new format utils.
*/
public static class FormatReader extends StorageReaderFileSections<GameFormat> {
public FormatReader(String file0) {
super(file0, GameFormat.FN_GET_NAME);
}
@Override
protected GameFormat read(String title, Iterable<String> body, int idx) {
List<String> sets = null; // default: all sets allowed
List<String> bannedCards = null; // default: nothing banned
FileSection section = FileSection.parse(body, ":");
String strSets = section.get("sets");
if ( null != strSets ) {
sets = Arrays.asList(strSets.split(", "));
}
String strCars = section.get("banned");
if ( strCars != null ) {
bannedCards = Arrays.asList(strCars.split("; "));
}
return new GameFormat(title, sets, bannedCards, 1 + idx);
}
}
}
/**

View File

@@ -1,6 +1,8 @@
package forge.card;
import forge.Constant;
import java.util.List;
import com.google.common.collect.ImmutableList;
/**
* Holds byte values for each color magic has.
@@ -22,31 +24,31 @@ public class MagicColor {
public static byte fromName(String s) {
if( s == null ) return 0;
if (s.equalsIgnoreCase(Constant.Color.WHITE) || s.equalsIgnoreCase("w")) {
if (s.equalsIgnoreCase(Constant.WHITE) || s.equalsIgnoreCase("w")) {
return MagicColor.WHITE;
}
if (s.equalsIgnoreCase(Constant.Color.BLUE) || s.equalsIgnoreCase("u")) {
if (s.equalsIgnoreCase(Constant.BLUE) || s.equalsIgnoreCase("u")) {
return MagicColor.BLUE;
}
if (s.equalsIgnoreCase(Constant.Color.BLACK) || s.equalsIgnoreCase("b")) {
if (s.equalsIgnoreCase(Constant.BLACK) || s.equalsIgnoreCase("b")) {
return MagicColor.BLACK;
}
if (s.equalsIgnoreCase(Constant.Color.RED) || s.equalsIgnoreCase("r")) {
if (s.equalsIgnoreCase(Constant.RED) || s.equalsIgnoreCase("r")) {
return MagicColor.RED;
}
if (s.equalsIgnoreCase(Constant.Color.GREEN) || s.equalsIgnoreCase("g")) {
if (s.equalsIgnoreCase(Constant.GREEN) || s.equalsIgnoreCase("g")) {
return MagicColor.GREEN;
}
return 0; // colorless
}
public static String toShortString(String color) {
if (color.equalsIgnoreCase(Constant.Color.SNOW)) return "S"; // compatibility
if (color.equalsIgnoreCase(Constant.SNOW)) return "S"; // compatibility
return toShortString(fromName(color));
}
public static String toLongString(String color) {
if (color.equalsIgnoreCase("s")) return Constant.Color.SNOW; // compatibility
if (color.equalsIgnoreCase("s")) return Constant.SNOW; // compatibility
return toLongString(fromName(color));
}
@@ -63,12 +65,47 @@ public class MagicColor {
public static String toLongString(byte color) {
switch(color){
case GREEN: return Constant.Color.GREEN ;
case RED: return Constant.Color.RED;
case BLUE: return Constant.Color.BLUE;
case BLACK: return Constant.Color.BLACK;
case WHITE: return Constant.Color.WHITE;
default: return Constant.Color.COLORLESS;
case GREEN: return Constant.GREEN ;
case RED: return Constant.RED;
case BLUE: return Constant.BLUE;
case BLACK: return Constant.BLACK;
case WHITE: return Constant.WHITE;
default: return Constant.COLORLESS;
}
}
/**
* The Interface Color.
*/
public static class Constant {
/** The Black. */
public static final String BLACK = "black";
/** The Blue. */
public static final String BLUE = "blue";
/** The Green. */
public static final String GREEN = "green";
/** The Red. */
public static final String RED = "red";
/** The White. */
public static final String WHITE = "white";
/** The Colorless. */
public static final String COLORLESS = "colorless";
// color order "wubrg"
/** The only colors. */
public static final ImmutableList<String> ONLY_COLORS = ImmutableList.of(WHITE, BLUE, BLACK, RED, GREEN);
/** The Snow. */
public static final String SNOW = "snow";
/** The Basic lands. */
public static final List<String> BASIC_LANDS = ImmutableList.of("Plains", "Island", "Swamp", "Mountain", "Forest");
public static final List<String> SNOW_LANDS = ImmutableList.of("Snow-Covered Plains", "Snow-Covered Island", "Snow-Covered Swamp", "Snow-Covered Mountain", "Snow-Covered Forest");
}
}

View File

@@ -1,5 +1,6 @@
package forge.item;
package forge.card;
import java.io.File;
import java.util.List;
import java.util.Map.Entry;
import java.util.ArrayList;
@@ -7,7 +8,9 @@ import java.util.Collection;
import com.google.common.base.Function;
import forge.util.ItemPool;
import forge.deck.CardPool;
import forge.item.PaperCard;
import forge.util.MyRandom;
import forge.util.storage.StorageReaderFileSections;
@@ -30,7 +33,7 @@ public class PrintSheet {
this(name0, null);
}
private PrintSheet(String name0, ItemPool<PaperCard> pool) {
public PrintSheet(String name0, ItemPool<PaperCard> pool) {
name = name0;
cardsWithWeights = pool != null ? pool : new ItemPool<PaperCard>(PaperCard.class);
}
@@ -105,18 +108,6 @@ public class PrintSheet {
return result;
}
public static class Reader extends StorageReaderFileSections<PrintSheet> {
public Reader(String fileName) {
super(fileName, PrintSheet.FN_GET_KEY);
}
@Override
protected PrintSheet read(String title, Iterable<String> body, int idx) {
return new PrintSheet(title, CardPool.fromCardList(body));
}
}
public boolean isEmpty() {
return cardsWithWeights.isEmpty();
}
@@ -125,5 +116,16 @@ public class PrintSheet {
return cardsWithWeights.toFlatList();
}
public static class Reader extends StorageReaderFileSections<PrintSheet> {
public Reader(File file) {
super(file, PrintSheet.FN_GET_KEY);
}
@Override
protected PrintSheet read(String title, Iterable<String> body, int idx) {
return new PrintSheet(title, CardPool.fromCardList(body));
}
}
}

View File

@@ -18,6 +18,7 @@
package forge.card;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -30,12 +31,13 @@ import com.google.common.collect.Lists;
import forge.util.TextUtil;
import forge.util.storage.StorageReaderFile;
public class SealedProductTemplate {
@SuppressWarnings("unchecked")
public final static SealedProductTemplate genericBooster = new SealedProductTemplate(null, Lists.newArrayList(
Pair.of(BoosterGenerator.COMMON, 10), Pair.of(BoosterGenerator.UNCOMMON, 3),
Pair.of(BoosterGenerator.RARE_MYTHIC, 1), Pair.of(BoosterGenerator.BASIC_LAND, 1)
Pair.of(BoosterSlots.COMMON, 10), Pair.of(BoosterSlots.UNCOMMON, 3),
Pair.of(BoosterSlots.RARE_MYTHIC, 1), Pair.of(BoosterSlots.BASIC_LAND, 1)
));
@@ -61,6 +63,10 @@ public class SealedProductTemplate {
name = name0;
}
public SealedProductTemplate(String code, String boosterDesc) {
this(code, Reader.parseSlots(boosterDesc));
}
public int getNumberOfCardsExpected() {
int sum = 0;
for(Pair<String, Integer> p : slots) {
@@ -69,7 +75,7 @@ public class SealedProductTemplate {
return sum;
}
protected static final Function<? super SealedProductTemplate, String> FN_GET_NAME = new Function<SealedProductTemplate, String>() {
public static final Function<? super SealedProductTemplate, String> FN_GET_NAME = new Function<SealedProductTemplate, String>() {
@Override
public String apply(SealedProductTemplate arg1) {
return arg1.name;
@@ -98,9 +104,9 @@ public class SealedProductTemplate {
return s.toString();
}
public static final class Reader extends StorageReaderFile<SealedProductTemplate> {
public Reader(String pathname) {
super(pathname, SealedProductTemplate.FN_GET_NAME);
public final static class Reader extends StorageReaderFile<SealedProductTemplate> {
public Reader(File file) {
super(file, SealedProductTemplate.FN_GET_NAME);
}
public static List<Pair<String, Integer>> parseSlots(String data) {
@@ -118,5 +124,5 @@ public class SealedProductTemplate {
String[] headAndData = TextUtil.split(line, ':', 2);
return new SealedProductTemplate(headAndData[0], parseSlots(headAndData[1]));
}
}
}
}

View File

@@ -18,7 +18,6 @@
package forge.deck;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -26,10 +25,9 @@ import java.util.NoSuchElementException;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.card.CardDb;
import forge.StaticData;
import forge.item.PaperCard;
import forge.item.ItemPool;
import forge.util.ItemPool;
/**
* Deck section.
@@ -54,15 +52,6 @@ public class CardPool extends ItemPool<PaperCard> {
this.addAll(cards);
}
/**
* Adds the.
*
* @param card
* the card
*/
public void add(final Card card) {
this.add(CardDb.getCard(card));
}
/**
* Adds the.
@@ -84,9 +73,9 @@ public class CardPool extends ItemPool<PaperCard> {
* @param amount the amount
*/
public void add(final String cardName, final String setCode, final int amount) {
PaperCard cp = CardDb.instance().tryGetCard(cardName, setCode);
PaperCard cp = StaticData.instance().getCommonCards().tryGetCard(cardName, setCode);
if ( cp == null )
cp = CardDb.variants().tryGetCard(cardName, setCode);
cp = StaticData.instance().getVariantCards().tryGetCard(cardName, setCode);
if ( cp != null)
this.add(cp, amount);
@@ -94,18 +83,6 @@ public class CardPool extends ItemPool<PaperCard> {
throw new RuntimeException(String.format("Card %s from %s is not supported by Forge, as it's neither a known common card nor one of casual variants' card.", cardName, setCode ));
}
/**
* Adds the.
*
* @param cardList
* the card list
*/
public void add(final List<Card> cardList) {
for (final Card c : cardList) {
this.add(c);
}
}
/**
* Add all from a List of CardPrinted.
*
@@ -124,9 +101,9 @@ public class CardPool extends ItemPool<PaperCard> {
* @param cardName the card name
*/
public void add(final String cardName, int cnt) {
PaperCard cp = CardDb.instance().tryGetCard(cardName);
PaperCard cp = StaticData.instance().getCommonCards().tryGetCard(cardName);
if ( cp == null )
cp = CardDb.variants().tryGetCard(cardName);
cp = StaticData.instance().getVariantCards().tryGetCard(cardName);
if ( cp != null)
this.add(cp, cnt);

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Max
*
*/
package forge.deck;

View File

@@ -17,7 +17,9 @@
*/
package forge.game;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -26,9 +28,11 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import forge.card.CardDb;
import forge.StaticData;
import forge.item.PaperCard;
import forge.item.IPaperCard;
import forge.util.FileSection;
import forge.util.storage.StorageReaderFileSections;
/**
@@ -90,7 +94,7 @@ public class GameFormat implements Comparable<GameFormat> {
if (this.allowedSetCodes == null || this.allowedSetCodes.isEmpty()) {
return banNames;
}
return Predicates.and(banNames, CardDb.instance().wasPrintedInSets(this.allowedSetCodes));
return Predicates.and(banNames, StaticData.instance().getCommonCards().wasPrintedInSets(this.allowedSetCodes));
}
/**
@@ -182,4 +186,30 @@ public class GameFormat implements Comparable<GameFormat> {
return index;
}
/**
* Instantiates a new format utils.
*/
public static class Reader extends StorageReaderFileSections<GameFormat> {
public Reader(File file0) {
super(file0, GameFormat.FN_GET_NAME);
}
@Override
protected GameFormat read(String title, Iterable<String> body, int idx) {
List<String> sets = null; // default: all sets allowed
List<String> bannedCards = null; // default: nothing banned
FileSection section = FileSection.parse(body, ":");
String strSets = section.get("sets");
if ( null != strSets ) {
sets = Arrays.asList(strSets.split(", "));
}
String strCars = section.get("banned");
if ( strCars != null ) {
bannedCards = Arrays.asList(strCars.split("; "));
}
return new GameFormat(title, sets, bannedCards, 1 + idx);
}
}
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Max
*
*/
package forge.game;

View File

@@ -19,10 +19,8 @@ package forge.item;
import com.google.common.base.Function;
import forge.Card;
import forge.card.CardRarity;
import forge.card.CardRules;
import forge.card.CardRulesReader;
/**
@@ -36,10 +34,10 @@ import forge.card.CardRulesReader;
*/
public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFromSet, IPaperCard {
// Reference to rules
private final transient CardRules rules;
private final transient CardRules card;
// These fields are kinda PK for PrintedCard
public String name;
public final String name;
public final String edition;
public final int artIndex;
public final boolean foil;
@@ -74,7 +72,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
@Override
public CardRules getRules() {
return this.rules;
return this.card;
}
@Override
@@ -82,11 +80,15 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
return this.rarity;
}
// @Override
// public String getImageKey() {
// return getImageLocator(getImageName(), getArtIndex(), true, false);
// }
@Override
public String getItemType() {
return "Card";
@@ -98,7 +100,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
public static final Function<PaperCard, CardRules> FN_GET_RULES = new Function<PaperCard, CardRules>() {
@Override
public CardRules apply(final PaperCard from) {
return from.rules;
return from.card;
}
};
public static final Function<PaperCard, String> FN_GET_NAME = new Function<PaperCard, String>() {
@@ -108,20 +110,19 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
}
};
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0) {
this(rules0, edition0, rarity0, artIndex0, false);
public PaperCard(final CardRules c, final String edition0, final CardRarity rare, final int index) {
this(c, edition0, rare, index, false);
}
public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0, final boolean foil0) {
if (edition0 == null || rules0 == null || rarity0 == null) {
public PaperCard(final CardRules c, final String edition0, final CardRarity rare, final int index, final boolean foil) {
if ( edition0 == null || c == null || rare == null )
throw new IllegalArgumentException("Cannot create card without rules, edition or rarity");
}
this.rules = rules0;
this.name = rules0.getName();
this.card = c;
this.name = c.getName();
this.edition = edition0;
this.rarity = rarity0;
this.artIndex = artIndex0;
this.foil = foil0;
this.artIndex = index;
this.foil = foil;
this.rarity = rare;
}
// Want this class to be a key for HashTable
@@ -192,10 +193,4 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
// TODO compare sets properly
return this.edition.compareTo(o.getEdition());
}
public void updateRules(String script) {
CardRulesReader.updateCardRules(this.rules, script);
this.name = this.rules.getName();
Card.updateCard(this);
}
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Max
*
*/
package forge.item;

View File

@@ -1,4 +1,4 @@
package forge.util.maps;
package forge.util;
import java.util.ArrayList;
import java.util.HashSet;

View File

@@ -31,8 +31,6 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import forge.error.BugReporter;
/**
* <p>
* FileUtil class.
@@ -109,28 +107,20 @@ public final class FileUtil {
}
p.close();
} catch (final Exception ex) {
BugReporter.reportException(ex);
throw new RuntimeException("FileUtil : writeFile() error, problem writing file - " + file + " : " + ex);
}
} // writeAllDecks()
public static String readFileToString(String filename) {
return readFileToString(new File(filename));
}
public static String readFileToString(File file) {
StringBuilder s = new StringBuilder();
for (String line : readFile(file)) {
if (s.length() > 0) {
s.append('\n');
}
s.append(line);
for (String line : readFile(filename)) {
s.append(line).append('\n');
}
return s.toString();
}
public static List<String> readFile(final String filename) {
return readFile(new File(filename));
return FileUtil.readFile(new File(filename));
}
// reads line by line and adds each line to the ArrayList
@@ -152,7 +142,6 @@ public final class FileUtil {
}
return FileUtil.readAllLines(new FileReader(file), false);
} catch (final Exception ex) {
BugReporter.reportException(ex);
throw new RuntimeException("FileUtil : readFile() error, " + ex);
}
} // readFile()
@@ -187,7 +176,6 @@ public final class FileUtil {
}
in.close();
} catch (final IOException ex) {
BugReporter.reportException(ex);
throw new RuntimeException("FileUtil : readAllLines() error, " + ex);
}
return list;

View File

@@ -15,11 +15,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
package forge.util;
import java.util.Collections;
import java.util.Map.Entry;
import forge.item.InventoryItem;
/**
* <p>
* ItemPool class.

View File

@@ -15,13 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
package forge.util;
import java.util.Comparator;
import java.util.Map.Entry;
import com.google.common.base.Function;
import forge.item.PaperCard;
/**
* <p>

View File

@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
package forge.util;
import java.util.ArrayList;
import java.util.Hashtable;
@@ -27,6 +27,8 @@ import java.util.Map.Entry;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import forge.item.InventoryItem;
/**
* <p>

View File

@@ -21,8 +21,6 @@ import java.io.File;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
@@ -76,10 +74,8 @@ public abstract class StorageReaderFile<T> extends StorageReaderBase<T> {
final T item = this.read(s, idx);
if (null == item) {
final String msg = "An object stored in " + this.file.getPath()
+ " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), msg);
continue;
final String msg = "An object stored in " + this.file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
throw new RuntimeException(msg);
}
idx++;

View File

@@ -23,8 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
@@ -104,8 +102,7 @@ public abstract class StorageReaderFileSections<T> extends StorageReaderBase<T>
if (null != item) return item;
final String msg = "An object stored in " + this.file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file attached.";
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), msg);
return null;
throw new RuntimeException(msg);
}
/**

View File

@@ -28,15 +28,8 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Function;
import forge.deck.io.OldDeckFileFormatException;
import forge.error.BugReporter;
/**
* This class treats every file in the given folder as a source for a named
* object. The descendant should implement read method to deserialize a single
@@ -67,7 +60,7 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
this.directory = deckDir0;
if (this.directory == null) {
throw new IllegalArgumentException("No deck directory specified");
throw new IllegalArgumentException("No directory specified");
}
try {
if (this.directory.isFile()) {
@@ -79,55 +72,37 @@ public abstract class StorageReaderFolder<T> extends StorageReaderBase<T> {
}
}
} catch (final IOException ex) {
BugReporter.reportException(ex);
throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage());
throw new RuntimeException("StorageReaderFolder.ctor() error, " + ex.getMessage());
}
}
public final List<String> objectsThatFailedToLoad = new ArrayList<String>();
/* (non-Javadoc)
* @see forge.util.IItemReader#readAll()
*/
@Override
public Map<String, T> readAll() {
final Map<String, T> result = new TreeMap<String, T>();
final List<String> decksThatFailedToLoad = new ArrayList<String>();
final File[] files = this.directory.listFiles(this.getFileFilter());
boolean hasWarnedOfOldFormat = false;
for (final File file : files) {
try {
final T newDeck = this.read(file);
if (null == newDeck) {
final String msg = "An object stored in "
+ file.getPath()
+ " failed to load.\nPlease submit this as a bug with the mentioned file/directory attached.";
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), msg);
continue;
final String msg = "An object stored in " + file.getPath() + " failed to load.\nPlease submit this as a bug with the mentioned file/directory attached.";
throw new RuntimeException(msg);
}
String newKey = keySelector.apply(newDeck);
if( result.containsKey(newKey))
System.err.println("StorageReader: Overwriting an object with key " + newKey);
result.put(newKey, newDeck);
} catch (final OldDeckFileFormatException ex) {
if (!hasWarnedOfOldFormat) {
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
"Found a deck in old fileformat in the storage.\nMoving this file and all similiar ones to parent folder.\n\nForge will try to convert them in a second.");
hasWarnedOfOldFormat = true;
}
file.renameTo(new File(this.directory.getParentFile(), file.getName()));
} catch (final NoSuchElementException ex) {
final String message = String.format("%s failed to load because ---- %s", file.getName(),
ex.getMessage());
decksThatFailedToLoad.add(message);
final String message = String.format("%s failed to load because ---- %s", file.getName(), ex.getMessage());
objectsThatFailedToLoad.add(message);
}
}
if (!decksThatFailedToLoad.isEmpty()) {
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
StringUtils.join(decksThatFailedToLoad, System.getProperty("line.separator")),
"Some of your objects were not loaded.", JOptionPane.WARNING_MESSAGE);
}
return result;
}

View File

@@ -0,0 +1,8 @@
/**
*
*/
/**
* @author Max
*
*/
package forge.util.storage;

View File

@@ -44,7 +44,6 @@ import com.google.common.collect.Lists;
import forge.CardPredicates.Presets;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardRarity;
import forge.card.CardRules;
@@ -7743,7 +7742,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a {@link java.lang.String} object.
*/
public final String getMostRecentSet() {
return CardDb.instance().getCard(this.getName()).getEdition();
return Singletons.getMagicDb().getCommonCards().getCard(this.getName()).getEdition();
}
public final void setImageKey(final String iFN) {
@@ -7892,8 +7891,8 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
public final void setRandomFoil() {
CardEdition.FoilType foilType = CardEdition.FoilType.NOT_SUPPORTED;
if (this.getCurSetCode() != null && Singletons.getModel().getEditions().get(this.getCurSetCode()) != null) {
foilType = Singletons.getModel().getEditions().get(this.getCurSetCode()).getFoilType();
if (this.getCurSetCode() != null && Singletons.getMagicDb().getEditions().get(this.getCurSetCode()) != null) {
foilType = Singletons.getMagicDb().getEditions().get(this.getCurSetCode()).getFoilType();
}
if (foilType != CardEdition.FoilType.NOT_SUPPORTED) {
this.setFoil(foilType == CardEdition.FoilType.MODERN ? MyRandom.getRandom().nextInt(9) + 1 : MyRandom.getRandom().nextInt(9) + 11);
@@ -8711,6 +8710,20 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return fromPaperCard(pc, null);
}
// Fetch from Forge's Card instance. Well, there should be no errors, but
// we'll still check
public PaperCard getPaperCard() {
final String name = getName();
final String set = getCurSetCode();
if (StringUtils.isNotBlank(set)) {
PaperCard cp = Singletons.getMagicDb().getVariantCards().tryGetCard(name, set);
return cp == null ? Singletons.getMagicDb().getCommonCards().getCard(name, set) : cp;
}
PaperCard cp = Singletons.getMagicDb().getVariantCards().tryGetCard(name, true);
return cp == null ? Singletons.getMagicDb().getCommonCards().getCard(name) : cp;
}
/**
* Update Card instance for the given PaperCard if any

View File

@@ -253,7 +253,7 @@ public final class CardUtil {
if (reflectProperty.equals("Is")) { // Meteor Crater
for (final Card card1 : cards) {
// For each card, go through all the colors and if the card is that color, add
for (final String col : Constant.Color.ONLY_COLORS) {
for (final String col : MagicColor.Constant.ONLY_COLORS) {
if (card1.isOfColor(col)) {
colors.add(col);
if (colors.size() == maxChoices) {
@@ -265,14 +265,14 @@ public final class CardUtil {
} else if (reflectProperty.equals("Produced")) {
// Why is this name so similar to the one below?
final String producedColors = abMana instanceof AbilitySub ? (String) abMana.getRootAbility().getTriggeringObject("Produced") : (String) abMana.getTriggeringObject("Produced");
for (final String col : Constant.Color.ONLY_COLORS) {
for (final String col : MagicColor.Constant.ONLY_COLORS) {
final String s = MagicColor.toShortString(col);
if (producedColors.contains(s)) {
colors.add(col);
}
}
if (maxChoices == 6 && producedColors.contains("1")) {
colors.add(Constant.Color.COLORLESS);
colors.add(MagicColor.Constant.COLORLESS);
}
} else if (reflectProperty.equals("Produce")) {
final List<SpellAbility> abilities = new ArrayList<SpellAbility>();
@@ -315,7 +315,7 @@ public final class CardUtil {
public static Set<String> canProduce(final int maxChoices, final AbilityManaPart ab,
final Set<String> colors) {
for (final String col : Constant.Color.ONLY_COLORS) {
for (final String col : MagicColor.Constant.ONLY_COLORS) {
final String s = MagicColor.toShortString(col);
if (ab.canProduce(s)) {
colors.add(col);
@@ -323,7 +323,7 @@ public final class CardUtil {
}
if (maxChoices == 6 && ab.canProduce("1")) {
colors.add(Constant.Color.COLORLESS);
colors.add(MagicColor.Constant.COLORLESS);
}
return colors;

View File

@@ -32,7 +32,6 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.google.common.cache.LoadingCache;
import com.mortennobel.imagescaling.ResampleOp;
import forge.card.CardDb;
import forge.card.CardRules;
import forge.card.CardSplitType;
import forge.game.player.IHasIcon;
@@ -237,7 +236,7 @@ public class ImageCache {
return ImageCache.TOURNAMENTPACK_PREFIX + ((TournamentPack)ii).getEdition();
if ( ii instanceof BoosterPack ) {
BoosterPack bp = (BoosterPack)ii;
int cntPics = Singletons.getModel().getEditions().get(bp.getEdition()).getCntBoosterPictures();
int cntPics = Singletons.getMagicDb().getEditions().get(bp.getEdition()).getCntBoosterPictures();
String suffix = (1 >= cntPics) ? "" : ("_" + bp.getArtIndex());
return ImageCache.BOOSTER_PREFIX + bp.getEdition() + suffix;
}
@@ -264,7 +263,7 @@ public class ImageCache {
final int cntPictures;
final boolean hasManyPictures;
if (includeSet) {
cntPictures = !card.isVariant() ? CardDb.instance().getPrintCount(card.getName(), edition) : CardDb.variants().getPrintCount(card.getName(), edition);
cntPictures = !card.isVariant() ? Singletons.getMagicDb().getCommonCards().getPrintCount(card.getName(), edition) : Singletons.getMagicDb().getVariantCards().getPrintCount(card.getName(), edition);
hasManyPictures = cntPictures > 1;
} else {
// without set number of pictures equals number of urls provided in Svar:Picture
@@ -272,7 +271,7 @@ public class ImageCache {
cntPictures = StringUtils.countMatches(urls, "\\") + 1;
// raise the art index limit to the maximum of the sets this card was printed in
int maxCntPictures = !card.isVariant() ? CardDb.instance().getMaxPrintCount(card.getName()) : CardDb.variants().getMaxPrintCount(card.getName());
int maxCntPictures = !card.isVariant() ? Singletons.getMagicDb().getCommonCards().getMaxPrintCount(card.getName()) : Singletons.getMagicDb().getVariantCards().getMaxPrintCount(card.getName());
hasManyPictures = maxCntPictures > 1;
}
@@ -297,7 +296,7 @@ public class ImageCache {
}
if (includeSet) {
String editionAliased = isDownloadUrl ? Singletons.getModel().getEditions().getCode2ByCode(edition) : getSetFolder(edition);
String editionAliased = isDownloadUrl ? Singletons.getMagicDb().getEditions().getCode2ByCode(edition) : getSetFolder(edition);
return String.format("%s/%s", editionAliased, fname);
} else {
return fname;
@@ -311,7 +310,7 @@ public class ImageCache {
public static String getSetFolder(String edition) {
return !NewConstants.CACHE_CARD_PICS_SUBDIR.containsKey(edition)
? Singletons.getModel().getEditions().getCode2ByCode(edition) // by default 2-letter codes from MWS are used
? Singletons.getMagicDb().getEditions().getCode2ByCode(edition) // by default 2-letter codes from MWS are used
: NewConstants.CACHE_CARD_PICS_SUBDIR.get(edition); // may use custom paths though
}

View File

@@ -17,8 +17,10 @@
*/
package forge;
import forge.card.cardfactory.CardStorageReader;
import forge.control.FControl;
import forge.model.FModel;
import forge.properties.NewConstants;
import forge.view.FView;
/**
@@ -28,6 +30,7 @@ public final class Singletons {
private static FModel model = null;
private static FView view = null;
private static FControl control = null;
private static StaticData magicDb = null;
/**
* IMPORTANT - does not return view frame! Must call
@@ -36,11 +39,23 @@ public final class Singletons {
public static FView getView() { return view; }
public static FControl getControl() { return control; }
public static FModel getModel() { return model; }
public static StaticData getMagicDb() { return magicDb; }
public static void setModel (FModel model0) { model = model0; }
public static void setView (FView view0) { view = view0; }
public static void setControl(FControl control0) { control = control0; }
public static void initializeOnce(boolean withUi) {
if(withUi)
view = FView.SINGLETON_INSTANCE;
// Loads all cards (using progress bar).
FThreads.assertExecutedByEdt(false);
final CardStorageReader reader = new CardStorageReader(NewConstants.CARD_DATA_DIR, true, withUi ? view.getSplash().getProgressBar() : null);
magicDb = new StaticData(reader, "res/editions", "res/blockdata");
model = FModel.getInstance(withUi);
if(withUi)
control = FControl.instance;
}
// disallow instantiation
private Singletons() { }
}

View File

@@ -37,7 +37,6 @@ import com.google.common.collect.Lists;
import forge.Singletons;
import forge.item.PaperCard;
import forge.item.IPaperCard;
import forge.item.PrintSheet;
import forge.util.TextUtil;
/**
@@ -50,22 +49,11 @@ import forge.util.TextUtil;
*/
public class BoosterGenerator {
private static final String LAND = "Land";
public static final String ANY = "Any";
public static final String COMMON = "Common";
public static final String UNCOMMON = "Uncommon";
public static final String UNCOMMON_RARE = "UncommonRare";
public static final String RARE = "Rare";
public static final String RARE_MYTHIC = "RareMythic";
public static final String MYTHIC = "Mythic";
public static final String BASIC_LAND = "BasicLand";
public static final String TIME_SHIFTED = "TimeShifted";
private final static Map<String, PrintSheet> cachedSheets = new TreeMap<String, PrintSheet>(String.CASE_INSENSITIVE_ORDER);
private static final synchronized PrintSheet getPrintSheet(String key) {
if( !cachedSheets.containsKey(key) )
cachedSheets.put(key, makeSheet(key, CardDb.instance().getAllCards()));
cachedSheets.put(key, makeSheet(key, Singletons.getMagicDb().getCommonCards().getAllCards()));
return cachedSheets.get(key);
}
@@ -77,7 +65,7 @@ public class BoosterGenerator {
String[] sType = TextUtil.splitWithParenthesis(slotType, ' ');
String setCode = sType.length == 1 && booster.getEdition() != null ? booster.getEdition() : null;
String sheetKey = Singletons.getModel().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim();
String sheetKey = Singletons.getMagicDb().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim();
PrintSheet ps = getPrintSheet(sheetKey);
result.addAll(ps.random(numCards, true));
@@ -100,7 +88,7 @@ public class BoosterGenerator {
String mainCode = itMod.next();
if ( mainCode.regionMatches(true, 0, "fromSheet", 0, 9)) { // custom print sheet
String sheetName = StringUtils.strip(mainCode.substring(9), "()\" ");
src = Singletons.getModel().getPrintSheets().get(sheetName).toFlatList();
src = Singletons.getMagicDb().getPrintSheets().get(sheetName).toFlatList();
setPred = Predicates.alwaysTrue();
} else if (mainCode.startsWith("promo")) { // get exactly the named cards, that's a tiny inlined print sheet
@@ -108,7 +96,7 @@ public class BoosterGenerator {
String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"');
List<PaperCard> srcList = new ArrayList<PaperCard>();
for(String cardName: cardNames)
srcList.add(CardDb.instance().getCard(cardName));
srcList.add(Singletons.getMagicDb().getCommonCards().getCard(cardName));
src = srcList;
setPred = Predicates.alwaysTrue();
@@ -121,18 +109,18 @@ public class BoosterGenerator {
// only special operators should remain by now - the ones that could not be turned into one predicate
String mainCode = operators.isEmpty() ? null : operators.get(0).trim();
if( null == mainCode || mainCode.equalsIgnoreCase(ANY) ) { // no restriction on rarity
if( null == mainCode || mainCode.equalsIgnoreCase(BoosterSlots.ANY) ) { // no restriction on rarity
Predicate<PaperCard> predicate = Predicates.and(setPred, extraPred);
ps.addAll(Iterables.filter(src, predicate));
} else if ( mainCode.equalsIgnoreCase(UNCOMMON_RARE) ) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
} else if ( mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE) ) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
ps.addAll(Iterables.filter(src, predicateRares));
Predicate<PaperCard> predicateUncommon = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_UNCOMMON, extraPred);
ps.addAll(Iterables.filter(src, predicateUncommon), 3);
} else if ( mainCode.equalsIgnoreCase(RARE_MYTHIC) ) {
} else if ( mainCode.equalsIgnoreCase(BoosterSlots.RARE_MYTHIC) ) {
// Typical ratio of rares to mythics is 53:15, changing to 35:10 in smaller sets.
// To achieve the desired 1:8 are all mythics are added once, and all rares added twice per print sheet.
@@ -168,13 +156,13 @@ public class BoosterGenerator {
Predicate<PaperCard> toAdd = null;
if( operator.equalsIgnoreCase("dfc") ) { toAdd = Predicates.compose(CardRulesPredicates.splitType(CardSplitType.Transform), PaperCard.FN_GET_RULES);
} else if ( operator.equalsIgnoreCase(LAND) ) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard.FN_GET_RULES);
} else if ( operator.equalsIgnoreCase(BASIC_LAND)) { toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND;
} else if ( operator.equalsIgnoreCase(TIME_SHIFTED)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL;
} else if ( operator.equalsIgnoreCase(MYTHIC)) { toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE;
} else if ( operator.equalsIgnoreCase(RARE)) { toAdd = IPaperCard.Predicates.Presets.IS_RARE;
} else if ( operator.equalsIgnoreCase(UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON;
} else if ( operator.equalsIgnoreCase(COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON;
} else if ( operator.equalsIgnoreCase(BoosterSlots.LAND) ) { toAdd = Predicates.compose(CardRulesPredicates.Presets.IS_LAND, PaperCard.FN_GET_RULES);
} else if ( operator.equalsIgnoreCase(BoosterSlots.BASIC_LAND)) { toAdd = IPaperCard.Predicates.Presets.IS_BASIC_LAND;
} else if ( operator.equalsIgnoreCase(BoosterSlots.TIME_SHIFTED)) { toAdd = IPaperCard.Predicates.Presets.IS_SPECIAL;
} else if ( operator.equalsIgnoreCase(BoosterSlots.MYTHIC)) { toAdd = IPaperCard.Predicates.Presets.IS_MYTHIC_RARE;
} else if ( operator.equalsIgnoreCase(BoosterSlots.RARE)) { toAdd = IPaperCard.Predicates.Presets.IS_RARE;
} else if ( operator.equalsIgnoreCase(BoosterSlots.UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON;
} else if ( operator.equalsIgnoreCase(BoosterSlots.COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON;
} else if ( operator.startsWith("name(") ) {
operator = StringUtils.strip(operator.substring(4), "() ");
String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"');

View File

@@ -297,6 +297,6 @@ public final class CardBlock implements Comparable<CardBlock> {
*/
public IUnOpenedProduct getBooster(final String code) {
MetaSet ms = metaSets.get(code);
return ms == null ? new UnOpenedProduct(Singletons.getModel().getBoosters().get(code)) : ms.getBooster();
return ms == null ? new UnOpenedProduct(Singletons.getMagicDb().getBoosters().get(code)) : ms.getBooster();
}
}

View File

@@ -0,0 +1,80 @@
package forge.card;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.Singletons;
import forge.game.GameFormat;
import forge.util.Aggregates;
/**
* The Class Predicates.
*/
public abstract class CardEditionPredicates {
/** The Constant canMakeBooster. */
public static final Predicate<CardEdition> CAN_MAKE_BOOSTER = new CanMakeBooster();
private static class CanMakeBooster implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return subject.hasBoosterTemplate();
}
}
public final static CardEdition getRandomSetWithAllBasicLands(Iterable<CardEdition> allEditions) {
return Aggregates.random(Iterables.filter(allEditions, CardEditionPredicates.hasBasicLands));
}
public static final Predicate<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
private static class CanMakeStarter implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getMagicDb().getTournamentPacks().contains(subject.getCode());
}
}
public static final Predicate<CardEdition> HAS_FAT_PACK = new CanMakeFatPack();
private static class CanMakeFatPack implements Predicate<CardEdition> {
@Override
public boolean apply(final CardEdition subject) {
return Singletons.getMagicDb().getFatPacks().contains(subject.getCode());
}
}
/**
* Checks if is legal in format.
*
* @param format the format
* @return the predicate
*/
public static final Predicate<CardEdition> isLegalInFormat(final GameFormat format) {
return new LegalInFormat(format);
}
private static class LegalInFormat implements Predicate<CardEdition> {
private final GameFormat format;
public LegalInFormat(final GameFormat fmt) {
this.format = fmt;
}
@Override
public boolean apply(final CardEdition subject) {
return this.format.isSetLegal(subject.getCode());
}
}
public static final Predicate<CardEdition> hasBasicLands = new Predicate<CardEdition>() {
@Override
public boolean apply(CardEdition ed) {
for(String landName : MagicColor.Constant.BASIC_LANDS) {
if (null == Singletons.getMagicDb().getCommonCards().tryGetCard(landName, ed.getCode(), 0))
return false;
}
return true;
};
};
}

View File

@@ -18,7 +18,6 @@
package forge.card;
import java.util.StringTokenizer;
import org.apache.commons.lang3.StringUtils;
import forge.card.mana.IParserManaCost;
@@ -48,6 +47,8 @@ public class CardRulesReader {
private boolean removedFromRandomDecks = false;
private DeckHints hints = null;
private DeckHints needs = null;
// Reset all fields to parse next card (to avoid allocating new
// CardRulesReader N times)
@@ -69,43 +70,35 @@ public class CardRulesReader {
this.needs = null;
this.hints = null;
}
/**
* Create new CardRules from read properties
* Gets the card.
*
* @return the card
*/
public final CardRules createCardRules() {
final CardRules rules = new CardRules();
apply(rules);
return rules;
}
/**
* Apply read properties to a CardRules object
*
*/
private final void apply(CardRules rules) {
public final CardRules getCard() {
CardAiHints cah = new CardAiHints(removedFromAIDecks, removedFromRandomDecks, hints, needs );
faces[0].assignMissingFields();
if (faces[1] != null) {
faces[1].assignMissingFields();
}
rules.setup(faces, altMode, cah);
rules.setDlUrls(pictureUrl);
if (StringUtils.isNotBlank(handLife)) {
rules.setVanguardProperties(handLife);
}
if (null != faces[1]) faces[1].assignMissingFields();
final CardRules result = new CardRules(faces, altMode, cah);
result.setDlUrls(pictureUrl);
if (StringUtils.isNotBlank(handLife))
result.setVanguardProperties(handLife);
return result;
}
public final CardRules readCard(final Iterable<String> script) {
this.reset();
for (String line : script) {
if (line.isEmpty() || line.charAt(0) == '#') {
continue;
}
this.parseLine(line);
}
return this.createCardRules();
return this.getCard();
}
/**
* Parses the line.
*
@@ -113,10 +106,6 @@ public class CardRulesReader {
* the line
*/
public final void parseLine(final String line) {
if (line.isEmpty() || line.charAt(0) == '#') {
return;
}
int colonPos = line.indexOf(':');
String key = colonPos > 0 ? line.substring(0, colonPos) : line;
String value = colonPos > 0 ? line.substring(1+colonPos).trim() : null;
@@ -184,6 +173,7 @@ public class CardRulesReader {
case 'O':
if ("Oracle".equals(key)) {
this.faces[this.curFace].setOracleText(value);
}
break;
@@ -234,11 +224,11 @@ public class CardRulesReader {
}
break;
}
}
/**
* Instantiates class, reads a card. Do not use for batch operations.
*
* @param script
* @return
*/
@@ -247,22 +237,7 @@ public class CardRulesReader {
for(String line : script) {
crr.parseLine(line);
}
return crr.createCardRules();
}
/**
* Instantiates class, reads card rules from script, then updates an existing card.
*
* @param rules
* @param script
*/
public static void updateCardRules(CardRules rules, String script) {
CardRulesReader crr = new CardRulesReader();
String[] lines = script.split("(\r\n)|\n");
for (String line : lines) {
crr.parseLine(line);
}
crr.apply(rules);
return crr.getCard();
}
/**

View File

@@ -164,13 +164,13 @@ public class MetaSet {
return new UnOpenedProduct(SealedProductTemplate.genericBooster);
case Booster:
return new UnOpenedProduct(Singletons.getModel().getBoosters().get(data));
return new UnOpenedProduct(Singletons.getMagicDb().getBoosters().get(data));
case SpecialBooster:
return new UnOpenedProduct(Singletons.getModel().getSpecialBoosters().get(data));
return new UnOpenedProduct(Singletons.getMagicDb().getSpecialBoosters().get(data));
case Pack:
return new UnOpenedProduct(Singletons.getModel().getTournamentPacks().get(data));
return new UnOpenedProduct(Singletons.getMagicDb().getTournamentPacks().get(data));
case JoinedSet:
Predicate<PaperCard> predicate = IPaperCard.Predicates.printedInSets(data.split(" "));

View File

@@ -10,9 +10,10 @@ import org.apache.commons.lang3.tuple.Pair;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.Singletons;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.item.PrintSheet;
import forge.util.ItemPoolView;
public class UnOpenedProduct implements IUnOpenedProduct {
@@ -47,7 +48,7 @@ public class UnOpenedProduct implements IUnOpenedProduct {
}
public UnOpenedProduct(SealedProductTemplate sealedProductTemplate, Predicate<PaperCard> filterPrinted) {
this(sealedProductTemplate, Iterables.filter(CardDb.instance().getAllCards(), filterPrinted));
this(sealedProductTemplate, Iterables.filter(Singletons.getMagicDb().getCommonCards().getAllCards(), filterPrinted));
}
private void prebuildSheets(Iterable<PaperCard> sourceList) {

View File

@@ -15,10 +15,10 @@ import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Constant;
import forge.GameEntity;
import forge.GameObject;
import forge.card.CardCharacteristicName;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityAi;
@@ -456,7 +456,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
final ArrayList<String> basics = new ArrayList<String>();
// what types can I go get?
for (final String name : Constant.Color.BASIC_LANDS) {
for (final String name : MagicColor.Constant.BASIC_LANDS) {
if (!CardLists.getType(list, name).isEmpty()) {
basics.add(name);
}
@@ -500,7 +500,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
*/
private static boolean areAllBasics(final String types) {
for (String ct : types.split(",")) {
if (!Constant.Color.BASIC_LANDS.contains(ct)) {
if (!MagicColor.Constant.BASIC_LANDS.contains(ct)) {
return false;
}
}

View File

@@ -7,7 +7,7 @@ import com.google.common.base.Predicate;
import forge.Card;
import forge.CardLists;
import forge.Constant;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi;
import forge.card.ability.effects.ProtectEffect;
@@ -26,7 +26,7 @@ import forge.game.zone.ZoneType;
public class ProtectAi extends SpellAbilityAi {
private static boolean hasProtectionFrom(final Card card, final String color) {
final ArrayList<String> onlyColors = new ArrayList<String>(Constant.Color.ONLY_COLORS);
final ArrayList<String> onlyColors = new ArrayList<String>(MagicColor.Constant.ONLY_COLORS);
// make sure we have a valid color
if (!onlyColors.contains(color)) {

View File

@@ -13,7 +13,7 @@ import com.google.common.collect.Lists;
import forge.Card;
import forge.CardLists;
import forge.CardPredicates.Presets;
import forge.card.CardDb;
import forge.Singletons;
import forge.card.CardRules;
import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils;
@@ -70,7 +70,7 @@ public class ChooseCardNameEffect extends SpellAbilityEffect {
Predicate<CardRules> additionalRule = CardRulesPredicates.cmc(ComparableOp.EQUALS, validAmount);
List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
Predicate<PaperCard> cpp = Predicates.and(Predicates.compose(baseRule, PaperCard.FN_GET_RULES),
Predicates.compose(additionalRule, PaperCard.FN_GET_RULES));
cards = Lists.newArrayList(Iterables.filter(cards, cpp));
@@ -83,7 +83,7 @@ public class ChooseCardNameEffect extends SpellAbilityEffect {
} else if (p.isHuman()) {
final String message = validDesc.equals("card") ? "Name a card" : "Name a " + validDesc + " card.";
List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
if ( StringUtils.containsIgnoreCase(valid, "nonland") )
{
Predicate<PaperCard> cpp = Predicates.compose(CardRulesPredicates.Presets.IS_NON_LAND, PaperCard.FN_GET_RULES);

View File

@@ -7,7 +7,7 @@ import java.util.List;
import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.Constant;
import forge.card.MagicColor;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.TargetRestrictions;
@@ -39,7 +39,7 @@ public class ChooseColorEffect extends SpellAbilityEffect {
public void resolve(SpellAbility sa) {
final Card card = sa.getSourceCard();
List<String> colorChoices = new ArrayList<String>(Constant.Color.ONLY_COLORS);
List<String> colorChoices = new ArrayList<String>(MagicColor.Constant.ONLY_COLORS);
if (sa.hasParam("Choices")) {
String[] restrictedChoices = sa.getParam("Choices").split(",");
colorChoices = Arrays.asList(restrictedChoices);
@@ -112,9 +112,9 @@ public class ChooseColorEffect extends SpellAbilityEffect {
else if (logic.equals("MostProminentKeywordInComputerDeck")) {
List<Card> list = ai.getAllCards();
int max = 0;
String chosenColor = Constant.Color.WHITE;
String chosenColor = MagicColor.Constant.WHITE;
for (final String c : Constant.Color.ONLY_COLORS) {
for (final String c : MagicColor.Constant.ONLY_COLORS) {
final int cmp = CardLists.filter(list, CardPredicates.containsKeyword(c)).size();
if (cmp > max) {
max = cmp;
@@ -125,7 +125,7 @@ public class ChooseColorEffect extends SpellAbilityEffect {
}
}
if (chosen.size() == 0) {
chosen.add(Constant.Color.GREEN);
chosen.add(MagicColor.Constant.GREEN);
}
GuiChoose.one("Computer picked: ", chosen);
final ArrayList<String> colorTemp = new ArrayList<String>();

View File

@@ -6,7 +6,6 @@ import java.util.Arrays;
import java.util.List;
import forge.Card;
import forge.Constant;
import forge.card.CardType;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
@@ -39,7 +38,7 @@ public class ChooseTypeEffect extends SpellAbilityEffect {
}
if (type.equals("Card")) {
if (validTypes.isEmpty()) validTypes.addAll(Constant.CardTypes.CARD_TYPES);
if (validTypes.isEmpty()) validTypes.addAll(CardType.Constant.CARD_TYPES);
} else if (type.equals("Creature")) {
if (validTypes.isEmpty()) validTypes.addAll(CardType.getCreatureTypes());
} else if (type.equals("Basic Land")) {

View File

@@ -15,8 +15,8 @@ import forge.Card;
import forge.CardLists;
import forge.Command;
import forge.GameEntity;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
@@ -71,7 +71,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
final TargetRestrictions tgt = sa.getTargetRestrictions();
if (sa.hasParam("ValidSupportedCopy")) {
List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
String valid = sa.getParam("ValidSupportedCopy");
if (valid.contains("X")) {
valid = valid.replace("X", Integer.toString(AbilityUtils.calculateAmount(hostCard, "X", sa)));
@@ -154,7 +154,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
if (!c.isToken() || c.isCopiedToken()) {
// copy creature and put it onto the battlefield
copy = CardFactory.getCard(CardDb.getCard(c), sa.getActivatingPlayer());
copy = CardFactory.getCard(c.getPaperCard(), sa.getActivatingPlayer());
copy.setToken(true);
copy.setCopiedToken(true);

View File

@@ -6,7 +6,6 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.Constant;
import forge.CounterType;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
@@ -60,7 +59,7 @@ public class ManaEffect extends SpellAbilityEffect {
}
}
else {
colorMenu = Constant.Color.ONLY_COLORS;
colorMenu = MagicColor.Constant.ONLY_COLORS;
}
for (int nMana = 1; nMana <= amount; nMana++) {
String choice = "";
@@ -83,12 +82,12 @@ public class ManaEffect extends SpellAbilityEffect {
else {
// TODO: Add some logic for AI choice (ArsenalNut 2012/09/16)
if (!sa.hasParam("AILogic") || sa.getParam("AILogic").equals("MostProminentInComputerHand")) {
String chosen = Constant.Color.BLACK;
String chosen = MagicColor.Constant.BLACK;
List<Card> hand = new ArrayList<Card>(activator.getCardsIn(ZoneType.Hand));
hand.addAll(activator.getCardsIn(ZoneType.Stack));
chosen = ComputerUtilCard.getMostProminentColor(hand);
if (chosen.equals("")) {
chosen = Constant.Color.BLACK;
chosen = MagicColor.Constant.BLACK;
}
GuiChoose.one("Computer picked: ", new String[]{chosen});
String manaString = "";
@@ -124,7 +123,7 @@ public class ManaEffect extends SpellAbilityEffect {
}
}
else {
colorMenu = Constant.Color.ONLY_COLORS;
colorMenu = MagicColor.Constant.ONLY_COLORS;
}
String s = GuiChoose.one("Select Mana to Produce", colorMenu);
if (s == null) {
@@ -141,12 +140,12 @@ public class ManaEffect extends SpellAbilityEffect {
else {
if (abMana.getExpressChoice().isEmpty()) {
final String logic = sa.hasParam("AILogic") ? sa.getParam("AILogic") : null;
String chosen = Constant.Color.BLACK;
String chosen = MagicColor.Constant.BLACK;
if (logic == null || logic.equals("MostProminentInComputerHand")) {
chosen = ComputerUtilCard.getMostProminentColor(act.getCardsIn(ZoneType.Hand));
}
if (chosen.equals("")) {
chosen = Constant.Color.GREEN;
chosen = MagicColor.Constant.GREEN;
}
GuiChoose.one("Computer picked: ", new String[]{chosen});
abMana.setExpressChoice(MagicColor.toShortString(chosen));

View File

@@ -11,8 +11,8 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
@@ -85,7 +85,7 @@ public class PlayEffect extends SpellAbilityEffect {
useEncoded = true;
}
else if (sa.hasParam("AnySupportedCard")) {
List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
String valid = sa.getParam("AnySupportedCard");
if (StringUtils.containsIgnoreCase(valid, "sorcery")) {
Predicate<PaperCard> cpp = Predicates.compose(CardRulesPredicates.Presets.IS_SORCERY, PaperCard.FN_GET_RULES);
@@ -160,7 +160,7 @@ public class PlayEffect extends SpellAbilityEffect {
}
Card original = tgtCard;
if (sa.hasParam("CopyCard")) {
tgtCard = Card.fromPaperCard(CardDb.getCard(tgtCard), sa.getActivatingPlayer());
tgtCard = Card.fromPaperCard(tgtCard.getPaperCard(), sa.getActivatingPlayer());
tgtCard.setToken(true);
tgtCard.setCopiedSpell(true);

View File

@@ -9,7 +9,7 @@ import forge.Card;
import forge.CardLists;
import forge.CardUtil;
import forge.Command;
import forge.Constant;
import forge.card.MagicColor;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
import forge.card.spellability.TargetRestrictions;
@@ -229,7 +229,7 @@ public class ProtectEffect extends SpellAbilityEffect {
// Replace AnyColor with the 5 colors
if (choices.contains("AnyColor")) {
gains.addAll(Constant.Color.ONLY_COLORS);
gains.addAll(MagicColor.Constant.ONLY_COLORS);
choices = choices.replaceAll("AnyColor,?", "");
}
// Add any remaining choices

View File

@@ -28,7 +28,6 @@ import forge.CardUtil;
import forge.ImageCache;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.CardDb;
import forge.card.CardRules;
import forge.card.CardSplitType;
import forge.card.ICardFace;
@@ -89,7 +88,8 @@ public class CardFactory {
}
Card out = null;
if (!in.isToken() || in.isCopiedToken()) {
out = assignNewId ? getCard(CardDb.getCard(in), in.getOwner()) : getCard(CardDb.getCard(in), in.getOwner(), in.getUniqueNumber());
out = assignNewId ? getCard(in.getPaperCard(), in.getOwner())
: getCard(in.getPaperCard(), in.getOwner(), in.getUniqueNumber());
} else { // token
out = assignNewId ? new Card(in.getGame().nextCardId()) : new Card(in.getUniqueNumber());
out = CardFactory.copyStats(in, in.getController());

View File

@@ -31,7 +31,6 @@ import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.CardUtil;
import forge.Command;
import forge.Constant;
import forge.CounterType;
import forge.GameEntity;
import forge.GameLogEntryType;
@@ -877,7 +876,7 @@ public class CardFactoryUtil {
int n = 0;
final List<Card> someCards = new ArrayList<Card>();
someCards.addAll(player.getCardsIn(ZoneType.Battlefield));
final List<String> basic = Constant.Color.BASIC_LANDS;
final List<String> basic = MagicColor.Constant.BASIC_LANDS;
for (int i = 0; i < basic.size(); i++) {
if (!CardLists.getType(someCards, basic.get(i)).isEmpty()) {
@@ -1423,7 +1422,7 @@ public class CardFactoryUtil {
int n = 0;
Player neededPlayer = sq[0].equals("DomainActivePlayer") ? activePlayer : cc;
List<Card> someCards = CardLists.filter(neededPlayer.getCardsIn(ZoneType.Battlefield), Presets.LANDS);
for (String basic : Constant.Color.BASIC_LANDS) {
for (String basic : MagicColor.Constant.BASIC_LANDS) {
if (!CardLists.getType(someCards, basic).isEmpty()) {
n++;
}
@@ -1636,7 +1635,7 @@ public class CardFactoryUtil {
}
// String sq0 = sq[0].toLowerCase();
// for(String color : Constant.Color.ONLY_COLORS) {
// for(String color : MagicColor.Constant.ONLY_COLORS) {
// if( sq0.contains(color) )
// someCards = someCards.filter(CardListFilter.WHITE);
// }

View File

@@ -43,6 +43,7 @@ import javax.swing.SwingUtilities;
import org.apache.commons.lang.time.StopWatch;
import forge.FThreads;
import forge.ICardStorageReader;
import forge.card.CardRules;
import forge.card.CardRulesReader;
import forge.error.BugReporter;
@@ -58,7 +59,8 @@ import forge.util.FileUtil;
* @author Forge
* @version $Id$
*/
public class CardStorageReader {
public class CardStorageReader implements ICardStorageReader {
private static final String CARD_FILE_DOT_EXTENSION = ".txt";
@@ -334,7 +336,7 @@ public class CardStorageReader {
try {
fileInputStream = new FileInputStream(file);
CardRules rules = this.loadCard(reader, fileInputStream);
rules.setSourceFile(file);
//rules.setSourceFile(file);
return rules;
} catch (final FileNotFoundException ex) {
BugReporter.reportException(ex, "File \"%s\" exception", file.getAbsolutePath());

View File

@@ -27,7 +27,6 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.Constant;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.Mana;
@@ -621,9 +620,9 @@ public class AbilityManaPart implements java.io.Serializable {
m.appendTail(sb);
String replaced = sb.toString();
while (replaced.contains("Any")) {
String rs = Constant.Color.GREEN;
String rs = MagicColor.Constant.GREEN;
if (act != null) {
rs = act.getController().chooseSingleColor(Constant.Color.ONLY_COLORS);
rs = act.getController().chooseSingleColor(MagicColor.Constant.ONLY_COLORS);
}
replaced = replaced.replaceFirst("Any", MagicColor.toShortString(rs));
}

View File

@@ -22,8 +22,8 @@ import java.util.List;
import java.util.Map;
import forge.Card;
import forge.Constant;
import forge.GameEntity;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
import forge.card.cost.Cost;
import forge.card.mana.ManaCostBeingPaid;
@@ -499,11 +499,11 @@ public class StaticAbility {
return false;
}
} else if (condition.equals("PermanentOfEachColor")) {
if ((controller.getColoredCardsInPlay(Constant.Color.BLACK).isEmpty()
|| controller.getColoredCardsInPlay(Constant.Color.BLUE).isEmpty()
|| controller.getColoredCardsInPlay(Constant.Color.GREEN).isEmpty()
|| controller.getColoredCardsInPlay(Constant.Color.RED).isEmpty()
|| controller.getColoredCardsInPlay(Constant.Color.WHITE).isEmpty())) {
if ((controller.getColoredCardsInPlay(MagicColor.Constant.BLACK).isEmpty()
|| controller.getColoredCardsInPlay(MagicColor.Constant.BLUE).isEmpty()
|| controller.getColoredCardsInPlay(MagicColor.Constant.GREEN).isEmpty()
|| controller.getColoredCardsInPlay(MagicColor.Constant.RED).isEmpty()
|| controller.getColoredCardsInPlay(MagicColor.Constant.WHITE).isEmpty())) {
return false;
}
} else if (condition.equals("FatefulHour")) {

View File

@@ -35,12 +35,12 @@ import com.google.common.base.Function;
import forge.card.CardDb;
import forge.deck.io.DeckFileHeader;
import forge.deck.io.DeckSerializer;
import forge.item.ItemPoolSorter;
import forge.item.PaperCard;
import forge.item.IPaperCard;
import forge.item.ItemPoolView;
import forge.util.FileSection;
import forge.util.FileUtil;
import forge.util.ItemPoolSorter;
import forge.util.ItemPoolView;
/**

View File

@@ -26,7 +26,6 @@ import org.apache.commons.lang.math.IntRange;
import forge.Singletons;
import forge.card.CardCoreType;
import forge.card.CardDb;
import forge.card.ColorSet;
import forge.item.PaperCard;
import forge.item.IPaperCard;
@@ -233,7 +232,7 @@ public enum DeckFormat {
// should group all cards by name, so that different editions of same card are really counted as the same card
for (Entry<String, Integer> cp : Aggregates.groupSumBy(tmp, PaperCard.FN_GET_NAME)) {
IPaperCard simpleCard = CardDb.instance().getCard(cp.getKey());
IPaperCard simpleCard = Singletons.getMagicDb().getCommonCards().getCard(cp.getKey());
boolean canHaveMultiple = simpleCard.getRules().getType().isBasicLand() || limitExceptions.contains(cp.getKey());
if (!canHaveMultiple && cp.getValue() > maxCopies) {

View File

@@ -24,7 +24,7 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import forge.card.CardDb;
import forge.Singletons;
import forge.card.ICardDatabase;
import forge.item.PaperCard;
@@ -169,7 +169,7 @@ public class DeckRecognizer {
public DeckRecognizer(boolean fromLatestSet) {
useLastSet = fromLatestSet;
db = CardDb.instance();
db = Singletons.getMagicDb().getCommonCards();
}
public Token recognizeLine(final String rawLine) {

View File

@@ -15,7 +15,6 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import forge.Singletons;
import forge.card.CardDb;
import forge.deck.generate.Generate2ColorDeck;
import forge.deck.generate.Generate3ColorDeck;
import forge.deck.generate.Generate5ColorDeck;
@@ -23,13 +22,13 @@ import forge.deck.generate.GenerateColoredDeckBase;
import forge.deck.generate.GenerateMonoColorDeck;
import forge.deck.generate.GenerateThemeDeck;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.item.PreconDeck;
import forge.quest.QuestController;
import forge.quest.QuestEvent;
import forge.quest.QuestEventChallenge;
import forge.quest.QuestEventDuel;
import forge.util.Aggregates;
import forge.util.ItemPoolView;
import forge.util.Lang;
import forge.util.MyRandom;
import forge.util.storage.IStorage;
@@ -305,7 +304,7 @@ public class DeckgenUtil {
public static CardPool generateSchemeDeck() {
CardPool schemes = new CardPool();
List<PaperCard> allSchemes = new ArrayList<PaperCard>();
for (PaperCard c : CardDb.variants().getAllCards()) {
for (PaperCard c : Singletons.getMagicDb().getVariantCards().getAllCards()) {
if (c.getRules().getType().isScheme()) {
allSchemes.add(c);
}
@@ -330,7 +329,7 @@ public class DeckgenUtil {
public static CardPool generatePlanarDeck() {
CardPool res = new CardPool();
List<PaperCard> allPlanars = new ArrayList<PaperCard>();
for (PaperCard c : CardDb.variants().getAllCards()) {
for (PaperCard c : Singletons.getMagicDb().getVariantCards().getAllCards()) {
if (c.getRules().getType().isPlane() || c.getRules().getType().isPhenomenon()) {
allPlanars.add(c);
}

View File

@@ -27,7 +27,7 @@ import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.ItemPoolView;
/**
* <p>

View File

@@ -27,7 +27,7 @@ import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.ItemPoolView;
import forge.util.MyRandom;
/**

View File

@@ -26,7 +26,7 @@ import com.google.common.collect.Lists;
import forge.card.ColorSet;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.ItemPoolView;
/**
* <p>

View File

@@ -31,19 +31,17 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Constant;
import forge.Singletons;
import forge.card.CardDb;
import forge.card.CardRules;
import forge.card.CardRulesPredicates;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.item.PaperCard;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.properties.ForgePreferences.FPref;
import forge.util.Aggregates;
import forge.util.ItemPool;
import forge.util.ItemPoolView;
import forge.util.MyRandom;
/**
@@ -132,8 +130,8 @@ public abstract class GenerateColoredDeckBase {
} while ((this.cardCounts.get(s) > 3) && (lc <= 20));
// not an error if looped too much - could play singleton mode, with 6 slots for 3 non-basic lands.
PaperCard cp = CardDb.instance().getCard(s);
tDeck.add(CardDb.instance().getCard(cp.getName(), false));
PaperCard cp = Singletons.getMagicDb().getCommonCards().getCard(s);
tDeck.add(Singletons.getMagicDb().getCommonCards().getCard(cp.getName(), false));
final int n = this.cardCounts.get(s);
this.cardCounts.put(s, n + 1);
@@ -169,10 +167,10 @@ public abstract class GenerateColoredDeckBase {
// just to prevent a null exception by the deck size fixing code
this.cardCounts.put(color, nLand);
PaperCard cp = CardDb.instance().getCard(color);
PaperCard cp = Singletons.getMagicDb().getCommonCards().getCard(color);
String basicLandSet = cp.getEdition();
tDeck.add(CardDb.instance().getCard(cp.getName(), basicLandSet), nLand);
tDeck.add(Singletons.getMagicDb().getCommonCards().getCard(cp.getName(), basicLandSet), nLand);
landsLeft -= nLand;
}
}
@@ -222,7 +220,7 @@ public abstract class GenerateColoredDeckBase {
final List<PaperCard> curvedRandomized = Lists.newArrayList();
for (PaperCard c : curved) {
this.cardCounts.put(c.getName(), 0);
curvedRandomized.add(CardDb.instance().getCard(c.getName(), false));
curvedRandomized.add(Singletons.getMagicDb().getCommonCards().getCard(c.getName(), false));
}
addSome(addOfThisCmc, curvedRandomized);
@@ -239,7 +237,7 @@ public abstract class GenerateColoredDeckBase {
if (!Singletons.getModel().getPreferences().getPrefBoolean(FPref.DECKGEN_ARTIFACTS)) {
hasColor = Predicates.or(hasColor, GenerateDeckUtil.COLORLESS_CARDS);
}
return Iterables.filter(CardDb.instance().getAllCards(), Predicates.compose(Predicates.and(canPlay, hasColor), PaperCard.FN_GET_RULES));
return Iterables.filter(Singletons.getMagicDb().getCommonCards().getAllCards(), Predicates.compose(Predicates.and(canPlay, hasColor), PaperCard.FN_GET_RULES));
}
protected static Map<String, Integer> countLands(ItemPool<PaperCard> outList) {
@@ -254,15 +252,15 @@ public abstract class GenerateColoredDeckBase {
int profile = cpe.getKey().getRules().getManaCost().getColorProfile();
if ((profile & MagicColor.WHITE) != 0) {
increment(res, Constant.Color.BASIC_LANDS.get(0), cpe.getValue());
increment(res, MagicColor.Constant.BASIC_LANDS.get(0), cpe.getValue());
} else if ((profile & MagicColor.BLUE) != 0) {
increment(res, Constant.Color.BASIC_LANDS.get(1), cpe.getValue());
increment(res, MagicColor.Constant.BASIC_LANDS.get(1), cpe.getValue());
} else if ((profile & MagicColor.BLACK) != 0) {
increment(res, Constant.Color.BASIC_LANDS.get(2), cpe.getValue());
increment(res, MagicColor.Constant.BASIC_LANDS.get(2), cpe.getValue());
} else if ((profile & MagicColor.RED) != 0) {
increment(res, Constant.Color.BASIC_LANDS.get(3), cpe.getValue());
increment(res, MagicColor.Constant.BASIC_LANDS.get(3), cpe.getValue());
} else if ((profile & MagicColor.GREEN) != 0) {
increment(res, Constant.Color.BASIC_LANDS.get(4), cpe.getValue());
increment(res, MagicColor.Constant.BASIC_LANDS.get(4), cpe.getValue());
}
}

View File

@@ -27,7 +27,7 @@ import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.deck.generate.GenerateDeckUtil.FilterCMC;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.ItemPoolView;
/**
* <p>

View File

@@ -22,11 +22,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import forge.card.CardDb;
import forge.Singletons;
import forge.error.BugReporter;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.FileUtil;
import forge.util.ItemPoolView;
import forge.util.MyRandom;
/**
@@ -130,7 +130,7 @@ public class GenerateThemeDeck extends GenerateColoredDeckBase {
}
final int n = cardCounts.get(s);
tDeck.add(CardDb.instance().getCard(s));
tDeck.add(Singletons.getMagicDb().getCommonCards().getCard(s));
cardCounts.put(s, n + 1);
tmpDeck += s + "\n";

View File

@@ -44,7 +44,6 @@ import forge.GameEntity;
import forge.GameLogEntryType;
import forge.GameObject;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardType;
import forge.card.TriggerReplacementBase;
import forge.card.ability.AbilityFactory;
@@ -75,7 +74,7 @@ import forge.game.zone.PlayerZoneBattlefield;
import forge.game.zone.Zone;
import forge.game.zone.ZoneType;
import forge.util.Aggregates;
import forge.util.maps.CollectionSuppliers;
import forge.util.CollectionSuppliers;
import forge.util.maps.HashMapOfLists;
import forge.util.maps.MapOfLists;
@@ -906,7 +905,7 @@ public class GameAction {
c.unEnchantEntity(perm);
if (c.isBestowed()) {
// TODO : support for tokens
ArrayList<String> type = CardFactory.getCard(CardDb.getCard(c), c.getController()).getType();
ArrayList<String> type = CardFactory.getCard(c.getPaperCard(), c.getController()).getType();
final long timestamp = game.getNextTimestamp();
c.addChangedCardTypes(type, Lists.newArrayList("Aura"), false, false, false, false, timestamp);
c.addChangedCardKeywords(new ArrayList<String>(), Lists.newArrayList("Enchant creature"), false, timestamp);
@@ -938,7 +937,7 @@ public class GameAction {
if (c.isInPlay() && !c.isEnchanting()) {
if (c.isBestowed()) {
// TODO : support for tokens
ArrayList<String> type = CardFactory.getCard(CardDb.getCard(c), c.getController()).getType();
ArrayList<String> type = CardFactory.getCard(c.getPaperCard(), c.getController()).getType();
final long timestamp = game.getNextTimestamp();
c.addChangedCardTypes(type, Lists.newArrayList("Aura"), false, false, false, false, timestamp);
c.addChangedCardKeywords(new ArrayList<String>(), Lists.newArrayList("Enchant creature"), false, timestamp);

View File

@@ -33,7 +33,6 @@ import forge.CardLists;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Command;
import forge.Constant;
import forge.card.MagicColor;
import forge.card.ability.AbilityFactory;
import forge.card.ability.AbilityFactory.AbilityRecordType;
@@ -217,7 +216,7 @@ public final class GameActionUtil {
// add all appropriate mana abilities based on current types
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
String landType = Constant.Color.BASIC_LANDS.get(i);
String landType = MagicColor.Constant.BASIC_LANDS.get(i);
String color = MagicColor.toShortString(MagicColor.WUBRG[i]);
String abString = "AB$ Mana | Cost$ T | Produced$ " + color + " | SpellDescription$ Add {" + color + "} to your mana pool.";
for (final Card land : lands) {

View File

@@ -19,7 +19,7 @@ import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.GameLogEntryType;
import forge.card.CardDb;
import forge.Singletons;
import forge.card.replacement.ReplacementEffect;
import forge.card.replacement.ReplacementHandler;
import forge.card.trigger.Trigger;
@@ -38,9 +38,9 @@ import forge.net.FServer;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
import forge.util.Aggregates;
import forge.util.CollectionSuppliers;
import forge.util.MyRandom;
import forge.util.TextUtil;
import forge.util.maps.CollectionSuppliers;
import forge.util.maps.HashMapOfLists;
import forge.util.maps.MapOfLists;
@@ -155,9 +155,9 @@ public class GameNew {
PaperCard cpi = cp;
// apply random pictures for cards
if (preferences.getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
cpi = CardDb.instance().getCard(cp.getName(), cp.getEdition(), -1);
cpi = Singletons.getMagicDb().getCommonCards().getCard(cp.getName(), cp.getEdition(), -1);
if ( cp.isFoil() )
cpi = CardDb.instance().getFoiled(cpi);
cpi = Singletons.getMagicDb().getCommonCards().getFoiled(cpi);
}
final Card card = Card.fromPaperCard(cpi, player);

View File

@@ -32,8 +32,8 @@ import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Constant;
import forge.GameEntity;
import forge.card.CardType;
import forge.card.MagicColor;
import forge.card.ability.ApiType;
import forge.card.cardfactory.CardFactoryUtil;
@@ -344,7 +344,7 @@ public class AiController {
byte color = MagicColor.WUBRG[i];
if (!CardLists.filter(oneDrops, CardPredicates.isColor(color)).isEmpty()) {
for (Card land : landList) {
if (land.isType(Constant.Color.BASIC_LANDS.get(i)))
if (land.isType(MagicColor.Constant.BASIC_LANDS.get(i)))
return land;
for (final SpellAbility m : ComputerUtilMana.getAIPlayableMana(land)) {
@@ -365,7 +365,7 @@ public class AiController {
final ArrayList<String> basics = new ArrayList<String>();
// what types can I go get?
for (final String name : Constant.CardTypes.BASIC_TYPES) {
for (final String name : CardType.Constant.BASIC_TYPES) {
if (Iterables.any(landList, CardPredicates.isType(name))) {
basics.add(name);
}

View File

@@ -32,7 +32,6 @@ import com.google.common.collect.Iterables;
import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.Constant;
import forge.CounterType;
import forge.CardPredicates.Presets;
import forge.CardUtil;
@@ -1654,7 +1653,7 @@ public class ComputerUtil {
if (logic.equals("MostNeededType")) {
// Choose a type that is in the deck, but not in hand or on the battlefield
final ArrayList<String> basics = new ArrayList<String>();
basics.addAll(Constant.CardTypes.BASIC_TYPES);
basics.addAll(CardType.Constant.BASIC_TYPES);
List<Card> presentCards = ai.getCardsIn(ZoneType.Battlefield);
presentCards.addAll(ai.getCardsIn(ZoneType.Hand));
List<Card> possibleCards = ai.getAllCards();

View File

@@ -21,7 +21,6 @@ import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardUtil;
import forge.Constant;
import forge.card.CardType;
import forge.card.ColorSet;
import forge.card.MagicColor;
@@ -145,7 +144,7 @@ public class ComputerUtilCard {
int iminBL = 20000; // hopefully no one will ever have more than 20000
// lands of one type....
int n = 0;
for (String name : Constant.Color.BASIC_LANDS) {
for (String name : MagicColor.Constant.BASIC_LANDS) {
n = CardLists.getType(land, name).size();
if ((n < iminBL) && (n > 0)) {
// if two or more are tied, only the
@@ -745,7 +744,7 @@ public class ComputerUtilCard {
if ( (colors & c) != 0 )
return MagicColor.toLongString(c);
}
return Constant.Color.WHITE; // no difference, there was no prominent color
return MagicColor.Constant.WHITE; // no difference, there was no prominent color
}
public static String getMostProminentColor(final List<Card> list, final List<String> restrictedToColors) {

View File

@@ -16,7 +16,6 @@ import com.google.common.base.Predicate;
import forge.Card;
import forge.CardLists;
import forge.CardUtil;
import forge.Constant;
import forge.FThreads;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
@@ -36,7 +35,7 @@ import forge.game.Game;
import forge.game.GameActionUtil;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.util.maps.CollectionSuppliers;
import forge.util.CollectionSuppliers;
import forge.util.maps.EnumMapOfLists;
import forge.util.maps.MapOfLists;
import forge.util.maps.TreeMapOfLists;
@@ -667,19 +666,19 @@ public class ComputerUtilMana {
Set<String> reflectedColors = CardUtil.getReflectableManaColors(m);
// find possible colors
if (mp.canProduce("W", m) || reflectedColors.contains(Constant.Color.WHITE)) {
if (mp.canProduce("W", m) || reflectedColors.contains(MagicColor.Constant.WHITE)) {
manaMap.add(ManaAtom.WHITE, m);
}
if (mp.canProduce("U", m) || reflectedColors.contains(Constant.Color.BLUE)) {
if (mp.canProduce("U", m) || reflectedColors.contains(MagicColor.Constant.BLUE)) {
manaMap.add(ManaAtom.BLUE, m);
}
if (mp.canProduce("B", m) || reflectedColors.contains(Constant.Color.BLACK)) {
if (mp.canProduce("B", m) || reflectedColors.contains(MagicColor.Constant.BLACK)) {
manaMap.add(ManaAtom.BLACK, m);
}
if (mp.canProduce("R", m) || reflectedColors.contains(Constant.Color.RED)) {
if (mp.canProduce("R", m) || reflectedColors.contains(MagicColor.Constant.RED)) {
manaMap.add(ManaAtom.RED, m);
}
if (mp.canProduce("G", m) || reflectedColors.contains(Constant.Color.GREEN)) {
if (mp.canProduce("G", m) || reflectedColors.contains(MagicColor.Constant.GREEN)) {
manaMap.add(ManaAtom.GREEN, m);
}
if (mp.isSnow()) {

View File

@@ -29,7 +29,6 @@ import com.google.common.collect.Lists;
import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
import forge.Constant;
import forge.GameEntity;
import forge.card.CardType;
import forge.card.MagicColor;
@@ -232,7 +231,7 @@ public class CombatUtil {
ArrayList<String> walkTypes = new ArrayList<String>();
for (String basic : Constant.Color.BASIC_LANDS) {
for (String basic : MagicColor.Constant.BASIC_LANDS) {
StringBuilder sbLand = new StringBuilder();
sbLand.append(basic);
sbLand.append("walk");

View File

@@ -37,6 +37,7 @@ import forge.Constant.Preferences;
import forge.Singletons;
import forge.card.CardBlock;
import forge.card.CardEdition;
import forge.card.CardEditionPredicates;
import forge.card.IUnOpenedProduct;
import forge.card.SealedProductTemplate;
import forge.card.UnOpenedProduct;
@@ -44,11 +45,11 @@ import forge.deck.Deck;
import forge.gui.GuiChoose;
import forge.item.PaperCard;
import forge.item.IPaperCard;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.properties.NewConstants;
import forge.util.FileUtil;
import forge.util.HttpUtil;
import forge.util.ItemPool;
import forge.util.ItemPoolView;
import forge.util.storage.IStorage;
/**
@@ -88,7 +89,7 @@ public final class BoosterDraft implements IBoosterDraft {
Supplier<List<PaperCard>> s = new UnOpenedProduct(SealedProductTemplate.genericBooster);
for (int i = 0; i < 3; i++) this.product.add(s);
IBoosterDraft.LAND_SET_CODE[0] = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions());
IBoosterDraft.LAND_SET_CODE[0] = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions());
break;
case Block: case FantasyBlock: // Draft from cards by block or set
@@ -165,7 +166,7 @@ public final class BoosterDraft implements IBoosterDraft {
this.product.add(toAdd);
}
IBoosterDraft.LAND_SET_CODE[0] = Singletons.getModel().getEditions().get(draft.getLandSetCode());
IBoosterDraft.LAND_SET_CODE[0] = Singletons.getMagicDb().getEditions().get(draft.getLandSetCode());
}
/** Looks for res/draft/*.draft files, reads them, returns a list. */

View File

@@ -25,15 +25,14 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import forge.Singletons;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardEditionPredicates;
import forge.card.SealedProductTemplate;
import forge.deck.Deck;
import forge.deck.DeckBase;
import forge.item.PaperCard;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.util.FileSection;
import forge.util.ItemPool;
import forge.util.ItemPoolView;
import forge.util.TextUtil;
import forge.util.storage.IStorage;
@@ -67,7 +66,7 @@ public class CustomLimited extends DeckBase {
private transient ItemPoolView<PaperCard> cardPool;
/** The Land set code. */
private String landSetCode = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions()).getCode();
private String landSetCode = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
private boolean singleton;
@@ -109,7 +108,7 @@ public class CustomLimited extends DeckBase {
cd.numPacks = data.getInt("NumPacks");
cd.singleton = data.getBoolean("Singleton");
final Deck deckCube = cubes.get(data.get("DeckFile"));
cd.cardPool = deckCube == null ? ItemPool.createFrom(CardDb.instance().getUniqueCards(), PaperCard.class) : deckCube.getMain();
cd.cardPool = deckCube == null ? ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getUniqueCards(), PaperCard.class) : deckCube.getMain();
return cd;
}

View File

@@ -20,7 +20,7 @@ package forge.game.limited;
import forge.card.CardEdition;
import forge.deck.Deck;
import forge.item.PaperCard;
import forge.item.ItemPoolView;
import forge.util.ItemPoolView;
/**
* <p>

View File

@@ -16,12 +16,11 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Constant;
import forge.Singletons;
import forge.Constant.Preferences;
import forge.card.CardAiHints;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardEditionPredicates;
import forge.card.CardRules;
import forge.card.CardRulesPredicates;
import forge.card.ColorSet;
@@ -269,8 +268,8 @@ public class LimitedDeckBuilder {
private void findBasicLandSets() {
Set<String> sets = new HashSet<String>();
for (PaperCard cp : aiPlayables) {
CardEdition ee = Singletons.getModel().getEditions().get(cp.edition);
if( !sets.contains(cp.getEdition()) && CardEdition.Predicates.hasBasicLands.apply(ee))
CardEdition ee = Singletons.getMagicDb().getEditions().get(cp.edition);
if( !sets.contains(cp.getEdition()) && CardEditionPredicates.hasBasicLands.apply(ee))
sets.add(cp.getEdition());
}
setsWithBasicLands.addAll(sets);
@@ -303,7 +302,7 @@ public class LimitedDeckBuilder {
final float p = (float) clrCnts[i] / (float) totalColor;
final int nLand = Math.round(landsNeeded * p); // desired truncation to int
if (Preferences.DEV_MODE) {
System.out.printf("Basics[%s]: %d/%d = %f%% = %d cards%n", Constant.Color.BASIC_LANDS.get(i), clrCnts[i], totalColor, 100*p, nLand);
System.out.printf("Basics[%s]: %d/%d = %f%% = %d cards%n", MagicColor.Constant.BASIC_LANDS.get(i), clrCnts[i], totalColor, 100*p, nLand);
}
for (int j = 0; j < nLand; j++) {
@@ -326,7 +325,7 @@ public class LimitedDeckBuilder {
} else {
set = setsWithBasicLands.get(0);
}
return CardDb.instance().getCard(Constant.Color.BASIC_LANDS.get(basicLand), set);
return Singletons.getMagicDb().getCommonCards().getCard(MagicColor.Constant.BASIC_LANDS.get(basicLand), set);
}
/**

Some files were not shown because too many files have changed in this diff Show More