Support showing generic mana in prompt if color can be paid with any color

This commit is contained in:
drdev
2016-03-14 05:41:47 +00:00
parent 81f0bbc633
commit 389681b62a
5 changed files with 25 additions and 12 deletions

View File

@@ -45,8 +45,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
private static final ColorSet[] cache = new ColorSet[32]; private static final ColorSet[] cache = new ColorSet[32];
private static final byte ALL_COLORS_MASK = MagicColor.WHITE | MagicColor.BLUE | MagicColor.BLACK | MagicColor.RED | MagicColor.GREEN; public static final ColorSet ALL_COLORS = fromMask(MagicColor.ALL_COLORS);
public static final ColorSet ALL_COLORS = fromMask(ALL_COLORS_MASK);
private static final ColorSet NO_COLORS = fromMask(MagicColor.COLORLESS); private static final ColorSet NO_COLORS = fromMask(MagicColor.COLORLESS);
private ColorSet(final byte mask) { private ColorSet(final byte mask) {
@@ -55,7 +54,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
} }
public static ColorSet fromMask(final int mask) { public static ColorSet fromMask(final int mask) {
final int mask32 = mask & ALL_COLORS_MASK; final int mask32 = mask & MagicColor.ALL_COLORS;
if (cache[mask32] == null) { if (cache[mask32] == null) {
cache[mask32] = new ColorSet((byte) mask32); cache[mask32] = new ColorSet((byte) mask32);
} }
@@ -259,7 +258,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
public ColorSet inverse() { public ColorSet inverse() {
byte mask = this.myColor; byte mask = this.myColor;
mask ^= ALL_COLORS_MASK; mask ^= MagicColor.ALL_COLORS;
return fromMask(mask); return fromMask(mask);
} }
@@ -364,7 +363,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
return shardOrderLookup[myColor]; return shardOrderLookup[myColor];
} }
private static final ManaCostShard[][] shardOrderLookup = new ManaCostShard[ALL_COLORS_MASK + 1][]; private static final ManaCostShard[][] shardOrderLookup = new ManaCostShard[MagicColor.ALL_COLORS + 1][];
static { static {
byte COLORLESS = MagicColor.COLORLESS; byte COLORLESS = MagicColor.COLORLESS;
byte WHITE = MagicColor.WHITE; byte WHITE = MagicColor.WHITE;
@@ -421,6 +420,6 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
shardOrderLookup[GREEN | WHITE | BLUE | BLACK] = new ManaCostShard[] { G, W, U, B }; shardOrderLookup[GREEN | WHITE | BLUE | BLACK] = new ManaCostShard[] { G, W, U, B };
//five-color //five-color
shardOrderLookup[ALL_COLORS_MASK] = new ManaCostShard[] { W, U, B, R, G }; shardOrderLookup[WHITE | BLUE | BLACK | RED | GREEN] = new ManaCostShard[] { W, U, B, R, G };
} }
} }

View File

@@ -19,6 +19,8 @@ public final class MagicColor {
// Any comparison between colorless cards and colorless mana need to be adjusted appropriately. // Any comparison between colorless cards and colorless mana need to be adjusted appropriately.
public static final byte COLORLESS = 0; public static final byte COLORLESS = 0;
public static final byte ALL_COLORS = WHITE | BLUE | BLACK | RED | GREEN;
public static final int NUMBER_OR_COLORS = 5; public static final int NUMBER_OR_COLORS = 5;
public static final byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN }; public static final byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN };

View File

@@ -472,7 +472,7 @@ public class ManaCostBeingPaid {
* the add x * the add x
* @return the string * @return the string
*/ */
public final String toString(final boolean addX) { public final String toString(final boolean addX, final ManaPool pool) {
// Boolean addX used to add Xs into the returned value // Boolean addX used to add Xs into the returned value
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
@@ -483,6 +483,19 @@ public class ManaCostBeingPaid {
} }
int nGeneric = getGenericManaAmount(); int nGeneric = getGenericManaAmount();
List<ManaCostShard> shards = new ArrayList<ManaCostShard>(unpaidShards.keySet());
if (pool != null) { //replace shards with generic mana if they can be paid with any color mana
for (int i = 0; i < shards.size(); i++) {
ManaCostShard shard = shards.get(i);
if (shard != ManaCostShard.GENERIC && pool.getPossibleColorUses(shard.getColorMask()) == MagicColor.ALL_COLORS) {
nGeneric += unpaidShards.get(shard).totalCount;
shards.remove(i);
i--;
}
}
}
if (nGeneric > 0) { if (nGeneric > 0) {
if (nGeneric <= 20) { if (nGeneric <= 20) {
sb.append("{" + nGeneric + "}"); sb.append("{" + nGeneric + "}");
@@ -496,7 +509,6 @@ public class ManaCostBeingPaid {
} }
// Sort the keys to get a deterministic ordering. // Sort the keys to get a deterministic ordering.
List<ManaCostShard> shards = new ArrayList<ManaCostShard>(unpaidShards.keySet());
Collections.sort(shards); Collections.sort(shards);
for (ManaCostShard shard : shards) { for (ManaCostShard shard : shards) {
if (shard == ManaCostShard.GENERIC) { if (shard == ManaCostShard.GENERIC) {
@@ -516,7 +528,7 @@ public class ManaCostBeingPaid {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final String toString() { public final String toString() {
return this.toString(true); return this.toString(true, null);
} }
/** /**

View File

@@ -42,7 +42,7 @@ public class InputPayManaOfCostPayment extends InputPayMana {
@Override @Override
protected String getMessage() { protected String getMessage() {
final String displayMana = manaCost.toString(false); final String displayMana = manaCost.toString(false, player.getManaPool());
final StringBuilder msg = new StringBuilder(); final StringBuilder msg = new StringBuilder();
if (messagePrefix != null) { if (messagePrefix != null) {

View File

@@ -119,7 +119,7 @@ public class InputPayManaSimple extends InputPayMana {
*/ */
@Override @Override
protected String getMessage() { protected String getMessage() {
final StringBuilder msg = new StringBuilder("Pay Mana Cost: " + this.manaCost.toString()); final StringBuilder msg = new StringBuilder("Pay Mana Cost: " + this.manaCost.toString(false, player.getManaPool()));
if (this.phyLifeToLose > 0) { if (this.phyLifeToLose > 0) {
msg.append(" ("); msg.append(" (");
msg.append(this.phyLifeToLose); msg.append(this.phyLifeToLose);