From 010b625658d9ec89f5f8c0bb69000aa77a946ea3 Mon Sep 17 00:00:00 2001 From: jendave Date: Sun, 7 Aug 2011 01:10:05 +0000 Subject: [PATCH] - Moved Unless cost to AbilityFactory making it available for all AFs. --- src/forge/GameActionUtil.java | 16 +++++ .../card/abilityFactory/AbilityFactory.java | 64 ++++++++++++++++++- .../AbilityFactory_CounterMagic.java | 54 +--------------- 3 files changed, 79 insertions(+), 55 deletions(-) diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 69c4288fb20..273e4d79c8f 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -6908,5 +6908,21 @@ public class GameActionUtil { return affected; }//end getAffectedCards() }; + + + public static void doPowerSink(Player p) { + //get all lands with mana abilities + CardList lands = AllZoneUtil.getPlayerLandsInPlay(p); + lands = lands.filter(new CardListFilter() { + public boolean addCard(Card c) { + return c.getManaAbility().size() > 0; + } + }); + //tap them + for(Card c:lands) c.tap(); + + //empty mana pool + if(p.isHuman()) AllZone.ManaPool.clearPool(); + } }//end class GameActionUtil diff --git a/src/forge/card/abilityFactory/AbilityFactory.java b/src/forge/card/abilityFactory/AbilityFactory.java index 9c9ecf175de..dad7610f65a 100644 --- a/src/forge/card/abilityFactory/AbilityFactory.java +++ b/src/forge/card/abilityFactory/AbilityFactory.java @@ -7,9 +7,13 @@ import forge.AllZone; import forge.AllZoneUtil; import forge.Card; import forge.CardList; +import forge.Command; +import forge.ComputerUtil; import forge.Constant; +import forge.GameActionUtil; import forge.Player; import forge.card.cardFactory.CardFactoryUtil; +import forge.card.spellability.Ability; import forge.card.spellability.Ability_Sub; import forge.card.spellability.Cost; import forge.card.spellability.SpellAbility; @@ -1279,14 +1283,70 @@ public class AbilityFactory { } } + public static void passUnlessCost(final SpellAbility sa) { + Card source = sa.getSourceCard(); + AbilityFactory af = sa.getAbilityFactory(); + final HashMap params = af.getMapParams(); + + //Nothing to do + if (params.get("UnlessCost") == null) { + sa.resolve(); + return; + } + + //The player who has the chance to cancel the ability + String pays = params.containsKey("UnlessPayer") ? params.get("UnlessPayer") : "Opponent"; + Player payer = getDefinedPlayers(sa.getSourceCard(), pays, sa).get(0); + + //The cost + String unlessCost = params.get("UnlessCost").trim(); + if(unlessCost.equals("X")) + unlessCost = Integer.toString(CardFactoryUtil.xCount(source, source.getSVar("X"))); + // Above xCount should probably be changed to a AF.calculateAmount + + Ability ability = new Ability(source, unlessCost) { + @Override + public void resolve() { + ; + } + }; + + final Command unpaidCommand = new Command() { + private static final long serialVersionUID = 8094833091127334678L; + + public void execute() { + if(params.containsKey("PowerSink")) GameActionUtil.doPowerSink(AllZone.HumanPlayer); + sa.resolve(); + } + }; + + if(payer.isHuman()) { + GameActionUtil.payManaDuringAbilityResolve(source + "\r\n", ability.getManaCost(), + Command.Blank, unpaidCommand); + } else { + if(ComputerUtil.canPayCost(ability)) { + ComputerUtil.playNoStack(ability); //Unless cost was payed - no resolve + } + else { + if(params.containsKey("PowerSink")) GameActionUtil.doPowerSink(AllZone.ComputerPlayer); + sa.resolve(); + } + } + } + public static void resolve(SpellAbility sa) { if (sa == null) return; AbilityFactory af = sa.getAbilityFactory(); HashMap params = af.getMapParams(); + //check conditions - if (AbilityFactory.checkConditional(params, sa)) - sa.resolve(); + if (AbilityFactory.checkConditional(params, sa)) { + if (params.get("UnlessCost") == null) + sa.resolve(); + else passUnlessCost(sa); + } + //try to resolve subabilities (see null check above) Ability_Sub abSub = sa.getSubAbility(); diff --git a/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java b/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java index f3e9135dfd8..7e8e8ae3a09 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java +++ b/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java @@ -295,44 +295,7 @@ public class AbilityFactory_CounterMagic { Card tgtSACard = tgtSA.getSourceCard(); if (AllZone.Stack.contains(tgtSA) && !tgtSACard.keywordsContain("CARDNAME can't be countered.")){ - // TODO: Unless Cost should be generalized for all AFS - if(unlessCost != null) { - String unlessCostFinal = unlessCost; - if(unlessCost.equals("X")) - unlessCostFinal = Integer.toString(CardFactoryUtil.xCount(af.getHostCard(), af.getHostCard().getSVar("X"))); - // Above xCount should probably be changed to a AF.calculateAmount - - Ability ability = new Ability(af.getHostCard(), unlessCostFinal) { - @Override - public void resolve() { - ; - } - }; - - final Command unpaidCommand = new Command() { - private static final long serialVersionUID = 8094833091127334678L; - - public void execute() { - removeFromStack(tgtSA, sa); - if(params.containsKey("PowerSink")) doPowerSink(AllZone.HumanPlayer); - } - }; - - if(tgtSA.getActivatingPlayer().isHuman()) { - GameActionUtil.payManaDuringAbilityResolve(af.getHostCard() + "\r\n", ability.getManaCost(), - Command.Blank, unpaidCommand); - } else { - if(ComputerUtil.canPayCost(ability)) { - ComputerUtil.playNoStack(ability); - } - else { - removeFromStack(tgtSA,sa); - if(params.containsKey("PowerSink")) doPowerSink(AllZone.ComputerPlayer); - } - } - } - else - removeFromStack(tgtSA,sa); + removeFromStack(tgtSA,sa); // Destroy Permanent may be able to be turned into a SubAbility if(tgtSA.isAbility() && params.containsKey("DestroyPermanent")) { @@ -349,21 +312,6 @@ public class AbilityFactory_CounterMagic { } } }//end counterResolve - - private void doPowerSink(Player p) { - //get all lands with mana abilities - CardList lands = AllZoneUtil.getPlayerLandsInPlay(p); - lands = lands.filter(new CardListFilter() { - public boolean addCard(Card c) { - return c.getManaAbility().size() > 0; - } - }); - //tap them - for(Card c:lands) c.tap(); - - //empty mana pool - if(p.isHuman()) AllZone.ManaPool.clearPool(); - } private String counterStackDescription(AbilityFactory af, SpellAbility sa) {