fix deck loading problem (wrong editions were shown)

This commit is contained in:
Maxmtg
2014-01-25 21:30:56 +00:00
parent dbf77d8548
commit dfebb08e1e
5 changed files with 26 additions and 15 deletions

View File

@@ -97,7 +97,7 @@ public final class CardDb implements ICardDatabase {
isFoil = true;
}
int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos]) : -1;
int artIndex = artPos > 0 ? Integer.parseInt(nameParts[artPos])-1 : -1;
String setName = setPos > 0 ? nameParts[setPos] : null;
if( "???".equals(setName) )
setName = null;
@@ -173,6 +173,7 @@ public final class CardDb implements ICardDatabase {
@Override
public PaperCard getCard(final String cardName, String setName) {
CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
request.edition = setName;
return tryGetCard(request);
}
@@ -180,7 +181,9 @@ public final class CardDb implements ICardDatabase {
@Override
public PaperCard getCard(final String cardName, String setName, int artIndex) {
CardRequest request = CardRequest.fromString(cardName);
if(setName != null)
request.edition = setName;
if(artIndex >= 0)
request.artIndex = artIndex;
return tryGetCard(request);
}
@@ -191,10 +194,17 @@ public final class CardDb implements ICardDatabase {
PaperCard result = null;
String reqEdition = request.edition;
if(reqEdition != null && !editions.contains(reqEdition)) {
CardEdition edition = editions.get(reqEdition);
if( edition != null )
reqEdition = edition.getCode();
}
if ( request.artIndex < 0 ) { // this stands for 'random art'
List<PaperCard> candidates = new ArrayList<PaperCard>(9); // 9 cards with same name per set is a maximum of what has been printed (Arnchenemy)
for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(request.edition) || request.edition == null )
if( pc.getEdition().equalsIgnoreCase(reqEdition) || reqEdition == null )
candidates.add(pc);
}
@@ -203,7 +213,7 @@ public final class CardDb implements ICardDatabase {
result = Aggregates.random(candidates);
} else {
for( PaperCard pc : cards ) {
if( pc.getEdition().equalsIgnoreCase(request.edition) && request.artIndex == pc.getArtIndex() ) {
if( pc.getEdition().equalsIgnoreCase(reqEdition) && request.artIndex == pc.getArtIndex() ) {
result = pc;
break;
}

View File

@@ -347,6 +347,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
public Iterable<CardEdition> getOrderedEditions() {
List<CardEdition> res = Lists.newArrayList(this);
Collections.sort(res);

View File

@@ -55,12 +55,12 @@ public class CardPool extends ItemPool<PaperCard> {
this.add(cardName, setCode, -1, amount);
}
// NOTE: ART indices are "1" -based
public void add(final String cardName, final String setCode, final int artIndex, final int amount) {
boolean isCommonCard = true;
PaperCard cp = StaticData.instance().getCommonCards().getCard(cardName, setCode, artIndex);
if ( cp == null ) {
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode, artIndex);
isCommonCard = false;
boolean isCommonCard = cp != null;
if ( !isCommonCard ) {
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
}
int artCount = isCommonCard
@@ -73,7 +73,7 @@ public class CardPool extends ItemPool<PaperCard> {
} else {
// random art index specified, make sure we get different groups of cards with different art
int[] artGroups = MyRandom.splitIntoRandomGroups(amount, artCount);
for (int i = 0; i < artGroups.length; i++) {
for (int i = 1; i <= artGroups.length; i++) {
PaperCard cp_random = isCommonCard ? StaticData.instance().getCommonCards().getCard(cardName, setCode, i) : StaticData.instance().getVariantCards().getCard(cardName, setCode, i);
this.add(cp_random, artGroups[i]);
}

View File

@@ -162,11 +162,11 @@ public class CEditorDraftingProcess extends ACEditorBase<PaperCard, DeckGroup> {
final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(landName, landSet);
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
for (int i = 0; i < numArt; i++) {
for (int i = 1; i <= numArt; i++) {
deck.get(DeckSection.Sideboard).add(landName, landSet, i, numArt > 1 ? landsCount : 30);
}
} else {
deck.get(DeckSection.Sideboard).add(landName, landSet, numArt > 1 ? MyRandom.getRandom().nextInt(numArt) : 0, 30);
deck.get(DeckSection.Sideboard).add(landName, landSet, 30);
}
}

View File

@@ -178,11 +178,11 @@ public enum CSubmenuSealed implements ICDoc {
final int numArt = Singletons.getMagicDb().getCommonCards().getArtCount(element, sd.getLandSetCode());
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) {
for (int i = 0; i < numArt; i++) {
for (int i = 1; i <= numArt; i++) {
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), i, numArt > 1 ? landsCount : 30);
}
} else {
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), numArt > 1 ? MyRandom.getRandom().nextInt(numArt) : 0, 30);
deck.get(DeckSection.Sideboard).add(element, sd.getLandSetCode(), 30);
}
}