forked from External/mage
Moved Mage.Common classes from src to src/main/java
This commit is contained in:
parent
e9d31aa93c
commit
21eb420c16
102 changed files with 0 additions and 0 deletions
72
Mage.Common/src/main/java/mage/utils/CardUtil.java
Normal file
72
Mage.Common/src/main/java/mage/utils/CardUtil.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package mage.utils;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.constants.CardType;
|
||||
import mage.view.CardView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class for {@link CardView}
|
||||
*
|
||||
* @version 0.1 02.11.2010
|
||||
* @author nantuko
|
||||
*/
|
||||
public final class CardUtil {
|
||||
|
||||
private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
|
||||
private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
|
||||
private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
|
||||
private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
|
||||
private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
|
||||
|
||||
|
||||
|
||||
|
||||
public static boolean isCreature(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.CREATURE);
|
||||
}
|
||||
|
||||
public static boolean isPlaneswalker(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.PLANESWALKER);
|
||||
}
|
||||
|
||||
public static boolean isLand(MagePermanent card) {
|
||||
return is(card.getOriginal(), CardType.LAND);
|
||||
}
|
||||
|
||||
public static boolean is(CardView card, CardType type) {
|
||||
return card.getCardTypes().contains(type);
|
||||
}
|
||||
|
||||
public static int getColorIdentitySortValue(List<String> manaCost, ObjectColor originalColor, List<String> rules) {
|
||||
ObjectColor color = new ObjectColor(originalColor);
|
||||
for (String rule : rules) {
|
||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||
if (rule.matches(regexBlack)) {
|
||||
color.setBlack(true);
|
||||
}
|
||||
if (rule.matches(regexBlue)) {
|
||||
color.setBlue(true);
|
||||
}
|
||||
if (rule.matches(regexGreen)) {
|
||||
color.setGreen(true);
|
||||
}
|
||||
if (rule.matches(regexRed)) {
|
||||
color.setRed(true);
|
||||
}
|
||||
if (rule.matches(regexWhite)) {
|
||||
color.setWhite(true);
|
||||
}
|
||||
}
|
||||
|
||||
int hash = 3;
|
||||
hash = 23 * hash + (color.isWhite() || manaCost.contains("{W}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isBlue() || manaCost.contains("{U}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isBlack() || manaCost.contains("{B}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isRed() || manaCost.contains("{R}") ? 1 : 0);
|
||||
hash = 23 * hash + (color.isGreen() || manaCost.contains("{G}") ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue