mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- 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:
@@ -44,6 +44,7 @@ import forge.util.Aggregates;
|
||||
import forge.util.CollectionSuppliers;
|
||||
import forge.util.Lang;
|
||||
import forge.util.MyRandom;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class CardDb implements ICardDatabase {
|
||||
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() ?
|
||||
final int pipePos = cardName.indexOf('|');
|
||||
String[] cardNameElems = cardName.split("\\|");
|
||||
|
||||
if (pipePos >= 0) {
|
||||
final String setName = cardName.substring(pipePos + 1).trim();
|
||||
cardName = cardName.substring(0, pipePos);
|
||||
// only if set is not blank try to load it
|
||||
if (StringUtils.isNotBlank(setName) && !"???".equals(setName)) {
|
||||
return new ImmutablePair<String, String>(cardName, setName);
|
||||
final String actualCardName = cardNameElems[0];
|
||||
String setName = null;
|
||||
String artIndex = "-1";
|
||||
if (cardNameElems.length > 1) {
|
||||
if (StringUtils.isNotBlank(cardNameElems[1]) && !"???".equals(cardNameElems[1])) {
|
||||
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) {
|
||||
@@ -163,11 +168,12 @@ public final class CardDb implements ICardDatabase {
|
||||
final boolean isFoil = this.isFoil(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;
|
||||
}
|
||||
|
||||
@@ -175,13 +181,13 @@ public final class CardDb implements ICardDatabase {
|
||||
public PaperCard tryGetCardPrintedByDate(final String name0, final boolean fromLatestSet, final Date printedBefore) {
|
||||
final boolean isFoil = this.isFoil(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;
|
||||
if (null != nameWithSet.right) // set explicitly requested, should return card from it and disregard the date
|
||||
res = tryGetCard(nameWithSet.left, nameWithSet.right);
|
||||
if (null != splitName.get(1)) // set explicitly requested, should return card from it and disregard the date
|
||||
res = tryGetCard(splitName.get(0), splitName.get(1), Integer.parseInt(splitName.get(2)));
|
||||
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;
|
||||
for (PaperCard card : cards) {
|
||||
if (editions.get(card.getEdition()).getDate().after(printedBefore))
|
||||
|
||||
@@ -228,6 +228,7 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
|
||||
|
||||
if (!hasBadSetInfo) {
|
||||
sb.append("|").append(card.getEdition());
|
||||
sb.append("|").append(card.getArtIndex());
|
||||
}
|
||||
if(card.isFoil()) {
|
||||
sb.append(CardDb.foilSuffix);
|
||||
|
||||
@@ -178,7 +178,9 @@ public abstract class DeckGeneratorBase {
|
||||
PaperCard cp = cardDb.getCard(basicLandName);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,14 +242,7 @@ public class Match {
|
||||
for (final Entry<PaperCard, Integer> stackOfCards : section) {
|
||||
final PaperCard cp = stackOfCards.getKey();
|
||||
for (int i = 0; i < stackOfCards.getValue(); i++) {
|
||||
|
||||
// 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);
|
||||
final Card card = Card.fromPaperCard(cp, player);
|
||||
|
||||
// Assign card-specific foiling or random foiling on approximately 1:20 cards if enabled
|
||||
if (cp.isFoil() || (canRandomFoil && MyRandom.percentTrue(5))) {
|
||||
|
||||
Reference in New Issue
Block a user