mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Moved cardDb and most of static data to core project. Had to rollback some incompatible changes. Sorry, drdev!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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() { }
|
||||
}
|
||||
|
||||
@@ -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, ',', '"', '"');
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class CardAiHints {
|
||||
|
||||
|
||||
private final boolean isRemovedFromAIDecks;
|
||||
private final boolean isRemovedFromRandomDecks;
|
||||
|
||||
private final DeckHints deckHints;
|
||||
private final DeckHints deckNeeds;
|
||||
|
||||
|
||||
public CardAiHints(boolean remAi, boolean remRandom, DeckHints dh, DeckHints dn) {
|
||||
isRemovedFromAIDecks = remAi;
|
||||
isRemovedFromRandomDecks = remRandom;
|
||||
deckHints = dh;
|
||||
deckNeeds = dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rem ai decks.
|
||||
*
|
||||
* @return the rem ai decks
|
||||
*/
|
||||
public boolean getRemAIDecks() {
|
||||
return this.isRemovedFromAIDecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rem random decks.
|
||||
*
|
||||
* @return the rem random decks
|
||||
*/
|
||||
public boolean getRemRandomDecks() {
|
||||
return this.isRemovedFromRandomDecks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deckHints
|
||||
*/
|
||||
public DeckHints getDeckHints() {
|
||||
return deckHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deckHints
|
||||
*/
|
||||
public DeckHints getDeckNeeds() {
|
||||
return deckNeeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ai status comparable.
|
||||
*
|
||||
* @return the ai status comparable
|
||||
*/
|
||||
public Integer getAiStatusComparable() {
|
||||
if (this.isRemovedFromAIDecks && this.isRemovedFromRandomDecks) {
|
||||
return Integer.valueOf(3);
|
||||
} else if (this.isRemovedFromAIDecks) {
|
||||
return Integer.valueOf(4);
|
||||
} else if (this.isRemovedFromRandomDecks) {
|
||||
return Integer.valueOf(2);
|
||||
} else {
|
||||
return Integer.valueOf(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,411 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
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.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 Map<String, PaperCard> uniqueCardsByName = new TreeMap<String, PaperCard>(String.CASE_INSENSITIVE_ORDER);
|
||||
private final Map<String, CardRules> rulesByName;
|
||||
|
||||
private final List<PaperCard> allCards = new ArrayList<PaperCard>();
|
||||
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) {
|
||||
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) {
|
||||
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))
|
||||
artIdx++;
|
||||
else {
|
||||
artIdx = 0;
|
||||
lastCardName = cis.name;
|
||||
}
|
||||
CardRules cr = rulesByName.get(lastCardName);
|
||||
if (cr != null) {
|
||||
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx));
|
||||
}
|
||||
else if (worthLogging) {
|
||||
missingCards.add(cis.name);
|
||||
}
|
||||
}
|
||||
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, " | ") );
|
||||
}
|
||||
missingCards.clear();
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
reIndex();
|
||||
}
|
||||
|
||||
private void addCard(PaperCard paperCard) {
|
||||
allCardsByName.put(paperCard.name, paperCard);
|
||||
}
|
||||
|
||||
private void reIndex() {
|
||||
uniqueCardsByName.clear();
|
||||
allCards.clear();
|
||||
for(Entry<String, Collection<PaperCard>> kv : allCardsByName.asMap().entrySet()) {
|
||||
uniqueCardsByName.put(kv.getKey(), Iterables.getFirst(kv.getValue(), null));
|
||||
allCards.addAll(kv.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits cardname into Name and set whenever deck line reads as name|set.
|
||||
*/
|
||||
private static ImmutablePair<String, String> splitCardName(final String name) {
|
||||
String cardName = name; // .trim() ?
|
||||
final int pipePos = cardName.indexOf('|');
|
||||
|
||||
if (pipePos >= 0) {
|
||||
final String setName = cardName.substring(pipePos + 1).trim();
|
||||
cardName = cardName.substring(0, pipePos);
|
||||
// only if set is not blank try to load it
|
||||
if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) {
|
||||
return new ImmutablePair<String, String>(cardName, setName);
|
||||
}
|
||||
}
|
||||
return new ImmutablePair<String, String>(cardName, null);
|
||||
}
|
||||
|
||||
private boolean isFoil(final String cardName) {
|
||||
return cardName.toLowerCase().endsWith(CardDb.foilSuffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the foil suffix.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @return the string
|
||||
*/
|
||||
public String removeFoilSuffix(final String cardName) {
|
||||
return cardName.toLowerCase().endsWith(CardDb.foilSuffix) ? cardName.substring(0, cardName.length() - CardDb.foilSuffixLength) : cardName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName0) {
|
||||
return tryGetCard(cardName0, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName0, boolean fromLastSet) {
|
||||
if (null == cardName0) {
|
||||
return null; // obviously
|
||||
}
|
||||
|
||||
final boolean isFoil = this.isFoil(cardName0);
|
||||
final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0;
|
||||
|
||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
|
||||
final PaperCard res = nameWithSet.right == null
|
||||
? ( fromLastSet ? this.uniqueCardsByName.get(nameWithSet.left) : Aggregates.random(this.allCardsByName.get(nameWithSet.left)) )
|
||||
: tryGetCard(nameWithSet.left, nameWithSet.right);
|
||||
return null != res && isFoil ? getFoiled(res) : res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCardPrintedByDate(final String name0, final boolean fromLatestSet, final Date printedBefore) {
|
||||
final boolean isFoil = this.isFoil(name0);
|
||||
final String cardName = isFoil ? this.removeFoilSuffix(name0) : name0;
|
||||
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName);
|
||||
|
||||
PaperCard res = null;
|
||||
if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date
|
||||
res = tryGetCard(nameWithSet.left, nameWithSet.right);
|
||||
else {
|
||||
Collection<PaperCard> cards = this.allCardsByName.get(nameWithSet.left); // cards are sorted by datetime desc
|
||||
int idxRightSet = 0;
|
||||
for (PaperCard card : cards) {
|
||||
if (editions.get(card.getEdition()).getDate().after(printedBefore))
|
||||
idxRightSet++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
res = fromLatestSet ? Iterables.get(cards, idxRightSet, null) : Aggregates.random(Iterables.skip(cards, idxRightSet));
|
||||
}
|
||||
|
||||
return null != res && isFoil ? getFoiled(res) : res;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName, String setName) {
|
||||
return tryGetCard(cardName, setName, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard tryGetCard(final String cardName0, String setName, int index) {
|
||||
final boolean isFoil = this.isFoil(cardName0);
|
||||
final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0;
|
||||
|
||||
Collection<PaperCard> cards = allCardsByName.get(cardName);
|
||||
if ( null == cards ) return null;
|
||||
|
||||
CardEdition edition = editions.get(setName);
|
||||
if ( null == edition )
|
||||
return tryGetCard(cardName, true); // set not found, try to get the same card from just any set.
|
||||
String effectiveSet = edition.getCode();
|
||||
|
||||
PaperCard result = null;
|
||||
if ( index < 0 ) { // this stands for 'random art'
|
||||
PaperCard[] candidates = new PaperCard[9]; // 9 cards with same name per set is a maximum of what has been printed (Arnchenemy)
|
||||
int cnt = 0;
|
||||
for( PaperCard pc : cards ) {
|
||||
if( pc.getEdition().equalsIgnoreCase(effectiveSet) )
|
||||
candidates[cnt++] = pc;
|
||||
}
|
||||
|
||||
if (cnt == 0 ) return null;
|
||||
result = cnt == 1 ? candidates[0] : candidates[MyRandom.getRandom().nextInt(cnt)];
|
||||
} else
|
||||
for( PaperCard pc : cards ) {
|
||||
if( pc.getEdition().equalsIgnoreCase(effectiveSet) && index == pc.getArtIndex() ) {
|
||||
result = pc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( result == null ) return null;
|
||||
return isFoil ? getFoiled(result) : result;
|
||||
}
|
||||
|
||||
public PaperCard getFoiled(PaperCard card0) {
|
||||
// Here - I am still unsure if there should be a cache Card->Card from unfoiled to foiled, to avoid creation of N instances of single plains
|
||||
return new PaperCard(card0.getRules(), card0.getEdition(), card0.getRarity(), card0.getArtIndex(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrintCount(String cardName, String edition) {
|
||||
int cnt = 0;
|
||||
for( PaperCard pc : allCardsByName.get(cardName) ) {
|
||||
if( pc.getEdition().equals(edition) )
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPrintCount(String cardName) {
|
||||
int max = -1;
|
||||
for( PaperCard pc : allCardsByName.get(cardName) ) {
|
||||
if ( max < pc.getArtIndex() )
|
||||
max = pc.getArtIndex();
|
||||
}
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
// Single fetch
|
||||
@Override
|
||||
public PaperCard getCard(final String name) {
|
||||
return this.getCard(name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard getCard(final String name0, final boolean fromLatestSet) {
|
||||
// Sometimes they read from decks things like "CardName|Set" - but we
|
||||
// can handle it
|
||||
final PaperCard result = tryGetCard(name0, fromLatestSet);
|
||||
if (null == result) {
|
||||
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PaperCard getCardPrintedByDate(final String name0, final boolean fromLatestSet, Date printedBefore ) {
|
||||
// Sometimes they read from decks things like "CardName|Set" - but we
|
||||
// can handle it
|
||||
final PaperCard result = tryGetCard(name0, fromLatestSet);
|
||||
if (null == result) {
|
||||
throw new NoSuchElementException(String.format("Card '%s' released before %s not found in our database.", name0, printedBefore.toString()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Advanced fetch by name+set
|
||||
@Override
|
||||
public PaperCard getCard(final String name, final String set) {
|
||||
return this.getCard(name, set, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaperCard getCard(final String name, final String set, final int artIndex) {
|
||||
|
||||
final PaperCard result = tryGetCard(name, set, artIndex);
|
||||
if (null == result) {
|
||||
final String message = String.format("Asked for '%s' from '%s' #%d: db didn't find that copy.", name, set, artIndex);
|
||||
throw new NoSuchElementException(message);
|
||||
}
|
||||
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() {
|
||||
return roUniqueCards;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PaperCard> getAllCards() {
|
||||
return roAllCards;
|
||||
}
|
||||
|
||||
/** Returns a modifiable list of cards matching the given predicate */
|
||||
@Override
|
||||
public List<PaperCard> getAllCards(Predicate<PaperCard> predicate) {
|
||||
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);
|
||||
}
|
||||
|
||||
private class PredicateExistsInSets implements Predicate<PaperCard> {
|
||||
private final List<String> sets;
|
||||
|
||||
public PredicateExistsInSets(final List<String> wantSets) {
|
||||
this.sets = wantSets; // maybe should make a copy here?
|
||||
}
|
||||
|
||||
@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;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,375 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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 forge.util.FileSection;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.storage.StorageReaderFolder;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* CardSet class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: CardSet.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
public final class CardEdition implements Comparable<CardEdition> { // immutable
|
||||
public enum Type {
|
||||
UNKNOWN,
|
||||
|
||||
CORE,
|
||||
EXPANSION,
|
||||
|
||||
REPRINT,
|
||||
STARTER,
|
||||
|
||||
DUEL_DECKS,
|
||||
PREMIUM_DECK_SERIES,
|
||||
FROM_THE_VAULT,
|
||||
|
||||
OTHER,
|
||||
THIRDPARTY // custom sets
|
||||
}
|
||||
|
||||
public enum FoilType {
|
||||
NOT_SUPPORTED, // sets before Urza's Legacy
|
||||
OLD_STYLE, // sets between Urza's Legacy and 8th Edition
|
||||
MODERN // 8th Edition and newer
|
||||
}
|
||||
|
||||
public static class CardInSet {
|
||||
public final CardRarity rarity;
|
||||
public final String name;
|
||||
|
||||
public CardInSet(final String name, final CardRarity rarity) {
|
||||
this.rarity = rarity;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** The Constant unknown. */
|
||||
private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
public static final CardEdition UNKNOWN = new CardEdition("1990-01-01", "??", "???", Type.UNKNOWN, "Undefined", FoilType.NOT_SUPPORTED, new CardInSet[]{});
|
||||
|
||||
private Date date;
|
||||
private String code2;
|
||||
private String code;
|
||||
private Type type;
|
||||
private String name;
|
||||
private String alias = null;
|
||||
private boolean whiteBorder = false;
|
||||
private FoilType foilType = FoilType.NOT_SUPPORTED;
|
||||
private int foilChanceInBooster = 0;
|
||||
private boolean foilAlwaysInCommonSlot = false;
|
||||
private final CardInSet[] cards;
|
||||
|
||||
|
||||
private int boosterArts = 1;
|
||||
private SealedProductTemplate boosterTpl = null;
|
||||
|
||||
private CardEdition(CardInSet[] cards) {
|
||||
this.cards = cards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new card set.
|
||||
*
|
||||
* @param index indicates order of set release date
|
||||
* @param code2 the 2 (usually) letter code used for image filenames/URLs distributed by the HQ pics team that
|
||||
* use Magic Workstation-type edition codes. Older sets only had 2-letter codes, and some of the 3-letter
|
||||
* codes they use now aren't the same as the official list of 3-letter codes. When Forge downloads set-pics,
|
||||
* it uses the 3-letter codes for the folder no matter the age of the set.
|
||||
* @param code the MTG 3-letter set code
|
||||
* @param type the set type
|
||||
* @param name the name of the set
|
||||
* @param an optional secondary code alias for the set
|
||||
*/
|
||||
private CardEdition(String date, String code2, String code, Type type, String name, FoilType foil, CardInSet[] cards) {
|
||||
this(cards);
|
||||
this.code2 = code2;
|
||||
this.code = code;
|
||||
this.type = type;
|
||||
this.name = name;
|
||||
this.date = parseDate(date);
|
||||
this.foilType = foil;
|
||||
}
|
||||
|
||||
private static Date parseDate(String date) {
|
||||
if( date.length() <= 7 )
|
||||
date = date + "-01";
|
||||
try {
|
||||
return formatter.parse(date);
|
||||
} catch (ParseException e) {
|
||||
return new Date();
|
||||
}
|
||||
}
|
||||
|
||||
public Date getDate() { return date; }
|
||||
public String getCode2() { return code2; }
|
||||
public String getCode() { return code; }
|
||||
public Type getType() { return type; }
|
||||
public String getName() { return name; }
|
||||
public String getAlias() { return alias; }
|
||||
public FoilType getFoilType() { return foilType; }
|
||||
public int getFoilChanceInBooster() { return foilChanceInBooster; }
|
||||
public boolean getFoilAlwaysInCommonSlot() { return foilAlwaysInCommonSlot; }
|
||||
public CardInSet[] getCards() { return cards; }
|
||||
|
||||
/** The Constant fnGetName. */
|
||||
public static final Function<CardEdition, String> FN_GET_CODE = new Function<CardEdition, String>() {
|
||||
@Override
|
||||
public String apply(final CardEdition arg1) {
|
||||
return arg1.getCode();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int compareTo(final CardEdition o) {
|
||||
if (o == null) {
|
||||
return 1;
|
||||
}
|
||||
return date.compareTo(o.date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (this.code.hashCode() * 17) + this.name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final CardEdition other = (CardEdition) obj;
|
||||
return other.name.equals(this.name) && this.code.equals(other.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + " (set)";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the whiteBorder
|
||||
*/
|
||||
public boolean isWhiteBorder() {
|
||||
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 static class EditionReader extends StorageReaderFolder<CardEdition> {
|
||||
public EditionReader(File path) {
|
||||
super(path, CardEdition.FN_GET_CODE);
|
||||
}
|
||||
|
||||
public final static CardInSet[] arrCards = new CardInSet[] {};
|
||||
|
||||
@Override
|
||||
protected CardEdition read(File file) {
|
||||
final Map<String, List<String>> contents = FileSection.parseSections(FileUtil.readFile(file));
|
||||
|
||||
List<CardEdition.CardInSet> processedCards = new ArrayList<CardEdition.CardInSet>();
|
||||
for(String line : contents.get("cards")) {
|
||||
if (StringUtils.isBlank(line))
|
||||
continue;
|
||||
|
||||
// You may omit rarity for early development
|
||||
CardRarity r = CardRarity.smartValueOf(line.substring(0, 1));
|
||||
boolean hadRarity = r != CardRarity.Unknown && line.charAt(1) == ' ';
|
||||
String cardName = hadRarity ? line.substring(2) : line;
|
||||
CardInSet cis = new CardInSet(cardName, r);
|
||||
processedCards.add(cis);
|
||||
}
|
||||
|
||||
CardEdition res = new CardEdition(processedCards.toArray(arrCards));
|
||||
|
||||
|
||||
FileSection section = FileSection.parse(contents.get("metadata"), "=");
|
||||
res.name = section.get("name");
|
||||
res.date = parseDate(section.get("date"));
|
||||
res.code = section.get("code");
|
||||
res.code2 = section.get("code2");
|
||||
if( res.code2 == null )
|
||||
res.code2 = res.code;
|
||||
|
||||
res.boosterArts = section.getInt("BoosterCovers", 1);
|
||||
String boosterDesc = section.get("Booster");
|
||||
res.boosterTpl = boosterDesc == null ? null : new SealedProductTemplate(res.code, SealedProductTemplate.Reader.parseSlots(boosterDesc));
|
||||
|
||||
res.alias = section.get("alias");
|
||||
res.whiteBorder = "white".equalsIgnoreCase(section.get("border"));
|
||||
String type = section.get("type");
|
||||
Type enumType = Type.UNKNOWN;
|
||||
if (null != type && !type.isEmpty()) {
|
||||
try {
|
||||
enumType = Type.valueOf(type.toUpperCase(Locale.ENGLISH));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore; type will get UNKNOWN
|
||||
System.err.println(String.format("Ignoring unknown type in set definitions: name: %s; type: %s", res.name, type));
|
||||
}
|
||||
}
|
||||
res.type = enumType;
|
||||
|
||||
switch(section.get("foil", "newstyle").toLowerCase()) {
|
||||
case "notsupported":
|
||||
res.foilType = FoilType.NOT_SUPPORTED;
|
||||
break;
|
||||
case "oldstyle":
|
||||
case "classic":
|
||||
res.foilType = FoilType.OLD_STYLE;
|
||||
break;
|
||||
case "newstyle":
|
||||
case "modern":
|
||||
res.foilType = FoilType.MODERN;
|
||||
break;
|
||||
default:
|
||||
res.foilType = FoilType.NOT_SUPPORTED;
|
||||
break;
|
||||
}
|
||||
res.foilChanceInBooster = section.getInt("FoilChanceInBooster", 16);
|
||||
res.foilAlwaysInCommonSlot = section.getBoolean("FoilAlwaysInCommonSlot", false);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FilenameFilter getFileFilter() {
|
||||
return TXT_FILE_FILTER;
|
||||
}
|
||||
|
||||
|
||||
public static final FilenameFilter TXT_FILE_FILTER = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(final File dir, final String name) {
|
||||
return name.endsWith(".txt");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
/**
|
||||
* A collection of methods containing full
|
||||
* meta and gameplay properties of a card.
|
||||
*
|
||||
* @author Forge
|
||||
* @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 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) {
|
||||
splitType = altMode;
|
||||
mainPart = faces[0];
|
||||
otherPart = faces[1];
|
||||
aiHints = cah;
|
||||
|
||||
//System.out.print(faces[0].getName());
|
||||
|
||||
// for (Entry<String, CardInSet> cs : sets.entrySet()) {
|
||||
// if( CardRulesReader.editions.get(cs.getKey()) != null )
|
||||
// setsPrinted.put(cs.getKey(), cs.getValue());
|
||||
// }
|
||||
//
|
||||
// if ( setsPrinted.isEmpty() ) {
|
||||
// System.err.println(getName() + " was not assigned any set.");
|
||||
// setsPrinted.put(CardEdition.UNKNOWN.getCode(), new CardInSet(CardRarity.Common, 1) );
|
||||
// }
|
||||
//
|
||||
//Calculate Color Identity
|
||||
byte colMask = calculateColorIdentity(mainPart);
|
||||
|
||||
if(otherPart != null)
|
||||
{
|
||||
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) {
|
||||
byte res = face.getColor().getColor();
|
||||
boolean isReminder = false;
|
||||
boolean isSymbol = false;
|
||||
String oracleText = face.getOracleText();
|
||||
int len = oracleText.length();
|
||||
for(int i = 0; i < len; i++) {
|
||||
char c = oracleText.charAt(i); // This is to avoid needless allocations performed by toCharArray()
|
||||
switch(c) {
|
||||
case('('): isReminder = i > 0; break; // if oracle has only reminder, consider it valid rules (basic and true lands need this)
|
||||
case(')'): isReminder = false; break;
|
||||
case('{'): isSymbol = true; break;
|
||||
case('}'): isSymbol = false; break;
|
||||
default:
|
||||
if(isSymbol && !isReminder) {
|
||||
switch(c) {
|
||||
case('W'): res |= MagicColor.WHITE; break;
|
||||
case('U'): res |= MagicColor.BLUE; break;
|
||||
case('B'): res |= MagicColor.BLACK; break;
|
||||
case('R'): res |= MagicColor.RED; break;
|
||||
case('G'): res |= MagicColor.GREEN; break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean isVariant() {
|
||||
CardType t = getType();
|
||||
return t.isVanguard() || t.isScheme() || t.isPlane() || t.isPhenomenon();
|
||||
}
|
||||
|
||||
public CardSplitType getSplitType() {
|
||||
return splitType;
|
||||
}
|
||||
|
||||
public ICardFace getMainPart() {
|
||||
return mainPart;
|
||||
}
|
||||
|
||||
public ICardFace getOtherPart() {
|
||||
return otherPart;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE:
|
||||
return mainPart.getName() + " // " + otherPart.getName();
|
||||
default:
|
||||
return mainPart.getName();
|
||||
}
|
||||
}
|
||||
|
||||
public CardAiHints getAiHints() {
|
||||
return aiHints;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardType getType() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE: // no cards currently have different types
|
||||
return CardType.combine(mainPart.getType(), otherPart.getType());
|
||||
default:
|
||||
return mainPart.getType();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManaCost getManaCost() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE:
|
||||
return ManaCost.combine(mainPart.getManaCost(), otherPart.getManaCost());
|
||||
default:
|
||||
return mainPart.getManaCost();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorSet getColor() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE:
|
||||
return ColorSet.fromMask(mainPart.getColor().getColor() | otherPart.getColor().getColor());
|
||||
default:
|
||||
return mainPart.getColor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override public int getIntPower() { return mainPart.getIntPower(); }
|
||||
@Override public int getIntToughness() { return mainPart.getIntToughness(); }
|
||||
@Override public String getPower() { return mainPart.getPower(); }
|
||||
@Override public String getToughness() { return mainPart.getToughness(); }
|
||||
@Override public int getInitialLoyalty() { return mainPart.getInitialLoyalty(); }
|
||||
|
||||
@Override
|
||||
public String getOracleText() {
|
||||
switch(splitType.getAggregationMethod()) {
|
||||
case AGGREGATE:
|
||||
return mainPart.getOracleText() + "\r\n\r\n" + otherPart.getOracleText();
|
||||
default:
|
||||
return mainPart.getOracleText();
|
||||
}
|
||||
}
|
||||
|
||||
// public Set<String> getSets() { return this.setsPrinted.keySet(); }
|
||||
// public CardInSet getEditionInfo(final String setCode) {
|
||||
// final CardInSet result = this.setsPrinted.get(setCode);
|
||||
// return result; // if returns null, String.format("Card '%s' was never printed in set '%s'", this.getName(), setCode);
|
||||
// }
|
||||
|
||||
// vanguard card fields, they don't use sides.
|
||||
private int deltaHand;
|
||||
private int deltaLife;
|
||||
|
||||
public int getHand() { return deltaHand; }
|
||||
public int getLife() { return deltaLife; }
|
||||
public void setVanguardProperties(String pt) {
|
||||
final int slashPos = pt == null ? -1 : pt.indexOf('/');
|
||||
if (slashPos == -1) {
|
||||
throw new RuntimeException(String.format("Vanguard '%s' has bad hand/life stats", this.getName()));
|
||||
}
|
||||
this.deltaHand = Integer.parseInt(pt.substring(0, slashPos).replace("+", ""));
|
||||
this.deltaLife = Integer.parseInt(pt.substring(slashPos+1).replace("+", ""));
|
||||
}
|
||||
|
||||
// Downloadable image
|
||||
private String dlUrl;
|
||||
private String dlUrlOtherSide;
|
||||
public String getPictureUrl(boolean backface ) { return backface ? dlUrlOtherSide : dlUrl; }
|
||||
public void setDlUrls(String[] dlUrls) { this.dlUrl = dlUrls[0]; this.dlUrlOtherSide = dlUrls[1]; }
|
||||
|
||||
public final List<String> getReplacements() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final List<String> getTriggers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final List<String> getStaticAbilities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final List<String> getAbilities() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ColorSet getColorIdentity() {
|
||||
return this.colorIdentity;
|
||||
}
|
||||
|
||||
public File getSourceFile() {
|
||||
return this.sourceFile;
|
||||
}
|
||||
|
||||
public void setSourceFile(File sourceFile0) {
|
||||
this.sourceFile = sourceFile0;
|
||||
}
|
||||
}
|
||||
@@ -1,549 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.util.ComparableOp;
|
||||
import forge.util.PredicateString;
|
||||
|
||||
/**
|
||||
* Filtering conditions specific for CardRules class, defined here along with
|
||||
* some presets.
|
||||
*/
|
||||
public final class CardRulesPredicates {
|
||||
|
||||
/** The Constant isKeptInAiDecks. */
|
||||
public static final Predicate<CardRules> IS_KEPT_IN_AI_DECKS = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return !card.getAiHints().getRemAIDecks();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isKeptInRandomDecks. */
|
||||
public static final Predicate<CardRules> IS_KEPT_IN_RANDOM_DECKS = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return !card.getAiHints().getRemRandomDecks();
|
||||
}
|
||||
};
|
||||
|
||||
// Static builder methods - they choose concrete implementation by
|
||||
// themselves
|
||||
/**
|
||||
* Cmc.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> cmc(final ComparableOp op, final int what) {
|
||||
return new LeafNumber(LeafNumber.CardField.CMC, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> power(final ComparableOp op, final int what) {
|
||||
return new LeafNumber(LeafNumber.CardField.POWER, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> toughness(final ComparableOp op, final int what) {
|
||||
return new LeafNumber(LeafNumber.CardField.TOUGHNESS, op, what);
|
||||
}
|
||||
|
||||
// P/T
|
||||
/**
|
||||
* Rules.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> rules(final PredicateString.StringOp op, final String what) {
|
||||
return new LeafString(LeafString.CardField.ORACLE_TEXT, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> name(final PredicateString.StringOp op, final String what) {
|
||||
return new LeafString(LeafString.CardField.NAME, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @param transform
|
||||
* @return
|
||||
*/
|
||||
public static Predicate<CardRules> splitType(CardSplitType transform) {
|
||||
return new PredicateSplitType(transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub type.
|
||||
*
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> subType(final String what) {
|
||||
return new LeafString(LeafString.CardField.SUBTYPE, PredicateString.StringOp.CONTAINS, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sub type.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> subType(final PredicateString.StringOp op, final String what) {
|
||||
return new LeafString(LeafString.CardField.SUBTYPE, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Joined type.
|
||||
*
|
||||
* @param op
|
||||
* the op
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> joinedType(final PredicateString.StringOp op, final String what) {
|
||||
return new LeafString(LeafString.CardField.JOINED_TYPE, op, what);
|
||||
}
|
||||
|
||||
/**
|
||||
* Has Keyword.
|
||||
*
|
||||
* @param keyword
|
||||
* the keyword
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> hasKeyword(final String keyword) {
|
||||
return new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return Iterables.contains(card.getMainPart().getKeywords(), keyword);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Core type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> coreType(final boolean isEqual, final String what) {
|
||||
try {
|
||||
return CardRulesPredicates.coreType(isEqual, Enum.valueOf(CardCoreType.class, what));
|
||||
} catch (final Exception e) {
|
||||
return com.google.common.base.Predicates.alwaysFalse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Core type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param type
|
||||
* the type
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> coreType(final boolean isEqual, final CardCoreType type) {
|
||||
return new PredicateCoreType(type, isEqual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Super type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param what
|
||||
* the what
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> superType(final boolean isEqual, final String what) {
|
||||
try {
|
||||
return CardRulesPredicates.superType(isEqual, Enum.valueOf(CardSuperType.class, what));
|
||||
} catch (final Exception e) {
|
||||
return com.google.common.base.Predicates.alwaysFalse();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Super type.
|
||||
*
|
||||
* @param isEqual
|
||||
* the is equal
|
||||
* @param type
|
||||
* the type
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> superType(final boolean isEqual, final CardSuperType type) {
|
||||
return new PredicateSuperType(type, isEqual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks for color.
|
||||
*
|
||||
* @param thatColor
|
||||
* the that color
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> hasColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.HasAllOf, thatColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is color.
|
||||
*
|
||||
* @param thatColor
|
||||
* the that color
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> isColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.HasAnyOf, thatColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is exactly that color.
|
||||
*
|
||||
* @param thatColor
|
||||
* color to check
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> isMonoColor(final byte thatColor) {
|
||||
return new LeafColor(LeafColor.ColorOperator.Equals, thatColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for cnt colors.
|
||||
*
|
||||
* @param cntColors
|
||||
* the cnt colors
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> hasCntColors(final byte cntColors) {
|
||||
return new LeafColor(LeafColor.ColorOperator.CountColors, cntColors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for at least cnt colors.
|
||||
*
|
||||
* @param cntColors
|
||||
* the cnt colors
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> hasAtLeastCntColors(final byte cntColors) {
|
||||
return new LeafColor(LeafColor.ColorOperator.CountColorsGreaterOrEqual, cntColors);
|
||||
}
|
||||
|
||||
private static class LeafString extends PredicateString<CardRules> {
|
||||
public enum CardField {
|
||||
ORACLE_TEXT, NAME, SUBTYPE, JOINED_TYPE
|
||||
}
|
||||
|
||||
private final String operand;
|
||||
private final LeafString.CardField field;
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
boolean shouldContain;
|
||||
switch (this.field) {
|
||||
case NAME:
|
||||
return op(card.getName(), this.operand);
|
||||
case SUBTYPE:
|
||||
shouldContain = (this.getOperator() == StringOp.CONTAINS) || (this.getOperator() == StringOp.EQUALS);
|
||||
return shouldContain == card.getType().subTypeContains(this.operand);
|
||||
case ORACLE_TEXT:
|
||||
return op(card.getOracleText(), operand);
|
||||
case JOINED_TYPE:
|
||||
return op(card.getType().toString(), operand);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public LeafString(final LeafString.CardField field, final StringOp operator, final String operand) {
|
||||
super(operator);
|
||||
this.field = field;
|
||||
this.operand = operand;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LeafColor implements Predicate<CardRules> {
|
||||
public enum ColorOperator {
|
||||
CountColors, CountColorsGreaterOrEqual, HasAnyOf, HasAllOf, Equals
|
||||
}
|
||||
|
||||
private final LeafColor.ColorOperator op;
|
||||
private final byte color;
|
||||
|
||||
public LeafColor(final LeafColor.ColorOperator operator, final byte thatColor) {
|
||||
this.op = operator;
|
||||
this.color = thatColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
if (null == subject) {
|
||||
return false;
|
||||
}
|
||||
switch (this.op) {
|
||||
case CountColors:
|
||||
return subject.getColor().countColors() == this.color;
|
||||
case CountColorsGreaterOrEqual:
|
||||
return subject.getColor().countColors() >= this.color;
|
||||
case Equals:
|
||||
return subject.getColor().isEqual(this.color);
|
||||
case HasAllOf:
|
||||
return subject.getColor().hasAllColors(this.color);
|
||||
case HasAnyOf:
|
||||
return subject.getColor().hasAnyColor(this.color);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LeafNumber implements Predicate<CardRules> {
|
||||
public enum CardField {
|
||||
CMC, POWER, TOUGHNESS,
|
||||
}
|
||||
|
||||
private final LeafNumber.CardField field;
|
||||
private final ComparableOp operator;
|
||||
private final int operand;
|
||||
|
||||
public LeafNumber(final LeafNumber.CardField field, final ComparableOp op, final int what) {
|
||||
this.field = field;
|
||||
this.operand = what;
|
||||
this.operator = op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
int value;
|
||||
switch (this.field) {
|
||||
case CMC:
|
||||
return this.op(card.getManaCost().getCMC(), this.operand);
|
||||
case POWER:
|
||||
value = card.getIntPower();
|
||||
return value >= 0 ? this.op(value, this.operand) : false;
|
||||
case TOUGHNESS:
|
||||
value = card.getIntToughness();
|
||||
return value >= 0 ? this.op(value, this.operand) : false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean op(final int op1, final int op2) {
|
||||
switch (this.operator) {
|
||||
case EQUALS:
|
||||
return op1 == op2;
|
||||
case GREATER_THAN:
|
||||
return op1 > op2;
|
||||
case GT_OR_EQUAL:
|
||||
return op1 >= op2;
|
||||
case LESS_THAN:
|
||||
return op1 < op2;
|
||||
case LT_OR_EQUAL:
|
||||
return op1 <= op2;
|
||||
case NOT_EQUALS:
|
||||
return op1 != op2;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class PredicateCoreType implements Predicate<CardRules> {
|
||||
private final CardCoreType operand;
|
||||
private final boolean shouldBeEqual;
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
if (null == card) {
|
||||
return false;
|
||||
}
|
||||
return this.shouldBeEqual == card.getType().typeContains(this.operand);
|
||||
}
|
||||
|
||||
public PredicateCoreType(final CardCoreType type, final boolean wantEqual) {
|
||||
this.operand = type;
|
||||
this.shouldBeEqual = wantEqual;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PredicateSuperType implements Predicate<CardRules> {
|
||||
private final CardSuperType operand;
|
||||
private final boolean shouldBeEqual;
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
return this.shouldBeEqual == card.getType().superTypeContains(this.operand);
|
||||
}
|
||||
|
||||
public PredicateSuperType(final CardSuperType type, final boolean wantEqual) {
|
||||
this.operand = type;
|
||||
this.shouldBeEqual = wantEqual;
|
||||
}
|
||||
}
|
||||
|
||||
private static class PredicateSplitType implements Predicate<CardRules> {
|
||||
private final CardSplitType cst;
|
||||
|
||||
public PredicateSplitType(final CardSplitType type) {
|
||||
cst = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
return subject.getSplitType() == cst;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class Presets.
|
||||
*/
|
||||
public static class Presets {
|
||||
|
||||
/** The Constant isCreature. */
|
||||
public static final Predicate<CardRules> IS_CREATURE = CardRulesPredicates
|
||||
.coreType(true, CardCoreType.Creature);
|
||||
|
||||
public static final Predicate<CardRules> IS_LEGENDARY = CardRulesPredicates
|
||||
.superType(true, CardSuperType.Legendary);
|
||||
|
||||
/** The Constant isArtifact. */
|
||||
public static final Predicate<CardRules> IS_ARTIFACT = CardRulesPredicates
|
||||
.coreType(true, CardCoreType.Artifact);
|
||||
|
||||
/** The Constant isEquipment. */
|
||||
public static final Predicate<CardRules> IS_EQUIPMENT = CardRulesPredicates
|
||||
.subType("Equipment");
|
||||
|
||||
/** The Constant isLand. */
|
||||
public static final Predicate<CardRules> IS_LAND = CardRulesPredicates.coreType(true, CardCoreType.Land);
|
||||
|
||||
/** The Constant isBasicLand. */
|
||||
public static final Predicate<CardRules> IS_BASIC_LAND = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
return subject.getType().isBasicLand();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isNonBasicLand. */
|
||||
public static final Predicate<CardRules> IS_NONBASIC_LAND = new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules subject) {
|
||||
return subject.getType().isLand() && !subject.getType().isBasicLand();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant isPlaneswalker. */
|
||||
public static final Predicate<CardRules> IS_PLANESWALKER = CardRulesPredicates.coreType(true,
|
||||
CardCoreType.Planeswalker);
|
||||
|
||||
/** The Constant isInstant. */
|
||||
public static final Predicate<CardRules> IS_INSTANT = CardRulesPredicates.coreType(true, CardCoreType.Instant);
|
||||
|
||||
/** The Constant isSorcery. */
|
||||
public static final Predicate<CardRules> IS_SORCERY = CardRulesPredicates.coreType(true, CardCoreType.Sorcery);
|
||||
|
||||
/** The Constant isEnchantment. */
|
||||
public static final Predicate<CardRules> IS_ENCHANTMENT = CardRulesPredicates.coreType(true, CardCoreType.Enchantment);
|
||||
|
||||
public static final Predicate<CardRules> IS_PLANE = CardRulesPredicates.coreType(true, CardCoreType.Plane);
|
||||
public static final Predicate<CardRules> IS_PHENOMENON = CardRulesPredicates.coreType(true, CardCoreType.Phenomenon);
|
||||
public static final Predicate<CardRules> IS_PLANE_OR_PHENOMENON = Predicates.or(IS_PLANE, IS_PHENOMENON);
|
||||
public static final Predicate<CardRules> IS_SCHEME = CardRulesPredicates.coreType(true, CardCoreType.Scheme);
|
||||
public static final Predicate<CardRules> IS_VANGUARD = CardRulesPredicates.coreType(true, CardCoreType.Vanguard);
|
||||
|
||||
/** The Constant isNonLand. */
|
||||
public static final Predicate<CardRules> IS_NON_LAND = CardRulesPredicates.coreType(false, CardCoreType.Land);
|
||||
|
||||
/** The Constant isNonCreatureSpell. */
|
||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = Predicates.not(Predicates.or(
|
||||
Presets.IS_CREATURE, Presets.IS_LAND));
|
||||
|
||||
/** The Constant IS_NONCREATURE_SPELL_FOR_GENERATOR. **/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Predicate<CardRules> IS_NONCREATURE_SPELL_FOR_GENERATOR = com.google.common.base.Predicates
|
||||
.or(Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT,
|
||||
Predicates.and(Presets.IS_ARTIFACT, Predicates.not(Presets.IS_CREATURE)));
|
||||
|
||||
/** The Constant isWhite. */
|
||||
public static final Predicate<CardRules> IS_WHITE = CardRulesPredicates.isColor(MagicColor.WHITE);
|
||||
|
||||
/** The Constant isBlue. */
|
||||
public static final Predicate<CardRules> IS_BLUE = CardRulesPredicates.isColor(MagicColor.BLUE);
|
||||
|
||||
/** The Constant isBlack. */
|
||||
public static final Predicate<CardRules> IS_BLACK = CardRulesPredicates.isColor(MagicColor.BLACK);
|
||||
|
||||
/** The Constant isRed. */
|
||||
public static final Predicate<CardRules> IS_RED = CardRulesPredicates.isColor(MagicColor.RED);
|
||||
|
||||
/** The Constant isGreen. */
|
||||
public static final Predicate<CardRules> IS_GREEN = CardRulesPredicates.isColor(MagicColor.GREEN);
|
||||
|
||||
/** The Constant isColorless. */
|
||||
public static final Predicate<CardRules> IS_COLORLESS = CardRulesPredicates.hasCntColors((byte) 0);
|
||||
|
||||
/** The Constant isMulticolor. */
|
||||
public static final Predicate<CardRules> IS_MULTICOLOR = CardRulesPredicates.hasAtLeastCntColors((byte) 2);
|
||||
|
||||
public static final Predicate<CardRules> IS_MONOCOLOR = CardRulesPredicates.hasCntColors((byte) 1);
|
||||
|
||||
/** The Constant colors. */
|
||||
public static final List<Predicate<CardRules>> COLORS = new ArrayList<Predicate<CardRules>>();
|
||||
static {
|
||||
Presets.COLORS.add(Presets.IS_WHITE);
|
||||
Presets.COLORS.add(Presets.IS_BLUE);
|
||||
Presets.COLORS.add(Presets.IS_BLACK);
|
||||
Presets.COLORS.add(Presets.IS_RED);
|
||||
Presets.COLORS.add(Presets.IS_GREEN);
|
||||
Presets.COLORS.add(Presets.IS_COLORLESS);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.PredicateString.StringOp;
|
||||
|
||||
/**
|
||||
* DeckHints provides the ability for a Card to "want" another Card or type of
|
||||
* Cards in its random deck.
|
||||
*
|
||||
*/
|
||||
public class DeckHints {
|
||||
|
||||
/**
|
||||
* Enum of types of DeckHints.
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
/** The Color. */
|
||||
COLOR,
|
||||
/** The Keyword. */
|
||||
KEYWORD,
|
||||
/** The Name. */
|
||||
NAME,
|
||||
/** The Type. */
|
||||
TYPE,
|
||||
/** The None. */
|
||||
NONE
|
||||
}
|
||||
|
||||
private Type type = Type.NONE;
|
||||
private String filterParam = null;
|
||||
|
||||
/**
|
||||
* Construct a DeckHints from the SVar string.
|
||||
*
|
||||
* @param wants
|
||||
* SVar for DeckHints
|
||||
*/
|
||||
public DeckHints(String wants) {
|
||||
String[] pieces = wants.split("\\$");
|
||||
if (pieces.length == 2) {
|
||||
try {
|
||||
Type typeValue = Type.valueOf(pieces[0].toUpperCase());
|
||||
for (Type t : Type.values()) {
|
||||
if (typeValue == t) {
|
||||
type = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// type will remain NONE
|
||||
}
|
||||
|
||||
filterParam = pieces[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of Cards from the given List<Card> that match this
|
||||
* DeckHints. I.e., other cards that this Card needs in its deck.
|
||||
*
|
||||
* @param cardList
|
||||
* list of cards to be filtered
|
||||
* @return List<Card> of Cards that match this DeckHints.
|
||||
*/
|
||||
public List<PaperCard> filter(Iterable<PaperCard> cardList) {
|
||||
List<PaperCard> ret;
|
||||
switch (type) {
|
||||
case TYPE:
|
||||
ret = new ArrayList<PaperCard>();
|
||||
String[] types = filterParam.split("\\|");
|
||||
for (String type : types) {
|
||||
addMatchingItems(ret, cardList, CardRulesPredicates.subType(type), PaperCard.FN_GET_RULES);
|
||||
}
|
||||
break;
|
||||
case COLOR:
|
||||
ret = new ArrayList<PaperCard>();
|
||||
String[] colors = filterParam.split("\\|");
|
||||
for (String color : colors) {
|
||||
ColorSet cc = ColorSet.fromNames(color);
|
||||
addMatchingItems(ret, cardList, CardRulesPredicates.isColor(cc.getColor()), PaperCard.FN_GET_RULES);
|
||||
}
|
||||
break;
|
||||
case KEYWORD:
|
||||
ret = new ArrayList<PaperCard>();
|
||||
String[] keywords = filterParam.split("\\|");
|
||||
for (String keyword : keywords) {
|
||||
addMatchingItems(ret, cardList, CardRulesPredicates.hasKeyword(keyword), PaperCard.FN_GET_RULES);
|
||||
}
|
||||
break;
|
||||
case NAME:
|
||||
ret = new ArrayList<PaperCard>();
|
||||
String[] names = filterParam.split("\\|");
|
||||
for (String name : names) {
|
||||
addMatchingItems(ret, cardList, CardRulesPredicates.name(StringOp.EQUALS, name), PaperCard.FN_GET_RULES);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = Lists.newArrayList(cardList);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static <T, U> void addMatchingItems(Collection<? super T> dest, Iterable<? extends T> source, Predicate<U> predicate, Function<T, U> fn) {
|
||||
for (T item : Iterables.filter(source, Predicates.compose(predicate, fn))) {
|
||||
dest.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.util.IItemReader;
|
||||
import forge.util.storage.StorageBase;
|
||||
import forge.util.storage.StorageReaderBase;
|
||||
|
||||
public final class EditionCollection extends StorageBase<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));
|
||||
|
||||
for (CardEdition ee : this) {
|
||||
String alias = ee.getAlias();
|
||||
if (null != alias) {
|
||||
aliasToEdition.put(alias, ee);
|
||||
}
|
||||
aliasToEdition.put(ee.getCode2(), ee);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a sets by code. It will search first by three letter codes, then by aliases and two-letter codes.
|
||||
*
|
||||
* @param code
|
||||
* the code
|
||||
* @return the sets the by code
|
||||
*/
|
||||
@Override
|
||||
public CardEdition get(final String code) {
|
||||
CardEdition baseResult = super.get(code);
|
||||
return baseResult == null ? aliasToEdition.get(code) : baseResult;
|
||||
}
|
||||
|
||||
|
||||
public Iterable<CardEdition> getOrderedEditions() {
|
||||
List<CardEdition> res = Lists.newArrayList(this);
|
||||
Collections.sort(res);
|
||||
Collections.reverse(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sets by code or throw.
|
||||
*
|
||||
* @param code
|
||||
* the code
|
||||
* @return the sets the by code or throw
|
||||
*/
|
||||
public CardEdition getEditionByCodeOrThrow(final String code) {
|
||||
final CardEdition set = this.get(code);
|
||||
if (null == set) {
|
||||
throw new RuntimeException(String.format("Edition with code '%s' not found", code));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
// used by image generating code
|
||||
/**
|
||||
* Gets the code2 by code.
|
||||
*
|
||||
* @param code
|
||||
* the code
|
||||
* @return the code2 by code
|
||||
*/
|
||||
public String getCode2ByCode(final String code) {
|
||||
final CardEdition set = this.get(code);
|
||||
return set == null ? "" : set.getCode2();
|
||||
}
|
||||
|
||||
public final Function<String, CardEdition> FN_EDITION_BY_CODE = new Function<String, CardEdition>() {
|
||||
@Override
|
||||
public CardEdition apply(String code) {
|
||||
return EditionCollection.this.get(code);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public IItemReader<SealedProductTemplate> getBoosterGenerator() {
|
||||
// TODO Auto-generated method stub
|
||||
return new StorageReaderBase<SealedProductTemplate>(null) {
|
||||
|
||||
@Override
|
||||
public Map<String, SealedProductTemplate> readAll() {
|
||||
Map<String, SealedProductTemplate> map = new TreeMap<String, SealedProductTemplate>(String.CASE_INSENSITIVE_ORDER);
|
||||
for(CardEdition ce : EditionCollection.this) {
|
||||
map.put(ce.getCode(), ce.getBoosterTemplate());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemKey(SealedProductTemplate item) {
|
||||
return item.getEdition();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.util.TextUtil;
|
||||
import forge.util.storage.StorageReaderFile;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class FatPackTemplate extends SealedProductTemplate {
|
||||
private final int cntBoosters;
|
||||
|
||||
|
||||
public int getCntBoosters() { return cntBoosters; }
|
||||
|
||||
private FatPackTemplate(String edition, int boosters, Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
super(edition, itrSlots);
|
||||
cntBoosters = boosters;
|
||||
}
|
||||
|
||||
public static final class Reader extends StorageReaderFile<FatPackTemplate> {
|
||||
public Reader(String pathname) {
|
||||
super(pathname, FatPackTemplate.FN_GET_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FatPackTemplate read(String line, int i) {
|
||||
String[] headAndData = TextUtil.split(line, ':', 2);
|
||||
final String edition = headAndData[0];
|
||||
final String[] data = TextUtil.splitWithParenthesis(headAndData[1], ',');
|
||||
int nBoosters = 6;
|
||||
|
||||
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
|
||||
for(String slotDesc : data) {
|
||||
String[] kv = TextUtil.split(slotDesc, ' ', 2);
|
||||
if (kv[1].startsWith("Booster"))
|
||||
nBoosters = Integer.parseInt(kv[0]);
|
||||
else
|
||||
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
|
||||
}
|
||||
|
||||
return new FatPackTemplate(edition, nBoosters, slots);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (0 >= cntBoosters) {
|
||||
return "no cards";
|
||||
}
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
for(Pair<String, Integer> p : slots) {
|
||||
s.append(p.getRight()).append(" ").append(p.getLeft()).append(", ");
|
||||
}
|
||||
// trim the last comma and space
|
||||
if( s.length() > 0 )
|
||||
s.replace(s.length() - 2, s.length(), "");
|
||||
|
||||
if (0 < cntBoosters) {
|
||||
if( s.length() > 0 )
|
||||
s.append(" and ");
|
||||
|
||||
s.append(cntBoosters).append(" booster packs ");
|
||||
}
|
||||
return s.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.StorageBase;
|
||||
|
||||
/**
|
||||
* The Class FormatUtils.
|
||||
*/
|
||||
public final class FormatCollection extends StorageBase<GameFormat> {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param io
|
||||
*/
|
||||
public FormatCollection(String filename) {
|
||||
super("Format collections", new FormatReader(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the standard.
|
||||
*
|
||||
* @return the standard
|
||||
*/
|
||||
public GameFormat getStandard() {
|
||||
return this.map.get("Standard");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extended.
|
||||
*
|
||||
* @return the extended
|
||||
*/
|
||||
public GameFormat getExtended() {
|
||||
return this.map.get("Extended");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the modern.
|
||||
*
|
||||
* @return the modern
|
||||
*/
|
||||
public GameFormat getModern() {
|
||||
return this.map.get("Modern");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specified format.
|
||||
* @return the requested format
|
||||
*/
|
||||
public GameFormat getFormat(String format) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@@ -1,34 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.item.PaperCard;
|
||||
|
||||
public interface ICardDatabase {
|
||||
PaperCard tryGetCard(String cardName);
|
||||
PaperCard tryGetCard(String cardName, boolean fromLastSet);
|
||||
PaperCard tryGetCard(String cardName, String edition);
|
||||
PaperCard tryGetCard(String cardName, String edition, int artIndex);
|
||||
PaperCard tryGetCardPrintedByDate(String name0, boolean fromLatestSet, Date printedBefore);
|
||||
|
||||
PaperCard getCard(String cardName);
|
||||
PaperCard getCard(String cardName, boolean fromLastSet);
|
||||
PaperCard getCard(String cardName, String edition);
|
||||
PaperCard getCard(String cardName, String edition, int artIndex);
|
||||
PaperCard getCardPrintedByDate(String name0, boolean fromLatestSet, Date printedBefore);
|
||||
|
||||
PaperCard getFoiled(PaperCard cpi);
|
||||
|
||||
int getPrintCount(String cardName, String edition);
|
||||
int getMaxPrintCount(String cardName);
|
||||
|
||||
Collection<PaperCard> getUniqueCards();
|
||||
List<PaperCard> getAllCards();
|
||||
List<PaperCard> getAllCards(Predicate<PaperCard> predicate);
|
||||
|
||||
Predicate<? super PaperCard> wasPrintedInSets(List<String> allowedSetCodes);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
|
||||
import forge.item.PaperCard;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IUnOpenedProduct extends Supplier<List<PaperCard>> {
|
||||
public List<PaperCard> get();
|
||||
}
|
||||
@@ -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(" "));
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package forge.card;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
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)
|
||||
));
|
||||
|
||||
|
||||
protected final List<Pair<String, Integer>> slots;
|
||||
protected final String name;
|
||||
|
||||
|
||||
public final List<Pair<String, Integer>> getSlots() {
|
||||
return slots;
|
||||
}
|
||||
|
||||
public final String getEdition() {
|
||||
return name;
|
||||
}
|
||||
public SealedProductTemplate(Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
this(null, itrSlots);
|
||||
}
|
||||
|
||||
public SealedProductTemplate(String name0, Iterable<Pair<String, Integer>> itrSlots)
|
||||
{
|
||||
slots = Lists.newArrayList(itrSlots);
|
||||
name = name0;
|
||||
}
|
||||
|
||||
public int getNumberOfCardsExpected() {
|
||||
int sum = 0;
|
||||
for(Pair<String, Integer> p : slots) {
|
||||
sum += p.getRight().intValue();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
protected static final Function<? super SealedProductTemplate, String> FN_GET_NAME = new Function<SealedProductTemplate, String>() {
|
||||
@Override
|
||||
public String apply(SealedProductTemplate arg1) {
|
||||
return arg1.name;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
|
||||
|
||||
s.append("consisting of ");
|
||||
for(Pair<String, Integer> p : slots) {
|
||||
s.append(p.getRight()).append(" ").append(p.getLeft()).append(", ");
|
||||
}
|
||||
|
||||
// trim the last comma and space
|
||||
s.replace(s.length() - 2, s.length(), "");
|
||||
|
||||
// put an 'and' before the previous comma
|
||||
int lastCommaIdx = s.lastIndexOf(",");
|
||||
if (0 < lastCommaIdx) {
|
||||
s.replace(lastCommaIdx+1, lastCommaIdx+1, " and");
|
||||
}
|
||||
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public static final class Reader extends StorageReaderFile<SealedProductTemplate> {
|
||||
public Reader(String pathname) {
|
||||
super(pathname, SealedProductTemplate.FN_GET_NAME);
|
||||
}
|
||||
|
||||
public static List<Pair<String, Integer>> parseSlots(String data) {
|
||||
final String[] dataz = TextUtil.splitWithParenthesis(data, ',');
|
||||
List<Pair<String, Integer>> slots = new ArrayList<Pair<String,Integer>>();
|
||||
for(String slotDesc : dataz) {
|
||||
String[] kv = TextUtil.splitWithParenthesis(slotDesc, ' ', 2);
|
||||
slots.add(ImmutablePair.of(kv[1], Integer.parseInt(kv[0])));
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SealedProductTemplate read(String line, int i) {
|
||||
String[] headAndData = TextUtil.split(line, ':', 2);
|
||||
return new SealedProductTemplate(headAndData[0], parseSlots(headAndData[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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")) {
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.card.CardDb;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.ItemPool;
|
||||
|
||||
/**
|
||||
* Deck section.
|
||||
*
|
||||
*/
|
||||
public class CardPool extends ItemPool<PaperCard> {
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*/
|
||||
public CardPool() {
|
||||
super(PaperCard.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck section.
|
||||
*
|
||||
* @param cards the cards
|
||||
*/
|
||||
public CardPool(final Iterable<Entry<PaperCard, Integer>> cards) {
|
||||
this();
|
||||
this.addAll(cards);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param card
|
||||
* the card
|
||||
*/
|
||||
public void add(final Card card) {
|
||||
this.add(CardDb.getCard(card));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName
|
||||
* the card name
|
||||
* @param setCode
|
||||
* the set code
|
||||
*/
|
||||
public void add(final String cardName, final String setCode) {
|
||||
this.add(cardName, setCode, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the.
|
||||
*
|
||||
* @param cardName the card name
|
||||
* @param setCode the set code
|
||||
* @param amount the amount
|
||||
*/
|
||||
public void add(final String cardName, final String setCode, final int amount) {
|
||||
PaperCard cp = CardDb.instance().tryGetCard(cardName, setCode);
|
||||
if ( cp == null )
|
||||
cp = CardDb.variants().tryGetCard(cardName, setCode);
|
||||
|
||||
if ( cp != null)
|
||||
this.add(cp, amount);
|
||||
else
|
||||
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.
|
||||
*
|
||||
* @param list
|
||||
* CardPrinteds to add
|
||||
*/
|
||||
public void add(final Iterable<PaperCard> list) {
|
||||
for (PaperCard cp : list) {
|
||||
this.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param cardName the card name
|
||||
*/
|
||||
public void add(final String cardName, int cnt) {
|
||||
PaperCard cp = CardDb.instance().tryGetCard(cardName);
|
||||
if ( cp == null )
|
||||
cp = CardDb.variants().tryGetCard(cardName);
|
||||
|
||||
if ( cp != null)
|
||||
this.add(cp, cnt);
|
||||
else
|
||||
throw new NoSuchElementException(String.format("Card %s is not supported by Forge, as it's neither a known common card nor one of casual variants' card.", cardName));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns n-th card from this DeckSection. LINEAR time. No fixed order between changes
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public PaperCard get(int n) {
|
||||
for(Entry<PaperCard, Integer> e : this)
|
||||
{
|
||||
n -= e.getValue();
|
||||
if ( n <= 0 ) return e.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.isEmpty()) return "[]";
|
||||
|
||||
boolean isFirst = true;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('[');
|
||||
for (Entry<PaperCard, Integer> e : this) {
|
||||
if ( isFirst ) isFirst = false;
|
||||
else sb.append(", ");
|
||||
|
||||
sb.append(e.getValue()).append(" x ").append(e.getKey().getName());
|
||||
}
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
|
||||
|
||||
public static CardPool fromCardList(final Iterable<String> lines) {
|
||||
CardPool pool = new CardPool();
|
||||
final Pattern p = Pattern.compile("((\\d+)\\s+)?(.*?)");
|
||||
|
||||
if (lines == null) {
|
||||
return pool;
|
||||
}
|
||||
|
||||
final Iterator<String> lineIterator = lines.iterator();
|
||||
while (lineIterator.hasNext()) {
|
||||
final String line = lineIterator.next();
|
||||
if (line.startsWith(";") || line.startsWith("#")) { continue; } // that is a comment or not-yet-supported card
|
||||
|
||||
final Matcher m = p.matcher(line.trim());
|
||||
m.matches();
|
||||
final String sCnt = m.group(2);
|
||||
final String cardName = m.group(3);
|
||||
if (StringUtils.isBlank(cardName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final int count = sCnt == null ? 1 : Integer.parseInt(sCnt);
|
||||
pool.add(cardName, count);
|
||||
}
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.IPaperCard;
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class GameFormat implements Comparable<GameFormat> {
|
||||
|
||||
private final String name;
|
||||
// contains allowed sets, when empty allows all sets
|
||||
protected final List<String> allowedSetCodes;
|
||||
protected final List<String> bannedCardNames;
|
||||
|
||||
protected final transient List<String> allowedSetCodes_ro;
|
||||
protected final transient List<String> bannedCardNames_ro;
|
||||
|
||||
protected final transient Predicate<PaperCard> filterRules;
|
||||
protected final transient Predicate<PaperCard> filterPrinted;
|
||||
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Instantiates a new game format.
|
||||
*
|
||||
* @param fName
|
||||
* the f name
|
||||
* @param sets
|
||||
* the sets
|
||||
* @param bannedCards
|
||||
* the banned cards
|
||||
*/
|
||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
|
||||
this(fName, sets, bannedCards, 0);
|
||||
}
|
||||
|
||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards, int compareIdx) {
|
||||
this.index = compareIdx;
|
||||
this.name = fName;
|
||||
this.allowedSetCodes = sets == null ? new ArrayList<String>() : Lists.newArrayList(sets);
|
||||
this.bannedCardNames = bannedCards == null ? new ArrayList<String>() : Lists.newArrayList(bannedCards);
|
||||
|
||||
this.allowedSetCodes_ro = Collections.unmodifiableList(allowedSetCodes);
|
||||
this.bannedCardNames_ro = Collections.unmodifiableList(bannedCardNames);
|
||||
|
||||
this.filterRules = this.buildFilterRules();
|
||||
this.filterPrinted = this.buildFilterPrinted();
|
||||
}
|
||||
|
||||
private Predicate<PaperCard> buildFilterPrinted() {
|
||||
final Predicate<PaperCard> banNames = Predicates.not(IPaperCard.Predicates.names(this.bannedCardNames));
|
||||
if (this.allowedSetCodes == null || this.allowedSetCodes.isEmpty()) {
|
||||
return banNames;
|
||||
}
|
||||
return Predicates.and(banNames, IPaperCard.Predicates.printedInSets(this.allowedSetCodes, true));
|
||||
}
|
||||
|
||||
private Predicate<PaperCard> buildFilterRules() {
|
||||
final Predicate<PaperCard> banNames = Predicates.not(IPaperCard.Predicates.names(this.bannedCardNames));
|
||||
if (this.allowedSetCodes == null || this.allowedSetCodes.isEmpty()) {
|
||||
return banNames;
|
||||
}
|
||||
return Predicates.and(banNames, CardDb.instance().wasPrintedInSets(this.allowedSetCodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set list (for GameFormatQuest).
|
||||
*
|
||||
* @return list of allowed set codes
|
||||
*/
|
||||
public List<String> getAllowedSetCodes() {
|
||||
return this.allowedSetCodes_ro;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the banned cards (for GameFormatQuest).
|
||||
*
|
||||
* @return list of banned card names
|
||||
*/
|
||||
public List<String> getBannedCardNames() {
|
||||
return this.bannedCardNames_ro;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter rules.
|
||||
*
|
||||
* @return the filter rules
|
||||
*/
|
||||
public Predicate<PaperCard> getFilterRules() {
|
||||
return this.filterRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter printed.
|
||||
*
|
||||
* @return the filter printed
|
||||
*/
|
||||
public Predicate<PaperCard> getFilterPrinted() {
|
||||
return this.filterPrinted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is sets the legal.
|
||||
*
|
||||
* @param setCode
|
||||
* the set code
|
||||
* @return true, if is sets the legal
|
||||
*/
|
||||
public boolean isSetLegal(final String setCode) {
|
||||
return this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + " (format)";
|
||||
}
|
||||
|
||||
public static final Function<GameFormat, String> FN_GET_NAME = new Function<GameFormat, String>() {
|
||||
@Override
|
||||
public String apply(GameFormat arg1) {
|
||||
return arg1.getName();
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* just used for ordering -- comparing the name is sufficient
|
||||
* @see java.lang.Comparable#compareTo(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(GameFormat other) {
|
||||
if (null == other) {
|
||||
return 1;
|
||||
}
|
||||
return index - other.index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.Map;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.card.MagicColor;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.FileUtil;
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ReadDraftRankings {
|
||||
Double rank = null;
|
||||
|
||||
// Basic lands should be excluded from the evaluation --BBU
|
||||
if ( Constant.Color.BASIC_LANDS.contains(cardName))
|
||||
if ( MagicColor.Constant.BASIC_LANDS.contains(cardName))
|
||||
return null;
|
||||
|
||||
if (draftRankings.containsKey(edition)) {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.apache.commons.lang.ArrayUtils;
|
||||
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.UnOpenedMeta;
|
||||
@@ -36,8 +37,8 @@ import forge.card.UnOpenedProduct;
|
||||
import forge.deck.CardPool;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.ItemPool;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
/**
|
||||
@@ -71,7 +72,7 @@ public class SealedCardPoolGenerator {
|
||||
// Choose number of boosters
|
||||
|
||||
chooseNumberOfBoosters(new UnOpenedProduct(SealedProductTemplate.genericBooster));
|
||||
landSetCode = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions()).getCode();
|
||||
landSetCode = CardEditionPredicates.getRandomSetWithAllBasicLands(Singletons.getMagicDb().getEditions()).getCode();
|
||||
break;
|
||||
|
||||
case Block:
|
||||
|
||||
@@ -9,11 +9,10 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Constant.Color;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.MagicColor;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
@@ -61,14 +60,14 @@ public class SealedDeckBuilder extends LimitedDeckBuilder {
|
||||
List<String> secondColors = new ArrayList<String>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (countsCopy[4] == colorCounts[i]) {
|
||||
maxColors.add(Constant.Color.ONLY_COLORS.get(i));
|
||||
maxColors.add(MagicColor.Constant.ONLY_COLORS.get(i));
|
||||
} else if (countsCopy[3] == colorCounts[i]) {
|
||||
secondColors.add(Constant.Color.ONLY_COLORS.get(i));
|
||||
secondColors.add(MagicColor.Constant.ONLY_COLORS.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
String color1 = Color.GREEN;
|
||||
String color2 = Color.BLACK;
|
||||
String color1 = MagicColor.Constant.GREEN;
|
||||
String color2 = MagicColor.Constant.BLACK;
|
||||
final Random r = MyRandom.getRandom();
|
||||
if (maxColors.size() > 1) {
|
||||
int n = r.nextInt(maxColors.size());
|
||||
|
||||
@@ -59,7 +59,7 @@ import forge.game.player.Player;
|
||||
import forge.game.player.PlayerController.ManaPaymentPurpose;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.maps.HashMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ import forge.GameObject;
|
||||
import forge.Singletons;
|
||||
import forge.CardPredicates.Presets;
|
||||
import forge.GameLogEntryType;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.ability.AbilityFactory;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
@@ -522,7 +521,7 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
|
||||
// 702.102d: if its target is illegal,
|
||||
// the effect making it an Aura spell ends.
|
||||
// It continues resolving as a creature spell.
|
||||
ArrayList<String> type = CardFactory.getCard(CardDb.getCard(source), source.getController()).getType();
|
||||
ArrayList<String> type = CardFactory.getCard(source.getPaperCard(), source.getController()).getType();
|
||||
final long timestamp = game.getNextTimestamp();
|
||||
source.addChangedCardTypes(type, Lists.newArrayList("Aura"), false, false, false, false, timestamp);
|
||||
source.addChangedCardKeywords(new ArrayList<String>(), Lists.newArrayList("Enchant creature"), false, timestamp);
|
||||
|
||||
@@ -33,7 +33,7 @@ import forge.game.Game;
|
||||
import forge.game.event.EventValueChangeType;
|
||||
import forge.game.event.GameEventZone;
|
||||
import forge.game.player.Player;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.maps.EnumMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.deck.CardPool;
|
||||
import forge.error.BugReporter;
|
||||
import forge.item.PaperCard;
|
||||
@@ -153,7 +153,7 @@ public class GauntletIO {
|
||||
final String nodename = reader.getNodeName();
|
||||
|
||||
if ("string".equals(nodename)) {
|
||||
result.add(CardDb.instance().getCard(reader.getValue()));
|
||||
result.add(Singletons.getMagicDb().getCommonCards().getCard(reader.getValue()));
|
||||
} else if ("card".equals(nodename)) { // new format
|
||||
result.add(this.readCardPrinted(reader), cnt);
|
||||
}
|
||||
@@ -183,8 +183,8 @@ public class GauntletIO {
|
||||
final String sIndex = reader.getAttribute("i");
|
||||
final short index = StringUtils.isNumeric(sIndex) ? Short.parseShort(sIndex) : 0;
|
||||
final boolean foil = "1".equals(reader.getAttribute("foil"));
|
||||
final PaperCard card = CardDb.instance().getCard(name, set, index);
|
||||
return foil ? CardDb.instance().getFoiled(card) : card;
|
||||
final PaperCard card = Singletons.getMagicDb().getCommonCards().getCard(name, set, index);
|
||||
return foil ? Singletons.getMagicDb().getCommonCards().getFoiled(card) : card;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class CardDetailPanel extends FPanel {
|
||||
setInfoLabel.setOpaque(false);
|
||||
setInfoLabel.setBorder(null);
|
||||
} else {
|
||||
CardEdition edition = Singletons.getModel().getEditions().get(set);
|
||||
CardEdition edition = Singletons.getMagicDb().getEditions().get(set);
|
||||
if (null != edition) {
|
||||
setInfoLabel.setToolTipText(edition.getName());
|
||||
}
|
||||
@@ -236,7 +236,7 @@ public class CardDetailPanel extends FPanel {
|
||||
String set = card.getCurSetCode();
|
||||
this.setInfoLabel.setText(set);
|
||||
if (null != set && !set.isEmpty()) {
|
||||
CardEdition edition = Singletons.getModel().getEditions().get(set);
|
||||
CardEdition edition = Singletons.getMagicDb().getEditions().get(set);
|
||||
if (null == edition) {
|
||||
setInfoLabel.setToolTipText(card.getRarity().name());
|
||||
} else {
|
||||
|
||||
@@ -42,7 +42,6 @@ import forge.CardPredicates;
|
||||
import forge.CounterType;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardCharacteristicName;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.spellability.AbilityManaPart;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.trigger.TriggerType;
|
||||
@@ -202,7 +201,7 @@ public final class GuiDisplayUtil {
|
||||
for (final String element : data) {
|
||||
final String[] cardinfo = element.trim().split("\\|");
|
||||
|
||||
final Card c = Card.fromPaperCard(CardDb.instance().getCard(cardinfo[0]), player);
|
||||
final Card c = Card.fromPaperCard(Singletons.getMagicDb().getCommonCards().getCard(cardinfo[0]), player);
|
||||
|
||||
boolean hasSetCurSet = false;
|
||||
for (final String info : cardinfo) {
|
||||
@@ -373,7 +372,7 @@ public final class GuiDisplayUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
|
||||
final List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
@@ -394,7 +393,7 @@ public final class GuiDisplayUtil {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<PaperCard> cards = Lists.newArrayList(CardDb.instance().getUniqueCards());
|
||||
final List<PaperCard> cards = Lists.newArrayList(Singletons.getMagicDb().getCommonCards().getUniqueCards());
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
@@ -468,7 +467,7 @@ public final class GuiDisplayUtil {
|
||||
final Player p = game.getPhaseHandler().getPlayerTurn();
|
||||
|
||||
final 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);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.EditionCollection;
|
||||
@@ -101,7 +100,7 @@ public class ImportSourceAnalyzer {
|
||||
else if ("pics_product".equalsIgnoreCase(dirname)) { _analyzeProductPicsDir(root); }
|
||||
else if ("preferences".equalsIgnoreCase(dirname)) { _analyzePreferencesDir(root); }
|
||||
else if ("quest".equalsIgnoreCase(dirname)) { _analyzeQuestDir(root); }
|
||||
else if (null != Singletons.getModel().getEditions().get(dirname)) { _analyzeCardPicsSetDir(root); }
|
||||
else if (null != Singletons.getMagicDb().getEditions().get(dirname)) { _analyzeCardPicsSetDir(root); }
|
||||
else {
|
||||
// look at files in directory and make a semi-educated guess based on file extensions
|
||||
int numUnhandledFiles = 0;
|
||||
@@ -323,13 +322,13 @@ public class ImportSourceAnalyzer {
|
||||
_defaultPicNames = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
_defaultPicOldNameToCurrentName = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (PaperCard c : CardDb.instance().getAllCards()) {
|
||||
for (PaperCard c : Singletons.getMagicDb().getCommonCards().getAllCards()) {
|
||||
_addDefaultPicNames(c, false);
|
||||
if (ImageCache.hasBackFacePicture(c))
|
||||
_addDefaultPicNames(c, true);
|
||||
}
|
||||
|
||||
for (PaperCard c : CardDb.variants().getAllCards()) {
|
||||
for (PaperCard c : Singletons.getMagicDb().getVariantCards().getAllCards()) {
|
||||
_addDefaultPicNames(c, false);
|
||||
// variants never have backfaces
|
||||
}
|
||||
@@ -378,11 +377,11 @@ public class ImportSourceAnalyzer {
|
||||
private void _analyzeCardPicsSetDir(File root) {
|
||||
if (null == _cardFileNamesBySet) {
|
||||
_cardFileNamesBySet = new TreeMap<String, Map<String, String>>(String.CASE_INSENSITIVE_ORDER);
|
||||
for (CardEdition ce : Singletons.getModel().getEditions()) {
|
||||
for (CardEdition ce : Singletons.getMagicDb().getEditions()) {
|
||||
Map<String, String> cardFileNames = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
Predicate<PaperCard> filter = IPaperCard.Predicates.printedInSet(ce.getCode());
|
||||
_addSetCards(cardFileNames, CardDb.instance().getAllCards(), filter);
|
||||
_addSetCards(cardFileNames, CardDb.variants().getAllCards(), filter);
|
||||
_addSetCards(cardFileNames, Singletons.getMagicDb().getCommonCards().getAllCards(), filter);
|
||||
_addSetCards(cardFileNames, Singletons.getMagicDb().getVariantCards().getAllCards(), filter);
|
||||
_cardFileNamesBySet.put(ce.getCode2(), cardFileNames);
|
||||
}
|
||||
|
||||
@@ -395,7 +394,7 @@ public class ImportSourceAnalyzer {
|
||||
}
|
||||
};
|
||||
|
||||
for (PaperCard c : Iterables.filter(CardDb.variants().getAllCards(), predPlanes)) {
|
||||
for (PaperCard c : Iterables.filter(Singletons.getMagicDb().getVariantCards().getAllCards(), predPlanes)) {
|
||||
String baseName = ImageCache.getImageKey(c,false, true);
|
||||
_nameUpdates.put(baseName + ".full.jpg", baseName + ".jpg");
|
||||
if (ImageCache.hasBackFacePicture(c)) {
|
||||
@@ -405,7 +404,7 @@ public class ImportSourceAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
EditionCollection editions = Singletons.getModel().getEditions();
|
||||
EditionCollection editions = Singletons.getMagicDb().getEditions();
|
||||
String editionCode = root.getName();
|
||||
CardEdition edition = editions.get(editionCode);
|
||||
if (null == edition) {
|
||||
|
||||
@@ -186,7 +186,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
}
|
||||
}, canSearch());
|
||||
JMenu fmt = new JMenu("Format");
|
||||
for (final GameFormat f : Singletons.getModel().getFormats()) {
|
||||
for (final GameFormat f : Singletons.getMagicDb().getFormats()) {
|
||||
GuiUtils.addMenuItem(fmt, f.getName(), null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -503,7 +503,7 @@ public enum CCardCatalog implements ICDoc {
|
||||
}
|
||||
|
||||
private Pair<FLabel, Predicate<PaperCard>> buildFormatRestriction(String displayName, GameFormat format, boolean allowReprints) {
|
||||
EditionCollection editions = Singletons.getModel().getEditions();
|
||||
EditionCollection editions = Singletons.getMagicDb().getEditions();
|
||||
StringBuilder tooltip = new StringBuilder("<html>Sets:");
|
||||
|
||||
int lastLen = 0;
|
||||
|
||||
@@ -5,10 +5,9 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.generate.Generate2ColorDeck;
|
||||
@@ -82,10 +81,10 @@ public enum CDeckgen implements ICDoc {
|
||||
final Deck randomDeck = new Deck();
|
||||
|
||||
Predicate<PaperCard> notBasicLand = Predicates.not(Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, PaperCard.FN_GET_RULES));
|
||||
Iterable<PaperCard> source = Iterables.filter(CardDb.instance().getUniqueCards(), notBasicLand);
|
||||
Iterable<PaperCard> source = Iterables.filter(Singletons.getMagicDb().getCommonCards().getUniqueCards(), notBasicLand);
|
||||
randomDeck.getMain().addAllFlat(Aggregates.random(source, 15 * 5));
|
||||
|
||||
for(String landName : Constant.Color.BASIC_LANDS) {
|
||||
for(String landName : MagicColor.Constant.BASIC_LANDS) {
|
||||
randomDeck.getMain().add(landName, 1);
|
||||
}
|
||||
randomDeck.getMain().add("Terramorphic Expanse", 1);
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.google.common.base.Supplier;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
@@ -46,10 +45,10 @@ import forge.gui.toolbox.itemmanager.SItemManagerIO.EditorPreference;
|
||||
import forge.gui.toolbox.itemmanager.table.TableColumnInfo;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
/**
|
||||
* Child controller for constructed deck editor UI.
|
||||
@@ -83,8 +82,8 @@ public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
|
||||
allSections.add(DeckSection.Sideboard);
|
||||
allSections.add(DeckSection.Commander);
|
||||
|
||||
commanderPool = ItemPool.createFrom(CardDb.instance().getAllCards(Predicates.compose(Predicates.and(CardRulesPredicates.Presets.IS_CREATURE,CardRulesPredicates.Presets.IS_LEGENDARY), PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
normalPool = ItemPool.createFrom(CardDb.instance().getAllCards(), PaperCard.class);
|
||||
commanderPool = ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(Predicates.compose(Predicates.and(CardRulesPredicates.Presets.IS_CREATURE,CardRulesPredicates.Presets.IS_LEGENDARY), PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
normalPool = ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class);
|
||||
|
||||
boolean wantUnique = SItemManagerIO.getPref(EditorPreference.display_unique_only);
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import com.google.common.base.Supplier;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
@@ -44,8 +43,8 @@ import forge.gui.toolbox.itemmanager.table.SColumnUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
/**
|
||||
* Child controller for constructed deck editor UI.
|
||||
@@ -84,9 +83,9 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||
allSections.add(DeckSection.Planes);
|
||||
//allSections.add(DeckSection.Commander);
|
||||
|
||||
avatarPool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_VANGUARD, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
planePool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_PLANE_OR_PHENOMENON, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
schemePool = ItemPool.createFrom(CardDb.variants().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_SCHEME, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
avatarPool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_VANGUARD, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
planePool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_PLANE_OR_PHENOMENON, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
schemePool = ItemPool.createFrom(Singletons.getMagicDb().getVariantCards().getAllCards(Predicates.compose(CardRulesPredicates.Presets.IS_SCHEME, PaperCard.FN_GET_RULES)),PaperCard.class);
|
||||
|
||||
boolean wantUnique = SItemManagerIO.getPref(EditorPreference.display_unique_only);
|
||||
|
||||
@@ -178,7 +177,7 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||
@Override
|
||||
public void resetTables() {
|
||||
// Constructed mode can use all cards, no limitations.
|
||||
this.getCatalogManager().setPool(ItemPool.createFrom(CardDb.instance().getAllCards(), PaperCard.class), true);
|
||||
this.getCatalogManager().setPool(ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true);
|
||||
this.getDeckManager().setPool(this.controller.getModel().getMain());
|
||||
}
|
||||
|
||||
@@ -210,7 +209,7 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
|
||||
case Main:
|
||||
lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY));
|
||||
this.getCatalogManager().getTable().setAvailableColumns(lstCatalogCols);
|
||||
this.getCatalogManager().setPool(ItemPool.createFrom(CardDb.instance().getAllCards(), PaperCard.class), true);
|
||||
this.getCatalogManager().setPool(ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true);
|
||||
this.getDeckManager().setPool(this.controller.getModel().getMain());
|
||||
showOptions = true;
|
||||
title = "Title: ";
|
||||
|
||||
@@ -20,10 +20,9 @@ package forge.gui.deckeditor.controllers;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
@@ -42,7 +41,7 @@ import forge.gui.toolbox.itemmanager.CardManager;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
/**
|
||||
* Updates the deck editor UI as necessary draft selection mode.
|
||||
@@ -162,8 +161,8 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
|
||||
|
||||
final CardEdition landSet = IBoosterDraft.LAND_SET_CODE[0];
|
||||
final int landsCount = 20;
|
||||
for(String landName : Constant.Color.BASIC_LANDS) {
|
||||
side.add(CardDb.instance().getCard(landName, landSet.getCode()), landsCount);
|
||||
for(String landName : MagicColor.Constant.BASIC_LANDS) {
|
||||
side.add(Singletons.getMagicDb().getCommonCards().getCard(landName, landSet.getCode()), landsCount);
|
||||
}
|
||||
|
||||
return deck;
|
||||
|
||||
@@ -46,8 +46,8 @@ import forge.gui.toolbox.itemmanager.table.SColumnUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.quest.QuestController;
|
||||
import forge.util.ItemPool;
|
||||
|
||||
//import forge.quest.data.QuestBoosterPack;
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import com.google.common.base.Function;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
@@ -59,13 +58,13 @@ import forge.item.PaperCard;
|
||||
import forge.item.FatPack;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.item.OpenablePack;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.item.TournamentPack;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.io.ReadPriceList;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
/**
|
||||
* Child controller for quest card shop UI.
|
||||
@@ -99,7 +98,7 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
|
||||
private ItemPoolView<InventoryItem> cardsForSale;
|
||||
private final ItemPool<InventoryItem> fullCatalogCards =
|
||||
ItemPool.createFrom(CardDb.instance().getAllCards(), InventoryItem.class);
|
||||
ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), InventoryItem.class);
|
||||
private boolean showingFullCatalog = false;
|
||||
private DragCell allDecksParent = null;
|
||||
private DragCell deckGenParent = null;
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.gui.deckeditor.SEditorIO;
|
||||
@@ -40,7 +40,7 @@ import forge.gui.toolbox.itemmanager.table.SColumnUtil;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
|
||||
*/
|
||||
@Override
|
||||
public void resetTables() {
|
||||
Iterable<PaperCard> allNT = CardDb.variants().getAllCards();
|
||||
Iterable<PaperCard> allNT = Singletons.getMagicDb().getVariantCards().getAllCards();
|
||||
allNT = Iterables.filter(allNT, cardPoolCondition);
|
||||
|
||||
this.getCatalogManager().setPool(ItemPool.createFrom(allNT, PaperCard.class), true);
|
||||
|
||||
@@ -15,8 +15,8 @@ import forge.gui.framework.ICDoc;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,8 @@ import forge.gui.framework.ICDoc;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.TreeMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardRules;
|
||||
import forge.item.PaperCard;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -39,13 +39,13 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
protected final Map<String, String> getNeededImages() {
|
||||
Map<String, String> downloads = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (PaperCard c : CardDb.instance().getAllCards()) {
|
||||
for (PaperCard c : Singletons.getMagicDb().getCommonCards().getAllCards()) {
|
||||
addDLObject(c, downloads, false);
|
||||
if (ImageCache.hasBackFacePicture(c))
|
||||
addDLObject(c, downloads, true);
|
||||
}
|
||||
|
||||
for (PaperCard c : CardDb.variants().getAllCards()) {
|
||||
for (PaperCard c : Singletons.getMagicDb().getVariantCards().getAllCards()) {
|
||||
addDLObject(c, downloads, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardEdition;
|
||||
import forge.item.PaperCard;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -41,7 +41,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
protected final Map<String, String> getNeededImages() {
|
||||
Map<String, String> downloads = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (final PaperCard c : Iterables.concat(CardDb.instance().getAllCards(), CardDb.variants().getAllCards())) {
|
||||
for (final PaperCard c : Iterables.concat(Singletons.getMagicDb().getCommonCards().getAllCards(), Singletons.getMagicDb().getVariantCards().getAllCards())) {
|
||||
final String setCode3 = c.getEdition();
|
||||
if (StringUtils.isBlank(setCode3) || CardEdition.UNKNOWN.getCode().equals(setCode3)) {
|
||||
// we don't want cards from unknown sets
|
||||
|
||||
@@ -31,7 +31,7 @@ import forge.Singletons;
|
||||
import forge.gui.toolbox.FAbsolutePositioner;
|
||||
import forge.properties.FileLocation;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.util.maps.CollectionSuppliers;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.maps.HashMapOfLists;
|
||||
import forge.util.maps.MapOfLists;
|
||||
import forge.view.FFrame;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DialogChooseSets {
|
||||
|
||||
// create a local copy of the editions list so we can sort it
|
||||
List<CardEdition> editions = new ArrayList<CardEdition>();
|
||||
for (CardEdition ce : Singletons.getModel().getEditions()) {
|
||||
for (CardEdition ce : Singletons.getMagicDb().getEditions()) {
|
||||
editions.add(ce);
|
||||
}
|
||||
Collections.sort(editions);
|
||||
|
||||
@@ -18,7 +18,6 @@ import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.CardCollections;
|
||||
@@ -239,7 +238,7 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
cbxPrizedCards.addItem(StartingPoolType.CustomFormat);
|
||||
cbxPrizedCards.addActionListener(alPrizesPool);
|
||||
|
||||
for (GameFormat gf : Singletons.getModel().getFormats()) {
|
||||
for (GameFormat gf : Singletons.getMagicDb().getFormats()) {
|
||||
cbxFormat.addItem(gf);
|
||||
cbxPrizeFormat.addItem(gf);
|
||||
}
|
||||
@@ -247,12 +246,12 @@ public enum VSubmenuQuestData implements IVSubmenu<CSubmenuQuestData> {
|
||||
// Initialize color balance selection
|
||||
cbxPreferredColor.addItem(stringBalancedDistribution);
|
||||
cbxPreferredColor.addItem(stringRandomizedDistribution);
|
||||
cbxPreferredColor.addItem(Constant.Color.WHITE + stringBias);
|
||||
cbxPreferredColor.addItem(Constant.Color.BLUE + stringBias);
|
||||
cbxPreferredColor.addItem(Constant.Color.BLACK + stringBias);
|
||||
cbxPreferredColor.addItem(Constant.Color.RED + stringBias);
|
||||
cbxPreferredColor.addItem(Constant.Color.GREEN + stringBias);
|
||||
cbxPreferredColor.addItem(Constant.Color.COLORLESS + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.WHITE + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.BLUE + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.BLACK + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.RED + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.GREEN + stringBias);
|
||||
cbxPreferredColor.addItem(MagicColor.Constant.COLORLESS + stringBias);
|
||||
|
||||
for (QuestWorld qw : Singletons.getModel().getWorlds()) {
|
||||
cbxStartingWorld.addItem(qw);
|
||||
|
||||
@@ -15,8 +15,8 @@ import javax.swing.SwingUtilities;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.card.MagicColor;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckGroup;
|
||||
@@ -34,7 +34,7 @@ import forge.gui.framework.FScreen;
|
||||
import forge.gui.framework.ICDoc;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
/**
|
||||
@@ -175,7 +175,7 @@ public enum CSubmenuSealed implements ICDoc {
|
||||
final Deck deck = new Deck(sDeckName);
|
||||
deck.getOrCreate(DeckSection.Sideboard).addAll(humanPool);
|
||||
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
for (final String element : MagicColor.Constant.BASIC_LANDS) {
|
||||
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), 18);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Card;
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.gui.CardDetailPanel;
|
||||
import forge.gui.deckchooser.FDeckChooser;
|
||||
import forge.gui.framework.DragCell;
|
||||
@@ -365,7 +365,7 @@ public enum VSubmenuVanguard implements IVSubmenu<CSubmenuVanguard> {
|
||||
*/
|
||||
public Iterable<PaperCard> getAllAvatars() {
|
||||
if (allAvatars.isEmpty()) {
|
||||
for (PaperCard c : CardDb.variants().getAllCards()) {
|
||||
for (PaperCard c : Singletons.getMagicDb().getVariantCards().getAllCards()) {
|
||||
if (c.getRules().getType().isVanguard()) {
|
||||
allAvatars.add(c);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import javax.swing.JButton;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameOutcome;
|
||||
@@ -138,7 +137,7 @@ public class ControlWinLose {
|
||||
Deck oDeck = psc.getOriginalDeck();
|
||||
|
||||
for (Card c : compAntes) {
|
||||
PaperCard toRemove = CardDb.getCard(c);
|
||||
PaperCard toRemove = (PaperCard) c.getPaperCard();
|
||||
cDeck.getMain().remove(toRemove);
|
||||
if ( cDeck != oDeck )
|
||||
oDeck.getMain().remove(toRemove);
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardEdition;
|
||||
import forge.card.IUnOpenedProduct;
|
||||
import forge.card.SealedProductTemplate;
|
||||
@@ -141,7 +140,7 @@ public class QuestWinLose extends ControlWinLose {
|
||||
continue;
|
||||
}
|
||||
for (Card c : p.getCardsIn(ZoneType.Ante)) {
|
||||
anteCards.add(CardDb.getCard(c));
|
||||
anteCards.add(c.getPaperCard());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,7 +542,7 @@ public class QuestWinLose extends ControlWinLose {
|
||||
String preferredFormat = Singletons.getModel().getQuestPreferences().getPref(QPref.BOOSTER_FORMAT);
|
||||
|
||||
GameFormat pref = null;
|
||||
for (GameFormat f : Singletons.getModel().getFormats()) {
|
||||
for (GameFormat f : Singletons.getMagicDb().getFormats()) {
|
||||
formats.add(f);
|
||||
if (f.toString().equals(preferredFormat)) {
|
||||
pref = f;
|
||||
@@ -564,7 +563,7 @@ public class QuestWinLose extends ControlWinLose {
|
||||
} else {
|
||||
final List<String> sets = new ArrayList<String>();
|
||||
|
||||
for (SealedProductTemplate bd : Singletons.getModel().getBoosters()) {
|
||||
for (SealedProductTemplate bd : Singletons.getMagicDb().getBoosters()) {
|
||||
if (bd != null && qData.getFormat().isSetLegal(bd.getEdition())) {
|
||||
sets.add(bd.getEdition());
|
||||
}
|
||||
@@ -585,13 +584,13 @@ public class QuestWinLose extends ControlWinLose {
|
||||
int ix = MyRandom.getRandom().nextInt(sets.size());
|
||||
String set = sets.get(ix);
|
||||
sets.remove(ix);
|
||||
options.add(Singletons.getModel().getEditions().get(set));
|
||||
options.add(Singletons.getMagicDb().getEditions().get(set));
|
||||
maxChoices--;
|
||||
}
|
||||
|
||||
final CardEdition chooseEd = GuiChoose.one("Choose bonus booster set:", options);
|
||||
|
||||
IUnOpenedProduct product = new UnOpenedProduct(Singletons.getModel().getBoosters().get(chooseEd.getCode()));
|
||||
IUnOpenedProduct product = new UnOpenedProduct(Singletons.getMagicDb().getBoosters().get(chooseEd.getCode()));
|
||||
cardsWon = product.get();
|
||||
qData.getCards().addAllCards(cardsWon);
|
||||
this.lblTemp1 = new TitleLabel("Bonus " + chooseEd.getName() + " booster pack!");
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class CardManager extends ItemManager<PaperCard> {
|
||||
@Override
|
||||
protected void buildFilterMenu(JPopupMenu menu) {
|
||||
JMenu fmt = new JMenu("Format");
|
||||
for (final GameFormat f : Singletons.getModel().getFormats()) {
|
||||
for (final GameFormat f : Singletons.getMagicDb().getFormats()) {
|
||||
GuiUtils.addMenuItem(fmt, f.getName(), null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -48,9 +48,9 @@ import forge.gui.toolbox.itemmanager.filters.ItemFilter;
|
||||
import forge.gui.toolbox.itemmanager.table.ItemTable;
|
||||
import forge.gui.toolbox.itemmanager.table.ItemTableModel;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
import forge.util.TypeUtil;
|
||||
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.ItemPoolView;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -12,8 +12,8 @@ import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.SkinImage;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.ItemPoolView;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ import forge.gui.toolbox.itemmanager.ItemManagerModel;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerIO;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.ColumnName;
|
||||
import forge.gui.toolbox.itemmanager.table.SColumnUtil.SortState;
|
||||
import forge.item.ItemPoolSorter;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.ItemPoolSorter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -317,7 +317,7 @@ public final class SColumnUtil {
|
||||
}
|
||||
|
||||
private static CardEdition toSetCmp(final InventoryItem i) {
|
||||
return i instanceof InventoryItemFromSet ? Singletons.getModel().getEditions()
|
||||
return i instanceof InventoryItemFromSet ? Singletons.getMagicDb().getEditions()
|
||||
.get(((InventoryItemFromSet) i).getEdition()) : CardEdition.UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class SetCodeRenderer extends DefaultTableCellRenderer implements AlwaysS
|
||||
String setAbbrev = getText();
|
||||
String setFullName = "Unknown set";
|
||||
|
||||
EditionCollection editions = Singletons.getModel().getEditions();
|
||||
EditionCollection editions = Singletons.getMagicDb().getEditions();
|
||||
|
||||
if (null != setAbbrev && editions.contains(setAbbrev)) {
|
||||
setFullName = editions.get(setAbbrev).getName();
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import forge.item.ItemPoolSorter;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.ItemPoolSorter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -83,16 +83,16 @@ public enum CCardScript implements ICDoc {
|
||||
String text = "";
|
||||
boolean editable = false;
|
||||
if (this.currentCard != null) {
|
||||
File sourceFile = this.currentCard.getRules().getSourceFile();
|
||||
if (sourceFile != null) {
|
||||
try {
|
||||
text = FileUtil.readFileToString(sourceFile);
|
||||
editable = true;
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
text = "Couldn't read file - " + sourceFile + "\n\nException:\n" + ex.toString();
|
||||
}
|
||||
}
|
||||
// File sourceFile = this.currentCard.getRules().getSourceFile();
|
||||
// if (sourceFile != null) {
|
||||
// try {
|
||||
// text = FileUtil.readFileToString(sourceFile);
|
||||
// editable = true;
|
||||
// }
|
||||
// catch (final Exception ex) {
|
||||
// text = "Couldn't read file - " + sourceFile + "\n\nException:\n" + ex.toString();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
this.baseText = text;
|
||||
|
||||
@@ -129,28 +129,29 @@ public enum CCardScript implements ICDoc {
|
||||
public boolean saveChanges() {
|
||||
if (!hasChanges()) { return true; } //not need if text hasn't been changed
|
||||
|
||||
File sourceFile = this.currentCard.getRules().getSourceFile();
|
||||
if (sourceFile == null) { return true; }
|
||||
|
||||
try {
|
||||
String text = VCardScript.SINGLETON_INSTANCE.getTxtScript().getText();
|
||||
|
||||
PrintWriter p = new PrintWriter(sourceFile);
|
||||
p.print(text);
|
||||
p.close();
|
||||
|
||||
this.baseText = text;
|
||||
updateDirtyFlag();
|
||||
|
||||
this.currentCard.updateRules(text);
|
||||
VWorkshopCatalog.SINGLETON_INSTANCE.getCardManager().repaint();
|
||||
CDetail.SINGLETON_INSTANCE.showCard(this.currentCard);
|
||||
CPicture.SINGLETON_INSTANCE.showImage(this.currentCard);
|
||||
return true;
|
||||
} catch (final Exception ex) {
|
||||
JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "FileUtil : writeFile() error, problem writing file - " + sourceFile + " : " + ex);
|
||||
return false;
|
||||
}
|
||||
// File sourceFile = this.currentCard.getRules().getSourceFile();
|
||||
// if (sourceFile == null) { return true; }
|
||||
//
|
||||
// try {
|
||||
// String text = VCardScript.SINGLETON_INSTANCE.getTxtScript().getText();
|
||||
//
|
||||
// PrintWriter p = new PrintWriter(sourceFile);
|
||||
// p.print(text);
|
||||
// p.close();
|
||||
//
|
||||
// this.baseText = text;
|
||||
// updateDirtyFlag();
|
||||
//
|
||||
// this.currentCard.updateRules(text);
|
||||
// VWorkshopCatalog.SINGLETON_INSTANCE.getCardManager().repaint();
|
||||
// CDetail.SINGLETON_INSTANCE.showCard(this.currentCard);
|
||||
// CPicture.SINGLETON_INSTANCE.showImage(this.currentCard);
|
||||
// return true;
|
||||
// } catch (final Exception ex) {
|
||||
// JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "FileUtil : writeFile() error, problem writing file - " + sourceFile + " : " + ex);
|
||||
// return false;
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
|
||||
//========== Overridden methods
|
||||
|
||||
@@ -174,7 +174,7 @@ public enum CWorkshopCatalog implements ICDoc {
|
||||
}
|
||||
}, canSearch());
|
||||
JMenu fmt = new JMenu("Format");
|
||||
for (final GameFormat f : Singletons.getModel().getFormats()) {
|
||||
for (final GameFormat f : Singletons.getMagicDb().getFormats()) {
|
||||
GuiUtils.addMenuItem(fmt, f.getName(), null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -490,7 +490,7 @@ public enum CWorkshopCatalog implements ICDoc {
|
||||
}
|
||||
|
||||
private Pair<FLabel, Predicate<PaperCard>> buildFormatRestriction(String displayName, GameFormat format, boolean allowReprints) {
|
||||
EditionCollection editions = Singletons.getModel().getEditions();
|
||||
EditionCollection editions = Singletons.getMagicDb().getEditions();
|
||||
StringBuilder tooltip = new StringBuilder("<html>Sets:");
|
||||
|
||||
int lastLen = 0;
|
||||
|
||||
@@ -18,7 +18,7 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.Command;
|
||||
import forge.card.CardDb;
|
||||
import forge.Singletons;
|
||||
import forge.gui.WrapLayout;
|
||||
import forge.gui.deckeditor.views.VCardCatalog.RangeTypes;
|
||||
import forge.gui.framework.DragCell;
|
||||
@@ -37,8 +37,8 @@ import forge.gui.toolbox.itemmanager.ItemManagerContainer;
|
||||
import forge.gui.toolbox.itemmanager.SItemManagerUtil;
|
||||
import forge.gui.workshop.controllers.CCardScript;
|
||||
import forge.gui.workshop.controllers.CWorkshopCatalog;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.ItemPool;
|
||||
|
||||
/**
|
||||
* Assembles Swing components of card catalog in workshop.
|
||||
@@ -125,7 +125,7 @@ public enum VWorkshopCatalog implements IVDoc<CWorkshopCatalog> {
|
||||
}
|
||||
|
||||
this.cardManager = new CardManager(this.statLabels, true);
|
||||
this.cardManager.setPool(ItemPool.createFrom(CardDb.instance().getAllCards(), PaperCard.class), true);
|
||||
this.cardManager.setPool(ItemPool.createFrom(Singletons.getMagicDb().getCommonCards().getAllCards(), PaperCard.class), true);
|
||||
this.cardManagerContainer.setItemManager(this.cardManager);
|
||||
|
||||
this.cardManager.addSelectionListener(new ListSelectionListener() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user