- Support distinction between cards with different card art indexes in the deck editors (the card index is now saved to .dck file and loaded from there if available).

- Remove a Singleton call from Match that was necessary to randomize card art (will be unsupported later and will not be necessary anyway once the true support is fully implemented).
- (WIP) Automatically randomize card art for cards that do not have the art index specified; for now only works for basic lands that were generated randomly (e.g. in random Constructed decks). Limited mode (sealed decks, draft decks, quest mode generated pool, quest mode spell shop) support for generating cards with different card art will hopefully follow soon.
This commit is contained in:
Agetian
2014-01-13 08:54:04 +00:00
parent fc7cc33111
commit 4837bb5740
4 changed files with 29 additions and 27 deletions

View File

@@ -44,6 +44,7 @@ import forge.util.Aggregates;
import forge.util.CollectionSuppliers; import forge.util.CollectionSuppliers;
import forge.util.Lang; import forge.util.Lang;
import forge.util.MyRandom; import forge.util.MyRandom;
import java.util.Arrays;
public final class CardDb implements ICardDatabase { public final class CardDb implements ICardDatabase {
public final static String foilSuffix = "+"; public final static String foilSuffix = "+";
@@ -118,21 +119,25 @@ public final class CardDb implements ICardDatabase {
} }
/** /**
* Splits cardname into Name and set whenever deck line reads as name|set. * Splits cardname into name, set and art index whenever deck line reads as name|set|artindex.
*/ */
private static ImmutablePair<String, String> splitCardName(final String name) { private static List<String> splitCardName(final String name) {
String cardName = name; // .trim() ? String cardName = name; // .trim() ?
final int pipePos = cardName.indexOf('|'); String[] cardNameElems = cardName.split("\\|");
if (pipePos >= 0) { final String actualCardName = cardNameElems[0];
final String setName = cardName.substring(pipePos + 1).trim(); String setName = null;
cardName = cardName.substring(0, pipePos); String artIndex = "-1";
// only if set is not blank try to load it if (cardNameElems.length > 1) {
if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) { if (StringUtils.isNotBlank(cardNameElems[1]) && !"???".equals(cardNameElems[1])) {
return new ImmutablePair<String, String>(cardName, setName); setName = cardNameElems[1];
}
if (cardNameElems.length > 2) {
artIndex = cardNameElems[2];
} }
} }
return new ImmutablePair<String, String>(cardName, null);
return Arrays.asList(actualCardName, setName, artIndex);
} }
private boolean isFoil(final String cardName) { private boolean isFoil(final String cardName) {
@@ -163,11 +168,12 @@ public final class CardDb implements ICardDatabase {
final boolean isFoil = this.isFoil(cardName0); final boolean isFoil = this.isFoil(cardName0);
final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0; final String cardName = isFoil ? this.removeFoilSuffix(cardName0) : cardName0;
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName); final List<String> splitName = CardDb.splitCardName(cardName);
final PaperCard res = splitName.get(1) == null
? ( fromLastSet ? this.uniqueCardsByName.get(splitName.get(0)) : tryGetCard(splitName.get(0), Aggregates.random(this.allCardsByName.get(splitName.get(0))).getEdition(), -1))
: tryGetCard(splitName.get(0), splitName.get(1), Integer.parseInt(splitName.get(2)));
final PaperCard res = nameWithSet.right == null
? ( fromLastSet ? this.uniqueCardsByName.get(nameWithSet.left) : Aggregates.random(this.allCardsByName.get(nameWithSet.left)) )
: tryGetCard(nameWithSet.left, nameWithSet.right);
return null != res && isFoil ? getFoiled(res) : res; return null != res && isFoil ? getFoiled(res) : res;
} }
@@ -175,13 +181,13 @@ public final class CardDb implements ICardDatabase {
public PaperCard tryGetCardPrintedByDate(final String name0, final boolean fromLatestSet, final Date printedBefore) { public PaperCard tryGetCardPrintedByDate(final String name0, final boolean fromLatestSet, final Date printedBefore) {
final boolean isFoil = this.isFoil(name0); final boolean isFoil = this.isFoil(name0);
final String cardName = isFoil ? this.removeFoilSuffix(name0) : name0; final String cardName = isFoil ? this.removeFoilSuffix(name0) : name0;
final ImmutablePair<String, String> nameWithSet = CardDb.splitCardName(cardName); final List<String> splitName = CardDb.splitCardName(cardName);
PaperCard res = null; PaperCard res = null;
if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date if (null != splitName.get(1)) // set explicitly requested, should return card from it and disregard the date
res = tryGetCard(nameWithSet.left, nameWithSet.right); res = tryGetCard(splitName.get(0), splitName.get(1), Integer.parseInt(splitName.get(2)));
else { else {
Collection<PaperCard> cards = this.allCardsByName.get(nameWithSet.left); // cards are sorted by datetime desc Collection<PaperCard> cards = this.allCardsByName.get(splitName.get(0)); // cards are sorted by datetime desc
int idxRightSet = 0; int idxRightSet = 0;
for (PaperCard card : cards) { for (PaperCard card : cards) {
if (editions.get(card.getEdition()).getDate().after(printedBefore)) if (editions.get(card.getEdition()).getDate().after(printedBefore))

View File

@@ -228,6 +228,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
if (!hasBadSetInfo) { if (!hasBadSetInfo) {
sb.append("|").append(card.getEdition()); sb.append("|").append(card.getEdition());
sb.append("|").append(card.getArtIndex());
} }
if(card.isFoil()) { if(card.isFoil()) {
sb.append(CardDb.foilSuffix); sb.append(CardDb.foilSuffix);

View File

@@ -178,7 +178,9 @@ public abstract class DeckGeneratorBase {
PaperCard cp = cardDb.getCard(basicLandName); PaperCard cp = cardDb.getCard(basicLandName);
String basicLandSet = cp.getEdition(); String basicLandSet = cp.getEdition();
tDeck.add(cardDb.getCard(cp.getName(), basicLandSet), nLand); for (int i=0; i < nLand; i++)
tDeck.add(cardDb.getCard(cp.getName(), basicLandSet, -1), 1);
landsLeft -= nLand; landsLeft -= nLand;
} }
} }

View File

@@ -242,14 +242,7 @@ public class Match {
for (final Entry<PaperCard, Integer> stackOfCards : section) { for (final Entry<PaperCard, Integer> stackOfCards : section) {
final PaperCard cp = stackOfCards.getKey(); final PaperCard cp = stackOfCards.getKey();
for (int i = 0; i < stackOfCards.getValue(); i++) { for (int i = 0; i < stackOfCards.getValue(); i++) {
final Card card = Card.fromPaperCard(cp, player);
// apply random art for cards with multiple pictures (basic lands, etc.) - currently always enabled
// TODO: implement true distinction between cards with different art (in deck editor, match, etc.)
PaperCard cpi = Singletons.getMagicDb().getCommonCards().getCard(cp.getName(), cp.getEdition(), -1);
if ( cp.isFoil() )
cpi = Singletons.getMagicDb().getCommonCards().getFoiled(cpi);
final Card card = cpi == null ? Card.fromPaperCard(cp, player) : Card.fromPaperCard(cpi, player);
// Assign card-specific foiling or random foiling on approximately 1:20 cards if enabled // Assign card-specific foiling or random foiling on approximately 1:20 cards if enabled
if (cp.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) { if (cp.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {