new AuraSpellPredicate for Brine Comber, Fugitive Druid (related to #11174)

This commit is contained in:
xenohedron 2023-09-21 23:24:45 -04:00
parent 48d7d07f93
commit a7cda75b22
4 changed files with 65 additions and 115 deletions

View file

@ -1,19 +1,19 @@
package mage.cards.b; package mage.cards.b;
import mage.MageInt; import mage.MageInt;
import mage.abilities.SpellAbility; import mage.abilities.common.BecomesTargetSourceTriggeredAbility;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.keyword.DisturbAbility; import mage.abilities.keyword.DisturbAbility;
import mage.abilities.meta.OrTriggeredAbility;
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.SubType; import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.filter.FilterSpell;
import mage.game.events.GameEvent; import mage.filter.predicate.other.AuraSpellPredicate;
import mage.game.permanent.token.SpiritWhiteToken; import mage.game.permanent.token.SpiritWhiteToken;
import mage.game.stack.Spell;
import java.util.UUID; import java.util.UUID;
@ -22,6 +22,12 @@ import java.util.UUID;
*/ */
public final class BrineComber extends CardImpl { public final class BrineComber extends CardImpl {
private static final FilterSpell filter = new FilterSpell("an Aura spell");
static {
filter.add(AuraSpellPredicate.instance);
}
public BrineComber(UUID ownerId, CardSetInfo setInfo) { public BrineComber(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}{U}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}{U}");
@ -31,7 +37,10 @@ public final class BrineComber extends CardImpl {
this.secondSideCardClazz = mage.cards.b.BrineboundGift.class; this.secondSideCardClazz = mage.cards.b.BrineboundGift.class;
// Whenever Brine Comber enters the battlefield or becomes the target of an Aura spell, create a 1/1 white Spirit creature token with flying. // Whenever Brine Comber enters the battlefield or becomes the target of an Aura spell, create a 1/1 white Spirit creature token with flying.
this.addAbility(new BrineComberTriggeredAbility()); this.addAbility(new OrTriggeredAbility(Zone.ALL, new CreateTokenEffect(new SpiritWhiteToken()), false,
"Whenever {this} enters the battlefield or becomes the target of an Aura spell, ",
new EntersBattlefieldTriggeredAbility(null),
new BecomesTargetSourceTriggeredAbility(null, filter)));
// Disturb {W}{U} // Disturb {W}{U}
this.addAbility(new DisturbAbility(this, "{W}{U}")); this.addAbility(new DisturbAbility(this, "{W}{U}"));
@ -46,54 +55,3 @@ public final class BrineComber extends CardImpl {
return new BrineComber(this); return new BrineComber(this);
} }
} }
class BrineComberTriggeredAbility extends TriggeredAbilityImpl {
BrineComberTriggeredAbility() {
super(Zone.ALL, new CreateTokenEffect(new SpiritWhiteToken()));
}
private BrineComberTriggeredAbility(final BrineComberTriggeredAbility effect) {
super(effect);
}
@Override
public BrineComberTriggeredAbility copy() {
return new BrineComberTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
|| event.getType() == GameEvent.EventType.TARGETED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch (event.getType()) {
case ENTERS_THE_BATTLEFIELD:
return event.getTargetId().equals(getSourceId());
case TARGETED:
break;
default:
return false;
}
if (this.getSourcePermanentIfItStillExists(game) == null
|| !event.getTargetId().equals(getSourceId())) {
return false;
}
Spell spell = game.getSpell(event.getSourceId());
if(spell == null) {
return false;
}
SpellAbility spellAbility = (SpellAbility) spell.getStackAbility();
return spellAbility != null
&& spellAbility.getCharacteristics(game).hasSubtype(SubType.AURA, game);
}
@Override
public String getRule() {
return "Whenever {this} enters the battlefield or becomes the target " +
"of an Aura spell, create a 1/1 white Spirit creature token with flying.";
}
}

View file

@ -1,23 +1,20 @@
package mage.cards.b; package mage.cards.b;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.BecomesTargetAttachedTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.PutIntoGraveFromAnywhereSourceAbility; import mage.abilities.common.PutIntoGraveFromAnywhereSourceAbility;
import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.ExileSourceEffect; import mage.abilities.effects.common.ExileSourceEffect;
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.abilities.meta.OrTriggeredAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.*;
import mage.constants.Outcome; import mage.filter.FilterSpell;
import mage.constants.SubType; import mage.filter.predicate.other.AuraSpellPredicate;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.SpiritWhiteToken; import mage.game.permanent.token.SpiritWhiteToken;
import mage.game.stack.Spell;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
@ -28,6 +25,12 @@ import java.util.UUID;
*/ */
public final class BrineboundGift extends CardImpl { public final class BrineboundGift extends CardImpl {
private static final FilterSpell filter = new FilterSpell("an Aura spell");
static {
filter.add(AuraSpellPredicate.instance);
}
public BrineboundGift(UUID ownerId, CardSetInfo setInfo) { public BrineboundGift(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, ""); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "");
@ -44,7 +47,10 @@ public final class BrineboundGift extends CardImpl {
this.addAbility(ability); this.addAbility(ability);
// Whenever Brinebound Gift enters the battlefield or enchanted creature becomes the target of an Aura spell, create a 1/1 white Spirit creature token with flying. // Whenever Brinebound Gift enters the battlefield or enchanted creature becomes the target of an Aura spell, create a 1/1 white Spirit creature token with flying.
this.addAbility(new BrineboundGiftTriggeredAbility()); this.addAbility(new OrTriggeredAbility(Zone.ALL, new CreateTokenEffect(new SpiritWhiteToken()), false,
"Whenever {this} enters the battlefield or enchanted creature becomes the target of an Aura spell, ",
new EntersBattlefieldTriggeredAbility(null),
new BecomesTargetAttachedTriggeredAbility(null, filter, SetTargetPointer.NONE, false)));
// If Brinebound Gift would be put into a graveyard from anywhere, exile it instead. // If Brinebound Gift would be put into a graveyard from anywhere, exile it instead.
this.addAbility(new PutIntoGraveFromAnywhereSourceAbility(new ExileSourceEffect().setText("exile it instead"))); this.addAbility(new PutIntoGraveFromAnywhereSourceAbility(new ExileSourceEffect().setText("exile it instead")));
@ -59,49 +65,3 @@ public final class BrineboundGift extends CardImpl {
return new BrineboundGift(this); return new BrineboundGift(this);
} }
} }
class BrineboundGiftTriggeredAbility extends TriggeredAbilityImpl {
BrineboundGiftTriggeredAbility() {
super(Zone.ALL, new CreateTokenEffect(new SpiritWhiteToken()));
}
private BrineboundGiftTriggeredAbility(final BrineboundGiftTriggeredAbility effect) {
super(effect);
}
@Override
public BrineboundGiftTriggeredAbility copy() {
return new BrineboundGiftTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
|| event.getType() == GameEvent.EventType.TARGETED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch (event.getType()) {
case ENTERS_THE_BATTLEFIELD:
return event.getTargetId().equals(getSourceId());
case TARGETED:
break;
default:
return false;
}
Permanent permanent = this.getSourcePermanentOrLKI(game);
if (permanent == null || !event.getTargetId().equals(permanent.getAttachedTo())) {
return false;
}
Spell spell = game.getSpell(event.getSourceId());
return spell != null && spell.hasSubtype(SubType.AURA, game);
}
@Override
public String getRule() {
return "Whenever {this} enters the battlefield or enchanted creature becomes the target " +
"of an Aura spell, create a 1/1 white Spirit creature token with flying.";
}
}

View file

@ -10,6 +10,7 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType; import mage.constants.SubType;
import mage.filter.FilterSpell; import mage.filter.FilterSpell;
import mage.filter.predicate.other.AuraSpellPredicate;
/** /**
* *
@ -20,7 +21,7 @@ public final class FugitiveDruid extends CardImpl {
private static final FilterSpell filter = new FilterSpell("an Aura spell"); private static final FilterSpell filter = new FilterSpell("an Aura spell");
static { static {
filter.add(SubType.AURA.getPredicate()); filter.add(AuraSpellPredicate.instance);
} }
public FugitiveDruid(UUID ownerId, CardSetInfo setInfo) { public FugitiveDruid(UUID ownerId, CardSetInfo setInfo) {
@ -31,7 +32,7 @@ public final class FugitiveDruid extends CardImpl {
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
// Whenever Fugitive Druid becomes the target of an Aura spell, you draw a card. // Whenever Fugitive Druid becomes the target of an Aura spell, you draw a card.
this.addAbility(new BecomesTargetSourceTriggeredAbility(new DrawCardSourceControllerEffect(1), filter)); this.addAbility(new BecomesTargetSourceTriggeredAbility(new DrawCardSourceControllerEffect(1, "you"), filter));
} }
private FugitiveDruid(final FugitiveDruid card) { private FugitiveDruid(final FugitiveDruid card) {

View file

@ -0,0 +1,31 @@
package mage.filter.predicate.other;
import mage.abilities.SpellAbility;
import mage.constants.SubType;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
/**
* Needed for "becomes the target of an Aura spell" to work correctly with e.g. Disturb, Bestow
*
* @author xenohedron
*/
public enum AuraSpellPredicate implements Predicate<StackObject> {
instance;
@Override
public boolean apply(StackObject input, Game game) {
if (!(input instanceof Spell)) {
return false;
}
SpellAbility spellAbility = ((Spell) input).getSpellAbility();
return spellAbility != null && spellAbility.getCharacteristics(game).hasSubtype(SubType.AURA, game);
}
@Override
public String toString() {
return "an Aura spell";
}
}