mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Added MockSplitCard
This commit is contained in:
parent
d819053930
commit
8287cbaaf0
4 changed files with 111 additions and 3 deletions
97
Mage/src/mage/cards/MockSplitCard.java
Normal file
97
Mage/src/mage/cards/MockSplitCard.java
Normal 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];
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue