Conditional mana - fixed that some mana cant be used for paying “counter unless” cost and other things (#11447)

* Add tests for conditional mana usage with soft counterspells

* Fix "to cast" conditions on common ManaCondition classes

* Add fix to all remaining ManaCondition classes

* SimpleActivatedAbilityConditionalMana is tested to pay for a soft counterspell activated ability

* Remove now-unused imports
This commit is contained in:
ssk97 2023-11-22 13:37:45 -08:00 committed by GitHub
parent 2cc9957753
commit e43e918c67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 81 additions and 55 deletions

View file

@ -5,19 +5,17 @@ import mage.MageInt;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.mana.ConditionalColorlessManaAbility;
import mage.abilities.mana.builder.ConditionalManaBuilder;
import mage.abilities.mana.conditional.ManaCondition;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.game.Game;
import mage.game.command.Commander;
import mage.game.stack.StackObject;
import java.util.UUID;
@ -75,7 +73,7 @@ class AutomatedArtificerManaCondition extends ManaCondition {
@Override
public boolean apply(Game game, Ability source) {
if (source == null) {
if (source == null || source.isActivated()) {
return false;
}
switch (source.getAbilityType()) {
@ -83,15 +81,10 @@ class AutomatedArtificerManaCondition extends ManaCondition {
case ACTIVATED:
return true;
case SPELL:
MageObject object = source.getSourceObject(game);
if (!(object instanceof StackObject) && !game.inCheckPlayableState()) {
return false;
if (source instanceof SpellAbility) {
MageObject object = game.getObject(source);
return object != null && object.isArtifact(game);
}
if (object instanceof Commander) {
Card card = ((Commander) object).getSourceObject();
return card != null && card.isArtifact(game);
}
return object.isArtifact(game);
}
return false;
}

View file

@ -94,7 +94,7 @@ class CrypticTrilobiteManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source != null) {
if (source != null && !source.isActivated()) {
// ex: SimpleManaAbility is an ACTIVATED ability, but it is categorized as a MANA ability
return source.getAbilityType() == AbilityType.MANA
|| source.getAbilityType() == AbilityType.ACTIVATED;

View file

@ -79,13 +79,13 @@ class CultivatorDroneManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source, UUID originalId, Cost costToPay) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if (object != null && object.getColor(game).isColorless()) {
return true;
}
}
if (source instanceof ActivatedAbility) {
if (source instanceof ActivatedAbility && !source.isActivated()) {
Permanent object = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (object != null && object.getColor(game).isColorless()) {
return true;

View file

@ -85,7 +85,7 @@ class DelightedHalflingManaCondition extends ManaCondition {
@Override
public boolean apply(Game game, Ability source) {
// check: ... to cast a spell
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
// check: ... that is legendary
if (object != null && object.isLegendary(game)) {

View file

@ -75,7 +75,7 @@ class GreatHallOfTheCitadelManaCondition extends ManaCondition implements Condit
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.isLegendary(game);
}

View file

@ -74,7 +74,7 @@ class KarfellHarbingerManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.isInstantOrSorcery(game);
}

View file

@ -122,7 +122,7 @@ class KlauthUnrivaledAncientManaCondition extends ManaCondition implements Condi
@Override
public boolean apply(Game game, Ability source) {
return source instanceof SpellAbility;
return source instanceof SpellAbility && !source.isActivated();
}
@Override

View file

@ -130,7 +130,7 @@ class MeetingOfTheFiveManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (!(source instanceof SpellAbility)) {
if (!(source instanceof SpellAbility) || source.isActivated()) {
return false;
}
MageObject object = game.getObject(source);

View file

@ -97,7 +97,7 @@ class NarsetOfTheAncientWayManaCondition extends ManaCondition implements Condit
@Override
public boolean apply(Game game, Ability source) {
if (!(source instanceof SpellAbility)) {
if (!(source instanceof SpellAbility) || source.isActivated()) {
return false;
}
MageObject object = game.getObject(source);

View file

@ -166,7 +166,7 @@ class NikoDefiesDestinyManaCondition extends ManaCondition implements Condition
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.getAbilities().containsClass(ForetellAbility.class);
}

View file

@ -73,7 +73,7 @@ class OmenHawkerManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source != null) {
if (source != null && !source.isActivated()) {
return source.getAbilityType() == AbilityType.MANA
|| source.getAbilityType() == AbilityType.ACTIVATED;
}

View file

@ -84,7 +84,7 @@ class OpenTheOmenpathsCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (!(source instanceof SpellAbility)) {
if (!(source instanceof SpellAbility) || source.isActivated()) {
return false;
}
MageObject object = game.getObject(source);

View file

@ -107,7 +107,7 @@ class PlazaOfHeroesManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if (object != null && object.isLegendary(game)) {
return true;

View file

@ -80,7 +80,7 @@ class ArtifactAbilityManaCondition extends ManaCondition implements Condition {
return false;
}
MageObject object = game.getObject(source);
return object != null && object.isArtifact(game);
return object != null && object.isArtifact(game) && !source.isActivated();
}
@Override

View file

@ -115,7 +115,7 @@ class SorcererClassManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.isInstantOrSorcery(game);
}

View file

@ -132,7 +132,7 @@ class TazriStalwartSurvivorManaEffect extends ManaEffect {
return false;
}
MageObject object = game.getObject(source);
return object != null && object.isCreature(game);
return object != null && object.isCreature(game) && !source.isActivated();
}
@Override

View file

@ -108,7 +108,7 @@ class TheEnigmaJewelManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source != null) {
if (source != null && !source.isActivated()) {
return source.getAbilityType() == AbilityType.MANA
|| source.getAbilityType() == AbilityType.ACTIVATED;
}

View file

@ -3,6 +3,7 @@ package mage.cards.t;
import mage.ConditionalMana;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.costs.Cost;
@ -101,6 +102,6 @@ class ThranTurbineManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source, UUID originalId, Cost costToPay) {
return !(source instanceof Spell);
return !(source instanceof SpellAbility && !source.isActivated());
}
}

View file

@ -94,7 +94,7 @@ class TitansNestManaCondition extends ManaCondition {
@Override
public boolean apply(Game game, Ability source, UUID originalId, Cost costToPay) {
if (!(source instanceof SpellAbility)) {
if (!(source instanceof SpellAbility) || source.isActivated()) {
return false;
}
MageObject object = game.getObject(source);

View file

@ -75,10 +75,10 @@ class UnblinkingObserverManaCondition extends ManaCondition implements Condition
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof DisturbAbility) {
if (source instanceof DisturbAbility && !source.isActivated()) {
return true;
}
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.isInstantOrSorcery(game);
}

View file

@ -76,7 +76,7 @@ class LegendaryCastManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if (object != null && object.isLegendary(game)) {
return true;

View file

@ -107,7 +107,7 @@ class VoldarenEstateManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.hasSubtype(SubType.VAMPIRE, game);
}

View file

@ -75,12 +75,12 @@ class VolsheTideturnerCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (!(source instanceof SpellAbility) && !source.isActivated()) {
return false;
}
if (KickedCondition.ONCE.apply(game, source)) {
return true;
}
if (!(source instanceof SpellAbility)) {
return false;
}
MageObject object = game.getObject(source);
return object != null && object.isInstantOrSorcery(game);
}

View file

@ -389,6 +389,45 @@ public class ConditionalManaTest extends CardTestPlayerBase {
assertManaOptions("{C}{C}{C}{C}{C}{C}{C}{R}[{XCostManaCondition}{TitansNestManaCondition}]", manaOptions);
}
@Test
public void testConditionalManaSoftCounter() {
addCard(Zone.HAND, playerA, "Fallaji Excavation", 1);
addCard(Zone.HAND, playerA, "Gigantosaurus", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
addCard(Zone.HAND, playerB, "Mana Leak");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fallaji Excavation");
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Gigantosaurus");
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Mana Leak", "Gigantosaurus");
setChoice(playerA, true);
setStrictChooseMode(true);
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertPermanentCount(playerA, "Gigantosaurus", 1);
assertTappedCount("Powerstone Token", true, 3);
}
@Test
public void testConditionalManaCantSoftCounter() {
addCard(Zone.BATTLEFIELD, playerA, "Jaya Ballard");
addCard(Zone.HAND, playerA, "Gigantosaurus", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 5);
addCard(Zone.HAND, playerB, "Mana Leak");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+1: Add");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Gigantosaurus");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Mana Leak", "Gigantosaurus");
setChoice(playerA, true);
setStrictChooseMode(true);
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertPermanentCount(playerA, "Gigantosaurus", 0);
}
@Test
public void testConditionalManaDeduplication() {
ManaOptions manaOptions = new ManaOptions();

View file

@ -42,7 +42,7 @@ class InstantOrSorceryCastManaCondition extends ManaCondition implements Conditi
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
return object != null && object.isInstantOrSorcery(game);
}

View file

@ -26,7 +26,7 @@ public class SimpleActivatedAbilityManaBuilder extends ConditionalManaBuilder {
@Override
public String getRule() {
return "Spend this mana only to activate simple abilities";
return "Spend this mana only to activate or pay for simple abilities";
}
}
@ -34,7 +34,7 @@ class SimpleActivatedAbilityConditionalMana extends ConditionalMana {
public SimpleActivatedAbilityConditionalMana(Mana mana) {
super(mana);
staticText = "Spend this mana only to activate simple abilities";
staticText = "Spend this mana only to activate or pay for simple abilities";
addCondition(new SimpleActivatedAbilityManaCondition());
}
}

View file

@ -74,7 +74,7 @@ class SpellCastManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if ((object instanceof StackObject)) {
return filter.match((StackObject) object, source.getControllerId(), source, game);

View file

@ -16,11 +16,9 @@ public class CreatureCastManaCondition extends ManaCondition implements Conditio
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if (object != null && object.isCreature(game)) {
return true;
}
return object != null && object.isCreature(game);
}
return false;
}

View file

@ -17,11 +17,9 @@ public class PlaneswalkerCastManaCondition extends ManaCondition implements Cond
@Override
public boolean apply(Game game, Ability source) {
if (source instanceof SpellAbility) {
if (source instanceof SpellAbility && !source.isActivated()) {
MageObject object = game.getObject(source);
if (object != null && object.isPlaneswalker(game)) {
return true;
}
return object != null && object.isPlaneswalker(game);
}
return false;
}

View file

@ -73,14 +73,11 @@ class PowerstoneTokenManaCondition extends ManaCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
if (!(source instanceof SpellAbility)) {
if (!(source instanceof SpellAbility) || source.isActivated()) {
return true;
}
MageObject object = game.getObject(source);
if (object != null && object.isArtifact(game)) {
return true;
}
return false;
return object != null && object.isArtifact(game);
}
@Override