diff --git a/.gitattributes b/.gitattributes index 778d2383015..c148e8f5017 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11391,6 +11391,7 @@ src/main/java/forge/item/InventoryItem.java -text src/main/java/forge/item/InventoryItemFromSet.java -text src/main/java/forge/item/ItemPool.java -text src/main/java/forge/item/ItemPoolView.java -text +src/main/java/forge/item/OpenablePack.java -text src/main/java/forge/item/PreconDeck.java -text src/main/java/forge/item/TournamentPack.java -text src/main/java/forge/item/package-info.java -text diff --git a/src/main/java/forge/gui/deckeditor/DeckController.java b/src/main/java/forge/gui/deckeditor/DeckController.java index b8299a8684a..bef9787b0b3 100644 --- a/src/main/java/forge/gui/deckeditor/DeckController.java +++ b/src/main/java/forge/gui/deckeditor/DeckController.java @@ -153,9 +153,12 @@ public class DeckController implements IDeckController { * * @see forge.gui.deckeditor.IDeckController#load(java.lang.String) */ + @SuppressWarnings("unchecked") @Override public void load(final String name) { - this.setModel(this.folder.get(name), true); + T newModel = this.folder.get(name); + if (null != newModel) + this.setModel((T)newModel.copyTo(name), true); } /* diff --git a/src/main/java/forge/gui/deckeditor/QuestCardShop.java b/src/main/java/forge/gui/deckeditor/QuestCardShop.java index 2c1aae78b52..5acecf36076 100644 --- a/src/main/java/forge/gui/deckeditor/QuestCardShop.java +++ b/src/main/java/forge/gui/deckeditor/QuestCardShop.java @@ -48,6 +48,7 @@ import forge.item.CardPrinted; import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; +import forge.item.OpenablePack; import forge.item.PreconDeck; import forge.item.TournamentPack; import forge.quest.ReadPriceList; @@ -330,23 +331,16 @@ public final class QuestCardShop extends DeckEditorBase { this.getBottomTableWithCards().addCard(card); this.questData.getCards().buyCard(card, value); - } else if (item instanceof BoosterPack) { + } else if (item instanceof OpenablePack) { this.getTopTableWithCards().removeCard(item); - - final BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone(); - this.questData.getCards().buyBooster(booster, value); - final List newCards = booster.getCards(); - for (final CardPrinted card : newCards) { - this.getBottomTableWithCards().addCard(card); + + OpenablePack booster = null; + if (item instanceof BoosterPack) { + booster = (BoosterPack) ((BoosterPack) item).clone(); + } else if (item instanceof TournamentPack) { + booster = (TournamentPack) ((TournamentPack) item).clone(); } - final CardListViewer c = new CardListViewer(booster.getName(), - "You have found the following cards inside:", newCards); - c.show(); - } else if (item instanceof TournamentPack) { - this.getTopTableWithCards().removeCard(item); - - final TournamentPack booster = (TournamentPack) ((TournamentPack) item).clone(); - this.questData.getCards().buyTournamentPack(booster, value); + this.questData.getCards().buyPack(booster, value); final List newCards = booster.getCards(); for (final CardPrinted card : newCards) { this.getBottomTableWithCards().addCard(card); diff --git a/src/main/java/forge/item/BoosterPack.java b/src/main/java/forge/item/BoosterPack.java index eba09b81cfe..733f871dd81 100644 --- a/src/main/java/forge/item/BoosterPack.java +++ b/src/main/java/forge/item/BoosterPack.java @@ -33,7 +33,7 @@ import forge.util.Predicate; * TODO Write javadoc for this type. * */ -public class BoosterPack implements InventoryItemFromSet { +public class BoosterPack extends OpenablePack { /** The Constant fnFromSet. */ public static final Lambda1 FN_FROM_SET = new Lambda1() { @@ -44,12 +44,6 @@ public class BoosterPack implements InventoryItemFromSet { } }; - private final BoosterData contents; - private final String name; - - private List cards = null; - - /** * Instantiates a new booster pack. * @@ -57,38 +51,7 @@ public class BoosterPack implements InventoryItemFromSet { * the set */ public BoosterPack(final String name0, final BoosterData boosterData) { - this.contents = boosterData; - this.name = name0; - } - - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItemFromSet#getSet() - */ - /** - * Gets the sets the. - * - * @return String - */ - @Override - public final String getEdition() { - return this.contents.getEdition(); - } - - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItemFromSet#getName() - */ - /** - * Gets the name. - * - * @return String - */ - @Override - public final String getName() { - return this.name + " " + this.getType(); + super(name0, boosterData); } /* @@ -125,83 +88,20 @@ public class BoosterPack implements InventoryItemFromSet { return this.getRandomBasicLand(Singletons.getModel().getEditions().get("M12")); } - private void generate() { + protected List generate() { final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter()); - this.cards = gen.getBoosterPack(this.contents); + List myCards = gen.getBoosterPack(this.contents); final int cntLands = this.contents.getLand(); if (cntLands > 0) { - this.cards.add(this.getLandFromNearestSet()); + myCards.add(this.getLandFromNearestSet()); } + return myCards; } - /** - * Gets the cards. - * - * @return the cards - */ - public final List getCards() { - if (null == this.cards) { - this.generate(); - } - return this.cards; - } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - /** - * Hash code. - * - * @return int - */ - @Override - public final int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode()); - return result; - } + - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public final boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } - final BoosterPack other = (BoosterPack) obj; - if (this.contents == null) { - if (other.contents != null) { - return false; - } - } else if (!this.contents.equals(other.contents)) { - return false; - } - return true; - } - - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItem#getType() - */ - /** - * Gets the type. - * - * @return String - */ @Override public final String getType() { return "Booster Pack"; @@ -222,12 +122,5 @@ public class BoosterPack implements InventoryItemFromSet { return new BoosterPack(name, contents); } - /** - * TODO: Write javadoc for this method. - * @return - */ - public int getTotalCards() { - return contents.getTotal(); - } } diff --git a/src/main/java/forge/item/OpenablePack.java b/src/main/java/forge/item/OpenablePack.java new file mode 100644 index 00000000000..4adeb1e33c9 --- /dev/null +++ b/src/main/java/forge/item/OpenablePack.java @@ -0,0 +1,98 @@ +package forge.item; + +import java.util.List; + +import forge.card.BoosterData; +import forge.card.BoosterGenerator; + +/** + * TODO: Write javadoc for this type. + */ +public abstract class OpenablePack implements InventoryItemFromSet { + protected final BoosterData contents; + protected final String name; + private List cards = null; + + public OpenablePack(final String name0, final BoosterData boosterData) { + this.contents = boosterData; + this.name = name0; + } + + + @Override + public final String getName() { + return this.name + " " + this.getType(); + } + + @Override + public final String getEdition() { + return this.contents.getEdition(); + } + + + protected abstract List generate(); + /** + * Gets the cards. + * + * @return the cards + */ + public final List getCards() { + if (null == this.cards) { + cards = this.generate(); + } + return this.cards; + } + + + public int getTotalCards() { + return contents.getTotal(); + } + + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final OpenablePack other = (OpenablePack) obj; + if (this.contents == null) { + if (other.contents != null) { + return false; + } + } else if (!this.contents.equals(other.contents)) { + return false; + } + return true; + } + + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + /** + * Hash code. + * + * @return int + */ + @Override + public final int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode()); + return result; + } + +} \ No newline at end of file diff --git a/src/main/java/forge/item/TournamentPack.java b/src/main/java/forge/item/TournamentPack.java index 47ca07b0e4b..d5922b1760f 100644 --- a/src/main/java/forge/item/TournamentPack.java +++ b/src/main/java/forge/item/TournamentPack.java @@ -29,7 +29,7 @@ import forge.card.CardEdition; * TODO Write javadoc for this type. * */ -public class TournamentPack implements InventoryItemFromSet { +public class TournamentPack extends OpenablePack { /** The Constant fnFromSet. */ public static final Lambda1 FN_FROM_SET = new Lambda1() { @@ -40,11 +40,6 @@ public class TournamentPack implements InventoryItemFromSet { } }; - private final BoosterData contents; - private final String name; - - private List cards = null; - /** * Instantiates a new booster pack. * @@ -52,132 +47,26 @@ public class TournamentPack implements InventoryItemFromSet { * the set */ public TournamentPack(final String name0, final BoosterData boosterData) { - this.contents = boosterData; - this.name = name0; + super(name0, boosterData); } - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItemFromSet#getSet() - */ - /** - * Gets the sets the. - * - * @return String - */ - @Override - public final String getEdition() { - return this.contents.getEdition(); - } - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItemFromSet#getName() - */ - /** - * Gets the name. - * - * @return String - */ - @Override - public final String getName() { - return this.name + " " + this.getType(); - } - - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItemFromSet#getImageFilename() - */ - /** - * Gets the image filename. - * - * @return String - */ @Override public final String getImageFilename() { return "tournamentpacks/" + this.contents.getEdition() + ".png"; } - private void generate() { - final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter()); - this.cards = gen.getBoosterPack(this.contents); - } - /** - * Gets the cards. - * - * @return the cards - */ - public final List getCards() { - if (null == this.cards) { - this.generate(); - } - return this.cards; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ - /** - * Hash code. - * - * @return int - */ - @Override - public final int hashCode() { - final int prime = 31; - int result = 1; - result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode()); - return result; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public final boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (this.getClass() != obj.getClass()) { - return false; - } - final TournamentPack other = (TournamentPack) obj; - if (this.contents == null) { - if (other.contents != null) { - return false; - } - } else if (!this.contents.equals(other.contents)) { - return false; - } - return true; - } - - /* - * (non-Javadoc) - * - * @see forge.item.InventoryItem#getType() - */ - /** - * Gets the type. - * - * @return String - */ @Override public final String getType() { return "Tournament Pack"; } + protected List generate() { + final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter()); + return gen.getBoosterPack(this.contents); + } + /* * (non-Javadoc) * @@ -193,13 +82,5 @@ public class TournamentPack implements InventoryItemFromSet { return new TournamentPack(name, contents); } - /** - * TODO: Write javadoc for this method. - * - * @return - */ - public int getTotalCards() { - return contents.getTotal(); - } } diff --git a/src/main/java/forge/quest/data/QuestUtilCards.java b/src/main/java/forge/quest/data/QuestUtilCards.java index a37abf401ca..906618dd365 100644 --- a/src/main/java/forge/quest/data/QuestUtilCards.java +++ b/src/main/java/forge/quest/data/QuestUtilCards.java @@ -33,6 +33,7 @@ import forge.item.CardPrinted; import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; +import forge.item.OpenablePack; import forge.item.PreconDeck; import forge.item.TournamentPack; import forge.quest.BoosterUtils; @@ -200,7 +201,7 @@ public final class QuestUtilCards { * @param value * the value */ - public void buyBooster(final BoosterPack booster, final int value) { + public void buyPack(final OpenablePack booster, final int value) { if (this.q.getCredits() >= value) { this.q.setCredits(this.q.getCredits() - value); this.q.getShopList().remove(booster); @@ -208,14 +209,7 @@ public final class QuestUtilCards { } } - public void buyTournamentPack(final TournamentPack booster, final int value) { - if (this.q.getCredits() >= value) { - this.q.setCredits(this.q.getCredits() - value); - this.q.getShopList().remove(booster); - this.addAllCards(booster.getCards()); - } - } - + /** * Buy precon deck. *