contains() added to PlayerZone - that's another AllZoneUtil call eliminated as well as useless copying to arrays with the only purpose of checking

This commit is contained in:
Maxmtg
2011-09-20 02:37:44 +00:00
parent 608c8a4705
commit 613b5a2bbd
7 changed files with 17 additions and 34 deletions

View File

@@ -393,14 +393,14 @@ public final class AllZone implements NewConstants {
final FGameState gameState = Singletons.getModel().getGameState(); final FGameState gameState = Singletons.getModel().getGameState();
if (gameState == null) { return null; } if (gameState == null) { return null; }
if (AllZoneUtil.isCardInZone(gameState.getStackZone(), c)) { if (gameState.getStackZone().contains(c)) {
return gameState.getStackZone(); return gameState.getStackZone();
} }
for (Player p : gameState.getPlayers()) { for (Player p : gameState.getPlayers()) {
for(Zone z : Player.ALL_ZONES) { for(Zone z : Player.ALL_ZONES) {
PlayerZone pz = p.getZone(z); PlayerZone pz = p.getZone(z);
if ( AllZoneUtil.isCardInZone(pz, c) ) if (pz.contains(c))
return pz; return pz;
} }
} }

View File

@@ -135,34 +135,11 @@ public final class AllZoneUtil {
* @return true if the card is present in this player's hand; false otherwise * @return true if the card is present in this player's hand; false otherwise
*/ */
public static boolean isCardInPlayerGraveyard(final Player player, final Card card) { public static boolean isCardInPlayerGraveyard(final Player player, final Card card) {
return isCardInZone(player.getZone(Constant.Zone.Graveyard), card); return player.getZone(Constant.Zone.Graveyard).contains(card);
} }
//////// HAND //////// HAND
/**
* answers the question "is a specific card in the specified zone?".
*
* @param pz the PlayerZone to check
* @param card the specific card to look for
* @return true if the card is present in this zone; false otherwise
*/
public static boolean isCardInZone(final PlayerZone pz, final Card card) {
if (card == null) {
return false;
}
for (Card c : pz.getCards()) {
if (c.equals(card)) {
return true;
}
}
return false;
}
/** /**
* answers the question "is the given card in any exile zone?". * answers the question "is the given card in any exile zone?".
* *

View File

@@ -17,7 +17,7 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
/** Constant <code>serialVersionUID=-5687652485777639176L</code>. */ /** Constant <code>serialVersionUID=-5687652485777639176L</code>. */
private static final long serialVersionUID = -5687652485777639176L; private static final long serialVersionUID = -5687652485777639176L;
private ArrayList<Card> cards = new ArrayList<Card>(); private List<Card> cards = new ArrayList<Card>();
private final Constant.Zone zoneName; private final Constant.Zone zoneName;
private final Player player; private final Player player;
private boolean update = true; private boolean update = true;
@@ -162,6 +162,10 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
update(); update();
} }
public final boolean contains(Card c) {
return cards.contains(c);
}
/** /**
* *
* @param c an Object * @param c an Object

View File

@@ -82,6 +82,8 @@ interface IPlayerZone {
Card[] getCards(); Card[] getCards();
Card[] getCards(int n); Card[] getCards(int n);
boolean contains(Card c);
/** isEmpty returns true if given zone contains no cards */ /** isEmpty returns true if given zone contains no cards */
boolean isEmpty(); boolean isEmpty();

View File

@@ -502,7 +502,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield); PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
// Animate Dead got destroyed before its ability resolved // Animate Dead got destroyed before its ability resolved
if (!AllZoneUtil.isCardInZone(play, card)) { if (!play.contains(card)) {
return; return;
} }
@@ -550,7 +550,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield); PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
if (AllZoneUtil.isCardInZone(play, c)) { if (play.contains(c)) {
AllZone.getGameAction().sacrifice(c); AllZone.getGameAction().sacrifice(c);
} }
} }
@@ -564,7 +564,7 @@ class CardFactory_Auras {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield); PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
if (AllZoneUtil.isCardInZone(play, c)) { if (play.contains(c)) {
AllZone.getStack().addSimultaneousStackEntry(detach); AllZone.getStack().addSimultaneousStackEntry(detach);
} }

View File

@@ -249,7 +249,7 @@ public class CardFactory_Creatures {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield); PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
boolean canPlayLand = card.getController().canPlayLand(); boolean canPlayLand = card.getController().canPlayLand();
return (AllZoneUtil.isCardInZone(play, card) && library.get(0).isLand() && canPlayLand); return (play.contains(card) && library.get(0).isLand() && canPlayLand);
} }
};//SpellAbility };//SpellAbility
@@ -814,7 +814,7 @@ public class CardFactory_Creatures {
PlayerZone grave = AllZone.getZoneOf(target[0]); PlayerZone grave = AllZone.getZoneOf(target[0]);
//checks to see if card is still in the graveyard //checks to see if card is still in the graveyard
if (grave != null && AllZoneUtil.isCardInZone(grave, target[0])) { if (grave != null && grave.contains(target[0])) {
PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield); PlayerZone play = card.getController().getZone(Constant.Zone.Battlefield);
target[0].addController(card.getController()); target[0].addController(card.getController());
AllZone.getGameAction().moveTo(play, target[0]); AllZone.getGameAction().moveTo(play, target[0]);

View File

@@ -95,7 +95,7 @@ public class CostExile extends CostPartWithList {
Integer amount = convertAmount(); Integer amount = convertAmount();
if (amount != null && typeList.size() < amount) if (amount != null && typeList.size() < amount)
return false; return false;
} else if (!AllZoneUtil.isCardInZone(zone, source)) } else if (!zone.contains(source))
return false; return false;
return true; return true;
@@ -341,7 +341,7 @@ public class CostExile extends CostPartWithList {
@Override @Override
public void showMessage() { public void showMessage() {
Card card = sa.getSourceCard(); Card card = sa.getSourceCard();
if (sa.getActivatingPlayer().isHuman() && AllZoneUtil.isCardInZone(sa.getActivatingPlayer().getZone(part.getFrom()), card)) { if (sa.getActivatingPlayer().isHuman() && sa.getActivatingPlayer().getZone(part.getFrom()).contains(card)) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(card.getName()); sb.append(card.getName());
sb.append(" - Exile?"); sb.append(" - Exile?");