Removed CardListFilter creation in AllZoneUtil, re-wired it to CardList.get... - which include both filter creation and filtering.

This commit is contained in:
Maxmtg
2011-09-20 02:19:34 +00:00
parent b307aae220
commit 608c8a4705
10 changed files with 25 additions and 113 deletions

View File

@@ -2,8 +2,6 @@ package forge;
import forge.Constant.Zone; import forge.Constant.Zone;
import forge.card.cardFactory.CardFactoryUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -72,7 +70,7 @@ public final class AllZoneUtil {
continue; continue;
} }
for (Player p : Singletons.getModel().getGameState().getPlayers()) { for (Player p : AllZone.getPlayersInGame()) {
cards.addAll(p.getZone(z).getCards()); cards.addAll(p.getZone(z).getCards());
} }
} }
@@ -108,8 +106,7 @@ public final class AllZoneUtil {
* @return a CardList containing all lands the given player has in play * @return a CardList containing all lands the given player has in play
*/ */
public static CardList getPlayerLandsInPlay(final Player player) { public static CardList getPlayerLandsInPlay(final Player player) {
CardList cards = player.getCardsIn(Zone.Battlefield); return player.getCardsIn(Zone.Battlefield).filter(CardListFilter.lands);
return cards.filter(CardListFilter.lands);
} }
/** /**
@@ -118,8 +115,7 @@ public final class AllZoneUtil {
* @return a CardList of all lands on the battlefield * @return a CardList of all lands on the battlefield
*/ */
public static CardList getLandsInPlay() { public static CardList getLandsInPlay() {
CardList cards = getCardsIn(Zone.Battlefield); return getCardsIn(Zone.Battlefield).filter(CardListFilter.lands);
return cards.filter(CardListFilter.lands);
} }
//============================================================================= //=============================================================================
@@ -320,53 +316,6 @@ public final class AllZoneUtil {
} }
/**
* get a CardListFilter to filter in only cards that can be targeted.
*
* @param source - the card to be the source for the target
* @return a CardListFilter to only add cards that can be targeted
*/
public static CardListFilter getCanTargetFilter(final Card source) {
CardListFilter canTarget = new CardListFilter() {
public boolean addCard(final Card c) {
return CardFactoryUtil.canTarget(source, c);
}
};
return canTarget;
}
/**
* get a CardListFilter to filter a CardList for a given keyword.
*
* @param keyword - the keyword to look for
* @return a CardListFilter to only add cards with the given keyword
*/
public static CardListFilter getKeywordFilter(final String keyword) {
CardListFilter filter = new CardListFilter() {
public boolean addCard(final Card c) {
return c.hasKeyword(keyword);
}
};
return filter;
}
/**
* get a CardListFilter to filter a CardList for a given type.
*
* @param type - the type to check for
* @return a CardListFilter to only add cards of the given type
*/
public static CardListFilter getTypeFilter(final String type) {
CardListFilter filter = new CardListFilter() {
public boolean addCard(final Card c) {
return c.isType(type);
}
};
return filter;
}
/** /**
* a CardListFilter to get all cards that are a part of this game. * a CardListFilter to get all cards that are a part of this game.
* *
@@ -374,22 +323,13 @@ public final class AllZoneUtil {
*/ */
public static CardList getCardsInGame() { public static CardList getCardsInGame() {
CardList all = new CardList(); CardList all = new CardList();
for (Player p : AllZone.getPlayersInGame()) { for (Player player : AllZone.getPlayersInGame()) {
getCardsInGame(p, all);
}
return all;
}
private static CardList getCardsInGame(Player player, CardList toAdd)
{
CardList all = toAdd == null ? new CardList() : toAdd;
all.addAll(player.getZone(Zone.Graveyard).getCards()); all.addAll(player.getZone(Zone.Graveyard).getCards());
all.addAll(player.getZone(Zone.Hand).getCards()); all.addAll(player.getZone(Zone.Hand).getCards());
all.addAll(player.getZone(Zone.Library).getCards()); // not sure if library should be included. all.addAll(player.getZone(Zone.Library).getCards()); // not sure if library should be included.
all.addAll(player.getZone(Zone.Battlefield).getCards()); all.addAll(player.getZone(Zone.Battlefield).getCards());
all.addAll(player.getZone(Zone.Exile).getCards()); all.addAll(player.getZone(Zone.Exile).getCards());
//should this include Human_Command ? }
//all.addAll(AllZone.getHumanSideboard().getCards());
return all; return all;
} }

View File

@@ -516,7 +516,7 @@ public final class GameActionUtil {
ability = new Ability(list.get(i), "0") { ability = new Ability(list.get(i), "0") {
public void resolve() { public void resolve() {
CardList creats = AllZoneUtil.getCreaturesInPlay(player); CardList creats = AllZoneUtil.getCreaturesInPlay(player);
creats = creats.filter(AllZoneUtil.getCanTargetFilter(card)); creats = creats.getTargetableCards(card);
if (creats.size() == 0) { if (creats.size() == 0) {
return; return;
} }

View File

@@ -2353,7 +2353,7 @@ public class Upkeep implements java.io.Serializable {
final Player player = AllZone.getPhase().getPlayerTurn(); final Player player = AllZone.getPhase().getPlayerTurn();
final String keyword = "At the beginning of your upkeep, you may have this creature become a copy of target creature except it doesn't copy that creature's color. If you do, this creature gains this ability."; final String keyword = "At the beginning of your upkeep, you may have this creature become a copy of target creature except it doesn't copy that creature's color. If you do, this creature gains this ability.";
CardList list = player.getCardsIn(Zone.Battlefield); CardList list = player.getCardsIn(Zone.Battlefield);
list = list.filter(AllZoneUtil.getKeywordFilter(keyword)); list = list.getKeyword(keyword);
for (final Card c : list) { for (final Card c : list) {
final SpellAbility ability = new Ability(c, "0") { final SpellAbility ability = new Ability(c, "0") {

View File

@@ -352,7 +352,7 @@ public final class AbilityFactory_Debuff {
{ {
Card hostCard = af.getHostCard(); Card hostCard = af.getHostCard();
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
list = list.filter(AllZoneUtil.getCanTargetFilter(hostCard)); list = list.getTargetableCards(hostCard);
if (!list.isEmpty()) { if (!list.isEmpty()) {
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {

View File

@@ -266,7 +266,7 @@ public class AbilityFactory_Pump {
*/ */
private CardList getCurseCreatures(SpellAbility sa, final int defense, int attack) { private CardList getCurseCreatures(SpellAbility sa, final int defense, int attack) {
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
list = list.filter(AllZoneUtil.getCanTargetFilter(hostCard)); list = list.getTargetableCards(hostCard);
if (defense < 0 && !list.isEmpty()) { // with spells that give -X/-X, compi will try to destroy a creature if (defense < 0 && !list.isEmpty()) { // with spells that give -X/-X, compi will try to destroy a creature
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {

View File

@@ -1327,7 +1327,7 @@ public abstract class AbstractCardFactory implements NewConstants, CardFactoryIn
public Card getCreature() { public Card getCreature() {
CardList tappedCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); CardList tappedCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
tappedCreatures = tappedCreatures.filter(CardListFilter.tapped); tappedCreatures = tappedCreatures.filter(CardListFilter.tapped);
tappedCreatures = tappedCreatures.filter(AllZoneUtil.getCanTargetFilter(card)); tappedCreatures = tappedCreatures.getTargetableCards(card);
if (tappedCreatures.isEmpty()) { if (tappedCreatures.isEmpty()) {
return null; return null;
} }

View File

@@ -2071,7 +2071,7 @@ public class CardFactoryUtil {
public static CardList AI_getHumanCreature(final Card spell, final boolean targeted) { public static CardList AI_getHumanCreature(final Card spell, final boolean targeted) {
CardList creature = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer()); CardList creature = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
if (targeted) { if (targeted) {
creature = creature.filter(AllZoneUtil.getCanTargetFilter(spell)); creature = creature.getTargetableCards(spell);
} }
return creature; return creature;
} }
@@ -3306,60 +3306,32 @@ public class CardFactoryUtil {
// "Untapped Lands" - Count$UntappedTypeYouCtrl.Land // "Untapped Lands" - Count$UntappedTypeYouCtrl.Land
if (sq[0].contains("Untapped")) { if (sq[0].contains("Untapped")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.untapped);
public boolean addCard(final Card c) {
return !c.isTapped();
}
});
} }
if (sq[0].contains("Tapped")) { if (sq[0].contains("Tapped")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.tapped);
public boolean addCard(final Card c) {
return c.isTapped();
}
});
} }
// "White Creatures" - Count$WhiteTypeYouCtrl.Creature // "White Creatures" - Count$WhiteTypeYouCtrl.Creature
if (sq[0].contains("White")) { if (sq[0].contains("White")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.white);
public boolean addCard(final Card c) {
return CardUtil.isColor(c, Constant.Color.White);
}
});
} }
if (sq[0].contains("Blue")) { if (sq[0].contains("Blue")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.blue);
public boolean addCard(final Card c) {
return CardUtil.isColor(c, Constant.Color.Blue);
}
});
} }
if (sq[0].contains("Black")) { if (sq[0].contains("Black")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.black);
public boolean addCard(final Card c) {
return CardUtil.isColor(c, Constant.Color.Black);
}
});
} }
if (sq[0].contains("Red")) { if (sq[0].contains("Red")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.red);
public boolean addCard(final Card c) {
return CardUtil.isColor(c, Constant.Color.Red);
}
});
} }
if (sq[0].contains("Green")) { if (sq[0].contains("Green")) {
someCards = someCards.filter(new CardListFilter() { someCards = someCards.filter(CardListFilter.green);
public boolean addCard(final Card c) {
return CardUtil.isColor(c, Constant.Color.Green);
}
});
} }
if (sq[0].contains("Multicolor")) { if (sq[0].contains("Multicolor")) {

View File

@@ -299,7 +299,7 @@ class CardFactory_Equipment {
@Override @Override
public void showMessage() { public void showMessage() {
CardList list = AllZoneUtil.getCreaturesInPlay(card.getController()); CardList list = AllZoneUtil.getCreaturesInPlay(card.getController());
list = list.filter(AllZoneUtil.getCanTargetFilter(card)); list = list.getTargetableCards(card);
AllZone.getDisplay().showMessage(card + " - Select target creature you control to attach"); AllZone.getDisplay().showMessage(card + " - Select target creature you control to attach");
ButtonUtil.disableAll(); ButtonUtil.disableAll();
if (list.size() == 0) { if (list.size() == 0) {

View File

@@ -1436,7 +1436,7 @@ public class CardFactory_Instants {
&& !c.hasKeyword("Indestructible"); && !c.hasKeyword("Indestructible");
} }
}); });
CardList infect = creatures.filter(AllZoneUtil.getKeywordFilter("Infect")); CardList infect = creatures.getKeyword("Infect");
if (infect.size() > 0) { if (infect.size() > 0) {
Card c = CardFactoryUtil.AI_getBestCreature(infect); Card c = CardFactoryUtil.AI_getBestCreature(infect);
setTargetCard(c); setTargetCard(c);

View File

@@ -691,7 +691,7 @@ class CardFactory_Lands {
public void computerExecute() { public void computerExecute() {
CardList hand = AllZone.getComputerPlayer().getCardsIn(Zone.Hand); CardList hand = AllZone.getComputerPlayer().getCardsIn(Zone.Hand);
hand = hand.filter(AllZoneUtil.getTypeFilter(type)); hand = hand.getType(type);
if (hand.size() > 0) { if (hand.size() > 0) {
revealCard(hand.get(0)); revealCard(hand.get(0));
} }