diff --git a/Mage.Sets/src/mage/cards/a/AstralCornucopia.java b/Mage.Sets/src/mage/cards/a/AstralCornucopia.java index 8114ad0853..44b06ad565 100644 --- a/Mage.Sets/src/mage/cards/a/AstralCornucopia.java +++ b/Mage.Sets/src/mage/cards/a/AstralCornucopia.java @@ -1,6 +1,8 @@ package mage.cards.a; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -66,27 +68,12 @@ class AstralCornucopiaManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if (sourcePermanent != null) { int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName()); if (counters > 0) { - if (netMana) { - return new Mana(0, 0, 0, 0, 0, 0, counters, 0); - } Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { ChoiceColor choice = new ChoiceColor(); @@ -120,4 +107,16 @@ class AstralCornucopiaManaEffect extends ManaEffect { return mana; } + @Override + public List getNetMana(Game game, Ability source) { + Permanent sourcePermanent = game.getPermanent(source.getSourceId()); + if (sourcePermanent != null) { + int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName()); + List netMana = new ArrayList<>(); + netMana.add(new Mana(0, 0, 0, 0, 0, 0, counters, 0)); + return netMana; + } + return null; + } + } diff --git a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java index 0760baeed8..82c6f7003b 100644 --- a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java +++ b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java @@ -124,19 +124,7 @@ class BenthicExplorersManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - //List mana = getNetMana(game, source); - Mana manaToProduce = produceMana(true, game, source); - controller.getManaPool().addMana(manaToProduce, game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); diff --git a/Mage.Sets/src/mage/cards/b/BloomTender.java b/Mage.Sets/src/mage/cards/b/BloomTender.java index 6db95a9994..8bbfcaa8e3 100644 --- a/Mage.Sets/src/mage/cards/b/BloomTender.java +++ b/Mage.Sets/src/mage/cards/b/BloomTender.java @@ -62,19 +62,7 @@ class BloomTenderEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Mana mana = getMana(game, source); - checkToFirePossibleEvents(mana, game, source); - controller.getManaPool().addMana(mana, game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) { if (mana.getBlack() == 0 && permanent.getColor(game).isBlack()) { diff --git a/Mage.Sets/src/mage/cards/c/CagedSun.java b/Mage.Sets/src/mage/cards/c/CagedSun.java index 0f5a5246ae..1eab28c98f 100644 --- a/Mage.Sets/src/mage/cards/c/CagedSun.java +++ b/Mage.Sets/src/mage/cards/c/CagedSun.java @@ -140,16 +140,7 @@ class CagedSunEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source); - } - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); if (color != null) { return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); diff --git a/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java b/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java index 328c82d115..bcb4bc99bc 100644 --- a/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java +++ b/Mage.Sets/src/mage/cards/c/CarpetOfFlowers.java @@ -116,18 +116,7 @@ class CarpetOfFlowersEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); ChoiceColor choice = new ChoiceColor(); if (controller != null && controller.choose(Outcome.Benefit, choice, game)) { diff --git a/Mage.Sets/src/mage/cards/c/CharmedPendant.java b/Mage.Sets/src/mage/cards/c/CharmedPendant.java index 949b901b84..af20ff0c11 100644 --- a/Mage.Sets/src/mage/cards/c/CharmedPendant.java +++ b/Mage.Sets/src/mage/cards/c/CharmedPendant.java @@ -108,19 +108,7 @@ class CharmedPendantManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Mana mana = new Mana(); diff --git a/Mage.Sets/src/mage/cards/c/ChromeMox.java b/Mage.Sets/src/mage/cards/c/ChromeMox.java index 75fd118e48..fb7f3befef 100644 --- a/Mage.Sets/src/mage/cards/c/ChromeMox.java +++ b/Mage.Sets/src/mage/cards/c/ChromeMox.java @@ -122,19 +122,6 @@ class ChromeMoxManaEffect extends ManaEffect { return new ChromeMoxManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Mana mana = getMana(game, source); - checkToFirePossibleEvents(mana, game, source); - controller.getManaPool().addMana(mana, game, source); - return true; - - } - return false; - } - @Override public List getNetMana(Game game, Ability source) { List netMana = new ArrayList<>(); @@ -167,7 +154,7 @@ class ChromeMoxManaEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); Player player = game.getPlayer(source.getControllerId()); if (permanent != null && player != null) { diff --git a/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java b/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java index f862495a08..62c2bc55a2 100644 --- a/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java +++ b/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java @@ -90,18 +90,7 @@ class CorruptedGrafstoneManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana types = getManaTypesInGraveyard(game, source); Choice choice = new ChoiceColor(true); choice.getChoices().clear(); diff --git a/Mage.Sets/src/mage/cards/d/DawnsReflection.java b/Mage.Sets/src/mage/cards/d/DawnsReflection.java index 85b962c872..3b3cb44781 100644 --- a/Mage.Sets/src/mage/cards/d/DawnsReflection.java +++ b/Mage.Sets/src/mage/cards/d/DawnsReflection.java @@ -1,6 +1,8 @@ package mage.cards.d; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -11,6 +13,7 @@ import mage.abilities.mana.TriggeredManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; @@ -102,46 +105,28 @@ class DawnsReflectionManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int x = 2; - Mana mana = new Mana(); - for (int i = 0; i < x; i++) { - ChoiceColor choiceColor = new ChoiceColor(); - if (!controller.choose(Outcome.Benefit, choiceColor, game)) { - return false; - } - choiceColor.increaseMana(mana); + public Player getPlayer(Game game, Ability source) { + Permanent enchantment = game.getPermanent(source.getSourceId()); + if (enchantment != null) { + Permanent permanentAttachedTo = game.getPermanent(enchantment.getAttachedTo()); + if (permanentAttachedTo != null) { + return game.getPlayer(permanentAttachedTo.getControllerId()); } - controller.getManaPool().addMana(mana, game, source); - return true; - - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return new Mana(0, 0, 0, 0, 0, 0, 2, 0); - } - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int x = 2; - Mana mana = new Mana(); - for (int i = 0; i < x; i++) { - ChoiceColor choiceColor = new ChoiceColor(); - if (!controller.choose(Outcome.Benefit, choiceColor, game)) { - return null; - } - choiceColor.increaseMana(mana); - } - controller.getManaPool().addMana(mana, game, source); - return mana; - } return null; } + @Override + public Mana produceMana(Game game, Ability source) { + Player player = getPlayer(game, source); + return ManaChoice.chooseAnyColor(player, game, 2); + } + + @Override + public List getNetMana(Game game, Ability source) { + List netMana = new ArrayList<>(); + netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0)); + return netMana; + } + } diff --git a/Mage.Sets/src/mage/cards/d/DoublingCube.java b/Mage.Sets/src/mage/cards/d/DoublingCube.java index 37d3984873..4712f044d0 100644 --- a/Mage.Sets/src/mage/cards/d/DoublingCube.java +++ b/Mage.Sets/src/mage/cards/d/DoublingCube.java @@ -55,18 +55,7 @@ class DoublingCubeEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return null; diff --git a/Mage.Sets/src/mage/cards/e/EmpoweredAutogenerator.java b/Mage.Sets/src/mage/cards/e/EmpoweredAutogenerator.java index 3d12f810c3..9dcfa481d4 100644 --- a/Mage.Sets/src/mage/cards/e/EmpoweredAutogenerator.java +++ b/Mage.Sets/src/mage/cards/e/EmpoweredAutogenerator.java @@ -16,6 +16,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; /** @@ -30,6 +32,7 @@ public final class EmpoweredAutogenerator extends CardImpl { this.addAbility(new EntersBattlefieldTappedAbility()); // {T}: Put a charge counter on Empowered Autogenerator. Add X mana of any one color, where X is the number of charge counters on Empowered Autogenerator. + // Empowered Autogenerator's activated ability is a mana ability. It doesn’t use the stack and can’t be responded to. (2019-08-23) this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new EmpoweredAutogeneratorManaEffect(), new TapSourceCost())); } @@ -65,35 +68,34 @@ class EmpoweredAutogeneratorManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if (controller == null - || sourcePermanent == null) { - return false; - } - sourcePermanent.addCounters(CounterType.CHARGE.createInstance(), source, game); - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; + public List getNetMana(Game game, Ability source) { + List netMana = new ArrayList<>(); + Permanent sourcePermanent = game.getState().getPermanent(source.getSourceId()); + if (sourcePermanent != null) { + int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE) + 1; // one counter will be added on real mana call + if (counters > 0) { + netMana.add(Mana.AnyMana(counters)); + } + } + + return netMana; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); game.applyEffects(); Permanent sourcePermanent = game.getState().getPermanent(source.getSourceId()); if (sourcePermanent == null) { return mana; } - int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE) + 1; + + sourcePermanent.addCounters(CounterType.CHARGE.createInstance(), source, game); + int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE); if (counters == 0) { return mana; } - if (netMana) { - return new Mana(0, 0, 0, 0, 0, 0, counters, 0); - } Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return mana; diff --git a/Mage.Sets/src/mage/cards/e/EverythingamajigC.java b/Mage.Sets/src/mage/cards/e/EverythingamajigC.java index 9868a33f90..d4bd3312ac 100644 --- a/Mage.Sets/src/mage/cards/e/EverythingamajigC.java +++ b/Mage.Sets/src/mage/cards/e/EverythingamajigC.java @@ -12,6 +12,7 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.abilities.effects.mana.BasicManaEffect; import mage.abilities.mana.ActivatedManaAbilityImpl; @@ -95,16 +96,15 @@ class ManaScrewAbility extends ActivatedManaAbilityImpl { } } -class ManaScrewEffect extends BasicManaEffect { +class ManaScrewEffect extends ManaEffect { public ManaScrewEffect() { - super(Mana.ColorlessMana(2)); + super(); this.staticText = "Flip a coin. If you win the flip, add {C}{C}"; } public ManaScrewEffect(final ManaScrewEffect effect) { super(effect); - this.manaTemplate = effect.manaTemplate.copy(); } @Override @@ -113,12 +113,13 @@ class ManaScrewEffect extends BasicManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); + public Mana produceMana(Game game, Ability source) { + Player player = getPlayer(game, source); if (player != null && player.flipCoin(source, game, true)) { - player.getManaPool().addMana(getMana(game, source), game, source); + return Mana.ColorlessMana(2); + } else { + return new Mana(); } - return true; } } diff --git a/Mage.Sets/src/mage/cards/f/FaeburrowElder.java b/Mage.Sets/src/mage/cards/f/FaeburrowElder.java index 6cfbe65430..056ea9a6a7 100644 --- a/Mage.Sets/src/mage/cards/f/FaeburrowElder.java +++ b/Mage.Sets/src/mage/cards/f/FaeburrowElder.java @@ -20,7 +20,6 @@ import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.players.Player; import java.util.UUID; @@ -106,19 +105,7 @@ class FaeburrowElderManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - Mana mana = getMana(game, source); - checkToFirePossibleEvents(mana, game, source); - controller.getManaPool().addMana(mana, game, source); - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) { if (mana.getBlack() == 0 && permanent.getColor(game).isBlack()) { diff --git a/Mage.Sets/src/mage/cards/f/FiremindVessel.java b/Mage.Sets/src/mage/cards/f/FiremindVessel.java index ca305fb40c..ac8f5dd510 100644 --- a/Mage.Sets/src/mage/cards/f/FiremindVessel.java +++ b/Mage.Sets/src/mage/cards/f/FiremindVessel.java @@ -5,10 +5,12 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTappedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.ManaEffect; +import mage.abilities.effects.mana.AddManaOfTwoDifferentColorsEffect; import mage.abilities.mana.SimpleManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Zone; import mage.game.Game; @@ -31,7 +33,7 @@ public final class FiremindVessel extends CardImpl { // {T}: Add two mana of different colors. this.addAbility(new SimpleManaAbility( - Zone.BATTLEFIELD, new FiremindVesselManaEffect(), new TapSourceCost() + Zone.BATTLEFIELD, new AddManaOfTwoDifferentColorsEffect(), new TapSourceCost() )); } @@ -44,67 +46,3 @@ public final class FiremindVessel extends CardImpl { return new FiremindVessel(this); } } - -class FiremindVesselManaEffect extends ManaEffect { - - FiremindVesselManaEffect() { - super(); - staticText = "Add two mana of different colors."; - } - - private FiremindVesselManaEffect(final FiremindVesselManaEffect effect) { - super(effect); - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null) { - return null; - } - - ChoiceColor color1 = new ChoiceColor(true, "Choose color 1"); - if (!player.choose(outcome, color1, game) || color1.getColor() == null) { - return null; - } - - ChoiceColor color2 = new ChoiceColor(true, "Choose color 2"); - color2.removeColorFromChoices(color1.getChoice()); - if (!player.choose(outcome, color2, game) || color2.getColor() == null) { - return null; - } - - if (color1.getColor().equals(color2.getColor())) { - game.informPlayers("Player " + player.getName() + " is cheating with mana choices."); - return null; - } - - Mana mana = new Mana(); - mana.add(color1.getMana(1)); - mana.add(color2.getMana(1)); - return mana; - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public List getNetMana(Game game, Ability source) { - ArrayList netMana = new ArrayList<>(); - netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0)); - return netMana; - } - - @Override - public FiremindVesselManaEffect copy() { - return new FiremindVesselManaEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/f/FoodChain.java b/Mage.Sets/src/mage/cards/f/FoodChain.java index 70b6ef75a7..0acd808d6f 100644 --- a/Mage.Sets/src/mage/cards/f/FoodChain.java +++ b/Mage.Sets/src/mage/cards/f/FoodChain.java @@ -80,18 +80,6 @@ class FoodChainManaEffect extends ManaEffect { return new FoodChainManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - - return false; - } - @Override public List getNetMana(Game game, Ability source) { List netMana = new ArrayList<>(); @@ -112,10 +100,7 @@ class FoodChainManaEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return null; - } + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int manaCostExiled = 0; diff --git a/Mage.Sets/src/mage/cards/g/GauntletOfPower.java b/Mage.Sets/src/mage/cards/g/GauntletOfPower.java index 9d14044b08..292d224f30 100644 --- a/Mage.Sets/src/mage/cards/g/GauntletOfPower.java +++ b/Mage.Sets/src/mage/cards/g/GauntletOfPower.java @@ -180,20 +180,16 @@ class GauntletOfPowerEffectEffect2 extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { + public Player getPlayer(Game game, Ability source) { Permanent land = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); if (land != null) { - Player player = game.getPlayer(land.getControllerId()); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } + return game.getPlayer(land.getControllerId()); } - return false; + return null; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Permanent land = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); if (land != null) { Mana mana = (Mana) getValue("mana"); diff --git a/Mage.Sets/src/mage/cards/g/GuildGlobe.java b/Mage.Sets/src/mage/cards/g/GuildGlobe.java index 199b438439..b504a938a6 100644 --- a/Mage.Sets/src/mage/cards/g/GuildGlobe.java +++ b/Mage.Sets/src/mage/cards/g/GuildGlobe.java @@ -8,10 +8,12 @@ import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.ManaEffect; +import mage.abilities.effects.mana.AddManaOfTwoDifferentColorsEffect; import mage.abilities.mana.SimpleManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Zone; import mage.game.Game; @@ -34,7 +36,7 @@ public final class GuildGlobe extends CardImpl { // {2}, {T}, Sacrifice Guild Globe: Add two mana of different colors. Ability ability = new SimpleManaAbility( - Zone.BATTLEFIELD, new GuildGlobeManaEffect(), new GenericManaCost(2) + Zone.BATTLEFIELD, new AddManaOfTwoDifferentColorsEffect(), new GenericManaCost(2) ); ability.addCost(new TapSourceCost()); ability.addCost(new SacrificeSourceCost()); @@ -50,67 +52,3 @@ public final class GuildGlobe extends CardImpl { return new GuildGlobe(this); } } - -class GuildGlobeManaEffect extends ManaEffect { - - GuildGlobeManaEffect() { - super(); - staticText = "Add two mana of different colors."; - } - - private GuildGlobeManaEffect(final GuildGlobeManaEffect effect) { - super(effect); - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null) { - return null; - } - - ChoiceColor color1 = new ChoiceColor(true, "Choose color 1"); - if (!player.choose(outcome, color1, game) || color1.getColor() == null) { - return null; - } - - ChoiceColor color2 = new ChoiceColor(true, "Choose color 2"); - color2.removeColorFromChoices(color1.getChoice()); - if (!player.choose(outcome, color2, game) || color2.getColor() == null) { - return null; - } - - if (color1.getColor().equals(color2.getColor())) { - game.informPlayers("Player " + player.getName() + " is cheating with mana choices."); - return null; - } - - Mana mana = new Mana(); - mana.add(color1.getMana(1)); - mana.add(color2.getMana(1)); - return mana; - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public List getNetMana(Game game, Ability source) { - ArrayList netMana = new ArrayList<>(); - netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0)); - return netMana; - } - - @Override - public GuildGlobeManaEffect copy() { - return new GuildGlobeManaEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/i/IceCauldron.java b/Mage.Sets/src/mage/cards/i/IceCauldron.java index 9a340d91e9..16fc49d2fb 100644 --- a/Mage.Sets/src/mage/cards/i/IceCauldron.java +++ b/Mage.Sets/src/mage/cards/i/IceCauldron.java @@ -211,18 +211,7 @@ class IceCauldronAddManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Permanent iceCauldron = game.getPermanent(source.getSourceId()); Player controller = game.getPlayer(source.getControllerId()); if (iceCauldron != null && controller != null) { diff --git a/Mage.Sets/src/mage/cards/i/IncubationDruid.java b/Mage.Sets/src/mage/cards/i/IncubationDruid.java index 1dc49717df..c97cecffcd 100644 --- a/Mage.Sets/src/mage/cards/i/IncubationDruid.java +++ b/Mage.Sets/src/mage/cards/i/IncubationDruid.java @@ -73,18 +73,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { int manaAmount = getManaAmount(game, source); Mana mana = new Mana(); Mana types = getManaTypes(game, source); diff --git a/Mage.Sets/src/mage/cards/j/JackInTheMox.java b/Mage.Sets/src/mage/cards/j/JackInTheMox.java index 8cfdefe6d5..cc4b89439a 100644 --- a/Mage.Sets/src/mage/cards/j/JackInTheMox.java +++ b/Mage.Sets/src/mage/cards/j/JackInTheMox.java @@ -63,17 +63,7 @@ class JackInTheMoxManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); if (controller != null && permanent != null) { diff --git a/Mage.Sets/src/mage/cards/j/JeweledAmulet.java b/Mage.Sets/src/mage/cards/j/JeweledAmulet.java index 203b634bdd..d9ff255076 100644 --- a/Mage.Sets/src/mage/cards/j/JeweledAmulet.java +++ b/Mage.Sets/src/mage/cards/j/JeweledAmulet.java @@ -112,18 +112,7 @@ class JeweledAmuletAddManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Permanent jeweledAmulet = game.getPermanent(source.getSourceId()); Player controller = game.getPlayer(source.getControllerId()); if (jeweledAmulet != null && controller != null) { diff --git a/Mage.Sets/src/mage/cards/k/KyrenToy.java b/Mage.Sets/src/mage/cards/k/KyrenToy.java index 901f67f225..7a09169227 100644 --- a/Mage.Sets/src/mage/cards/k/KyrenToy.java +++ b/Mage.Sets/src/mage/cards/k/KyrenToy.java @@ -1,6 +1,8 @@ package mage.cards.k; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -78,25 +80,7 @@ public final class KyrenToy extends CardImpl { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - Permanent sourceObject = game.getPermanent(source.getSourceId()); - if (sourceObject != null) { - return new Mana(0, 0, 0, 0, 0, 0, 0, sourceObject.getCounters(game).getCount(CounterType.CHARGE) + 1); - } - return null; - } + public Mana produceMana(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { int numberOfMana = 0; @@ -110,6 +94,17 @@ public final class KyrenToy extends CardImpl { return null; } + @Override + public List getNetMana(Game game, Ability source) { + Permanent sourceObject = game.getPermanent(source.getSourceId()); + if (sourceObject != null) { + List netMana = new ArrayList<>(); + netMana.add(new Mana(0, 0, 0, 0, 0, 0, 0, sourceObject.getCounters(game).getCount(CounterType.CHARGE) + 1)); + return netMana; + } + return null; + } + @Override public KyrenToyManaEffect copy() { return new KyrenToyManaEffect(this); diff --git a/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java b/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java index c420fdd938..871c231ed8 100644 --- a/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java +++ b/Mage.Sets/src/mage/cards/m/MadScienceFairProject.java @@ -1,5 +1,7 @@ package mage.cards.m; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -9,10 +11,13 @@ import mage.abilities.mana.SimpleManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Zone; +import mage.counters.CounterType; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; /** @@ -55,34 +60,22 @@ class MadScienceFairManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return null; - } + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { int amount = controller.rollDice(game, 6); if (amount <= 3) { return Mana.ColorlessMana(1); } else { - ChoiceColor choice = new ChoiceColor(); - if (controller.choose(Outcome.PutManaInPool, choice, game)) { - Mana chosen = choice.getMana(1); - return chosen; - } + return ManaChoice.chooseAnyColor(controller, game, 1); } } return null; } + @Override + public List getNetMana(Game game, Ability source) { + return null; + } + } diff --git a/Mage.Sets/src/mage/cards/m/ManaScrew.java b/Mage.Sets/src/mage/cards/m/ManaScrew.java index 24b3514c9e..282bdefc18 100644 --- a/Mage.Sets/src/mage/cards/m/ManaScrew.java +++ b/Mage.Sets/src/mage/cards/m/ManaScrew.java @@ -5,7 +5,7 @@ import java.util.UUID; import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.mana.BasicManaEffect; +import mage.abilities.effects.common.ManaEffect; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -68,16 +68,15 @@ class ManaScrewAbility extends ActivatedManaAbilityImpl { } } -class ManaScrewEffect extends BasicManaEffect { +class ManaScrewEffect extends ManaEffect { public ManaScrewEffect() { - super(Mana.ColorlessMana(2)); + super(); this.staticText = "Flip a coin. If you win the flip, add {C}{C}"; } public ManaScrewEffect(final ManaScrewEffect effect) { super(effect); - this.manaTemplate = effect.manaTemplate.copy(); } @Override @@ -86,11 +85,12 @@ class ManaScrewEffect extends BasicManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); + public Mana produceMana(Game game, Ability source) { + Player player = getPlayer(game, source); if (player != null && player.flipCoin(source, game, true)) { - player.getManaPool().addMana(getMana(game, source), game, source); + return Mana.ColorlessMana(2); + } else { + return new Mana(); } - return true; } } diff --git a/Mage.Sets/src/mage/cards/m/MarketFestival.java b/Mage.Sets/src/mage/cards/m/MarketFestival.java index b6431fa765..df45a64eba 100644 --- a/Mage.Sets/src/mage/cards/m/MarketFestival.java +++ b/Mage.Sets/src/mage/cards/m/MarketFestival.java @@ -12,6 +12,7 @@ import mage.abilities.mana.TriggeredManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; @@ -103,43 +104,18 @@ class MarketFestivalManaEffect extends ManaEffect { return new MarketFestivalManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; + public Player getPlayer(Game game, Ability source) { + Permanent sourceObject = game.getPermanent(source.getSourceId()); + if (sourceObject == null) { + return null; } - return false; + return game.getPlayer(sourceObject.getControllerId()); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = game.getObject(source.getSourceId()); - if (controller != null && sourceObject != null) { - int x = 2; - - Mana mana = new Mana(); - for (int i = 0; i < x; i++) { - ChoiceColor choiceColor = new ChoiceColor(); - if (i == 0) { - choiceColor.setMessage("First mana color for " + sourceObject.getLogName()); - } else { - choiceColor.setMessage("Second mana color for " + sourceObject.getLogName()); - } - if (!controller.choose(Outcome.Benefit, choiceColor, game)) { - return null; - } - if (choiceColor.getChoice() == null) { // Possible after reconnect? - return null; - } - choiceColor.increaseMana(mana); - } - return mana; - } - return null; + public Mana produceMana(Game game, Ability source) { + Player controller = getPlayer(game, source); + return ManaChoice.chooseAnyColor(controller, game, 2); } } diff --git a/Mage.Sets/src/mage/cards/m/Metalworker.java b/Mage.Sets/src/mage/cards/m/Metalworker.java index 07dc1dae34..1996839380 100644 --- a/Mage.Sets/src/mage/cards/m/Metalworker.java +++ b/Mage.Sets/src/mage/cards/m/Metalworker.java @@ -1,6 +1,8 @@ package mage.cards.m; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.MageInt; import mage.Mana; @@ -16,8 +18,10 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; +import mage.counters.CounterType; import mage.filter.StaticFilters; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCardInHand; @@ -65,26 +69,12 @@ class MetalworkerManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); + public Mana produceMana(Game game, Ability source) { + Player controller = getPlayer(game, source); if (controller == null) { return null; } int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game); - if (netMana) { - return Mana.ColorlessMana(artifacts * 2); - } if (artifacts > 0) { TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_ARTIFACT); if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) { @@ -96,4 +86,16 @@ class MetalworkerManaEffect extends ManaEffect { return new Mana(); } + @Override + public List getNetMana(Game game, Ability source) { + Player controller = getPlayer(game, source); + if (controller == null) { + return null; + } + int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game); + List netMana = new ArrayList<>(); + netMana.add(Mana.ColorlessMana(artifacts * 2)); + return netMana; + } + } diff --git a/Mage.Sets/src/mage/cards/m/MeteorCrater.java b/Mage.Sets/src/mage/cards/m/MeteorCrater.java index 265d8cf2e8..0a0ca8ed81 100644 --- a/Mage.Sets/src/mage/cards/m/MeteorCrater.java +++ b/Mage.Sets/src/mage/cards/m/MeteorCrater.java @@ -64,18 +64,7 @@ class MeteorCraterEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); choice.getChoices().clear(); diff --git a/Mage.Sets/src/mage/cards/n/NehebTheEternal.java b/Mage.Sets/src/mage/cards/n/NehebTheEternal.java index c56200a21f..842682644f 100644 --- a/Mage.Sets/src/mage/cards/n/NehebTheEternal.java +++ b/Mage.Sets/src/mage/cards/n/NehebTheEternal.java @@ -6,6 +6,7 @@ import mage.abilities.Ability; import mage.abilities.common.BeginningOfPostCombatMainTriggeredAbility; import mage.abilities.dynamicvalue.common.OpponentsLostLifeCount; import mage.abilities.effects.common.ManaEffect; +import mage.abilities.effects.mana.DynamicManaEffect; import mage.abilities.keyword.AfflictAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -37,7 +38,14 @@ public final class NehebTheEternal extends CardImpl { addAbility(new AfflictAbility(3)); // At the beginning of your postcombat main phase, add {R} for each 1 life your opponents have lost this turn. - this.addAbility(new BeginningOfPostCombatMainTriggeredAbility(new NehebTheEternalManaEffect(), TargetController.YOU, false)); + this.addAbility( + new BeginningOfPostCombatMainTriggeredAbility( + new DynamicManaEffect( + Mana.RedMana(1), + OpponentsLostLifeCount.instance, + "add {R} for each 1 life your opponents have lost this turn"), + TargetController.YOU, + false)); } public NehebTheEternal(final NehebTheEternal card) { @@ -49,35 +57,3 @@ public final class NehebTheEternal extends CardImpl { return new NehebTheEternal(this); } } - -class NehebTheEternalManaEffect extends ManaEffect { - - NehebTheEternalManaEffect() { - super(); - this.staticText = "add {R} for each 1 life your opponents have lost this turn"; - } - - NehebTheEternalManaEffect(final NehebTheEternalManaEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - return Mana.RedMana(OpponentsLostLifeCount.instance.calculate(game, source, this)); - } - - @Override - public NehebTheEternalManaEffect copy() { - return new NehebTheEternalManaEffect(this); - } -} diff --git a/Mage.Sets/src/mage/cards/n/NykthosShrineToNyx.java b/Mage.Sets/src/mage/cards/n/NykthosShrineToNyx.java index b9a4605e4a..3e288bee9c 100644 --- a/Mage.Sets/src/mage/cards/n/NykthosShrineToNyx.java +++ b/Mage.Sets/src/mage/cards/n/NykthosShrineToNyx.java @@ -96,18 +96,6 @@ class NykthosDynamicManaEffect extends ManaEffect { return new NykthosDynamicManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - - } - @Override public List getNetMana(Game game, Ability source) { return ChoiceColor.getBaseColors() @@ -118,7 +106,7 @@ class NykthosDynamicManaEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return null; diff --git a/Mage.Sets/src/mage/cards/n/NyxLotus.java b/Mage.Sets/src/mage/cards/n/NyxLotus.java index cc89d5c329..f63afbd1cb 100644 --- a/Mage.Sets/src/mage/cards/n/NyxLotus.java +++ b/Mage.Sets/src/mage/cards/n/NyxLotus.java @@ -95,18 +95,6 @@ class NyxLotusDynamicManaEffect extends ManaEffect { return new NyxLotusDynamicManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - - } - @Override public List getNetMana(Game game, Ability source) { return ChoiceColor.getBaseColors() @@ -117,7 +105,7 @@ class NyxLotusDynamicManaEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return null; diff --git a/Mage.Sets/src/mage/cards/o/OrcishLumberjack.java b/Mage.Sets/src/mage/cards/o/OrcishLumberjack.java index 7dbd242d0b..8cbd5b2869 100644 --- a/Mage.Sets/src/mage/cards/o/OrcishLumberjack.java +++ b/Mage.Sets/src/mage/cards/o/OrcishLumberjack.java @@ -84,24 +84,13 @@ class OrcishLumberjackManaEffect extends ManaEffect { return new OrcishLumberjackManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - @Override public List getNetMana(Game game, Ability source) { return netMana; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { Choice manaChoice = new ChoiceImpl(); diff --git a/Mage.Sets/src/mage/cards/p/PlasmCapture.java b/Mage.Sets/src/mage/cards/p/PlasmCapture.java index da7d253e61..3a1c278e76 100644 --- a/Mage.Sets/src/mage/cards/p/PlasmCapture.java +++ b/Mage.Sets/src/mage/cards/p/PlasmCapture.java @@ -1,6 +1,8 @@ package mage.cards.p; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.delayed.AtTheBeginOfMainPhaseDelayedTriggeredAbility; @@ -9,6 +11,8 @@ import mage.abilities.effects.mana.AddManaInAnyCombinationEffect; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.TargetController; @@ -70,4 +74,4 @@ class PlasmCaptureCounterEffect extends OneShotEffect { } return false; } -} +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/RhysticCave.java b/Mage.Sets/src/mage/cards/r/RhysticCave.java index 72465f596b..57347858ca 100644 --- a/Mage.Sets/src/mage/cards/r/RhysticCave.java +++ b/Mage.Sets/src/mage/cards/r/RhysticCave.java @@ -1,6 +1,8 @@ package mage.cards.r; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -15,6 +17,7 @@ import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Zone; import mage.game.Game; @@ -92,42 +95,16 @@ class RhysticCaveManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; + public Mana produceMana(Game game, Ability source) { + Player controller = getPlayer(game, source); + return ManaChoice.chooseAnyColor(controller, game, 1); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - ChoiceColor choice = new ChoiceColor(true); - if (controller != null && controller.choose(outcome, choice, game)) { - Mana chosenMana = new Mana(); - switch (choice.getColor().toString()) { - case "R": - chosenMana.setRed(1); - break; - case "U": - chosenMana.setBlue(1); - break; - case "W": - chosenMana.setWhite(1); - break; - case "B": - chosenMana.setBlack(1); - break; - case "G": - chosenMana.setGreen(1); - break; - } - return chosenMana; - } - return null; + public List getNetMana(Game game, Ability source) { + List netMana = new ArrayList<>(); + netMana.add(new Mana(0, 0, 0, 0, 0, 0, 1, 0)); + return netMana; } @Override diff --git a/Mage.Sets/src/mage/cards/r/RiteOfFlame.java b/Mage.Sets/src/mage/cards/r/RiteOfFlame.java index 13aafbd7d4..ca3132ff5f 100644 --- a/Mage.Sets/src/mage/cards/r/RiteOfFlame.java +++ b/Mage.Sets/src/mage/cards/r/RiteOfFlame.java @@ -54,17 +54,7 @@ class RiteOfFlameManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { int count = 0; for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { Player player = game.getPlayer(playerId); diff --git a/Mage.Sets/src/mage/cards/s/SacellumGodspeaker.java b/Mage.Sets/src/mage/cards/s/SacellumGodspeaker.java index be5561958b..24662821bd 100644 --- a/Mage.Sets/src/mage/cards/s/SacellumGodspeaker.java +++ b/Mage.Sets/src/mage/cards/s/SacellumGodspeaker.java @@ -1,13 +1,17 @@ package mage.cards.s; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import mage.MageInt; import mage.Mana; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.effects.common.ManaEffect; import mage.abilities.mana.SimpleManaAbility; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -18,6 +22,7 @@ import mage.constants.Zone; import mage.filter.common.FilterCreatureCard; import mage.filter.predicate.mageobject.PowerPredicate; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCardInHand; @@ -71,24 +76,17 @@ class SacellumGodspeakerEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); - if (target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) { - checkToFirePossibleEvents(getMana(game, source), game, source); - game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source); - return true; + public List getNetMana(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + List netMana = new ArrayList<>(); + netMana.add(Mana.GreenMana(controller.getHand().count(filter, game))); + return netMana; } - return false; + return null; } - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - return Mana.GreenMana(controller.getHand().count(filter, game)); - } - } + public Mana produceMana(Game game, Ability source) { TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); if (target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) { return Mana.GreenMana(target.getTargets().size()); diff --git a/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java b/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java index ff3b4d9cba..3079091424 100644 --- a/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java +++ b/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java @@ -1,5 +1,6 @@ package mage.cards.s; +import java.util.List; import java.util.UUID; import mage.MageInt; import mage.Mana; @@ -130,19 +131,7 @@ class SasayasEssenceManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Mana mana = (Mana) this.getValue("mana"); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); @@ -215,4 +204,8 @@ class SasayasEssenceManaEffect extends ManaEffect { return null; } + @Override + public List getNetMana(Game game, Ability source) { + return null; + } } diff --git a/Mage.Sets/src/mage/cards/s/SavageVentmaw.java b/Mage.Sets/src/mage/cards/s/SavageVentmaw.java index 0461dea80d..a47a29dabc 100644 --- a/Mage.Sets/src/mage/cards/s/SavageVentmaw.java +++ b/Mage.Sets/src/mage/cards/s/SavageVentmaw.java @@ -14,6 +14,7 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.game.Game; +import mage.players.ManaPool; import mage.players.Player; /** @@ -32,10 +33,8 @@ public final class SavageVentmaw extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever Savage Ventmaw attacks, add {R}{R}{R}{G}{G}{G}. Until end of turn, you don't lose this mana as steps and phases end. - Effect effect = new SavageVentmawManaEffect(new Mana(3, 3, 0, 0, 0, 0, 0, 0), "your", true); - effect.setText("add {R}{R}{R}{G}{G}{G}. Until end of turn, you don't lose this mana as steps and phases end"); + Effect effect = new SavageVentmawManaEffect(); this.addAbility(new AttacksTriggeredAbility(effect, false)); - } public SavageVentmaw(final SavageVentmaw card) { @@ -51,19 +50,17 @@ public final class SavageVentmaw extends CardImpl { class SavageVentmawManaEffect extends ManaEffect { protected Mana mana; - protected boolean emptyOnlyOnTurnsEnd; - public SavageVentmawManaEffect(Mana mana, String textManaPoolOwner, boolean emptyOnTurnsEnd) { + public SavageVentmawManaEffect() { super(); - this.mana = mana; - this.emptyOnlyOnTurnsEnd = emptyOnTurnsEnd; - this.staticText = (textManaPoolOwner.equals("their") ? "that player adds " : "add ") + mana.toString(); + this.mana = new Mana(3, 3, 0, 0, 0, 0, 0, 0); + this.staticText = "add " + mana.toString() + ". Until end of turn, you don't lose this mana as steps and phases end"; } public SavageVentmawManaEffect(final SavageVentmawManaEffect effect) { super(effect); this.mana = effect.mana; - this.emptyOnlyOnTurnsEnd = effect.emptyOnlyOnTurnsEnd; + this.staticText = effect.staticText; } @Override @@ -72,17 +69,12 @@ class SavageVentmawManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.getManaPool().addMana(getMana(game, source), game, source, emptyOnlyOnTurnsEnd); - return true; - } - return false; + protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) { + player.getManaPool().addMana(manaToAdd, game, source, true); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { return mana.copy(); } diff --git a/Mage.Sets/src/mage/cards/s/SelvalaExplorerReturned.java b/Mage.Sets/src/mage/cards/s/SelvalaExplorerReturned.java index e8994c82cd..7666181b6a 100644 --- a/Mage.Sets/src/mage/cards/s/SelvalaExplorerReturned.java +++ b/Mage.Sets/src/mage/cards/s/SelvalaExplorerReturned.java @@ -1,6 +1,7 @@ package mage.cards.s; +import java.util.List; import java.util.UUID; import mage.MageInt; import mage.Mana; @@ -72,25 +73,18 @@ class SelvalaExplorerReturnedEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Mana mana = getMana(game, source); - if (mana.getGreen() > 0) { - controller.getManaPool().addMana(mana, game, source); - controller.gainLife(mana.getGreen(), game, source); - } - return true; + public Mana produceMana(Game game, Ability source) { + int parleyCount = ParleyCount.getInstance().calculate(game, source, this); + Player player = getPlayer(game, source); + if (player != null) { + player.gainLife(parleyCount, game, source); } - return false; + return Mana.GreenMana(parleyCount); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - - } - return Mana.GreenMana(ParleyCount.getInstance().calculate(game, source, this)); + public List getNetMana(Game game, Ability source) { + return null; } } diff --git a/Mage.Sets/src/mage/cards/s/SpectralSearchlight.java b/Mage.Sets/src/mage/cards/s/SpectralSearchlight.java index 4575ce3930..3b185b61f8 100644 --- a/Mage.Sets/src/mage/cards/s/SpectralSearchlight.java +++ b/Mage.Sets/src/mage/cards/s/SpectralSearchlight.java @@ -1,6 +1,7 @@ package mage.cards.s; +import java.util.List; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -11,6 +12,7 @@ import mage.abilities.mana.SimpleManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.choices.ChoiceColor; +import mage.choices.ManaChoice; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Zone; @@ -27,8 +29,7 @@ public final class SpectralSearchlight extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); // {T}: Choose a player. That player adds one mana of any color they chooses. - ManaEffect effect = new SpectralSearchlightManaEffect("chosen player"); - effect.setText("That player adds one mana of any color they choose"); + ManaEffect effect = new SpectralSearchlightManaEffect(); Ability ability = new SimpleManaAbility(Zone.BATTLEFIELD, effect, new TapSourceCost()); // choosing player as first effect, before adding mana effect ability.getEffects().add(0, new ChoosePlayerEffect(Outcome.PutManaInPool)); @@ -47,9 +48,9 @@ public final class SpectralSearchlight extends CardImpl { class SpectralSearchlightManaEffect extends ManaEffect { - public SpectralSearchlightManaEffect(String textManaPoolOwner) { + public SpectralSearchlightManaEffect() { super(); - this.staticText = (textManaPoolOwner.equals("their") ? "that player adds " : "add ") + "one mana of any color" + " to " + textManaPoolOwner + " mana pool"; + this.staticText = "That player adds one mana of any color they choose"; } public SpectralSearchlightManaEffect(final SpectralSearchlightManaEffect effect) { @@ -57,28 +58,19 @@ class SpectralSearchlightManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; + public Player getPlayer(Game game, Ability source) { + return game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return null; - } - UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + "_player"); - Player player = game.getPlayer(playerId); - ChoiceColor choice = new ChoiceColor(); - if (player != null && player.choose(outcome, choice, game)) { - return choice.getMana(1); - } - return new Mana(); + public Mana produceMana(Game game, Ability source) { + Player player = getPlayer(game, source); + return ManaChoice.chooseAnyColor(player, game, 1); + } + + @Override + public List getNetMana(Game game, Ability source) { + return null; } @Override diff --git a/Mage.Sets/src/mage/cards/s/SquanderedResources.java b/Mage.Sets/src/mage/cards/s/SquanderedResources.java index 9a51bf738a..13aef9ab7f 100644 --- a/Mage.Sets/src/mage/cards/s/SquanderedResources.java +++ b/Mage.Sets/src/mage/cards/s/SquanderedResources.java @@ -63,18 +63,7 @@ class SquanderedResourcesEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); choice.getChoices().clear(); diff --git a/Mage.Sets/src/mage/cards/s/StarCompass.java b/Mage.Sets/src/mage/cards/s/StarCompass.java index 1cca2f5b2e..88a07f6505 100644 --- a/Mage.Sets/src/mage/cards/s/StarCompass.java +++ b/Mage.Sets/src/mage/cards/s/StarCompass.java @@ -70,82 +70,7 @@ class StarCompassManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Mana types = getManaTypes(game, source); - Choice choice = new ChoiceColor(true); - choice.getChoices().clear(); - 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.getColorless() > 0) { - choice.getChoices().add("Colorless"); - } - if (types.getAny() > 0) { - choice.getChoices().add("Black"); - choice.getChoices().add("Red"); - choice.getChoices().add("Blue"); - choice.getChoices().add("Green"); - choice.getChoices().add("White"); - choice.getChoices().add("Colorless"); - } - if (!choice.getChoices().isEmpty()) { - Player player = game.getPlayer(source.getControllerId()); - if(player == null){ - return false; - } - if (choice.getChoices().size() == 1) { - choice.setChoice(choice.getChoices().iterator().next()); - } else { - if (!player.choose(outcome, choice, game)) { - return false; - } - } - if (choice.getChoice() != null) { - Mana mana = new Mana(); - switch (choice.getChoice()) { - case "Black": - mana.setBlack(1); - break; - case "Blue": - mana.setBlue(1); - break; - case "Red": - mana.setRed(1); - break; - case "Green": - mana.setGreen(1); - break; - case "White": - mana.setWhite(1); - break; - case "Colorless": - mana.setColorless(1); - break; - } - checkToFirePossibleEvents(mana, game, source); - player.getManaPool().addMana(mana, game, source); - return true; - } - return false; - } - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); choice.getChoices().clear(); diff --git a/Mage.Sets/src/mage/cards/u/UtopiaSprawl.java b/Mage.Sets/src/mage/cards/u/UtopiaSprawl.java index 2cd1cbae2c..9913cec39f 100644 --- a/Mage.Sets/src/mage/cards/u/UtopiaSprawl.java +++ b/Mage.Sets/src/mage/cards/u/UtopiaSprawl.java @@ -101,23 +101,19 @@ class UtopiaSprawlEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { + public Player getPlayer(Game game, Ability source) { Permanent enchantment = game.getPermanent(source.getSourceId()); if (enchantment != null) { Permanent land = game.getPermanent(enchantment.getAttachedTo()); if (land != null) { - Player player = game.getPlayer(land.getControllerId()); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } + return game.getPlayer(land.getControllerId()); } } - return false; + return null; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); if (color != null) { return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); diff --git a/Mage.Sets/src/mage/cards/v/VedalkenEngineer.java b/Mage.Sets/src/mage/cards/v/VedalkenEngineer.java index 5b573e53f2..5b9d2205c7 100644 --- a/Mage.Sets/src/mage/cards/v/VedalkenEngineer.java +++ b/Mage.Sets/src/mage/cards/v/VedalkenEngineer.java @@ -111,29 +111,17 @@ class VedalkenEngineerEffect extends ManaEffect { return new VedalkenEngineerEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - @Override public List getNetMana(Game game, Ability source) { return netMana; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); ChoiceColor choiceColor = new ChoiceColor(true); if (controller != null && controller.choose(Outcome.Benefit, choiceColor, game)) { - Mana condMana = manaBuilder.setMana(choiceColor.getMana(amount), source, game).build(); - return condMana; + return manaBuilder.setMana(choiceColor.getMana(amount), source, game).build(); } return null; } diff --git a/Mage.Sets/src/mage/cards/v/VictoryChimes.java b/Mage.Sets/src/mage/cards/v/VictoryChimes.java index 54f53653ef..a9353239d2 100644 --- a/Mage.Sets/src/mage/cards/v/VictoryChimes.java +++ b/Mage.Sets/src/mage/cards/v/VictoryChimes.java @@ -60,18 +60,12 @@ class VictoryChimesManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; + public Player getPlayer(Game game, Ability source) { + return game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { return Mana.ColorlessMana(1); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/mana/ConditionalManaTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/mana/ConditionalManaTest.java index ac8367bab6..bfaac7e559 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/mana/ConditionalManaTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/mana/ConditionalManaTest.java @@ -3,12 +3,12 @@ package org.mage.test.cards.mana; import mage.abilities.keyword.FlyingAbility; import mage.constants.PhaseStep; import mage.constants.Zone; +import mage.counters.CounterType; import org.junit.Ignore; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; /** - * * @author LevelX2 */ public class ConditionalManaTest extends CardTestPlayerBase { @@ -209,4 +209,81 @@ public class ConditionalManaTest extends CardTestPlayerBase { assertLife(playerB, 18); } + + @Test + public void EmpoweredAutogeneratorAddsCountWithMana() { + // Empowered Autogenerator's activated ability is a mana ability. It doesn’t use the stack and can’t be responded to. (2019-08-23) + + // Empowered Autogenerator enters the battlefield tapped. + // {T}: Put a charge counter on Empowered Autogenerator. Add X mana of any one color, where X is the number of charge counters on Empowered Autogenerator. + addCard(Zone.BATTLEFIELD, playerA, "Empowered Autogenerator", 1); + // + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + + activateManaAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Put a charge counter"); + setChoice(playerA, "Red"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + + setStrictChooseMode(true); + setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + assertCounterCount(playerA, "Empowered Autogenerator", CounterType.CHARGE, 1); + assertLife(playerB, 20 - 3); + } + + @Test + public void EmpoweredAutogeneratorAddsDoubleCountersWithDoubleSeason() { + // Empowered Autogenerator's activated ability is a mana ability. It doesn’t use the stack and can’t be responded to. (2019-08-23) + + // Empowered Autogenerator enters the battlefield tapped. + // {T}: Put a charge counter on Empowered Autogenerator. Add X mana of any one color, where X is the number of charge counters on Empowered Autogenerator. + addCard(Zone.BATTLEFIELD, playerA, "Empowered Autogenerator", 1); + // + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + // + // If an effect would put one or more tokens into play under your control, it puts twice that many of those tokens into play instead. + // If an effect would place one or more counters on a permanent you control, it places twice that many of those counters on that permanent instead. + addCard(Zone.BATTLEFIELD, playerA, "Doubling Season", 1); + + activateManaAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Put a charge counter"); + setChoice(playerA, "Red"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + + setStrictChooseMode(true); + setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + assertCounterCount(playerA, "Empowered Autogenerator", CounterType.CHARGE, 2); + assertLife(playerB, 20 - 3); + } + + @Test + public void EmpoweredAutogeneratorAddsDoubleCountersWithDoubleSeason_AutoPay() { + // Empowered Autogenerator's activated ability is a mana ability. It doesn’t use the stack and can’t be responded to. (2019-08-23) + + // Empowered Autogenerator enters the battlefield tapped. + // {T}: Put a charge counter on Empowered Autogenerator. Add X mana of any one color, where X is the number of charge counters on Empowered Autogenerator. + addCard(Zone.BATTLEFIELD, playerA, "Empowered Autogenerator", 1); + // + addCard(Zone.HAND, playerA, "Lightning Bolt", 1); + // + // If an effect would put one or more tokens into play under your control, it puts twice that many of those tokens into play instead. + // If an effect would place one or more counters on a permanent you control, it places twice that many of those counters on that permanent instead. + addCard(Zone.BATTLEFIELD, playerA, "Doubling Season", 1); + + //activateManaAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Put a charge counter"); // auto pay + setChoice(playerA, "Red"); + castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + + setStrictChooseMode(true); + setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); + execute(); + assertAllCommandsUsed(); + + assertCounterCount(playerA, "Empowered Autogenerator", CounterType.CHARGE, 2); + assertLife(playerB, 20 - 3); + } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/ManaReflectionTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/ManaReflectionTest.java new file mode 100644 index 0000000000..f947ba0afd --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/ManaReflectionTest.java @@ -0,0 +1,57 @@ +package org.mage.test.cards.replacement; + +import mage.constants.ManaType; +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.counters.CounterType; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +public class ManaReflectionTest extends CardTestPlayerBase { + + @Test + public void generatesCorrectManaFromMarwyn() { + addCard(Zone.BATTLEFIELD, playerA, "Mana Reflection"); + addCard(Zone.BATTLEFIELD, playerA, "Marwyn, the Nurturer"); + addCard(Zone.BATTLEFIELD, playerA, "Upwelling"); // Prevent mana from emptying before we can check it + + addCounters(1, PhaseStep.UPKEEP, playerA, "Marwyn, the Nurturer", CounterType.P1P1, 2); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add"); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertPowerToughness(playerA, "Marwyn, the Nurturer", 3, 3); + assertManaPool(playerA, ManaType.GREEN, 6); + } + + @Test + public void generatesCorrectManaFromGemstoneCaverns() { + addCard(Zone.BATTLEFIELD, playerA, "Mana Reflection"); + addCard(Zone.BATTLEFIELD, playerA, "Gemstone Caverns"); + addCard(Zone.BATTLEFIELD, playerA, "Upwelling"); // Prevent mana from emptying before we can check it + + addCounters(1, PhaseStep.UPKEEP, playerA, "Gemstone Caverns", CounterType.LUCK, 1); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add"); + setChoice(playerA, "Green"); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertManaPool(playerA, ManaType.GREEN, 2); + } + + @Test + public void generatesCorrectManaFromLlanowarElves() { + addCard(Zone.BATTLEFIELD, playerA, "Mana Reflection"); + addCard(Zone.BATTLEFIELD, playerA, "Llanowar Elves"); + addCard(Zone.BATTLEFIELD, playerA, "Upwelling"); // Prevent mana from emptying before we can check it + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add"); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertManaPool(playerA, ManaType.GREEN, 2); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index ff97f6d175..fb4d960589 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -576,7 +576,9 @@ public class TestPlayer implements Player { String[] groups = command.split("\\$"); for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { if (permanent.getName().equals(groups[0])) { - Counter counter = new Counter(groups[1], Integer.parseInt(groups[2])); + CounterType counterType = CounterType.findByName(groups[1]); + Assert.assertNotNull("Invalid counter type " + groups[1], counterType); + Counter counter = counterType.createInstance(Integer.parseInt(groups[2])); permanent.addCounters(counter, null, game); actions.remove(action); return true; diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index fedd2613df..2a9ac27c9f 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -381,27 +381,6 @@ public abstract class AbilityImpl implements Ability { game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText()); } activated = true; - // fire if tapped for mana (may only fire now because else costs of ability itself can be payed with mana of abilities that trigger for that event - if (this.getAbilityType() == AbilityType.MANA) { - for (Cost cost : costs) { - if (cost instanceof TapSourceCost) { - Mana mana = null; - Effect effect = getEffects().get(0); - if (effect instanceof DynamicManaEffect) { - mana = ((DynamicManaEffect) effect).getMana(game, this); - } else if (effect instanceof ManaEffect) { - mana = ((ManaEffect) effect).getMana(game, this); - } - if (mana != null && mana.getAny() == 0) { // if mana == null or Any > 0 the event has to be fired in the mana effect to know which mana was produced - ManaEvent event = new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId, mana); - if (!game.replaceEvent(event)) { - game.fireEvent(event); - } - } - break; - } - } - } return true; } diff --git a/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java b/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java index 7d2f3a75fe..9928d870e8 100644 --- a/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java +++ b/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java @@ -41,30 +41,11 @@ public class ConditionalManaEffect extends ManaEffect { this.condition = effect.condition; } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller == null) { - return false; - } - Mana mana = getMana(game, source); - if (produceMana(true, game, source).getAny() > 0) { - checkToFirePossibleEvents(mana, game, source); - } - controller.getManaPool().addMana(mana, game, source); - return true; - } - @Override public ConditionalManaEffect copy() { return new ConditionalManaEffect(this); } - @Override - public Mana getMana(Game game, Ability source) { - return produceMana(false, game, source); - } - @Override public List getNetMana(Game game, Ability source) { if (condition.apply(game, source)) { @@ -76,7 +57,7 @@ public class ConditionalManaEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); if (condition.apply(game, source)) { mana = effect.getManaTemplate().copy(); diff --git a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java index 22380836bc..542656774c 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java @@ -1,8 +1,5 @@ - package mage.abilities.effects.common; -import java.util.ArrayList; -import java.util.List; import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.Cost; @@ -13,9 +10,12 @@ import mage.constants.Outcome; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ManaEvent; +import mage.players.Player; + +import java.util.ArrayList; +import java.util.List; /** - * * @author BetaSteward_at_googlemail.com */ public abstract class ManaEffect extends OneShotEffect { @@ -32,19 +32,26 @@ public abstract class ManaEffect extends OneShotEffect { this.createdMana = effect.createdMana == null ? null : effect.createdMana.copy(); } - /** - * Creates the mana the effect can produce or if that already has happened - * returns the mana the effect has created during its process of resolving - * - * @param game - * @param source - * @return - */ - public Mana getMana(Game game, Ability source) { - if (createdMana == null) { - return createdMana = produceMana(false, game, source); + @Override + public boolean apply(Game game, Ability source) { + Player player = getPlayer(game, source); + if (player == null) { + return false; } - return createdMana; + Mana manaToAdd = produceMana(game, source); + if (manaToAdd.count() > 0) { + checkToFirePossibleEvents(manaToAdd, game, source); + addManaToPool(player, manaToAdd, game, source); + } + return true; + } + + protected Player getPlayer(Game game, Ability source) { + return game.getPlayer(source.getControllerId()); + } + + protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) { + player.getManaPool().addMana(manaToAdd, game, source); } /** @@ -57,7 +64,7 @@ public abstract class ManaEffect extends OneShotEffect { */ public List getNetMana(Game game, Ability source) { List netMana = new ArrayList<>(); - Mana mana = produceMana(true, game, source); + Mana mana = produceMana(game, source); if (mana != null) { netMana.add(mana); } @@ -66,14 +73,15 @@ public abstract class ManaEffect extends OneShotEffect { /** * Produced the mana the effect can produce + * WARNING, produceMana can be called multiple times for mana and spell available calculations + * if you don't want it then overide getNetMana to return max possible mana values + * (if you have choose dialogs or extra effects like new counters in produceMana) * - * @param netMana true - produce the hypotetical possible mana for check of - * possible castable spells * @param game * @param source * @return */ - public abstract Mana produceMana(boolean netMana, Game game, Ability source); + public abstract Mana produceMana(Game game, Ability source); /** * Only used for mana effects that decide which kind of mana is produced diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java index 3ee00370ff..a489ec5440 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaEffect.java @@ -40,17 +40,7 @@ public class AddConditionalManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { return manaBuilder.setMana(mana, source, game).build(); } diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaOfAnyColorEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaOfAnyColorEffect.java index c6e1966da9..ac2af2e319 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaOfAnyColorEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddConditionalManaOfAnyColorEffect.java @@ -61,23 +61,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Mana mana = getMana(game, source); - if (mana != null) { - checkToFirePossibleEvents(mana, game, source); - controller.getManaPool().addMana(mana, game, source); - } else { - logger.error("There was no mana created: " + source.getSourceObject(game).getName() + " - Ability: " + source.getRule()); - } - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return null; diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaAnyColorAttachedControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaAnyColorAttachedControllerEffect.java index f8fb4a249d..4a3b49fe5f 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaAnyColorAttachedControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaAnyColorAttachedControllerEffect.java @@ -27,20 +27,15 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { + public Player getPlayer(Game game, Ability source) { Permanent enchantment = game.getPermanent(source.getSourceId()); if (enchantment != null) { - Permanent permanentattachedTo = game.getPermanent(enchantment.getAttachedTo()); - if (permanentattachedTo != null) { - Player player = game.getPlayer(permanentattachedTo.getControllerId()); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } + Permanent permanentAttachedTo = game.getPermanent(enchantment.getAttachedTo()); + if (permanentAttachedTo != null) { + return game.getPlayer(permanentAttachedTo.getControllerId()); } } - return false; + return null; } @Override @@ -49,7 +44,7 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Permanent enchantment = game.getPermanent(source.getSourceId()); if (enchantment != null) { Permanent land = game.getPermanent(enchantment.getAttachedTo()); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaChosenColorEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaChosenColorEffect.java index eefb08c618..f394320614 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaChosenColorEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaChosenColorEffect.java @@ -29,16 +29,7 @@ public class AddManaChosenColorEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source); - } - return true; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); if (color != null) { return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java index 748155b901..377726ef40 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java @@ -65,18 +65,7 @@ public class AddManaInAnyCombinationEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - player.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { Mana mana = new Mana(); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java index 42f5af2737..742691a3a4 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java @@ -50,23 +50,13 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect { return new AddManaOfAnyColorEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - @Override public List getNetMana(Game game, Ability source) { return netMana; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { String mes = String.format("Select color of %d mana to add it", this.amount); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyTypeProducedEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyTypeProducedEffect.java index 62bb496d51..a6bd6cdefa 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyTypeProducedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyTypeProducedEffect.java @@ -10,6 +10,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.List; + /** * * @author LevelX2 @@ -26,25 +28,16 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { + public Player getPlayer(Game game, Ability source) { Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (permanent != null) { - Player targetController = game.getPlayer(permanent.getControllerId()); - if (targetController == null) { - return false; - } - checkToFirePossibleEvents(getMana(game, source), game, source); - targetController.getManaPool().addMana(getMana(game, source), game, source); - return true; + return game.getPlayer(permanent.getControllerId()); } - return false; + return null; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return null; - } + public Mana produceMana(Game game, Ability source) { Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (permanent != null) { Player targetController = game.getPlayer(permanent.getControllerId()); @@ -109,6 +102,11 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect { return null; } + @Override + public List getNetMana(Game game, Ability source) { + return null; + } + @Override public AddManaOfAnyTypeProducedEffect copy() { return new AddManaOfAnyTypeProducedEffect(this); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfTwoDifferentColorsEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfTwoDifferentColorsEffect.java new file mode 100644 index 0000000000..2e7f29857a --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfTwoDifferentColorsEffect.java @@ -0,0 +1,42 @@ +package mage.abilities.effects.mana; + + +import mage.Mana; +import mage.abilities.Ability; +import mage.abilities.effects.common.ManaEffect; +import mage.choices.ManaChoice; +import mage.game.Game; +import mage.players.Player; + +import java.util.ArrayList; +import java.util.List; + +public class AddManaOfTwoDifferentColorsEffect extends ManaEffect { + + public AddManaOfTwoDifferentColorsEffect() { + super(); + staticText = "Add two mana of different colors."; + } + + private AddManaOfTwoDifferentColorsEffect(final AddManaOfTwoDifferentColorsEffect effect) { + super(effect); + } + + @Override + public Mana produceMana(Game game, Ability source) { + Player player = getPlayer(game, source); + return ManaChoice.chooseTwoDifferentColors(player, game); + } + + @Override + public List getNetMana(Game game, Ability source) { + ArrayList netMana = new ArrayList<>(); + netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0)); + return netMana; + } + + @Override + public AddManaOfTwoDifferentColorsEffect copy() { + return new AddManaOfTwoDifferentColorsEffect(this); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaToManaPoolTargetControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaToManaPoolTargetControllerEffect.java index 0770c1f94d..4798057e87 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaToManaPoolTargetControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaToManaPoolTargetControllerEffect.java @@ -11,6 +11,8 @@ import mage.abilities.effects.common.ManaEffect; import mage.game.Game; import mage.players.Player; +import java.util.List; + /** * * @author LevelX2 @@ -53,20 +55,22 @@ public class AddManaToManaPoolTargetControllerEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); - if (player != null) { - player.getManaPool().addMana(getMana(game, source), game, source, emptyOnlyOnTurnsEnd); - return true; - } - return false; + public Player getPlayer(Game game, Ability source) { + return game.getPlayer(getTargetPointer().getFirst(game, source)); } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - if (netMana) { - return null; - } + public Mana produceMana(Game game, Ability source) { return mana.copy(); } + + @Override + protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) { + player.getManaPool().addMana(manaToAdd, game, source, emptyOnlyOnTurnsEnd); + } + + @Override + public List getNetMana(Game game, Ability source) { + return null; + } } diff --git a/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java index 98a361c12e..c3c0e99633 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/BasicManaEffect.java @@ -5,6 +5,7 @@ import mage.Mana; import mage.abilities.Ability; import mage.abilities.effects.common.ManaEffect; import mage.game.Game; +import mage.players.Player; public class BasicManaEffect extends ManaEffect { @@ -33,18 +34,12 @@ public class BasicManaEffect extends ManaEffect { return new BasicManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source); - return true; - } - public Mana getManaTemplate() { return manaTemplate; } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { return manaTemplate.copy(); } diff --git a/Mage/src/main/java/mage/abilities/effects/mana/DoUnlessAnyPlayerPaysManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/DoUnlessAnyPlayerPaysManaEffect.java index 82605c39ec..2b3aad2f21 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/DoUnlessAnyPlayerPaysManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/DoUnlessAnyPlayerPaysManaEffect.java @@ -43,58 +43,30 @@ public class DoUnlessAnyPlayerPaysManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); + public List getNetMana(Game game, Ability source) { + return manaEffect.getNetMana(game, source); + } + + @Override + public Mana produceMana(Game game, Ability source) { + Player controller = getPlayer(game, source); MageObject sourceObject = game.getObject(source.getSourceId()); - if (controller != null && sourceObject != null) { - String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName()); - boolean result = true; - boolean doEffect = true; - // check if any player is willing to pay - for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - Player player = game.getPlayer(playerId); - if (player != null && player.canRespond() - && cost.canPay(source, source.getSourceId(), player.getId(), game) - && player.chooseUse(Outcome.Detriment, message, source, game)) { - cost.clearPaid(); - if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) { - if (!game.isSimulation()) { - game.informPlayers(player.getLogName() + " pays the cost to prevent the effect"); - } - doEffect = false; - break; + String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName()); + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + Player player = game.getPlayer(playerId); + if (player != null && player.canRespond() + && cost.canPay(source, source.getSourceId(), player.getId(), game) + && player.chooseUse(Outcome.Detriment, message, source, game)) { + cost.clearPaid(); + if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) { + if (!game.isSimulation()) { + game.informPlayers(player.getLogName() + " pays the cost to prevent the effect"); } + return null; } } - // do the effects if nobody paid - if (doEffect) { - return manaEffect.apply(game, source); - } - return result; } - return false; - } - - @Override - public List getNetMana(Game game, Ability source) { - if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) { - return manaEffect.getNetMana(game, source); - } - return new ArrayList<>(); - } - - @Override - public Mana getMana(Game game, Ability source) { - return manaEffect.getMana(game, source); - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { - return manaEffect.produceMana(netMana, game, source); - } - - protected Player getPayingPlayer(Game game, Ability source) { - return game.getPlayer(source.getControllerId()); + return manaEffect.produceMana(game, source); } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java index 17e4e0fdde..27f17b7d39 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java @@ -5,20 +5,25 @@ import mage.Mana; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.common.ManaEffect; import mage.choices.ChoiceColor; import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; +import java.util.ArrayList; +import java.util.List; + /** * * @author North */ -public class DynamicManaEffect extends BasicManaEffect { +public class DynamicManaEffect extends ManaEffect { + private Mana baseMana; private final DynamicValue amount; private final DynamicValue netAmount; - private String text = null; + private String text; private boolean oneChoice; public DynamicManaEffect(Mana mana, DynamicValue amount) { @@ -38,13 +43,14 @@ public class DynamicManaEffect extends BasicManaEffect { * @param mana * @param amount * @param text - * @param oneChoice is all manaTemplate from the same colour or if false the + * @param oneChoice is all mana from the same colour or if false the * player can choose different colours * @param netAmount a dynamic value that calculates the possible available - * manaTemplate (e.g. if you have to pay by removing counters from source) + * mana (e.g. if you have to pay by removing counters from source) */ public DynamicManaEffect(Mana mana, DynamicValue amount, String text, boolean oneChoice, DynamicValue netAmount) { - super(mana); + super(); + this.baseMana = mana; this.amount = amount; this.text = text; this.oneChoice = oneChoice; @@ -53,6 +59,7 @@ public class DynamicManaEffect extends BasicManaEffect { public DynamicManaEffect(final DynamicManaEffect effect) { super(effect); + this.baseMana = effect.baseMana.copy(); this.amount = effect.amount.copy(); this.text = effect.text; this.oneChoice = effect.oneChoice; @@ -68,13 +75,6 @@ public class DynamicManaEffect extends BasicManaEffect { return new DynamicManaEffect(this); } - @Override - public boolean apply(Game game, Ability source) { - checkToFirePossibleEvents(getMana(game, source), game, source); - game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source); - return true; - } - @Override public String getText(Mode mode) { if (text != null && !text.isEmpty()) { @@ -84,46 +84,69 @@ public class DynamicManaEffect extends BasicManaEffect { } @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public List getNetMana(Game game, Ability source) { Mana computedMana = new Mana(); int count; - if (netMana && netAmount != null) { - // calculate the maximum available manaTemplate + if (netAmount != null) { + // calculate the maximum available mana count = netAmount.calculate(game, source, this); } else { count = amount.calculate(game, source, this); } - if (manaTemplate.getBlack() > 0) { + if (baseMana.getBlack() > 0) { computedMana.setBlack(count); - } else if (manaTemplate.getBlue() > 0) { + } else if (baseMana.getBlue() > 0) { computedMana.setBlue(count); - } else if (manaTemplate.getGreen() > 0) { + } else if (baseMana.getGreen() > 0) { computedMana.setGreen(count); - } else if (manaTemplate.getRed() > 0) { + } else if (baseMana.getRed() > 0) { computedMana.setRed(count); - } else if (manaTemplate.getWhite() > 0) { + } else if (baseMana.getWhite() > 0) { computedMana.setWhite(count); - } else if (manaTemplate.getColorless() > 0) { + } else if (baseMana.getColorless() > 0) { computedMana.setColorless(count); - } else if (manaTemplate.getAny() > 0) { - if (netMana) { - computedMana.setAny(count); - } else { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - ChoiceColor choiceColor = new ChoiceColor(true); - for (int i = 0; i < count; i++) { - if (!choiceColor.isChosen()) { - if (!controller.choose(Outcome.Benefit, choiceColor, game)) { - return computedMana; - } - } - choiceColor.increaseMana(computedMana); - if (!oneChoice) { - choiceColor.clearChoice(); + } else if (baseMana.getAny() > 0) { + computedMana.setAny(count); + } else { + computedMana.setGeneric(count); + } + List netMana = new ArrayList<>(); + netMana.add(computedMana); + return netMana; + } + + @Override + public Mana produceMana(Game game, Ability source) { + Mana computedMana = new Mana(); + int count = amount.calculate(game, source, this); + + if (baseMana.getBlack() > 0) { + computedMana.setBlack(count); + } else if (baseMana.getBlue() > 0) { + computedMana.setBlue(count); + } else if (baseMana.getGreen() > 0) { + computedMana.setGreen(count); + } else if (baseMana.getRed() > 0) { + computedMana.setRed(count); + } else if (baseMana.getWhite() > 0) { + computedMana.setWhite(count); + } else if (baseMana.getColorless() > 0) { + computedMana.setColorless(count); + } else if (baseMana.getAny() > 0) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choiceColor = new ChoiceColor(true); + for (int i = 0; i < count; i++) { + if (!choiceColor.isChosen()) { + if (!controller.choose(Outcome.Benefit, choiceColor, game)) { + return computedMana; } } + choiceColor.increaseMana(computedMana); + if (!oneChoice) { + choiceColor.clearChoice(); + } } } } else { diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java index 288e48b195..057329b0f4 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java @@ -87,18 +87,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java index 58c544d2ea..093c0736aa 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java @@ -81,18 +81,7 @@ class AnyColorPermanentTypesManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); Mana types = getManaTypes(game, source); Choice choice = new ChoiceColor(true); diff --git a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java index 47f7d1dea5..e9509a7afd 100644 --- a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java @@ -14,9 +14,7 @@ import mage.filter.FilterMana; import mage.game.Game; import mage.players.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; /** * @author LevelX2 @@ -40,39 +38,6 @@ public class CommanderColorIdentityManaAbility extends ActivatedManaAbilityImpl return new CommanderColorIdentityManaAbility(this); } - @Override - public List getNetMana(Game game) { - List netManas = new ArrayList<>(); - if (netMana.isEmpty() && game != null) { - Player controller = game.getPlayer(getControllerId()); - if (controller != null) { - for (UUID commanderId : game.getCommandersIds(controller)) { - Card commander = game.getCard(commanderId); - if (commander != null) { - FilterMana commanderMana = commander.getColorIdentity(); - if (commanderMana.isBlack()) { - netMana.add(new Mana(ColoredManaSymbol.B)); - } - if (commanderMana.isBlue()) { - netMana.add(new Mana(ColoredManaSymbol.U)); - } - if (commanderMana.isGreen()) { - netMana.add(new Mana(ColoredManaSymbol.G)); - } - if (commanderMana.isRed()) { - netMana.add(new Mana(ColoredManaSymbol.R)); - } - if (commanderMana.isWhite()) { - netMana.add(new Mana(ColoredManaSymbol.W)); - } - } - } - } - } - netManas.addAll(netMana); - return netManas; - } - @Override public boolean definesMana(Game game) { return true; @@ -97,18 +62,7 @@ class CommanderIdentityManaEffect extends ManaEffect { } @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); - return true; - } - return false; - } - - @Override - public Mana produceMana(boolean netMana, Game game, Ability source) { + public Mana produceMana(Game game, Ability source) { Mana mana = new Mana(); Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { @@ -167,4 +121,34 @@ class CommanderIdentityManaEffect extends ManaEffect { return mana; } + @Override + public List getNetMana(Game game, Ability source) { + List netMana = new ArrayList<>(); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + for (UUID commanderId : game.getCommandersIds(controller)) { + Card commander = game.getCard(commanderId); + if (commander != null) { + FilterMana commanderMana = commander.getColorIdentity(); + if (commanderMana.isBlack()) { + netMana.add(new Mana(ColoredManaSymbol.B)); + } + if (commanderMana.isBlue()) { + netMana.add(new Mana(ColoredManaSymbol.U)); + } + if (commanderMana.isGreen()) { + netMana.add(new Mana(ColoredManaSymbol.G)); + } + if (commanderMana.isRed()) { + netMana.add(new Mana(ColoredManaSymbol.R)); + } + if (commanderMana.isWhite()) { + netMana.add(new Mana(ColoredManaSymbol.W)); + } + } + } + } + return netMana; + } + } diff --git a/Mage/src/main/java/mage/choices/ManaChoice.java b/Mage/src/main/java/mage/choices/ManaChoice.java new file mode 100644 index 0000000000..f755d3b2fa --- /dev/null +++ b/Mage/src/main/java/mage/choices/ManaChoice.java @@ -0,0 +1,53 @@ +package mage.choices; + +import mage.Mana; +import mage.constants.Outcome; +import mage.game.Game; +import mage.players.Player; + +public class ManaChoice { + public static Mana chooseAnyColor(Player player, Game game, int amount) { + if (player == null) { + return null; + } + Mana mana = new Mana(); + for (int i = 0; i < amount; i++) { + ChoiceColor choiceColor = new ChoiceColor(); + if (amount > 1) { + choiceColor.setMessage("Choose color " + (i+1)); + } + if (!player.choose(Outcome.Benefit, choiceColor, game)) { + return null; + } + choiceColor.increaseMana(mana); + } + return mana; + } + + public static Mana chooseTwoDifferentColors(Player player, Game game) { + if (player == null) { + return null; + } + + ChoiceColor color1 = new ChoiceColor(true, "Choose color 1"); + if (!player.choose(Outcome.PutManaInPool, color1, game) || color1.getColor() == null) { + return null; + } + + ChoiceColor color2 = new ChoiceColor(true, "Choose color 2"); + color2.removeColorFromChoices(color1.getChoice()); + if (!player.choose(Outcome.PutManaInPool, color2, game) || color2.getColor() == null) { + return null; + } + + if (color1.getColor().equals(color2.getColor())) { + game.informPlayers("Player " + player.getName() + " is cheating with mana choices."); + return null; + } + + Mana mana = new Mana(); + mana.add(color1.getMana(1)); + mana.add(color2.getMana(1)); + return mana; + } +}