From d7209a5d08f52c48e2a334aa20e6129de4d7d2cd Mon Sep 17 00:00:00 2001 From: jendave Date: Sun, 7 Aug 2011 01:12:03 +0000 Subject: [PATCH] code simplifications in Target.java --- src/forge/AllZoneUtil.java | 21 ++++++++++++++++++--- src/forge/card/spellability/Target.java | 5 +++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/forge/AllZoneUtil.java b/src/forge/AllZoneUtil.java index 7e65ee2d5f8..c64b14ce141 100644 --- a/src/forge/AllZoneUtil.java +++ b/src/forge/AllZoneUtil.java @@ -253,10 +253,10 @@ public class AllZoneUtil { if(card == null) return false; - Card c[] = pz.getCards(); + CardList cl = getCardsInZone(pz); - for(int i = 0; i < c.length; i++) - if(c[i].equals(card)) + for(int i = 0; i < cl.size(); i++) + if(cl.get(i).equals(card)) return true; return false; @@ -482,6 +482,10 @@ public class AllZoneUtil { return getCardsInZone(zone, null); } + public static CardList getCardsInZone(PlayerZone zone){ + return new CardList(zone.getCards()); + } + public static CardList getCardsInZone(String zone, Player player){ CardList all = new CardList(); @@ -519,6 +523,17 @@ public class AllZoneUtil { return all; } + public static CardList getPlayerCardsWithPhasing(final Player player) { + CardList cards = new CardList(); + cards.addAll(AllZone.getZone(Constant.Zone.Battlefield, player).getCards()); + cards = cards.filter(new CardListFilter() { + public boolean addCard(Card c) { + return c.hasPhasing(); + } + }); + return cards; + } + //zone manipulation, maybe be better off in GameAction.java... /** diff --git a/src/forge/card/spellability/Target.java b/src/forge/card/spellability/Target.java index 6a9af54e597..5a1f88416a0 100644 --- a/src/forge/card/spellability/Target.java +++ b/src/forge/card/spellability/Target.java @@ -3,6 +3,7 @@ package forge.card.spellability; import java.util.ArrayList; import forge.AllZone; +import forge.AllZoneUtil; import forge.Card; import forge.Constant; import forge.Player; @@ -240,7 +241,7 @@ public class Target { return true; } - for(Card c : AllZone.getZone(tgtZone,AllZone.HumanPlayer).getCards()) + for(Card c : AllZoneUtil.getCardsInZone(tgtZone, AllZone.HumanPlayer)) { if(c.isValidCard(ValidTgts, srcCard.getController(), srcCard) && CardFactoryUtil.canTarget(srcCard, c)) { @@ -248,7 +249,7 @@ public class Target { } } - for(Card c : AllZone.getZone(tgtZone,AllZone.ComputerPlayer).getCards()) + for(Card c : AllZoneUtil.getCardsInZone(tgtZone, AllZone.ComputerPlayer)) { if(c.isValidCard(ValidTgts, srcCard.getController(), srcCard) && CardFactoryUtil.canTarget(srcCard, c)) {