moved a few classes to core module

This commit is contained in:
Maxmtg
2013-11-09 02:27:38 +00:00
parent a0479f9610
commit 6c712d86fb
47 changed files with 71 additions and 44 deletions

View File

@@ -42,6 +42,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import forge.CardPredicates.Presets;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.CardDb;
import forge.card.CardEdition;
@@ -761,7 +762,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* a {@link forge.card.trigger.Trigger} object.
*
* @param state
* a {@link forge.CardCharacteristicName} object.
* a {@link forge.card.CardCharacteristicName} object.
*/
public final void removeTrigger(final Trigger t, final CardCharacteristicName state) {
CardCharacteristics stateCharacteristics = this.getState(state);

View File

@@ -1,45 +0,0 @@
package forge;
/**
* TODO: Write javadoc for this type.
*
*/
public enum CardCharacteristicName {
Original,
FaceDown,
Flipped,
Cloner,
Transformed,
Licid,
Cloned,
LeftSplit,
RightSplit;
/**
* TODO: Write javadoc for this method.
* @param substring
* @return
*/
public static CardCharacteristicName smartValueOf(String value) {
if (value == null) {
return null;
}
if ("All".equals(value)) {
return null;
}
final String valToCompate = value.trim();
for (final CardCharacteristicName v : CardCharacteristicName.values()) {
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
return v;
}
}
if ("Flip".equalsIgnoreCase(value)) {
return CardCharacteristicName.Flipped;
}
if ("DoubleFaced".equalsIgnoreCase(value)) {
return CardCharacteristicName.Transformed;
}
throw new IllegalArgumentException("No element named " + value + " in enum CardCharactersticName");
}
}

View File

@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.ColorSet;
import forge.card.MagicColor;

View File

@@ -1,145 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ImmutableList;
/**
* <p>
* Constant interface.
* </p>
*
* @author Forge
* @version $Id$
*/
public final class Constant {
// used to pass information between the GUI screens
/**
* The Class Runtime.
*/
public static class Preferences {
/** The Constant DevMode. */
// one for normal mode, one for quest mode
public static boolean DEV_MODE;
/** The Constant UpldDrft. */
public static boolean UPLOAD_DRAFT;
}
public static class Runtime {
/** The Constant NetConn. */
public static volatile boolean NET_CONN = false;
/** The Constant width. */
public static final int WIDTH = 300;
/** The Constant height. */
public static final int HEIGHT = 0;
}
/**
* The Interface Color.
*/
public static class Color {
/** The Black. */
public static final String BLACK = "black";
/** The Blue. */
public static final String BLUE = "blue";
/** The Green. */
public static final String GREEN = "green";
/** The Red. */
public static final String RED = "red";
/** The White. */
public static final String WHITE = "white";
/** The Colorless. */
public static final String COLORLESS = "colorless";
// color order "wubrg"
/** The only colors. */
public static final ImmutableList<String> ONLY_COLORS = ImmutableList.of(Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN);
/** The Snow. */
public static final String SNOW = "snow";
/** The Basic lands. */
public static final List<String> BASIC_LANDS = ImmutableList.of("Plains", "Island", "Swamp", "Mountain", "Forest");
public static final List<String> SNOW_LANDS = ImmutableList.of("Snow-Covered Plains", "Snow-Covered Island", "Snow-Covered Swamp", "Snow-Covered Mountain", "Snow-Covered Forest");
}
/**
* The Interface CardTypes.
*/
public static class CardTypes {
/** The loaded. */
public static final boolean[] LOADED = { false };
/** The card types. */
public static final List<String> CARD_TYPES = new ArrayList<String>();
/** The super types. */
public static final List<String> SUPER_TYPES = new ArrayList<String>();
/** The basic types. */
public static final List<String> BASIC_TYPES = new ArrayList<String>();
/** The land types. */
public static final List<String> LAND_TYPES = new ArrayList<String>();
/** The creature types. */
public static final List<String> CREATURE_TYPES = new ArrayList<String>();
/** The instant types. */
public static final List<String> INSTANT_TYPES = new ArrayList<String>();
/** The sorcery types. */
public static final List<String> SORCERY_TYPES = new ArrayList<String>();
/** The enchantment types. */
public static final List<String> ENCHANTMENT_TYPES = new ArrayList<String>();
/** The artifact types. */
public static final List<String> ARTIFACT_TYPES = new ArrayList<String>();
/** The walker types. */
public static final List<String> WALKER_TYPES = new ArrayList<String>();
}
/**
* The Interface Keywords.
*/
public static class Keywords {
/** The loaded. */
public static final boolean[] LOADED = { false };
/** The Non stacking list. */
public static final List<String> NON_STACKING_LIST = new ArrayList<String>();
}
} // Constant

View File

@@ -1,7 +0,0 @@
package forge.card;
public enum AggregationMethod {
USE_ACTIVE_FACE,
USE_PRIMARY_FACE,
AGGREGATE;
}

View File

@@ -1,49 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card;
/**
* The Enum CardCoreType.
*/
public enum CardCoreType {
/** The Artifact. */
Artifact,
/** The Creature. */
Creature,
/** The Enchantment. */
Enchantment,
/** The Instant. */
Instant,
/** The Land. */
Land,
/** The Plane. */
Plane,
/** The Planeswalker. */
Planeswalker,
/** The Scheme. */
Scheme,
/** The Sorcery. */
Sorcery,
/** The Tribal. */
Tribal,
/** The Vanguard. */
Vanguard,
/** The Phenomenon. */
Phenomenon
}

View File

@@ -1,36 +0,0 @@
package forge.card;
import forge.CardCharacteristicName;
public enum CardSplitType
{
None(AggregationMethod.USE_PRIMARY_FACE, null),
Transform(AggregationMethod.USE_ACTIVE_FACE, CardCharacteristicName.Transformed),
Split(AggregationMethod.AGGREGATE, CardCharacteristicName.RightSplit),
Flip(AggregationMethod.USE_PRIMARY_FACE, CardCharacteristicName.Flipped),
// used by 12 licid creatures to switch type into enchantment aura
Licid(AggregationMethod.USE_PRIMARY_FACE, CardCharacteristicName.Licid);
private CardSplitType(AggregationMethod calcMode, CardCharacteristicName stateName) {
method = calcMode;
this.changedStateName = stateName;
}
public AggregationMethod getAggregationMethod() {
return method;
}
private final AggregationMethod method;
private final CardCharacteristicName changedStateName;
public static CardSplitType smartValueOf(String text) {
if ("DoubleFaced".equals(text)) return Transform;
// Will throw exceptions here if bad text passed
CardSplitType res = CardSplitType.valueOf(text);
return res;
}
public CardCharacteristicName getChangedStateName() {
return changedStateName;
}
}

View File

@@ -1,35 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card;
/**
* The Enum CardSuperType.
*/
public enum CardSuperType {
/** The Basic. */
Basic,
/** The Legendary. */
Legendary,
/** The Snow. */
Snow,
/** The Ongoing. */
Ongoing,
/** The World. */
World
}

View File

@@ -1,306 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import forge.Constant;
/**
* <p>
* Immutable Card type. Can be build only from parsing a string.
* </p>
*
* @author Forge
* @version $Id: CardType.java 9708 2011-08-09 19:34:12Z jendave $
*/
public final class CardType implements Comparable<CardType> {
private final List<String> subType = new ArrayList<String>();
private final EnumSet<CardCoreType> coreType = EnumSet.noneOf(CardCoreType.class);
private final EnumSet<CardSuperType> superType = EnumSet.noneOf(CardSuperType.class);
private String calculatedType = null; // since obj is immutable, this is
// calc'd once
// This will be useful for faster parses
private static HashMap<String, CardCoreType> stringToCoreType = new HashMap<String, CardCoreType>();
private static HashMap<String, CardSuperType> stringToSuperType = new HashMap<String, CardSuperType>();
static {
for (final CardSuperType st : CardSuperType.values()) {
CardType.stringToSuperType.put(st.name(), st);
}
for (final CardCoreType ct : CardCoreType.values()) {
CardType.stringToCoreType.put(ct.name(), ct);
}
}
private CardType() { }
// TODO: Debug this code
public static CardType parse(final String typeText) {
// Most types and subtypes, except "Serra's Realm" and
// "Bolas's Meditation Realm" consist of only one word
final char space = ' ';
final CardType result = new CardType();
int iTypeStart = 0;
int iSpace = typeText.indexOf(space);
boolean hasMoreTypes = typeText.length() > 0;
while (hasMoreTypes) {
final String type = typeText.substring(iTypeStart, iSpace == -1 ? typeText.length() : iSpace);
hasMoreTypes = iSpace != -1;
if (!CardType.isMultiwordType(type) || !hasMoreTypes) {
iTypeStart = iSpace + 1;
result.parseAndAdd(type);
}
iSpace = typeText.indexOf(space, iSpace + 1);
}
return result;
}
public static CardType combine(final CardType a, final CardType b) {
CardType result = new CardType();
result.superType.addAll(a.superType);
result.superType.addAll(b.superType);
result.coreType.addAll(a.coreType);
result.coreType.addAll(b.coreType);
result.subType.addAll(a.subType);
result.subType.addAll(b.subType);
return result;
}
private static boolean isMultiwordType(final String type) {
final String[] multiWordTypes = { "Serra's Realm", "Bolas's Meditation Realm" };
// no need to loop for only 2 exceptions!
if (multiWordTypes[0].startsWith(type) && !multiWordTypes[0].equals(type)) {
return true;
}
if (multiWordTypes[1].startsWith(type) && !multiWordTypes[1].equals(type)) {
return true;
}
return false;
}
private void parseAndAdd(final String type) {
if ("-".equals(type)) {
return;
}
final CardCoreType ct = CardType.stringToCoreType.get(type);
if (ct != null) {
this.coreType.add(ct);
return;
}
final CardSuperType st = CardType.stringToSuperType.get(type);
if (st != null) {
this.superType.add(st);
return;
}
// If not recognized by super- and core- this must be subtype
this.subType.add(type);
}
public boolean subTypeContains(final String operand) {
return this.subType.contains(operand);
}
public boolean typeContains(final CardCoreType operand) {
return this.coreType.contains(operand);
}
public boolean superTypeContains(final CardSuperType operand) {
return this.superType.contains(operand);
}
public boolean isCreature() {
return this.coreType.contains(CardCoreType.Creature);
}
public boolean isPlaneswalker() {
return this.coreType.contains(CardCoreType.Planeswalker);
}
public boolean isLand() {
return this.coreType.contains(CardCoreType.Land);
}
public boolean isArtifact() {
return this.coreType.contains(CardCoreType.Artifact);
}
public boolean isInstant() {
return this.coreType.contains(CardCoreType.Instant);
}
public boolean isSorcery() {
return this.coreType.contains(CardCoreType.Sorcery);
}
public boolean isVanguard() {
return this.coreType.contains(CardCoreType.Vanguard);
}
public boolean isScheme() {
return this.coreType.contains(CardCoreType.Scheme);
}
public boolean isEnchantment() {
return this.coreType.contains(CardCoreType.Enchantment);
}
public boolean isBasic() {
return this.superType.contains(CardSuperType.Basic);
}
public boolean isLegendary() {
return this.superType.contains(CardSuperType.Legendary);
}
public boolean isBasicLand() {
return this.isBasic() && this.isLand();
}
@Override
public String toString() {
if (null == this.calculatedType) {
this.calculatedType = this.toStringImpl();
}
return this.calculatedType;
}
private String toStringImpl() {
if (this.subType.isEmpty()) {
return StringUtils.join(this.getTypesBeforeDash(), ' ');
} else {
return String.format("%s - %s", StringUtils.join(this.getTypesBeforeDash(), ' '), StringUtils.join(this.subType, " "));
}
}
public List<String> getTypesBeforeDash() {
final ArrayList<String> types = new ArrayList<String>();
for (final CardSuperType st : this.superType) {
types.add(st.name());
}
for (final CardCoreType ct : this.coreType) {
types.add(ct.name());
}
return types;
}
@Override
public int compareTo(final CardType o) {
return this.toString().compareTo(o.toString());
}
public List<String> getSubTypes() {
return this.subType;
}
public boolean sharesSubTypeWith(CardType ctOther) {
for (String t : ctOther.getSubTypes()) {
if (this.subTypeContains(t)) {
return true;
}
}
return false;
}
public boolean isPlane() {
return this.coreType.contains(CardCoreType.Plane);
}
public boolean isPhenomenon() {
return this.coreType.contains(CardCoreType.Phenomenon);
}
///////// Utility methods
public static boolean isACardType(final String cardType) {
return CardType.getAllCardTypes().contains(cardType);
}
public static ArrayList<String> getAllCardTypes() {
final ArrayList<String> types = new ArrayList<String>();
// types.addAll(getCardTypes());
types.addAll(Constant.CardTypes.CARD_TYPES);
// not currently used by Forge
types.add("Plane");
types.add("Scheme");
types.add("Vanguard");
return types;
}
public static ArrayList<String> getBasicTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.BASIC_TYPES);
return types;
}
public static ArrayList<String> getLandTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.BASIC_TYPES);
types.addAll(Constant.CardTypes.LAND_TYPES);
return types;
}
public static ArrayList<String> getCreatureTypes() {
final ArrayList<String> types = new ArrayList<String>();
types.addAll(Constant.CardTypes.CREATURE_TYPES);
return types;
}
public static boolean isASuperType(final String cardType) {
return (Constant.CardTypes.SUPER_TYPES.contains(cardType));
}
public static boolean isASubType(final String cardType) {
return (!CardType.isASuperType(cardType) && !CardType.isACardType(cardType));
}
public static boolean isACreatureType(final String cardType) {
return (Constant.CardTypes.CREATURE_TYPES.contains(cardType));
}
public static boolean isALandType(final String cardType) {
return (Constant.CardTypes.LAND_TYPES.contains(cardType));
}
public static boolean isAPlaneswalkerType(final String cardType) {
return (Constant.CardTypes.WALKER_TYPES.contains(cardType));
}
public static boolean isABasicLandType(final String cardType) {
return (Constant.CardTypes.BASIC_TYPES.contains(cardType));
}
}

View File

@@ -1,284 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card;
import forge.Constant;
import forge.card.mana.ManaCost;
import forge.util.BinaryUtil;
/**
* <p>CardColor class.</p>
* <p>Represents a set of any number of colors out of 5 possible in the game</p>
* <p><i>This class is immutable, do not generate any setters here</i></p>
*
* @author Max mtg
* @version $Id: CardColor.java 9708 2011-08-09 19:34:12Z jendave $
*
*
*/
public final class ColorSet implements Comparable<ColorSet> {
private final byte myColor;
private final int orderWeight;
private static ColorSet[] allColors = new ColorSet[32];
private static final ColorSet noColor = new ColorSet();
// 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 ColorSet(final byte mask) {
this.myColor = mask;
this.orderWeight = this.getOrderWeight();
}
public static ColorSet fromMask(final int mask) {
int mask32 = (mask & MagicColor.ALL_COLORS) >> 1;
if (allColors[mask32] == null) {
allColors[mask32] = new ColorSet((byte) mask);
}
return allColors[mask32];
}
public static ColorSet fromNames(String... colors) {
byte mask = 0;
for (String s : colors) {
mask |= MagicColor.fromName(s);
}
return fromMask(mask);
}
public static ColorSet fromNames(Iterable<String> colors) {
byte mask = 0;
for (String s : colors) {
mask |= MagicColor.fromName(s);
}
return fromMask(mask);
}
public static ColorSet fromManaCost(final ManaCost mana) {
return fromMask(mana.getColorProfile());
}
/**
* Checks for any color.
*
* @param colormask
* the colormask
* @return true, if successful
*/
public boolean hasAnyColor(final int colormask) {
return (this.myColor & colormask) != 0;
}
/**
* Checks for all colors.
*
* @param colormask
* the colormask
* @return true, if successful
*/
public boolean hasAllColors(final int colormask) {
return (this.myColor & colormask) == colormask;
}
/** this has no other colors except defined by operand. */
public boolean hasNoColorsExcept(final int colormask) {
return (this.myColor & ~colormask) == 0;
}
/** Operand has no other colors except defined by this. */
public boolean containsAllColorsFrom(int colorProfile) {
return (~this.myColor & colorProfile) == 0;
}
/**
* Count colors.
*
* @return the int
*/
public int countColors() {
return BinaryUtil.bitCount(this.myColor);
} // bit count
// order has to be: W U B R G multi colorless - same as cards numbering
// through a set
/**
* Gets the order weight.
*
* @return the order weight
*/
public int getOrderWeight() {
return this.myColor == 0 ? 0x400 : (this.countColors() == 1 ? this.myColor : 0x200);
}
/**
* Checks if is colorless.
*
* @return true, if is colorless
*/
public boolean isColorless() {
return this.myColor == 0;
}
/**
* Checks if is multicolor.
*
* @return true, if is multicolor
*/
public boolean isMulticolor() {
return this.countColors() > 1;
}
/**
* Checks if is mono color.
*
* @return true, if is mono color
*/
public boolean isMonoColor() {
return this.countColors() == 1;
}
/**
* Checks if is equal.
*
* @param color
* the color
* @return true, if is equal
*/
public boolean isEqual(final byte color) {
return color == this.myColor;
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(final ColorSet other) {
return this.orderWeight - other.orderWeight;
}
// Presets
/**
* Checks for white.
*
* @return true, if successful
*/
public boolean hasWhite() {
return this.hasAnyColor(MagicColor.WHITE);
}
/**
* Checks for blue.
*
* @return true, if successful
*/
public boolean hasBlue() {
return this.hasAnyColor(MagicColor.BLUE);
}
/**
* Checks for black.
*
* @return true, if successful
*/
public boolean hasBlack() {
return this.hasAnyColor(MagicColor.BLACK);
}
/**
* Checks for red.
*
* @return true, if successful
*/
public boolean hasRed() {
return this.hasAnyColor(MagicColor.RED);
}
/**
* Checks for green.
*
* @return true, if successful
*/
public boolean hasGreen() {
return this.hasAnyColor(MagicColor.GREEN);
}
public ColorSet inverse() {
byte mask = this.myColor;
mask ^= (MagicColor.WHITE | MagicColor.BLUE | MagicColor.BLACK | MagicColor.GREEN | MagicColor.RED);
return fromMask(mask);
}
public byte getColor() {
return myColor;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
if (this.orderWeight == -1) {
return "n/a";
}
String toReturn = MagicColor.toLongString(myColor);
if (toReturn == Constant.Color.COLORLESS && myColor != 0) {
return "multi";
}
return toReturn;
}
/**
* Gets the null color.
*
* @return the nullColor
*/
public static ColorSet getNullColor() {
return noColor;
}
/**
* Shares color with.
*
* @param ccOther the cc other
* @return true, if successful
*/
public boolean sharesColorWith(ColorSet ccOther) {
return (this.myColor & ccOther.myColor) != 0;
}
public ColorSet getOffColors(ColorSet ccOther) {
return ColorSet.fromMask(~this.myColor & ccOther.myColor);
}
}

View File

@@ -1,18 +0,0 @@
package forge.card;
import forge.card.mana.ManaCost;
public interface ICardCharacteristics {
String getName();
CardType getType();
ManaCost getManaCost();
ColorSet getColor();
int getIntPower();
int getIntToughness();
String getPower();
String getToughness();
int getInitialLoyalty();
String getOracleText();
}

View File

@@ -1,9 +0,0 @@
package forge.card;
/**
* TODO: Write javadoc for this type.
*
*/
public interface ICardFace extends ICardCharacteristics, ICardRawAbilites {
}

View File

@@ -1,16 +0,0 @@
package forge.card;
import java.util.Map.Entry;
public interface ICardRawAbilites
{
Iterable<String> getKeywords();
Iterable<String> getReplacements();
Iterable<String> getTriggers();
Iterable<String> getStaticAbilities();
Iterable<String> getAbilities();
String getNonAbilityText();
Iterable<Entry<String, String>> getVariables();
}

View File

@@ -1,74 +0,0 @@
package forge.card;
import forge.Constant;
/**
* Holds byte values for each color magic has.
*
*/
public class MagicColor {
public static final byte COLORLESS = 0;
public static final byte WHITE = 1 << 1;
public static final byte BLUE = 1 << 2;
public static final byte BLACK = 1 << 3;
public static final byte RED = 1 << 4;
public static final byte GREEN = 1 << 5;
public static final byte ALL_COLORS = BLACK | BLUE | WHITE | RED | GREEN;
public static final int NUMBER_OR_COLORS = 5;
public static final byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN };
public static byte fromName(String s) {
if( s == null ) return 0;
if (s.equalsIgnoreCase(Constant.Color.WHITE) || s.equalsIgnoreCase("w")) {
return MagicColor.WHITE;
}
if (s.equalsIgnoreCase(Constant.Color.BLUE) || s.equalsIgnoreCase("u")) {
return MagicColor.BLUE;
}
if (s.equalsIgnoreCase(Constant.Color.BLACK) || s.equalsIgnoreCase("b")) {
return MagicColor.BLACK;
}
if (s.equalsIgnoreCase(Constant.Color.RED) || s.equalsIgnoreCase("r")) {
return MagicColor.RED;
}
if (s.equalsIgnoreCase(Constant.Color.GREEN) || s.equalsIgnoreCase("g")) {
return MagicColor.GREEN;
}
return 0; // colorless
}
public static String toShortString(String color) {
if (color.equalsIgnoreCase(Constant.Color.SNOW)) return "S"; // compatibility
return toShortString(fromName(color));
}
public static String toLongString(String color) {
if (color.equalsIgnoreCase("s")) return Constant.Color.SNOW; // compatibility
return toLongString(fromName(color));
}
public static String toShortString(byte color) {
switch(color){
case GREEN: return "G";
case RED: return "R";
case BLUE: return "U";
case BLACK: return "B";
case WHITE: return "W";
default: return "1";
}
}
public static String toLongString(byte color) {
switch(color){
case GREEN: return Constant.Color.GREEN ;
case RED: return Constant.Color.RED;
case BLUE: return Constant.Color.BLUE;
case BLACK: return Constant.Color.BLACK;
case WHITE: return Constant.Color.WHITE;
default: return Constant.Color.COLORLESS;
}
}
}

View File

@@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map;
import forge.Card;
import forge.CardCharacteristicName;
import forge.card.CardCharacteristicName;
import forge.card.cost.Cost;
import forge.card.spellability.AbilitySub;
import forge.card.spellability.SpellAbility;

View File

@@ -12,13 +12,13 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
import forge.Constant;
import forge.GameEntity;
import forge.GameObject;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.ApiType;
import forge.card.ability.SpellAbilityAi;

View File

@@ -5,9 +5,9 @@ import java.util.List;
import com.google.common.collect.Iterables;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;

View File

@@ -9,13 +9,13 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardUtil;
import forge.CounterType;
import forge.GameEntity;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
import forge.card.ability.ai.ChangeZoneAi;

View File

@@ -6,10 +6,10 @@ import java.util.List;
import java.util.Map;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardUtil;
import forge.Command;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
import forge.card.cardfactory.CardFactory;

View File

@@ -12,10 +12,10 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.Command;
import forge.GameEntity;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils;

View File

@@ -7,8 +7,8 @@ import java.util.List;
import java.util.Random;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;

View File

@@ -3,7 +3,7 @@ package forge.card.ability.effects;
import java.util.List;
import forge.Card;
import forge.CardCharacteristicName;
import forge.card.CardCharacteristicName;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;

View File

@@ -11,7 +11,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardRulesPredicates;
import forge.card.ability.AbilityUtils;

View File

@@ -4,7 +4,7 @@ import java.util.Iterator;
import java.util.List;
import forge.Card;
import forge.CardCharacteristicName;
import forge.card.CardCharacteristicName;
import forge.card.ability.SpellAbilityEffect;
import forge.card.spellability.SpellAbility;
import forge.game.Game;

View File

@@ -23,10 +23,10 @@ import java.util.List;
import java.util.Map.Entry;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardColor;
import forge.CardUtil;
import forge.ImageCache;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.CardDb;
import forge.card.CardRules;

View File

@@ -26,7 +26,6 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardPredicates.Presets;
@@ -37,6 +36,7 @@ import forge.CounterType;
import forge.GameEntity;
import forge.GameLogEntryType;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardType;
import forge.card.ColorSet;
import forge.card.MagicColor;

View File

@@ -1,17 +0,0 @@
package forge.card.mana;
import java.util.Iterator;
/**
* The Interface ManaParser.
*/
public interface IParserManaCost extends Iterator<ManaCostShard> {
/**
* Gets the total colorless cost.
*
* @return the total colorless cost
*/
int getTotalColorlessCost();
}

View File

@@ -1,35 +0,0 @@
package forge.card.mana;
import forge.card.MagicColor;
/** A bitmask to represent any mana symbol as an integer. */
public abstract class ManaAtom {
public static final int COLORLESS = 1 << 0;
/** The Constant WHITE. */
public static final int WHITE = MagicColor.WHITE; // 1 << 1;
/** The Constant BLUE. */
public static final int BLUE = MagicColor.BLUE; // 1 << 2;
/** The Constant BLACK. */
public static final int BLACK = MagicColor.BLACK; // 1 << 3;
/** The Constant RED. */
public static final int RED = MagicColor.RED; // 1 << 4;
/** The Constant GREEN. */
public static final int GREEN = MagicColor.GREEN; // 1 << 5;
/** The Constant IS_X. */
public static final int IS_X = 1 << 8;
/** The Constant OR_2_COLORLESS. */
public static final int OR_2_COLORLESS = 1 << 9;
/** The Constant OR_2_LIFE. */
public static final int OR_2_LIFE = 1 << 10;
/** The Constant IS_SNOW. */
public static final int IS_SNOW = 1 << 11;
}

View File

@@ -1,291 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import forge.card.ColorSet;
/**
* <p>
* CardManaCost class.
* </p>
*
* @author Forge
* @version $Id: CardManaCost.java 9708 2011-08-09 19:34:12Z jendave $
*/
public final class ManaCost implements Comparable<ManaCost> {
private List<ManaCostShard> shards;
private final int genericCost;
private final boolean hasNoCost; // lands cost
private String stringValue; // precalculated for toString;
private Float compareWeight = null;
/** The Constant empty. */
public static final ManaCost NO_COST = new ManaCost(-1);
public static final ManaCost ZERO = new ManaCost(0);
public static final ManaCost ONE = new ManaCost(1);
public static final ManaCost TWO = new ManaCost(2);
public static final ManaCost THREE = new ManaCost(3);
public static final ManaCost FOUR = new ManaCost(4);
public static ManaCost get(int cntColorless) {
switch (cntColorless) {
case 0: return ZERO;
case 1: return ONE;
case 2: return TWO;
case 3: return THREE;
case 4: return FOUR;
}
return cntColorless > 0 ? new ManaCost(cntColorless) : NO_COST;
}
// pass mana cost parser here
private ManaCost(int cmc) {
this.hasNoCost = cmc < 0;
this.genericCost = cmc < 0 ? 0 : cmc;
sealClass(new ArrayList<ManaCostShard>());
}
private void sealClass(List<ManaCostShard> shards0) {
this.shards = Collections.unmodifiableList(shards0);
this.stringValue = this.getSimpleString();
}
// public ctor, should give it a mana parser
/**
* Instantiates a new card mana cost.
*
* @param parser
* the parser
*/
public ManaCost(final IParserManaCost parser) {
final List<ManaCostShard> shardsTemp = new ArrayList<ManaCostShard>();
this.hasNoCost = false;
while (parser.hasNext()) {
final ManaCostShard shard = parser.next();
if (shard != null && shard != ManaCostShard.COLORLESS) {
shardsTemp.add(shard);
} // null is OK - that was generic mana
}
this.genericCost = parser.getTotalColorlessCost(); // collect generic mana
// here
sealClass(shardsTemp);
}
private String getSimpleString() {
if (this.hasNoCost) {
return "no cost";
}
if (this.shards.isEmpty()) {
return Integer.toString(this.genericCost);
}
final StringBuilder sb = new StringBuilder();
boolean isFirst = true;
if (this.genericCost > 0) {
sb.append(this.genericCost);
isFirst = false;
}
for (final ManaCostShard s : this.shards) {
if (!isFirst) {
sb.append(' ');
} else {
isFirst = false;
}
sb.append(s.toString());
}
return sb.toString();
}
/**
* Gets the cMC.
*
* @return the cMC
*/
public int getCMC() {
int sum = 0;
for (final ManaCostShard s : this.shards) {
sum += s.getCmc();
}
return sum + this.genericCost;
}
/**
* Gets the color profile.
*
* @return the color profile
*/
public byte getColorProfile() {
byte result = 0;
for (final ManaCostShard s : this.shards) {
result |= s.getColorMask();
}
return result;
}
/**
* Gets the shards.
*
* @return the shards
*/
public List<ManaCostShard> getShards() {
return this.shards;
}
public int getShardCount(ManaCostShard which) {
if (which == ManaCostShard.COLORLESS) {
return genericCost;
}
int res = 0;
for (ManaCostShard shard : shards) {
if (shard == which) {
res++;
}
}
return res;
}
/**
* Gets the generic cost.
*
* @return the generic cost
*/
public int getGenericCost() {
return this.genericCost;
}
/**
* Checks if is empty.
*
* @return true, if is empty
*/
public boolean isNoCost() {
return this.hasNoCost;
}
/**
* Checks if is pure generic.
*
* @return true, if is pure generic
*/
public boolean isPureGeneric() {
return this.shards.isEmpty() && !this.isNoCost();
}
public boolean isZero() {
return genericCost == 0 && isPureGeneric();
}
/*
* (non-Javadoc)
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(final ManaCost o) {
return this.getCompareWeight().compareTo(o.getCompareWeight());
}
private Float getCompareWeight() {
if (this.compareWeight == null) {
float weight = this.genericCost;
for (final ManaCostShard s : this.shards) {
weight += s.getCmpc();
}
if (this.hasNoCost) {
weight = -1; // for those who doesn't even have a 0 sign on card
}
this.compareWeight = Float.valueOf(weight);
}
return this.compareWeight;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.stringValue;
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public boolean hasPhyrexian() {
for (ManaCostShard shard : shards) {
if (shard.isPhyrexian()) {
return true;
}
}
return false;
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public int countX() {
int iX = 0;
for (ManaCostShard shard : shards) {
if (shard == ManaCostShard.X) {
iX++;
}
}
return iX;
}
/**
* Can this mana cost be paid with unlimited mana of given color set.
* @param color
* @return
*/
public boolean canBePaidWithAvaliable(ColorSet color) {
for (ManaCostShard shard : shards) {
if (!shard.isPhyrexian() && !shard.canBePaidWithManaOfColor(color.getColor())) {
return false;
}
}
return true;
}
/**
* TODO: Write javadoc for this method.
* @param manaCost
* @param manaCost2
* @return
*/
public static ManaCost combine(ManaCost a, ManaCost b) {
ManaCost res = new ManaCost(a.genericCost + b.genericCost);
List<ManaCostShard> sh = new ArrayList<ManaCostShard>();
sh.addAll(a.shards);
sh.addAll(b.shards);
res.sealClass(sh);
return res;
}
}

View File

@@ -1,76 +0,0 @@
package forge.card.mana;
import org.apache.commons.lang3.StringUtils;
/**
* The Class ParserCardnameTxtManaCost.
*/
public class ManaCostParser implements IParserManaCost {
private final String[] cost;
private int nextToken;
private int colorlessCost;
/**
* Instantiates a new parser cardname txt mana cost.
*
* @param cost
* the cost
*/
public ManaCostParser(final String cost) {
this.cost = cost.split(" ");
// System.out.println(cost);
this.nextToken = 0;
this.colorlessCost = 0;
}
/*
* (non-Javadoc)
*
* @see forge.card.CardManaCost.ManaParser#getTotalColorlessCost()
*/
@Override
public final int getTotalColorlessCost() {
if (this.hasNext()) {
throw new RuntimeException("Colorless cost should be obtained after iteration is complete");
}
return this.colorlessCost;
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#hasNext()
*/
@Override
public final boolean hasNext() {
return this.nextToken < this.cost.length;
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#next()
*/
@Override
public final ManaCostShard next() {
final String unparsed = this.cost[this.nextToken++];
// System.out.println(unparsed);
if (StringUtils.isNumeric(unparsed)) {
this.colorlessCost += Integer.parseInt(unparsed);
return null;
}
return ManaCostShard.parseNonGeneric(unparsed);
}
/*
* (non-Javadoc)
*
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
} // unsuported
}

View File

@@ -1,280 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card.mana;
import forge.util.BinaryUtil;
/**
* The Class CardManaCostShard.
*/
public enum ManaCostShard implements Comparable<ManaCostShard> {
// declaration order matters! Place the shards that offer least ways to be paid for first
/* Pure colors */
WHITE(ManaAtom.WHITE, "W"),
BLUE(ManaAtom.BLUE, "U"),
BLACK(ManaAtom.BLACK, "B"),
RED(ManaAtom.RED, "R"),
GREEN(ManaAtom.GREEN, "G"),
/* Hybrid */
WU(ManaAtom.WHITE | ManaAtom.BLUE, "W/U", "WU"),
WB(ManaAtom.WHITE | ManaAtom.BLACK, "W/B", "WB"),
WR(ManaAtom.WHITE | ManaAtom.RED, "W/R", "RW"),
WG(ManaAtom.WHITE | ManaAtom.GREEN, "W/G", "GW"),
UB(ManaAtom.BLUE | ManaAtom.BLACK, "U/B", "UB"),
UR(ManaAtom.BLUE | ManaAtom.RED, "U/R", "UR"),
UG(ManaAtom.BLUE | ManaAtom.GREEN, "U/G", "GU"),
BR(ManaAtom.BLACK | ManaAtom.RED, "B/R", "BR"),
BG(ManaAtom.BLACK | ManaAtom.GREEN, "B/G", "BG"),
RG(ManaAtom.RED | ManaAtom.GREEN, "R/G", "RG"),
/* Or 2 colorless */
W2(ManaAtom.WHITE | ManaAtom.OR_2_COLORLESS, "2/W", "2W"),
U2(ManaAtom.BLUE | ManaAtom.OR_2_COLORLESS, "2/U", "2U"),
B2(ManaAtom.BLACK | ManaAtom.OR_2_COLORLESS, "2/B", "2B"),
R2(ManaAtom.RED | ManaAtom.OR_2_COLORLESS, "2/R", "2R"),
G2(ManaAtom.GREEN | ManaAtom.OR_2_COLORLESS, "2/G", "2G"),
// Snow and colorless
S(ManaAtom.IS_SNOW, "S"),
COLORLESS(ManaAtom.COLORLESS, "1"),
/* Phyrexian */
PW(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "W/P", "PW"),
PU(ManaAtom.BLUE | ManaAtom.OR_2_LIFE, "U/P", "PU"),
PB(ManaAtom.BLACK | ManaAtom.OR_2_LIFE, "B/P", "PB"),
PR(ManaAtom.RED | ManaAtom.OR_2_LIFE, "R/P", "PR"),
PG(ManaAtom.GREEN | ManaAtom.OR_2_LIFE, "G/P", "PG"),
X(ManaAtom.IS_X, "X");
private final int shard;
/** The cmc. */
private final int cmc;
/** The cmpc. */
private final float cmpc;
private final String stringValue;
/** The image key. */
private final String imageKey;
/**
* Instantiates a new card mana cost shard.
*
* @param value
* the value
* @param sValue
* the s value
*/
private ManaCostShard(final int value, final String sValue) {
this(value, sValue, sValue);
}
/**
* Instantiates a new card mana cost shard.
*
* @param value
* the value
* @param sValue
* the s value
* @param imgKey
* the img key
*/
private ManaCostShard(final int value, final String sValue, final String imgKey) {
this.shard = value;
this.cmc = this.getCMC();
this.cmpc = this.getCmpCost();
this.stringValue = sValue;
this.imageKey = imgKey;
}
public static final int COLORS_SUPERPOSITION = ManaAtom.WHITE | ManaAtom.BLUE | ManaAtom.BLACK | ManaAtom.RED | ManaAtom.GREEN;
private int getCMC() {
if (0 != (this.shard & ManaAtom.IS_X)) {
return 0;
}
if (0 != (this.shard & ManaAtom.OR_2_COLORLESS)) {
return 2;
}
return 1;
}
/**
* Returns Mana cost, adjusted slightly to make colored mana parts more
* significant. Should only be used for comparison purposes; using this
* method allows the sort: 2 < X 2 < 1 U < U U < UR U < X U U < X X U U
*
* @return The converted cost + 0.0005* the number of colored mana in the
* cost + 0.00001 * the number of X's in the cost
*/
private float getCmpCost() {
if (0 != (this.shard & ManaAtom.IS_X)) {
return 0.0001f;
}
float cost = 0 != (this.shard & ManaAtom.OR_2_COLORLESS) ? 2 : 1;
// yes, these numbers are magic, slightly-magic
if (0 != (this.shard & ManaAtom.WHITE)) {
cost += 0.0005f;
}
if (0 != (this.shard & ManaAtom.BLUE)) {
cost += 0.0020f;
}
if (0 != (this.shard & ManaAtom.BLACK)) {
cost += 0.0080f;
}
if (0 != (this.shard & ManaAtom.RED)) {
cost += 0.0320f;
}
if (0 != (this.shard & ManaAtom.GREEN)) {
cost += 0.1280f;
}
if (0 != (this.shard & ManaAtom.OR_2_LIFE)) {
cost += 0.00003f;
}
return cost;
}
/**
* Gets the color mask.
*
* @return the color mask
*/
public final byte getColorMask() {
return (byte)(this.shard & COLORS_SUPERPOSITION);
}
/**
* Value of.
*
* @param atoms
* the atoms
* @return the card mana cost shard
*/
public static ManaCostShard valueOf(final int atoms) {
if ( atoms == 0 ) return ManaCostShard.COLORLESS;
for (final ManaCostShard element : ManaCostShard.values()) {
if (element.shard == atoms) {
return element;
}
}
return null; // will consider anything else plain colorless;
//throw new RuntimeException(String.format("Not found: mana shard with profile = %x", atoms));
}
public static ManaCostShard parseNonGeneric(final String unparsed) {
int atoms = 0;
for (int iChar = 0; iChar < unparsed.length(); iChar++) {
char c = unparsed.charAt(iChar);
switch (c) {
case 'W': atoms |= ManaAtom.WHITE; break;
case 'U': atoms |= ManaAtom.BLUE; break;
case 'B': atoms |= ManaAtom.BLACK; break;
case 'R': atoms |= ManaAtom.RED; break;
case 'G': atoms |= ManaAtom.GREEN; break;
case 'P': atoms |= ManaAtom.OR_2_LIFE; break;
case 'S': atoms |= ManaAtom.IS_SNOW; break;
case 'X': atoms |= ManaAtom.IS_X; break;
case '2': atoms |= ManaAtom.OR_2_COLORLESS; break;
default:
if (c <= '9' && c >= '0') {
atoms |= ManaAtom.COLORLESS;
}
break;
}
}
// for cases when unparsed equals '2' or unparsed is like '12' or '20'
if (atoms == ManaAtom.OR_2_COLORLESS || atoms == (ManaAtom.OR_2_COLORLESS | ManaAtom.COLORLESS)) {
atoms = ManaAtom.COLORLESS;
}
return ManaCostShard.valueOf(atoms);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public final String toString() {
return this.stringValue;
}
/**
* Gets the cmc.
*
* @return the cmc
*/
public int getCmc() {
return this.cmc;
}
/**
* Gets the cmpc.
*
* @return the cmpc
*/
public float getCmpc() {
return this.cmpc;
}
/**
* Gets the image key.
*
* @return the imageKey
*/
public String getImageKey() {
return this.imageKey;
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public boolean isPhyrexian() {
return (this.shard & ManaAtom.OR_2_LIFE) != 0;
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public boolean isSnow() {
return (this.shard & ManaAtom.IS_SNOW) != 0;
}
public boolean isMonoColor() {
return BinaryUtil.bitCount(this.shard & COLORS_SUPERPOSITION) == 1;
}
public boolean isOr2Colorless() {
return (this.shard & ManaAtom.OR_2_COLORLESS) != 0;
}
public boolean canBePaidWithManaOfColor(byte colorCode) {
return this.isOr2Colorless() || (COLORS_SUPERPOSITION & this.shard) == 0 || (colorCode & this.shard) > 0;
}
}

View File

@@ -20,8 +20,8 @@ package forge.card.spellability;
import java.util.Arrays;
import forge.Card;
import forge.CardCharacteristicName;
import forge.Command;
import forge.card.CardCharacteristicName;
import forge.card.CardCharacteristics;
import forge.card.mana.ManaCost;
import forge.card.trigger.ZCTrigger;

View File

@@ -34,7 +34,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.CardUtil;
@@ -44,6 +43,7 @@ import forge.FThreads;
import forge.GameEntity;
import forge.GameLogEntryType;
import forge.GameObject;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.CardType;
import forge.card.TriggerReplacementBase;

View File

@@ -38,11 +38,11 @@ import javax.swing.border.EtchedBorder;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardUtil;
import forge.CounterType;
import forge.GameEntity;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardEdition;
import forge.card.CardType;
import forge.card.ColorSet;

View File

@@ -24,9 +24,9 @@ import java.awt.image.BufferedImage;
import javax.swing.JPanel;
import forge.Card;
import forge.CardCharacteristicName;
import forge.ImageCache;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FSkin.JComponentSkin;
import forge.gui.toolbox.imaging.FImagePanel;

View File

@@ -37,11 +37,11 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardLists;
import forge.CardPredicates;
import forge.CounterType;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardDb;
import forge.card.spellability.AbilityManaPart;
import forge.card.spellability.SpellAbility;

View File

@@ -24,9 +24,9 @@ import java.awt.event.MouseWheelListener;
import javax.swing.JLabel;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardUtil;
import forge.Command;
import forge.card.CardCharacteristicName;
import forge.gui.CardPicturePanel;
import forge.gui.framework.ICDoc;
import forge.gui.match.views.VPicture;

View File

@@ -5,8 +5,8 @@ import java.util.ArrayList;
import java.util.List;
import forge.Card;
import forge.CardCharacteristicName;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.cardfactory.CardFactory;
import forge.game.zone.PlayerZone;
import forge.gui.ForgeAction;

View File

@@ -22,8 +22,8 @@ import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import forge.Card;
import forge.CardCharacteristicName;
import forge.ImageCache;
import forge.card.CardCharacteristicName;
import forge.gui.toolbox.CardFaceSymbols;
import forge.gui.toolbox.FSkin.ComponentSkin;

View File

@@ -32,8 +32,8 @@ import javax.swing.Timer;
import net.miginfocom.swing.MigLayout;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardUtil;
import forge.card.CardCharacteristicName;
import forge.gui.SOverlayUtils;
import forge.gui.toolbox.FOverlay;
import forge.gui.toolbox.FSkin;

View File

@@ -1,46 +0,0 @@
package forge.util;
/**
* TODO: Write javadoc for this type.
*
*/
public class BinaryUtil {
public static int bitCount(final int num) {
int v = num;
int c = 0;
for (; v != 0; c++) {
v &= v - 1;
}
return c;
} // bit count
public static int bitCount(final byte num) {
byte v = num;
int c = 0;
for (; v != 0; c++) {
v &= v - 1;
}
return c;
} // bit count
public static int bitCount(final short num) {
short v = num;
int c = 0;
for (; v != 0; c++) {
v &= v - 1;
}
return c;
} // bit count
public static int getLeastImportantBitIndex(final byte num) {
if( num == 0 ) return -1;
byte mask = 1;
for(int i = 0; mask != 0; i++) {
if( (mask & num) != 0)
return i;
mask = (byte) (mask << 1);
}
return -1;
}
}

View File

@@ -36,10 +36,10 @@ import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CounterType;
import forge.ImageCache;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardEdition;
import forge.card.mana.ManaCost;
import forge.game.combat.Combat;