CardDb & CardRules & Card & CardFactory: use MeldPair to get the Backside from the Secondary

if CardFactory use StaticData to get the other card
This commit is contained in:
Hanmac
2016-07-24 07:14:51 +00:00
parent e447aa87b4
commit 86d9d2e5f7
4 changed files with 36 additions and 3 deletions

View File

@@ -177,8 +177,10 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
if (paperCard.getRules().getSplitType() == CardSplitType.None) { return; }
//allow looking up card by the name of other faces
allCardsByName.put(paperCard.getRules().getOtherPart().getName(), paperCard);
if (paperCard.getRules().getOtherPart() != null) {
//allow looking up card by the name of other faces
allCardsByName.put(paperCard.getRules().getOtherPart().getName(), paperCard);
}
if (paperCard.getRules().getSplitType() == CardSplitType.Split) {
//also include main part for split cards
allCardsByName.put(paperCard.getRules().getMainPart().getName(), paperCard);
@@ -218,6 +220,15 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
return false;
}
public CardRules getRules(String cardname) {
CardRules result = rulesByName.get(cardname);
if (result != null) {
return result;
} else {
return CardRules.getUnsupportedCardNamed(cardname);
}
}
@Override
public PaperCard getCard(String cardName) {
CardRequest request = CardRequest.fromString(cardName);

View File

@@ -38,12 +38,14 @@ public final class CardRules implements ICardCharacteristics {
private ICardFace otherPart;
private CardAiHints aiHints;
private ColorSet colorIdentity;
private String meldWith;
private CardRules(ICardFace[] faces, CardSplitType altMode, CardAiHints cah) {
splitType = altMode;
mainPart = faces[0];
otherPart = faces[1];
aiHints = cah;
meldWith = "";
//calculate color identity
byte colMask = calculateColorIdentity(mainPart);
@@ -63,6 +65,7 @@ public final class CardRules implements ICardCharacteristics {
otherPart = newRules.otherPart;
aiHints = newRules.aiHints;
colorIdentity = newRules.colorIdentity;
meldWith = newRules.meldWith;
}
private static byte calculateColorIdentity(final ICardFace face) {
@@ -195,6 +198,10 @@ public final class CardRules implements ICardCharacteristics {
return mainPart.getOracleText().contains("can be your commander");
}
public String getMeldWith() {
return meldWith;
}
// public Set<String> getSets() { return this.setsPrinted.keySet(); }
// public CardInSet getEditionInfo(final String setCode) {
// final CardInSet result = this.setsPrinted.get(setCode);
@@ -242,6 +249,7 @@ public final class CardRules implements ICardCharacteristics {
private String[] pictureUrl = new String[] { null, null };
private int curFace = 0;
private CardSplitType altMode = CardSplitType.None;
private String meldWith = "";
private String handLife = null;
// fields to build CardAiHints
@@ -281,6 +289,7 @@ public final class CardRules implements ICardCharacteristics {
faces[0].assignMissingFields();
if (null != faces[1]) faces[1].assignMissingFields();
final CardRules result = new CardRules(faces, altMode, cah);
result.meldWith = this.meldWith;
result.setDlUrls(pictureUrl);
if (StringUtils.isNotBlank(handLife))
result.setVanguardProperties(handLife);
@@ -362,6 +371,8 @@ public final class CardRules implements ICardCharacteristics {
if ("ManaCost".equals(key)) {
this.faces[this.curFace].setManaCost("no cost".equals(value) ? ManaCost.NO_COST
: new ManaCost(new ManaCostParser(value)));
} else if ("MeldPair".equals(key)) {
this.meldWith = value;
}
break;

View File

@@ -324,6 +324,9 @@ public class Card extends GameEntity implements Comparable<Card> {
else if (isDoubleFaced() && currentStateName != CardStateName.Transformed) {
return states.get(CardStateName.Transformed);
}
else if (this.isMeldable() && currentStateName != CardStateName.Meld) {
return states.get(CardStateName.Meld);
}
else {
return states.get(CardStateName.Original);
}
@@ -6623,6 +6626,8 @@ public class Card extends GameEntity implements Comparable<Card> {
}
public boolean isCommander() {
if (this.getMeldedWith() != null && this.getMeldedWith().isCommander())
return true;
return isCommander;
}
public void setCommander(boolean b) {

View File

@@ -18,7 +18,9 @@
package forge.game.card;
import forge.ImageKeys;
import forge.StaticData;
import forge.card.CardStateName;
import forge.card.CardDb;
import forge.card.CardRules;
import forge.card.CardSplitType;
import forge.card.CardType;
@@ -423,7 +425,11 @@ public class CardFactory {
if (st != CardSplitType.None) {
card.addAlternateState(st.getChangedStateName(), false);
card.setState(st.getChangedStateName(), false);
readCardFace(card, rules.getOtherPart());
if (rules.getOtherPart() != null) {
readCardFace(card, rules.getOtherPart());
} else if (!rules.getMeldWith().isEmpty()) {
readCardFace(card, StaticData.instance().getCommonCards().getRules(rules.getMeldWith()).getOtherPart());
}
}
if (card.isInAlternateState()) {