mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Support showing generic mana in prompt if color can be paid with any color
This commit is contained in:
@@ -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 byte ALL_COLORS_MASK = MagicColor.WHITE | MagicColor.BLUE | MagicColor.BLACK | MagicColor.RED | MagicColor.GREEN;
|
||||
public static final ColorSet ALL_COLORS = fromMask(ALL_COLORS_MASK);
|
||||
public static final ColorSet ALL_COLORS = fromMask(MagicColor.ALL_COLORS);
|
||||
private static final ColorSet NO_COLORS = fromMask(MagicColor.COLORLESS);
|
||||
|
||||
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) {
|
||||
final int mask32 = mask & ALL_COLORS_MASK;
|
||||
final int mask32 = mask & MagicColor.ALL_COLORS;
|
||||
if (cache[mask32] == null) {
|
||||
cache[mask32] = new ColorSet((byte) mask32);
|
||||
}
|
||||
@@ -259,7 +258,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
|
||||
|
||||
public ColorSet inverse() {
|
||||
byte mask = this.myColor;
|
||||
mask ^= ALL_COLORS_MASK;
|
||||
mask ^= MagicColor.ALL_COLORS;
|
||||
return fromMask(mask);
|
||||
}
|
||||
|
||||
@@ -364,7 +363,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
|
||||
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 {
|
||||
byte COLORLESS = MagicColor.COLORLESS;
|
||||
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 };
|
||||
|
||||
//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 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ public final class MagicColor {
|
||||
// Any comparison between colorless cards and colorless mana need to be adjusted appropriately.
|
||||
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 byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN };
|
||||
|
||||
@@ -472,7 +472,7 @@ public class ManaCostBeingPaid {
|
||||
* the add x
|
||||
* @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
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -483,6 +483,19 @@ public class ManaCostBeingPaid {
|
||||
}
|
||||
|
||||
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 <= 20) {
|
||||
sb.append("{" + nGeneric + "}");
|
||||
@@ -496,7 +509,6 @@ public class ManaCostBeingPaid {
|
||||
}
|
||||
|
||||
// Sort the keys to get a deterministic ordering.
|
||||
List<ManaCostShard> shards = new ArrayList<ManaCostShard>(unpaidShards.keySet());
|
||||
Collections.sort(shards);
|
||||
for (ManaCostShard shard : shards) {
|
||||
if (shard == ManaCostShard.GENERIC) {
|
||||
@@ -510,13 +522,13 @@ public class ManaCostBeingPaid {
|
||||
}
|
||||
}
|
||||
|
||||
return sb.length() == 0 ? "0" : sb.toString();
|
||||
return sb.length() == 0 ? "0" : sb.toString();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.toString(true);
|
||||
return this.toString(true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,7 +42,7 @@ public class InputPayManaOfCostPayment extends InputPayMana {
|
||||
|
||||
@Override
|
||||
protected String getMessage() {
|
||||
final String displayMana = manaCost.toString(false);
|
||||
final String displayMana = manaCost.toString(false, player.getManaPool());
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
if (messagePrefix != null) {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class InputPayManaSimple extends InputPayMana {
|
||||
*/
|
||||
@Override
|
||||
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) {
|
||||
msg.append(" (");
|
||||
msg.append(this.phyLifeToLose);
|
||||
|
||||
Reference in New Issue
Block a user