* Fixed spell cost reduction for bestow not working during calculation of castable spells (#6698).

This commit is contained in:
LevelX2 2020-07-24 16:04:52 +02:00
parent a90dbd8533
commit 98ebcc07ca
19 changed files with 132 additions and 94 deletions

View file

@ -1,5 +1,6 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.Ability;
@ -19,8 +20,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author LevelX2
*/
@ -82,9 +81,12 @@ class AnimarCostReductionEffect extends CostModificationEffectImpl {
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
if (abilityToModify.isControlledBy(source.getControllerId())) {
Card card = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (card != null) {
return card.isCreature();
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return spellCard.isCreature();
}
}
}

View file

@ -1,4 +1,3 @@
package mage.cards.d;
import java.util.UUID;
@ -11,12 +10,12 @@ import mage.abilities.effects.common.SacrificeSourceUnlessPaysEffect;
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.AbilityType;
import mage.constants.CardType;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
@ -54,9 +53,10 @@ public final class Drought extends CardImpl {
class DroughtAdditionalCostEffect extends CostModificationEffectImpl {
private boolean appliesToSpells;
private final boolean appliesToSpells;
private static final FilterControlledPermanent filter = new FilterControlledPermanent("a Swamp");
static{
static {
filter.add(SubType.SWAMP.getPredicate());
}

View file

@ -1,5 +1,6 @@
package mage.cards.e;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.SagaAbility;
@ -23,8 +24,6 @@ import mage.target.TargetPermanent;
import mage.target.common.TargetCardInYourGraveyard;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author TheElk801
*/
@ -99,12 +98,17 @@ class ElspethConquersDeathCostEffect extends CostModificationEffectImpl {
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (!(abilityToModify instanceof SpellAbility) ||
!game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
return false;
if ((abilityToModify instanceof SpellAbility)
&& game.getOpponents(source.getControllerId()).contains(abilityToModify.getControllerId())) {
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return !spellCard.isCreature();
}
}
Card card = game.getCard(abilityToModify.getSourceId());
return card != null && !card.isCreature();
return false;
}
@Override
@ -117,8 +121,8 @@ class ElspethConquersDeathReturnEffect extends OneShotEffect {
ElspethConquersDeathReturnEffect() {
super(Outcome.Benefit);
staticText = "Return target creature or planeswalker card from your graveyard to the battlefield. " +
"Put a +1/+1 counter or a loyalty counter on it";
staticText = "Return target creature or planeswalker card from your graveyard to the battlefield. "
+ "Put a +1/+1 counter or a loyalty counter on it";
}
private ElspethConquersDeathReturnEffect(final ElspethConquersDeathReturnEffect effect) {
@ -149,4 +153,5 @@ class ElspethConquersDeathReturnEffect extends OneShotEffect {
permanent.addCounters(counter, source, game);
return true;
}
}
}

View file

@ -1,4 +1,3 @@
package mage.cards.h;
import java.util.UUID;
@ -25,7 +24,7 @@ import mage.util.CardUtil;
public final class HeraldOfWar extends CardImpl {
public HeraldOfWar(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{W}");
this.subtype.add(SubType.ANGEL);
this.power = new MageInt(3);
@ -54,7 +53,7 @@ class HeraldOfWarCostReductionEffect extends CostModificationEffectImpl {
HeraldOfWarCostReductionEffect() {
super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST);
staticText = "Angel spells and Human spells you cast cost {1} less to cast for each +1/+1 counter on Herald of War";
staticText = "Angel spells and Human spells you cast cost {1} less to cast for each +1/+1 counter on {this}";
}
HeraldOfWarCostReductionEffect(HeraldOfWarCostReductionEffect effect) {

View file

@ -1,6 +1,5 @@
package mage.cards.h;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.SimpleStaticAbility;
@ -13,6 +12,7 @@ import mage.game.Game;
import mage.util.CardUtil;
import java.util.UUID;
import mage.cards.Card;
/**
* @author Pete Rossi
@ -58,9 +58,12 @@ class HumOfTheRadixCostIncreaseEffect extends CostModificationEffectImpl {
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
MageObject sourceObject = abilityToModify.getSourceObject(game);
if (sourceObject != null && sourceObject.isArtifact()) {
return true;
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return !spellCard.isArtifact();
}
}
return false;

View file

@ -15,10 +15,10 @@ import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.util.CardUtil;
import java.util.UUID;
import mage.cards.Card;
/**
* @author LevelX2
@ -115,9 +115,12 @@ class RakdosLordOfRiotsCostReductionEffect extends CostModificationEffectImpl {
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
if (abilityToModify.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return spell.isCreature();
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return spellCard.isCreature();
}
}
}

View file

@ -1,5 +1,7 @@
package mage.cards.s;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -18,9 +20,6 @@ import mage.players.Player;
import mage.target.TargetCard;
import mage.util.CardUtil;
import java.util.List;
import java.util.UUID;
/**
* @author nantuko
*/
@ -107,15 +106,19 @@ class SemblanceAnvilCostReductionEffect extends CostModificationEffectImpl {
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Card sourceCard = game.getCard(abilityToModify.getSourceId());
if (sourceCard != null && sourceCard.isOwnedBy(source.getControllerId())) {
if (abilityToModify instanceof SpellAbility
&& abilityToModify.isControlledBy(source.getControllerId())) {
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
List<UUID> imprinted = permanent.getImprinted();
if (imprinted != null && !imprinted.isEmpty()) {
Card imprintedCard = game.getCard(imprinted.get(0));
return imprintedCard != null && imprintedCard.shareTypes(sourceCard);
return imprintedCard != null && imprintedCard.shareTypes(spellCard);
}
}
}

View file

@ -191,7 +191,6 @@ public class BestowTest extends CardTestPlayerBase {
addTarget(playerB, playerA); // Away
addTarget(playerA, "Nyxborn Rollicker");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();
@ -463,4 +462,26 @@ public class BestowTest extends CardTestPlayerBase {
Assert.assertFalse("The unattached Nighthowler may not have the aura subtype.", nighthowler.getSubtype(currentGame).contains(SubType.AURA));
}
@Test
public void testCastBestowWithCostReduction() {
// Enchantment Creature Horror
// Bestow {5}{G} (If you cast this card for its bestow cost, it's an Aura spell with enchant creature. It becomes a creature again if it's not attached to a creature.)
// Trample
// Enchanted creature gets +3/+3 and has trample.
addCard(Zone.HAND, playerA, "Nylea's Emissary"); // Enchantment Creature
addCard(Zone.BATTLEFIELD, playerA, "Forest", 4);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); // {1}{W} 2/2 creature
// Aura spells you cast cost {1} less to cast.
addCard(Zone.BATTLEFIELD, playerA, "Transcendent Envoy", 2);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Nylea's Emissary using bestow", "Silvercoat Lion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Nylea's Emissary", 1);
assertPowerToughness(playerA, "Silvercoat Lion", 5, 5);
assertType("Nylea's Emissary", CardType.CREATURE, false);
assertType("Nylea's Emissary", CardType.ENCHANTMENT, SubType.AURA);
}
}

View file

@ -18,7 +18,7 @@ import mage.util.CardUtil;
*/
public class AbilitiesCostReductionControllerEffect extends CostModificationEffectImpl {
private Class activatedAbility;
private final Class activatedAbility;
public AbilitiesCostReductionControllerEffect(Class activatedAbility, String activatedAbilityName) {
super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST);

View file

@ -10,8 +10,6 @@ import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
public class CostModificationSourceEffect extends CostModificationEffectImpl {
private final Class<? extends Ability> abilityType;

View file

@ -18,7 +18,7 @@ import mage.util.CardUtil;
public class SpellCostReductionForEachSourceEffect extends CostModificationEffectImpl {
private final DynamicValue eachAmount;
private ManaCosts<ManaCost> reduceManaCosts;
private final ManaCosts<ManaCost> reduceManaCosts;
private final int reduceGenericMana;
public SpellCostReductionForEachSourceEffect(int reduceGenericMana, DynamicValue eachAmount) {
@ -50,7 +50,6 @@ public class SpellCostReductionForEachSourceEffect extends CostModificationEffec
this.staticText = sb.toString();
}
protected SpellCostReductionForEachSourceEffect(final SpellCostReductionForEachSourceEffect effect) {
super(effect);
this.eachAmount = effect.eachAmount;

View file

@ -23,7 +23,7 @@ public class SpellsCostIncreasingAllEffect extends CostModificationEffectImpl {
private final FilterCard filter;
private final TargetController targetController;
private final int increaseGenericCost;
private ManaCosts<ManaCost> increaseManaCosts;
private final ManaCosts<ManaCost> increaseManaCosts;
public SpellsCostIncreasingAllEffect(int increaseGenericCost, FilterCard filter, TargetController targetController) {
super(Duration.WhileOnBattlefield, Outcome.Detriment, CostModificationType.INCREASE_COST);

View file

@ -1,5 +1,7 @@
package mage.abilities.effects.common.cost;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.constants.CostModificationType;
@ -12,9 +14,6 @@ import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Set;
import java.util.UUID;
/**
* @author JayDi85
*/
@ -23,7 +22,7 @@ public class SpellsCostModificationThatTargetSourceEffect extends CostModificati
private final FilterCard spellFilter;
private final int modificationAmount;
private String targetName = "{this}";
private TargetController targetController;
private final TargetController targetController;
public SpellsCostModificationThatTargetSourceEffect(int modificationAmount, FilterCard spellFilter, TargetController targetController) {
super(Duration.WhileOnBattlefield, Outcome.Neutral, modificationAmount < 0 ? CostModificationType.REDUCE_COST : CostModificationType.INCREASE_COST);

View file

@ -1,5 +1,8 @@
package mage.abilities.effects.common.cost;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import mage.Mana;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
@ -8,16 +11,12 @@ import mage.choices.ChoiceImpl;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SpellAbilityCastMode;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
/**
* @author LevelX2
*/
@ -123,15 +122,12 @@ public class SpellsCostReductionAllEffect extends CostModificationEffectImpl {
return false;
}
if (abilityToModify instanceof SpellAbility) {
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
// real cast with put on stack
return this.filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else {
// get playable and other staff without put on stack
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return this.filter.match(spellCard, game) && selectedByRuntimeData(spellCard, source, game);
}
}
return false;

View file

@ -1,5 +1,7 @@
package mage.abilities.effects.common.cost;
import java.util.LinkedHashSet;
import java.util.Set;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
@ -11,15 +13,12 @@ import mage.choices.ChoiceImpl;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SpellAbilityCastMode;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author North
*/
@ -114,15 +113,12 @@ public class SpellsCostReductionControllerEffect extends CostModificationEffectI
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
if (abilityToModify.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
// real cast with put on stack
return this.filter.match(spell, source.getSourceId(), source.getControllerId(), game);
} else {
// get playable and other staff without put on stack
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && this.filter.match(sourceCard, source.getSourceId(), source.getControllerId(), game);
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);;
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return this.filter.match(spellCard, source.getSourceId(), source.getControllerId(), game);
}
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.keyword;
import mage.MageObject;
@ -138,6 +137,14 @@ public class BestowAbility extends SpellAbility {
}
}
static public void becomeAura(Card card) {
if (card != null) {
card.getSubtype(null).add(SubType.AURA);
card.getCardType().remove(CardType.CREATURE);
card.getCardType().add(CardType.ENCHANTMENT);
}
}
}
class BestowEntersBattlefieldEffect extends ReplacementEffectImpl {

View file

@ -1,6 +1,9 @@
package mage.constants;
import mage.abilities.keyword.BestowAbility;
import mage.cards.Card;
import mage.game.Game;
/**
*
* @author LevelX2
@ -21,4 +24,12 @@ public enum SpellAbilityCastMode {
public String toString() {
return text;
}
public Card getTypeModifiedCardObjectCopy(Card card, Game game) {
Card cardCopy = card.copy();
if (this.equals(BESTOW)) {
BestowAbility.becomeAura(cardCopy);
}
return cardCopy;
}
}

View file

@ -1,5 +1,7 @@
package mage.game.command.planes;
import java.util.ArrayList;
import java.util.List;
import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Ability;
@ -29,9 +31,6 @@ import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
import mage.watchers.common.PlanarRollWatcher;
import java.util.ArrayList;
import java.util.List;
/**
* @author spjspj
*/
@ -52,9 +51,9 @@ public class FeedingGroundsPlane extends Plane {
Effect chaosEffect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(), TargetConvertedManaCost.instance);
Target chaosTarget = new TargetCreaturePermanent(1, 1, filter, false);
List<Effect> chaosEffects = new ArrayList<Effect>();
List<Effect> chaosEffects = new ArrayList<>();
chaosEffects.add(chaosEffect);
List<Target> chaosTargets = new ArrayList<Target>();
List<Target> chaosTargets = new ArrayList<>();
chaosTargets.add(chaosTarget);
ActivateIfConditionActivatedAbility chaosAbility = new ActivateIfConditionActivatedAbility(Zone.COMMAND, new RollPlanarDieEffect(chaosEffects, chaosTargets), new GenericManaCost(0), MainPhaseStackEmptyCondition.instance);

View file

@ -17,7 +17,6 @@ import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.game.command.Plane;
import mage.game.stack.Spell;
import mage.target.Target;
import mage.util.CardUtil;
import mage.watchers.common.PlanarRollWatcher;
@ -42,9 +41,9 @@ public class TurriIslandPlane extends Plane {
Effect chaosEffect = new RevealLibraryPutIntoHandEffect(3, new FilterCreatureCard("creature cards"), Zone.GRAVEYARD);
Target chaosTarget = null;
List<Effect> chaosEffects = new ArrayList<Effect>();
List<Effect> chaosEffects = new ArrayList<>();
chaosEffects.add(chaosEffect);
List<Target> chaosTargets = new ArrayList<Target>();
List<Target> chaosTargets = new ArrayList<>();
chaosTargets.add(chaosTarget);
ActivateIfConditionActivatedAbility chaosAbility = new ActivateIfConditionActivatedAbility(Zone.COMMAND, new RollPlanarDieEffect(chaosEffects, chaosTargets), new GenericManaCost(0), MainPhaseStackEmptyCondition.instance);
@ -110,14 +109,12 @@ class TurriIslandEffect extends CostModificationEffectImpl {
if (!cPlane.getPlaneType().equals(Planes.PLANE_TURRI_ISLAND)) {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else {
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return sourceCard != null && filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
Card spellCard = ((SpellAbility) abilityToModify).getCharacteristics(game);
if (spellCard != null) {
if (((SpellAbility) abilityToModify).getSpellAbilityCastMode() != SpellAbilityCastMode.NORMAL) {
spellCard = ((SpellAbility) abilityToModify).getSpellAbilityCastMode().getTypeModifiedCardObjectCopy(spellCard, game);
}
return filter.match(spellCard, game) && selectedByRuntimeData(spellCard, source, game);
}
}
return false;