From cd162a2d04eb65a1737a8c6f454576adafdcdc16 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 23:23:25 +0000 Subject: [PATCH] delete PlayerZoneUtil.java (very few things used these functions, and should have been using AllZoneUtil functions anyways); moved one function to AllZoneUtil --- .gitattributes | 1 - src/forge/AllZoneUtil.java | 31 ++++++++++++++++++---- src/forge/ComputerUtil.java | 49 ++++++++++++++++++----------------- src/forge/GameAction.java | 30 ++++++++++----------- src/forge/PlayerZoneUtil.java | 48 ---------------------------------- 5 files changed, 64 insertions(+), 95 deletions(-) delete mode 100644 src/forge/PlayerZoneUtil.java diff --git a/.gitattributes b/.gitattributes index ca33d637fcb..899eda8eac1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8705,7 +8705,6 @@ src/forge/PhaseUtil.java -text svneol=native#text/plain src/forge/Player.java -text svneol=native#text/plain src/forge/PlayerUtil.java -text svneol=native#text/plain src/forge/PlayerZone.java svneol=native#text/plain -src/forge/PlayerZoneUtil.java svneol=native#text/plain src/forge/PlayerZone_ComesIntoPlay.java svneol=native#text/plain src/forge/PrintCardNames.java svneol=native#text/plain src/forge/PrintCardPictures.java svneol=native#text/plain diff --git a/src/forge/AllZoneUtil.java b/src/forge/AllZoneUtil.java index 282ec03f71d..fea277529ad 100644 --- a/src/forge/AllZoneUtil.java +++ b/src/forge/AllZoneUtil.java @@ -214,7 +214,7 @@ public class AllZoneUtil { */ public static boolean isCardInPlayerGraveyard(Player player, Card card) { - return PlayerZoneUtil.isCardInZone(AllZone.getZone(Constant.Zone.Graveyard, player), card); + return isCardInZone(AllZone.getZone(Constant.Zone.Graveyard, player), card); } //////// HAND @@ -242,11 +242,24 @@ public class AllZoneUtil { * @return true if the card is present in this player's hand; false otherwise */ public static boolean isCardInPlayerHand(Player player, Card card) { - return PlayerZoneUtil.isCardInZone(AllZone.getZone(Constant.Zone.Hand, player), card); + return isCardInZone(AllZone.getZone(Constant.Zone.Hand, player), card); } public static boolean isCardInPlayerLibrary(Player player, Card card) { - return PlayerZoneUtil.isCardInZone(AllZone.getZone(Constant.Zone.Library, player), card); + return isCardInZone(AllZone.getZone(Constant.Zone.Library, player), card); + } + + public static boolean isCardInZone(PlayerZone pz, Card card) { + if(card == null) + return false; + + Card c[] = pz.getCards(); + + for(int i = 0; i < c.length; i++) + if(c[i].equals(card)) + return true; + + return false; } ////////////// EXILE @@ -338,8 +351,7 @@ public class AllZoneUtil { ///Check if a certain card is in play public static boolean isCardInPlay(Card card) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Battlefield, card) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Battlefield, card); + return getCardsInPlay().contains(card); } /** @@ -618,6 +630,15 @@ public class AllZoneUtil { } }; + /** + * a CardListFilter to get all equipment + */ + public static CardListFilter equipment = new CardListFilter() { + public boolean addCard(Card c) { + return c.isEquipment(); + } + }; + /** * a CardListFilter to get all unenchanted cards in a list */ diff --git a/src/forge/ComputerUtil.java b/src/forge/ComputerUtil.java index f01ca3f0c12..a5bbbde3afe 100644 --- a/src/forge/ComputerUtil.java +++ b/src/forge/ComputerUtil.java @@ -774,32 +774,33 @@ public class ComputerUtil static public boolean chooseLandsToPlay() { Player computer = AllZone.ComputerPlayer; - ArrayList landList = PlayerZoneUtil.getCardType(AllZone.Computer_Hand, "Land"); - - if (AllZoneUtil.getPlayerCardsInPlay(computer, "Crucible of Worlds").size() > 0) - { - CardList lands = AllZoneUtil.getPlayerTypeInGraveyard(computer, "Land"); - for (Card crd : lands) - landList.add(crd); - } + CardList landList = AllZoneUtil.getPlayerHand(computer); + landList = landList.filter(AllZoneUtil.lands); - while(!landList.isEmpty() && computer.canPlayLand()){ - // play as many lands as you can - int ix = 0; - while (landList.get(ix).isReflectedLand() && (ix+1 < landList.size())) { - // Skip through reflected lands. Choose last if they are all reflected. - ix++; - } + if (AllZoneUtil.getPlayerCardsInPlay(computer, "Crucible of Worlds").size() > 0) + { + CardList lands = AllZoneUtil.getPlayerTypeInGraveyard(computer, "Land"); + for (Card crd : lands) + landList.add(crd); + } - Card land = landList.get(ix); - landList.remove(ix); - computer.playLand(land); - - AllZone.GameAction.checkStateEffects(); - if (AllZone.Stack.size() != 0) - return false; - } - return true; + while(!landList.isEmpty() && computer.canPlayLand()){ + // play as many lands as you can + int ix = 0; + while (landList.get(ix).isReflectedLand() && (ix+1 < landList.size())) { + // Skip through reflected lands. Choose last if they are all reflected. + ix++; + } + + Card land = landList.get(ix); + landList.remove(ix); + computer.playLand(land); + + AllZone.GameAction.checkStateEffects(); + if (AllZone.Stack.size() != 0) + return false; + } + return true; } static public Card getCardPreference(Card activate, String pref, CardList typeList){ diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index 606d9746ca4..9814cedcc5c 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -507,8 +507,7 @@ public class GameAction { GameActionUtil.stPump.execute(); //System.out.println("checking state effects"); - ArrayList creature = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Creature"); - creature.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Creature")); + CardList creature = AllZoneUtil.getCreaturesInPlay(); Card c; Iterator it = creature.iterator(); @@ -538,8 +537,8 @@ public class GameAction { }//while it.hasNext() - ArrayList enchantments = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Enchantment"); - enchantments.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Enchantment")); + CardList enchantments = AllZoneUtil.getCardsInPlay(); + enchantments = enchantments.filter(AllZoneUtil.enchantments); Iterator iterate = enchantments.iterator(); while(iterate.hasNext()) { @@ -563,8 +562,8 @@ public class GameAction { }//while iterate.hasNext() //Make sure all equipment stops equipping previously equipped creatures that have left play. - ArrayList equip = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Equipment"); - equip.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Equipment")); + CardList equip = AllZoneUtil.getCardsInPlay(); + equip = equip.filter(AllZoneUtil.equipment); Iterator iter = equip.iterator(); while(iter.hasNext()) { @@ -2176,18 +2175,17 @@ public class GameAction { //is this card a permanent that is in play? public boolean isCardInPlay(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Battlefield, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Battlefield, c); + return AllZoneUtil.isCardInPlay(c); } public boolean isCardInGrave(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Graveyard, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Graveyard, c); + return AllZoneUtil.isCardInZone(AllZone.Computer_Graveyard, c) + || AllZoneUtil.isCardInZone(AllZone.Human_Graveyard, c); } public boolean isCardExiled(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Exile, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Exile, c); + return AllZoneUtil.isCardInZone(AllZone.Computer_Exile, c) + || AllZoneUtil.isCardInZone(AllZone.Human_Exile, c); } /** @@ -2213,11 +2211,9 @@ public class GameAction { //removes all damage from player's creatures public void removeDamage(Player player) { - PlayerZone p = AllZone.getZone(Constant.Zone.Battlefield, player); - ArrayList a = PlayerZoneUtil.getCardType(p, "Creature"); - Card c[] = CardUtil.toCard(a); - for(int i = 0; i < c.length; i++) - c[i].setDamage(0); + CardList list = AllZoneUtil.getCreaturesInPlay(player); + for(Card c:list) + c.setDamage(0); } //for Quest fantasy mode diff --git a/src/forge/PlayerZoneUtil.java b/src/forge/PlayerZoneUtil.java deleted file mode 100644 index c07bead6782..00000000000 --- a/src/forge/PlayerZoneUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -package forge; -import java.util.ArrayList; - -public class PlayerZoneUtil -{ - //TODO(sol) this whole class is pretty useless - public static ArrayList getCardType(PlayerZone zone, String cardType) - { - Card c; - ArrayList list = new ArrayList(); - - for(int i = 0; i < zone.size(); i++) - { - c = zone.get(i); - if(c.isType(cardType)) - list.add(c); - } - return list; - } - - public static ArrayList getUntappedCreatures(PlayerZone zone) - { - ArrayList all = getCardType(zone, "Creature"); - ArrayList untapped = new ArrayList(); - - for(int i = 0; i < all.size(); i++) - if(((Card)all.get(i)).isUntapped()) - untapped.add(all.get(i)); - - return untapped; - } - - static public boolean isCardInZone(PlayerZone pz, Card card) - { - if(card == null) - return false; - - Card c[] = pz.getCards(); - - for(int i = 0; i < c.length; i++) - if(c[i].equals(card)) - return true; - - return false; - } - -} -