diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index 98df78bf24a..02ffc322634 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -913,6 +913,10 @@ public class ComputerUtilMana { // Make mana needed to avoid negative effect a mandatory cost for the AI for (String manaPart : card.getSVar("ManaNeededToAvoidNegativeEffect").split(",")) { // convert long color strings to short color strings + if (manaPart.isEmpty()) { + continue; + } + byte mask = ManaAtom.fromName(manaPart); // make mana mandatory for AI diff --git a/forge-core/src/main/java/forge/card/MagicColor.java b/forge-core/src/main/java/forge/card/MagicColor.java index bc452e19520..37e6294a056 100644 --- a/forge-core/src/main/java/forge/card/MagicColor.java +++ b/forge-core/src/main/java/forge/card/MagicColor.java @@ -103,15 +103,6 @@ public final class MagicColor { } } - public static int getIndexOfFirstColor(final byte color){ - for (int i = 0; i < NUMBER_OR_COLORS; i++) { - if ((color & WUBRG[i]) != 0) { - return i; - } - } - return -1; // colorless - } - /** * The Interface Color. */ diff --git a/forge-core/src/main/java/forge/card/mana/ManaAtom.java b/forge-core/src/main/java/forge/card/mana/ManaAtom.java index 1416139cda5..5a38b3a3310 100644 --- a/forge-core/src/main/java/forge/card/mana/ManaAtom.java +++ b/forge-core/src/main/java/forge/card/mana/ManaAtom.java @@ -14,6 +14,9 @@ public abstract class ManaAtom { public static final byte[] MANACOLORS = new byte[] { WHITE, BLUE, BLACK, RED, GREEN }; public static final byte[] MANATYPES = new byte[] { WHITE, BLUE, BLACK, RED, GREEN, COLORLESS }; + public static final byte ALL_MANA_COLORS = WHITE | BLUE | BLACK | RED | GREEN; + public static final byte ALL_MANA_TYPES = ALL_MANA_COLORS | COLORLESS; + public static final int GENERIC = 1 << 6; // Below here skip due to byte conversion shenanigans @@ -62,6 +65,6 @@ public abstract class ManaAtom { return i; } } - return -1; // colorless + return -1; // somehow the mana is not colored or colorless? } } \ No newline at end of file diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index 3401a5d6a80..f3b9d374e66 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -1655,7 +1655,8 @@ public class AbilityUtils { String convertTo = params.get(key); byte convertByte = 0; if ("All".equals(convertTo)) { - convertByte = ColorSet.ALL_COLORS.getColor(); + // IMPORTANT! We need to use Mana Color here not Card Color. + convertByte = ManaAtom.ALL_MANA_TYPES; } else { for (final String convertColor : convertTo.split(",")) { convertByte |= ManaAtom.fromName(convertColor); diff --git a/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java b/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java index f1f43259799..f5c381fb9ca 100644 --- a/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java +++ b/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java @@ -586,6 +586,7 @@ public class ManaCostBeingPaid { // Boolean addX used to add Xs into the returned value final StringBuilder sb = new StringBuilder(); + // TODO Prepend a line about paying with any type/color if available if (addX) { for (int i = 0; i < this.getXcounter(); i++) { sb.append("{X}"); @@ -595,10 +596,11 @@ public class ManaCostBeingPaid { int nGeneric = getGenericManaAmount(); List shards = new ArrayList(unpaidShards.keySet()); - if (pool != null) { //replace shards with generic mana if they can be paid with any color mana + // TODO Fix this. Should we really be changing Shards here? + if (false && 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) { + if (shard != ManaCostShard.GENERIC && pool.getPossibleColorUses(shard.getColorMask()) == ManaAtom.ALL_MANA_TYPES) { nGeneric += unpaidShards.get(shard).totalCount; shards.remove(i); i--; diff --git a/forge-game/src/main/java/forge/game/mana/ManaPool.java b/forge-game/src/main/java/forge/game/mana/ManaPool.java index 2d2de63d968..d76c2145973 100644 --- a/forge-game/src/main/java/forge/game/mana/ManaPool.java +++ b/forge-game/src/main/java/forge/game/mana/ManaPool.java @@ -22,7 +22,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import forge.GameCommand; -import forge.card.ColorSet; import forge.card.MagicColor; import forge.card.mana.ManaAtom; import forge.card.mana.ManaCostShard; @@ -364,7 +363,7 @@ public class ManaPool implements Iterable { public void adjustColorReplacement(byte originalColor, byte replacementColor, boolean additive) { // Fix the index without hardcodes - int rowIdx = MagicColor.getIndexOfFirstColor(originalColor); + int rowIdx = ManaAtom.getIndexOfFirstManaType(originalColor); rowIdx = rowIdx < 0 ? identityMatrix.length - 1 : rowIdx; if (additive) { colorConversionMatrix[rowIdx] |= replacementColor; @@ -375,17 +374,19 @@ public class ManaPool implements Iterable { } public void restoreColorReplacements() { + // By default each color can only be paid by itself ( {G} -> {G}, {C} -> {C} for (int i = 0; i < colorConversionMatrix.length; i++) { colorConversionMatrix[i] = identityMatrix[i]; } + // By default all mana types are unrestricted for (int i = 0; i < colorRestrictionMatrix.length; i++) { - colorRestrictionMatrix[i] = ColorSet.ALL_COLORS.getColor(); + colorRestrictionMatrix[i] = ManaAtom.ALL_MANA_TYPES; } } public byte getPossibleColorUses(byte color) { // Take the current conversion value, AND with restrictions to get mana usage - int rowIdx = MagicColor.getIndexOfFirstColor(color); + int rowIdx = ManaAtom.getIndexOfFirstManaType(color); int matrixIdx = rowIdx < 0 ? identityMatrix.length - 1 : rowIdx; byte colorUse = colorConversionMatrix[matrixIdx]; @@ -394,14 +395,16 @@ public class ManaPool implements Iterable { } public boolean canPayForShardWithColor(ManaCostShard shard, byte color) { + // TODO Debug this for Paying Gonti, byte line = getPossibleColorUses(color); - for (int i = 0; i < MagicColor.NUMBER_OR_COLORS; i++) { - byte outColor = MagicColor.WUBRG[i]; + + for(byte outColor : ManaAtom.MANATYPES) { if ((line & outColor) != 0 && shard.canBePaidWithManaOfColor(outColor)) { return true; } } + // TODO The following may not be needed anymore? if (((color & (byte) ManaAtom.COLORLESS) != 0) && shard.canBePaidWithManaOfColor((byte) (byte)ManaAtom.COLORLESS)) { return true; }