[CMR] fixed multiple copies of Imoti, Celebrant of Bounty only giving cascade once
package mage.abilities.effects;
import mage.abilities.Ability;
+import mage.abilities.MageSingleton;
import mage.cards.Card;
import mage.constants.*;
import mage.filter.FilterObject;
@@ -21,7 +22,7 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
staticText = filter.getMessage() + " have " + ability.getRule();
}
- public GainAbilitySpellsEffect(final GainAbilitySpellsEffect effect) {
+ private GainAbilitySpellsEffect(final GainAbilitySpellsEffect effect) {
super(effect);
this.ability = effect.ability;
this.filter = effect.filter;
@@ -36,7 +37,9 @@ public class GainAbilitySpellsEffect extends ContinuousEffectImpl {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
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)) {
if (card.isOwnedBy(source.getControllerId()) && filter.match(card, game)) {
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)
- game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY).stream()
+ game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY)
+ .stream()
.filter(card -> filter.match(card, game))
.forEach(card -> {
game.getState().addOtherAbility(card, ability);
});
for (StackObject stackObject : game.getStack()) {
- if (stackObject.isControlledBy(source.getControllerId())) {
- Card card = game.getCard(stackObject.getSourceId());
- if (card != null && filter.match(stackObject, game)) {
- if (!card.hasAbility(ability, game)) {
- game.getState().addOtherAbility(card, ability);
+ if (!stackObject.isControlledBy(source.getControllerId())) {
+ continue;
}
+ Card card = game.getCard(stackObject.getSourceId());
+ if (card == null || !filter.match(stackObject, game)) {
+ continue;
}
+ if (ability instanceof MageSingleton && card.hasAbility(ability, game)) {
+ continue;
}
+ game.getState().addOtherAbility(card, ability);
}
return true;
}
- return false;
- }
}
