Added MockSplitCard

This commit is contained in:
North 2013-06-26 22:28:33 +03:00
parent d819053930
commit 8287cbaaf0
4 changed files with 111 additions and 3 deletions

View file

@ -0,0 +1,97 @@
package mage.cards;
import java.util.List;
import mage.MageInt;
import mage.abilities.Ability;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.CardType;
/**
*
* @author North
*/
public class MockSplitCard extends SplitCard<MockSplitCard> {
public MockSplitCard(CardInfo card) {
super(null,
card.getCardNumber(),
getLeftHalfName(card),
getRightHalfName(card),
card.getRarity(),
card.getTypes().toArray(new CardType[0]),
join(card.getManaCosts()),
"",
join(card.getRules()).contains("Fuse"));
this.expansionSetCode = card.getSetCode();
this.power = mageIntFromString(card.getPower());
this.toughness = mageIntFromString(card.getToughness());
this.cardType = card.getTypes();
this.subtype = card.getSubTypes();
this.supertype = card.getSupertypes();
this.color = card.getColor();
this.splitCard = card.isSplitCard();
this.flipCard = card.isFlipCard();
this.canTransform = card.isDoubleFaced();
this.nightCard = card.isNightCard();
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
this.secondSideCard = new MockCard(CardRepository.instance.findCard(card.getSecondSideName()));
}
this.flipCardName = card.getFlipCardName();
for (String ruleText : card.getRules()) {
this.addAbility(textAbilityFromString(ruleText));
}
CardInfo leftHalf = CardRepository.instance.findCard(getLeftHalfName(card));
if(leftHalf != null) {
this.leftHalfCard = new MockCard(leftHalf);
}
CardInfo rightHalf = CardRepository.instance.findCard(getRightHalfName(card));
if(rightHalf != null) {
this.rightHalfCard = new MockCard(rightHalf);
}
}
public MockSplitCard(final MockSplitCard card) {
super(card);
}
@Override
public MockSplitCard copy() {
return new MockSplitCard(this);
}
private MageInt mageIntFromString(String value) {
try {
int intValue = Integer.parseInt(value);
return new MageInt(intValue);
} catch (NumberFormatException e) {
return new MageInt(0, value);
}
}
private static String join(List<String> strings) {
StringBuilder sb = new StringBuilder();
for (String string : strings) {
sb.append(string);
}
return sb.toString();
}
private Ability textAbilityFromString(final String text) {
return new MockAbility(text);
}
private static String getLeftHalfName(CardInfo card) {
return card.getName().split(" // ")[0];
}
private static String getRightHalfName(CardInfo card) {
return card.getName().split(" // ")[1];
}
}

View file

@ -50,8 +50,8 @@ import mage.watchers.Watcher;
public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
private Card leftHalfCard;
private Card rightHalfCard;
protected Card leftHalfCard;
protected Card rightHalfCard;
public SplitCard(UUID ownerId, int cardNumber, String nameLeft, String nameRight, Rarity rarity, CardType[] cardTypes, String costsLeft, String costsRight, boolean fused) {
super(ownerId, cardNumber, new StringBuilder(nameLeft).append(" // ").append(nameRight).toString(), rarity, cardTypes, costsLeft + costsRight, (fused ?SpellAbilityType.SPLIT_FUSED:SpellAbilityType.SPLIT));

View file

@ -41,6 +41,7 @@ import mage.constants.Rarity;
import mage.ObjectColor;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.MockSplitCard;
/**
*
@ -141,7 +142,11 @@ public class CardInfo {
}
public Card getMockCard() {
return new MockCard(this);
if (this.splitCard) {
return new MockSplitCard(this);
} else {
return new MockCard(this);
}
}
public ObjectColor getColor() {

View file

@ -33,6 +33,7 @@ import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
import mage.cards.SplitCard;
import mage.util.ClassScanner;
/**
@ -61,6 +62,11 @@ public class CardScanner {
Card card = CardImpl.createCard(c);
if (card != null) {
cardsToAdd.add(new CardInfo(card));
if (card instanceof SplitCard) {
SplitCard splitCard = (SplitCard) card;
cardsToAdd.add(new CardInfo(splitCard.getLeftHalfCard()));
cardsToAdd.add(new CardInfo(splitCard.getRightHalfCard()));
}
}
}
}