diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/SylvokLifestaff.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/SylvokLifestaff.java index 5555158c4a..b73fd0aca3 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/SylvokLifestaff.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/SylvokLifestaff.java @@ -33,6 +33,8 @@ import mage.Constants.CardType; import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.common.DiesAttachedTriggeredAbility; import mage.abilities.common.DiesTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; @@ -44,7 +46,7 @@ import mage.cards.CardImpl; /** * - * @author North + * @author North, Loki */ public class SylvokLifestaff extends CardImpl { @@ -54,8 +56,7 @@ public class SylvokLifestaff extends CardImpl { this.subtype.add("Equipment"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(1, 0))); - DiesTriggeredAbility ability = new DiesTriggeredAbility(new GainLifeEffect(3)); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(ability, AttachmentType.EQUIPMENT))); + this.addAbility(new DiesAttachedTriggeredAbility(new GainLifeEffect(3), "equipped creature")); this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(1))); } diff --git a/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java new file mode 100644 index 0000000000..8d205579b2 --- /dev/null +++ b/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java @@ -0,0 +1,50 @@ +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; + +/** + * "When enchanted/equipped creature dies" triggered ability + * @author Loki + */ +public class DiesAttachedTriggeredAbility extends TriggeredAbilityImpl { + private String attachedDescription; + + public DiesAttachedTriggeredAbility(Effect effect, String attachedDescription) { + super(Constants.Zone.BATTLEFIELD, effect); + this.attachedDescription = attachedDescription; + } + + public DiesAttachedTriggeredAbility(final DiesAttachedTriggeredAbility ability) { + super(ability); + this.attachedDescription = ability.attachedDescription; + } + + @Override + public DiesAttachedTriggeredAbility copy() { + return new DiesAttachedTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + if (zEvent.getFromZone() == Constants.Zone.BATTLEFIELD && zEvent.getToZone() == Constants.Zone.GRAVEYARD) { + Permanent p = (Permanent) game.getLastKnownInformation(event.getTargetId(), Constants.Zone.BATTLEFIELD); + if (p.getAttachments().contains(this.getSourceId())) + return true; + } + } + return false; + } + + @Override + public String getRule() { + return "When " + attachedDescription + " dies," + super.getRule(); + } +}