- Cleanup and performance updates in AllZoneUtil.

This commit is contained in:
Sloth
2012-02-03 19:18:22 +00:00
parent 2f80d736c8
commit 5bb0769b62
6 changed files with 22 additions and 22 deletions

View File

@@ -178,7 +178,12 @@ public abstract class AllZoneUtil {
* @return true is the card is in play, false otherwise * @return true is the card is in play, false otherwise
*/ */
public static boolean isCardInPlay(final String cardName) { public static boolean isCardInPlay(final String cardName) {
return AllZoneUtil.getCardsIn(Zone.Battlefield, cardName).size() > 0; for (Card card : AllZoneUtil.getCardsIn(Zone.Battlefield)) {
if (card.getName() == cardName) {
return true;
}
}
return false;
} }
/** /**
@@ -191,7 +196,12 @@ public abstract class AllZoneUtil {
* @return true if that player has that card in play, false otherwise * @return true if that player has that card in play, false otherwise
*/ */
public static boolean isCardInPlay(final String cardName, final Player player) { public static boolean isCardInPlay(final String cardName, final Player player) {
return player.getCardsIn(Zone.Battlefield, cardName).size() > 0; for (Card card : player.getCardsIn(Zone.Battlefield)) {
if (card.getName() == cardName) {
return true;
}
}
return false;
} }
// ////////////// getting all cards of a given color // ////////////// getting all cards of a given color
@@ -300,15 +310,9 @@ public abstract class AllZoneUtil {
for (final Player player : AllZone.getPlayersInGame()) { for (final Player player : AllZone.getPlayersInGame()) {
all.addAll(player.getZone(Zone.Graveyard).getCards()); all.addAll(player.getZone(Zone.Graveyard).getCards());
all.addAll(player.getZone(Zone.Hand).getCards()); all.addAll(player.getZone(Zone.Hand).getCards());
all.addAll(player.getZone(Zone.Library).getCards()); // not sure if all.addAll(player.getZone(Zone.Library).getCards());
// library
// should be
// included.
all.addAll(player.getZone(Zone.Battlefield).getCards(false)); all.addAll(player.getZone(Zone.Battlefield).getCards(false));
all.addAll(player.getZone(Zone.Exile).getCards()); // Spawnsire of all.addAll(player.getZone(Zone.Exile).getCards());
// Ulamog plays
// spells from
// here?
} }
all.addAll(AllZone.getStackZone().getCards()); all.addAll(AllZone.getStackZone().getCards());
return all; return all;
@@ -411,13 +415,13 @@ public abstract class AllZoneUtil {
* a {@link forge.Card} object. * a {@link forge.Card} object.
* @return a boolean. * @return a boolean.
*/ */
public static boolean matchesValid(final Object o, final String[] valids, final Card srcCard) { /*public static boolean matchesValid(final Object o, final String[] valids, final Card srcCard) {
if (o instanceof GameEntity) { if (o instanceof GameEntity) {
final GameEntity c = (GameEntity) o; final GameEntity c = (GameEntity) o;
return c.isValid(valids, srcCard.getController(), srcCard); return c.isValid(valids, srcCard.getController(), srcCard);
} }
return false; return false;
} }*/
} // end class AllZoneUtil } // end class AllZoneUtil

View File

@@ -49,12 +49,12 @@ public class ReplaceDamage extends ReplacementEffect {
return false; return false;
} }
if (getMapParams().containsKey("ValidSource")) { if (getMapParams().containsKey("ValidSource")) {
if (!AllZoneUtil.matchesValid(runParams.get("DamageSource"), getMapParams().get("ValidSource").split(","), getHostCard())) { if (!matchesValid(runParams.get("DamageSource"), getMapParams().get("ValidSource").split(","), getHostCard())) {
return false; return false;
} }
} }
if (getMapParams().containsKey("ValidTarget")) { if (getMapParams().containsKey("ValidTarget")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), getMapParams().get("ValidTarget").split(","), getHostCard())) { if (!matchesValid(runParams.get("Affected"), getMapParams().get("ValidTarget").split(","), getHostCard())) {
return false; return false;
} }
} }

View File

@@ -19,7 +19,6 @@ package forge.card.replacement;
import java.util.HashMap; import java.util.HashMap;
import forge.AllZoneUtil;
import forge.Card; import forge.Card;
/** /**
@@ -47,7 +46,7 @@ public class ReplaceDraw extends ReplacementEffect {
return false; return false;
} }
if (this.getMapParams().containsKey("ValidPlayer")) { if (this.getMapParams().containsKey("ValidPlayer")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) { if (!matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) {
return false; return false;
} }
} }

View File

@@ -19,7 +19,6 @@ package forge.card.replacement;
import java.util.HashMap; import java.util.HashMap;
import forge.AllZoneUtil;
import forge.Card; import forge.Card;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -48,7 +47,7 @@ public class ReplaceGainLife extends ReplacementEffect {
return false; return false;
} }
if (this.getMapParams().containsKey("ValidPlayer")) { if (this.getMapParams().containsKey("ValidPlayer")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) { if (!matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) {
return false; return false;
} }
} }

View File

@@ -2,7 +2,6 @@ package forge.card.replacement;
import java.util.HashMap; import java.util.HashMap;
import forge.AllZoneUtil;
import forge.Card; import forge.Card;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -31,7 +30,7 @@ public class ReplaceGameLoss extends ReplacementEffect {
return false; return false;
} }
if (this.getMapParams().containsKey("ValidPlayer")) { if (this.getMapParams().containsKey("ValidPlayer")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) { if (!matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidPlayer").split(","), this.getHostCard())) {
return false; return false;
} }
} }

View File

@@ -2,7 +2,6 @@ package forge.card.replacement;
import java.util.HashMap; import java.util.HashMap;
import forge.AllZoneUtil;
import forge.Card; import forge.Card;
import forge.Constant.Zone; import forge.Constant.Zone;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
@@ -32,7 +31,7 @@ public class ReplaceMoved extends ReplacementEffect {
return false; return false;
} }
if (this.getMapParams().containsKey("ValidCard")) { if (this.getMapParams().containsKey("ValidCard")) {
if (!AllZoneUtil.matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidCard").split(","), this.getHostCard())) { if (!matchesValid(runParams.get("Affected"), this.getMapParams().get("ValidCard").split(","), this.getHostCard())) {
return false; return false;
} }
} }