* 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 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);

View file

@ -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);