From b1a4fada8a2d70ded87f61c4425d2a79048d043f Mon Sep 17 00:00:00 2001 From: North Date: Thu, 6 Sep 2012 15:21:10 +0300 Subject: [PATCH] Fixed Aegis Angel --- .../src/mage/sets/magic2012/AegisAngel.java | 105 +++++++++++++++++- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2012/AegisAngel.java b/Mage.Sets/src/mage/sets/magic2012/AegisAngel.java index 7c27e337a1..bf0bd9cc04 100644 --- a/Mage.Sets/src/mage/sets/magic2012/AegisAngel.java +++ b/Mage.Sets/src/mage/sets/magic2012/AegisAngel.java @@ -32,23 +32,36 @@ import java.util.UUID; import mage.Constants.CardType; import mage.Constants.Duration; +import mage.Constants.Outcome; import mage.Constants.Rarity; +import mage.Constants.WatcherScope; +import mage.Constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.effects.common.IndestructibleTargetEffect; +import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.filter.FilterPermanent; import mage.filter.predicate.permanent.AnotherPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; import mage.target.Target; import mage.target.TargetPermanent; +import mage.watchers.WatcherImpl; /** * @author Loki */ public class AegisAngel extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent("another target permanent"); + + static { + filter.add(new AnotherPredicate()); + } + public AegisAngel(UUID ownerId) { super(ownerId, 1, "Aegis Angel", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{W}{W}"); this.expansionSetCode = "M12"; @@ -60,13 +73,13 @@ public class AegisAngel extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); // When Aegis Angel enters the battlefield, another target permanent is indestructible for as long as you control Aegis Angel. - FilterPermanent filter = new FilterPermanent("another target permanent"); - filter.add(new AnotherPredicate()); - Ability ability = new EntersBattlefieldTriggeredAbility(new IndestructibleTargetEffect(Duration.WhileOnBattlefield), false); + Ability ability = new EntersBattlefieldTriggeredAbility(new AegisAngelEffect(), false); Target target = new TargetPermanent(filter); target.setRequired(true); ability.addTarget(target); this.addAbility(ability); + + this.addWatcher(new AegisAngelWatcher()); } public AegisAngel(final AegisAngel card) { @@ -79,3 +92,87 @@ public class AegisAngel extends CardImpl { } } + +class AegisAngelEffect extends ReplacementEffectImpl { + + public AegisAngelEffect() { + super(Duration.OneUse, Outcome.Benefit); + this.staticText = "another target permanent is indestructible for as long as you control {this}"; + } + + public AegisAngelEffect(AegisAngelEffect effect) { + super(effect); + } + + @Override + public AegisAngelEffect copy() { + return new AegisAngelEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + return true; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (event.getType() == GameEvent.EventType.LOST_CONTROL) { + if (event.getTargetId().equals(source.getSourceId())) { + this.used = true; + return false; + } + } + if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(source.getSourceId())) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD) { + this.used = true; + return false; + } + } + + return event.getType().equals(GameEvent.EventType.DESTROY_PERMANENT) + && this.targetPointer.getTargets(game, source).contains(event.getTargetId()); + } +} + +class AegisAngelWatcher extends WatcherImpl { + + AegisAngelWatcher() { + super("ControlLost", WatcherScope.CARD); + } + + AegisAngelWatcher(AegisAngelWatcher watcher) { + super(watcher); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.LOST_CONTROL && event.getPlayerId().equals(controllerId) && event.getTargetId().equals(sourceId)) { + condition = true; + game.replaceEvent(event); + return; + } + if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(sourceId)) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getFromZone() == Zone.BATTLEFIELD) { + condition = true; + game.replaceEvent(event); + } + } + } + + @Override + public void reset() { + //don't reset condition each turn - only when this leaves the battlefield + } + + @Override + public AegisAngelWatcher copy() { + return new AegisAngelWatcher(this); + } +}