forked from External/mage
149 lines
4.7 KiB
Java
149 lines
4.7 KiB
Java
package mage.cards.mock;
|
|
|
|
import java.util.List;
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import mage.MageInt;
|
|
import mage.abilities.Ability;
|
|
import mage.abilities.costs.mana.ManaCost;
|
|
import mage.abilities.costs.mana.ManaCosts;
|
|
import mage.abilities.costs.mana.ManaCostsImpl;
|
|
import mage.cards.CardImpl;
|
|
import mage.cards.repository.CardInfo;
|
|
import mage.cards.repository.CardRepository;
|
|
|
|
/**
|
|
* Mock card for GUI (deck editor and panels)
|
|
*
|
|
* @author North
|
|
*/
|
|
public class MockCard extends CardImpl {
|
|
|
|
static public String ADVENTURE_NAME_SEPARATOR = " // ";
|
|
|
|
// Needs to be here, as it is normally calculated from the
|
|
// PlaneswalkerEntersWithLoyaltyAbility of the card... but the MockCard
|
|
// only has MockAbilities.
|
|
private int startingLoyalty;
|
|
|
|
// mana cost extra info for multiple mana drawing
|
|
protected ManaCosts<ManaCost> manaCostLeft;
|
|
protected ManaCosts<ManaCost> manaCostRight;
|
|
protected String adventureSpellName;
|
|
|
|
public MockCard(CardInfo card) {
|
|
super(null, card.getName());
|
|
this.cardNumber = card.getCardNumber();
|
|
this.expansionSetCode = card.getSetCode();
|
|
this.power = mageIntFromString(card.getPower());
|
|
this.toughness = mageIntFromString(card.getToughness());
|
|
this.rarity = card.getRarity();
|
|
this.cardType = card.getTypes();
|
|
this.subtype = card.getSubTypes();
|
|
this.supertype = card.getSupertypes();
|
|
|
|
this.usesVariousArt = card.usesVariousArt();
|
|
|
|
this.manaCostLeft = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.LEFT)));
|
|
this.manaCostRight = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.RIGHT)));
|
|
this.manaCost = new ManaCostsImpl(join(card.getManaCosts(CardInfo.ManaCostSide.ALL)));
|
|
|
|
this.color = card.getColor();
|
|
|
|
this.frameColor = card.getFrameColor();
|
|
this.frameStyle = card.getFrameStyle();
|
|
|
|
this.splitCard = card.isSplitCard();
|
|
this.flipCard = card.isFlipCard();
|
|
|
|
this.transformable = card.isDoubleFaced();
|
|
this.nightCard = card.isNightCard();
|
|
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
|
|
this.secondSideCard = new MockCard(CardRepository.instance.findCardWPreferredSet(card.getSecondSideName(), card.getSetCode(), false));
|
|
}
|
|
|
|
if (card.isAdventureCard()) {
|
|
this.adventureSpellName = card.getAdventureSpellName();
|
|
}
|
|
|
|
if (this.isPlaneswalker()) {
|
|
String startingLoyaltyString = card.getStartingLoyalty();
|
|
if (startingLoyaltyString.isEmpty()) {
|
|
//Logger.getLogger(MockCard.class).warn("Planeswalker `" + this.name + "` has empty starting loyalty.");
|
|
} else {
|
|
try {
|
|
this.startingLoyalty = Integer.parseInt(startingLoyaltyString);
|
|
} catch (NumberFormatException e) {
|
|
Logger.getLogger(MockCard.class).warn("Planeswalker `" + this.name + "` starting loyalty in bad format: `" + startingLoyaltyString + "`.");
|
|
}
|
|
}
|
|
}
|
|
|
|
this.flipCardName = card.getFlipCardName();
|
|
for (String ruleText : card.getRules()) {
|
|
this.addAbility(textAbilityFromString(ruleText));
|
|
}
|
|
}
|
|
|
|
public MockCard(final MockCard card) {
|
|
super(card);
|
|
}
|
|
|
|
@Override
|
|
public int getStartingLoyalty() {
|
|
return startingLoyalty;
|
|
}
|
|
|
|
@Override
|
|
public MockCard copy() {
|
|
return new MockCard(this);
|
|
}
|
|
|
|
@Override
|
|
public ManaCosts<ManaCost> getManaCost() {
|
|
return manaCost;
|
|
}
|
|
|
|
public ManaCosts<ManaCost> getManaCost(CardInfo.ManaCostSide manaCostSide) {
|
|
switch (manaCostSide) {
|
|
case LEFT:
|
|
return manaCostLeft;
|
|
case RIGHT:
|
|
return manaCostRight;
|
|
default:
|
|
case ALL:
|
|
return manaCost;
|
|
}
|
|
}
|
|
|
|
public String getFullName(boolean showSecondName) {
|
|
if (adventureSpellName != null) {
|
|
return getName() + ADVENTURE_NAME_SEPARATOR + adventureSpellName;
|
|
} else {
|
|
return getName();
|
|
}
|
|
}
|
|
|
|
|
|
private MageInt mageIntFromString(String value) {
|
|
try {
|
|
int intValue = Integer.parseInt(value);
|
|
return new MageInt(intValue);
|
|
} catch (NumberFormatException e) {
|
|
return new MageInt(0, value);
|
|
}
|
|
}
|
|
|
|
private 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);
|
|
}
|
|
}
|