From 06bf9d3e655bdb4cec673e6aeb642d7c7ce7795e Mon Sep 17 00:00:00 2001 From: Sol Date: Wed, 20 Mar 2013 01:31:33 +0000 Subject: [PATCH] - Convert Global Ruin to script. --- res/cardsfolder/g/global_ruin.txt | 3 +- res/cardsfolder/s/sundering_titan.txt | 2 +- src/main/java/forge/Card.java | 4 + .../ability/effects/ChooseCardEffect.java | 59 +++--- .../cardfactory/CardFactorySorceries.java | 182 ------------------ 5 files changed, 38 insertions(+), 212 deletions(-) diff --git a/res/cardsfolder/g/global_ruin.txt b/res/cardsfolder/g/global_ruin.txt index bdc012d295b..c27f172f938 100644 --- a/res/cardsfolder/g/global_ruin.txt +++ b/res/cardsfolder/g/global_ruin.txt @@ -1,7 +1,8 @@ Name:Global Ruin ManaCost:4 W Types:Sorcery -Text:Each player chooses from the lands he or she controls a land of each basic land type and sacrifices the rest. +A:SP$ ChooseCard | Cost$ 4 W | Defined$ Player | EachBasicType$ Controlled | SubAbility$ DBDestroy | SpellDescription$ Each player chooses from the lands he or she controls a land of each basic land type, then sacrifices the rest. | StackDescription$ SpellDescription +SVar:DBDestroy:DB$ SacrificeAll | ValidCards$ Land.nonChosenCard | StackDescription$ None SVar:RemRandomDeck:True SVar:Picture:http://www.wizards.com/global/images/magic/general/global_ruin.jpg Oracle:Each player chooses from the lands he or she controls a land of each basic land type, then sacrifices the rest. diff --git a/res/cardsfolder/s/sundering_titan.txt b/res/cardsfolder/s/sundering_titan.txt index 6b04f9ace79..bc3149e4b98 100644 --- a/res/cardsfolder/s/sundering_titan.txt +++ b/res/cardsfolder/s/sundering_titan.txt @@ -4,7 +4,7 @@ Types:Artifact Creature Golem PT:7/10 T:Mode$ ChangesZone | ValidCard$ Card.Self | Origin$ Any | Destination$ Battlefield | Execute$ TrigChoose | TriggerDescription$ When CARDNAME enters the battlefield or leaves the battlefield, choose a land of each basic land type, then destroy those lands. T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Any | ValidCard$ Card.Self | Execute$ TrigChoose | Secondary$ True | TriggerDescription$ When CARDNAME enters the battlefield or leaves the battlefield, choose a land of each basic land type, then destroy those lands. -SVar:TrigChoose:AB$ ChooseCard | Cost$ 0 | Defined$ You | SunderingTitan$ True | SubAbility$ DBDestroy +SVar:TrigChoose:AB$ ChooseCard | Cost$ 0 | Defined$ You | EachBasicType$ Land | SubAbility$ DBDestroy SVar:DBDestroy:DB$ DestroyAll | ValidCards$ Card.ChosenCard | SpellDescription$ Destroy all chosen cards. SVar:RemAIDeck:True SVar:Picture:http://www.wizards.com/global/images/magic/general/sundering_titan.jpg diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 5bb08883f00..5c31bf8c8b2 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -6145,6 +6145,10 @@ public class Card extends GameEntity implements Comparable { if (!source.getChosenCard().contains(this)) { return false; } + } else if (property.equals("nonChosenCard")) { + if (source.getChosenCard().contains(this)) { + return false; + } } // ... Card colors else if (property.contains("White") || property.contains("Blue") || property.contains("Black") diff --git a/src/main/java/forge/card/ability/effects/ChooseCardEffect.java b/src/main/java/forge/card/ability/effects/ChooseCardEffect.java index 995c802b9bf..afa68b2b6b0 100644 --- a/src/main/java/forge/card/ability/effects/ChooseCardEffect.java +++ b/src/main/java/forge/card/ability/effects/ChooseCardEffect.java @@ -54,25 +54,28 @@ public class ChooseCardEffect extends SpellAbilityEffect { final int validAmount = !numericAmount.matches("[0-9][0-9]?") ? CardFactoryUtil.xCount(host, host.getSVar(sa.getParam("Amount"))) : Integer.parseInt(numericAmount); - if (sa.hasParam("SunderingTitan")) { - final List land = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.LANDS); - for (final String type : CardType.getBasicTypes()) { - final List cl = CardLists.getType(land, type); - if (cl.size() > 0) { - final String prompt = "Choose a" + (type.equals("Island") ? "n " : " ") + type; - final Object o = GuiChoose.one(prompt, cl); - if (null != o) { - final Card c = (Card) o; - chosen.add(c); + for (final Player p : tgtPlayers) { + if (sa.hasParam("EachBasicType")) { + // Get all lands, + List land = CardLists.filter(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield), Presets.LANDS); + String eachBasic = sa.getParam("EachBasicType"); + if (eachBasic.equals("Controlled")) { + land = CardLists.filterControlledBy(land, p); + } + + // Choose one of each BasicLand given special place + for (final String type : CardType.getBasicTypes()) { + final List cl = CardLists.getType(land, type); + if (!cl.isEmpty()) { + final String prompt = "Choose a" + (type.equals("Island") ? "n " : " ") + type; + Card c = p.getController().chooseSingleCardForEffect(cl, sa, prompt, true); + + if (null != c) { + chosen.add(c); + } } } - } - host.setChosenCard(chosen); - return; - } - - for (final Player p : tgtPlayers) { - if ((tgt == null) || p.canBeTargetedBy(sa)) { + } else if ((tgt == null) || p.canBeTargetedBy(sa)) { for (int i = 0; i < validAmount; i++) { Card c; @@ -89,17 +92,17 @@ public class ChooseCardEffect extends SpellAbilityEffect { break; } } - host.setChosenCard(chosen); - if (sa.hasParam("RememberChosen")) { - for (final Card rem : chosen) { - host.addRemembered(rem); - } - } - if (sa.hasParam("ForgetChosen")) { - for (final Card rem : chosen) { - host.removeRemembered(rem); - } - } + } + } + host.setChosenCard(chosen); + if (sa.hasParam("RememberChosen")) { + for (final Card rem : chosen) { + host.addRemembered(rem); + } + } + if (sa.hasParam("ForgetChosen")) { + for (final Card rem : chosen) { + host.removeRemembered(rem); } } } diff --git a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java index 07291bd975d..2c9322d99b2 100644 --- a/src/main/java/forge/card/cardfactory/CardFactorySorceries.java +++ b/src/main/java/forge/card/cardfactory/CardFactorySorceries.java @@ -248,187 +248,6 @@ public class CardFactorySorceries { } - private static final SpellAbility getGlobalRuin(final Card card) { - final List target = new ArrayList(); - final List saveList = new ArrayList(); - // need to use arrays so we can declare them final and still set the - // values in the input and runtime classes. This is a hack. - final int[] index = new int[1]; - final int[] countBase = new int[1]; - final Vector humanBasic = new Vector(); - - final SpellAbility spell = new Spell(card) { - private static final long serialVersionUID = 5739127258598357186L; - - @Override - public boolean canPlayAI() { - return false; - // should check if computer has land in hand, or if computer - // has more basic land types than human. - } - - @Override - public void resolve() { - // add computer's lands to target - - // int computerCountBase = 0; - // Vector computerBasic = new Vector(); - - // figure out which basic land types the computer has - List land = Singletons.getControl().getPlayer().getOpponent().getLandsInPlay(); - - for (final String element : Constant.Color.BASIC_LANDS) { - final List cl = CardLists.getType(land, element); - if (!cl.isEmpty()) { - // remove one land of this basic type from this list - // the computer AI should really jump in here and - // select the land which is the best. - // to determine the best look at which lands have - // enchantments, which lands are tapped - cl.remove(cl.get(0)); - // add the rest of the lands of this basic type to - // the target list, this is the list which will be - // sacrificed. - target.addAll(cl); - } - } - - // need to sacrifice the other non-basic land types - land = CardLists.filter(land, new Predicate() { - @Override - public boolean apply(final Card c) { - if (c.getName().contains("Dryad Arbor")) { - return true; - } else { - return (!(c.isType("Forest") || c.isType("Plains") || c.isType("Mountain") - || c.isType("Island") || c.isType("Swamp"))); - } - } - }); - target.addAll(land); - - // when this spell resolves all basic lands which were not - // selected are sacrificed. - for (int i = 0; i < target.size(); i++) { - if (target.get(i).isInPlay() && !saveList.contains(target.get(i))) { - Singletons.getModel().getGame().getAction().sacrifice(target.get(i), this); - } - } - } // resolve() - }; // SpellAbility - - final Input input = new Input() { - private static final long serialVersionUID = 1739423591445361917L; - private int count; - - @Override - public void showMessage() { // count is the current index we are - // on. - // countBase[0] is the total number of basic land types the - // human has - // index[0] is the number to offset the index by - this.count = countBase[0] - index[0] - 1; // subtract by one - // since humanBasic is - // 0 indexed. - if (this.count < 0) { - // need to reset the variables in case they cancel this - // spell and it stays in hand. - humanBasic.clear(); - countBase[0] = 0; - index[0] = 0; - this.stop(); - } else { - final StringBuilder sb = new StringBuilder(); - sb.append("Select target ").append(humanBasic.get(this.count)); - sb.append(" land to not sacrifice"); - CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString()); - ButtonUtil.enableOnlyCancel(); - } - } - - @Override - public void selectButtonCancel() { - this.stop(); - } - - @Override - public void selectCard(final Card c) { - if (!c.isLand() || !Singletons.getControl().getPlayer().getZone(ZoneType.Battlefield).contains(c) ) - return; - - if ( !c.isType(humanBasic.get(this.count) ) ) return; - - List land = c.getController().getLandsInPlay(); - List cl = CardLists.getType(land, humanBasic.get(this.count)); - cl = CardLists.filter(cl, new Predicate() { - @Override - public boolean apply(final Card crd) { - return !saveList.contains(crd); - } - }); - - if (!c.getName().contains("Dryad Arbor")) { - cl.remove(c); - saveList.add(c); - } - target.addAll(cl); - - index[0]++; - this.showMessage(); - - if (index[0] >= humanBasic.size()) { - this.stopSetNext(new InputPayManaSimple(Singletons.getModel().getGame(), spell)); - } - - // need to sacrifice the other non-basic land types - land = CardLists.filter(land, new Predicate() { - @Override - public boolean apply(final Card c) { - if (c.getName().contains("Dryad Arbor")) { - return true; - } else { - return (!(c.isType("Forest") || c.isType("Plains") || c.isType("Mountain") - || c.isType("Island") || c.isType("Swamp"))); - } - } - }); - target.addAll(land); - - } // selectCard() - }; // Input - - final Input runtime = new Input() { - private static final long serialVersionUID = -122635387376995855L; - - @Override - public void showMessage() { - countBase[0] = 0; - // figure out which basic land types the human has - // put those in an set to use laters - final List land = Singletons.getControl().getPlayer().getCardsIn(ZoneType.Battlefield); - - for (final String element : Constant.Color.BASIC_LANDS) { - final List c = CardLists.getType(land, element); - if (!c.isEmpty()) { - humanBasic.add(element); - countBase[0]++; - } - } - if (countBase[0] == 0) { - // human has no basic land, so don't prompt to select - // one. - this.stop(); - } else { - index[0] = 0; - target.clear(); - this.stopSetNext(input); - } - } - }; // Input - spell.setBeforePayMana(runtime); - return spell; - } - private static final void balanceLands(Spell card) { List> lands = new ArrayList>(); @@ -676,7 +495,6 @@ public class CardFactorySorceries { public static void buildCard(final Card card, final String cardName) { if (cardName.equals("Brilliant Ultimatum")) { card.addSpellAbility(getBrilliantUltimatum(card)); - } else if (cardName.equals("Global Ruin")) { card.addSpellAbility(getGlobalRuin(card)); } else if (cardName.equals("Balance")) { card.addSpellAbility(getBalance(card)); } else if (cardName.equals("Patriarch's Bidding")) { card.addSpellAbility(getPatriarchsBidding(card)); } else if (cardName.equals("Transmute Artifact")) { card.addSpellAbility(getTransmuteArtifact(card));