diff --git a/.gitattributes b/.gitattributes index ae91a09678e..6f9b76d6c40 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11386,6 +11386,7 @@ 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/PreconDeck.java -text +src/main/java/forge/item/TournamentPack.java -text src/main/java/forge/item/package-info.java -text src/main/java/forge/model/BuildInfo.java -text src/main/java/forge/model/FMatchState.java svneol=native#text/plain diff --git a/src/main/java/forge/card/BoosterData.java b/src/main/java/forge/card/BoosterData.java index f63c768796f..7ecf0e2ce93 100644 --- a/src/main/java/forge/card/BoosterData.java +++ b/src/main/java/forge/card/BoosterData.java @@ -177,7 +177,9 @@ public class BoosterData { int nR = section.getInt("Rares", 0); int nS = section.getInt("Special", 0); int nDf = section.getInt("DoubleFaced", 0); - return new BoosterData(section.get("Set"), nC, nU, nR, nS, nDf); + int nLand = section.getInt("BasicLands", 0); + int nFoilRate = section.getInt("FoilRate", 68); + return new BoosterData(section.get("Set"), nC, nU, nR, nS, nDf, nLand, nFoilRate); } } } \ No newline at end of file diff --git a/src/main/java/forge/card/BoosterGenerator.java b/src/main/java/forge/card/BoosterGenerator.java index 437b7324344..6c50e3dc3ca 100644 --- a/src/main/java/forge/card/BoosterGenerator.java +++ b/src/main/java/forge/card/BoosterGenerator.java @@ -199,7 +199,7 @@ public class BoosterGenerator { * @return the singleton booster pack */ public final List getSingletonBoosterPack(final int nAnyCard) { - return this.pickRandomCards(this.allButLands, nAnyCard, true); + return this.pickRandomCards(new ArrayList(this.allButLands), nAnyCard, true); } /** @@ -209,7 +209,7 @@ public class BoosterGenerator { */ public final List getBoosterPack(BoosterData booster) { return this.getBoosterPack(booster.getCommon(), booster.getUncommon(), booster.getRare(), 0, 0, booster.getSpecial(), - booster.getDoubleFaced(), 0, 0); + booster.getDoubleFaced(), 0, booster.getLand()); } /** diff --git a/src/main/java/forge/card/CardEdition.java b/src/main/java/forge/card/CardEdition.java index 353bef409fa..666a7f72c46 100644 --- a/src/main/java/forge/card/CardEdition.java +++ b/src/main/java/forge/card/CardEdition.java @@ -187,7 +187,16 @@ public final class CardEdition implements Comparable { // immutable private static class CanMakeBooster extends Predicate { @Override public boolean isTrue(final CardEdition subject) { - return Singletons.getModel().getBoosters().get(subject.getCode()) != null; + return Singletons.getModel().getBoosters().contains(subject.getCode()); + } + } + + public static final Predicate HAS_TOURNAMENT_PACK = new CanMakeStarter(); + + private static class CanMakeStarter extends Predicate { + @Override + public boolean isTrue(final CardEdition subject) { + return Singletons.getModel().getTournamentPacks().contains(subject.getCode()); } } diff --git a/src/main/java/forge/game/limited/BoosterDraft.java b/src/main/java/forge/game/limited/BoosterDraft.java index 7c3eedbc7e3..42ca57f3163 100644 --- a/src/main/java/forge/game/limited/BoosterDraft.java +++ b/src/main/java/forge/game/limited/BoosterDraft.java @@ -34,7 +34,6 @@ import forge.Card; import forge.CardList; import forge.Constant; import forge.Singletons; -import forge.card.BoosterData; import forge.card.BoosterGenerator; import forge.card.CardBlock; import forge.card.CardEdition; diff --git a/src/main/java/forge/game/limited/SealedDeck.java b/src/main/java/forge/game/limited/SealedDeck.java index f6c8c1ab78b..cceae1361ed 100644 --- a/src/main/java/forge/game/limited/SealedDeck.java +++ b/src/main/java/forge/game/limited/SealedDeck.java @@ -32,7 +32,6 @@ import forge.CardListFilter; import forge.CardListUtil; import forge.Constant; import forge.Singletons; -import forge.card.BoosterData; import forge.card.BoosterGenerator; import forge.card.CardBlock; import forge.card.CardEdition; diff --git a/src/main/java/forge/gui/deckeditor/QuestCardShop.java b/src/main/java/forge/gui/deckeditor/QuestCardShop.java index 59168cdd1af..2c1aae78b52 100644 --- a/src/main/java/forge/gui/deckeditor/QuestCardShop.java +++ b/src/main/java/forge/gui/deckeditor/QuestCardShop.java @@ -49,6 +49,7 @@ import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; import forge.item.PreconDeck; +import forge.item.TournamentPack; import forge.quest.ReadPriceList; import forge.quest.data.QuestData; import forge.util.Predicate; @@ -304,6 +305,8 @@ public final class QuestCardShop extends DeckEditorBase { } } else if (card instanceof BoosterPack) { return 395; + } else if (card instanceof TournamentPack) { + return 995; } else if (card instanceof PreconDeck) { return ((PreconDeck) card).getRecommendedDeals().getCost(); } @@ -339,6 +342,18 @@ public final class QuestCardShop extends DeckEditorBase { 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); + final List newCards = booster.getCards(); + for (final CardPrinted card : newCards) { + this.getBottomTableWithCards().addCard(card); + } + final CardListViewer c = new CardListViewer(booster.getName(), + "You have found the following cards inside:", newCards); + c.show(); } else if (item instanceof PreconDeck) { this.getTopTableWithCards().removeCard(item); final PreconDeck deck = (PreconDeck) item; diff --git a/src/main/java/forge/item/BoosterPack.java b/src/main/java/forge/item/BoosterPack.java index 536234bd6dc..d80b2415846 100644 --- a/src/main/java/forge/item/BoosterPack.java +++ b/src/main/java/forge/item/BoosterPack.java @@ -39,7 +39,8 @@ public class BoosterPack implements InventoryItemFromSet { public static final Lambda1 FN_FROM_SET = new Lambda1() { @Override public BoosterPack apply(final CardEdition arg1) { - return new BoosterPack(arg1); + BoosterData d = Singletons.getModel().getBoosters().get(arg1.getCode()); + return new BoosterPack(arg1.getName(), d); } }; @@ -48,15 +49,6 @@ public class BoosterPack implements InventoryItemFromSet { private List cards = null; - /** - * Instantiates a new booster pack. - * - * @param set - * the set - */ - public BoosterPack(final String set) { - this(Singletons.getModel().getEditions().getEditionByCodeOrThrow(set)); - } /** * Instantiates a new booster pack. @@ -64,9 +56,9 @@ public class BoosterPack implements InventoryItemFromSet { * @param set * the set */ - public BoosterPack(final CardEdition set) { - this.contents = Singletons.getModel().getBoosters().get(set.getCode()); - this.name = set.getName() + " Booster Pack"; + public BoosterPack(final String name0, final BoosterData boosterData) { + this.contents = boosterData; + this.name = name0; } /* @@ -227,8 +219,7 @@ public class BoosterPack implements InventoryItemFromSet { */ @Override public final Object clone() { - return new BoosterPack(Singletons.getModel().getEditions().getEditionByCodeOrThrow(this.contents.getEdition())); // it's ok to share a reference to - // cardSet which is static anyway + return new BoosterPack(name, contents); } /** diff --git a/src/main/java/forge/item/TournamentPack.java b/src/main/java/forge/item/TournamentPack.java new file mode 100644 index 00000000000..b1bc5f36c95 --- /dev/null +++ b/src/main/java/forge/item/TournamentPack.java @@ -0,0 +1,205 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.item; + +import java.util.List; + +import net.slightlymagic.braids.util.lambda.Lambda1; +import forge.Singletons; +import forge.card.BoosterData; +import forge.card.BoosterGenerator; +import forge.card.CardEdition; + +/** + * TODO Write javadoc for this type. + * + */ +public class TournamentPack implements InventoryItemFromSet { + + /** The Constant fnFromSet. */ + public static final Lambda1 FN_FROM_SET = new Lambda1() { + @Override + public TournamentPack apply(final CardEdition arg1) { + BoosterData d = Singletons.getModel().getTournamentPacks().get(arg1.getCode()); + return new TournamentPack(arg1.getName(), d); + } + }; + + private final BoosterData contents; + private final String name; + + private List cards = null; + + + /** + * Instantiates a new booster pack. + * + * @param set + * the set + */ + public TournamentPack(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; + } + + /* + * (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"; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + /** + * Clone. + * + * @return Object + */ + @Override + public final Object clone() { + 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/model/FModel.java b/src/main/java/forge/model/FModel.java index 90e34f3dd71..b95f5021429 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -86,6 +86,7 @@ public enum FModel { private final EditionCollection editions; private final FormatCollection formats; private final IStorageView boosters; + private final IStorageView tournaments; private final StorageView blocks; // have to implement lazy initialization - at the moment of FModel.ctor() @@ -131,9 +132,11 @@ public enum FModel { this.matchState = new FMatchState(); this.questPreferences = new QuestPreferences(); this.questEventManager = new QuestEventManager(); + this.editions = new EditionCollection(); this.formats = new FormatCollection("res/blockdata/formats.txt"); this.boosters = new StorageView(new BoosterData.Reader("res/blockdata/boosters.txt")); + this.tournaments = new StorageView(new BoosterData.Reader("res/blockdata/starters.txt")); this.blocks = new StorageView(new CardBlock.Reader("res/blockdata/blocks.txt", editions)); @@ -166,6 +169,10 @@ public enum FModel { FModel.loadDynamicGamedata(); } + public final IStorageView getTournamentPacks() { + return tournaments; + } + public final IStorageView getBoosters() { return boosters; } diff --git a/src/main/java/forge/quest/data/QuestDataIO.java b/src/main/java/forge/quest/data/QuestDataIO.java index 9b510063072..85333dfb5d2 100644 --- a/src/main/java/forge/quest/data/QuestDataIO.java +++ b/src/main/java/forge/quest/data/QuestDataIO.java @@ -45,6 +45,9 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.mapper.MapperWrapper; +import forge.Singletons; +import forge.card.BoosterData; +import forge.card.CardEdition; import forge.deck.DeckSection; import forge.error.ErrorViewer; import forge.game.GameType; @@ -54,6 +57,7 @@ import forge.item.CardPrinted; import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.PreconDeck; +import forge.item.TournamentPack; import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.quest.data.item.QuestInventory; @@ -297,6 +301,13 @@ public class QuestDataIO { writer.endNode(); } + protected void write(final TournamentPack booster, final Integer count, final HierarchicalStreamWriter writer) { + writer.startNode("tpack"); + writer.addAttribute("s", booster.getEdition()); + writer.addAttribute("n", count.toString()); + writer.endNode(); + } + protected void write(final PreconDeck deck, final Integer count, final HierarchicalStreamWriter writer) { writer.startNode("precon"); writer.addAttribute("name", deck.getName()); @@ -315,6 +326,8 @@ public class QuestDataIO { this.write((CardPrinted) item, count, writer); } else if (item instanceof BoosterPack) { this.write((BoosterPack) item, count, writer); + } else if (item instanceof TournamentPack) { + this.write((TournamentPack) item, count, writer); } else if (item instanceof PreconDeck) { this.write((PreconDeck) item, count, writer); } @@ -337,6 +350,8 @@ public class QuestDataIO { result.add(this.readCardPrinted(reader), cnt); } else if ("booster".equals(nodename)) { result.add(this.readBooster(reader), cnt); + } else if ("tpack".equals(nodename)) { + result.add(this.readTournamentPack(reader), cnt); } else if ("precon".equals(nodename)) { final PreconDeck toAdd = this.readPreconDeck(reader); if (null != toAdd) { @@ -358,9 +373,18 @@ public class QuestDataIO { protected BoosterPack readBooster(final HierarchicalStreamReader reader) { final String set = reader.getAttribute("s"); - return new BoosterPack(set); + CardEdition ed = Singletons.getModel().getEditions().get(set); + BoosterData bd = Singletons.getModel().getBoosters().get(set); + return new BoosterPack(ed.getName(), bd); } + protected TournamentPack readTournamentPack(final HierarchicalStreamReader reader) { + final String set = reader.getAttribute("s"); + CardEdition ed = Singletons.getModel().getEditions().get(set); + BoosterData bd = Singletons.getModel().getTournamentPacks().get(set); + return new TournamentPack(ed.getName(), bd); + } + protected CardPrinted readCardPrinted(final HierarchicalStreamReader reader) { final String name = reader.getAttribute("c"); final String set = reader.getAttribute("s"); diff --git a/src/main/java/forge/quest/data/QuestUtilCards.java b/src/main/java/forge/quest/data/QuestUtilCards.java index c8a9bf8b161..a37abf401ca 100644 --- a/src/main/java/forge/quest/data/QuestUtilCards.java +++ b/src/main/java/forge/quest/data/QuestUtilCards.java @@ -34,6 +34,7 @@ import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; import forge.item.PreconDeck; +import forge.item.TournamentPack; import forge.quest.BoosterUtils; import forge.quest.data.QuestPreferences.QPref; import forge.util.MyRandom; @@ -207,6 +208,14 @@ 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. * @@ -346,6 +355,17 @@ public final class QuestUtilCards { } } + /** + * Generate precons in shop. + * + * @param count + * the count + */ + public void generateTournamentsInShop(final int count) { + Predicate hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK; + this.q.getShopList().addAllFlat( hasTournament.random(Singletons.getModel().getEditions(), count, TournamentPack.FN_FROM_SET)); + } + /** * Generate precons in shop. * @@ -387,6 +407,7 @@ public final class QuestUtilCards { this.generateBoostersInShop(totalPacks); this.generatePreconsInShop(totalPacks); + this.generateTournamentsInShop(totalPacks); this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5)); }