fixed: several boosters yeilded the same Cards

cardDetailPanel not shown if non-card is under cursor
boosters show their pictures (may keep them in booster/CODE.png)
fixed too mythics chances (was 1/4)
BoosterPacks (inventory) add basic land if there is a slot for it
This commit is contained in:
Maxmtg
2011-09-15 01:16:34 +00:00
parent e31e445a0d
commit 887a668478
11 changed files with 92 additions and 35 deletions

View File

@@ -89,7 +89,8 @@ public class ImageCache implements NewConstants {
} else path = ForgeProps.getFile(IMAGE_BASE);
File file = null;
file = new File(path, key + ".jpg");
String fName = key.endsWith(".png") ? key : key + ".jpg";
file = new File(path, fName);
if (!file.exists()) {
//DEBUG
//System.out.println("File not found, no image created: " + file);

View File

@@ -90,8 +90,9 @@ public class BoosterGenerator {
for (CardPrinted c : cardsInThisSet) {
addToRarity(c);
//System.out.println(c);
}
//System.out.println("done");
}
private List<CardPrinted> pickRandomCards(List<CardPrinted> source, int count)
@@ -123,7 +124,8 @@ public class BoosterGenerator {
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;
int rollD8 = MyRandom.random.nextInt(8);
boolean takeMythic = mythicsSize > 0 && rollD8 < 1;
if (takeMythic) {
if (indexRares >= raresSize) {
Collections.shuffle(mythics, MyRandom.random);
@@ -147,13 +149,13 @@ public class BoosterGenerator {
public final List<CardPrinted> getBoosterPack() {
return getBoosterPack(numCommons, numUncommons, numRareSlots, 0, 0, numSpecials, 0);
return getBoosterPack(numCommons, numUncommons, numRareSlots, 0, 0, numSpecials, 0, 0);
}
/**
* So many parameters needed for custom limited cardpools,
*/
public final List<CardPrinted> getBoosterPack(final int nCom, final int nUnc, final int nRareSlots,
final int nRares, final int nMythics, final int nSpecs, final int nAnyCard) {
final int nRares, final int nMythics, final int nSpecs, final int nAnyCard, final int nLands) {
List<CardPrinted> temp = new ArrayList<CardPrinted>();
@@ -181,6 +183,8 @@ public class BoosterGenerator {
temp.addAll(pickRandomCards(specials, nSpecs));
temp.addAll(pickRandomCards(allButLands, nAnyCard));
temp.addAll(pickRandomCards(basicLands, nLands));
return temp;
}
@@ -192,10 +196,13 @@ public class BoosterGenerator {
case Rare: rares.add(c); break;
case MythicRare: mythics.add(c); break;
case Special: specials.add(c); break;
default: return;
}
if (c.getCard().getType().isBasicLand()) { basicLands.add(c); } else { allButLands.add(c); }
if (c.getCard().getType().isBasicLand()) {
basicLands.add(c);
} else {
allButLands.add(c);
}
}
}

View File

@@ -362,6 +362,8 @@ public final class CardRules {
public static final Predicate<CardRules> isCreature = coreType(true, CardCoreType.Creature);
public static final Predicate<CardRules> isArtifact = coreType(true, CardCoreType.Artifact);
public static final Predicate<CardRules> isLand = coreType(true, CardCoreType.Land);
public static final Predicate<CardRules> isBasicLand = new Predicate<CardRules>(){
@Override public boolean isTrue(CardRules subject) { return subject.getType().isBasicLand(); } };
public static final Predicate<CardRules> isPlaneswalker = coreType(true, CardCoreType.Planeswalker);
public static final Predicate<CardRules> isInstant = coreType(true, CardCoreType.Instant);
public static final Predicate<CardRules> isSorcery = coreType(true, CardCoreType.Sorcery);

View File

@@ -80,7 +80,8 @@ public final class CardSet implements Comparable<CardSet> { // immutable
//private final String landCode;
public BoosterData(final int nC, final int nU, final int nR, final int nS) {
this(nC, nU, nR, nS, CARDS_PER_BOOSTER - nC - nR - nU - nS, 68);
// if this booster has more that 10 cards, there must be a land in 15th slot unless it's already taken
this(nC, nU, nR, nS, nC + nR + nU + nS > 10 ? CARDS_PER_BOOSTER - nC - nR - nU - nS : 0, 68);
}
public BoosterData(final int nC, final int nU, final int nR, final int nS, final int nL, final int oneFoilPer) {

View File

@@ -144,9 +144,9 @@ public final class BoosterDraft_1 implements BoosterDraft {
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
if ( draft.IgnoreRarity ) {
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, draft.NumCards);
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, draft.NumCards, 0);
}
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0);
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0, 0);
}
};

View File

@@ -133,9 +133,9 @@ public class SealedDeck {
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
if ( draft.IgnoreRarity ) {
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, draft.NumCards);
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, draft.NumCards, 0);
}
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0);
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0, 0);
}
};

View File

@@ -28,7 +28,9 @@ public class CardPanelLite extends CardPanelBase {
public void showCard(InventoryItem card) {
picture.setCard(card);
detail.setCard(card != null && card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null);
boolean isCard = card != null && card instanceof CardPrinted;
detail.setVisible(isCard);
if (isCard) { detail.setCard(((CardPrinted) card).toForgeCard()); }
}
public Card getCard() { return detail.getCard(); }

View File

@@ -32,7 +32,6 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPoolView;
import forge.quest.data.QuestData;
//import forge.view.swing.OldGuiNewGame;
/**
* <p>
@@ -148,9 +147,9 @@ public final class DeckEditorShop extends DeckEditorBase {
columns.add(new TableColumnInfo<InventoryItem>("Price", 40, fnPriceCompare, fnPriceGet));
top.setup(columns, cardView);
columnsBelow.add(new TableColumnInfo<InventoryItem>("#Dk", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 30, questData.getCards().fnNewCompare, questData.getCards().fnNewGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 40, fnPriceCompare, fnPriceSellGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, fnDeckCompare, fnDeckGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, questData.getCards().fnNewCompare, questData.getCards().fnNewGet));
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 35, fnPriceCompare, fnPriceSellGet));
bottom.setup(columnsBelow, cardView);
this.setSize(1024, 768);
@@ -276,7 +275,7 @@ public final class DeckEditorShop extends DeckEditorBase {
questData.getCards().buyCard(card, value);
} else if (item instanceof BoosterPack) {
top.removeCard(item);
BoosterPack booster = (BoosterPack) item;
BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
questData.getCards().buyBooster(booster, value);
List<CardPrinted> newCards = booster.getCards();
for (CardPrinted card : newCards) { bottom.addCard(card); }

View File

@@ -3,9 +3,11 @@ package forge.item;
import java.util.List;
import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate;
import forge.SetUtils;
import forge.card.BoosterGenerator;
import forge.card.CardRules;
import forge.card.CardSet;
/**
@@ -36,17 +38,39 @@ public class BoosterPack implements InventoryItemFromSet {
@Override public String getName() { return name; }
@Override public String getImageFilename() {
// TODO: need images for boosters
return null;
return "booster/"+cardSet.getCode()+".png";
}
public List<CardPrinted> getCards() {
if (null == cards)
private CardPrinted getRandomBasicLand(CardSet set) {
return Predicate.and(CardPrinted.Predicates.printedInSets(set.getCode()),
CardRules.Predicates.Presets.isBasicLand,
CardPrinted.fnGetRules).random(CardDb.instance().getAllCards());
}
private CardPrinted getLandFromNearestSet()
{
List<CardSet> sets = SetUtils.getAllSets();
int iThisSet = sets.indexOf(cardSet);
for (int iSet = iThisSet; iSet < sets.size(); iSet++)
{
BoosterGenerator gen = new BoosterGenerator(cardSet);
cards = gen.getBoosterPack();
// TODO: Add land here!
CardPrinted land = getRandomBasicLand(sets.get(iSet));
if (null != land) return land;
}
// if not found (though that's impossible)
return getRandomBasicLand(SetUtils.getSetByCode("M12"));
}
private void generate() {
BoosterGenerator gen = new BoosterGenerator(cardSet);
cards = gen.getBoosterPack();
int cntLands = cardSet.getBoosterData().getLand();
if (cntLands > 0) {
cards.add(getLandFromNearestSet());
}
}
public List<CardPrinted> getCards() {
if (null == cards) { generate(); }
return cards;
}
@@ -75,12 +99,9 @@ public class BoosterPack implements InventoryItemFromSet {
return true;
}
/* (non-Javadoc)
* @see forge.item.InventoryItem#getType()
*/
@Override
public String getType() {
return "Booster Pack";
@Override public String getType() { return "Booster Pack"; }
@Override public Object clone() {
return new BoosterPack(cardSet); // it's ok to share a reference to cardSet which is static anyway
}

View File

@@ -160,16 +160,29 @@ public final class QuestUtilCards {
q.shopList.clear();
for (int i = 0; i < totalPacks; i++) {
q.shopList.addAllCards(pack.getBoosterPack(7, 3, 1, 0, 0, 0, 0));
q.shopList.addAllCards(pack.getBoosterPack(7, 3, 1, 0, 0, 0, 0, 0));
}
addBasicLands(q.shopList, 10, 5);
final int BOOSTERS_T2 = 2;
final int BOOSTERS_EXT_BUT_T2 = 2;
final int BOOSTERS_MODERN_BUT_EXT = 2;
final int BOOSTERS_NOT_MODERN = 2;
Predicate<CardSet> filterT2 = CardSet.Predicates.isLegalInFormat(SetUtils.getStandard());
q.shopList.addAllCards(filterT2.random(SetUtils.getAllSets(), 2, BoosterPack.fnFromSet));
q.shopList.addAllCards(filterT2.random(SetUtils.getAllSets(), BOOSTERS_T2, BoosterPack.fnFromSet));
Predicate<CardSet> filterExt = CardSet.Predicates.isLegalInFormat(SetUtils.getExtended());
Predicate<CardSet> filterExtButT2 = Predicate.and(filterExt, Predicate.not(filterT2));
q.shopList.addAllCards(filterExtButT2.random(SetUtils.getAllSets(), 3, BoosterPack.fnFromSet));
q.shopList.addAllCards(filterExtButT2.random(SetUtils.getAllSets(), BOOSTERS_EXT_BUT_T2, BoosterPack.fnFromSet));
Predicate<CardSet> filterModern = CardSet.Predicates.isLegalInFormat(SetUtils.getModern());
Predicate<CardSet> filterModernButExt = Predicate.and(filterModern, Predicate.not(filterExt));
q.shopList.addAllCards(filterModernButExt.random(SetUtils.getAllSets(), BOOSTERS_MODERN_BUT_EXT, BoosterPack.fnFromSet));
Predicate<CardSet> filterNotModern = Predicate.not(filterModern);
q.shopList.addAllCards(filterNotModern.random(SetUtils.getAllSets(), BOOSTERS_NOT_MODERN, BoosterPack.fnFromSet));
}
public ItemPool<InventoryItem> getCardpool() {

View File

@@ -64,6 +64,17 @@ public abstract class Predicate<T> {
return result;
}
// Check if any element meeting the criteria is present
public final boolean any(final Iterable<T> source) {
if (source != null) { for (T c : source) { if (isTrue(c)) { return true; } } }
return false;
}
public final <U> boolean any(final Iterable<U> source, final Lambda1<T, U> accessor) {
if (source != null) { for (U c : source) { if (isTrue(accessor.apply(c))) { return true; } } }
return false;
}
// select top 1
public final T first(final Iterable<T> source) {
if (source != null) { for (T c : source) { if (isTrue(c)) { return c; } } }