Merge pull request #2216 from stravant/master

Full characteristic-based card rendering for cards
This commit is contained in:
LevelX2 2016-09-03 09:13:49 +02:00 committed by GitHub
commit cb91c5b9aa
70 changed files with 6154 additions and 1013 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,10 +33,12 @@ 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;
import mage.abilities.keyword.ChangelingAbility;
import mage.abilities.mana.ManaAbility;
import mage.constants.CardType;
import mage.game.Game;
import mage.util.CardUtil;
@ -49,6 +51,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 +70,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 +81,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 +159,67 @@ 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) {
// For lands, add any colors of mana the land can produce to
// its frame colors.
if (getCardType().contains(CardType.LAND)) {
ObjectColor cl = frameColor.copy();
for (Ability ab: getAbilities()) {
if (ab instanceof ManaAbility) {
ManaAbility mana = (ManaAbility)ab;
try {
List<Mana> manaAdded = mana.getNetMana(game);
for (Mana m: manaAdded) {
if (m.getAny() > 0) {
return new ObjectColor("WUBRG");
}
if (m.getWhite() > 0) {
cl.setWhite(true);
}
if (m.getBlue() > 0) {
cl.setBlue(true);
}
if (m.getBlack() > 0) {
cl.setBlack(true);
}
if (m.getRed() > 0) {
cl.setRed(true);
}
if (m.getGreen() > 0) {
cl.setGreen(true);
}
}
} catch (NullPointerException e) {
// Ability depends on game
// but no game passed
// All such abilities are 5-color ones
return new ObjectColor("WUBRG");
}
}
}
return cl;
} else {
// For everything else, just return the frame colors
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,9 @@ 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.cards.Card;
import mage.cards.CardImpl;
import mage.cards.mock.MockCard;
@ -70,6 +72,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 +98,8 @@ public class CardInfo {
@DatabaseField
protected boolean white;
@DatabaseField
protected String frameColor;
@DatabaseField
protected boolean splitCard;
@DatabaseField
protected boolean splitCardHalf;
@ -132,6 +138,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 +151,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 +180,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 +222,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 +312,10 @@ public class CardInfo {
public String getToughness() {
return toughness;
}
public String getStartingLoyalty() {
return startingLoyalty;
}
public String getSetCode() {
return setCode;

View file

@ -61,9 +61,9 @@ public enum CardRepository {
private static final String JDBC_URL = "jdbc:h2:file:./db/cards.h2;AUTO_SERVER=TRUE";
private static final String VERSION_ENTITY_NAME = "card";
// raise this if db structure was changed
private static final long CARD_DB_VERSION = 44;
private static final long CARD_DB_VERSION = 46;
// raise this if new cards were added to the server
private static final long CARD_CONTENT_VERSION = 55;
private static final long CARD_CONTENT_VERSION = 57;
private final Random random = new Random();
private Dao<CardInfo, Object> cardDao;

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

@ -118,6 +118,7 @@ public class PermanentCard extends PermanentImpl {
this.cardType.clear();
this.cardType.addAll(card.getCardType());
this.color = card.getColor(null).copy();
this.frameColor = card.getFrameColor(null).copy();
this.manaCost = card.getManaCost().copy();
if (card instanceof PermanentCard) {
this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters;

View file

@ -82,6 +82,7 @@ public class PermanentToken extends PermanentImpl {
}
this.cardType = token.getCardType();
this.color = token.getColor(game).copy();
this.frameColor = token.getFrameColor(game);
this.power.modifyBaseValue(token.getPower().getBaseValueModified());
this.toughness.modifyBaseValue(token.getToughness().getBaseValueModified());
this.supertype = token.getSupertype();

View file

@ -187,7 +187,7 @@ public class Token extends MageObjectImpl {
} else {
MageObject object = game.getObject(sourceId);
if (object instanceof PermanentToken) {
((PermanentToken) object).getExpansionSetCode();
setCode = ((PermanentToken) object).getExpansionSetCode();
}
}
}

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() {