From 58a333ef9906f11365f362d1d4a69c8293e892f0 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sun, 16 Jun 2013 22:26:38 +0000 Subject: [PATCH] removed unused classes, removed literals for basic lands --- .gitattributes | 2 - src/main/java/forge/Constant.java | 5 +- src/main/java/forge/card/CardDb.java | 1 - src/main/java/forge/card/CardEdition.java | 15 +- .../card/cardfactory/CardFactoryUtil.java | 6 +- src/main/java/forge/game/GameActionUtil.java | 13 - .../java/forge/game/limited/BoosterDraft.java | 8 +- src/main/java/forge/game/limited/CCnt.java | 108 ------ .../forge/game/limited/CustomLimited.java | 4 +- .../forge/game/limited/IBoosterDraft.java | 3 +- .../game/limited/LimitedDeckBuilder.java | 87 ++--- .../forge/game/limited/ReadDraftRankings.java | 5 +- .../game/limited/SealedCardPoolGenerator.java | 3 +- .../java/forge/gui/deckeditor/MenuCommon.java | 313 ------------------ .../gui/deckeditor/controllers/CDeckgen.java | 9 +- .../controllers/CEditorDraftingProcess.java | 12 +- src/main/java/forge/quest/QuestUtilCards.java | 8 +- .../java/forge/quest/io/ReadPriceList.java | 7 +- 18 files changed, 66 insertions(+), 543 deletions(-) delete mode 100644 src/main/java/forge/game/limited/CCnt.java delete mode 100644 src/main/java/forge/gui/deckeditor/MenuCommon.java diff --git a/.gitattributes b/.gitattributes index ea6b510a8b1..aa24db74f63 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14483,7 +14483,6 @@ src/main/java/forge/game/event/package-info.java -text src/main/java/forge/game/limited/BoosterDeckBuilder.java -text src/main/java/forge/game/limited/BoosterDraft.java svneol=native#text/plain src/main/java/forge/game/limited/BoosterDraftAI.java svneol=native#text/plain -src/main/java/forge/game/limited/CCnt.java svneol=native#text/plain src/main/java/forge/game/limited/CardRankingComparator.java -text src/main/java/forge/game/limited/CustomLimited.java svneol=native#text/plain src/main/java/forge/game/limited/DeckColors.java svneol=native#text/plain @@ -14554,7 +14553,6 @@ src/main/java/forge/gui/UnsortedListModel.java -text src/main/java/forge/gui/WrapLayout.java -text src/main/java/forge/gui/deckeditor/CDeckEditorUI.java -text src/main/java/forge/gui/deckeditor/DeckImport.java -text -src/main/java/forge/gui/deckeditor/MenuCommon.java svneol=native#text/plain src/main/java/forge/gui/deckeditor/SEditorIO.java -text src/main/java/forge/gui/deckeditor/SEditorUtil.java -text src/main/java/forge/gui/deckeditor/SFilterUtil.java -text diff --git a/src/main/java/forge/Constant.java b/src/main/java/forge/Constant.java index 5583599972c..cb1950ccf29 100644 --- a/src/main/java/forge/Constant.java +++ b/src/main/java/forge/Constant.java @@ -18,8 +18,6 @@ package forge; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import com.google.common.collect.ImmutableList; @@ -87,7 +85,8 @@ public final class Constant { public static final String SNOW = "snow"; /** The Basic lands. */ - public static final List BASIC_LANDS = Collections.unmodifiableList(Arrays.asList("Plains", "Island", "Swamp", "Mountain", "Forest")); + public static final List BASIC_LANDS = ImmutableList.of("Plains", "Island", "Swamp", "Mountain", "Forest"); + public static final List SNOW_LANDS = ImmutableList.of("Snow-Covered Plains", "Snow-Covered Island", "Snow-Covered Swamp", "Snow-Covered Mountain", "Snow-Covered Forest"); } /** diff --git a/src/main/java/forge/card/CardDb.java b/src/main/java/forge/card/CardDb.java index 0dee6eb0014..51b85e5d406 100644 --- a/src/main/java/forge/card/CardDb.java +++ b/src/main/java/forge/card/CardDb.java @@ -344,7 +344,6 @@ public final class CardDb implements ICardDatabase { } } - public Predicate wasPrintedInSets(List setCodes) { return new PredicateExistsInSets(setCodes); } diff --git a/src/main/java/forge/card/CardEdition.java b/src/main/java/forge/card/CardEdition.java index 7273f5c191e..637675d6acd 100644 --- a/src/main/java/forge/card/CardEdition.java +++ b/src/main/java/forge/card/CardEdition.java @@ -31,10 +31,12 @@ 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; @@ -326,19 +328,16 @@ public final class CardEdition implements Comparable { // immutable } }; } + + public final static CardEdition getRandomSetWithAllBasicLands(Iterable allEditions) { + return Aggregates.random(Iterables.filter(allEditions, CardEdition.Predicates.hasBasicLands)); + } - /** - * TODO: Write javadoc for this method. - * @return - */ public int getCntBoosterPictures() { return boosterArts; } - /** - * TODO: Write javadoc for this method. - * @return - */ + public SealedProductTemplate getBoosterTemplate() { return boosterTpl; } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index 5b724aac399..0b62fe17e97 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -1034,10 +1034,10 @@ public class CardFactoryUtil { int n = 0; final List someCards = new ArrayList(); someCards.addAll(player.getCardsIn(ZoneType.Battlefield)); - final String[] basic = { "Forest", "Plains", "Mountain", "Island", "Swamp" }; + final List basic = Constant.Color.BASIC_LANDS; - for (int i = 0; i < basic.length; i++) { - if (!CardLists.getType(someCards, basic[i]).isEmpty()) { + for (int i = 0; i < basic.size(); i++) { + if (!CardLists.getType(someCards, basic.get(i)).isEmpty()) { n++; } } diff --git a/src/main/java/forge/game/GameActionUtil.java b/src/main/java/forge/game/GameActionUtil.java index b6e8b3ac5fe..f785dd83f17 100644 --- a/src/main/java/forge/game/GameActionUtil.java +++ b/src/main/java/forge/game/GameActionUtil.java @@ -637,19 +637,6 @@ public final class GameActionUtil { * @return the stLandManaAbilities */ public static void grantBasicLandsManaAbilities(Game game) { - /* - * for future use boolean naked = - * AllZoneUtil.isCardInPlay("Naked Singularity"); boolean twist = - * AllZoneUtil.isCardInPlay("Reality Twist"); //set up what they - * produce produces.put("Forest", naked || twist ? "B" : "G"); - * produces.put("Island", naked == true ? "G" : "U"); if(naked) - * produces.put("Mountain", "U"); else if(twist) - * produces.put("Mountain", "W"); else produces.put("Mountain", - * "R"); produces.put("Plains", naked || twist ? "R" : "W"); - * if(naked) produces.put("Swamp", "W"); else if(twist) - * produces.put("Swamp", "G"); else produces.put("Swamp", "B"); - */ - List lands = game.getCardsIn(ZoneType.Battlefield); lands = CardLists.filter(lands, Presets.LANDS); diff --git a/src/main/java/forge/game/limited/BoosterDraft.java b/src/main/java/forge/game/limited/BoosterDraft.java index 5bd78e02b94..37fec4c0789 100644 --- a/src/main/java/forge/game/limited/BoosterDraft.java +++ b/src/main/java/forge/game/limited/BoosterDraft.java @@ -32,6 +32,7 @@ import javax.swing.JOptionPane; import org.apache.commons.lang.ArrayUtils; import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; import forge.Card; import forge.Constant.Preferences; @@ -49,6 +50,7 @@ import forge.item.IPaperCard; import forge.item.ItemPool; import forge.item.ItemPoolView; import forge.properties.NewConstants; +import forge.util.Aggregates; import forge.util.FileUtil; import forge.util.HttpUtil; import forge.util.storage.IStorageView; @@ -90,7 +92,7 @@ public final class BoosterDraft implements IBoosterDraft { Supplier> s = new UnOpenedProduct(SealedProductTemplate.genericBooster); for (int i = 0; i < 3; i++) this.product.add(s); - IBoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getEdition(); + IBoosterDraft.LAND_SET_CODE[0] = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions()); break; case Block: case FantasyBlock: // Draft from cards by block or set @@ -133,7 +135,7 @@ public final class BoosterDraft implements IBoosterDraft { } } - IBoosterDraft.LAND_SET_CODE[0] = block.getLandSet().getCode(); + IBoosterDraft.LAND_SET_CODE[0] = block.getLandSet(); break; case Custom: @@ -169,7 +171,7 @@ public final class BoosterDraft implements IBoosterDraft { this.product.add(toAdd); } - IBoosterDraft.LAND_SET_CODE[0] = draft.getLandSetCode(); + IBoosterDraft.LAND_SET_CODE[0] = Singletons.getModel().getEditions().get(draft.getLandSetCode()); } /** Looks for res/draft/*.draft files, reads them, returns a list. */ diff --git a/src/main/java/forge/game/limited/CCnt.java b/src/main/java/forge/game/limited/CCnt.java deleted file mode 100644 index 2279b4096b5..00000000000 --- a/src/main/java/forge/game/limited/CCnt.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.game.limited; - -/** - *

- * CCnt class. - *

- * - * @author Forge - * @version $Id$ - */ -class CCnt implements Comparable { - - /** The Color. */ - private String color; - - /** The Count. */ - private int count; - - /** - *

- * Constructor for CCnt. - *

- * - * @param clr - * a {@link java.lang.String} object. - * @param cnt - * a int. - */ - /** - *

- * deckColors class. - *

- * - * @param clr - * a {@link java.lang.String} object. - * @param cnt - * a int. - */ - public CCnt(final String clr, final int cnt) { - this.setColor(clr); - this.setCount(cnt); - } - - /** - * Gets the color. - * - * @return the color - */ - public String getColor() { - return this.color; - } - - /** - * Sets the color. - * - * @param color0 - * the color to set - */ - public void setColor(final String color0) { - this.color = color0; - } - - /** - * Gets the count. - * - * @return the count - */ - public int getCount() { - return this.count; - } - - /** - * Sets the count. - * - * @param count0 - * the count to set - */ - public void setCount(final int count0) { - this.count = count0; - } - - /* (non-Javadoc) - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(CCnt o) { - int compareCount = o.getCount(); - return this.count - compareCount; - } - -} diff --git a/src/main/java/forge/game/limited/CustomLimited.java b/src/main/java/forge/game/limited/CustomLimited.java index c4efe22626d..fecbc8b6cb0 100644 --- a/src/main/java/forge/game/limited/CustomLimited.java +++ b/src/main/java/forge/game/limited/CustomLimited.java @@ -24,7 +24,9 @@ import org.apache.commons.lang3.StringUtils; 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.SealedProductTemplate; import forge.deck.Deck; import forge.deck.DeckBase; @@ -65,7 +67,7 @@ public class CustomLimited extends DeckBase { private transient ItemPoolView cardPool; /** The Land set code. */ - private String landSetCode = CardDb.instance().getCard("Plains", true).getEdition(); + private String landSetCode = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions()).getCode(); private boolean singleton; diff --git a/src/main/java/forge/game/limited/IBoosterDraft.java b/src/main/java/forge/game/limited/IBoosterDraft.java index d52dc1d5938..5a19ae294f1 100644 --- a/src/main/java/forge/game/limited/IBoosterDraft.java +++ b/src/main/java/forge/game/limited/IBoosterDraft.java @@ -17,6 +17,7 @@ */ package forge.game.limited; +import forge.card.CardEdition; import forge.deck.Deck; import forge.item.PaperCard; import forge.item.ItemPoolView; @@ -68,7 +69,7 @@ public interface IBoosterDraft { Deck[] getDecks(); // size 7, all the computers decks /** Constant LandSetCode="{}". */ - String[] LAND_SET_CODE = { "" }; + CardEdition[] LAND_SET_CODE = { null }; /** * Called when drafting is over - to upload picks. diff --git a/src/main/java/forge/game/limited/LimitedDeckBuilder.java b/src/main/java/forge/game/limited/LimitedDeckBuilder.java index be93cea168d..8731e15b2e4 100644 --- a/src/main/java/forge/game/limited/LimitedDeckBuilder.java +++ b/src/main/java/forge/game/limited/LimitedDeckBuilder.java @@ -1,7 +1,6 @@ package forge.game.limited; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -17,9 +16,12 @@ 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.CardRules; import forge.card.CardRulesPredicates; import forge.card.ColorSet; @@ -164,7 +166,7 @@ public class LimitedDeckBuilder { addNonBasicLands(); // 11. Fill up with basic lands. - final CCnt[] clrCnts = calculateLandNeeds(); + final int[] clrCnts = calculateLandNeeds(); if (landsNeeded > 0) { addLands(clrCnts); } @@ -226,7 +228,7 @@ public class LimitedDeckBuilder { * @param clrCnts * color counts needed */ - private void fixDeckSize(final CCnt[] clrCnts) { + private void fixDeckSize(final int[] clrCnts) { while (deckList.size() > 40) { System.out.println("WARNING: Fixing deck size, currently " + deckList.size() + " cards."); final PaperCard c = deckList.get(MyRandom.getRandom().nextInt(deckList.size() - 1)); @@ -250,8 +252,8 @@ public class LimitedDeckBuilder { } else { // if no playable cards remain fill up with basic lands for (int i = 0; i < 5; i++) { - if (clrCnts[i].getCount() > 0) { - final PaperCard cp = getBasicLand(clrCnts[i].getColor()); + if (clrCnts[i] > 0) { + final PaperCard cp = getBasicLand(i); deckList.add(cp); System.out.println(" - Added " + cp.getName() + " as last resort."); break; @@ -267,9 +269,9 @@ public class LimitedDeckBuilder { private void findBasicLandSets() { Set sets = new HashSet(); for (PaperCard cp : aiPlayables) { - if (null != CardDb.instance().tryGetCard("Plains", cp.getEdition())) { + CardEdition ee = Singletons.getModel().getEditions().get(cp.edition); + if( !sets.contains(cp.getEdition()) && CardEdition.Predicates.hasBasicLands.apply(ee)) sets.add(cp.getEdition()); - } } setsWithBasicLands.addAll(sets); if (setsWithBasicLands.isEmpty()) { @@ -282,12 +284,12 @@ public class LimitedDeckBuilder { * * @param clrCnts */ - private void addLands(final CCnt[] clrCnts) { + private void addLands(final int[] clrCnts) { // total of all ClrCnts int totalColor = 0; for (int i = 0; i < 5; i++) { - totalColor += clrCnts[i].getCount(); + totalColor += clrCnts[i]; } if (totalColor == 0) { throw new RuntimeException("Add Lands to empty deck list!"); @@ -295,44 +297,20 @@ public class LimitedDeckBuilder { // do not update landsNeeded until after the loop, because the // calculation involves landsNeeded - int landsAdded = 0; for (int i = 0; i < 5; i++) { - if (clrCnts[i].getCount() > 0) { + if (clrCnts[i] > 0) { // calculate number of lands for each color - final float p = (float) clrCnts[i].getCount() / (float) totalColor; - final int nLand = (int) (landsNeeded * p); // desired truncation - // to int + 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.println("Basics[" + clrCnts[i].getColor() + "]: " + clrCnts[i].getCount() + "/" - + totalColor + " = " + p + " = " + nLand); + System.out.printf("Basics[%s]: %d/%d = %f%% = %d cards", Constant.Color.BASIC_LANDS.get(i), clrCnts[i], totalColor, 100*p, nLand); } for (int j = 0; j < nLand; j++) { - deckList.add(getBasicLand(clrCnts[i].getColor())); - landsAdded++; + deckList.add(getBasicLand(i)); } } } - - // Add extra lands to get up to the right number. - // Start with the smallest CCnt to "even out" a little. - landsNeeded -= landsAdded; - Arrays.sort(clrCnts); - int n = 0; - while (landsNeeded > 0) { - if (clrCnts[n].getCount() > 0) { - final PaperCard cp = getBasicLand(clrCnts[n].getColor()); - deckList.add(cp); - landsNeeded--; - - if (Preferences.DEV_MODE) { - System.out.println("AddBasics: " + cp.getName()); - } - } - if (++n > 4) { - n = 0; - } - } } /** @@ -341,14 +319,14 @@ public class LimitedDeckBuilder { * @param basicLand * @return card */ - private PaperCard getBasicLand(String basicLand) { + private PaperCard getBasicLand(int basicLand) { String set; if (setsWithBasicLands.size() > 1) { set = setsWithBasicLands.get(MyRandom.getRandom().nextInt(setsWithBasicLands.size() - 1)); } else { set = setsWithBasicLands.get(0); } - return CardDb.instance().getCard(basicLand, set); + return CardDb.instance().getCard(Constant.Color.BASIC_LANDS.get(basicLand), set); } /** @@ -359,32 +337,19 @@ public class LimitedDeckBuilder { * * @return CCnt */ - private CCnt[] calculateLandNeeds() { - final CCnt[] clrCnts = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0), - new CCnt("Mountain", 0), new CCnt("Forest", 0) }; + private int[] calculateLandNeeds() { + final int[] clrCnts = { 0,0,0,0,0 }; // count each card color using mana costs - for (int i = 0; i < deckList.size(); i++) { - final ManaCost mc = deckList.get(i).getRules().getManaCost(); + for (PaperCard cp : deckList) { + final ManaCost mc = cp.getRules().getManaCost(); // count each mana symbol in the mana cost for (ManaCostShard shard : mc.getShards()) { - byte mask = shard.getColorMask(); - - if ((mask & MagicColor.WHITE) > 0 && colors.hasWhite()) { - clrCnts[0].setCount(clrCnts[0].getCount() + 1); - } - if ((mask & MagicColor.BLUE) > 0 && colors.hasBlue()) { - clrCnts[1].setCount(clrCnts[1].getCount() + 1); - } - if ((mask & MagicColor.BLACK) > 0 && colors.hasBlack()) { - clrCnts[2].setCount(clrCnts[2].getCount() + 1); - } - if ((mask & MagicColor.RED) > 0 && colors.hasRed()) { - clrCnts[3].setCount(clrCnts[3].getCount() + 1); - } - if ((mask & MagicColor.GREEN) > 0 && colors.hasGreen()) { - clrCnts[4].setCount(clrCnts[4].getCount() + 1); + for ( int i = 0 ; i < MagicColor.WUBRG.length; i++ ) { + byte c = MagicColor.WUBRG[i]; + if ( shard.canBePaidWithManaOfColor(c) && colors.hasAnyColor(c)) + clrCnts[i]++; } } } diff --git a/src/main/java/forge/game/limited/ReadDraftRankings.java b/src/main/java/forge/game/limited/ReadDraftRankings.java index 1517b353f3a..aee635eff03 100644 --- a/src/main/java/forge/game/limited/ReadDraftRankings.java +++ b/src/main/java/forge/game/limited/ReadDraftRankings.java @@ -6,6 +6,7 @@ import java.util.Map; import com.esotericsoftware.minlog.Log; +import forge.Constant; import forge.properties.NewConstants; import forge.util.FileUtil; @@ -90,10 +91,8 @@ public class ReadDraftRankings { Double rank = null; // Basic lands should be excluded from the evaluation --BBU - if (cardName.equals("Island") || cardName.equals("Forest") || cardName.equals("Swamp") - || cardName.equals("Plains") || cardName.equals("Mountain")) { + if ( Constant.Color.BASIC_LANDS.contains(cardName)) return null; - } if (draftRankings.containsKey(edition)) { String safeName = cardName.replaceAll("-", " ").replaceAll("[^A-Za-z ]", ""); diff --git a/src/main/java/forge/game/limited/SealedCardPoolGenerator.java b/src/main/java/forge/game/limited/SealedCardPoolGenerator.java index 6ceb2cb527d..a4ef1444719 100644 --- a/src/main/java/forge/game/limited/SealedCardPoolGenerator.java +++ b/src/main/java/forge/game/limited/SealedCardPoolGenerator.java @@ -28,7 +28,6 @@ import org.apache.commons.lang.ArrayUtils; import forge.Singletons; import forge.card.CardBlock; -import forge.card.CardDb; import forge.card.CardEdition; import forge.card.IUnOpenedProduct; import forge.card.SealedProductTemplate; @@ -72,7 +71,7 @@ public class SealedCardPoolGenerator { // Choose number of boosters chooseNumberOfBoosters(new UnOpenedProduct(SealedProductTemplate.genericBooster)); - landSetCode = CardDb.instance().getCard("Plains").getEdition(); + landSetCode = CardEdition.getRandomSetWithAllBasicLands(Singletons.getModel().getEditions()).getCode(); break; case Block: diff --git a/src/main/java/forge/gui/deckeditor/MenuCommon.java b/src/main/java/forge/gui/deckeditor/MenuCommon.java deleted file mode 100644 index 9d74f5fd588..00000000000 --- a/src/main/java/forge/gui/deckeditor/MenuCommon.java +++ /dev/null @@ -1,313 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - - -/** - *

- * Gui_DeckEditor_Menu class. - *

- * - * @author Forge - * @version $Id$ - */ -public final class MenuCommon { - - /** Constant serialVersionUID=-4037993759604768755L. * - private static final long serialVersionUID = -4037993759604768755L; - /** Constant previousDirectory. * - private static File previousDirectory = null; - - /** - * Menu for Deck Editor. - * - * @param ctrl - * the ctrl - * @param exit - * a Command - * - public MenuCommon(final DeckController ctrl, final Command exit) { - super(ctrl, exit); - - // this is added just to make save() and saveAs() work ok - // when first started up, just a silly patch - - } - - private void newRandomConstructed() { - if (!this.canLeaveCurrentDeck()) { - return; - } - - final Deck randomDeck = new Deck(); - - // The only remaining reference to global variable! - - - randomDeck.getMain().addAllFlat(Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND) - .random(CardDb.instance().getAllUniqueCards(), CardPrinted.FN_GET_RULES, 15 * 5)); - randomDeck.getMain().add("Plains"); - randomDeck.getMain().add("Island"); - randomDeck.getMain().add("Swamp"); - randomDeck.getMain().add("Mountain"); - randomDeck.getMain().add("Forest"); - randomDeck.getMain().add("Terramorphic Expanse"); - - this.getController().setModel(randomDeck); - } - - private void newGenerateConstructed() { - if (!this.canLeaveCurrentDeck()) { - return; - } - - final Deck genConstructed = new Deck(); - genConstructed.getMain().addAll((new Generate2ColorDeck("AI", "AI")).get2ColorDeck(60, PlayerType.HUMAN)); - this.getController().setModel(genConstructed); - } - - private File getImportFilename() { - final JFileChooser chooser = new JFileChooser(MenuCommon.previousDirectory); - - chooser.addChoosableFileFilter(DeckSerializer.DCK_FILTER); - final int returnVal = chooser.showOpenDialog(null); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - final File file = chooser.getSelectedFile(); - MenuCommon.previousDirectory = file.getParentFile(); - return file; - } - return null; - } // openFileDialog() - - private void importDeck() { - final File file = this.getImportFilename(); - if (file == null) { - } else if (file.getName().endsWith(".dck")) { - try { - this.getController().setModel(Deck.fromFile(file)); - - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex); - } - } - - } - - /** - *

- * exportDeck. - *

- * - private void exportDeck() { - final File filename = this.getExportFilename(); - if (filename == null) { - return; - } - - try { - DeckSerializer.writeDeck(this.getController().getModel(), filename); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex); - } - } - - private File getExportFilename() { - final JFileChooser save = new JFileChooser(MenuCommon.previousDirectory); - save.setDialogTitle("Export Deck Filename"); - save.setDialogType(JFileChooser.SAVE_DIALOG); - save.setFileFilter(DeckSerializer.DCK_FILTER); - - if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { - final File file = save.getSelectedFile(); - final String check = file.getAbsolutePath(); - - MenuCommon.previousDirectory = file.getParentFile(); - - return check.endsWith(".dck") ? file : new File(check + ".dck"); - } - return null; - } - - /** - *

- * Generate Proxy for a Deck. - *

- * - private void generateProxies() { - final File filename = this.getProxiesFilename(); - if (filename == null) { - return; - } - - try { - DeckSerializer.writeDeckHtml(this.getController().getModel(), filename); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : printProxies() error, " + ex); - } - } - - private File getProxiesFilename() { - final JFileChooser save = new JFileChooser(MenuCommon.previousDirectory); - save.setDialogTitle("Proxy HTML Filename"); - save.setDialogType(JFileChooser.SAVE_DIALOG); - save.setFileFilter(DeckSerializer.HTML_FILTER); - - if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { - final File file = save.getSelectedFile(); - final String check = file.getAbsolutePath(); - - MenuCommon.previousDirectory = file.getParentFile(); - - return check.endsWith(".html") ? file : new File(check + ".html"); - } - return null; - } - - // deck.setName(currentDeckName); - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.MenuBase#getDefaultFileMenu() - * - @Override - protected JMenu getDefaultFileMenu() { - final JMenu fileMenu = super.getDefaultFileMenu(); - - final JMenuItem newRandomConstructed = new JMenuItem("New Deck - Generate Random Constructed Cardpool"); - final JMenuItem newGenerateConstructed = new JMenuItem("New Deck - Generate Constructed Deck"); - - final JMenuItem importDeck = new JMenuItem("Import Deck..."); - final JMenuItem exportDeck = new JMenuItem("Export Deck..."); - // JMenuItem downloadDeck = new JMenuItem("Download Deck"); - - // newDraftItem = newDraft; - // newDraftItem.setEnabled(false); - - // fileMenu.add(newSealed); - // fileMenu.add(newDraft); - fileMenu.addSeparator(); - - fileMenu.add(importDeck); - fileMenu.add(exportDeck); - - final JMenuItem generateProxies = new JMenuItem("Generate Proxies..."); - fileMenu.add(generateProxies); - - // fileMenu.add(downloadDeck); - fileMenu.addSeparator(); - - fileMenu.add(newRandomConstructed); - fileMenu.add(newGenerateConstructed); - - this.appendCloseMenuItemTo(fileMenu); - - generateProxies.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuCommon.this.generateProxies(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : generateProxies() error - " + ex); - } - } - }); - - // add listeners - exportDeck.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuCommon.this.exportDeck(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error - " + ex); - } - } - }); - - importDeck.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuCommon.this.importDeck(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error - " + ex); - } - } - }); - - newRandomConstructed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuCommon.this.newRandomConstructed(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex); - } - } - }); - - newGenerateConstructed.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuCommon.this.newGenerateConstructed(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : newRandomConstructed() error - " + ex); - } - } - }); - - return fileMenu; - } // setupMenu() - */ -} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java index 14a15ad81f8..51bd319812e 100644 --- a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java +++ b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java @@ -5,6 +5,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import forge.Command; +import forge.Constant; import forge.card.CardDb; import forge.card.CardRulesPredicates; import forge.deck.Deck; @@ -83,11 +84,9 @@ public enum CDeckgen implements ICDoc { Iterable source = Iterables.filter(CardDb.instance().getUniqueCards(), notBasicLand); randomDeck.getMain().addAllFlat(Aggregates.random(source, 15 * 5)); - randomDeck.getMain().add("Plains", 1); - randomDeck.getMain().add("Island", 1); - randomDeck.getMain().add("Swamp", 1); - randomDeck.getMain().add("Mountain", 1); - randomDeck.getMain().add("Forest", 1); + for(String landName : Constant.Color.BASIC_LANDS) { + randomDeck.getMain().add(landName, 1); + } randomDeck.getMain().add("Terramorphic Expanse", 1); final ACEditorBase ed = (ACEditorBase) diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java index 4b691e69d9d..34479efeeb6 100644 --- a/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java @@ -20,8 +20,10 @@ 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.control.FControl; import forge.deck.CardPool; import forge.deck.Deck; @@ -172,13 +174,11 @@ public class CEditorDraftingProcess extends ACEditorBase { CardPool side = deck.getOrCreate(DeckSection.Sideboard); side.addAll(this.getTableDeck().getCards()); - final String landSet = IBoosterDraft.LAND_SET_CODE[0]; + final CardEdition landSet = IBoosterDraft.LAND_SET_CODE[0]; final int landsCount = 20; - side.add(CardDb.instance().getCard("Forest", landSet), landsCount); - side.add(CardDb.instance().getCard("Mountain", landSet), landsCount); - side.add(CardDb.instance().getCard("Swamp", landSet), landsCount); - side.add(CardDb.instance().getCard("Island", landSet), landsCount); - side.add(CardDb.instance().getCard("Plains", landSet), landsCount); + for(String landName : Constant.Color.BASIC_LANDS) { + side.add(CardDb.instance().getCard(landName, landSet.getCode()), landsCount); + } return deck; } // getPlayersDeck() diff --git a/src/main/java/forge/quest/QuestUtilCards.java b/src/main/java/forge/quest/QuestUtilCards.java index c2ad9b86ad4..bf100f00b38 100644 --- a/src/main/java/forge/quest/QuestUtilCards.java +++ b/src/main/java/forge/quest/QuestUtilCards.java @@ -133,11 +133,9 @@ public final class QuestUtilCards { if (!snowLandCodes.isEmpty()) { String snowLandCode = Aggregates.random(snowLandCodes); - pool.add(db.getCard("Snow-Covered Forest", snowLandCode), nSnow); - pool.add(db.getCard("Snow-Covered Mountain", snowLandCode), nSnow); - pool.add(db.getCard("Snow-Covered Swamp", snowLandCode), nSnow); - pool.add(db.getCard("Snow-Covered Island", snowLandCode), nSnow); - pool.add(db.getCard("Snow-Covered Plains", snowLandCode), nSnow); + for(String landName : Constant.Color.SNOW_LANDS) { + pool.add(db.getCard(landName, snowLandCode), nSnow); + } } return pool; diff --git a/src/main/java/forge/quest/io/ReadPriceList.java b/src/main/java/forge/quest/io/ReadPriceList.java index 9a137ef3d33..7bf77b0a933 100644 --- a/src/main/java/forge/quest/io/ReadPriceList.java +++ b/src/main/java/forge/quest/io/ReadPriceList.java @@ -24,6 +24,7 @@ import java.util.Random; import com.esotericsoftware.minlog.Log; +import forge.Constant; import forge.properties.NewConstants; import forge.util.FileUtil; import forge.util.MyRandom; @@ -93,11 +94,7 @@ public class ReadPriceList { try { int val = Integer.parseInt(price.trim()); - if (!(name.equals("Plains") || name.equals("Island") || name.equals("Swamp") - || name.equals("Mountain") || name.equals("Forest") - || name.equals("Snow-Covered Plains") || name.equals("Snow-Covered Island") - || name.equals("Snow-Covered Swamp") || name.equals("Snow-Covered Mountain") || name - .equals("Snow-Covered Forest"))) { + if (!(Constant.Color.BASIC_LANDS.contains(name) || Constant.Color.SNOW_LANDS.contains(name))) { float ff = 0; if (r.nextInt(100) < 90) { ff = r.nextInt(10) * (float) .01;