methods now access and set state directly, rather than through the API, which is meant to prevent accidently setting minus values

This commit is contained in:
poixen 2015-11-25 23:12:23 +01:00
parent 3ffb11d2e9
commit c0ee279da9

View file

@ -320,44 +320,44 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public boolean enough(Mana avail) { public boolean enough(Mana avail) {
Mana compare = avail.copy(); Mana compare = avail.copy();
compare.subtract(this); compare.subtract(this);
if (compare.getRed() < 0) { if (compare.red < 0) {
compare.setAny(compare.getAny() + compare.getRed()); compare.any = compare.getAny() + compare.getRed();
if (compare.getAny() < 0) { if (compare.any < 0) {
return false; return false;
} }
compare.setRed(0); compare.red =0;
} }
if (compare.getGreen() < 0) { if (compare.green < 0) {
compare.setAny(compare.getAny() + compare.getGreen()); compare.any = compare.getAny() + compare.getGreen();
if (compare.getAny() < 0) { if (compare.any < 0) {
return false; return false;
} }
compare.setGreen(0); compare.green = 0;
} }
if (compare.getBlue() < 0) { if (compare.blue < 0) {
compare.setAny(compare.getAny() + compare.getBlue()); compare.any = compare.getAny() + compare.getBlue();
if (compare.getAny() < 0) { if (compare.any < 0) {
return false; return false;
} }
compare.setBlue(0); compare.blue = 0;
} }
if (compare.getBlack() < 0) { if (compare.black < 0) {
compare.setAny(compare.getAny() + compare.getBlack()); compare.any = compare.getAny() + compare.getBlack();
if (compare.getAny() < 0) { if (compare.any < 0) {
return false; return false;
} }
compare.setBlack(0); compare.black = 0;
} }
if (compare.getWhite() < 0) { if (compare.white < 0) {
compare.setAny(compare.getAny() + compare.getWhite()); compare.any = compare.getAny() + compare.getWhite();
if (compare.getAny() < 0) { if (compare.any < 0) {
return false; return false;
} }
compare.setWhite(0); compare.white = 0;
} }
if (compare.getColorless() < 0) { if (compare.colorless < 0) {
int remaining = compare.getRed() + compare.getGreen() + compare.getBlack() + compare.getBlue() + compare.getWhite() + compare.getAny(); int remaining = compare.red + compare.green + compare.black + compare.blue + compare.white + compare.any;
if (compare.getColorless() + remaining < 0) { if (compare.colorless + remaining < 0) {
return false; return false;
} }
} }
@ -367,62 +367,62 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public Mana needed(Mana avail) { public Mana needed(Mana avail) {
Mana compare = avail.copy(); Mana compare = avail.copy();
compare.subtract(this); compare.subtract(this);
if (compare.getRed() < 0 && compare.getAny() > 0) { if (compare.red < 0 && compare.any > 0) {
int diff = Math.min(compare.getAny(), Math.abs(compare.getRed())); int diff = Math.min(compare.any, Math.abs(compare.red));
compare.setAny(compare.getAny() - diff); compare.any = compare.getAny() - diff;
compare.setRed(compare.getRed() + diff); compare.red = compare.getRed() + diff;
} }
if (compare.getGreen() < 0 && compare.getAny() > 0) { if (compare.green < 0 && compare.any > 0) {
int diff = Math.min(compare.getAny(), Math.abs(compare.getGreen())); int diff = Math.min(compare.any, Math.abs(compare.green));
compare.setAny(compare.getAny() - diff); compare.any = compare.any - diff;
compare.setGreen(compare.getGreen() + diff); compare.green = compare.green + diff;
} }
if (compare.getBlue() < 0 && compare.getAny() > 0) { if (compare.blue < 0 && compare.any > 0) {
int diff = Math.min(compare.getAny(), Math.abs(compare.getBlue())); int diff = Math.min(compare.any, Math.abs(compare.blue));
compare.setAny(compare.getAny() - diff); compare.any = compare.any - diff;
compare.setBlue(compare.getBlue() + diff); compare.blue = compare.blue + diff;
} }
if (compare.getBlack() < 0 && compare.getAny() > 0) { if (compare.black < 0 && compare.any > 0) {
int diff = Math.min(compare.getAny(), Math.abs(compare.getBlack())); int diff = Math.min(compare.any, Math.abs(compare.black));
compare.setAny(compare.getAny() - diff); compare.any = compare.any - diff;
compare.setBlack(compare.getBlack() + diff); compare.black = compare.getBlack() + diff;
} }
if (compare.getWhite() < 0 && compare.getAny() > 0) { if (compare.white < 0 && compare.any > 0) {
int diff = Math.min(compare.getAny(), Math.abs(compare.getWhite())); int diff = Math.min(compare.any, Math.abs(compare.white));
compare.setAny(compare.getAny() - diff); compare.any = compare.any - diff;
compare.setWhite(compare.getWhite() + diff); compare.white = compare.white + diff;
} }
if (compare.getColorless() < 0) { if (compare.colorless < 0) {
int remaining = 0; int remaining = 0;
remaining += Math.min(0, compare.getRed()); remaining += Math.min(0, compare.red);
remaining += Math.min(0, compare.getWhite()); remaining += Math.min(0, compare.white);
remaining += Math.min(0, compare.getGreen()); remaining += Math.min(0, compare.green);
remaining += Math.min(0, compare.getBlack()); remaining += Math.min(0, compare.black);
remaining += Math.min(0, compare.getBlue()); remaining += Math.min(0, compare.blue);
remaining += Math.min(0, compare.getAny()); remaining += Math.min(0, compare.any);
if (remaining > 0) { if (remaining > 0) {
int diff = Math.min(remaining, Math.abs(compare.getColorless())); int diff = Math.min(remaining, Math.abs(compare.colorless));
compare.setColorless(compare.getColorless() + diff); compare.colorless = compare.colorless + diff;
} }
} }
Mana needed = new Mana(); Mana needed = new Mana();
if (compare.getRed() < 0) { if (compare.red < 0) {
needed.setRed(Math.abs(compare.getRed())); needed.red = Math.abs(compare.red);
} }
if (compare.getWhite() < 0) { if (compare.white < 0) {
needed.setWhite(Math.abs(compare.getWhite())); needed.white = Math.abs(compare.white);
} }
if (compare.getGreen() < 0) { if (compare.green < 0) {
needed.setGreen(Math.abs(compare.getGreen())); needed.green = Math.abs(compare.green);
} }
if (compare.getBlack() < 0) { if (compare.black < 0) {
needed.setBlack(Math.abs(compare.getBlack())); needed.black = Math.abs(compare.black);
} }
if (compare.getBlue() < 0) { if (compare.blue < 0) {
needed.setBlue(Math.abs(compare.getBlue())); needed.blue = Math.abs(compare.blue);
} }
if (compare.getColorless() < 0) { if (compare.colorless < 0) {
needed.setColorless(Math.abs(compare.getColorless())); needed.colorless = Math.abs(compare.colorless);
} }
return needed; return needed;
} }