mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Removed CardListFilter creation in AllZoneUtil, re-wired it to CardList.get... - which include both filter creation and filtering.
This commit is contained in:
@@ -2,8 +2,6 @@ package forge;
|
||||
|
||||
|
||||
import forge.Constant.Zone;
|
||||
import forge.card.cardFactory.CardFactoryUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -72,7 +70,7 @@ public final class AllZoneUtil {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (Player p : Singletons.getModel().getGameState().getPlayers()) {
|
||||
for (Player p : AllZone.getPlayersInGame()) {
|
||||
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
|
||||
*/
|
||||
public static CardList getPlayerLandsInPlay(final Player player) {
|
||||
CardList cards = player.getCardsIn(Zone.Battlefield);
|
||||
return cards.filter(CardListFilter.lands);
|
||||
return player.getCardsIn(Zone.Battlefield).filter(CardListFilter.lands);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,8 +115,7 @@ public final class AllZoneUtil {
|
||||
* @return a CardList of all lands on the battlefield
|
||||
*/
|
||||
public static CardList getLandsInPlay() {
|
||||
CardList cards = getCardsIn(Zone.Battlefield);
|
||||
return cards.filter(CardListFilter.lands);
|
||||
return getCardsIn(Zone.Battlefield).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.
|
||||
*
|
||||
@@ -374,22 +323,13 @@ public final class AllZoneUtil {
|
||||
*/
|
||||
public static CardList getCardsInGame() {
|
||||
CardList all = new CardList();
|
||||
for (Player p : AllZone.getPlayersInGame()) {
|
||||
getCardsInGame(p, all);
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
private static CardList getCardsInGame(Player player, CardList toAdd)
|
||||
{
|
||||
CardList all = toAdd == null ? new CardList() : toAdd;
|
||||
for (Player player : AllZone.getPlayersInGame()) {
|
||||
all.addAll(player.getZone(Zone.Graveyard).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.Battlefield).getCards());
|
||||
all.addAll(player.getZone(Zone.Exile).getCards());
|
||||
//should this include Human_Command ?
|
||||
//all.addAll(AllZone.getHumanSideboard().getCards());
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ public final class GameActionUtil {
|
||||
ability = new Ability(list.get(i), "0") {
|
||||
public void resolve() {
|
||||
CardList creats = AllZoneUtil.getCreaturesInPlay(player);
|
||||
creats = creats.filter(AllZoneUtil.getCanTargetFilter(card));
|
||||
creats = creats.getTargetableCards(card);
|
||||
if (creats.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2353,7 +2353,7 @@ public class Upkeep implements java.io.Serializable {
|
||||
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.";
|
||||
CardList list = player.getCardsIn(Zone.Battlefield);
|
||||
list = list.filter(AllZoneUtil.getKeywordFilter(keyword));
|
||||
list = list.getKeyword(keyword);
|
||||
|
||||
for (final Card c : list) {
|
||||
final SpellAbility ability = new Ability(c, "0") {
|
||||
|
||||
@@ -352,7 +352,7 @@ public final class AbilityFactory_Debuff {
|
||||
{
|
||||
Card hostCard = af.getHostCard();
|
||||
CardList list = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
|
||||
list = list.filter(AllZoneUtil.getCanTargetFilter(hostCard));
|
||||
list = list.getTargetableCards(hostCard);
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
list = list.filter(new CardListFilter() {
|
||||
|
||||
@@ -266,7 +266,7 @@ public class AbilityFactory_Pump {
|
||||
*/
|
||||
private CardList getCurseCreatures(SpellAbility sa, final int defense, int attack) {
|
||||
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
|
||||
list = list.filter(new CardListFilter() {
|
||||
|
||||
@@ -1327,7 +1327,7 @@ public abstract class AbstractCardFactory implements NewConstants, CardFactoryIn
|
||||
public Card getCreature() {
|
||||
CardList tappedCreatures = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
|
||||
tappedCreatures = tappedCreatures.filter(CardListFilter.tapped);
|
||||
tappedCreatures = tappedCreatures.filter(AllZoneUtil.getCanTargetFilter(card));
|
||||
tappedCreatures = tappedCreatures.getTargetableCards(card);
|
||||
if (tappedCreatures.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2071,7 +2071,7 @@ public class CardFactoryUtil {
|
||||
public static CardList AI_getHumanCreature(final Card spell, final boolean targeted) {
|
||||
CardList creature = AllZoneUtil.getCreaturesInPlay(AllZone.getHumanPlayer());
|
||||
if (targeted) {
|
||||
creature = creature.filter(AllZoneUtil.getCanTargetFilter(spell));
|
||||
creature = creature.getTargetableCards(spell);
|
||||
}
|
||||
return creature;
|
||||
}
|
||||
@@ -3306,60 +3306,32 @@ public class CardFactoryUtil {
|
||||
|
||||
// "Untapped Lands" - Count$UntappedTypeYouCtrl.Land
|
||||
if (sq[0].contains("Untapped")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return !c.isTapped();
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.untapped);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Tapped")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return c.isTapped();
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.tapped);
|
||||
}
|
||||
|
||||
// "White Creatures" - Count$WhiteTypeYouCtrl.Creature
|
||||
if (sq[0].contains("White")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return CardUtil.isColor(c, Constant.Color.White);
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.white);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Blue")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return CardUtil.isColor(c, Constant.Color.Blue);
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.blue);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Black")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return CardUtil.isColor(c, Constant.Color.Black);
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.black);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Red")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return CardUtil.isColor(c, Constant.Color.Red);
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.red);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Green")) {
|
||||
someCards = someCards.filter(new CardListFilter() {
|
||||
public boolean addCard(final Card c) {
|
||||
return CardUtil.isColor(c, Constant.Color.Green);
|
||||
}
|
||||
});
|
||||
someCards = someCards.filter(CardListFilter.green);
|
||||
}
|
||||
|
||||
if (sq[0].contains("Multicolor")) {
|
||||
|
||||
@@ -299,7 +299,7 @@ class CardFactory_Equipment {
|
||||
@Override
|
||||
public void showMessage() {
|
||||
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");
|
||||
ButtonUtil.disableAll();
|
||||
if (list.size() == 0) {
|
||||
|
||||
@@ -1436,7 +1436,7 @@ public class CardFactory_Instants {
|
||||
&& !c.hasKeyword("Indestructible");
|
||||
}
|
||||
});
|
||||
CardList infect = creatures.filter(AllZoneUtil.getKeywordFilter("Infect"));
|
||||
CardList infect = creatures.getKeyword("Infect");
|
||||
if (infect.size() > 0) {
|
||||
Card c = CardFactoryUtil.AI_getBestCreature(infect);
|
||||
setTargetCard(c);
|
||||
|
||||
@@ -691,7 +691,7 @@ class CardFactory_Lands {
|
||||
|
||||
public void computerExecute() {
|
||||
CardList hand = AllZone.getComputerPlayer().getCardsIn(Zone.Hand);
|
||||
hand = hand.filter(AllZoneUtil.getTypeFilter(type));
|
||||
hand = hand.getType(type);
|
||||
if (hand.size() > 0) {
|
||||
revealCard(hand.get(0));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user