diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/Rancor.java b/Mage.Sets/src/mage/sets/urzaslegacy/Rancor.java index c4552248ba..b8db415293 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/Rancor.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/Rancor.java @@ -31,7 +31,7 @@ import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.abilities.Ability; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.PutIntoGraveFromBattlefield; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.ReturnToHandSourceEffect; @@ -40,10 +40,6 @@ import mage.abilities.effects.common.continious.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.TrampleAbility; import mage.cards.CardImpl; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.game.events.ZoneChangeEvent; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -73,7 +69,7 @@ public class Rancor extends CardImpl { this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new GainAbilityAttachedEffect(TrampleAbility.getInstance(), Constants.AttachmentType.AURA))); // When Rancor is put into a graveyard from the battlefield, return Rancor to its owner's hand. - this.addAbility(new RancorTriggeredAbility()); + this.addAbility(new PutIntoGraveFromBattlefield(new ReturnToHandSourceEffect())); } public Rancor(final Rancor card) { @@ -85,41 +81,3 @@ public class Rancor extends CardImpl { return new Rancor(this); } } - -class RancorTriggeredAbility extends TriggeredAbilityImpl { - - public RancorTriggeredAbility() { - super(Constants.Zone.ALL, new ReturnToHandSourceEffect(), false); - } - - RancorTriggeredAbility(RancorTriggeredAbility ability) { - super(ability); - } - - @Override - public RancorTriggeredAbility copy() { - return new RancorTriggeredAbility(this); - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { - - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - Permanent permanent = zEvent.getTarget(); - - if (permanent != null && - zEvent.getToZone() == Constants.Zone.GRAVEYARD && - zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && - permanent.getId().equals(this.getSourceId())) { - return true; - } - } - return false; - } - - @Override - public String getRule() { - return "When {this} is put into a graveyard from the battlefield, return {this} to its owner's hand"; - } -} diff --git a/Mage.Sets/src/mage/sets/urzassaga/BrilliantHalo.java b/Mage.Sets/src/mage/sets/urzassaga/BrilliantHalo.java index c637f1a7be..d3d2a57524 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/BrilliantHalo.java +++ b/Mage.Sets/src/mage/sets/urzassaga/BrilliantHalo.java @@ -33,7 +33,7 @@ import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.abilities.Ability; -import mage.abilities.common.DiesTriggeredAbility; +import mage.abilities.common.PutIntoGraveFromBattlefield; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.ReturnToHandSourceEffect; @@ -65,7 +65,7 @@ public class BrilliantHalo extends CardImpl { // Enchanted creature gets +1/+2. this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new BoostEnchantedEffect(1, 2, Constants.Duration.WhileOnBattlefield))); // When Brilliant Halo is put into a graveyard from the battlefield, return Brilliant Halo to its owner's hand. - this.addAbility(new DiesTriggeredAbility(new ReturnToHandSourceEffect())); + this.addAbility(new PutIntoGraveFromBattlefield(new ReturnToHandSourceEffect())); } public BrilliantHalo(final BrilliantHalo card) { diff --git a/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefield.java b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefield.java new file mode 100644 index 0000000000..d8b3478dac --- /dev/null +++ b/Mage/src/mage/abilities/common/PutIntoGraveFromBattlefield.java @@ -0,0 +1,54 @@ +package mage.abilities.common; + +import mage.Constants; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; + +/** + * @author nantuko, loki + */ +public class PutIntoGraveFromBattlefield extends TriggeredAbilityImpl { + + public PutIntoGraveFromBattlefield(Effect effect) { + this(effect, false); + } + + public PutIntoGraveFromBattlefield(Effect effect, boolean optional) { + super(Constants.Zone.ALL, effect, optional); + } + + PutIntoGraveFromBattlefield(PutIntoGraveFromBattlefield ability) { + super(ability); + } + + @Override + public PutIntoGraveFromBattlefield copy() { + return new PutIntoGraveFromBattlefield(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + Permanent permanent = zEvent.getTarget(); + + if (permanent != null && + zEvent.getToZone() == Constants.Zone.GRAVEYARD && + zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && + permanent.getId().equals(this.getSourceId())) { + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "When {this} is put into a graveyard from the battlefield, return {this} to its owner's hand"; + } +}