diff --git a/.gitattributes b/.gitattributes index 1d450218c94..d2b0a0c188d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9754,8 +9754,8 @@ src/main/java/forge/card/trigger/Trigger_TurnFaceUp.java svneol=native#text/plai src/main/java/forge/card/trigger/Trigger_Unequip.java svneol=native#text/plain src/main/java/forge/card/trigger/Trigger_Untaps.java svneol=native#text/plain src/main/java/forge/card/trigger/package-info.java svneol=native#text/plain -src/main/java/forge/deck/Deck.java -text -src/main/java/forge/deck/DeckManager.java -text +src/main/java/forge/deck/Deck.java svneol=native#text/plain +src/main/java/forge/deck/DeckManager.java svneol=native#text/plain src/main/java/forge/deck/DownloadDeck.java svneol=native#text/plain src/main/java/forge/deck/generate/Generate2ColorDeck.java svneol=native#text/plain src/main/java/forge/deck/generate/Generate3ColorDeck.java svneol=native#text/plain @@ -9783,7 +9783,6 @@ src/main/java/forge/gui/ListChooser.java svneol=native#text/plain src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain src/main/java/forge/gui/MultiPhaseProgressMonitorWithETA.java svneol=native#text/plain -src/main/java/forge/gui/SelectablePanel.java -text src/main/java/forge/gui/deckeditor/CardPanelBase.java -text src/main/java/forge/gui/deckeditor/CardPanelHeavy.java -text src/main/java/forge/gui/deckeditor/CardPanelLite.java -text @@ -9832,10 +9831,6 @@ src/main/java/forge/properties/NewConstants.java svneol=native#text/plain src/main/java/forge/properties/Preferences.java svneol=native#text/plain src/main/java/forge/properties/SavePreferencesListener.java svneol=native#text/plain src/main/java/forge/properties/package-info.java svneol=native#text/plain -src/main/java/forge/quest/data/DeckSingleBattle.java svneol=native#text/plain -src/main/java/forge/quest/data/DeckSingleQuest.java svneol=native#text/plain -src/main/java/forge/quest/data/ManagerBattle.java svneol=native#text/plain -src/main/java/forge/quest/data/ManagerQuest.java -text src/main/java/forge/quest/data/QuestBattleManager.java svneol=native#text/plain src/main/java/forge/quest/data/QuestBoosterPack.java svneol=native#text/plain src/main/java/forge/quest/data/QuestData.java svneol=native#text/plain @@ -9867,11 +9862,8 @@ src/main/java/forge/quest/data/pet/QuestPetManager.java svneol=native#text/plain src/main/java/forge/quest/data/pet/QuestPetPlant.java svneol=native#text/plain src/main/java/forge/quest/data/pet/QuestPetWolf.java svneol=native#text/plain src/main/java/forge/quest/data/pet/package-info.java svneol=native#text/plain -src/main/java/forge/quest/gui/PanelSingleBattle.java -text -src/main/java/forge/quest/gui/PanelSingleQuest.java -text src/main/java/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestFrame.java svneol=native#text/plain -src/main/java/forge/quest/gui/QuestMainPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestOptions.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarItem.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarPanel.java svneol=native#text/plain @@ -9940,6 +9932,7 @@ src/test/java/forge/GuiWinLoseTest.java svneol=native#text/plain src/test/java/forge/PanelTest.java svneol=native#text/plain src/test/java/forge/PhaseTest.java svneol=native#text/plain src/test/java/forge/ReadBoosterPackTest.java svneol=native#text/plain +src/test/java/forge/ReadQuestAssignmentTest.java svneol=native#text/plain src/test/java/forge/RunTest.java svneol=native#text/plain src/test/java/forge/TinyTest.java svneol=native#text/plain src/test/java/forge/card/cardFactory/CardFactoryTest.java svneol=native#text/plain diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java index 3f7f2ef3ea1..41fe213057a 100644 --- a/src/main/java/forge/AllZone.java +++ b/src/main/java/forge/AllZone.java @@ -17,7 +17,6 @@ import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.quest.data.QuestMatchState; import forge.quest.data.QuestData; -import forge.quest.data.DeckSingleQuest; /** * Please use public getters and setters instead of direct field access. @@ -41,9 +40,9 @@ public final class AllZone implements NewConstants { /** Global questData. */ private static forge.quest.data.QuestData questData = null; - - /** Global currentQuest. */ - private static forge.quest.data.DeckSingleQuest currentQuest = null; + + /** Global QuestAssignment. */ + private static Quest_Assignment questAssignment = null; /** Constant NAME_CHANGER. */ private static final NameChanger NAME_CHANGER = new NameChanger(); @@ -130,25 +129,25 @@ public final class AllZone implements NewConstants { public static void setQuestData(final QuestData questData0) { questData = questData0; } - + /** - *

getCurrentQuest.

+ *

getQuestAssignment.

* - * @return a {@link forge.quest.data.QuestData} object. - * + * @return a {@link forge.Quest_Assignment} object. + * @since 1.0.15 */ - public static forge.quest.data.DeckSingleQuest getCurrentQuest() { - return currentQuest; + public static Quest_Assignment getQuestAssignment() { + return questAssignment; } /** - *

setCurrentQuest.

+ *

setQuestAssignment.

* - * @param a DeckSingleQuest object. - * + * @param assignment a {@link forge.Quest_Assignment} object. + * @since 1.0.15 */ - public static void setCurrentQuest(final DeckSingleQuest qq) { - currentQuest = qq; + public static void setQuestAssignment(final Quest_Assignment assignment) { + questAssignment = assignment; } /** diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java index 323aae97065..f5bbaf5aaf1 100644 --- a/src/main/java/forge/deck/Deck.java +++ b/src/main/java/forge/deck/Deck.java @@ -1,392 +1,346 @@ -package forge.deck; - -import forge.Constant; -import forge.card.CardDb; -import forge.card.CardPool; -import forge.card.CardPoolView; -import forge.card.CardPrinted; - -import java.io.Serializable; -import java.util.*; - -/** - *

Deck class.

- * - * @author Forge - * @version $Id: Deck.java 10183 2011-09-02 22:51:47Z Max mtg $ - */ -public final class Deck implements Comparable, Serializable { - /** - * - */ - private static final long serialVersionUID = -7478025567887481994L; - - //gameType is from Constant.GameType, like Constant.GameType.Regular - - private Map metadata = new HashMap(); - - private CardPool main; - private CardPool sideboard; - private CardPool humanExtraCards; - private CardPool aiExtraCards; - - /** Constant NAME="Name" */ - public static final String NAME = "Name"; - /** Constant DECK_TYPE="Deck Type" */ - public static final String DECK_TYPE = "Deck Type"; - /** Constant COMMENT="Comment" */ - public static final String COMMENT = "Comment"; - /** Constant DESCRIPTION="Description" */ - public static final String DESCRIPTION = "Description"; - /** Constant DIFFICULTY="Difficulty" */ - public static final String DIFFICULTY = "Difficulty"; - - - //gameType is from Constant.GameType, like Constant.GameType.Regular - /** - *

Constructor for Deck.

- */ - public Deck() { - main = new CardPool(); - sideboard = new CardPool(); - humanExtraCards = new CardPool(); - aiExtraCards = new CardPool(); - } - - /** - *

Constructor for Deck.

- * - * @param deckType a {@link java.lang.String} object. - * @param main a {@link java.util.List} object. - * @param sideboard a {@link java.util.List} object. - * @param name a {@link java.lang.String} object. - */ - public Deck(String deckType, List main, List sideboard, String name) { - setDeckType(deckType); - setName(name); - - this.main = new CardPool(main); - this.sideboard = new CardPool(sideboard); - } - - /** - *

Constructor for Deck.

- * - * @param type a {@link java.lang.String} object. - */ - public Deck(final String type) { - this(); - setDeckType(type); - } - - /** - *

Getter for the field main.

- * - * @return a {@link java.util.List} object. - */ - public CardPoolView getMain() { - return main.getView(); - } - - /** - *

Getter for the field sideboard.

- * - * @return a {@link java.util.List} object. - */ - public CardPoolView getSideboard() { - return sideboard.getView(); - } - - /** - *

Getter for the field humanExtraCards.

- * - * @return a {@link java.util.List} object. - */ - public CardPoolView getHumanExtraCards() { - return humanExtraCards.getView(); - } - - /** - *

Getter for the field aiExtraCards.

- * - * @return a {@link java.util.List} object. - */ - public CardPoolView getAIExtraCards() { - return aiExtraCards.getView(); - } - - /** - *

getDeckType.

- * - * @return a {@link java.lang.String} object. - */ - public String getDeckType() { - return metadata.get(DECK_TYPE); - } - - //can only call this method ONCE - /** - *

setDeckType.

- * - * @param deckType a {@link java.lang.String} object. - */ - void setDeckType(String deckType) { - if (this.getDeckType() != null) { - throw new IllegalStateException( - "Deck : setDeckType() error, deck type has already been set"); - } - - if (!Constant.GameType.GameTypes.contains(deckType)) { - throw new RuntimeException( - "Deck : setDeckType() error, invalid deck type - " + deckType); - } - - metadata.put(DECK_TYPE, deckType); - } - - /** - *

setName.

- * - * @param s a {@link java.lang.String} object. - */ - public void setName(String s) { - metadata.put(NAME, s); - } - - /** - *

getName.

- * - * @return a {@link java.lang.String} object. - */ - public String getName() { - return metadata.get(NAME); - } - - /** - *

setComment.

- * - * @param comment a {@link java.lang.String} object. - */ - public void setComment(String comment) { - metadata.put(COMMENT, comment); - } - - /** - *

getComment.

- * - * @return a {@link java.lang.String} object. - */ - public String getComment() { - return metadata.get(COMMENT); - - } - - /** - *

addMain.

- * - * @param cardName a {@link java.lang.String} object. - */ - public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); } - public void addMain(final CardPrinted card) { main.add(card); } - public void addMain(final CardPoolView list) { main.addAll(list); } - public void removeMain(final CardPrinted card) { main.remove(card); } - public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); } - public int countMain() { return main.countAll(); } - - /** - *

addSideboard.

- * - * @param cardName a {@link java.lang.String} object. - */ - public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); } - public final void addSideboard(final CardPrinted card) { sideboard.add(card); } - public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); } - public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); } - - /** - *

countSideboard.

- * - * @return a int. - */ - public int countSideboard() { - return sideboard.countAll(); - } - - /** - *

removeSideboard.

- * - * @param index a int. - * @return a {@link java.lang.String} object. - */ - public void removeFromSideboard(CardPrinted card) { - sideboard.remove(card); - } - - /** - *

addHumanExtraCards.

- * - * @param cardName a {@link java.lang.String} object. - */ - public void addHumanExtraCards(final String cardName) { addHumanExtraCards(CardDb.instance().getCard(cardName)); } - public void addHumanExtraCards(final CardPrinted card) { humanExtraCards.add(card); } - public void addHumanExtraCards(final CardPoolView list) { humanExtraCards.addAll(list); } - public void removeHumanExtraCards(final CardPrinted card) { humanExtraCards.remove(card); } - public void removeHumanExtraCards(final CardPrinted card, final int amount) { humanExtraCards.remove(card, amount); } - public int countHumanExtraCards() { return main.countAll(); } - - /** - *

addAIExtraCards.

- * - * @param cardName a {@link java.lang.String} object. - */ - public void addAIExtraCards(final String cardName) { addAIExtraCards(CardDb.instance().getCard(cardName)); } - public void addAIExtraCards(final CardPrinted card) { aiExtraCards.add(card); } - public void addAIExtraCards(final CardPoolView list) { aiExtraCards.addAll(list); } - public void removeAIExtraCards(final CardPrinted card) { aiExtraCards.remove(card); } - public void removeAIExtraCards(final CardPrinted card, final int amount) { aiExtraCards.remove(card, amount); } - public int countAIExtraCards() { return aiExtraCards.countAll(); } - - /** - *

isDraft.

- * - * @return a boolean. - */ - public boolean isDraft() { - return getDeckType().equals(Constant.GameType.Draft); - } - - /** - *

isSealed.

- * - * @return a boolean. - */ - public boolean isSealed() { - return getDeckType().equals(Constant.GameType.Sealed); - } - - /** - *

isRegular.

- * - * @return a boolean. - */ - public boolean isRegular() { - return getDeckType().equals(Constant.GameType.Constructed); - } - - /** - *

hashCode.

- * - * @return a int. - */ - public int hashCode() { - return getName().hashCode(); - } - - /** {@inheritDoc} */ - @Override - public String toString() { - return getName(); - } - - - // The setters and getters below are for Quest decks - /** - *

setDifficulty.

- * - * @param s a {@link java.lang.String} object. - */ - public void setDifficulty(String s) { - metadata.put(DIFFICULTY, s); - } - - /** - *

getDifficulty.

- * - * @return a {@link java.lang.String} object. - */ - public String getDifficulty() { - return metadata.get(DIFFICULTY); - } - - /** - *

setDescription.

- * - * @param s a {@link java.lang.String} object. - */ - public void setDescription(String s) { - metadata.put(DESCRIPTION, s); - } - - /** - *

getDescription.

- * - * @return a {@link java.lang.String} object. - */ - public String getDescription() { - return metadata.get(DESCRIPTION); - } - - /** - *

compareTo.

- * - * @param d a {@link forge.deck.Deck} object. - * @return a int. - */ - public int compareTo(Deck d) { - return getName().compareTo(d.getName()); - } - - /** {@inheritDoc} */ - public boolean equals(Object o) { - if (o instanceof Deck) { - Deck d = (Deck) o; - return getName().equals(d.getName()); - } - return false; - } - - /** - *

Getter for the field metadata.

- * - * @return a {@link java.util.Set} object. - */ - public Set> getMetadata() { - return metadata.entrySet(); - } - - /** - *

Getter for the field metadata.

- * - * @param key a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - * @since 1.0.15 - */ - public String getMetadata(String key) { - if (metadata.containsKey(key)) - return metadata.get(key); - - System.err.println("In forge.deck/Deck.java, getMetadata() failed "+ - "for property '"+key+"' in deck '"+getName()+"'."); - return ""; - } - - /** - *

addMetaData.

- * - * @param key a {@link java.lang.String} object. - * @param value a {@link java.lang.String} object. - */ - public void addMetaData(String key, String value) { - metadata.put(key, value); - } - - public void clearSideboard() { - sideboard.clear(); - } - - public void clearMain() { - main.clear(); - - } - -} +package forge.deck; + +import forge.Constant; +import forge.card.CardDb; +import forge.card.CardPool; +import forge.card.CardPoolView; +import forge.card.CardPrinted; + +import java.io.Serializable; +import java.util.*; + +/** + *

Deck class.

+ * + * @author Forge + * @version $Id$ + */ +public final class Deck implements Comparable, Serializable { + /** + * + */ + private static final long serialVersionUID = -7478025567887481994L; + + //gameType is from Constant.GameType, like Constant.GameType.Regular + + private Map metadata = new HashMap(); + + private CardPool main; + private CardPool sideboard; + + /** Constant NAME="Name" */ + public static final String NAME = "Name"; + /** Constant DECK_TYPE="Deck Type" */ + public static final String DECK_TYPE = "Deck Type"; + /** Constant COMMENT="Comment" */ + public static final String COMMENT = "Comment"; + /** Constant DESCRIPTION="Description" */ + public static final String DESCRIPTION = "Description"; + /** Constant DIFFICULTY="Difficulty" */ + public static final String DIFFICULTY = "Difficulty"; + + + //gameType is from Constant.GameType, like Constant.GameType.Regular + /** + *

Constructor for Deck.

+ */ + public Deck() { + main = new CardPool(); + sideboard = new CardPool(); + } + + /** + *

Constructor for Deck.

+ * + * @param deckType a {@link java.lang.String} object. + * @param main a {@link java.util.List} object. + * @param sideboard a {@link java.util.List} object. + * @param name a {@link java.lang.String} object. + */ + public Deck(String deckType, List main, List sideboard, String name) { + setDeckType(deckType); + setName(name); + + this.main = new CardPool(main); + this.sideboard = new CardPool(sideboard); + } + + /** + *

Constructor for Deck.

+ * + * @param type a {@link java.lang.String} object. + */ + public Deck(final String type) { + this(); + setDeckType(type); + } + + /** + *

Getter for the field main.

+ * + * @return a {@link java.util.List} object. + */ + public CardPoolView getMain() { + return main.getView(); + } + + /** + *

Getter for the field sideboard.

+ * + * @return a {@link java.util.List} object. + */ + public CardPoolView getSideboard() { + return sideboard.getView(); + } + + /** + *

getDeckType.

+ * + * @return a {@link java.lang.String} object. + */ + public String getDeckType() { + return metadata.get(DECK_TYPE); + } + + //can only call this method ONCE + /** + *

setDeckType.

+ * + * @param deckType a {@link java.lang.String} object. + */ + void setDeckType(String deckType) { + if (this.getDeckType() != null) { + throw new IllegalStateException( + "Deck : setDeckType() error, deck type has already been set"); + } + + if (!Constant.GameType.GameTypes.contains(deckType)) { + throw new RuntimeException( + "Deck : setDeckType() error, invalid deck type - " + deckType); + } + + metadata.put(DECK_TYPE, deckType); + } + + /** + *

setName.

+ * + * @param s a {@link java.lang.String} object. + */ + public void setName(String s) { + metadata.put(NAME, s); + } + + /** + *

getName.

+ * + * @return a {@link java.lang.String} object. + */ + public String getName() { + return metadata.get(NAME); + } + + /** + *

setComment.

+ * + * @param comment a {@link java.lang.String} object. + */ + public void setComment(String comment) { + metadata.put(COMMENT, comment); + } + + /** + *

getComment.

+ * + * @return a {@link java.lang.String} object. + */ + public String getComment() { + return metadata.get(COMMENT); + + } + + /** + *

addMain.

+ * + * @param cardName a {@link java.lang.String} object. + */ + public void addMain(final String cardName) { addMain(CardDb.instance().getCard(cardName)); } + public void addMain(final CardPrinted card) { main.add(card); } + public void addMain(final CardPoolView list) { main.addAll(list); } + public void removeMain(final CardPrinted card) { main.remove(card); } + public void removeMain(final CardPrinted card, final int amount) { main.remove(card, amount); } + public int countMain() { return main.countAll(); } + + /** + *

addSideboard.

+ * + * @param cardName a {@link java.lang.String} object. + */ + public final void addSideboard(final String cardName) { addSideboard(CardDb.instance().getCard(cardName)); } + public final void addSideboard(final CardPrinted card) { sideboard.add(card); } + public final void addSideboard(final CardPrinted card, final int amount) { sideboard.add(card, amount); } + public final void addSideboard(final CardPoolView cards) { sideboard.addAll(cards); } + + /** + *

countSideboard.

+ * + * @return a int. + */ + public int countSideboard() { + return sideboard.countAll(); + } + + /** + *

removeSideboard.

+ * + * @param index a int. + * @return a {@link java.lang.String} object. + */ + public void removeFromSideboard(CardPrinted card) { + sideboard.remove(card); + } + + /** + *

isDraft.

+ * + * @return a boolean. + */ + public boolean isDraft() { + return getDeckType().equals(Constant.GameType.Draft); + } + + /** + *

isSealed.

+ * + * @return a boolean. + */ + public boolean isSealed() { + return getDeckType().equals(Constant.GameType.Sealed); + } + + /** + *

isRegular.

+ * + * @return a boolean. + */ + public boolean isRegular() { + return getDeckType().equals(Constant.GameType.Constructed); + } + + /** + *

hashCode.

+ * + * @return a int. + */ + public int hashCode() { + return getName().hashCode(); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return getName(); + } + + + // The setters and getters below are for Quest decks + /** + *

setDifficulty.

+ * + * @param s a {@link java.lang.String} object. + */ + public void setDifficulty(String s) { + metadata.put(DIFFICULTY, s); + } + + /** + *

getDifficulty.

+ * + * @return a {@link java.lang.String} object. + */ + public String getDifficulty() { + return metadata.get(DIFFICULTY); + } + + /** + *

setDescription.

+ * + * @param s a {@link java.lang.String} object. + */ + public void setDescription(String s) { + metadata.put(DESCRIPTION, s); + } + + /** + *

getDescription.

+ * + * @return a {@link java.lang.String} object. + */ + public String getDescription() { + return metadata.get(DESCRIPTION); + } + + /** + *

compareTo.

+ * + * @param d a {@link forge.deck.Deck} object. + * @return a int. + */ + public int compareTo(Deck d) { + return getName().compareTo(d.getName()); + } + + /** {@inheritDoc} */ + public boolean equals(Object o) { + if (o instanceof Deck) { + Deck d = (Deck) o; + return getName().equals(d.getName()); + } + return false; + } + + /** + *

Getter for the field metadata.

+ * + * @return a {@link java.util.Set} object. + */ + public Set> getMetadata() { + return metadata.entrySet(); + } + + /** + *

Getter for the field metadata.

+ * + * @param key a {@link java.lang.String} object. + * @return a {@link java.lang.String} object. + * @since 1.0.15 + */ + public String getMetadata(String key) { + if (metadata.containsKey(key)) + return metadata.get(key); + + System.err.println("In forge.deck/Deck.java, getMetadata() failed "+ + "for property '"+key+"' in deck '"+getName()+"'."); + return ""; + } + + /** + *

addMetaData.

+ * + * @param key a {@link java.lang.String} object. + * @param value a {@link java.lang.String} object. + */ + public void addMetaData(String key, String value) { + metadata.put(key, value); + } + + public void clearSideboard() { + sideboard.clear(); + } + + public void clearMain() { + main.clear(); + + } + +} diff --git a/src/main/java/forge/deck/DeckManager.java b/src/main/java/forge/deck/DeckManager.java index 2e88721a471..fd2de901ca1 100644 --- a/src/main/java/forge/deck/DeckManager.java +++ b/src/main/java/forge/deck/DeckManager.java @@ -1,533 +1,487 @@ -package forge.deck; - - -import forge.Card; -import forge.Constant; -import forge.card.CardPrinted; -import forge.error.ErrorViewer; -import forge.quest.data.QuestUtil; - -import java.io.*; -import java.util.*; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang3.StringUtils; - -import static java.lang.Integer.parseInt; -import static java.lang.String.format; -import static java.util.Arrays.asList; - - -//reads and writeDeck Deck objects -/** - *

DeckManager class.

- * - * @author Forge - * @version $Id: DeckManager.java 10146 2011-09-01 18:11:00Z Max mtg $ - */ -public class DeckManager { - /** Constant BDKFileFilter */ - private static FilenameFilter BDKFileFilter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".bdk"); - } - }; - - /** Constant DCKFileFilter */ - private static FilenameFilter DCKFileFilter = new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".dck"); - } - }; - - - private File deckDir; - Map deckMap; - Map draftMap; - - /** - *

Constructor for DeckManager.

- * - * @param deckDir a {@link java.io.File} object. - */ - public DeckManager(File deckDir) { - if (deckDir == null) { - throw new IllegalArgumentException("No deck directory specified"); - } - try { - this.deckDir = deckDir; - - if (deckDir.isFile()) { - throw new IOException("Not a directory"); - } else { - deckDir.mkdirs(); - if (!deckDir.isDirectory()) { - throw new IOException("Directory can't be created"); - } - this.deckMap = new HashMap(); - this.draftMap = new HashMap(); - readAllDecks(); - } - } catch (IOException ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); - } - } - - - /** - *

isUnique.

- * - * @param deckName a {@link java.lang.String} object. - * @return a boolean. - */ - public boolean isUnique(String deckName) { - return !deckMap.containsKey(deckName); - } - - /** - *

isUniqueDraft.

- * - * @param deckName a {@link java.lang.String} object. - * @return a boolean. - */ - public boolean isUniqueDraft(String deckName) { - return !draftMap.keySet().contains(deckName); - } - - /** - *

getDeck.

- * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public Deck getDeck(String deckName) { - return deckMap.get(deckName); - } - - - /** - *

addDeck.

- * - * @param deck a {@link forge.deck.Deck} object. - */ - public void addDeck(Deck deck) { - if (deck.getDeckType().equals(Constant.GameType.Draft)) { - throw new RuntimeException( - "DeckManager : addDeck() error, deck type is Draft"); - } - - deckMap.put(deck.getName(), deck); - } - - /** - *

deleteDeck.

- * - * @param deckName a {@link java.lang.String} object. - */ - public void deleteDeck(String deckName) { - deckMap.remove(deckName); - } - - /** - *

getDraftDeck.

- * - * @param deckName a {@link java.lang.String} object. - * @return an array of {@link forge.deck.Deck} objects. - */ - public Deck[] getDraftDeck(String deckName) { - if (!draftMap.containsKey(deckName)) { - throw new RuntimeException( - "DeckManager : getDraftDeck() error, deck name not found - " + deckName); - } - - return draftMap.get(deckName); - } - - /** - *

addDraftDeck.

- * - * @param deck an array of {@link forge.deck.Deck} objects. - */ - public void addDraftDeck(Deck[] deck) { - checkDraftDeck(deck); - - draftMap.put(deck[0].toString(), deck); - } - - /** - *

deleteDraftDeck.

- * - * @param deckName a {@link java.lang.String} object. - */ - public void deleteDraftDeck(String deckName) { - if (!draftMap.containsKey(deckName)) { - throw new RuntimeException( - "DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); - } - - draftMap.remove(deckName); - } - - /** - *

checkDraftDeck.

- * - * @param deck an array of {@link forge.deck.Deck} objects. - */ - private void checkDraftDeck(Deck[] deck) { - if (deck == null || deck.length != 8 || deck[0].getName().equals("") - || (!deck[0].getDeckType().equals(Constant.GameType.Draft))) { - throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); - } - } - - - /** - *

getDecks.

- * - * @return a {@link java.util.Collection} object. - */ - public Collection getDecks() { - return deckMap.values(); - } - - /** - *

getDraftDecks.

- * - * @return a {@link java.util.Map} object. - */ - public Map getDraftDecks() { - return new HashMap(draftMap); - } - - /** - *

close.

- */ - public void close() { - writeAllDecks(); - } - - - /** - *

readAllDecks.

- */ - public void readAllDecks() { - deckMap.clear(); - draftMap.clear(); - - File[] files; - - files = deckDir.listFiles(DCKFileFilter); - for (File file : files) { - Deck newDeck = readDeck(file); - deckMap.put(newDeck.getName(), newDeck); - } - - files = deckDir.listFiles(BDKFileFilter); - for (File file : files) { - Deck[] d = new Deck[8]; - - for (int i = 0; i < d.length; i++) { - d[i] = readDeck(new File(file, i + ".dck")); - } - - draftMap.put(d[0].getName(), d); - } - } - - /** - *

readDeck.

- * - * @param deckFile a {@link java.io.File} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck readDeck(File deckFile) { - - List lines = new LinkedList(); - - try { - BufferedReader r = new BufferedReader(new FileReader(deckFile)); - - String line; - while ((line = r.readLine()) != null) { - lines.add(line); - } - - r.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - ListIterator lineIterator = lines.listIterator(); - - String line = lineIterator.next(); - - //Old text-based format - if (!line.equals("[metadata]")) { - lineIterator.previous(); - return readDeckOld(lineIterator); - } - - Deck d = new Deck(); - - //read metadata - while (!(line = lineIterator.next()).equals("[main]")) { - String[] linedata = line.split("=", 2); - d.addMetaData(linedata[0], linedata[1]); - } - - addCardList(lineIterator, d); - - return d; - - } - - /** - *

readDeckOld.

- * - * @param iterator a {@link java.util.ListIterator} object. - * @return a {@link forge.deck.Deck} object. - */ - private static Deck readDeckOld(ListIterator iterator) { - - String line; - //readDeck name - String name = iterator.next(); - - //readDeck comments - String comment = null; - while ((line = iterator.next()) != null && !line.equals("[general]")) { - if (comment == null) { - comment = line; - } else { - comment += "\n" + line; - } - } - - //readDeck deck type - String deckType = iterator.next(); - - Deck d = new Deck(); - d.setName(name); - d.setComment(comment); - d.setDeckType(deckType); - - //go to [main] - while ((line = iterator.next()) != null && !line.equals("[main]")) { - System.err.println("unexpected line: " + line); - } - - addCardList(iterator, d); - - return d; - } - - /** - *

addCardList.

- * - * @param lineIterator a {@link java.util.ListIterator} object. - * @param d a {@link forge.deck.Deck} object. - */ - private static void addCardList(ListIterator lineIterator, Deck d) { - String line; - - Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*"); - - //readDeck main deck - while (lineIterator.hasNext() && !(line = lineIterator.next()).equals("[sideboard]")) { - Matcher m = p.matcher(line); - m.matches(); - String s = m.group(2); - int count = s == null ? 1 : parseInt(s); - - for (int i = 0; i < count; i++) { - d.addMain(m.group(3)); - } - } - - //readDeck sideboard - while (lineIterator.hasNext() && !(line = lineIterator.next()).equals("[human_extra_cards]")) { - Matcher m = p.matcher(line); - m.matches(); - String s = m.group(2); - String cardName = m.group(3); - if (StringUtils.isBlank(cardName)) { continue; } - - int count = s == null ? 1 : parseInt(s); - for (int i = 0; i < count; i++) { - d.addSideboard(cardName); - } - } - - // readDeck human extras - while (lineIterator.hasNext() && !(line = lineIterator.next()).equals("[ai_extra_cards]")) { - Matcher m = p.matcher(line); - m.matches(); - String s = m.group(2); - String cardName = m.group(3); - if (StringUtils.isBlank(cardName)) { continue; } - - int count = s == null ? 1 : parseInt(s); - for (int i = 0; i < count; i++) { - if(cardName.substring(0,5).equals("TOKEN")) { - System.out.println("DeckManager: Token ignored ("+cardName+")"); - // Build token below, but of type Card, not CardPrinted, - // so can't be added to deck. - //Card c = QuestUtil.extraCardBuilder(cardName); - } - else { - d.addHumanExtraCards(cardName); - } - } - } - - // readDeck AI extras - while (lineIterator.hasNext()) { - line = lineIterator.next(); - Matcher m = p.matcher(line); - m.matches(); - String s = m.group(2); - String cardName = m.group(3); - if (StringUtils.isBlank(cardName)) { continue; } - - int count = s == null ? 1 : parseInt(s); - for (int i = 0; i < count; i++) { - if(cardName.substring(0,5).equals("TOKEN")) { - System.out.println("DeckManager: Token ignored ("+cardName+")"); - // Build token below, but of type Card, not CardPrinted, - // so can't be added to deck. - //Card c = QuestUtil.extraCardBuilder(cardName); - } - else { - d.addAIExtraCards(cardName); - } - } - } - } - - /** - *

deriveFileName.

- * - * @param deckName a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - */ - private String deriveFileName(String deckName) { - //skips all but the listed characters - return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", ""); - } - - /** - *

writeAllDecks.

- */ - public void writeAllDecks() { - try { - //store the files that do exist - List files = new ArrayList(); - files.addAll(asList(deckDir.listFiles(DCKFileFilter))); - - //save the files and remove them from the list - for (Deck deck : deckMap.values()) { - File f = new File(deckDir, deriveFileName(deck.getName()) + ".dck"); - files.remove(f); - BufferedWriter out = new BufferedWriter(new FileWriter(f)); - writeDeck(deck, out); - out.close(); - } - //delete the files that were not written out: the decks that were deleted - for (File file : files) { - file.delete(); - } - - //store the files that do exist - files.clear(); - files.addAll(asList(deckDir.listFiles(BDKFileFilter))); - - //save the files and remove them from the list - for (Entry e : draftMap.entrySet()) { - File f = new File(deckDir, deriveFileName(e.getValue()[0].getName()) + ".bdk"); - f.mkdir(); - for (int i = 0; i < e.getValue().length; i++) { - BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck"))); - writeDeck(e.getValue()[i], out); - out.close(); - } - } - /* - //delete the files that were not written out: the decks that were deleted - for(File file:files) { - for(int i = 0; i < 8; i++) - new File(file, i + ".dck").delete(); - file.delete(); - } - */ - } catch (IOException ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); - } - } - - /** - *

writeDeck.

- * - * @param d a {@link forge.deck.Deck} object. - * @param out a {@link java.io.BufferedWriter} object. - * @throws java.io.IOException if any. - */ - private static void writeDeck(Deck d, BufferedWriter out) throws IOException { - out.write("[metadata]\n"); - - for (Entry entry : d.getMetadata()) { - if (entry.getValue() != null) - out.write(format("%s=%s%n", entry.getKey(), entry.getValue().replaceAll("\n", ""))); - } - - out.write(format("%s%n", "[main]")); - for (Entry e : d.getMain()) { - out.write(format("%d %s%n", e.getValue(), e.getKey().getName())); - } - out.write(format("%s%n", "[sideboard]")); - for (Entry e : d.getSideboard()) { - out.write(format("%d %s%n", e.getValue(), e.getKey().getName())); - } - } - - /** - *

count.

- * - * @param src a {@link java.util.List} object. - * @return a {@link java.util.Map} object. - */ - private static Map count(List src) { - Map result = new HashMap(); - for (String s : src) { - Integer dstValue = result.get(s); - if (dstValue == null) { - result.put(s, 1); - } else { - result.put(s, dstValue + 1); - } - } - return result; - } - - /** - *

writeDeck.

- * - * @param d a {@link forge.deck.Deck} object. - * @param f a {@link java.io.File} object. - */ - public static void writeDeck(Deck d, File f) { - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(f)); - writeDeck(d, writer); - - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - } - -} +package forge.deck; + + +import forge.Constant; +import forge.card.CardPrinted; +import forge.error.ErrorViewer; + +import java.io.*; +import java.util.*; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang3.StringUtils; + +import static java.lang.Integer.parseInt; +import static java.lang.String.format; +import static java.util.Arrays.asList; + + +//reads and writeDeck Deck objects +/** + *

DeckManager class.

+ * + * @author Forge + * @version $Id$ + */ +public class DeckManager { + /** Constant BDKFileFilter */ + private static FilenameFilter BDKFileFilter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".bdk"); + } + }; + + /** Constant DCKFileFilter */ + private static FilenameFilter DCKFileFilter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.endsWith(".dck"); + } + }; + + + private File deckDir; + Map deckMap; + Map draftMap; + + /** + *

Constructor for DeckManager.

+ * + * @param deckDir a {@link java.io.File} object. + */ + public DeckManager(File deckDir) { + if (deckDir == null) { + throw new IllegalArgumentException("No deck directory specified"); + } + try { + this.deckDir = deckDir; + + if (deckDir.isFile()) { + throw new IOException("Not a directory"); + } else { + deckDir.mkdirs(); + if (!deckDir.isDirectory()) { + throw new IOException("Directory can't be created"); + } + this.deckMap = new HashMap(); + this.draftMap = new HashMap(); + readAllDecks(); + } + } catch (IOException ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); + } + } + + + /** + *

isUnique.

+ * + * @param deckName a {@link java.lang.String} object. + * @return a boolean. + */ + public boolean isUnique(String deckName) { + return !deckMap.containsKey(deckName); + } + + /** + *

isUniqueDraft.

+ * + * @param deckName a {@link java.lang.String} object. + * @return a boolean. + */ + public boolean isUniqueDraft(String deckName) { + return !draftMap.keySet().contains(deckName); + } + + /** + *

getDeck.

+ * + * @param deckName a {@link java.lang.String} object. + * @return a {@link forge.deck.Deck} object. + */ + public Deck getDeck(String deckName) { + return deckMap.get(deckName); + } + + + /** + *

addDeck.

+ * + * @param deck a {@link forge.deck.Deck} object. + */ + public void addDeck(Deck deck) { + if (deck.getDeckType().equals(Constant.GameType.Draft)) { + throw new RuntimeException( + "DeckManager : addDeck() error, deck type is Draft"); + } + + deckMap.put(deck.getName(), deck); + } + + /** + *

deleteDeck.

+ * + * @param deckName a {@link java.lang.String} object. + */ + public void deleteDeck(String deckName) { + deckMap.remove(deckName); + } + + /** + *

getDraftDeck.

+ * + * @param deckName a {@link java.lang.String} object. + * @return an array of {@link forge.deck.Deck} objects. + */ + public Deck[] getDraftDeck(String deckName) { + if (!draftMap.containsKey(deckName)) { + throw new RuntimeException( + "DeckManager : getDraftDeck() error, deck name not found - " + deckName); + } + + return draftMap.get(deckName); + } + + /** + *

addDraftDeck.

+ * + * @param deck an array of {@link forge.deck.Deck} objects. + */ + public void addDraftDeck(Deck[] deck) { + checkDraftDeck(deck); + + draftMap.put(deck[0].toString(), deck); + } + + /** + *

deleteDraftDeck.

+ * + * @param deckName a {@link java.lang.String} object. + */ + public void deleteDraftDeck(String deckName) { + if (!draftMap.containsKey(deckName)) { + throw new RuntimeException( + "DeckManager : deleteDraftDeck() error, deck name not found - " + deckName); + } + + draftMap.remove(deckName); + } + + /** + *

checkDraftDeck.

+ * + * @param deck an array of {@link forge.deck.Deck} objects. + */ + private void checkDraftDeck(Deck[] deck) { + if (deck == null || deck.length != 8 || deck[0].getName().equals("") + || (!deck[0].getDeckType().equals(Constant.GameType.Draft))) { + throw new RuntimeException("DeckManager : checkDraftDeck() error, invalid deck"); + } + } + + + /** + *

getDecks.

+ * + * @return a {@link java.util.Collection} object. + */ + public Collection getDecks() { + return deckMap.values(); + } + + /** + *

getDraftDecks.

+ * + * @return a {@link java.util.Map} object. + */ + public Map getDraftDecks() { + return new HashMap(draftMap); + } + + /** + *

close.

+ */ + public void close() { + writeAllDecks(); + } + + + /** + *

readAllDecks.

+ */ + public void readAllDecks() { + deckMap.clear(); + draftMap.clear(); + + File[] files; + + files = deckDir.listFiles(DCKFileFilter); + for (File file : files) { + Deck newDeck = readDeck(file); + deckMap.put(newDeck.getName(), newDeck); + } + + files = deckDir.listFiles(BDKFileFilter); + for (File file : files) { + Deck[] d = new Deck[8]; + + for (int i = 0; i < d.length; i++) { + d[i] = readDeck(new File(file, i + ".dck")); + } + + draftMap.put(d[0].getName(), d); + } + } + + /** + *

readDeck.

+ * + * @param deckFile a {@link java.io.File} object. + * @return a {@link forge.deck.Deck} object. + */ + public static Deck readDeck(File deckFile) { + + List lines = new LinkedList(); + + try { + BufferedReader r = new BufferedReader(new FileReader(deckFile)); + + String line; + while ((line = r.readLine()) != null) { + lines.add(line); + } + + r.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + ListIterator lineIterator = lines.listIterator(); + + String line = lineIterator.next(); + + //Old text-based format + if (!line.equals("[metadata]")) { + lineIterator.previous(); + return readDeckOld(lineIterator); + } + + Deck d = new Deck(); + + //read metadata + while (!(line = lineIterator.next()).equals("[main]")) { + String[] linedata = line.split("=", 2); + d.addMetaData(linedata[0], linedata[1]); + } + + addCardList(lineIterator, d); + + return d; + + } + + /** + *

readDeckOld.

+ * + * @param iterator a {@link java.util.ListIterator} object. + * @return a {@link forge.deck.Deck} object. + */ + private static Deck readDeckOld(ListIterator iterator) { + + String line; + //readDeck name + String name = iterator.next(); + + //readDeck comments + String comment = null; + while ((line = iterator.next()) != null && !line.equals("[general]")) { + if (comment == null) { + comment = line; + } else { + comment += "\n" + line; + } + } + + //readDeck deck type + String deckType = iterator.next(); + + Deck d = new Deck(); + d.setName(name); + d.setComment(comment); + d.setDeckType(deckType); + + //go to [main] + while ((line = iterator.next()) != null && !line.equals("[main]")) { + System.err.println("unexpected line: " + line); + } + + addCardList(iterator, d); + + return d; + } + + /** + *

addCardList.

+ * + * @param lineIterator a {@link java.util.ListIterator} object. + * @param d a {@link forge.deck.Deck} object. + */ + private static void addCardList(ListIterator lineIterator, Deck d) { + String line; + + Pattern p = Pattern.compile("\\s*((\\d+)\\s+)?(.*?)\\s*"); + + //readDeck main deck + while (lineIterator.hasNext() && !(line = lineIterator.next()).equals("[sideboard]")) { + Matcher m = p.matcher(line); + m.matches(); + String s = m.group(2); + int count = s == null ? 1 : parseInt(s); + + for (int i = 0; i < count; i++) { + d.addMain(m.group(3)); + } + } + + //readDeck sideboard + while (lineIterator.hasNext()) { + line = lineIterator.next(); + Matcher m = p.matcher(line); + m.matches(); + String s = m.group(2); + String cardName = m.group(3); + if (StringUtils.isBlank(cardName)) { continue; } + + int count = s == null ? 1 : parseInt(s); + for (int i = 0; i < count; i++) { + d.addSideboard(cardName); + } + } + } + + /** + *

deriveFileName.

+ * + * @param deckName a {@link java.lang.String} object. + * @return a {@link java.lang.String} object. + */ + private String deriveFileName(String deckName) { + //skips all but the listed characters + return deckName.replaceAll("[^-_$#@.{[()]} a-zA-Z0-9]", ""); + } + + /** + *

writeAllDecks.

+ */ + public void writeAllDecks() { + try { + //store the files that do exist + List files = new ArrayList(); + files.addAll(asList(deckDir.listFiles(DCKFileFilter))); + + //save the files and remove them from the list + for (Deck deck : deckMap.values()) { + File f = new File(deckDir, deriveFileName(deck.getName()) + ".dck"); + files.remove(f); + BufferedWriter out = new BufferedWriter(new FileWriter(f)); + writeDeck(deck, out); + out.close(); + } + //delete the files that were not written out: the decks that were deleted + for (File file : files) { + file.delete(); + } + + //store the files that do exist + files.clear(); + files.addAll(asList(deckDir.listFiles(BDKFileFilter))); + + //save the files and remove them from the list + for (Entry e : draftMap.entrySet()) { + File f = new File(deckDir, deriveFileName(e.getValue()[0].getName()) + ".bdk"); + f.mkdir(); + for (int i = 0; i < e.getValue().length; i++) { + BufferedWriter out = new BufferedWriter(new FileWriter(new File(f, i + ".dck"))); + writeDeck(e.getValue()[i], out); + out.close(); + } + } + /* + //delete the files that were not written out: the decks that were deleted + for(File file:files) { + for(int i = 0; i < 8; i++) + new File(file, i + ".dck").delete(); + file.delete(); + } + */ + } catch (IOException ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("DeckManager : writeDeck() error, " + ex.getMessage()); + } + } + + /** + *

writeDeck.

+ * + * @param d a {@link forge.deck.Deck} object. + * @param out a {@link java.io.BufferedWriter} object. + * @throws java.io.IOException if any. + */ + private static void writeDeck(Deck d, BufferedWriter out) throws IOException { + out.write("[metadata]\n"); + + for (Entry entry : d.getMetadata()) { + if (entry.getValue() != null) + out.write(format("%s=%s%n", entry.getKey(), entry.getValue().replaceAll("\n", ""))); + } + + out.write(format("%s%n", "[main]")); + for (Entry e : d.getMain()) { + out.write(format("%d %s%n", e.getValue(), e.getKey().getName())); + } + out.write(format("%s%n", "[sideboard]")); + for (Entry e : d.getSideboard()) { + out.write(format("%d %s%n", e.getValue(), e.getKey().getName())); + } + } + + /** + *

count.

+ * + * @param src a {@link java.util.List} object. + * @return a {@link java.util.Map} object. + */ + private static Map count(List src) { + Map result = new HashMap(); + for (String s : src) { + Integer dstValue = result.get(s); + if (dstValue == null) { + result.put(s, 1); + } else { + result.put(s, dstValue + 1); + } + } + return result; + } + + /** + *

writeDeck.

+ * + * @param d a {@link forge.deck.Deck} object. + * @param f a {@link java.io.File} object. + */ + public static void writeDeck(Deck d, File f) { + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(f)); + writeDeck(d, writer); + + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + } + +} diff --git a/src/main/java/forge/gui/SelectablePanel.java b/src/main/java/forge/gui/SelectablePanel.java deleted file mode 100644 index 5af89c1013c..00000000000 --- a/src/main/java/forge/gui/SelectablePanel.java +++ /dev/null @@ -1,43 +0,0 @@ -package forge.gui; - -import java.awt.Color; - -import javax.swing.JPanel; - - -/** - *

SelectablePanel

- * VIEW - Standard selectable JPanel used for many places in the GUI. - * - */ -@SuppressWarnings("serial") -public abstract class SelectablePanel extends JPanel { - - private boolean selected = false; - protected Color backgroundColor = this.getBackground(); - - /** - *

Getter for the field selected

- * - * @return boolean. - */ - public boolean getSelected() { - return selected; - } - - /** - *

Setter for the field selected

- * Sets selected field and visual effect. - * - * @param boolean. - */ - public void setSelected(boolean selected) { - if (selected) { - this.setBackground(backgroundColor.darker()); - } else { - this.setBackground(backgroundColor); - } - - this.selected = selected; - } -} diff --git a/src/main/java/forge/quest/data/DeckSingleBattle.java b/src/main/java/forge/quest/data/DeckSingleBattle.java deleted file mode 100644 index ba7dde7ab3f..00000000000 --- a/src/main/java/forge/quest/data/DeckSingleBattle.java +++ /dev/null @@ -1,116 +0,0 @@ -package forge.quest.data; - -import javax.swing.ImageIcon; -import forge.deck.Deck; -import forge.gui.GuiUtils; - -/** - *

DeckSingleBattle

- * MODEL - Assembles and stores information from a battle deck. - * - * @author Forge - * @version $Id$ - */ -public class DeckSingleBattle { - private String deckName; - private String displayName; - private String diff; - private String desc; - private String iconFilename; - private ImageIcon icon; - private Deck deckObj; - - /** - *

Constructor for DeckSingleBattle.

- * - * @param {@link java.lang.String} storing name of AI deck for this battle - */ - public DeckSingleBattle(Deck d) { - // Get deck object and properties for this opponent. - this.deckObj = d; - this.deckName = d.getName(); - this.displayName = deckObj.getMetadata("DisplayName"); - this.diff = deckObj.getMetadata("Difficulty"); - this.desc = deckObj.getMetadata("Description"); - this.iconFilename = deckObj.getMetadata("Icon"); - - // Default icon - this.icon = GuiUtils.getIconFromFile(displayName + ".jpg"); - - // If non-default icon defined, use it. Any filetype accepted. - if(!iconFilename.equals("")) { - this.icon = GuiUtils.getIconFromFile(iconFilename); - } - } - - /** - *

getDifficulty()

- * Retrieve rated difficulty of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDifficulty() { - return this.diff; - } - - /** - *

getDescription()

- * Retrieve description of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDescription() { - return this.desc; - } - - /** - *

getDisplayName()

- * Retrieve display name of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDisplayName() { - return this.displayName; - } - - /** - *

getDeckName()

- * Retrieve file name of this battle deck. - * - * @return {@link java.lang.String} - */ - public String getDeckName() { - return this.deckName; - } - - /** - *

getIconFilename()

- * Retrieve file name of preferred icon - * - * @return {@link java.lang.String} - */ - public String getIconFilename() { - return this.iconFilename; - } - - /** - *

getDeck()

- * Retrieve this battle deck. - * - * @return {@link java.lang.String} - */ - public Deck getDeck() { - return this.deckObj; - } - - /** - *

getIcon()

- * Retrieve the icon used with this battle deck. - * - * @return {@link java.lang.String} - */ - public ImageIcon getIcon() { - return this.icon; - } - -} diff --git a/src/main/java/forge/quest/data/DeckSingleQuest.java b/src/main/java/forge/quest/data/DeckSingleQuest.java deleted file mode 100644 index 238fa6196a5..00000000000 --- a/src/main/java/forge/quest/data/DeckSingleQuest.java +++ /dev/null @@ -1,272 +0,0 @@ -package forge.quest.data; - -import java.util.ArrayList; -import java.util.List; - -import javax.swing.ImageIcon; - -import com.google.code.jyield.Generator; -import com.google.code.jyield.YieldUtils; - -import forge.AllZone; -import forge.Card; -import forge.Constant; -import forge.card.CardPrinted; -import forge.card.CardRarity; -import forge.deck.Deck; -import forge.gui.GuiUtils; - -/** - *

DeckSingleQuest

- * MODEL - Assembles and stores information from a quest deck. - * - * @author Forge - * @version $Id$ - */ -public class DeckSingleQuest { - private String deckName; - private String displayName; - private String diff; - private String desc; - private String iconFilename; - private String cardReward; - - private int creditsReward; - private int numberWinsRequired; - private int AILife; - private int id; - - private boolean repeatable; - private ImageIcon icon; - private Deck deckObj; - - /** - *

Constructor for DeckSingleQuest

- * - * @param {@link java.lang.String} storing name of AI deck for this quest - */ - public DeckSingleQuest(Deck d) { - // Get deck object and properties for this opponent. - this.deckObj = d; - this.deckName = d.getName(); - this.id = Integer.parseInt(deckObj.getMetadata("ID")); - this.displayName = deckObj.getMetadata("DisplayName"); - this.diff = deckObj.getMetadata("Difficulty"); - this.desc = deckObj.getMetadata("Description"); - this.iconFilename = deckObj.getMetadata("Icon"); - this.cardReward = deckObj.getMetadata("CardReward"); - this.creditsReward = Integer.parseInt(deckObj.getMetadata("CreditsReward")); - this.numberWinsRequired = Integer.parseInt(deckObj.getMetadata("NumberWinsRequired")); - this.AILife = Integer.parseInt(deckObj.getMetadata("AILife")); - - // Default icon - this.icon = GuiUtils.getIconFromFile(displayName + ".jpg"); - - // If non-default icon defined, use it. Any filetype accepted. - if(!iconFilename.equals("")) { - this.icon = GuiUtils.getIconFromFile(iconFilename); - } - - // Repeatability test - if(deckObj.getMetadata("Repeatable").equals("true")) { - this.repeatable = true; - } - else { - this.repeatable = false; - } - - } - - /** - *

getID()

- * Retrieve ID number of this quest deck for recordkeeping. - * - * @return {@link java.lang.int} - */ - public int getID() { - return this.id; - } - - /** - *

getDifficulty()

- * Retrieve rated difficulty of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDifficulty() { - return this.diff; - } - - /** - *

getDescription()

- * Retrieve description of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDescription() { - return this.desc; - } - - /** - *

getDisplayName()

- * Retrieve display name of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDisplayName() { - return this.displayName; - } - - /** - *

getDeckName()

- * Retrieve file name of this quest deck. - * - * @return {@link java.lang.String} - */ - public String getDeckName() { - return this.deckName; - } - - /** - *

getCardReward()

- * Retrieve cards rewarded after a win with this quest deck. - * - * @return {@link java.lang.String} - */ - private String getCardReward() { - return this.cardReward; - } - - /** - *

getCardRewardList()

- * Retrieve cards rewarded after a win with this quest deck. - * - * @return String[] - */ - public List getCardRewardList() { - List cardRewardList = new ArrayList(); - - String[] details = this.getCardReward().split(" "); - - // Set quantity, color and rarity from file meta. - String cardscolor; - CardRarity rarity; - int quantity = Integer.parseInt(details[0]); - - // Color - if(details[1].toLowerCase().equals("random")) { - cardscolor = null; - } - else if(details[1].toLowerCase().equals("blue")) { - cardscolor = Constant.Color.Blue; - } - else if(details[1].toLowerCase().equals("black")) { - cardscolor = Constant.Color.Black; - } - else if(details[1].toLowerCase().equals("green")) { - cardscolor = Constant.Color.Green; - } - else if(details[1].toLowerCase().equals("red")) { - cardscolor = Constant.Color.Red; - } - else if(details[1].toLowerCase().equals("white")) { - cardscolor = Constant.Color.White; - } - else if(details[1].toLowerCase().equals("multi-color") || - details[1].toLowerCase().equals("multi-colored")) { - cardscolor = "Multicolor"; - } - else if(details[1].toLowerCase().equals("colorless")) { - cardscolor = Constant.Color.Colorless; - } - else { - cardscolor = null; - System.err.println("DeckSingleQuest > getCardRewardList() reports "+ - "a badly formed card reward for quest "+ - this.getID()+".\n The color "+details[1]+" is not permitted.\n"+ - "Random colors have been substituted."); - } - - // Rarity - if(details[2].toLowerCase().equals("rares")) { - rarity = CardRarity.Rare; - } - else { - rarity = CardRarity.Common; - } - - // Generate deck list. - QuestBoosterPack pack = new QuestBoosterPack(); - return pack.generateCards(quantity, rarity, cardscolor); - } - - /** - *

getNumberWinsRequired()

- * Retrieve number of wins required to play against this quest deck. - * - * @return {@link java.lang.int} - */ - public int getNumberWinsRequired() { - return this.numberWinsRequired; - } - - /** - *

getAILife()

- * Retrieve starting value of life for the AI playing this quest deck. - * - * @return {@link java.lang.int} - */ - public int getAILife() { - return this.AILife; - } - - /** - *

getCreditsReward()

- * Retrieve number of credits rewarded after a win against this quest deck. - * - * @return {@link java.lang.int} - */ - public int getCreditsReward() { - return this.creditsReward; - } - - /** - *

getDeck()

- * Retrieve this quest deck. - * - * @return {@link forge.deck.Deck} - */ - public Deck getDeck() { - return this.deckObj; - } - - /** - *

getIconFilename()

- * Retrieve file name of preferred icon - * - * @return {@link java.lang.String} - */ - public String getIconFilename() { - return this.iconFilename; - } - - /** - *

getIcon()

- * Retrieve the icon used with this quest deck. - * - * @return {@link javax.swing.ImageIcon} - */ - public ImageIcon getIcon() { - return this.icon; - } - - /** - *

getRepeatable.

- * Retrieve boolean indicating if this quest is repeatable. - * - */ - public boolean getRepeatable() { - return this.repeatable; - } - -} diff --git a/src/main/java/forge/quest/data/ManagerBattle.java b/src/main/java/forge/quest/data/ManagerBattle.java deleted file mode 100644 index 4cb3579693d..00000000000 --- a/src/main/java/forge/quest/data/ManagerBattle.java +++ /dev/null @@ -1,237 +0,0 @@ -package forge.quest.data; - -import forge.AllZone; -import forge.FileUtil; -import forge.deck.Deck; -import forge.deck.DeckManager; -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -import java.io.File; -import java.util.*; - -/** - *

QuestBattleManager

- * MODEL - Provides static methods to accomplish two key tasks: - * 1. Stores various AI difficulty decks and generates opponent list based on quest record. - * - * 2. Can instantiate a DeckSingleBattle for each opponent in the list. - * - * @author Forge - * @version $Id$ - */ - -// This could be combined with BattleManager and moved into QuestUtil. -public class ManagerBattle { - /** Constant aiDecks */ - private static transient Map aiDecks = new HashMap(); - /** Constant easyAIDecks */ - private static transient List easyAIDecks; - /** Constant mediumAIDecks */ - private static transient List mediumAIDecks; - /** Constant hardAIDecks */ - private static transient List hardAIDecks; - /** Constant veryHardAIDecks */ - private static transient List veryHardAIDecks; - - static { - List aiDeckNames = getAIDeckNames(); - easyAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.EASY), aiDeckNames); - mediumAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.MEDIUM), aiDeckNames); - hardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.HARD), aiDeckNames); - veryHardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.VERYHARD), aiDeckNames); - } - - - /** - *

removeAIDeck.

- * Removes a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param deckName a {@link java.lang.String} object. - */ - public static void removeAIDeck(String deckName) { - aiDecks.remove(deckName); - } - - /** - *

addAIDeck.

- * Adds a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param d a {@link forge.deck.Deck} object. - */ - public static void addAIDeck(Deck d) { - aiDecks.put(d.getName(), d); - } - - /** - *

getAIDeckFromMap.

- * Returns a deck object stored in the - *{@link forge.quest.gui.main.aiDecks} map. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromMap(String deckName) { - if (!aiDecks.containsKey(deckName)) { - ErrorViewer.showError(new Exception(), - "QuestData : getAIDeckFromMap(String deckName) error, deck name not found - %s", deckName); - } - - return aiDecks.get(deckName); - } - - /** - *

getAIDeckNames.

- * Returns a list of decks stored in the - * {@link forge.quest.gui.main.aiDecks} map. - * - * @return a {@link java.util.List} object. - */ - public static List getAIDeckNames() { - return new ArrayList(aiDecks.keySet()); - } - - /** - *

getDeckFromFile.

- * Returns a deck object built from a file name. - * Req'd because NewConstants.QUEST.DECKS must be used. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromFile(String deckName) { - final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); - final DeckManager manager = new DeckManager(file); - return manager.getDeck(deckName); - } - - /** - *

getOpponent.

- * - * Poorly named; AllZoneUtil already has a method called getOpponents. - * ????? Mechanics of this still a mystery ????? - * - * @param aiDeck a {@link java.util.List} object. - * @param number a int. - * @return a {@link java.lang.String} object. - */ - public static String getOpponent(List aiDeck, int number) { - //This is to make sure that the opponents do not change when the deck editor is launched. - List deckListCopy = new ArrayList(aiDeck); - Collections.shuffle(deckListCopy, new Random(AllZone.getQuestData().getRandomSeed())); - - return deckListCopy.get(number); - } - - - /** - *

generateBattles.

- * Generates an array of new opponents based on current win conditions. - * - * @return an array of {@link java.lang.String} objects. - */ - public static String[] generateBattles() { - int index = AllZone.getQuestData().getDifficultyIndex(); - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(easyAIDecks, 1), - getOpponent(easyAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1), - getOpponent(mediumAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) { - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(veryHardAIDecks, 0)}; - } - - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(hardAIDecks, 2)}; - } // End generateBattles() - - /** - *

readFile.

- * A reader util for accessing the AI deck list text files. - * - * @param file a {@link java.io.File} object. - * @param aiDecks a {@link java.util.List} object. - * @return a {@link java.util.List} object. - */ - private static List readFile(File file, List aiDecks) { - ArrayList list = FileUtil.readFile(file); - - //remove any blank lines - ArrayList noBlankLines = new ArrayList(); - String s; - for (String aList : list) { - s = aList.trim(); - if (!s.equals("")) { - noBlankLines.add(s); - } - } - list = noBlankLines; - - if (list.size() < 3) { - ErrorViewer.showError(new Exception(), - "QuestData : readFile() error, file %s is too short, it must contain at least 3 ai deck names", - file); - } - - for (String aList : list) { - if (!aiDecks.contains(aList)) { - aiDecks.add(aList); - } - } - - return list; - } - - /** - *

getBattles.

- * - * Returns list of DeckSingleBattle objects storing data - * of the battles currently available. - * - * @return a {@link java.util.List} object. - */ - public static List getBattles() { - List battlesAvailable = new ArrayList(); - - String[] oppDecks = ManagerBattle.generateBattles(); - - for (String oppDeckName : oppDecks) { - battlesAvailable.add(new DeckSingleBattle(getAIDeckFromFile(oppDeckName))); - } - - return battlesAvailable; - } - -} diff --git a/src/main/java/forge/quest/data/ManagerQuest.java b/src/main/java/forge/quest/data/ManagerQuest.java deleted file mode 100644 index 68c6d45bbbf..00000000000 --- a/src/main/java/forge/quest/data/ManagerQuest.java +++ /dev/null @@ -1,104 +0,0 @@ -package forge.quest.data; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import forge.AllZone; -import forge.deck.Deck; -import forge.deck.DeckManager; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - - -/** - *

ManagerQuest

- * MODEL - Provides static methods to work with quest-related tasks. - * - */ - -// This could be combined with BattleManager and moved into QuestUtil? -public class ManagerQuest { - /** - *

getQuests

- * - * Returns list of DeckSingleQuest objects storing data - * of the quests currently available. - * - * @return a {@link java.util.List} object. - */ - - public static List getQuests() { - QuestData questData = AllZone.getQuestData(); - - List idsCompleted = questData.getCompletedQuests(); - List idsAvailable = new ArrayList(); - List allQuests = new ArrayList(); - List questsAvailable = new ArrayList(); - - // Generate DeckSingleQuest objects for available quest IDs. - // If there are quests IDs available, use them. - if (questData.getAvailableQuests() != null && questData.getAvailableQuests().size() > 0) { - idsAvailable = questData.getAvailableQuests(); - for (int id : idsAvailable) { - questsAvailable.add(new DeckSingleQuest(getAIDeckFromFile("quest"+id))); - } - } - // Otherwise, re-generate list. - // To do this, each quest file must be opened and metadata examined. - // DeckSingleQuest objects are grabbed directly from opened list. - else { - File[] files = ForgeProps.getFile(NewConstants.QUEST.DECKS).listFiles(); - - for(File f : files) { - if(!f.isDirectory() && f.getName().substring(0,5).equals("quest")) { - DeckSingleQuest temp = new DeckSingleQuest(getAIDeckFromFile( - f.getName().substring(0, f.getName().lastIndexOf('.')))); - - idsAvailable.add(temp.getID()); - if (temp.getNumberWinsRequired() <= questData.getWin() && - !idsCompleted.contains(temp.getID())) { - allQuests.add(temp); - } - } - } - - // Limit available IDs. - int maxQuests = questData.getWin() / 10; - if (maxQuests > 5) { - maxQuests = 5; - } - if (idsAvailable.size() < maxQuests) { - maxQuests = idsAvailable.size(); - } - - Collections.shuffle(idsAvailable); - idsAvailable = idsAvailable.subList(0,maxQuests); - - questData.setAvailableQuests(idsAvailable); - questData.saveData(); - - for (int id : idsAvailable) { - questsAvailable.add(allQuests.get(id)); - } - } - - return questsAvailable; - } - - - /** - *

getDeckFromFile.

- * Returns a deck object built from a file name. - * Req'd because NewConstants.QUEST.DECKS must be used. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromFile(String deckName) { - final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); - final DeckManager manager = new DeckManager(file); - return manager.getDeck(deckName); - } -} diff --git a/src/main/java/forge/quest/data/QuestUtil.java b/src/main/java/forge/quest/data/QuestUtil.java index 528e2547b25..7a885a75ce7 100644 --- a/src/main/java/forge/quest/data/QuestUtil.java +++ b/src/main/java/forge/quest/data/QuestUtil.java @@ -1,15 +1,12 @@ package forge.quest.data; -import java.util.List; -import java.util.Map.Entry; - import forge.*; -import forge.card.CardPoolView; -import forge.card.CardPrinted; +import forge.card.CardRarity; + +import java.util.ArrayList; /** *

QuestUtil class.

- * General utility class for quest tasks. * * @author Forge * @version $Id$ @@ -22,43 +19,41 @@ public class QuestUtil { * @param qd a {@link forge.quest.data.QuestData} object. * @return a {@link forge.CardList} object. */ - public static CardList getAIExtraCards(QuestData qd) { + public static CardList getComputerCreatures(final QuestData qd) { return new CardList(); } - + /** *

getComputerCreatures.

- * Assembles extra cards computer will have in play. * * @param qd a {@link forge.quest.data.QuestData} object. * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getAIExtraCards(QuestData qd, DeckSingleQuest sq) { + public static CardList getComputerCreatures(final QuestData qd, Quest_Assignment qa) { CardList list = new CardList(); - if (sq != null) { - CardPoolView compCards = sq.getDeck().getAIExtraCards(); + if (qa != null) { + ArrayList compCards = qa.getCompy(); - /*for (String s : compCards) { - Card c = extraCardBuilder(s); - if(c!=null) { - list.add(c); - } - }*/ + for (String s : compCards) { + Card c = AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + list.add(c); + } } return list; } - + /** *

getHumanPlantAndPet.

- * Starts up empty list of extra cards for human. - * Adds plant and pet as appropriate. * * @param qd a {@link forge.quest.data.QuestData} object. * @return a {@link forge.CardList} object. */ - public static CardList getHumanExtraCards(QuestData qd) { - System.out.println("LOOKATME"); + public static CardList getHumanPlantAndPet(final QuestData qd) { CardList list = new CardList(); if (qd.getPetManager().shouldPetBeUsed()) { @@ -74,115 +69,38 @@ public class QuestUtil { /** *

getHumanPlantAndPet.

- * Checks for plant and pet, then adds extra cards for human from quest deck. - * Assembles extra cards human will have in play. * * @param qd a {@link forge.quest.data.QuestData} object. - * @param qq a DeckSingleQuest object. + * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getHumanExtraCards(QuestData qd, DeckSingleQuest sq) { - CardList list = getHumanExtraCards(qd); + public static CardList getHumanPlantAndPet(final QuestData qd, Quest_Assignment qa) { + CardList list = getHumanPlantAndPet(qd); - /*if (sq != null) { - List> humanCards = - sq.getDeck().getHumanExtraCards().getOrderedList(); + if (qa != null) { + list.addAll(qa.getHuman()); + } - for (String s : humanCards) { - Card c = extraCardBuilder(s); - if(c!=null) { - list.add(c); - } - } - }*/ return list; } - - /** - *

extraCardBuilder.

- * Assembles card objects for extra cards and tokens for AI and human. - * - * @param String card name - * @return Card object. - */ - public static Card extraCardBuilder(String s) { - Card c = null; - int i; - - if(s.substring(0,5).equals("TOKEN")) { - String[] tokenProps = s.split("\\|"); - - if(tokenProps.length < 6) { - System.err.println("QuestUtil > extraCardBuilder() reports an " + - "incomplete token in the current deck.\n"+ - "Token should follow the form:\n"+ - "TOKEN|color|attack|defense|name|type|type...\n"+ - "For example: TOKEN|G|0|1|sheep|Creature"); - return c; - } - else { - c = new Card(); - - c.setManaCost("0"); - c.addColor(tokenProps[1]); - c.setBaseAttack(Integer.parseInt(tokenProps[2])); - c.setBaseDefense(Integer.parseInt(tokenProps[3])); - - // Uppercase each word in name - StringBuilder name = new StringBuilder(tokenProps[4]); - i = 0; - do { - name.replace(i, i + 1, name.substring(i,i + 1).toUpperCase()); - i = name.indexOf(" ", i) + 1; - } while (i > 0 && i < name.length()); - c.setName(name.toString()); - - i = 4; - while(isetupQuest.

* * @param qa a {@link forge.Quest_Assignment} object. */ - - /* public static void setupQuest(Quest_Assignment qa) { QuestBoosterPack pack = new QuestBoosterPack(); qa.clearCompy(); int id = qa.getId(); - Generator cards = YieldUtils.toGenerator(AllZone.getCardFactory()); - if (id == 1) //White Dungeon { qa.addCompy("Divine Presence"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.White)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.White)); } else if (id == 2) //Blue Dungeon { CardList humanList = new CardList(); @@ -197,17 +115,17 @@ public class QuestUtil { qa.addCompy("Forced Fruition"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.Blue)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.Blue)); } else if (id == 3) //Black Dungeon { qa.addCompy("Infernal Genesis"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.Black)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.Black)); } else if (id == 4) //Red Dungeon { qa.addCompy("Furnace of Rath"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.Red)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.Red)); } else if (id == 5) //Green Dungeon { CardList humanList = new CardList(); @@ -223,17 +141,17 @@ public class QuestUtil { qa.addCompy("Eladamri's Vineyard"); qa.addCompy("Upwelling"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.Green)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.Green)); } else if (id == 6) //Colorless Dungeon { for (int i = 0; i < 3; i++) qa.addCompy("Eon Hub"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, Constant.Color.Colorless)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, Constant.Color.Colorless)); } else if (id == 7) //Gold Dungeon { qa.addCompy("Darksteel Ingot"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, "Multicolor")); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, "Multicolor")); } else if (id == 8) { CardList humanList = new CardList(); for (int i = 0; i < 3; i++) { @@ -258,7 +176,7 @@ public class QuestUtil { humanList.add(c); } qa.setHuman(humanList); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, null)); } else if (id == 9) { CardList humanList = new CardList(); Card c = AllZone.getCardFactory().getCard("Trusty Machete", AllZone.getHumanPlayer()); @@ -273,7 +191,7 @@ public class QuestUtil { for (int i = 0; i < 3; i++) qa.addCompy("Wall of Wood"); - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, Constant.Color.Green)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, Constant.Color.Green)); } else if (id == 10) { CardList humanList = new CardList(); @@ -311,7 +229,7 @@ public class QuestUtil { qa.addCompy("Scathe Zombies"); qa.addCompy("Mass of Ghouls"); - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, Constant.Color.Black)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, Constant.Color.Black)); } else if (id == 11) // The King's Contest { CardList humanList = new CardList(); @@ -326,7 +244,7 @@ public class QuestUtil { qa.addCompy("Loyal Retainers"); - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, null)); } else if (id == 12) // Barroom Brawl { CardList humanList = new CardList(); @@ -357,7 +275,7 @@ public class QuestUtil { qa.addCompy("Lowland Giant"); - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, null)); } else if (id == 13) // The Court Jester { CardList humanList = new CardList(); @@ -372,7 +290,7 @@ public class QuestUtil { qa.addCompy("Teferi's Puzzle Box"); - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, "Multicolor")); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, "Multicolor")); } else if (id == 14) // Ancient Battlefield { CardList humanList = new CardList(); @@ -394,7 +312,7 @@ public class QuestUtil { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, null)); } else if (id == 15) // Don't Play With Matches { CardList humanList = new CardList(); @@ -416,11 +334,11 @@ public class QuestUtil { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, Constant.Color.Red)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, Constant.Color.Red)); } else if (id == 16) // Mines of Kazum Durl { CardList humanList = new CardList(); - String humanSetupCards[] = {"Dwarven Demolition Team", "Dwarven Pony", "Dwarven Trader"}; + String[] humanSetupCards = {"Dwarven Demolition Team", "Dwarven Pony", "Dwarven Trader"}; for (int i = 0; i < 3; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -432,18 +350,18 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = + String[] compySetupCards = {"Wall of Earth", "Wall of Air", "Wall of Ice", "Wall of Light", "Carrion Wall", "Steel Wall"}; for (int i = 0; i < 6; i++) { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, Constant.Color.Green)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, Constant.Color.Green)); } else if (id == 17) // House Party { CardList humanList = new CardList(); - String humanSetupCards[] = {"Hopping Automaton", "Honden of Life's Web", "Forbidden Orchard"}; + String[] humanSetupCards = {"Hopping Automaton", "Honden of Life's Web", "Forbidden Orchard"}; for (int i = 0; i < 3; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -455,17 +373,17 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = {"Honden of Infinite Rage", "Mikokoro, Center of the Sea", "Tidehollow Strix"}; + String[] compySetupCards = {"Honden of Infinite Rage", "Mikokoro, Center of the Sea", "Tidehollow Strix"}; for (int i = 0; i < 3; i++) { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 4, Constant.Rarity.Rare, Constant.Color.Colorless)); + qa.setCardRewardList(pack.generateCards(4, CardRarity.Rare, Constant.Color.Colorless)); } else if (id == 18) // Crows in the Field { CardList humanList = new CardList(); - String humanSetupCards[] = {"Straw Soldiers", "Femeref Archers", "Moonglove Extract"}; + String[] humanSetupCards = {"Straw Soldiers", "Femeref Archers", "Moonglove Extract"}; for (int i = 0; i < 3; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -477,17 +395,17 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = {"Defiant Falcon", "Soulcatcher", "Storm Crow", "Hypnotic Specter"}; + String[] compySetupCards = {"Defiant Falcon", "Soulcatcher", "Storm Crow", "Hypnotic Specter"}; for (int i = 0; i < 4; i++) { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 5, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(5, CardRarity.Rare, null)); } else if (id == 19) // The Desert Caravan { CardList humanList = new CardList(); - String humanSetupCards[] = {"Spidersilk Net", "Dromad Purebred"}; + String[] humanSetupCards = {"Spidersilk Net", "Dromad Purebred"}; for (int i = 0; i < 2; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -499,17 +417,17 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = {"Ambush Party", "Ambush Party", "Gnat Alley Creeper", "Ambush Party", "Ambush Party"}; + String[] compySetupCards = {"Ambush Party", "Ambush Party", "Gnat Alley Creeper", "Ambush Party", "Ambush Party"}; for (int i = 0; i < 5; i++) { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 5, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(5, CardRarity.Rare, null)); } else if (id == 20) // Blood Oath { CardList humanList = new CardList(); - String humanSetupCards[] = {"Counterbalance", "Hatching Plans", "Ley Druid"}; + String[] humanSetupCards = {"Counterbalance", "Hatching Plans", "Ley Druid"}; for (int i = 0; i < 3; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -521,13 +439,13 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = {"Ior Ruin Expedition", "Oversold Cemetery", "Trapjaw Kelpie"}; + String[] compySetupCards = {"Ior Ruin Expedition", "Oversold Cemetery", "Trapjaw Kelpie"}; for (int i = 0; i < 3; i++) { qa.addCompy(compySetupCards[i]); } - qa.setCardRewardList(pack.generateCards(cards, 5, Constant.Rarity.Rare, Constant.Color.Colorless)); + qa.setCardRewardList(pack.generateCards(5, CardRarity.Rare, Constant.Color.Colorless)); } else if (id == 21) // Private Domain { CardList humanList = new CardList(); @@ -541,16 +459,17 @@ public class QuestUtil { qa.setHuman(humanList); - String compySetupCards[] = {"Plains", "Island", "Swamp", "Mountain", "Forest"}; + String[] compySetupCards = {"Plains", "Island", "Swamp", "Mountain", "Forest"}; - for (int i = 0; i < 5; i++) + for (int i = 0; i < 5; i++) { qa.addCompy(compySetupCards[i]); + } - qa.setCardRewardList(pack.generateCards(cards, 6, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(6, CardRarity.Rare, null)); } else if (id == 22) // Pied Piper { CardList humanList = new CardList(); - String humanSetupCards[] = {"Volunteer Militia", "Land Tax", "Elvish Farmer", "An-Havva Township"}; + String[] humanSetupCards = {"Volunteer Militia", "Land Tax", "Elvish Farmer", "An-Havva Township"}; for (int i = 0; i < 4; i++) { Card c = AllZone.getCardFactory().getCard(humanSetupCards[i], AllZone.getHumanPlayer()); @@ -562,15 +481,15 @@ public class QuestUtil { } qa.setHuman(humanList); - String compySetupCards[] = {"Darksteel Citadel", "Relentless Rats"}; + String[] compySetupCards = {"Darksteel Citadel", "Relentless Rats"}; - for (int i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { qa.addCompy(compySetupCards[i]); + } - qa.setCardRewardList(pack.generateCards(cards, 3, Constant.Rarity.Rare, null)); + qa.setCardRewardList(pack.generateCards(3, CardRarity.Rare, null)); } } - */ -}//QuestUtil +} //QuestUtil diff --git a/src/main/java/forge/quest/gui/PanelSingleBattle.java b/src/main/java/forge/quest/gui/PanelSingleBattle.java deleted file mode 100644 index 02b8b18ef2b..00000000000 --- a/src/main/java/forge/quest/gui/PanelSingleBattle.java +++ /dev/null @@ -1,100 +0,0 @@ -package forge.quest.gui; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; - -import javax.swing.BoxLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; - -import forge.gui.GuiUtils; -import forge.gui.SelectablePanel; -import forge.quest.data.DeckSingleBattle; - -/** - *

PanelSingleBattle

- * VIEW - A selectable panel for battles available in Quest mode. - * - */ -@SuppressWarnings("serial") -public class PanelSingleBattle extends SelectablePanel { - - private final DeckSingleBattle battle; - - public PanelSingleBattle(DeckSingleBattle b) { - battle = b; - final JPanel centerPanel = new JPanel(); - - this.setLayout(new BorderLayout(5, 5)); - - // Icon stuff - JLabel iconLabel; - - if (battle.getIcon() == null) { - iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40)); - } else { - iconLabel = new JLabel(GuiUtils.getResizedIcon(battle.getIcon(), 40, 40)); - } - - iconLabel.setBorder(new LineBorder(Color.BLACK)); - iconLabel.setAlignmentY(TOP_ALIGNMENT); - - JPanel iconPanel = new JPanel(new BorderLayout()); - iconPanel.setOpaque(false); - iconPanel.add(iconLabel, BorderLayout.NORTH); - this.add(iconPanel, BorderLayout.WEST); - - centerPanel.setOpaque(false); - centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel centerTopPanel = new JPanel(); - centerTopPanel.setOpaque(false); - centerTopPanel.setAlignmentX(LEFT_ALIGNMENT); - centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS)); - - JLabel nameLabel = new JLabel(battle.getDisplayName()); - GuiUtils.setFontSize(nameLabel, 20); - nameLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(nameLabel); - - GuiUtils.addExpandingHorizontalSpace(centerTopPanel); - - JLabel difficultyLabel = new JLabel(battle.getDifficulty()); - difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(difficultyLabel); - centerPanel.add(centerTopPanel); - - GuiUtils.addGap(centerPanel); - - JLabel descriptionLabel = new JLabel(battle.getDescription()); - descriptionLabel.setAlignmentX(LEFT_ALIGNMENT); - centerPanel.add(descriptionLabel); - - this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80)); - this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5))); - } - - /** - *

getIconFilename()

- * Retrieves filename of icon used in this panel's display. - * - * @return - */ - public String getIconFilename() { - return this.battle.getIconFilename(); - } - - /** - *

getQuest()

- * - * @return the DeckSingleBattle model associated with this panel. - */ - public DeckSingleBattle getBattle() { - return this.battle; - } -} diff --git a/src/main/java/forge/quest/gui/PanelSingleQuest.java b/src/main/java/forge/quest/gui/PanelSingleQuest.java deleted file mode 100644 index b4f119ca457..00000000000 --- a/src/main/java/forge/quest/gui/PanelSingleQuest.java +++ /dev/null @@ -1,110 +0,0 @@ -package forge.quest.gui; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; - -import javax.swing.BoxLayout; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.CompoundBorder; -import javax.swing.border.EmptyBorder; -import javax.swing.border.LineBorder; - -import forge.gui.GuiUtils; -import forge.gui.SelectablePanel; -import forge.quest.data.DeckSingleQuest; - -/** - *

PanelSingleQuest

- * VIEW - A selectable panel for quests available in Quest mode. - * - */ -@SuppressWarnings("serial") -public class PanelSingleQuest extends SelectablePanel { - - private final DeckSingleQuest quest; - - public PanelSingleQuest(DeckSingleQuest q) { - quest = q; - final JPanel centerPanel = new JPanel(); - - this.setLayout(new BorderLayout(5, 5)); - - JLabel iconLabel; - - if (quest.getIcon() == null) { - iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40)); - } else { - iconLabel = new JLabel(GuiUtils.getResizedIcon(quest.getIcon(), 40, 40)); - } - - iconLabel.setBorder(new LineBorder(Color.BLACK)); - iconLabel.setAlignmentY(TOP_ALIGNMENT); - - JPanel iconPanel = new JPanel(new BorderLayout()); - iconPanel.setOpaque(false); - iconPanel.add(iconLabel, BorderLayout.NORTH); - this.add(iconPanel, BorderLayout.WEST); - - centerPanel.setOpaque(false); - centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel centerTopPanel = new JPanel(); - centerTopPanel.setOpaque(false); - centerTopPanel.setAlignmentX(LEFT_ALIGNMENT); - centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS)); - - JLabel nameLabel = new JLabel(quest.getDisplayName()); - GuiUtils.setFontSize(nameLabel, 20); - nameLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(nameLabel); - - GuiUtils.addExpandingHorizontalSpace(centerTopPanel); - - JLabel difficultyLabel = new JLabel(quest.getDifficulty()); - difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT); - centerTopPanel.add(difficultyLabel); - centerPanel.add(centerTopPanel); - - GuiUtils.addGap(centerPanel); - - JLabel descriptionLabel = new JLabel(quest.getDescription()); - descriptionLabel.setAlignmentX(LEFT_ALIGNMENT); - centerPanel.add(descriptionLabel); - - // Temporarily removed; no meaning yet (all quests repeat anyway) - /*JLabel repeatabilityLabel; - if (quest.getRepeatable()) { - repeatabilityLabel = new JLabel("This quest is repeatable"); - } else { - repeatabilityLabel = new JLabel("This quest is not repeatable"); - } - - GuiUtils.addGap(centerPanel); - centerPanel.add(repeatabilityLabel);*/ - - this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80)); - this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5))); - } - - /** - *

getIconFilename()

- * Retrieves filename of icon used in this panel's display. - * - * @return - */ - public String getIconFilename() { - return this.quest.getIconFilename(); - } - - /** - *

getQuest()

- * - * @return the DeckSingleQuest model associated with this panel. - */ - public DeckSingleQuest getQuest() { - return this.quest; - } -} diff --git a/src/main/java/forge/quest/gui/QuestFrame.java b/src/main/java/forge/quest/gui/QuestFrame.java index 0fad3534028..d72750139ce 100644 --- a/src/main/java/forge/quest/gui/QuestFrame.java +++ b/src/main/java/forge/quest/gui/QuestFrame.java @@ -3,6 +3,7 @@ package forge.quest.gui; import forge.AllZone; import forge.gui.GuiUtils; import forge.quest.gui.bazaar.QuestBazaarPanel; +import forge.quest.gui.main.QuestMainPanel; import forge.view.swing.OldGuiNewGame; import javax.swing.*; diff --git a/src/main/java/forge/quest/gui/QuestMainPanel.java b/src/main/java/forge/quest/gui/QuestMainPanel.java deleted file mode 100644 index 02f19dcddea..00000000000 --- a/src/main/java/forge/quest/gui/QuestMainPanel.java +++ /dev/null @@ -1,819 +0,0 @@ -package forge.quest.gui; - - -import forge.*; -import forge.deck.Deck; -import forge.gui.GuiUtils; -import forge.gui.SelectablePanel; -import forge.gui.deckeditor.DeckEditorQuest; -import forge.gui.deckeditor.DeckEditorShop; -import forge.quest.data.DeckSingleBattle; -import forge.quest.data.ManagerBattle; -import forge.quest.data.QuestData; -import forge.quest.data.DeckSingleQuest; -import forge.quest.data.ManagerQuest; -import forge.quest.data.item.QuestItemZeppelin; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; - - -/** - *

QuestMainPanel class.

- * VIEW - handler for main screen of Quest GUI. - * - * @author Forge - * @version $Id$ - */ -public class QuestMainPanel extends QuestAbstractPanel { - /** Constant serialVersionUID=6142934729724012402L */ - private static final long serialVersionUID = 6142934729724012402L; - - private forge.quest.data.QuestData questData; - - JLabel creditsLabel = new JLabel(); - JLabel lifeLabel = new JLabel(); - JLabel statsLabel = new JLabel(); - JLabel titleLabel = new JLabel(); - JLabel nextQuestLabel = new JLabel(); - - JComboBox petComboBox = new JComboBox(); - JComboBox deckComboBox = new JComboBox(); - - JButton questButton = new JButton("Quests"); - JButton playButton = new JButton("Play"); - - private SelectablePanel lastPanelSelected; - - JPanel nextMatchPanel = new JPanel(); - CardLayout nextMatchLayout; - - boolean isShowingQuests = false; - private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode"); - //private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true); - private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land"); - private JCheckBox petCheckBox = new JCheckBox("Summon Pet"); - - private JCheckBox plantBox = new JCheckBox("Summon Plant"); - /** Constant NO_DECKS_AVAILABLE="No decks available" */ - private static final String NO_DECKS_AVAILABLE = "No decks available"; - /** Constant BATTLES="Battles" */ - private static final String BATTLES = "Battles"; - /** Constant QUESTS="Quests" */ - private static final String QUESTS = "Quests"; - - //TODO: Make this ordering permanent - /** Constant lastUsedDeck="//TODO: Make this ordering permanent" */ - private static String lastUsedDeck; - private JButton zeppelinButton = new JButton("Launch
Zeppelin", - GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); - private JPanel zeppelinPanel = new JPanel(); - - /** - *

Constructor for QuestMainPanel.

- * - * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. - */ - public QuestMainPanel(QuestFrame mainFrame) { - super(mainFrame); - questData = AllZone.getQuestData(); - - initUI(); - } - - /** - *

initUI.

- */ - private void initUI() { - refresh(); - this.setLayout(new BorderLayout(5, 5)); - JPanel centerPanel = new JPanel(new BorderLayout()); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel northPanel = createStatusPanel(); - this.add(northPanel, BorderLayout.NORTH); - - JPanel eastPanel = createSidePanel(); - this.add(eastPanel, BorderLayout.EAST); - - JPanel matchSettingsPanel = createMatchSettingsPanel(); - centerPanel.add(matchSettingsPanel, BorderLayout.SOUTH); - - centerPanel.add(nextMatchPanel, BorderLayout.CENTER); - this.setBorder(new EmptyBorder(5, 5, 5, 5)); - - } - - /** - *

createStatusPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createStatusPanel() { - JPanel northPanel = new JPanel(); - JLabel modeLabel; - JLabel difficultyLabel;//Create labels at the top - titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28)); - titleLabel.setAlignmentX(LEFT_ALIGNMENT); - northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); - northPanel.add(titleLabel); - - northPanel.add(Box.createVerticalStrut(5)); - - JPanel statusPanel = new JPanel(); - statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); - statusPanel.setAlignmentX(LEFT_ALIGNMENT); - - modeLabel = new JLabel(questData.getMode()); - statusPanel.add(modeLabel); - statusPanel.add(Box.createHorizontalGlue()); - - difficultyLabel = new JLabel(questData.getDifficulty()); - statusPanel.add(difficultyLabel); - statusPanel.add(Box.createHorizontalGlue()); - - statusPanel.add(statsLabel); - - northPanel.add(statusPanel); - return northPanel; - } - - /** - *

createSidePanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createSidePanel() { - JPanel panel = new JPanel(); - JPanel optionsPanel; //Create options checkbox list - optionsPanel = createOptionsPanel(); - - List eastComponents = new ArrayList(); - //Create buttons - - JButton mainMenuButton = new JButton("Return to Main Menu"); - mainMenuButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - mainFrame.returnToMainMenu(); - } - }); - eastComponents.add(mainMenuButton); - - JButton cardShopButton = new JButton("Card Shop"); - cardShopButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.showCardShop(); - } - }); - eastComponents.add(cardShopButton); - cardShopButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); - - JButton bazaarButton = null; - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - - bazaarButton = new JButton("Bazaar"); - bazaarButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.showBazaar(); - } - }); - eastComponents.add(bazaarButton); - bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); - } - - - questButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.toggleBattleQuest(); - } - }); - eastComponents.add(questButton); - questButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18)); - questButton.setPreferredSize(new Dimension(0, 60)); - - - playButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.launchGame(); - } - }); - - playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28)); - playButton.setPreferredSize(new Dimension(0, 100)); - - - eastComponents.add(playButton); - eastComponents.add(optionsPanel); - - GuiUtils.setWidthToMax(eastComponents); - - panel.add(mainMenuButton); - GuiUtils.addGap(panel); - panel.add(optionsPanel); - panel.add(Box.createVerticalGlue()); - panel.add(Box.createVerticalGlue()); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - panel.add(this.lifeLabel); - this.lifeLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); - this.lifeLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("Life.png"), 30, 30)); - } - - GuiUtils.addGap(panel); - panel.add(this.creditsLabel); - this.creditsLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("CoinStack.png"), 30, 30)); - this.creditsLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); - GuiUtils.addGap(panel, 10); - panel.add(cardShopButton); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - GuiUtils.addGap(panel); - panel.add(bazaarButton); - } - - panel.add(Box.createVerticalGlue()); - - panel.add(questButton); - this.nextQuestLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 11)); - panel.add(nextQuestLabel); - GuiUtils.addGap(panel); - - panel.add(playButton); - - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - return panel; - } - - /** - *

createOptionsPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createOptionsPanel() { - JPanel optionsPanel; - optionsPanel = new JPanel(); - optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); - - //optionsPanel.add(this.newGUICheckbox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.smoothLandCheckBox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.devModeCheckBox); - optionsPanel.setBorder(new TitledBorder(new EtchedBorder(), "Options")); - return optionsPanel; - } - - /** - *

createMatchSettingsPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createMatchSettingsPanel() { - - JPanel matchPanel = new JPanel(); - matchPanel.setLayout(new BoxLayout(matchPanel, BoxLayout.Y_AXIS)); - - JPanel deckPanel = new JPanel(); - deckPanel.setLayout(new BoxLayout(deckPanel, BoxLayout.X_AXIS)); - - JLabel deckLabel = new JLabel("Use Deck"); - deckPanel.add(deckLabel); - GuiUtils.addGap(deckPanel); - - this.deckComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - playButton.setEnabled(canGameBeLaunched()); - lastUsedDeck = (String) deckComboBox.getSelectedItem(); - } - }); - - deckPanel.add(this.deckComboBox); - GuiUtils.addGap(deckPanel); - - JButton editDeckButton = new JButton("Deck Editor"); - editDeckButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - showDeckEditor(); - } - }); - deckPanel.add(editDeckButton); - deckPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, deckPanel.getPreferredSize().height)); - deckPanel.setAlignmentX(LEFT_ALIGNMENT); - matchPanel.add(deckPanel); - - - GuiUtils.addGap(matchPanel); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - JPanel fantasyPanel = new JPanel(); - fantasyPanel.setLayout(new BorderLayout()); - - JPanel petPanel = new JPanel(); - petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS)); - - this.petCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - - petComboBox.setEnabled(petCheckBox.isSelected()); - } - }); - - petPanel.add(this.petCheckBox); - GuiUtils.addGap(petPanel); - this.petComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - } - }); - this.petComboBox.setMaximumSize( - new Dimension(Integer.MAX_VALUE, - (int) this.petCheckBox.getPreferredSize().getHeight())); - petPanel.add(this.petComboBox); - - this.plantBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.getPetManager().usePlant = plantBox.isSelected(); - } - }); - - GuiUtils.addGap(petPanel, 10); - petPanel.add(this.plantBox); - petPanel.setMaximumSize(petPanel.getPreferredSize()); - petPanel.setAlignmentX(LEFT_ALIGNMENT); - - fantasyPanel.add(petPanel, BorderLayout.WEST); - - zeppelinButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.randomizeOpponents(); - refreshNextMatchPanel(); - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(true); - zeppelinButton.setEnabled(false); - } - }); - - zeppelinButton.setMaximumSize(zeppelinButton.getPreferredSize()); - zeppelinPanel.setLayout(new BorderLayout()); - - fantasyPanel.add(zeppelinPanel, BorderLayout.EAST); - fantasyPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - matchPanel.add(fantasyPanel); - } - return matchPanel; - } - - /** - *

createBattlePanel

- * Returns a JPanel containing PanelSingleBattle instances for each battle. - * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createBattlePanel() { - JPanel pan = new JPanel(); - pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS)); - pan.setBorder(new TitledBorder(new EtchedBorder(), "Available Battles")); - PanelSingleBattle pb; - - List Battles = ManagerBattle.getBattles(); - - for (DeckSingleBattle Battle : Battles) { - pb = new PanelSingleBattle(Battle); - - pan.add(pb); - pb.addMouseListener(new SelectionAdapter(pb)); - - GuiUtils.addGap(pan, 3); - } - - pan.setAlignmentX(LEFT_ALIGNMENT); - - return pan; - } - - /** - *

createQuestPanel.

- * Returns a JPanel containing PanelSingleQuest instances for each battle. - * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createQuestPanel() { - JPanel pan = new JPanel(); - pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS)); - pan.setBorder(new TitledBorder(new EtchedBorder(), "Available Quests")); - PanelSingleQuest pq; - - List Quests = ManagerQuest.getQuests(); - - for (DeckSingleQuest Quest : Quests) { - pq = new PanelSingleQuest(Quest); - - pan.add(pq); - pq.addMouseListener(new SelectionAdapter(pq)); - - GuiUtils.addGap(pan, 3); - } - - pan.setAlignmentX(LEFT_ALIGNMENT); - - return pan; - } - - /** - *

refresh.

- */ - void refresh() { - AllZone.getQuestData().saveData(); - - devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); - smoothLandCheckBox.setSelected(Constant.Runtime.Smooth[0]); - //newGUICheckbox.setSelected(OldGuiNewGame.preferences.newGui); - - creditsLabel.setText(" " + questData.getCredits()); - statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); - titleLabel.setText(questData.getRank()); - - //copy lastUsedDeck as removal triggers selection change. - String lastUsedDeck = QuestMainPanel.lastUsedDeck; - deckComboBox.removeAllItems(); - - if (questData.getDeckNames().size() > 0) { - deckComboBox.setEnabled(true); - - List deckNames = new ArrayList(questData.getDeckNames()); - - Collections.sort(deckNames, new Comparator() { - public int compare(String s, String s1) { - return s.compareToIgnoreCase(s1); - } - }); - - if (deckNames.contains(lastUsedDeck)) { - deckNames.remove(lastUsedDeck); - deckNames.add(0, lastUsedDeck); - } - - for (String deckName : deckNames) { - deckComboBox.addItem(deckName); - } - } else { - deckComboBox.addItem(NO_DECKS_AVAILABLE); - deckComboBox.setEnabled(false); - } - deckComboBox.setMinimumSize(new Dimension(150, 0)); - - questButton.setEnabled(nextQuestInWins() == 0); - - playButton.setEnabled(canGameBeLaunched()); - - if (questData.getMode().equals(QuestData.FANTASY)) { - lifeLabel.setText(" " + questData.getLife()); - - petComboBox.removeAllItems(); - - Set petList = questData.getPetManager().getAvailablePetNames(); - - if (petList.size() > 0) { - petComboBox.setEnabled(true); - petCheckBox.setEnabled(true); - for (String aPetList : petList) { - petComboBox.addItem(aPetList); - } - } else { - petComboBox.addItem("No pets available"); - petComboBox.setEnabled(false); - petCheckBox.setEnabled(false); - } - - if (!questData.getPetManager().shouldPetBeUsed()) { - petCheckBox.setSelected(false); - petComboBox.setEnabled(false); - } else { - petCheckBox.setSelected(true); - petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); - } - - - this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0); - this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed()); - - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - - if (zeppelin.getLevel() > 0) { - zeppelinPanel.removeAll(); - zeppelinPanel.add(zeppelinButton, BorderLayout.CENTER); - } - - if (!zeppelin.hasBeenUsed()) { - zeppelinButton.setEnabled(true); - } else { - zeppelinButton.setEnabled(false); - } - - - } - - if (nextQuestInWins() > 0) { - nextQuestLabel.setText("Next Quest in " + nextQuestInWins() + " Wins."); - } else { - nextQuestLabel.setText("Next Quest available now."); - } - - nextMatchLayout = new CardLayout(); - - refreshNextMatchPanel(); - } - - /** - *

refreshNextMatchPanel.

- */ - private void refreshNextMatchPanel() { - nextMatchPanel.removeAll(); - nextMatchLayout = new CardLayout(); - nextMatchPanel.setLayout(nextMatchLayout); - nextMatchPanel.add(createBattlePanel(), BATTLES); - nextMatchPanel.add(createQuestPanel(), QUESTS); - if (isShowingQuests) { - this.nextMatchLayout.show(nextMatchPanel, QUESTS); - } else { - this.nextMatchLayout.show(nextMatchPanel, BATTLES); - } - } - - /** - *

nextQuestInWins.

- * - * @return a int. - */ - private int nextQuestInWins() { - - // Number of wins was 25, lowereing the number to 20 to help short term questers. - if (questData.getWin() < 20) { - return 20 - questData.getWin(); - } - - // The int mul has been lowered by one, should face special opps more frequently. - int questsPlayed = questData.getQuestsPlayed(); - int mul = 5; - - if (questData.getInventory().hasItem("Zeppelin")) { - mul = 3; - } else if (questData.getInventory().hasItem("Map")) { - mul = 4; - } - - int delta = (questsPlayed * mul) - questData.getWin(); - - return (delta > 0) ? delta : 0; - } - - - /** - *

showDeckEditor.

- */ - void showDeckEditor() { - Command exit = new Command() { - private static final long serialVersionUID = -5110231879431074581L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorQuest g = new DeckEditorQuest(); - - g.show(exit); - g.setVisible(true); - mainFrame.dispose(); - }//deck editor button - - /** - *

showBazaar.

- */ - void showBazaar() { - mainFrame.showBazaarPane(); - } - - /** - *

showCardShop.

- */ - void showCardShop() { - Command exit = new Command() { - private static final long serialVersionUID = 8567193482568076362L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorShop g = new DeckEditorShop(questData); - - g.show(exit); - g.setVisible(true); - - this.mainFrame.dispose(); - - }//card shop button - - /** - *

launchGame.

- */ - private void launchGame() { - //TODO: This is a temporary hack to see if the image cache affects the heap usage significantly. - ImageCache.clear(); - - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(false); - questData.randomizeOpponents(); - - String humanDeckName = (String) deckComboBox.getSelectedItem(); - Deck humanDeck = questData.getDeck(humanDeckName); - Constant.Runtime.HumanDeck[0] = humanDeck; - moveDeckToTop(humanDeckName); - - Constant.Quest.oppIconName[0] = getMatchIcon(); - - // Dev Mode occurs before Display - Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); - - //DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added - //if (newGUICheckbox.isSelected()) { - AllZone.setDisplay(new GuiDisplay4()); - //} else { - // AllZone.setDisplay(new GuiDisplay3()); - //} - - //OldGuiNewGame.preferences.newGui = newGUICheckbox.isSelected(); - - Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); - - AllZone.getMatchState().reset(); - if (isShowingQuests) { - setupQuest(humanDeck); - } else { - setupBattle(humanDeck); - } - - AllZone.getQuestData().saveData(); - - AllZone.getDisplay().setVisible(true); - mainFrame.dispose(); - } - - - /** - *

setupBattle.

- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - void setupBattle(Deck humanDeck) { - Deck computer = ((PanelSingleBattle) lastPanelSelected).getBattle().getDeck(); - Constant.Runtime.ComputerDeck[0] = computer; - - AllZone.getGameAction().newGame(humanDeck, computer, forge.quest.data.QuestUtil.getHumanExtraCards(questData), - new CardList(), questData.getLife(), 20, null); - } - - /** - *

setupQuest.

- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - private void setupQuest(Deck humanDeck) { - DeckSingleQuest selectedQuest = ((PanelSingleQuest) lastPanelSelected).getQuest(); - AllZone.setCurrentQuest(selectedQuest); - - Deck computerDeck = ManagerBattle.getAIDeckFromFile("quest" + selectedQuest.getID()); - Constant.Runtime.ComputerDeck[0] = computerDeck; - - int extraLife = 0; - - if (questData.getInventory().getItemLevel("Gear") == 2) { - extraLife = 3; - } - - AllZone.getGameAction().newGame(humanDeck, computerDeck, - forge.quest.data.QuestUtil.getHumanExtraCards(questData, selectedQuest), new CardList(), - questData.getLife() + extraLife, selectedQuest.getAILife(), selectedQuest); - - } - - /** - *

getMatchIcon.

- * - * @return a {@link java.lang.String} object. - */ - String getMatchIcon() { - String oppIconName; - - if (isShowingQuests) { - PanelSingleQuest selectedQuest = (PanelSingleQuest) lastPanelSelected; - oppIconName = selectedQuest.getIconFilename(); - } else { - PanelSingleBattle selectedBattle = (PanelSingleBattle) lastPanelSelected; - oppIconName = selectedBattle.getIconFilename(); - } - return oppIconName; - } - - /** - *

toggleBattleQuest.

- * Toggles view between battle and quest screen. - */ - void toggleBattleQuest() { - if (isShowingQuests) { - isShowingQuests = false; - questButton.setText("Quests"); - } else { - isShowingQuests = true; - questButton.setText("Battles"); - } - - if (lastPanelSelected != null) { - lastPanelSelected.setSelected(false); - } - - lastPanelSelected = null; - - refresh(); - } - - /** - *

SelectionAdapter

- * Handles (de)selection of various SelectablePanel instances using lastPanelSelected field. - * Also toggles launch button after (de)selection. - * - */ - class SelectionAdapter extends MouseAdapter { - SelectablePanel targetPanel; - - SelectionAdapter(SelectablePanel sp) { - super(); - this.targetPanel = sp; - } - - @Override - public void mouseClicked(MouseEvent mouseEvent) { - // Deselect previous - if (lastPanelSelected != null) { - lastPanelSelected.setSelected(false); - } - - targetPanel.setSelected(true); - - lastPanelSelected = targetPanel; - playButton.setEnabled(canGameBeLaunched()); - } - - } - - /** - *

moveDeckToTop.

- * - * @param humanDeckName a {@link java.lang.String} object. - */ - private void moveDeckToTop(String humanDeckName) { - QuestMainPanel.lastUsedDeck = humanDeckName; - } - - - /** - *

canGameBeLaunched.

- * - * @return a boolean. - */ - boolean canGameBeLaunched() { - return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || lastPanelSelected == null); - } - - /** {@inheritDoc} */ - @Override - public void refreshState() { - this.refresh(); - } - -} diff --git a/src/test/java/forge/ReadQuestAssignmentTest.java b/src/test/java/forge/ReadQuestAssignmentTest.java new file mode 100644 index 00000000000..9e426d40bbd --- /dev/null +++ b/src/test/java/forge/ReadQuestAssignmentTest.java @@ -0,0 +1,41 @@ +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import org.testng.annotations.Test; + +/** + * Created by IntelliJ IDEA. + * User: dhudson + */ +@Test(groups = {"UnitTest"}, timeOut = 1000) +public class ReadQuestAssignmentTest implements NewConstants { + /** + * + * + */ + @Test(groups = {"UnitTest", "fast"}, timeOut = 1000) + public void ReadQuestAssignmentTest1() { + try { + ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(QUEST.QUESTS), null); + + javax.swing.SwingUtilities.invokeAndWait(read); + // read.run(); + + Quest_Assignment qa[] = new Quest_Assignment[read.allQuests.size()]; + read.allQuests.toArray(qa); + for (int i = 0; i < qa.length; i++) { + System.out.println(qa[i].getId()); + System.out.println(qa[i].getName()); + System.out.println(qa[i].getDesc()); + System.out.println(qa[i].getDifficulty()); + System.out.println(qa[i].isRepeatable()); + System.out.println(qa[i].getRequiredNumberWins()); + } + } catch (Exception ex) { + ErrorViewer.showError(ex); + System.out.println("Error reading file " + ex); + } + } +}