@@ -36,8 +36,10 @@
import mage.abilities.Ability;
import mage.abilities.common.ActivateAsSorceryActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
@@ -46,6 +48,7 @@
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;

@@ -68,10 +71,10 @@ public NineRingedBo(UUID ownerId) {
// {T}: Nine-Ringed Bo deals 1 damage to target Spirit creature. If that creature would die this turn, exile it instead.
Ability ability = new ActivateAsSorceryActivatedAbility(Zone.BATTLEFIELD, new DamageTargetEffect(1), new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter));
ability.addEffect(new NineRingedBoEffect());
Effect effect = new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn);
effect.setText("If that creature would die this turn, exile it instead");
ability.addEffect(effect);
this.addAbility(ability);

this.addWatcher(new DamagedByWatcher());
}

public NineRingedBo(final NineRingedBo card) {
@@ -83,45 +86,3 @@ public NineRingedBo copy() {
return new NineRingedBo(this);
}
}

class NineRingedBoEffect extends ReplacementEffectImpl {

public NineRingedBoEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If that creature would die this turn, exile it instead";
}

public NineRingedBoEffect(final NineRingedBoEffect effect) {
super(effect);
}

@Override
public NineRingedBoEffect copy() {
return new NineRingedBoEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
}
}
return false;
}
}
@@ -30,21 +30,13 @@
package mage.sets.championsofkamigawa;

import java.util.UUID;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -62,8 +54,7 @@ public YamabushisFlame(UUID ownerId) {
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());

// If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new YamabushisFlameEffect());
this.addWatcher(new DamagedByWatcher());
this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
}

public YamabushisFlame(final YamabushisFlame card) {
@@ -75,46 +66,3 @@ public YamabushisFlame copy() {
return new YamabushisFlame(this);
}
}

class YamabushisFlameEffect extends ReplacementEffectImpl {

public YamabushisFlameEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If a creature dealt damage this way would die this turn, exile it instead";
}

public YamabushisFlameEffect(final YamabushisFlameEffect effect) {
super(effect);
}

@Override
public YamabushisFlameEffect copy() {
return new YamabushisFlameEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
DamagedByWatcher watcher =
(DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null)
return watcher.damagedCreatures.contains(event.getTargetId());
}
return false;
}

}
@@ -37,6 +37,7 @@
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageAllEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
@@ -61,8 +62,7 @@ public YamabushisStorm(UUID ownerId) {
// Yamabushi's Storm deals 1 damage to each creature.
this.getSpellAbility().addEffect(new DamageAllEffect(1, new FilterCreaturePermanent()));
// If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new YamabushisStormEffect());
this.addWatcher(new DamagedByWatcher());
this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
}

public YamabushisStorm(final YamabushisStorm card) {
@@ -31,19 +31,18 @@

import mage.abilities.Ability;
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -60,7 +59,9 @@ public Disintegrate(UUID ownerId) {
// Disintegrate deals X damage to target creature or player. That creature can't be regenerated this turn. If the creature would die this turn, exile it instead.
this.getSpellAbility().addEffect(new DamageTargetEffect(new ManacostVariableValue()));
this.getSpellAbility().addEffect(new DisintegrateCantRegenerateEffect());
this.getSpellAbility().addEffect(new DisintegrateExileEffect());
Effect effect = new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn);
effect.setText("If the creature would die this turn, exile it instead");
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
}

@@ -111,45 +112,3 @@ public boolean applies(GameEvent event, Ability source, Game game) {
return false;
}
}

class DisintegrateExileEffect extends ReplacementEffectImpl {

public DisintegrateExileEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If the creature would die this turn, exile it instead";
}

public DisintegrateExileEffect(final DisintegrateExileEffect effect) {
super(effect);
}

@Override
public DisintegrateExileEffect copy() {
return new DisintegrateExileEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (GameEvent.EventType.ZONE_CHANGE.equals(event.getType()) && ((ZoneChangeEvent) event).isDiesEvent()) {
UUID targetId = getTargetPointer().getFirst(game, source);
if (targetId != null) {
return targetId.equals(event.getTargetId());
}
}
return false;
}
}
@@ -40,7 +40,6 @@
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -28,21 +28,14 @@
package mage.sets.mirrodinbesieged;

import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;

@@ -56,9 +49,10 @@ public RedSunsZenith(UUID ownerId) {
super(ownerId, 74, "Red Sun's Zenith", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{X}{R}");
this.expansionSetCode = "MBS";
this.color.setRed(true);

this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
this.getSpellAbility().addEffect(new DamageTargetEffect(new ManacostVariableValue()));
this.getSpellAbility().addEffect(new RedSunsZenithEffect());
this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
this.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance());
this.addWatcher(new DamagedByWatcher());
}
@@ -73,45 +67,3 @@ public RedSunsZenith copy() {
}

}

class RedSunsZenithEffect extends ReplacementEffectImpl {

public RedSunsZenithEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If a creature dealt damage this way would die this turn, exile it instead";
}

public RedSunsZenithEffect(final RedSunsZenithEffect effect) {
super(effect);
}

@Override
public RedSunsZenithEffect copy() {
return new RedSunsZenithEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null)
return watcher.damagedCreatures.contains(event.getTargetId());
}
return false;
}

}
@@ -42,7 +42,6 @@
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -60,7 +59,6 @@ public EngulfingFlames(UUID ownerId) {
this.getSpellAbility().addEffect(new DamageTargetEffect(1));
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new EngulfingFlamesEffect());
this.addWatcher(new DamagedByWatcher());
// Flashback {3}{R}
this.addAbility(new FlashbackAbility(new ManaCostsImpl("{3}{R}"), TimingRule.INSTANT));
}
@@ -30,21 +30,13 @@
package mage.sets.returntoravnica;

import java.util.UUID;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -62,8 +54,7 @@ public AnnihilatingFire(UUID ownerId) {
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());

// If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new AnnihilatingFireEffect());
this.addWatcher(new DamagedByWatcher());
this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
}

public AnnihilatingFire(final AnnihilatingFire card) {
@@ -75,45 +66,3 @@ public AnnihilatingFire copy() {
return new AnnihilatingFire(this);
}
}

class AnnihilatingFireEffect extends ReplacementEffectImpl {

public AnnihilatingFireEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If a creature dealt damage this way would die this turn, exile it instead";
}

public AnnihilatingFireEffect(final AnnihilatingFireEffect effect) {
super(effect);
}

@Override
public AnnihilatingFireEffect copy() {
return new AnnihilatingFireEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
}
}
return false;
}
}
@@ -28,21 +28,14 @@
package mage.sets.shardsofalara;

import java.util.UUID;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -60,8 +53,9 @@ public MagmaSpray(UUID ownerId) {
this.getSpellAbility().addEffect(new DamageTargetEffect(2));
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
// If that creature would die this turn, exile it instead.
this.getSpellAbility().addEffect(new MagmaSprayEffect());
this.addWatcher(new DamagedByWatcher());
Effect effect = new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn);
effect.setText("If that creature would die this turn, exile it instead");
this.getSpellAbility().addEffect(effect);
}

public MagmaSpray(final MagmaSpray card) {
@@ -73,45 +67,3 @@ public MagmaSpray copy() {
return new MagmaSpray(this);
}
}

class MagmaSprayEffect extends ReplacementEffectImpl {

public MagmaSprayEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If that creature would die this turn, exile it instead";
}

public MagmaSprayEffect(final MagmaSprayEffect effect) {
super(effect);
}

@Override
public MagmaSprayEffect copy() {
return new MagmaSprayEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
}
}
return false;
}
}
@@ -46,6 +46,7 @@
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.token.Token;
import mage.target.common.TargetCreaturePermanent;
@@ -124,10 +125,13 @@ public SkeletonizeDelayedTriggeredAbility copy() {

@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", this.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
if (event.getType().equals(EventType.ZONE_CHANGE)) {
ZoneChangeEvent zce = (ZoneChangeEvent) event;
if (zce.isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", this.getSourceId());
if (watcher != null) {
return watcher.wasDamaged(zce.getTarget());
}
}
}
return false;
@@ -28,14 +28,14 @@
package mage.sets.tenth;

import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
@@ -70,10 +70,10 @@ public Incinerate copy() {
}
}

class IncinerateEffect extends ReplacementEffectImpl {
class IncinerateEffect extends ContinuousRuleModifiyingEffectImpl {

public IncinerateEffect() {
super(Duration.EndOfTurn, Outcome.Detriment);
super(Duration.EndOfTurn, Outcome.Detriment, true, false);
staticText = "A creature dealt damage this way can't be regenerated this turn";
}

@@ -91,17 +91,12 @@ public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
return watcher.wasDamaged(event.getTargetId(), game);
}
}
return false;
@@ -28,20 +28,13 @@
package mage.sets.theros;

import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageAllEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.watchers.common.DamagedByWatcher;

/**
*
@@ -59,8 +52,7 @@ public AngerOfTheGods(UUID ownerId) {
this.getSpellAbility().addEffect(new DamageAllEffect(3, new FilterCreaturePermanent()));

//If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new AngerOfTheGodsEffect());
this.addWatcher(new DamagedByWatcher());
this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
}

public AngerOfTheGods(final AngerOfTheGods card) {
@@ -72,48 +64,3 @@ public AngerOfTheGods copy() {
return new AngerOfTheGods(this);
}
}


class AngerOfTheGodsEffect extends ReplacementEffectImpl {

public AngerOfTheGodsEffect() {
super(Duration.EndOfTurn, Outcome.Exile);
staticText = "If a creature dealt damage this way would die this turn, exile it instead";
}

public AngerOfTheGodsEffect(final AngerOfTheGodsEffect effect) {
super(effect);
}

@Override
public AngerOfTheGodsEffect copy() {
return new AngerOfTheGodsEffect(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
if (permanent != null) {
return permanent.moveToExile(null, "", source.getSourceId(), game);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) {
DamagedByWatcher watcher =
(DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null){
return watcher.damagedCreatures.contains(event.getTargetId());
}
}
return false;
}

}
@@ -29,7 +29,7 @@

import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.ScryEffect;
import mage.cards.CardImpl;
@@ -74,7 +74,7 @@ public RageOfPurphoros copy() {
}
}

class RageOfPurphorosEffect extends ReplacementEffectImpl {
class RageOfPurphorosEffect extends ContinuousRuleModifiyingEffectImpl {

public RageOfPurphorosEffect() {
super(Duration.EndOfTurn, Outcome.Detriment);
@@ -95,17 +95,12 @@ public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
return watcher.wasDamaged(event.getTargetId(), game);
}
}
return false;
@@ -35,6 +35,7 @@
import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageEverythingEffect;
import mage.abilities.effects.common.DamageTargetEffect;
@@ -111,7 +112,7 @@ public JayaBallardTaskMage copy() {
}
}

class CantRegenerateEffect extends ReplacementEffectImpl {
class CantRegenerateEffect extends ContinuousRuleModifiyingEffectImpl {

public CantRegenerateEffect() {
super(Duration.EndOfTurn, Outcome.Detriment);
@@ -132,17 +133,12 @@ public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId());
return watcher.wasDamaged(event.getTargetId(), game);
}
}
return false;
@@ -0,0 +1,101 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 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
* provided with the distribution.
*
* 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
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* 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
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* 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
* or implied, of BetaSteward_at_googlemail.com.
*/

package mage.abilities.effects.common.replacement;

import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.common.DamagedByWatcher;

/**
*
* @author LevelX2
*/

public class DealtDamageToCreatureBySourceDies extends ReplacementEffectImpl {

public DealtDamageToCreatureBySourceDies(Card card, Duration duration) {
super(Duration.WhileOnBattlefield, Outcome.Exile);
card.addWatcher(new DamagedByWatcher());
if (card.getCardType().contains(CardType.CREATURE)) {
staticText = "If a creature dealt damage by {this} this turn would die, exile it instead";
} else {
staticText = "If a creature dealt damage this way would die this turn, exile it instead";
}
}

public DealtDamageToCreatureBySourceDies(final DealtDamageToCreatureBySourceDies effect) {
super(effect);
}

@Override
public DealtDamageToCreatureBySourceDies copy() {
return new DealtDamageToCreatureBySourceDies(this);
}

@Override
public boolean apply(Game game, Ability source) {
return true;
}

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && permanent != null) {
return controller.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD);
}
return false;
}

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType().equals(EventType.ZONE_CHANGE)) {
ZoneChangeEvent zce = (ZoneChangeEvent) event;
if (zce.isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) {
return watcher.wasDamaged(zce.getTarget());
}
}
}
return false;
}

}
@@ -27,23 +27,25 @@
*/
package mage.watchers.common;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DamagedByWatcher extends Watcher {

public List<UUID> damagedCreatures = new ArrayList<>();
public Set<MageObjectReference> damagedCreatures = new HashSet<>();

public DamagedByWatcher() {
super("DamagedByWatcher", WatcherScope.CARD);
@@ -61,9 +63,10 @@ public DamagedByWatcher copy() {

@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_CREATURE) {
if (sourceId.equals(event.getSourceId()) && !damagedCreatures.contains(event.getTargetId())) {
damagedCreatures.add(event.getTargetId());
if (event.getType() == EventType.DAMAGED_CREATURE && sourceId.equals(event.getSourceId())) {
MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
if (!damagedCreatures.contains(mor)) {
damagedCreatures.add(mor);
}
}
}
@@ -74,4 +77,15 @@ public void reset() {
damagedCreatures.clear();
}

public boolean wasDamaged(UUID sourceId, Game game) {
MageObject mageObject = game.getObject(sourceId);
if (mageObject instanceof Permanent) {
return wasDamaged((Permanent) mageObject);
}
return false;
}

public boolean wasDamaged(Permanent permanent) {
return damagedCreatures.contains(new MageObjectReference(permanent));
}
}