cardSet's members are finalized

M10-Booster added to quest cardshop (experimental and non-functional yet)
BoosterGenerator uses now rare-slots together with explicit numbers for rares and mythics
ItemPool has to be parametrized by Class<T> (unfortunatelly java erases types of generics)
This commit is contained in:
Maxmtg
2011-09-14 09:40:34 +00:00
parent 49b21e09ad
commit ab0f24d97d
26 changed files with 236 additions and 162 deletions

3
.gitattributes vendored
View File

@@ -9871,11 +9871,14 @@ src/main/java/forge/gui/input/Input_PayManaCostUtil.java svneol=native#text/plai
src/main/java/forge/gui/input/Input_PayManaCost_Ability.java svneol=native#text/plain src/main/java/forge/gui/input/Input_PayManaCost_Ability.java svneol=native#text/plain
src/main/java/forge/gui/input/package-info.java svneol=native#text/plain src/main/java/forge/gui/input/package-info.java svneol=native#text/plain
src/main/java/forge/gui/package-info.java svneol=native#text/plain src/main/java/forge/gui/package-info.java svneol=native#text/plain
src/main/java/forge/item/Booster.java -text
src/main/java/forge/item/CardDb.java -text src/main/java/forge/item/CardDb.java -text
src/main/java/forge/item/CardPrinted.java -text src/main/java/forge/item/CardPrinted.java -text
src/main/java/forge/item/InventoryItem.java -text 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/ItemPool.java -text
src/main/java/forge/item/ItemPoolView.java -text src/main/java/forge/item/ItemPoolView.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/FGameState.java -text src/main/java/forge/model/FGameState.java -text
src/main/java/forge/model/FModel.java svneol=native#text/plain src/main/java/forge/model/FModel.java svneol=native#text/plain

View File

@@ -27,16 +27,14 @@ public class BoosterGenerator {
private List<CardPrinted> mythics = new ArrayList<CardPrinted>(); private List<CardPrinted> mythics = new ArrayList<CardPrinted>();
private List<CardPrinted> specials = new ArrayList<CardPrinted>(); private List<CardPrinted> specials = new ArrayList<CardPrinted>();
private int iCommons = 0;
private int iUncommons = 0;
private int iRares = 0;
private int iMythics = 0;
private int iSpecials = 0;
private int numCommons = 0; private int numCommons = 0;
private int numUncommons = 0; private int numUncommons = 0;
// these two used when numbers of rares/myths is specified explicitly
private int numRares = 0; private int numRares = 0;
private int numMythics = 0; private int numMythics = 0;
// this is used to specify number of slots for a rare - generator will decide by itself which to take
private int numRareSlots = 0;
private int numSpecials = 0; private int numSpecials = 0;
//private Random r = new Random(); //private Random r = new Random();
@@ -44,18 +42,15 @@ public class BoosterGenerator {
/** /**
* <p>Constructor for BoosterGenerator.</p> * <p>Constructor for BoosterGenerator.</p>
*/ */
public BoosterGenerator() { public BoosterGenerator(Iterable<CardPrinted> cards) {
numCommons = 11; numCommons = 11;
numUncommons = 3; numUncommons = 3;
numRares = 1; numRareSlots = 1;
numMythics = 0;
numSpecials = 0; numSpecials = 0;
for (CardPrinted c : CardDb.instance().getAllUniqueCards()) { for (CardPrinted c : cards) {
addToRarity(c); addToRarity(c);
} }
shuffleAll();
} }
/** /**
@@ -70,13 +65,13 @@ public class BoosterGenerator {
* @param ignoreRarity a boolean * @param ignoreRarity a boolean
*/ */
public BoosterGenerator(final String deckFile, final int nCommons, final int nUncommons, final int nRares, public BoosterGenerator(final String deckFile, final int nCommons, final int nUncommons, final int nRares,
final int nMythics, final int nSpecials, final boolean ignoreRarity) final int nMythics, final int nSpecials, final boolean ignoreRarity)
{ {
numCommons = nCommons; numCommons = nCommons;
numUncommons = nUncommons; numUncommons = nUncommons;
numRares = nRares; numRares = nRares;
numMythics = nMythics;
numSpecials = nSpecials; numSpecials = nSpecials;
numMythics = nMythics;
//DeckManager dio = new DeckManager(ForgeProps.getFile(NewConstants.NEW_DECKS)); //DeckManager dio = new DeckManager(ForgeProps.getFile(NewConstants.NEW_DECKS));
DeckManager dio = AllZone.getDeckManager(); DeckManager dio = AllZone.getDeckManager();
@@ -91,7 +86,6 @@ public class BoosterGenerator {
else { addToRarity(e.getKey()); } else { addToRarity(e.getKey()); }
} }
shuffleAll();
} }
/** /**
@@ -103,7 +97,6 @@ public class BoosterGenerator {
numCommons = 0; numCommons = 0;
numUncommons = 0; numUncommons = 0;
numRares = 0; numRares = 0;
numMythics = 0;
numSpecials = 0; numSpecials = 0;
List<String> setsList = Arrays.asList(new String[]{setCode}); List<String> setsList = Arrays.asList(new String[]{setCode});
@@ -114,8 +107,6 @@ public class BoosterGenerator {
addToRarity(c); addToRarity(c);
} }
shuffleAll();
ArrayList<String> bpData = FileUtil.readFile("res/boosterdata/" + setCode + ".pack"); ArrayList<String> bpData = FileUtil.readFile("res/boosterdata/" + setCode + ".pack");
for (String line : bpData) { for (String line : bpData) {
@@ -124,9 +115,7 @@ public class BoosterGenerator {
} else if (line.startsWith("Uncommons:")) { } else if (line.startsWith("Uncommons:")) {
numUncommons = Integer.parseInt(line.substring(10)); numUncommons = Integer.parseInt(line.substring(10));
} else if (line.startsWith("Rares:")) { } else if (line.startsWith("Rares:")) {
numRares = Integer.parseInt(line.substring(6)); numRareSlots = Integer.parseInt(line.substring(6));
} else if (line.startsWith("Mythics:")) {
numMythics = Integer.parseInt(line.substring(8));
} else if (line.startsWith("Specials:")) { } else if (line.startsWith("Specials:")) {
numSpecials = Integer.parseInt(line.substring(9)); numSpecials = Integer.parseInt(line.substring(9));
} }
@@ -137,30 +126,59 @@ public class BoosterGenerator {
System.out.println("numCommons: " + numCommons); System.out.println("numCommons: " + numCommons);
System.out.println("numUncommons: " + numUncommons); System.out.println("numUncommons: " + numUncommons);
System.out.println("numRares: " + numRares); System.out.println("numRares: " + numRares);
System.out.println("numMythics: " + numMythics);
System.out.println("numSpecials: " + numSpecials); System.out.println("numSpecials: " + numSpecials);
} }
} }
/** private List<CardPrinted> pickRandomCards(List<CardPrinted> source, int count)
* <p>shuffleAll.</p> {
*/ List<CardPrinted> result = new ArrayList<CardPrinted>(count);
private void shuffleAll() { if (count <= 0 || source == null || source.isEmpty()) { return result; }
if (!commons.isEmpty()) { Collections.shuffle(commons, MyRandom.random); } int listSize = source.size();
if (!uncommons.isEmpty()) { Collections.shuffle(uncommons, MyRandom.random); } int index = Integer.MAX_VALUE;
if (!rares.isEmpty()) { Collections.shuffle(rares, MyRandom.random); } for (int iCard = 0; iCard < count; iCard++) {
if (!mythics.isEmpty()) { Collections.shuffle(mythics, MyRandom.random); } if (index >= listSize) {
if (!specials.isEmpty()) { Collections.shuffle(specials, MyRandom.random); } Collections.shuffle(source, MyRandom.random);
index = 0;
if (Constant.Runtime.DevMode[0]) { }
System.out.println("commons.size: " + commons.size()); result.add(source.get(index));
System.out.println("uncommons.size: " + uncommons.size()); index++;
System.out.println("rares.size: " + rares.size());
System.out.println("mythics.size: " + mythics.size());
System.out.println("specials.size: " + specials.size());
} }
return result;
}
private List<CardPrinted> pickRandomRaresOrMythics(List<CardPrinted> rares, List<CardPrinted> mythics, int count)
{
List<CardPrinted> result = new ArrayList<CardPrinted>(count);
int raresSize = rares == null ? 0 : rares.size();
int mythicsSize = mythics == null ? 0 : mythics.size();
if (count <= 0 || raresSize == 0) { return result; }
int indexRares = Integer.MAX_VALUE;
int indexMythics = Integer.MAX_VALUE;
for (int iCard = 0; iCard < count; iCard++) {
boolean takeMythic = mythicsSize > 0 && MyRandom.random.nextInt(8) <= 1;
if (takeMythic) {
if (indexRares >= raresSize) {
Collections.shuffle(mythics, MyRandom.random);
indexMythics = 0;
}
result.add(mythics.get(indexMythics));
indexMythics++;
}
else
{
if (indexRares >= raresSize) {
Collections.shuffle(rares, MyRandom.random);
indexRares = 0;
}
result.add(rares.get(indexRares));
indexRares++;
}
}
return result;
} }
/** /**
@@ -171,65 +189,18 @@ public class BoosterGenerator {
public final List<CardPrinted> getBoosterPack() { public final List<CardPrinted> getBoosterPack() {
List<CardPrinted> temp = new ArrayList<CardPrinted>(); List<CardPrinted> temp = new ArrayList<CardPrinted>();
int i = 0; temp.addAll(pickRandomCards(commons, numCommons));
temp.addAll(pickRandomCards(uncommons, numUncommons));
if (commons.size() > numCommons) { // You can specify number of rare-slots or number of rares and mythics explicitly... or both, but they'll sum up
for (i = 0; i < numCommons; i++) { if (numRareSlots > 0) {
if (iCommons >= commons.size()) { temp.addAll(pickRandomRaresOrMythics(rares, mythics, numRareSlots));
iCommons = 0; }
} if (numRares > 0 || numMythics > 0) {
temp.addAll(pickRandomCards(rares, numRares));
temp.add(commons.get(iCommons++)); temp.addAll(pickRandomCards(mythics, numMythics));
}
} }
if (uncommons.size() > numUncommons) { temp.addAll(pickRandomCards(specials, numSpecials));
for (i = 0; i < numUncommons; i++) {
if (iUncommons >= uncommons.size()) {
iUncommons = 0;
}
temp.add(uncommons.get(iUncommons++));
}
}
for (i = 0; i < numRares; i++) {
if (numMythics > 0) {
if (mythics.size() > numMythics) {
if (MyRandom.random.nextInt(8) <= 1) {
if (iMythics >= mythics.size()) {
iMythics = 0;
}
temp.add(mythics.get(iMythics++));
} else {
if (iRares >= rares.size()) {
iRares = 0;
}
temp.add(rares.get(iRares++));
}
}
} else {
if (rares.size() > numRares) {
if (iRares >= rares.size()) {
iRares = 0;
}
temp.add(rares.get(iRares++));
}
}
}
if (specials.size() > numSpecials) {
for (i = 0; i < numSpecials; i++) {
if (iSpecials >= specials.size()) {
iSpecials = 0;
}
temp.add(specials.get(iSpecials++));
}
}
return temp; return temp;
} }

View File

@@ -55,7 +55,7 @@ public class ReadBoosterPack implements NewConstants {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public ItemPoolView<CardPrinted> getBoosterPack5() { public ItemPoolView<CardPrinted> getBoosterPack5() {
ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(CardPrinted.class);
for (int i = 0; i < 5; i++) { list.addAll(getBoosterPack()); } for (int i = 0; i < 5; i++) { list.addAll(getBoosterPack()); }
addBasicLands(list, 20); addBasicLands(list, 20);
@@ -92,7 +92,7 @@ public class ReadBoosterPack implements NewConstants {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public ItemPoolView<CardPrinted> getBoosterPack() { public ItemPoolView<CardPrinted> getBoosterPack() {
ItemPool<CardPrinted> pack = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> pack = new ItemPool<CardPrinted>(CardPrinted.class);
pack.add(getRandomCard(rares)); pack.add(getRandomCard(rares));
@@ -126,7 +126,7 @@ public class ReadBoosterPack implements NewConstants {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public ItemPoolView<CardPrinted> getShopCards(int totalPacks) { public ItemPoolView<CardPrinted> getShopCards(int totalPacks) {
ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(CardPrinted.class);
// Number of Packs granted // Number of Packs granted

View File

@@ -46,7 +46,7 @@ public class ReadDraftBoosterPack implements NewConstants {
} }
public ItemPoolView<CardPrinted> getBoosterPack5() { public ItemPoolView<CardPrinted> getBoosterPack5() {
ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> list = new ItemPool<CardPrinted>(CardPrinted.class);
for (int i = 0; i < 5; i++) { list.addAll(getBoosterPack()); } for (int i = 0; i < 5; i++) { list.addAll(getBoosterPack()); }
addBasicLands(list, 20); addBasicLands(list, 20);
@@ -82,7 +82,7 @@ public class ReadDraftBoosterPack implements NewConstants {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final ItemPoolView<CardPrinted> getBoosterPack() { public final ItemPoolView<CardPrinted> getBoosterPack() {
ItemPool<CardPrinted> pack = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> pack = new ItemPool<CardPrinted>(CardPrinted.class);
pack.add(getRandomCard(rareList)); pack.add(getRandomCard(rareList));

View File

@@ -9,10 +9,10 @@ import net.slightlymagic.braids.util.lambda.Lambda1;
* @version $Id: CardSet.java 9708 2011-08-09 19:34:12Z jendave $ * @version $Id: CardSet.java 9708 2011-08-09 19:34:12Z jendave $
*/ */
public final class CardSet implements Comparable<CardSet> { // immutable public final class CardSet implements Comparable<CardSet> { // immutable
private int index; private final int index;
private String code; private final String code;
private String code2; private final String code2;
private String name; private final String name;
public CardSet(final int index, final String name, final String code, final String code2) { public CardSet(final int index, final String name, final String code, final String code2) {
this.code = code; this.code = code;

View File

@@ -41,8 +41,8 @@ public final class Deck implements Comparable<Deck>, Serializable {
* <p>Constructor for Deck.</p> * <p>Constructor for Deck.</p>
*/ */
public Deck() { public Deck() {
main = new ItemPool<CardPrinted>(); main = new ItemPool<CardPrinted>(CardPrinted.class);
sideboard = new ItemPool<CardPrinted>(); sideboard = new ItemPool<CardPrinted>(CardPrinted.class);
} }
/** /**

View File

@@ -10,7 +10,9 @@ import forge.SetUtils;
import forge.card.CardBlock; import forge.card.CardBlock;
import forge.card.CardSet; import forge.card.CardSet;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckManager;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.ItemPool; import forge.item.ItemPool;
import forge.item.ItemPoolView; import forge.item.ItemPoolView;
@@ -70,7 +72,7 @@ public class BoosterDraft_1 implements BoosterDraft {
draftFormat[0] = draftType; draftFormat[0] = draftType;
if (draftType.equals("Full")) { // Draft from all cards in Forge if (draftType.equals("Full")) { // Draft from all cards in Forge
BoosterGenerator bpFull = new BoosterGenerator(); BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
packs.add(bpFull); packs.add(bpFull);
} }

View File

@@ -44,7 +44,7 @@ public class SealedDeck {
public SealedDeck(String sealedType) { public SealedDeck(String sealedType) {
if (sealedType.equals("Full")) { if (sealedType.equals("Full")) {
BoosterGenerator bpFull = new BoosterGenerator(); BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
packs.add(bpFull); packs.add(bpFull);
@@ -182,7 +182,7 @@ public class SealedDeck {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public ItemPool<CardPrinted> getCardpool() { public ItemPool<CardPrinted> getCardpool() {
ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
for (int i = 0; i < packs.size(); i++) for (int i = 0; i < packs.size(); i++)
pool.addAllCards(packs.get(i).getBoosterPack()); pool.addAllCards(packs.get(i).getBoosterPack());

View File

@@ -16,6 +16,7 @@ import forge.item.ItemPoolView;
*/ */
public interface DeckDisplay { public interface DeckDisplay {
void setDeck(ItemPoolView<CardPrinted> top, ItemPoolView<CardPrinted> bottom, GameType gameType); void setDeck(ItemPoolView<CardPrinted> top, ItemPoolView<CardPrinted> bottom, GameType gameType);
<T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt);
//top shows available card pool //top shows available card pool
//if constructed, top shows all cards //if constructed, top shows all cards

View File

@@ -74,6 +74,12 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
bottom.setDeck(bottomParam); bottom.setDeck(bottomParam);
} }
public <T extends InventoryItem> void setItems(ItemPoolView<T> topParam, ItemPoolView<T> bottomParam, GameType gt) {
gameType = gt;
top.setDeck(topParam);
bottom.setDeck(bottomParam);
}
public void updateDisplay() { public void updateDisplay() {
top.setFilter(buildFilter()); top.setFilter(buildFilter());
} }
@@ -84,6 +90,7 @@ public abstract class DeckEditorBase extends JFrame implements DeckDisplay {
} }
}; };
/** This class is used for a feature: when you start typing card name, the list gets auto-filtered. */
protected class OnChangeTextUpdateDisplay implements DocumentListener { protected class OnChangeTextUpdateDisplay implements DocumentListener {
private void onChange() { if (isFiltersChangeFiringUpdate) { updateDisplay(); } } private void onChange() { if (isFiltersChangeFiringUpdate) { updateDisplay(); } }
@Override public void insertUpdate(DocumentEvent e) { onChange(); } @Override public void insertUpdate(DocumentEvent e) { onChange(); }

View File

@@ -147,7 +147,7 @@ public final class DeckEditorMenu extends JMenuBar implements NewConstants {
// The only remaining reference to global variable! // The only remaining reference to global variable!
CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(15 * 5)); CardList random = new CardList(forge.AllZone.getCardFactory().getRandomCombinationWithoutRepetition(15 * 5));
ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> cpRandom = new ItemPool<CardPrinted>(CardPrinted.class);
for (Card c : random) { cpRandom.add(CardDb.instance().getCard(c)); } for (Card c : random) { cpRandom.add(CardDb.instance().getCard(c)); }
cpRandom.add(CardDb.instance().getCard("Forest")); cpRandom.add(CardDb.instance().getCard("Forest"));
cpRandom.add(CardDb.instance().getCard("Island")); cpRandom.add(CardDb.instance().getCard("Island"));
@@ -166,7 +166,7 @@ public final class DeckEditorMenu extends JMenuBar implements NewConstants {
GenerateConstructedDeck gen = new GenerateConstructedDeck(); GenerateConstructedDeck gen = new GenerateConstructedDeck();
ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> generated = new ItemPool<CardPrinted>(CardPrinted.class);
for (Card c : gen.generateDeck()) { generated.add(CardDb.instance().getCard(c)); } for (Card c : gen.generateDeck()) { generated.add(CardDb.instance().getCard(c)); }
deckDisplay.setDeck(null, generated, GameType.Constructed); deckDisplay.setDeck(null, generated, GameType.Constructed);
} }

View File

@@ -99,7 +99,7 @@ public final class DeckEditorQuest extends DeckEditorBase implements NewConstant
customMenu.setPlayerDeckName(deck.getName()); customMenu.setPlayerDeckName(deck.getName());
ItemPoolView<CardPrinted> bottomPool = deck.getMain(); ItemPoolView<CardPrinted> bottomPool = deck.getMain();
ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(CardPrinted.class);
cardpool.addAll(questData.getCards().getCardpool()); cardpool.addAll(questData.getCards().getCardpool());
// remove bottom cards that are in the deck from the card pool // remove bottom cards that are in the deck from the card pool

View File

@@ -271,7 +271,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
questData.addDeck(newDeck); questData.addDeck(newDeck);
ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(), CardPrinted.class); ItemPool<CardPrinted> cardpool = ItemPool.createFrom(questData.getCards().getCardpool(), CardPrinted.class);
ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(); ItemPool<CardPrinted> decklist = new ItemPool<CardPrinted>(CardPrinted.class);
for (Entry<CardPrinted, Integer> s : newDeck.getMain()) { for (Entry<CardPrinted, Integer> s : newDeck.getMain()) {
CardPrinted cp = s.getKey(); CardPrinted cp = s.getKey();
decklist.add(cp, s.getValue()); decklist.add(cp, s.getValue());
@@ -348,7 +348,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
private final ActionListener newDeckActionListener = new ActionListener() { private final ActionListener newDeckActionListener = new ActionListener() {
public void actionPerformed(final ActionEvent a) { public void actionPerformed(final ActionEvent a) {
deckDisplay.setDeck(questData.getCards().getCardpool().getView(), null, GameType.Quest); deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest);
setPlayerDeckName(""); setPlayerDeckName("");
} }
}; };
@@ -431,7 +431,7 @@ public class DeckEditorQuestMenu extends JMenuBar {
questData.removeDeck(currentDeck.getName()); questData.removeDeck(currentDeck.getName());
//show card pool //show card pool
deckDisplay.setDeck(questData.getCards().getCardpool().getView(), null, GameType.Quest); deckDisplay.setItems(questData.getCards().getCardpool().getView(), null, GameType.Quest);
setPlayerDeckName(""); setPlayerDeckName("");
} }

View File

@@ -88,15 +88,15 @@ public final class DeckEditorShop extends DeckEditorBase {
multiplier = questData.getCards().getSellMutliplier(); multiplier = questData.getCards().getSellMutliplier();
ItemPoolView<CardPrinted> forSale = questData.getCards().getShopList(); ItemPoolView<InventoryItem> forSale = questData.getCards().getShopList();
if (forSale.isEmpty()) { if (forSale.isEmpty()) {
questData.getCards().generateCardsInShop(); questData.getCards().generateCardsInShop();
forSale = questData.getCards().getShopList(); forSale = questData.getCards().getShopList();
} }
ItemPoolView<CardPrinted> owned = questData.getCards().getCardpool().getView(); ItemPoolView<InventoryItem> owned = questData.getCards().getCardpool().getView();
//newCardsList = questData.getCards().getNewCards(); //newCardsList = questData.getCards().getNewCards();
setDeck(forSale, owned, GameType.Quest); setItems(forSale, owned, GameType.Quest);
double multiPercent = multiplier * 100; double multiPercent = multiplier * 100;
NumberFormat formatter = new DecimalFormat("#0.00"); NumberFormat formatter = new DecimalFormat("#0.00");

View File

@@ -10,6 +10,7 @@ import forge.card.CardRarity;
import forge.card.CardSet; import forge.card.CardSet;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.item.InventoryItemFromSet;
/** /**
* TODO: Write javadoc for this type. * TODO: Write javadoc for this type.
@@ -22,8 +23,8 @@ public abstract class PresetColumns {
private static String toType(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getType().toString() : i.getClass().toString(); } private static String toType(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getType().toString() : i.getClass().toString(); }
private static String toPTL(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : ""; } private static String toPTL(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : ""; }
private static CardRarity toRarity(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown; } private static CardRarity toRarity(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown; }
private static CardSet toSetCmp(InventoryItem i) { return i instanceof CardPrinted ? SetUtils.getSetByCode(((CardPrinted) i).getSet()) : CardSet.unknown; } private static CardSet toSetCmp(InventoryItem i) { return i instanceof InventoryItemFromSet ? SetUtils.getSetByCode(((InventoryItemFromSet) i).getSet()) : CardSet.unknown; }
private static String toSetStr(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getSet() : "n/a"; } private static String toSetStr(InventoryItem i) { return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getSet() : "n/a"; }
private static Integer toAiCmp(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1); } private static Integer toAiCmp(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1); }
private static String toAiStr(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a"; } private static String toAiStr(InventoryItem i) { return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a"; }

View File

@@ -91,12 +91,13 @@ public final class TableModel<T extends InventoryItem> extends AbstractTableMode
} }
} }
private ItemPool<T> data = new ItemPool<T>(); private ItemPool<T> data;
private final CardPanelBase cardDisplay; private final CardPanelBase cardDisplay;
private final List<TableColumnInfo<T>> columns; private final List<TableColumnInfo<T>> columns;
private final SortOrders sortOrders = new SortOrders(); private final SortOrders sortOrders = new SortOrders();
public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow) { public TableModel(final CardPanelBase cd, final List<TableColumnInfo<T>> columnsToShow, Class<T> cls) {
data = new ItemPool<T>(cls);
cardDisplay = cd; cardDisplay = cd;
columns = columnsToShow; columns = columnsToShow;
columns.get(4).isMinMaxApplied = false; columns.get(4).isMinMaxApplied = false;

View File

@@ -66,7 +66,7 @@ public final class TableWithCards {
public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView)
{ {
model = new TableModel<InventoryItem>(cardView, columns); model = new TableModel<InventoryItem>(cardView, columns, InventoryItem.class);
model.addListeners(table); model.addListeners(table);
table.setModel(model); table.setModel(model);
model.resizeCols(table); model.resizeCols(table);

View File

@@ -0,0 +1,43 @@
package forge.item;
import java.util.List;
import forge.BoosterGenerator;
import forge.SetUtils;
/**
* TODO: Write javadoc for this type.
*
*/
public class Booster implements InventoryItemFromSet {
private final String cardSet;
private final String name;
private List<CardPrinted> cards = null;
public Booster(String set) {
cardSet = set;
name = SetUtils.getSetByCodeOrThrow(set).getName() + " booster";
}
@Override public String getSet() { return cardSet; }
@Override public String getName() { return name; }
@Override public String getImageFilename() {
// TODO: images for boosters
return null;
}
public List<CardPrinted> getCards() {
if (null == cards)
{
BoosterGenerator gen = new BoosterGenerator(cardSet);
cards = gen.getBoosterPack();
// TODO: Add land here!
}
return cards;
}
}

View File

@@ -20,7 +20,7 @@ import forge.card.CardRules;
* @author Forge * @author Forge
* @version $Id: CardReference.java 9708 2011-08-09 19:34:12Z jendave $ * @version $Id: CardReference.java 9708 2011-08-09 19:34:12Z jendave $
*/ */
public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem { public final class CardPrinted implements Comparable<CardPrinted>, InventoryItemFromSet {
// Reference to rules // Reference to rules
private final transient CardRules card; private final transient CardRules card;

View File

@@ -0,0 +1,14 @@
package forge.item;
/**
* Interface to define a player's inventory may hold.
* Should include CardPrinted, Booster, Pets, Plants... etc
*/
public interface InventoryItemFromSet extends InventoryItem {
/** An inventory item has to provide a name. */
String getName();
/** An inventory item has to provide a picture. */
String getImageFilename();
/** An item belonging to a set should return its set as well*/
String getSet();
}

View File

@@ -12,16 +12,16 @@ import java.util.Map.Entry;
public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> { public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
// Constructors here // Constructors here
public ItemPool() { super(); } public ItemPool(final Class<T> cls) { super(cls); }
@SuppressWarnings("unchecked") // conversion here must be safe @SuppressWarnings("unchecked") // conversion here must be safe
public ItemPool(final List<String> names) { super(); addAllCards((Iterable<T>) CardDb.instance().getCards(names)); } public ItemPool(final List<String> names, final Class<T> cls) { super(cls); addAllCards((Iterable<T>) CardDb.instance().getCards(names)); }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
createFrom(ItemPoolView<Tin> from, Class<Tout> clsHint) createFrom(ItemPoolView<Tin> from, Class<Tout> clsHint)
{ {
ItemPool<Tout> result = new ItemPool<Tout>(); ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
if (from != null) { if (from != null) {
for (Entry<Tin, Integer> e : from) { for (Entry<Tin, Integer> e : from) {
Tin srcKey = e.getKey(); Tin srcKey = e.getKey();
@@ -35,8 +35,9 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout> public static <Tin extends InventoryItem, Tout extends InventoryItem> ItemPool<Tout>
createFrom(Iterable<Tin> from, Class<Tout> clsHint) { createFrom(Iterable<Tin> from, Class<Tout> clsHint)
ItemPool<Tout> result = new ItemPool<Tout>(); {
ItemPool<Tout> result = new ItemPool<Tout>(clsHint);
if (from != null) { if (from != null) {
for (Tin srcKey : from) { for (Tin srcKey : from) {
if (clsHint.isInstance(srcKey)) { if (clsHint.isInstance(srcKey)) {
@@ -48,7 +49,7 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
} }
// get // get
public ItemPoolView<T> getView() { return new ItemPoolView<T>(Collections.unmodifiableMap(cards)); } public ItemPoolView<T> getView() { return new ItemPoolView<T>(Collections.unmodifiableMap(cards), myClass); }
// Cards manipulation // Cards manipulation
public void add(final T card) { add(card, 1); } public void add(final T card) { add(card, 1); }
@@ -65,8 +66,14 @@ public final class ItemPool<T extends InventoryItem> extends ItemPoolView<T> {
for (T cr : cards) { add(cr); } for (T cr : cards) { add(cr); }
isListInSync = false; isListInSync = false;
} }
public void addAll(final Iterable<Entry<T, Integer>> map) {
for (Entry<T, Integer> e : map) { add(e.getKey(), e.getValue()); } @SuppressWarnings("unchecked")
public <U extends InventoryItem> void addAll(final Iterable<Entry<U, Integer>> map) {
for (Entry<U, Integer> e : map) {
if (myClass.isInstance(e.getKey())) {
add((T) e.getKey(), e.getValue());
}
}
isListInSync = false; isListInSync = false;
} }

View File

@@ -42,11 +42,12 @@ public class ItemPoolView<T extends InventoryItem> implements Iterable<Entry<T,
}; };
// Constructors // Constructors
public ItemPoolView() { cards = new Hashtable<T, Integer>(); } public ItemPoolView(final Class<T> cls) { cards = new Hashtable<T, Integer>(); myClass = cls; }
public ItemPoolView(final Map<T, Integer> inMap) { cards = inMap; } public ItemPoolView(final Map<T, Integer> inMap, final Class<T> cls) { cards = inMap; myClass = cls; }
// Data members // Data members
protected Map<T, Integer> cards; protected Map<T, Integer> cards;
protected final Class<T> myClass; // class does not keep this in runtime by itself
// same thing as above, it was copied to provide sorting (needed by table views in deck editors) // same thing as above, it was copied to provide sorting (needed by table views in deck editors)
protected List<Entry<T, Integer>> cardsListOrdered = new ArrayList<Map.Entry<T,Integer>>(); protected List<Entry<T, Integer>> cardsListOrdered = new ArrayList<Map.Entry<T,Integer>>();

View File

@@ -0,0 +1,2 @@
/** Forge Card Game */
package forge.item;

View File

@@ -68,9 +68,9 @@ public final class QuestData {
Map<String, Deck> myDecks = new HashMap<String, Deck>(); Map<String, Deck> myDecks = new HashMap<String, Deck>();
// Cards associated with quest // Cards associated with quest
ItemPool<CardPrinted> cardPool = new ItemPool<CardPrinted>(); // player's belonging ItemPool<InventoryItem> cardPool = new ItemPool<InventoryItem>(InventoryItem.class); // player's belonging
ItemPool<CardPrinted> shopList = new ItemPool<CardPrinted>(); // the current shop list ItemPool<InventoryItem> shopList = new ItemPool<InventoryItem>(InventoryItem.class); // the current shop list
ItemPool<InventoryItem> newCardList = new ItemPool<InventoryItem>(); // cards acquired since last game-win/loss ItemPool<InventoryItem> newCardList = new ItemPool<InventoryItem>(InventoryItem.class); // cards acquired since last game-win/loss
// Quests history // Quests history
int questsPlayed; int questsPlayed;
@@ -116,8 +116,8 @@ public final class QuestData {
myRewards = new QuestUtilRewards(this); myRewards = new QuestUtilRewards(this);
// to avoid NPE some pools will be created here if they are null // to avoid NPE some pools will be created here if they are null
if (null == newCardList) { newCardList = new ItemPool<InventoryItem>(); } if (null == newCardList) { newCardList = new ItemPool<InventoryItem>(InventoryItem.class); }
if (null == shopList) { shopList = new ItemPool<CardPrinted>(); } if (null == shopList) { shopList = new ItemPool<InventoryItem>(InventoryItem.class); }
} }

View File

@@ -10,6 +10,7 @@ import com.thoughtworks.xstream.converters.UnmarshallingContext;
import forge.error.ErrorViewer; import forge.error.ErrorViewer;
import forge.game.GameType; import forge.game.GameType;
import forge.item.Booster;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
@@ -222,26 +223,37 @@ public class QuestDataIO {
return clasz.equals(ItemPool.class); return clasz.equals(ItemPool.class);
} }
private void writeCardRef(CardPrinted cref, HierarchicalStreamWriter writer) private void write(CardPrinted cref, Integer count, HierarchicalStreamWriter writer)
{ {
writer.startNode("card");
writer.addAttribute("c", cref.getName()); writer.addAttribute("c", cref.getName());
writer.addAttribute("s", cref.getSet()); writer.addAttribute("s", cref.getSet());
if (cref.isFoil()) { writer.addAttribute("foil", "1"); } if (cref.isFoil()) { writer.addAttribute("foil", "1"); }
if (cref.getArtIndex() > 0) { writer.addAttribute("i", Integer.toString(cref.getArtIndex())); } if (cref.getArtIndex() > 0) { writer.addAttribute("i", Integer.toString(cref.getArtIndex())); }
writer.addAttribute("n", count.toString());
writer.endNode();
} }
private void write(Booster booster, Integer count, HierarchicalStreamWriter writer)
{
writer.startNode("booster");
writer.addAttribute("s", booster.getSet());
writer.addAttribute("n", count.toString());
writer.endNode();
}
@Override @Override
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ItemPool<InventoryItem> pool = (ItemPool<InventoryItem>) source; ItemPool<InventoryItem> pool = (ItemPool<InventoryItem>) source;
for (Entry<InventoryItem, Integer> e : pool) { for (Entry<InventoryItem, Integer> e : pool) {
if ( e.getKey() instanceof CardPrinted) InventoryItem item = e.getKey();
{ Integer count = e.getValue();
writer.startNode("card"); if (item instanceof CardPrinted) {
writeCardRef((CardPrinted) e.getKey(), writer); write((CardPrinted) item, count, writer);
writer.addAttribute("n", e.getValue().toString()); } else if (item instanceof Booster) {
writer.endNode(); write((Booster) item, count, writer);
} }
} }
@@ -249,24 +261,31 @@ public class QuestDataIO {
@Override @Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
ItemPool<CardPrinted> result = new ItemPool<CardPrinted>(); ItemPool<InventoryItem> result = new ItemPool<InventoryItem>(InventoryItem.class);
while (reader.hasMoreChildren()) { while (reader.hasMoreChildren()) {
reader.moveDown(); reader.moveDown();
String sCnt = reader.getAttribute("n");
int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1;
String nodename = reader.getNodeName(); String nodename = reader.getNodeName();
if("string".equals(nodename)) { if("string".equals(nodename)) {
CardPrinted cp = CardDb.instance().getCard(reader.getValue()); result.add(CardDb.instance().getCard(reader.getValue()));
result.add(cp); } else if ("card".equals(nodename)) { // new format
} else { // new format result.add(readCardPrinted(reader), cnt);
CardPrinted cp = readCardPrinted(reader); } else if ("booster".equals(nodename)) {
String sCnt = reader.getAttribute("n"); result.add(readBooster(reader), cnt);
int cnt = StringUtils.isNumeric(sCnt) ? Integer.parseInt(sCnt) : 1;
result.add(cp, cnt);
} }
reader.moveUp(); reader.moveUp();
} }
return result; return result;
} }
private Booster readBooster(final HierarchicalStreamReader reader)
{
String set = reader.getAttribute("s");
return new Booster(set);
}
private CardPrinted readCardPrinted(final HierarchicalStreamReader reader) private CardPrinted readCardPrinted(final HierarchicalStreamReader reader)
{ {
String name = reader.getAttribute("c"); String name = reader.getAttribute("c");

View File

@@ -10,6 +10,7 @@ import net.slightlymagic.maxmtg.Predicate;
import forge.ReadBoosterPack; import forge.ReadBoosterPack;
import forge.card.CardRarity; import forge.card.CardRarity;
import forge.deck.Deck; import forge.deck.Deck;
import forge.item.Booster;
import forge.item.CardDb; import forge.item.CardDb;
import forge.item.CardPrinted; import forge.item.CardPrinted;
import forge.item.InventoryItem; import forge.item.InventoryItem;
@@ -149,13 +150,14 @@ public final class QuestUtilCards {
ItemPoolView<CardPrinted> fromBoosters = pack.getShopCards(totalPacks); ItemPoolView<CardPrinted> fromBoosters = pack.getShopCards(totalPacks);
q.shopList.clear(); q.shopList.clear();
q.shopList.addAll(fromBoosters); q.shopList.addAll(fromBoosters);
q.shopList.add(new Booster("M10"));
} }
public ItemPool<CardPrinted> getCardpool() { public ItemPool<InventoryItem> getCardpool() {
return q.cardPool; return q.cardPool;
} }
public ItemPoolView<CardPrinted> getShopList() { public ItemPoolView<InventoryItem> getShopList() {
if (q.shopList.isEmpty()) { if (q.shopList.isEmpty()) {
generateCardsInShop(); generateCardsInShop();
} }