reworked Thunderkin Awakener targeting to account for its toughness changing between trigger and resolution

This commit is contained in:
Evan Kranzler 2019-06-29 12:10:59 -04:00
parent 08028265d5
commit d09e93a91b

View file

@ -15,18 +15,16 @@ import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.ComparisonType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.mageobject.ToughnessPredicate; import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCardInYourGraveyard;
import mage.target.targetadjustment.TargetAdjuster;
import mage.target.targetpointer.FixedTarget; import mage.target.targetpointer.FixedTarget;
import java.util.UUID; import java.util.UUID;
@ -36,6 +34,13 @@ import java.util.UUID;
*/ */
public final class ThunderkinAwakener extends CardImpl { public final class ThunderkinAwakener extends CardImpl {
private static final FilterCard filter
= new FilterCreatureCard("creature card in your graveyard with lesser toughness");
static {
filter.add(ThunderkinAwakenerPredicate.instance);
}
public ThunderkinAwakener(UUID ownerId, CardSetInfo setInfo) { public ThunderkinAwakener(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}");
this.subtype.add(SubType.ELEMENTAL); this.subtype.add(SubType.ELEMENTAL);
@ -50,11 +55,11 @@ public final class ThunderkinAwakener extends CardImpl {
// with toughness less than Thunderkin Awakeners toughness. Return that card to the battlefield tapped and attacking. // with toughness less than Thunderkin Awakeners toughness. Return that card to the battlefield tapped and attacking.
// Sacrifice it at the beginning of the next end step. // Sacrifice it at the beginning of the next end step.
Ability ability = new AttacksTriggeredAbility(new ThunderkinAwakenerEffect(), false); Ability ability = new AttacksTriggeredAbility(new ThunderkinAwakenerEffect(), false);
ability.setTargetAdjuster(ThunderkinAwakenerAdjuster.instance); ability.addTarget(new TargetCardInYourGraveyard(filter));
this.addAbility(ability); this.addAbility(ability);
} }
public ThunderkinAwakener(final ThunderkinAwakener card) { private ThunderkinAwakener(final ThunderkinAwakener card) {
super(card); super(card);
} }
@ -64,34 +69,26 @@ public final class ThunderkinAwakener extends CardImpl {
} }
} }
enum ThunderkinAwakenerAdjuster implements TargetAdjuster { enum ThunderkinAwakenerPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Card>> {
instance; instance;
@Override @Override
public void adjustTargets(Ability ability, Game game) { public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
// target Elemental creature card in your graveyard with toughness less than Thunderkin Awakeners toughness Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(input.getSourceId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId()); return sourcePermanent != null
if (sourcePermanent != null) { & input.getObject().getToughness().getValue() < sourcePermanent.getToughness().getValue();
int xValue = sourcePermanent.getToughness().getValue();
FilterCard filter = new FilterCreatureCard("creature card in your graveyard with toughness less than Thunderkin Awakeners toughness");
filter.add(new SubtypePredicate(SubType.ELEMENTAL));
filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, xValue + 1));
ability.getTargets().clear();
ability.addTarget(new TargetCardInYourGraveyard(filter));
}
} }
} }
class ThunderkinAwakenerEffect extends OneShotEffect { class ThunderkinAwakenerEffect extends OneShotEffect {
public ThunderkinAwakenerEffect() { ThunderkinAwakenerEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
staticText = "choose target Elemental creature card in your graveyard with toughness less than Thunderkin Awakeners toughness." staticText = "choose target Elemental creature card in your graveyard with toughness less than {this}s toughness."
+ " Return that card to the battlefield tapped and attacking. Sacrifice it at the beginning of the next end step"; + " Return that card to the battlefield tapped and attacking. Sacrifice it at the beginning of the next end step";
} }
public ThunderkinAwakenerEffect(final ThunderkinAwakenerEffect effect) { private ThunderkinAwakenerEffect(final ThunderkinAwakenerEffect effect) {
super(effect); super(effect);
} }