diff --git a/.gitattributes b/.gitattributes index 7767eea88f9..e965eb20dc8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -240,6 +240,7 @@ src/forge/CardListFilter.java svneol=native#text/plain src/forge/CardListUtil.java svneol=native#text/plain src/forge/CardShopTableModel.java -text svneol=native#text/plain src/forge/CardUtil.java svneol=native#text/plain +src/forge/Color.java -text svneol=native#text/plain src/forge/Combat.java svneol=native#text/plain src/forge/CombatPlaneswalker.java svneol=native#text/plain src/forge/CombatUtil.java svneol=native#text/plain diff --git a/src/forge/Card.java b/src/forge/Card.java index cd5fabe1ce0..bbfda568a5b 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -5,10 +5,15 @@ package forge; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; +import java.util.Set; +import java.util.StringTokenizer; import java.util.Map.Entry; +import forge.error.ErrorViewer; + public class Card extends MyObservable { private static int nextUniqueNumber; @@ -80,6 +85,10 @@ public class Card extends MyObservable { private int otherAttackBoost = 0; private int otherDefenseBoost = 0; + //updates for Colorness refactor + private ArrayList baseColors = new ArrayList(); + private ArrayList currentColors = new ArrayList(); + private int randomPicture = 0; private int upkeepDamage = 0; @@ -969,6 +978,261 @@ public class Card extends MyObservable { this.updateObservers(); } + //======================================================================= + //Color refactor begin + + public ArrayList setBaseColors(ArrayList colors) { + baseColors.clear(); + for(Color color:colors) { + baseColors.add(color); + } + return baseColors; + } + + public ArrayList getBaseColors() { + return baseColors; + } + + public ArrayList addColor(Color color) { + if(!currentColors.contains(color)) { + currentColors.add(color); + } + return currentColors; + } + + //maybe this should return the new currentColor list? + public boolean removeColor(Color color) { + if(currentColors.contains(color)) { + currentColors.remove(color); + return true; + } + else { + return false; + } + } + + public ArrayList setColors(Color... colors) { + for(Color color:colors) { + addColor(color); + } + return currentColors; + } + + public ArrayList setColors(ArrayList colors) { + Color[] colorArray = new Color[colors.size()]; + return setColors(colors.toArray(colorArray)); + } + + public ArrayList getColorsNew() { + return currentColors; + } + + public boolean isBlack() { + return currentColors.contains(Color.BLACK); + } + + public boolean isBlue() { + return currentColors.contains(Color.BLUE); + } + + public boolean isGreen() { + return currentColors.contains(Color.GREEN); + } + + public boolean isRed() { + return currentColors.contains(Color.RED); + } + + public boolean isWhite() { + return currentColors.contains(Color.WHITE); + } + + public boolean isColorless() { + return currentColors.isEmpty(); + } + + ///////////from CardUtil.java + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + //returns something like Constant.Color.Green or something + /* public static String getColor(Card c) { + + String manaCost = c.getManaCost(); + + if(-1 != manaCost.indexOf("G")) return Constant.Color.Green; + else if(-1 != manaCost.indexOf("W")) return Constant.Color.White; + else if(-1 != manaCost.indexOf("B")) return Constant.Color.Black; + else if(-1 != manaCost.indexOf("U")) return Constant.Color.Blue; + else if(-1 != manaCost.indexOf("R")) return Constant.Color.Red; + else return Constant.Color.Colorless; + return null; + } */ + + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + /** + * gets a list of all of the colors that this card is based on the mana cost in cards.txt + * + * @return an ArrayList with the enumerated colors + */ + public ArrayList getColorsBasedOnManaCost() { + String m = this.getManaCost(); + Set colors = new HashSet(); + + for(int i = 0; i < m.length(); i++) { + switch(m.charAt(i)) { + case ' ': + break; + case 'G': + colors.add(Color.GREEN); + break; + case 'W': + colors.add(Color.WHITE); + break; + case 'B': + colors.add(Color.BLACK); + break; + case 'U': + colors.add(Color.BLUE); + break; + case 'R': + colors.add(Color.RED); + break; + } + } + return new ArrayList(colors); + /* + for(String kw : this.getKeyword()) + if(kw.startsWith(this.getName()+" is ")) { + for(Color color : Color.values()) + if(kw.endsWith(color.getName()+".")) + colors.add(color); + if(kw.endsWith("is Colorless.")) { + colors.clear(); + } + } + //if(colors.isEmpty()) colors.add(Constant.Color.Colorless); + */ + }//getColorsBasedOnManaCost + + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + /* + * public static ArrayList getOnlyColors(Card c) { + + String m = c.getManaCost(); + Set colors = new HashSet(); + + for(int i = 0; i < m.length(); i++) { + switch(m.charAt(i)) { + case ' ': + break; + case 'G': + colors.add(Constant.Color.Green); + break; + case 'W': + colors.add(Constant.Color.White); + break; + case 'B': + colors.add(Constant.Color.Black); + break; + case 'U': + colors.add(Constant.Color.Blue); + break; + case 'R': + colors.add(Constant.Color.Red); + break; + } + } + for(String kw : c.getKeyword()) + if(kw.startsWith(c.getName()+" is ")) + for(String color : Constant.Color.Colors) + if(kw.endsWith(color+".")) + colors.add(color); + return new ArrayList(colors); + } + */ + /////////////end from CardUtil.java + + //Color refactor End + //======================================================================= + + //======================================================================= + //mana cost refactor + + + + + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + /* + //probably should put this somewhere else, but not sure where + static public int getConvertedManaCost(SpellAbility sa) { + return getConvertedManaCost(sa.getManaCost()); + }*/ + + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + /* + public int getConvertedManaCost() { + if (this.isToken() && !this.isCopiedToken()) + return 0; + return getConvertedManaCost(this.getManaCost()); + } */ + + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java (from CardUtil.java + */ + public int getConvertedManaCost() { + //see if the mana cost is all colorless, like "2", "0", or "12" + + if(manaCost.equals("")) return 0; + + while (manaCost.startsWith("X")) + manaCost = manaCost.substring(2); + + if(!manaCost.matches(".*[A-Z]+.*")) { + try { + return Integer.parseInt(manaCost); + } catch(NumberFormatException ex) { + ErrorViewer.showError(ex); + } + } + + //see if mana cost is colored and colorless like "2 B" or "1 U U" + StringTokenizer tok = new StringTokenizer(manaCost); + int cost = 0; + try { + //get the int from the mana cost like "1 U", get the 1 + cost = Integer.parseInt(tok.nextToken()); + //count colored mana cost + cost += tok.countTokens(); + return cost; + } + //catches in case the cost has no colorless mana requirements like "U U" + catch(NumberFormatException ex) {} + + //the mana cost is all colored mana like "U" or "B B B" + tok = new StringTokenizer(manaCost); + return tok.countTokens(); + } + + //end warning for moving to Card.java + + //end mana cost refactor + //======================================================================= + public ArrayList getEquippedBy() { return equippedBy; } diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index 3b2690cc6ed..7d983dc7243 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -19838,6 +19838,8 @@ public class CardFactory implements NewConstants { c.setType(sim.getType()); c.setText(sim.getSpellText()); c.setManaCost(sim.getManaCost()); + //for Color refactor + //c.setBaseColors(sim.getBaseColors()); return c; }// copyStats() diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index 57684f5a374..b621e106120 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -3527,6 +3527,8 @@ public class CardFactoryUtil { //do card1 and card2 share any colors? public static boolean sharesColorWith(Card card1, Card card2) { + //slapshot5 - not sure why this needs getOnlyColors vs. getColors() + //Color refactor ArrayList card1Colors = CardUtil.getOnlyColors(card1); ArrayList card2Colors = CardUtil.getOnlyColors(card2); diff --git a/src/forge/CardUtil.java b/src/forge/CardUtil.java index 93319cc3333..14290aa0783 100644 --- a/src/forge/CardUtil.java +++ b/src/forge/CardUtil.java @@ -69,7 +69,7 @@ public class CardUtil { a.add(c[i]); return a; } - + //returns "G", longColor is Constant.Color.Green and the like public static String getShortColor(String longColor) { Map map = new HashMap(); @@ -85,7 +85,10 @@ public class CardUtil { return (String) o; } - + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ //returns something like Constant.Color.Green or something public static String getColor(Card c) { String manaCost = c.getManaCost(); @@ -98,6 +101,10 @@ public class CardUtil { else return Constant.Color.Colorless; } + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ public static ArrayList getColors(Card c) { String m = c.getManaCost(); Set colors = new HashSet(); @@ -135,6 +142,10 @@ public class CardUtil { return new ArrayList(colors); } + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ public static ArrayList getOnlyColors(Card c) { String m = c.getManaCost(); Set colors = new HashSet(); @@ -168,26 +179,19 @@ public class CardUtil { return new ArrayList(colors); } - - public static boolean hasCardName(String cardName, ArrayList list) { - Card c; - boolean b = false; - - for(int i = 0; i < list.size(); i++) { - c = list.get(i); - if(c.getName().equals(cardName)) { - b = true; - break; - } - } - return b; - }//hasCardName() - + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ //probably should put this somewhere else, but not sure where static public int getConvertedManaCost(SpellAbility sa) { return getConvertedManaCost(sa.getManaCost()); } + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ static public int getConvertedManaCost(Card c) { if (c.isToken() && !c.isCopiedToken()) @@ -195,6 +199,10 @@ public class CardUtil { return getConvertedManaCost(c.getManaCost()); } + /* ***Warning*** - the following functions are being refactored to be + * properties of the card. If you make changes here, please add them to + * the corresponding function in Card.java + */ static public int getConvertedManaCost(String manaCost) { //see if the mana cost is all colorless, like "2", "0", or "12" @@ -229,6 +237,22 @@ public class CardUtil { return tok.countTokens(); } + //end warning for moving to Card.java + + public static boolean hasCardName(String cardName, ArrayList list) { + Card c; + boolean b = false; + + for(int i = 0; i < list.size(); i++) { + c = list.get(i); + if(c.getName().equals(cardName)) { + b = true; + break; + } + } + return b; + }//hasCardName() + static public String addManaCosts(String mc1, String mc2) { String tMC = ""; diff --git a/src/forge/Color.java b/src/forge/Color.java new file mode 100644 index 00000000000..334adec1530 --- /dev/null +++ b/src/forge/Color.java @@ -0,0 +1,35 @@ +/** + * Color.java + * + * Created on 5.1.2010 + */ + +package forge; + +/** + * The class Color. + * + * @author dennis.r.friedrichsen + */ +public enum Color { + BLACK("black"), + BLUE("blue"), + GREEN("green"), + RED("red"), + WHITE("white"); //, + //COLORLESS("colorless"); + + private String name; + + private Color() { + this.name = name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase(); + } + + private Color(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/forge/ReadCard.java b/src/forge/ReadCard.java index e86e258390d..946e521d832 100644 --- a/src/forge/ReadCard.java +++ b/src/forge/ReadCard.java @@ -76,7 +76,14 @@ public class ReadCard implements Runnable, NewConstants { s = readLine(); - if(!s.equals("no cost")) c.setManaCost(s); + if(!s.equals("no cost")) { + c.setManaCost(s); + //c.setBaseColors(c.getColorsBasedOnManaCost()); + } + else { + //c.setBaseColors(new ArrayList()); + } + //c.setColors(c.getBaseColors()); s = readLine(); addTypes(c, s);