mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
consolidating AllZone.GameAction.isCardInZone(...) function to AllZoneUtil.isCardInZone(...) to reduce code duplication
This commit is contained in:
@@ -99,7 +99,7 @@ public class AllZone implements NewConstants {
|
||||
{
|
||||
p = (PlayerZone)it.next();
|
||||
|
||||
if(GameAction.isCardInZone(c, p))
|
||||
if(AllZoneUtil.isCardInZone(p, c))
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -188,7 +188,7 @@ public class GameAction {
|
||||
Ability ability = new Ability(pVoid, "0") {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if(AllZone.GameAction.isCardInZone(voidingCard, grave))
|
||||
if(AllZoneUtil.isCardInZone(grave, 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("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(Source.getController().equals(AllZone.HumanPlayer)) {
|
||||
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("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[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.HumanPlayer)) {
|
||||
paidCommand.execute();
|
||||
@@ -2189,6 +2189,7 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean isCardInZone(Card card, PlayerZone p) {
|
||||
ArrayList<Card> list = new ArrayList<Card>(Arrays.asList(p.getCards()));
|
||||
return list.contains(card);
|
||||
@@ -2687,16 +2688,16 @@ public class GameAction {
|
||||
SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility());
|
||||
ArrayList<String> choices = new ArrayList<String>();
|
||||
|
||||
if(c.isLand() && isCardInZone(c, AllZone.Human_Hand) && AllZone.HumanPlayer.canPlayLand())
|
||||
choices.add("Play land");
|
||||
|
||||
if(c.isLand() && AllZoneUtil.isCardInZone(AllZone.Human_Hand, c) && AllZone.HumanPlayer.canPlayLand())
|
||||
choices.add("Play land");
|
||||
|
||||
for(SpellAbility sa:abilities) {
|
||||
// for uncastables like lotus bloom, check if manaCost is blank
|
||||
sa.setActivatingPlayer(AllZone.HumanPlayer);
|
||||
if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) {
|
||||
choices.add(sa.toString());
|
||||
map.put(sa.toString(), sa);
|
||||
}
|
||||
if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) {
|
||||
choices.add(sa.toString());
|
||||
map.put(sa.toString(), sa);
|
||||
}
|
||||
}
|
||||
|
||||
String choice;
|
||||
|
||||
@@ -409,9 +409,7 @@ public class GameActionUtil {
|
||||
{
|
||||
final Player controller = c.getController();
|
||||
final PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, controller);
|
||||
final PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, controller);
|
||||
CardList list = new CardList();
|
||||
list.addAll(grave.getCards());
|
||||
CardList list = AllZoneUtil.getPlayerGraveyard(controller);
|
||||
list = list.getName("Vengevine");
|
||||
if(list.size() > 0) {
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
@@ -419,18 +417,18 @@ public class GameActionUtil {
|
||||
Ability ability = new Ability(card, "0") {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if(controller == AllZone.HumanPlayer){
|
||||
if(controller.isHuman()){
|
||||
Object[] possibleValues = {"Yes", "No"};
|
||||
Object q = JOptionPane.showOptionDialog(null, "Return Vengevine from the graveyard?", "Vengevine Ability",
|
||||
JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
|
||||
null, possibleValues, possibleValues[0]);
|
||||
if(q.equals(0)) {
|
||||
if(AllZone.GameAction.isCardInZone(card, grave)) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(controller, card)) {
|
||||
AllZone.GameAction.moveTo(play, card);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(AllZone.GameAction.isCardInZone(card, grave)) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(controller, card)) {
|
||||
AllZone.GameAction.moveTo(play, card);
|
||||
}
|
||||
}
|
||||
@@ -2339,10 +2337,9 @@ public class GameActionUtil {
|
||||
public void resolve() {
|
||||
Card target = getTargetCard();
|
||||
if(target != null){
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, src.getController());
|
||||
if(AllZone.GameAction.isCardInZone(getTargetCard(), grave)) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(src.getController(), target)) {
|
||||
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;
|
||||
|
||||
public void execute() {
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, src.getController());
|
||||
CardList list = new CardList(grave.getCards());
|
||||
|
||||
list = list.filter(new CardListFilter() {
|
||||
public boolean addCard(Card crd) {
|
||||
return crd.isCreature();
|
||||
}
|
||||
});
|
||||
// list = list.getType("Creature");
|
||||
CardList list = AllZoneUtil.getPlayerGraveyard(src.getController());
|
||||
list = list.filter(AllZoneUtil.creatures);
|
||||
|
||||
if(list.isEmpty()) {
|
||||
AllZone.Stack.addSimultaneousStackEntry(ability);
|
||||
|
||||
@@ -23,8 +23,8 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone {
|
||||
|
||||
super.add(o);
|
||||
|
||||
Card c = (Card) o;
|
||||
//final Player player = c.getController();
|
||||
final Card c = (Card) o;
|
||||
final Player player = c.getController();
|
||||
|
||||
if(trigger && ((CardFactoryUtil.oppHasKismet(c.getController()) && (c.isLand() || c.isCreature() || c.isArtifact()))
|
||||
|| (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
|
||||
CardList tis = AllZoneUtil.getCardsInPlay("Tectonic Instability");
|
||||
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) {
|
||||
for(int i = 0; i < meek.size(); i++) {
|
||||
final Card crd = meek.get(i);
|
||||
final Card creat = c;
|
||||
final PlayerZone graveZone = grave;
|
||||
|
||||
Ability ability = new Ability(meek.get(i), "0") {
|
||||
@Override
|
||||
public void resolve() {
|
||||
if(crd.getController().equals(AllZone.HumanPlayer)) {
|
||||
if(GameActionUtil.showYesNoDialog(crd, "Attach " + crd + " to " + creat + "?")) {
|
||||
if(AllZone.GameAction.isCardInZone(crd, graveZone)
|
||||
&& AllZoneUtil.isCardInPlay(creat) && creat.isCreature()
|
||||
&& creat.getNetAttack() == 1 && creat.getNetDefense() == 1) {
|
||||
if(crd.getController().isHuman()) {
|
||||
if(GameActionUtil.showYesNoDialog(crd, "Attach " + crd + " to " + c + "?")) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(player, crd)
|
||||
&& AllZoneUtil.isCardInPlay(c) && c.isCreature()
|
||||
&& c.getNetAttack() == 1 && c.getNetDefense() == 1) {
|
||||
AllZone.GameAction.moveToPlay(crd);
|
||||
|
||||
crd.equipCard(creat);
|
||||
crd.equipCard(c);
|
||||
}
|
||||
}
|
||||
|
||||
} else //computer
|
||||
{
|
||||
if(AllZone.GameAction.isCardInZone(crd, graveZone)
|
||||
&& AllZoneUtil.isCardInPlay(creat) && creat.isCreature()
|
||||
&& creat.getNetAttack() == 1 && creat.getNetDefense() == 1) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(player, crd)
|
||||
&& AllZoneUtil.isCardInPlay(c) && c.isCreature()
|
||||
&& c.getNetAttack() == 1 && c.getNetDefense() == 1) {
|
||||
AllZone.GameAction.moveToPlay(crd);
|
||||
|
||||
crd.equipCard(creat);
|
||||
crd.equipCard(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,12 +888,10 @@ public class CardFactoryUtil {
|
||||
|
||||
@Override
|
||||
public boolean canPlay() {
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, sourceCard.getController());
|
||||
|
||||
ArrayList<Card> spellsOnStack = AllZone.Stack.getSourceCards();
|
||||
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()));
|
||||
|
||||
}
|
||||
|
||||
@@ -958,7 +958,7 @@ class CardFactory_Auras {
|
||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
|
||||
|
||||
// Animate Dead got destroyed before its ability resolved
|
||||
if (!AllZone.GameAction.isCardInZone(card, play))
|
||||
if (!AllZoneUtil.isCardInZone(play, card))
|
||||
return;
|
||||
|
||||
Card animated = targetC[0];
|
||||
@@ -1002,7 +1002,7 @@ class CardFactory_Auras {
|
||||
|
||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
|
||||
|
||||
if(AllZone.GameAction.isCardInZone(c, play)) {
|
||||
if(AllZoneUtil.isCardInZone(play, c)) {
|
||||
AllZone.GameAction.sacrifice(c);
|
||||
}
|
||||
}
|
||||
@@ -1016,7 +1016,7 @@ class CardFactory_Auras {
|
||||
|
||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
|
||||
|
||||
if(AllZone.GameAction.isCardInZone(c, play))
|
||||
if(AllZoneUtil.isCardInZone(play, c))
|
||||
AllZone.Stack.addSimultaneousStackEntry(detach);
|
||||
|
||||
}
|
||||
|
||||
@@ -424,9 +424,7 @@ public class CardFactory_Creatures {
|
||||
|
||||
@Override
|
||||
public boolean canPlay() {
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
|
||||
|
||||
return AllZone.GameAction.isCardInZone(card, grave);
|
||||
return AllZoneUtil.isCardInPlayerGraveyard(card.getController(), card);
|
||||
}
|
||||
};//Ability
|
||||
|
||||
@@ -525,14 +523,14 @@ public class CardFactory_Creatures {
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
// TODO: change to static ability?
|
||||
// TODO: change to static ability?
|
||||
CardList library = AllZoneUtil.getPlayerCardsInLibrary(card.getController());
|
||||
if(library.size() == 0)
|
||||
return;
|
||||
|
||||
Card top = library.get(0);
|
||||
if(top.isLand())
|
||||
card.getController().playLand(top);
|
||||
|
||||
Card top = library.get(0);
|
||||
if(top.isLand())
|
||||
card.getController().playLand(top);
|
||||
}//resolve()
|
||||
|
||||
@Override
|
||||
@@ -542,7 +540,7 @@ public class CardFactory_Creatures {
|
||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, card.getController());
|
||||
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
|
||||
|
||||
@@ -1606,7 +1604,7 @@ public class CardFactory_Creatures {
|
||||
PlayerZone grave = AllZone.getZone(target[0]);
|
||||
//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());
|
||||
target[0].setController(card.getController());
|
||||
AllZone.GameAction.moveTo(play, target[0]);
|
||||
@@ -2323,7 +2321,7 @@ public class CardFactory_Creatures {
|
||||
@Override
|
||||
public void resolve() {
|
||||
Card c = null;
|
||||
if(card.getController().equals(AllZone.HumanPlayer)) {
|
||||
if(card.getController().isHuman()) {
|
||||
Object o = GuiUtils.getChoiceOptional("Select Elemental", getCreatures());
|
||||
c = (Card) o;
|
||||
|
||||
@@ -2331,9 +2329,7 @@ public class CardFactory_Creatures {
|
||||
c = getAIElemental();
|
||||
}
|
||||
|
||||
PlayerZone grave = AllZone.getZone(c);
|
||||
|
||||
if(AllZone.GameAction.isCardInZone(c, grave)) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c)) {
|
||||
PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getController());
|
||||
AllZone.GameAction.moveTo(play, c);
|
||||
}
|
||||
|
||||
@@ -446,9 +446,8 @@ public class CardFactory_Sorceries {
|
||||
if(biggest.getNetAttack() < creature.get(i).getNetAttack()) biggest = creature.get(i);
|
||||
c2 = biggest;
|
||||
}
|
||||
}
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
|
||||
if(AllZone.GameAction.isCardInZone(c2, grave)) {
|
||||
}
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c2)) {
|
||||
AllZone.GameAction.moveToHand(c2);
|
||||
}
|
||||
// Player Draws 3 Cards
|
||||
@@ -3524,20 +3523,18 @@ public class CardFactory_Sorceries {
|
||||
|
||||
@Override
|
||||
public void resolve() {
|
||||
CardList threshold = new CardList();
|
||||
PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, card.getController());
|
||||
threshold.addAll(grave.getCards());
|
||||
CardList threshold = AllZoneUtil.getPlayerGraveyard(card.getController());
|
||||
Card c = getTargetCard();
|
||||
|
||||
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());
|
||||
AllZone.GameAction.moveTo(play, c);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
if(AllZone.GameAction.isCardInZone(c, grave)) {
|
||||
if(AllZoneUtil.isCardInPlayerGraveyard(card.getController(), c)) {
|
||||
PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, card.getController());
|
||||
AllZone.GameAction.moveTo(hand, c);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user