();
-
- // handles costs like "3", "G", "GW", "10", "S"
- if ((cost.length() == 1) || (cost.length() == 2)) {
- if (Character.isDigit(cost.charAt(0))) {
- list.add(new ManaPartColorless(cost));
- } else if (cost.charAt(0) == 'S') {
- list.add(new ManaPartSnow());
- } else if (cost.charAt(0) == 'P') {
- list.add(new ManaPartPhyrexian(cost));
- } else {
- list.add(new ManaPartColor(cost));
- }
- } else {
- // handles "3 GW", "10 GW", "1 G G", "G G", "S 1"
- // all costs that have a length greater than 2 have a space
- final StringTokenizer tok = new StringTokenizer(cost);
-
- while (tok.hasMoreTokens()) {
- list.add(this.getManaPart(tok.nextToken()));
- }
-
- // ManaPartColorless needs to be added AFTER the colored mana
- // in order for isNeeded() and addMana() to work correctly
- Object o = list.get(0);
- if (o instanceof ManaPartSnow) {
- // move snow cost to the end of the list
- list.remove(0);
- list.add((ManaPartSnow) o);
- }
- o = list.get(0);
-
- if (o instanceof ManaPartColorless) {
- // move colorless cost to the end of the list
- list.remove(0);
- list.add((ManaPartColorless) o);
- }
- } // else
-
- return list;
- } // split()
-
- /**
- *
- * Getter for the field manaPart.
- *
- *
- * @param partCost
- * a {@link java.lang.String} object.
- * @return a {@link forge.card.mana.ManaPart} object.
- */
- private ManaPart getManaPart(final String partCost) {
- if (partCost.length() == 3) {
- return new ManaPartSplit(partCost);
- } else if (Character.isDigit(partCost.charAt(0))) {
- return new ManaPartColorless(partCost);
- } else if (partCost.equals("S")) {
- return new ManaPartSnow();
- } else if (partCost.startsWith("P")) {
- return new ManaPartPhyrexian(partCost);
- } else {
- return new ManaPartColor(partCost);
- }
- }
-
- /**
- *
- * Setter for the field xcounter.
- *
- *
- * @param xcounter
- * a int.
- */
- public final void setXcounter(final int xcounter) {
- this.xcounter = xcounter;
- }
-
/**
*
* Getter for the field xcounter.
@@ -667,7 +550,8 @@ public class ManaCost {
* @return a int.
*/
public final int getXcounter() {
- return this.xcounter;
+ Integer x = unpaidShards.get(ManaCostShard.X);
+ return x == null ? 0 : x;
}
/**
@@ -678,12 +562,7 @@ public class ManaCost {
* @since 1.0.15
*/
public final void removeColorlessMana() {
-
- for (int i = 0; i < this.manaPart.size(); i++) {
- if (this.manaPart.get(i) instanceof ManaPartColorless) {
- this.manaPart.remove(this.manaPart.get(i));
- }
- }
+ unpaidShards.remove(ManaCostShard.COLORLESS);
}
/**
diff --git a/src/main/java/forge/card/mana/ManaCostParser.java b/src/main/java/forge/card/mana/ManaCostParser.java
new file mode 100644
index 00000000000..b3282466635
--- /dev/null
+++ b/src/main/java/forge/card/mana/ManaCostParser.java
@@ -0,0 +1,107 @@
+package forge.card.mana;
+
+import org.apache.commons.lang3.StringUtils;
+
+
+/**
+ * The Class ParserCardnameTxtManaCost.
+ */
+public class ManaCostParser implements IParserManaCost {
+ private final String[] cost;
+ private int nextToken;
+ private int colorlessCost;
+
+ /**
+ * Instantiates a new parser cardname txt mana cost.
+ *
+ * @param cost
+ * the cost
+ */
+ public ManaCostParser(final String cost) {
+ this.cost = cost.split(" ");
+ // System.out.println(cost);
+ this.nextToken = 0;
+ this.colorlessCost = 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see forge.card.CardManaCost.ManaParser#getTotalColorlessCost()
+ */
+ @Override
+ public final int getTotalColorlessCost() {
+ if (this.hasNext()) {
+ throw new RuntimeException("Colorless cost should be obtained after iteration is complete");
+ }
+ return this.colorlessCost;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#hasNext()
+ */
+ @Override
+ public final boolean hasNext() {
+ return this.nextToken < this.cost.length;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#next()
+ */
+ @Override
+ public final ManaCostShard next() {
+
+ final String unparsed = this.cost[this.nextToken++];
+ // System.out.println(unparsed);
+ if (StringUtils.isNumeric(unparsed)) {
+ this.colorlessCost += Integer.parseInt(unparsed);
+ return null;
+ }
+
+ int atoms = 0;
+ for (int iChar = 0; iChar < unparsed.length(); iChar++) {
+ switch (unparsed.charAt(iChar)) {
+ case 'W':
+ atoms |= ManaCostShard.Atom.WHITE;
+ break;
+ case 'U':
+ atoms |= ManaCostShard.Atom.BLUE;
+ break;
+ case 'B':
+ atoms |= ManaCostShard.Atom.BLACK;
+ break;
+ case 'R':
+ atoms |= ManaCostShard.Atom.RED;
+ break;
+ case 'G':
+ atoms |= ManaCostShard.Atom.GREEN;
+ break;
+ case '2':
+ atoms |= ManaCostShard.Atom.OR_2_COLORLESS;
+ break;
+ case 'P':
+ atoms |= ManaCostShard.Atom.OR_2_LIFE;
+ break;
+ case 'X':
+ atoms |= ManaCostShard.Atom.IS_X;
+ break;
+ default:
+ break;
+ }
+ }
+ return ManaCostShard.valueOf(atoms);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.util.Iterator#remove()
+ */
+ @Override
+ public void remove() {
+ } // unsuported
+}
diff --git a/src/main/java/forge/card/CardManaCostShard.java b/src/main/java/forge/card/mana/ManaCostShard.java
similarity index 58%
rename from src/main/java/forge/card/CardManaCostShard.java
rename to src/main/java/forge/card/mana/ManaCostShard.java
index 2ab99cb8c27..b4d421b1459 100644
--- a/src/main/java/forge/card/CardManaCostShard.java
+++ b/src/main/java/forge/card/mana/ManaCostShard.java
@@ -15,12 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package forge.card;
+package forge.card.mana;
+
+import forge.card.CardColor;
+import forge.util.BinaryUtil;
/**
* The Class CardManaCostShard.
*/
-public class CardManaCostShard {
+public class ManaCostShard {
private final int shard;
@@ -42,7 +45,7 @@ public class CardManaCostShard {
* @param sValue
* the s value
*/
- protected CardManaCostShard(final int value, final String sValue) {
+ protected ManaCostShard(final int value, final String sValue) {
this(value, sValue, sValue);
}
@@ -56,7 +59,7 @@ public class CardManaCostShard {
* @param imgKey
* the img key
*/
- protected CardManaCostShard(final int value, final String sValue, final String imgKey) {
+ protected ManaCostShard(final int value, final String sValue, final String imgKey) {
this.shard = value;
this.cmc = this.getCMC();
this.cmpc = this.getCmpCost();
@@ -66,7 +69,8 @@ public class CardManaCostShard {
/** A bitmask to represent any mana symbol as an integer. */
public abstract static class Atom {
- // int COLORLESS = 1 << 0;
+ public static final int COLORLESS = 1 << 0;
+
/** The Constant WHITE. */
public static final int WHITE = 1 << 1;
@@ -105,95 +109,98 @@ public class CardManaCostShard {
* I choose the latter, because memory for boxed objects will be taken from
* heap, while unboxed values will lay on stack, which is faster
*/
+
+ public static final ManaCostShard COLORLESS = new ManaCostShard(Atom.COLORLESS, "1");
+
/** The Constant X. */
- public static final CardManaCostShard X = new CardManaCostShard(Atom.IS_X, "X");
+ public static final ManaCostShard X = new ManaCostShard(Atom.IS_X, "X");
/** The Constant S. */
- public static final CardManaCostShard S = new CardManaCostShard(Atom.IS_SNOW, "S");
+ public static final ManaCostShard S = new ManaCostShard(Atom.IS_SNOW, "S");
/** The Constant WHITE. */
- public static final CardManaCostShard WHITE = new CardManaCostShard(Atom.WHITE, "W");
+ public static final ManaCostShard WHITE = new ManaCostShard(Atom.WHITE, "W");
/** The Constant BLUE. */
- public static final CardManaCostShard BLUE = new CardManaCostShard(Atom.BLUE, "U");
+ public static final ManaCostShard BLUE = new ManaCostShard(Atom.BLUE, "U");
/** The Constant BLACK. */
- public static final CardManaCostShard BLACK = new CardManaCostShard(Atom.BLACK, "B");
+ public static final ManaCostShard BLACK = new ManaCostShard(Atom.BLACK, "B");
/** The Constant RED. */
- public static final CardManaCostShard RED = new CardManaCostShard(Atom.RED, "R");
+ public static final ManaCostShard RED = new ManaCostShard(Atom.RED, "R");
/** The Constant GREEN. */
- public static final CardManaCostShard GREEN = new CardManaCostShard(Atom.GREEN, "G");
+ public static final ManaCostShard GREEN = new ManaCostShard(Atom.GREEN, "G");
/** The Constant PW. */
- public static final CardManaCostShard PW = new CardManaCostShard(Atom.WHITE | Atom.OR_2_LIFE, "W/P", "PW");
+ public static final ManaCostShard PW = new ManaCostShard(Atom.WHITE | Atom.OR_2_LIFE, "W/P", "PW");
/** The Constant PU. */
- public static final CardManaCostShard PU = new CardManaCostShard(Atom.BLUE | Atom.OR_2_LIFE, "U/P", "PU");
+ public static final ManaCostShard PU = new ManaCostShard(Atom.BLUE | Atom.OR_2_LIFE, "U/P", "PU");
/** The Constant PB. */
- public static final CardManaCostShard PB = new CardManaCostShard(Atom.BLACK | Atom.OR_2_LIFE, "B/P", "PB");
+ public static final ManaCostShard PB = new ManaCostShard(Atom.BLACK | Atom.OR_2_LIFE, "B/P", "PB");
/** The Constant PR. */
- public static final CardManaCostShard PR = new CardManaCostShard(Atom.RED | Atom.OR_2_LIFE, "R/P", "PR");
+ public static final ManaCostShard PR = new ManaCostShard(Atom.RED | Atom.OR_2_LIFE, "R/P", "PR");
/** The Constant PG. */
- public static final CardManaCostShard PG = new CardManaCostShard(Atom.GREEN | Atom.OR_2_LIFE, "G/P", "PG");
+ public static final ManaCostShard PG = new ManaCostShard(Atom.GREEN | Atom.OR_2_LIFE, "G/P", "PG");
/** The Constant WU. */
- public static final CardManaCostShard WU = new CardManaCostShard(Atom.WHITE | Atom.BLUE, "W/U", "WU");
+ public static final ManaCostShard WU = new ManaCostShard(Atom.WHITE | Atom.BLUE, "W/U", "WU");
/** The Constant WB. */
- public static final CardManaCostShard WB = new CardManaCostShard(Atom.WHITE | Atom.BLACK, "W/B", "WB");
+ public static final ManaCostShard WB = new ManaCostShard(Atom.WHITE | Atom.BLACK, "W/B", "WB");
/** The Constant WR. */
- public static final CardManaCostShard WR = new CardManaCostShard(Atom.WHITE | Atom.RED, "W/R", "RW");
+ public static final ManaCostShard WR = new ManaCostShard(Atom.WHITE | Atom.RED, "W/R", "RW");
/** The Constant WG. */
- public static final CardManaCostShard WG = new CardManaCostShard(Atom.WHITE | Atom.GREEN, "W/G", "GW");
+ public static final ManaCostShard WG = new ManaCostShard(Atom.WHITE | Atom.GREEN, "W/G", "GW");
/** The Constant UB. */
- public static final CardManaCostShard UB = new CardManaCostShard(Atom.BLUE | Atom.BLACK, "U/B", "UB");
+ public static final ManaCostShard UB = new ManaCostShard(Atom.BLUE | Atom.BLACK, "U/B", "UB");
/** The Constant UR. */
- public static final CardManaCostShard UR = new CardManaCostShard(Atom.BLUE | Atom.RED, "U/R", "UR");
+ public static final ManaCostShard UR = new ManaCostShard(Atom.BLUE | Atom.RED, "U/R", "UR");
/** The Constant UG. */
- public static final CardManaCostShard UG = new CardManaCostShard(Atom.BLUE | Atom.GREEN, "U/G", "GU");
+ public static final ManaCostShard UG = new ManaCostShard(Atom.BLUE | Atom.GREEN, "U/G", "GU");
/** The Constant BR. */
- public static final CardManaCostShard BR = new CardManaCostShard(Atom.BLACK | Atom.RED, "B/R", "BR");
+ public static final ManaCostShard BR = new ManaCostShard(Atom.BLACK | Atom.RED, "B/R", "BR");
/** The Constant BG. */
- public static final CardManaCostShard BG = new CardManaCostShard(Atom.BLACK | Atom.GREEN, "B/G", "BG");
+ public static final ManaCostShard BG = new ManaCostShard(Atom.BLACK | Atom.GREEN, "B/G", "BG");
/** The Constant RG. */
- public static final CardManaCostShard RG = new CardManaCostShard(Atom.RED | Atom.GREEN, "R/G", "RG");
+ public static final ManaCostShard RG = new ManaCostShard(Atom.RED | Atom.GREEN, "R/G", "RG");
/** The Constant W2. */
- public static final CardManaCostShard W2 = new CardManaCostShard(Atom.WHITE | Atom.OR_2_COLORLESS, "2/W", "2W");
+ public static final ManaCostShard W2 = new ManaCostShard(Atom.WHITE | Atom.OR_2_COLORLESS, "2/W", "2W");
/** The Constant U2. */
- public static final CardManaCostShard U2 = new CardManaCostShard(Atom.BLUE | Atom.OR_2_COLORLESS, "2/U", "2U");
+ public static final ManaCostShard U2 = new ManaCostShard(Atom.BLUE | Atom.OR_2_COLORLESS, "2/U", "2U");
/** The Constant B2. */
- public static final CardManaCostShard B2 = new CardManaCostShard(Atom.BLACK | Atom.OR_2_COLORLESS, "2/B", "2B");
+ public static final ManaCostShard B2 = new ManaCostShard(Atom.BLACK | Atom.OR_2_COLORLESS, "2/B", "2B");
/** The Constant R2. */
- public static final CardManaCostShard R2 = new CardManaCostShard(Atom.RED | Atom.OR_2_COLORLESS, "2/R", "2R");
+ public static final ManaCostShard R2 = new ManaCostShard(Atom.RED | Atom.OR_2_COLORLESS, "2/R", "2R");
/** The Constant G2. */
- public static final CardManaCostShard G2 = new CardManaCostShard(Atom.GREEN | Atom.OR_2_COLORLESS, "2/G", "2G");
+ public static final ManaCostShard G2 = new ManaCostShard(Atom.GREEN | Atom.OR_2_COLORLESS, "2/G", "2G");
- private static final CardManaCostShard[] ALL_POSSIBLE = new CardManaCostShard[] { CardManaCostShard.X,
- CardManaCostShard.WHITE, CardManaCostShard.BLUE, CardManaCostShard.BLACK, CardManaCostShard.RED,
- CardManaCostShard.GREEN, CardManaCostShard.PW, CardManaCostShard.PU, CardManaCostShard.PB,
- CardManaCostShard.PR, CardManaCostShard.PG, CardManaCostShard.WU, CardManaCostShard.WB,
- CardManaCostShard.WR, CardManaCostShard.WG, CardManaCostShard.UB, CardManaCostShard.UR,
- CardManaCostShard.UG, CardManaCostShard.BR, CardManaCostShard.BG, CardManaCostShard.RG,
- CardManaCostShard.W2, CardManaCostShard.U2, CardManaCostShard.B2, CardManaCostShard.R2,
- CardManaCostShard.G2, CardManaCostShard.S };
+ private static final ManaCostShard[] ALL_POSSIBLE = new ManaCostShard[] { ManaCostShard.X,
+ ManaCostShard.WHITE, ManaCostShard.BLUE, ManaCostShard.BLACK, ManaCostShard.RED,
+ ManaCostShard.GREEN, ManaCostShard.PW, ManaCostShard.PU, ManaCostShard.PB,
+ ManaCostShard.PR, ManaCostShard.PG, ManaCostShard.WU, ManaCostShard.WB,
+ ManaCostShard.WR, ManaCostShard.WG, ManaCostShard.UB, ManaCostShard.UR,
+ ManaCostShard.UG, ManaCostShard.BR, ManaCostShard.BG, ManaCostShard.RG,
+ ManaCostShard.W2, ManaCostShard.U2, ManaCostShard.B2, ManaCostShard.R2,
+ ManaCostShard.G2, ManaCostShard.S };
private int getCMC() {
if (0 != (this.shard & Atom.IS_X)) {
@@ -245,7 +252,7 @@ public class CardManaCostShard {
*
* @return the color mask
*/
- final byte getColorMask() {
+ public final byte getColorMask() {
byte result = 0;
if (0 != (this.shard & Atom.WHITE)) {
result |= CardColor.WHITE;
@@ -272,8 +279,8 @@ public class CardManaCostShard {
* the atoms
* @return the card mana cost shard
*/
- public static CardManaCostShard valueOf(final int atoms) {
- for (final CardManaCostShard element : CardManaCostShard.ALL_POSSIBLE) {
+ public static ManaCostShard valueOf(final int atoms) {
+ for (final ManaCostShard element : ManaCostShard.ALL_POSSIBLE) {
if (element.shard == atoms) {
return element;
}
@@ -325,4 +332,26 @@ public class CardManaCostShard {
public boolean isPhyrexian() {
return (this.shard & Atom.OR_2_LIFE) != 0;
}
+
+ /**
+ * TODO: Write javadoc for this method.
+ * @return
+ */
+ public boolean isSnow() {
+ return (this.shard & Atom.IS_SNOW) != 0;
+ }
+
+ public boolean isMonoColor() {
+ int colormask = this.shard & (Atom.WHITE | Atom.BLUE | Atom.BLACK | Atom.RED | Atom.GREEN);
+ return BinaryUtil.bitCount(colormask) == 1;
+
+ }
+
+ /**
+ * TODO: Write javadoc for this method.
+ * @return
+ */
+ public boolean isOr2Colorless() {
+ return (this.shard & Atom.OR_2_COLORLESS) != 0;
+ }
}
diff --git a/src/main/java/forge/card/mana/Mana.java b/src/main/java/forge/card/mana/ManaPaid.java
similarity index 94%
rename from src/main/java/forge/card/mana/Mana.java
rename to src/main/java/forge/card/mana/ManaPaid.java
index 6ffa022a61e..6006d26c6cb 100644
--- a/src/main/java/forge/card/mana/Mana.java
+++ b/src/main/java/forge/card/mana/ManaPaid.java
@@ -29,7 +29,7 @@ import forge.control.input.InputPayManaCostUtil;
* @author Forge
* @version $Id$
*/
-public class Mana {
+public class ManaPaid {
private String color;
private int amount = 0;
private Card sourceCard = null;
@@ -46,7 +46,7 @@ public class Mana {
* @param source
* a {@link forge.Card} object.
*/
- public Mana(final String col, final int amt, final Card source) {
+ public ManaPaid(final String col, final int amt, final Card source) {
this.color = col;
this.amount = amt;
if (source == null) {
@@ -117,12 +117,12 @@ public class Mana {
* toSingleArray.
*
*
- * @return an array of {@link forge.card.mana.Mana} objects.
+ * @return an array of {@link forge.card.mana.ManaPaid} objects.
*/
- public final Mana[] toSingleArray() {
- final Mana[] normalize = new Mana[this.amount];
+ public final ManaPaid[] toSingleArray() {
+ final ManaPaid[] normalize = new ManaPaid[this.amount];
for (int i = 0; i < normalize.length; i++) {
- normalize[i] = new Mana(this.color, 1, this.sourceCard);
+ normalize[i] = new ManaPaid(this.color, 1, this.sourceCard);
}
return normalize;
}
diff --git a/src/main/java/forge/card/mana/ManaPart.java b/src/main/java/forge/card/mana/ManaPart.java
deleted file mode 100644
index 4c10392f1c9..00000000000
--- a/src/main/java/forge/card/mana/ManaPart.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-/**
- *
- * Abstract Mana_Part class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public abstract class ManaPart {
- /** {@inheritDoc} */
- @Override
- public abstract String toString();
-
- /**
- *
- * reduce.
- *
- *
- * @param mana
- * a {@link java.lang.String} object.
- */
- public abstract void reduce(String mana);
-
- /**
- *
- * reduce.
- *
- *
- * @param mana
- * a {@link forge.card.mana.Mana} object.
- */
- public abstract void reduce(Mana mana);
-
- /**
- *
- * isPaid.
- *
- *
- * @return a boolean.
- */
- public abstract boolean isPaid();
-
- /**
- *
- * isNeeded.
- *
- *
- * @param mana
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- public abstract boolean isNeeded(String mana);
-
- /**
- *
- * isNeeded.
- *
- *
- * @param mana
- * a {@link forge.card.mana.Mana} object.
- * @return a boolean.
- */
- public abstract boolean isNeeded(Mana mana);
-
- /**
- *
- * isColor.
- *
- *
- * @param mana
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- public abstract boolean isColor(String mana);
-
- /**
- *
- * isColor.
- *
- *
- * @param mana
- * a {@link forge.card.mana.Mana} object.
- * @return a boolean.
- */
- public abstract boolean isColor(Mana mana);
-
- /**
- *
- * isEasierToPay.
- *
- *
- * @param mp
- * a {@link forge.card.mana.ManaPart} object.
- * @return a boolean.
- */
- public abstract boolean isEasierToPay(ManaPart mp);
-
- /**
- *
- * getConvertedManaCost.
- *
- *
- * @return a int.
- */
- public abstract int getConvertedManaCost();
-
- /**
- *
- * checkSingleMana.
- *
- *
- * @param m
- * a {@link java.lang.String} object.
- */
- public static void checkSingleMana(final String m) {
- if (m.length() != 1) {
- throw new RuntimeException("Mana_Part : checkMana() error, argument mana is not of length 1, mana - " + m);
- }
-
- if (!(m.equals("G") || m.equals("U") || m.equals("W") || m.equals("B") || m.equals("R") || m.equals("1")
- || m.equals("S") || m.startsWith("P"))) {
- throw new RuntimeException("Mana_Part : checkMana() error, argument mana is invalid mana, mana - " + m);
- }
- }
-}
diff --git a/src/main/java/forge/card/mana/ManaPartColor.java b/src/main/java/forge/card/mana/ManaPartColor.java
deleted file mode 100644
index d814391b63e..00000000000
--- a/src/main/java/forge/card/mana/ManaPartColor.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-import forge.control.input.InputPayManaCostUtil;
-
-/**
- *
- * Mana_PartColor class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class ManaPartColor extends ManaPart {
- private String manaCost;
-
- // String manaCostToPay is either "G" or "GW" NOT "3 G"
- // ManaPartColor only needs 1 mana in order to be paid
- // GW means it will accept either G or W like Selesnya Guildmage
- /**
- *
- * Constructor for Mana_PartColor.
- *
- *
- * @param manaCostToPay
- * a {@link java.lang.String} object.
- */
- public ManaPartColor(final String manaCostToPay) {
- final char[] c = manaCostToPay.toCharArray();
- for (int i = 0; i < c.length; i++) {
- if ((i != 0) || (c[i] != ' ')) {
- ManaPart.checkSingleMana("" + c[i]);
- }
- }
-
- this.manaCost = manaCostToPay;
- }
-
- /** {@inheritDoc} */
- @Override
- public final String toString() {
- return this.manaCost;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final String mana) {
- // ManaPart method
- ManaPart.checkSingleMana(mana);
-
- return !this.isPaid() && this.isColor(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final Mana mana) {
- return (!this.isPaid() && this.isColor(mana));
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final String mana) {
- // ManaPart method
- ManaPart.checkSingleMana(mana);
-
- return this.manaCost.indexOf(mana) != -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final Mana mana) {
- final String color = InputPayManaCostUtil.getShortColorString(mana.getColor());
-
- return this.manaCost.indexOf(color) != -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isEasierToPay(final ManaPart mp) {
- if (mp instanceof ManaPartColorless) {
- return false;
- }
- return this.toString().length() >= mp.toString().length();
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final String mana) {
- // if mana is needed, then this mana cost is all paid up
- if (!this.isNeeded(mana)) {
- throw new RuntimeException("Mana_PartColor : reduce() error, argument mana not needed, mana - " + mana
- + ", toString() - " + this.toString());
- }
-
- this.manaCost = "";
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final Mana mana) {
- // if mana is needed, then this mana cost is all paid up
- if (!this.isNeeded(mana)) {
- throw new RuntimeException("Mana_PartColor : reduce() error, argument mana not needed, mana - " + mana
- + ", toString() - " + this.toString());
- }
-
- this.manaCost = "";
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isPaid() {
- return this.manaCost.length() == 0;
- }
-
- /** {@inheritDoc} */
- @Override
- public final int getConvertedManaCost() {
- return 1;
- }
-}
diff --git a/src/main/java/forge/card/mana/ManaPartColorless.java b/src/main/java/forge/card/mana/ManaPartColorless.java
deleted file mode 100644
index e7abc4effe4..00000000000
--- a/src/main/java/forge/card/mana/ManaPartColorless.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-import forge.error.ErrorViewer;
-
-/**
- *
- * Mana_PartColorless class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class ManaPartColorless extends ManaPart {
- private int manaNeeded;
-
- /**
- *
- * addToManaNeeded.
- *
- *
- * @param additional
- * a int.
- */
- public final void addToManaNeeded(final int additional) {
- this.manaNeeded += additional;
- }
-
- /**
- *
- * Getter for the field manaNeeded.
- *
- *
- * @return a int.
- */
- public final int getManaNeeded() {
- return this.manaNeeded;
- }
-
- // String manaCostToPay is like "1", "4", but NO COLOR
- /**
- *
- * Constructor for Mana_PartColorless.
- *
- *
- * @param manaCostToPay
- * a {@link java.lang.String} object.
- */
- public ManaPartColorless(final String manaCostToPay) {
- try {
- this.manaNeeded = Integer.parseInt(manaCostToPay);
- } catch (final NumberFormatException ex) {
- ErrorViewer.showError(ex, "mana cost is not a number - %s", manaCostToPay);
- throw new RuntimeException(String.format("mana cost is not a number - %s", manaCostToPay), ex);
- }
- }
-
- /**
- *
- * Constructor for Mana_PartColorless.
- *
- *
- * @param manaCostToPay
- * a int.
- */
- public ManaPartColorless(final int manaCostToPay) {
- this.manaNeeded = manaCostToPay;
- }
-
- /** {@inheritDoc} */
- @Override
- public final String toString() {
- if (this.isPaid()) {
- return "";
- }
-
- return String.valueOf(this.manaNeeded);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final String mana) {
- // ManaPart method
- ManaPart.checkSingleMana(mana);
-
- return 0 < this.manaNeeded;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final Mana mana) {
- // ManaPart method
- if (mana.getAmount() > 1) {
- throw new RuntimeException("Mana_PartColorless received Mana type with amount > 1");
- }
-
- return 0 < this.manaNeeded;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final String mana) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final Mana mana) {
- return false;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isEasierToPay(final ManaPart mp) {
- // Colorless is always easier to Pay for
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final String mana) {
- // if mana is needed, then this mana cost is all paid up
- if (!this.isNeeded(mana)) {
- throw new RuntimeException("Mana_PartColorless : reduce() error, argument mana not needed, mana - " + mana
- + ", toString() - " + this.toString());
- }
-
- this.manaNeeded--;
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final Mana mana) {
- // if mana is needed, then this mana cost is all paid up
- if (!this.isNeeded(mana)) {
- throw new RuntimeException("Mana_PartColorless : reduce() error, argument mana not needed, mana - " + mana
- + ", toString() - " + this.toString());
- }
-
- this.manaNeeded--;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isPaid() {
- return this.manaNeeded == 0;
- }
-
- /** {@inheritDoc} */
- @Override
- public final int getConvertedManaCost() {
- return this.manaNeeded;
- }
-}
diff --git a/src/main/java/forge/card/mana/ManaPartPhyrexian.java b/src/main/java/forge/card/mana/ManaPartPhyrexian.java
deleted file mode 100644
index 46373fd2e1b..00000000000
--- a/src/main/java/forge/card/mana/ManaPartPhyrexian.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-/**
- *
- * Mana_PartPhyrexian class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class ManaPartPhyrexian extends ManaPart {
- private final ManaPartColor wrappedColor;
- private final String color;
-
- /**
- *
- * Constructor for Mana_PartPhyrexian.
- *
- *
- * @param manaCostToPay
- * a {@link java.lang.String} object.
- */
- public ManaPartPhyrexian(final String manaCostToPay) {
- this.wrappedColor = new ManaPartColor(manaCostToPay.substring(1));
- this.color = manaCostToPay.substring(1);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isEasierToPay(final ManaPart part) {
- return true;
- }
-
- /**
- *
- * toString.
- *
- *
- * @return a {@link java.lang.String} object.
- */
- @Override
- public final String toString() {
- return this.wrappedColor.toString().equals("") ? "" : "P" + this.wrappedColor.toString();
- }
-
- /**
- *
- * isPaid.
- *
- *
- * @return a boolean.
- */
- @Override
- public final boolean isPaid() {
- return this.wrappedColor.isPaid();
- }
-
- /**
- * {@inheritDoc}
- *
- *
- * isColor.
- *
- *
- * @param mana
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- @Override
- public final boolean isColor(final String mana) {
- return this.wrappedColor.isColor(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final Mana mana) {
- return this.wrappedColor.isColor(mana);
- }
-
- /**
- *
- * isNeeded.
- *
- *
- * @param mana
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- @Override
- public final boolean isNeeded(final String mana) {
- return this.wrappedColor.isNeeded(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final Mana mana) {
- return this.wrappedColor.isNeeded(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final String mana) {
- this.wrappedColor.reduce(mana);
- }
-
- /**
- * {@inheritDoc}
- *
- *
- * reduce.
- *
- *
- * @param mana
- * a {@link forge.card.mana.Mana} object.
- */
- @Override
- public final void reduce(final Mana mana) {
- this.wrappedColor.reduce(mana);
- }
-
- /**
- *
- * getConvertedManaCost.
- *
- *
- * @return a int.
- */
- @Override
- public final int getConvertedManaCost() {
- return this.wrappedColor.getConvertedManaCost();
- }
-
- /**
- *
- * payLife.
- *
- */
- public final void payLife() {
- this.wrappedColor.reduce(this.color);
- }
-}
diff --git a/src/main/java/forge/card/mana/ManaPartSnow.java b/src/main/java/forge/card/mana/ManaPartSnow.java
deleted file mode 100644
index 8bacb478f78..00000000000
--- a/src/main/java/forge/card/mana/ManaPartSnow.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-/**
- *
- * Mana_PartSnow class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class ManaPartSnow extends ManaPart {
-
- private boolean isPaid = false;
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final String mana) {
- return !this.isPaid && mana.equals("S");
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final Mana mana) {
- return !this.isPaid && mana.isSnow();
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final String mana) {
- // ManaPart method
- return mana.indexOf("S") != -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final Mana mana) {
- return mana.isSnow();
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isPaid() {
- return this.isPaid;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isEasierToPay(final ManaPart mp) {
- if (mp instanceof ManaPartColorless) {
- return false;
- }
- return this.toString().length() >= mp.toString().length();
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final String mana) {
- if (!mana.equals("S")) {
- throw new RuntimeException("Mana_PartSnow: reduce() error, " + mana + " is not snow mana");
- }
- this.isPaid = true;
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final Mana mana) {
- if (!mana.isSnow()) {
- throw new RuntimeException("Mana_PartSnow: reduce() error, " + mana + " is not snow mana");
- }
- this.isPaid = true;
- }
-
- /** {@inheritDoc} */
- @Override
- public final String toString() {
- return (this.isPaid ? "" : "S");
- }
-
- /** {@inheritDoc} */
- @Override
- public final int getConvertedManaCost() {
- return 1;
- }
-
-}
diff --git a/src/main/java/forge/card/mana/ManaPartSplit.java b/src/main/java/forge/card/mana/ManaPartSplit.java
deleted file mode 100644
index fa2ad5c8550..00000000000
--- a/src/main/java/forge/card/mana/ManaPartSplit.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Forge: Play Magic: the Gathering.
- * Copyright (C) 2011 Forge Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package forge.card.mana;
-
-import forge.control.input.InputPayManaCostUtil;
-
-//handles mana costs like 2/R or 2/B
-//for cards like Flame Javelin (Shadowmoor)
-/**
- *
- * Mana_PartSplit class.
- *
- *
- * @author Forge
- * @version $Id$
- */
-public class ManaPartSplit extends ManaPart {
- private ManaPart manaPart = null;
- private String originalCost = "";
-
- /**
- *
- * Constructor for Mana_PartSplit.
- *
- *
- * @param manaCost
- * a {@link java.lang.String} object.
- */
- public ManaPartSplit(final String manaCost) {
- // is mana cost like "2/R"
- if (manaCost.length() != 3) {
- throw new RuntimeException("Mana_PartSplit : constructor() error, bad mana cost parameter - " + manaCost);
- }
-
- this.originalCost = manaCost;
- }
-
- /**
- *
- * isFirstTime.
- *
- *
- * @return a boolean.
- */
- private boolean isFirstTime() {
- return this.manaPart == null;
- }
-
- /**
- *
- * setup.
- *
- *
- * @param manaToPay
- * a {@link java.lang.String} object.
- */
- private void setup(final String manaToPay) {
- // get R out of "2/R"
- final String color = this.originalCost.substring(2, 3);
-
- // is manaToPay the one color we want or do we
- // treat it like colorless?
- // if originalCost is 2/R and is color W (treated like colorless)
- // or R? if W use Mana_PartColorless, if R use Mana_PartColor
- // does manaToPay contain color?
- if (0 <= manaToPay.indexOf(color)) {
- this.manaPart = new ManaPartColor(color);
- } else {
- // get 2 out of "2/R"
- this.manaPart = new ManaPartColorless(this.originalCost.substring(0, 1));
- }
- } // setup()
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final String mana) {
- if (this.isFirstTime()) {
- this.setup(mana);
- }
-
- this.manaPart.reduce(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final void reduce(final Mana mana) {
- if (this.isFirstTime()) {
- this.setup(InputPayManaCostUtil.getShortColorString(mana.getColor()));
- }
-
- this.manaPart.reduce(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final String mana) {
- if (this.isFirstTime()) {
- // always true because any mana can pay the colorless part of 2/G
- return true;
- }
-
- return this.manaPart.isNeeded(mana);
- } // isNeeded()
-
- /** {@inheritDoc} */
- @Override
- public final boolean isNeeded(final Mana mana) {
- if (this.isFirstTime()) {
- // always true because any mana can pay the colorless part of 2/G
- return true;
- }
-
- return this.manaPart.isNeeded(mana);
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final String mana) {
- // ManaPart method
- final String mp = this.toString();
- return mp.indexOf(mana) != -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isColor(final Mana mana) {
- final String color = InputPayManaCostUtil.getShortColorString(mana.getColor());
- final String mp = this.toString();
- return mp.indexOf(color) != -1;
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isEasierToPay(final ManaPart mp) {
- if (mp instanceof ManaPartColorless) {
- return false;
- }
- if (!this.isFirstTime()) {
- return true;
- }
- return this.toString().length() >= mp.toString().length();
- }
-
- /** {@inheritDoc} */
- @Override
- public final String toString() {
- if (this.isFirstTime()) {
- return this.originalCost;
- }
-
- return this.manaPart.toString();
- }
-
- /** {@inheritDoc} */
- @Override
- public final boolean isPaid() {
- if (this.isFirstTime()) {
- return false;
- }
-
- return this.manaPart.isPaid();
- }
-
- /** {@inheritDoc} */
- @Override
- public final int getConvertedManaCost() {
- // grab the colorless portion of the split cost (usually 2, but possibly
- // more later)
- return Integer.parseInt(this.originalCost.substring(0, 1));
- }
-}
diff --git a/src/main/java/forge/card/mana/ManaPool.java b/src/main/java/forge/card/mana/ManaPool.java
index 31538ab34cd..21de02dcbf9 100644
--- a/src/main/java/forge/card/mana/ManaPool.java
+++ b/src/main/java/forge/card/mana/ManaPool.java
@@ -43,7 +43,7 @@ import forge.gui.GuiUtils;
public class ManaPool {
// current paying moved to SpellAbility
- private final ArrayList floatingMana = new ArrayList();
+ private final ArrayList floatingMana = new ArrayList();
private final int[] floatingTotals = new int[6]; // WUBRGC
private final int[] floatingSnowTotals = new int[6]; // WUBRGC
@@ -133,7 +133,7 @@ public class ManaPool {
floatingSnowTotals[i] = 0;
}
- for (final Mana m : this.floatingMana) {
+ for (final ManaPaid m : this.floatingMana) {
if (m.isSnow()) {
floatingSnowTotals[ManaPool.MAP.get(m.getColor())] += m.getAmount();
} else {
@@ -229,9 +229,9 @@ public class ManaPool {
* @param pool
* a {@link java.util.ArrayList} object.
* @param mana
- * a {@link forge.card.mana.Mana} object.
+ * a {@link forge.card.mana.ManaPaid} object.
*/
- public final void addManaToPool(final ArrayList pool, final Mana mana) {
+ public final void addManaToPool(final ArrayList pool, final ManaPaid mana) {
pool.add(mana);
if (pool.equals(this.floatingMana)) {
int i = ManaPool.MAP.get(mana.getColor());
@@ -256,8 +256,8 @@ public class ManaPool {
* a {@link forge.Card} object.
*/
public final void addManaToFloating(final String manaStr, final Card card) {
- final ArrayList manaList = ManaPool.convertStringToMana(manaStr, card);
- for (final Mana m : manaList) {
+ final ArrayList manaList = ManaPool.convertStringToMana(manaStr, card);
+ for (final ManaPaid m : manaList) {
this.addManaToPool(this.floatingMana, m);
}
Singletons.getModel().getGameAction().checkStateEffects();
@@ -275,8 +275,8 @@ public class ManaPool {
* a {@link forge.Card} object.
* @return a {@link java.util.ArrayList} object.
*/
- public static ArrayList convertStringToMana(String manaStr, final Card card) {
- final ArrayList manaList = new ArrayList();
+ public static ArrayList convertStringToMana(String manaStr, final Card card) {
+ final ArrayList manaList = new ArrayList();
manaStr = manaStr.trim();
final String[] manaArr = manaStr.split(" ");
@@ -295,17 +295,17 @@ public class ManaPool {
total++;
} else { // more than one color generated
// add aggregate color
- manaList.add(new Mana(color, total, card));
+ manaList.add(new ManaPaid(color, total, card));
color = longStr;
total = 1;
}
}
if (total > 0) {
- manaList.add(new Mana(color, total, card));
+ manaList.add(new ManaPaid(color, total, card));
}
if (genericTotal > 0) {
- manaList.add(new Mana(Constant.Color.COLORLESS, genericTotal, card));
+ manaList.add(new ManaPaid(Constant.Color.COLORLESS, genericTotal, card));
}
return manaList;
@@ -357,9 +357,9 @@ public class ManaPool {
* a {@link java.util.ArrayList} object.
* @param manaStr
* a {@link java.lang.String} object.
- * @return a {@link forge.card.mana.Mana} object.
+ * @return a {@link forge.card.mana.ManaPaid} object.
*/
- public final Mana getManaFrom(final ArrayList pool, final String manaStr) {
+ public final ManaPaid getManaFrom(final ArrayList pool, final String manaStr) {
final String[] colors = manaStr.split("/");
boolean wantSnow = false;
for (int i = 0; i < colors.length; i++) {
@@ -369,10 +369,10 @@ public class ManaPool {
}
}
- Mana choice = null;
- final ArrayList manaChoices = new ArrayList();
+ ManaPaid choice = null;
+ final ArrayList manaChoices = new ArrayList();
- for (final Mana mana : pool) {
+ for (final ManaPaid mana : pool) {
if (mana.isColor(colors)) {
if (choice == null) {
choice = mana;
@@ -422,7 +422,7 @@ public class ManaPool {
Constant.Color.RED, Constant.Color.GREEN, Constant.Color.COLORLESS };
// loop through manaChoices adding
- for (final Mana m : manaChoices) {
+ for (final ManaPaid m : manaChoices) {
if (m.isSnow()) {
snowMana[ManaPool.MAP.get(m.getColor())] += m.getAmount();
} else {
@@ -472,7 +472,7 @@ public class ManaPool {
ch = ch.substring(0, ch.indexOf("("));
- for (final Mana m : manaChoices) {
+ for (final ManaPaid m : manaChoices) {
if (m.isColor(ch) && (!grabSnow || (grabSnow && m.isSnow()))) {
if (choice == null) {
choice = m;
@@ -496,11 +496,11 @@ public class ManaPool {
* @param pool
* a {@link java.util.ArrayList} object.
* @param mana
- * a {@link forge.card.mana.Mana} object.
+ * a {@link forge.card.mana.ManaPaid} object.
*/
- public final void findAndRemoveFrom(final ArrayList pool, final Mana mana) {
- Mana set = null;
- for (final Mana m : pool) {
+ public final void findAndRemoveFrom(final ArrayList pool, final ManaPaid mana) {
+ ManaPaid set = null;
+ for (final ManaPaid m : pool) {
if (m.getSourceCard().equals(mana.getSourceCard()) && m.getColor().equals(mana.getColor())) {
set = m;
break;
@@ -517,11 +517,11 @@ public class ManaPool {
* @param pool
* a {@link java.util.ArrayList} object.
* @param choice
- * a {@link forge.card.mana.Mana} object.
+ * a {@link forge.card.mana.ManaPaid} object.
* @param amount
* an int .
*/
- public final void removeManaFrom(final ArrayList pool, final Mana choice, final int amount) {
+ public final void removeManaFrom(final ArrayList pool, final ManaPaid choice, final int amount) {
if (choice != null) {
if (choice.getAmount() == amount) {
pool.remove(choice);
@@ -744,17 +744,17 @@ public class ManaPool {
return manaCost;
}
- final ArrayList payMana = sa.getPayingMana();
+ final ArrayList payMana = sa.getPayingMana();
// get a mana of this type from floating, bail if none available
- final Mana mana = this.getManaFrom(this.floatingMana, manaStr);
+ final ManaPaid mana = this.getManaFrom(this.floatingMana, manaStr);
if (mana == null) {
return manaCost; // no matching mana in the pool
}
- final Mana[] manaArray = mana.toSingleArray();
+ final ManaPaid[] manaArray = mana.toSingleArray();
- for (final Mana m : manaArray) {
+ for (final ManaPaid m : manaArray) {
if (manaCost.isNeeded(m)) {
manaCost.payMana(m);
payMana.add(m); // what is this used for? anything
@@ -775,7 +775,7 @@ public class ManaPool {
*/
public final int totalMana() {
int total = 0;
- for (final Mana c : this.floatingMana) {
+ for (final ManaPaid c : this.floatingMana) {
total += c.getAmount();
}
return total;
@@ -793,12 +793,12 @@ public class ManaPool {
*/
public final void clearPay(final SpellAbility ability, final boolean refund) {
final ArrayList payAbs = ability.getPayingManaAbilities();
- final ArrayList payMana = ability.getPayingMana();
+ final ArrayList payMana = ability.getPayingMana();
payAbs.clear();
// move non-undoable paying mana back to floating
if (refund) {
- for (final Mana m : payMana) {
+ for (final ManaPaid m : payMana) {
this.addManaToPool(this.floatingMana, m);
}
}
@@ -823,18 +823,18 @@ public class ManaPool {
*/
public final boolean accountFor(final SpellAbility sa, final String[] mana, final Card c) {
// TODO account for unpaying mana in payMana and floatingPool
- final ArrayList payMana = sa.getPayingMana();
+ final ArrayList payMana = sa.getPayingMana();
if ((payMana.size() == 0) && (this.floatingMana.size() == 0)) {
return false;
}
- final ArrayList removePaying = new ArrayList();
- final ArrayList removeFloating = new ArrayList();
+ final ArrayList removePaying = new ArrayList();
+ final ArrayList removeFloating = new ArrayList();
int manaAccounted = 0;
// loop over mana paid
- for (Mana manaPaid : payMana) {
+ for (ManaPaid manaPaid : payMana) {
if (manaPaid.fromSourceCard(c)) {
for (int i = 0; i < mana.length; i++) {
if (manaPaid.getColor().equals(InputPayManaCostUtil.getLongColorString(mana[i]))) {
@@ -860,7 +860,7 @@ public class ManaPool {
}
// loop over mana pool if not all of the generated mana is accounted for
if (manaAccounted < mana.length) {
- for (Mana manaFloat : this.floatingMana) {
+ for (ManaPaid manaFloat : this.floatingMana) {
if (manaFloat.fromSourceCard(c)) {
for (int i = 0; i < mana.length; i++) {
if (manaFloat.getColor().equals(InputPayManaCostUtil.getLongColorString(mana[i]))) {
diff --git a/src/main/java/forge/card/spellability/SpellAbility.java b/src/main/java/forge/card/spellability/SpellAbility.java
index cc17076de2e..5c0cd59d68d 100644
--- a/src/main/java/forge/card/spellability/SpellAbility.java
+++ b/src/main/java/forge/card/spellability/SpellAbility.java
@@ -27,7 +27,7 @@ import forge.CommandArgs;
import forge.GameEntity;
import forge.card.abilityfactory.AbilityFactory;
import forge.card.cost.Cost;
-import forge.card.mana.Mana;
+import forge.card.mana.ManaPaid;
import forge.control.input.Input;
import forge.game.player.ComputerUtil;
import forge.game.player.Player;
@@ -105,7 +105,7 @@ public abstract class SpellAbility {
private AbilityFactory abilityFactory = null;
- private final ArrayList payingMana = new ArrayList();
+ private final ArrayList payingMana = new ArrayList();
private final ArrayList paidAbilities = new ArrayList();
private HashMap paidLists = new HashMap();
@@ -812,7 +812,7 @@ public abstract class SpellAbility {
*
* @return a {@link java.util.ArrayList} object.
*/
- public ArrayList getPayingMana() {
+ public ArrayList getPayingMana() {
return this.payingMana;
}
diff --git a/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java b/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java
index 3295586471c..25a9536c35f 100644
--- a/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java
+++ b/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java
@@ -25,7 +25,7 @@ import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import forge.card.CardManaCost;
-import forge.card.CardManaCostShard;
+import forge.card.mana.ManaCostShard;
import forge.gui.toolbox.CardFaceSymbols;
/**
@@ -68,7 +68,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
final int genericManaCost = this.value.getGenericCost();
final boolean hasGeneric = (genericManaCost > 0) || this.value.isPureGeneric();
- final List shards = this.value.getShards();
+ final List shards = this.value.getShards();
final int cellWidth = this.getWidth();
final int cntGlyphs = hasGeneric ? shards.size() + 1 : shards.size();
@@ -82,7 +82,7 @@ public class ManaCostRenderer extends DefaultTableCellRenderer {
xpos += offset;
}
- for (final CardManaCostShard s : shards) {
+ for (final ManaCostShard s : shards) {
CardFaceSymbols.drawSymbol(s.getImageKey(), g, (int) xpos, 1);
xpos += offset;
}
diff --git a/src/main/java/forge/util/BinaryUtil.java b/src/main/java/forge/util/BinaryUtil.java
new file mode 100644
index 00000000000..b9e58891277
--- /dev/null
+++ b/src/main/java/forge/util/BinaryUtil.java
@@ -0,0 +1,17 @@
+package forge.util;
+
+/**
+ * TODO: Write javadoc for this type.
+ *
+ */
+public class BinaryUtil {
+
+ public static int bitCount(final int num) {
+ int v = num;
+ int c = 0;
+ for (; v != 0; c++) {
+ v &= v - 1;
+ }
+ return c;
+ } // bit count
+}