replaced some cardFactory.getcard to CardPrinted.toForgeCard calls

still renaming set to edition
streamlined challenge reward generation
This commit is contained in:
Maxmtg
2012-02-24 08:40:19 +00:00
parent e8a903453c
commit 115b76e1ca
13 changed files with 71 additions and 211 deletions

View File

@@ -696,7 +696,7 @@ public final class CardUtil {
* @return the string
*/
public static String buildFilename(final CardPrinted card) {
final int maxIndex = card.getCard().getSetInfo(card.getEdition()).getCopiesCount();
final int maxIndex = card.getCard().getEditionInfo(card.getEdition()).getCopiesCount();
return CardUtil.buildFilename(card.getName(), card.getEdition(), card.getArtIndex(), maxIndex, false);
}
@@ -710,7 +710,7 @@ public final class CardUtil {
* @return the string
*/
public static String buildFilename(final CardPrinted card, final String nameToUse) {
final int maxIndex = card.getCard().getSetInfo(card.getEdition()).getCopiesCount();
final int maxIndex = card.getCard().getEditionInfo(card.getEdition()).getCopiesCount();
return CardUtil.buildFilename(nameToUse, card.getEdition(), card.getArtIndex(), maxIndex, false);
}

View File

@@ -81,7 +81,7 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
System.out.println("Oh snap!");
}
if (!foundSetImage) {
final int artsCnt = c.getCard().getSetInfo(setCode3).getCopiesCount();
final int artsCnt = c.getCard().getEditionInfo(setCode3).getCopiesCount();
final String fn = CardUtil.buildIdealFilename(cardName, c.getArtIndex(), artsCnt);
cList.add(new DownloadObject(fn, urlBase + setCode2 + "/" + Base64Coder.encodeString(fn, true),
this.picturesPath + File.separator + setCode3));

View File

@@ -304,7 +304,7 @@ public final class CardRules {
* the set code
* @return the sets the info
*/
public CardInSet getSetInfo(final String setCode) {
public CardInSet getEditionInfo(final String setCode) {
final CardInSet result = this.setsPrinted.get(setCode);
if (result != null) {
return result;

View File

@@ -111,7 +111,6 @@ public class GameNew {
Singletons.getControl().getControlMatch().getMessageControl().updateGameCount();
// friendliness
final CardFactoryInterface c = AllZone.getCardFactory();
Card.resetUniqueNumber();
final boolean canRandomFoil = Constant.Runtime.RANDOM_FOIL[0]
&& Constant.Runtime.getGameType().equals(GameType.Constructed);
@@ -125,16 +124,13 @@ public class GameNew {
final CardPrinted cardPrinted = stackOfCards.getKey();
for (int i = 0; i < stackOfCards.getValue(); i++) {
final Card card = c.getCard(cardPrinted.getName(), AllZone.getHumanPlayer());
card.setCurSetCode(cardPrinted.getEdition());
final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getEdition()).getCopiesCount();
final Card card = cardPrinted.toForgeCard(AllZone.getHumanPlayer());
final int cntVariants = cardPrinted.getCard().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
if (cntVariants > 1) {
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
card.setImageFilename(CardUtil.buildFilename(card));
}
card.setImageFilename(CardUtil.buildFilename(card));
// Assign random foiling on approximately 1:20 cards
if (cardPrinted.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {
final int iFoil = MyRandom.getRandom().nextInt(9) + 1;
@@ -167,16 +163,13 @@ public class GameNew {
final CardPrinted cardPrinted = stackOfCards.getKey();
for (int i = 0; i < stackOfCards.getValue(); i++) {
final Card card = c.getCard(cardPrinted.getName(), AllZone.getComputerPlayer());
card.setCurSetCode(cardPrinted.getEdition());
final int cntVariants = cardPrinted.getCard().getSetInfo(cardPrinted.getEdition()).getCopiesCount();
final Card card = cardPrinted.toForgeCard(AllZone.getComputerPlayer());
final int cntVariants = cardPrinted.getCard().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
if (cntVariants > 1) {
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
card.setImageFilename(CardUtil.buildFilename(card));
}
card.setImageFilename(CardUtil.buildFilename(card));
// Assign random foiling on approximately 1:20 cards
if (cardPrinted.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {
final int iFoil = MyRandom.getRandom().nextInt(9) + 1;

View File

@@ -21,7 +21,6 @@ import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import forge.AllZone;
import forge.card.CardRarity;
import forge.deck.Deck;
import forge.deck.DeckBase;
@@ -70,8 +69,7 @@ public class CustomLimited extends DeckBase {
private transient ItemPoolView<CardPrinted> cardPool;
/** The Land set code. */
private String landSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer())
.getMostRecentSet();
private String landSetCode = CardDb.instance().getCard("Plains", true).getEdition();
/*
* (non-Javadoc)

View File

@@ -37,9 +37,7 @@ import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.AllZone;
import forge.Card;
import forge.CardUtil;
import forge.gui.game.CardDetailPanel;
import forge.gui.game.CardPicturePanel;
import forge.item.CardPrinted;
@@ -217,10 +215,7 @@ public class CardListViewer {
this.cache = new Card[CardListViewer.this.list.size()];
}
if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card;
this.cache[row] = cp.toForgeCard();
}
}
}

View File

@@ -29,6 +29,7 @@ import org.apache.commons.lang3.ArrayUtils;
import forge.AllZone;
import forge.Card;
import forge.CardUtil;
import forge.Player;
import forge.card.CardRarity;
import forge.card.CardRules;
@@ -83,7 +84,7 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
* @see forge.item.InventoryItemFromSet#getSet()
*/
/**
* Gets the sets the.
* Gets the edition code of the card.
*
* @return String
*/
@@ -274,8 +275,13 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
*
* @return the card
*/
public Card toForgeCard() {
final Card c = AllZone.getCardFactory().getCard(this.name, null);
public Card toForgeCard() {
return toForgeCard(null);
}
public Card toForgeCard(Player owner) {
final Card c = AllZone.getCardFactory().getCard(this.name, owner);
if (c != null) {
c.setCurSetCode(this.getEdition());
c.setRandomPicture(this.artIndex + 1);

View File

@@ -22,14 +22,10 @@ import java.util.Collections;
import java.util.List;
import net.slightlymagic.maxmtg.Predicate;
import org.apache.commons.lang3.StringUtils;
import forge.Constant;
import forge.card.CardRarity;
import forge.card.CardRules;
import forge.item.CardDb;
import forge.item.CardPrinted;
import forge.item.CardPrinted.Predicates;
import forge.util.MyRandom;
// The BoosterPack generates cards for the Card Pool in Quest Mode
@@ -161,49 +157,16 @@ public final class BoosterUtils {
return result;
}
// Left if only for backwards compatibility
/**
* Generate cards.
*
* @param num
* the num
* @param rarity
* the rarity
* @param color
* the color
* @return the list
*/
public static List<CardPrinted> generateCards(final int num, final CardRarity rarity, final String color) {
final Predicate<CardPrinted> whatYouWant = BoosterUtils.getPredicateForConditions(rarity, color);
return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
}
/**
* Generate cards.
*
* @param filter
* the filter
* @param num
* the num
* @param rarity
* the rarity
* @param color
* the color
* @return the list
*/
public static List<CardPrinted> generateCards(final Predicate<CardPrinted> filter, final int num,
final CardRarity rarity, final String color) {
final Predicate<CardPrinted> whatYouWant = Predicate.and(filter,
BoosterUtils.getPredicateForConditions(rarity, color));
return BoosterUtils.generateDistinctCards(CardDb.instance().getAllUniqueCards(), whatYouWant, num);
}
private static List<CardPrinted> generateDistinctCards(final Iterable<CardPrinted> source,
public static List<CardPrinted> generateDistinctCards(final Predicate<CardPrinted> filter, final int cntNeeded) {
return generateDistinctCards(CardDb.instance().getAllCards(), filter, cntNeeded);
}
public static List<CardPrinted> generateDistinctCards(final Iterable<CardPrinted> source,
final Predicate<CardPrinted> filter, final int cntNeeded) {
final ArrayList<CardPrinted> result = new ArrayList<CardPrinted>();
int cntMade = 0;
// This will prevent endless loop @ wh
// This will prevent endless loop @ while
int allowedMisses = (2 + 2) * cntNeeded; // lol, 2+2 is not magic
// constant!
@@ -221,85 +184,45 @@ public final class BoosterUtils {
return result;
}
private static Predicate<CardPrinted> getPredicateForConditions(final CardRarity rarity, final String color) {
Predicate<CardPrinted> rFilter;
switch (rarity) {
case Rare:
rFilter = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
break;
case Common:
rFilter = CardPrinted.Predicates.Presets.IS_COMMON;
break;
case Uncommon:
rFilter = CardPrinted.Predicates.Presets.IS_UNCOMMON;
break;
default:
rFilter = Predicate.getTrue(CardPrinted.class);
}
Predicate<CardRules> colorFilter;
if (StringUtils.isBlank(color)) {
colorFilter = Predicate.getTrue(CardRules.class);
} else {
final String col = color.toLowerCase();
if (col.startsWith("wh")) {
colorFilter = CardRules.Predicates.Presets.IS_WHITE;
} else if (col.startsWith("bla")) {
colorFilter = CardRules.Predicates.Presets.IS_BLACK;
} else if (col.startsWith("blu")) {
colorFilter = CardRules.Predicates.Presets.IS_BLUE;
} else if (col.startsWith("re")) {
colorFilter = CardRules.Predicates.Presets.IS_RED;
} else if (col.startsWith("col")) {
colorFilter = CardRules.Predicates.Presets.IS_COLORLESS;
} else if (col.startsWith("gre")) {
colorFilter = CardRules.Predicates.Presets.IS_GREEN;
} else if (col.startsWith("mul")) {
colorFilter = CardRules.Predicates.Presets.IS_MULTICOLOR;
} else {
colorFilter = Predicate.getTrue(CardRules.class);
}
}
return Predicate.and(rFilter, colorFilter, CardPrinted.FN_GET_RULES);
}
// return List<CardPrinted> of 5 or 6 cards, one for each color and maybe an
// artifact
/**
* Gets the variety.
* <p>
* generateCardRewardList.
* </p>
* Takes a reward list string, parses, and returns list of cards rewarded.
*
* @param in
* the in
* @return the variety
* @param s
* Properties string of reward (97 multicolor rares)
* @return CardList
*/
public static List<CardPrinted> getVariety(final List<CardPrinted> in) {
final List<CardPrinted> out = new ArrayList<CardPrinted>();
Collections.shuffle(in, MyRandom.getRandom());
for (int i = 0; i < Constant.Color.COLORS.length; i++) {
final CardPrinted check = BoosterUtils.findCardOfColor(in, i);
if (check != null) {
out.add(check);
}
public static List<CardPrinted> generateCardRewardList(final String s) {
final String[] temp = s.split(" ");
final int qty = Integer.parseInt(temp[0]);
// Determine rarity
Predicate<CardPrinted> rar = CardPrinted.Predicates.Presets.IS_UNCOMMON;
if (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")) {
rar = CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC;
}
return out;
} // getVariety()
/**
* Find card of color.
*
* @param in
* the in
* @param color
* the color
* @return the card printed
*/
private static CardPrinted findCardOfColor(final List<CardPrinted> in, final int color) {
final Predicate<CardRules> filter = CardRules.Predicates.Presets.COLORS.get(color);
if (null == filter) {
return null;
// Determine color ("random" defaults to null color)
Predicate<CardRules> col = Predicate.getTrue(CardRules.class);
if (temp[1].equalsIgnoreCase("black")) {
col = CardRules.Predicates.Presets.IS_BLACK;
} else if (temp[1].equalsIgnoreCase("blue")) {
col = CardRules.Predicates.Presets.IS_BLUE;
} else if (temp[1].equalsIgnoreCase("colorless")) {
col = CardRules.Predicates.Presets.IS_COLORLESS;
} else if (temp[1].equalsIgnoreCase("green")) {
col = CardRules.Predicates.Presets.IS_GREEN;
} else if (temp[1].equalsIgnoreCase("multicolor")) {
col = CardRules.Predicates.Presets.IS_MULTICOLOR;
} else if (temp[1].equalsIgnoreCase("red")) {
col = CardRules.Predicates.Presets.IS_RED;
} else if (temp[1].equalsIgnoreCase("white")) {
col = CardRules.Predicates.Presets.IS_WHITE;
}
return filter.first(in, CardPrinted.FN_GET_RULES);
return BoosterUtils.generateDistinctCards(Predicate.and(rar, col, CardPrinted.FN_GET_RULES), qty);
}
}

View File

@@ -32,6 +32,7 @@ import forge.deck.Deck;
import forge.deck.io.DeckSerializer;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.quest.BoosterUtils;
import forge.quest.data.QuestPreferences.QPref;
import forge.util.FileUtil;
import forge.util.SectionUtil;
@@ -186,7 +187,7 @@ public class QuestEventManager {
qc.setCreditsReward(Integer.parseInt(value));
} else if (key.equalsIgnoreCase("Card Reward")) {
qc.setCardReward(value);
qc.setCardRewardList(QuestUtil.generateCardRewardList(value));
qc.setCardRewardList(BoosterUtils.generateCardRewardList(value));
}
// Human extra card list assembled here.
else if (key.equalsIgnoreCase("HumanExtras") && !value.equals("")) {
@@ -213,7 +214,7 @@ public class QuestEventManager {
// Card reward list assembled here.
else if (key.equalsIgnoreCase("Card Reward")) {
qc.setCardReward(value);
qc.setCardRewardList(QuestUtil.generateCardRewardList(value));
qc.setCardRewardList(BoosterUtils.generateCardRewardList(value));
}
}
return qc;

View File

@@ -23,11 +23,7 @@ import forge.AllZone;
import forge.Card;
import forge.CardList;
import forge.CardUtil;
import forge.Constant;
import forge.Player;
import forge.card.CardRarity;
import forge.item.CardPrinted;
import forge.quest.BoosterUtils;
/**
* <p>
@@ -161,47 +157,6 @@ public class QuestUtil {
return c;
}
/**
* <p>
* generateCardRewardList.
* </p>
* Takes a reward list string, parses, and returns list of cards rewarded.
*
* @param s
* Properties string of reward (97 multicolor rares)
* @return CardList
*/
public static List<CardPrinted> generateCardRewardList(final String s) {
final String[] temp = s.split(" ");
final int qty = Integer.parseInt(temp[0]);
// Determine rarity
CardRarity rar = CardRarity.Uncommon;
if (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")) {
rar = CardRarity.Rare;
}
// Determine color ("random" defaults to null color)
String col = null;
if (temp[1].equalsIgnoreCase("black")) {
col = Constant.Color.BLACK;
} else if (temp[1].equalsIgnoreCase("blue")) {
col = Constant.Color.BLUE;
} else if (temp[1].equalsIgnoreCase("colorless")) {
col = Constant.Color.COLORLESS;
} else if (temp[1].equalsIgnoreCase("green")) {
col = Constant.Color.GREEN;
} else if (temp[1].equalsIgnoreCase("multicolor")) {
col = "Multicolor"; // Note: No constant color for this??
} else if (temp[1].equalsIgnoreCase("red")) {
col = Constant.Color.RED;
} else if (temp[1].equalsIgnoreCase("white")) {
col = Constant.Color.WHITE;
}
return BoosterUtils.generateCards(qty, rar, col);
}
/**
* <p>
* readExtraCard.

View File

@@ -25,7 +25,6 @@ import net.slightlymagic.braids.util.lambda.Lambda1;
import net.slightlymagic.maxmtg.Predicate;
import forge.Singletons;
import forge.card.BoosterGenerator;
import forge.card.CardRarity;
import forge.card.CardEdition;
import forge.card.FormatUtils;
import forge.deck.Deck;
@@ -104,9 +103,9 @@ public final class QuestUtilCards {
final int nRare = this.qpref.getPreferenceInt(QPref.BOOSTER_RARES);
final ArrayList<CardPrinted> newCards = new ArrayList<CardPrinted>();
newCards.addAll(BoosterUtils.generateCards(fSets, nCommon, CardRarity.Common, null));
newCards.addAll(BoosterUtils.generateCards(fSets, nUncommon, CardRarity.Uncommon, null));
newCards.addAll(BoosterUtils.generateCards(fSets, nRare, CardRarity.Rare, null));
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_COMMON), nCommon));
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_UNCOMMON), nUncommon));
newCards.addAll(BoosterUtils.generateDistinctCards(Predicate.and(fSets, CardPrinted.Predicates.Presets.IS_RARE_OR_MYTHIC), nRare));
this.addAllCards(newCards);
return newCards;

View File

@@ -26,9 +26,7 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import net.miginfocom.swing.MigLayout;
import forge.AllZone;
import forge.Card;
import forge.CardUtil;
import forge.gui.game.CardDetailPanel;
import forge.gui.game.CardPicturePanel;
import forge.item.CardPrinted;
@@ -119,10 +117,7 @@ public class QuestWinLoseCardViewer extends FPanel {
this.cache = new Card[QuestWinLoseCardViewer.this.list.size()];
}
if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card;
this.cache[row] = cp.toForgeCard();
}
}
}

View File

@@ -27,9 +27,7 @@ import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.AllZone;
import forge.Card;
import forge.CardUtil;
import forge.gui.game.CardDetailPanel;
import forge.gui.game.CardPicturePanel;
import forge.item.CardPrinted;
@@ -108,10 +106,7 @@ public class CardViewer extends JPanel {
this.cache = new Card[CardViewer.this.list.size()];
}
if (null == this.cache[row]) {
final Card card = AllZone.getCardFactory().getCard(cp.getName(), null);
card.setCurSetCode(cp.getEdition());
card.setImageFilename(CardUtil.buildFilename(card));
this.cache[row] = card;
this.cache[row] = cp.toForgeCard();
}
}
}