diff --git a/src/main/java/forge/CardContainer.java b/src/main/java/forge/CardContainer.java index 118f7b9da65..692af1e3153 100644 --- a/src/main/java/forge/CardContainer.java +++ b/src/main/java/forge/CardContainer.java @@ -6,24 +6,29 @@ package forge; - /** - * The class CardContainer. A card container is an object that references a card. - * + * The class CardContainer. A card container is an object that references a + * card. + * * @author Clemens Koza * @version V0.0 17.02.2010 */ public interface CardContainer { /** - *

setCard.

- * - * @param card a {@link forge.Card} object. + *

+ * setCard. + *

+ * + * @param card + * a {@link forge.Card} object. */ void setCard(Card card); /** - *

getCard.

- * + *

+ * getCard. + *

+ * * @return a {@link forge.Card} object. */ Card getCard(); diff --git a/src/main/java/forge/CardFilter.java b/src/main/java/forge/CardFilter.java index 179a969a595..d48f29bca13 100644 --- a/src/main/java/forge/CardFilter.java +++ b/src/main/java/forge/CardFilter.java @@ -9,25 +9,28 @@ import net.slightlymagic.braids.util.lambda.Lambda1; import com.google.code.jyield.Generator; /** - *

CardFilter class.

- * + *

+ * CardFilter class. + *

+ * * @author Forge * @version $Id$ */ public class CardFilter { - /** * Filter a sequence (iterable) of cards to a list of equal or smaller size * whose names contain the given substring. * * We perform the substring search without sensitivity to case. - * - * @param toBeFiltered an {@link java.lang.Iterable} of Card instances - * @param substring a {@link java.lang.String} object. + * + * @param toBeFiltered + * an {@link java.lang.Iterable} of Card instances + * @param substring + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ - public CardList cardListNameFilter(Iterable toBeFiltered, String substring) { + public final CardList cardListNameFilter(final Iterable toBeFiltered, final String substring) { String s; CardList listFilter = new CardList(); @@ -45,12 +48,16 @@ public class CardFilter { } /** - *

CardListTextFilter.

- * - * TODO style: rename this method so it starts with a lowercase letter - * - * @param all a {@link forge.CardList} object. - * @param name a {@link java.lang.String} object. + *

+ * CardListTextFilter. + *

+ * + * TODO style: rename this method so it starts with a lowercase letter + * + * @param all + * a {@link forge.CardList} object. + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList CardListTextFilter(CardList all, String name) { @@ -72,14 +79,17 @@ public class CardFilter { return listFilter; } - /** - *

CardListColorFilter.

- * - * TODO style: rename this method so it starts with a lowercase letter - * - * @param all a {@link forge.CardList} object. - * @param name a {@link java.lang.String} object. + *

+ * CardListColorFilter. + *

+ * + * TODO style: rename this method so it starts with a lowercase letter + * + * @param all + * a {@link forge.CardList} object. + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList CardListColorFilter(CardList all, String name) { @@ -89,7 +99,7 @@ public class CardFilter { if (name == "black") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.Black) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.Black)) { listFilter.add(CardName); } @@ -99,7 +109,7 @@ public class CardFilter { if (name == "blue") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.Blue) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.Blue)) { listFilter.add(CardName); } @@ -109,7 +119,7 @@ public class CardFilter { if (name == "green") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.Green) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.Green)) { listFilter.add(CardName); } @@ -119,7 +129,7 @@ public class CardFilter { if (name == "red") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.Red) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.Red)) { listFilter.add(CardName); } @@ -129,7 +139,7 @@ public class CardFilter { if (name == "white") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.White) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.White)) { listFilter.add(CardName); } @@ -139,7 +149,7 @@ public class CardFilter { if (name.equals("colorless")) { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardUtil.getColors(CardName).contains(Constant.Color.Colorless) == false) { + if (!CardUtil.getColors(CardName).contains(Constant.Color.Colorless)) { listFilter.add(CardName); } @@ -150,22 +160,26 @@ public class CardFilter { } /** - *

CardListTypeFilter.

- * - * TODO style: rename this method so it starts with a lowercase letter - * - * @param all a {@link forge.CardList} object. - * @param name a {@link java.lang.String} object. + *

+ * CardListTypeFilter. + *

+ * + * TODO style: rename this method so it starts with a lowercase letter + * + * @param all + * a {@link forge.CardList} object. + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ - public CardList CardListTypeFilter(CardList all, String name) { + public final CardList CardListTypeFilter(CardList all, String name) { Card CardName = new Card(); CardList listFilter = new CardList(); if (name == "artifact") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isArtifact() == false) { + if (!CardName.isArtifact()) { listFilter.add(CardName); } @@ -175,7 +189,7 @@ public class CardFilter { if (name == "creature") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isCreature() == false) { + if (!CardName.isCreature()) { listFilter.add(CardName); } @@ -185,7 +199,7 @@ public class CardFilter { if (name == "enchantment") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isEnchantment() == false) { + if (!CardName.isEnchantment()) { listFilter.add(CardName); } @@ -195,7 +209,7 @@ public class CardFilter { if (name == "instant") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isInstant() == false) { + if (!CardName.isInstant()) { listFilter.add(CardName); } @@ -205,7 +219,7 @@ public class CardFilter { if (name == "land") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isLand() == false) { + if (!CardName.isLand()) { listFilter.add(CardName); } @@ -215,7 +229,7 @@ public class CardFilter { if (name == "planeswalker") { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isPlaneswalker() == false) { + if (!CardName.isPlaneswalker()) { listFilter.add(CardName); } @@ -225,7 +239,7 @@ public class CardFilter { if (name.equals("sorcery")) { for (int i = 0; i < all.size(); i++) { CardName = all.getCard(i); - if (CardName.isSorcery() == false) { + if (!CardName.isSorcery()) { listFilter.add(CardName); } @@ -235,100 +249,104 @@ public class CardFilter { return listFilter; } + /** + * Filter an iterable sequence of Cards; note this is a static method that + * is very similar to the non-static one. + * + * @param iterable + * the sequence of cards to examine + * + * @param filt + * determines which cards are present in the resulting list + * + * @return a list of Cards that meet the filtering criteria; may be empty, + * but never null + */ + public static CardList filter(final Iterable iterable, final CardListFilter filt) { + CardList result = new CardList(); + for (Card card : iterable) { + if (filt.addCard(card)) { + result.add(card); + } + } - /** - * Filter an iterable sequence of Cards; note this is a static method - * that is very similar to the non-static one. - * - * @param iterable the sequence of cards to examine - * - * @param filt determines which cards are present in the resulting list - * - * @return a list of Cards that meet the filtering criteria; may be empty, - * but never null - */ - public static CardList filter(final Iterable iterable, final CardListFilter filt) { - CardList result = new CardList(); - for (Card card : iterable) { - if (filt.addCard(card)) { - result.add(card); - } - } - - return result; - } - - /** - * Filter a Generator of Cards based on their colors; this does not cause - * the generator to be evaluated, but rather defers the filtering to when - * the result's generate method is called (e.g., by YieldUtils.toIterable). - * - * @param inputGenerator the sequence to filter; must not be null - * - * @param cardColor - * a {@link java.lang.String} object; "Multicolor" is also - * accepted. Must not be null. - * - * @return a new Generator containing cards only of the desired color or - * multicolored cards. - */ - public static Generator getColor(final Generator inputGenerator, final String cardColor) { - UtilFunctions.checkNotNull("inputGenerator", inputGenerator); - UtilFunctions.checkNotNull("cardColor", cardColor); - - final boolean weWantMulticolor = cardColor.equals("Multicolor"); - - Lambda1 predicate = new Lambda1() { - public Boolean apply(final Card c) { - if (c == null) { - return false; - } - - if (weWantMulticolor && c.getColor() != null && c.getColor().size() > 1) { - return true; - } - else if (c.isColor(cardColor) && c.getColor() != null && c.getColor().size() == 1) { - return true; - } - - return false; - } - }; - - return GeneratorFunctions.filterGenerator(predicate, inputGenerator); - } //getColor() + return result; + } /** - * Filter a Generator of cards so that it contains only the ones that exist in certain sets. - * - * @param inputGenerator a sequence Generator of Card instances; must not be null. - * - * @param sets an ArrayList of Strings identifying the valid sets; must not be null. - * - * @return a {@link forge.CardList} object. - */ - public static Generator getSets(final Generator inputGenerator, final List sets) - { - UtilFunctions.checkNotNull("inputGenerator", inputGenerator); - UtilFunctions.checkNotNull("sets", sets); + * Filter a Generator of Cards based on their colors; this does not cause + * the generator to be evaluated, but rather defers the filtering to when + * the result's generate method is called (e.g., by YieldUtils.toIterable). + * + * @param inputGenerator + * the sequence to filter; must not be null + * + * @param cardColor + * a {@link java.lang.String} object; "Multicolor" is also + * accepted. Must not be null. + * + * @return a new Generator containing cards only of the desired color or + * multicolored cards. + */ + public static Generator getColor(final Generator inputGenerator, final String cardColor) { + UtilFunctions.checkNotNull("inputGenerator", inputGenerator); + UtilFunctions.checkNotNull("cardColor", cardColor); - Lambda1 predicate = new Lambda1() { - public Boolean apply(final Card c) { - if (c == null) { - return false; - } + final boolean weWantMulticolor = cardColor.equals("Multicolor"); - for (SetInfo set : c.getSets()) { - if (set != null && sets.contains(set.toString())) { - return true; - } - } + Lambda1 predicate = new Lambda1() { + public Boolean apply(final Card c) { + if (c == null) { + return false; + } - return false; - } - }; + if (weWantMulticolor && c.getColor() != null && c.getColor().size() > 1) { + return true; + } else if (c.isColor(cardColor) && c.getColor() != null && c.getColor().size() == 1) { + return true; + } - return GeneratorFunctions.filterGenerator(predicate, inputGenerator); - } //getSets(Generator,ArrayList) + return false; + } + }; + + return GeneratorFunctions.filterGenerator(predicate, inputGenerator); + } // getColor() + + /** + * Filter a Generator of cards so that it contains only the ones that exist + * in certain sets. + * + * @param inputGenerator + * a sequence Generator of Card instances; must not be null. + * + * @param sets + * an ArrayList of Strings identifying the valid sets; must not + * be null. + * + * @return a {@link forge.CardList} object. + */ + public static Generator getSets(final Generator inputGenerator, final List sets) { + UtilFunctions.checkNotNull("inputGenerator", inputGenerator); + UtilFunctions.checkNotNull("sets", sets); + + Lambda1 predicate = new Lambda1() { + public Boolean apply(final Card c) { + if (c == null) { + return false; + } + + for (SetInfo set : c.getSets()) { + if (set != null && sets.contains(set.toString())) { + return true; + } + } + + return false; + } + }; + + return GeneratorFunctions.filterGenerator(predicate, inputGenerator); + } // getSets(Generator,ArrayList) } diff --git a/src/main/java/forge/CardList.java b/src/main/java/forge/CardList.java index 4fc3179c6bd..5d5c7cf3506 100644 --- a/src/main/java/forge/CardList.java +++ b/src/main/java/forge/CardList.java @@ -1,28 +1,31 @@ package forge; - -import com.google.code.jyield.Generator; -import com.google.code.jyield.Yieldable; -import forge.card.cardFactory.CardFactoryUtil; - import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; +import com.google.code.jyield.Generator; +import com.google.code.jyield.Yieldable; + +import forge.card.cardFactory.CardFactoryUtil; /** - *

CardList class.

- * + *

+ * CardList class. + *

+ * * @author Forge * @version $Id$ */ public class CardList implements Iterable { /** - *

iterator.

- * + *

+ * iterator. + *

+ * * @return a {@link java.util.Iterator} object. */ public final Iterator iterator() { @@ -32,24 +35,32 @@ public class CardList implements Iterable { private ArrayList list = new ArrayList(); /** - *

Constructor for CardList.

+ *

+ * Constructor for CardList. + *

*/ public CardList() { } /** - *

Constructor for CardList.

- * - * @param c a {@link forge.Card} object. + *

+ * Constructor for CardList. + *

+ * + * @param c + * a {@link forge.Card} object. */ public CardList(final Card... c) { addAll(c); } /** - *

Constructor for CardList.

- * - * @param al a {@link java.util.ArrayList} object. + *

+ * Constructor for CardList. + *

+ * + * @param al + * a {@link java.util.ArrayList} object. */ public CardList(final List al) { addAll(al.toArray()); @@ -58,9 +69,9 @@ public class CardList implements Iterable { /** * Make a shallow copy of an Iterable's contents; this could be another * CardList. - * - * @param iterable we traverse this and copy its contents into a local - * field. + * + * @param iterable + * we traverse this and copy its contents into a local field. */ public CardList(final Iterable iterable) { for (Card card : iterable) { @@ -69,9 +80,12 @@ public class CardList implements Iterable { } /** - *

Constructor for CardList.

- * - * @param c an array of {@link java.lang.Object} objects. + *

+ * Constructor for CardList. + *

+ * + * @param c + * an array of {@link java.lang.Object} objects. */ public CardList(final Object[] c) { addAll(c); @@ -82,10 +96,11 @@ public class CardList implements Iterable { * * We ignore null values produced by the generator. * - * @param generator a non-infinite generator of Card instances. + * @param generator + * a non-infinite generator of Card instances. */ public CardList(final Generator generator) { - // Generators yield their contents to a Yieldable. Here, + // Generators yield their contents to a Yieldable. Here, // we create a quick Yieldable that adds the information it // receives to this CardList's list field. @@ -104,16 +119,20 @@ public class CardList implements Iterable { /** * Create a cardlist with an initial estimate of its maximum size. * - * @param size an initialize estimate of its maximum size + * @param size + * an initialize estimate of its maximum size */ public CardList(final int size) { list = new ArrayList(size); } /** - *

Get any cards that exist in the passed in sets list.

- * - * @param sets a {@link java.util.ArrayList} object. + *

+ * Get any cards that exist in the passed in sets list. + *

+ * + * @param sets + * a {@link java.util.ArrayList} object. * @return a {@link forge.CardList} object. */ public final CardList getSets(final ArrayList sets) { @@ -128,13 +147,15 @@ public class CardList implements Iterable { } return list; - } //getSets() - + } // getSets() /** - *

getColor.

- * - * @param cardColor a {@link java.lang.String} object. + *

+ * getColor. + *

+ * + * @param cardColor + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getColor(final String cardColor) { @@ -148,13 +169,17 @@ public class CardList implements Iterable { } return list; - } //getColor() + } // getColor() /** - *

getOnly2Colors.

- * - * @param clr1 a {@link java.lang.String} object. - * @param clr2 a {@link java.lang.String} object. + *

+ * getOnly2Colors. + *

+ * + * @param clr1 + * a {@link java.lang.String} object. + * @param clr2 + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getOnly2Colors(final String clr1, final String clr2) { @@ -166,8 +191,7 @@ public class CardList implements Iterable { ArrayList cClrs = c.getColor(); for (int i = 0; i < cClrs.size(); i++) { if (!cClrs.get(i).toStringArray().get(0).equals(clr1) - && !cClrs.get(i).toStringArray().get(0).equals(clr2)) - { + && !cClrs.get(i).toStringArray().get(0).equals(clr2)) { return false; } } @@ -179,7 +203,9 @@ public class CardList implements Iterable { } /** - *

reverse.

+ *

+ * reverse. + *

*/ public final void reverse() { Collections.reverse(list); @@ -205,11 +231,14 @@ public class CardList implements Iterable { } } - //removes one copy of that card + // removes one copy of that card /** - *

remove.

- * - * @param cardName a {@link java.lang.String} object. + *

+ * remove. + *

+ * + * @param cardName + * a {@link java.lang.String} object. */ public final void remove(final String cardName) { CardList find = this.filter(new CardListFilter() { @@ -221,15 +250,17 @@ public class CardList implements Iterable { if (0 < find.size()) { this.remove(find.get(0)); } else { - throw new RuntimeException("CardList : remove(String cardname), error - card name not found: " - + cardName + " - contents of Arraylist:" + list); + throw new RuntimeException("CardList : remove(String cardname), error - card name not found: " + cardName + + " - contents of Arraylist:" + list); } - } //remove(String cardName) + } // remove(String cardName) /** - *

size.

- * + *

+ * size. + *

+ * * @return a int. */ public final int size() { @@ -237,19 +268,26 @@ public class CardList implements Iterable { } /** - *

add.

- * - * @param c a {@link forge.Card} object. + *

+ * add. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void add(final Card c) { list.add(c); } /** - *

add.

- * - * @param n a int. - * @param c a {@link forge.Card} object. + *

+ * add. + *

+ * + * @param n + * a int. + * @param c + * a {@link forge.Card} object. */ public final void add(final int n, final Card c) { list.add(n, c); @@ -257,17 +295,21 @@ public class CardList implements Iterable { /** * addAll(CardList) - lets you add one CardList to another directly. - * - * @param in - CardList to add to the current CardList + * + * @param in + * - CardList to add to the current CardList */ public final void addAll(final CardList in) { addAll(in.toArray()); } /** - *

addAll.

- * - * @param c an array of {@link java.lang.Object} objects. + *

+ * addAll. + *

+ * + * @param c + * an array of {@link java.lang.Object} objects. */ public final void addAll(final Object[] c) { for (int i = 0; i < c.length; i++) { @@ -276,20 +318,26 @@ public class CardList implements Iterable { } /** - *

contains.

- * - * @param c a {@link forge.Card} object. + *

+ * contains. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ public final boolean contains(final Card c) { return list.contains(c); } - //probably remove getCard() in the future + // probably remove getCard() in the future /** - *

getCard.

- * - * @param index a int. + *

+ * getCard. + *

+ * + * @param index + * a int. * @return a {@link forge.Card} object. */ public final Card getCard(final int index) { @@ -297,9 +345,12 @@ public class CardList implements Iterable { } /** - *

get.

- * - * @param i a int. + *

+ * get. + *

+ * + * @param i + * a int. * @return a {@link forge.Card} object. */ public final Card get(final int i) { @@ -307,9 +358,12 @@ public class CardList implements Iterable { } /** - *

containsName.

- * - * @param c a {@link forge.Card} object. + *

+ * containsName. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ public final boolean containsName(final Card c) { @@ -317,9 +371,12 @@ public class CardList implements Iterable { } /** - *

containsName.

- * - * @param name a {@link java.lang.String} object. + *

+ * containsName. + *

+ * + * @param name + * a {@link java.lang.String} object. * @return a boolean. */ public final boolean containsName(final String name) { @@ -332,11 +389,14 @@ public class CardList implements Iterable { return false; } - //returns new subset of all the cards with the same name + // returns new subset of all the cards with the same name /** - *

getName.

- * - * @param name a {@link java.lang.String} object. + *

+ * getName. + *

+ * + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getName(final String name) { @@ -351,11 +411,14 @@ public class CardList implements Iterable { return c; } - //returns new subset of all the cards that have a different name + // returns new subset of all the cards that have a different name /** - *

getNotName.

- * - * @param name a {@link java.lang.String} object. + *

+ * getNotName. + *

+ * + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getNotName(final String name) { @@ -371,9 +434,12 @@ public class CardList implements Iterable { } /** - *

getImageName.

- * - * @param name a {@link java.lang.String} object. + *

+ * getImageName. + *

+ * + * @param name + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getImageName(final String name) { @@ -389,9 +455,12 @@ public class CardList implements Iterable { } /** - *

getController.

- * - * @param player a {@link forge.Player} object. + *

+ * getController. + *

+ * + * @param player + * a {@link forge.Player} object. * @return a {@link forge.CardList} object. */ public final CardList getController(final Player player) { @@ -403,9 +472,12 @@ public class CardList implements Iterable { } /** - *

getOwner.

- * - * @param player a {@link forge.Player} object. + *

+ * getOwner. + *

+ * + * @param player + * a {@link forge.Player} object. * @return a {@link forge.CardList} object. */ public final CardList getOwner(final Player player) { @@ -416,11 +488,15 @@ public class CardList implements Iterable { }); } - //cardType is like "Land" or "Goblin", returns a new CardList that is a subset of current CardList + // cardType is like "Land" or "Goblin", returns a new CardList that is a + // subset of current CardList /** - *

getType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * getType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getType(final String cardType) { @@ -431,11 +507,15 @@ public class CardList implements Iterable { }); } - //cardType is like "Land" or "Goblin", returns a new CardList with cards that do not have this type + // cardType is like "Land" or "Goblin", returns a new CardList with cards + // that do not have this type /** - *

getNotType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * getNotType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getNotType(final String cardType) { @@ -447,8 +527,10 @@ public class CardList implements Iterable { } /** - *

getPermanents.

- * + *

+ * getPermanents. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getPermanents() { @@ -460,9 +542,12 @@ public class CardList implements Iterable { } /** - *

getKeyword.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * getKeyword. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getKeyword(final String keyword) { @@ -474,9 +559,12 @@ public class CardList implements Iterable { } /** - *

getNotKeyword.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * getNotKeyword. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getNotKeyword(final String keyword) { @@ -487,11 +575,14 @@ public class CardList implements Iterable { }); } - //get all cards that have this string in their keywords + // get all cards that have this string in their keywords /** - *

getKeywordsContain.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * getKeywordsContain. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getKeywordsContain(final String keyword) { @@ -502,11 +593,14 @@ public class CardList implements Iterable { }); } - //get all cards that don't have this string in their keywords + // get all cards that don't have this string in their keywords /** - *

getKeywordsDontContain.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * getKeywordsDontContain. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ public final CardList getKeywordsDontContain(final String keyword) { @@ -518,8 +612,10 @@ public class CardList implements Iterable { } /** - *

getTokens.

- * + *

+ * getTokens. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getTokens() { @@ -533,18 +629,21 @@ public class CardList implements Iterable { /** * Create a new list of cards by applying a filter to this one. * - * @param filt determines which cards are present in the resulting list + * @param filt + * determines which cards are present in the resulting list * - * @return a subset of this CardList whose items meet the filtering - * criteria; may be empty, but never null. + * @return a subset of this CardList whose items meet the filtering + * criteria; may be empty, but never null. */ public final CardList filter(final CardListFilter filt) { - return CardFilter.filter(this, filt); + return CardFilter.filter(this, filt); } /** - *

toArray.

- * + *

+ * toArray. + *

+ * * @return an array of {@link forge.Card} objects. */ public final Card[] toArray() { @@ -560,8 +659,10 @@ public class CardList implements Iterable { } /** - *

isEmpty.

- * + *

+ * isEmpty. + *

+ * * @return a boolean. */ public final boolean isEmpty() { @@ -569,9 +670,12 @@ public class CardList implements Iterable { } /** - *

remove.

- * - * @param i a int. + *

+ * remove. + *

+ * + * @param i + * a int. * @return a {@link forge.Card} object. */ public final Card remove(final int i) { @@ -579,18 +683,24 @@ public class CardList implements Iterable { } /** - *

remove.

- * - * @param c a {@link forge.Card} object. + *

+ * remove. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void remove(final Card c) { list.remove(c); } /** - *

removeAll.

- * - * @param c a {@link forge.Card} object. + *

+ * removeAll. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void removeAll(final Card c) { ArrayList cList = new ArrayList(); @@ -599,36 +709,46 @@ public class CardList implements Iterable { } /** - *

clear.

+ *

+ * clear. + *

*/ public final void clear() { list.clear(); } /** - *

shuffle.

+ *

+ * shuffle. + *

*/ public final void shuffle() { // reseed Random each time we want to Shuffle - //MyRandom.random = MyRandom.random; + // MyRandom.random = MyRandom.random; Collections.shuffle(list, MyRandom.random); Collections.shuffle(list, MyRandom.random); Collections.shuffle(list, MyRandom.random); } /** - *

sort.

- * - * @param c a {@link java.util.Comparator} object. + *

+ * sort. + *

+ * + * @param c + * a {@link java.util.Comparator} object. */ public final void sort(final Comparator c) { Collections.sort(list, c); } /** - *

getTargetableCards.

- * - * @param source a {@link forge.Card} object. + *

+ * getTargetableCards. + *

+ * + * @param source + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ public final CardList getTargetableCards(final Card source) { @@ -640,25 +760,33 @@ public class CardList implements Iterable { } /** - *

getUnprotectedCards.

- * - * @param source a {@link forge.Card} object. + *

+ * getUnprotectedCards. + *

+ * + * @param source + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ public final CardList getUnprotectedCards(final Card source) { return this.filter(new CardListFilter() { public boolean addCard(final Card c) { - return !CardFactoryUtil.hasProtectionFrom(source, c); + return !CardFactoryUtil.hasProtectionFrom(source, c); } }); } /** - *

getValidCards.

- * - * @param restrictions a {@link java.lang.String} object. - * @param sourceController a {@link forge.Player} object. - * @param source a {@link forge.Card} object. + *

+ * getValidCards. + *

+ * + * @param restrictions + * a {@link java.lang.String} object. + * @param sourceController + * a {@link forge.Player} object. + * @param source + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ public final CardList getValidCards(final String restrictions, final Player sourceController, final Card source) { @@ -666,11 +794,16 @@ public class CardList implements Iterable { } /** - *

getValidCards.

- * - * @param restrictions a {@link java.lang.String} object. - * @param sourceController a {@link forge.Player} object. - * @param source a {@link forge.Card} object. + *

+ * getValidCards. + *

+ * + * @param restrictions + * a {@link java.lang.String} object. + * @param sourceController + * a {@link forge.Player} object. + * @param source + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ public final CardList getValidCards(final String[] restrictions, final Player sourceController, final Card source) { @@ -682,36 +815,42 @@ public class CardList implements Iterable { } /** - *

getEquipMagnets.

- * + *

+ * getEquipMagnets. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getEquipMagnets() { return this.filter(new CardListFilter() { public boolean addCard(final Card c) { - return (c.isCreature() && (c.getSVar("EquipMe").equals("Multiple") - || (c.getSVar("EquipMe").equals("Once") && !c.isEquipped()))); + return (c.isCreature() && (c.getSVar("EquipMe").equals("Multiple") || (c.getSVar("EquipMe").equals( + "Once") && !c.isEquipped()))); } }); } /** - *

getEnchantMagnets.

- * + *

+ * getEnchantMagnets. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getEnchantMagnets() { return this.filter(new CardListFilter() { public boolean addCard(final Card c) { - return (c.isCreature() && (c.getSVar("EnchantMe").equals("Multiple") - || (c.getSVar("EnchantMe").equals("Once") && !c.isEnchanted()))); + return (c.isCreature() && (c.getSVar("EnchantMe").equals("Multiple") || (c.getSVar("EnchantMe").equals( + "Once") && !c.isEnchanted()))); } }); } /** - *

getTotalConvertedManaCost.

- * + *

+ * getTotalConvertedManaCost. + *

+ * * @return a int. */ public final int getTotalConvertedManaCost() { @@ -721,14 +860,16 @@ public class CardList implements Iterable { } return total; } - + /** * - *

getTotalCreaturePower.

+ *

+ * getTotalCreaturePower. + *

* * @return a int. */ - + public final int getTotalCreaturePower() { int total = 0; for (int i = 0; i < size(); i++) { @@ -738,8 +879,10 @@ public class CardList implements Iterable { } /** - *

getHighestConvertedManaCost.

- * + *

+ * getHighestConvertedManaCost. + *

+ * * @return a int. * @since 1.0.15 */ @@ -752,8 +895,10 @@ public class CardList implements Iterable { } /** - *

getColored.

- * + *

+ * getColored. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getColored() { @@ -767,8 +912,10 @@ public class CardList implements Iterable { /** * getAbove. * - * @param source a Card object - * @param compared a Card object + * @param source + * a Card object + * @param compared + * a Card object * @return a boolean */ public final boolean getAbove(final Card source, final Card compared) { @@ -789,8 +936,10 @@ public class CardList implements Iterable { /** * getDirectlyAbove. * - * @param source a Card object - * @param compared a Card object + * @param source + * a Card object + * @param compared + * a Card object * @return a boolean */ public final boolean getDirectlyAbove(final Card source, final Card compared) { @@ -805,8 +954,7 @@ public class CardList implements Iterable { return true; } return false; - } - else if (itr.equals(source)) { + } else if (itr.equals(source)) { checkNext = true; } else if (itr.equals(compared)) { return false; @@ -815,4 +963,4 @@ public class CardList implements Iterable { return false; } -} //end class CardList +} // end class CardList diff --git a/src/main/java/forge/CardListFilter.java b/src/main/java/forge/CardListFilter.java index 1c4b0a1e418..1595385802e 100644 --- a/src/main/java/forge/CardListFilter.java +++ b/src/main/java/forge/CardListFilter.java @@ -1,24 +1,29 @@ package forge; /** - *

CardListFilter interface.

- * + *

+ * CardListFilter interface. + *

+ * * @author Forge * @version $Id$ */ public interface CardListFilter { /** - *

addCard.

- * - * @param c a {@link forge.Card} object. + *

+ * addCard. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ boolean addCard(Card c); - + /** * a CardListFilter to get all cards that are tapped. */ - public static final CardListFilter tapped = new CardListFilter() { + CardListFilter tapped = new CardListFilter() { public boolean addCard(final Card c) { return c.isTapped(); } @@ -27,7 +32,7 @@ public interface CardListFilter { /** * a CardListFilter to get all cards that are untapped. */ - public static final CardListFilter untapped = new CardListFilter() { + CardListFilter untapped = new CardListFilter() { public boolean addCard(final Card c) { return c.isUntapped(); } @@ -36,7 +41,7 @@ public interface CardListFilter { /** * a CardListFilter to get all creatures. */ - public static final CardListFilter creatures = new CardListFilter() { + CardListFilter creatures = new CardListFilter() { public boolean addCard(final Card c) { return c.isCreature(); } @@ -45,7 +50,7 @@ public interface CardListFilter { /** * a CardListFilter to get all enchantments. */ - public static final CardListFilter enchantments = new CardListFilter() { + CardListFilter enchantments = new CardListFilter() { public boolean addCard(final Card c) { return c.isEnchantment(); } @@ -54,7 +59,7 @@ public interface CardListFilter { /** * a CardListFilter to get all equipment. */ - public static final CardListFilter equipment = new CardListFilter() { + CardListFilter equipment = new CardListFilter() { public boolean addCard(final Card c) { return c.isEquipment(); } @@ -63,7 +68,7 @@ public interface CardListFilter { /** * a CardListFilter to get all unenchanted cards in a list. */ - public static final CardListFilter unenchanted = new CardListFilter() { + CardListFilter unenchanted = new CardListFilter() { public boolean addCard(final Card c) { return !c.isEnchanted(); } @@ -72,7 +77,7 @@ public interface CardListFilter { /** * a CardListFilter to get all enchanted cards in a list. */ - public static final CardListFilter enchanted = new CardListFilter() { + CardListFilter enchanted = new CardListFilter() { public boolean addCard(final Card c) { return c.isEnchanted(); } @@ -81,7 +86,7 @@ public interface CardListFilter { /** * a CardListFilter to get all nontoken cards. */ - public static final CardListFilter nonToken = new CardListFilter() { + CardListFilter nonToken = new CardListFilter() { public boolean addCard(final Card c) { return !c.isToken(); } @@ -90,7 +95,7 @@ public interface CardListFilter { /** * a CardListFilter to get all token cards. */ - public static final CardListFilter token = new CardListFilter() { + CardListFilter token = new CardListFilter() { public boolean addCard(final Card c) { return c.isToken(); } @@ -99,7 +104,7 @@ public interface CardListFilter { /** * a CardListFilter to get all nonbasic lands. */ - public static final CardListFilter nonBasicLand = new CardListFilter() { + CardListFilter nonBasicLand = new CardListFilter() { public boolean addCard(final Card c) { return !c.isBasicLand(); } @@ -108,9 +113,9 @@ public interface CardListFilter { /** * a CardListFilter to get all basicLands. */ - public static final CardListFilter basicLands = new CardListFilter() { + CardListFilter basicLands = new CardListFilter() { public boolean addCard(final Card c) { - //the isBasicLand() check here may be sufficient... + // the isBasicLand() check here may be sufficient... return c.isLand() && c.isBasicLand(); } }; @@ -118,7 +123,7 @@ public interface CardListFilter { /** * a CardListFilter to get all artifacts. */ - public static final CardListFilter artifacts = new CardListFilter() { + CardListFilter artifacts = new CardListFilter() { public boolean addCard(final Card c) { return c.isArtifact(); } @@ -127,7 +132,7 @@ public interface CardListFilter { /** * a CardListFilter to get all nonartifacts. */ - public static final CardListFilter nonartifacts = new CardListFilter() { + CardListFilter nonartifacts = new CardListFilter() { public boolean addCard(final Card c) { return !c.isArtifact(); } @@ -136,7 +141,7 @@ public interface CardListFilter { /** * a CardListFilter to get all lands. */ - public static final CardListFilter lands = new CardListFilter() { + CardListFilter lands = new CardListFilter() { public boolean addCard(final Card c) { return c.isLand(); } @@ -145,17 +150,16 @@ public interface CardListFilter { /** * a CardListFilter to get all nonlands. */ - public static final CardListFilter nonlands = new CardListFilter() { + CardListFilter nonlands = new CardListFilter() { public boolean addCard(final Card c) { return !c.isLand(); } - }; - + }; /** * a CardListFilter to get all cards that are black. */ - public static final CardListFilter black = new CardListFilter() { + CardListFilter black = new CardListFilter() { public boolean addCard(final Card c) { return c.isBlack(); } @@ -164,7 +168,7 @@ public interface CardListFilter { /** * a CardListFilter to get all cards that are blue. */ - public static final CardListFilter blue = new CardListFilter() { + CardListFilter blue = new CardListFilter() { public boolean addCard(final Card c) { return c.isBlue(); } @@ -173,7 +177,7 @@ public interface CardListFilter { /** * a CardListFilter to get all cards that are green. */ - public static final CardListFilter green = new CardListFilter() { + CardListFilter green = new CardListFilter() { public boolean addCard(final Card c) { return c.isGreen(); } @@ -182,7 +186,7 @@ public interface CardListFilter { /** * a CardListFilter to get all cards that are red. */ - public static final CardListFilter red = new CardListFilter() { + CardListFilter red = new CardListFilter() { public boolean addCard(final Card c) { return c.isRed(); } @@ -191,7 +195,7 @@ public interface CardListFilter { /** * a CardListFilter to get all cards that are white. */ - public static final CardListFilter white = new CardListFilter() { + CardListFilter white = new CardListFilter() { public boolean addCard(final Card c) { return c.isWhite(); } diff --git a/src/main/java/forge/CardListUtil.java b/src/main/java/forge/CardListUtil.java index 186c70bdfc5..3ea0d298209 100644 --- a/src/main/java/forge/CardListUtil.java +++ b/src/main/java/forge/CardListUtil.java @@ -1,183 +1,224 @@ package forge; -import com.esotericsoftware.minlog.Log; -import forge.card.cardFactory.CardFactoryUtil; - import java.util.ArrayList; import java.util.Comparator; +import com.esotericsoftware.minlog.Log; + +import forge.card.cardFactory.CardFactoryUtil; + /** - *

CardListUtil class.

- * + *

+ * CardListUtil class. + *

+ * * @author Forge * @version $Id$ */ public class CardListUtil { /** - *

filterToughness.

- * - * @param in a {@link forge.CardList} object. - * @param atLeastToughness a int. + *

+ * filterToughness. + *

+ * + * @param in + * a {@link forge.CardList} object. + * @param atLeastToughness + * a int. * @return a {@link forge.CardList} object. */ - public static CardList filterToughness(CardList in, int atLeastToughness) { + public static CardList filterToughness(final CardList in, final int atLeastToughness) { CardList out = new CardList(); - for (int i = 0; i < in.size(); i++) - if (in.get(i).getNetDefense() <= atLeastToughness) + for (int i = 0; i < in.size(); i++) { + if (in.get(i).getNetDefense() <= atLeastToughness) { out.add(in.get(i)); + } + } return out; } - //the higher the defense the better + // the higher the defense the better /** - *

sortDefense.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortDefense. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortDefense(CardList list) { + public static void sortDefense(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { return b.getNetDefense() - a.getNetDefense(); } }; list.sort(com); - }//sortDefense() + } // sortDefense() - //the higher the attack the better + // the higher the attack the better /** - *

sortAttack.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortAttack. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortAttack(CardList list) { + public static void sortAttack(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { - if (CombatUtil.isDoranInPlay()) + if (CombatUtil.isDoranInPlay()) { return b.getNetDefense() - a.getNetDefense(); - else + } else { return b.getNetAttack() - a.getNetAttack(); + } } }; list.sort(com); - }//sortAttack() + } // sortAttack() // sort by "best" using the EvaluateCreature function // the best creatures will be first in the list /** - *

sortByEvaluateCreature.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByEvaluateCreature. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByEvaluateCreature(CardList list) { + public static void sortByEvaluateCreature(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { return CardFactoryUtil.evaluateCreature(b) - CardFactoryUtil.evaluateCreature(a); } }; list.sort(com); - }//sortByEvaluateCreature() + } // sortByEvaluateCreature() // sort by "best" using the EvaluateCreature function // the best creatures will be first in the list /** - *

sortByMostExpensive.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByMostExpensive. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByMostExpensive(CardList list) { + public static void sortByMostExpensive(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { return b.getCMC() - a.getCMC(); } }; list.sort(com); - }//sortByEvaluateCreature() + } // sortByEvaluateCreature() - //the lower the attack the better + // the lower the attack the better /** - *

sortAttackLowFirst.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortAttackLowFirst. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortAttackLowFirst(CardList list) { + public static void sortAttackLowFirst(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { - if (CombatUtil.isDoranInPlay()) + public int compare(final Card a, final Card b) { + if (CombatUtil.isDoranInPlay()) { return a.getNetDefense() - b.getNetDefense(); - else + } else { return a.getNetAttack() - b.getNetAttack(); + } } }; list.sort(com); - }//sortAttackLowFirst() + } // sortAttackLowFirst() /** - *

sortNonFlyingFirst.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortNonFlyingFirst. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortNonFlyingFirst(CardList list) { + public static void sortNonFlyingFirst(final CardList list) { sortFlying(list); list.reverse(); - }//sortNonFlyingFirst + } // sortNonFlyingFirst - //the creature with flying are better + // the creature with flying are better /** - *

sortFlying.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortFlying. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortFlying(CardList list) { + public static void sortFlying(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { - if (a.hasKeyword("Flying") && b.hasKeyword("Flying")) + public int compare(final Card a, final Card b) { + if (a.hasKeyword("Flying") && b.hasKeyword("Flying")) { return 0; - else if (a.hasKeyword("Flying")) + } else if (a.hasKeyword("Flying")) { return -1; - else if (b.hasKeyword("Flying")) + } else if (b.hasKeyword("Flying")) { return 1; + } return 0; } }; list.sort(com); - }//sortFlying() + } // sortFlying() - //sort by keyword + // sort by keyword /** - *

sortByKeyword.

- * - * @param list a {@link forge.CardList} object. - * @param kw a {@link java.lang.String} object. + *

+ * sortByKeyword. + *

+ * + * @param list + * a {@link forge.CardList} object. + * @param kw + * a {@link java.lang.String} object. */ - public static void sortByKeyword(CardList list, String kw) { + public static void sortByKeyword(final CardList list, final String kw) { final String keyword = kw; Comparator com = new Comparator() { - public int compare(Card a, Card b) { - if (a.hasKeyword(keyword) && b.hasKeyword(keyword)) + public int compare(final Card a, final Card b) { + if (a.hasKeyword(keyword) && b.hasKeyword(keyword)) { return 0; - else if (a.hasKeyword(keyword)) + } else if (a.hasKeyword(keyword)) { return -1; - else if (b.hasKeyword(keyword)) + } else if (b.hasKeyword(keyword)) { return 1; + } return 0; } }; list.sort(com); - }//sortByKeyword() + } // sortByKeyword() /** - *

sortByDestroyEffect.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByDestroyEffect. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByDestroyEffect(CardList list) { + public static void sortByDestroyEffect(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { ArrayList aKeywords = a.getKeyword(); ArrayList bKeywords = b.getKeyword(); @@ -197,12 +238,13 @@ public class CardListUtil { break; } } - if (aContains && bContains) + if (aContains && bContains) { return 0; - else if (aContains) + } else if (aContains) { return 1; - else if (bContains) + } else if (bContains) { return -1; + } return 0; } @@ -211,23 +253,27 @@ public class CardListUtil { } /** - *

sortByIndestructible.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByIndestructible. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByIndestructible(CardList list) { + public static void sortByIndestructible(final CardList list) { final ArrayList arrList = new ArrayList(); arrList.add("Timber Protector"); arrList.add("Eldrazi Monument"); Comparator com = new Comparator() { - public int compare(Card a, Card b) { - if (arrList.contains(a.getName()) && arrList.contains(b.getName())) + public int compare(final Card a, final Card b) { + if (arrList.contains(a.getName()) && arrList.contains(b.getName())) { return 0; - else if (arrList.contains(a.getName())) + } else if (arrList.contains(a.getName())) { return 1; - else if (arrList.contains(b.getName())) + } else if (arrList.contains(b.getName())) { return -1; + } return 0; } @@ -236,20 +282,24 @@ public class CardListUtil { } /** - *

sortByTapped.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByTapped. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByTapped(CardList list) { + public static void sortByTapped(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { - if (a.isTapped() && b.isTapped()) + if (a.isTapped() && b.isTapped()) { return 0; - else if (a.isTapped()) + } else if (a.isTapped()) { return 1; - else if (b.isTapped()) + } else if (b.isTapped()) { return -1; + } return 0; } @@ -258,13 +308,16 @@ public class CardListUtil { } /** - *

sortByName.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByName. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByName(CardList list) { + public static void sortByName(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { String aName = a.getName(); String bName = b.getName(); @@ -276,22 +329,26 @@ public class CardListUtil { } /** - *

sortBySelectable.

- * - * @param list a {@link forge.CardList} object. - * @param type a {@link java.lang.String} object. + *

+ * sortBySelectable. + *

+ * + * @param list + * a {@link forge.CardList} object. + * @param type + * a {@link java.lang.String} object. */ - public static void sortBySelectable(CardList list, String type) { + public static void sortBySelectable(final CardList list, final String type) { final String t = type; Comparator com = new Comparator() { - public int compare(Card a, Card b) { - if (a.isType(t) - && b.isType(t)) + public int compare(final Card a, final Card b) { + if (a.isType(t) && b.isType(t)) { return 0; - else if (a.hasKeyword(t)) + } else if (a.hasKeyword(t)) { return 1; - else if (b.hasKeyword(t)) + } else if (b.hasKeyword(t)) { return -1; + } return 0; } @@ -300,22 +357,26 @@ public class CardListUtil { } /** - *

sortByTextLen.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortByTextLen. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortByTextLen(CardList list) { + public static void sortByTextLen(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { int aLen = a.getText().length(); int bLen = b.getText().length(); - if (aLen == bLen) + if (aLen == bLen) { return 0; - else if (aLen > bLen) + } else if (aLen > bLen) { return 1; - else if (bLen > aLen) + } else if (bLen > aLen) { return -1; + } return 0; } @@ -323,105 +384,129 @@ public class CardListUtil { list.sort(com); } - //Sorts from high to low + // Sorts from high to low /** - *

sortCMC.

- * - * @param list a {@link forge.CardList} object. + *

+ * sortCMC. + *

+ * + * @param list + * a {@link forge.CardList} object. */ - public static void sortCMC(CardList list) { + public static void sortCMC(final CardList list) { Comparator com = new Comparator() { - public int compare(Card a, Card b) { + public int compare(final Card a, final Card b) { int cmcA = CardUtil.getConvertedManaCost(a.getManaCost()); int cmcB = CardUtil.getConvertedManaCost(b.getManaCost()); - if (cmcA == cmcB) + if (cmcA == cmcB) { return 0; - if (cmcA > cmcB) + } + if (cmcA > cmcB) { return -1; - if (cmcB > cmcA) + } + if (cmcB > cmcA) { return 1; + } return 0; } }; list.sort(com); - }//sortCMC - + } // sortCMC /** - *

getColor.

- * - * @param list a {@link forge.CardList} object. - * @param color a {@link java.lang.String} object. + *

+ * getColor. + *

+ * + * @param list + * a {@link forge.CardList} object. + * @param color + * a {@link java.lang.String} object. * @return a {@link forge.CardList} object. */ - public static CardList getColor(CardList list, final String color) { + public static CardList getColor(final CardList list, final String color) { return list.filter(new CardListFilter() { - public boolean addCard(Card c) { + public boolean addCard(final Card c) { return CardUtil.getColors(c).contains(color); } }); - }//getColor() + } // getColor() /** - *

getGoldCards.

- * - * @param list a {@link forge.CardList} object. + *

+ * getGoldCards. + *

+ * + * @param list + * a {@link forge.CardList} object. * @return a {@link forge.CardList} object. */ - public static CardList getGoldCards(CardList list) { + public static CardList getGoldCards(final CardList list) { return list.filter(new CardListFilter() { - public boolean addCard(Card c) { + public boolean addCard(final Card c) { return CardUtil.getColors(c).size() >= 2; } }); } /** - *

sumAttack.

- * - * @param c a {@link forge.CardList} object. + *

+ * sumAttack. + *

+ * + * @param c + * a {@link forge.CardList} object. * @return a int. */ - public static int sumAttack(CardList c) { + public static int sumAttack(final CardList c) { int attack = 0; for (int i = 0; i < c.size(); i++) { - //if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) { - if (c.get(i).isCreature() && (!c.get(i).hasFirstStrike() || (c.get(i).hasDoubleStrike() && c.get(i).hasFirstStrike()))) { + // if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) { + if (c.get(i).isCreature() + && (!c.get(i).hasFirstStrike() || (c.get(i).hasDoubleStrike() && c.get(i).hasFirstStrike()))) + { attack += c.get(i).getNetCombatDamage(); } } - //System.out.println("Total attack: " +attack); + // System.out.println("Total attack: " +attack); return attack; - }//sumAttack() + } // sumAttack() /** - *

sumDefense.

- * - * @param c a {@link forge.CardList} object. + *

+ * sumDefense. + *

+ * + * @param c + * a {@link forge.CardList} object. * @return a int. */ - public static int sumDefense(CardList c) { + public static int sumDefense(final CardList c) { int defense = 0; for (int i = 0; i < c.size(); i++) { - //if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) { - if (c.get(i).isCreature()) + // if(c.get(i).isCreature() && c.get(i).hasSecondStrike()) { + if (c.get(i).isCreature()) { defense += c.get(i).getNetDefense(); + } } - //System.out.println("Total attack: " +attack); + // System.out.println("Total attack: " +attack); return defense; - }//sumAttack() + } // sumAttack() /** - *

sumFirstStrikeAttack.

- * - * @param c a {@link forge.CardList} object. + *

+ * sumFirstStrikeAttack. + *

+ * + * @param c + * a {@link forge.CardList} object. * @return a int. */ - public static int sumFirstStrikeAttack(CardList c) { + public static int sumFirstStrikeAttack(final CardList c) { int attack = 0; for (int i = 0; i < c.size(); i++) { @@ -431,33 +516,47 @@ public class CardListUtil { } Log.debug("Total First Strike attack: " + attack); return attack; - }//sumFirstStrikeAttack() + } // sumFirstStrikeAttack() - //Get the total converted mana cost of a card list + // Get the total converted mana cost of a card list /** - *

sumCMC.

- * - * @param c a {@link forge.CardList} object. + *

+ * sumCMC. + *

+ * + * @param c + * a {@link forge.CardList} object. * @return a int. */ - public static int sumCMC(CardList c) { + public static int sumCMC(final CardList c) { int cmc = 0; for (int i = 0; i < c.size(); i++) { cmc += CardUtil.getConvertedManaCost(c.get(i).getManaCost()); } - //System.out.println("Total CMC: " +cmc); + // System.out.println("Total CMC: " +cmc); return cmc; - }//sumCMC - - public static CardList getRandomSubList(CardList c, int amount){ - if (c.size() < amount) + } // sumCMC + + /** + * + * TODO Write javadoc for this method. + * + * @param c + * CardList + * @param amount + * int + * @return CardList + */ + public static CardList getRandomSubList(final CardList c, final int amount) { + if (c.size() < amount) { return null; - + } + CardList subList = new CardList(); - while(subList.size() < amount){ + while (subList.size() < amount) { c.shuffle(); subList.add(c.get(0)); c.remove(0); diff --git a/src/main/java/forge/CardReader.java b/src/main/java/forge/CardReader.java index 48ea974b9c5..4adbb7770e6 100644 --- a/src/main/java/forge/CardReader.java +++ b/src/main/java/forge/CardReader.java @@ -27,7 +27,6 @@ import net.slightlymagic.braids.util.progress_monitor.StderrProgressMonitor; import com.google.code.jyield.Generator; import com.google.code.jyield.YieldUtils; -import forge.card.CardColor; import forge.card.CardRules; import forge.card.CardRulesReader; import forge.card.trigger.TriggerHandler; @@ -35,33 +34,57 @@ import forge.error.ErrorViewer; import forge.properties.NewConstants; import forge.view.FView; - /** - *

CardReader class.

- * + *

+ * CardReader class. + *

+ * * @author Forge * @version $Id$ */ -public class CardReader - implements Runnable, // NOPMD by Braids on 8/18/11 10:55 PM - NewConstants -{ - private static final String CARD_FILE_DOT_EXTENSION = ".txt"; // NOPMD by Braids on 8/18/11 11:04 PM +public class CardReader implements Runnable, NewConstants { + // NOPMD by Braids on 8/18/11 10:55 + // PM + private static final String CARD_FILE_DOT_EXTENSION = ".txt"; // NOPMD by + // Braids on + // 8/18/11 + // 11:04 PM /** Default charset when loading from files. */ - public static final String DEFAULT_CHARSET_NAME = "US-ASCII"; // NOPMD by Braids on 8/18/11 10:54 PM + public static final String DEFAULT_CHARSET_NAME = "US-ASCII"; // NOPMD by + // Braids on + // 8/18/11 + // 10:54 PM /** Regex that matches a single hyphen (-) or space. */ public static final Pattern HYPHEN_OR_SPACE = Pattern.compile("[ -]"); /** Regex for punctuation that we omit from card file names. */ - public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]"); // NOPMD by Braids on 8/18/11 10:54 PM + public static final Pattern PUNCTUATION_TO_ZAP = Pattern.compile("[,'\"]"); // NOPMD + // by + // Braids + // on + // 8/18/11 + // 10:54 + // PM /** Regex that matches two or more underscores (_). */ - public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+"); // NOPMD by Braids on 8/18/11 10:54 PM + public static final Pattern MULTIPLE_UNDERSCORES = Pattern.compile("__+"); // NOPMD + // by + // Braids + // on + // 8/18/11 + // 10:54 + // PM /** Special value for estimatedFilesRemaining. */ - protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1; // NOPMD by Braids on 8/18/11 10:54 PM + protected static final int UNKNOWN_NUMBER_OF_FILES_REMAINING = -1; // NOPMD + // by + // Braids + // on + // 8/18/11 + // 10:54 + // PM private transient Map mapToFill; private transient List listRulesToFill; @@ -73,46 +96,71 @@ public class CardReader private transient Enumeration zipEnum; - private transient long estimatedFilesRemaining = // NOPMD by Braids on 8/18/11 10:56 PM - UNKNOWN_NUMBER_OF_FILES_REMAINING; + private transient long estimatedFilesRemaining = // NOPMD by Braids on + // 8/18/11 10:56 PM + UNKNOWN_NUMBER_OF_FILES_REMAINING; - private transient Iterable findNonDirsIterable; // NOPMD by Braids on 8/18/11 10:56 PM + private transient Iterable findNonDirsIterable; // NOPMD by Braids on + // 8/18/11 10:56 PM - - - public CardReader(final File theCardsFolder, final Map theMapToFill ) { + /** + * Instantiates a new card reader. + * + * @param theCardsFolder + * the the cards folder + * @param theMapToFill + * the the map to fill + */ + public CardReader(final File theCardsFolder, final Map theMapToFill) { this(theCardsFolder, theMapToFill, null, true); } /** * This is a convenience for CardReader(cardsfolder, mapToFill, true); . - * - * @param theCardsFolder indicates location of the cardsFolder - * - * @param theMapToFill maps card names to Card instances; this is where we - * place the cards once read - * + * + * @param theCardsFolder + * indicates location of the cardsFolder + * @param listRules2Fill + * List + * @param theMapToFill + * maps card names to Card instances; this is where we place the + * cards once read + * */ - public CardReader(final File theCardsFolder, final Map theMapToFill, - final List listRules2Fill) { + public CardReader(final File theCardsFolder, final Map theMapToFill, + final List listRules2Fill) + { this(theCardsFolder, theMapToFill, listRules2Fill, true); } /** - *

Constructor for CardReader.

- * - * @param theCardsFolder indicates location of the cardsFolder - * - * @param theMapToFill maps card names to Card instances; this is where we - * place the cards once read - * - * @param useZip if true, attempts to load cards from a zip file, if one exists. + *

+ * Constructor for CardReader. + *

+ * + * @param theCardsFolder + * indicates location of the cardsFolder + * + * @param theMapToFill + * maps card names to Card instances; this is where we place the + * cards once read + * @param listRules2Fill + * List + * @param useZip + * if true, attempts to load cards from a zip file, if one + * exists. */ public CardReader(final File theCardsFolder, final Map theMapToFill, final List listRules2Fill, final boolean useZip) { if (theMapToFill == null) { - throw new NullPointerException("theMapToFill must not be null."); // NOPMD by Braids on 8/18/11 10:53 PM + throw new NullPointerException("theMapToFill must not be null."); // NOPMD + // by + // Braids + // on + // 8/18/11 + // 10:53 + // PM } this.mapToFill = theMapToFill; // These read data for lightweight classes. @@ -122,18 +170,16 @@ public class CardReader if (!theCardsFolder.exists()) { throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM "CardReader : constructor error -- file not found -- filename is " - + theCardsFolder.getAbsolutePath()); + + theCardsFolder.getAbsolutePath()); } if (!theCardsFolder.isDirectory()) { throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM - "CardReader : constructor error -- not a directory -- " - + theCardsFolder.getAbsolutePath()); + "CardReader : constructor error -- not a directory -- " + theCardsFolder.getAbsolutePath()); } this.cardsfolder = theCardsFolder; - final File zipFile = new File(theCardsFolder, "cardsfolder.zip"); // Prepare resources to read cards lazily. @@ -141,12 +187,16 @@ public class CardReader try { this.zip = new ZipFile(zipFile); } catch (Exception exn) { - System.err.println("Error reading zip file \"" // NOPMD by Braids on 8/18/11 10:53 PM - + zipFile.getAbsolutePath() + "\": " + exn + ". " + System.err.println("Error reading zip file \"" // NOPMD by + // Braids on + // 8/18/11 10:53 + // PM + + zipFile.getAbsolutePath() + + "\": " + + exn + + ". " + "Defaulting to txt files in \"" - + theCardsFolder.getAbsolutePath() - + "\"." - ); + + theCardsFolder.getAbsolutePath() + "\"."); } } @@ -158,22 +208,22 @@ public class CardReader setEncoding(DEFAULT_CHARSET_NAME); - } //CardReader() - + } // CardReader() /** * This finalizer helps assure there is no memory or thread leak with * findNonDirsIterable, which was created with YieldUtils.toIterable. - * - * @throws Throwable indirectly + * + * @throws Throwable + * indirectly */ protected final void finalize() throws Throwable { try { if (findNonDirsIterable != null) { - for (@SuppressWarnings("unused") File ignored - : findNonDirsIterable) + for (@SuppressWarnings("unused") + // Do nothing; just exercising the Iterable. + File ignored : findNonDirsIterable) { - // Do nothing; just exercising the Iterable. } } } finally { @@ -181,9 +231,8 @@ public class CardReader } } - /** - * Reads the rest of ALL the cards into memory. This is not lazy. + * Reads the rest of ALL the cards into memory. This is not lazy. */ public final void run() { loadCardsUntilYouFind(null); @@ -191,12 +240,13 @@ public class CardReader /** * Starts reading cards into memory until the given card is found. - * + * * After that, we save our place in the list of cards (on disk) in case we * need to load more. - * - * @param cardName the name to find; if null, load all cards. - * + * + * @param cardName + * the name to find; if null, load all cards. + * * @return the Card or null if it was not found. */ protected final Card loadCardsUntilYouFind(final String cardName) { @@ -209,7 +259,7 @@ public class CardReader if (view != null) { monitor = view.getCardLoadingProgressMonitor(); } - + if (monitor == null) { monitor = new StderrProgressMonitor(1, 0L); } @@ -223,7 +273,7 @@ public class CardReader findNonDirsIterable = YieldUtils.toIterable(findNonDirsGen); } - if(monitor!=null) { + if (monitor != null) { monitor.setTotalUnitsThisPhase(estimatedFilesRemaining); } @@ -237,10 +287,11 @@ public class CardReader monitor.incrementUnitsCompletedThisPhase(1L); if (cardName != null && cardName.equals(result.getName())) { - break; // no thread leak here if entire card DB is loaded, or if this object is finalized. + break; // no thread leak here if entire card DB is loaded, + // or if this object is finalized. } - } //endfor + } // endfor } else { monitor.setTotalUnitsThisPhase(estimatedFilesRemaining); @@ -263,17 +314,20 @@ public class CardReader } } - } //endif + } // endif return result; - } //loadCardsUntilYouFind(String) - + } // loadCardsUntilYouFind(String) /** - *

addTypes to an existing card.

- * - * @param card a {@link forge.Card} object. - * @param types a {@link java.lang.String} object. + *

+ * addTypes to an existing card. + *

+ * + * @param card + * a {@link forge.Card} object. + * @param types + * a {@link java.lang.String} object. */ public static void addTypes(final Card card, final String types) { final StringTokenizer tok = new StringTokenizer(types); @@ -283,13 +337,16 @@ public class CardReader } /** - *

Reads a line from the given reader and handles exceptions.

- * + *

+ * Reads a line from the given reader and handles exceptions. + *

+ * * @return a {@link java.lang.String} object. - * @param reader a {@link java.io.BufferedReader} object. + * @param reader + * a {@link java.io.BufferedReader} object. */ public static String readLine(final BufferedReader reader) { - //makes the checked exception, into an unchecked runtime exception + // makes the checked exception, into an unchecked runtime exception try { String line = reader.readLine(); if (line != null) { @@ -298,15 +355,24 @@ public class CardReader return line; } catch (Exception ex) { ErrorViewer.showError(ex); - throw new RuntimeException("CardReader : readLine(Card) error", ex); // NOPMD by Braids on 8/18/11 10:53 PM + throw new RuntimeException("CardReader : readLine(Card) error", ex); // NOPMD + // by + // Braids + // on + // 8/18/11 + // 10:53 + // PM } - } //readLine(BufferedReader) + } // readLine(BufferedReader) /** - *

load a card.

- * - * @param inputStream the stream from which to load the card's information - * + *

+ * load a card. + *

+ * + * @param inputStream + * the stream from which to load the card's information + * * @return the card loaded from the stream */ protected final Card loadCard(final InputStream inputStream) { @@ -322,21 +388,22 @@ public class CardReader String line = readLine(reader); while (!"End".equals(line)) { rulesReader.parseLine(line); - if(line.isEmpty()) { - //Ignore empty lines. - } else if (line.charAt(0) == '#') { // NOPMD by Braids on 8/18/11 10:59 PM - //no need to do anything, this indicates a comment line + if (line.isEmpty()) { + // Ignore empty lines. + } else if (line.charAt(0) == '#') { // NOPMD by Braids on + // 8/18/11 10:59 PM + // no need to do anything, this indicates a comment line } else if (line.startsWith("Name:")) { final String value = line.substring(5); - //System.out.println(s); + // System.out.println(s); if (mapToFill.containsKey(value)) { - break; // this card has already been loaded. + break; // this card has already been loaded. } else { card.setName(value); } } else if (line.startsWith("ManaCost:")) { final String value = line.substring(9); - //System.out.println(s); + // System.out.println(s); if (!"no cost".equals(value)) { card.setManaCost(value); } @@ -391,13 +458,14 @@ public class CardReader card.addStaticAbilityString(value); } else if (line.startsWith("SetInfo:")) { final String value = line.substring("SetInfo:".length()); - card.addSet(new SetInfo(value)); // NOPMD by Braids on 8/18/11 11:08 PM + card.addSet(new SetInfo(value)); // NOPMD by Braids on + // 8/18/11 11:08 PM } else if (line.equals("ALTERNATE")) { card.addAlternateState(); card.changeState(); } else if (line.startsWith("AlternateMode:")) { final String value = line.substring("AlternateMode:".length()); - if(value.equalsIgnoreCase("Flip")) { + if (value.equalsIgnoreCase("Flip")) { card.setFlip(true); } else { card.setDoubleFaced(true); @@ -405,12 +473,12 @@ public class CardReader } else if (line.startsWith("Colors:")) { final String value = line.substring("Colors:".length()); ArrayList newCols = new ArrayList(); - for(String col : value.split(",")) { + for (String col : value.split(",")) { Card_Color newCol = new Card_Color(card); newCol.addToCardColor(col); newCols.add(newCol); } - + card.setColor(newCols); card.setCardColorsOverridden(true); } @@ -420,41 +488,45 @@ public class CardReader } finally { try { reader.close(); - } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM + } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 + // PM } try { inputStreamReader.close(); - } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM + } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 + // PM } } - - if(card.isInAlternateState()) { + + if (card.isInAlternateState()) { card.changeState(); } CardRules[] crdRules = rulesReader.getCard(); listRulesToFill.add(crdRules[0]); - if(crdRules[1] != null) { listRulesToFill.add(crdRules[1]); } + if (crdRules[1] != null) { + listRulesToFill.add(crdRules[1]); + } mapToFill.put(card.getName(), card); return card; } - /** * Set the character encoding to use when loading cards. - * - * @param charsetName the name of the charset, for example, "UTF-8" + * + * @param charsetName + * the name of the charset, for example, "UTF-8" */ public final void setEncoding(final String charsetName) { this.charset = Charset.forName(charsetName); } - /** * Load a card from a txt file. - * - * @param pathToTxtFile the full or relative path to the file to load - * + * + * @param pathToTxtFile + * the full or relative path to the file to load + * * @return a new Card instance */ protected final Card loadCard(final File pathToTxtFile) { @@ -465,21 +537,22 @@ public class CardReader } catch (FileNotFoundException ex) { ErrorViewer.showError(ex, "File \"%s\" exception", pathToTxtFile.getAbsolutePath()); throw new RuntimeException(// NOPMD by Braids on 8/18/11 10:53 PM - "CardReader : run error -- file exception -- filename is " - + pathToTxtFile.getPath(), ex); + "CardReader : run error -- file exception -- filename is " + pathToTxtFile.getPath(), ex); } finally { try { fileInputStream.close(); - } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM + } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 + // PM } } } /** * Load a card from an entry in a zip file. - * - * @param entry to load from - * + * + * @param entry + * to load from + * * @return a new Card instance */ protected final Card loadCard(final ZipEntry entry) { @@ -489,27 +562,29 @@ public class CardReader return loadCard(zipInputStream); } catch (IOException exn) { - throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 10:53 PM + throw new RuntimeException(exn); // NOPMD by Braids on 8/18/11 10:53 + // PM } finally { try { if (zipInputStream != null) { zipInputStream.close(); } - } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 PM + } catch (IOException ignored) { // NOPMD by Braids on 8/18/11 11:08 + // PM } } } - /** * Attempt to guess what the path to a given card's txt file would be. - * - * @param asciiCardName the card name in canonicalized ASCII form - * - * @return the likeliest path of the card's txt file, excluding - * cardsFolder but including the subdirectory of that and the ".txt" - * suffix. For example, "e/elvish_warrior.txt" - * + * + * @param asciiCardName + * the card name in canonicalized ASCII form + * + * @return the likeliest path of the card's txt file, excluding cardsFolder + * but including the subdirectory of that and the ".txt" suffix. For + * example, "e/elvish_warrior.txt" + * * @see CardUtil#canonicalizeCardName */ public final String toMostLikelyPath(final String asciiCardName) { @@ -519,8 +594,9 @@ public class CardReader * friarsol wrote: "hyphens and spaces are converted to underscores, * commas and apostrophes are removed (I'm not sure if there are any * other punctuation used)." - * - * @see http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=4887#p63189 + * + * @see + * http://www.slightlymagic.net/forum/viewtopic.php?f=52&t=4887#p63189 */ baseFileName = HYPHEN_OR_SPACE.matcher(baseFileName).replaceAll("_"); @@ -542,12 +618,16 @@ public class CardReader /** * Attempt to load a card by its canonical ASCII name. - * - * @param canonicalASCIIName the canonical ASCII name of the card - * + * + * @param canonicalASCIIName + * the canonical ASCII name of the card + * * @return a new Card instance having that name, or null if not found */ - public final Card findCard(final String canonicalASCIIName) { // NOPMD by Braids on 8/18/11 11:08 PM + public final Card findCard(final String canonicalASCIIName) { // NOPMD by + // Braids on + // 8/18/11 + // 11:08 PM UtilFunctions.checkNotNull("canonicalASCIIName", canonicalASCIIName); final String cardFilePath = toMostLikelyPath(canonicalASCIIName); @@ -567,7 +647,7 @@ public class CardReader } if (result == null || !(result.getName().equals(canonicalASCIIName))) { - //System.err.println(":Could not find \"" + cardFilePath + "\"."); + // System.err.println(":Could not find \"" + cardFilePath + "\"."); result = loadCardsUntilYouFind(canonicalASCIIName); } diff --git a/src/main/java/forge/CardUtil.java b/src/main/java/forge/CardUtil.java index a6312172eca..3a1a5d713d8 100644 --- a/src/main/java/forge/CardUtil.java +++ b/src/main/java/forge/CardUtil.java @@ -1,12 +1,5 @@ package forge; -import forge.card.mana.ManaCost; -import forge.card.spellability.SpellAbility; -import forge.card.spellability.SpellAbilityList; -import forge.item.CardPrinted; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -20,10 +13,19 @@ import net.slightlymagic.maxmtg.Predicate; import org.apache.commons.lang3.StringUtils; +import forge.card.mana.ManaCost; +import forge.card.spellability.SpellAbility; +import forge.card.spellability.SpellAbilityList; +import forge.item.CardPrinted; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +// TODO: Auto-generated Javadoc /** - *

CardUtil class.

- * + *

+ * CardUtil class. + *

+ * * @author Forge * @version $Id$ */ @@ -31,7 +33,6 @@ public final class CardUtil { /** Constant RANDOM. */ public static final Random RANDOM = MyRandom.random; - /** * Do not instantiate. */ @@ -40,24 +41,29 @@ public final class CardUtil { } /** - *

getRandomIndex.

- * - * @param o an array of {@link java.lang.Object} objects. + *

+ * getRandomIndex. + *

+ * + * @param o + * an array of {@link java.lang.Object} objects. * @return a int. */ public static int getRandomIndex(final Object[] o) { if (o == null || o.length == 0) { - throw new RuntimeException( - "CardUtil : getRandomIndex() argument is null or length is 0"); + throw new RuntimeException("CardUtil : getRandomIndex() argument is null or length is 0"); } return RANDOM.nextInt(o.length); } /** - *

getRandom.

- * - * @param o an array of {@link forge.Card} objects. + *

+ * getRandom. + *

+ * + * @param o + * an array of {@link forge.Card} objects. * @return a {@link forge.Card} object. */ public static Card getRandom(final Card[] o) { @@ -65,36 +71,44 @@ public final class CardUtil { } /** - *

getRandomIndex.

- * - * @param list a {@link forge.card.spellability.SpellAbilityList} object. + *

+ * getRandomIndex. + *

+ * + * @param list + * a {@link forge.card.spellability.SpellAbilityList} object. * @return a int. */ public static int getRandomIndex(final SpellAbilityList list) { if (list == null || list.size() == 0) { - throw new RuntimeException( - "CardUtil : getRandomIndex(SpellAbilityList) argument is null or length is 0"); + throw new RuntimeException("CardUtil : getRandomIndex(SpellAbilityList) argument is null or length is 0"); } return RANDOM.nextInt(list.size()); } /** - *

getRandomIndex.

- * - * @param c a {@link forge.CardList} object. + *

+ * getRandomIndex. + *

+ * + * @param c + * a {@link forge.CardList} object. * @return a int. */ public static int getRandomIndex(final CardList c) { return RANDOM.nextInt(c.size()); } - //returns Card Name (unique number) attack/defense - //example: Big Elf (12) 2/3 + // returns Card Name (unique number) attack/defense + // example: Big Elf (12) 2/3 /** - *

toText.

- * - * @param c a {@link forge.Card} object. + *

+ * toText. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a {@link java.lang.String} object. */ public static String toText(final Card c) { @@ -102,9 +116,12 @@ public final class CardUtil { } /** - *

toCard.

- * - * @param col a {@link java.util.Collection} object. + *

+ * toCard. + *

+ * + * @param col + * a {@link java.util.Collection} object. * @return an array of {@link forge.Card} objects. */ public static Card[] toCard(final Collection col) { @@ -116,8 +133,8 @@ public final class CardUtil { if (swap instanceof Card) { c[i] = (Card) o[i]; } else { - throw new RuntimeException("CardUtil : toCard() invalid class, should be Card - " - + o[i].getClass() + " - toString() - " + o[i].toString()); + throw new RuntimeException("CardUtil : toCard() invalid class, should be Card - " + o[i].getClass() + + " - toString() - " + o[i].toString()); } } @@ -125,9 +142,12 @@ public final class CardUtil { } /** - *

toCard.

- * - * @param list a {@link java.util.ArrayList} object. + *

+ * toCard. + *

+ * + * @param list + * a {@link java.util.ArrayList} object. * @return an array of {@link forge.Card} objects. */ public static Card[] toCard(final ArrayList list) { @@ -137,9 +157,12 @@ public final class CardUtil { } /** - *

toList.

- * - * @param c an array of {@link forge.Card} objects. + *

+ * toList. + *

+ * + * @param c + * an array of {@link forge.Card} objects. * @return a {@link java.util.ArrayList} object. */ public static ArrayList toList(final Card[] c) { @@ -150,11 +173,14 @@ public final class CardUtil { return a; } - //returns "G", longColor is Constant.Color.Green and the like + // returns "G", longColor is Constant.Color.Green and the like /** - *

getShortColor.

- * - * @param longColor a {@link java.lang.String} object. + *

+ * getShortColor. + *

+ * + * @param longColor + * a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static String getShortColor(final String longColor) { @@ -174,10 +200,14 @@ public final class CardUtil { } /** - *

isColor.

- * - * @param c a {@link forge.Card} object. - * @param col a {@link java.lang.String} object. + *

+ * isColor. + *

+ * + * @param c + * a {@link forge.Card} object. + * @param col + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isColor(final Card c, final String col) { @@ -186,9 +216,12 @@ public final class CardUtil { } /** - *

getColors.

- * - * @param c a {@link forge.Card} object. + *

+ * getColors. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList getColors(final Card c) { @@ -196,9 +229,12 @@ public final class CardUtil { } /** - *

getOnlyColors.

- * - * @param c a {@link forge.Card} object. + *

+ * getOnlyColors. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a {@link java.util.ArrayList} object. */ public static ArrayList getOnlyColors(final Card c) { @@ -240,12 +276,15 @@ public final class CardUtil { return new ArrayList(colors); } - /** - *

hasCardName.

- * - * @param cardName a {@link java.lang.String} object. - * @param list a {@link java.util.ArrayList} object. + *

+ * hasCardName. + *

+ * + * @param cardName + * a {@link java.lang.String} object. + * @param list + * a {@link java.util.ArrayList} object. * @return a boolean. */ public static boolean hasCardName(final String cardName, final ArrayList list) { @@ -260,13 +299,16 @@ public final class CardUtil { } } return b; - } //hasCardName() + } // hasCardName() - //probably should put this somewhere else, but not sure where + // probably should put this somewhere else, but not sure where /** - *

getConvertedManaCost.

- * - * @param sa a {@link forge.card.spellability.SpellAbility} object. + *

+ * getConvertedManaCost. + *

+ * + * @param sa + * a {@link forge.card.spellability.SpellAbility} object. * @return a int. */ public static int getConvertedManaCost(final SpellAbility sa) { @@ -274,9 +316,12 @@ public final class CardUtil { } /** - *

getConvertedManaCost.

- * - * @param c a {@link forge.Card} object. + *

+ * getConvertedManaCost. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a int. */ public static int getConvertedManaCost(final Card c) { @@ -287,9 +332,12 @@ public final class CardUtil { } /** - *

getConvertedManaCost.

- * - * @param manaCost a {@link java.lang.String} object. + *

+ * getConvertedManaCost. + *

+ * + * @param manaCost + * a {@link java.lang.String} object. * @return a int. */ public static int getConvertedManaCost(final String manaCost) { @@ -302,10 +350,14 @@ public final class CardUtil { } /** - *

addManaCosts.

- * - * @param mc1 a {@link java.lang.String} object. - * @param mc2 a {@link java.lang.String} object. + *

+ * addManaCosts. + *

+ * + * @param mc1 + * a {@link java.lang.String} object. + * @param mc2 + * a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ public static String addManaCosts(final String mc1, final String mc2) { @@ -336,15 +388,19 @@ public final class CardUtil { tMC = tCL.toString() + " " + cc1 + " " + cc2; - //System.out.println("TMC:" + tMC); + // System.out.println("TMC:" + tMC); return tMC.trim(); } /** - *

getRelative.

- * - * @param c a {@link forge.Card} object. - * @param relation a {@link java.lang.String} object. + *

+ * getRelative. + *

+ * + * @param c + * a {@link forge.Card} object. + * @param relation + * a {@link java.lang.String} object. * @return a {@link forge.Card} object. */ public static Card getRelative(final Card c, final String relation) { @@ -354,17 +410,20 @@ public final class CardUtil { return c.getEnchantingCard(); } else if (relation.startsWith("equipped ")) { return c.getEquipping().get(0); - //else if(relation.startsWith("target ")) return c.getTargetCard(); + // else if(relation.startsWith("target ")) return c.getTargetCard(); } else { - throw new IllegalArgumentException("Error at CardUtil.getRelative: " + relation - + "is not a valid relation"); + throw new IllegalArgumentException( + "Error at CardUtil.getRelative: " + relation + "is not a valid relation"); } } /** - *

isACardType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isACardType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isACardType(final String cardType) { @@ -372,17 +431,19 @@ public final class CardUtil { } /** - *

getAllCardTypes.

- * + *

+ * getAllCardTypes. + *

+ * * @return a {@link java.util.ArrayList} object. */ public static ArrayList getAllCardTypes() { ArrayList types = new ArrayList(); - //types.addAll(getCardTypes()); + // types.addAll(getCardTypes()); types.addAll(Constant.CardTypes.cardTypes[0].list); - //not currently used by Forge + // not currently used by Forge types.add("Plane"); types.add("Scheme"); types.add("Vanguard"); @@ -391,21 +452,23 @@ public final class CardUtil { } /** - *

getCardTypes.

- * + *

+ * getCardTypes. + *

+ * * @return a {@link java.util.ArrayList} object. */ public static ArrayList getCardTypes() { ArrayList types = new ArrayList(); - // types.add("Artifact"); - // types.add("Creature"); - // types.add("Enchantment"); - // types.add("Instant"); - // types.add("Land"); - // types.add("Planeswalker"); - // types.add("Sorcery"); - // types.add("Tribal"); + // types.add("Artifact"); + // types.add("Creature"); + // types.add("Enchantment"); + // types.add("Instant"); + // types.add("Land"); + // types.add("Planeswalker"); + // types.add("Sorcery"); + // types.add("Tribal"); types.addAll(Constant.CardTypes.cardTypes[0].list); @@ -413,8 +476,10 @@ public final class CardUtil { } /** - *

getBasicTypes.

- * + *

+ * getBasicTypes. + *

+ * * @return a {@link java.util.ArrayList} object. * @since 1.1.3 */ @@ -425,7 +490,12 @@ public final class CardUtil { return types; } - + + /** + * Gets the land types. + * + * @return the land types + */ public static ArrayList getLandTypes() { ArrayList types = new ArrayList(); @@ -434,10 +504,12 @@ public final class CardUtil { return types; } - + /** - *

getCreatureTypes.

- * + *

+ * getCreatureTypes. + *

+ * * @return a {@link java.util.ArrayList} object. * @since 1.1.6 */ @@ -450,9 +522,12 @@ public final class CardUtil { } /** - *

isASuperType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isASuperType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ @@ -461,9 +536,12 @@ public final class CardUtil { } /** - *

isASubType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isASubType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isASubType(final String cardType) { @@ -471,9 +549,12 @@ public final class CardUtil { } /** - *

isACreatureType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isACreatureType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isACreatureType(final String cardType) { @@ -481,34 +562,50 @@ public final class CardUtil { } /** - *

isALandType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isALandType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isALandType(final String cardType) { return (Constant.CardTypes.landTypes[0].list.contains(cardType)); } - + + /** + * Checks if is a planeswalker type. + * + * @param cardType the card type + * @return true, if is a planeswalker type + */ public static boolean isAPlaneswalkerType(final String cardType) { return (Constant.CardTypes.walkerTypes[0].list.contains(cardType)); } /** - *

isABasicLandType.

- * - * @param cardType a {@link java.lang.String} object. + *

+ * isABasicLandType. + *

+ * + * @param cardType + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isABasicLandType(final String cardType) { return (Constant.CardTypes.basicTypes[0].list.contains(cardType)); } - //this function checks, if duplicates of a keyword are not necessary (like flying, trample, etc.) + // this function checks, if duplicates of a keyword are not necessary (like + // flying, trample, etc.) /** - *

isNonStackingKeyword.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * isNonStackingKeyword. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isNonStackingKeyword(final String keyword) { @@ -516,27 +613,40 @@ public final class CardUtil { } /** - *

isStackingKeyword.

- * - * @param keyword a {@link java.lang.String} object. + *

+ * isStackingKeyword. + *

+ * + * @param keyword + * a {@link java.lang.String} object. * @return a boolean. */ public static boolean isStackingKeyword(final String keyword) { return !isNonStackingKeyword(keyword); } - - public static String buildIdealFilename(final String cardName, final int artIndex, final int artIndexMax) - { - String nn = artIndexMax > 1 ? Integer.toString(artIndex+1) : ""; + /** + * Builds the ideal filename. + * + * @param cardName the card name + * @param artIndex the art index + * @param artIndexMax the art index max + * @return the string + */ + public static String buildIdealFilename(final String cardName, final int artIndex, final int artIndexMax) { + String nn = artIndexMax > 1 ? Integer.toString(artIndex + 1) : ""; String mwsCardName = GuiDisplayUtil.cleanStringMWS(cardName); - //3 letter set code with MWS filename format + // 3 letter set code with MWS filename format return String.format("%s%s.full.jpg", mwsCardName, nn); } + /** - *

buildFilename.

- * - * @param card a {@link forge.Card} object. + *

+ * buildFilename. + *

+ * + * @param card + * a {@link forge.Card} object. * @return a {@link java.lang.String} object. */ public static String buildFilename(final Card card) { @@ -544,7 +654,10 @@ public final class CardUtil { final String set = card.getCurSetCode(); Predicate findSetInfo = new Predicate() { - @Override public boolean isTrue(final SetInfo subject) { return subject.Code.equals(set); } + @Override + public boolean isTrue(final SetInfo subject) { + return subject.Code.equals(set); + } }; SetInfo neededSet = findSetInfo.first(card.getSets()); int cntPictures = neededSet == null ? 1 : neededSet.PicCount; @@ -552,58 +665,74 @@ public final class CardUtil { } /** - * buildFilename for lightweight card. Searches for a matching file on disk, + * buildFilename for lightweight card. Searches for a matching file on disk, + * + * @param card the card + * @return the string */ public static String buildFilename(final CardPrinted card) { int maxIndex = card.getCard().getSetInfo(card.getSet()).getCopiesCount(); return buildFilename(card.getName(), card.getSet(), card.getArtIndex(), maxIndex, false); } - private static String buildFilename(final String cardName, final String setName, - final int artIndex, final int artIndexMax, final boolean isToken) + private static String buildFilename(final String cardName, final String setName, final int artIndex, + final int artIndexMax, final boolean isToken) { File path = ForgeProps.getFile(isToken ? NewConstants.IMAGE_TOKEN : NewConstants.IMAGE_BASE); - String nn = artIndexMax > 1 ? Integer.toString(artIndex+1) : ""; + String nn = artIndexMax > 1 ? Integer.toString(artIndex + 1) : ""; String cleanCardName = GuiDisplayUtil.cleanString(cardName); File f = null; if (StringUtils.isNotBlank(setName)) { String mwsCardName = GuiDisplayUtil.cleanStringMWS(cardName); - //First, try 3 letter set code with MWS filename format + // First, try 3 letter set code with MWS filename format String mwsSet3 = String.format("%s/%s%s.full", setName, mwsCardName, nn); f = new File(path, mwsSet3 + ".jpg"); - if (f.exists()) { return mwsSet3; } + if (f.exists()) { + return mwsSet3; + } - //Second, try 2 letter set code with MWS filename format + // Second, try 2 letter set code with MWS filename format String mwsSet2 = String.format("%s/%s%s.full", SetUtils.getCode2ByCode(setName), mwsCardName, nn); f = new File(path, mwsSet2 + ".jpg"); - if (f.exists()) { return mwsSet2; } + if (f.exists()) { + return mwsSet2; + } - //Third, try 3 letter set code with Forge filename format + // Third, try 3 letter set code with Forge filename format String forgeSet3 = String.format("%s/%s%s", setName, cleanCardName, nn); f = new File(path, forgeSet3 + ".jpg"); - if (f.exists()) { return forgeSet3; } + if (f.exists()) { + return forgeSet3; + } } - //Last, give up with set images, go with the old picture type + // Last, give up with set images, go with the old picture type String forgePlain = String.format("%s%s", cleanCardName, nn); f = new File(path, forgePlain + ".jpg"); - if (f.exists()) { return forgePlain; } + if (f.exists()) { + return forgePlain; + } // give up with art index f = new File(path, cleanCardName + ".jpg"); - if (f.exists()) { return cleanCardName; } + if (f.exists()) { + return cleanCardName; + } - //if still no file, download if option enabled? + // if still no file, download if option enabled? return "none"; } /** - *

getWeightedManaCost.

- * - * @param manaCost a {@link java.lang.String} object. + *

+ * getWeightedManaCost. + *

+ * + * @param manaCost + * a {@link java.lang.String} object. * @return a double. */ public static double getWeightedManaCost(final String manaCost) { @@ -616,9 +745,12 @@ public final class CardUtil { } /** - *

getShortColorsString.

- * - * @param colors a {@link java.util.ArrayList} object. + *

+ * getShortColorsString. + *

+ * + * @param colors + * a {@link java.util.ArrayList} object. * @return a {@link java.lang.String} object. */ public static String getShortColorsString(final ArrayList colors) { @@ -643,14 +775,15 @@ public final class CardUtil { /** * Compute the canonicalized ASCII form of a card name. - * - * @param cardName the name to transform (but not side effect) - * + * + * @param cardName + * the name to transform (but not side effect) + * * @return the name in ASCII characters */ public static String canonicalizeCardName(final String cardName) { String result = cardName; - result = result.replace("\u00ae", "(R)"); // Ultimate Nightmare ... + result = result.replace("\u00ae", "(R)"); // Ultimate Nightmare ... result = result.replace("\u00c6", "AE"); result = result.replace("\u00e0", "a"); result = result.replace("\u00e1", "a"); @@ -666,7 +799,7 @@ public final class CardUtil { result = result.replace("\u2015", "-"); result = result.replace("\u2018", "'"); result = result.replace("\u2019", "'"); - result = result.replace("\u221e", "Infinity"); // Mox Lo... + result = result.replace("\u221e", "Infinity"); // Mox Lo... return result; } @@ -674,19 +807,24 @@ public final class CardUtil { /** * getThisTurnEntered. * - * @param to zone going to - * @param from zone coming from - * @param valid a isValid expression - * @param src a Card object + * @param to + * zone going to + * @param from + * zone coming from + * @param valid + * a isValid expression + * @param src + * a Card object * @return a CardList that matches the given criteria */ - public static CardList getThisTurnEntered(final Constant.Zone to, final Constant.Zone from, final String valid, final Card src) { + public static CardList getThisTurnEntered(final Constant.Zone to, final Constant.Zone from, final String valid, + final Card src) + { CardList res = new CardList(); if (to != Constant.Zone.Stack) { res.addAll(((DefaultPlayerZone) AllZone.getComputerPlayer().getZone(to)).getCardsAddedThisTurn(from)); res.addAll(((DefaultPlayerZone) AllZone.getHumanPlayer().getZone(to)).getCardsAddedThisTurn(from)); - } - else { + } else { res.addAll(((DefaultPlayerZone) AllZone.getStackZone()).getCardsAddedThisTurn(from)); } @@ -694,44 +832,50 @@ public final class CardUtil { return res; } - + /** * getThisTurnCast. * - * @param valid a String object - * @param src a Card object + * @param valid + * a String object + * @param src + * a Card object * @return a CardList that matches the given criteria */ public static CardList getThisTurnCast(final String valid, final Card src) { CardList res = new CardList(); - + res.addAll(AllZone.getStack().getCardsCastThisTurn()); - + res = res.getValidCards(valid, src.getController(), src); - + return res; } - + /** * getLastTurnCast. * - * @param valid a String object - * @param src a Card object + * @param valid + * a String object + * @param src + * a Card object * @return a CardList that matches the given criteria */ public static CardList getLastTurnCast(final String valid, final Card src) { CardList res = new CardList(); - + res.addAll(AllZone.getStack().getCardsCastLastTurn()); - + res = res.getValidCards(valid, src.getController(), src); - + return res; } /** * getLKICopy. - * @param c a Card. + * + * @param c + * a Card. * @return a copy of C with LastKnownInfo stuff retained. */ public static Card getLKICopy(final Card c) { @@ -746,32 +890,38 @@ public final class CardUtil { res.setNewPT(c.getNewPT()); res.setReceivedDamageFromThisTurn(c.getReceivedDamageFromThisTurn()); res.setHaunting(c.getHaunting()); - for(Card haunter : c.getHauntedBy()) { + for (Card haunter : c.getHauntedBy()) { res.addHauntedBy(haunter); } return res; } - + + /** + * Gets the radiance. + * + * @param source the source + * @param origin the origin + * @param valid the valid + * @return the radiance + */ public static CardList getRadiance(final Card source, final Card origin, final String[] valid) { CardList res = new CardList(); - - for(Card_Color col : origin.getColor()) { - for(String strCol : col.toStringArray()) - { - if(strCol.equalsIgnoreCase("Colorless")) { + + for (Card_Color col : origin.getColor()) { + for (String strCol : col.toStringArray()) { + if (strCol.equalsIgnoreCase("Colorless")) { continue; } - for(Card c : AllZoneUtil.getColorInPlay(strCol)) - { - if(!res.contains(c) && c.isValid(valid, source.getController(), source) && !c.equals(origin)) { + for (Card c : AllZoneUtil.getColorInPlay(strCol)) { + if (!res.contains(c) && c.isValid(valid, source.getController(), source) && !c.equals(origin)) { res.add(c); } } } } - + return res; } -} //end class CardUtil +} // end class CardUtil diff --git a/src/main/java/forge/Color.java b/src/main/java/forge/Color.java index 6bc11058ecd..092ed855909 100644 --- a/src/main/java/forge/Color.java +++ b/src/main/java/forge/Color.java @@ -1,38 +1,53 @@ package forge; -import forge.card.mana.ManaCost; - import java.util.EnumSet; +import forge.card.mana.ManaCost; + +// TODO Auto-generated Javadoc /** - *

Color class.

- * + *

+ * Color class. + *

+ * * @author Forge * @version $Id$ */ public enum Color { + + /** The Colorless. */ Colorless(0), + /** The White. */ White(1), + /** The Green. */ Green(2), + /** The Red. */ Red(4), + /** The Black. */ Black(8), + /** The Blue. */ Blue(16); @SuppressWarnings("unused") private int flag = 0; /** - *

Constructor for Color.

- * - * @param c a int. + *

+ * Constructor for Color. + *

+ * + * @param c + * a int. */ Color(final int c) { flag = c; } /** - *

Colorless.

- * + *

+ * Colorless. + *

+ * * @return a {@link java.util.EnumSet} object. */ public static EnumSet Colorless() { @@ -41,9 +56,12 @@ public enum Color { } /** - *

ConvertStringsToColor.

- * - * @param s an array of {@link java.lang.String} objects. + *

+ * ConvertStringsToColor. + *

+ * + * @param s + * an array of {@link java.lang.String} objects. * @return a {@link java.util.EnumSet} object. */ public static EnumSet ConvertStringsToColor(String[] s) { @@ -61,33 +79,39 @@ public enum Color { } /** - *

ConvertFromString.

- * - * @param s a {@link java.lang.String} object. + *

+ * ConvertFromString. + *

+ * + * @param s + * a {@link java.lang.String} object. * @return a {@link forge.Color} object. */ public static Color ConvertFromString(String s) { - { - if (s.equals(Constant.Color.White)) { - return Color.White; - } else if (s.equals(Constant.Color.Green)) { - return Color.Green; - } else if (s.equals(Constant.Color.Red)) { - return Color.Red; - } else if (s.equals(Constant.Color.Black)) { - return Color.Black; - } else if (s.equals(Constant.Color.Blue)) { - return Color.Blue; - } - return Color.Colorless; + if (s.equals(Constant.Color.White)) { + return Color.White; + } else if (s.equals(Constant.Color.Green)) { + return Color.Green; + } else if (s.equals(Constant.Color.Red)) { + return Color.Red; + } else if (s.equals(Constant.Color.Black)) { + return Color.Black; + } else if (s.equals(Constant.Color.Blue)) { + return Color.Blue; } + + return Color.Colorless; + } /** - *

ConvertManaCostToColor.

- * - * @param m a {@link forge.card.mana.ManaCost} object. + *

+ * ConvertManaCostToColor. + *

+ * + * @param m + * a {@link forge.card.mana.ManaCost} object. * @return a {@link java.util.EnumSet} object. */ public static EnumSet ConvertManaCostToColor(final ManaCost m) { @@ -117,8 +141,10 @@ public enum Color { } /** - *

toString.

- * + *

+ * toString. + *

+ * * @return a {@link java.lang.String} object. */ public String toString() { diff --git a/src/main/java/forge/ColorChanger.java b/src/main/java/forge/ColorChanger.java index bd0d61491d1..576b6278f20 100644 --- a/src/main/java/forge/ColorChanger.java +++ b/src/main/java/forge/ColorChanger.java @@ -5,25 +5,29 @@ import java.util.ArrayList; import forge.card.mana.ManaCost; /** - * class ColorChanger. - * TODO Write javadoc for this type. - * + * class ColorChanger. TODO Write javadoc for this type. + * */ public class ColorChanger { private ArrayList globalColorChanges = new ArrayList(); - /** - *

addColorChanges.

- * - * @param s a {@link java.lang.String} object. - * @param c a {@link forge.Card} object. - * @param addToColors a boolean. - * @param bIncrease a boolean. + *

+ * addColorChanges. + *

+ * + * @param s + * a {@link java.lang.String} object. + * @param c + * a {@link forge.Card} object. + * @param addToColors + * a boolean. + * @param bIncrease + * a boolean. * @return a long. */ - public final long addColorChanges(final String s, final Card c, final boolean addToColors, - final boolean bIncrease) + public final long addColorChanges(final String s, + final Card c, final boolean addToColors, final boolean bIncrease) { if (bIncrease) { Card_Color.increaseTimestamp(); @@ -33,12 +37,18 @@ public class ColorChanger { } /** - *

removeColorChanges.

- * - * @param s a {@link java.lang.String} object. - * @param c a {@link forge.Card} object. - * @param addTo a boolean. - * @param timestamp a long. + *

+ * removeColorChanges. + *

+ * + * @param s + * a {@link java.lang.String} object. + * @param c + * a {@link forge.Card} object. + * @param addTo + * a boolean. + * @param timestamp + * a long. */ public final void removeColorChanges(final String s, final Card c, final boolean addTo, final long timestamp) { Card_Color removeCol = null; @@ -54,14 +64,18 @@ public class ColorChanger { } /** - *

reset = clearColorChanges.

+ *

+ * reset = clearColorChanges. + *

*/ public final void reset() { clearColorChanges(); } /** - *

clearColorChanges.

+ *

+ * clearColorChanges. + *

*/ public final void clearColorChanges() { // clear the global color changes at end of each game @@ -69,8 +83,10 @@ public class ColorChanger { } /** - *

getColorChanges.

- * + *

+ * getColorChanges. + *

+ * * @return a {@link java.util.ArrayList} object. */ public final ArrayList getColorChanges() { diff --git a/src/main/java/forge/Combat.java b/src/main/java/forge/Combat.java index f9767a6ee29..e7fa6bb5920 100644 --- a/src/main/java/forge/Combat.java +++ b/src/main/java/forge/Combat.java @@ -1,13 +1,22 @@ package forge; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; import forge.Constant.Zone; /** - *

Combat class.

- * + *

+ * Combat class. + *

+ * * @author Forge * @version $Id$ */ @@ -20,7 +29,8 @@ public class Combat { private HashMap unblockedMap = new HashMap(); private HashMap defendingDamageMap = new HashMap(); - // Defenders are the Defending Player + Each Planeswalker that player controls + // Defenders are the Defending Player + Each Planeswalker that player + // controls private ArrayList defenders = new ArrayList(); private int currentDefender = 0; private int nextDefender = 0; @@ -37,14 +47,18 @@ public class Combat { private CardList canBlockAttackerWithLure = new CardList(); /** - *

Constructor for Combat.

+ *

+ * Constructor for Combat. + *

*/ public Combat() { // Let the Begin Turn/Untap Phase Reset Combat properly } /** - *

reset.

+ *

+ * reset. + *

*/ public final void reset() { resetAttackers(); @@ -69,9 +83,12 @@ public class Combat { } /** - *

initiatePossibleDefenders.

- * - * @param defender a {@link forge.Player} object. + *

+ * initiatePossibleDefenders. + *

+ * + * @param defender + * a {@link forge.Player} object. */ public final void initiatePossibleDefenders(final Player defender) { defenders.add(defender); @@ -83,8 +100,10 @@ public class Combat { } /** - *

nextDefender.

- * + *

+ * nextDefender. + *

+ * * @return a {@link java.lang.Object} object. */ public final Object nextDefender() { @@ -99,17 +118,22 @@ public class Combat { } /** - *

Setter for the field currentDefender.

- * - * @param def a int. + *

+ * Setter for the field currentDefender. + *

+ * + * @param def + * a int. */ public final void setCurrentDefender(final int def) { currentDefender = def; } /** - *

getRemainingDefenders.

- * + *

+ * getRemainingDefenders. + *

+ * * @return a int. */ public final int getRemainingDefenders() { @@ -117,8 +141,10 @@ public class Combat { } /** - *

Getter for the field defenders.

- * + *

+ * Getter for the field defenders. + *

+ * * @return a {@link java.util.ArrayList} object. */ public final ArrayList getDefenders() { @@ -126,17 +152,22 @@ public class Combat { } /** - *

Setter for the field defenders.

- * - * @param newDef a {@link java.util.ArrayList} object. + *

+ * Setter for the field defenders. + *

+ * + * @param newDef + * a {@link java.util.ArrayList} object. */ - public final void setDefenders(ArrayList newDef) { + public final void setDefenders(final ArrayList newDef) { defenders = newDef; } /** - *

getDefendingPlaneswalkers.

- * + *

+ * getDefendingPlaneswalkers. + *

+ * * @return an array of {@link forge.Card} objects. */ public final Card[] getDefendingPlaneswalkers() { @@ -155,8 +186,10 @@ public class Combat { } /** - *

getDeclaredAttackers.

- * + *

+ * getDeclaredAttackers. + *

+ * * @return a int. */ public final int getDeclaredAttackers() { @@ -164,26 +197,34 @@ public class Combat { } /** - *

Setter for the field attackingPlayer.

- * - * @param player a {@link forge.Player} object. + *

+ * Setter for the field attackingPlayer. + *

+ * + * @param player + * a {@link forge.Player} object. */ public final void setAttackingPlayer(final Player player) { attackingPlayer = player; } /** - *

Setter for the field defendingPlayer.

- * - * @param player a {@link forge.Player} object. + *

+ * Setter for the field defendingPlayer. + *

+ * + * @param player + * a {@link forge.Player} object. */ public final void setDefendingPlayer(final Player player) { defendingPlayer = player; } /** - *

Getter for the field attackingPlayer.

- * + *

+ * Getter for the field attackingPlayer. + *

+ * * @return a {@link forge.Player} object. */ public final Player getAttackingPlayer() { @@ -191,8 +232,10 @@ public class Combat { } /** - *

Getter for the field defendingPlayer.

- * + *

+ * Getter for the field defendingPlayer. + *

+ * * @return a {@link forge.Player} object. */ public final Player getDefendingPlayer() { @@ -200,8 +243,10 @@ public class Combat { } /** - *

Getter for the field defendingDamageMap.

- * + *

+ * Getter for the field defendingDamageMap. + *

+ * * @return a {@link java.util.HashMap} object. */ public final HashMap getDefendingDamageMap() { @@ -209,8 +254,10 @@ public class Combat { } /** - *

getTotalDefendingDamage.

- * + *

+ * getTotalDefendingDamage. + *

+ * * @return a int. */ public final int getTotalDefendingDamage() { @@ -227,21 +274,22 @@ public class Combat { } /** - *

setDefendingDamage.

+ *

+ * setDefendingDamage. + *

*/ public final void setDefendingDamage() { defendingDamageMap.clear(); CardList att = new CardList(getAttackers()); // sum unblocked attackers' power for (int i = 0; i < att.size(); i++) { - if (!isBlocked(att.get(i)) - || (getBlockers(att.get(i)).size() == 0 && att.get(i).hasKeyword("Trample"))) - { + if (!isBlocked(att.get(i)) || (getBlockers(att.get(i)).size() == 0 && att.get(i).hasKeyword("Trample"))) { int damageDealt = att.get(i).getNetCombatDamage(); if (damageDealt > 0) { - //if the creature has first strike do not do damage in the normal combat phase + // if the creature has first strike do not do damage in the + // normal combat phase if (!att.get(i).hasFirstStrike() || att.get(i).hasDoubleStrike()) { addDefendingDamage(damageDealt, att.get(i)); } @@ -250,10 +298,11 @@ public class Combat { } // for } - /** - *

setDefendingFirstStrikeDamage.

- * + *

+ * setDefendingFirstStrikeDamage. + *

+ * * @return a boolean. */ public final boolean setDefendingFirstStrikeDamage() { @@ -267,7 +316,8 @@ public class Combat { int damageDealt = att.get(i).getNetCombatDamage(); if (damageDealt > 0) { - // if the creature has first strike or double strike do damage in the first strike combat phase + // if the creature has first strike or double strike do + // damage in the first strike combat phase if (att.get(i).hasFirstStrike() || att.get(i).hasDoubleStrike()) { addDefendingDamage(damageDealt, att.get(i)); needsFirstStrike = true; @@ -279,12 +329,15 @@ public class Combat { return needsFirstStrike; } - /** - *

addDefendingDamage.

- * - * @param n a int. - * @param source a {@link forge.Card} object. + *

+ * addDefendingDamage. + *

+ * + * @param n + * a int. + * @param source + * a {@link forge.Card} object. */ public final void addDefendingDamage(final int n, final Card source) { String slot = getDefenderByAttacker(source).toString(); @@ -305,17 +358,22 @@ public class Combat { } /** - *

addAttackingDamage.

- * - * @param n a int. + *

+ * addAttackingDamage. + *

+ * + * @param n + * a int. */ - public final void addAttackingDamage(int n) { + public final void addAttackingDamage(final int n) { attackingDamage += n; } /** - *

Getter for the field attackingDamage.

- * + *

+ * Getter for the field attackingDamage. + *

+ * * @return a int. */ public final int getAttackingDamage() { @@ -323,8 +381,10 @@ public class Combat { } /** - *

sortAttackerByDefender.

- * + *

+ * sortAttackerByDefender. + *

+ * * @return an array of {@link forge.CardList} objects. */ public final CardList[] sortAttackerByDefender() { @@ -343,9 +403,12 @@ public class Combat { } /** - *

isAttacking.

- * - * @param c a {@link forge.Card} object. + *

+ * isAttacking. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ public final boolean isAttacking(final Card c) { @@ -353,9 +416,12 @@ public class Combat { } /** - *

addAttacker.

- * - * @param c a {@link forge.Card} object. + *

+ * addAttacker. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void addAttacker(final Card c) { map.put(c, new CardList()); @@ -363,9 +429,12 @@ public class Combat { } /** - *

getDefenderByAttacker.

- * - * @param c a {@link forge.Card} object. + *

+ * getDefenderByAttacker. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a {@link java.lang.Object} object. */ public final Object getDefenderByAttacker(final Card c) { @@ -373,7 +442,9 @@ public class Combat { } /** - *

resetAttackers.

+ *

+ * resetAttackers. + *

*/ public final void resetAttackers() { map.clear(); @@ -381,8 +452,10 @@ public class Combat { } /** - *

getAttackers.

- * + *

+ * getAttackers. + *

+ * * @return an array of {@link forge.Card} objects. */ public final Card[] getAttackers() { @@ -397,9 +470,12 @@ public class Combat { } // getAttackers() /** - *

isBlocked.

- * - * @param attacker a {@link forge.Card} object. + *

+ * isBlocked. + *

+ * + * @param attacker + * a {@link forge.Card} object. * @return a boolean. */ public final boolean isBlocked(final Card attacker) { @@ -407,10 +483,14 @@ public class Combat { } /** - *

addBlocker.

- * - * @param attacker a {@link forge.Card} object. - * @param blocker a {@link forge.Card} object. + *

+ * addBlocker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param blocker + * a {@link forge.Card} object. */ public final void addBlocker(final Card attacker, final Card blocker) { blocked.add(attacker); @@ -418,7 +498,9 @@ public class Combat { } /** - *

resetBlockers.

+ *

+ * resetBlockers. + *

*/ public final void resetBlockers() { reset(); @@ -430,8 +512,10 @@ public class Combat { } /** - *

getAllBlockers.

- * + *

+ * getAllBlockers. + *

+ * * @return a {@link forge.CardList} object. */ public final CardList getAllBlockers() { @@ -446,9 +530,12 @@ public class Combat { } // getAllBlockers() /** - *

getBlockers.

- * - * @param attacker a {@link forge.Card} object. + *

+ * getBlockers. + *

+ * + * @param attacker + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ public final CardList getBlockers(final Card attacker) { @@ -460,9 +547,12 @@ public class Combat { } /** - *

getAttackerBlockedBy.

- * - * @param blocker a {@link forge.Card} object. + *

+ * getAttackerBlockedBy. + *

+ * + * @param blocker + * a {@link forge.Card} object. * @return a {@link forge.Card} object. */ public final Card getAttackerBlockedBy(final Card blocker) { @@ -478,9 +568,12 @@ public class Combat { } /** - *

getList.

- * - * @param attacker a {@link forge.Card} object. + *

+ * getList. + *

+ * + * @param attacker + * a {@link forge.Card} object. * @return a {@link forge.CardList} object. */ private CardList getList(final Card attacker) { @@ -488,9 +581,12 @@ public class Combat { } /** - *

removeFromCombat.

- * - * @param c a {@link forge.Card} object. + *

+ * removeFromCombat. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void removeFromCombat(final Card c) { // is card an attacker? @@ -502,7 +598,8 @@ public class Combat { for (Card a : att) { if (getBlockers(a).contains(c)) { getList(a).remove(c); - // TODO if Declare Blockers and Declare Blockers (Abilities) merge this logic needs to be tweaked + // TODO if Declare Blockers and Declare Blockers (Abilities) + // merge this logic needs to be tweaked if (getBlockers(a).size() == 0 && AllZone.getPhase().is(Constant.Phase.Combat_Declare_Blockers)) { blocked.remove(a); } @@ -514,9 +611,11 @@ public class Combat { } // removeFromCombat() /** - *

verifyCreaturesInPlay.

+ *

+ * verifyCreaturesInPlay. + *

*/ - public void verifyCreaturesInPlay() { + public final void verifyCreaturesInPlay() { CardList all = new CardList(); all.addAll(getAttackers()); all.addAll(getAllBlockers()); @@ -529,7 +628,9 @@ public class Combat { } // verifyCreaturesInPlay() /** - *

setUnblocked.

+ *

+ * setUnblocked. + *

*/ public final void setUnblocked() { CardList attacking = new CardList(getAttackers()); @@ -538,10 +639,10 @@ public class Combat { CardList block = getBlockers(attacker); if (block.size() == 0) { - // this damage is assigned to a player by setPlayerDamage() + // this damage is assigned to a player by setPlayerDamage() addUnblockedAttacker(attacker); - //Run Unblocked Trigger + // Run Unblocked Trigger HashMap runParams = new HashMap(); runParams.put("Attacker", attacker); AllZone.getTriggerHandler().runTrigger("AttackerUnblocked", runParams); @@ -553,8 +654,10 @@ public class Combat { // set Card.setAssignedDamage() for all creatures in combat // also assigns player damage by setPlayerDamage() /** - *

setAssignedFirstStrikeDamage.

- * + *

+ * setAssignedFirstStrikeDamage. + *

+ * * @return a boolean. */ public final boolean setAssignedFirstStrikeDamage() { @@ -582,7 +685,8 @@ public class Combat { } if (block.size() == 0) { - // this damage is assigned to a player by setDefendingFirstStrikeDamage() + // this damage is assigned to a player by + // setDefendingFirstStrikeDamage() } else if (attacker.hasFirstStrike() || attacker.hasDoubleStrike()) { needFirstStrike = true; if (getAttackingPlayer().isHuman()) { // human attacks @@ -602,7 +706,9 @@ public class Combat { // set Card.setAssignedDamage() for all creatures in combat // also assigns player damage by setPlayerDamage() /** - *

setAssignedDamage.

+ *

+ * setAssignedDamage. + *

*/ public final void setAssignedDamage() { setDefendingDamage(); @@ -646,11 +752,16 @@ public class Combat { } // assignDamage() /** - *

distributeAIDamage.

- * - * @param attacker a {@link forge.Card} object. - * @param block a {@link forge.CardList} object. - * @param damage a int. + *

+ * distributeAIDamage. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param block + * a {@link forge.CardList} object. + * @param damage + * a int. */ private void distributeAIDamage(final Card attacker, final CardList block, int damage) { Card c = attacker; @@ -664,7 +775,8 @@ public class Combat { int damageNeeded = 0; - //TODO if the human can be killed distribute only the minimum of damage to the blocker + // TODO if the human can be killed distribute only the minimum + // of damage to the blocker damageNeeded = blocker.getEnoughDamageToKill(damage, attacker, true); @@ -676,7 +788,8 @@ public class Combat { int trample = damage - damageNeeded; - // If Extra trample damage, assign to defending player/planeswalker + // If Extra trample damage, assign to defending + // player/planeswalker if (0 < trample) { this.addDefendingDamage(trample, attacker); } @@ -687,7 +800,8 @@ public class Combat { } } // 1 blocker else { - boolean killsAllBlockers = true; //Does the attacker deal lethal damage to all blockers + boolean killsAllBlockers = true; // Does the attacker deal lethal + // damage to all blockers for (Card b : block) { int enoughDamageToKill = b.getEnoughDamageToKill(damage, attacker, true); if (enoughDamageToKill <= damage) { @@ -701,23 +815,23 @@ public class Combat { } } // for - // if attacker has no trample, and there's damage left, assign the rest + // if attacker has no trample, and there's damage left, assign the + // rest // to a random blocker - if (damage > 0 - && !(c.hasKeyword("Trample") - && killsAllBlockers == true)) { + if (damage > 0 && !(c.hasKeyword("Trample") && killsAllBlockers)) { int index = CardUtil.getRandomIndex(block); block.get(index).addAssignedDamage(damage, c); damage = 0; - } else if (c.hasKeyword("Trample") - && killsAllBlockers == true) { + } else if (c.hasKeyword("Trample") && killsAllBlockers) { this.addDefendingDamage(damage, c); } } } // setAssignedDamage() /** - *

dealAssignedDamage.

+ *

+ * dealAssignedDamage. + *

*/ public static void dealAssignedDamage() { // This function handles both Regular and First Strike combat assignment @@ -731,8 +845,8 @@ public class Combat { player.addCombatDamage(entry.getValue(), entry.getKey()); } - CardList unblocked = new CardList(bFirstStrike ? AllZone.getCombat().getUnblockedAttackers() : - AllZone.getCombat().getUnblockedFirstStrikeAttackers()); + CardList unblocked = new CardList(bFirstStrike ? AllZone.getCombat().getUnblockedAttackers() : AllZone + .getCombat().getUnblockedFirstStrikeAttackers()); for (int j = 0; j < unblocked.size(); j++) { if (bFirstStrike) { @@ -773,14 +887,18 @@ public class Combat { c.clearAssignedDamage(); } - //This was deeper before, but that resulted in the stack entry acting like before. + // This was deeper before, but that resulted in the stack entry acting + // like before. } /** - *

isUnblocked.

- * - * @param att a {@link forge.Card} object. + *

+ * isUnblocked. + *

+ * + * @param att + * a {@link forge.Card} object. * @return a boolean. */ public final boolean isUnblocked(final Card att) { @@ -788,8 +906,10 @@ public class Combat { } /** - *

getUnblockedAttackers.

- * + *

+ * getUnblockedAttackers. + *

+ * * @return an array of {@link forge.Card} objects. */ public final Card[] getUnblockedAttackers() { @@ -807,8 +927,10 @@ public class Combat { } // getUnblockedAttackers() /** - *

getUnblockedFirstStrikeAttackers.

- * + *

+ * getUnblockedFirstStrikeAttackers. + *

+ * * @return an array of {@link forge.Card} objects. */ public final Card[] getUnblockedFirstStrikeAttackers() { @@ -826,9 +948,12 @@ public class Combat { } // getUnblockedAttackers() /** - *

addUnblockedAttacker.

- * - * @param c a {@link forge.Card} object. + *

+ * addUnblockedAttacker. + *

+ * + * @param c + * a {@link forge.Card} object. */ public final void addUnblockedAttacker(final Card c) { unblockedMap.put(c, new CardList()); diff --git a/src/main/java/forge/CombatUtil.java b/src/main/java/forge/CombatUtil.java index 415eec200d9..089d3b66482 100644 --- a/src/main/java/forge/CombatUtil.java +++ b/src/main/java/forge/CombatUtil.java @@ -1,5 +1,9 @@ package forge; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.esotericsoftware.minlog.Log; @@ -11,31 +15,32 @@ import forge.card.trigger.Trigger; import forge.gui.GuiUtils; import forge.gui.input.Input_PayManaCost_Ability; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - /** - *

CombatUtil class.

- * + *

+ * CombatUtil class. + *

+ * * @author Forge * @version $Id$ */ public class CombatUtil { - //can the creature block given the combat state? + // can the creature block given the combat state? /** - *

canBlock.

- * - * @param blocker a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * canBlock. + *

+ * + * @param blocker + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean canBlock(Card blocker, Combat combat) { - if (blocker == null) return false; + if (blocker == null) + return false; if (combat.getAllBlockers().size() > 1 && AllZoneUtil.isCardInPlay("Caverns of Despair")) return false; @@ -46,26 +51,29 @@ public class CombatUtil { if (combat.getAllBlockers().size() > 0 && AllZoneUtil.isCardInPlay("Dueling Grounds")) return false; - return canBlock(blocker); } - - //can the creature block at all? + // can the creature block at all? /** - *

canBlock.

- * - * @param blocker a {@link forge.Card} object. + *

+ * canBlock. + *

+ * + * @param blocker + * a {@link forge.Card} object. * @return a boolean. */ public static boolean canBlock(Card blocker) { - if (blocker == null) return false; + if (blocker == null) + return false; if (blocker.isTapped() && !AllZoneUtil.isCardInPlay("Masako the Humorless", blocker.getController())) return false; - if (blocker.hasKeyword("CARDNAME can't block.") || blocker.hasKeyword("CARDNAME can't attack or block.") || blocker.isPhasedOut()) + if (blocker.hasKeyword("CARDNAME can't block.") || blocker.hasKeyword("CARDNAME can't attack or block.") + || blocker.isPhasedOut()) return false; CardList kulrath = AllZoneUtil.getCardsIn(Zone.Battlefield, "Kulrath Knight"); @@ -82,84 +90,93 @@ public class CombatUtil { return true; } - //can the attacker be blocked at all? + // can the attacker be blocked at all? /** - *

canBeBlocked.

- * - * @param attacker a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * canBeBlocked. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean canBeBlocked(Card attacker, Combat combat) { - if (attacker == null) return true; + if (attacker == null) + return true; if (attacker.hasKeyword("CARDNAME can't be blocked by more than one creature.") - && combat.getBlockers(attacker).size() > 0) return false; + && combat.getBlockers(attacker).size() > 0) + return false; return canBeBlocked(attacker); } - //can the attacker be blocked at all? + // can the attacker be blocked at all? /** - *

canBeBlocked.

- * - * @param attacker a {@link forge.Card} object. + *

+ * canBeBlocked. + *

+ * + * @param attacker + * a {@link forge.Card} object. * @return a boolean. */ public static boolean canBeBlocked(Card attacker) { - if (attacker == null) return true; + if (attacker == null) + return true; - if (attacker.hasKeyword("Unblockable")) return false; + if (attacker.hasKeyword("Unblockable")) + return false; - //Landwalk - if (!AllZoneUtil.isCardInPlay("Staff of the Ages")) { //"Creatures with landwalk abilities can be blocked as though they didn't have those abilities." + // Landwalk + if (!AllZoneUtil.isCardInPlay("Staff of the Ages")) { // "Creatures with landwalk abilities can be blocked as though they didn't have those abilities." CardList blkCL = attacker.getController().getOpponent().getCardsIn(Zone.Battlefield); CardList temp = new CardList(); if (attacker.hasKeyword("Plainswalk")) { temp = blkCL.getType("Plains"); - if (!AllZoneUtil.isCardInPlay("Lord Magnus") - && !AllZoneUtil.isCardInPlay("Great Wall") - && !temp.isEmpty()) return false; + if (!AllZoneUtil.isCardInPlay("Lord Magnus") && !AllZoneUtil.isCardInPlay("Great Wall") + && !temp.isEmpty()) + return false; } if (attacker.hasKeyword("Islandwalk")) { temp = blkCL.getType("Island"); - if (!AllZoneUtil.isCardInPlay("Undertow") - && !AllZoneUtil.isCardInPlay("Gosta Dirk") - && !temp.isEmpty()) return false; + if (!AllZoneUtil.isCardInPlay("Undertow") && !AllZoneUtil.isCardInPlay("Gosta Dirk") && !temp.isEmpty()) + return false; } if (attacker.hasKeyword("Swampwalk")) { temp = blkCL.getType("Swamp"); - if (!AllZoneUtil.isCardInPlay("Ur-drago") - && !AllZoneUtil.isCardInPlay("Quagmire") - && !temp.isEmpty()) return false; + if (!AllZoneUtil.isCardInPlay("Ur-drago") && !AllZoneUtil.isCardInPlay("Quagmire") && !temp.isEmpty()) + return false; } if (attacker.hasKeyword("Mountainwalk")) { temp = blkCL.getType("Mountain"); - if (!AllZoneUtil.isCardInPlay("Crevasse") - && !temp.isEmpty()) return false; + if (!AllZoneUtil.isCardInPlay("Crevasse") && !temp.isEmpty()) + return false; } if (attacker.hasKeyword("Forestwalk")) { temp = blkCL.getType("Forest"); - if (!AllZoneUtil.isCardInPlay("Lord Magnus") - && !AllZoneUtil.isCardInPlay("Deadfall") - && !temp.isEmpty()) return false; + if (!AllZoneUtil.isCardInPlay("Lord Magnus") && !AllZoneUtil.isCardInPlay("Deadfall") + && !temp.isEmpty()) + return false; } if (attacker.hasKeyword("Legendary landwalk")) { temp = blkCL.filter(new CardListFilter() { public boolean addCard(Card c) { - return c.isLand() - && c.isType("Legendary"); + return c.isLand() && c.isType("Legendary"); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow swampwalk")) { @@ -168,7 +185,8 @@ public class CombatUtil { return c.isType("Swamp") && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow forestwalk")) { @@ -177,7 +195,8 @@ public class CombatUtil { return c.isType("Forest") && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow islandwalk")) { @@ -186,7 +205,8 @@ public class CombatUtil { return c.isType("Island") && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow plainswalk")) { @@ -195,7 +215,8 @@ public class CombatUtil { return c.isType("Plains") && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow mountainwalk")) { @@ -204,7 +225,8 @@ public class CombatUtil { return c.isType("Mountain") && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Snow landwalk")) { @@ -213,17 +235,18 @@ public class CombatUtil { return c.isLand() && c.isSnow(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Desertwalk")) { temp = blkCL.filter(new CardListFilter() { public boolean addCard(Card c) { - return c.isLand() - && c.isType("Desert"); + return c.isLand() && c.isType("Desert"); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } if (attacker.hasKeyword("Nonbasic landwalk")) { @@ -232,7 +255,8 @@ public class CombatUtil { return c.isLand() && !c.isBasicLand(); } }); - if (!temp.isEmpty()) return false; + if (!temp.isEmpty()) + return false; } } return true; @@ -240,9 +264,12 @@ public class CombatUtil { // Has the player chosen all mandatory blocks? /** - *

finishedMandatotyBlocks.

- * - * @param combat a {@link forge.Combat} object. + *

+ * finishedMandatotyBlocks. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean finishedMandatotyBlocks(Combat combat) { @@ -250,15 +277,14 @@ public class CombatUtil { CardList blockers = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); CardList attackers = new CardList(combat.getAttackers()); - //if a creature does not block but should, return false + // if a creature does not block but should, return false for (Card blocker : blockers) { - //lure effects + // lure effects if (!combat.getAllBlockers().contains(blocker) && mustBlockAnAttacker(blocker, combat)) return false; - //"CARDNAME blocks each turn if able." - if (!combat.getAllBlockers().contains(blocker) - && blocker.hasKeyword("CARDNAME blocks each turn if able.")) + // "CARDNAME blocks each turn if able." + if (!combat.getAllBlockers().contains(blocker) && blocker.hasKeyword("CARDNAME blocks each turn if able.")) for (Card attacker : attackers) if (canBlock(attacker, blocker, combat)) return false; @@ -269,27 +295,35 @@ public class CombatUtil { // can the blocker block an attacker with a lure effect? /** - *

mustBlockAnAttacker.

- * - * @param blocker a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * mustBlockAnAttacker. + *

+ * + * @param blocker + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean mustBlockAnAttacker(Card blocker, Combat combat) { - if (blocker == null) return false; + if (blocker == null) + return false; - if (canBlock(blocker, combat) == false) return false; + if (canBlock(blocker, combat) == false) + return false; CardList attackersWithLure = new CardList(combat.getAttackers()); attackersWithLure = attackersWithLure.getKeyword("All creatures able to block CARDNAME do so."); for (Card attacker : attackersWithLure) { - if (canBeBlocked(attacker, combat) && canBlock(attacker, blocker)) return true; + if (canBeBlocked(attacker, combat) && canBlock(attacker, blocker)) + return true; } - + for (Card attacker : blocker.getMustBlockCards()) { - if (canBeBlocked(attacker, combat) && canBlock(attacker, blocker)) return true; + if (canBeBlocked(attacker, combat) && canBlock(attacker, blocker)) + return true; } return false; @@ -297,52 +331,68 @@ public class CombatUtil { // can the blocker block the attacker given the combat state? /** - *

canBlock.

- * - * @param attacker a {@link forge.Card} object. - * @param blocker a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * canBlock. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param blocker + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean canBlock(Card attacker, Card blocker, Combat combat) { - if (attacker == null || blocker == null) return false; + if (attacker == null || blocker == null) + return false; - if (canBlock(blocker, combat) == false) return false; - if (canBeBlocked(attacker, combat) == false) return false; + if (canBlock(blocker, combat) == false) + return false; + if (canBeBlocked(attacker, combat) == false) + return false; - //if the attacker has no lure effect, but the blocker can block another attacker with lure, the blocker can't block the former + // if the attacker has no lure effect, but the blocker can block another + // attacker with lure, the blocker can't block the former if (!attacker.hasKeyword("All creatures able to block CARDNAME do so.") - && !(blocker.getMustBlockCards().contains(attacker)) - && mustBlockAnAttacker(blocker, combat)) + && !(blocker.getMustBlockCards().contains(attacker)) && mustBlockAnAttacker(blocker, combat)) return false; return canBlock(attacker, blocker); } - // can the blocker block the attacker? /** - *

canBlock.

- * - * @param attacker a {@link forge.Card} object. - * @param blocker a {@link forge.Card} object. + *

+ * canBlock. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param blocker + * a {@link forge.Card} object. * @return a boolean. */ public static boolean canBlock(Card attacker, Card blocker) { - if (attacker == null || blocker == null) return false; + if (attacker == null || blocker == null) + return false; - if (canBlock(blocker) == false) return false; - if (canBeBlocked(attacker) == false) return false; + if (canBlock(blocker) == false) + return false; + if (canBeBlocked(attacker) == false) + return false; + + if (CardFactoryUtil.hasProtectionFrom(blocker, attacker)) + return false; - if (CardFactoryUtil.hasProtectionFrom(blocker, attacker)) return false; - if (blocker.hasStartOfKeyword("CARDNAME can't block ")) { for (String kw : blocker.getKeyword()) { if (kw.startsWith("CARDNAME can't block ")) { String unblockableCard = kw.substring(21); - int ID = Integer.parseInt(unblockableCard.substring(unblockableCard.lastIndexOf("(") + 1, unblockableCard.length() - 1)); + int ID = Integer.parseInt(unblockableCard.substring(unblockableCard.lastIndexOf("(") + 1, + unblockableCard.length() - 1)); if (attacker.getUniqueNumber() == ID) { return false; } @@ -350,27 +400,28 @@ public class CombatUtil { } } - //rare case: + // rare case: if (blocker.hasKeyword("Shadow") - && blocker.hasKeyword( - "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false; + && blocker.hasKeyword("CARDNAME can block creatures with shadow as though they didn't have shadow.")) + return false; - if (attacker.hasKeyword("Shadow") - && !blocker.hasKeyword("Shadow") - && !blocker.hasKeyword( - "CARDNAME can block creatures with shadow as though they didn't have shadow.")) return false; + if (attacker.hasKeyword("Shadow") && !blocker.hasKeyword("Shadow") + && !blocker.hasKeyword("CARDNAME can block creatures with shadow as though they didn't have shadow.")) + return false; + + if (!attacker.hasKeyword("Shadow") && blocker.hasKeyword("Shadow")) + return false; - if (!attacker.hasKeyword("Shadow") - && blocker.hasKeyword("Shadow")) return false; - if (attacker.hasKeyword("Creatures with power less than CARDNAME's power can't block it.") - && attacker.getNetAttack() > blocker.getNetAttack()) - return false; + && attacker.getNetAttack() > blocker.getNetAttack()) + return false; if (blocker.getNetAttack() > attacker.getNetAttack() - && blocker.hasKeyword("CARDNAME can't be blocked by creatures with power greater than CARDNAME's power.")) + && blocker + .hasKeyword("CARDNAME can't be blocked by creatures with power greater than CARDNAME's power.")) return false; if (blocker.getNetAttack() >= attacker.getNetDefense() - && blocker.hasKeyword("CARDNAME can't be blocked by creatures with power equal to or greater than CARDNAME's toughness.")) + && blocker + .hasKeyword("CARDNAME can't be blocked by creatures with power equal to or greater than CARDNAME's toughness.")) return false; if (attacker.hasStartOfKeyword("CantBeBlockedBy")) { @@ -381,7 +432,7 @@ public class CombatUtil { if (blocker.isValid(restrictions, attacker.getController(), attacker)) return false; } - + if (blocker.hasStartOfKeyword("CantBlock")) { int KeywordPosition = blocker.getKeywordPosition("CantBlock"); String parse = blocker.getKeyword().get(KeywordPosition).toString(); @@ -391,23 +442,29 @@ public class CombatUtil { return false; } - if (attacker.hasKeyword("CARDNAME can't be blocked by black creatures.") && blocker.isBlack()) return false; - if (attacker.hasKeyword("CARDNAME can't be blocked by blue creatures.") && blocker.isBlue()) return false; - if (attacker.hasKeyword("CARDNAME can't be blocked by green creatures.") && blocker.isGreen()) return false; - if (attacker.hasKeyword("CARDNAME can't be blocked by red creatures.") && blocker.isRed()) return false; - if (attacker.hasKeyword("CARDNAME can't be blocked by white creatures.") && blocker.isWhite()) return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by black creatures.") && blocker.isBlack()) + return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by blue creatures.") && blocker.isBlue()) + return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by green creatures.") && blocker.isGreen()) + return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by red creatures.") && blocker.isRed()) + return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by white creatures.") && blocker.isWhite()) + return false; - if (blocker.hasKeyword("CARDNAME can block only creatures with flying.") - && !attacker.hasKeyword("Flying")) return false; + if (blocker.hasKeyword("CARDNAME can block only creatures with flying.") && !attacker.hasKeyword("Flying")) + return false; if (attacker.hasKeyword("Flying") || attacker.hasKeyword("CARDNAME can't be blocked except by creatures with flying or reach.")) { - if (!blocker.hasKeyword("Flying") - && !blocker.hasKeyword("Reach")) return false; + if (!blocker.hasKeyword("Flying") && !blocker.hasKeyword("Reach")) + return false; } if (attacker.hasKeyword("Horsemanship")) { - if (!blocker.hasKeyword("Horsemanship")) return false; + if (!blocker.hasKeyword("Horsemanship")) + return false; } if (attacker.hasKeyword("Fear")) { @@ -420,28 +477,33 @@ public class CombatUtil { return false; } - if (attacker.hasKeyword("CARDNAME can't be blocked by Walls.") - && blocker.isWall()) return false; + if (attacker.hasKeyword("CARDNAME can't be blocked by Walls.") && blocker.isWall()) + return false; - if (attacker.hasKeyword("CARDNAME can't be blocked except by Walls.") - && !blocker.isWall()) return false; - - if (attacker.hasKeyword("CARDNAME can't be blocked except by black creatures.") - && !blocker.isBlack()) return false; + if (attacker.hasKeyword("CARDNAME can't be blocked except by Walls.") && !blocker.isWall()) + return false; + + if (attacker.hasKeyword("CARDNAME can't be blocked except by black creatures.") && !blocker.isBlack()) + return false; if (AllZoneUtil.isCardInPlay("Shifting Sliver")) { - if (attacker.isType("Sliver") && !blocker.isType("Sliver")) return false; + if (attacker.isType("Sliver") && !blocker.isType("Sliver")) + return false; } return true; - }//canBlock() + }// canBlock() - //can a creature attack given the combat state + // can a creature attack given the combat state /** - *

canAttack.

- * - * @param c a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * canAttack. + *

+ * + * @param c + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean canAttack(Card c, Combat combat) { @@ -461,43 +523,55 @@ public class CombatUtil { return canAttack(c); } - //can a creature attack at the moment? + // can a creature attack at the moment? /** - *

canAttack.

- * - * @param c a {@link forge.Card} object. + *

+ * canAttack. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ public static boolean canAttack(Card c) { - if (c.isTapped() || c.isPhasedOut() || (c.hasSickness() && !c.isEnchantedBy("Instill Energy"))) return false; + if (c.isTapped() || c.isPhasedOut() || (c.hasSickness() && !c.isEnchantedBy("Instill Energy"))) + return false; return canAttackNextTurn(c); } - //can a creature attack if untapped and without summoning sickness? + // can a creature attack if untapped and without summoning sickness? /** - *

canAttackNextTurn.

- * - * @param c a {@link forge.Card} object. + *

+ * canAttackNextTurn. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a boolean. */ public static boolean canAttackNextTurn(Card c) { - if (!c.isCreature()) return false; + if (!c.isCreature()) + return false; - // CARDNAME can't attack if defending player controls an untapped creature with power ... - final int powerLimit[] = {0}; + // CARDNAME can't attack if defending player controls an untapped + // creature with power ... + final int powerLimit[] = { 0 }; int keywordPosition = 0; boolean hasKeyword = false; ArrayList attackerKeywords = c.getKeyword(); for (int i = 0; i < attackerKeywords.size(); i++) { - if (attackerKeywords.get(i).toString().startsWith("CARDNAME can't attack if defending player controls an untapped creature with power")) { + if (attackerKeywords.get(i).toString() + .startsWith("CARDNAME can't attack if defending player controls an untapped creature with power")) { hasKeyword = true; keywordPosition = i; } } - // The keyword "CARDNAME can't attack if defending player controls an untapped creature with power" ... is present + // The keyword + // "CARDNAME can't attack if defending player controls an untapped creature with power" + // ... is present if (hasKeyword) { String tmpString = c.getKeyword().get(keywordPosition).toString(); final String asSeparateWords[] = tmpString.trim().split(" "); @@ -509,65 +583,73 @@ public class CombatUtil { CardList list = AllZoneUtil.getCreaturesInPlay(c.getController().getOpponent()); list = list.filter(new CardListFilter() { public boolean addCard(Card ct) { - return ((ct.isUntapped() && ct.getNetAttack() >= powerLimit[0] && asSeparateWords[14].contains("greater")) || - (ct.isUntapped() && ct.getNetAttack() <= powerLimit[0] && asSeparateWords[14].contains("less"))); + return ((ct.isUntapped() && ct.getNetAttack() >= powerLimit[0] && asSeparateWords[14] + .contains("greater")) || (ct.isUntapped() && ct.getNetAttack() <= powerLimit[0] && asSeparateWords[14] + .contains("less"))); } }); - if (!list.isEmpty()) return false; + if (!list.isEmpty()) + return false; } } - } // hasKeyword = CARDNAME can't attack if defending player controls an untapped creature with power ... + } // hasKeyword = CARDNAME can't attack if defending player controls an + // untapped creature with power ... CardList list = c.getController().getOpponent().getCardsIn(Zone.Battlefield); CardList temp; if (c.hasKeyword("CARDNAME can't attack unless defending player controls an Island.")) { temp = list.getType("Island"); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } if (c.hasKeyword("CARDNAME can't attack unless defending player controls a Forest.")) { temp = list.getType("Forest"); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } if (c.hasKeyword("CARDNAME can't attack unless defending player controls a Swamp.")) { temp = list.getType("Swamp"); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } if (c.hasKeyword("CARDNAME can't attack unless defending player controls a Mountain.")) { temp = list.getType("Montain"); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } if (c.hasKeyword("CARDNAME can't attack unless defending player controls a snow land.")) { temp = list.filter(new CardListFilter() { public boolean addCard(Card c) { - return c.isLand() - && c.isSnow(); + return c.isLand() && c.isSnow(); } }); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } if (c.hasKeyword("CARDNAME can't attack unless defending player controls a blue permanent.")) { temp = list.getColor(Constant.Color.Blue); - if (temp.isEmpty()) return false; + if (temp.isEmpty()) + return false; } - if (c.getName().equals("Harbor Serpent")) { CardList allislands = AllZoneUtil.getCardsIn(Zone.Battlefield).getType("Island"); - if (allislands.size() < 5) return false; + if (allislands.size() < 5) + return false; } - //The creature won't untap next turn - if (c.isTapped() && !PhaseUtil.canUntap(c)) return false; + // The creature won't untap next turn + if (c.isTapped() && !PhaseUtil.canUntap(c)) + return false; if (c.hasKeyword("CARDNAME can't attack.") || c.hasKeyword("CARDNAME can't attack or block.")) return false; - if (c.hasKeyword("Defender") - && !c.hasKeyword("CARDNAME can attack as though it didn't have defender.")) { + if (c.hasKeyword("Defender") && !c.hasKeyword("CARDNAME can attack as though it didn't have defender.")) { return false; } @@ -583,14 +665,17 @@ public class CombatUtil { } return true; - }//canAttack() - + }// canAttack() /** - *

getTotalFirstStrikeBlockPower.

- * - * @param attacker a {@link forge.Card} object. - * @param player a {@link forge.Player} object. + *

+ * getTotalFirstStrikeBlockPower. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param player + * a {@link forge.Player} object. * @return a int. */ public static int getTotalFirstStrikeBlockPower(Card attacker, Player player) { @@ -607,11 +692,14 @@ public class CombatUtil { } - //This function takes Doran and Double Strike into account + // This function takes Doran and Double Strike into account /** - *

getAttack.

- * - * @param c a {@link forge.Card} object. + *

+ * getAttack. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a int. */ public static int getAttack(Card c) { @@ -623,13 +711,18 @@ public class CombatUtil { return n; } - //Returns the damage an unblocked attacker would deal + // Returns the damage an unblocked attacker would deal /** - *

damageIfUnblocked.

- * - * @param attacker a {@link forge.Card} object. - * @param attacked a {@link forge.Player} object. - * @param combat a {@link forge.Combat} object. + *

+ * damageIfUnblocked. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param attacked + * a {@link forge.Player} object. + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int damageIfUnblocked(Card attacker, Player attacked, Combat combat) { @@ -638,18 +731,24 @@ public class CombatUtil { damage += predictPowerBonusOfAttacker(attacker, null, combat); if (!attacker.hasKeyword("Infect")) { sum = attacked.predictDamage(damage, attacker, true); - if (attacker.hasKeyword("Double Strike")) sum += attacked.predictDamage(damage, attacker, true); + if (attacker.hasKeyword("Double Strike")) + sum += attacked.predictDamage(damage, attacker, true); } return sum; } - //Returns the poison an unblocked attacker would deal + // Returns the poison an unblocked attacker would deal /** - *

poisonIfUnblocked.

- * - * @param attacker a {@link forge.Card} object. - * @param attacked a {@link forge.Player} object. - * @param combat a {@link forge.Combat} object. + *

+ * poisonIfUnblocked. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param attacked + * a {@link forge.Player} object. + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int poisonIfUnblocked(Card attacker, Player attacked, Combat combat) { @@ -658,18 +757,24 @@ public class CombatUtil { damage += predictPowerBonusOfAttacker(attacker, null, null); if (attacker.hasKeyword("Infect")) { poison += attacked.predictDamage(damage, attacker, true); - if (attacker.hasKeyword("Double Strike")) poison += attacked.predictDamage(damage, attacker, true); + if (attacker.hasKeyword("Double Strike")) + poison += attacked.predictDamage(damage, attacker, true); } - if (attacker.hasKeyword("Poisonous") && damage > 0) poison += attacker.getKeywordMagnitude("Poisonous"); + if (attacker.hasKeyword("Poisonous") && damage > 0) + poison += attacker.getKeywordMagnitude("Poisonous"); return poison; } - //Returns the damage unblocked attackers would deal + // Returns the damage unblocked attackers would deal /** - *

sumDamageIfUnblocked.

- * - * @param attackers a {@link forge.CardList} object. - * @param attacked a {@link forge.Player} object. + *

+ * sumDamageIfUnblocked. + *

+ * + * @param attackers + * a {@link forge.CardList} object. + * @param attacked + * a {@link forge.Player} object. * @return a int. */ private static int sumDamageIfUnblocked(CardList attackers, Player attacked) { @@ -680,12 +785,16 @@ public class CombatUtil { return sum; } - //Returns the number of poison counters unblocked attackers would deal + // Returns the number of poison counters unblocked attackers would deal /** - *

sumPoisonIfUnblocked.

- * - * @param attackers a {@link forge.CardList} object. - * @param attacked a {@link forge.Player} object. + *

+ * sumPoisonIfUnblocked. + *

+ * + * @param attackers + * a {@link forge.CardList} object. + * @param attacked + * a {@link forge.Player} object. * @return a int. */ private static int sumPoisonIfUnblocked(CardList attackers, Player attacked) { @@ -696,11 +805,14 @@ public class CombatUtil { return sum; } - //calculates the amount of life that will remain after the attack + // calculates the amount of life that will remain after the attack /** - *

lifeThatWouldRemain.

- * - * @param combat a {@link forge.Combat} object. + *

+ * lifeThatWouldRemain. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int lifeThatWouldRemain(Combat combat) { @@ -714,8 +826,10 @@ public class CombatUtil { CardList blockers = combat.getBlockers(attacker); - if (blockers.size() == 0) unblocked.add(attacker); - else if (attacker.hasKeyword("Trample") && getAttack(attacker) > CombatUtil.totalShieldDamage(attacker, blockers)) { + if (blockers.size() == 0) + unblocked.add(attacker); + else if (attacker.hasKeyword("Trample") + && getAttack(attacker) > CombatUtil.totalShieldDamage(attacker, blockers)) { if (!attacker.hasKeyword("Infect")) damage += getAttack(attacker) - CombatUtil.totalShieldDamage(attacker, blockers); } @@ -723,16 +837,20 @@ public class CombatUtil { damage += sumDamageIfUnblocked(unblocked, AllZone.getComputerPlayer()); - if (!AllZone.getComputerPlayer().canLoseLife()) damage = 0; + if (!AllZone.getComputerPlayer().canLoseLife()) + damage = 0; return AllZone.getComputerPlayer().getLife() - damage; } - //calculates the amount of poison counters after the attack + // calculates the amount of poison counters after the attack /** - *

resultingPoison.

- * - * @param combat a {@link forge.Combat} object. + *

+ * resultingPoison. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int resultingPoison(Combat combat) { @@ -746,8 +864,10 @@ public class CombatUtil { CardList blockers = combat.getBlockers(attacker); - if (blockers.size() == 0) unblocked.add(attacker); - else if (attacker.hasKeyword("Trample") && getAttack(attacker) > CombatUtil.totalShieldDamage(attacker, blockers)) { + if (blockers.size() == 0) + unblocked.add(attacker); + else if (attacker.hasKeyword("Trample") + && getAttack(attacker) > CombatUtil.totalShieldDamage(attacker, blockers)) { if (attacker.hasKeyword("Infect")) poison += getAttack(attacker) - CombatUtil.totalShieldDamage(attacker, blockers); if (attacker.hasKeyword("Poisonous")) @@ -760,15 +880,19 @@ public class CombatUtil { return AllZone.getComputerPlayer().getPoisonCounters() + poison; } - //Checks if the life of the attacked Player/Planeswalker is in danger + // Checks if the life of the attacked Player/Planeswalker is in danger /** - *

lifeInDanger.

- * - * @param combat a {@link forge.Combat} object. + *

+ * lifeInDanger. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean lifeInDanger(Combat combat) { - // life in danger only cares about the player's life. Not about a Planeswalkers life + // life in danger only cares about the player's life. Not about a + // Planeswalkers life if (AllZone.getComputerPlayer().cantLose()) return false; @@ -779,11 +903,14 @@ public class CombatUtil { return (resultingPoison(combat) > Math.max(7, AllZone.getComputerPlayer().getPoisonCounters())); } - //Checks if the life of the attacked Player would be reduced + // Checks if the life of the attacked Player would be reduced /** - *

wouldLoseLife.

- * - * @param combat a {@link forge.Combat} object. + *

+ * wouldLoseLife. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean wouldLoseLife(Combat combat) { @@ -791,15 +918,19 @@ public class CombatUtil { return (lifeThatWouldRemain(combat) < AllZone.getComputerPlayer().getLife()); } - //Checks if the life of the attacked Player/Planeswalker is in danger + // Checks if the life of the attacked Player/Planeswalker is in danger /** - *

lifeInSeriousDanger.

- * - * @param combat a {@link forge.Combat} object. + *

+ * lifeInSeriousDanger. + *

+ * + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean lifeInSeriousDanger(Combat combat) { - // life in danger only cares about the player's life. Not about a Planeswalkers life + // life in danger only cares about the player's life. Not about a + // Planeswalkers life if (AllZone.getComputerPlayer().cantLose()) return false; @@ -809,52 +940,61 @@ public class CombatUtil { return (resultingPoison(combat) > 9); } - // This calculates the amount of damage a blockgang can deal to the attacker (first strike not supported) + // This calculates the amount of damage a blockgang can deal to the attacker + // (first strike not supported) /** - *

totalDamageOfBlockers.

- * - * @param attacker a {@link forge.Card} object. - * @param defenders a {@link forge.CardList} object. + *

+ * totalDamageOfBlockers. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defenders + * a {@link forge.CardList} object. * @return a int. */ public static int totalDamageOfBlockers(Card attacker, CardList defenders) { int damage = 0; - for (Card defender : defenders) damage += dealsDamageAsBlocker(attacker, defender); + for (Card defender : defenders) + damage += dealsDamageAsBlocker(attacker, defender); return damage; } - - // This calculates the amount of damage a blocker in a blockgang can deal to the attacker + // This calculates the amount of damage a blocker in a blockgang can deal to + // the attacker /** - *

dealsDamageAsBlocker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. + *

+ * dealsDamageAsBlocker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. * @return a int. */ public static int dealsDamageAsBlocker(Card attacker, Card defender) { - if (attacker.getName().equals("Sylvan Basilisk") - && !defender.hasKeyword("Indestructible")) + if (attacker.getName().equals("Sylvan Basilisk") && !defender.hasKeyword("Indestructible")) return 0; - + int flankingMagnitude = 0; - if (attacker.hasKeyword("Flanking") - && !defender.hasKeyword("Flanking")) { + if (attacker.hasKeyword("Flanking") && !defender.hasKeyword("Flanking")) { flankingMagnitude = attacker.getAmountOfKeyword("Flanking"); - if (flankingMagnitude >= defender.getNetDefense()) return 0; + if (flankingMagnitude >= defender.getNetDefense()) + return 0; if (flankingMagnitude >= defender.getNetDefense() - defender.getDamage() && !defender.hasKeyword("Indestructible")) return 0; - }//flanking - if (attacker.hasKeyword("Indestructible") - && !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) return 0; - + }// flanking + if (attacker.hasKeyword("Indestructible") && !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) + return 0; + int defenderDamage = defender.getNetAttack() + predictPowerBonusOfBlocker(attacker, defender); if (AllZoneUtil.isCardInPlay("Doran, the Siege Tower")) { defenderDamage = defender.getNetDefense() + predictToughnessBonusOfBlocker(attacker, defender); @@ -869,38 +1009,49 @@ public class CombatUtil { return defenderDamage; } - // This calculates the amount of damage a blocker in a blockgang can take from the attacker (for trampling attackers) + // This calculates the amount of damage a blocker in a blockgang can take + // from the attacker (for trampling attackers) /** - *

totalShieldDamage.

- * - * @param attacker a {@link forge.Card} object. - * @param defenders a {@link forge.CardList} object. + *

+ * totalShieldDamage. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defenders + * a {@link forge.CardList} object. * @return a int. */ public static int totalShieldDamage(Card attacker, CardList defenders) { int defenderDefense = 0; - for (Card defender : defenders) defenderDefense += shieldDamage(attacker, defender); + for (Card defender : defenders) + defenderDefense += shieldDamage(attacker, defender); return defenderDefense; } - // This calculates the amount of damage a blocker in a blockgang can take from the attacker (for trampling attackers) + // This calculates the amount of damage a blocker in a blockgang can take + // from the attacker (for trampling attackers) /** - *

shieldDamage.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. + *

+ * shieldDamage. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. * @return a int. */ public static int shieldDamage(Card attacker, Card defender) { - if (!canDestroyBlocker(defender, attacker, null, false)) return 100; + if (!canDestroyBlocker(defender, attacker, null, false)) + return 100; int flankingMagnitude = 0; - if (attacker.hasKeyword("Flanking") - && !defender.hasKeyword("Flanking")) { + if (attacker.hasKeyword("Flanking") && !defender.hasKeyword("Flanking")) { flankingMagnitude = attacker.getAmountOfKeyword("Flanking"); @@ -910,20 +1061,23 @@ public class CombatUtil { && !defender.hasKeyword("Indestructible")) return 0; - }//flanking + }// flanking int defBushidoMagnitude = defender.getKeywordMagnitude("Bushido"); int defenderDefense = defender.getNetDefense() - flankingMagnitude + defBushidoMagnitude; return defenderDefense; - }//shieldDamage + }// shieldDamage - //For AI safety measures like Regeneration + // For AI safety measures like Regeneration /** - *

combatantWouldBeDestroyed.

- * - * @param combatant a {@link forge.Card} object. + *

+ * combatantWouldBeDestroyed. + *

+ * + * @param combatant + * a {@link forge.Card} object. * @return a boolean. */ public static boolean combatantWouldBeDestroyed(Card combatant) { @@ -935,11 +1089,14 @@ public class CombatUtil { return false; } - //For AI safety measures like Regeneration + // For AI safety measures like Regeneration /** - *

attackerWouldBeDestroyed.

- * - * @param attacker a {@link forge.Card} object. + *

+ * attackerWouldBeDestroyed. + *

+ * + * @param attacker + * a {@link forge.Card} object. * @return a boolean. */ public static boolean attackerWouldBeDestroyed(Card attacker) { @@ -954,32 +1111,42 @@ public class CombatUtil { return totalDamageOfBlockers(attacker, blockers) >= attacker.getKillDamage(); } - //Will this trigger trigger? + // Will this trigger trigger? /** - *

combatTriggerWillTrigger.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. - * @param trigger a {@link forge.card.trigger.Trigger} object. - * @param combat a {@link forge.Combat} object. + *

+ * combatTriggerWillTrigger. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. + * @param trigger + * a {@link forge.card.trigger.Trigger} object. + * @param combat + * a {@link forge.Combat} object. * @return a boolean. */ public static boolean combatTriggerWillTrigger(Card attacker, Card defender, Trigger trigger, Combat combat) { HashMap trigParams = trigger.getMapParams(); boolean willTrigger = false; Card source = trigger.getHostCard(); - if (combat == null) combat = AllZone.getCombat(); + if (combat == null) + combat = AllZone.getCombat(); - if (!trigger.zonesCheck()) return false; - if (!trigger.requirementsCheck()) return false; + if (!trigger.zonesCheck()) + return false; + if (!trigger.requirementsCheck()) + return false; if (trigParams.get("Mode").equals("Attacks")) { willTrigger = true; - if (attacker.isAttacking()) return false; //The trigger should have triggered already + if (attacker.isAttacking()) + return false; // The trigger should have triggered already if (trigParams.containsKey("ValidCard")) { if (!trigger.matchesValid(attacker, trigParams.get("ValidCard").split(","), source) - && !(combat.isAttacking(source) && - trigger.matchesValid(source, trigParams.get("ValidCard").split(","), source))) + && !(combat.isAttacking(source) && trigger.matchesValid(source, trigParams.get("ValidCard") + .split(","), source))) return false; } } @@ -992,7 +1159,8 @@ public class CombatUtil { return false; } - if (defender == null) return willTrigger; + if (defender == null) + return willTrigger; if (trigParams.get("Mode").equals("Blocks")) { willTrigger = true; @@ -1015,26 +1183,31 @@ public class CombatUtil { return willTrigger; } - //Predict the Power bonus of the blocker if blocking the attacker (Flanking, Bushido and other triggered abilities) + // Predict the Power bonus of the blocker if blocking the attacker + // (Flanking, Bushido and other triggered abilities) /** - *

predictPowerBonusOfBlocker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. + *

+ * predictPowerBonusOfBlocker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. * @return a int. */ public static int predictPowerBonusOfBlocker(Card attacker, Card defender) { int power = 0; - if (attacker.hasKeyword("Flanking") - && !defender.hasKeyword("Flanking")) + if (attacker.hasKeyword("Flanking") && !defender.hasKeyword("Flanking")) power -= attacker.getAmountOfKeyword("Flanking"); - //if the attacker has first strike and wither the blocker will deal less damage than expected + // if the attacker has first strike and wither the blocker will deal + // less damage than expected if ((attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike")) && (attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect")) - && !(defender.hasKeyword("First Strike") || defender.hasKeyword("Double Strike") - || defender.hasKeyword("CARDNAME can't have counters placed on it."))) + && !(defender.hasKeyword("First Strike") || defender.hasKeyword("Double Strike") || defender + .hasKeyword("CARDNAME can't have counters placed on it."))) power -= attacker.getNetCombatDamage(); power += defender.getKeywordMagnitude("Bushido"); @@ -1055,13 +1228,16 @@ public class CombatUtil { if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump")) continue; if (abilityParams.containsKey("ValidTgts") || abilityParams.containsKey("Tgt")) - continue; //targeted pumping not supported + continue; // targeted pumping not supported ArrayList list = AbilityFactory.getDefinedCards(source, abilityParams.get("Defined"), null); if (abilityParams.containsKey("Defined") && abilityParams.get("Defined").equals("TriggeredBlocker")) list.add(defender); - if (list.isEmpty()) continue; - if (!list.contains(defender)) continue; - if (!abilityParams.containsKey("NumAtt")) continue; + if (list.isEmpty()) + continue; + if (!list.contains(defender)) + continue; + if (!abilityParams.containsKey("NumAtt")) + continue; String att = abilityParams.get("NumAtt"); if (att.startsWith("+")) @@ -1069,26 +1245,30 @@ public class CombatUtil { try { power += Integer.parseInt(att); } catch (NumberFormatException nfe) { - //can't parse the number (X for example) + // can't parse the number (X for example) power += 0; } } return power; } - //Predict the Toughness bonus of the blocker if blocking the attacker (Flanking, Bushido and other triggered abilities) + // Predict the Toughness bonus of the blocker if blocking the attacker + // (Flanking, Bushido and other triggered abilities) /** - *

predictToughnessBonusOfBlocker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. + *

+ * predictToughnessBonusOfBlocker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. * @return a int. */ public static int predictToughnessBonusOfBlocker(Card attacker, Card defender) { int toughness = 0; - if (attacker.hasKeyword("Flanking") - && !defender.hasKeyword("Flanking")) + if (attacker.hasKeyword("Flanking") && !defender.hasKeyword("Flanking")) toughness -= attacker.getAmountOfKeyword("Flanking"); toughness += defender.getKeywordMagnitude("Bushido"); @@ -1109,13 +1289,16 @@ public class CombatUtil { if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump")) continue; if (abilityParams.containsKey("ValidTgts") || abilityParams.containsKey("Tgt")) - continue; //targeted pumping not supported + continue; // targeted pumping not supported ArrayList list = AbilityFactory.getDefinedCards(source, abilityParams.get("Defined"), null); if (abilityParams.containsKey("Defined") && abilityParams.get("Defined").equals("TriggeredBlocker")) list.add(defender); - if (list.isEmpty()) continue; - if (!list.contains(defender)) continue; - if (!abilityParams.containsKey("NumDef")) continue; + if (list.isEmpty()) + continue; + if (!list.contains(defender)) + continue; + if (!abilityParams.containsKey("NumDef")) + continue; String def = abilityParams.get("NumDef"); if (def.startsWith("+")) @@ -1123,40 +1306,46 @@ public class CombatUtil { try { toughness += Integer.parseInt(def); } catch (NumberFormatException nfe) { - //can't parse the number (X for example) + // can't parse the number (X for example) toughness += 0; } } return toughness; } - //Predict the Power bonus of the blocker if blocking the attacker (Flanking, Bushido and other triggered abilities) + // Predict the Power bonus of the blocker if blocking the attacker + // (Flanking, Bushido and other triggered abilities) /** - *

predictPowerBonusOfAttacker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * predictPowerBonusOfAttacker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int predictPowerBonusOfAttacker(Card attacker, Card defender, Combat combat) { int power = 0; power += attacker.getKeywordMagnitude("Bushido"); - - + ArrayList theTriggers = new ArrayList(attacker.getTriggers()); - //if the defender has first strike and wither the attacker will deal less damage than expected + // if the defender has first strike and wither the attacker will deal + // less damage than expected if (null != defender) { if ((defender.hasKeyword("First Strike") || defender.hasKeyword("Double Strike")) && (defender.hasKeyword("Wither") || defender.hasKeyword("Infect")) - && !(attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike") - || attacker.hasKeyword("CARDNAME can't have counters placed on it."))) { + && !(attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike") || attacker + .hasKeyword("CARDNAME can't have counters placed on it."))) { power -= defender.getNetCombatDamage(); } theTriggers.addAll(defender.getTriggers()); } - + for (Trigger trigger : theTriggers) { HashMap trigParams = trigger.getMapParams(); Card source = trigger.getHostCard(); @@ -1167,24 +1356,29 @@ public class CombatUtil { AbilityFactory AF = new AbilityFactory(); HashMap abilityParams = AF.getMapParams(ability, source); if (abilityParams.containsKey("ValidTgts") || abilityParams.containsKey("Tgt")) - continue; //targeted pumping not supported - if (abilityParams.containsKey("AB") && !abilityParams.get("AB").equals("Pump") && !abilityParams.get("AB").equals("PumpAll")) + continue; // targeted pumping not supported + if (abilityParams.containsKey("AB") && !abilityParams.get("AB").equals("Pump") + && !abilityParams.get("AB").equals("PumpAll")) continue; - if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump") && !abilityParams.get("DB").equals("PumpAll")) + if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump") + && !abilityParams.get("DB").equals("PumpAll")) continue; ArrayList list = new ArrayList(); - if (!abilityParams.containsKey("ValidCards")) //no pumpAll + if (!abilityParams.containsKey("ValidCards")) // no pumpAll list = AbilityFactory.getDefinedCards(source, abilityParams.get("Defined"), null); if (abilityParams.containsKey("Defined") && abilityParams.get("Defined").equals("TriggeredAttacker")) list.add(attacker); if (abilityParams.containsKey("ValidCards")) if (attacker.isValid(abilityParams.get("ValidCards").split(","), source.getController(), source) - || attacker.isValid(abilityParams.get("ValidCards").replace("attacking+", "").split(",") - , source.getController(), source)) + || attacker.isValid(abilityParams.get("ValidCards").replace("attacking+", "").split(","), + source.getController(), source)) list.add(attacker); - if (list.isEmpty()) continue; - if (!list.contains(attacker)) continue; - if (!abilityParams.containsKey("NumAtt")) continue; + if (list.isEmpty()) + continue; + if (!list.contains(attacker)) + continue; + if (!abilityParams.containsKey("NumAtt")) + continue; String att = abilityParams.get("NumAtt"); if (att.startsWith("+")) @@ -1192,20 +1386,26 @@ public class CombatUtil { try { power += Integer.parseInt(att); } catch (NumberFormatException nfe) { - //can't parse the number (X for example) + // can't parse the number (X for example) power += 0; } } return power; } - //Predict the Toughness bonus of the blocker if blocking the attacker (Flanking, Bushido and other triggered abilities) + // Predict the Toughness bonus of the blocker if blocking the attacker + // (Flanking, Bushido and other triggered abilities) /** - *

predictToughnessBonusOfAttacker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. + *

+ * predictToughnessBonusOfAttacker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. * @return a int. */ public static int predictToughnessBonusOfAttacker(Card attacker, Card defender, Combat combat) { @@ -1216,8 +1416,7 @@ public class CombatUtil { toughness += attacker.getKeywordMagnitude("Bushido"); theTriggers.addAll(defender.getTriggers()); } - - + for (Trigger trigger : theTriggers) { HashMap trigParams = trigger.getMapParams(); Card source = trigger.getHostCard(); @@ -1228,8 +1427,8 @@ public class CombatUtil { AbilityFactory AF = new AbilityFactory(); HashMap abilityParams = AF.getMapParams(ability, source); if (abilityParams.containsKey("ValidTgts") || abilityParams.containsKey("Tgt")) - continue; //targeted pumping not supported - + continue; // targeted pumping not supported + // DealDamage triggers if ((abilityParams.containsKey("AB") && abilityParams.get("AB").equals("DealDamage")) || (abilityParams.containsKey("DB") && abilityParams.get("DB").equals("DealDamage"))) { @@ -1240,31 +1439,36 @@ public class CombatUtil { try { damage = Integer.parseInt(abilityParams.get("NumDmg")); } catch (NumberFormatException nfe) { - //can't parse the number (X for example) + // can't parse the number (X for example) continue; } toughness -= attacker.predictDamage(damage, 0, source, false); continue; } - + // Pump triggers - if (abilityParams.containsKey("AB") && !abilityParams.get("AB").equals("Pump") && !abilityParams.get("AB").equals("PumpAll")) + if (abilityParams.containsKey("AB") && !abilityParams.get("AB").equals("Pump") + && !abilityParams.get("AB").equals("PumpAll")) continue; - if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump") && !abilityParams.get("DB").equals("PumpAll")) + if (abilityParams.containsKey("DB") && !abilityParams.get("DB").equals("Pump") + && !abilityParams.get("DB").equals("PumpAll")) continue; ArrayList list = new ArrayList(); - if (!abilityParams.containsKey("ValidCards")) //no pumpAll + if (!abilityParams.containsKey("ValidCards")) // no pumpAll list = AbilityFactory.getDefinedCards(source, abilityParams.get("Defined"), null); if (abilityParams.containsKey("Defined") && abilityParams.get("Defined").equals("TriggeredAttacker")) list.add(attacker); if (abilityParams.containsKey("ValidCards")) if (attacker.isValid(abilityParams.get("ValidCards").split(","), source.getController(), source) - || attacker.isValid(abilityParams.get("ValidCards").replace("attacking+", "").split(",") - , source.getController(), source)) + || attacker.isValid(abilityParams.get("ValidCards").replace("attacking+", "").split(","), + source.getController(), source)) list.add(attacker); - if (list.isEmpty()) continue; - if (!list.contains(attacker)) continue; - if (!abilityParams.containsKey("NumDef")) continue; + if (list.isEmpty()) + continue; + if (!list.contains(attacker)) + continue; + if (!abilityParams.containsKey("NumDef")) + continue; String def = abilityParams.get("NumDef"); if (def.startsWith("+")) @@ -1272,39 +1476,49 @@ public class CombatUtil { try { toughness += Integer.parseInt(def); } catch (NumberFormatException nfe) { - //can't parse the number (X for example) + // can't parse the number (X for example) toughness += 0; } } return toughness; } - //can the blocker destroy the attacker? + // can the blocker destroy the attacker? /** - *

canDestroyAttacker.

- * - * @param attacker a {@link forge.Card} object. - * @param defender a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. - * @param withoutAbilities a boolean. + *

+ * canDestroyAttacker. + *

+ * + * @param attacker + * a {@link forge.Card} object. + * @param defender + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. + * @param withoutAbilities + * a boolean. * @return a boolean. */ public static boolean canDestroyAttacker(Card attacker, Card defender, Combat combat, boolean withoutAbilities) { - if (attacker.getName().equals("Sylvan Basilisk") && !defender.hasKeyword("Indestructible")) return false; + if (attacker.getName().equals("Sylvan Basilisk") && !defender.hasKeyword("Indestructible")) + return false; int flankingMagnitude = 0; if (attacker.hasKeyword("Flanking") && !defender.hasKeyword("Flanking")) { flankingMagnitude = attacker.getAmountOfKeyword("Flanking"); - if (flankingMagnitude >= defender.getNetDefense()) return false; - if (flankingMagnitude >= defender.getNetDefense() - defender.getDamage() && !defender.hasKeyword("Indestructible")) + if (flankingMagnitude >= defender.getNetDefense()) return false; - }//flanking + if (flankingMagnitude >= defender.getNetDefense() - defender.getDamage() + && !defender.hasKeyword("Indestructible")) + return false; + }// flanking - if ((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) && - !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) return false; + if ((attacker.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(attacker) && !withoutAbilities)) + && !(defender.hasKeyword("Wither") || defender.hasKeyword("Infect"))) + return false; int defenderDamage = defender.getNetAttack() + predictPowerBonusOfBlocker(attacker, defender); int attackerDamage = attacker.getNetAttack() + predictPowerBonusOfAttacker(attacker, defender, combat); @@ -1328,61 +1542,78 @@ public class CombatUtil { int attackerLife = attacker.getKillDamage() + predictToughnessBonusOfAttacker(attacker, defender, combat); if (defender.hasKeyword("Double Strike")) { - if (defender.hasKeyword("Deathtouch") && defenderDamage > 0) return true; - if (defenderDamage >= attackerLife) return true; + if (defender.hasKeyword("Deathtouch") && defenderDamage > 0) + return true; + if (defenderDamage >= attackerLife) + return true; - //Attacker may kill the blocker before he can deal normal (secondary) damage + // Attacker may kill the blocker before he can deal normal + // (secondary) damage if ((attacker.hasKeyword("Double Strike") || attacker.hasKeyword("First Strike")) && !defender.hasKeyword("Indestructible")) { - if (attackerDamage >= defenderLife) return false; - if (attackerDamage > 0 && attacker.hasKeyword("Deathtouch")) return false; + if (attackerDamage >= defenderLife) + return false; + if (attackerDamage > 0 && attacker.hasKeyword("Deathtouch")) + return false; } - if (attackerLife <= 2 * defenderDamage) return true; - }//defender double strike + if (attackerLife <= 2 * defenderDamage) + return true; + }// defender double strike - else //no double strike for defender + else // no double strike for defender { - //Attacker may kill the blocker before he can deal any damage + // Attacker may kill the blocker before he can deal any damage if (attacker.hasKeyword("Double Strike") || attacker.hasKeyword("First Strike") && !defender.hasKeyword("Indestructible") && !defender.hasKeyword("First Strike")) { - if (attackerDamage >= defenderLife) return false; - if (attackerDamage > 0 && attacker.hasKeyword("Deathtouch")) return false; + if (attackerDamage >= defenderLife) + return false; + if (attackerDamage > 0 && attacker.hasKeyword("Deathtouch")) + return false; } - if (defender.hasKeyword("Deathtouch") && defenderDamage > 0) return true; + if (defender.hasKeyword("Deathtouch") && defenderDamage > 0) + return true; return defenderDamage >= attackerLife; - }//defender no double strike - return false; //should never arrive here - } //canDestroyAttacker + }// defender no double strike + return false; // should never arrive here + } // canDestroyAttacker - - //For AI safety measures like Regeneration + // For AI safety measures like Regeneration /** - *

blockerWouldBeDestroyed.

- * - * @param blocker a {@link forge.Card} object. + *

+ * blockerWouldBeDestroyed. + *

+ * + * @param blocker + * a {@link forge.Card} object. * @return a boolean. */ public static boolean blockerWouldBeDestroyed(Card blocker) { Card attacker = AllZone.getCombat().getAttackerBlockedBy(blocker); - if (canDestroyBlocker(blocker, attacker, AllZone.getCombat(), true) && - !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) + if (canDestroyBlocker(blocker, attacker, AllZone.getCombat(), true) + && !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) return true; return false; } - //can the attacker destroy this blocker? + // can the attacker destroy this blocker? /** - *

canDestroyBlocker.

- * - * @param defender a {@link forge.Card} object. - * @param attacker a {@link forge.Card} object. - * @param combat a {@link forge.Combat} object. - * @param withoutAbilities a boolean. + *

+ * canDestroyBlocker. + *

+ * + * @param defender + * a {@link forge.Card} object. + * @param attacker + * a {@link forge.Card} object. + * @param combat + * a {@link forge.Combat} object. + * @param withoutAbilities + * a boolean. * @return a boolean. */ public static boolean canDestroyBlocker(Card defender, Card attacker, Combat combat, boolean withoutAbilities) { @@ -1392,14 +1623,18 @@ public class CombatUtil { flankingMagnitude = attacker.getAmountOfKeyword("Flanking"); - if (flankingMagnitude >= defender.getNetDefense()) return true; - if ((flankingMagnitude >= defender.getKillDamage()) && !defender.hasKeyword("Indestructible")) return true; - }//flanking + if (flankingMagnitude >= defender.getNetDefense()) + return true; + if ((flankingMagnitude >= defender.getKillDamage()) && !defender.hasKeyword("Indestructible")) + return true; + }// flanking - if ((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) && - !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) return false; + if ((defender.hasKeyword("Indestructible") || (ComputerUtil.canRegenerate(defender) && !withoutAbilities)) + && !(attacker.hasKeyword("Wither") || attacker.hasKeyword("Infect"))) + return false; - if (attacker.getName().equals("Sylvan Basilisk") && !defender.hasKeyword("Indestructible")) return true; + if (attacker.getName().equals("Sylvan Basilisk") && !defender.hasKeyword("Indestructible")) + return true; int defenderDamage = defender.getNetAttack() + predictPowerBonusOfBlocker(attacker, defender); int attackerDamage = attacker.getNetAttack() + predictPowerBonusOfAttacker(attacker, defender, combat); @@ -1423,38 +1658,49 @@ public class CombatUtil { int attackerLife = attacker.getKillDamage() + predictToughnessBonusOfAttacker(attacker, defender, combat); if (attacker.hasKeyword("Double Strike")) { - if (attacker.hasKeyword("Deathtouch") && attackerDamage > 0) return true; - if (attackerDamage >= defenderLife) return true; + if (attacker.hasKeyword("Deathtouch") && attackerDamage > 0) + return true; + if (attackerDamage >= defenderLife) + return true; - //Attacker may kill the blocker before he can deal normal (secondary) damage + // Attacker may kill the blocker before he can deal normal + // (secondary) damage if ((defender.hasKeyword("Double Strike") || defender.hasKeyword("First Strike")) && !attacker.hasKeyword("Indestructible")) { - if (defenderDamage >= attackerLife) return false; - if (defenderDamage > 0 && defender.hasKeyword("Deathtouch")) return false; + if (defenderDamage >= attackerLife) + return false; + if (defenderDamage > 0 && defender.hasKeyword("Deathtouch")) + return false; } - if (defenderLife <= 2 * attackerDamage) return true; - }//attacker double strike + if (defenderLife <= 2 * attackerDamage) + return true; + }// attacker double strike - else //no double strike for attacker + else // no double strike for attacker { - //Defender may kill the attacker before he can deal any damage + // Defender may kill the attacker before he can deal any damage if (defender.hasKeyword("Double Strike") || defender.hasKeyword("First Strike") && !attacker.hasKeyword("Indestructible") && !attacker.hasKeyword("First Strike")) { - if (defenderDamage >= attackerLife) return false; - if (defenderDamage > 0 && defender.hasKeyword("Deathtouch")) return false; + if (defenderDamage >= attackerLife) + return false; + if (defenderDamage > 0 && defender.hasKeyword("Deathtouch")) + return false; } - if (attacker.hasKeyword("Deathtouch") && attackerDamage > 0) return true; + if (attacker.hasKeyword("Deathtouch") && attackerDamage > 0) + return true; return attackerDamage >= defenderLife; - }//attacker no double strike - return false; //should never arrive here - }//canDestroyBlocker + }// attacker no double strike + return false; // should never arrive here + }// canDestroyBlocker /** - *

removeAllDamage.

+ *

+ * removeAllDamage. + *

*/ public static void removeAllDamage() { CardList cl = AllZoneUtil.getCardsIn(Zone.Battlefield); @@ -1464,7 +1710,9 @@ public class CombatUtil { } /** - *

showCombat.

+ *

+ * showCombat. + *

*/ public static void showCombat() { AllZone.getDisplay().showCombat(""); @@ -1492,27 +1740,30 @@ public class CombatUtil { CardList list = attackers[def]; for (Card c : list) { - //loop through attackers + // loop through attackers display.append("-> "); display.append(combatantToString(c)).append("\n"); defend = AllZone.getCombat().getBlockers(c).toArray(); - //loop through blockers + // loop through blockers for (int inner = 0; inner < defend.length; inner++) { display.append(" [ "); display.append(combatantToString(defend[inner])).append("\n"); } - }//loop through attackers + }// loop through attackers } AllZone.getDisplay().showCombat(display.toString().trim()); - }//showBlockers() + }// showBlockers() /** - *

combatantToString.

- * - * @param c a {@link forge.Card} object. + *

+ * combatantToString. + *

+ * + * @param c + * a {@link forge.Card} object. * @return a {@link java.lang.String} object. */ private static String combatantToString(Card c) { @@ -1528,8 +1779,10 @@ public class CombatUtil { } /** - *

isDoranInPlay.

- * + *

+ * isDoranInPlay. + *

+ * * @return a boolean. */ public static boolean isDoranInPlay() { @@ -1537,10 +1790,14 @@ public class CombatUtil { } /** - *

checkPropagandaEffects.

- * - * @param c a {@link forge.Card} object. - * @param bLast a boolean. + *

+ * checkPropagandaEffects. + *

+ * + * @param c + * a {@link forge.Card} object. + * @param bLast + * a boolean. */ public static void checkPropagandaEffects(Card c, final boolean bLast) { String cost = CardFactoryUtil.getPropagandaCost(c); @@ -1557,7 +1814,8 @@ public class CombatUtil { String phase = AllZone.getPhase().getPhase(); - if (phase.equals(Constant.Phase.Combat_Declare_Attackers) || phase.equals(Constant.Phase.Combat_Declare_Attackers_InstantAbility)) { + if (phase.equals(Constant.Phase.Combat_Declare_Attackers) + || phase.equals(Constant.Phase.Combat_Declare_Attackers_InstantAbility)) { if (!cost.equals("0")) { final Ability ability = new Ability(c, cost) { @Override @@ -1592,15 +1850,17 @@ public class CombatUtil { }; if (c.getController().isHuman()) { - AllZone.getInputControl().setInput(new Input_PayManaCost_Ability(c + " - Pay to Attack\r\n", - ability.getManaCost(), paidCommand, unpaidCommand)); - } else { //computer + AllZone.getInputControl().setInput( + new Input_PayManaCost_Ability(c + " - Pay to Attack\r\n", ability.getManaCost(), + paidCommand, unpaidCommand)); + } else { // computer if (ComputerUtil.canPayCost(ability)) { ComputerUtil.playNoStack(ability); if (!crd.hasKeyword("Vigilance")) crd.tap(); } else { - // TODO: remove the below line after Propaganda occurs during Declare_Attackers + // TODO: remove the below line after Propaganda occurs + // during Declare_Attackers AllZone.getCombat().removeFromCombat(crd); } } @@ -1609,13 +1869,20 @@ public class CombatUtil { } /** - *

checkDeclareAttackers.

- * - * @param c a {@link forge.Card} object. + *

+ * checkDeclareAttackers. + *

+ * + * @param c + * a {@link forge.Card} object. */ - public static void checkDeclareAttackers(Card c) //this method checks triggered effects of attacking creatures, right before defending player declares blockers + public static void checkDeclareAttackers(Card c) // this method checks + // triggered effects of + // attacking creatures, + // right before defending + // player declares blockers { - //Run triggers + // Run triggers HashMap runParams = new HashMap(); runParams.put("Attacker", c); CardList otherAttackers = new CardList(AllZone.getCombat().getAttackers()); @@ -1623,7 +1890,7 @@ public class CombatUtil { runParams.put("OtherAttackers", otherAttackers); AllZone.getTriggerHandler().runTrigger("Attacks", runParams); - //Annihilator: + // Annihilator: if (!c.getCreatureAttackedThisCombat()) { ArrayList kws = c.getKeyword(); Pattern p = Pattern.compile("Annihilator [0-9]+"); @@ -1651,28 +1918,30 @@ public class CombatUtil { ability.setStackDescription(sb.toString()); AllZone.getStack().add(ability); - } //find - } //for - }//creatureAttacked - //Annihilator + } // find + } // for + }// creatureAttacked + // Annihilator - //Mijae Djinn + // Mijae Djinn if (c.getName().equals("Mijae Djinn")) { if (!GameActionUtil.flipACoin(c.getController(), c)) { AllZone.getCombat().removeFromCombat(c); c.tap(); } - }//Mijae Djinn + }// Mijae Djinn if (c.getName().equals("Zur the Enchanter") && !c.getCreatureAttackedThisCombat()) { - //hack, to make sure this doesn't break grabbing an oblivion ring: + // hack, to make sure this doesn't break grabbing an oblivion ring: c.setCreatureAttackedThisCombat(true); CardList enchantments = c.getController().getCardsIn(Zone.Library); enchantments = enchantments.filter(new CardListFilter() { public boolean addCard(Card c) { - if (c.isEnchantment() && c.getCMC() <= 3) return true; - else return false; + if (c.isEnchantment() && c.getCMC() <= 3) + return true; + else + return false; } }); @@ -1688,13 +1957,13 @@ public class CombatUtil { Object obj = null; if (crd.hasKeyword("Enchant creature")) { CardList creats = AllZoneUtil.getCreaturesInPlay(); - obj = GuiUtils.getChoiceOptional("Pick a creature to attach " - + crd.getName() + " to", creats.toArray()); - } else if (crd.hasKeyword("Enchant land") - || crd.hasKeyword("Enchant land you control")) { + obj = GuiUtils.getChoiceOptional("Pick a creature to attach " + crd.getName() + " to", + creats.toArray()); + } else if (crd.hasKeyword("Enchant land") || crd.hasKeyword("Enchant land you control")) { CardList lands = AllZoneUtil.getLandsInPlay(); - if (lands.size() > 0) obj = GuiUtils.getChoiceOptional( - "Pick a land to attach " + crd.getName() + " to", lands.toArray()); + if (lands.size() > 0) + obj = GuiUtils.getChoiceOptional("Pick a land to attach " + crd.getName() + " to", + lands.toArray()); } if (obj != null) { Card target = (Card) obj; @@ -1704,7 +1973,8 @@ public class CombatUtil { } } c.getController().shuffle(); - //we have to have cards like glorious anthem take effect immediately: + // we have to have cards like glorious anthem take + // effect immediately: for (String effect : AllZone.getStaticEffects().getStateBasedMap().keySet()) { Command com = GameActionUtil.commands.get(effect); com.execute(); @@ -1723,8 +1993,8 @@ public class CombatUtil { c.getController().shuffle(); } } - } //enchantments.size > 0 - }//Zur the enchanter + } // enchantments.size > 0 + }// Zur the enchanter else if (c.getName().equals("Spectral Bears")) { Player opp = c.getController().getOpponent(); @@ -1759,15 +2029,15 @@ public class CombatUtil { charger.removeIntrinsicKeyword("Trample"); } } - };//Command + };// Command if (AllZoneUtil.isCardInPlay(charger)) { charger.addIntrinsicKeyword("Trample"); AllZone.getEndOfTurn().addUntil(untilEOT); } - }//resolve - };//ability + }// resolve + };// ability StringBuilder sb2 = new StringBuilder(); sb2.append(c.getName()).append(" - gains trample until end of turn if its power is 10 or greater."); @@ -1775,7 +2045,7 @@ public class CombatUtil { AllZone.getStack().add(ability2); - }//Witch-Maw Nephilim + }// Witch-Maw Nephilim else if (c.getName().equals("Preeminent Captain") && !c.getCreatureAttackedThisCombat()) { System.out.println("Preeminent Captain Attacks"); @@ -1807,11 +2077,10 @@ public class CombatUtil { } } - } //if (creatures.size() > 0) - }//Preeminent Captain + } // if (creatures.size() > 0) + }// Preeminent Captain - else if (c.getName().equals("Sapling of Colfenor") - && !c.getCreatureAttackedThisCombat()) { + else if (c.getName().equals("Sapling of Colfenor") && !c.getCreatureAttackedThisCombat()) { Player player = c.getController(); PlayerZone lib = player.getZone(Constant.Zone.Library); @@ -1828,28 +2097,34 @@ public class CombatUtil { AllZone.getGameAction().moveToHand(top); } } - }//Sapling of Colfenor + }// Sapling of Colfenor c.setCreatureAttackedThisCombat(true); - }//checkDeclareAttackers + }// checkDeclareAttackers /** - *

checkUnblockedAttackers.

- * - * @param c a {@link forge.Card} object. + *

+ * checkUnblockedAttackers. + *

+ * + * @param c + * a {@link forge.Card} object. */ public static void checkUnblockedAttackers(Card c) { - //Run triggers + // Run triggers HashMap runParams = new HashMap(); runParams.put("Card", c); AllZone.getTriggerHandler().runTrigger("AttackerUnblocked", runParams); } /** - *

checkDeclareBlockers.

- * - * @param cl a {@link forge.CardList} object. + *

+ * checkDeclareBlockers. + *

+ * + * @param cl + * a {@link forge.CardList} object. */ public static void checkDeclareBlockers(CardList cl) { for (Card c : cl) { @@ -1860,20 +2135,24 @@ public class CombatUtil { } c.setCreatureBlockedThisCombat(true); - }//for + }// for - }//checkDeclareBlockers + }// checkDeclareBlockers /** - *

checkBlockedAttackers.

- * - * @param a a {@link forge.Card} object. - * @param b a {@link forge.Card} object. + *

+ * checkBlockedAttackers. + *

+ * + * @param a + * a {@link forge.Card} object. + * @param b + * a {@link forge.Card} object. */ public static void checkBlockedAttackers(final Card a, Card b) { - //System.out.println(a.getName() + " got blocked by " + b.getName()); + // System.out.println(a.getName() + " got blocked by " + b.getName()); - //Run triggers + // Run triggers HashMap runParams = new HashMap(); runParams.put("Attacker", a); runParams.put("Blocker", b); @@ -1884,11 +2163,11 @@ public class CombatUtil { runParams.put("NumBlockers", blockers); AllZone.getTriggerHandler().runTrigger("AttackerBlocked", runParams); - //Bushido + // Bushido for (Ability ab : CardFactoryUtil.getBushidoEffects(a)) AllZone.getStack().add(ab); - //Rampage + // Rampage ArrayList keywords = a.getKeyword(); Pattern p = Pattern.compile("Rampage [0-9]+"); Matcher m; @@ -1901,8 +2180,8 @@ public class CombatUtil { if (numBlockers > 1) { executeRampageAbility(a, magnitude, numBlockers); } - } //find - }//end Rampage + } // find + }// end Rampage } if (a.hasKeyword("Flanking") && !b.hasKeyword("Flanking")) { @@ -1912,7 +2191,8 @@ public class CombatUtil { for (int i = 0; i < list.size(); i++) { kw = list.get(i); - if (kw.equals("Flanking")) flankingMagnitude++; + if (kw.equals("Flanking")) + flankingMagnitude++; } final int mag = flankingMagnitude; final Card blocker = b; @@ -1930,8 +2210,7 @@ public class CombatUtil { blocker.addTempDefenseBoost(mag); } } - };//Command - + };// Command if (AllZoneUtil.isCardInPlay(blocker)) { blocker.addTempAttackBoost(-mag); @@ -1940,9 +2219,9 @@ public class CombatUtil { AllZone.getEndOfTurn().addUntil(untilEOT); System.out.println("Flanking!"); } - }//resolve + }// resolve - };//ability + };// ability StringBuilder sb2 = new StringBuilder(); sb2.append(b.getName()).append(" - gets -").append(mag).append("/-").append(mag).append(" until EOT."); @@ -1951,8 +2230,7 @@ public class CombatUtil { AllZone.getStack().add(ability2); Log.debug("Adding Flanking!"); - }//flanking - + }// flanking if (a.getName().equals("Robber Fly") && !a.getCreatureGotBlockedThisCombat()) { Player opp = b.getController(); @@ -1969,10 +2247,14 @@ public class CombatUtil { } /** - *

executeExaltedAbility.

- * - * @param c a {@link forge.Card} object. - * @param magnitude a int. + *

+ * executeExaltedAbility. + *

+ * + * @param c + * a {@link forge.Card} object. + * @param magnitude + * a int. */ public static void executeExaltedAbility(Card c, int magnitude) { final Card crd = c; @@ -1991,7 +2273,7 @@ public class CombatUtil { crd.addTempDefenseBoost(-1); } } - };//Command + };// Command if (AllZoneUtil.isCardInPlay(crd)) { crd.addTempAttackBoost(1); @@ -1999,9 +2281,9 @@ public class CombatUtil { AllZone.getEndOfTurn().addUntil(untilEOT); } - }//resolve + }// resolve - };//ability + };// ability StringBuilder sb = new StringBuilder(); sb.append(c).append(" - (Exalted) gets +1/+1 until EOT."); @@ -2012,8 +2294,8 @@ public class CombatUtil { Player phasingPlayer = c.getController(); // Finest Hour untaps the creature on the first combat phase - if ((phasingPlayer.getCardsIn(Zone.Battlefield, "Finest Hour").size() > 0) && - AllZone.getPhase().isFirstCombat()) { + if ((phasingPlayer.getCardsIn(Zone.Battlefield, "Finest Hour").size() > 0) + && AllZone.getPhase().isFirstCombat()) { // Untap the attacking creature Ability fhUntap = new Ability(c, "0") { public void resolve() { @@ -2053,10 +2335,10 @@ public class CombatUtil { enchantments = enchantments.filter(new CardListFilter() { public boolean addCard(Card c) { if (attacker.hasKeyword("Protection from enchantments") - || (attacker.hasKeyword("Protection from everything"))) return false; - return (c.isEnchantment() - && c.hasKeyword("Enchant creature") - && !CardFactoryUtil.hasProtectionFrom(c, attacker)); + || (attacker.hasKeyword("Protection from everything"))) + return false; + return (c.isEnchantment() && c.hasKeyword("Enchant creature") && !CardFactoryUtil + .hasProtectionFrom(c, attacker)); } }); Player player = attacker.getController(); @@ -2067,7 +2349,8 @@ public class CombatUtil { Card crd = enchantments.get(j); Target[j] = crd; } - Object check = GuiUtils.getChoiceOptional("Select enchantment to enchant exalted creature", Target); + Object check = GuiUtils.getChoiceOptional("Select enchantment to enchant exalted creature", + Target); if (check != null) { Enchantment = ((Card) check); } @@ -2075,16 +2358,17 @@ public class CombatUtil { Enchantment = CardFactoryUtil.AI_getBestEnchantment(enchantments, attacker, false); } if (Enchantment != null && AllZoneUtil.isCardInPlay(attacker)) { - GameAction.changeZone(AllZone.getZoneOf(Enchantment), + GameAction.changeZone(AllZone.getZoneOf(Enchantment), Enchantment.getOwner().getZone(Constant.Zone.Battlefield), Enchantment); Enchantment.enchantEntity(attacker); } attacker.getController().shuffle(); - }//resolve + }// resolve };// ability4 StringBuilder sb4 = new StringBuilder(); - sb4.append(c).append(" - (Exalted) searches library for an Aura card that could enchant that creature, "); + sb4.append(c).append( + " - (Exalted) searches library for an Aura card that could enchant that creature, "); sb4.append("put it onto the battlefield attached to that creature, then shuffles library."); ability4.setDescription(sb4.toString()); ability4.setStackDescription(sb4.toString()); @@ -2096,17 +2380,21 @@ public class CombatUtil { /** * executes Rampage abilities for a given card - * - * @param c the card to add rampage bonus to - * @param magnitude the magnitude of rampage (ie Rampage 2 means magnitude should be 2) - * @param numBlockers - the number of creatures blocking this rampaging creature + * + * @param c + * the card to add rampage bonus to + * @param magnitude + * the magnitude of rampage (ie Rampage 2 means magnitude should + * be 2) + * @param numBlockers + * - the number of creatures blocking this rampaging creature */ private static void executeRampageAbility(Card c, int magnitude, int numBlockers) { final Card crd = c; final int pump = magnitude; Ability ability; - //numBlockers -1 since it is for every creature beyond the first + // numBlockers -1 since it is for every creature beyond the first for (int i = 0; i < numBlockers - 1; i++) { ability = new Ability(c, "0") { @Override @@ -2120,7 +2408,7 @@ public class CombatUtil { crd.addTempDefenseBoost(-pump); } } - };//Command + };// Command if (AllZoneUtil.isCardInPlay(crd)) { crd.addTempAttackBoost(pump); @@ -2128,9 +2416,9 @@ public class CombatUtil { AllZone.getEndOfTurn().addUntil(untilEOT); } - }//resolve + }// resolve - };//ability + };// ability StringBuilder sb = new StringBuilder(); sb.append(c).append(" - (Rampage) gets +").append(pump).append("/+").append(pump).append(" until EOT."); @@ -2140,4 +2428,4 @@ public class CombatUtil { } } -}//end class CombatUtil +}// end class CombatUtil