mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
checkstyle
This commit is contained in:
@@ -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 {
|
||||
/**
|
||||
* <p>setCard.</p>
|
||||
*
|
||||
* @param card a {@link forge.Card} object.
|
||||
* <p>
|
||||
* setCard.
|
||||
* </p>
|
||||
*
|
||||
* @param card
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
void setCard(Card card);
|
||||
|
||||
/**
|
||||
* <p>getCard.</p>
|
||||
*
|
||||
* <p>
|
||||
* getCard.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.Card} object.
|
||||
*/
|
||||
Card getCard();
|
||||
|
||||
@@ -9,25 +9,28 @@ import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import com.google.code.jyield.Generator;
|
||||
|
||||
/**
|
||||
* <p>CardFilter class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardFilter class.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> toBeFiltered, String substring) {
|
||||
public final CardList cardListNameFilter(final Iterable<Card> toBeFiltered, final String substring) {
|
||||
String s;
|
||||
|
||||
CardList listFilter = new CardList();
|
||||
@@ -45,12 +48,16 @@ public class CardFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>CardListTextFilter.</p>
|
||||
*
|
||||
* 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.
|
||||
* <p>
|
||||
* CardListTextFilter.
|
||||
* </p>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardListColorFilter.</p>
|
||||
*
|
||||
* 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.
|
||||
* <p>
|
||||
* CardListColorFilter.
|
||||
* </p>
|
||||
*
|
||||
* 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>CardListTypeFilter.</p>
|
||||
*
|
||||
* 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.
|
||||
* <p>
|
||||
* CardListTypeFilter.
|
||||
* </p>
|
||||
*
|
||||
* 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<Card> 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<Card> 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<Card> getColor(final Generator<Card> inputGenerator, final String cardColor) {
|
||||
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
|
||||
UtilFunctions.checkNotNull("cardColor", cardColor);
|
||||
|
||||
final boolean weWantMulticolor = cardColor.equals("Multicolor");
|
||||
|
||||
Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
|
||||
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<Card> getSets(final Generator<Card> inputGenerator, final List<String> 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<Card> getColor(final Generator<Card> inputGenerator, final String cardColor) {
|
||||
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
|
||||
UtilFunctions.checkNotNull("cardColor", cardColor);
|
||||
|
||||
Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
|
||||
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<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
|
||||
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<Card> getSets(final Generator<Card> inputGenerator, final List<String> sets) {
|
||||
UtilFunctions.checkNotNull("inputGenerator", inputGenerator);
|
||||
UtilFunctions.checkNotNull("sets", sets);
|
||||
|
||||
Lambda1<Boolean, Card> predicate = new Lambda1<Boolean, Card>() {
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>CardList class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardList class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CardList implements Iterable<Card> {
|
||||
|
||||
/**
|
||||
* <p>iterator.</p>
|
||||
*
|
||||
* <p>
|
||||
* iterator.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.Iterator} object.
|
||||
*/
|
||||
public final Iterator<Card> iterator() {
|
||||
@@ -32,24 +35,32 @@ public class CardList implements Iterable<Card> {
|
||||
private ArrayList<Card> list = new ArrayList<Card>();
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardList.</p>
|
||||
* <p>
|
||||
* Constructor for CardList.
|
||||
* </p>
|
||||
*/
|
||||
public CardList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardList.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* Constructor for CardList.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public CardList(final Card... c) {
|
||||
addAll(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardList.</p>
|
||||
*
|
||||
* @param al a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* Constructor for CardList.
|
||||
* </p>
|
||||
*
|
||||
* @param al
|
||||
* a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public CardList(final List<Card> al) {
|
||||
addAll(al.toArray());
|
||||
@@ -58,9 +69,9 @@ public class CardList implements Iterable<Card> {
|
||||
/**
|
||||
* 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<Card> iterable) {
|
||||
for (Card card : iterable) {
|
||||
@@ -69,9 +80,12 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardList.</p>
|
||||
*
|
||||
* @param c an array of {@link java.lang.Object} objects.
|
||||
* <p>
|
||||
* Constructor for CardList.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
*
|
||||
* 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<Card> 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<Card> {
|
||||
/**
|
||||
* 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<Card>(size);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Get any cards that exist in the passed in sets list.</p>
|
||||
*
|
||||
* @param sets a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* Get any cards that exist in the passed in sets list.
|
||||
* </p>
|
||||
*
|
||||
* @param sets
|
||||
* a {@link java.util.ArrayList} object.
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getSets(final ArrayList<String> sets) {
|
||||
@@ -128,13 +147,15 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
return list;
|
||||
} //getSets()
|
||||
|
||||
} // getSets()
|
||||
|
||||
/**
|
||||
* <p>getColor.</p>
|
||||
*
|
||||
* @param cardColor a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getColor.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
return list;
|
||||
} //getColor()
|
||||
} // getColor()
|
||||
|
||||
/**
|
||||
* <p>getOnly2Colors.</p>
|
||||
*
|
||||
* @param clr1 a {@link java.lang.String} object.
|
||||
* @param clr2 a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getOnly2Colors.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
ArrayList<Card_Color> 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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>reverse.</p>
|
||||
* <p>
|
||||
* reverse.
|
||||
* </p>
|
||||
*/
|
||||
public final void reverse() {
|
||||
Collections.reverse(list);
|
||||
@@ -205,11 +231,14 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
}
|
||||
|
||||
//removes one copy of that card
|
||||
// removes one copy of that card
|
||||
/**
|
||||
* <p>remove.</p>
|
||||
*
|
||||
* @param cardName a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* remove.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
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)
|
||||
|
||||
/**
|
||||
* <p>size.</p>
|
||||
*
|
||||
* <p>
|
||||
* size.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int size() {
|
||||
@@ -237,19 +268,26 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>add.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* add.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public final void add(final Card c) {
|
||||
list.add(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>add.</p>
|
||||
*
|
||||
* @param n a int.
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* add.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addAll.</p>
|
||||
*
|
||||
* @param c an array of {@link java.lang.Object} objects.
|
||||
* <p>
|
||||
* addAll.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>contains.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* contains.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
/**
|
||||
* <p>getCard.</p>
|
||||
*
|
||||
* @param index a int.
|
||||
* <p>
|
||||
* getCard.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get.</p>
|
||||
*
|
||||
* @param i a int.
|
||||
* <p>
|
||||
* get.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>containsName.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* containsName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>containsName.</p>
|
||||
*
|
||||
* @param name a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* containsName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
return false;
|
||||
}
|
||||
|
||||
//returns new subset of all the cards with the same name
|
||||
// returns new subset of all the cards with the same name
|
||||
/**
|
||||
* <p>getName.</p>
|
||||
*
|
||||
* @param name a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
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
|
||||
/**
|
||||
* <p>getNotName.</p>
|
||||
*
|
||||
* @param name a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getNotName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getImageName.</p>
|
||||
*
|
||||
* @param name a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getImageName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getController.</p>
|
||||
*
|
||||
* @param player a {@link forge.Player} object.
|
||||
* <p>
|
||||
* getController.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getOwner.</p>
|
||||
*
|
||||
* @param player a {@link forge.Player} object.
|
||||
* <p>
|
||||
* getOwner.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
//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
|
||||
/**
|
||||
* <p>getType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getType.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
//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
|
||||
/**
|
||||
* <p>getNotType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getNotType.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getPermanents.</p>
|
||||
*
|
||||
* <p>
|
||||
* getPermanents.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getPermanents() {
|
||||
@@ -460,9 +542,12 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getKeyword.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getNotKeyword.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getNotKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
//get all cards that have this string in their keywords
|
||||
// get all cards that have this string in their keywords
|
||||
/**
|
||||
* <p>getKeywordsContain.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getKeywordsContain.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
});
|
||||
}
|
||||
|
||||
//get all cards that don't have this string in their keywords
|
||||
// get all cards that don't have this string in their keywords
|
||||
/**
|
||||
* <p>getKeywordsDontContain.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getKeywordsDontContain.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getTokens.</p>
|
||||
*
|
||||
* <p>
|
||||
* getTokens.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getTokens() {
|
||||
@@ -533,18 +629,21 @@ public class CardList implements Iterable<Card> {
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toArray.</p>
|
||||
*
|
||||
* <p>
|
||||
* toArray.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public final Card[] toArray() {
|
||||
@@ -560,8 +659,10 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isEmpty.</p>
|
||||
*
|
||||
* <p>
|
||||
* isEmpty.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isEmpty() {
|
||||
@@ -569,9 +670,12 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>remove.</p>
|
||||
*
|
||||
* @param i a int.
|
||||
* <p>
|
||||
* remove.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>remove.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* remove.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public final void remove(final Card c) {
|
||||
list.remove(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>removeAll.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* removeAll.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public final void removeAll(final Card c) {
|
||||
ArrayList<Card> cList = new ArrayList<Card>();
|
||||
@@ -599,36 +709,46 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>clear.</p>
|
||||
* <p>
|
||||
* clear.
|
||||
* </p>
|
||||
*/
|
||||
public final void clear() {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>shuffle.</p>
|
||||
* <p>
|
||||
* shuffle.
|
||||
* </p>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sort.</p>
|
||||
*
|
||||
* @param c a {@link java.util.Comparator} object.
|
||||
* <p>
|
||||
* sort.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link java.util.Comparator} object.
|
||||
*/
|
||||
public final void sort(final Comparator<Card> c) {
|
||||
Collections.sort(list, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getTargetableCards.</p>
|
||||
*
|
||||
* @param source a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getTargetableCards.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getUnprotectedCards.</p>
|
||||
*
|
||||
* @param source a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getUnprotectedCards.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getValidCards.</p>
|
||||
*
|
||||
* @param restrictions a {@link java.lang.String} object.
|
||||
* @param sourceController a {@link forge.Player} object.
|
||||
* @param source a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getValidCards.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getValidCards.</p>
|
||||
*
|
||||
* @param restrictions a {@link java.lang.String} object.
|
||||
* @param sourceController a {@link forge.Player} object.
|
||||
* @param source a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getValidCards.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getEquipMagnets.</p>
|
||||
*
|
||||
* <p>
|
||||
* getEquipMagnets.
|
||||
* </p>
|
||||
*
|
||||
* @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())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getEnchantMagnets.</p>
|
||||
*
|
||||
* <p>
|
||||
* getEnchantMagnets.
|
||||
* </p>
|
||||
*
|
||||
* @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())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getTotalConvertedManaCost.</p>
|
||||
*
|
||||
* <p>
|
||||
* getTotalConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getTotalConvertedManaCost() {
|
||||
@@ -721,14 +860,16 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>getTotalCreaturePower.</p>
|
||||
* <p>
|
||||
* getTotalCreaturePower.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getHighestConvertedManaCost.</p>
|
||||
*
|
||||
* <p>
|
||||
* getHighestConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
@@ -752,8 +895,10 @@ public class CardList implements Iterable<Card> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getColored.</p>
|
||||
*
|
||||
* <p>
|
||||
* getColored.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getColored() {
|
||||
@@ -767,8 +912,10 @@ public class CardList implements Iterable<Card> {
|
||||
/**
|
||||
* 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<Card> {
|
||||
/**
|
||||
* 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<Card> {
|
||||
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<Card> {
|
||||
return false;
|
||||
}
|
||||
|
||||
} //end class CardList
|
||||
} // end class CardList
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
package forge;
|
||||
|
||||
/**
|
||||
* <p>CardListFilter interface.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardListFilter interface.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface CardListFilter {
|
||||
/**
|
||||
* <p>addCard.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* addCard.
|
||||
* </p>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>CardListUtil class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardListUtil class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CardListUtil {
|
||||
/**
|
||||
* <p>filterToughness.</p>
|
||||
*
|
||||
* @param in a {@link forge.CardList} object.
|
||||
* @param atLeastToughness a int.
|
||||
* <p>
|
||||
* filterToughness.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
|
||||
/**
|
||||
* <p>sortDefense.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortDefense.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortDefense(CardList list) {
|
||||
public static void sortDefense(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortAttack.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortAttack.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortAttack(CardList list) {
|
||||
public static void sortAttack(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortByEvaluateCreature.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByEvaluateCreature.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByEvaluateCreature(CardList list) {
|
||||
public static void sortByEvaluateCreature(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortByMostExpensive.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByMostExpensive.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByMostExpensive(CardList list) {
|
||||
public static void sortByMostExpensive(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortAttackLowFirst.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortAttackLowFirst.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortAttackLowFirst(CardList list) {
|
||||
public static void sortAttackLowFirst(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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()
|
||||
|
||||
/**
|
||||
* <p>sortNonFlyingFirst.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortNonFlyingFirst.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
/**
|
||||
* <p>sortFlying.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortFlying.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortFlying(CardList list) {
|
||||
public static void sortFlying(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortByKeyword.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* @param kw a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* sortByKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> com = new Comparator<Card>() {
|
||||
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()
|
||||
|
||||
/**
|
||||
* <p>sortByDestroyEffect.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByDestroyEffect.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByDestroyEffect(CardList list) {
|
||||
public static void sortByDestroyEffect(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
public int compare(Card a, Card b) {
|
||||
public int compare(final Card a, final Card b) {
|
||||
ArrayList<String> aKeywords = a.getKeyword();
|
||||
ArrayList<String> 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortByIndestructible.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByIndestructible.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByIndestructible(CardList list) {
|
||||
public static void sortByIndestructible(final CardList list) {
|
||||
final ArrayList<String> arrList = new ArrayList<String>();
|
||||
arrList.add("Timber Protector");
|
||||
arrList.add("Eldrazi Monument");
|
||||
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortByTapped.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByTapped.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByTapped(CardList list) {
|
||||
public static void sortByTapped(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortByName.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByName.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByName(CardList list) {
|
||||
public static void sortByName(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortBySelectable.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* @param type a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* sortBySelectable.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> com = new Comparator<Card>() {
|
||||
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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortByTextLen.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortByTextLen.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortByTextLen(CardList list) {
|
||||
public static void sortByTextLen(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
/**
|
||||
* <p>sortCMC.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sortCMC.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
public static void sortCMC(CardList list) {
|
||||
public static void sortCMC(final CardList list) {
|
||||
Comparator<Card> com = new Comparator<Card>() {
|
||||
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
|
||||
|
||||
/**
|
||||
* <p>getColor.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* @param color a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getColor.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>getGoldCards.</p>
|
||||
*
|
||||
* @param list a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* getGoldCards.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sumAttack.</p>
|
||||
*
|
||||
* @param c a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sumAttack.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>sumDefense.</p>
|
||||
*
|
||||
* @param c a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sumDefense.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>sumFirstStrikeAttack.</p>
|
||||
*
|
||||
* @param c a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sumFirstStrikeAttack.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
/**
|
||||
* <p>sumCMC.</p>
|
||||
*
|
||||
* @param c a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* sumCMC.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
* <p>CardReader class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardReader class.
|
||||
* </p>
|
||||
*
|
||||
* @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<String, Card> mapToFill;
|
||||
private transient List<CardRules> listRulesToFill;
|
||||
@@ -73,46 +96,71 @@ public class CardReader
|
||||
|
||||
private transient Enumeration<? extends ZipEntry> 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<File> findNonDirsIterable; // NOPMD by Braids on 8/18/11 10:56 PM
|
||||
private transient Iterable<File> findNonDirsIterable; // NOPMD by Braids on
|
||||
// 8/18/11 10:56 PM
|
||||
|
||||
|
||||
|
||||
public CardReader(final File theCardsFolder, final Map<String, Card> 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<String, Card> 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<CardRules>
|
||||
* @param theMapToFill
|
||||
* maps card names to Card instances; this is where we place the
|
||||
* cards once read
|
||||
*
|
||||
*/
|
||||
public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill,
|
||||
final List<CardRules> listRules2Fill) {
|
||||
public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill,
|
||||
final List<CardRules> listRules2Fill)
|
||||
{
|
||||
this(theCardsFolder, theMapToFill, listRules2Fill, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for CardReader.</p>
|
||||
*
|
||||
* @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.
|
||||
* <p>
|
||||
* Constructor for CardReader.
|
||||
* </p>
|
||||
*
|
||||
* @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<CardRules>
|
||||
* @param useZip
|
||||
* if true, attempts to load cards from a zip file, if one
|
||||
* exists.
|
||||
*/
|
||||
public CardReader(final File theCardsFolder, final Map<String, Card> theMapToFill,
|
||||
final List<CardRules> 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)
|
||||
|
||||
/**
|
||||
* <p>addTypes to an existing card.</p>
|
||||
*
|
||||
* @param card a {@link forge.Card} object.
|
||||
* @param types a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* addTypes to an existing card.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Reads a line from the given reader and handles exceptions.</p>
|
||||
*
|
||||
* <p>
|
||||
* Reads a line from the given reader and handles exceptions.
|
||||
* </p>
|
||||
*
|
||||
* @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)
|
||||
|
||||
/**
|
||||
* <p>load a card.</p>
|
||||
*
|
||||
* @param inputStream the stream from which to load the card's information
|
||||
*
|
||||
* <p>
|
||||
* load a card.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card_Color> newCols = new ArrayList<Card_Color>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/**
|
||||
* <p>CardUtil class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CardUtil class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -31,7 +33,6 @@ public final class CardUtil {
|
||||
/** Constant <code>RANDOM</code>. */
|
||||
public static final Random RANDOM = MyRandom.random;
|
||||
|
||||
|
||||
/**
|
||||
* Do not instantiate.
|
||||
*/
|
||||
@@ -40,24 +41,29 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRandomIndex.</p>
|
||||
*
|
||||
* @param o an array of {@link java.lang.Object} objects.
|
||||
* <p>
|
||||
* getRandomIndex.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRandom.</p>
|
||||
*
|
||||
* @param o an array of {@link forge.Card} objects.
|
||||
* <p>
|
||||
* getRandom.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRandomIndex.</p>
|
||||
*
|
||||
* @param list a {@link forge.card.spellability.SpellAbilityList} object.
|
||||
* <p>
|
||||
* getRandomIndex.
|
||||
* </p>
|
||||
*
|
||||
* @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());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRandomIndex.</p>
|
||||
*
|
||||
* @param c a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* getRandomIndex.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
/**
|
||||
* <p>toText.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* toText.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toCard.</p>
|
||||
*
|
||||
* @param col a {@link java.util.Collection} object.
|
||||
* <p>
|
||||
* toCard.
|
||||
* </p>
|
||||
*
|
||||
* @param col
|
||||
* a {@link java.util.Collection} object.
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public static Card[] toCard(final Collection<Card> 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toCard.</p>
|
||||
*
|
||||
* @param list a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* toCard.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link java.util.ArrayList} object.
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public static Card[] toCard(final ArrayList<Card> list) {
|
||||
@@ -137,9 +157,12 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toList.</p>
|
||||
*
|
||||
* @param c an array of {@link forge.Card} objects.
|
||||
* <p>
|
||||
* toList.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* an array of {@link forge.Card} objects.
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<Card> 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
|
||||
/**
|
||||
* <p>getShortColor.</p>
|
||||
*
|
||||
* @param longColor a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getShortColor.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isColor.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* @param col a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isColor.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getColors.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getColors.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getColors(final Card c) {
|
||||
@@ -196,9 +229,12 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getOnlyColors.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getOnlyColors.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getOnlyColors(final Card c) {
|
||||
@@ -240,12 +276,15 @@ public final class CardUtil {
|
||||
return new ArrayList<String>(colors);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>hasCardName.</p>
|
||||
*
|
||||
* @param cardName a {@link java.lang.String} object.
|
||||
* @param list a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* hasCardName.
|
||||
* </p>
|
||||
*
|
||||
* @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<Card> 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
|
||||
/**
|
||||
* <p>getConvertedManaCost.</p>
|
||||
*
|
||||
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||
* <p>
|
||||
* getConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getConvertedManaCost.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getConvertedManaCost.</p>
|
||||
*
|
||||
* @param manaCost a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getConvertedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addManaCosts.</p>
|
||||
*
|
||||
* @param mc1 a {@link java.lang.String} object.
|
||||
* @param mc2 a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* addManaCosts.
|
||||
* </p>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRelative.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* @param relation a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getRelative.
|
||||
* </p>
|
||||
*
|
||||
* @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");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isACardType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isACardType.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getAllCardTypes.</p>
|
||||
*
|
||||
* <p>
|
||||
* getAllCardTypes.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getAllCardTypes() {
|
||||
ArrayList<String> types = new ArrayList<String>();
|
||||
|
||||
//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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCardTypes.</p>
|
||||
*
|
||||
* <p>
|
||||
* getCardTypes.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getCardTypes() {
|
||||
ArrayList<String> types = new ArrayList<String>();
|
||||
|
||||
// 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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getBasicTypes.</p>
|
||||
*
|
||||
* <p>
|
||||
* getBasicTypes.
|
||||
* </p>
|
||||
*
|
||||
* @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<String> getLandTypes() {
|
||||
ArrayList<String> types = new ArrayList<String>();
|
||||
|
||||
@@ -434,10 +504,12 @@ public final class CardUtil {
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>getCreatureTypes.</p>
|
||||
*
|
||||
* <p>
|
||||
* getCreatureTypes.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
* @since 1.1.6
|
||||
*/
|
||||
@@ -450,9 +522,12 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isASuperType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isASuperType.
|
||||
* </p>
|
||||
*
|
||||
* @param cardType
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
|
||||
@@ -461,9 +536,12 @@ public final class CardUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isASubType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isASubType.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isACreatureType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isACreatureType.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isALandType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isALandType.
|
||||
* </p>
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isABasicLandType.</p>
|
||||
*
|
||||
* @param cardType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isABasicLandType.
|
||||
* </p>
|
||||
*
|
||||
* @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.)
|
||||
/**
|
||||
* <p>isNonStackingKeyword.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isNonStackingKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isStackingKeyword.</p>
|
||||
*
|
||||
* @param keyword a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* isStackingKeyword.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>buildFilename.</p>
|
||||
*
|
||||
* @param card a {@link forge.Card} object.
|
||||
* <p>
|
||||
* buildFilename.
|
||||
* </p>
|
||||
*
|
||||
* @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<SetInfo> findSetInfo = new Predicate<SetInfo>() {
|
||||
@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";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getWeightedManaCost.</p>
|
||||
*
|
||||
* @param manaCost a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* getWeightedManaCost.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getShortColorsString.</p>
|
||||
*
|
||||
* @param colors a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* getShortColorsString.
|
||||
* </p>
|
||||
*
|
||||
* @param colors
|
||||
* a {@link java.util.ArrayList} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String getShortColorsString(final ArrayList<String> 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
|
||||
|
||||
@@ -1,38 +1,53 @@
|
||||
package forge;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import forge.card.mana.ManaCost;
|
||||
|
||||
// TODO Auto-generated Javadoc
|
||||
/**
|
||||
* <p>Color class.</p>
|
||||
*
|
||||
* <p>
|
||||
* Color class.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* <p>Constructor for Color.</p>
|
||||
*
|
||||
* @param c a int.
|
||||
* <p>
|
||||
* Constructor for Color.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a int.
|
||||
*/
|
||||
Color(final int c) {
|
||||
flag = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Colorless.</p>
|
||||
*
|
||||
* <p>
|
||||
* Colorless.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.EnumSet} object.
|
||||
*/
|
||||
public static EnumSet<Color> Colorless() {
|
||||
@@ -41,9 +56,12 @@ public enum Color {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ConvertStringsToColor.</p>
|
||||
*
|
||||
* @param s an array of {@link java.lang.String} objects.
|
||||
* <p>
|
||||
* ConvertStringsToColor.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* an array of {@link java.lang.String} objects.
|
||||
* @return a {@link java.util.EnumSet} object.
|
||||
*/
|
||||
public static EnumSet<Color> ConvertStringsToColor(String[] s) {
|
||||
@@ -61,33 +79,39 @@ public enum Color {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ConvertFromString.</p>
|
||||
*
|
||||
* @param s a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* ConvertFromString.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ConvertManaCostToColor.</p>
|
||||
*
|
||||
* @param m a {@link forge.card.mana.ManaCost} object.
|
||||
* <p>
|
||||
* ConvertManaCostToColor.
|
||||
* </p>
|
||||
*
|
||||
* @param m
|
||||
* a {@link forge.card.mana.ManaCost} object.
|
||||
* @return a {@link java.util.EnumSet} object.
|
||||
*/
|
||||
public static EnumSet<Color> ConvertManaCostToColor(final ManaCost m) {
|
||||
@@ -117,8 +141,10 @@ public enum Color {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>toString.</p>
|
||||
*
|
||||
* <p>
|
||||
* toString.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
@@ -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<Card_Color> globalColorChanges = new ArrayList<Card_Color>();
|
||||
|
||||
|
||||
/**
|
||||
* <p>addColorChanges.</p>
|
||||
*
|
||||
* @param s a {@link java.lang.String} object.
|
||||
* @param c a {@link forge.Card} object.
|
||||
* @param addToColors a boolean.
|
||||
* @param bIncrease a boolean.
|
||||
* <p>
|
||||
* addColorChanges.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>removeColorChanges.</p>
|
||||
*
|
||||
* @param s a {@link java.lang.String} object.
|
||||
* @param c a {@link forge.Card} object.
|
||||
* @param addTo a boolean.
|
||||
* @param timestamp a long.
|
||||
* <p>
|
||||
* removeColorChanges.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>reset = clearColorChanges.</p>
|
||||
* <p>
|
||||
* reset = clearColorChanges.
|
||||
* </p>
|
||||
*/
|
||||
public final void reset() {
|
||||
clearColorChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>clearColorChanges.</p>
|
||||
* <p>
|
||||
* clearColorChanges.
|
||||
* </p>
|
||||
*/
|
||||
public final void clearColorChanges() {
|
||||
// clear the global color changes at end of each game
|
||||
@@ -69,8 +83,10 @@ public class ColorChanger {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getColorChanges.</p>
|
||||
*
|
||||
* <p>
|
||||
* getColorChanges.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final ArrayList<Card_Color> getColorChanges() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>Combat class.</p>
|
||||
*
|
||||
* <p>
|
||||
* Combat class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -20,7 +29,8 @@ public class Combat {
|
||||
private HashMap<Card, CardList> unblockedMap = new HashMap<Card, CardList>();
|
||||
private HashMap<Card, Integer> defendingDamageMap = new HashMap<Card, Integer>();
|
||||
|
||||
// Defenders are the Defending Player + Each Planeswalker that player controls
|
||||
// Defenders are the Defending Player + Each Planeswalker that player
|
||||
// controls
|
||||
private ArrayList<Object> defenders = new ArrayList<Object>();
|
||||
private int currentDefender = 0;
|
||||
private int nextDefender = 0;
|
||||
@@ -37,14 +47,18 @@ public class Combat {
|
||||
private CardList canBlockAttackerWithLure = new CardList();
|
||||
|
||||
/**
|
||||
* <p>Constructor for Combat.</p>
|
||||
* <p>
|
||||
* Constructor for Combat.
|
||||
* </p>
|
||||
*/
|
||||
public Combat() {
|
||||
// Let the Begin Turn/Untap Phase Reset Combat properly
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>reset.</p>
|
||||
* <p>
|
||||
* reset.
|
||||
* </p>
|
||||
*/
|
||||
public final void reset() {
|
||||
resetAttackers();
|
||||
@@ -69,9 +83,12 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>initiatePossibleDefenders.</p>
|
||||
*
|
||||
* @param defender a {@link forge.Player} object.
|
||||
* <p>
|
||||
* initiatePossibleDefenders.
|
||||
* </p>
|
||||
*
|
||||
* @param defender
|
||||
* a {@link forge.Player} object.
|
||||
*/
|
||||
public final void initiatePossibleDefenders(final Player defender) {
|
||||
defenders.add(defender);
|
||||
@@ -83,8 +100,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>nextDefender.</p>
|
||||
*
|
||||
* <p>
|
||||
* nextDefender.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.Object} object.
|
||||
*/
|
||||
public final Object nextDefender() {
|
||||
@@ -99,17 +118,22 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>currentDefender</code>.</p>
|
||||
*
|
||||
* @param def a int.
|
||||
* <p>
|
||||
* Setter for the field <code>currentDefender</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param def
|
||||
* a int.
|
||||
*/
|
||||
public final void setCurrentDefender(final int def) {
|
||||
currentDefender = def;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getRemainingDefenders.</p>
|
||||
*
|
||||
* <p>
|
||||
* getRemainingDefenders.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getRemainingDefenders() {
|
||||
@@ -117,8 +141,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>defenders</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>defenders</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final ArrayList<Object> getDefenders() {
|
||||
@@ -126,17 +152,22 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>defenders</code>.</p>
|
||||
*
|
||||
* @param newDef a {@link java.util.ArrayList} object.
|
||||
* <p>
|
||||
* Setter for the field <code>defenders</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param newDef
|
||||
* a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public final void setDefenders(ArrayList<Object> newDef) {
|
||||
public final void setDefenders(final ArrayList<Object> newDef) {
|
||||
defenders = newDef;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDefendingPlaneswalkers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getDefendingPlaneswalkers.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public final Card[] getDefendingPlaneswalkers() {
|
||||
@@ -155,8 +186,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDeclaredAttackers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getDeclaredAttackers.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getDeclaredAttackers() {
|
||||
@@ -164,26 +197,34 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>attackingPlayer</code>.</p>
|
||||
*
|
||||
* @param player a {@link forge.Player} object.
|
||||
* <p>
|
||||
* Setter for the field <code>attackingPlayer</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param player
|
||||
* a {@link forge.Player} object.
|
||||
*/
|
||||
public final void setAttackingPlayer(final Player player) {
|
||||
attackingPlayer = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>defendingPlayer</code>.</p>
|
||||
*
|
||||
* @param player a {@link forge.Player} object.
|
||||
* <p>
|
||||
* Setter for the field <code>defendingPlayer</code>.
|
||||
* </p>
|
||||
*
|
||||
* @param player
|
||||
* a {@link forge.Player} object.
|
||||
*/
|
||||
public final void setDefendingPlayer(final Player player) {
|
||||
defendingPlayer = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>attackingPlayer</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>attackingPlayer</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.Player} object.
|
||||
*/
|
||||
public final Player getAttackingPlayer() {
|
||||
@@ -191,8 +232,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>defendingPlayer</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>defendingPlayer</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.Player} object.
|
||||
*/
|
||||
public final Player getDefendingPlayer() {
|
||||
@@ -200,8 +243,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>defendingDamageMap</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>defendingDamageMap</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.HashMap} object.
|
||||
*/
|
||||
public final HashMap<Card, Integer> getDefendingDamageMap() {
|
||||
@@ -209,8 +254,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getTotalDefendingDamage.</p>
|
||||
*
|
||||
* <p>
|
||||
* getTotalDefendingDamage.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getTotalDefendingDamage() {
|
||||
@@ -227,21 +274,22 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>setDefendingDamage.</p>
|
||||
* <p>
|
||||
* setDefendingDamage.
|
||||
* </p>
|
||||
*/
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>setDefendingFirstStrikeDamage.</p>
|
||||
*
|
||||
* <p>
|
||||
* setDefendingFirstStrikeDamage.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>addDefendingDamage.</p>
|
||||
*
|
||||
* @param n a int.
|
||||
* @param source a {@link forge.Card} object.
|
||||
* <p>
|
||||
* addDefendingDamage.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addAttackingDamage.</p>
|
||||
*
|
||||
* @param n a int.
|
||||
* <p>
|
||||
* addAttackingDamage.
|
||||
* </p>
|
||||
*
|
||||
* @param n
|
||||
* a int.
|
||||
*/
|
||||
public final void addAttackingDamage(int n) {
|
||||
public final void addAttackingDamage(final int n) {
|
||||
attackingDamage += n;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>attackingDamage</code>.</p>
|
||||
*
|
||||
* <p>
|
||||
* Getter for the field <code>attackingDamage</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int getAttackingDamage() {
|
||||
@@ -323,8 +381,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>sortAttackerByDefender.</p>
|
||||
*
|
||||
* <p>
|
||||
* sortAttackerByDefender.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.CardList} objects.
|
||||
*/
|
||||
public final CardList[] sortAttackerByDefender() {
|
||||
@@ -343,9 +403,12 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isAttacking.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* isAttacking.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isAttacking(final Card c) {
|
||||
@@ -353,9 +416,12 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addAttacker.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* addAttacker.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getDefenderByAttacker.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getDefenderByAttacker.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>resetAttackers.</p>
|
||||
* <p>
|
||||
* resetAttackers.
|
||||
* </p>
|
||||
*/
|
||||
public final void resetAttackers() {
|
||||
map.clear();
|
||||
@@ -381,8 +452,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getAttackers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getAttackers.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public final Card[] getAttackers() {
|
||||
@@ -397,9 +470,12 @@ public class Combat {
|
||||
} // getAttackers()
|
||||
|
||||
/**
|
||||
* <p>isBlocked.</p>
|
||||
*
|
||||
* @param attacker a {@link forge.Card} object.
|
||||
* <p>
|
||||
* isBlocked.
|
||||
* </p>
|
||||
*
|
||||
* @param attacker
|
||||
* a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isBlocked(final Card attacker) {
|
||||
@@ -407,10 +483,14 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>addBlocker.</p>
|
||||
*
|
||||
* @param attacker a {@link forge.Card} object.
|
||||
* @param blocker a {@link forge.Card} object.
|
||||
* <p>
|
||||
* addBlocker.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>resetBlockers.</p>
|
||||
* <p>
|
||||
* resetBlockers.
|
||||
* </p>
|
||||
*/
|
||||
public final void resetBlockers() {
|
||||
reset();
|
||||
@@ -430,8 +512,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getAllBlockers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getAllBlockers.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public final CardList getAllBlockers() {
|
||||
@@ -446,9 +530,12 @@ public class Combat {
|
||||
} // getAllBlockers()
|
||||
|
||||
/**
|
||||
* <p>getBlockers.</p>
|
||||
*
|
||||
* @param attacker a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getBlockers.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getAttackerBlockedBy.</p>
|
||||
*
|
||||
* @param blocker a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getAttackerBlockedBy.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getList.</p>
|
||||
*
|
||||
* @param attacker a {@link forge.Card} object.
|
||||
* <p>
|
||||
* getList.
|
||||
* </p>
|
||||
*
|
||||
* @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 {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>removeFromCombat.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* removeFromCombat.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>verifyCreaturesInPlay.</p>
|
||||
* <p>
|
||||
* verifyCreaturesInPlay.
|
||||
* </p>
|
||||
*/
|
||||
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()
|
||||
|
||||
/**
|
||||
* <p>setUnblocked.</p>
|
||||
* <p>
|
||||
* setUnblocked.
|
||||
* </p>
|
||||
*/
|
||||
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<String, Object> runParams = new HashMap<String, Object>();
|
||||
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()
|
||||
/**
|
||||
* <p>setAssignedFirstStrikeDamage.</p>
|
||||
*
|
||||
* <p>
|
||||
* setAssignedFirstStrikeDamage.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
/**
|
||||
* <p>setAssignedDamage.</p>
|
||||
* <p>
|
||||
* setAssignedDamage.
|
||||
* </p>
|
||||
*/
|
||||
public final void setAssignedDamage() {
|
||||
setDefendingDamage();
|
||||
@@ -646,11 +752,16 @@ public class Combat {
|
||||
} // assignDamage()
|
||||
|
||||
/**
|
||||
* <p>distributeAIDamage.</p>
|
||||
*
|
||||
* @param attacker a {@link forge.Card} object.
|
||||
* @param block a {@link forge.CardList} object.
|
||||
* @param damage a int.
|
||||
* <p>
|
||||
* distributeAIDamage.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>dealAssignedDamage.</p>
|
||||
* <p>
|
||||
* dealAssignedDamage.
|
||||
* </p>
|
||||
*/
|
||||
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.
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>isUnblocked.</p>
|
||||
*
|
||||
* @param att a {@link forge.Card} object.
|
||||
* <p>
|
||||
* isUnblocked.
|
||||
* </p>
|
||||
*
|
||||
* @param att
|
||||
* a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public final boolean isUnblocked(final Card att) {
|
||||
@@ -788,8 +906,10 @@ public class Combat {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getUnblockedAttackers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getUnblockedAttackers.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public final Card[] getUnblockedAttackers() {
|
||||
@@ -807,8 +927,10 @@ public class Combat {
|
||||
} // getUnblockedAttackers()
|
||||
|
||||
/**
|
||||
* <p>getUnblockedFirstStrikeAttackers.</p>
|
||||
*
|
||||
* <p>
|
||||
* getUnblockedFirstStrikeAttackers.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.Card} objects.
|
||||
*/
|
||||
public final Card[] getUnblockedFirstStrikeAttackers() {
|
||||
@@ -826,9 +948,12 @@ public class Combat {
|
||||
} // getUnblockedAttackers()
|
||||
|
||||
/**
|
||||
* <p>addUnblockedAttacker.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* addUnblockedAttacker.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
public final void addUnblockedAttacker(final Card c) {
|
||||
unblockedMap.put(c, new CardList());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user