getPlayerTypeIn from AllZoneUtil removed in favour of player.getCardsIn(zone).getType(type)

This commit is contained in:
Maxmtg
2011-09-20 03:13:48 +00:00
parent d4aaddcaa2
commit 165b6eb47e
10 changed files with 23 additions and 39 deletions

View File

@@ -12,26 +12,11 @@ import java.util.List;
* @author dennis.r.friedrichsen (slapshot5 on slightlymagic.net) * @author dennis.r.friedrichsen (slapshot5 on slightlymagic.net)
* @version $Id$ * @version $Id$
*/ */
public final class AllZoneUtil { public abstract class AllZoneUtil {
private AllZoneUtil() {
throw new AssertionError();
}
//////////// Creatures //////////// Creatures
/**
* gets a list of all cards of a certain type that a given player has in given zone.
*
* @param player the player to check for cards in play
* @param cardType the card type to check for
* @return a CardList with all cards of a certain type the player has in play
*/
public static CardList getPlayerTypeIn(final Player player, final Constant.Zone zone, final String cardType) {
CardList cards = player.getCardsIn(zone);
cards = cards.getType(cardType);
return cards;
}
/** /**
* gets a list of all cards owned by both players that have are currently in the given zone. * gets a list of all cards owned by both players that have are currently in the given zone.
@@ -250,8 +235,8 @@ public final class AllZoneUtil {
public static int compareTypeAmountInPlay(final Player player, final String type) { public static int compareTypeAmountInPlay(final Player player, final String type) {
// returns the difference between player's // returns the difference between player's
Player opponent = player.getOpponent(); Player opponent = player.getOpponent();
CardList playerList = getPlayerTypeIn(player, Zone.Battlefield, type); CardList playerList = player.getCardsIn(Zone.Battlefield).getType(type);
CardList opponentList = getPlayerTypeIn(opponent, Zone.Battlefield, type); CardList opponentList = opponent.getCardsIn(Zone.Battlefield).getType(type);
return (playerList.size() - opponentList.size()); return (playerList.size() - opponentList.size());
} }
@@ -265,8 +250,8 @@ public final class AllZoneUtil {
public static int compareTypeAmountInGraveyard(final Player player, final String type) { public static int compareTypeAmountInGraveyard(final Player player, final String type) {
// returns the difference between player's // returns the difference between player's
Player opponent = player.getOpponent(); Player opponent = player.getOpponent();
CardList playerList = getPlayerTypeIn(player, Zone.Graveyard, type); CardList playerList = player.getCardsIn(Zone.Graveyard).getType(type);
CardList opponentList = getPlayerTypeIn(opponent, Zone.Graveyard, type); CardList opponentList = opponent.getCardsIn(Zone.Graveyard).getType(type);
return (playerList.size() - opponentList.size()); return (playerList.size() - opponentList.size());
} }

View File

@@ -778,7 +778,7 @@ public class ComputerUtil {
landList = landList.filter(CardListFilter.lands); landList = landList.filter(CardListFilter.lands);
CardList lands = AllZoneUtil.getPlayerTypeIn(computer, Zone.Graveyard, "Land"); CardList lands = computer.getCardsIn(Zone.Graveyard).getType("Land");
for (Card crd : lands){ for (Card crd : lands){
if (crd.isLand() && crd.hasKeyword("May be played")) if (crd.isLand() && crd.hasKeyword("May be played"))
landList.add(crd); landList.add(crd);
@@ -972,7 +972,7 @@ public class ComputerUtil {
if (hand.size() <= 0) { if (hand.size() <= 0) {
continue; continue;
} }
CardList landsInPlay = AllZoneUtil.getPlayerTypeIn(AllZone.getComputerPlayer(), Zone.Battlefield, "Land"); CardList landsInPlay = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield).getType("Land");
if (landsInPlay.size() > 5) { if (landsInPlay.size() > 5) {
CardList landsInHand = hand.getType("Land"); CardList landsInHand = hand.getType("Land");
if (landsInHand.size() > 0) { //discard lands if (landsInHand.size() > 0) { //discard lands

View File

@@ -1274,7 +1274,7 @@ public abstract class Player extends GameEntity {
* @return a {@link forge.Card} object. * @return a {@link forge.Card} object.
*/ */
public Card getPlaneswalker() { public Card getPlaneswalker() {
CardList c = AllZoneUtil.getPlayerTypeIn(this, Zone.Battlefield, "Planeswalker"); CardList c = getCardsIn(Zone.Battlefield).getType("Planeswalker");
if (null != c && c.size() > 0) return c.get(0); if (null != c && c.size() > 0) return c.get(0);
else return null; else return null;
} }
@@ -1580,7 +1580,7 @@ public abstract class Player extends GameEntity {
* @return a boolean. * @return a boolean.
*/ */
public boolean hasMetalcraft() { public boolean hasMetalcraft() {
CardList list = AllZoneUtil.getPlayerTypeIn(this, Zone.Battlefield, "Artifact"); CardList list = getCardsIn(Zone.Battlefield).getType("Artifact");
return list.size() >= 3; return list.size() >= 3;
} }

View File

@@ -2066,8 +2066,8 @@ public class Upkeep implements java.io.Serializable {
oathFlag = false; oathFlag = false;
} }
} else { // if player == Computer } else { // if player == Computer
CardList creaturesInLibrary = AllZoneUtil.getPlayerTypeIn(player, Zone.Library, "Creature"); CardList creaturesInLibrary = player.getCardsIn(Zone.Library).getType("Creature");
CardList creaturesInBattlefield = AllZoneUtil.getPlayerTypeIn(player, Zone.Battlefield, "Creature"); CardList creaturesInBattlefield = player.getCardsIn(Zone.Battlefield).getType("Creature");
// if there are at least 3 creatures in library, or none in play with one in library, oath // if there are at least 3 creatures in library, or none in play with one in library, oath
if (creaturesInLibrary.size() > 2 if (creaturesInLibrary.size() > 2
@@ -2131,7 +2131,7 @@ public class Upkeep implements java.io.Serializable {
Ability ability = new Ability(oathList.get(0), "0") { Ability ability = new Ability(oathList.get(0), "0") {
@Override @Override
public void resolve() { public void resolve() {
CardList graveyardCreatures = AllZoneUtil.getPlayerTypeIn(player, Zone.Graveyard, "Creature"); CardList graveyardCreatures = player.getCardsIn(Zone.Graveyard).getType("Creature");
if (AllZoneUtil.compareTypeAmountInGraveyard(player, "Creature") > 0) { if (AllZoneUtil.compareTypeAmountInGraveyard(player, "Creature") > 0) {
if (player.isHuman()) { if (player.isHuman()) {
@@ -2169,7 +2169,7 @@ public class Upkeep implements java.io.Serializable {
private static void upkeep_Karma() { private static void upkeep_Karma() {
final Player player = AllZone.getPhase().getPlayerTurn(); final Player player = AllZone.getPhase().getPlayerTurn();
CardList karmas = AllZoneUtil.getCardsIn(Zone.Battlefield, "Karma"); CardList karmas = AllZoneUtil.getCardsIn(Zone.Battlefield, "Karma");
CardList swamps = AllZoneUtil.getPlayerTypeIn(player, Zone.Battlefield, "Swamp"); CardList swamps = player.getCardsIn(Zone.Battlefield).getType("Swamp");
// determine how much damage to deal the current player // determine how much damage to deal the current player
final int damage = swamps.size(); final int damage = swamps.size();

View File

@@ -2773,7 +2773,7 @@ public class CardFactoryUtil {
} }
if (sq[0].contains("LandsInGraveyard")) { if (sq[0].contains("LandsInGraveyard")) {
if (players.size() > 0) { if (players.size() > 0) {
return doXMath(AllZoneUtil.getPlayerTypeIn(players.get(0), Zone.Graveyard, "Land").size(), m, source); return doXMath(players.get(0).getCardsIn(Zone.Graveyard).getType("Land").size(), m, source);
} }
} }

View File

@@ -485,7 +485,7 @@ public class CardFactory_Creatures {
if (card.getController().isHuman()) { if (card.getController().isHuman()) {
CardList artifacts = AllZoneUtil.getPlayerTypeIn(AllZone.getHumanPlayer(), Zone.Battlefield, "Artifact"); CardList artifacts = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield).getType("Artifact");
if (artifacts.size() != 0) AllZone.getInputControl().setInput(target); if (artifacts.size() != 0) AllZone.getInputControl().setInput(target);
@@ -986,7 +986,7 @@ public class CardFactory_Creatures {
} }
public CardList getCreatures() { public CardList getCreatures() {
CardList creatures = AllZoneUtil.getPlayerTypeIn(card.getController(), Zone.Graveyard, "Elemental"); CardList creatures = card.getController().getCardsIn(Zone.Graveyard).getType("Elemental");
return creatures; return creatures;
} }

View File

@@ -1506,7 +1506,7 @@ public class CardFactory_Instants {
String[] choices = new String[]{"Artifact", "Creature", "Land"}; String[] choices = new String[]{"Artifact", "Creature", "Land"};
Object o = GuiUtils.getChoice("Select permanent type", choices); Object o = GuiUtils.getChoice("Select permanent type", choices);
String cardType = (String) o; String cardType = (String) o;
CardList list = AllZoneUtil.getPlayerTypeIn(getTargetPlayer(), Zone.Battlefield, cardType); CardList list = getTargetPlayer().getCardsIn(Zone.Battlefield).getType(cardType);
String[] tapOrUntap = new String[]{"Tap", "Untap"}; String[] tapOrUntap = new String[]{"Tap", "Untap"};
Object z = GuiUtils.getChoice("Tap or Untap?", tapOrUntap); Object z = GuiUtils.getChoice("Tap or Untap?", tapOrUntap);

View File

@@ -1238,7 +1238,7 @@ public class CardFactory_Planeswalkers {
final Player target = getTargetPlayer(); final Player target = getTargetPlayer();
final Player player = card.getController(); final Player player = card.getController();
CardList dragons = AllZoneUtil.getPlayerTypeIn(player, Zone.Battlefield, "Dragon"); CardList dragons = player.getCardsIn(Zone.Battlefield).getType("Dragon");
for (int i = 0; i < dragons.size(); i++) { for (int i = 0; i < dragons.size(); i++) {
Card dragon = dragons.get(i); Card dragon = dragons.get(i);
int damage = dragon.getNetAttack(); int damage = dragon.getNetAttack();
@@ -1250,7 +1250,7 @@ public class CardFactory_Planeswalkers {
@Override @Override
public boolean canPlayAI() { public boolean canPlayAI() {
setTargetPlayer(AllZone.getHumanPlayer()); setTargetPlayer(AllZone.getHumanPlayer());
CardList dragons = AllZoneUtil.getPlayerTypeIn(AllZone.getComputerPlayer(), Zone.Battlefield, "Dragon"); CardList dragons = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield).getType("Dragon");
return card.getCounters(Counters.LOYALTY) >= 4 && dragons.size() >= 1; return card.getCounters(Counters.LOYALTY) >= 4 && dragons.size() >= 1;
} }
@@ -1471,7 +1471,7 @@ public class CardFactory_Planeswalkers {
@Override @Override
public void showMessage() { public void showMessage() {
CardList lands = AllZoneUtil.getPlayerTypeIn(card.getController(), Zone.Battlefield, "Mountain"); CardList lands = card.getController().getCardsIn(Zone.Battlefield).getType("Mountain");
stopSetNext(CardFactoryUtil.input_targetSpecific(ability1, lands, "Select target Mountain", stopSetNext(CardFactoryUtil.input_targetSpecific(ability1, lands, "Select target Mountain",
true, false)); true, false));

View File

@@ -2266,12 +2266,12 @@ public class CardFactory_Sorceries {
} }
public Card[] getCreatures() { public Card[] getCreatures() {
CardList creature = AllZoneUtil.getPlayerTypeIn(card.getController(), Zone.Graveyard, "Creature"); CardList creature = card.getController().getCardsIn(Zone.Graveyard).getType("Creature");
return creature.toArray(); return creature.toArray();
} }
public Card[] getCreaturesAI() { public Card[] getCreaturesAI() {
CardList creature = AllZoneUtil.getPlayerTypeIn(card.getController(), Zone.Graveyard, "Creature"); CardList creature = card.getController().getCardsIn(Zone.Graveyard).getType("Creature");
creature = creature.filter(new CardListFilter() { creature = creature.filter(new CardListFilter() {
public boolean addCard(Card c) { public boolean addCard(Card c) {
return c.getNetAttack() > 4; return c.getNetAttack() > 4;
@@ -2300,7 +2300,7 @@ public class CardFactory_Sorceries {
@Override @Override
public void showMessage() { public void showMessage() {
CardList creature = AllZoneUtil.getPlayerTypeIn(card.getController(), Zone.Graveyard, "Creature"); CardList creature = card.getController().getCardsIn(Zone.Graveyard).getType("Creature");
Object check = GuiUtils.getChoiceOptional("Select creature", creature); Object check = GuiUtils.getChoiceOptional("Select creature", creature);
if (check != null) { if (check != null) {
spell.setTargetCard((Card) check); spell.setTargetCard((Card) check);

View File

@@ -5,7 +5,6 @@ import java.util.Iterator;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import forge.AllZone; import forge.AllZone;
import forge.AllZoneUtil;
import forge.ButtonUtil; import forge.ButtonUtil;
import forge.Card; import forge.Card;
import forge.CardList; import forge.CardList;