Tournament packs ready. quick but working

This commit is contained in:
Maxmtg
2012-02-25 11:42:02 +00:00
parent 9193e03933
commit b0155aee0c
12 changed files with 295 additions and 22 deletions

1
.gitattributes vendored
View File

@@ -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/ItemPool.java -text
src/main/java/forge/item/ItemPoolView.java -text src/main/java/forge/item/ItemPoolView.java -text
src/main/java/forge/item/PreconDeck.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/item/package-info.java -text
src/main/java/forge/model/BuildInfo.java -text src/main/java/forge/model/BuildInfo.java -text
src/main/java/forge/model/FMatchState.java svneol=native#text/plain src/main/java/forge/model/FMatchState.java svneol=native#text/plain

View File

@@ -177,7 +177,9 @@ public class BoosterData {
int nR = section.getInt("Rares", 0); int nR = section.getInt("Rares", 0);
int nS = section.getInt("Special", 0); int nS = section.getInt("Special", 0);
int nDf = section.getInt("DoubleFaced", 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);
} }
} }
} }

View File

@@ -199,7 +199,7 @@ public class BoosterGenerator {
* @return the singleton booster pack * @return the singleton booster pack
*/ */
public final List<CardPrinted> getSingletonBoosterPack(final int nAnyCard) { public final List<CardPrinted> getSingletonBoosterPack(final int nAnyCard) {
return this.pickRandomCards(this.allButLands, nAnyCard, true); return this.pickRandomCards(new ArrayList<CardPrinted>(this.allButLands), nAnyCard, true);
} }
/** /**
@@ -209,7 +209,7 @@ public class BoosterGenerator {
*/ */
public final List<CardPrinted> getBoosterPack(BoosterData booster) { public final List<CardPrinted> getBoosterPack(BoosterData booster) {
return this.getBoosterPack(booster.getCommon(), booster.getUncommon(), booster.getRare(), 0, 0, booster.getSpecial(), return this.getBoosterPack(booster.getCommon(), booster.getUncommon(), booster.getRare(), 0, 0, booster.getSpecial(),
booster.getDoubleFaced(), 0, 0); booster.getDoubleFaced(), 0, booster.getLand());
} }
/** /**

View File

@@ -187,7 +187,16 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
private static class CanMakeBooster extends Predicate<CardEdition> { private static class CanMakeBooster extends Predicate<CardEdition> {
@Override @Override
public boolean isTrue(final CardEdition subject) { 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<CardEdition> HAS_TOURNAMENT_PACK = new CanMakeStarter();
private static class CanMakeStarter extends Predicate<CardEdition> {
@Override
public boolean isTrue(final CardEdition subject) {
return Singletons.getModel().getTournamentPacks().contains(subject.getCode());
} }
} }

View File

@@ -34,7 +34,6 @@ import forge.Card;
import forge.CardList; import forge.CardList;
import forge.Constant; import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.card.BoosterData;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
import forge.card.CardBlock; import forge.card.CardBlock;
import forge.card.CardEdition; import forge.card.CardEdition;

View File

@@ -32,7 +32,6 @@ import forge.CardListFilter;
import forge.CardListUtil; import forge.CardListUtil;
import forge.Constant; import forge.Constant;
import forge.Singletons; import forge.Singletons;
import forge.card.BoosterData;
import forge.card.BoosterGenerator; import forge.card.BoosterGenerator;
import forge.card.CardBlock; import forge.card.CardBlock;
import forge.card.CardEdition; import forge.card.CardEdition;

View File

@@ -49,6 +49,7 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.item.PreconDeck; import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.quest.ReadPriceList; import forge.quest.ReadPriceList;
import forge.quest.data.QuestData; import forge.quest.data.QuestData;
import forge.util.Predicate; import forge.util.Predicate;
@@ -304,6 +305,8 @@ public final class QuestCardShop extends DeckEditorBase<InventoryItem, Object> {
} }
} else if (card instanceof BoosterPack) { } else if (card instanceof BoosterPack) {
return 395; return 395;
} else if (card instanceof TournamentPack) {
return 995;
} else if (card instanceof PreconDeck) { } else if (card instanceof PreconDeck) {
return ((PreconDeck) card).getRecommendedDeals().getCost(); return ((PreconDeck) card).getRecommendedDeals().getCost();
} }
@@ -339,6 +342,18 @@ public final class QuestCardShop extends DeckEditorBase<InventoryItem, Object> {
final CardListViewer c = new CardListViewer(booster.getName(), final CardListViewer c = new CardListViewer(booster.getName(),
"You have found the following cards inside:", newCards); "You have found the following cards inside:", newCards);
c.show(); 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<CardPrinted> 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) { } else if (item instanceof PreconDeck) {
this.getTopTableWithCards().removeCard(item); this.getTopTableWithCards().removeCard(item);
final PreconDeck deck = (PreconDeck) item; final PreconDeck deck = (PreconDeck) item;

View File

@@ -39,7 +39,8 @@ public class BoosterPack implements InventoryItemFromSet {
public static final Lambda1<BoosterPack, CardEdition> FN_FROM_SET = new Lambda1<BoosterPack, CardEdition>() { public static final Lambda1<BoosterPack, CardEdition> FN_FROM_SET = new Lambda1<BoosterPack, CardEdition>() {
@Override @Override
public BoosterPack apply(final CardEdition arg1) { 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<CardPrinted> cards = null; private List<CardPrinted> 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. * Instantiates a new booster pack.
@@ -64,9 +56,9 @@ public class BoosterPack implements InventoryItemFromSet {
* @param set * @param set
* the set * the set
*/ */
public BoosterPack(final CardEdition set) { public BoosterPack(final String name0, final BoosterData boosterData) {
this.contents = Singletons.getModel().getBoosters().get(set.getCode()); this.contents = boosterData;
this.name = set.getName() + " Booster Pack"; this.name = name0;
} }
/* /*
@@ -227,8 +219,7 @@ public class BoosterPack implements InventoryItemFromSet {
*/ */
@Override @Override
public final Object clone() { public final Object clone() {
return new BoosterPack(Singletons.getModel().getEditions().getEditionByCodeOrThrow(this.contents.getEdition())); // it's ok to share a reference to return new BoosterPack(name, contents);
// cardSet which is static anyway
} }
/** /**

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<TournamentPack, CardEdition> FN_FROM_SET = new Lambda1<TournamentPack, CardEdition>() {
@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<CardPrinted> 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<CardPrinted> 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();
}
}

View File

@@ -86,6 +86,7 @@ public enum FModel {
private final EditionCollection editions; private final EditionCollection editions;
private final FormatCollection formats; private final FormatCollection formats;
private final IStorageView<BoosterData> boosters; private final IStorageView<BoosterData> boosters;
private final IStorageView<BoosterData> tournaments;
private final StorageView<CardBlock> blocks; private final StorageView<CardBlock> blocks;
// have to implement lazy initialization - at the moment of FModel.ctor() // have to implement lazy initialization - at the moment of FModel.ctor()
@@ -131,9 +132,11 @@ public enum FModel {
this.matchState = new FMatchState(); this.matchState = new FMatchState();
this.questPreferences = new QuestPreferences(); this.questPreferences = new QuestPreferences();
this.questEventManager = new QuestEventManager(); this.questEventManager = new QuestEventManager();
this.editions = new EditionCollection(); this.editions = new EditionCollection();
this.formats = new FormatCollection("res/blockdata/formats.txt"); this.formats = new FormatCollection("res/blockdata/formats.txt");
this.boosters = new StorageView<BoosterData>(new BoosterData.Reader("res/blockdata/boosters.txt")); this.boosters = new StorageView<BoosterData>(new BoosterData.Reader("res/blockdata/boosters.txt"));
this.tournaments = new StorageView<BoosterData>(new BoosterData.Reader("res/blockdata/starters.txt"));
this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions)); this.blocks = new StorageView<CardBlock>(new CardBlock.Reader("res/blockdata/blocks.txt", editions));
@@ -166,6 +169,10 @@ public enum FModel {
FModel.loadDynamicGamedata(); FModel.loadDynamicGamedata();
} }
public final IStorageView<BoosterData> getTournamentPacks() {
return tournaments;
}
public final IStorageView<BoosterData> getBoosters() { public final IStorageView<BoosterData> getBoosters() {
return boosters; return boosters;
} }

View File

@@ -45,6 +45,9 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.mapper.MapperWrapper; import com.thoughtworks.xstream.mapper.MapperWrapper;
import forge.Singletons;
import forge.card.BoosterData;
import forge.card.CardEdition;
import forge.deck.DeckSection; import forge.deck.DeckSection;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.game.GameType; import forge.game.GameType;
@@ -54,6 +57,7 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.PreconDeck; import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
import forge.quest.data.item.QuestInventory; import forge.quest.data.item.QuestInventory;
@@ -297,6 +301,13 @@ public class QuestDataIO {
writer.endNode(); 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) { protected void write(final PreconDeck deck, final Integer count, final HierarchicalStreamWriter writer) {
writer.startNode("precon"); writer.startNode("precon");
writer.addAttribute("name", deck.getName()); writer.addAttribute("name", deck.getName());
@@ -315,6 +326,8 @@ public class QuestDataIO {
this.write((CardPrinted) item, count, writer); this.write((CardPrinted) item, count, writer);
} else if (item instanceof BoosterPack) { } else if (item instanceof BoosterPack) {
this.write((BoosterPack) item, count, writer); this.write((BoosterPack) item, count, writer);
} else if (item instanceof TournamentPack) {
this.write((TournamentPack) item, count, writer);
} else if (item instanceof PreconDeck) { } else if (item instanceof PreconDeck) {
this.write((PreconDeck) item, count, writer); this.write((PreconDeck) item, count, writer);
} }
@@ -337,6 +350,8 @@ public class QuestDataIO {
result.add(this.readCardPrinted(reader), cnt); result.add(this.readCardPrinted(reader), cnt);
} else if ("booster".equals(nodename)) { } else if ("booster".equals(nodename)) {
result.add(this.readBooster(reader), cnt); result.add(this.readBooster(reader), cnt);
} else if ("tpack".equals(nodename)) {
result.add(this.readTournamentPack(reader), cnt);
} else if ("precon".equals(nodename)) { } else if ("precon".equals(nodename)) {
final PreconDeck toAdd = this.readPreconDeck(reader); final PreconDeck toAdd = this.readPreconDeck(reader);
if (null != toAdd) { if (null != toAdd) {
@@ -358,9 +373,18 @@ public class QuestDataIO {
protected BoosterPack readBooster(final HierarchicalStreamReader reader) { protected BoosterPack readBooster(final HierarchicalStreamReader reader) {
final String set = reader.getAttribute("s"); 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) { protected CardPrinted readCardPrinted(final HierarchicalStreamReader reader) {
final String name = reader.getAttribute("c"); final String name = reader.getAttribute("c");
final String set = reader.getAttribute("s"); final String set = reader.getAttribute("s");

View File

@@ -34,6 +34,7 @@ import forge.item.InventoryItem;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
import forge.item.PreconDeck; import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.quest.BoosterUtils; import forge.quest.BoosterUtils;
import forge.quest.data.QuestPreferences.QPref; import forge.quest.data.QuestPreferences.QPref;
import forge.util.MyRandom; 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. * 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<CardEdition> hasTournament = CardEdition.Predicates.HAS_TOURNAMENT_PACK;
this.q.getShopList().addAllFlat( hasTournament.random(Singletons.getModel().getEditions(), count, TournamentPack.FN_FROM_SET));
}
/** /**
* Generate precons in shop. * Generate precons in shop.
* *
@@ -387,6 +407,7 @@ public final class QuestUtilCards {
this.generateBoostersInShop(totalPacks); this.generateBoostersInShop(totalPacks);
this.generatePreconsInShop(totalPacks); this.generatePreconsInShop(totalPacks);
this.generateTournamentsInShop(totalPacks);
this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5)); this.q.getShopList().addAll(QuestUtilCards.generateBasicLands(10, 5));
} }