- Synchronize nomenclature of Generic Cost

- Add new Colorless Cost
- Start displaying of colorless mana with new symbol (with backwards compatibility for existing scripts that produce "{1}" instead of "{C}")
This commit is contained in:
Sol
2015-12-29 16:37:22 +00:00
parent 3cc5f6495b
commit ff73eb78eb
31 changed files with 129 additions and 134 deletions

View File

@@ -427,19 +427,19 @@ public final class CardRules implements ICardCharacteristics {
*/
private static class ManaCostParser implements IParserManaCost {
private final StringTokenizer st;
private int colorlessCost;
private int genericCost;
public ManaCostParser(final String cost) {
st = new StringTokenizer(cost, " ");
this.colorlessCost = 0;
this.genericCost = 0;
}
@Override
public final int getTotalColorlessCost() {
public final int getTotalGenericCost() {
if (this.hasNext()) {
throw new RuntimeException("Colorless cost should be obtained after iteration is complete");
throw new RuntimeException("Generic cost should be obtained after iteration is complete");
}
return this.colorlessCost;
return this.genericCost;
}
/*
@@ -463,7 +463,7 @@ public final class CardRules implements ICardCharacteristics {
// System.out.println(unparsed);
try {
int iVal = Integer.parseInt(unparsed);
this.colorlessCost += iVal;
this.genericCost += iVal;
return null;
}
catch (NumberFormatException nex) { }

View File

@@ -394,7 +394,7 @@ public final class CardRulesPredicates {
public static class LeafNumber implements Predicate<CardRules> {
public enum CardField {
CMC, COLORLESS_COST, POWER, TOUGHNESS
CMC, GENERIC_COST, POWER, TOUGHNESS
}
private final LeafNumber.CardField field;
@@ -413,7 +413,7 @@ public final class CardRulesPredicates {
switch (this.field) {
case CMC:
return this.op(card.getManaCost().getCMC(), this.operand);
case COLORLESS_COST:
case GENERIC_COST:
return this.op(card.getManaCost().getGenericCost(), this.operand);
case POWER:
value = card.getIntPower();

View File

@@ -7,11 +7,5 @@ import java.util.Iterator;
* The Interface ManaParser.
*/
public interface IParserManaCost extends Iterator<ManaCostShard> {
/**
* Gets the total colorless cost.
*
* @return the total colorless cost
*/
int getTotalColorlessCost();
int getTotalGenericCost();
}

View File

@@ -4,7 +4,7 @@ import forge.card.MagicColor;
/** A bitmask to represent any mana symbol as an integer. */
public abstract class ManaAtom {
public static final int COLORLESS = 1 << 6;
public static final int GENERIC = 1 << 6;
/** The Constant WHITE. */
public static final int WHITE = MagicColor.WHITE;
@@ -24,12 +24,14 @@ public abstract class ManaAtom {
/** The Constant IS_X. */
public static final int IS_X = 1 << 8;
/** The Constant OR_2_COLORLESS. */
public static final int OR_2_COLORLESS = 1 << 9;
/** The Constant OR_2_GENERIC. */
public static final int OR_2_GENERIC = 1 << 9;
/** The Constant OR_2_LIFE. */
public static final int OR_2_LIFE = 1 << 10;
/** The Constant IS_SNOW. */
public static final int IS_SNOW = 1 << 11;
public static final int COLORLESS = 1 << 12;
}

View File

@@ -48,7 +48,6 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
private Float compareWeight = null;
/** The Constant empty. */
public static final ManaCost NO_COST = new ManaCost(-1);
public static final ManaCost ZERO = new ManaCost(0);
public static final ManaCost ONE = new ManaCost(1);
@@ -56,15 +55,15 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
public static final ManaCost THREE = new ManaCost(3);
public static final ManaCost FOUR = new ManaCost(4);
public static ManaCost get(int cntColorless) {
switch (cntColorless) {
public static ManaCost get(int cntGeneric) {
switch (cntGeneric) {
case 0: return ZERO;
case 1: return ONE;
case 2: return TWO;
case 3: return THREE;
case 4: return FOUR;
}
return cntColorless > 0 ? new ManaCost(cntColorless) : NO_COST;
return cntGeneric > 0 ? new ManaCost(cntGeneric) : NO_COST;
}
// pass mana cost parser here
@@ -91,11 +90,11 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
this.hasNoCost = false;
while (parser.hasNext()) {
final ManaCostShard shard = parser.next();
if (shard != null && shard != ManaCostShard.COLORLESS) {
if (shard != null && shard != ManaCostShard.GENERIC) {
shardsTemp.add(shard);
} // null is OK - that was generic mana
}
this.genericCost = parser.getTotalColorlessCost(); // collect generic mana
this.genericCost = parser.getTotalGenericCost(); // collect generic mana
// here
sealClass(shardsTemp);
}
@@ -149,7 +148,7 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh
}
public int getShardCount(ManaCostShard which) {
if (which == ManaCostShard.COLORLESS) {
if (which == ManaCostShard.GENERIC) {
return genericCost;
}

View File

@@ -9,7 +9,7 @@ import org.apache.commons.lang3.StringUtils;
public class ManaCostParser implements IParserManaCost {
private final String[] cost;
private int nextToken;
private int colorlessCost;
private int genericCost;
/**
* Parse the given cost and output formatted cost string
@@ -32,20 +32,20 @@ public class ManaCostParser implements IParserManaCost {
this.cost = cost.split(" ");
// System.out.println(cost);
this.nextToken = 0;
this.colorlessCost = 0;
this.genericCost = 0;
}
/*
* (non-Javadoc)
*
* @see forge.card.CardManaCost.ManaParser#getTotalColorlessCost()
* @see forge.card.CardManaCost.ManaParser#getTotalGenericCost()
*/
@Override
public final int getTotalColorlessCost() {
public final int getTotalGenericCost() {
if (this.hasNext()) {
throw new RuntimeException("Colorless cost should be obtained after iteration is complete");
throw new RuntimeException("Generic cost should be obtained after iteration is complete");
}
return this.colorlessCost;
return this.genericCost;
}
/*
@@ -68,7 +68,7 @@ public class ManaCostParser implements IParserManaCost {
final String unparsed = this.cost[this.nextToken++];
// System.out.println(unparsed);
if (StringUtils.isNumeric(unparsed)) {
this.colorlessCost += Integer.parseInt(unparsed);
this.genericCost += Integer.parseInt(unparsed);
return null;
}

View File

@@ -45,15 +45,16 @@ public enum ManaCostShard {
GU(ManaAtom.GREEN | ManaAtom.BLUE, "G/U", "GU"),
/* Or 2 colorless */
W2(ManaAtom.WHITE | ManaAtom.OR_2_COLORLESS, "2/W", "2W"),
U2(ManaAtom.BLUE | ManaAtom.OR_2_COLORLESS, "2/U", "2U"),
B2(ManaAtom.BLACK | ManaAtom.OR_2_COLORLESS, "2/B", "2B"),
R2(ManaAtom.RED | ManaAtom.OR_2_COLORLESS, "2/R", "2R"),
G2(ManaAtom.GREEN | ManaAtom.OR_2_COLORLESS, "2/G", "2G"),
W2(ManaAtom.WHITE | ManaAtom.OR_2_GENERIC, "2/W", "2W"),
U2(ManaAtom.BLUE | ManaAtom.OR_2_GENERIC, "2/U", "2U"),
B2(ManaAtom.BLACK | ManaAtom.OR_2_GENERIC, "2/B", "2B"),
R2(ManaAtom.RED | ManaAtom.OR_2_GENERIC, "2/R", "2R"),
G2(ManaAtom.GREEN | ManaAtom.OR_2_GENERIC, "2/G", "2G"),
// Snow and colorless
S(ManaAtom.IS_SNOW, "S"),
COLORLESS(ManaAtom.COLORLESS, "1"),
GENERIC(ManaAtom.GENERIC, "1"),
COLORLESS(ManaAtom.COLORLESS, "C"),
/* Phyrexian */
PW(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "P/W", "PW"),
@@ -112,7 +113,7 @@ public enum ManaCostShard {
if (0 != (this.shard & ManaAtom.IS_X)) {
return 0;
}
if (0 != (this.shard & ManaAtom.OR_2_COLORLESS)) {
if (0 != (this.shard & ManaAtom.OR_2_GENERIC)) {
return 2;
}
return 1;
@@ -130,7 +131,7 @@ public enum ManaCostShard {
if (0 != (this.shard & ManaAtom.IS_X)) {
return 0.0001f;
}
float cost = 0 != (this.shard & ManaAtom.OR_2_COLORLESS) ? 2 : 1;
float cost = 0 != (this.shard & ManaAtom.OR_2_GENERIC) ? 2 : 1;
// yes, these numbers are magic, slightly-magic
if (0 != (this.shard & ManaAtom.WHITE)) {
cost += 0.0005f;
@@ -170,7 +171,7 @@ public enum ManaCostShard {
* @return the card mana cost shard
*/
public static ManaCostShard valueOf(final int atoms) {
if ( atoms == 0 ) return ManaCostShard.COLORLESS;
if ( atoms == 0 ) return ManaCostShard.GENERIC;
for (final ManaCostShard element : ManaCostShard.values()) {
if (element.shard == atoms) {
return element;
@@ -194,17 +195,18 @@ public enum ManaCostShard {
case 'P': atoms |= ManaAtom.OR_2_LIFE; break;
case 'S': atoms |= ManaAtom.IS_SNOW; break;
case 'X': atoms |= ManaAtom.IS_X; break;
case '2': atoms |= ManaAtom.OR_2_COLORLESS; break;
case 'C': atoms |= ManaAtom.COLORLESS; break;
case '2': atoms |= ManaAtom.OR_2_GENERIC; break;
default:
if (c <= '9' && c >= '0') {
atoms |= ManaAtom.COLORLESS;
atoms |= ManaAtom.GENERIC;
}
break;
}
}
// for cases when unparsed equals '2' or unparsed is like '12' or '20'
if (atoms == ManaAtom.OR_2_COLORLESS || atoms == (ManaAtom.OR_2_COLORLESS | ManaAtom.COLORLESS)) {
atoms = ManaAtom.COLORLESS;
if (atoms == ManaAtom.OR_2_GENERIC || atoms == (ManaAtom.OR_2_GENERIC | ManaAtom.GENERIC)) {
atoms = ManaAtom.GENERIC;
}
return ManaCostShard.valueOf(atoms);
}
@@ -282,11 +284,11 @@ public enum ManaCostShard {
return BinaryUtil.bitCount(this.shard & COLORS_SUPERPOSITION) == 1;
}
public boolean isOr2Colorless() {
return (this.shard & ManaAtom.OR_2_COLORLESS) != 0;
public boolean isOr2Generic() {
return (this.shard & ManaAtom.OR_2_GENERIC) != 0;
}
public boolean canBePaidWithManaOfColor(byte colorCode) {
return this.isOr2Colorless() || (COLORS_SUPERPOSITION & this.shard) == 0 || (colorCode & this.shard) > 0;
return this.isOr2Generic() || (COLORS_SUPERPOSITION & this.shard) == 0 || (colorCode & this.shard) > 0;
}
}