mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Fixing Mana types being inappropriately referenced in relation to Matrices
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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?
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<ManaCostShard> shards = new ArrayList<ManaCostShard>(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--;
|
||||
|
||||
@@ -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<Mana> {
|
||||
|
||||
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<Mana> {
|
||||
}
|
||||
|
||||
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<Mana> {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user