* Unearth - Fixed a problem with exiling the unearthed creature (fixes #1912).

This commit is contained in:
LevelX2 2016-04-27 16:52:15 +02:00
parent 0d11a39fc4
commit 6a03522ee8
4 changed files with 34 additions and 33 deletions

View file

@ -29,6 +29,7 @@ package mage.sets.darkascension;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; 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; return event.getType() == GameEvent.EventType.UNTAP || event.getType() == GameEvent.EventType.ZONE_CHANGE || event.getType() == GameEvent.EventType.LOST_CONTROL;
} }
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { 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 // 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 // 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) // event will happen before this effect is applied ever)
Permanent sourcePermanent = (Permanent) source.getSourceObjectIfItStillExists(game); MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (sourcePermanent == null || !sourcePermanent.getControllerId().equals(source.getControllerId())) { if (!(sourceObject instanceof Permanent) || !((Permanent) sourceObject).getControllerId().equals(source.getControllerId())) {
discard(); discard();
return false; return false;
} }
switch(event.getType()) { switch (event.getType()) {
case ZONE_CHANGE: case ZONE_CHANGE:
// end effect if source does a zone move // end effect if source does a zone move
if (event.getTargetId().equals(source.getSourceId())) { if (event.getTargetId().equals(source.getSourceId())) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD) { if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
discard(); discard();
return false; return false;
@ -147,14 +147,14 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl {
discard(); discard();
return false; return false;
} }
} }
break; break;
case LOST_CONTROL: case LOST_CONTROL:
// end effect if source control is changed // end effect if source control is changed
if (event.getTargetId().equals(source.getSourceId())) { if (event.getTargetId().equals(source.getSourceId())) {
discard(); discard();
return false; return false;
} }
break; break;
} }
return false; return false;
@ -163,7 +163,7 @@ class DungeonGeistsEffect extends ContinuousRuleModifyingEffectImpl {
class DungeonGeistsWatcher extends Watcher { class DungeonGeistsWatcher extends Watcher {
DungeonGeistsWatcher () { DungeonGeistsWatcher() {
super("ControlLost", WatcherScope.CARD); super("ControlLost", WatcherScope.CARD);
} }
@ -179,7 +179,7 @@ class DungeonGeistsWatcher extends Watcher {
return; return;
} }
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(sourceId)) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(sourceId)) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD) { if (zEvent.getFromZone() == Zone.BATTLEFIELD) {
condition = true; condition = true;
game.replaceEvent(event); game.replaceEvent(event);

View file

@ -29,6 +29,7 @@ package mage.sets.tempest;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
@ -59,13 +60,13 @@ import mage.target.targetpointer.FixedTarget;
public class StarkeOfRath extends CardImpl { public class StarkeOfRath extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("artifact or creature"); private static final FilterPermanent filter = new FilterPermanent("artifact or creature");
static { static {
filter.add(Predicates.or( filter.add(Predicates.or(
new CardTypePredicate(CardType.ARTIFACT), new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE))); new CardTypePredicate(CardType.CREATURE)));
} }
public StarkeOfRath(UUID ownerId) { public StarkeOfRath(UUID ownerId) {
super(ownerId, 205, "Starke of Rath", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{R}{R}"); super(ownerId, 205, "Starke of Rath", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{1}{R}{R}");
this.expansionSetCode = "TMP"; this.expansionSetCode = "TMP";
@ -79,7 +80,7 @@ public class StarkeOfRath extends CardImpl {
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new StarkeOfRathEffect(), new TapSourceCost()); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new StarkeOfRathEffect(), new TapSourceCost());
ability.addTarget(new TargetPermanent(filter)); ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability); this.addAbility(ability);
} }
public StarkeOfRath(final StarkeOfRath card) { public StarkeOfRath(final StarkeOfRath card) {
@ -93,31 +94,31 @@ public class StarkeOfRath extends CardImpl {
} }
class StarkeOfRathEffect extends OneShotEffect { class StarkeOfRathEffect extends OneShotEffect {
public StarkeOfRathEffect() { public StarkeOfRathEffect() {
super(Outcome.DestroyPermanent); super(Outcome.DestroyPermanent);
this.staticText = "Destroy target artifact or creature. That permanent's controller gains control of {this}"; this.staticText = "Destroy target artifact or creature. That permanent's controller gains control of {this}";
} }
public StarkeOfRathEffect(final StarkeOfRathEffect effect) { public StarkeOfRathEffect(final StarkeOfRathEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public StarkeOfRathEffect copy() { public StarkeOfRathEffect copy() {
return new StarkeOfRathEffect(this); return new StarkeOfRathEffect(this);
} }
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) { if (targetPermanent != null) {
targetPermanent.destroy(source.getSourceId(), game, false); targetPermanent.destroy(source.getSourceId(), game, false);
} }
Permanent sourcePermanent = (Permanent) source.getSourceObjectIfItStillExists(game); MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (sourcePermanent != null && targetPermanent != null) { if ((sourceObject instanceof Permanent) && targetPermanent != null) {
ContinuousEffect effect = new StarkeOfRathControlEffect(); ContinuousEffect effect = new StarkeOfRathControlEffect();
effect.setTargetPointer(new FixedTarget(targetPermanent.getControllerId())); effect.setTargetPointer(new FixedTarget(targetPermanent.getControllerId()));
game.addEffect(effect, source); game.addEffect(effect, source);

View file

@ -1176,7 +1176,7 @@ public abstract class AbilityImpl implements Ability {
MageObjectReference mor = new MageObjectReference(currentObject, game); MageObjectReference mor = new MageObjectReference(currentObject, game);
if (mor.getZoneChangeCounter() == getSourceObjectZoneChangeCounter()) { if (mor.getZoneChangeCounter() == getSourceObjectZoneChangeCounter()) {
// source object has meanwhile not changed zone // source object has meanwhile not changed zone
return sourceObject; return currentObject;
} }
} }
return null; return null;

View file

@ -1,16 +1,16 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.keyword; package mage.abilities.keyword;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -55,11 +54,12 @@ import mage.players.Player;
* *
* 702.82. Unearth * 702.82. Unearth
* *
* 702.82a Unearth is an activated ability that functions while the card with unearth * 702.82a Unearth is an activated ability that functions while the card with
* is in a graveyard. "Unearth [cost]" means "[Cost]: Return this card from your graveyard * unearth is in a graveyard. "Unearth [cost]" means "[Cost]: Return this card
* to the battlefield. It gains haste. Exile it at the beginning of the next end step. * from your graveyard to the battlefield. It gains haste. Exile it at the
* If it would leave the battlefield, exile it instead of putting it anywhere else. * beginning of the next end step. If it would leave the battlefield, exile it
* Activate this ability only any time you could cast a sorcery." * instead of putting it anywhere else. Activate this ability only any time you
* could cast a sorcery."
* *
*/ */
public class UnearthAbility extends ActivatedAbilityImpl { public class UnearthAbility extends ActivatedAbilityImpl {
@ -147,9 +147,9 @@ class UnearthLeavesBattlefieldEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getSourceId())) { if (event.getTargetId().equals(source.getSourceId())) {
ZoneChangeEvent zEvent = (ZoneChangeEvent)event; ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() != Zone.EXILED) { 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()); return source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId());
} }
} }