From 6a03522ee8f3ce3e9b9dab6c23a493df5bbb4d40 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 27 Apr 2016 16:52:15 +0200 Subject: [PATCH] * Unearth - Fixed a problem with exiling the unearthed creature (fixes #1912). --- .../sets/darkascension/DungeonGeists.java | 18 ++++++------- .../src/mage/sets/tempest/StarkeOfRath.java | 21 ++++++++------- .../main/java/mage/abilities/AbilityImpl.java | 2 +- .../abilities/keyword/UnearthAbility.java | 26 +++++++++---------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Mage.Sets/src/mage/sets/darkascension/DungeonGeists.java b/Mage.Sets/src/mage/sets/darkascension/DungeonGeists.java index e7578f9772..899254a323 100644 --- a/Mage.Sets/src/mage/sets/darkascension/DungeonGeists.java +++ b/Mage.Sets/src/mage/sets/darkascension/DungeonGeists.java @@ -29,6 +29,7 @@ package mage.sets.darkascension; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; @@ -115,22 +116,21 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl { return event.getType() == GameEvent.EventType.UNTAP || event.getType() == GameEvent.EventType.ZONE_CHANGE || event.getType() == GameEvent.EventType.LOST_CONTROL; } - @Override public boolean applies(GameEvent event, Ability source, Game game) { // Source must be on the battlefield (it's neccessary to check here because if as response to the enter // the battlefield triggered ability the source dies (or will be exiled), then the ZONE_CHANGE or LOST_CONTROL // event will happen before this effect is applied ever) - Permanent sourcePermanent = (Permanent) source.getSourceObjectIfItStillExists(game); - if (sourcePermanent == null || !sourcePermanent.getControllerId().equals(source.getControllerId())) { + MageObject sourceObject = source.getSourceObjectIfItStillExists(game); + if (!(sourceObject instanceof Permanent) || !((Permanent) sourceObject).getControllerId().equals(source.getControllerId())) { discard(); return false; } - switch(event.getType()) { + switch (event.getType()) { case ZONE_CHANGE: // end effect if source does a zone move if (event.getTargetId().equals(source.getSourceId())) { - ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; if (zEvent.getFromZone() == Zone.BATTLEFIELD) { discard(); return false; @@ -147,14 +147,14 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl { discard(); return false; } - } + } break; case LOST_CONTROL: // end effect if source control is changed if (event.getTargetId().equals(source.getSourceId())) { discard(); return false; - } + } break; } return false; @@ -163,7 +163,7 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl { class DungeonGeistsWatcher extends Watcher { - DungeonGeistsWatcher () { + DungeonGeistsWatcher() { super("ControlLost", WatcherScope.CARD); } @@ -179,7 +179,7 @@ class DungeonGeistsWatcher extends Watcher { return; } if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(sourceId)) { - ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; if (zEvent.getFromZone() == Zone.BATTLEFIELD) { condition = true; game.replaceEvent(event); diff --git a/Mage.Sets/src/mage/sets/tempest/StarkeOfRath.java b/Mage.Sets/src/mage/sets/tempest/StarkeOfRath.java index 3dc6b963cb..acdaf2f352 100644 --- a/Mage.Sets/src/mage/sets/tempest/StarkeOfRath.java +++ b/Mage.Sets/src/mage/sets/tempest/StarkeOfRath.java @@ -29,6 +29,7 @@ package mage.sets.tempest; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; @@ -59,13 +60,13 @@ import mage.target.targetpointer.FixedTarget; public class StarkeOfRath extends CardImpl { private static final FilterPermanent filter = new FilterPermanent("artifact or creature"); - + static { filter.add(Predicates.or( new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.CREATURE))); } - + public StarkeOfRath(UUID ownerId) { super(ownerId, 205, "Starke of Rath", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{R}{R}"); this.expansionSetCode = "TMP"; @@ -79,7 +80,7 @@ public class StarkeOfRath extends CardImpl { Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new StarkeOfRathEffect(), new TapSourceCost()); ability.addTarget(new TargetPermanent(filter)); this.addAbility(ability); - + } public StarkeOfRath(final StarkeOfRath card) { @@ -93,31 +94,31 @@ public class StarkeOfRath extends CardImpl { } class StarkeOfRathEffect extends OneShotEffect { - + public StarkeOfRathEffect() { super(Outcome.DestroyPermanent); this.staticText = "Destroy target artifact or creature. That permanent's controller gains control of {this}"; } - + public StarkeOfRathEffect(final StarkeOfRathEffect effect) { super(effect); } - + @Override public StarkeOfRathEffect copy() { return new StarkeOfRathEffect(this); } - + @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); + Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); if (targetPermanent != null) { targetPermanent.destroy(source.getSourceId(), game, false); } - Permanent sourcePermanent = (Permanent) source.getSourceObjectIfItStillExists(game); - if (sourcePermanent != null && targetPermanent != null) { + MageObject sourceObject = source.getSourceObjectIfItStillExists(game); + if ((sourceObject instanceof Permanent) && targetPermanent != null) { ContinuousEffect effect = new StarkeOfRathControlEffect(); effect.setTargetPointer(new FixedTarget(targetPermanent.getControllerId())); game.addEffect(effect, source); diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 497fc66ddb..17cdcf4e8c 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -1176,7 +1176,7 @@ public abstract class AbilityImpl implements Ability { MageObjectReference mor = new MageObjectReference(currentObject, game); if (mor.getZoneChangeCounter() == getSourceObjectZoneChangeCounter()) { // source object has meanwhile not changed zone - return sourceObject; + return currentObject; } } return null; diff --git a/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java b/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java index c8411cfb87..a688f576a4 100644 --- a/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java @@ -1,16 +1,16 @@ /* * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR @@ -20,12 +20,11 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.abilities.keyword; import mage.abilities.Ability; @@ -55,11 +54,12 @@ import mage.players.Player; * * 702.82. Unearth * - * 702.82a Unearth is an activated ability that functions while the card with unearth - * is in a graveyard. "Unearth [cost]" means "[Cost]: Return this card from your graveyard - * to the battlefield. It gains haste. Exile it at the beginning of the next end step. - * If it would leave the battlefield, exile it instead of putting it anywhere else. - * Activate this ability only any time you could cast a sorcery." + * 702.82a Unearth is an activated ability that functions while the card with + * unearth is in a graveyard. "Unearth [cost]" means "[Cost]: Return this card + * from your graveyard to the battlefield. It gains haste. Exile it at the + * beginning of the next end step. If it would leave the battlefield, exile it + * instead of putting it anywhere else. Activate this ability only any time you + * could cast a sorcery." * */ public class UnearthAbility extends ActivatedAbilityImpl { @@ -147,9 +147,9 @@ class UnearthLeavesBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (event.getTargetId().equals(source.getSourceId())) { - ZoneChangeEvent zEvent = (ZoneChangeEvent)event; + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() != Zone.EXILED) { - // started in graveyard goint to battlefield so current zone change counter has to be +1 + // started in graveyard going to battlefield so current zone change counter has to be +1 return source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId()); } }