diff --git a/Mage.Sets/src/mage/cards/c/Crystallization.java b/Mage.Sets/src/mage/cards/c/Crystallization.java index 648365f60d6..64455c7837a 100644 --- a/Mage.Sets/src/mage/cards/c/Crystallization.java +++ b/Mage.Sets/src/mage/cards/c/Crystallization.java @@ -1,12 +1,10 @@ - package mage.cards.c; import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.BecomesTargetAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.ExileTargetEffect; +import mage.abilities.effects.common.ExileAttachedEffect; import mage.abilities.effects.common.combat.CantAttackBlockAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; @@ -16,13 +14,8 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; -import mage.target.targetpointer.FixedTarget; /** * @@ -37,15 +30,14 @@ public final class Crystallization extends CardImpl { // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.Removal)); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Enchanted creature can't attack or block. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackBlockAttachedEffect(AttachmentType.AURA))); // When enchanted creature becomes the target of a spell or ability, exile that creature. - this.addAbility(new CrystallizationTriggeredAbility()); + this.addAbility(new BecomesTargetAttachedTriggeredAbility(new ExileAttachedEffect().setText("exile that creature"))); } private Crystallization(final Crystallization card) { @@ -57,42 +49,3 @@ public final class Crystallization extends CardImpl { return new Crystallization(this); } } - -class CrystallizationTriggeredAbility extends TriggeredAbilityImpl { - - public CrystallizationTriggeredAbility() { - super(Zone.BATTLEFIELD, new ExileTargetEffect()); - } - - public CrystallizationTriggeredAbility(final CrystallizationTriggeredAbility ability) { - super(ability); - } - - @Override - public CrystallizationTriggeredAbility copy() { - return new CrystallizationTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.TARGETED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent enchantment = game.getPermanent(sourceId); - if (enchantment != null && enchantment.getAttachedTo() != null) { - UUID enchanted = enchantment.getAttachedTo(); - if (event.getTargetId().equals(enchanted)) { - getEffects().get(0).setTargetPointer(new FixedTarget(enchanted, game)); - return true; - } - } - return false; - } - - @Override - public String getRule() { - return "When enchanted creature becomes the target of a spell or ability, exile that creature."; - } -} diff --git a/Mage.Sets/src/mage/cards/i/IceCage.java b/Mage.Sets/src/mage/cards/i/IceCage.java index 99f5ca6d7d8..2de7423b090 100644 --- a/Mage.Sets/src/mage/cards/i/IceCage.java +++ b/Mage.Sets/src/mage/cards/i/IceCage.java @@ -1,9 +1,6 @@ - - package mage.cards.i; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.BecomesTargetAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; @@ -27,15 +24,13 @@ public final class IceCage extends CardImpl { public IceCage(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}"); - this.subtype.add(SubType.AURA); // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); // Enchanted creature can't attack or block, and its activated abilities can't be activated. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantBlockAttackActivateAttachedEffect())); diff --git a/Mage.Sets/src/mage/cards/s/SleepingPotion.java b/Mage.Sets/src/mage/cards/s/SleepingPotion.java index 2585988f833..a25b7212b92 100644 --- a/Mage.Sets/src/mage/cards/s/SleepingPotion.java +++ b/Mage.Sets/src/mage/cards/s/SleepingPotion.java @@ -1,8 +1,6 @@ - package mage.cards.s; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.BecomesTargetAttachedTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -34,12 +32,14 @@ public final class SleepingPotion extends CardImpl { TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); - Ability ability = new EnchantAbility(auraTarget.getTargetName()); - this.addAbility(ability); + this.addAbility(new EnchantAbility(auraTarget.getTargetName())); + // When Sleeping Potion enters the battlefield, tap enchanted creature. this.addAbility(new EntersBattlefieldTriggeredAbility(new TapEnchantedEffect())); + // Enchanted creature doesn't untap during its controller's untap step. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DontUntapInControllersUntapStepEnchantedEffect())); + // When enchanted creature becomes the target of a spell or ability, sacrifice Sleeping Potion. this.addAbility(new BecomesTargetAttachedTriggeredAbility(new SacrificeSourceEffect())); } diff --git a/Mage.Sets/src/mage/cards/s/SpectralPrison.java b/Mage.Sets/src/mage/cards/s/SpectralPrison.java index 1d27b0c154f..32b82d1d3fd 100644 --- a/Mage.Sets/src/mage/cards/s/SpectralPrison.java +++ b/Mage.Sets/src/mage/cards/s/SpectralPrison.java @@ -1,13 +1,11 @@ - package mage.cards.s; import java.util.UUID; -import mage.MageObject; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.BecomesTargetAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.DestroySourceEffect; import mage.abilities.effects.common.DontUntapInControllersUntapStepEnchantedEffect; +import mage.abilities.effects.common.SacrificeSourceEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -15,11 +13,7 @@ import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Outcome; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.game.permanent.Permanent; -import mage.game.stack.Spell; +import mage.filter.StaticFilters; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -33,18 +27,17 @@ public final class SpectralPrison extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}"); this.subtype.add(SubType.AURA); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.Detriment)); this.addAbility(new EnchantAbility(auraTarget.getTargetName())); - + // Enchanted creature doesn't untap during its controller's untap step. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DontUntapInControllersUntapStepEnchantedEffect())); // When enchanted creature becomes the target of a spell, sacrifice Spectral Prison. - this.addAbility(new SpectralPrisonAbility()); + this.addAbility(new BecomesTargetAttachedTriggeredAbility(new SacrificeSourceEffect(), StaticFilters.FILTER_SPELL_A)); } private SpectralPrison(final SpectralPrison card) { @@ -56,44 +49,3 @@ public final class SpectralPrison extends CardImpl { return new SpectralPrison(this); } } - -class SpectralPrisonAbility extends TriggeredAbilityImpl { - - public SpectralPrisonAbility() { - super(Zone.BATTLEFIELD, new DestroySourceEffect()); - } - - public SpectralPrisonAbility(final SpectralPrisonAbility ability) { - super(ability); - } - - @Override - public SpectralPrisonAbility copy() { - return new SpectralPrisonAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.TARGETED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - MageObject eventSourceObject = game.getObject(event.getSourceId()); - if (eventSourceObject instanceof Spell) { - Permanent enchantment = game.getPermanent(sourceId); - if (enchantment != null && enchantment.getAttachedTo() != null) { - if (event.getTargetId().equals(enchantment.getAttachedTo())) { - return true; - } - } - } - return false; - } - - @Override - public String getRule() { - return "When enchanted creature becomes the target of a spell or ability, destroy {this}."; - } - -} diff --git a/Mage.Sets/src/mage/cards/s/SpinalGraft.java b/Mage.Sets/src/mage/cards/s/SpinalGraft.java index d2079b8f6be..fc3b67bfe20 100644 --- a/Mage.Sets/src/mage/cards/s/SpinalGraft.java +++ b/Mage.Sets/src/mage/cards/s/SpinalGraft.java @@ -1,10 +1,10 @@ package mage.cards.s; import java.util.UUID; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.BecomesTargetAttachedTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; -import mage.abilities.effects.common.DestroyTargetEffect; +import mage.abilities.effects.common.DestroyAttachedToEffect; import mage.abilities.effects.common.continuous.BoostEnchantedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; @@ -14,12 +14,8 @@ import mage.constants.SubType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; -import mage.target.targetpointer.FixedTarget; /** * @@ -41,7 +37,7 @@ public final class SpinalGraft extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(3, 3, Duration.WhileOnBattlefield))); // When enchanted creature becomes the target of a spell or ability, destroy that creature. It can't be regenerated. - this.addAbility(new SpinalGraftTriggeredAbility()); + this.addAbility(new BecomesTargetAttachedTriggeredAbility(new DestroyAttachedToEffect("that creature", true))); } private SpinalGraft(final SpinalGraft card) { @@ -53,42 +49,3 @@ public final class SpinalGraft extends CardImpl { return new SpinalGraft(this); } } - -class SpinalGraftTriggeredAbility extends TriggeredAbilityImpl { - - public SpinalGraftTriggeredAbility() { - super(Zone.BATTLEFIELD, new DestroyTargetEffect(true)); - } - - public SpinalGraftTriggeredAbility(final SpinalGraftTriggeredAbility ability) { - super(ability); - } - - @Override - public SpinalGraftTriggeredAbility copy() { - return new SpinalGraftTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.TARGETED; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - Permanent enchantment = game.getPermanent(sourceId); - if (enchantment != null && enchantment.getAttachedTo() != null) { - UUID enchanted = enchantment.getAttachedTo(); - if (event.getTargetId().equals(enchanted)) { - getEffects().get(0).setTargetPointer(new FixedTarget(enchanted, game)); - return true; - } - } - return false; - } - - @Override - public String getRule() { - return "When enchanted creature becomes the target of a spell or ability, destroy that creature. It can't be regenerated."; - } -} diff --git a/Mage.Sets/src/mage/cards/w/WeightOfConscience.java b/Mage.Sets/src/mage/cards/w/WeightOfConscience.java index ec39a5d89ae..e0ff6e12b24 100644 --- a/Mage.Sets/src/mage/cards/w/WeightOfConscience.java +++ b/Mage.Sets/src/mage/cards/w/WeightOfConscience.java @@ -5,8 +5,8 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.TapTargetCost; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.ExileAttachedEffect; import mage.abilities.effects.common.combat.CantAttackAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; @@ -46,7 +46,7 @@ public final class WeightOfConscience extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackAttachedEffect(AttachmentType.AURA))); // Tap two untapped creatures you control that share a creature type: Exile enchanted creature. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new WeightOfConscienceEffect(), new TapTargetCost(new WeightOfConscienceTarget()))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ExileAttachedEffect(), new TapTargetCost(new WeightOfConscienceTarget()))); } private WeightOfConscience(final WeightOfConscience card) { @@ -59,43 +59,6 @@ public final class WeightOfConscience extends CardImpl { } } -class WeightOfConscienceEffect extends OneShotEffect { - - WeightOfConscienceEffect() { - super(Outcome.Exile); - staticText = "Exile enchanted creature"; - } - - WeightOfConscienceEffect(final WeightOfConscienceEffect effect) { - super(effect); - } - - @Override - public WeightOfConscienceEffect copy() { - return new WeightOfConscienceEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - // In the case that the enchantment is blinked - Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - if (enchantment == null) { - // It was not blinked, use the standard method - enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId()); - } - if (controller != null - && enchantment != null - && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - controller.moveCardsToExile(creature, source, game, true, null, ""); - } - } - return false; - } -} - class WeightOfConscienceTarget extends TargetControlledCreaturePermanent { private static final FilterControlledCreaturePermanent filterUntapped = new FilterControlledCreaturePermanent("untapped creatures you control that share a creature type"); diff --git a/Mage/src/main/java/mage/abilities/common/BecomesTargetAttachedTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/BecomesTargetAttachedTriggeredAbility.java index d9e61c229f1..fef952f3a74 100644 --- a/Mage/src/main/java/mage/abilities/common/BecomesTargetAttachedTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/BecomesTargetAttachedTriggeredAbility.java @@ -1,12 +1,14 @@ - package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; import mage.constants.Zone; +import mage.filter.FilterStackObject; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent; +import mage.game.stack.StackObject; import mage.game.permanent.Permanent; /** @@ -15,19 +17,26 @@ import mage.game.permanent.Permanent; */ public class BecomesTargetAttachedTriggeredAbility extends TriggeredAbilityImpl { + private final FilterStackObject filter; private final String enchantType; public BecomesTargetAttachedTriggeredAbility(Effect effect) { - this(effect, "creature"); + this(effect, StaticFilters.FILTER_SPELL_OR_ABILITY_A); } - public BecomesTargetAttachedTriggeredAbility(Effect effect, String enchantType) { + public BecomesTargetAttachedTriggeredAbility(Effect effect, FilterStackObject filter) { + this(effect, filter, "creature"); + } + + public BecomesTargetAttachedTriggeredAbility(Effect effect, FilterStackObject filter, String enchantType) { super(Zone.BATTLEFIELD, effect); + this.filter = filter.copy(); this.enchantType = enchantType; } public BecomesTargetAttachedTriggeredAbility(final BecomesTargetAttachedTriggeredAbility ability) { super(ability); + this.filter = ability.filter.copy(); this.enchantType = ability.enchantType; } @@ -44,8 +53,10 @@ public class BecomesTargetAttachedTriggeredAbility extends TriggeredAbilityImpl @Override public boolean checkTrigger(GameEvent event, Game game) { Permanent enchantment = game.getPermanent(sourceId); + StackObject sourceObject = game.getStack().getStackObject(event.getSourceId()); if (enchantment != null && enchantment.getAttachedTo() != null) { - if (event.getTargetId().equals(enchantment.getAttachedTo())) { + if (event.getTargetId().equals(enchantment.getAttachedTo()) + && filter.match(sourceObject, getSourceId(), getControllerId(), game)) { return true; } } @@ -54,6 +65,6 @@ public class BecomesTargetAttachedTriggeredAbility extends TriggeredAbilityImpl @Override public String getTriggerPhrase() { - return "When enchanted " + enchantType + " becomes the target of a spell or ability, " ; + return "When enchanted " + enchantType + " becomes the target of " + filter.getMessage() + ", "; } }