* Jeweled Lotus - fixed that mana can't be used to cast commanders without normal mana (#7272);

This commit is contained in:
Oleg Agafonov 2020-12-22 23:22:41 +04:00
parent 736901efcf
commit 347a3b1e1a
5 changed files with 104 additions and 9 deletions

View file

@ -0,0 +1,61 @@
package org.mage.test.cards.single.cmr;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestCommanderDuelBase;
/**
* @author JayDi85
*/
public class JeweledLotusTest extends CardTestCommanderDuelBase {
@Test
public void test_CantUseManaForNormalSpells() {
// {T}, Sacrifice Jeweled Lotus: Add three mana of any one color. Spend this mana only to cast your commander.
addCard(Zone.BATTLEFIELD, playerA, "Jeweled Lotus", 1);
//
addCard(Zone.HAND, playerA, "Balduvian Bears", 1);
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Balduvian Bears", false);
// generate mana
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Sacrifice");
setChoice(playerA, "Green");
checkManaPool("new mana", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "G", 3);
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Balduvian Bears", false);
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
}
@Test
public void test_CanUseManaForCommander() {
// {T}, Sacrifice Jeweled Lotus: Add three mana of any one color. Spend this mana only to cast your commander.
addCard(Zone.BATTLEFIELD, playerA, "Jeweled Lotus", 1);
//
addCard(Zone.COMMAND, playerA, "Balduvian Bears", 1);
// Jeweled Lotus is mana ability -- game will use that mana for playable too, so must be playable here
checkPlayableAbility("before", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Balduvian Bears", true);
// generate mana
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Sacrifice");
setChoice(playerA, "Green");
checkManaPool("new mana", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "G", 3);
checkPlayableAbility("after", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cast Balduvian Bears", true);
// play commander
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Balduvian Bears");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Balduvian Bears", 1);
}
}

View file

@ -16,6 +16,7 @@ import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.cards.Card;
import mage.filter.FilterSpell;
import mage.game.Game;
import mage.game.command.Commander;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
@ -65,13 +66,20 @@ class SpellCastManaCondition extends ManaCondition implements Condition {
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
MageObject object = game.getObject(source.getSourceId());
if (game.inCheckPlayableState() && object instanceof Card) {
Spell spell = new Spell((Card) object, (SpellAbility) source, source.getControllerId(), game.getState().getZone(source.getSourceId()), game);
return filter.match(spell, source.getSourceId(), source.getControllerId(), game);
}
if ((object instanceof StackObject)) {
return filter.match((StackObject) object, source.getSourceId(), source.getControllerId(), game);
}
// checking mana without real cast
if (game.inCheckPlayableState()) {
Spell spell = null;
if (object instanceof Card) {
spell = new Spell((Card) object, (SpellAbility) source, source.getControllerId(), game.getState().getZone(source.getSourceId()), game);
} else if (object instanceof Commander) {
spell = new Spell(((Commander) object).getSourceObject(), (SpellAbility) source, source.getControllerId(), game.getState().getZone(source.getSourceId()), game);
}
return spell != null && filter.match(spell, source.getSourceId(), source.getControllerId(), game);
}
}
return false;
}

View file

@ -13,8 +13,8 @@ public enum CommanderPredicate implements Predicate<MageObject> {
@Override
public boolean apply(MageObject input, Game game) {
Player owner = game.getPlayer(game.getOwnerId(input.getId()));
return owner != null && game.getCommandersIds(owner).contains(input.getId());
Player owner = game.getPlayer(game.getOwnerId(input));
return owner != null && game.isCommanderObject(owner, input);
}
@Override

View file

@ -19,6 +19,7 @@ import mage.choices.Choice;
import mage.constants.*;
import mage.counters.Counters;
import mage.game.combat.Combat;
import mage.game.command.CommandObject;
import mage.game.command.Commander;
import mage.game.command.Emblem;
import mage.game.command.Plane;
@ -519,6 +520,27 @@ public interface Game extends MageItem, Serializable {
.collect(Collectors.toSet());
}
/**
* Finds is it a commander card/object (use it in conditional and other things)
*
* @param player
* @param object
* @return
*/
default boolean isCommanderObject(Player player, MageObject object) {
UUID idToCheck = null;
if (object instanceof Spell) {
idToCheck = ((Spell) object).getCard().getId();
}
if (object instanceof CommandObject) {
idToCheck = object.getId();
}
if (object instanceof Card) {
idToCheck = ((Card) object).getMainCard().getId();
}
return idToCheck != null && this.getCommandersIds(player).contains(idToCheck);
}
void setGameStopped(boolean gameStopped);
boolean isGameStopped();

View file

@ -436,19 +436,23 @@ public abstract class GameImpl implements Game, Serializable {
@Override
public UUID getOwnerId(MageObject object) {
if (object instanceof Card) {
return ((Card) object).getOwnerId();
}
if (object instanceof Spell) {
return ((Spell) object).getOwnerId();
}
if (object instanceof StackObject) {
// maybe this is not correct in all cases?
return ((StackObject) object).getControllerId();
}
if (object instanceof CommandObject) {
return ((CommandObject) object).getControllerId();
}
if (object instanceof Card) {
return ((Card) object).getOwnerId();
}
return null;
}