added a method Card.isSplitCard() to shorten tests for split type.

This commit is contained in:
Maxmtg
2013-03-18 19:29:14 +00:00
parent 260f626ee1
commit 5bea8704c3
9 changed files with 31 additions and 35 deletions

View File

@@ -508,6 +508,10 @@ public class Card extends GameEntity implements Comparable<Card> {
return this.isFlipCard; return this.isFlipCard;
} }
public final boolean isSplitCard() {
return cardRules != null && cardRules.getSplitType() == CardSplitType.Split;
}
/** /**
* Sets the flip card. * Sets the flip card.
* *
@@ -7021,7 +7025,7 @@ public class Card extends GameEntity implements Comparable<Card> {
} else if (property.startsWith("greatestCMC")) { } else if (property.startsWith("greatestCMC")) {
final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES); final List<Card> list = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.CREATURES);
for (final Card crd : list) { for (final Card crd : list) {
if (crd.getRules() != null && crd.getRules().getSplitType() == CardSplitType.Split) { if (crd.isSplitCard()) {
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > this.getCMC()) { if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > this.getCMC()) {
return false; return false;
} }
@@ -7049,7 +7053,7 @@ public class Card extends GameEntity implements Comparable<Card> {
final List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield); final List<Card> list = Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield);
for (final Card crd : list) { for (final Card crd : list) {
if (!crd.isLand() && !crd.isImmutable()) { if (!crd.isLand() && !crd.isImmutable()) {
if (crd.getRules() != null && crd.getRules().getSplitType() == CardSplitType.Split) { if (crd.isSplitCard()) {
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) < this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) < this.getCMC()) { if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) < this.getCMC() || crd.getCMC(Card.SplitCMCMode.RightSplitCMC) < this.getCMC()) {
return false; return false;
} }
@@ -7119,7 +7123,7 @@ public class Card extends GameEntity implements Comparable<Card> {
y = this.getNetDefense(); y = this.getNetDefense();
} else if (property.startsWith("cmc")) { } else if (property.startsWith("cmc")) {
rhs = property.substring(5); rhs = property.substring(5);
if (getRules() != null && getRules().getSplitType() == CardSplitType.Split && getCurState() == CardCharacteristicName.Original) { if (isSplitCard() && getCurState() == CardCharacteristicName.Original) {
y = getState(CardCharacteristicName.LeftSplit).getManaCost().getCMC(); y = getState(CardCharacteristicName.LeftSplit).getManaCost().getCMC();
y2 = getState(CardCharacteristicName.RightSplit).getManaCost().getCMC(); y2 = getState(CardCharacteristicName.RightSplit).getManaCost().getCMC();
} else { } else {
@@ -9126,7 +9130,7 @@ public class Card extends GameEntity implements Comparable<Card> {
int requestedCMC = 0; int requestedCMC = 0;
if (getRules() != null && getRules().getSplitType() == CardSplitType.Split) { if (isSplitCard()) {
switch(mode) { switch(mode) {
case CurrentSideCMC: case CurrentSideCMC:
// TODO: test if this returns combined CMC for the full face (then get rid of CombinedCMC mode?) // TODO: test if this returns combined CMC for the full face (then get rid of CombinedCMC mode?)

View File

@@ -271,7 +271,7 @@ public class CardLists {
final List<Card> tiedForHighest = new ArrayList<Card>(); final List<Card> tiedForHighest = new ArrayList<Card>();
int highest = 0; int highest = 0;
for (final Card crd : cardList) { for (final Card crd : cardList) {
if (crd.getRules() != null && crd.getRules().getSplitType() == CardSplitType.Split) { if (crd.isSplitCard()) {
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > highest) { if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > highest) {
highest = crd.getCMC(Card.SplitCMCMode.LeftSplitCMC); highest = crd.getCMC(Card.SplitCMCMode.LeftSplitCMC);
tiedForHighest.clear(); tiedForHighest.clear();

View File

@@ -240,7 +240,7 @@ public class CardFactory {
c.setState(CardCharacteristicName.Transformed); c.setState(CardCharacteristicName.Transformed);
c.setImageKey(ImageCache.getImageKey(cp, true)); c.setImageKey(ImageCache.getImageKey(cp, true));
} }
else if (c.getRules().getSplitType() == CardSplitType.Split) { else if (c.isSplitCard()) {
c.setState(CardCharacteristicName.LeftSplit); c.setState(CardCharacteristicName.LeftSplit);
c.setImageKey(originalPicture); c.setImageKey(originalPicture);
c.setCurSetCode(cp.getEdition()); c.setCurSetCode(cp.getEdition());

View File

@@ -1421,7 +1421,7 @@ public class CardFactoryUtil {
} }
} }
for (final Card crd : list) { for (final Card crd : list) {
if (crd.getRules() != null && crd.getRules().getSplitType() == CardSplitType.Split) { if (crd.isSplitCard()) {
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > highest) { if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > highest) {
highest = crd.getCMC(Card.SplitCMCMode.LeftSplitCMC); highest = crd.getCMC(Card.SplitCMCMode.LeftSplitCMC);
} }

View File

@@ -153,10 +153,8 @@ public class SpellAbilityRequirements {
final Card c = this.ability.getSourceCard(); final Card c = this.ability.getSourceCard();
// split cards transform back to full form if targeting is canceled // split cards transform back to full form if targeting is canceled
if (c.getRules() != null) { if (c.isSplitCard()) {
if (c.getRules().getSplitType() == CardSplitType.Split) { c.setState(CardCharacteristicName.Original);
c.setState(CardCharacteristicName.Original);
}
} }
if (this.bCasting && !c.isCopiedSpell()) { // and not a copy if (this.bCasting && !c.isCopiedSpell()) { // and not a copy
@@ -206,10 +204,8 @@ public class SpellAbilityRequirements {
final Card c = this.ability.getSourceCard(); final Card c = this.ability.getSourceCard();
// split cards transform back to full form if mana cost is not paid // split cards transform back to full form if mana cost is not paid
if (c.getRules() != null) { if (c.isSplitCard()) {
if (c.getRules().getSplitType() == CardSplitType.Split) { c.setState(CardCharacteristicName.Original);
c.setState(CardCharacteristicName.Original);
}
} }
if (this.bCasting && !c.isCopiedSpell()) { // and not a copy if (this.bCasting && !c.isCopiedSpell()) { // and not a copy

View File

@@ -344,10 +344,8 @@ public class GameAction {
*/ */
public final Card moveTo(final Zone zoneTo, Card c) { public final Card moveTo(final Zone zoneTo, Card c) {
// if a split card is moved, convert it back to its full form before moving (unless moving to stack) // if a split card is moved, convert it back to its full form before moving (unless moving to stack)
if (c.getRules() != null) { if (c.isSplitCard() && zoneTo != game.getStackZone()) {
if ((c.getRules().getSplitType() == CardSplitType.Split) && (zoneTo != game.getStackZone())) { c.setState(CardCharacteristicName.Original);
c.setState(CardCharacteristicName.Original);
}
} }
return moveTo(zoneTo, c, null); return moveTo(zoneTo, c, null);

View File

@@ -541,21 +541,19 @@ public class GameActionPlay {
private void setSplitCardState(final Card source, SpellAbility sa) { private void setSplitCardState(final Card source, SpellAbility sa) {
// Split card support // Split card support
if (source.getRules() != null) { if (source.isSplitCard()) {
if (source.getRules().getSplitType() == CardSplitType.Split) { List<SpellAbility> leftSplitAbilities = source.getState(CardCharacteristicName.LeftSplit).getSpellAbility();
List<SpellAbility> leftSplitAbilities = source.getState(CardCharacteristicName.LeftSplit).getSpellAbility(); List<SpellAbility> rightSplitAbilities = source.getState(CardCharacteristicName.RightSplit).getSpellAbility();
List<SpellAbility> rightSplitAbilities = source.getState(CardCharacteristicName.RightSplit).getSpellAbility(); for (SpellAbility a : leftSplitAbilities) {
for (SpellAbility a : leftSplitAbilities) { if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) {
if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) { source.setState(CardCharacteristicName.LeftSplit);
source.setState(CardCharacteristicName.LeftSplit); break;
break;
}
} }
for (SpellAbility a : rightSplitAbilities) { }
if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) { for (SpellAbility a : rightSplitAbilities) {
source.setState(CardCharacteristicName.RightSplit); if (sa == a || sa.getDescription().equals(String.format("%s (without paying its mana cost)", a.getDescription()))) {
break; source.setState(CardCharacteristicName.RightSplit);
} break;
} }
} }
} }

View File

@@ -218,7 +218,7 @@ public class CardDetailPanel extends FPanel {
this.nameCostLabel.setText(card.getName()); this.nameCostLabel.setText(card.getName());
} else { } else {
String manaCost = card.getManaCost().toString(); String manaCost = card.getManaCost().toString();
if ( card.getRules() != null && card.getRules().getSplitType() == CardSplitType.Split && card.getCurState() == CardCharacteristicName.Original) { if ( card.isSplitCard() && card.getCurState() == CardCharacteristicName.Original) {
manaCost = card.getRules().getMainPart().getManaCost().toString() + " // " + card.getRules().getOtherPart().getManaCost().toString(); manaCost = card.getRules().getMainPart().getManaCost().toString() + " // " + card.getRules().getOtherPart().getManaCost().toString();
} }
this.nameCostLabel.setText(card.getName() + " - " + manaCost); this.nameCostLabel.setText(card.getName() + " - " + manaCost);

View File

@@ -377,7 +377,7 @@ public class CardPanel extends JPanel implements CardContainer {
if (this.showCastingCost) { if (this.showCastingCost) {
if (this.cardWidth < 200) { if (this.cardWidth < 200) {
Card gameCard = this.getGameCard(); Card gameCard = this.getGameCard();
boolean showSplitMana = gameCard.getRules() != null && gameCard.getRules().getSplitType() == CardSplitType.Split && gameCard.getCurState() == CardCharacteristicName.Original; boolean showSplitMana = gameCard.isSplitCard() && gameCard.getCurState() == CardCharacteristicName.Original;
if ( !showSplitMana ) { if ( !showSplitMana ) {
drawManaCost(g, gameCard.getManaCost(), 0); drawManaCost(g, gameCard.getManaCost(), 0);
} else { } else {