From 036095f6ec3f126090cf081b7cf94ede7b1d7efa Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 17 Nov 2014 23:44:40 +0100 Subject: [PATCH] Some more changes to net mana handling. --- .../sets/bornofthegods/AstralCornucopia.java | 76 +++---- .../HeartbeatOfSpring.java | 7 +- .../src/mage/sets/conflux/ExoticOrchard.java | 109 +--------- .../mage/sets/dragonsmaze/ZhurTaaAncient.java | 37 ++-- .../mage/sets/fifthdawn/SylvokExplorer.java | 103 +--------- .../src/mage/sets/mirage/LionsEyeDiamond.java | 11 +- .../mage/sets/ninthedition/FellwarStone.java | 103 +--------- .../src/mage/sets/tempest/ReflectingPool.java | 84 ++++++-- .../cards/control/PutIntoPlayEffectsTest.java | 6 +- ...yColorOpponentLandsProduceManaAbility.java | 190 ++++++++++++++++++ Mage/src/mage/abilities/mana/ManaAbility.java | 12 +- .../abilities/mana/SimpleManaAbility.java | 2 + .../abilities/mana/TriggeredManaAbility.java | 3 +- 13 files changed, 352 insertions(+), 391 deletions(-) create mode 100644 Mage/src/mage/abilities/mana/AnyColorOpponentLandsProduceManaAbility.java diff --git a/Mage.Sets/src/mage/sets/bornofthegods/AstralCornucopia.java b/Mage.Sets/src/mage/sets/bornofthegods/AstralCornucopia.java index 719bb7721f..fff9479e63 100644 --- a/Mage.Sets/src/mage/sets/bornofthegods/AstralCornucopia.java +++ b/Mage.Sets/src/mage/sets/bornofthegods/AstralCornucopia.java @@ -27,7 +27,6 @@ */ package mage.sets.bornofthegods; -import java.util.ArrayList; import java.util.List; import java.util.UUID; import mage.Mana; @@ -40,7 +39,6 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ManaEffect; import mage.abilities.mana.ManaAbility; import mage.cards.CardImpl; -import mage.choices.Choice; import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.Outcome; @@ -49,6 +47,7 @@ import mage.constants.Zone; import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -64,11 +63,7 @@ public class AstralCornucopia extends CardImpl { this.addAbility(new EntersBattlefieldAbility(new AstralCornucopiaEffect(), "with X charge counters on it")); // {T}: Choose a color. Add one mana of that color to your mana pool for each charge counter on Astral Cornucopia. - Ability ability = new AstralCornucopiaManaAbility(); - Choice choice = new ChoiceColor(); - choice.setMessage("Choose a color to add mana of that color"); - ability.addChoice(choice); - this.addAbility(ability); + this.addAbility(new AstralCornucopiaManaAbility()); } public AstralCornucopia(final AstralCornucopia card) { @@ -130,15 +125,18 @@ class AstralCornucopiaManaAbility extends ManaAbility { @Override public List getNetMana(Game game) { - List newNetMana = new ArrayList<>(); - if (game != null) { - newNetMana.add(new Mana(((AstralCornucopiaManaEffect)this.getEffects().get(0)).computeMana(game, this))); - } - return newNetMana; + netMana.clear(); + Permanent sourcePermanent = game.getPermanent(getSourceId()); + if (sourcePermanent != null) { + int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName()); + if (counters > 0) { + netMana.add(new Mana(0,0,0,0,0,0,counters)); + } + } + return netMana; } } - class AstralCornucopiaManaEffect extends ManaEffect { private final Mana computedMana; @@ -161,32 +159,36 @@ class AstralCornucopiaManaEffect extends ManaEffect { @Override public boolean apply(Game game, Ability source) { - computeMana(game, source); - game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source); - return true; - } - - public Mana computeMana(Game game, Ability source){ - this.computedMana.clear(); - if (!source.getChoices().isEmpty()) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); - if (choice != null && choice instanceof ChoiceColor && choice.getChoice() != null) { - String color = choice.getChoice(); - int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName()); - if (color.equals("Red")) { - computedMana.setRed(counters); - } else if (color.equals("Blue")) { - computedMana.setBlue(counters); - } else if (color.equals("White")) { - computedMana.setWhite(counters); - } else if (color.equals("Black")) { - computedMana.setBlack(counters); - } else if (color.equals("Green")) { - computedMana.setGreen(counters); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choice = new ChoiceColor(); + choice.setMessage("Choose a color to add mana of that color"); + if (controller.choose(outcome, choice, game)) { + Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + if (choice.getChoice() != null) { + String color = choice.getChoice(); + int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName()); + switch (color) { + case "Red": + computedMana.setRed(counters); + break; + case "Blue": + computedMana.setBlue(counters); + break; + case "White": + computedMana.setWhite(counters); + break; + case "Black": + computedMana.setBlack(counters); + break; + case "Green": + computedMana.setGreen(counters); + break; + } } + return true; } } - return computedMana; + return false; } } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/HeartbeatOfSpring.java b/Mage.Sets/src/mage/sets/championsofkamigawa/HeartbeatOfSpring.java index 065fedb07f..7f038d2d9f 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/HeartbeatOfSpring.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/HeartbeatOfSpring.java @@ -28,10 +28,6 @@ package mage.sets.championsofkamigawa; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.Mana; import mage.abilities.Abilities; import mage.abilities.Ability; @@ -41,6 +37,9 @@ import mage.abilities.mana.TriggeredManaAbility; import mage.cards.CardImpl; import mage.choices.Choice; import mage.choices.ChoiceImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; diff --git a/Mage.Sets/src/mage/sets/conflux/ExoticOrchard.java b/Mage.Sets/src/mage/sets/conflux/ExoticOrchard.java index c277e21be0..04e515f8ef 100644 --- a/Mage.Sets/src/mage/sets/conflux/ExoticOrchard.java +++ b/Mage.Sets/src/mage/sets/conflux/ExoticOrchard.java @@ -27,28 +27,11 @@ */ package mage.sets.conflux; -import java.util.List; import java.util.UUID; +import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility; +import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.constants.TargetController; -import mage.constants.Zone; -import mage.Mana; -import mage.abilities.Abilities; -import mage.abilities.Ability; -import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.common.ManaEffect; -import mage.abilities.mana.ManaAbility; -import mage.abilities.mana.SimpleManaAbility; -import mage.cards.CardImpl; -import mage.choices.Choice; -import mage.choices.ChoiceImpl; -import mage.filter.FilterPermanent; -import mage.filter.common.FilterLandPermanent; -import mage.filter.predicate.permanent.ControllerPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -61,7 +44,7 @@ public class ExoticOrchard extends CardImpl { this.expansionSetCode = "CON"; // {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce. - this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new ExoticOrchardEffect(), new TapSourceCost())); + this.addAbility(new AnyColorOpponentLandsProduceManaAbility()); } public ExoticOrchard(final ExoticOrchard card) { @@ -73,89 +56,3 @@ public class ExoticOrchard extends CardImpl { return new ExoticOrchard(this); } } - -class ExoticOrchardEffect extends ManaEffect { - - private static final FilterPermanent filter = new FilterLandPermanent(); - static { - filter.add(new ControllerPredicate(TargetController.OPPONENT)); - } - - public ExoticOrchardEffect() { - super(); - staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce"; - } - - public ExoticOrchardEffect(final ExoticOrchardEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); - Mana types = new Mana(); - for (Permanent land : lands) { - Abilities mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); - for (ManaAbility ability : mana) { - for (Mana netMana: ability.getNetMana(game)) { - types.add(netMana); - } - } - } - Choice choice = new ChoiceImpl(true); - choice.setMessage("Pick a mana color"); - if (types.getBlack() > 0) { - choice.getChoices().add("Black"); - } - if (types.getRed() > 0) { - choice.getChoices().add("Red"); - } - if (types.getBlue() > 0) { - choice.getChoices().add("Blue"); - } - if (types.getGreen() > 0) { - choice.getChoices().add("Green"); - } - if (types.getWhite() > 0) { - choice.getChoices().add("White"); - } - if (types.getAny() > 0) { - choice.getChoices().add("Black"); - choice.getChoices().add("Red"); - choice.getChoices().add("Blue"); - choice.getChoices().add("Green"); - choice.getChoices().add("White"); - } - if (choice.getChoices().size() > 0) { - Player player = game.getPlayer(source.getControllerId()); - if (choice.getChoices().size() == 1) { - choice.setChoice(choice.getChoices().iterator().next()); - } else { - player.choose(outcome, choice, game); - } - switch (choice.getChoice()) { - case "Black": - player.getManaPool().addMana(Mana.BlackMana, game, source); - break; - case "Blue": - player.getManaPool().addMana(Mana.BlueMana, game, source); - break; - case "Red": - player.getManaPool().addMana(Mana.RedMana, game, source); - break; - case "Green": - player.getManaPool().addMana(Mana.GreenMana, game, source); - break; - case "White": - player.getManaPool().addMana(Mana.WhiteMana, game, source); - break; - } - } - return true; - } - - @Override - public ExoticOrchardEffect copy() { - return new ExoticOrchardEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/ZhurTaaAncient.java b/Mage.Sets/src/mage/sets/dragonsmaze/ZhurTaaAncient.java index 12ce318cc8..1af4290f4a 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/ZhurTaaAncient.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/ZhurTaaAncient.java @@ -164,24 +164,25 @@ class ZhurTaaAncientEffect extends ManaEffect { } else { player.choose(outcome, choice, game); } - if (choice.getChoice().equals("Black")) { - player.getManaPool().addMana(Mana.BlackMana, game, source); - return true; - } else if (choice.getChoice().equals("Blue")) { - player.getManaPool().addMana(Mana.BlueMana, game, source); - return true; - } else if (choice.getChoice().equals("Red")) { - player.getManaPool().addMana(Mana.RedMana, game, source); - return true; - } else if (choice.getChoice().equals("Green")) { - player.getManaPool().addMana(Mana.GreenMana, game, source); - return true; - } else if (choice.getChoice().equals("White")) { - player.getManaPool().addMana(Mana.WhiteMana, game, source); - return true; - } else if (choice.getChoice().equals("Colorless")) { - player.getManaPool().addMana(Mana.ColorlessMana, game, source); - return true; + switch (choice.getChoice()) { + case "Black": + player.getManaPool().addMana(Mana.BlackMana, game, source); + return true; + case "Blue": + player.getManaPool().addMana(Mana.BlueMana, game, source); + return true; + case "Red": + player.getManaPool().addMana(Mana.RedMana, game, source); + return true; + case "Green": + player.getManaPool().addMana(Mana.GreenMana, game, source); + return true; + case "White": + player.getManaPool().addMana(Mana.WhiteMana, game, source); + return true; + case "Colorless": + player.getManaPool().addMana(Mana.ColorlessMana, game, source); + return true; } } return true; diff --git a/Mage.Sets/src/mage/sets/fifthdawn/SylvokExplorer.java b/Mage.Sets/src/mage/sets/fifthdawn/SylvokExplorer.java index 3d35c2f87a..4b46ca9bc0 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/SylvokExplorer.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/SylvokExplorer.java @@ -27,29 +27,12 @@ */ package mage.sets.fifthdawn; -import java.util.List; import java.util.UUID; import mage.MageInt; -import mage.Mana; -import mage.abilities.Abilities; -import mage.abilities.Ability; -import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.common.ManaEffect; -import mage.abilities.mana.ManaAbility; -import mage.abilities.mana.SimpleManaAbility; +import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility; import mage.cards.CardImpl; -import mage.choices.Choice; -import mage.choices.ChoiceImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.constants.TargetController; -import mage.constants.Zone; -import mage.filter.FilterPermanent; -import mage.filter.common.FilterLandPermanent; -import mage.filter.predicate.permanent.ControllerPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -67,8 +50,8 @@ public class SylvokExplorer extends CardImpl { this.power = new MageInt(1); this.toughness = new MageInt(1); - // {tap}: Add to your mana pool one mana of any color that a land an opponent controls could produce. - this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new SylvokExplorerEffect(), new TapSourceCost())); + // {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce. + this.addAbility(new AnyColorOpponentLandsProduceManaAbility()); } public SylvokExplorer(final SylvokExplorer card) { @@ -80,83 +63,3 @@ public class SylvokExplorer extends CardImpl { return new SylvokExplorer(this); } } - -class SylvokExplorerEffect extends ManaEffect { - - private static final FilterPermanent filter = new FilterLandPermanent(); - static { - filter.add(new ControllerPredicate(TargetController.OPPONENT)); - } - - public SylvokExplorerEffect() { - super(); - staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce"; - } - - public SylvokExplorerEffect(final SylvokExplorerEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); - Mana types = new Mana(); - for (Permanent land : lands) { - Abilities mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); - for (ManaAbility ability : mana) { - for (Mana netMana: ability.getNetMana(game)) { - types.add(netMana); - } - } - } - Choice choice = new ChoiceImpl(true); - choice.setMessage("Pick a mana color"); - if (types.getBlack() > 0) { - choice.getChoices().add("Black"); - } - if (types.getRed() > 0) { - choice.getChoices().add("Red"); - } - if (types.getBlue() > 0) { - choice.getChoices().add("Blue"); - } - if (types.getGreen() > 0) { - choice.getChoices().add("Green"); - } - if (types.getWhite() > 0) { - choice.getChoices().add("White"); - } - if (types.getAny() > 0) { - choice.getChoices().add("Black"); - choice.getChoices().add("Red"); - choice.getChoices().add("Blue"); - choice.getChoices().add("Green"); - choice.getChoices().add("White"); - } - if (choice.getChoices().size() > 0) { - Player player = game.getPlayer(source.getControllerId()); - if (choice.getChoices().size() == 1) { - choice.setChoice(choice.getChoices().iterator().next()); - } else { - player.choose(outcome, choice, game); - } - if (choice.getChoice().equals("Black")) { - player.getManaPool().addMana(Mana.BlackMana, game, source); - } else if (choice.getChoice().equals("Blue")) { - player.getManaPool().addMana(Mana.BlueMana, game, source); - } else if (choice.getChoice().equals("Red")) { - player.getManaPool().addMana(Mana.RedMana, game, source); - } else if (choice.getChoice().equals("Green")) { - player.getManaPool().addMana(Mana.GreenMana, game, source); - } else if (choice.getChoice().equals("White")) { - player.getManaPool().addMana(Mana.WhiteMana, game, source); - } - } - return true; - } - - @Override - public SylvokExplorerEffect copy() { - return new SylvokExplorerEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/mirage/LionsEyeDiamond.java b/Mage.Sets/src/mage/sets/mirage/LionsEyeDiamond.java index 47d9bda690..ce7a10b8a2 100644 --- a/Mage.Sets/src/mage/sets/mirage/LionsEyeDiamond.java +++ b/Mage.Sets/src/mage/sets/mirage/LionsEyeDiamond.java @@ -28,10 +28,6 @@ package mage.sets.mirage; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.constants.TimingRule; -import mage.constants.Zone; import mage.Mana; import mage.abilities.costs.Cost; import mage.abilities.costs.common.DiscardHandCost; @@ -40,7 +36,9 @@ import mage.abilities.effects.common.AddManaOfAnyColorEffect; import mage.abilities.effects.common.BasicManaEffect; import mage.abilities.mana.ManaAbility; import mage.cards.CardImpl; -import mage.choices.ChoiceColor; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.constants.Zone; /** * @@ -72,11 +70,12 @@ class LionsEyeDiamondAbility extends ManaAbility { public LionsEyeDiamondAbility() { super(Zone.BATTLEFIELD, new AddManaOfAnyColorEffect(3), new SacrificeSourceCost()); this.addCost(new DiscardHandCost()); + this.netMana.add(new Mana(0,0,0,0,0,0,3)); } public LionsEyeDiamondAbility(Zone zone, Mana mana, Cost cost) { super(zone, new BasicManaEffect(mana), cost); - this.netMana.add(mana.copy()); + } public LionsEyeDiamondAbility(final LionsEyeDiamondAbility ability) { diff --git a/Mage.Sets/src/mage/sets/ninthedition/FellwarStone.java b/Mage.Sets/src/mage/sets/ninthedition/FellwarStone.java index eb902f8bdf..b9c37a37bc 100644 --- a/Mage.Sets/src/mage/sets/ninthedition/FellwarStone.java +++ b/Mage.Sets/src/mage/sets/ninthedition/FellwarStone.java @@ -27,28 +27,11 @@ */ package mage.sets.ninthedition; -import java.util.List; import java.util.UUID; -import mage.Mana; -import mage.abilities.Abilities; -import mage.abilities.Ability; -import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.common.ManaEffect; -import mage.abilities.mana.ManaAbility; -import mage.abilities.mana.SimpleManaAbility; +import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility; import mage.cards.CardImpl; -import mage.choices.Choice; -import mage.choices.ChoiceImpl; import mage.constants.CardType; import mage.constants.Rarity; -import mage.constants.TargetController; -import mage.constants.Zone; -import mage.filter.FilterPermanent; -import mage.filter.common.FilterLandPermanent; -import mage.filter.predicate.permanent.ControllerPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; /** * @@ -60,8 +43,8 @@ public class FellwarStone extends CardImpl { super(ownerId, 297, "Fellwar Stone", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "9ED"; - // {tap}: Add to your mana pool one mana of any color that a land an opponent controls could produce. - this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new FellwarStoneEffect(), new TapSourceCost())); + // {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce. + this.addAbility(new AnyColorOpponentLandsProduceManaAbility()); } public FellwarStone(final FellwarStone card) { @@ -73,83 +56,3 @@ public class FellwarStone extends CardImpl { return new FellwarStone(this); } } - -class FellwarStoneEffect extends ManaEffect { - - private static final FilterPermanent filter = new FilterLandPermanent(); - static { - filter.add(new ControllerPredicate(TargetController.OPPONENT)); - } - - public FellwarStoneEffect() { - super(); - staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce"; - } - - public FellwarStoneEffect(final FellwarStoneEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); - Mana types = new Mana(); - for (Permanent land : lands) { - Abilities mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); - for (ManaAbility ability : mana) { - for (Mana netMana: ability.getNetMana(game)) { - types.add(netMana); - } - } - } - Choice choice = new ChoiceImpl(true); - choice.setMessage("Pick a mana color"); - if (types.getBlack() > 0) { - choice.getChoices().add("Black"); - } - if (types.getRed() > 0) { - choice.getChoices().add("Red"); - } - if (types.getBlue() > 0) { - choice.getChoices().add("Blue"); - } - if (types.getGreen() > 0) { - choice.getChoices().add("Green"); - } - if (types.getWhite() > 0) { - choice.getChoices().add("White"); - } - if (types.getAny() > 0) { - choice.getChoices().add("Black"); - choice.getChoices().add("Red"); - choice.getChoices().add("Blue"); - choice.getChoices().add("Green"); - choice.getChoices().add("White"); - } - if (choice.getChoices().size() > 0) { - Player player = game.getPlayer(source.getControllerId()); - if (choice.getChoices().size() == 1) { - choice.setChoice(choice.getChoices().iterator().next()); - } else { - player.choose(outcome, choice, game); - } - if (choice.getChoice().equals("Black")) { - player.getManaPool().addMana(Mana.BlackMana, game, source); - } else if (choice.getChoice().equals("Blue")) { - player.getManaPool().addMana(Mana.BlueMana, game, source); - } else if (choice.getChoice().equals("Red")) { - player.getManaPool().addMana(Mana.RedMana, game, source); - } else if (choice.getChoice().equals("Green")) { - player.getManaPool().addMana(Mana.GreenMana, game, source); - } else if (choice.getChoice().equals("White")) { - player.getManaPool().addMana(Mana.WhiteMana, game, source); - } - } - return true; - } - - @Override - public FellwarStoneEffect copy() { - return new FellwarStoneEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/tempest/ReflectingPool.java b/Mage.Sets/src/mage/sets/tempest/ReflectingPool.java index ceda2c6e70..780dd8afa0 100644 --- a/Mage.Sets/src/mage/sets/tempest/ReflectingPool.java +++ b/Mage.Sets/src/mage/sets/tempest/ReflectingPool.java @@ -27,21 +27,21 @@ */ package mage.sets.tempest; +import java.util.ArrayList; import java.util.List; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; import mage.Mana; import mage.abilities.Abilities; import mage.abilities.Ability; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.ManaEffect; import mage.abilities.mana.ManaAbility; -import mage.abilities.mana.SimpleManaAbility; import mage.cards.CardImpl; import mage.choices.Choice; import mage.choices.ChoiceImpl; +import mage.constants.CardType; +import mage.constants.ColoredManaSymbol; +import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterControlledLandPermanent; import mage.filter.common.FilterControlledPermanent; @@ -60,7 +60,7 @@ public class ReflectingPool extends CardImpl { this.expansionSetCode = "TMP"; // {T}: Add to your mana pool one mana of any type that a land you control could produce. - this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new ReflectingPoolEffect(), new TapSourceCost())); + this.addAbility(new ReflectingPoolManaAbility()); } public ReflectingPool(final ReflectingPool card) { @@ -73,6 +73,27 @@ public class ReflectingPool extends CardImpl { } } +class ReflectingPoolManaAbility extends ManaAbility { + + public ReflectingPoolManaAbility() { + super(Zone.BATTLEFIELD, new ReflectingPoolEffect(),new TapSourceCost()); + } + + public ReflectingPoolManaAbility(final ReflectingPoolManaAbility ability) { + super(ability); + } + + @Override + public ReflectingPoolManaAbility copy() { + return new ReflectingPoolManaAbility(this); + } + + @Override + public List getNetMana(Game game) { + return ((ReflectingPoolEffect)getEffects().get(0)).getNetMana(game, this); + } +} + class ReflectingPoolEffect extends ManaEffect { private static final FilterControlledPermanent filter = new FilterControlledLandPermanent(); @@ -88,16 +109,7 @@ class ReflectingPoolEffect extends ManaEffect { @Override public boolean apply(Game game, Ability source) { - List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); - Mana types = new Mana(); - for (Permanent land : lands) { - Abilities mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); - for (ManaAbility ability : mana) { - for (Mana netMana: ability.getNetMana(game)) { - types.add(netMana); - } - } - } + Mana types = getManaTypes(game, source); Choice choice = new ChoiceImpl(false); choice.setMessage("Pick a mana color"); if (types.getBlack() > 0) { @@ -161,8 +173,48 @@ class ReflectingPoolEffect extends ManaEffect { return true; } + public List getNetMana(Game game, Ability source) { + List netManas = new ArrayList<>(); + Mana types = getManaTypes(game, source); + if (types.getBlack() > 0) { + netManas.add(new Mana(ColoredManaSymbol.B)); + } + if (types.getRed() > 0) { + netManas.add(new Mana(ColoredManaSymbol.R)); + } + if (types.getBlue() > 0) { + netManas.add(new Mana(ColoredManaSymbol.U)); + } + if (types.getGreen() > 0) { + netManas.add(new Mana(ColoredManaSymbol.G)); + } + if (types.getWhite() > 0) { + netManas.add(new Mana(ColoredManaSymbol.W)); + } + if (types.getColorless() > 0) { + netManas.add(new Mana(0,0,0,0,0,1,0)); + } + return netManas; + } + + private Mana getManaTypes(Game game, Ability source) { + List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); + Mana types = new Mana(); + for (Permanent land : lands) { + Abilities manaAbilities = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); + for (ManaAbility ability : manaAbilities) { + if (!ability.equals(source) && ability.definesMana()) { + for (Mana netMana: ability.getNetMana(game)) { + types.add(netMana); + } + } + } + } + return types; + } + @Override public ReflectingPoolEffect copy() { return new ReflectingPoolEffect(this); } -} \ No newline at end of file +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/control/PutIntoPlayEffectsTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/control/PutIntoPlayEffectsTest.java index 3d549a25b9..cb889676b4 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/control/PutIntoPlayEffectsTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/control/PutIntoPlayEffectsTest.java @@ -83,6 +83,8 @@ public class PutIntoPlayEffectsTest extends CardTestPlayerBase { // onto the battlefield under your control. addCard(Zone.BATTLEFIELD, playerB, "Island", 4); addCard(Zone.BATTLEFIELD, playerB, "Lord of the Void"); + + // Put target creature on top of its owner's library. addCard(Zone.HAND, playerB, "Griptide"); castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Griptide", "Oracle of Mul Daya"); @@ -96,8 +98,8 @@ public class PutIntoPlayEffectsTest extends CardTestPlayerBase { assertLife(playerA, 13); assertPermanentCount(playerB, "Oracle of Mul Daya", 1); - Assert.assertTrue("Top card of the library of player B should be reveled.", playerB.isTopCardRevealed()); - Assert.assertFalse("Top card of the library of player A should not be reveled.", playerA.isTopCardRevealed()); + Assert.assertTrue("Top card of the library of player B should be revealed.", playerB.isTopCardRevealed()); + Assert.assertFalse("Top card of the library of player A should not be revealed.", playerA.isTopCardRevealed()); } /** diff --git a/Mage/src/mage/abilities/mana/AnyColorOpponentLandsProduceManaAbility.java b/Mage/src/mage/abilities/mana/AnyColorOpponentLandsProduceManaAbility.java new file mode 100644 index 0000000000..371230b1be --- /dev/null +++ b/Mage/src/mage/abilities/mana/AnyColorOpponentLandsProduceManaAbility.java @@ -0,0 +1,190 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.abilities.mana; + +import java.util.ArrayList; +import java.util.List; +import mage.Mana; +import mage.abilities.Abilities; +import mage.abilities.Ability; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.common.ManaEffect; +import mage.choices.Choice; +import mage.choices.ChoiceImpl; +import mage.constants.ColoredManaSymbol; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterLandPermanent; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ + +public class AnyColorOpponentLandsProduceManaAbility extends ManaAbility { + + public AnyColorOpponentLandsProduceManaAbility() { + super(Zone.BATTLEFIELD, new AnyColorOpponentLandsProduceManaEffect(),new TapSourceCost()); + } + + public AnyColorOpponentLandsProduceManaAbility(final AnyColorOpponentLandsProduceManaAbility ability) { + super(ability); + } + + @Override + public AnyColorOpponentLandsProduceManaAbility copy() { + return new AnyColorOpponentLandsProduceManaAbility(this); + } + + @Override + public List getNetMana(Game game) { + return ((AnyColorOpponentLandsProduceManaEffect)getEffects().get(0)).getNetMana(game, this); + } +} + +class AnyColorOpponentLandsProduceManaEffect extends ManaEffect { + + private static final FilterPermanent filter = new FilterLandPermanent(); + static { + filter.add(new ControllerPredicate(TargetController.OPPONENT)); + } + + public AnyColorOpponentLandsProduceManaEffect() { + super(); + staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce"; + } + + public AnyColorOpponentLandsProduceManaEffect(final AnyColorOpponentLandsProduceManaEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Mana types = getManaTypes(game, source); + Choice choice = new ChoiceImpl(true); + choice.setMessage("Pick a mana color"); + if (types.getBlack() > 0) { + choice.getChoices().add("Black"); + } + if (types.getRed() > 0) { + choice.getChoices().add("Red"); + } + if (types.getBlue() > 0) { + choice.getChoices().add("Blue"); + } + if (types.getGreen() > 0) { + choice.getChoices().add("Green"); + } + if (types.getWhite() > 0) { + choice.getChoices().add("White"); + } + if (types.getAny() > 0) { + choice.getChoices().add("Black"); + choice.getChoices().add("Red"); + choice.getChoices().add("Blue"); + choice.getChoices().add("Green"); + choice.getChoices().add("White"); + } + if (choice.getChoices().size() > 0) { + Player player = game.getPlayer(source.getControllerId()); + if (choice.getChoices().size() == 1) { + choice.setChoice(choice.getChoices().iterator().next()); + } else { + player.choose(outcome, choice, game); + } + switch (choice.getChoice()) { + case "Black": + player.getManaPool().addMana(Mana.BlackMana, game, source); + break; + case "Blue": + player.getManaPool().addMana(Mana.BlueMana, game, source); + break; + case "Red": + player.getManaPool().addMana(Mana.RedMana, game, source); + break; + case "Green": + player.getManaPool().addMana(Mana.GreenMana, game, source); + break; + case "White": + player.getManaPool().addMana(Mana.WhiteMana, game, source); + break; + } + } + return true; + } + + private Mana getManaTypes(Game game, Ability source) { + List lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); + Mana types = new Mana(); + for (Permanent land : lands) { + Abilities mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD); + for (ManaAbility ability : mana) { + if (!ability.equals(source) && ability.definesMana()) { + for (Mana netMana: ability.getNetMana(game)) { + types.add(netMana); + } + } + } + } + return types; + } + + public List getNetMana(Game game, Ability source) { + List netManas = new ArrayList<>(); + Mana types = getManaTypes(game, source); + if (types.getBlack() > 0) { + netManas.add(new Mana(ColoredManaSymbol.B)); + } + if (types.getRed() > 0) { + netManas.add(new Mana(ColoredManaSymbol.R)); + } + if (types.getBlue() > 0) { + netManas.add(new Mana(ColoredManaSymbol.U)); + } + if (types.getGreen() > 0) { + netManas.add(new Mana(ColoredManaSymbol.G)); + } + if (types.getWhite() > 0) { + netManas.add(new Mana(ColoredManaSymbol.W)); + } + if (types.getColorless() > 0) { + netManas.add(new Mana(0,0,0,0,0,1,0)); + } + return netManas; + } + + @Override + public AnyColorOpponentLandsProduceManaEffect copy() { + return new AnyColorOpponentLandsProduceManaEffect(this); + } +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/mana/ManaAbility.java b/Mage/src/mage/abilities/mana/ManaAbility.java index a1a2bcc327..bccdaaf9a4 100644 --- a/Mage/src/mage/abilities/mana/ManaAbility.java +++ b/Mage/src/mage/abilities/mana/ManaAbility.java @@ -81,5 +81,15 @@ public abstract class ManaAbility extends ActivatedAbilityImpl { */ public List getNetMana(Game game) { return netMana; - } + } + + /** + * Used to check if the ability itself defines mana types + * it can produce. + * + * @return + */ + public boolean definesMana() { + return netMana.size() > 0; + } } diff --git a/Mage/src/mage/abilities/mana/SimpleManaAbility.java b/Mage/src/mage/abilities/mana/SimpleManaAbility.java index bd974e740e..2e5d2add57 100644 --- a/Mage/src/mage/abilities/mana/SimpleManaAbility.java +++ b/Mage/src/mage/abilities/mana/SimpleManaAbility.java @@ -28,11 +28,13 @@ package mage.abilities.mana; +import java.util.List; import mage.constants.Zone; import mage.Mana; import mage.abilities.costs.Cost; import mage.abilities.effects.common.BasicManaEffect; import mage.abilities.effects.common.ManaEffect; +import mage.game.Game; /** * diff --git a/Mage/src/mage/abilities/mana/TriggeredManaAbility.java b/Mage/src/mage/abilities/mana/TriggeredManaAbility.java index 525824b545..4a2c997d83 100644 --- a/Mage/src/mage/abilities/mana/TriggeredManaAbility.java +++ b/Mage/src/mage/abilities/mana/TriggeredManaAbility.java @@ -27,9 +27,9 @@ */ package mage.abilities.mana; -import mage.constants.Zone; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.common.ManaEffect; +import mage.constants.Zone; /** * see 20110715 - 605.1b @@ -43,6 +43,7 @@ public abstract class TriggeredManaAbility extends TriggeredAbilityImpl { public TriggeredManaAbility(Zone zone, ManaEffect effect, boolean optional) { super(zone, effect, optional); + this.usesStack = false; } public TriggeredManaAbility(final TriggeredManaAbility ability) {