mirror of
https://github.com/correl/mage.git
synced 2025-03-16 17:00:13 -09:00
* Some standardisation of dies trigger handling (fixes #7063 Midnight Reaper triggers when dies face down).
This commit is contained in:
parent
e1ab14e0f5
commit
2fec825523
17 changed files with 720 additions and 710 deletions
|
@ -1,7 +1,6 @@
|
||||||
package mage.cards.e;
|
package mage.cards.e;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.condition.Condition;
|
import mage.abilities.condition.Condition;
|
||||||
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
|
import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition;
|
||||||
|
@ -18,6 +17,7 @@ import mage.filter.common.FilterControlledPermanent;
|
||||||
import mage.filter.predicate.permanent.AnotherPredicate;
|
import mage.filter.predicate.permanent.AnotherPredicate;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @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."
|
// As long as you control another Wizard, Expedition Diviner has "When this creature dies, draw a card."
|
||||||
this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect(
|
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.\""
|
condition, "As long as you control another Wizard, {this} has \"When this creature dies, draw a card.\""
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mage.cards.f;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.condition.common.EquippedSourceCondition;
|
import mage.abilities.condition.common.EquippedSourceCondition;
|
||||||
import mage.abilities.decorator.ConditionalContinuousEffect;
|
import mage.abilities.decorator.ConditionalContinuousEffect;
|
||||||
|
@ -19,6 +18,7 @@ import mage.constants.SubType;
|
||||||
import mage.target.common.TargetAnyTarget;
|
import mage.target.common.TargetAnyTarget;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @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.
|
// 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")
|
new DamageTargetEffect(xValue).setText("it deals damage equal to its power to any target")
|
||||||
);
|
);
|
||||||
ability.addTarget(new TargetAnyTarget());
|
ability.addTarget(new TargetAnyTarget());
|
||||||
|
|
|
@ -3,7 +3,6 @@ package mage.cards.g;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DiesCreatureTriggeredAbility;
|
import mage.abilities.common.DiesCreatureTriggeredAbility;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.common.EntersBattlefieldAbility;
|
import mage.abilities.common.EntersBattlefieldAbility;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||||
|
@ -22,6 +21,7 @@ import mage.game.permanent.Permanent;
|
||||||
import mage.game.permanent.token.GrakmawSkyclaveRavagerToken;
|
import mage.game.permanent.token.GrakmawSkyclaveRavagerToken;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @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.
|
// 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) {
|
private GrakmawSkyclaveRavager(final GrakmawSkyclaveRavager card) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mage.cards.g;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
|
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
|
@ -12,6 +11,7 @@ import mage.counters.CounterType;
|
||||||
import mage.target.common.TargetControlledCreaturePermanent;
|
import mage.target.common.TargetControlledCreaturePermanent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @author TheElk801
|
||||||
|
@ -26,7 +26,7 @@ public final class GuulDrazMucklord extends CardImpl {
|
||||||
this.toughness = new MageInt(3);
|
this.toughness = new MageInt(3);
|
||||||
|
|
||||||
// When Guul Draz Mucklord dies, put a +1/+1 counter on target creature you control.
|
// 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());
|
ability.addTarget(new TargetControlledCreaturePermanent());
|
||||||
this.addAbility(ability);
|
this.addAbility(ability);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mage.cards.l;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.common.delayed.ReflexiveTriggeredAbility;
|
import mage.abilities.common.delayed.ReflexiveTriggeredAbility;
|
||||||
import mage.abilities.costs.Cost;
|
import mage.abilities.costs.Cost;
|
||||||
|
@ -19,6 +18,7 @@ import mage.players.Player;
|
||||||
import mage.target.common.TargetAnyTarget;
|
import mage.target.common.TargetAnyTarget;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @author TheElk801
|
||||||
|
@ -39,7 +39,7 @@ public final class LeylineTyrant extends CardImpl {
|
||||||
this.addAbility(new SimpleStaticAbility(new LeylineTyrantManaEffect()));
|
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.
|
// 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) {
|
private LeylineTyrant(final LeylineTyrant card) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ public final class ShrivelingRot extends CardImpl {
|
||||||
// Choose one -
|
// Choose one -
|
||||||
// Until end of turn, whenever a creature is dealt damage, destroy it.
|
// Until end of turn, whenever a creature is dealt damage, destroy it.
|
||||||
this.getSpellAbility().addEffect(new CreateDelayedTriggeredAbilityEffect(new ShrivelingRotDestroyTriggeredAbility()));
|
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.
|
// Until end of turn, whenever a creature dies, that creature's controller loses life equal to its toughness.
|
||||||
Mode mode = new Mode();
|
Mode mode = new Mode();
|
||||||
mode.addEffect(new CreateDelayedTriggeredAbilityEffect(new ShrivelingRotLoseLifeTriggeredAbility()));
|
mode.addEffect(new CreateDelayedTriggeredAbilityEffect(new ShrivelingRotLoseLifeTriggeredAbility()));
|
||||||
|
|
|
@ -102,8 +102,8 @@ class TimeToFeedTextEffect extends OneShotEffect {
|
||||||
|
|
||||||
class TimeToFeedDiesTriggeredAbility extends DelayedTriggeredAbility {
|
class TimeToFeedDiesTriggeredAbility extends DelayedTriggeredAbility {
|
||||||
|
|
||||||
private UUID watchedCreatureId;
|
private final UUID watchedCreatureId;
|
||||||
private int zoneChangeCounter;
|
private final int zoneChangeCounter;
|
||||||
|
|
||||||
public TimeToFeedDiesTriggeredAbility(UUID watchedCreatureId, int zoneChangeCounter) {
|
public TimeToFeedDiesTriggeredAbility(UUID watchedCreatureId, int zoneChangeCounter) {
|
||||||
super(new GainLifeEffect(3), Duration.EndOfTurn, false);
|
super(new GainLifeEffect(3), Duration.EndOfTurn, false);
|
||||||
|
|
|
@ -2,7 +2,6 @@ package mage.cards.t;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.DiesTriggeredAbility;
|
|
||||||
import mage.abilities.common.LandfallAbility;
|
import mage.abilities.common.LandfallAbility;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.common.ExileTargetForSourceEffect;
|
import mage.abilities.effects.common.ExileTargetForSourceEffect;
|
||||||
|
@ -20,6 +19,7 @@ import mage.target.common.TargetCardInYourGraveyard;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.abilities.common.DiesSourceTriggeredAbility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @author TheElk801
|
||||||
|
@ -50,7 +50,7 @@ public final class TroveWarden extends CardImpl {
|
||||||
this.addAbility(ability);
|
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.
|
// 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) {
|
private TroveWarden(final TroveWarden card) {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,11 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
public class GrimHaruspexTest extends CardTestPlayerBase {
|
public class GrimHaruspexTest extends CardTestPlayerBase {
|
||||||
@Test
|
@Test
|
||||||
public void testMorphed() {
|
public void testMorphed() {
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
|
||||||
addCard(Zone.HAND, playerA, "Wrath of God");
|
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.HAND, playerA, "Grim Haruspex");
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
|
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
|
||||||
|
|
||||||
|
@ -19,6 +23,8 @@ public class GrimHaruspexTest extends CardTestPlayerBase {
|
||||||
setStopAt(1, PhaseStep.END_COMBAT);
|
setStopAt(1, PhaseStep.END_COMBAT);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
|
||||||
assertGraveyardCount(playerA, "Grim Haruspex", 1);
|
assertGraveyardCount(playerA, "Grim Haruspex", 1);
|
||||||
assertHandCount(playerA, 0);
|
assertHandCount(playerA, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,8 @@ import mage.util.CardUtil;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.permanent.PermanentToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -222,4 +224,37 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
||||||
return optional;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package mage.abilities.common;
|
package mage.abilities.common;
|
||||||
|
|
||||||
|
import mage.MageObject;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
@ -81,6 +82,11 @@ public class DiesCreatureTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
|
||||||
|
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
return "Whenever " + filter.getMessage() + " dies, " + super.getRule();
|
return "Whenever " + filter.getMessage() + " dies, " + super.getRule();
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
package mage.abilities.common;
|
package mage.abilities.common;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.ZoneChangeEvent;
|
import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.game.permanent.Permanent;
|
|
||||||
import mage.game.permanent.PermanentToken;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -26,48 +25,15 @@ public class DiesSourceTriggeredAbility extends ZoneChangeTriggeredAbility {
|
||||||
super(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
|
@Override
|
||||||
public DiesSourceTriggeredAbility copy() {
|
public DiesSourceTriggeredAbility copy() {
|
||||||
return new DiesSourceTriggeredAbility(this);
|
return new DiesSourceTriggeredAbility(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
if (super.checkTrigger(event, game)) {
|
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
if (zEvent.isDiesEvent() && event.getTargetId().equals(getSourceId())) {
|
||||||
if (zEvent.getTarget().isTransformable()) {
|
|
||||||
if (!zEvent.getTarget().getAbilities().contains(this)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Effect effect : getEffects()) {
|
for (Effect effect : getEffects()) {
|
||||||
effect.setValue("permanentLeftBattlefield", zEvent.getTarget());
|
effect.setValue("permanentLeftBattlefield", zEvent.getTarget());
|
||||||
}
|
}
|
||||||
|
@ -75,5 +41,12 @@ public class DiesSourceTriggeredAbility extends ZoneChangeTriggeredAbility {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
|
||||||
|
return TriggeredAbilityImpl.isInUseableZoneDiesTrigger(this, event, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,31 +41,15 @@ public class DiesThisOrAnotherCreatureOrPlaneswalkerTriggeredAbility extends Tri
|
||||||
public boolean checkEventType(GameEvent event, Game game) {
|
public boolean checkEventType(GameEvent event, Game game) {
|
||||||
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
|
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
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||||
|
// if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
|
//
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zEvent.isDiesEvent()) {
|
if (zEvent.isDiesEvent()) {
|
||||||
if (zEvent.getTarget() != null) {
|
if (zEvent.getTarget() != null) {
|
||||||
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
|
if (zEvent.getTarget().getId().equals(this.getSourceId())) {
|
||||||
|
@ -80,6 +64,23 @@ public class DiesThisOrAnotherCreatureOrPlaneswalkerTriggeredAbility extends Tri
|
||||||
return false;
|
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
|
@Override
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
return "Whenever {this} or another " + filter.getMessage() + " dies, " + super.getRule();
|
return "Whenever {this} or another " + filter.getMessage() + " dies, " + super.getRule();
|
||||||
|
|
|
@ -48,30 +48,14 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
|
||||||
return event.getType() == GameEvent.EventType.ZONE_CHANGE;
|
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
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||||
|
//
|
||||||
if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
|
// if (game.getPermanentOrLKIBattlefield(getSourceId()) == null) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if (zEvent.isDiesEvent()) {
|
if (zEvent.isDiesEvent()) {
|
||||||
if (zEvent.getTarget() != null) {
|
if (zEvent.getTarget() != null) {
|
||||||
if (!applyFilterOnSource && zEvent.getTarget().getId().equals(this.getSourceId())) {
|
if (!applyFilterOnSource && zEvent.getTarget().getId().equals(this.getSourceId())) {
|
||||||
|
@ -85,6 +69,24 @@ public class DiesThisOrAnotherCreatureTriggeredAbility extends TriggeredAbilityI
|
||||||
}
|
}
|
||||||
return false;
|
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
|
@Override
|
||||||
public String getRule() {
|
public String getRule() {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue