Mostly cosmetic changes to color code

This commit is contained in:
elcnesh
2015-05-06 16:26:45 +00:00
parent fd4f55d9df
commit 658fd8f953
15 changed files with 123 additions and 143 deletions

View File

@@ -3,6 +3,7 @@ package forge.ai;
import com.google.common.base.Predicate;
import com.google.common.collect.ArrayListMultimap;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.ManaAtom;
import forge.card.mana.ManaCost;
@@ -696,7 +697,7 @@ public class ComputerUtilMana {
// * pay hybrids
// * pay phyrexian, keep mana for colorless
// * pay colorless
return cost.getShardToPayByPriority(cost.getDistinctShards(), MagicColor.ALL_COLORS);
return cost.getShardToPayByPriority(cost.getDistinctShards(), ColorSet.ALL_COLORS.getColor());
}
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) {

View File

@@ -42,21 +42,11 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
private final byte myColor;
private final float orderWeight;
private static final ColorSet[] allColors = new ColorSet[32];
private static final ColorSet noColor = new ColorSet();
private static final ColorSet[] cache = new ColorSet[32];
// TODO: some cards state "CardName is %color%" (e.g. pacts of...) - fix
// this later
/**
* Instantiates a new card color.
*
* @param mana
* the mana
*/
private ColorSet() {
myColor = 0;
orderWeight = -1;
}
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);
private static final ColorSet NO_COLORS = fromMask(MagicColor.COLORLESS);
private ColorSet(final byte mask) {
this.myColor = mask;
@@ -64,11 +54,11 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
}
public static ColorSet fromMask(final int mask) {
final int mask32 = mask & MagicColor.ALL_COLORS;
if (allColors[mask32] == null) {
allColors[mask32] = new ColorSet((byte) mask);
final int mask32 = mask & ALL_COLORS_MASK;
if (cache[mask32] == null) {
cache[mask32] = new ColorSet((byte) mask32);
}
return allColors[mask32];
return cache[mask32];
}
public static ColorSet fromNames(final String... colors) {
@@ -113,6 +103,11 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
return (this.myColor & colormask) == colormask;
}
/** this has no other colors except defined by operand. */
public boolean hasNoColorsExcept(final ColorSet other) {
return hasNoColorsExcept(other.getColor());
}
/** this has no other colors except defined by operand. */
public boolean hasNoColorsExcept(final int colormask) {
return (this.myColor & ~colormask) == 0;
@@ -139,7 +134,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
*
* @return the order weight
*/
public float getOrderWeight() {
private float getOrderWeight() {
float res = this.countColors();
if(hasWhite()) {
res += 0.0005f;
@@ -255,7 +250,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
public ColorSet inverse() {
byte mask = this.myColor;
mask ^= MagicColor.ALL_COLORS;
mask ^= ALL_COLORS_MASK;
return fromMask(mask);
}
@@ -286,7 +281,7 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
* @return the nullColor
*/
public static ColorSet getNullColor() {
return noColor;
return NO_COLORS;
}
/**
@@ -299,8 +294,12 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
return (this.myColor & ccOther.myColor) != 0;
}
public ColorSet getSharedColors(final ColorSet ccOther) {
return fromMask(getColor() & ccOther.getColor());
}
public ColorSet getOffColors(final ColorSet ccOther) {
return ColorSet.fromMask(~this.myColor & ccOther.myColor);
return fromMask(~this.myColor & ccOther.myColor);
}
@Override
@@ -313,8 +312,8 @@ public final class ColorSet implements Comparable<ColorSet>, Iterable<Byte>, Ser
private int getIndexOfNextColor(){
int nextBit = currentBit + 1;
while(nextBit < MagicColor.NUMBER_OR_COLORS) {
if((myColor & MagicColor.WUBRG[nextBit]) != 0) {
while (nextBit < MagicColor.NUMBER_OR_COLORS) {
if ((myColor & MagicColor.WUBRG[nextBit]) != 0) {
break;
}
nextBit++;

View File

@@ -6,7 +6,7 @@ import com.google.common.collect.ImmutableMap;
/**
* Holds byte values for each color magic has.
*/
public class MagicColor {
public final class MagicColor {
public static final byte COLORLESS = 0;
public static final byte WHITE = 1 << 0;
@@ -15,7 +15,6 @@ public class MagicColor {
public static final byte RED = 1 << 3;
public static final byte GREEN = 1 << 4;
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 };
@@ -37,30 +36,19 @@ public class MagicColor {
s = s.toLowerCase();
if (s.length() == 1) {
switch (s) {
case "w":
return MagicColor.WHITE;
case "u":
return MagicColor.BLUE;
case "b":
return MagicColor.BLACK;
case "r":
return MagicColor.RED;
case "g":
return MagicColor.GREEN;
case "w": return MagicColor.WHITE;
case "u": return MagicColor.BLUE;
case "b": return MagicColor.BLACK;
case "r": return MagicColor.RED;
case "g": return MagicColor.GREEN;
}
}
else {
} else {
switch (s) {
case Constant.WHITE:
return MagicColor.WHITE;
case Constant.BLUE:
return MagicColor.BLUE;
case Constant.BLACK:
return MagicColor.BLACK;
case Constant.RED:
return MagicColor.RED;
case Constant.GREEN:
return MagicColor.GREEN;
case Constant.WHITE: return MagicColor.WHITE;
case Constant.BLUE: return MagicColor.BLUE;
case Constant.BLACK: return MagicColor.BLACK;
case Constant.RED: return MagicColor.RED;
case Constant.GREEN: return MagicColor.GREEN;
}
}
return 0; // colorless
@@ -78,7 +66,9 @@ public class MagicColor {
}
public static String toShortString(final String color) {
if (color.equalsIgnoreCase(Constant.SNOW)) { return "S"; } // compatibility
if (color.equalsIgnoreCase(Constant.SNOW)) {
return "S";
} // compatibility
return toShortString(fromName(color));
}

View File

@@ -2,6 +2,7 @@ package forge.game.ability;
import com.google.common.collect.Iterables;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.ManaCost;
import forge.card.mana.ManaCostShard;
@@ -1494,9 +1495,9 @@ public class AbilityUtils {
String convertTo = params.get(key);
byte convertByte = 0;
if ("All".equals(convertTo)) {
convertByte = MagicColor.ALL_COLORS;
} else{
for(String convertColor : convertTo.split(",")) {
convertByte = ColorSet.ALL_COLORS.getColor();
} else {
for (final String convertColor : convertTo.split(",")) {
convertByte |= MagicColor.fromName(convertColor);
}
}

View File

@@ -33,7 +33,7 @@ public class ChangeTextEffect extends SpellAbilityEffect {
final String[] changedColorWordsArray = sa.getParam("ChangeColorWord").split(" ");
if (changedColorWordsArray[0].equals("Choose")) {
originalColor = sa.getActivatingPlayer().getController().chooseColor(
"Choose a color word to replace", sa, ColorSet.fromMask(MagicColor.ALL_COLORS));
"Choose a color word to replace", sa, ColorSet.ALL_COLORS);
changedColorWordOriginal = TextUtil.capitalize(MagicColor.toLongString(originalColor));
} else {
changedColorWordOriginal = changedColorWordsArray[0];
@@ -43,7 +43,7 @@ public class ChangeTextEffect extends SpellAbilityEffect {
if (changedColorWordsArray[1].equals("Choose")) {
final ColorSet possibleNewColors;
if (originalColor == 0) { // no original color (ie. any or absent)
possibleNewColors = ColorSet.fromMask(MagicColor.ALL_COLORS);
possibleNewColors = ColorSet.ALL_COLORS;
} else { // may choose any except original color
possibleNewColors = ColorSet.fromMask(originalColor).inverse();
}
@@ -129,7 +129,7 @@ public class ChangeTextEffect extends SpellAbilityEffect {
* @see forge.card.abilityfactory.SpellEffect#getStackDescription(java.util.Map, forge.card.spellability.SpellAbility)
*/
@Override
protected String getStackDescription(SpellAbility sa) {
protected String getStackDescription(final SpellAbility sa) {
final String changedColorWordOriginal, changedColorWordNew;
if (sa.hasParam("ChangeColorWord")) {
final String[] changedColorWordsArray = sa.getParam("ChangeColorWord").split(" ");

View File

@@ -87,7 +87,7 @@ public class ManaEffect extends SpellAbilityEffect {
for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) {
mask |= MagicColor.fromName(colorsNeeded.charAt(nChar));
}
colorMenu = ColorSet.fromMask(mask == 0 ? MagicColor.ALL_COLORS : mask);
colorMenu = mask == 0 ? ColorSet.ALL_COLORS : ColorSet.fromMask(mask);
byte val = act.getController().chooseColor("Select Mana to Produce", sa, colorMenu);
if (0 == val) {
throw new RuntimeException("ManaEffect::resolve() /*any mana*/ - " + act + " color mana choice is empty for " + card.getName());

View File

@@ -417,7 +417,7 @@ public class ManaCostBeingPaid {
if (bill.isMonoColor()) {
if (bill.isOr2Colorless()) {
return (bill.getColorMask() & paymentColor & MagicColor.ALL_COLORS) != 0? 9 : 4;
return !ColorSet.fromMask(bill.getColorMask() & paymentColor).isColorless() ? 9 : 4;
}
if (!bill.isPhyrexian()) {
return 10;

View File

@@ -22,6 +22,7 @@ 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.ManaCostShard;
import forge.game.GlobalRuleChange;
@@ -368,7 +369,7 @@ public class ManaPool implements Iterable<Mana> {
colorConversionMatrix[i] = identityMatrix[i];
}
for (int i = 0; i < colorRestrictionMatrix.length; i++) {
colorRestrictionMatrix[i] = MagicColor.ALL_COLORS;
colorRestrictionMatrix[i] = ColorSet.ALL_COLORS.getColor();
}
}

View File

@@ -2,7 +2,7 @@ package forge.game.player;
import java.util.HashSet;
import forge.card.MagicColor;
import forge.card.ColorSet;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
@@ -15,17 +15,17 @@ public class AchievementTracker {
public int maxStormCount = 0;
public int landsPlayed = 0;
public void onSpellAbilityPlayed(SpellAbility sa) {
public void onSpellAbilityPlayed(final SpellAbility sa) {
final Card card = sa.getHostCard();
if (sa.getRestrictions().isPwAbility() && sa.hasParam("Ultimate")) {
activatedUltimates.add(card.getName());
}
if (card.determineColor().getColor() == MagicColor.ALL_COLORS) {
if (card.determineColor().equals(ColorSet.ALL_COLORS)) {
challengesCompleted.add("Chromatic");
}
}
public void onSpellResolve(SpellAbility spell) {
public void onSpellResolve(final SpellAbility spell) {
final Card card = spell.getHostCard();
if (card.hasKeyword("Epic")) {
challengesCompleted.add("Epic");

View File

@@ -623,7 +623,7 @@ public class AbilityManaPart implements java.io.Serializable {
if (replaced.equals("Any")) {
byte rs = MagicColor.GREEN;
if (act != null) {
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.fromMask(MagicColor.ALL_COLORS));
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
}
replaced = MagicColor.toShortString(rs);
}
@@ -657,7 +657,7 @@ public class AbilityManaPart implements java.io.Serializable {
while (replaced.contains("Any")) {
byte rs = MagicColor.GREEN;
if (act != null) {
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.fromMask(MagicColor.ALL_COLORS));
rs = act.getController().chooseColor("Choose a color", sa, ColorSet.ALL_COLORS);
}
replaced = replaced.replaceFirst("Any", MagicColor.toShortString(rs));
}

View File

@@ -176,29 +176,25 @@ public class SFilterUtil {
if (wantMulticolor) {
if (colors == 0) { //handle showing all multi-color cards if all 5 colors are filtered
result = color.isMulticolor() || (wantColorless && color.isColorless());
}
else if (colors != MagicColor.ALL_COLORS) {
} else if (colors != ColorSet.ALL_COLORS.getColor()) {
if (useColorIdentity) {
result = color.hasAllColors(colors);
}
else {
} else {
result = rules.canCastWithAvailable(colors);
}
}
}
else {
} else {
result = !color.isMulticolor();
if (colors != MagicColor.ALL_COLORS) {
if (colors != ColorSet.ALL_COLORS.getColor()) {
if (useColorIdentity) {
result = result && color.hasAnyColor(colors);
}
else {
} else {
result = result && rules.canCastWithAvailable(colors);
}
}
}
if (!wantColorless) {
if (colors != 0 && colors != MagicColor.ALL_COLORS) {
if (colors != 0 && colors != ColorSet.ALL_COLORS.getColor()) {
//if colorless filtered out ensure phyrexian cards don't appear
//unless at least one of their colors is selected
result = result && color.hasAnyColor(colors);

View File

@@ -17,64 +17,56 @@
*/
package forge.limited;
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.card.mana.ManaCost;
import forge.item.IPaperCard;
import java.util.List;
/**
* Created by IntelliJ IDEA. User: dhudson Date: 6/24/11 Time: 8:42 PM To change
* this template use File | Settings | File Templates.
*/
import forge.card.ColorSet;
import forge.card.MagicColor;
import forge.item.IPaperCard;
class DeckColors {
private ColorSet chosen;
private int colorMask;
public final static int MAX_COLORS = 2;
// public String Splash = "none";
public ColorSet getChosenColors() {
if ( null == chosen )
if (null == chosen) {
chosen = ColorSet.fromMask(colorMask);
}
return chosen;
}
/**
* TODO: Write javadoc for this method.
* @param pickedCard
*/
public void addColorsOf(IPaperCard pickedCard) {
ManaCost colorsInCard = pickedCard.getRules().getManaCost();
int colorsCanAdd = MagicColor.ALL_COLORS & ~getChosenColors().getColor();
int colorsWantAdd = colorsInCard.getColorProfile() & colorsCanAdd;
ColorSet toAdd = ColorSet.fromMask(colorsWantAdd);
public void addColorsOf(final IPaperCard pickedCard) {
final ColorSet colorsCanAdd = chosen.inverse();
final ColorSet toAdd = colorsCanAdd.getSharedColors(pickedCard.getRules().getColor());
int cntColorsAssigned = getChosenColors().countColors();
boolean haveSpace = cntColorsAssigned < MAX_COLORS;
if( !haveSpace || toAdd.isColorless() )
final boolean haveSpace = cntColorsAssigned < MAX_COLORS;
if (!haveSpace || toAdd.isColorless()) {
return;
}
for(int i = 0; i < MagicColor.NUMBER_OR_COLORS && cntColorsAssigned < MAX_COLORS; i++ )
if (( colorsWantAdd & MagicColor.WHITE << i ) > 0) {
colorMask |= MagicColor.WHITE << i;
for (final byte color : MagicColor.WUBRG) {
if (toAdd.hasAnyColor(color)) {
colorMask |= color;
chosen = null; // invalidate color set
cntColorsAssigned++;
}
if (cntColorsAssigned >= MAX_COLORS) {
break;
}
}
}
public void setColorsByList(List<Byte> colors) {
public void setColorsByList(final List<Byte> colors) {
colorMask = 0;
for (Byte col : colors) {
colorMask |= col;
for (final Byte col : colors) {
colorMask |= col.byteValue();
}
chosen = null;
}
public boolean canChoseMoreColors() {
return getChosenColors().countColors() < MAX_COLORS;
}

View File

@@ -233,7 +233,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
// If the card has any ability that tracks mana spent, skip express Mana choice
if (saPaidFor.tracksManaSpent()) {
colorCanUse = MagicColor.ALL_COLORS;
colorCanUse = ColorSet.ALL_COLORS.getColor();
guessAbilityWithRequiredColors = false;
}

View File

@@ -93,7 +93,7 @@ public enum ConquestPlane {
new Region("Auntie's Hovel", "Auntie's Hovel", MagicColor.BLACK | MagicColor.RED),
new Region("Gilt-Leaf Palace", "Gilt-Leaf Palace", MagicColor.BLACK | MagicColor.GREEN),
new Region("Murmuring Bosk", "Murmuring Bosk", MagicColor.WHITE | MagicColor.BLACK | MagicColor.GREEN),
new Region("Primal Beyond", "Primal Beyond", MagicColor.ALL_COLORS),
new Region("Primal Beyond", "Primal Beyond", ColorSet.ALL_COLORS.getColor()),
new Region("Rustic Clachan", "Rustic Clachan", MagicColor.GREEN | MagicColor.WHITE),
new Region("Secluded Glen", "Secluded Glen", MagicColor.BLUE | MagicColor.BLACK),
new Region("Wanderwine Hub", "Wanderwine Hub", MagicColor.WHITE | MagicColor.BLUE),
@@ -116,7 +116,7 @@ public enum ConquestPlane {
new Region("Ish Sah", "Vault of Whispers", MagicColor.BLACK),
new Region("Kuldotha", "Great Furnace", MagicColor.RED),
new Region("Tel-Jilad", "Tree of Tales", MagicColor.GREEN),
new Region("Glimmervoid", "Glimmervoid", MagicColor.ALL_COLORS)
new Region("Glimmervoid", "Glimmervoid", ColorSet.ALL_COLORS.getColor())
}),
Rath("Rath", new String[] {
"TMP", "STH", "EXO"
@@ -299,7 +299,7 @@ public enum ConquestPlane {
name = name0;
artCardName = artCardName0;
pred = pred0;
colorSet = ColorSet.fromMask(MagicColor.ALL_COLORS);
colorSet = ColorSet.fromMask(ColorSet.ALL_COLORS.getColor());
}
public String getName() {

View File

@@ -102,8 +102,8 @@ public class ConquestUtil {
availableCards.remove(commander);
//remove any cards that aren't allowed in deck due to color identity
byte colorIdentity = commander.getRules().getColorIdentity().getColor();
if (colorIdentity != MagicColor.ALL_COLORS) {
final ColorSet colorIdentity = commander.getRules().getColorIdentity();
if (!colorIdentity.equals(ColorSet.ALL_COLORS)) {
List<PaperCard> invalidCards = new ArrayList<PaperCard>();
for (PaperCard pc : availableCards) {
if (!pc.getRules().getColorIdentity().hasNoColorsExcept(colorIdentity)) {
@@ -119,7 +119,7 @@ public class ConquestUtil {
String setCode = FModel.getConquest().getModel().getCurrentPlane().getEditions().get(0).getCode();
for (int i = 0; i < MagicColor.WUBRG.length; i++) {
if ((colorIdentity & MagicColor.WUBRG[i]) != 0) {
if (colorIdentity.hasAnyColor(MagicColor.WUBRG[i])) {
pool.add(MagicColor.Constant.BASIC_LANDS.get(i), setCode, 50);
}
}