[CMR] fixed multiple copies of Imoti, Celebrant of Bounty only giving cascade once

This commit is contained in:
Evan Kranzler 2021-03-01 08:45:42 -05:00
parent 852aa562d2
commit f52753ad61

View file

@ -1,6 +1,7 @@
package mage.abilities.effects; package mage.abilities.effects;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.MageSingleton;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.*; import mage.constants.*;
import mage.filter.FilterObject; import mage.filter.FilterObject;
@ -21,7 +22,7 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
staticText = filter.getMessage() + " have " + ability.getRule(); staticText = filter.getMessage() + " have " + ability.getRule();
} }
public GainAbilitySpellsEffect(final GainAbilitySpellsEffect effect) { private GainAbilitySpellsEffect(final GainAbilitySpellsEffect effect) {
super(effect); super(effect);
this.ability = effect.ability; this.ability = effect.ability;
this.filter = effect.filter; this.filter = effect.filter;
@ -36,7 +37,9 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
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());
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) { if (player == null || permanent == null) {
return false;
}
for (Card card : game.getExile().getAllCards(game)) { for (Card card : game.getExile().getAllCards(game)) {
if (card.isOwnedBy(source.getControllerId()) && filter.match(card, game)) { if (card.isOwnedBy(source.getControllerId()) && filter.match(card, game)) {
game.getState().addOtherAbility(card, ability); game.getState().addOtherAbility(card, ability);
@ -59,24 +62,26 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
} }
// workaround to gain cost reduction abilities to commanders before cast (make it playable) // workaround to gain cost reduction abilities to commanders before cast (make it playable)
game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY).stream() game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY)
.stream()
.filter(card -> filter.match(card, game)) .filter(card -> filter.match(card, game))
.forEach(card -> { .forEach(card -> {
game.getState().addOtherAbility(card, ability); game.getState().addOtherAbility(card, ability);
}); });
for (StackObject stackObject : game.getStack()) { for (StackObject stackObject : game.getStack()) {
if (stackObject.isControlledBy(source.getControllerId())) { if (!stackObject.isControlledBy(source.getControllerId())) {
continue;
}
Card card = game.getCard(stackObject.getSourceId()); Card card = game.getCard(stackObject.getSourceId());
if (card != null && filter.match(stackObject, game)) { if (card == null || !filter.match(stackObject, game)) {
if (!card.hasAbility(ability, game)) { continue;
}
if (ability instanceof MageSingleton && card.hasAbility(ability, game)) {
continue;
}
game.getState().addOtherAbility(card, ability); game.getState().addOtherAbility(card, ability);
} }
}
}
}
return true; return true;
} }
return false;
}
} }