mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08: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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
Add a link
Reference in a new issue