mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Update Legerdemain to use filters in targeting.
Fix the way targeting is handled on Legerdemain. Previously it was possible to get into an impossible state if there was no valid second target.
This commit is contained in:
parent
4c9a49df5b
commit
2173069c09
1 changed files with 38 additions and 25 deletions
|
@ -28,6 +28,7 @@
|
||||||
package mage.sets.tempest;
|
package mage.sets.tempest;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.MageItem;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect;
|
import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
|
@ -35,10 +36,14 @@ import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayer;
|
||||||
|
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||||
import mage.filter.predicate.Predicates;
|
import mage.filter.predicate.Predicates;
|
||||||
|
import mage.filter.predicate.mageobject.AnotherTargetPredicate;
|
||||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
import mage.filter.predicate.mageobject.CardTypePredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.stack.StackObject;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,9 +52,12 @@ import mage.target.TargetPermanent;
|
||||||
*/
|
*/
|
||||||
public class Legerdemain extends CardImpl {
|
public class Legerdemain extends CardImpl {
|
||||||
|
|
||||||
private static final FilterPermanent filter = new FilterPermanent("artifact or creature");
|
private static final FilterPermanent firstFilter = new FilterPermanent("artifact or creature");
|
||||||
|
private static final FilterPermanent secondFilter = new FilterPermanent("another permanent that shares the type of artifact or creature");
|
||||||
static {
|
static {
|
||||||
filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE)));
|
firstFilter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE)));
|
||||||
|
secondFilter.add(new AnotherTargetPredicate(2));
|
||||||
|
secondFilter.add(new SharesTypePredicate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Legerdemain(UUID ownerId) {
|
public Legerdemain(UUID ownerId) {
|
||||||
|
@ -58,8 +66,12 @@ public class Legerdemain extends CardImpl {
|
||||||
|
|
||||||
// Exchange control of target artifact or creature and another target permanent that shares one of those types with it.
|
// Exchange control of target artifact or creature and another target permanent that shares one of those types with it.
|
||||||
this.getSpellAbility().addEffect(new ExchangeControlTargetEffect(Duration.EndOfGame, "Exchange control of target artifact or creature and another target permanent that shares one of those types with it", false, true));
|
this.getSpellAbility().addEffect(new ExchangeControlTargetEffect(Duration.EndOfGame, "Exchange control of target artifact or creature and another target permanent that shares one of those types with it", false, true));
|
||||||
this.getSpellAbility().addTarget(new TargetPermanent(filter));
|
TargetPermanent firstTarget = new TargetPermanent(firstFilter);
|
||||||
this.getSpellAbility().addTarget(new LegerdemainSecondTarget());
|
firstTarget.setTargetTag(1);
|
||||||
|
TargetPermanent secondTarget = new TargetPermanent(secondFilter);
|
||||||
|
secondTarget.setTargetTag(2);
|
||||||
|
this.getSpellAbility().addTarget(firstTarget);
|
||||||
|
this.getSpellAbility().addTarget(secondTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Legerdemain(final Legerdemain card) {
|
public Legerdemain(final Legerdemain card) {
|
||||||
|
@ -72,21 +84,19 @@ public class Legerdemain extends CardImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LegerdemainSecondTarget extends TargetPermanent {
|
class SharesTypePredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<MageItem>> {
|
||||||
|
|
||||||
LegerdemainSecondTarget() {
|
|
||||||
super();
|
|
||||||
this.targetName = "another permanent that shares one of those types";
|
|
||||||
}
|
|
||||||
|
|
||||||
LegerdemainSecondTarget(final LegerdemainSecondTarget target) {
|
|
||||||
super(target);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
|
public boolean apply(ObjectSourcePlayer<MageItem> input, Game game) {
|
||||||
Permanent firstPermanent = game.getPermanent(source.getTargets().getFirstTarget());
|
StackObject source = game.getStack().getStackObject(input.getSourceId());
|
||||||
Permanent secondPermanent = game.getPermanent(id);
|
if (source != null) {
|
||||||
|
if (source.getStackAbility().getTargets().isEmpty()
|
||||||
|
|| source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Permanent firstPermanent = game.getPermanent(
|
||||||
|
source.getStackAbility().getTargets().get(0).getTargets().get(0));
|
||||||
|
Permanent secondPermanent = game.getPermanent(input.getObject().getId());
|
||||||
if (firstPermanent != null && secondPermanent != null) {
|
if (firstPermanent != null && secondPermanent != null) {
|
||||||
if (firstPermanent.getCardType().contains(CardType.CREATURE) && secondPermanent.getCardType().contains(CardType.CREATURE)) {
|
if (firstPermanent.getCardType().contains(CardType.CREATURE) && secondPermanent.getCardType().contains(CardType.CREATURE)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -97,9 +107,12 @@ class LegerdemainSecondTarget extends TargetPermanent {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LegerdemainSecondTarget copy() {
|
public String toString() {
|
||||||
return new LegerdemainSecondTarget(this);
|
return "Target permanent that shares the type of artifact or creature";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue