mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Revert "Mana Class Overhaul"
This commit is contained in:
parent
02c1b9f22f
commit
c4ab5806e0
16 changed files with 192 additions and 1070 deletions
|
|
@ -28,32 +28,19 @@
|
|||
package mage;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.ManaType;
|
||||
import static mage.constants.ManaType.COLORLESS;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.util.Copyable;
|
||||
import mage.util.Logging;
|
||||
import mage.util.ThreadLocalStringBuilder;
|
||||
|
||||
/**
|
||||
* Representation of a mana pool. Can contain colored and colorless mana.
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
||||
|
||||
private static Logger logger = Logging.getLogger(Mana.class.getName());
|
||||
|
||||
public static final String RED = "RED";
|
||||
public static final String GREEN = "GREEN";
|
||||
public static final String BLUE = "BLUE";
|
||||
public static final String WHITE = "WHITE";
|
||||
public static final String BLACK = "BLACK";
|
||||
public static final String COLORLESS = "COLORLESS";
|
||||
public static final String ANY = "ANY";
|
||||
|
||||
protected int red;
|
||||
protected int green;
|
||||
protected int blue;
|
||||
|
|
@ -63,7 +50,6 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
protected int any;
|
||||
protected boolean flag = false;
|
||||
|
||||
//todo unsafe and mutable
|
||||
public static final Mana RedMana = RedMana(1);
|
||||
public static final Mana GreenMana = GreenMana(1);
|
||||
public static final Mana BlueMana = BlueMana(1);
|
||||
|
|
@ -74,13 +60,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
public Mana() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param mana The {@link Mana} to copy from. Can not be null.
|
||||
*/
|
||||
public Mana(final Mana mana) {
|
||||
Objects.requireNonNull(mana, "The passed in Mana can not be null");
|
||||
this.red = mana.red;
|
||||
this.green = mana.green;
|
||||
this.blue = mana.blue;
|
||||
|
|
@ -91,38 +71,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
this.flag = mana.flag;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with the mana passed in.
|
||||
*
|
||||
* @param red Total red mana to add.
|
||||
* @param green Total green mana to add.
|
||||
* @param blue Total blue mana to add.
|
||||
* @param white Total white mana to add.
|
||||
* @param black Total black mana to add.
|
||||
* @param colorless Total colorless mana to add.
|
||||
* @param any Total any colored mana to add.
|
||||
*/
|
||||
public Mana(final int red, final int green, final int blue, final int white,
|
||||
final int black, final int colorless, final int any) {
|
||||
this.red = notNegative(red, RED);
|
||||
this.green = notNegative(green, GREEN);
|
||||
this.blue = notNegative(blue, BLUE);
|
||||
this.white = notNegative(white, WHITE);
|
||||
this.black = notNegative(black, BLACK);
|
||||
this.colorless = notNegative(colorless, COLORLESS);
|
||||
this.any = notNegative(any, ANY);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object from the {@link ColoredManaSymbol} {@code color}.
|
||||
*
|
||||
* @param color The {@link ColoredManaSymbol} to create {@link Mana} from.
|
||||
* Can not be null.
|
||||
*/
|
||||
public Mana(final ColoredManaSymbol color) {
|
||||
Objects.requireNonNull(color, "The passed in ColoredManaSymbol can not be null");
|
||||
public Mana(ColoredManaSymbol color) {
|
||||
switch (color) {
|
||||
case G:
|
||||
green = 1;
|
||||
|
|
@ -139,154 +88,95 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
case W:
|
||||
white = 1;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown color " + color.getColorName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} Red mana.
|
||||
*
|
||||
* @param num The amount of Red mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} Red mana.
|
||||
*/
|
||||
public static Mana RedMana(final int num) {
|
||||
return new Mana(notNegative(num, RED), 0, 0, 0, 0, 0, 0);
|
||||
public static Mana RedMana(int num) {
|
||||
return new Mana(num, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} Green mana.
|
||||
*
|
||||
* @param num The amount of Green mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} Green mana.
|
||||
*/
|
||||
public static Mana GreenMana(final int num) {
|
||||
return new Mana(0, notNegative(num, GREEN), 0, 0, 0, 0, 0);
|
||||
public static Mana GreenMana(int num) {
|
||||
return new Mana(0, num, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} Blue mana.
|
||||
*
|
||||
* @param num The amount of Blue mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} Blue mana.
|
||||
*/
|
||||
public static Mana BlueMana(final int num) {
|
||||
return new Mana(0, 0, notNegative(num, BLUE), 0, 0, 0, 0);
|
||||
public static Mana BlueMana(int num) {
|
||||
return new Mana(0, 0, num, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} White mana.
|
||||
*
|
||||
* @param num The amount of White mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} White mana.
|
||||
*/
|
||||
public static Mana WhiteMana(final int num) {
|
||||
return new Mana(0, 0, 0, notNegative(num, WHITE), 0, 0, 0);
|
||||
public static Mana WhiteMana(int num) {
|
||||
return new Mana(0, 0, 0, num, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} Black mana.
|
||||
*
|
||||
* @param num The amount of Black mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} Black mana.
|
||||
*/
|
||||
public static Mana BlackMana(final int num) {
|
||||
return new Mana(0, 0, 0, 0, notNegative(num, BLACK), 0, 0);
|
||||
public static Mana BlackMana(int num) {
|
||||
return new Mana(0, 0, 0, 0, num, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with {@code num} Colorless mana.
|
||||
*
|
||||
* @param num The amount of Colorless mana to add. Can not be negative.
|
||||
* @return {@link Mana} object with {@code num} Colorless mana.
|
||||
*/
|
||||
public static Mana ColorlessMana(final int num) {
|
||||
return new Mana(0, 0, 0, 0, 0, notNegative(num, COLORLESS), 0);
|
||||
public static Mana ColorlessMana(int num) {
|
||||
return new Mana(0, 0, 0, 0, 0, num, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Increases the mana in this object by the relative mana in the passed in {@link Mana} object.
|
||||
*
|
||||
* @param mana {@link Mana} object to increase this mana by.
|
||||
*/
|
||||
public void add(final Mana mana) {
|
||||
red += mana.red;
|
||||
green += mana.green;
|
||||
blue += mana.blue;
|
||||
white += mana.white;
|
||||
black += mana.black;
|
||||
colorless += mana.colorless;
|
||||
any += mana.any;
|
||||
public Mana(int red, int green, int blue, int white, int black, int colorless, int any) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.white = white;
|
||||
this.black = black;
|
||||
this.colorless = colorless;
|
||||
this.any = any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the Red mana by one.
|
||||
*/
|
||||
public void increaseRed() {
|
||||
public void add(Mana mana) {
|
||||
red += mana.getRed();
|
||||
green += mana.getGreen();
|
||||
blue += mana.getBlue();
|
||||
white += mana.getWhite();
|
||||
black += mana.getBlack();
|
||||
colorless += mana.getColorless();
|
||||
any += mana.getAny();
|
||||
}
|
||||
|
||||
public void addRed() {
|
||||
red++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the Green mana by one.
|
||||
*/
|
||||
public void increaseGreen() {
|
||||
public void addGreen() {
|
||||
green++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the Blue mana by one.
|
||||
*/
|
||||
public void increaseBlue() {
|
||||
public void addBlue() {
|
||||
blue++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the White mana by one.
|
||||
*/
|
||||
public void increaseWhite() {
|
||||
public void addWhite() {
|
||||
white++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the Black mana by one.
|
||||
*/
|
||||
public void increaseBlack() {
|
||||
public void addBlack() {
|
||||
black++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the Colorless mana by one.
|
||||
*/
|
||||
public void increaseColorless() {
|
||||
public void addColorless() {
|
||||
colorless++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subtracts the passed in mana values from this instance. Will not
|
||||
* reduce this instances mana below 0.
|
||||
*
|
||||
* @param mana mana values to subtract
|
||||
*/
|
||||
public void subtract(final Mana mana) {
|
||||
red -= mana.red;
|
||||
green -= mana.green;
|
||||
blue -= mana.blue;
|
||||
white -= mana.white;
|
||||
black -= mana.black;
|
||||
colorless -= mana.colorless;
|
||||
any -= mana.any;
|
||||
public void subtract(Mana mana) {
|
||||
red -= mana.getRed();
|
||||
green -= mana.getGreen();
|
||||
blue -= mana.getBlue();
|
||||
white -= mana.getWhite();
|
||||
black -= mana.getBlack();
|
||||
colorless -= mana.getColorless();
|
||||
any -= mana.getAny();
|
||||
}
|
||||
|
||||
public void subtractCost(Mana cost) {
|
||||
red -= cost.red;
|
||||
green -= cost.green;
|
||||
blue -= cost.blue;
|
||||
white -= cost.white;
|
||||
black -= cost.black;
|
||||
any -= cost.any;
|
||||
colorless -= cost.colorless;
|
||||
|
||||
red -= cost.getRed();
|
||||
green -= cost.getGreen();
|
||||
blue -= cost.getBlue();
|
||||
white -= cost.getWhite();
|
||||
black -= cost.getBlack();
|
||||
any -= cost.getAny();
|
||||
colorless -= cost.getColorless();
|
||||
while (colorless < 0) {
|
||||
int oldColorless = colorless;
|
||||
if (red > 0) {
|
||||
|
|
@ -323,72 +213,15 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this object's mana to be equal to the passed in {@code mana}
|
||||
*
|
||||
* @param mana the mana to copy from
|
||||
*/
|
||||
public void setToMana(final Mana mana) {
|
||||
any = mana.any;
|
||||
red = mana.red;
|
||||
green = mana.green;
|
||||
white = mana.white;
|
||||
blue = mana.blue;
|
||||
black = mana.black;
|
||||
colorless = mana.colorless;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total mana count.
|
||||
*
|
||||
* @return the total mana count.
|
||||
*/
|
||||
public int count() {
|
||||
return red + green + blue + white + black + colorless + any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total colored mana count.
|
||||
*
|
||||
* @return the total colored mana count.
|
||||
*/
|
||||
public int countColored() {
|
||||
return red + green + blue + white + black + any;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns how many colors are currently more than 0.
|
||||
*
|
||||
* @return how many colors are currently more than 0.
|
||||
*/
|
||||
public int getDifferentColors() {
|
||||
int count = 0;
|
||||
if (blue > 0) {
|
||||
count++;
|
||||
}
|
||||
if (black > 0) {
|
||||
count++;
|
||||
}
|
||||
if (green > 0) {
|
||||
count++;
|
||||
}
|
||||
if (white > 0) {
|
||||
count++;
|
||||
}
|
||||
if (red > 0) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total mana with a {@link FilterMana} applied.
|
||||
*
|
||||
* @param filter the filter to apply when counting mana
|
||||
* @return the total mana after filtration.
|
||||
*/
|
||||
public int count(final FilterMana filter) {
|
||||
public int count(FilterMana filter) {
|
||||
if (filter == null) {
|
||||
return count();
|
||||
}
|
||||
|
|
@ -414,9 +247,6 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets all mana to 0
|
||||
*/
|
||||
public void clear() {
|
||||
red = 0;
|
||||
green = 0;
|
||||
|
|
@ -427,11 +257,6 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
any = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link String} of internal state.
|
||||
*
|
||||
* @return text version of internal state.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sbMana = new StringBuilder();
|
||||
|
|
@ -459,24 +284,14 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return sbMana.toString();
|
||||
}
|
||||
|
||||
private static final transient ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(10);
|
||||
|
||||
/**
|
||||
* Returns a deep copy of this object
|
||||
*
|
||||
* @return a deep copy of this object
|
||||
*/
|
||||
@Override
|
||||
public Mana copy() {
|
||||
return new Mana(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if there is enough mana available compared to the passed in {@link Mana}
|
||||
*
|
||||
* @param avail value to compare with
|
||||
* @return if there is enough mana in the mana pool compared to the passed in {@link Mana}
|
||||
*/
|
||||
public boolean enough(final Mana avail) {
|
||||
public boolean enough(Mana avail) {
|
||||
Mana compare = avail.copy();
|
||||
compare.subtract(this);
|
||||
if (compare.getRed() < 0) {
|
||||
|
|
@ -523,13 +338,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how much mana is needed to meet the passed in cost
|
||||
*
|
||||
* @param avail mana cost to meet
|
||||
* @return how much mana is needed to meet the passed in cost
|
||||
*/
|
||||
public Mana needed(final Mana avail) {
|
||||
public Mana needed(Mana avail) {
|
||||
Mana compare = avail.copy();
|
||||
compare.subtract(this);
|
||||
if (compare.getRed() < 0 && compare.getAny() > 0) {
|
||||
|
|
@ -596,8 +405,8 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return red;
|
||||
}
|
||||
|
||||
public void setRed(final int red) {
|
||||
this.red = notNegative(red, "Red");
|
||||
public void setRed(int red) {
|
||||
this.red = red;
|
||||
}
|
||||
|
||||
public int getGreen() {
|
||||
|
|
@ -605,7 +414,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setGreen(int green) {
|
||||
this.green = notNegative(green, "Green");
|
||||
this.green = green;
|
||||
}
|
||||
|
||||
public int getBlue() {
|
||||
|
|
@ -613,7 +422,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setBlue(int blue) {
|
||||
this.blue = notNegative(blue, "Blue");
|
||||
this.blue = blue;
|
||||
}
|
||||
|
||||
public int getWhite() {
|
||||
|
|
@ -621,7 +430,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setWhite(int white) {
|
||||
this.white = notNegative(white, "White");
|
||||
this.white = white;
|
||||
}
|
||||
|
||||
public int getBlack() {
|
||||
|
|
@ -629,7 +438,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setBlack(int black) {
|
||||
this.black = notNegative(black, "Black");
|
||||
this.black = black;
|
||||
}
|
||||
|
||||
public int getColorless() {
|
||||
|
|
@ -637,7 +446,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setColorless(int colorless) {
|
||||
this.colorless = notNegative(colorless, "Colorless");
|
||||
this.colorless = colorless;
|
||||
}
|
||||
|
||||
public int getAny() {
|
||||
|
|
@ -645,51 +454,43 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
|
||||
public void setAny(int any) {
|
||||
this.any = notNegative(any, "Any");
|
||||
this.any = any;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(final Mana o) {
|
||||
return count() - o.count();
|
||||
public int compareTo(Mana o) {
|
||||
return this.count() - o.count();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param mana
|
||||
* @return true if this contains any values that mana has
|
||||
*/
|
||||
// todo what purpose does this serve?
|
||||
// todo what if you want to check for red, and you have black?
|
||||
public boolean contains(Mana mana) {
|
||||
if (mana.black > 0 && black > 0) {
|
||||
if (mana.black > 0 && this.black > 0) {
|
||||
return true;
|
||||
}
|
||||
if (mana.blue > 0 && blue > 0) {
|
||||
if (mana.blue > 0 && this.blue > 0) {
|
||||
return true;
|
||||
}
|
||||
if (mana.red > 0 && red > 0) {
|
||||
if (mana.red > 0 && this.red > 0) {
|
||||
return true;
|
||||
}
|
||||
if (mana.white > 0 && white > 0) {
|
||||
if (mana.white > 0 && this.white > 0) {
|
||||
return true;
|
||||
}
|
||||
if (mana.green > 0 && green > 0) {
|
||||
if (mana.green > 0 && this.green > 0) {
|
||||
return true;
|
||||
}
|
||||
if (mana.colorless > 0 && count() > 0) {
|
||||
if (mana.colorless > 0 && this.count() > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total color based on the {@link ColoredManaSymbol} passed in
|
||||
*
|
||||
* @param color the {@link ColoredManaSymbol} to get mana for
|
||||
* @return the total color based on the {@link ColoredManaSymbol} passed in
|
||||
*/
|
||||
public int getColor(final ColoredManaSymbol color) {
|
||||
public int getColor(ColoredManaSymbol color) {
|
||||
if (color.equals(ColoredManaSymbol.G)) {
|
||||
return getGreen();
|
||||
}
|
||||
|
|
@ -708,13 +509,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total color based on the {@link ManaType} passed in
|
||||
*
|
||||
* @param manaType the {@link ManaType} to return the color for
|
||||
* @return the total color based on the {@link ManaType} passed in
|
||||
*/
|
||||
public int get(final ManaType manaType) {
|
||||
public int get(ManaType manaType) {
|
||||
switch (manaType) {
|
||||
case BLACK:
|
||||
return black;
|
||||
|
|
@ -732,14 +527,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total mana based on the passed int {@code manaType} and {@code amount}
|
||||
*
|
||||
* @param manaType the type of mana
|
||||
* @param amount the amount to set the mana to, can not be negative
|
||||
*/
|
||||
public void set(final ManaType manaType, final int amount) {
|
||||
notNegative(amount, manaType.toString());
|
||||
public void set(ManaType manaType, int amount) {
|
||||
switch (manaType) {
|
||||
case BLACK:
|
||||
black = amount;
|
||||
|
|
@ -762,7 +550,6 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
}
|
||||
}
|
||||
|
||||
//todo not sure what this does, should we add some documentation of what a flag is?
|
||||
public void setFlag(boolean flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
|
@ -771,21 +558,24 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return flag;
|
||||
}
|
||||
|
||||
public void setToMana(Mana mana) {
|
||||
this.any = mana.any;
|
||||
this.red = mana.red;
|
||||
this.green = mana.green;
|
||||
this.white = mana.white;
|
||||
this.blue = mana.blue;
|
||||
this.black = mana.black;
|
||||
this.colorless = mana.colorless;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this object has the same mana values as the passed in {@link Mana}
|
||||
*
|
||||
* @param mana the {@link Mana} to compare to
|
||||
* @return if both {@link Mana} objects have the same mana values
|
||||
*/
|
||||
public boolean equalManaValue(final Mana mana) {
|
||||
return any == mana.any
|
||||
&& red == mana.red
|
||||
&& green == mana.green
|
||||
&& white == mana.white
|
||||
&& blue == mana.blue
|
||||
&& black == mana.black
|
||||
&& colorless == mana.colorless;
|
||||
public boolean equalManaValue(Mana mana) {
|
||||
return this.any == mana.any
|
||||
&& this.red == mana.red
|
||||
&& this.green == mana.green
|
||||
&& this.white == mana.white
|
||||
&& this.blue == mana.blue
|
||||
&& this.black == mana.black
|
||||
&& this.colorless == mana.colorless;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -796,13 +586,14 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
* @return
|
||||
*/
|
||||
public boolean includesMana(Mana mana) {
|
||||
return green >= mana.green
|
||||
&& blue >= mana.blue
|
||||
&& white >= mana.white
|
||||
&& black >= mana.black
|
||||
&& red >= mana.red
|
||||
&& (colorless >= mana.colorless
|
||||
|| countColored() >= mana.countColored() + mana.colorless);
|
||||
return this.green >= mana.green
|
||||
&& this.blue >= mana.blue
|
||||
&& this.white >= mana.white
|
||||
&& this.black >= mana.black
|
||||
&& this.red >= mana.red
|
||||
&& (this.colorless >= mana.colorless
|
||||
|| this.countColored() >= mana.countColored() + mana.colorless);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -837,49 +628,23 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return moreMana;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to check if a passed in value is less than 0. Log if the value is.
|
||||
*
|
||||
* @param value The value to check
|
||||
* @param valueName The name of the value
|
||||
* @return 0 if less than 0, or the value if more than 0
|
||||
*/
|
||||
private static int notNegative(int value, final String valueName) {
|
||||
if (value < 0) {
|
||||
logger.info(valueName + " can not be set to less than 0. Setting to 0");
|
||||
value = 0;
|
||||
public int getDifferentColors() {
|
||||
int count = 0;
|
||||
if (blue > 0) {
|
||||
count++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Mana mana = (Mana) o;
|
||||
|
||||
if (red != mana.red) return false;
|
||||
if (green != mana.green) return false;
|
||||
if (blue != mana.blue) return false;
|
||||
if (white != mana.white) return false;
|
||||
if (black != mana.black) return false;
|
||||
if (colorless != mana.colorless) return false;
|
||||
if (any != mana.any) return false;
|
||||
return flag == mana.flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = red;
|
||||
result = 31 * result + green;
|
||||
result = 31 * result + blue;
|
||||
result = 31 * result + white;
|
||||
result = 31 * result + black;
|
||||
result = 31 * result + colorless;
|
||||
result = 31 * result + any;
|
||||
result = 31 * result + (flag ? 1 : 0);
|
||||
return result;
|
||||
if (black > 0) {
|
||||
count++;
|
||||
}
|
||||
if (green > 0) {
|
||||
count++;
|
||||
}
|
||||
if (white > 0) {
|
||||
count++;
|
||||
}
|
||||
if (red > 0) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,31 +118,31 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
|
|||
switch (mana) {
|
||||
case B:
|
||||
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game)) {
|
||||
this.payment.increaseBlack();
|
||||
this.payment.addBlack();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case U:
|
||||
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game)) {
|
||||
this.payment.increaseBlue();
|
||||
this.payment.addBlue();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case W:
|
||||
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game)) {
|
||||
this.payment.increaseWhite();
|
||||
this.payment.addWhite();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case G:
|
||||
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game)) {
|
||||
this.payment.increaseGreen();
|
||||
this.payment.addGreen();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case R:
|
||||
if (pool.pay(ManaType.RED, ability, sourceFilter, game)) {
|
||||
this.payment.increaseRed();
|
||||
this.payment.addRed();
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
|
@ -154,27 +154,27 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
|
|||
int conditionalCount = pool.getConditionalCount(ability, game, null);
|
||||
while (mana > payment.count() && (pool.count() > 0 || conditionalCount > 0)) {
|
||||
if (pool.pay(ManaType.COLORLESS, ability, sourceFilter, game)) {
|
||||
this.payment.increaseColorless();
|
||||
this.payment.addColorless();
|
||||
continue;
|
||||
}
|
||||
if (pool.pay(ManaType.BLACK, ability, sourceFilter, game)) {
|
||||
this.payment.increaseBlack();
|
||||
this.payment.addBlack();
|
||||
continue;
|
||||
}
|
||||
if (pool.pay(ManaType.BLUE, ability, sourceFilter, game)) {
|
||||
this.payment.increaseBlue();
|
||||
this.payment.addBlue();
|
||||
continue;
|
||||
}
|
||||
if (pool.pay(ManaType.WHITE, ability, sourceFilter, game)) {
|
||||
this.payment.increaseWhite();
|
||||
this.payment.addWhite();
|
||||
continue;
|
||||
}
|
||||
if (pool.pay(ManaType.GREEN, ability, sourceFilter, game)) {
|
||||
this.payment.increaseGreen();
|
||||
this.payment.addGreen();
|
||||
continue;
|
||||
}
|
||||
if (pool.pay(ManaType.RED, ability, sourceFilter, game)) {
|
||||
this.payment.increaseRed();
|
||||
this.payment.addRed();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -154,15 +154,15 @@ public class DynamicManaEffect extends BasicManaEffect {
|
|||
}
|
||||
}
|
||||
if (choiceColor.getColor().isBlack()) {
|
||||
computedMana.increaseBlack();
|
||||
computedMana.addBlack();
|
||||
} else if (choiceColor.getColor().isBlue()) {
|
||||
computedMana.increaseBlue();
|
||||
computedMana.addBlue();
|
||||
} else if (choiceColor.getColor().isRed()) {
|
||||
computedMana.increaseRed();
|
||||
computedMana.addRed();
|
||||
} else if (choiceColor.getColor().isGreen()) {
|
||||
computedMana.increaseGreen();
|
||||
computedMana.addGreen();
|
||||
} else if (choiceColor.getColor().isWhite()) {
|
||||
computedMana.increaseWhite();
|
||||
computedMana.addWhite();
|
||||
}
|
||||
if (!oneChoice) {
|
||||
choiceColor.clearChoice();
|
||||
|
|
|
|||
|
|
@ -81,31 +81,31 @@ public class CommanderManaReplacementEffect extends ReplacementEffectImpl {
|
|||
Mana mana = ((ManaEvent) event).getMana();
|
||||
if (mana.getBlack() > 0 && !commanderMana.isBlack()) {
|
||||
for (int i = 0; i < mana.getBlack(); i++) {
|
||||
mana.increaseColorless();
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setBlack(0);
|
||||
}
|
||||
if (mana.getBlue() > 0 && !commanderMana.isBlue()) {
|
||||
for (int i = 0; i < mana.getBlue(); i++) {
|
||||
mana.increaseColorless();
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setBlue(0);
|
||||
}
|
||||
if (mana.getGreen() > 0 && !commanderMana.isGreen()) {
|
||||
for (int i = 0; i < mana.getGreen(); i++) {
|
||||
mana.increaseColorless();
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setGreen(0);
|
||||
}
|
||||
if (mana.getRed() > 0 && !commanderMana.isRed()) {
|
||||
for (int i = 0; i < mana.getRed(); i++) {
|
||||
mana.increaseColorless();
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setRed(0);
|
||||
}
|
||||
if (mana.getWhite() > 0 && !commanderMana.isWhite()) {
|
||||
for (int i = 0; i < mana.getWhite(); i++) {
|
||||
mana.increaseColorless();
|
||||
mana.addColorless();
|
||||
}
|
||||
mana.setWhite(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue