* Some standardisation of dies trigger handling (fixes #7063 Midnight Reaper triggers when dies face down).

This commit is contained in:
LevelX2 2020-09-18 16:15:21 +02:00
parent e1ab14e0f5
commit 2fec825523
17 changed files with 720 additions and 710 deletions

View file

@ -1,7 +1,6 @@
package mage.cards.e;
import mage.MageInt;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
@ -18,6 +17,7 @@ import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -45,7 +45,7 @@ public final class ExpeditionDiviner extends CardImpl {
// As long as you control another Wizard, Expedition Diviner has "When this creature dies, draw a card."
this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(
new GainAbilitySourceEffect(new DiesTriggeredAbility(new DrawCardSourceControllerEffect(1))),
new GainAbilitySourceEffect(new DiesSourceTriggeredAbility(new DrawCardSourceControllerEffect(1))),
condition, "As long as you control another Wizard, {this} has \"When this creature dies, draw a card.\""
)));
}

View file

@ -2,7 +2,6 @@ package mage.cards.f;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.EquippedSourceCondition;
import mage.abilities.decorator.ConditionalContinuousEffect;
@ -19,6 +18,7 @@ import mage.constants.SubType;
import mage.target.common.TargetAnyTarget;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -42,7 +42,7 @@ public final class FirebladeCharger extends CardImpl {
)));
// When Fireblade Charger dies, it deals damage equal to its power to any target.
Ability ability = new DiesTriggeredAbility(
Ability ability = new DiesSourceTriggeredAbility(
new DamageTargetEffect(xValue).setText("it deals damage equal to its power to any target")
);
ability.addTarget(new TargetAnyTarget());

View file

@ -3,7 +3,6 @@ package mage.cards.g;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesCreatureTriggeredAbility;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
@ -22,6 +21,7 @@ import mage.game.permanent.Permanent;
import mage.game.permanent.token.GrakmawSkyclaveRavagerToken;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -59,7 +59,7 @@ public final class GrakmawSkyclaveRavager extends CardImpl {
));
// When Grakmaw dies, create an X/X black and green Hydra creature token, where X is the number of +1/+1 counters on Grakmaw.
this.addAbility(new DiesTriggeredAbility(new GrakmawSkyclaveRavagerEffect()));
this.addAbility(new DiesSourceTriggeredAbility(new GrakmawSkyclaveRavagerEffect()));
}
private GrakmawSkyclaveRavager(final GrakmawSkyclaveRavager card) {

View file

@ -2,7 +2,6 @@ package mage.cards.g;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -12,6 +11,7 @@ import mage.counters.CounterType;
import mage.target.common.TargetControlledCreaturePermanent;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -26,7 +26,7 @@ public final class GuulDrazMucklord extends CardImpl {
this.toughness = new MageInt(3);
// When Guul Draz Mucklord dies, put a +1/+1 counter on target creature you control.
Ability ability = new DiesTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance()));
Ability ability = new DiesSourceTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance()));
ability.addTarget(new TargetControlledCreaturePermanent());
this.addAbility(ability);
}

View file

@ -2,7 +2,6 @@ package mage.cards.l;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.delayed.ReflexiveTriggeredAbility;
import mage.abilities.costs.Cost;
@ -19,6 +18,7 @@ import mage.players.Player;
import mage.target.common.TargetAnyTarget;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -39,7 +39,7 @@ public final class LeylineTyrant extends CardImpl {
this.addAbility(new SimpleStaticAbility(new LeylineTyrantManaEffect()));
// When Leyline Tyrant dies, you may pay any amount of {R}. When you do, it deals that much damage to any target.
this.addAbility(new DiesTriggeredAbility(new LeylineTyrantDamageEffect()));
this.addAbility(new DiesSourceTriggeredAbility(new LeylineTyrantDamageEffect()));
}
private LeylineTyrant(final LeylineTyrant card) {

View file

@ -35,6 +35,7 @@ public final class ShrivelingRot extends CardImpl {
// Choose one -
// Until end of turn, whenever a creature is dealt damage, destroy it.
this.getSpellAbility().addEffect(new CreateDelayedTriggeredAbilityEffect(new ShrivelingRotDestroyTriggeredAbility()));
// Until end of turn, whenever a creature dies, that creature's controller loses life equal to its toughness.
Mode mode = new Mode();
mode.addEffect(new CreateDelayedTriggeredAbilityEffect(new ShrivelingRotLoseLifeTriggeredAbility()));

View file

@ -102,8 +102,8 @@ class TimeToFeedTextEffect extends OneShotEffect {
class TimeToFeedDiesTriggeredAbility extends DelayedTriggeredAbility {
private UUID watchedCreatureId;
private int zoneChangeCounter;
private final UUID watchedCreatureId;
private final int zoneChangeCounter;
public TimeToFeedDiesTriggeredAbility(UUID watchedCreatureId, int zoneChangeCounter) {
super(new GainLifeEffect(3), Duration.EndOfTurn, false);

View file

@ -2,7 +2,6 @@ package mage.cards.t;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.LandfallAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileTargetForSourceEffect;
@ -20,6 +19,7 @@ import mage.target.common.TargetCardInYourGraveyard;
import mage.util.CardUtil;
import java.util.UUID;
import mage.abilities.common.DiesSourceTriggeredAbility;
/**
* @author TheElk801
@ -50,7 +50,7 @@ public final class TroveWarden extends CardImpl {
this.addAbility(ability);
// When Trove Warden dies, put each permanent card exiled with it onto the battlefield under the control of that card's owner.
this.addAbility(new DiesTriggeredAbility(new TroveWardenEffect()));
this.addAbility(new DiesSourceTriggeredAbility(new TroveWardenEffect()));
}
private TroveWarden(final TroveWarden card) {

View file

@ -8,7 +8,11 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
public class GrimHaruspexTest extends CardTestPlayerBase {
@Test
public void testMorphed() {
setStrictChooseMode(true);
addCard(Zone.HAND, playerA, "Wrath of God");
// Morph {B}
// Whenever another nontoken creature you control dies, draw a card.
addCard(Zone.HAND, playerA, "Grim Haruspex");
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
@ -19,6 +23,8 @@ public class GrimHaruspexTest extends CardTestPlayerBase {
setStopAt(1, PhaseStep.END_COMBAT);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, "Grim Haruspex", 1);
assertHandCount(playerA, 0);
}

View file

@ -0,0 +1,62 @@
package org.mage.test.cards.facedown;
import mage.cards.Card;
import mage.constants.EmptyNames;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class TriggerTest extends CardTestPlayerBase {
/**
* Midnight Reaper triggers when dies face down #7063
* Ixidron has turned Midnight Reaper and Balduvian Bears face down:
*
*/
// test that cards imprinted using Summoner's Egg are face down
@Test
public void testReaperDoesNotTriggerDiesTriggerFaceDown() {
setStrictChooseMode(true);
addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
// As Ixidron enters the battlefield, turn all other nontoken creatures face down.
// Ixidron's power and toughness are each equal to the number of face-down creatures on the battlefield.
addCard(Zone.HAND, playerA, "Ixidron"); // Creature {3}{U}{U} (*/*)
// Whenever a nontoken creature you control dies, Midnight Reaper deals 1 damage to you and you draw a card.
addCard(Zone.BATTLEFIELD, playerA, "Midnight Reaper"); // Creature {2}{B}
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);
addCard(Zone.HAND, playerB, "Lightning Bolt"); // Instant 3 damage
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Ixidron");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Lightning Bolt", EmptyNames.FACE_DOWN_CREATURE.toString());
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerB, "Lightning Bolt", 1);
assertGraveyardCount(playerA, "Midnight Reaper", 1);
assertGraveyardCount(playerA, "Ixidron", 1);
assertHandCount(playerA, 0);
assertLife(playerA, 20);
}
}

View file

@ -13,6 +13,8 @@ import mage.util.CardUtil;
import java.util.Locale;
import java.util.UUID;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
/**
* @author BetaSteward_at_googlemail.com
@ -222,4 +224,37 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return optional;
}
public static boolean isInUseableZoneDiesTrigger(TriggeredAbility source, GameEvent event, Game game) {
// Get the source permanent of the ability
MageObject sourceObject = null;
if (game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
sourceObject = game.getPermanent(source.getSourceId());
} else {
if (game.getShortLivingLKI(source.getSourceId(), Zone.BATTLEFIELD)) {
sourceObject = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
}
if (sourceObject == null) { // source is no permanent
sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null || sourceObject.isPermanent()) {
return false; // No source object found => ability is not valid
}
}
if (!source.hasSourceObjectAbility(game, sourceObject, event)) {
return false; // the permanent does currently not have or before it dies the ability so no trigger
}
// check now it is in graveyard (only if it is no token and was the target itself)
if (source.getSourceId().equals(event.getTargetId()) // source is also the target
&& !(sourceObject instanceof PermanentToken) // it's no token
&& sourceObject.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(source.getSourceId())) { // It's in the next zone
Zone after = game.getState().getZone(source.getSourceId());
if (after == null || !Zone.GRAVEYARD.match(after)) { // Zone is not the graveyard
return false; // Moving to graveyard was replaced so no trigger
}
}
return true;
}
}

View file

@ -1,5 +1,6 @@
package mage.abilities.common;
import mage.MageObject;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
@ -81,6 +82,11 @@ public class DiesCreatureTriggeredAbility extends TriggeredAbilityImpl {
return false;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
}
@Override
public String getRule() {
return "Whenever " + filter.getMessage() + " dies, " + super.getRule();

View file

@ -1,13 +1,12 @@
package mage.abilities.common;
import mage.MageObject;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
/**
* @author BetaSteward_at_googlemail.com
@ -26,48 +25,15 @@ public class DiesSourceTriggeredAbility extends ZoneChangeTriggeredAbility {
super(ability);
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
// check it was previously on battlefield
Permanent before = ((ZoneChangeEvent) event).getTarget();
if (before == null) {
return false;
}
if (!this.hasSourceObjectAbility(game, before, event)) { // the permanent does not have the ability so no trigger
return false;
}
// check now it is in graveyard if it is no token
if (!(before instanceof PermanentToken) && before.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(sourceId)) {
Zone after = game.getState().getZone(sourceId);
return after != null && Zone.GRAVEYARD.match(after);
} else {
// Already moved to another zone, so guess it's ok
return true;
}
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
if (super.checkEventType(event, game)) {
return ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD;
}
return false;
}
@Override
public DiesSourceTriggeredAbility copy() {
return new DiesSourceTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTarget().isTransformable()) {
if (!zEvent.getTarget().getAbilities().contains(this)) {
return false;
}
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.isDiesEvent() && event.getTargetId().equals(getSourceId())) {
for (Effect effect : getEffects()) {
effect.setValue("permanentLeftBattlefield", zEvent.getTarget());
}
@ -75,5 +41,12 @@ public class DiesSourceTriggeredAbility extends ZoneChangeTriggeredAbility {
}
return false;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
}
}

View file

@ -41,31 +41,15 @@ public class DiesThisOrAnotherCreatureOrPlaneswalkerTriggeredAbility extends Tri
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
Permanent sourcePermanent = null;
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent = game.getPermanent(getSourceId());
} else {
if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
}
}
if (sourcePermanent == null) {
return false;
}
return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
// if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
// return false;
// }
if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
return false;
}
//
if (zEvent.isDiesEvent()) {
if (zEvent.getTarget() != null) {
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
@ -80,6 +64,23 @@ public class DiesThisOrAnotherCreatureOrPlaneswalkerTriggeredAbility extends Tri
return false;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
// Permanent sourcePermanent = null;
// if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
// sourcePermanent = game.getPermanent(getSourceId());
// } else {
// if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
// sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
// }
// }
// if (sourcePermanent == null) {
// return false;
// }
// return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
public String getRule() {
return "Whenever {this} or another " + filter.getMessage() + " dies, " + super.getRule();

View file

@ -48,30 +48,14 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
Permanent sourcePermanent = null;
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent = game.getPermanent(getSourceId());
} else {
if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
}
}
if (sourcePermanent == null) {
return false;
}
return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
return false;
}
//
// if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
// return false;
// }
//
if (zEvent.isDiesEvent()) {
if (zEvent.getTarget() != null) {
if (!applyFilterOnSource && zEvent.getTarget().getId().equals(this.getSourceId())) {
@ -85,6 +69,24 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
}
return false;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
//
// Permanent sourcePermanent = null;
// if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
// sourcePermanent = game.getPermanent(getSourceId());
// } else {
// if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
// sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
// }
// }
// if (sourcePermanent == null) {
// return false;
// }
// return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
public String getRule() {

View file

@ -1,79 +0,0 @@
package mage.abilities.common;
import mage.MageObject;
import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentToken;
/**
* @author BetaSteward_at_googlemail.com
*/
public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility {
public DiesTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, Zone.GRAVEYARD, effect, "When {this} dies, ", optional);
}
public DiesTriggeredAbility(Effect effect) {
this(effect, false);
}
public DiesTriggeredAbility(DiesTriggeredAbility ability) {
super(ability);
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
// check it was previously on battlefield
Permanent before = ((ZoneChangeEvent) event).getTarget();
if (before == null) {
return false;
}
if (!this.hasSourceObjectAbility(game, before, event)) { // the permanent does not have the ability so no trigger
return false;
}
// check now it is in graveyard if it is no token
if (!(before instanceof PermanentToken) && before.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(sourceId)) {
Zone after = game.getState().getZone(sourceId);
return after != null && Zone.GRAVEYARD.match(after);
} else {
// Already moved to another zone, so guess it's ok
return true;
}
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
if (super.checkEventType(event, game)) {
return ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD;
}
return false;
}
@Override
public DiesTriggeredAbility copy() {
return new DiesTriggeredAbility(this);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTarget().isTransformable()) {
if (!zEvent.getTarget().getAbilities().contains(this)) {
return false;
}
}
for (Effect effect : getEffects()) {
effect.setValue("permanentLeftBattlefield", zEvent.getTarget());
}
return true;
}
return false;
}
}