Working Card Rendering

This commit is contained in:
Mark Langen 2016-08-31 04:43:28 -06:00
parent eeaea4c566
commit d5415d2d04
63 changed files with 17729 additions and 1769 deletions

View file

@ -35,6 +35,8 @@ public interface MageObject extends MageItem, Serializable {
boolean hasAbility(UUID abilityId, Game game);
ObjectColor getColor(Game game);
ObjectColor getFrameColor(Game game);
ManaCosts<ManaCost> getManaCost();
@ -43,6 +45,10 @@ public interface MageObject extends MageItem, Serializable {
MageInt getPower();
MageInt getToughness();
int getStartingLoyalty();
void adjustCosts(Ability ability, Game game);

View file

@ -33,6 +33,7 @@ import java.util.UUID;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
import mage.abilities.common.PlanswalkerEntersWithLoyalityCountersAbility;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
@ -49,6 +50,7 @@ public abstract class MageObjectImpl implements MageObject {
protected String name;
protected ManaCosts<ManaCost> manaCost;
protected ObjectColor color;
protected ObjectColor frameColor;
protected List<CardType> cardType = new ArrayList<>();
protected List<String> subtype = new ArrayList<>();
protected List<String> supertype = new ArrayList<>();
@ -67,6 +69,7 @@ public abstract class MageObjectImpl implements MageObject {
power = new MageInt(0);
toughness = new MageInt(0);
color = new ObjectColor();
frameColor = new ObjectColor();
manaCost = new ManaCostsImpl<>("");
abilities = new AbilitiesImpl<>();
}
@ -77,6 +80,7 @@ public abstract class MageObjectImpl implements MageObject {
manaCost = object.manaCost.copy();
text = object.text;
color = object.color.copy();
frameColor = object.frameColor.copy();
power = object.power.copy();
toughness = object.toughness.copy();
abilities = object.abilities.copy();
@ -154,11 +158,26 @@ public abstract class MageObjectImpl implements MageObject {
public MageInt getToughness() {
return toughness;
}
@Override
public int getStartingLoyalty() {
for (Ability ab: getAbilities()) {
if (ab instanceof PlanswalkerEntersWithLoyalityCountersAbility) {
return ((PlanswalkerEntersWithLoyalityCountersAbility)ab).getStartingLoyalty();
}
}
return 0;
}
@Override
public ObjectColor getColor(Game game) {
return color;
}
@Override
public ObjectColor getFrameColor(Game game) {
return frameColor;
}
@Override
public ManaCosts<ManaCost> getManaCost() {

View file

@ -81,6 +81,22 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor>, Compara
red = color.red;
green = color.green;
}
/**
* Returns a new color which contains all of the colors of this ObjectColor
* in addition to all of the colors of the other ObjectColor.
* @param other The other ObjectColor to union with
* @return A new color which is the union of this and other
*/
public ObjectColor union(ObjectColor other) {
ObjectColor newColor = new ObjectColor();
newColor.white = white | other.white;
newColor.blue = blue | other.blue;
newColor.black = black | other.black;
newColor.red = red | other.red;
newColor.green = green | other.green;
return newColor;
}
public int getColorCount() {
int count = 0;

View file

@ -14,13 +14,21 @@ import mage.counters.CounterType;
*/
public class PlanswalkerEntersWithLoyalityCountersAbility extends EntersBattlefieldAbility {
public PlanswalkerEntersWithLoyalityCountersAbility(int loyality) {
super(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(loyality)));
private final int startingLoyalty;
public PlanswalkerEntersWithLoyalityCountersAbility(int loyalty) {
super(new AddCountersSourceEffect(CounterType.LOYALTY.createInstance(loyalty)));
startingLoyalty = loyalty;
setRuleVisible(false);
}
public PlanswalkerEntersWithLoyalityCountersAbility(final PlanswalkerEntersWithLoyalityCountersAbility ability) {
super(ability);
startingLoyalty = ability.startingLoyalty;
}
public int getStartingLoyalty() {
return startingLoyalty;
}
@Override

View file

@ -29,6 +29,7 @@
package mage.cards.basiclands;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.mana.GreenManaAbility;
/**
@ -43,6 +44,7 @@ public abstract class Forest extends BasicLand {
public Forest(UUID ownerId, String cardNumber) {
super(ownerId, cardNumber, "Forest", new GreenManaAbility());
this.frameColor = ObjectColor.GREEN;
}
public Forest(final Forest land) {

View file

@ -29,6 +29,7 @@
package mage.cards.basiclands;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.mana.BlueManaAbility;
/**
@ -43,6 +44,7 @@ public abstract class Island extends BasicLand {
public Island(UUID ownerId, String cardNumber) {
super(ownerId, cardNumber, "Island", new BlueManaAbility());
this.frameColor = ObjectColor.BLUE;
}
public Island(Island land) {

View file

@ -29,6 +29,7 @@
package mage.cards.basiclands;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.mana.RedManaAbility;
/**
@ -43,6 +44,7 @@ public abstract class Mountain extends BasicLand {
public Mountain(UUID ownerId, String cardNumber) {
super(ownerId, cardNumber, "Mountain", new RedManaAbility());
this.frameColor = ObjectColor.RED;
}
public Mountain(Mountain land) {

View file

@ -29,6 +29,7 @@
package mage.cards.basiclands;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.mana.WhiteManaAbility;
/**
@ -43,6 +44,7 @@ public abstract class Plains extends BasicLand {
public Plains(UUID ownerId, String cardNumber) {
super(ownerId, cardNumber, "Plains", new WhiteManaAbility());
this.frameColor = ObjectColor.WHITE;
}
public Plains(Plains land) {

View file

@ -29,6 +29,7 @@
package mage.cards.basiclands;
import java.util.UUID;
import mage.ObjectColor;
import mage.abilities.mana.BlackManaAbility;
/**
@ -43,6 +44,7 @@ public abstract class Swamp extends BasicLand {
public Swamp(UUID ownerId, String cardNumber) {
super(ownerId, cardNumber, "Swamp", new BlackManaAbility());
this.frameColor = ObjectColor.BLACK;
}
public Swamp(Swamp land) {

View file

@ -7,11 +7,18 @@ import mage.abilities.costs.mana.ManaCostsImpl;
import mage.cards.CardImpl;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.CardType;
import org.apache.log4j.Logger;
/**
* @author North
*/
public class MockCard extends CardImpl {
// Needs to be here, as it is normally calculated from the
// PlaneswalkerEntersWithLoyaltyAbility of the card... but the MockCard
// only has MockAbilities.
private int startingLoyalty;
public MockCard(CardInfo card) {
super(null, card.getName());
this.cardNumber = card.getCardNumber();
@ -28,6 +35,9 @@ public class MockCard extends CardImpl {
this.manaCost = new ManaCostsImpl(join(card.getManaCosts()));
this.color = card.getColor();
this.frameColor = card.getFrameColor();
this.splitCard = card.isSplitCard();
this.flipCard = card.isFlipCard();
@ -36,9 +46,21 @@ public class MockCard extends CardImpl {
if (card.getSecondSideName() != null && !card.getSecondSideName().isEmpty()) {
this.secondSideCard = new MockCard(CardRepository.instance.findCard(card.getSecondSideName()));
}
if (this.cardType.contains(CardType.PLANESWALKER)) {
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));
}
@ -47,6 +69,11 @@ public class MockCard extends CardImpl {
public MockCard(final MockCard card) {
super(card);
}
@Override
public int getStartingLoyalty() {
return startingLoyalty;
}
@Override
public MockCard copy() {

View file

@ -39,7 +39,10 @@ import java.util.List;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.PlanswalkerEntersWithLoyalityCountersAbility;
import mage.abilities.effects.PlaneswalkerRedirectionEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.mock.MockCard;
@ -70,6 +73,8 @@ public class CardInfo {
@DatabaseField
protected String toughness;
@DatabaseField
protected String startingLoyalty;
@DatabaseField
protected int convertedManaCost;
@DatabaseField(dataType = DataType.ENUM_STRING)
protected Rarity rarity;
@ -94,6 +99,8 @@ public class CardInfo {
@DatabaseField
protected boolean white;
@DatabaseField
protected String frameColor;
@DatabaseField
protected boolean splitCard;
@DatabaseField
protected boolean splitCardHalf;
@ -132,6 +139,7 @@ public class CardInfo {
this.secondSideName = secondSide.getName();
}
this.frameColor = card.getFrameColor(null).toString();
this.blue = card.getColor(null).isBlue();
this.black = card.getColor(null).isBlack();
this.green = card.getColor(null).isGreen();
@ -144,13 +152,13 @@ public class CardInfo {
this.setManaCosts(card.getManaCost().getSymbols());
int length = 0;
for (String rule :card.getRules()) {
for (String rule: card.getRules()) {
length += rule.length();
}
if (length > MAX_RULE_LENGTH) {
length = 0;
ArrayList<String> shortRules = new ArrayList<>();
for (String rule :card.getRules()) {
for (String rule: card.getRules()) {
if (length + rule.length() + 3 <= MAX_RULE_LENGTH) {
shortRules.add(rule);
length += rule.length() + 3;
@ -173,6 +181,21 @@ public class CardInfo {
this.splitCardHalf = true;
}
}
// Starting loyalty
if (card.getCardType().contains(CardType.PLANESWALKER)) {
for (Ability ab: card.getAbilities()) {
if (ab instanceof PlanswalkerEntersWithLoyalityCountersAbility) {
this.startingLoyalty = "" + ((PlanswalkerEntersWithLoyalityCountersAbility) ab).getStartingLoyalty();
}
}
if (this.startingLoyalty == null) {
Logger.getLogger(CardInfo.class).warn("Planeswalker `" + card.getName() + "` missing starting loyalty");
this.startingLoyalty = "";
}
} else {
this.startingLoyalty = "";
}
}
public Card getCard() {
@ -200,6 +223,10 @@ public class CardInfo {
color.setWhite(white);
return color;
}
public ObjectColor getFrameColor() {
return new ObjectColor(frameColor);
}
private String joinList(List<String> items) {
StringBuilder sb = new StringBuilder();
@ -286,6 +313,10 @@ public class CardInfo {
public String getToughness() {
return toughness;
}
public String getStartingLoyalty() {
return startingLoyalty;
}
public String getSetCode() {
return setCode;

View file

@ -144,6 +144,11 @@ public class Commander implements CommandObject {
public ObjectColor getColor(Game game) {
return card.getColor(game);
}
@Override
public ObjectColor getFrameColor(Game game) {
return card.getFrameColor(game);
}
@Override
public ManaCosts<ManaCost> getManaCost() {
@ -164,6 +169,11 @@ public class Commander implements CommandObject {
public MageInt getToughness() {
return card.getToughness();
}
@Override
public int getStartingLoyalty() {
return card.getStartingLoyalty();
}
@Override
public void adjustCosts(Ability ability, Game game) {

View file

@ -153,6 +153,11 @@ public class Emblem implements CommandObject {
public ObjectColor getColor(Game game) {
return emptyColor;
}
@Override
public ObjectColor getFrameColor(Game game) {
return emptyColor;
}
@Override
public ManaCosts<ManaCost> getManaCost() {
@ -173,6 +178,11 @@ public class Emblem implements CommandObject {
public MageInt getToughness() {
return MageInt.EmptyMageInt;
}
@Override
public int getStartingLoyalty() {
return 0;
}
@Override
public void adjustCosts(Ability ability, Game game) {

View file

@ -75,6 +75,7 @@ public class Spell extends StackObjImpl implements Card {
private final Card card;
private final ObjectColor color;
private final ObjectColor frameColor;
private final SpellAbility ability;
private final Zone fromZone;
private final UUID id;
@ -87,6 +88,7 @@ public class Spell extends StackObjImpl implements Card {
public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) {
this.card = card;
this.color = card.getColor(null).copy();
this.frameColor = card.getFrameColor(null).copy();
id = ability.getId();
this.ability = ability;
this.ability.setControllerId(controllerId);
@ -127,6 +129,7 @@ public class Spell extends StackObjImpl implements Card {
this.copiedSpell = spell.copiedSpell;
this.faceDown = spell.faceDown;
this.color = spell.color.copy();
this.frameColor = spell.color.copy();
}
public boolean activate(Game game, boolean noMana) {
@ -482,6 +485,11 @@ public class Spell extends StackObjImpl implements Card {
public ObjectColor getColor(Game game) {
return color;
}
@Override
public ObjectColor getFrameColor(Game game) {
return frameColor;
}
@Override
public ManaCosts<ManaCost> getManaCost() {
@ -518,6 +526,11 @@ public class Spell extends StackObjImpl implements Card {
public MageInt getToughness() {
return card.getToughness();
}
@Override
public int getStartingLoyalty() {
return card.getStartingLoyalty();
}
@Override
public UUID getId() {

View file

@ -192,6 +192,11 @@ public class StackAbility extends StackObjImpl implements Ability {
public ObjectColor getColor(Game game) {
return emptyColor;
}
@Override
public ObjectColor getFrameColor(Game game) {
return ability.getSourceObject(game).getFrameColor(game);
}
@Override
public ManaCosts<ManaCost> getManaCost() {
@ -207,6 +212,11 @@ public class StackAbility extends StackObjImpl implements Ability {
public MageInt getToughness() {
return MageInt.EmptyMageInt;
}
@Override
public int getStartingLoyalty() {
return 0;
}
@Override
public Zone getZone() {