Forge will no longer crash when there are decks with unsupported cards. These cards will appear in decks and games player starts as a dummy without cost, types, abilities, but with explanation in card's text

This commit is contained in:
Maxmtg
2014-02-01 21:43:42 +00:00
parent c3d7a9f075
commit 691c52fff9
5 changed files with 35 additions and 10 deletions

View File

@@ -490,4 +490,17 @@ public final class CardRules implements ICardCharacteristics {
} // unsuported
}
}
public static CardRules getUnsupportedCardNamed(String name) {
CardAiHints cah = new CardAiHints(true, true, null, null);
CardFace[] faces = { new CardFace(name), null};
faces[0].setColor(ColorSet.fromMask(0));
faces[0].setType(CardType.parse(""));
faces[0].setOracleText("This card is not supported by Forge. Whenever you start a game with this card, it will be bugged.");
faces[0].setNonAbilityText("This card is not supported by Forge.\nWhenever you start a game with this card, it will be bugged.");
faces[0].assignMissingFields();
final CardRules result = new CardRules(faces, CardSplitType.None, cah);
return result;
}
}

View File

@@ -64,14 +64,16 @@ public class CardPool extends ItemPool<PaperCard> {
cp = StaticData.instance().getVariantCards().getCard(cardName, setCode);
}
if (cp == null )
throw new RuntimeException(String.format("Card %s from %s is not supported by Forge, as it's neither a known common card nor one of casual variants' card.", cardName, setCode ));
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length()-1)) && cardName.charAt(cardName.length()-2) == CardDb.NameSetSeparator;
setCode = cp.getEdition();
cardName = cp.getName();
int artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
boolean artIndexExplicitlySet = artIndex > 0 || Character.isDigit(cardName.charAt(cardName.length()-1)) && cardName.charAt(cardName.length()-2) == CardDb.NameSetSeparator;
int artCount = 1;
if (cp != null ) {
setCode = cp.getEdition();
cardName = cp.getName();
artCount = isCommonCard ? StaticData.instance().getCommonCards().getArtCount(cardName, setCode) : 1;
}
else
cp = PaperCard.createUnsuportedCard(cardName);
if (artIndexExplicitlySet || artCount <= 1) {
// either a specific art index is specified, or there is only one art, so just add the card

View File

@@ -249,6 +249,8 @@ public class Deck extends DeckBase implements Iterable<Entry<DeckSection, CardPo
if( c == null)
c = StaticData.instance().getCommonCards().getCardFromEdition(cardName, dayAfterNewestSetRelease, SetPreference.Latest, -1);
// this is to randomize art of all those cards
if( c == null ) // I give up!
c = cp.getKey();
newPool.add(cardName, c.getEdition(), cp.getValue());
} else
newPool.add(c, cp.getValue());

View File

@@ -19,6 +19,7 @@ package forge.item;
import com.google.common.base.Function;
import forge.card.CardEdition;
import forge.card.CardRarity;
import forge.card.CardRules;
@@ -190,4 +191,8 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
return Integer.compare(artIndex, o.getArtIndex());
}
public static PaperCard createUnsuportedCard(String cardName) {
return new PaperCard(CardRules.getUnsupportedCardNamed(cardName), CardEdition.UNKNOWN.getCode(), CardRarity.Unknown, 1);
}
}