#5935 Fix and standardise firing of TAPPED_FOR_MANA event

This commit is contained in:
Iain Monro 2019-08-15 20:41:06 +01:00
parent 0cf758ea5e
commit 48fbd30f2d
62 changed files with 556 additions and 1115 deletions

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
List<Mana> netMana = new ArrayList<>();
netMana.add(new Mana(0, 0, 0, 0, 0, 0, counters, 0));
return netMana;
}
return null;
}
}

View file

@ -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> 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);

View file

@ -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()) {

View file

@ -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)));

View file

@ -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)) {

View file

@ -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();

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
List<Mana> 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) {

View file

@ -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();

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
netMana.add(new Mana(0, 0, 0, 0, 0, 0, 2, 0));
return netMana;
}
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
ArrayList<Mana> 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);
}
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
List<Mana> 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;

View file

@ -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");

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
ArrayList<Mana> 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);
}
}

View file

@ -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) {

View file

@ -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);

View file

@ -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) {

View file

@ -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) {

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (sourceObject != null) {
List<Mana> 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);

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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<Mana> 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<Mana> netMana = new ArrayList<>();
netMana.add(Mana.ColorlessMana(artifacts * 2));
return netMana;
}
}

View file

@ -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();

View file

@ -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);
}
}

View file

@ -90,18 +90,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) {
checkToFirePossibleEvents(getMana(game, source), game, source);
controller.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
return false;
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
@ -115,7 +103,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) {
ChoiceColor choice = new ChoiceColor();

View file

@ -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<Mana> 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();

View file

@ -1,6 +1,8 @@
package mage.cards.p;
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.effects.common.ManaEffect;
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;
@ -96,35 +99,15 @@ class PlasmCaptureManaEffect 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;
public Mana produceMana(Game game, Ability source) {
Player player = getPlayer(game, source);
return ManaChoice.chooseAnyColor(player, game, amountOfMana);
}
@Override
public Mana produceMana(boolean netMana, Game game, Ability source) {
if (netMana) {
return new Mana(0, 0, 0, 0, 0, 0, amountOfMana, 0);
}
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Mana mana = new Mana();
for (int i = 0; i < amountOfMana; i++) {
ChoiceColor choiceColor = new ChoiceColor();
if (!player.choose(Outcome.Benefit, choiceColor, game)) {
return null;
}
choiceColor.increaseMana(mana);
}
player.getManaPool().addMana(mana, game, source);
return mana;
}
return null;
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
netMana.add(new Mana(0, 0, 0, 0, 0, 0, amountOfMana, 0));
return netMana;
}
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
netMana.add(new Mana(0, 0, 0, 0, 0, 0, 1, 0));
return netMana;
}
@Override

View file

@ -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);

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Mana> 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());

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
}

View file

@ -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();
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
@Override

View file

@ -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();

View file

@ -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();

View file

@ -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)));

View file

@ -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<Mana> 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;
}

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -574,7 +574,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;

View file

@ -404,27 +404,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;
}

View file

@ -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<Mana> 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();

View file

@ -13,6 +13,8 @@ import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ManaEvent;
import mage.players.ManaPool;
import mage.players.Player;
/**
*
@ -32,19 +34,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 +66,7 @@ public abstract class ManaEffect extends OneShotEffect {
*/
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
Mana mana = produceMana(true, game, source);
Mana mana = produceMana(game, source);
if (mana != null) {
netMana.add(mana);
}
@ -67,13 +76,11 @@ public abstract class ManaEffect extends OneShotEffect {
/**
* Produced the mana the effect can produce
*
* @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

View file

@ -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();
}

View file

@ -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;

View file

@ -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());

View file

@ -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)));

View file

@ -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();

View file

@ -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<Mana> 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);

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
@Override
public AddManaOfAnyTypeProducedEffect copy() {
return new AddManaOfAnyTypeProducedEffect(this);

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
ArrayList<Mana> 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);
}
}

View file

@ -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<Mana> getNetMana(Game game, Ability source) {
return null;
}
}

View file

@ -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();
}

View file

@ -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<Mana> 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<Mana> 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

View file

@ -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<Mana> 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<Mana> 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 {

View file

@ -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);

View file

@ -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);

View file

@ -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<Mana> getNetMana(Game game) {
List<Mana> 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<Mana> getNetMana(Game game, Ability source) {
List<Mana> 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;
}
}

View file

@ -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;
}
}