Switched mana to ManaCostShards, removed special classes for each mana kind

This commit is contained in:
Maxmtg
2012-05-14 23:21:42 +00:00
parent aa08dd7b0b
commit d883874286
20 changed files with 449 additions and 1326 deletions

13
.gitattributes vendored
View File

@@ -11649,7 +11649,6 @@ src/main/java/forge/card/CardCoreType.java -text
src/main/java/forge/card/CardEdition.java -text
src/main/java/forge/card/CardInSet.java -text
src/main/java/forge/card/CardManaCost.java -text
src/main/java/forge/card/CardManaCostShard.java -text
src/main/java/forge/card/CardRarity.java -text
src/main/java/forge/card/CardRuleCharacteristics.java -text
src/main/java/forge/card/CardRules.java -text
@@ -11734,14 +11733,11 @@ src/main/java/forge/card/cost/CostTapType.java -text
src/main/java/forge/card/cost/CostUntap.java -text
src/main/java/forge/card/cost/CostUtil.java -text
src/main/java/forge/card/cost/package-info.java svneol=native#text/plain
src/main/java/forge/card/mana/Mana.java svneol=native#text/plain
src/main/java/forge/card/mana/IParserManaCost.java -text
src/main/java/forge/card/mana/ManaCost.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPart.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPartColor.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPartColorless.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPartPhyrexian.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPartSnow.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPartSplit.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaCostParser.java -text
src/main/java/forge/card/mana/ManaCostShard.java -text
src/main/java/forge/card/mana/ManaPaid.java svneol=native#text/plain
src/main/java/forge/card/mana/ManaPool.java svneol=native#text/plain
src/main/java/forge/card/mana/package-info.java svneol=native#text/plain
src/main/java/forge/card/package-info.java svneol=native#text/plain
@@ -12131,6 +12127,7 @@ src/main/java/forge/quest/io/ReadPriceList.java svneol=native#text/plain
src/main/java/forge/quest/io/package-info.java svneol=native#text/plain
src/main/java/forge/quest/package-info.java svneol=native#text/plain
src/main/java/forge/util/Base64Coder.java svneol=native#text/plain
src/main/java/forge/util/BinaryUtil.java -text
src/main/java/forge/util/CopyFiles.java svneol=native#text/plain
src/main/java/forge/util/FileFinder.java svneol=native#text/plain
src/main/java/forge/util/FileSection.java -text

View File

@@ -760,24 +760,6 @@ public final class CardUtil {
return "none";
}
/**
* <p>
* getWeightedManaCost.
* </p>
*
* @param manaCost
* a {@link java.lang.String} object.
* @return a double.
*/
public static double getWeightedManaCost(final String manaCost) {
if (manaCost.equals("")) {
return 0;
}
final ManaCost cost = new ManaCost(manaCost);
return cost.getWeightedManaCost();
}
/**
* <p>
* getShortColorsString.

View File

@@ -19,9 +19,11 @@ package forge.card;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import forge.card.mana.ManaCostShard;
import forge.card.mana.IParserManaCost;
/**
* <p>
* CardManaCost class.
@@ -32,7 +34,7 @@ import java.util.List;
*/
public final class CardManaCost implements Comparable<CardManaCost> {
private final List<CardManaCostShard> shards;
private final List<ManaCostShard> shards;
private final int genericCost;
private final boolean hasNoCost; // lands cost
private final String stringValue; // precalculated for toString;
@@ -48,7 +50,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
private CardManaCost(int cmc) {
this.hasNoCost = cmc < 0;
this.genericCost = cmc < 0 ? 0 : cmc;
this.shards = Collections.unmodifiableList(new ArrayList<CardManaCostShard>());
this.shards = Collections.unmodifiableList(new ArrayList<ManaCostShard>());
this.stringValue = this.getSimpleString();
}
@@ -59,14 +61,14 @@ public final class CardManaCost implements Comparable<CardManaCost> {
* @param parser
* the parser
*/
public CardManaCost(final ManaParser parser) {
public CardManaCost(final IParserManaCost parser) {
if (!parser.hasNext()) {
throw new RuntimeException("Empty manacost passed to parser (this should have been handled before)");
}
final List<CardManaCostShard> shardsTemp = new ArrayList<CardManaCostShard>();
final List<ManaCostShard> shardsTemp = new ArrayList<ManaCostShard>();
this.hasNoCost = false;
while (parser.hasNext()) {
final CardManaCostShard shard = parser.next();
final ManaCostShard shard = parser.next();
if (shard != null) {
shardsTemp.add(shard);
} // null is OK - that was generic mana
@@ -90,7 +92,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
sb.append(this.genericCost);
isFirst = false;
}
for (final CardManaCostShard s : this.shards) {
for (final ManaCostShard s : this.shards) {
if (!isFirst) {
sb.append(' ');
} else {
@@ -108,7 +110,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
*/
public int getCMC() {
int sum = 0;
for (final CardManaCostShard s : this.shards) {
for (final ManaCostShard s : this.shards) {
sum += s.getCmc();
}
return sum + this.genericCost;
@@ -121,7 +123,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
*/
public byte getColorProfile() {
byte result = 0;
for (final CardManaCostShard s : this.shards) {
for (final ManaCostShard s : this.shards) {
result |= s.getColorMask();
}
return result;
@@ -132,7 +134,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
*
* @return the shards
*/
public List<CardManaCostShard> getShards() {
public List<ManaCostShard> getShards() {
return this.shards;
}
@@ -176,7 +178,7 @@ public final class CardManaCost implements Comparable<CardManaCost> {
private Float getCompareWeight() {
if (this.compareWeight == null) {
float weight = this.genericCost;
for (final CardManaCostShard s : this.shards) {
for (final ManaCostShard s : this.shards) {
weight += s.getCmpc();
}
if (this.hasNoCost) {
@@ -197,25 +199,12 @@ public final class CardManaCost implements Comparable<CardManaCost> {
return this.stringValue;
}
/**
* The Interface ManaParser.
*/
public interface ManaParser extends Iterator<CardManaCostShard> {
/**
* Gets the total colorless cost.
*
* @return the total colorless cost
*/
int getTotalColorlessCost();
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public boolean hasPhyrexian() {
for (CardManaCostShard shard : shards) {
for (ManaCostShard shard : shards) {
if (shard.isPhyrexian()) {
return true;
}
@@ -229,8 +218,8 @@ public final class CardManaCost implements Comparable<CardManaCost> {
*/
public int countX() {
int iX = 0;
for (CardManaCostShard shard : shards) {
if (shard == CardManaCostShard.X) {
for (ManaCostShard shard : shards) {
if (shard == ManaCostShard.X) {
iX++;
}
}

View File

@@ -21,7 +21,9 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import forge.card.CardManaCost.ManaParser;
import forge.card.mana.ManaCostShard;
import forge.card.mana.IParserManaCost;
/**
* <p>
@@ -220,7 +222,7 @@ public class CardRulesReader {
/**
* The Class ParserCardnameTxtManaCost.
*/
public static class ParserCardnameTxtManaCost implements ManaParser {
public static class ParserCardnameTxtManaCost implements IParserManaCost {
private final String[] cost;
private int nextToken;
private int colorlessCost;
@@ -267,7 +269,7 @@ public class CardRulesReader {
* @see java.util.Iterator#next()
*/
@Override
public final CardManaCostShard next() {
public final ManaCostShard next() {
final String unparsed = this.cost[this.nextToken++];
// System.out.println(unparsed);
@@ -280,34 +282,34 @@ public class CardRulesReader {
for (int iChar = 0; iChar < unparsed.length(); iChar++) {
switch (unparsed.charAt(iChar)) {
case 'W':
atoms |= CardManaCostShard.Atom.WHITE;
atoms |= ManaCostShard.Atom.WHITE;
break;
case 'U':
atoms |= CardManaCostShard.Atom.BLUE;
atoms |= ManaCostShard.Atom.BLUE;
break;
case 'B':
atoms |= CardManaCostShard.Atom.BLACK;
atoms |= ManaCostShard.Atom.BLACK;
break;
case 'R':
atoms |= CardManaCostShard.Atom.RED;
atoms |= ManaCostShard.Atom.RED;
break;
case 'G':
atoms |= CardManaCostShard.Atom.GREEN;
atoms |= ManaCostShard.Atom.GREEN;
break;
case '2':
atoms |= CardManaCostShard.Atom.OR_2_COLORLESS;
atoms |= ManaCostShard.Atom.OR_2_COLORLESS;
break;
case 'P':
atoms |= CardManaCostShard.Atom.OR_2_LIFE;
atoms |= ManaCostShard.Atom.OR_2_LIFE;
break;
case 'X':
atoms |= CardManaCostShard.Atom.IS_X;
atoms |= ManaCostShard.Atom.IS_X;
break;
default:
break;
}
}
return CardManaCostShard.valueOf(atoms);
return ManaCostShard.valueOf(atoms);
}
/*

View File

@@ -25,7 +25,8 @@ import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import forge.card.CardManaCost.ManaParser;
import forge.card.mana.ManaCostShard;
import forge.card.mana.IParserManaCost;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
import forge.util.FileUtil;
@@ -287,7 +288,7 @@ public final class MtgDataParser implements Iterator<CardRules> {
/**
* This is a mana-parser for mana written in curly braces like {2}{R}{B}.
*/
public static final class ManaParserMtgData implements ManaParser {
public static final class ManaParserMtgData implements IParserManaCost {
private final String cost;
private int nextBracket;
@@ -335,7 +336,7 @@ public final class MtgDataParser implements Iterator<CardRules> {
* @see java.util.Iterator#next()
*/
@Override
public CardManaCostShard next() {
public ManaCostShard next() {
final int closeBracket = this.cost.indexOf('}', this.nextBracket);
final String unparsed = this.cost.substring(this.nextBracket + 1, closeBracket);
this.nextBracket = this.cost.indexOf('{', closeBracket + 1);
@@ -350,34 +351,34 @@ public final class MtgDataParser implements Iterator<CardRules> {
for (int iChar = 0; iChar < unparsed.length(); iChar++) {
switch (unparsed.charAt(iChar)) {
case 'W':
atoms |= CardManaCostShard.Atom.WHITE;
atoms |= ManaCostShard.Atom.WHITE;
break;
case 'U':
atoms |= CardManaCostShard.Atom.BLUE;
atoms |= ManaCostShard.Atom.BLUE;
break;
case 'B':
atoms |= CardManaCostShard.Atom.BLACK;
atoms |= ManaCostShard.Atom.BLACK;
break;
case 'R':
atoms |= CardManaCostShard.Atom.RED;
atoms |= ManaCostShard.Atom.RED;
break;
case 'G':
atoms |= CardManaCostShard.Atom.GREEN;
atoms |= ManaCostShard.Atom.GREEN;
break;
case '2':
atoms |= CardManaCostShard.Atom.OR_2_COLORLESS;
atoms |= ManaCostShard.Atom.OR_2_COLORLESS;
break;
case 'P':
atoms |= CardManaCostShard.Atom.OR_2_LIFE;
atoms |= ManaCostShard.Atom.OR_2_LIFE;
break;
case 'X':
atoms |= CardManaCostShard.Atom.IS_X;
atoms |= ManaCostShard.Atom.IS_X;
break;
default:
break;
}
}
return CardManaCostShard.valueOf(atoms);
return ManaCostShard.valueOf(atoms);
}
/*

View File

@@ -0,0 +1,17 @@
package forge.card.mana;
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();
}

View File

@@ -20,9 +20,12 @@ package forge.card.mana;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import forge.Constant;
import forge.card.CardManaCost;
import forge.control.input.InputPayManaCostUtil;
/**
@@ -36,9 +39,8 @@ import forge.control.input.InputPayManaCostUtil;
public class ManaCost {
// holds Mana_Part objects
// ManaPartColor is stored before ManaPartColorless
private final ArrayList<ManaPart> manaPart;
private final HashMap<ManaCostShard, Integer> unpaidShards = new HashMap<ManaCostShard, Integer>();
private final HashMap<String, Integer> sunburstMap = new HashMap<String, Integer>();
private int xcounter = 0;
private final ArrayList<String> manaNeededToAvoidNegativeEffect = new ArrayList<String>();
private final ArrayList<String> manaPaidToAvoidNegativeEffect = new ArrayList<String>();
@@ -54,20 +56,17 @@ public class ManaCost {
* @param manaCost
* a {@link java.lang.String} object.
*/
public ManaCost(String manaCost) {
if (manaCost.equals("") || manaCost.equals("C")) {
manaCost = "0";
}
public ManaCost(String sCost) {
if ( "0".equals(sCost) || "C".equals(sCost) )
return;
while (manaCost.contains("X")) {
if (manaCost.length() < 2) {
manaCost = "0";
} else {
manaCost = manaCost.replaceFirst("X ", "");
}
this.setXcounter(this.getXcounter() + 1);
final CardManaCost manaCost = new CardManaCost(new ManaCostParser(sCost));
for(ManaCostShard shard : manaCost.getShards()) {
increaseShard(shard, 1);
}
this.manaPart = this.split(manaCost);
int generic = manaCost.getGenericCost();
if( generic > 0 )
unpaidShards.put(ManaCostShard.COLORLESS, Integer.valueOf(generic));
}
/**
@@ -119,18 +118,14 @@ public class ManaCost {
*
* @return a {@link java.util.ArrayList} object.
*/
private ArrayList<ManaPartPhyrexian> getUnpaidPhyrexianMana() {
final ArrayList<ManaPartPhyrexian> res = new ArrayList<ManaPartPhyrexian>();
for (final Object o : this.manaPart) {
if (o instanceof ManaPartPhyrexian) {
final ManaPartPhyrexian phy = (ManaPartPhyrexian) o;
if (!phy.isPaid()) {
res.add(phy);
}
}
private List<ManaCostShard> getUnpaidPhyrexianMana() {
ArrayList<ManaCostShard> res = new ArrayList<ManaCostShard>();
for(final Entry<ManaCostShard, Integer> part : this.unpaidShards.entrySet() )
{
if( !part.getKey().isPhyrexian() ) continue;
for(int i = 0; i < part.getValue(); i++)
res.add(part.getKey());
}
return res;
}
@@ -142,12 +137,9 @@ public class ManaCost {
* @return a boolean.
*/
public final boolean containsPhyrexianMana() {
for (final Object o : this.manaPart) {
if (o instanceof ManaPartPhyrexian) {
return true;
}
for(ManaCostShard shard : unpaidShards.keySet()) {
if ( shard.isPhyrexian() ) return true;
}
return false;
}
@@ -159,10 +151,12 @@ public class ManaCost {
* @return a boolean.
*/
public final boolean payPhyrexian() {
final ArrayList<ManaPartPhyrexian> phy = this.getUnpaidPhyrexianMana();
final List<ManaCostShard> phy = this.getUnpaidPhyrexianMana();
if (phy.size() > 0) {
phy.get(0).payLife();
Integer cnt = unpaidShards.get(phy.get(0));
if( cnt <= 1 ) unpaidShards.remove(phy.get(0));
else unpaidShards.put(phy.get(0), Integer.valueOf(cnt - 1));
return true;
}
@@ -182,11 +176,13 @@ public class ManaCost {
* @return a boolean.
*/
public final boolean isColor(final String color) {
for (final Object s : this.manaPart) {
if (s.toString().contains(color)
|| (s.toString().matches(".*[0-9].*") && "1".equals(color))) {
if ( "1".equals(color) ) return getColorlessManaAmount() > 0;
for(ManaCostShard shard : unpaidShards.keySet())
{
String ss = shard.toString();
if (ss.contains(color))
return true;
}
}
return false;
}
@@ -214,10 +210,8 @@ public class ManaCost {
if (mana.length() > 1) {
mana = InputPayManaCostUtil.getShortColorString(mana);
}
ManaPart m;
for (int i = 0; i < this.manaPart.size(); i++) {
m = (ManaPart) this.manaPart.get(i);
if (m.isNeeded(mana)) {
for(ManaCostShard shard : unpaidShards.keySet()) {
if (canBePaidWith(shard, mana)) {
return true;
}
}
@@ -229,18 +223,18 @@ public class ManaCost {
* isNeeded.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
* @param paid
* a {@link forge.card.mana.ManaPaid} object.
* @return a boolean.
*/
public final boolean isNeeded(final Mana mana) {
ManaPart m;
for (int i = 0; i < this.manaPart.size(); i++) {
m = (ManaPart) this.manaPart.get(i);
if (m.isNeeded(mana)) {
public final boolean isNeeded(final ManaPaid paid) {
for (ManaCostShard shard : unpaidShards.keySet()) {
if (canBePaidWith(shard, paid)) {
return true;
}
if ((m instanceof ManaPartSnow) && mana.isSnow()) {
if (shard.isSnow() && paid.isSnow()) {
return true;
}
}
@@ -255,14 +249,7 @@ public class ManaCost {
* @return a boolean.
*/
public final boolean isPaid() {
ManaPart m;
for (int i = 0; i < this.manaPart.size(); i++) {
m = (ManaPart) this.manaPart.get(i);
if (!m.isPaid()) {
return false;
}
}
return true;
return unpaidShards.isEmpty();
} // isPaid()
/**
@@ -271,10 +258,10 @@ public class ManaCost {
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
* a {@link forge.card.mana.ManaPaid} object.
* @return a boolean.
*/
public final boolean payMana(final Mana mana) {
public final boolean payMana(final ManaPaid mana) {
return this.addMana(mana);
}
@@ -304,21 +291,19 @@ public class ManaCost {
* a int.
*/
public final void increaseColorlessMana(final int manaToAdd) {
if (manaToAdd <= 0) {
return;
}
ManaPart m;
for (int i = 0; i < this.manaPart.size(); i++) {
m = (ManaPart) this.manaPart.get(i);
if (m instanceof ManaPartColorless) {
((ManaPartColorless) m).addToManaNeeded(manaToAdd);
return;
}
}
this.manaPart.add(new ManaPartColorless(manaToAdd));
increaseShard(ManaCostShard.COLORLESS, manaToAdd);
}
public final void increaseShard(final ManaCostShard shard, final int toAdd) {
if (toAdd <= 0) {
return;
}
Integer cnt = unpaidShards.get(shard);
unpaidShards.put(shard, Integer.valueOf(cnt == null || cnt == 0 ? toAdd : toAdd + cnt ));
}
/**
* <p>
* decreaseColorlessMana
@@ -330,25 +315,22 @@ public class ManaCost {
* cost.Used by Delve.
*/
public final void decreaseColorlessMana(final int manaToSubtract) {
decreaseShard(ManaCostShard.COLORLESS, manaToSubtract);
}
public final void decreaseShard(final ManaCostShard shard, final int manaToSubtract) {
if (manaToSubtract <= 0) {
return;
}
ManaPart m;
for (int i = 0; i < this.manaPart.size(); i++) {
m = (ManaPart) this.manaPart.get(i);
if (m instanceof ManaPartColorless) {
final int remainingColorless = ((ManaPartColorless) m).getManaNeeded() - manaToSubtract;
if (remainingColorless <= 0) {
this.manaPart.remove(m);
break;
} else {
this.manaPart.remove(m);
this.manaPart.add(new ManaPartColorless(remainingColorless));
}
}
}
Integer genericCnt = unpaidShards.get(shard);
if( null == genericCnt || genericCnt - manaToSubtract <= 0 )
unpaidShards.remove(shard);
else
unpaidShards.put(shard, Integer.valueOf(genericCnt - manaToSubtract));
}
/**
* <p>
@@ -360,12 +342,8 @@ public class ManaCost {
* @return an int.
*/
public final int getColorlessManaAmount() {
for (final Object m : this.manaPart) {
if (m instanceof ManaPartColorless) {
return ((ManaPartColorless) m).getManaNeeded();
}
}
return 0;
Integer genericCnt = unpaidShards.get(ManaCostShard.COLORLESS);
return genericCnt == null ? 0 : genericCnt;
}
/**
@@ -383,18 +361,17 @@ public class ManaCost {
//throw new RuntimeException("ManaCost : addMana() error, mana not needed - " + mana);
}
ManaPart choice = null;
for (int i = 0; i < this.manaPart.size(); i++) {
final ManaPart m = (ManaPart) this.manaPart.get(i);
if (m.isNeeded(mana)) {
ManaCostShard choice = null;
for(ManaCostShard toPay : unpaidShards.keySet())
{
if (canBePaidWith(toPay, mana)) {
// if m is a better to pay than choice
if (choice == null) {
choice = m;
choice = toPay;
continue;
}
if (m.isColor(mana) && choice.isEasierToPay(m)) {
choice = m;
if (isFisrtChoiceBetter(toPay, choice)) {
choice = toPay;
}
}
} // for
@@ -402,7 +379,7 @@ public class ManaCost {
return false;
}
choice.reduce(mana);
decreaseShard(choice, 1);
if (!mana.equals(Constant.Color.COLORLESS)) {
if (this.sunburstMap.containsKey(mana)) {
this.sunburstMap.put(mana, this.sunburstMap.get(mana) + 1);
@@ -413,32 +390,61 @@ public class ManaCost {
return true;
}
private boolean isFisrtChoiceBetter(ManaCostShard s1, ManaCostShard s2 ) {
return getPayPriority(s1) > getPayPriority(s2);
}
private int getPayPriority(ManaCostShard s1) {
if ( s1 == ManaCostShard.COLORLESS ) return 0;
if( s1.isMonoColor() ) {
if ( s1.isOr2Colorless() ) return 9;
if ( !s1.isPhyrexian() ) return 10;
return 8;
}
return 5;
}
private boolean canBePaidWith(ManaCostShard shard, ManaPaid mana) {
//System.err.println(String.format("ManaPaid: paying for %s with %s" , shard, mana));
// debug here even more;
return canBePaidWith(shard, InputPayManaCostUtil.getShortColorString(mana.getColor()) );
}
private boolean canBePaidWith(ManaCostShard shard, String mana) {
// most debug here!!
String sShard = shard.toString();
boolean res = "1".equals(sShard) || sShard.contains(mana);
//System.out.println(String.format("Str: paying for %s with %s => %d" , shard, mana, res ? 1 : 0));
return res;
}
/**
* <p>
* addMana.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
* a {@link forge.card.mana.ManaPaid} object.
* @return a boolean.
*/
public final boolean addMana(final Mana mana) {
public final boolean addMana(final ManaPaid mana) {
if (!this.isNeeded(mana)) {
throw new RuntimeException("ManaCost : addMana() error, mana not needed - " + mana);
}
ManaPart choice = null;
for (int i = 0; i < this.manaPart.size(); i++) {
final ManaPart m = (ManaPart) this.manaPart.get(i);
if (m.isNeeded(mana)) {
ManaCostShard choice = null;
for(ManaCostShard toPay : unpaidShards.keySet())
{
if (canBePaidWith(toPay, mana)) {
// if m is a better to pay than choice
if (choice == null) {
choice = m;
choice = toPay;
continue;
}
if (m.isColor(mana) && choice.isEasierToPay(m)) {
choice = m;
if (isFisrtChoiceBetter(toPay, choice)) {
choice = toPay;
}
}
} // for
@@ -446,7 +452,8 @@ public class ManaCost {
return false;
}
choice.reduce(mana);
decreaseShard(choice, 1);
if (!mana.isColor(Constant.Color.COLORLESS)) {
if (this.sunburstMap.containsKey(mana.getColor())) {
this.sunburstMap.put(mana.getColor(), this.sunburstMap.get(mana.getColor()) + 1);
@@ -466,35 +473,14 @@ public class ManaCost {
* a {@link java.lang.String} object.
*/
public final void combineManaCost(final String extra) {
final ArrayList<ManaPart> extraParts = this.split(extra);
ManaPartColorless part = null;
for (int i = 0; i < this.manaPart.size(); i++) {
final Object o = this.manaPart.get(i);
if (o instanceof ManaPartColorless) {
part = (ManaPartColorless) o;
}
}
if (part != null) {
this.manaPart.remove(part);
}
while (extraParts.size() > 0) {
final ManaPart o = extraParts.get(0);
if (o instanceof ManaPartColorless) {
if (part == null) {
part = (ManaPartColorless) o;
} else {
part.addToManaNeeded(((ManaPartColorless) o).getManaNeeded());
}
} else {
this.manaPart.add(o);
}
extraParts.remove(o);
}
if (part != null) {
this.manaPart.add(part);
final CardManaCost manaCost = new CardManaCost(new ManaCostParser(extra));
for(ManaCostShard shard : manaCost.getShards()) {
Integer cnt = unpaidShards.get(shard);
unpaidShards.put(shard, cnt == null ? Integer.valueOf(1) : Integer.valueOf(cnt + 1));
}
int generic = manaCost.getGenericCost() + this.getColorlessManaAmount();
if( generic > 0)
unpaidShards.put(ManaCostShard.COLORLESS, Integer.valueOf(generic));
}
/**
@@ -507,9 +493,6 @@ public class ManaCost {
public final String toString(final boolean addX) {
// Boolean addX used to add Xs into the returned value
final StringBuilder sb = new StringBuilder();
final ArrayList<Object> list = new ArrayList<Object>(this.manaPart);
// need to reverse everything since the colored mana is stored first
Collections.reverse(list);
if (addX) {
for (int i = 0; i < this.getXcounter(); i++) {
@@ -517,8 +500,15 @@ public class ManaCost {
}
}
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i).toString()).append(" ");
int nGeneric = getColorlessManaAmount();
if( nGeneric > 0 )
sb.append(nGeneric).append(" ");
for( Entry<ManaCostShard, Integer> s : unpaidShards.entrySet() ) {
if ( s.getKey() == ManaCostShard.COLORLESS) continue;
for (int i = 0; i < s.getValue(); i++) {
sb.append(s.getKey().toString()).append(" ");
}
}
final String str = sb.toString().trim();
@@ -545,120 +535,13 @@ public class ManaCost {
*/
public final int getConvertedManaCost() {
int cmc = 0;
for (final Object s : this.manaPart) {
cmc += ((ManaPart) s).getConvertedManaCost();
for (final Entry<ManaCostShard, Integer> s : this.unpaidShards.entrySet()) {
cmc += s.getKey().getCmc() * s.getValue();
}
return cmc;
}
/**
* Returns Mana cost, adjusted slightly to make colored mana parts more
* significant. Should only be used for comparison purposes; using this
* method allows the sort: 2 < X 2 < 1 U < U U == UR U < X U U < X X U U
*
* @return The converted cost + 0.0001* the number of colored mana in the
* cost + 0.00001 * the number of X's in the cost
*/
public final double getWeightedManaCost() {
double cmc = 0;
for (final Object s : this.manaPart) {
cmc += ((ManaPart) s).getConvertedManaCost();
if (s instanceof ManaPartColor) {
cmc += 0.0001;
}
}
cmc += 0.00001 * this.getXcounter();
return cmc;
}
/**
* <p>
* split.
* </p>
*
* @param cost
* a {@link java.lang.String} object.
* @return a {@link java.util.ArrayList} object.
*/
private ArrayList<ManaPart> split(final String cost) {
final ArrayList<ManaPart> list = new ArrayList<ManaPart>();
// 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()
/**
* <p>
* Getter for the field <code>manaPart</code>.
* </p>
*
* @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);
}
}
/**
* <p>
* Setter for the field <code>xcounter</code>.
* </p>
*
* @param xcounter
* a int.
*/
public final void setXcounter(final int xcounter) {
this.xcounter = xcounter;
}
/**
* <p>
* Getter for the field <code>xcounter</code>.
@@ -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);
}
/**

View File

@@ -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
}

View File

@@ -15,12 +15,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@@ -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.
* </p>
*
* @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;
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
/**
* <p>
* Abstract Mana_Part class.
* </p>
*
* @author Forge
* @version $Id$
*/
public abstract class ManaPart {
/** {@inheritDoc} */
@Override
public abstract String toString();
/**
* <p>
* reduce.
* </p>
*
* @param mana
* a {@link java.lang.String} object.
*/
public abstract void reduce(String mana);
/**
* <p>
* reduce.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
*/
public abstract void reduce(Mana mana);
/**
* <p>
* isPaid.
* </p>
*
* @return a boolean.
*/
public abstract boolean isPaid();
/**
* <p>
* isNeeded.
* </p>
*
* @param mana
* a {@link java.lang.String} object.
* @return a boolean.
*/
public abstract boolean isNeeded(String mana);
/**
* <p>
* isNeeded.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
* @return a boolean.
*/
public abstract boolean isNeeded(Mana mana);
/**
* <p>
* isColor.
* </p>
*
* @param mana
* a {@link java.lang.String} object.
* @return a boolean.
*/
public abstract boolean isColor(String mana);
/**
* <p>
* isColor.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
* @return a boolean.
*/
public abstract boolean isColor(Mana mana);
/**
* <p>
* isEasierToPay.
* </p>
*
* @param mp
* a {@link forge.card.mana.ManaPart} object.
* @return a boolean.
*/
public abstract boolean isEasierToPay(ManaPart mp);
/**
* <p>
* getConvertedManaCost.
* </p>
*
* @return a int.
*/
public abstract int getConvertedManaCost();
/**
* <p>
* checkSingleMana.
* </p>
*
* @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);
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
import forge.control.input.InputPayManaCostUtil;
/**
* <p>
* Mana_PartColor class.
* </p>
*
* @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
/**
* <p>
* Constructor for Mana_PartColor.
* </p>
*
* @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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
import forge.error.ErrorViewer;
/**
* <p>
* Mana_PartColorless class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class ManaPartColorless extends ManaPart {
private int manaNeeded;
/**
* <p>
* addToManaNeeded.
* </p>
*
* @param additional
* a int.
*/
public final void addToManaNeeded(final int additional) {
this.manaNeeded += additional;
}
/**
* <p>
* Getter for the field <code>manaNeeded</code>.
* </p>
*
* @return a int.
*/
public final int getManaNeeded() {
return this.manaNeeded;
}
// String manaCostToPay is like "1", "4", but NO COLOR
/**
* <p>
* Constructor for Mana_PartColorless.
* </p>
*
* @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);
}
}
/**
* <p>
* Constructor for Mana_PartColorless.
* </p>
*
* @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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
/**
* <p>
* Mana_PartPhyrexian class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class ManaPartPhyrexian extends ManaPart {
private final ManaPartColor wrappedColor;
private final String color;
/**
* <p>
* Constructor for Mana_PartPhyrexian.
* </p>
*
* @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;
}
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
@Override
public final String toString() {
return this.wrappedColor.toString().equals("") ? "" : "P" + this.wrappedColor.toString();
}
/**
* <p>
* isPaid.
* </p>
*
* @return a boolean.
*/
@Override
public final boolean isPaid() {
return this.wrappedColor.isPaid();
}
/**
* {@inheritDoc}
*
* <p>
* isColor.
* </p>
*
* @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);
}
/**
* <p>
* isNeeded.
* </p>
*
* @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}
*
* <p>
* reduce.
* </p>
*
* @param mana
* a {@link forge.card.mana.Mana} object.
*/
@Override
public final void reduce(final Mana mana) {
this.wrappedColor.reduce(mana);
}
/**
* <p>
* getConvertedManaCost.
* </p>
*
* @return a int.
*/
@Override
public final int getConvertedManaCost() {
return this.wrappedColor.getConvertedManaCost();
}
/**
* <p>
* payLife.
* </p>
*/
public final void payLife() {
this.wrappedColor.reduce(this.color);
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
/**
* <p>
* Mana_PartSnow class.
* </p>
*
* @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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
import forge.control.input.InputPayManaCostUtil;
//handles mana costs like 2/R or 2/B
//for cards like Flame Javelin (Shadowmoor)
/**
* <p>
* Mana_PartSplit class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class ManaPartSplit extends ManaPart {
private ManaPart manaPart = null;
private String originalCost = "";
/**
* <p>
* Constructor for Mana_PartSplit.
* </p>
*
* @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;
}
/**
* <p>
* isFirstTime.
* </p>
*
* @return a boolean.
*/
private boolean isFirstTime() {
return this.manaPart == null;
}
/**
* <p>
* setup.
* </p>
*
* @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));
}
}

View File

@@ -43,7 +43,7 @@ import forge.gui.GuiUtils;
public class ManaPool {
// current paying moved to SpellAbility
private final ArrayList<Mana> floatingMana = new ArrayList<Mana>();
private final ArrayList<ManaPaid> floatingMana = new ArrayList<ManaPaid>();
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<Mana> pool, final Mana mana) {
public final void addManaToPool(final ArrayList<ManaPaid> 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<Mana> manaList = ManaPool.convertStringToMana(manaStr, card);
for (final Mana m : manaList) {
final ArrayList<ManaPaid> 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<Mana> convertStringToMana(String manaStr, final Card card) {
final ArrayList<Mana> manaList = new ArrayList<Mana>();
public static ArrayList<ManaPaid> convertStringToMana(String manaStr, final Card card) {
final ArrayList<ManaPaid> manaList = new ArrayList<ManaPaid>();
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<Mana> pool, final String manaStr) {
public final ManaPaid getManaFrom(final ArrayList<ManaPaid> 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<Mana> manaChoices = new ArrayList<Mana>();
ManaPaid choice = null;
final ArrayList<ManaPaid> manaChoices = new ArrayList<ManaPaid>();
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<Mana> pool, final Mana mana) {
Mana set = null;
for (final Mana m : pool) {
public final void findAndRemoveFrom(final ArrayList<ManaPaid> 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<Mana> pool, final Mana choice, final int amount) {
public final void removeManaFrom(final ArrayList<ManaPaid> 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<Mana> payMana = sa.getPayingMana();
final ArrayList<ManaPaid> 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<AbilityMana> payAbs = ability.getPayingManaAbilities();
final ArrayList<Mana> payMana = ability.getPayingMana();
final ArrayList<ManaPaid> 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<Mana> payMana = sa.getPayingMana();
final ArrayList<ManaPaid> payMana = sa.getPayingMana();
if ((payMana.size() == 0) && (this.floatingMana.size() == 0)) {
return false;
}
final ArrayList<Mana> removePaying = new ArrayList<Mana>();
final ArrayList<Mana> removeFloating = new ArrayList<Mana>();
final ArrayList<ManaPaid> removePaying = new ArrayList<ManaPaid>();
final ArrayList<ManaPaid> removeFloating = new ArrayList<ManaPaid>();
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]))) {

View File

@@ -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<Mana> payingMana = new ArrayList<Mana>();
private final ArrayList<ManaPaid> payingMana = new ArrayList<ManaPaid>();
private final ArrayList<AbilityMana> paidAbilities = new ArrayList<AbilityMana>();
private HashMap<String, CardList> paidLists = new HashMap<String, CardList>();
@@ -812,7 +812,7 @@ public abstract class SpellAbility {
*
* @return a {@link java.util.ArrayList} object.
*/
public ArrayList<Mana> getPayingMana() {
public ArrayList<ManaPaid> getPayingMana() {
return this.payingMana;
}

View File

@@ -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<CardManaCostShard> shards = this.value.getShards();
final List<ManaCostShard> 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;
}

View File

@@ -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
}