* Cavern of Souls - Fixed that conditional mana in the mana pool remembers correctly for which creature subtrype its usable.

This commit is contained in:
LevelX2 2014-08-29 14:48:04 +02:00
parent 35d3c14dc6
commit 1f196f0bc7
11 changed files with 133 additions and 36 deletions

View file

@ -119,8 +119,8 @@ class CavernOfSoulsEffect extends OneShotEffect {
} }
} }
game.informPlayers(permanent.getName() + ": " + player.getName() + " has chosen " + typeChoice.getChoice()); game.informPlayers(permanent.getName() + ": " + player.getName() + " has chosen " + typeChoice.getChoice());
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice().toString()); game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice().toString())); permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()));
} }
return false; return false;
} }
@ -133,10 +133,21 @@ class CavernOfSoulsEffect extends OneShotEffect {
class CavernOfSoulsManaBuilder extends ConditionalManaBuilder { class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
String creatuerType;
@Override
public ConditionalManaBuilder setMana(Mana mana, Ability source, Game game) {
Object value = game.getState().getValue(source.getSourceId() + "_type");
if (value != null && value instanceof String) {
creatuerType = (String) value;
}
return super.setMana(mana, source, game);
}
@Override @Override
public ConditionalMana build(Object... options) { public ConditionalMana build(Object... options) {
this.mana.setFlag(true); // indicates that the mana is from second ability this.mana.setFlag(true); // indicates that the mana is from second ability
return new CavernOfSoulsConditionalMana(this.mana); return new CavernOfSoulsConditionalMana(this.mana, creatuerType);
} }
@Override @Override
@ -147,28 +158,31 @@ class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
class CavernOfSoulsConditionalMana extends ConditionalMana { class CavernOfSoulsConditionalMana extends ConditionalMana {
public CavernOfSoulsConditionalMana(Mana mana) { public CavernOfSoulsConditionalMana(Mana mana, String creatureType) {
super(mana); super(mana);
staticText = "Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered"; staticText = "Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered";
addCondition(new CavernOfSoulsManaCondition()); addCondition(new CavernOfSoulsManaCondition(creatureType));
} }
} }
class CavernOfSoulsManaCondition extends CreatureCastManaCondition { class CavernOfSoulsManaCondition extends CreatureCastManaCondition {
String creatureType;
CavernOfSoulsManaCondition(String creatureType) {
this.creatureType = creatureType;
}
@Override @Override
public boolean apply(Game game, Ability source, UUID manaProducer) { public boolean apply(Game game, Ability source, UUID manaProducer) {
// check: ... to cast a creature spell // check: ... to cast a creature spell
if (super.apply(game, source)) { if (super.apply(game, source)) {
// check: ... of the chosen type // check: ... of the chosen type
Object value = game.getState().getValue(manaProducer + "_type");
if (value != null && value instanceof String) {
MageObject object = game.getObject(source.getSourceId()); MageObject object = game.getObject(source.getSourceId());
if (object.hasSubtype((String) value)) { if (creatureType != null && object.hasSubtype(creatureType)) {
return true; return true;
} }
} }
}
return false; return false;
} }
} }

View file

@ -117,19 +117,19 @@ class FoodChainManaEffect extends ManaEffect {
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
Mana mana = null; Mana mana = null;
if (choice.getColor().isBlack()) { if (choice.getColor().isBlack()) {
mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1)).build(); mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build();
} }
else if (choice.getColor().isBlue()) { else if (choice.getColor().isBlue()) {
mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1)).build(); mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build();
} }
else if (choice.getColor().isRed()) { else if (choice.getColor().isRed()) {
mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1)).build(); mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build();
} }
else if (choice.getColor().isGreen()) { else if (choice.getColor().isGreen()) {
mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1)).build(); mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build();
} }
else if (choice.getColor().isWhite()) { else if (choice.getColor().isWhite()) {
mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1)).build(); mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build();
} }
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());

View file

@ -163,15 +163,15 @@ class VedalkenEngineerEffect extends ManaEffect {
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
Mana mana = null; Mana mana = null;
if (choice.getColor().isBlack()) { if (choice.getColor().isBlack()) {
mana = manaBuilder.setMana(Mana.BlackMana(1)).build(); mana = manaBuilder.setMana(Mana.BlackMana(1), source, game).build();
} else if (choice.getColor().isBlue()) { } else if (choice.getColor().isBlue()) {
mana = manaBuilder.setMana(Mana.BlueMana(1)).build(); mana = manaBuilder.setMana(Mana.BlueMana(1), source, game).build();
} else if (choice.getColor().isRed()) { } else if (choice.getColor().isRed()) {
mana = manaBuilder.setMana(Mana.RedMana(1)).build(); mana = manaBuilder.setMana(Mana.RedMana(1), source, game).build();
} else if (choice.getColor().isGreen()) { } else if (choice.getColor().isGreen()) {
mana = manaBuilder.setMana(Mana.GreenMana(1)).build(); mana = manaBuilder.setMana(Mana.GreenMana(1), source, game).build();
} else if (choice.getColor().isWhite()) { } else if (choice.getColor().isWhite()) {
mana = manaBuilder.setMana(Mana.WhiteMana(1)).build(); mana = manaBuilder.setMana(Mana.WhiteMana(1), source, game).build();
} }
if (mana != null) { if (mana != null) {
player.getManaPool().addMana(mana, game, source); player.getManaPool().addMana(mana, game, source);

View file

@ -136,4 +136,54 @@ public class CavernOfSoulsTest extends CardTestPlayerBase {
assertGraveyardCount(playerA, "Azure Drake", 1); assertGraveyardCount(playerA, "Azure Drake", 1);
assertPermanentCount(playerA, "Azure Drake", 0); assertPermanentCount(playerA, "Azure Drake", 0);
} }
/**
* Tests conditional mana from Cavern in pool will still work if Cavern got back to hand and is played again with other creature type
*/
@Test
public void testConditionlManaWorksIfCavernIsReplayed() {
addCard(Zone.HAND, playerA, "Cavern of Souls");
addCard(Zone.HAND, playerA, "Gladecover Scout"); // Elf costing {G}
// addCard(Zone.HAND, playerA, "Fume Spitter"); // Horror costing {B}
// Instant - {U}{U} - Return target permanent to its owner's hand.
addCard(Zone.HAND, playerB, "Boomerang");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
playLand(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cavern of Souls");
setChoice(playerA, "Elf");
// getting green mana for Elf into pool
activateManaAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add 1 mana of any one color to your mana pool. Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered.");
setChoice(playerA, "Green");
// return cavern to hand
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Boomerang", "Cavern of Souls");
// playing the cavern again choose different creature type
playLand(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Cavern of Souls");
setChoice(playerA, "Horror");
// the green mana usable for Elf should be in the mana pool
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Gladecover Scout");
activateManaAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add 1 mana of any one color to your mana pool. Spend this mana only to cast a creature spell of the chosen type, and that spell can't be countered.");
setChoice(playerA, "Black");
// the black mana usable for Horror should be in the mana pool
// castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Fume Spitter");
setStopAt(3, PhaseStep.BEGIN_COMBAT);
execute();
assertGraveyardCount(playerB, "Boomerang", 1);
assertPermanentCount(playerA, "Cavern of Souls", 1);
// Check the elf was cast
assertPermanentCount(playerA, "Gladecover Scout", 1);
// Check Horror on the Battlefield
// assertPermanentCount(playerA, "Fume Spitter", 1);
}
} }

View file

@ -62,6 +62,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.abilities.mana.ManaAbility;
import mage.constants.Zone;
/** /**
* *
@ -114,6 +116,7 @@ public class TestPlayer extends ComputerPlayer {
public boolean priority(Game game) { public boolean priority(Game game) {
for (PlayerAction action: actions) { for (PlayerAction action: actions) {
if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getStep().getType()) { if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getStep().getType()) {
if (action.getAction().startsWith("activate:")) { if (action.getAction().startsWith("activate:")) {
String command = action.getAction(); String command = action.getAction();
command = command.substring(command.indexOf("activate:") + 9); command = command.substring(command.indexOf("activate:") + 9);
@ -135,7 +138,26 @@ public class TestPlayer extends ComputerPlayer {
return true; return true;
} }
} }
} else
if (action.getAction().startsWith("manaActivate:")) {
String command = action.getAction();
command = command.substring(command.indexOf("manaActivate:") + 13);
String[] groups = command.split(";");
List<Permanent> manaPerms = this.getAvailableManaProducers(game);
for (Permanent perm: manaPerms) {
for (Ability manaAbility: perm.getAbilities().getAvailableManaAbilities(Zone.BATTLEFIELD, game)) {
if (manaAbility.toString().startsWith(groups[0])) {
Ability newManaAbility = manaAbility.copy();
this.activateAbility((ActivatedAbility)newManaAbility, game);
actions.remove(action);
return true;
} }
}
}
} else
if (action.getAction().startsWith("addCounters:")) { if (action.getAction().startsWith("addCounters:")) {
String command = action.getAction(); String command = action.getAction();
command = command.substring(command.indexOf("addCounters:") + 12); command = command.substring(command.indexOf("addCounters:") + 12);

View file

@ -734,6 +734,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
player.addAction(turnNum, step, action); player.addAction(turnNum, step, action);
} }
public void activateManaAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) {
player.addAction(turnNum, step, "manaActivate:" + ability);
}
public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) { public void activateAbility(int turnNum, PhaseStep step, TestPlayer player, String ability) {
player.addAction(turnNum, step, "activate:" + ability); player.addAction(turnNum, step, "activate:" + ability);
} }

View file

@ -7,7 +7,6 @@ import mage.constants.CardType;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.interfaces.rate.RateCallback; import mage.interfaces.rate.RateCallback;
import mage.sets.guru.Island;
import mage.utils.DeckBuilder; import mage.utils.DeckBuilder;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -16,6 +15,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.sets.unhinged.Island;
/** /**
* @author dustinconrad * @author dustinconrad

View file

@ -44,7 +44,7 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player != null) {
player.getManaPool().addMana(manaBuilder.setMana(Mana.ColorlessMana(amount)).build(), game, source); player.getManaPool().addMana(manaBuilder.setMana(Mana.ColorlessMana(amount), source, game).build(), game, source);
return true; return true;
} }
return false; return false;

View file

@ -39,8 +39,8 @@ import mage.players.Player;
*/ */
public class AddConditionalManaOfAnyColorEffect extends ManaEffect { public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
private int amount; private final int amount;
private ConditionalManaBuilder manaBuilder; private final ConditionalManaBuilder manaBuilder;
public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) { public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) {
super(); super();
@ -73,15 +73,15 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
Mana mana = null; Mana mana = null;
if (choice.getColor().isBlack()) { if (choice.getColor().isBlack()) {
mana = manaBuilder.setMana(Mana.BlackMana(1)).build(); mana = manaBuilder.setMana(Mana.BlackMana(1), source, game).build();
} else if (choice.getColor().isBlue()) { } else if (choice.getColor().isBlue()) {
mana = manaBuilder.setMana(Mana.BlueMana(1)).build(); mana = manaBuilder.setMana(Mana.BlueMana(1), source, game).build();
} else if (choice.getColor().isRed()) { } else if (choice.getColor().isRed()) {
mana = manaBuilder.setMana(Mana.RedMana(1)).build(); mana = manaBuilder.setMana(Mana.RedMana(1), source, game).build();
} else if (choice.getColor().isGreen()) { } else if (choice.getColor().isGreen()) {
mana = manaBuilder.setMana(Mana.GreenMana(1)).build(); mana = manaBuilder.setMana(Mana.GreenMana(1), source, game).build();
} else if (choice.getColor().isWhite()) { } else if (choice.getColor().isWhite()) {
mana = manaBuilder.setMana(Mana.WhiteMana(1)).build(); mana = manaBuilder.setMana(Mana.WhiteMana(1), source, game).build();
} }
if (mana != null) { if (mana != null) {

View file

@ -78,8 +78,9 @@ public class ManaOptions extends ArrayList<Mana> {
} }
public void addManaWithCost(List<ManaAbility> abilities, Game game) { public void addManaWithCost(List<ManaAbility> abilities, Game game) {
if (isEmpty()) if (isEmpty()) {
this.add(new Mana()); this.add(new Mana());
}
if (!abilities.isEmpty()) { if (!abilities.isEmpty()) {
if (abilities.size() == 1) { if (abilities.size() == 1) {
//if there is only one mana option available add it to all the existing options //if there is only one mana option available add it to all the existing options
@ -121,16 +122,18 @@ public class ManaOptions extends ArrayList<Mana> {
} }
public void addMana(Mana addMana) { public void addMana(Mana addMana) {
if (isEmpty()) if (isEmpty()) {
this.add(new Mana()); this.add(new Mana());
}
for (Mana mana: this) { for (Mana mana: this) {
mana.add(addMana); mana.add(addMana);
} }
} }
public void addMana(ManaOptions options) { public void addMana(ManaOptions options) {
if (isEmpty()) if (isEmpty()) {
this.add(new Mana()); this.add(new Mana());
}
if (!options.isEmpty()) { if (!options.isEmpty()) {
if (options.size() == 1) { if (options.size() == 1) {
//if there is only one mana option available add it to all the existing options //if there is only one mana option available add it to all the existing options
@ -157,8 +160,9 @@ public class ManaOptions extends ArrayList<Mana> {
} }
public void addMana(Mana cost, Mana addMana) { public void addMana(Mana cost, Mana addMana) {
if (isEmpty()) if (isEmpty()) {
this.add(new Mana()); this.add(new Mana());
}
for (Mana mana: this) { for (Mana mana: this) {
if (mana.contains(cost)) { if (mana.contains(cost)) {
mana.subtract(cost); mana.subtract(cost);

View file

@ -29,6 +29,8 @@ package mage.abilities.mana.builder;
import mage.ConditionalMana; import mage.ConditionalMana;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability;
import mage.game.Game;
/** /**
* @author noxx * @author noxx
@ -37,7 +39,7 @@ public abstract class ConditionalManaBuilder implements Builder<ConditionalMana>
protected Mana mana; protected Mana mana;
public ConditionalManaBuilder setMana(Mana mana) { public ConditionalManaBuilder setMana(Mana mana, Ability source, Game game) {
this.mana = mana; this.mana = mana;
return this; return this;
} }