#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; package mage.cards.a;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -66,27 +68,12 @@ class AstralCornucopiaManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) { if (sourcePermanent != null) {
int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName()); int counters = sourcePermanent.getCounters(game).getCount(CounterType.CHARGE.getName());
if (counters > 0) { if (counters > 0) {
if (netMana) {
return new Mana(0, 0, 0, 0, 0, 0, counters, 0);
}
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();
@ -120,4 +107,16 @@ class AstralCornucopiaManaEffect extends ManaEffect {
return mana; 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 @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);

View file

@ -62,19 +62,7 @@ class BloomTenderEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(source.getControllerId())) {
if (mana.getBlack() == 0 && permanent.getColor(game).isBlack()) { if (mana.getBlack() == 0 && permanent.getColor(game).isBlack()) {

View file

@ -140,16 +140,7 @@ class CagedSunEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
if (color != null) { if (color != null) {
return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0)));

View file

@ -116,18 +116,7 @@ class CarpetOfFlowersEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();
if (controller != null && controller.choose(Outcome.Benefit, choice, game)) { if (controller != null && controller.choose(Outcome.Benefit, choice, game)) {

View file

@ -108,19 +108,7 @@ class CharmedPendantManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Mana mana = new Mana(); Mana mana = new Mana();

View file

@ -122,19 +122,6 @@ class ChromeMoxManaEffect extends ManaEffect {
return new ChromeMoxManaEffect(this); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>(); List<Mana> netMana = new ArrayList<>();
@ -167,7 +154,7 @@ class ChromeMoxManaEffect extends ManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (permanent != null && player != null) { if (permanent != null && player != null) {

View file

@ -90,18 +90,7 @@ class CorruptedGrafstoneManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana types = getManaTypesInGraveyard(game, source); Mana types = getManaTypesInGraveyard(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);
choice.getChoices().clear(); choice.getChoices().clear();

View file

@ -1,6 +1,8 @@
package mage.cards.d; package mage.cards.d;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -11,6 +13,7 @@ import mage.abilities.mana.TriggeredManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
@ -102,46 +105,28 @@ class DawnsReflectionManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (controller != null) { if (enchantment != null) {
int x = 2; Permanent permanentAttachedTo = game.getPermanent(enchantment.getAttachedTo());
Mana mana = new Mana(); if (permanentAttachedTo != null) {
for (int i = 0; i < x; i++) { return game.getPlayer(permanentAttachedTo.getControllerId());
ChoiceColor choiceColor = new ChoiceColor();
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
return false;
}
choiceColor.increaseMana(mana);
} }
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; 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 @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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()); Player controller = game.getPlayer(source.getControllerId());
if (controller == null) { if (controller == null) {
return 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.GenericManaCost;
import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.costs.mana.VariableManaCost;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.effects.common.discard.DiscardTargetEffect; import mage.abilities.effects.common.discard.DiscardTargetEffect;
import mage.abilities.effects.mana.BasicManaEffect; import mage.abilities.effects.mana.BasicManaEffect;
import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.abilities.mana.ActivatedManaAbilityImpl;
@ -95,16 +96,15 @@ class ManaScrewAbility extends ActivatedManaAbilityImpl {
} }
} }
class ManaScrewEffect extends BasicManaEffect { class ManaScrewEffect extends ManaEffect {
public ManaScrewEffect() { public ManaScrewEffect() {
super(Mana.ColorlessMana(2)); super();
this.staticText = "Flip a coin. If you win the flip, add {C}{C}"; this.staticText = "Flip a coin. If you win the flip, add {C}{C}";
} }
public ManaScrewEffect(final ManaScrewEffect effect) { public ManaScrewEffect(final ManaScrewEffect effect) {
super(effect); super(effect);
this.manaTemplate = effect.manaTemplate.copy();
} }
@Override @Override
@ -113,12 +113,13 @@ class ManaScrewEffect extends BasicManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = getPlayer(game, source);
if (player != null && player.flipCoin(source, game, true)) { 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.common.EntersBattlefieldTappedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.abilities.effects.mana.AddManaOfTwoDifferentColorsEffect;
import mage.abilities.mana.SimpleManaAbility; import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
@ -31,7 +33,7 @@ public final class FiremindVessel extends CardImpl {
// {T}: Add two mana of different colors. // {T}: Add two mana of different colors.
this.addAbility(new SimpleManaAbility( 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); 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); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>(); List<Mana> netMana = new ArrayList<>();
@ -112,10 +100,7 @@ class FoodChainManaEffect extends ManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
if (netMana) {
return null;
}
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
int manaCostExiled = 0; int manaCostExiled = 0;

View file

@ -180,20 +180,16 @@ class GauntletOfPowerEffectEffect2 extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Permanent land = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); Permanent land = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (land != null) { if (land != null) {
Player player = game.getPlayer(land.getControllerId()); return game.getPlayer(land.getControllerId());
if (player != null) {
player.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
} }
return false; return null;
} }
@Override @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)); Permanent land = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (land != null) { if (land != null) {
Mana mana = (Mana) getValue("mana"); 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.costs.mana.GenericManaCost;
import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.abilities.effects.mana.AddManaOfTwoDifferentColorsEffect;
import mage.abilities.mana.SimpleManaAbility; import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; 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. // {2}, {T}, Sacrifice Guild Globe: Add two mana of different colors.
Ability ability = new SimpleManaAbility( 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 TapSourceCost());
ability.addCost(new SacrificeSourceCost()); ability.addCost(new SacrificeSourceCost());
@ -50,67 +52,3 @@ public final class GuildGlobe extends CardImpl {
return new GuildGlobe(this); 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 @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Permanent iceCauldron = game.getPermanent(source.getSourceId()); Permanent iceCauldron = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (iceCauldron != null && controller != null) { if (iceCauldron != null && controller != null) {

View file

@ -73,18 +73,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
int manaAmount = getManaAmount(game, source); int manaAmount = getManaAmount(game, source);
Mana mana = new Mana(); Mana mana = new Mana();
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);

View file

@ -63,17 +63,7 @@ class JackInTheMoxManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) { if (controller != null && permanent != null) {

View file

@ -112,18 +112,7 @@ class JeweledAmuletAddManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Permanent jeweledAmulet = game.getPermanent(source.getSourceId()); Permanent jeweledAmulet = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (jeweledAmulet != null && controller != null) { if (jeweledAmulet != null && controller != null) {

View file

@ -1,6 +1,8 @@
package mage.cards.k; package mage.cards.k;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -78,25 +80,7 @@ public final class KyrenToy extends CardImpl {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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;
}
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
int numberOfMana = 0; int numberOfMana = 0;
@ -110,6 +94,17 @@ public final class KyrenToy extends CardImpl {
return null; 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 @Override
public KyrenToyManaEffect copy() { public KyrenToyManaEffect copy() {
return new KyrenToyManaEffect(this); return new KyrenToyManaEffect(this);

View file

@ -1,5 +1,7 @@
package mage.cards.m; package mage.cards.m;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -9,10 +11,13 @@ import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
/** /**
@ -55,34 +60,22 @@ class MadScienceFairManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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;
}
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
int amount = controller.rollDice(game, 6); int amount = controller.rollDice(game, 6);
if (amount <= 3) { if (amount <= 3) {
return Mana.ColorlessMana(1); return Mana.ColorlessMana(1);
} else { } else {
ChoiceColor choice = new ChoiceColor(); return ManaChoice.chooseAnyColor(controller, game, 1);
if (controller.choose(Outcome.PutManaInPool, choice, game)) {
Mana chosen = choice.getMana(1);
return chosen;
}
} }
} }
return null; 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.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.mana.GenericManaCost; 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.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
@ -68,16 +68,15 @@ class ManaScrewAbility extends ActivatedManaAbilityImpl {
} }
} }
class ManaScrewEffect extends BasicManaEffect { class ManaScrewEffect extends ManaEffect {
public ManaScrewEffect() { public ManaScrewEffect() {
super(Mana.ColorlessMana(2)); super();
this.staticText = "Flip a coin. If you win the flip, add {C}{C}"; this.staticText = "Flip a coin. If you win the flip, add {C}{C}";
} }
public ManaScrewEffect(final ManaScrewEffect effect) { public ManaScrewEffect(final ManaScrewEffect effect) {
super(effect); super(effect);
this.manaTemplate = effect.manaTemplate.copy();
} }
@Override @Override
@ -86,11 +85,12 @@ class ManaScrewEffect extends BasicManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = getPlayer(game, source);
if (player != null && player.flipCoin(source, game, true)) { 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.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
@ -103,43 +104,18 @@ class MarketFestivalManaEffect extends ManaEffect {
return new MarketFestivalManaEffect(this); return new MarketFestivalManaEffect(this);
} }
@Override public Player getPlayer(Game game, Ability source) {
public boolean apply(Game game, Ability source) { Permanent sourceObject = game.getPermanent(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId()); if (sourceObject == null) {
if (controller != null) { return null;
checkToFirePossibleEvents(getMana(game, source), game, source);
controller.getManaPool().addMana(getMana(game, source), game, source);
return true;
} }
return false; return game.getPlayer(sourceObject.getControllerId());
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = getPlayer(game, source);
MageObject sourceObject = game.getObject(source.getSourceId()); return ManaChoice.chooseAnyColor(controller, game, 2);
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;
} }
} }

View file

@ -1,6 +1,8 @@
package mage.cards.m; package mage.cards.m;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
@ -16,8 +18,10 @@ import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
@ -65,26 +69,12 @@ class MetalworkerManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = getPlayer(game, source);
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());
if (controller == null) { if (controller == null) {
return null; return null;
} }
int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game); int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game);
if (netMana) {
return Mana.ColorlessMana(artifacts * 2);
}
if (artifacts > 0) { if (artifacts > 0) {
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_ARTIFACT); TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_ARTIFACT);
if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) { if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
@ -96,4 +86,16 @@ class MetalworkerManaEffect extends ManaEffect {
return new Mana(); 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 @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);
choice.getChoices().clear(); choice.getChoices().clear();

View file

@ -6,6 +6,7 @@ import mage.abilities.Ability;
import mage.abilities.common.BeginningOfPostCombatMainTriggeredAbility; import mage.abilities.common.BeginningOfPostCombatMainTriggeredAbility;
import mage.abilities.dynamicvalue.common.OpponentsLostLifeCount; import mage.abilities.dynamicvalue.common.OpponentsLostLifeCount;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.abilities.effects.mana.DynamicManaEffect;
import mage.abilities.keyword.AfflictAbility; import mage.abilities.keyword.AfflictAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
@ -37,7 +38,14 @@ public final class NehebTheEternal extends CardImpl {
addAbility(new AfflictAbility(3)); addAbility(new AfflictAbility(3));
// At the beginning of your postcombat main phase, add {R} for each 1 life your opponents have lost this turn. // 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) { public NehebTheEternal(final NehebTheEternal card) {
@ -49,35 +57,3 @@ public final class NehebTheEternal extends CardImpl {
return new NehebTheEternal(this); 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); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>(); List<Mana> netMana = new ArrayList<>();
@ -115,7 +103,7 @@ class NykthosDynamicManaEffect extends ManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();

View file

@ -84,24 +84,13 @@ class OrcishLumberjackManaEffect extends ManaEffect {
return new OrcishLumberjackManaEffect(this); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
return netMana; return netMana;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
Choice manaChoice = new ChoiceImpl(); Choice manaChoice = new ChoiceImpl();

View file

@ -1,6 +1,8 @@
package mage.cards.p; package mage.cards.p;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -11,6 +13,7 @@ import mage.abilities.effects.common.ManaEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.TargetController; import mage.constants.TargetController;
@ -96,35 +99,15 @@ class PlasmCaptureManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player player = getPlayer(game, source);
if (controller != null) { return ManaChoice.chooseAnyColor(player, game, amountOfMana);
controller.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
return false;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
if (netMana) { List<Mana> netMana = new ArrayList<>();
return new Mana(0, 0, 0, 0, 0, 0, amountOfMana, 0); netMana.add(new Mana(0, 0, 0, 0, 0, 0, amountOfMana, 0));
} return netMana;
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;
} }
} }

View file

@ -1,6 +1,8 @@
package mage.cards.r; package mage.cards.r;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -15,6 +17,7 @@ import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
@ -92,42 +95,16 @@ class RhysticCaveManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = getPlayer(game, source);
if (controller != null) { return ManaChoice.chooseAnyColor(controller, game, 1);
checkToFirePossibleEvents(getMana(game, source), game, source);
controller.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
return false;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); List<Mana> netMana = new ArrayList<>();
ChoiceColor choice = new ChoiceColor(true); netMana.add(new Mana(0, 0, 0, 0, 0, 0, 1, 0));
if (controller != null && controller.choose(outcome, choice, game)) { return netMana;
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;
} }
@Override @Override

View file

@ -54,17 +54,7 @@ class RiteOfFlameManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
int count = 0; int count = 0;
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);

View file

@ -1,13 +1,17 @@
package mage.cards.s; package mage.cards.s;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.SimpleManaAbility; import mage.abilities.mana.SimpleManaAbility;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -18,6 +22,7 @@ import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.PowerPredicate; import mage.filter.predicate.mageobject.PowerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInHand; import mage.target.common.TargetCardInHand;
@ -71,24 +76,17 @@ class SacellumGodspeakerEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); Player controller = game.getPlayer(source.getControllerId());
if (target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) { if (controller != null) {
checkToFirePossibleEvents(getMana(game, source), game, source); List<Mana> netMana = new ArrayList<>();
game.getPlayer(source.getControllerId()).getManaPool().addMana(getMana(game, source), game, source); netMana.add(Mana.GreenMana(controller.getHand().count(filter, game)));
return true; return netMana;
} }
return false; return null;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
if (netMana) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
return Mana.GreenMana(controller.getHand().count(filter, game));
}
}
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
if (target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) { if (target.choose(Outcome.Benefit, source.getControllerId(), source.getSourceId(), game)) {
return Mana.GreenMana(target.getTargets().size()); return Mana.GreenMana(target.getTargets().size());

View file

@ -1,5 +1,6 @@
package mage.cards.s; package mage.cards.s;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
@ -130,19 +131,7 @@ class SasayasEssenceManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Mana mana = (Mana) this.getValue("mana"); Mana mana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
@ -215,4 +204,8 @@ class SasayasEssenceManaEffect extends ManaEffect {
return null; 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.CardType;
import mage.constants.SubType; import mage.constants.SubType;
import mage.game.Game; import mage.game.Game;
import mage.players.ManaPool;
import mage.players.Player; import mage.players.Player;
/** /**
@ -32,10 +33,8 @@ public final class SavageVentmaw extends CardImpl {
this.addAbility(FlyingAbility.getInstance()); 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. // 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 effect = new SavageVentmawManaEffect();
effect.setText("add {R}{R}{R}{G}{G}{G}. Until end of turn, you don't lose this mana as steps and phases end");
this.addAbility(new AttacksTriggeredAbility(effect, false)); this.addAbility(new AttacksTriggeredAbility(effect, false));
} }
public SavageVentmaw(final SavageVentmaw card) { public SavageVentmaw(final SavageVentmaw card) {
@ -51,19 +50,17 @@ public final class SavageVentmaw extends CardImpl {
class SavageVentmawManaEffect extends ManaEffect { class SavageVentmawManaEffect extends ManaEffect {
protected Mana mana; protected Mana mana;
protected boolean emptyOnlyOnTurnsEnd;
public SavageVentmawManaEffect(Mana mana, String textManaPoolOwner, boolean emptyOnTurnsEnd) { public SavageVentmawManaEffect() {
super(); super();
this.mana = mana; this.mana = new Mana(3, 3, 0, 0, 0, 0, 0, 0);
this.emptyOnlyOnTurnsEnd = emptyOnTurnsEnd; this.staticText = "add " + mana.toString() + ". Until end of turn, you don't lose this mana as steps and phases end";
this.staticText = (textManaPoolOwner.equals("their") ? "that player adds " : "add ") + mana.toString();
} }
public SavageVentmawManaEffect(final SavageVentmawManaEffect effect) { public SavageVentmawManaEffect(final SavageVentmawManaEffect effect) {
super(effect); super(effect);
this.mana = effect.mana; this.mana = effect.mana;
this.emptyOnlyOnTurnsEnd = effect.emptyOnlyOnTurnsEnd; this.staticText = effect.staticText;
} }
@Override @Override
@ -72,17 +69,12 @@ class SavageVentmawManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { protected void addManaToPool(Player player, Mana manaToAdd, Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); player.getManaPool().addMana(manaToAdd, game, source, true);
if (controller != null) {
controller.getManaPool().addMana(getMana(game, source), game, source, emptyOnlyOnTurnsEnd);
return true;
}
return false;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
return mana.copy(); return mana.copy();
} }

View file

@ -1,6 +1,7 @@
package mage.cards.s; package mage.cards.s;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
@ -72,25 +73,18 @@ class SelvalaExplorerReturnedEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); int parleyCount = ParleyCount.getInstance().calculate(game, source, this);
if (controller != null) { Player player = getPlayer(game, source);
Mana mana = getMana(game, source); if (player != null) {
if (mana.getGreen() > 0) { player.gainLife(parleyCount, game, source);
controller.getManaPool().addMana(mana, game, source);
controller.gainLife(mana.getGreen(), game, source);
}
return true;
} }
return false; return Mana.GreenMana(parleyCount);
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
if (netMana) { return null;
}
return Mana.GreenMana(ParleyCount.getInstance().calculate(game, source, this));
} }
} }

View file

@ -1,6 +1,7 @@
package mage.cards.s; package mage.cards.s;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -11,6 +12,7 @@ import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.choices.ManaChoice;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
@ -27,8 +29,7 @@ public final class SpectralSearchlight extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}");
// {T}: Choose a player. That player adds one mana of any color they chooses. // {T}: Choose a player. That player adds one mana of any color they chooses.
ManaEffect effect = new SpectralSearchlightManaEffect("chosen player"); ManaEffect effect = new SpectralSearchlightManaEffect();
effect.setText("That player adds one mana of any color they choose");
Ability ability = new SimpleManaAbility(Zone.BATTLEFIELD, effect, new TapSourceCost()); Ability ability = new SimpleManaAbility(Zone.BATTLEFIELD, effect, new TapSourceCost());
// choosing player as first effect, before adding mana effect // choosing player as first effect, before adding mana effect
ability.getEffects().add(0, new ChoosePlayerEffect(Outcome.PutManaInPool)); ability.getEffects().add(0, new ChoosePlayerEffect(Outcome.PutManaInPool));
@ -47,9 +48,9 @@ public final class SpectralSearchlight extends CardImpl {
class SpectralSearchlightManaEffect extends ManaEffect { class SpectralSearchlightManaEffect extends ManaEffect {
public SpectralSearchlightManaEffect(String textManaPoolOwner) { public SpectralSearchlightManaEffect() {
super(); 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) { public SpectralSearchlightManaEffect(final SpectralSearchlightManaEffect effect) {
@ -57,28 +58,19 @@ class SpectralSearchlightManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Player player = game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); return 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;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
if (netMana) { Player player = getPlayer(game, source);
return null; return ManaChoice.chooseAnyColor(player, game, 1);
} }
UUID playerId = (UUID) game.getState().getValue(source.getSourceId() + "_player");
Player player = game.getPlayer(playerId); @Override
ChoiceColor choice = new ChoiceColor(); public List<Mana> getNetMana(Game game, Ability source) {
if (player != null && player.choose(outcome, choice, game)) { return null;
return choice.getMana(1);
}
return new Mana();
} }
@Override @Override

View file

@ -63,18 +63,7 @@ class SquanderedResourcesEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);
choice.getChoices().clear(); choice.getChoices().clear();

View file

@ -70,82 +70,7 @@ class StarCompassManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);
choice.getChoices().clear(); choice.getChoices().clear();

View file

@ -101,23 +101,19 @@ class UtopiaSprawlEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) { if (enchantment != null) {
Permanent land = game.getPermanent(enchantment.getAttachedTo()); Permanent land = game.getPermanent(enchantment.getAttachedTo());
if (land != null) { if (land != null) {
Player player = game.getPlayer(land.getControllerId()); return game.getPlayer(land.getControllerId());
if (player != null) {
player.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
} }
} }
return false; return null;
} }
@Override @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"); ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
if (color != null) { if (color != null) {
return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0)));

View file

@ -111,29 +111,17 @@ class VedalkenEngineerEffect extends ManaEffect {
return new VedalkenEngineerEffect(this); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
return netMana; return netMana;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
ChoiceColor choiceColor = new ChoiceColor(true); ChoiceColor choiceColor = new ChoiceColor(true);
if (controller != null && controller.choose(Outcome.Benefit, choiceColor, game)) { if (controller != null && controller.choose(Outcome.Benefit, choiceColor, game)) {
Mana condMana = manaBuilder.setMana(choiceColor.getMana(amount), source, game).build(); return manaBuilder.setMana(choiceColor.getMana(amount), source, game).build();
return condMana;
} }
return null; return null;
} }

View file

@ -60,18 +60,12 @@ class VictoryChimesManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Player player = game.getPlayer((UUID) game.getState().getValue(source.getSourceId() + "_player")); return 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;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
return Mana.ColorlessMana(1); 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("\\$"); String[] groups = command.split("\\$");
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (permanent.getName().equals(groups[0])) { 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); permanent.addCounters(counter, null, game);
actions.remove(action); actions.remove(action);
return true; 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()); game.informPlayers(controller.getLogName() + " announces a value of " + xValue + " for " + variableManaCost.getText());
} }
activated = true; 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; return true;
} }

View file

@ -41,30 +41,11 @@ public class ConditionalManaEffect extends ManaEffect {
this.condition = effect.condition; 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 @Override
public ConditionalManaEffect copy() { public ConditionalManaEffect copy() {
return new ConditionalManaEffect(this); return new ConditionalManaEffect(this);
} }
@Override
public Mana getMana(Game game, Ability source) {
return produceMana(false, game, source);
}
@Override @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
if (condition.apply(game, source)) { if (condition.apply(game, source)) {
@ -76,7 +57,7 @@ public class ConditionalManaEffect extends ManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana(); Mana mana = new Mana();
if (condition.apply(game, source)) { if (condition.apply(game, source)) {
mana = effect.getManaTemplate().copy(); mana = effect.getManaTemplate().copy();

View file

@ -13,6 +13,8 @@ import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ManaEvent; 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(); this.createdMana = effect.createdMana == null ? null : effect.createdMana.copy();
} }
/** @Override
* Creates the mana the effect can produce or if that already has happened public boolean apply(Game game, Ability source) {
* returns the mana the effect has created during its process of resolving Player player = getPlayer(game, source);
* if (player == null) {
* @param game return false;
* @param source
* @return
*/
public Mana getMana(Game game, Ability source) {
if (createdMana == null) {
return createdMana = produceMana(false, game, source);
} }
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) { public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>(); List<Mana> netMana = new ArrayList<>();
Mana mana = produceMana(true, game, source); Mana mana = produceMana(game, source);
if (mana != null) { if (mana != null) {
netMana.add(mana); netMana.add(mana);
} }
@ -67,13 +76,11 @@ public abstract class ManaEffect extends OneShotEffect {
/** /**
* Produced the mana the effect can produce * Produced the mana the effect can produce
* *
* @param netMana true - produce the hypotetical possible mana for check of
* possible castable spells
* @param game * @param game
* @param source * @param source
* @return * @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 * 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 @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
return manaBuilder.setMana(mana, source, game).build(); return manaBuilder.setMana(mana, source, game).build();
} }

View file

@ -61,23 +61,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller == null) { if (controller == null) {
return null; return null;

View file

@ -27,20 +27,15 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) { if (enchantment != null) {
Permanent permanentattachedTo = game.getPermanent(enchantment.getAttachedTo()); Permanent permanentAttachedTo = game.getPermanent(enchantment.getAttachedTo());
if (permanentattachedTo != null) { if (permanentAttachedTo != null) {
Player player = game.getPlayer(permanentattachedTo.getControllerId()); return game.getPlayer(permanentAttachedTo.getControllerId());
if (player != null) {
checkToFirePossibleEvents(getMana(game, source), game, source);
player.getManaPool().addMana(getMana(game, source), game, source);
return true;
}
} }
} }
return false; return null;
} }
@Override @Override
@ -49,7 +44,7 @@ public class AddManaAnyColorAttachedControllerEffect extends ManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null) { if (enchantment != null) {
Permanent land = game.getPermanent(enchantment.getAttachedTo()); Permanent land = game.getPermanent(enchantment.getAttachedTo());

View file

@ -29,16 +29,7 @@ public class AddManaChosenColorEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
if (color != null) { if (color != null) {
return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0))); return new Mana(ColoredManaSymbol.lookup(color.toString().charAt(0)));

View file

@ -65,18 +65,7 @@ public class AddManaInAnyCombinationEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
Mana mana = new Mana(); Mana mana = new Mana();

View file

@ -50,23 +50,13 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
return new AddManaOfAnyColorEffect(this); 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 @Override
public List<Mana> getNetMana(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
return netMana; return netMana;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
String mes = String.format("Select color of %d mana to add it", this.amount); 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.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.List;
/** /**
* *
* @author LevelX2 * @author LevelX2
@ -26,25 +28,16 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) { if (permanent != null) {
Player targetController = game.getPlayer(permanent.getControllerId()); return 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 false; return null;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
if (netMana) {
return null;
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) { if (permanent != null) {
Player targetController = game.getPlayer(permanent.getControllerId()); Player targetController = game.getPlayer(permanent.getControllerId());
@ -109,6 +102,11 @@ public class AddManaOfAnyTypeProducedEffect extends ManaEffect {
return null; return null;
} }
@Override
public List<Mana> getNetMana(Game game, Ability source) {
return null;
}
@Override @Override
public AddManaOfAnyTypeProducedEffect copy() { public AddManaOfAnyTypeProducedEffect copy() {
return new AddManaOfAnyTypeProducedEffect(this); 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.game.Game;
import mage.players.Player; import mage.players.Player;
import java.util.List;
/** /**
* *
* @author LevelX2 * @author LevelX2
@ -53,20 +55,22 @@ public class AddManaToManaPoolTargetControllerEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Player getPlayer(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); return game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
player.getManaPool().addMana(getMana(game, source), game, source, emptyOnlyOnTurnsEnd);
return true;
}
return false;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
if (netMana) {
return null;
}
return mana.copy(); 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.Ability;
import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.ManaEffect;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
public class BasicManaEffect extends ManaEffect { public class BasicManaEffect extends ManaEffect {
@ -33,18 +34,12 @@ public class BasicManaEffect extends ManaEffect {
return new BasicManaEffect(this); 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() { public Mana getManaTemplate() {
return manaTemplate; return manaTemplate;
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
return manaTemplate.copy(); return manaTemplate.copy();
} }

View file

@ -43,58 +43,30 @@ public class DoUnlessAnyPlayerPaysManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); return manaEffect.getNetMana(game, source);
}
@Override
public Mana produceMana(Game game, Ability source) {
Player controller = getPlayer(game, source);
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) { String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName());
String message = CardUtil.replaceSourceName(chooseUseText, sourceObject.getName()); for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
boolean result = true; Player player = game.getPlayer(playerId);
boolean doEffect = true; if (player != null && player.canRespond()
// check if any player is willing to pay && cost.canPay(source, source.getSourceId(), player.getId(), game)
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { && player.chooseUse(Outcome.Detriment, message, source, game)) {
Player player = game.getPlayer(playerId); cost.clearPaid();
if (player != null && player.canRespond() if (cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) {
&& cost.canPay(source, source.getSourceId(), player.getId(), game) if (!game.isSimulation()) {
&& player.chooseUse(Outcome.Detriment, message, source, game)) { game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
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;
} }
return null;
} }
} }
// do the effects if nobody paid
if (doEffect) {
return manaEffect.apply(game, source);
}
return result;
} }
return false; return manaEffect.produceMana(game, source);
}
@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());
} }
@Override @Override

View file

@ -5,20 +5,25 @@ import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.common.ManaEffect;
import mage.choices.ChoiceColor; import mage.choices.ChoiceColor;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import java.util.ArrayList;
import java.util.List;
/** /**
* *
* @author North * @author North
*/ */
public class DynamicManaEffect extends BasicManaEffect { public class DynamicManaEffect extends ManaEffect {
private Mana baseMana;
private final DynamicValue amount; private final DynamicValue amount;
private final DynamicValue netAmount; private final DynamicValue netAmount;
private String text = null; private String text;
private boolean oneChoice; private boolean oneChoice;
public DynamicManaEffect(Mana mana, DynamicValue amount) { public DynamicManaEffect(Mana mana, DynamicValue amount) {
@ -38,13 +43,14 @@ public class DynamicManaEffect extends BasicManaEffect {
* @param mana * @param mana
* @param amount * @param amount
* @param text * @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 * player can choose different colours
* @param netAmount a dynamic value that calculates the possible available * @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) { public DynamicManaEffect(Mana mana, DynamicValue amount, String text, boolean oneChoice, DynamicValue netAmount) {
super(mana); super();
this.baseMana = mana;
this.amount = amount; this.amount = amount;
this.text = text; this.text = text;
this.oneChoice = oneChoice; this.oneChoice = oneChoice;
@ -53,6 +59,7 @@ public class DynamicManaEffect extends BasicManaEffect {
public DynamicManaEffect(final DynamicManaEffect effect) { public DynamicManaEffect(final DynamicManaEffect effect) {
super(effect); super(effect);
this.baseMana = effect.baseMana.copy();
this.amount = effect.amount.copy(); this.amount = effect.amount.copy();
this.text = effect.text; this.text = effect.text;
this.oneChoice = effect.oneChoice; this.oneChoice = effect.oneChoice;
@ -68,13 +75,6 @@ public class DynamicManaEffect extends BasicManaEffect {
return new DynamicManaEffect(this); 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 @Override
public String getText(Mode mode) { public String getText(Mode mode) {
if (text != null && !text.isEmpty()) { if (text != null && !text.isEmpty()) {
@ -84,46 +84,69 @@ public class DynamicManaEffect extends BasicManaEffect {
} }
@Override @Override
public Mana produceMana(boolean netMana, Game game, Ability source) { public List<Mana> getNetMana(Game game, Ability source) {
Mana computedMana = new Mana(); Mana computedMana = new Mana();
int count; int count;
if (netMana && netAmount != null) { if (netAmount != null) {
// calculate the maximum available manaTemplate // calculate the maximum available mana
count = netAmount.calculate(game, source, this); count = netAmount.calculate(game, source, this);
} else { } else {
count = amount.calculate(game, source, this); count = amount.calculate(game, source, this);
} }
if (manaTemplate.getBlack() > 0) { if (baseMana.getBlack() > 0) {
computedMana.setBlack(count); computedMana.setBlack(count);
} else if (manaTemplate.getBlue() > 0) { } else if (baseMana.getBlue() > 0) {
computedMana.setBlue(count); computedMana.setBlue(count);
} else if (manaTemplate.getGreen() > 0) { } else if (baseMana.getGreen() > 0) {
computedMana.setGreen(count); computedMana.setGreen(count);
} else if (manaTemplate.getRed() > 0) { } else if (baseMana.getRed() > 0) {
computedMana.setRed(count); computedMana.setRed(count);
} else if (manaTemplate.getWhite() > 0) { } else if (baseMana.getWhite() > 0) {
computedMana.setWhite(count); computedMana.setWhite(count);
} else if (manaTemplate.getColorless() > 0) { } else if (baseMana.getColorless() > 0) {
computedMana.setColorless(count); computedMana.setColorless(count);
} else if (manaTemplate.getAny() > 0) { } else if (baseMana.getAny() > 0) {
if (netMana) { computedMana.setAny(count);
computedMana.setAny(count); } else {
} else { computedMana.setGeneric(count);
Player controller = game.getPlayer(source.getControllerId()); }
if (controller != null) { List<Mana> netMana = new ArrayList<>();
ChoiceColor choiceColor = new ChoiceColor(true); netMana.add(computedMana);
for (int i = 0; i < count; i++) { return netMana;
if (!choiceColor.isChosen()) { }
if (!controller.choose(Outcome.Benefit, choiceColor, game)) {
return computedMana; @Override
} public Mana produceMana(Game game, Ability source) {
} Mana computedMana = new Mana();
choiceColor.increaseMana(computedMana); int count = amount.calculate(game, source, this);
if (!oneChoice) {
choiceColor.clearChoice(); 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 { } else {

View file

@ -87,18 +87,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);

View file

@ -81,18 +81,7 @@ class AnyColorPermanentTypesManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
Mana types = getManaTypes(game, source); Mana types = getManaTypes(game, source);
Choice choice = new ChoiceColor(true); Choice choice = new ChoiceColor(true);

View file

@ -14,9 +14,7 @@ import mage.filter.FilterMana;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.UUID;
/** /**
* @author LevelX2 * @author LevelX2
@ -40,39 +38,6 @@ public class CommanderColorIdentityManaAbility extends ActivatedManaAbilityImpl
return new CommanderColorIdentityManaAbility(this); 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 @Override
public boolean definesMana(Game game) { public boolean definesMana(Game game) {
return true; return true;
@ -97,18 +62,7 @@ class CommanderIdentityManaEffect extends ManaEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source) { public Mana produceMana(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) {
Mana mana = new Mana(); Mana mana = new Mana();
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
@ -167,4 +121,34 @@ class CommanderIdentityManaEffect extends ManaEffect {
return mana; 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;
}
}