diff --git a/src/main/java/forge/AllZoneUtil.java b/src/main/java/forge/AllZoneUtil.java index c874c1c1db9..76d5e702142 100644 --- a/src/main/java/forge/AllZoneUtil.java +++ b/src/main/java/forge/AllZoneUtil.java @@ -279,8 +279,8 @@ public abstract class AllZoneUtil { public static int compareTypeAmountInPlay(final Player player, final String type) { // returns the difference between player's final Player opponent = player.getOpponent(); - final CardList playerList = player.getCardsIn(ZoneType.Battlefield).getType(type); - final CardList opponentList = opponent.getCardsIn(ZoneType.Battlefield).getType(type); + final CardList playerList = CardListUtil.getType(player.getCardsIn(ZoneType.Battlefield), type); + final CardList opponentList = CardListUtil.getType(opponent.getCardsIn(ZoneType.Battlefield), type); return (playerList.size() - opponentList.size()); } @@ -298,8 +298,8 @@ public abstract class AllZoneUtil { public static int compareTypeAmountInGraveyard(final Player player, final String type) { // returns the difference between player's final Player opponent = player.getOpponent(); - final CardList playerList = player.getCardsIn(ZoneType.Graveyard).getType(type); - final CardList opponentList = opponent.getCardsIn(ZoneType.Graveyard).getType(type); + final CardList playerList = CardListUtil.getType(player.getCardsIn(ZoneType.Graveyard), type); + final CardList opponentList = CardListUtil.getType(opponent.getCardsIn(ZoneType.Graveyard), type); return (playerList.size() - opponentList.size()); } diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 2bfa80c975c..9aaf93681cd 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -6547,7 +6547,7 @@ public class Card extends GameEntity implements Comparable { } else if (property.startsWith("ControllerControls")) { final String type = property.substring(18); final CardList list = this.getController().getCardsIn(ZoneType.Battlefield); - if (list.getType(type).isEmpty()) { + if (CardListUtil.getType(list, type).isEmpty()) { return false; } } else if (property.startsWith("Other")) { diff --git a/src/main/java/forge/CardList.java b/src/main/java/forge/CardList.java index 7ba1075d733..089c88aabb3 100644 --- a/src/main/java/forge/CardList.java +++ b/src/main/java/forge/CardList.java @@ -19,12 +19,8 @@ package forge; import java.util.ArrayList; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Iterables; -import forge.card.spellability.SpellAbility; -import forge.game.player.Player; - /** *

@@ -56,24 +52,4 @@ public class CardList extends ArrayList { return new CardList(Iterables.filter(this, filt)); } - // cardType is like "Land" or "Goblin", returns a new CardList that is a - // subset of current CardList - public final CardList getType(final String cardType) { - return this.filter(CardPredicates.isType(cardType)); - } - - // cardType is like "Land" or "Goblin", returns a new CardList with cards - // that do not have this type - public final CardList getNotType(final String cardType) { - return this.filter(Predicates.not(CardPredicates.isType(cardType))); - } - - public final CardList getKeyword(final String keyword) { - return this.filter(CardPredicates.hasKeyword(keyword)); - } - - public final CardList getNotKeyword(final String keyword) { - return this.filter(Predicates.not(CardPredicates.hasKeyword(keyword))); - } - } // end class CardList diff --git a/src/main/java/forge/CardListUtil.java b/src/main/java/forge/CardListUtil.java index 702fff0b3c5..e10d91f2ed3 100644 --- a/src/main/java/forge/CardListUtil.java +++ b/src/main/java/forge/CardListUtil.java @@ -22,6 +22,7 @@ import java.util.Comparator; import java.util.List; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.SpellAbility; @@ -314,4 +315,22 @@ public class CardListUtil { public static CardList getTargetableCards(CardList cardList, SpellAbility source) { return cardList.filter(CardPredicates.isTargetableBy(source)); } + + public static CardList getKeyword(CardList cardList, String keyword) { + return cardList.filter(CardPredicates.hasKeyword(keyword)); + } + + public static CardList getNotKeyword(CardList cardList, String keyword) { + return cardList.filter(Predicates.not(CardPredicates.hasKeyword(keyword))); + } + + // cardType is like "Land" or "Goblin", returns a new CardList that is a + // subset of current CardList + public static CardList getNotType(CardList cardList, String cardType) { + return cardList.filter(Predicates.not(CardPredicates.isType(cardType))); + } + + public static CardList getType(CardList cardList, String cardType) { + return cardList.filter(CardPredicates.isType(cardType)); + } } diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index 584f5453718..541b352a490 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -1233,7 +1233,7 @@ public class GameAction { continue; } - final CardList cl = list.getType(type); + final CardList cl = CardListUtil.getType(list, type); if (cl.size() > 1) { for (final Card crd : cl) { @@ -1250,14 +1250,14 @@ public class GameAction { *

*/ private void destroyLegendaryCreatures() { - final CardList a = AllZoneUtil.getCardsIn(ZoneType.Battlefield).getType("Legendary"); + final CardList a = CardListUtil.getType(AllZoneUtil.getCardsIn(ZoneType.Battlefield), "Legendary"); if (a.isEmpty() || AllZoneUtil.isCardInPlay("Mirror Gallery")) { return; } while (!a.isEmpty()) { CardList b = AllZoneUtil.getCardsIn(ZoneType.Battlefield, a.get(0).getName()); - b = b.getType("Legendary"); + b = CardListUtil.getType(b, "Legendary"); b = b.filter(new Predicate() { @Override public boolean apply(final Card c) { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java index 7db4e2c872c..2bd1fc1f575 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryAttach.java @@ -502,7 +502,7 @@ public class AbilityFactoryAttach { public static Card attachAIAnimatePreference(final SpellAbility sa, final CardList list, final boolean mandatory, final Card attachSource) { // AI For choosing a Card to Animate. - CardList betterList = list.getNotType("Creature"); + CardList betterList = CardListUtil.getNotType(list, "Creature"); if (sa.getSourceCard().getName().equals("Animate Artifact")) { betterList = betterList.filter(new Predicate() { @Override @@ -961,7 +961,7 @@ public class AbilityFactoryAttach { } } - list = list.getNotType(type); // Filter out Basic Lands that have the + list = CardListUtil.getNotType(list, type); // Filter out Basic Lands that have the // same type as the changing type final Card c = CardFactoryUtil.getBestAI(list); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java index eee6551da05..c39b17cfef7 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChangeZone.java @@ -1207,7 +1207,7 @@ public final class AbilityFactoryChangeZone { } else if (origin.contains(ZoneType.Library) && (type.contains("Basic") || AbilityFactoryChangeZone.areAllBasics(type))) { c = AbilityFactoryChangeZone.basicManaFixing(fetchList); - } else if (ZoneType.Hand.equals(destination) && fetchList.getNotType("Creature").size() == 0) { + } else if (ZoneType.Hand.equals(destination) && CardListUtil.getNotType(fetchList, "Creature").size() == 0) { c = AbilityFactoryChangeZone.chooseCreature(fetchList); } else if (ZoneType.Battlefield.equals(destination) || ZoneType.Graveyard.equals(destination)) { c = CardFactoryUtil.getBestAI(fetchList); @@ -1233,7 +1233,7 @@ public final class AbilityFactoryChangeZone { } if (c == null) { System.out.println("Don't need a land or none available; trying for a creature."); - fetchList = fetchList.getNotType("Land"); + fetchList = CardListUtil.getNotType(fetchList, "Land"); // Prefer to pull a creature, generally more useful for AI. c = chooseCreature(fetchList.filter(CardPredicates.Presets.CREATURES)); } @@ -1365,7 +1365,7 @@ public final class AbilityFactoryChangeZone { // what types can I go get? for (final String name : Constant.Color.BASIC_LANDS) { - if (!list.getType(name).isEmpty()) { + if (!CardListUtil.getType(list, name).isEmpty()) { basics.add(name); } } @@ -1377,7 +1377,7 @@ public final class AbilityFactoryChangeZone { for (int i = 0; i < basics.size(); i++) { final String b = basics.get(i); - final int num = combined.getType(b).size(); + final int num = CardListUtil.getType(combined, b).size(); if (num < minSize) { minType = b; minSize = num; @@ -1386,7 +1386,7 @@ public final class AbilityFactoryChangeZone { List result = list; if (minType != null) { - result = list.getType(minType); + result = CardListUtil.getType(list, minType); } return result.get(0); @@ -1791,7 +1791,7 @@ public final class AbilityFactoryChangeZone { choice = mostExpensive; } } else if (destination.equals(ZoneType.Hand) || destination.equals(ZoneType.Library)) { - CardList nonLands = list.getNotType("Land"); + CardList nonLands = CardListUtil.getNotType(list, "Land"); // Prefer to pull a creature, generally more useful for AI. choice = chooseCreature(nonLands.filter(CardPredicates.Presets.CREATURES)); if (choice == null) { // Could not find a creature. @@ -1904,7 +1904,7 @@ public final class AbilityFactoryChangeZone { } else if (destination.equals(ZoneType.Battlefield) || origin.equals(ZoneType.Battlefield)) { choice = CardFactoryUtil.getMostExpensivePermanentAI(list, sa, false); } else if (destination.equals(ZoneType.Hand) || destination.equals(ZoneType.Library)) { - CardList nonLands = list.getNotType("Land"); + CardList nonLands = CardListUtil.getNotType(list, "Land"); // Prefer to pull a creature, generally more useful for AI. choice = chooseCreature(nonLands.filter(CardPredicates.Presets.CREATURES)); if (choice == null) { // Could not find a creature. @@ -2607,7 +2607,7 @@ public final class AbilityFactoryChangeZone { tgt.addTarget(AllZone.getHumanPlayer()); computerType.clear(); } - if ((humanType.getNotType("Creature").size() == 0) && (computerType.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanType, "Creature").size() == 0) && (CardListUtil.getNotType(computerType, "Creature").size() == 0)) { if ((CardFactoryUtil.evaluateCreatureList(computerType) + 200) >= CardFactoryUtil .evaluateCreatureList(humanType)) { return false; @@ -2645,7 +2645,7 @@ public final class AbilityFactoryChangeZone { if (destination.equals(ZoneType.Battlefield)) { if (params.get("GainControl") != null) { // Check if the cards are valuable enough - if ((humanType.getNotType("Creature").size() == 0) && (computerType.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanType, "Creature").size() == 0) && (CardListUtil.getNotType(computerType, "Creature").size() == 0)) { if ((CardFactoryUtil.evaluateCreatureList(computerType) + CardFactoryUtil .evaluateCreatureList(humanType)) < 400) { return false; @@ -2658,7 +2658,7 @@ public final class AbilityFactoryChangeZone { } } else { // don't activate if human gets more back than AI does - if ((humanType.getNotType("Creature").size() == 0) && (computerType.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanType, "Creature").size() == 0) && (CardListUtil.getNotType(computerType, "Creature").size() == 0)) { if (CardFactoryUtil.evaluateCreatureList(computerType) <= (CardFactoryUtil .evaluateCreatureList(humanType) + 100)) { return false; @@ -2761,7 +2761,7 @@ public final class AbilityFactoryChangeZone { // if the AI is using it defensively, then something else needs to occur // if only creatures are affected evaluate both lists and pass only // if human creatures are more valuable - if ((humanType.getNotType("Creature").isEmpty()) && (computerType.getNotType("Creature").isEmpty())) { + if ((CardListUtil.getNotType(humanType, "Creature").isEmpty()) && (CardListUtil.getNotType(computerType, "Creature").isEmpty())) { if (CardFactoryUtil.evaluateCreatureList(computerType) >= CardFactoryUtil .evaluateCreatureList(humanType)) { return false; @@ -2795,7 +2795,7 @@ public final class AbilityFactoryChangeZone { if (destination.equals(ZoneType.Battlefield)) { if (params.get("GainControl") != null) { // Check if the cards are valuable enough - if ((humanType.getNotType("Creature").size() == 0) && (computerType.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanType, "Creature").size() == 0) && (CardListUtil.getNotType(computerType, "Creature").size() == 0)) { if ((CardFactoryUtil.evaluateCreatureList(computerType) + CardFactoryUtil .evaluateCreatureList(humanType)) < 1) { return false; @@ -2808,7 +2808,7 @@ public final class AbilityFactoryChangeZone { } } else { // don't activate if human gets more back than AI does - if ((humanType.getNotType("Creature").isEmpty()) && (computerType.getNotType("Creature").isEmpty())) { + if ((CardListUtil.getNotType(humanType, "Creature").isEmpty()) && (CardListUtil.getNotType(computerType, "Creature").isEmpty())) { if (CardFactoryUtil.evaluateCreatureList(computerType) <= CardFactoryUtil .evaluateCreatureList(humanType)) { return false; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java index 9d21fc46e5c..c6bf5bb46e3 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryChoose.java @@ -1947,7 +1947,7 @@ public final class AbilityFactoryChoose { final ArrayList basic = CardUtil.getBasicTypes(); for (final String type : basic) { - final CardList cl = land.getType(type); + final CardList cl = CardListUtil.getType(land, type); if (cl.size() > 0) { final String prompt = "Choose a" + (type.equals("Island") ? "n " : " ") + type; final Object o = GuiChoose.one(prompt, cl); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryClash.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryClash.java index 3f0c8dc1ff0..cd3df97ff50 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryClash.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryClash.java @@ -901,7 +901,7 @@ public final class AbilityFactoryClash { } else { int cmc1 = CardFactoryUtil.evaluatePermanentList(new CardList(pile1)); int cmc2 = CardFactoryUtil.evaluatePermanentList(new CardList(pile2)); - if (pool.getNotType("Creature").isEmpty()) { + if (CardListUtil.getNotType(pool, "Creature").isEmpty()) { cmc1 = CardFactoryUtil.evaluateCreatureList(new CardList(pile1)); cmc2 = CardFactoryUtil.evaluateCreatureList(new CardList(pile2)); System.out.println("value:" + cmc1 + " " + cmc2); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java index b59e693f2d3..e6cbcdec077 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDealDamage.java @@ -1255,7 +1255,7 @@ public class AbilityFactoryDealDamage { } }; - list = list.getNotKeyword("Indestructible"); + list = CardListUtil.getNotKeyword(list, "Indestructible"); list = list.filter(filterKillable); return list; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java index aca6179e232..49e776c8b3d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDebuff.java @@ -501,7 +501,7 @@ public final class AbilityFactoryDebuff { } Card c; - if (pref.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(pref, "Creature").size() == 0) { c = CardFactoryUtil.getBestCreatureAI(pref); } else { c = CardFactoryUtil.getMostExpensivePermanentAI(pref, sa, true); @@ -520,7 +520,7 @@ public final class AbilityFactoryDebuff { // TODO - if forced targeting, just pick something without the given // keyword Card c; - if (forced.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(forced, "Creature").size() == 0) { c = CardFactoryUtil.getWorstCreatureAI(forced); } else { c = CardFactoryUtil.getCheapestPermanentAI(forced, sa, true); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java index dfa7140e879..f8f736950b4 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryDestroy.java @@ -253,7 +253,7 @@ public class AbilityFactoryDestroy { if (params.containsKey("AITgts")) { list = CardListUtil.getValidCards(list, params.get("AITgts"), sa.getActivatingPlayer(), source); } - list = list.getNotKeyword("Indestructible"); + list = CardListUtil.getNotKeyword(list, "Indestructible"); if (!AbilityFactory.playReusable(sa)) { list = list.filter(new Predicate() { @Override @@ -294,9 +294,9 @@ public class AbilityFactoryDestroy { Card choice = null; // If the targets are only of one type, take the best - if (list.getNotType("Creature").isEmpty()) { + if (CardListUtil.getNotType(list, "Creature").isEmpty()) { choice = CardFactoryUtil.getBestCreatureAI(list); - } else if (list.getNotType("Land").isEmpty()) { + } else if (CardListUtil.getNotType(list, "Land").isEmpty()) { choice = CardFactoryUtil.getBestLandAI(list); } else { choice = CardFactoryUtil.getMostExpensivePermanentAI(list, sa, true); @@ -320,7 +320,7 @@ public class AbilityFactoryDestroy { list = new CardList(AbilityFactory.getDefinedCards(af.getHostCard(), params.get("Defined"), sa)); if (list.isEmpty() || !CardListUtil.filterControlledBy(list, AllZone.getComputerPlayer()).isEmpty() - || list.getNotKeyword("Indestructible").isEmpty()) { + || CardListUtil.getNotKeyword(list, "Indestructible").isEmpty()) { return false; } } @@ -387,7 +387,7 @@ public class AbilityFactoryDestroy { tgt.resetTargets(); - CardList preferred = list.getNotKeyword("Indestructible"); + CardList preferred = CardListUtil.getNotKeyword(list, "Indestructible"); preferred = CardListUtil.filterControlledBy(preferred, AllZone.getHumanPlayer()); // If NoRegen is not set, filter out creatures that have a @@ -422,9 +422,9 @@ public class AbilityFactoryDestroy { } } else { Card c; - if (preferred.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(preferred, "Creature").size() == 0) { c = CardFactoryUtil.getBestCreatureAI(preferred); - } else if (preferred.getNotType("Land").size() == 0) { + } else if (CardListUtil.getNotType(preferred, "Land").size() == 0) { c = CardFactoryUtil.getBestLandAI(preferred); } else { c = CardFactoryUtil.getMostExpensivePermanentAI(preferred, sa, false); @@ -439,7 +439,7 @@ public class AbilityFactoryDestroy { break; } else { Card c; - if (list.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(list, "Creature").size() == 0) { c = CardFactoryUtil.getWorstCreatureAI(list); } else { c = CardFactoryUtil.getCheapestPermanentAI(list, sa, false); @@ -881,7 +881,7 @@ public class AbilityFactoryDestroy { // if only creatures are affected evaluate both lists and pass only if // human creatures are more valuable - if ((humanlist.getNotType("Creature").size() == 0) && (computerlist.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanlist, "Creature").size() == 0) && (CardListUtil.getNotType(computerlist, "Creature").size() == 0)) { if (CardFactoryUtil.evaluateCreatureList(computerlist) >= CardFactoryUtil.evaluateCreatureList(humanlist) && !computerlist.isEmpty()) { return false; @@ -972,13 +972,13 @@ public class AbilityFactoryDestroy { // if only creatures are affected evaluate both lists and pass only if // human creatures are more valuable - if ((humanlist.getNotType("Creature").size() == 0) && (computerlist.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanlist, "Creature").size() == 0) && (CardListUtil.getNotType(computerlist, "Creature").size() == 0)) { if ((CardFactoryUtil.evaluateCreatureList(computerlist) + 200) >= CardFactoryUtil .evaluateCreatureList(humanlist)) { return false; } } // only lands involved - else if ((humanlist.getNotType("Land").size() == 0) && (computerlist.getNotType("Land").size() == 0)) { + else if ((CardListUtil.getNotType(humanlist, "Land").size() == 0) && (CardListUtil.getNotType(computerlist, "Land").size() == 0)) { if ((CardFactoryUtil.evaluatePermanentList(computerlist) + 1) >= CardFactoryUtil .evaluatePermanentList(humanlist)) { return false; diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java index f4517e05212..fcf076e0370 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPermanentState.java @@ -431,7 +431,7 @@ public class AbilityFactoryPermanentState { } } - if (untapList.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(untapList, "Creature").size() == 0) { choice = CardFactoryUtil.getBestCreatureAI(untapList); // if // only // creatures @@ -551,7 +551,7 @@ public class AbilityFactoryPermanentState { } } - if (tapList.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(tapList, "Creature").size() == 0) { choice = CardFactoryUtil.getBestCreatureAI(tapList); // if only // creatures // take @@ -638,7 +638,7 @@ public class AbilityFactoryPermanentState { AllZone.getInputControl().setInput(CardFactoryUtil.inputUntapUpToNType(num, valid)); } else { CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); - list = list.getType(valid); + list = CardListUtil.getType(list, valid); list = list.filter(Presets.TAPPED); int count = 0; @@ -1191,7 +1191,7 @@ public class AbilityFactoryPermanentState { } } - if (tapList.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(tapList, "Creature").size() == 0) { // if only creatures take the best choice = CardFactoryUtil.getBestCreatureAI(tapList); } else { diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java index c8551c430e8..092486bfd6e 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryProtection.java @@ -508,7 +508,7 @@ public final class AbilityFactoryProtection { } Card c; - if (pref.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(pref, "Creature").size() == 0) { c = CardFactoryUtil.getBestCreatureAI(pref); } else { c = CardFactoryUtil.getMostExpensivePermanentAI(pref, sa, true); @@ -525,7 +525,7 @@ public final class AbilityFactoryProtection { } Card c; - if (pref2.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(pref2, "Creature").size() == 0) { c = CardFactoryUtil.getBestCreatureAI(pref2); } else { c = CardFactoryUtil.getMostExpensivePermanentAI(pref2, sa, true); @@ -542,7 +542,7 @@ public final class AbilityFactoryProtection { } Card c; - if (forced.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(forced, "Creature").size() == 0) { c = CardFactoryUtil.getWorstCreatureAI(forced); } else { c = CardFactoryUtil.getCheapestPermanentAI(forced, sa, true); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java index 9291d5d83fb..2d3f3df704c 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryPump.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Random; import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; import forge.AllZone; import forge.AllZoneUtil; @@ -347,7 +349,7 @@ public class AbilityFactoryPump { || card.getNetCombatDamage() <= 0 || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY) || ph.getPhase().isBefore(PhaseType.MAIN1) - || AllZoneUtil.getCreaturesInPlay(computer).getNotKeyword("Defender").isEmpty())) { + || CardListUtil.getNotKeyword(AllZoneUtil.getCreaturesInPlay(computer), "Defender").isEmpty())) { return false; } if (ph.isPlayerTurn(human) && (!card.isAttacking() @@ -405,22 +407,22 @@ public class AbilityFactoryPump { } else if (keyword.endsWith("Flying")) { if (ph.isPlayerTurn(human) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) - && !AllZone.getCombat().getAttackerList().getKeyword("Flying").isEmpty() + && !CardListUtil.getKeyword(AllZone.getCombat().getAttackerList(), "Flying").isEmpty() && !card.hasKeyword("Reach") && CombatUtil.canBlock(card) && CombatUtil.lifeInDanger(AllZone.getCombat())) { return true; } + Predicate flyingOrReach = Predicates.or(CardPredicates.hasKeyword("Flying"), CardPredicates.hasKeyword("Reach")); if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) - || card.getNetCombatDamage() <= 0 - || cardsCanBlock.getNotKeyword("Flying").getNotKeyword("Reach").isEmpty()) { + || card.getNetCombatDamage() <= 0 || !Iterables.any(cardsCanBlock, Predicates.not(flyingOrReach))) { return false; } } else if (keyword.endsWith("Horsemanship")) { if (ph.isPlayerTurn(human) && ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) - && !AllZone.getCombat().getAttackerList().getKeyword("Horsemanship").isEmpty() + && !CardListUtil.getKeyword(AllZone.getCombat().getAttackerList(), "Horsemanship").isEmpty() && CombatUtil.canBlock(card) && CombatUtil.lifeInDanger(AllZone.getCombat())) { return true; @@ -428,7 +430,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || cardsCanBlock.getNotKeyword("Horsemanship").isEmpty()) { + || CardListUtil.getNotKeyword(cardsCanBlock, "Horsemanship").isEmpty()) { return false; } } else if (keyword.endsWith("Haste")) { @@ -484,7 +486,7 @@ public class AbilityFactoryPump { } else if (keyword.startsWith("Flanking")) { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) - || cardsCanBlock.getNotKeyword("Flanking").isEmpty()) { + || CardListUtil.getNotKeyword(cardsCanBlock, "Flanking").isEmpty()) { return false; } } else if (keyword.startsWith("Trample")) { @@ -528,13 +530,13 @@ public class AbilityFactoryPump { } else if (keyword.equals("Vigilance")) { if (ph.isPlayerTurn(human) || !CombatUtil.canAttack(card) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS) - || AllZoneUtil.getCreaturesInPlay(human).getNotKeyword("Defender").size() < 1) { + || CardListUtil.getNotKeyword(AllZoneUtil.getCreaturesInPlay(human), "Defender").size() < 1) { return false; } } else if (keyword.equals("Reach")) { if (ph.isPlayerTurn(computer) || !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) - || AllZone.getCombat().getAttackerList().getKeyword("Flying").isEmpty() + || CardListUtil.getKeyword(AllZone.getCombat().getAttackerList(), "Flying").isEmpty() || card.hasKeyword("Flying") || !CombatUtil.canBlock(card)) { return false; @@ -565,7 +567,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || AllZoneUtil.getPlayerLandsInPlay(human).getType("Island").isEmpty() + || CardListUtil.getType(AllZoneUtil.getPlayerLandsInPlay(human), "Island").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -573,7 +575,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || AllZoneUtil.getPlayerLandsInPlay(human).getType("Swamp").isEmpty() + || CardListUtil.getType(AllZoneUtil.getPlayerLandsInPlay(human), "Swamp").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -581,7 +583,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || AllZoneUtil.getPlayerLandsInPlay(human).getType("Mountain").isEmpty() + || CardListUtil.getType(AllZoneUtil.getPlayerLandsInPlay(human), "Mountain").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -589,7 +591,7 @@ public class AbilityFactoryPump { if (ph.isPlayerTurn(human) || !(CombatUtil.canAttack(card) || card.isAttacking()) || ph.getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) || card.getNetCombatDamage() <= 0 - || AllZoneUtil.getPlayerLandsInPlay(human).getType("Forest").isEmpty() + || CardListUtil.getType(AllZoneUtil.getPlayerLandsInPlay(human), "Forest").isEmpty() || cardsCanBlock.isEmpty()) { return false; } @@ -1088,7 +1090,7 @@ public class AbilityFactoryPump { } Card c; - if (pref.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(pref, "Creature").size() == 0) { c = CardFactoryUtil.getBestCreatureAI(pref); } else { c = CardFactoryUtil.getMostExpensivePermanentAI(pref, sa, true); @@ -1105,7 +1107,7 @@ public class AbilityFactoryPump { } Card c; - if (forced.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(forced, "Creature").size() == 0) { c = CardFactoryUtil.getWorstCreatureAI(forced); } else { c = CardFactoryUtil.getCheapestPermanentAI(forced, sa, true); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java index 170002dacab..44472e3359d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryRegenerate.java @@ -445,7 +445,7 @@ public class AbilityFactoryRegenerate { // can target // choose my best X without regen - if (compTargetables.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(compTargetables, "Creature").size() == 0) { for (final Card c : combatants) { if (c.getShield() == 0) { tgt.addTarget(c); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java b/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java index c5dbaeb6e68..fc0b769d68d 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactorySacrifice.java @@ -865,13 +865,13 @@ public class AbilityFactorySacrifice { // if only creatures are affected evaluate both lists and pass only if // human creatures are more valuable - if ((humanlist.getNotType("Creature").size() == 0) && (computerlist.getNotType("Creature").size() == 0)) { + if ((CardListUtil.getNotType(humanlist, "Creature").size() == 0) && (CardListUtil.getNotType(computerlist, "Creature").size() == 0)) { if ((CardFactoryUtil.evaluateCreatureList(computerlist) + 200) >= CardFactoryUtil .evaluateCreatureList(humanlist)) { return false; } } // only lands involved - else if ((humanlist.getNotType("Land").size() == 0) && (computerlist.getNotType("Land").size() == 0)) { + else if ((CardListUtil.getNotType(humanlist, "Land").size() == 0) && (CardListUtil.getNotType(computerlist, "Land").size() == 0)) { if ((CardFactoryUtil.evaluatePermanentList(computerlist) + 1) >= CardFactoryUtil .evaluatePermanentList(humanlist)) { return false; diff --git a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java index 2fd3c7e52b0..36c035a2753 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryAuras.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryAuras.java @@ -113,7 +113,7 @@ class CardFactoryAuras { newType[0] = landTypes[minAt]; CardList list = AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()); - list = list.getNotType(newType[0]); // Don't enchant lands + list = CardListUtil.getNotType(list, newType[0]); // Don't enchant lands // that already have the // type if (list.isEmpty()) { @@ -266,7 +266,7 @@ class CardFactoryAuras { @Override public boolean canPlayAI() { CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); - list = list.getKeyword("Flying"); + list = CardListUtil.getKeyword(list, "Flying"); if (list.isEmpty()) { return false; } diff --git a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java index 49f8f9466fe..fa1b07d5a00 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryCreatures.java @@ -546,7 +546,7 @@ public class CardFactoryCreatures { @Override public boolean canPlayAI() { - List wolves = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Wolf"); + List wolves = CardListUtil.getType(AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield), "Wolf"); Iterable untappedWolves = Iterables.filter(wolves, untappedCreature); final int totalPower = Aggregates.sum(untappedWolves, CardPredicates.Accessors.fnGetNetAttack); @@ -575,7 +575,7 @@ public class CardFactoryCreatures { @Override public void resolve() { - CardList wolves = card.getController().getCardsIn(ZoneType.Battlefield).getType("Wolf"); + CardList wolves = CardListUtil.getType(card.getController().getCardsIn(ZoneType.Battlefield), "Wolf"); wolves = wolves.filter(untappedCreature); final Card target = this.getTargetCard(); diff --git a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java index 2e855a69a91..1d799a188a9 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryEnchantments.java @@ -4,6 +4,7 @@ import forge.AllZone; import forge.AllZoneUtil; import forge.Card; import forge.CardList; +import forge.CardListUtil; import forge.Command; import forge.GameActionUtil; import forge.Singletons; @@ -69,7 +70,7 @@ class CardFactoryEnchantments { public boolean canPlay() { final CardList grave = AllZone.getHumanPlayer().getCardsIn(ZoneType.Graveyard); final CardList aiGrave = AllZone.getComputerPlayer().getCardsIn(ZoneType.Graveyard); - return ((grave.getType("Creature").size() > 1) || (aiGrave.getType("Creature").size() > 1)) + return ((CardListUtil.getType(grave, "Creature").size() > 1) || (CardListUtil.getType(aiGrave, "Creature").size() > 1)) && super.canPlay(); } }; diff --git a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java index 9840570d5cc..57742c76ed1 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryInstants.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryInstants.java @@ -26,6 +26,7 @@ import forge.AllZone; import forge.AllZoneUtil; import forge.Card; import forge.CardList; +import forge.CardListUtil; import forge.CardPredicates; import forge.CardPredicates.Presets; import forge.Command; @@ -479,7 +480,7 @@ public class CardFactoryInstants { final String[] choices = new String[] { "Artifact", "Creature", "Land" }; final Object o = GuiChoose.one("Select permanent type", choices); final String cardType = (String) o; - final CardList list = this.getTargetPlayer().getCardsIn(ZoneType.Battlefield).getType(cardType); + final CardList list = CardListUtil.getType(this.getTargetPlayer().getCardsIn(ZoneType.Battlefield), cardType); final String[] tapOrUntap = new String[] { "Tap", "Untap" }; final Object z = GuiChoose.one("Tap or Untap?", tapOrUntap); diff --git a/src/main/java/forge/card/cardfactory/CardFactoryLands.java b/src/main/java/forge/card/cardfactory/CardFactoryLands.java index e5fc4ef17ca..c94a9e3ce35 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryLands.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryLands.java @@ -488,7 +488,7 @@ class CardFactoryLands { public void computerExecute() { CardList hand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand); - hand = hand.getType(type); + hand = CardListUtil.getType(hand, type); if (hand.size() > 0) { this.revealCard(hand.get(0)); } else { diff --git a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java index 8e5f4cdb023..645eb60e762 100644 --- a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java +++ b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java @@ -356,7 +356,7 @@ public class CardFactorySorceries { CardList land = AllZoneUtil.getPlayerLandsInPlay(AllZone.getComputerPlayer()); for (final String element : Constant.Color.BASIC_LANDS) { - final CardList cl = land.getType(element); + final CardList cl = CardListUtil.getType(land, element); if (!cl.isEmpty()) { // remove one land of this basic type from this list // the computer AI should really jump in here and @@ -438,7 +438,7 @@ public class CardFactorySorceries { // get all other basic[count] lands human player // controls and add them to target CardList land = AllZoneUtil.getPlayerLandsInPlay(AllZone.getHumanPlayer()); - CardList cl = land.getType(humanBasic.get(this.count)); + CardList cl = CardListUtil.getType(land, humanBasic.get(this.count)); cl = cl.filter(new Predicate() { @Override public boolean apply(final Card crd) { @@ -488,7 +488,7 @@ public class CardFactorySorceries { final CardList land = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield); for (final String element : Constant.Color.BASIC_LANDS) { - final CardList c = land.getType(element); + final CardList c = CardListUtil.getType(land, element); if (!c.isEmpty()) { humanBasic.add(element); countBase[0]++; diff --git a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java index 9602350fe0c..71ae55c5926 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryUtil.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryUtil.java @@ -247,7 +247,7 @@ public class CardFactoryUtil { // lands of one type.... int n = 0; for (String name : Constant.Color.BASIC_LANDS) { - n = land.getType(name).size(); + n = CardListUtil.getType(land, name).size(); if ((n < iminBL) && (n > 0)) { // if two or more are tied, only the // first @@ -260,7 +260,7 @@ public class CardFactoryUtil { return null; // no basic land was a minimum } - final CardList bLand = land.getType(sminBL); + final CardList bLand = CardListUtil.getType(land, sminBL); for( Card ut : Iterables.filter(bLand, CardPredicates.Presets.UNTAPPED) ) { @@ -590,11 +590,11 @@ public class CardFactoryUtil { public static Card getBestAI(final CardList list) { // Get Best will filter by appropriate getBest list if ALL of the list // is of that type - if (list.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(list, "Creature").size() == 0) { return CardFactoryUtil.getBestCreatureAI(list); } - if (list.getNotType("Land").size() == 0) { + if (CardListUtil.getNotType(list, "Land").size() == 0) { return CardFactoryUtil.getBestLandAI(list); } @@ -726,7 +726,7 @@ public class CardFactoryUtil { return CardFactoryUtil.getWorstLand(lands); } - if ((list.getType("Artifact").size() > 0) || (list.getType("Enchantment").size() > 0)) { + if ((CardListUtil.getType(list, "Artifact").size() > 0) || (CardListUtil.getType(list, "Enchantment").size() > 0)) { return CardFactoryUtil.getCheapestPermanentAI(list.filter(new Predicate() { @Override public boolean apply(final Card c) { @@ -735,8 +735,8 @@ public class CardFactoryUtil { }), null, false); } - if (list.getType("Creature").size() > 0) { - return CardFactoryUtil.getWorstCreatureAI(list.getType("Creature")); + if (CardListUtil.getType(list, "Creature").size() > 0) { + return CardFactoryUtil.getWorstCreatureAI(CardListUtil.getType(list, "Creature")); } // Planeswalkers fall through to here, lands will fall through if there @@ -2025,7 +2025,7 @@ public class CardFactoryUtil { final String[] basic = { "Forest", "Plains", "Mountain", "Island", "Swamp" }; for (int i = 0; i < basic.length; i++) { - if (!someCards.getType(basic[i]).isEmpty()) { + if (!CardListUtil.getType(someCards, basic[i]).isEmpty()) { n++; } } @@ -2045,7 +2045,7 @@ public class CardFactoryUtil { } if (sq[0].contains("LandsInGraveyard")) { if (players.size() > 0) { - return CardFactoryUtil.doXMath(players.get(0).getCardsIn(ZoneType.Graveyard).getType("Land").size(), m, + return CardFactoryUtil.doXMath(CardListUtil.getType(players.get(0).getCardsIn(ZoneType.Graveyard), "Land").size(), m, source); } } @@ -2353,7 +2353,7 @@ public class CardFactoryUtil { if (sq[0].contains("Domain")) { someCards.addAll(cardController.getCardsIn(ZoneType.Battlefield)); for (String basic : Constant.Color.BASIC_LANDS) { - if (!someCards.getType(basic).isEmpty()) { + if (!CardListUtil.getType(someCards, basic).isEmpty()) { n++; } } @@ -2364,7 +2364,7 @@ public class CardFactoryUtil { if (sq[0].contains("OpponentDom")) { someCards.addAll(cardController.getOpponent().getCardsIn(ZoneType.Battlefield)); for (String basic : Constant.Color.BASIC_LANDS) { - if (!someCards.getType(basic).isEmpty()) { + if (!CardListUtil.getType(someCards, basic).isEmpty()) { n++; } } @@ -2493,7 +2493,7 @@ public class CardFactoryUtil { CardList enchantedControllerInPlay = new CardList(); if (c.getEnchantingCard() != null) { enchantedControllerInPlay = c.getEnchantingCard().getController().getCardsIn(ZoneType.Battlefield); - enchantedControllerInPlay = enchantedControllerInPlay.getType("Creature"); + enchantedControllerInPlay = CardListUtil.getType(enchantedControllerInPlay, "Creature"); } return enchantedControllerInPlay.size(); } @@ -4695,7 +4695,7 @@ public class CardFactoryUtil { @Override public void execute() { - final CardList cardsInPlay = AllZoneUtil.getCardsIn(ZoneType.Battlefield).getType("World"); + final CardList cardsInPlay = CardListUtil.getType(AllZoneUtil.getCardsIn(ZoneType.Battlefield), "World"); cardsInPlay.remove(card); for (int i = 0; i < cardsInPlay.size(); i++) { Singletons.getModel().getGameAction().sacrificeDestroy(cardsInPlay.get(i)); diff --git a/src/main/java/forge/card/cost/CostSacrifice.java b/src/main/java/forge/card/cost/CostSacrifice.java index 9b744910d3b..c9762269a42 100644 --- a/src/main/java/forge/card/cost/CostSacrifice.java +++ b/src/main/java/forge/card/cost/CostSacrifice.java @@ -106,7 +106,7 @@ public class CostSacrifice extends CostPartWithList { final Integer amount = this.convertAmount(); if (activator.hasKeyword("You can't sacrifice creatures to cast spells or activate abilities.")) { - typeList = typeList.getNotType("Creature"); + typeList = CardListUtil.getNotType(typeList, "Creature"); } if ((amount != null) && (typeList.size() < amount)) { @@ -158,7 +158,7 @@ public class CostSacrifice extends CostPartWithList { CardList list = activator.getCardsIn(ZoneType.Battlefield); list = CardListUtil.getValidCards(list, type.split(";"), activator, source); if (activator.hasKeyword("You can't sacrifice creatures to cast spells or activate abilities.")) { - list = list.getNotType("Creature"); + list = CardListUtil.getNotType(list, "Creature"); } if (this.getThis()) { @@ -206,7 +206,7 @@ public class CostSacrifice extends CostPartWithList { CardList typeList = activator.getCardsIn(ZoneType.Battlefield); typeList = CardListUtil.getValidCards(typeList, this.getType().split(";"), activator, source); if (activator.hasKeyword("You can't sacrifice creatures to cast spells or activate abilities.")) { - typeList = typeList.getNotType("Creature"); + typeList = CardListUtil.getNotType(typeList, "Creature"); } // Does the AI want to use Sacrifice All? return false; diff --git a/src/main/java/forge/card/spellability/SpellPermanent.java b/src/main/java/forge/card/spellability/SpellPermanent.java index 2f3049efa51..debf123f554 100644 --- a/src/main/java/forge/card/spellability/SpellPermanent.java +++ b/src/main/java/forge/card/spellability/SpellPermanent.java @@ -362,7 +362,7 @@ public class SpellPermanent extends Spell { for (int i = 0; i < list.size(); i++) { List type = card.getType(); final String subtype = type.get(type.size() - 1); - final CardList cl = list.getType(subtype); + final CardList cl = CardListUtil.getType(list, subtype); if (cl.size() > 0) { return false; @@ -371,7 +371,7 @@ public class SpellPermanent extends Spell { } if (card.isType("World")) { CardList list = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield); - list = list.getType("World"); + list = CardListUtil.getType(list, "World"); if (list.size() > 0) { return false; } diff --git a/src/main/java/forge/game/phase/CombatUtil.java b/src/main/java/forge/game/phase/CombatUtil.java index c4d86e699af..f9d87c96c46 100644 --- a/src/main/java/forge/game/phase/CombatUtil.java +++ b/src/main/java/forge/game/phase/CombatUtil.java @@ -908,22 +908,22 @@ public class CombatUtil { } else if (keyword.equals("Defender") && !c.hasKeyword("CARDNAME can attack as though it didn't have defender.")) { return false; } else if (keyword.equals("CARDNAME can't attack unless defending player controls an Island.")) { - temp = list.getType("Island"); + temp = CardListUtil.getType(list, "Island"); if (temp.isEmpty()) { return false; } } else if (keyword.equals("CARDNAME can't attack unless defending player controls a Forest.")) { - temp = list.getType("Forest"); + temp = CardListUtil.getType(list, "Forest"); if (temp.isEmpty()) { return false; } } else if (keyword.equals("CARDNAME can't attack unless defending player controls a Swamp.")) { - temp = list.getType("Swamp"); + temp = CardListUtil.getType(list, "Swamp"); if (temp.isEmpty()) { return false; } } else if (keyword.equals("CARDNAME can't attack unless defending player controls a Mountain.")) { - temp = list.getType("Mountain"); + temp = CardListUtil.getType(list, "Mountain"); if (temp.isEmpty()) { return false; } diff --git a/src/main/java/forge/game/phase/Upkeep.java b/src/main/java/forge/game/phase/Upkeep.java index bed890486ab..f2c445e448a 100644 --- a/src/main/java/forge/game/phase/Upkeep.java +++ b/src/main/java/forge/game/phase/Upkeep.java @@ -517,7 +517,7 @@ public class Upkeep extends Phase implements java.io.Serializable { } } else { // computer - final CardList indestruct = targets.getKeyword("Indestructible"); + final CardList indestruct = CardListUtil.getKeyword(targets, "Indestructible"); if (indestruct.size() > 0) { Singletons.getModel().getGameAction().destroyNoRegeneration(indestruct.get(0)); } else if (targets.size() > 0) { @@ -1216,11 +1216,11 @@ public class Upkeep extends Phase implements java.io.Serializable { CardList humanCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); humanCreatures = CardListUtil.getValidCards(humanCreatures, smallCreatures, k.getController(), k); - humanCreatures = humanCreatures.getNotKeyword("Indestructible"); + humanCreatures = CardListUtil.getNotKeyword(humanCreatures, "Indestructible"); CardList computerCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getComputerPlayer()); computerCreatures = CardListUtil.getValidCards(computerCreatures, smallCreatures, k.getController(), k); - computerCreatures = computerCreatures.getNotKeyword("Indestructible"); + computerCreatures = CardListUtil.getNotKeyword(computerCreatures, "Indestructible"); // We assume that both players will want to peek, ask if // they want to reveal. @@ -2065,7 +2065,7 @@ public class Upkeep extends Phase implements java.io.Serializable { private static void upkeepKarma() { final Player player = Singletons.getModel().getGameState().getPhaseHandler().getPlayerTurn(); final CardList karmas = AllZoneUtil.getCardsIn(ZoneType.Battlefield, "Karma"); - final CardList swamps = player.getCardsIn(ZoneType.Battlefield).getType("Swamp"); + final CardList swamps = CardListUtil.getType(player.getCardsIn(ZoneType.Battlefield), "Swamp"); // determine how much damage to deal the current player final int damage = swamps.size(); diff --git a/src/main/java/forge/game/player/AIPlayer.java b/src/main/java/forge/game/player/AIPlayer.java index e2327cc42e1..0c7738c1d02 100644 --- a/src/main/java/forge/game/player/AIPlayer.java +++ b/src/main/java/forge/game/player/AIPlayer.java @@ -179,7 +179,7 @@ public class AIPlayer extends Player { @Override public final void discardUnless(final int num, final String uType, final SpellAbility sa) { final CardList hand = this.getCardsIn(ZoneType.Hand); - final CardList tHand = hand.getType(uType); + final CardList tHand = CardListUtil.getType(hand, uType); if (tHand.size() > 0) { Card toDiscard = Aggregates.itemWithMin(tHand, CardPredicates.Accessors.fnGetCmc); diff --git a/src/main/java/forge/game/player/ComputerUtil.java b/src/main/java/forge/game/player/ComputerUtil.java index 9bf8964a0cb..071a6e073f8 100644 --- a/src/main/java/forge/game/player/ComputerUtil.java +++ b/src/main/java/forge/game/player/ComputerUtil.java @@ -1397,7 +1397,7 @@ public class ComputerUtil { // what types can I go get? for (final String name : Constant.CardTypes.BASIC_TYPES) { - if (!landList.getType(name).isEmpty()) { + if (!CardListUtil.getType(landList, name).isEmpty()) { basics.add(name); } } @@ -1409,7 +1409,7 @@ public class ComputerUtil { for (int i = 0; i < basics.size(); i++) { final String b = basics.get(i); - final int num = combined.getType(b).size(); + final int num = CardListUtil.getType(combined, b).size(); if (num < minSize) { minType = b; minSize = num; @@ -1417,7 +1417,7 @@ public class ComputerUtil { } if (minType != null) { - landList = landList.getType(minType); + landList = CardListUtil.getType(landList, minType); } land = landList.get(0); @@ -1491,10 +1491,10 @@ public class ComputerUtil { } // Discard lands - final CardList landsInHand = typeList.getType("Land"); + final CardList landsInHand = CardListUtil.getType(typeList, "Land"); if (!landsInHand.isEmpty()) { - final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).getType("Land"); - final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land"); + final CardList landsInPlay = CardListUtil.getType(AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield), "Land"); + final CardList nonLandsInHand = CardListUtil.getNotType(AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand), "Land"); final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc)); if (landsInPlay.size() >= highestCMC || (landsInPlay.size() + landsInHand.size() > 6 && landsInHand.size() > 1)) { @@ -1528,7 +1528,7 @@ public class ComputerUtil { CardList typeList = activator.getCardsIn(ZoneType.Battlefield); typeList = CardListUtil.getValidCards(typeList, type.split(";"), activate.getController(), activate); if (activator.hasKeyword("You can't sacrifice creatures to cast spells or activate abilities.")) { - typeList = typeList.getNotType("Creature"); + typeList = CardListUtil.getNotType(typeList, "Creature"); } if ((target != null) && target.getController().isComputer() && typeList.contains(target)) { @@ -2036,7 +2036,7 @@ public class ComputerUtil { Card c = null; if (destroy) { - final CardList indestructibles = list.getKeyword("Indestructible"); + final CardList indestructibles = CardListUtil.getKeyword(list, "Indestructible"); if (!indestructibles.isEmpty()) { c = indestructibles.get(0); } @@ -2052,9 +2052,9 @@ public class ComputerUtil { } if (c == null) { - if (list.getNotType("Creature").size() == 0) { + if (CardListUtil.getNotType(list, "Creature").size() == 0) { c = CardFactoryUtil.getWorstCreatureAI(list); - } else if (list.getNotType("Land").size() == 0) { + } else if (CardListUtil.getNotType(list, "Land").size() == 0) { c = CardFactoryUtil.getWorstLand(AllZone.getComputerPlayer()); } else { c = CardFactoryUtil.getWorstPermanentAI(list, false, false, false, false); @@ -2299,7 +2299,7 @@ public class ComputerUtil { } final CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield).filter(CardPredicates.Presets.LANDS); final CardList landsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).filter(CardPredicates.Presets.LANDS); - final CardList nonLandsInHand = AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand).getNotType("Land"); + final CardList nonLandsInHand = CardListUtil.getNotType(AllZone.getComputerPlayer().getCardsIn(ZoneType.Hand), "Land"); final int highestCMC = Math.max(6, Aggregates.max(nonLandsInHand, CardPredicates.Accessors.fnGetCmc)); final int discardCMC = discard.getCMC(); if (discard.isLand()) { diff --git a/src/main/java/forge/game/player/ComputerUtilBlock.java b/src/main/java/forge/game/player/ComputerUtilBlock.java index 85fecd1f412..6a682f351ed 100644 --- a/src/main/java/forge/game/player/ComputerUtilBlock.java +++ b/src/main/java/forge/game/player/ComputerUtilBlock.java @@ -597,7 +597,7 @@ public class ComputerUtilBlock { CardList chumpBlockers; - CardList tramplingAttackers = ComputerUtilBlock.getAttackers().getKeyword("Trample"); + CardList tramplingAttackers = CardListUtil.getKeyword(ComputerUtilBlock.getAttackers(), "Trample"); tramplingAttackers = tramplingAttackers.filter(Predicates.not(rampagesOrNeedsManyToBlock)); // TODO - should check here for a "rampage-like" trigger that replaced @@ -675,8 +675,8 @@ public class ComputerUtilBlock { // Don't use blockers without First Strike or Double Strike if // attacker has it if (attacker.hasKeyword("First Strike") || attacker.hasKeyword("Double Strike")) { - safeBlockers = blockers.getKeyword("First Strike"); - safeBlockers.addAll(blockers.getKeyword("Double Strike")); + safeBlockers = CardListUtil.getKeyword(blockers, "First Strike"); + safeBlockers.addAll(CardListUtil.getKeyword(blockers, "Double Strike")); } else { safeBlockers = new CardList(blockers); } @@ -884,7 +884,7 @@ public class ComputerUtilBlock { } // assign blockers that have to block - chumpBlockers = ComputerUtilBlock.getBlockersLeft().getKeyword("CARDNAME blocks each turn if able."); + chumpBlockers = CardListUtil.getKeyword(ComputerUtilBlock.getBlockersLeft(), "CARDNAME blocks each turn if able."); // if an attacker with lure attacks - all that can block for (final Card blocker : ComputerUtilBlock.getBlockersLeft()) { if (CombatUtil.mustBlockAnAttacker(blocker, combat)) { diff --git a/src/main/java/forge/game/player/PlayerUtil.java b/src/main/java/forge/game/player/PlayerUtil.java index f3fc996eae3..cc6bb5a6f13 100644 --- a/src/main/java/forge/game/player/PlayerUtil.java +++ b/src/main/java/forge/game/player/PlayerUtil.java @@ -22,6 +22,7 @@ import com.google.common.base.Predicate; import forge.AllZone; import forge.Card; import forge.CardList; +import forge.CardListUtil; import forge.Singletons; import forge.card.spellability.SpellAbility; import forge.control.input.Input; @@ -57,7 +58,7 @@ public final class PlayerUtil { public static boolean worshipFlag(final Player player) { // Instead of hardcoded Ali from Cairo like cards, it is now a Keyword CardList list = player.getCardsIn(ZoneType.Battlefield); - list = list.getKeyword("Damage that would reduce your life total to less than 1 reduces it to 1 instead."); + list = CardListUtil.getKeyword(list, "Damage that would reduce your life total to less than 1 reduces it to 1 instead."); list = list.filter(new Predicate() { @Override public boolean apply(final Card c) { @@ -260,7 +261,7 @@ public final class PlayerUtil { public static Input inputSacrificePermanents(final int nCards, final String type) { CardList list = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield); - list = list.getType(type); + list = CardListUtil.getType(list, type); return PlayerUtil.inputSacrificePermanentsFromList(nCards, list, "Select a " + type + " to sacrifice"); } // input_sacrificePermanents()