From 5029706d80de8077bff680b52ef58ae53c419dfc Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 08:13:50 +0000 Subject: [PATCH] Fixes issue 40 Added CardList.getTargetableCards. Replaced the redundant filter code for the DestroyTgt and BounceTgt effects. Added this method in the CanPlayAI and the ETB command which chooses the target. --- src/forge/CardFactory.java | 35 +++++++++++++++++------------------ src/forge/CardList.java | 9 +++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index 400e60f704e..a7f741bcf27 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -2588,13 +2588,10 @@ public class CardFactory implements NewConstants { CardList getTargets() { CardList tmpList = new CardList(); tmpList.addAll(AllZone.Human_Play.getCards()); - tmpList = tmpList.filter(new CardListFilter() { - public boolean addCard(Card c) { - return (CardFactoryUtil.canTarget(card, c)); - } - }); + tmpList = tmpList.getValidCards(Tgts); + tmpList = tmpList.getTargetableCards(card); - return tmpList.getValidCards(Tgts); + return tmpList; } @Override @@ -2749,13 +2746,10 @@ public class CardFactory implements NewConstants { CardList getTargets() { CardList tmpList = new CardList(); tmpList.addAll(AllZone.Human_Play.getCards()); - tmpList = tmpList.filter(new CardListFilter() { - public boolean addCard(Card c) { - return (CardFactoryUtil.canTarget(card, c)); - } - }); + tmpList = tmpList.getValidCards(Tgts); + tmpList = tmpList.getTargetableCards(card); - return tmpList.getValidCards(Tgts); + return tmpList; } @Override @@ -2854,11 +2848,13 @@ public class CardFactory implements NewConstants { CardList hCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards()); hCards = hCards.getValidCards(Tgts); + hCards = hCards.getTargetableCards(card); if (hCards.size() > 0) return true; CardList cCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards()); cCards = cCards.getValidCards(Tgts); + cCards = cCards.getTargetableCards(card); if (cCards.size() == 0) return true; else @@ -2908,7 +2904,9 @@ public class CardFactory implements NewConstants { CardList cCards = new CardList(AllZone.Computer_Play.getCards()); hCards = hCards.getValidCards(Tgts); + hCards = hCards.getTargetableCards(card); cCards = cCards.getValidCards(Tgts); + cCards = cCards.getTargetableCards(card); if(hCards.size() > 0 || cCards.size() > 0) { @@ -3209,13 +3207,10 @@ public class CardFactory implements NewConstants { CardList getTargets() { CardList tmpList = new CardList(); tmpList.addAll(AllZone.Human_Play.getCards()); - tmpList = tmpList.filter(new CardListFilter() { - public boolean addCard(Card c) { - return (CardFactoryUtil.canTarget(card, c)); - } - }); + tmpList = tmpList.getValidCards(Tgts); + tmpList = tmpList.getTargetableCards(card); - return tmpList.getValidCards(Tgts); + return tmpList; } @Override @@ -3357,11 +3352,13 @@ public class CardFactory implements NewConstants { CardList hCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Human).getCards()); hCards = hCards.getValidCards(Tgts); + hCards = hCards.getTargetableCards(card); if (hCards.size() > 0) return true; CardList cCards = new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards()); cCards = cCards.getValidCards(Tgts); + cCards = cCards.getTargetableCards(card); if (cCards.size() == 0) return true; else @@ -3423,7 +3420,9 @@ public class CardFactory implements NewConstants { CardList cCards = new CardList(AllZone.Computer_Play.getCards()); hCards = hCards.getValidCards(Tgts); + hCards = hCards.getTargetableCards(card); cCards = cCards.getValidCards(Tgts); + cCards = cCards.getTargetableCards(card); if (hCards.size() > 0 || cCards.size() > 0) { diff --git a/src/forge/CardList.java b/src/forge/CardList.java index 8d8dadb7cef..57b64f01612 100644 --- a/src/forge/CardList.java +++ b/src/forge/CardList.java @@ -279,6 +279,15 @@ public class CardList implements Iterable { Collections.sort(list, c); } + public CardList getTargetableCards(final Card Source) + { + return this.filter(new CardListFilter() { + public boolean addCard(Card c) { + return CardFactoryUtil.canTarget(Source, c); + } + }); + } + public CardList getValidCards(final String Restrictions[], final String Controller) { return this.filter(new CardListFilter() { public boolean addCard(Card c) {