* Fixed that cast conditions of legendary sorceries were checked correctly if you cast a card owned by another player e.g. from exile (fixes #4921).

This commit is contained in:
LevelX2 2018-05-10 08:55:10 +02:00
parent a227bd9e1c
commit 74f05d438f
3 changed files with 203 additions and 51 deletions

View file

@ -1,18 +1,27 @@
package mage.abilities.common;
import mage.abilities.condition.common.LegendaryCondition;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SupertypePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
/**
* @author JRHerlehy
* Created on 4/8/18.
* @author JRHerlehy Created on 4/8/18.
*/
public class LegendarySpellAbility extends SimpleStaticAbility {
public LegendarySpellAbility() {
super(Zone.ALL, new CastOnlyIfConditionIsTrueEffect(LegendaryCondition.instance));
super(Zone.ALL, new LegendarySpellAbilityCheckEffect());
this.setRuleAtTheTop(true);
this.getEffects().get(0).setText("<i>(You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)</i>");
}
private LegendarySpellAbility(final LegendarySpellAbility ability) {
@ -24,3 +33,46 @@ public class LegendarySpellAbility extends SimpleStaticAbility {
return new LegendarySpellAbility(this);
}
}
class LegendarySpellAbilityCheckEffect extends ContinuousRuleModifyingEffectImpl {
private static final FilterPermanent filter = new FilterPermanent("legendary creature or planeswalker");
static {
filter.add(
Predicates.and(
new SupertypePredicate(SuperType.LEGENDARY),
Predicates.or(
new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.PLANESWALKER)
)
)
);
}
public LegendarySpellAbilityCheckEffect() {
super(Duration.EndOfGame, Outcome.Detriment);
staticText = "<i>(You may cast a legendary sorcery only if you control a legendary creature or planeswalker.)</i>";
}
private LegendarySpellAbilityCheckEffect(final LegendarySpellAbilityCheckEffect effect) {
super(effect);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.CAST_SPELL;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
return event.getSourceId().equals(source.getSourceId())
&& !game.getBattlefield().contains(filter, event.getPlayerId(), 1, game);
}
@Override
public LegendarySpellAbilityCheckEffect copy() {
return new LegendarySpellAbilityCheckEffect(this);
}
}

View file

@ -1,46 +0,0 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.CardType;
import mage.constants.SuperType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SupertypePredicate;
import mage.game.Game;
/**
* @author JRHerlehy
* Created on 4/7/18.
*/
public enum LegendaryCondition implements Condition {
instance;
private static final FilterPermanent filter = new FilterPermanent("legendary creature or planeswalker");
static {
filter.add(
Predicates.and(
new SupertypePredicate(SuperType.LEGENDARY),
Predicates.or(
new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.PLANESWALKER)
)
)
);
}
@Override
public boolean apply(Game game, Ability source) {
return game.getBattlefield().contains(filter, source.getControllerId(), 1, game);
}
@Override
public String toString() {
return super.toString();
}
}