more resilent quest loader - handles situations like 'I took quest save from my friend who has all duel decks added to setdata.txt, and this quest fails to load on my machine dues to missing cards'

This commit is contained in:
Maxmtg
2013-05-15 04:03:09 +00:00
parent f549dbe189
commit 77e9ebc456
2 changed files with 10 additions and 5 deletions

View File

@@ -150,14 +150,18 @@ public final class CardDb {
}
public CardPrinted tryGetCard(final String cardName, String setName) {
return tryGetCard(cardName, setName, 0);
}
public CardPrinted tryGetCard(final String cardName, String setName, int index) {
// Set exists?
final Map<String, CardPrinted[]> cardsFromset = this.allCardsBySet.get(setName.toUpperCase());
final Map<String, CardPrinted[]> cardsFromset = this.allCardsBySet.get(setName);
if (cardsFromset == null) {
return null;
}
// Card exists?
final CardPrinted[] cardCopies = cardsFromset.get(cardName.toLowerCase());
return cardCopies != null ? cardCopies[0] : null;
final CardPrinted[] cardCopies = cardsFromset.get(cardName);
return cardCopies != null && index < cardCopies.length ? cardCopies[index] : null;
}
// Single fetch

View File

@@ -669,8 +669,9 @@ public class QuestDataIO {
final String sIndex = reader.getAttribute("i");
final short index = StringUtils.isNumeric(sIndex) ? Short.parseShort(sIndex) : 0;
final boolean foil = "1".equals(reader.getAttribute("foil"));
final CardPrinted card = CardDb.instance().getCard(name, set, index);
return foil ? CardPrinted.makeFoiled(card) : card;
CardPrinted c = CardDb.instance().tryGetCard(name, set, index);
if ( null == c ) c = CardDb.instance().getCard(name);
return foil ? CardPrinted.makeFoiled(c) : c;
}
}
}