Some more changes to net mana handling.

This commit is contained in:
LevelX2 2014-11-17 23:44:40 +01:00
parent 1c2233b1f8
commit 036095f6ec
13 changed files with 352 additions and 391 deletions

View file

@ -27,7 +27,6 @@
*/
package mage.sets.bornofthegods;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.Mana;
@ -40,7 +39,6 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Outcome;
@ -49,6 +47,7 @@ import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -64,11 +63,7 @@ public class AstralCornucopia extends CardImpl {
this.addAbility(new EntersBattlefieldAbility(new AstralCornucopiaEffect(), "with X charge counters on it"));
// {T}: Choose a color. Add one mana of that color to your mana pool for each charge counter on Astral Cornucopia.
Ability ability = new AstralCornucopiaManaAbility();
Choice choice = new ChoiceColor();
choice.setMessage("Choose a color to add mana of that color");
ability.addChoice(choice);
this.addAbility(ability);
this.addAbility(new AstralCornucopiaManaAbility());
}
public AstralCornucopia(final AstralCornucopia card) {
@ -130,15 +125,18 @@ class AstralCornucopiaManaAbility extends ManaAbility {
@Override
public List<Mana> getNetMana(Game game) {
List<Mana> newNetMana = new ArrayList<>();
if (game != null) {
newNetMana.add(new Mana(((AstralCornucopiaManaEffect)this.getEffects().get(0)).computeMana(game, this)));
}
return newNetMana;
netMana.clear();
Permanent sourcePermanent = game.getPermanent(getSourceId());
if (sourcePermanent != null) {
int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName());
if (counters > 0) {
netMana.add(new Mana(0,0,0,0,0,0,counters));
}
}
return netMana;
}
}
class AstralCornucopiaManaEffect extends ManaEffect {
private final Mana computedMana;
@ -161,32 +159,36 @@ class AstralCornucopiaManaEffect extends ManaEffect {
@Override
public boolean apply(Game game, Ability source) {
computeMana(game, source);
game.getPlayer(source.getControllerId()).getManaPool().addMana(computedMana, game, source);
return true;
}
public Mana computeMana(Game game, Ability source){
this.computedMana.clear();
if (!source.getChoices().isEmpty()) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
if (choice != null && choice instanceof ChoiceColor && choice.getChoice() != null) {
String color = choice.getChoice();
int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName());
if (color.equals("Red")) {
computedMana.setRed(counters);
} else if (color.equals("Blue")) {
computedMana.setBlue(counters);
} else if (color.equals("White")) {
computedMana.setWhite(counters);
} else if (color.equals("Black")) {
computedMana.setBlack(counters);
} else if (color.equals("Green")) {
computedMana.setGreen(counters);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor choice = new ChoiceColor();
choice.setMessage("Choose a color to add mana of that color");
if (controller.choose(outcome, choice, game)) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (choice.getChoice() != null) {
String color = choice.getChoice();
int counters = sourcePermanent.getCounters().getCount(CounterType.CHARGE.getName());
switch (color) {
case "Red":
computedMana.setRed(counters);
break;
case "Blue":
computedMana.setBlue(counters);
break;
case "White":
computedMana.setWhite(counters);
break;
case "Black":
computedMana.setBlack(counters);
break;
case "Green":
computedMana.setGreen(counters);
break;
}
}
return true;
}
}
return computedMana;
return false;
}
}

View file

@ -28,10 +28,6 @@
package mage.sets.championsofkamigawa;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -41,6 +37,9 @@ import mage.abilities.mana.TriggeredManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;

View file

@ -27,28 +27,11 @@
*/
package mage.sets.conflux;
import java.util.List;
import java.util.UUID;
import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -61,7 +44,7 @@ public class ExoticOrchard extends CardImpl {
this.expansionSetCode = "CON";
// {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce.
this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new ExoticOrchardEffect(), new TapSourceCost()));
this.addAbility(new AnyColorOpponentLandsProduceManaAbility());
}
public ExoticOrchard(final ExoticOrchard card) {
@ -73,89 +56,3 @@ public class ExoticOrchard extends CardImpl {
return new ExoticOrchard(this);
}
}
class ExoticOrchardEffect extends ManaEffect {
private static final FilterPermanent filter = new FilterLandPermanent();
static {
filter.add(new ControllerPredicate(TargetController.OPPONENT));
}
public ExoticOrchardEffect() {
super();
staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce";
}
public ExoticOrchardEffect(final ExoticOrchardEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : mana) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
}
if (choice.getChoices().size() > 0) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
switch (choice.getChoice()) {
case "Black":
player.getManaPool().addMana(Mana.BlackMana, game, source);
break;
case "Blue":
player.getManaPool().addMana(Mana.BlueMana, game, source);
break;
case "Red":
player.getManaPool().addMana(Mana.RedMana, game, source);
break;
case "Green":
player.getManaPool().addMana(Mana.GreenMana, game, source);
break;
case "White":
player.getManaPool().addMana(Mana.WhiteMana, game, source);
break;
}
}
return true;
}
@Override
public ExoticOrchardEffect copy() {
return new ExoticOrchardEffect(this);
}
}

View file

@ -164,24 +164,25 @@ class ZhurTaaAncientEffect extends ManaEffect {
} else {
player.choose(outcome, choice, game);
}
if (choice.getChoice().equals("Black")) {
player.getManaPool().addMana(Mana.BlackMana, game, source);
return true;
} else if (choice.getChoice().equals("Blue")) {
player.getManaPool().addMana(Mana.BlueMana, game, source);
return true;
} else if (choice.getChoice().equals("Red")) {
player.getManaPool().addMana(Mana.RedMana, game, source);
return true;
} else if (choice.getChoice().equals("Green")) {
player.getManaPool().addMana(Mana.GreenMana, game, source);
return true;
} else if (choice.getChoice().equals("White")) {
player.getManaPool().addMana(Mana.WhiteMana, game, source);
return true;
} else if (choice.getChoice().equals("Colorless")) {
player.getManaPool().addMana(Mana.ColorlessMana, game, source);
return true;
switch (choice.getChoice()) {
case "Black":
player.getManaPool().addMana(Mana.BlackMana, game, source);
return true;
case "Blue":
player.getManaPool().addMana(Mana.BlueMana, game, source);
return true;
case "Red":
player.getManaPool().addMana(Mana.RedMana, game, source);
return true;
case "Green":
player.getManaPool().addMana(Mana.GreenMana, game, source);
return true;
case "White":
player.getManaPool().addMana(Mana.WhiteMana, game, source);
return true;
case "Colorless":
player.getManaPool().addMana(Mana.ColorlessMana, game, source);
return true;
}
}
return true;

View file

@ -27,29 +27,12 @@
*/
package mage.sets.fifthdawn;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.SimpleManaAbility;
import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -67,8 +50,8 @@ public class SylvokExplorer extends CardImpl {
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// {tap}: Add to your mana pool one mana of any color that a land an opponent controls could produce.
this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new SylvokExplorerEffect(), new TapSourceCost()));
// {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce.
this.addAbility(new AnyColorOpponentLandsProduceManaAbility());
}
public SylvokExplorer(final SylvokExplorer card) {
@ -80,83 +63,3 @@ public class SylvokExplorer extends CardImpl {
return new SylvokExplorer(this);
}
}
class SylvokExplorerEffect extends ManaEffect {
private static final FilterPermanent filter = new FilterLandPermanent();
static {
filter.add(new ControllerPredicate(TargetController.OPPONENT));
}
public SylvokExplorerEffect() {
super();
staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce";
}
public SylvokExplorerEffect(final SylvokExplorerEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : mana) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
}
if (choice.getChoices().size() > 0) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
if (choice.getChoice().equals("Black")) {
player.getManaPool().addMana(Mana.BlackMana, game, source);
} else if (choice.getChoice().equals("Blue")) {
player.getManaPool().addMana(Mana.BlueMana, game, source);
} else if (choice.getChoice().equals("Red")) {
player.getManaPool().addMana(Mana.RedMana, game, source);
} else if (choice.getChoice().equals("Green")) {
player.getManaPool().addMana(Mana.GreenMana, game, source);
} else if (choice.getChoice().equals("White")) {
player.getManaPool().addMana(Mana.WhiteMana, game, source);
}
}
return true;
}
@Override
public SylvokExplorerEffect copy() {
return new SylvokExplorerEffect(this);
}
}

View file

@ -28,10 +28,6 @@
package mage.sets.mirage;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.Mana;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.DiscardHandCost;
@ -40,7 +36,9 @@ import mage.abilities.effects.common.AddManaOfAnyColorEffect;
import mage.abilities.effects.common.BasicManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.cards.CardImpl;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
/**
*
@ -72,11 +70,12 @@ class LionsEyeDiamondAbility extends ManaAbility {
public LionsEyeDiamondAbility() {
super(Zone.BATTLEFIELD, new AddManaOfAnyColorEffect(3), new SacrificeSourceCost());
this.addCost(new DiscardHandCost());
this.netMana.add(new Mana(0,0,0,0,0,0,3));
}
public LionsEyeDiamondAbility(Zone zone, Mana mana, Cost cost) {
super(zone, new BasicManaEffect(mana), cost);
this.netMana.add(mana.copy());
}
public LionsEyeDiamondAbility(final LionsEyeDiamondAbility ability) {

View file

@ -27,28 +27,11 @@
*/
package mage.sets.ninthedition;
import java.util.List;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.SimpleManaAbility;
import mage.abilities.mana.AnyColorOpponentLandsProduceManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
@ -60,8 +43,8 @@ public class FellwarStone extends CardImpl {
super(ownerId, 297, "Fellwar Stone", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}");
this.expansionSetCode = "9ED";
// {tap}: Add to your mana pool one mana of any color that a land an opponent controls could produce.
this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new FellwarStoneEffect(), new TapSourceCost()));
// {T}: Add to your mana pool one mana of any color that a land an opponent controls could produce.
this.addAbility(new AnyColorOpponentLandsProduceManaAbility());
}
public FellwarStone(final FellwarStone card) {
@ -73,83 +56,3 @@ public class FellwarStone extends CardImpl {
return new FellwarStone(this);
}
}
class FellwarStoneEffect extends ManaEffect {
private static final FilterPermanent filter = new FilterLandPermanent();
static {
filter.add(new ControllerPredicate(TargetController.OPPONENT));
}
public FellwarStoneEffect() {
super();
staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce";
}
public FellwarStoneEffect(final FellwarStoneEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : mana) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
Choice choice = new ChoiceImpl(true);
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
}
if (choice.getChoices().size() > 0) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
if (choice.getChoice().equals("Black")) {
player.getManaPool().addMana(Mana.BlackMana, game, source);
} else if (choice.getChoice().equals("Blue")) {
player.getManaPool().addMana(Mana.BlueMana, game, source);
} else if (choice.getChoice().equals("Red")) {
player.getManaPool().addMana(Mana.RedMana, game, source);
} else if (choice.getChoice().equals("Green")) {
player.getManaPool().addMana(Mana.GreenMana, game, source);
} else if (choice.getChoice().equals("White")) {
player.getManaPool().addMana(Mana.WhiteMana, game, source);
}
}
return true;
}
@Override
public FellwarStoneEffect copy() {
return new FellwarStoneEffect(this);
}
}

View file

@ -27,21 +27,21 @@
*/
package mage.sets.tempest;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledLandPermanent;
import mage.filter.common.FilterControlledPermanent;
@ -60,7 +60,7 @@ public class ReflectingPool extends CardImpl {
this.expansionSetCode = "TMP";
// {T}: Add to your mana pool one mana of any type that a land you control could produce.
this.addAbility(new SimpleManaAbility(Zone.BATTLEFIELD, new ReflectingPoolEffect(), new TapSourceCost()));
this.addAbility(new ReflectingPoolManaAbility());
}
public ReflectingPool(final ReflectingPool card) {
@ -73,6 +73,27 @@ public class ReflectingPool extends CardImpl {
}
}
class ReflectingPoolManaAbility extends ManaAbility {
public ReflectingPoolManaAbility() {
super(Zone.BATTLEFIELD, new ReflectingPoolEffect(),new TapSourceCost());
}
public ReflectingPoolManaAbility(final ReflectingPoolManaAbility ability) {
super(ability);
}
@Override
public ReflectingPoolManaAbility copy() {
return new ReflectingPoolManaAbility(this);
}
@Override
public List<Mana> getNetMana(Game game) {
return ((ReflectingPoolEffect)getEffects().get(0)).getNetMana(game, this);
}
}
class ReflectingPoolEffect extends ManaEffect {
private static final FilterControlledPermanent filter = new FilterControlledLandPermanent();
@ -88,16 +109,7 @@ class ReflectingPoolEffect extends ManaEffect {
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : mana) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceImpl(false);
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
@ -161,8 +173,48 @@ class ReflectingPoolEffect extends ManaEffect {
return true;
}
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netManas = new ArrayList<>();
Mana types = getManaTypes(game, source);
if (types.getBlack() > 0) {
netManas.add(new Mana(ColoredManaSymbol.B));
}
if (types.getRed() > 0) {
netManas.add(new Mana(ColoredManaSymbol.R));
}
if (types.getBlue() > 0) {
netManas.add(new Mana(ColoredManaSymbol.U));
}
if (types.getGreen() > 0) {
netManas.add(new Mana(ColoredManaSymbol.G));
}
if (types.getWhite() > 0) {
netManas.add(new Mana(ColoredManaSymbol.W));
}
if (types.getColorless() > 0) {
netManas.add(new Mana(0,0,0,0,0,1,0));
}
return netManas;
}
private Mana getManaTypes(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> manaAbilities = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : manaAbilities) {
if (!ability.equals(source) && ability.definesMana()) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
}
return types;
}
@Override
public ReflectingPoolEffect copy() {
return new ReflectingPoolEffect(this);
}
}
}

View file

@ -83,6 +83,8 @@ public class PutIntoPlayEffectsTest extends CardTestPlayerBase {
// onto the battlefield under your control.
addCard(Zone.BATTLEFIELD, playerB, "Island", 4);
addCard(Zone.BATTLEFIELD, playerB, "Lord of the Void");
// Put target creature on top of its owner's library.
addCard(Zone.HAND, playerB, "Griptide");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Griptide", "Oracle of Mul Daya");
@ -96,8 +98,8 @@ public class PutIntoPlayEffectsTest extends CardTestPlayerBase {
assertLife(playerA, 13);
assertPermanentCount(playerB, "Oracle of Mul Daya", 1);
Assert.assertTrue("Top card of the library of player B should be reveled.", playerB.isTopCardRevealed());
Assert.assertFalse("Top card of the library of player A should not be reveled.", playerA.isTopCardRevealed());
Assert.assertTrue("Top card of the library of player B should be revealed.", playerB.isTopCardRevealed());
Assert.assertFalse("Top card of the library of player A should not be revealed.", playerA.isTopCardRevealed());
}
/**

View file

@ -0,0 +1,190 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.mana;
import java.util.ArrayList;
import java.util.List;
import mage.Mana;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.common.ManaEffect;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.ColoredManaSymbol;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class AnyColorOpponentLandsProduceManaAbility extends ManaAbility {
public AnyColorOpponentLandsProduceManaAbility() {
super(Zone.BATTLEFIELD, new AnyColorOpponentLandsProduceManaEffect(),new TapSourceCost());
}
public AnyColorOpponentLandsProduceManaAbility(final AnyColorOpponentLandsProduceManaAbility ability) {
super(ability);
}
@Override
public AnyColorOpponentLandsProduceManaAbility copy() {
return new AnyColorOpponentLandsProduceManaAbility(this);
}
@Override
public List<Mana> getNetMana(Game game) {
return ((AnyColorOpponentLandsProduceManaEffect)getEffects().get(0)).getNetMana(game, this);
}
}
class AnyColorOpponentLandsProduceManaEffect extends ManaEffect {
private static final FilterPermanent filter = new FilterLandPermanent();
static {
filter.add(new ControllerPredicate(TargetController.OPPONENT));
}
public AnyColorOpponentLandsProduceManaEffect() {
super();
staticText = "Add to your mana pool one mana of any color that a land an opponent controls could produce";
}
public AnyColorOpponentLandsProduceManaEffect(final AnyColorOpponentLandsProduceManaEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Mana types = getManaTypes(game, source);
Choice choice = new ChoiceImpl(true);
choice.setMessage("Pick a mana color");
if (types.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (types.getRed() > 0) {
choice.getChoices().add("Red");
}
if (types.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (types.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (types.getWhite() > 0) {
choice.getChoices().add("White");
}
if (types.getAny() > 0) {
choice.getChoices().add("Black");
choice.getChoices().add("Red");
choice.getChoices().add("Blue");
choice.getChoices().add("Green");
choice.getChoices().add("White");
}
if (choice.getChoices().size() > 0) {
Player player = game.getPlayer(source.getControllerId());
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
player.choose(outcome, choice, game);
}
switch (choice.getChoice()) {
case "Black":
player.getManaPool().addMana(Mana.BlackMana, game, source);
break;
case "Blue":
player.getManaPool().addMana(Mana.BlueMana, game, source);
break;
case "Red":
player.getManaPool().addMana(Mana.RedMana, game, source);
break;
case "Green":
player.getManaPool().addMana(Mana.GreenMana, game, source);
break;
case "White":
player.getManaPool().addMana(Mana.WhiteMana, game, source);
break;
}
}
return true;
}
private Mana getManaTypes(Game game, Ability source) {
List<Permanent> lands = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game);
Mana types = new Mana();
for (Permanent land : lands) {
Abilities<ManaAbility> mana = land.getAbilities().getManaAbilities(Zone.BATTLEFIELD);
for (ManaAbility ability : mana) {
if (!ability.equals(source) && ability.definesMana()) {
for (Mana netMana: ability.getNetMana(game)) {
types.add(netMana);
}
}
}
}
return types;
}
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netManas = new ArrayList<>();
Mana types = getManaTypes(game, source);
if (types.getBlack() > 0) {
netManas.add(new Mana(ColoredManaSymbol.B));
}
if (types.getRed() > 0) {
netManas.add(new Mana(ColoredManaSymbol.R));
}
if (types.getBlue() > 0) {
netManas.add(new Mana(ColoredManaSymbol.U));
}
if (types.getGreen() > 0) {
netManas.add(new Mana(ColoredManaSymbol.G));
}
if (types.getWhite() > 0) {
netManas.add(new Mana(ColoredManaSymbol.W));
}
if (types.getColorless() > 0) {
netManas.add(new Mana(0,0,0,0,0,1,0));
}
return netManas;
}
@Override
public AnyColorOpponentLandsProduceManaEffect copy() {
return new AnyColorOpponentLandsProduceManaEffect(this);
}
}

View file

@ -81,5 +81,15 @@ public abstract class ManaAbility extends ActivatedAbilityImpl {
*/
public List<Mana> getNetMana(Game game) {
return netMana;
}
}
/**
* Used to check if the ability itself defines mana types
* it can produce.
*
* @return
*/
public boolean definesMana() {
return netMana.size() > 0;
}
}

View file

@ -28,11 +28,13 @@
package mage.abilities.mana;
import java.util.List;
import mage.constants.Zone;
import mage.Mana;
import mage.abilities.costs.Cost;
import mage.abilities.effects.common.BasicManaEffect;
import mage.abilities.effects.common.ManaEffect;
import mage.game.Game;
/**
*

View file

@ -27,9 +27,9 @@
*/
package mage.abilities.mana;
import mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.common.ManaEffect;
import mage.constants.Zone;
/**
* see 20110715 - 605.1b
@ -43,6 +43,7 @@ public abstract class TriggeredManaAbility extends TriggeredAbilityImpl {
public TriggeredManaAbility(Zone zone, ManaEffect effect, boolean optional) {
super(zone, effect, optional);
this.usesStack = false;
}
public TriggeredManaAbility(final TriggeredManaAbility ability) {