consolidating AllZone.GameAction.isCardInZone(...) function to AllZoneUtil.isCardInZone(...) to reduce code duplication

This commit is contained in:
jendave
2011-08-06 23:36:04 +00:00
parent 8b6f45ba75
commit 015c89c206
8 changed files with 51 additions and 92 deletions

View File

@@ -99,7 +99,7 @@ public class AllZone implements NewConstants {
{ {
p = (PlayerZone)it.next(); p = (PlayerZone)it.next();
if(GameAction.isCardInZone(c, p)) if(AllZoneUtil.isCardInZone(p, c))
return p; return p;
} }
return null; return null;

View File

@@ -188,7 +188,7 @@ public class GameAction {
Ability ability = new Ability(pVoid, "0") { Ability ability = new Ability(pVoid, "0") {
@Override @Override
public void resolve() { public void resolve() {
if(AllZone.GameAction.isCardInZone(voidingCard, grave)) if(AllZoneUtil.isCardInZone(grave, voidingCard))
moveTo(AllZone.getZone(Constant.Zone.Exile, voidingCard.getOwner()), voidingCard); moveTo(AllZone.getZone(Constant.Zone.Exile, voidingCard.getOwner()), voidingCard);
} }
@@ -2024,7 +2024,7 @@ public class GameAction {
if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController());
//if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController());
if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { if(AllZoneUtil.isCardInZone(Required_Zone[0], Source) || Zones.equals("Any")) {
if(Keyword_Details[7].equals("Yes_No")) { if(Keyword_Details[7].equals("Yes_No")) {
if(Source.getController().equals(AllZone.HumanPlayer)) { if(Source.getController().equals(AllZone.HumanPlayer)) {
Object[] possibleValues = {"Yes", "No"}; Object[] possibleValues = {"Yes", "No"};
@@ -2063,7 +2063,7 @@ public class GameAction {
if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController());
//if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController());
if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { if(AllZoneUtil.isCardInZone(Required_Zone[0], Source) || Zones.equals("Any")) {
if(Keyword_Details[6].equals("ASAP")) { if(Keyword_Details[6].equals("ASAP")) {
if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.HumanPlayer)) { if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.HumanPlayer)) {
paidCommand.execute(); paidCommand.execute();
@@ -2189,6 +2189,7 @@ public class GameAction {
} }
} }
@Deprecated
public boolean isCardInZone(Card card, PlayerZone p) { public boolean isCardInZone(Card card, PlayerZone p) {
ArrayList<Card> list = new ArrayList<Card>(Arrays.asList(p.getCards())); ArrayList<Card> list = new ArrayList<Card>(Arrays.asList(p.getCards()));
return list.contains(card); return list.contains(card);
@@ -2687,16 +2688,16 @@ public class GameAction {
SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility()); SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility());
ArrayList<String> choices = new ArrayList<String>(); ArrayList<String> choices = new ArrayList<String>();
if(c.isLand() && isCardInZone(c, AllZone.Human_Hand) && AllZone.HumanPlayer.canPlayLand()) if(c.isLand() && AllZoneUtil.isCardInZone(AllZone.Human_Hand, c) && AllZone.HumanPlayer.canPlayLand())
choices.add("Play land"); choices.add("Play land");
for(SpellAbility sa:abilities) { for(SpellAbility sa:abilities) {
// for uncastables like lotus bloom, check if manaCost is blank // for uncastables like lotus bloom, check if manaCost is blank
sa.setActivatingPlayer(AllZone.HumanPlayer); sa.setActivatingPlayer(AllZone.HumanPlayer);
if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) { if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) {
choices.add(sa.toString()); choices.add(sa.toString());
map.put(sa.toString(), sa); map.put(sa.toString(), sa);
} }
} }
String choice; String choice;

View File

@@ -409,9 +409,7 @@ public class GameActionUtil {
{ {
final Player controller = c.getController(); final Player controller = c.getController();
final PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, controller); final PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, controller);
final PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, controller); CardList list = AllZoneUtil.getPlayerGraveyard(controller);
CardList list = new CardList();
list.addAll(grave.getCards());
list = list.getName("Vengevine"); list = list.getName("Vengevine");
if(list.size() > 0) { if(list.size() > 0) {
for(int i = 0; i < list.size(); i++) { for(int i = 0; i < list.size(); i++) {
@@ -419,18 +417,18 @@ public class GameActionUtil {
Ability ability = new Ability(card, "0") { Ability ability = new Ability(card, "0") {
@Override @Override
public void resolve() { public void resolve() {
if(controller == AllZone.HumanPlayer){ if(controller.isHuman()){
Object[] possibleValues = {"Yes", "No"}; Object[] possibleValues = {"Yes", "No"};
Object q = JOptionPane.showOptionDialog(null, "Return Vengevine from the graveyard?", "Vengevine Ability", Object q = JOptionPane.showOptionDialog(null, "Return Vengevine from the graveyard?", "Vengevine Ability",
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
null, possibleValues, possibleValues[0]); null, possibleValues, possibleValues[0]);
if(q.equals(0)) { if(q.equals(0)) {
if(AllZone.GameAction.isCardInZone(card, grave)) { if(AllZoneUtil.isCardInPlayerGraveyard(controller, card)) {
AllZone.GameAction.moveTo(play, card); AllZone.GameAction.moveTo(play, card);
} }
} }
} else { } else {
if(AllZone.GameAction.isCardInZone(card, grave)) { if(AllZoneUtil.isCardInPlayerGraveyard(controller, card)) {
AllZone.GameAction.moveTo(play, card); AllZone.GameAction.moveTo(play, card);
} }
} }
@@ -2339,10 +2337,9 @@ public class GameActionUtil {
public void resolve() { public void resolve() {
Card target = getTargetCard(); Card target = getTargetCard();
if(target != null){ if(target != null){
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, src.getController()); if(AllZoneUtil.isCardInPlayerGraveyard(src.getController(), target)) {
if(AllZone.GameAction.isCardInZone(getTargetCard(), grave)) {
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, src.getController()); PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, src.getController());
AllZone.GameAction.moveTo(hand, getTargetCard()); AllZone.GameAction.moveTo(hand, target);
} }
} }
@@ -2354,15 +2351,8 @@ public class GameActionUtil {
private static final long serialVersionUID = -7433708170033536384L; private static final long serialVersionUID = -7433708170033536384L;
public void execute() { public void execute() {
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, src.getController()); CardList list = AllZoneUtil.getPlayerGraveyard(src.getController());
CardList list = new CardList(grave.getCards()); list = list.filter(AllZoneUtil.creatures);
list = list.filter(new CardListFilter() {
public boolean addCard(Card crd) {
return crd.isCreature();
}
});
// list = list.getType("Creature");
if(list.isEmpty()) { if(list.isEmpty()) {
AllZone.Stack.addSimultaneousStackEntry(ability); AllZone.Stack.addSimultaneousStackEntry(ability);

View File

@@ -23,8 +23,8 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
super.add(o); super.add(o);
Card c = (Card) o; final Card c = (Card) o;
//final Player player = c.getController(); final Player player = c.getController();
if(trigger && ((CardFactoryUtil.oppHasKismet(c.getController()) && (c.isLand() || c.isCreature() || c.isArtifact())) if(trigger && ((CardFactoryUtil.oppHasKismet(c.getController()) && (c.isLand() || c.isCreature() || c.isArtifact()))
|| (AllZoneUtil.isCardInPlay("Urabrask the Hidden",c.getController().getOpponent()) && c.isCreature()) || (AllZoneUtil.isCardInPlay("Urabrask the Hidden",c.getController().getOpponent()) && c.isCreature())
@@ -121,27 +121,6 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
} }
} }
/* Converted to AF trigger
CardList seeds = AllZoneUtil.getCardsInPlay("Seed the Land");
final Card seedLand = c;
for(Card seed:seeds) {
final Card source = seed;
SpellAbility ability = new Ability(source, "") {
@Override
public void resolve() {
CardFactoryUtil.makeToken("Snake", "G 1 1 Snake", seedLand.getController(),
"G", new String[] {"Creature", "Snake"}, 1, 1, new String[] {});
}
};
StringBuilder sb = new StringBuilder();
sb.append(source).append(" - ").append(seedLand.getController());
sb.append(" puts a 1/1 green Snake token onto the battlefield.");
ability.setStackDescription(sb.toString());
AllZone.Stack.add(ability);
}
*/
//Tectonic Instability //Tectonic Instability
CardList tis = AllZoneUtil.getCardsInPlay("Tectonic Instability"); CardList tis = AllZoneUtil.getCardsInPlay("Tectonic Instability");
final Card tisLand = c; final Card tisLand = c;
@@ -206,31 +185,29 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
if(meek.size() > 0 && c.isCreature() && c.getNetAttack() == 1 && c.getNetDefense() == 1) { if(meek.size() > 0 && c.isCreature() && c.getNetAttack() == 1 && c.getNetDefense() == 1) {
for(int i = 0; i < meek.size(); i++) { for(int i = 0; i < meek.size(); i++) {
final Card crd = meek.get(i); final Card crd = meek.get(i);
final Card creat = c;
final PlayerZone graveZone = grave;
Ability ability = new Ability(meek.get(i), "0") { Ability ability = new Ability(meek.get(i), "0") {
@Override @Override
public void resolve() { public void resolve() {
if(crd.getController().equals(AllZone.HumanPlayer)) { if(crd.getController().isHuman()) {
if(GameActionUtil.showYesNoDialog(crd, "Attach " + crd + " to " + creat + "?")) { if(GameActionUtil.showYesNoDialog(crd, "Attach " + crd + " to " + c + "?")) {
if(AllZone.GameAction.isCardInZone(crd, graveZone) if(AllZoneUtil.isCardInPlayerGraveyard(player, crd)
&& AllZoneUtil.isCardInPlay(creat) && creat.isCreature() && AllZoneUtil.isCardInPlay(c) && c.isCreature()
&& creat.getNetAttack() == 1 && creat.getNetDefense() == 1) { && c.getNetAttack() == 1 && c.getNetDefense() == 1) {
AllZone.GameAction.moveToPlay(crd); AllZone.GameAction.moveToPlay(crd);
crd.equipCard(creat); crd.equipCard(c);
} }
} }
} else //computer } else //computer
{ {
if(AllZone.GameAction.isCardInZone(crd, graveZone) if(AllZoneUtil.isCardInPlayerGraveyard(player, crd)
&& AllZoneUtil.isCardInPlay(creat) && creat.isCreature() && AllZoneUtil.isCardInPlay(c) && c.isCreature()
&& creat.getNetAttack() == 1 && creat.getNetDefense() == 1) { && c.getNetAttack() == 1 && c.getNetDefense() == 1) {
AllZone.GameAction.moveToPlay(crd); AllZone.GameAction.moveToPlay(crd);
crd.equipCard(creat); crd.equipCard(c);
} }
} }
} }

View File

@@ -888,12 +888,10 @@ public class CardFactoryUtil {
@Override @Override
public boolean canPlay() { public boolean canPlay() {
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, sourceCard.getController());
ArrayList<Card> spellsOnStack = AllZone.Stack.getSourceCards(); ArrayList<Card> spellsOnStack = AllZone.Stack.getSourceCards();
Card sourceCard = this.getSourceCard(); Card sourceCard = this.getSourceCard();
return AllZone.GameAction.isCardInZone(sourceCard, grave) && !spellsOnStack.contains(sourceCard) return AllZoneUtil.isCardInPlayerGraveyard(sourceCard.getController(), sourceCard) && !spellsOnStack.contains(sourceCard)
&& (sourceCard.isInstant() || Phase.canCastSorcery(sourceCard.getController())); && (sourceCard.isInstant() || Phase.canCastSorcery(sourceCard.getController()));
} }

View File

@@ -958,7 +958,7 @@ class CardFactory_Auras {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
// Animate Dead got destroyed before its ability resolved // Animate Dead got destroyed before its ability resolved
if (!AllZone.GameAction.isCardInZone(card, play)) if (!AllZoneUtil.isCardInZone(play, card))
return; return;
Card animated = targetC[0]; Card animated = targetC[0];
@@ -1002,7 +1002,7 @@ class CardFactory_Auras {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
if(AllZone.GameAction.isCardInZone(c, play)) { if(AllZoneUtil.isCardInZone(play, c)) {
AllZone.GameAction.sacrifice(c); AllZone.GameAction.sacrifice(c);
} }
} }
@@ -1016,7 +1016,7 @@ class CardFactory_Auras {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
if(AllZone.GameAction.isCardInZone(c, play)) if(AllZoneUtil.isCardInZone(play, c))
AllZone.Stack.addSimultaneousStackEntry(detach); AllZone.Stack.addSimultaneousStackEntry(detach);
} }

View File

@@ -424,9 +424,7 @@ public class CardFactory_Creatures {
@Override @Override
public boolean canPlay() { public boolean canPlay() {
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); return AllZoneUtil.isCardInPlayerGraveyard(card.getController(), card);
return AllZone.GameAction.isCardInZone(card, grave);
} }
};//Ability };//Ability
@@ -525,14 +523,14 @@ public class CardFactory_Creatures {
@Override @Override
public void resolve() { public void resolve() {
// TODO: change to static ability? // TODO: change to static ability?
CardList library = AllZoneUtil.getPlayerCardsInLibrary(card.getController()); CardList library = AllZoneUtil.getPlayerCardsInLibrary(card.getController());
if(library.size() == 0) if(library.size() == 0)
return; return;
Card top = library.get(0); Card top = library.get(0);
if(top.isLand()) if(top.isLand())
card.getController().playLand(top); card.getController().playLand(top);
}//resolve() }//resolve()
@Override @Override
@@ -542,7 +540,7 @@ public class CardFactory_Creatures {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
boolean canPlayLand = card.getController().canPlayLand(); boolean canPlayLand = card.getController().canPlayLand();
return (AllZone.GameAction.isCardInZone(card, play) && library.get(0).isLand() && canPlayLand); return (AllZoneUtil.isCardInZone(play, card) && library.get(0).isLand() && canPlayLand);
} }
};//SpellAbility };//SpellAbility
@@ -1606,7 +1604,7 @@ public class CardFactory_Creatures {
PlayerZone grave = AllZone.getZone(target[0]); PlayerZone grave = AllZone.getZone(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 && AllZone.GameAction.isCardInZone(target[0], grave)) { if(grave != null && AllZoneUtil.isCardInZone(grave, target[0])) {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
target[0].setController(card.getController()); target[0].setController(card.getController());
AllZone.GameAction.moveTo(play, target[0]); AllZone.GameAction.moveTo(play, target[0]);
@@ -2323,7 +2321,7 @@ public class CardFactory_Creatures {
@Override @Override
public void resolve() { public void resolve() {
Card c = null; Card c = null;
if(card.getController().equals(AllZone.HumanPlayer)) { if(card.getController().isHuman()) {
Object o = GuiUtils.getChoiceOptional("Select Elemental", getCreatures()); Object o = GuiUtils.getChoiceOptional("Select Elemental", getCreatures());
c = (Card) o; c = (Card) o;
@@ -2331,9 +2329,7 @@ public class CardFactory_Creatures {
c = getAIElemental(); c = getAIElemental();
} }
PlayerZone grave = AllZone.getZone(c); if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c)) {
if(AllZone.GameAction.isCardInZone(c, grave)) {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getController());
AllZone.GameAction.moveTo(play, c); AllZone.GameAction.moveTo(play, c);
} }

View File

@@ -447,8 +447,7 @@ public class CardFactory_Sorceries {
c2 = biggest; c2 = biggest;
} }
} }
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c2)) {
if(AllZone.GameAction.isCardInZone(c2, grave)) {
AllZone.GameAction.moveToHand(c2); AllZone.GameAction.moveToHand(c2);
} }
// Player Draws 3 Cards // Player Draws 3 Cards
@@ -3524,20 +3523,18 @@ public class CardFactory_Sorceries {
@Override @Override
public void resolve() { public void resolve() {
CardList threshold = new CardList(); CardList threshold = AllZoneUtil.getPlayerGraveyard(card.getController());
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
threshold.addAll(grave.getCards());
Card c = getTargetCard(); Card c = getTargetCard();
if(threshold.size() >= 7) { if(threshold.size() >= 7) {
if(AllZone.GameAction.isCardInZone(c, grave)) { if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c)) {
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
AllZone.GameAction.moveTo(play, c); AllZone.GameAction.moveTo(play, c);
} }
} }
else { else {
if(AllZone.GameAction.isCardInZone(c, grave)) { if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c)) {
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController()); PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
AllZone.GameAction.moveTo(hand, c); AllZone.GameAction.moveTo(hand, c);
} }