mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
* Cavern of Souls - Fixed that conditional mana in the mana pool remembers correctly for which creature subtrype its usable.
This commit is contained in:
parent
35d3c14dc6
commit
1f196f0bc7
11 changed files with 133 additions and 36 deletions
|
|
@ -119,8 +119,8 @@ class CavernOfSoulsEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
game.informPlayers(permanent.getName() + ": " + player.getName() + " has chosen " + typeChoice.getChoice());
|
||||
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice().toString());
|
||||
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice().toString()));
|
||||
game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice());
|
||||
permanent.addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -133,10 +133,21 @@ class CavernOfSoulsEffect extends OneShotEffect {
|
|||
|
||||
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
|
||||
public ConditionalMana build(Object... options) {
|
||||
this.mana.setFlag(true); // indicates that the mana is from second ability
|
||||
return new CavernOfSoulsConditionalMana(this.mana);
|
||||
return new CavernOfSoulsConditionalMana(this.mana, creatuerType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -147,28 +158,31 @@ class CavernOfSoulsManaBuilder extends ConditionalManaBuilder {
|
|||
|
||||
class CavernOfSoulsConditionalMana extends ConditionalMana {
|
||||
|
||||
public CavernOfSoulsConditionalMana(Mana mana) {
|
||||
public CavernOfSoulsConditionalMana(Mana mana, String creatureType) {
|
||||
super(mana);
|
||||
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 {
|
||||
|
||||
String creatureType;
|
||||
|
||||
CavernOfSoulsManaCondition(String creatureType) {
|
||||
this.creatureType = creatureType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source, UUID manaProducer) {
|
||||
// check: ... to cast a creature spell
|
||||
if (super.apply(game, source)) {
|
||||
// check: ... of the chosen type
|
||||
Object value = game.getState().getValue(manaProducer + "_type");
|
||||
if (value != null && value instanceof String) {
|
||||
MageObject object = game.getObject(source.getSourceId());
|
||||
if (object.hasSubtype((String) value)) {
|
||||
if (creatureType != null && object.hasSubtype(creatureType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,19 +117,19 @@ class FoodChainManaEffect extends ManaEffect {
|
|||
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
|
||||
Mana mana = null;
|
||||
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()) {
|
||||
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()) {
|
||||
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()) {
|
||||
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()) {
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -163,15 +163,15 @@ class VedalkenEngineerEffect extends ManaEffect {
|
|||
ChoiceColor choice = (ChoiceColor) source.getChoices().get(0);
|
||||
Mana mana = null;
|
||||
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()) {
|
||||
mana = manaBuilder.setMana(Mana.BlueMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.BlueMana(1), source, game).build();
|
||||
} 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()) {
|
||||
mana = manaBuilder.setMana(Mana.GreenMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.GreenMana(1), source, game).build();
|
||||
} else if (choice.getColor().isWhite()) {
|
||||
mana = manaBuilder.setMana(Mana.WhiteMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.WhiteMana(1), source, game).build();
|
||||
}
|
||||
if (mana != null) {
|
||||
player.getManaPool().addMana(mana, game, source);
|
||||
|
|
|
|||
|
|
@ -136,4 +136,54 @@ public class CavernOfSoulsTest extends CardTestPlayerBase {
|
|||
assertGraveyardCount(playerA, "Azure Drake", 1);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
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) {
|
||||
for (PlayerAction action: actions) {
|
||||
if (action.getTurnNum() == game.getTurnNum() && action.getStep() == game.getStep().getType()) {
|
||||
|
||||
if (action.getAction().startsWith("activate:")) {
|
||||
String command = action.getAction();
|
||||
command = command.substring(command.indexOf("activate:") + 9);
|
||||
|
|
@ -135,7 +138,26 @@ public class TestPlayer extends ComputerPlayer {
|
|||
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:")) {
|
||||
String command = action.getAction();
|
||||
command = command.substring(command.indexOf("addCounters:") + 12);
|
||||
|
|
|
|||
|
|
@ -734,6 +734,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
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) {
|
||||
player.addAction(turnNum, step, "activate:" + ability);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import mage.constants.CardType;
|
|||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.Rarity;
|
||||
import mage.interfaces.rate.RateCallback;
|
||||
import mage.sets.guru.Island;
|
||||
import mage.utils.DeckBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
|
@ -16,6 +15,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.sets.unhinged.Island;
|
||||
|
||||
|
||||
/**
|
||||
* @author dustinconrad
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class AddConditionalColorlessManaEffect extends ManaEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
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 false;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ import mage.players.Player;
|
|||
*/
|
||||
public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
|
||||
|
||||
private int amount;
|
||||
private ConditionalManaBuilder manaBuilder;
|
||||
private final int amount;
|
||||
private final ConditionalManaBuilder manaBuilder;
|
||||
|
||||
public AddConditionalManaOfAnyColorEffect(int amount, ConditionalManaBuilder manaBuilder) {
|
||||
super();
|
||||
|
|
@ -73,15 +73,15 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
|
|||
|
||||
Mana mana = null;
|
||||
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()) {
|
||||
mana = manaBuilder.setMana(Mana.BlueMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.BlueMana(1), source, game).build();
|
||||
} 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()) {
|
||||
mana = manaBuilder.setMana(Mana.GreenMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.GreenMana(1), source, game).build();
|
||||
} else if (choice.getColor().isWhite()) {
|
||||
mana = manaBuilder.setMana(Mana.WhiteMana(1)).build();
|
||||
mana = manaBuilder.setMana(Mana.WhiteMana(1), source, game).build();
|
||||
}
|
||||
|
||||
if (mana != null) {
|
||||
|
|
|
|||
|
|
@ -78,8 +78,9 @@ public class ManaOptions extends ArrayList<Mana> {
|
|||
}
|
||||
|
||||
public void addManaWithCost(List<ManaAbility> abilities, Game game) {
|
||||
if (isEmpty())
|
||||
if (isEmpty()) {
|
||||
this.add(new Mana());
|
||||
}
|
||||
if (!abilities.isEmpty()) {
|
||||
if (abilities.size() == 1) {
|
||||
//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) {
|
||||
if (isEmpty())
|
||||
if (isEmpty()) {
|
||||
this.add(new Mana());
|
||||
}
|
||||
for (Mana mana: this) {
|
||||
mana.add(addMana);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMana(ManaOptions options) {
|
||||
if (isEmpty())
|
||||
if (isEmpty()) {
|
||||
this.add(new Mana());
|
||||
}
|
||||
if (!options.isEmpty()) {
|
||||
if (options.size() == 1) {
|
||||
//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) {
|
||||
if (isEmpty())
|
||||
if (isEmpty()) {
|
||||
this.add(new Mana());
|
||||
}
|
||||
for (Mana mana: this) {
|
||||
if (mana.contains(cost)) {
|
||||
mana.subtract(cost);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ package mage.abilities.mana.builder;
|
|||
|
||||
import mage.ConditionalMana;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
|
|
@ -37,7 +39,7 @@ public abstract class ConditionalManaBuilder implements Builder<ConditionalMana>
|
|||
|
||||
protected Mana mana;
|
||||
|
||||
public ConditionalManaBuilder setMana(Mana mana) {
|
||||
public ConditionalManaBuilder setMana(Mana mana, Ability source, Game game) {
|
||||
this.mana = mana;
|
||||
return this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue