Used new MageObjectReference class for DamagedByWatcher damaged object comparison.

This commit is contained in:
LevelX2 2014-08-23 18:01:55 +02:00
parent 36444b9496
commit b0a18d4f36
22 changed files with 221 additions and 598 deletions

View file

@ -127,7 +127,7 @@ class AggravateRequirementEffect extends RequirementEffect {
public boolean applies(Permanent permanent, Ability source, Game game) { public boolean applies(Permanent permanent, Ability source, Game game) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(permanent.getId()); return watcher.wasDamaged(permanent);
} }
return false; return false;
} }

View file

@ -35,6 +35,7 @@ import mage.constants.Rarity;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -60,8 +61,7 @@ public class PillarOfFlame extends CardImpl {
this.getSpellAbility().addEffect(new DamageTargetEffect(2)); this.getSpellAbility().addEffect(new DamageTargetEffect(2));
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
// If a creature dealt damage this way would die this turn, exile it instead. // If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new PillarOfFlameEffect()); this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
this.addWatcher(new DamagedByWatcher());
} }
public PillarOfFlame(final PillarOfFlame card) { public PillarOfFlame(final PillarOfFlame card) {

View file

@ -27,9 +27,10 @@
*/ */
package mage.sets.betrayersofkamigawa; package mage.sets.betrayersofkamigawa;
import java.util.ArrayList; import java.util.HashSet;
import java.util.List; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
@ -123,10 +124,13 @@ class KumanosBlessingEffect extends ReplacementEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) { if (event.getType() == EventType.ZONE_CHANGE) {
ZoneChangeEvent zce = (ZoneChangeEvent) event;
if (zce.isDiesEvent()) {
DamagedByEnchantedWatcher watcher = (DamagedByEnchantedWatcher) game.getState().getWatchers().get("DamagedByEnchantedWatcher", source.getSourceId()); DamagedByEnchantedWatcher watcher = (DamagedByEnchantedWatcher) game.getState().getWatchers().get("DamagedByEnchantedWatcher", source.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId()); return watcher.wasDamaged(zce.getTarget());
}
} }
} }
return false; return false;
@ -136,7 +140,7 @@ class KumanosBlessingEffect extends ReplacementEffectImpl {
class DamagedByEnchantedWatcher extends Watcher { class DamagedByEnchantedWatcher extends Watcher {
public List<UUID> damagedCreatures = new ArrayList<>(); private final Set<MageObjectReference> damagedCreatures = new HashSet<>();
public DamagedByEnchantedWatcher() { public DamagedByEnchantedWatcher() {
super("DamagedByEnchantedWatcher", WatcherScope.CARD); super("DamagedByEnchantedWatcher", WatcherScope.CARD);
@ -157,8 +161,11 @@ class DamagedByEnchantedWatcher extends Watcher {
if (event.getType() == EventType.DAMAGED_CREATURE) { if (event.getType() == EventType.DAMAGED_CREATURE) {
Permanent enchantment = game.getPermanent(this.getSourceId()); Permanent enchantment = game.getPermanent(this.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) { if (enchantment != null && enchantment.getAttachedTo() != null) {
if (enchantment.getAttachedTo().equals(event.getSourceId()) && !damagedCreatures.contains(event.getTargetId())) { if (enchantment.getAttachedTo().equals(event.getSourceId())) {
damagedCreatures.add(event.getTargetId()); MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
if (!damagedCreatures.contains(mor)) {
damagedCreatures.add(mor);
}
} }
} }
} }
@ -170,4 +177,7 @@ class DamagedByEnchantedWatcher extends Watcher {
damagedCreatures.clear(); damagedCreatures.clear();
} }
public boolean wasDamaged(Permanent permanent) {
return damagedCreatures.contains(new MageObjectReference(permanent));
}
} }

View file

@ -29,26 +29,19 @@
package mage.sets.championsofkamigawa; package mage.sets.championsofkamigawa;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.constants.CardType;
import mage.game.events.GameEvent; import mage.constants.Duration;
import mage.game.events.GameEvent.EventType; import mage.constants.Rarity;
import mage.game.events.ZoneChangeEvent; import mage.constants.Zone;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;
/** /**
* @author LevelX * @author LevelX
@ -69,9 +62,8 @@ public class Frostwielder extends CardImpl {
ability.addTarget(new TargetCreatureOrPlayer()); ability.addTarget(new TargetCreatureOrPlayer());
this.addAbility(ability); this.addAbility(ability);
// If a creature dealt damage by Frostwielder this turn would die, exile it instead. // If a creature dealt damage by Frostwielder this turn would die, exile it instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new FrostwielderEffect())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DealtDamageToCreatureBySourceDies(this, Duration.WhileOnBattlefield)));
this.addWatcher(new DamagedByWatcher());
} }
public Frostwielder(final Frostwielder card) { public Frostwielder(final Frostwielder card) {
@ -84,47 +76,3 @@ public class Frostwielder extends CardImpl {
} }
} }
class FrostwielderEffect extends ReplacementEffectImpl {
public FrostwielderEffect() {
super(Duration.WhileOnBattlefield, Outcome.Exile);
staticText = "If a creature dealt damage by {this} this turn would die, exile it instead";
}
public FrostwielderEffect(final FrostwielderEffect effect) {
super(effect);
}
@Override
public FrostwielderEffect copy() {
return new FrostwielderEffect(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;
}
}

View file

@ -31,28 +31,19 @@
package mage.sets.championsofkamigawa; package mage.sets.championsofkamigawa;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.constants.CardType;
import mage.game.events.GameEvent; import mage.constants.Duration;
import mage.game.events.GameEvent.EventType; import mage.constants.Rarity;
import mage.game.events.ZoneChangeEvent; import mage.constants.Zone;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;
/** /**
* @author LevelX * @author LevelX
@ -72,10 +63,10 @@ public class KumanoMasterYamabushi extends CardImpl {
// {{1}{R}: Kumano, Master Yamabushi deals 1 damage to target creature or player. // {{1}{R}: Kumano, Master Yamabushi deals 1 damage to target creature or player.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DamageTargetEffect(1), new ManaCostsImpl("{1}{R}") ); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DamageTargetEffect(1), new ManaCostsImpl("{1}{R}") );
ability.addTarget(new TargetCreatureOrPlayer()); ability.addTarget(new TargetCreatureOrPlayer());
// If a creature dealt damage by Kumano this turn would die, exile it instead.
this.addAbility(ability); this.addAbility(ability);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KumanaoMasterYamabushiEffect())); // If a creature dealt damage by Kumano this turn would die, exile it instead.
this.addWatcher(new DamagedByWatcher()); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DealtDamageToCreatureBySourceDies(this, Duration.WhileOnBattlefield)));
} }
public KumanoMasterYamabushi(final KumanoMasterYamabushi card) { public KumanoMasterYamabushi(final KumanoMasterYamabushi card) {
@ -88,45 +79,3 @@ public class KumanoMasterYamabushi extends CardImpl {
} }
} }
class KumanaoMasterYamabushiEffect extends ReplacementEffectImpl {
public KumanaoMasterYamabushiEffect() {
super(Duration.WhileOnBattlefield, Outcome.Exile);
staticText = "If a creature dealt damage by {this} this turn would die, exile it instead";
}
public KumanaoMasterYamabushiEffect(final KumanaoMasterYamabushiEffect effect) {
super(effect);
}
@Override
public KumanaoMasterYamabushiEffect copy() {
return new KumanaoMasterYamabushiEffect(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;
}
}

View file

@ -29,24 +29,14 @@
package mage.sets.championsofkamigawa; package mage.sets.championsofkamigawa;
import java.util.UUID; import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ReplacementEffectImpl;
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.watchers.common.DamagedByWatcher;
/** /**
* @author LevelX * @author LevelX
@ -63,9 +53,7 @@ public class KumanosPupils extends CardImpl {
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
// If a creature dealt damage by Kumano's Pupils this turn would die, exile it instead. // If a creature dealt damage by Kumano's Pupils this turn would die, exile it instead.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KumanosPupilsEffect())); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DealtDamageToCreatureBySourceDies(this, Duration.WhileOnBattlefield)));
this.addWatcher(new DamagedByWatcher());
} }
public KumanosPupils(final KumanosPupils card) { public KumanosPupils(final KumanosPupils card) {
@ -78,45 +66,3 @@ public class KumanosPupils extends CardImpl {
} }
} }
class KumanosPupilsEffect extends ReplacementEffectImpl {
public KumanosPupilsEffect() {
super(Duration.WhileOnBattlefield, Outcome.Exile);
staticText = "If a creature dealt damage by {this} this turn would die, exile it instead";
}
public KumanosPupilsEffect(final KumanosPupilsEffect effect) {
super(effect);
}
@Override
public KumanosPupilsEffect copy() {
return new KumanosPupilsEffect(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;
}
}

View file

@ -36,8 +36,10 @@ import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.ActivateAsSorceryActivatedAbility; import mage.abilities.common.ActivateAsSorceryActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -46,6 +48,7 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher; import mage.watchers.common.DamagedByWatcher;
@ -68,10 +71,10 @@ public class NineRingedBo extends CardImpl {
// {T}: Nine-Ringed Bo deals 1 damage to target Spirit creature. If that creature would die this turn, exile it instead. // {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 ability = new ActivateAsSorceryActivatedAbility(Zone.BATTLEFIELD, new DamageTargetEffect(1), new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent(filter)); 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.addAbility(ability);
this.addWatcher(new DamagedByWatcher());
} }
public NineRingedBo(final NineRingedBo card) { public NineRingedBo(final NineRingedBo card) {
@ -83,45 +86,3 @@ public class NineRingedBo extends CardImpl {
return new NineRingedBo(this); 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;
}
}

View file

@ -30,21 +30,13 @@
package mage.sets.championsofkamigawa; package mage.sets.championsofkamigawa;
import java.util.UUID; 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.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity; 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.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *
@ -62,8 +54,7 @@ public class YamabushisFlame extends CardImpl {
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
// If a creature dealt damage this way would die this turn, exile it instead. // If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new YamabushisFlameEffect()); this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
this.addWatcher(new DamagedByWatcher());
} }
public YamabushisFlame(final YamabushisFlame card) { public YamabushisFlame(final YamabushisFlame card) {
@ -75,46 +66,3 @@ public class YamabushisFlame extends CardImpl {
return new YamabushisFlame(this); 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;
}
}

View file

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

View file

@ -31,8 +31,10 @@ import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
@ -40,10 +42,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
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.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *
@ -60,7 +59,9 @@ public class Disintegrate extends CardImpl {
// 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. // 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 DamageTargetEffect(new ManacostVariableValue()));
this.getSpellAbility().addEffect(new DisintegrateCantRegenerateEffect()); 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()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
} }
@ -111,45 +112,3 @@ class DisintegrateCantRegenerateEffect extends ReplacementEffectImpl {
return false; 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;
}
}

View file

@ -40,7 +40,6 @@ import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *

View file

@ -28,21 +28,14 @@
package mage.sets.mirrodinbesieged; package mage.sets.mirrodinbesieged;
import java.util.UUID; 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.dynamicvalue.common.ManacostVariableValue;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.ShuffleSpellEffect; import mage.abilities.effects.common.ShuffleSpellEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.constants.CardType;
import mage.game.events.GameEvent; import mage.constants.Duration;
import mage.game.events.GameEvent.EventType; import mage.constants.Rarity;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher; import mage.watchers.common.DamagedByWatcher;
@ -56,9 +49,10 @@ public class RedSunsZenith extends CardImpl {
super(ownerId, 74, "Red Sun's Zenith", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{X}{R}"); super(ownerId, 74, "Red Sun's Zenith", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{X}{R}");
this.expansionSetCode = "MBS"; this.expansionSetCode = "MBS";
this.color.setRed(true); this.color.setRed(true);
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
this.getSpellAbility().addEffect(new DamageTargetEffect(new ManacostVariableValue())); 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.getSpellAbility().addEffect(ShuffleSpellEffect.getInstance());
this.addWatcher(new DamagedByWatcher()); this.addWatcher(new DamagedByWatcher());
} }
@ -73,45 +67,3 @@ public class RedSunsZenith extends CardImpl {
} }
} }
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;
}
}

View file

@ -42,7 +42,6 @@ import mage.constants.TimingRule;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *
@ -60,7 +59,6 @@ public class EngulfingFlames extends CardImpl {
this.getSpellAbility().addEffect(new DamageTargetEffect(1)); this.getSpellAbility().addEffect(new DamageTargetEffect(1));
this.getSpellAbility().addTarget(new TargetCreaturePermanent()); this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new EngulfingFlamesEffect()); this.getSpellAbility().addEffect(new EngulfingFlamesEffect());
this.addWatcher(new DamagedByWatcher());
// Flashback {3}{R} // Flashback {3}{R}
this.addAbility(new FlashbackAbility(new ManaCostsImpl("{3}{R}"), TimingRule.INSTANT)); this.addAbility(new FlashbackAbility(new ManaCostsImpl("{3}{R}"), TimingRule.INSTANT));
} }

View file

@ -30,21 +30,13 @@
package mage.sets.returntoravnica; package mage.sets.returntoravnica;
import java.util.UUID; 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.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity; 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.target.common.TargetCreatureOrPlayer;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *
@ -62,8 +54,7 @@ public class AnnihilatingFire extends CardImpl {
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer()); this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
// If a creature dealt damage this way would die this turn, exile it instead. // If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new AnnihilatingFireEffect()); this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
this.addWatcher(new DamagedByWatcher());
} }
public AnnihilatingFire(final AnnihilatingFire card) { public AnnihilatingFire(final AnnihilatingFire card) {
@ -75,45 +66,3 @@ public class AnnihilatingFire extends CardImpl {
return new AnnihilatingFire(this); 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;
}
}

View file

@ -28,21 +28,14 @@
package mage.sets.shardsofalara; package mage.sets.shardsofalara;
import java.util.UUID; 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.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity; 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.target.common.TargetCreaturePermanent;
import mage.watchers.common.DamagedByWatcher;
/** /**
* *
@ -60,8 +53,9 @@ public class MagmaSpray extends CardImpl {
this.getSpellAbility().addEffect(new DamageTargetEffect(2)); this.getSpellAbility().addEffect(new DamageTargetEffect(2));
this.getSpellAbility().addTarget(new TargetCreaturePermanent()); this.getSpellAbility().addTarget(new TargetCreaturePermanent());
// If that creature would die this turn, exile it instead. // If that creature would die this turn, exile it instead.
this.getSpellAbility().addEffect(new MagmaSprayEffect()); Effect effect = new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn);
this.addWatcher(new DamagedByWatcher()); effect.setText("If that creature would die this turn, exile it instead");
this.getSpellAbility().addEffect(effect);
} }
public MagmaSpray(final MagmaSpray card) { public MagmaSpray(final MagmaSpray card) {
@ -73,45 +67,3 @@ public class MagmaSpray extends CardImpl {
return new MagmaSpray(this); 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;
}
}

View file

@ -46,6 +46,7 @@ import mage.abilities.effects.common.RegenerateSourceEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.token.Token; import mage.game.permanent.token.Token;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
@ -124,10 +125,13 @@ class SkeletonizeDelayedTriggeredAbility extends DelayedTriggeredAbility {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent) event).isDiesEvent()) { if (event.getType().equals(EventType.ZONE_CHANGE)) {
ZoneChangeEvent zce = (ZoneChangeEvent) event;
if (zce.isDiesEvent()) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", this.getSourceId()); DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", this.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId()); return watcher.wasDamaged(zce.getTarget());
}
} }
} }
return false; return false;

View file

@ -28,14 +28,14 @@
package mage.sets.tenth; package mage.sets.tenth;
import java.util.UUID; 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.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; 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.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
@ -70,10 +70,10 @@ public class Incinerate extends CardImpl {
} }
} }
class IncinerateEffect extends ReplacementEffectImpl { class IncinerateEffect extends ContinuousRuleModifiyingEffectImpl {
public IncinerateEffect() { 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"; staticText = "A creature dealt damage this way can't be regenerated this turn";
} }
@ -91,17 +91,12 @@ class IncinerateEffect extends ReplacementEffectImpl {
return true; return true;
} }
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) { if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId()); return watcher.wasDamaged(event.getTargetId(), game);
} }
} }
return false; return false;

View file

@ -28,20 +28,13 @@
package mage.sets.theros; package mage.sets.theros;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageAllEffect; import mage.abilities.effects.common.DamageAllEffect;
import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.filter.common.FilterCreaturePermanent; 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 class AngerOfTheGods extends CardImpl {
this.getSpellAbility().addEffect(new DamageAllEffect(3, new FilterCreaturePermanent())); this.getSpellAbility().addEffect(new DamageAllEffect(3, new FilterCreaturePermanent()));
//If a creature dealt damage this way would die this turn, exile it instead. //If a creature dealt damage this way would die this turn, exile it instead.
this.getSpellAbility().addEffect(new AngerOfTheGodsEffect()); this.getSpellAbility().addEffect(new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn));
this.addWatcher(new DamagedByWatcher());
} }
public AngerOfTheGods(final AngerOfTheGods card) { public AngerOfTheGods(final AngerOfTheGods card) {
@ -72,48 +64,3 @@ public class AngerOfTheGods extends CardImpl {
return new AngerOfTheGods(this); 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;
}
}

View file

@ -29,7 +29,7 @@ package mage.sets.theros;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; 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.DamageTargetEffect;
import mage.abilities.effects.common.ScryEffect; import mage.abilities.effects.common.ScryEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
@ -74,7 +74,7 @@ public class RageOfPurphoros extends CardImpl {
} }
} }
class RageOfPurphorosEffect extends ReplacementEffectImpl { class RageOfPurphorosEffect extends ContinuousRuleModifiyingEffectImpl {
public RageOfPurphorosEffect() { public RageOfPurphorosEffect() {
super(Duration.EndOfTurn, Outcome.Detriment); super(Duration.EndOfTurn, Outcome.Detriment);
@ -95,17 +95,12 @@ class RageOfPurphorosEffect extends ReplacementEffectImpl {
return true; return true;
} }
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) { if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId()); return watcher.wasDamaged(event.getTargetId(), game);
} }
} }
return false; return false;

View file

@ -35,6 +35,7 @@ import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.DiscardCardCost; import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.ContinuousRuleModifiyingEffectImpl;
import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.DamageEverythingEffect; import mage.abilities.effects.common.DamageEverythingEffect;
import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.DamageTargetEffect;
@ -111,7 +112,7 @@ public class JayaBallardTaskMage extends CardImpl {
} }
} }
class CantRegenerateEffect extends ReplacementEffectImpl { class CantRegenerateEffect extends ContinuousRuleModifiyingEffectImpl {
public CantRegenerateEffect() { public CantRegenerateEffect() {
super(Duration.EndOfTurn, Outcome.Detriment); super(Duration.EndOfTurn, Outcome.Detriment);
@ -132,17 +133,12 @@ class CantRegenerateEffect extends ReplacementEffectImpl {
return true; return true;
} }
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return true;
}
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == EventType.REGENERATE) { if (event.getType() == EventType.REGENERATE) {
DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId()); DamagedByWatcher watcher = (DamagedByWatcher) game.getState().getWatchers().get("DamagedByWatcher", source.getSourceId());
if (watcher != null) { if (watcher != null) {
return watcher.damagedCreatures.contains(event.getTargetId()); return watcher.wasDamaged(event.getTargetId(), game);
} }
} }
return false; return false;

View file

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

View file

@ -27,23 +27,25 @@
*/ */
package mage.watchers.common; 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.constants.WatcherScope;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher; import mage.watchers.Watcher;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class DamagedByWatcher extends Watcher { public class DamagedByWatcher extends Watcher {
public List<UUID> damagedCreatures = new ArrayList<>(); public Set<MageObjectReference> damagedCreatures = new HashSet<>();
public DamagedByWatcher() { public DamagedByWatcher() {
super("DamagedByWatcher", WatcherScope.CARD); super("DamagedByWatcher", WatcherScope.CARD);
@ -61,9 +63,10 @@ public class DamagedByWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == EventType.DAMAGED_CREATURE) { if (event.getType() == EventType.DAMAGED_CREATURE && sourceId.equals(event.getSourceId())) {
if (sourceId.equals(event.getSourceId()) && !damagedCreatures.contains(event.getTargetId())) { MageObjectReference mor = new MageObjectReference(event.getTargetId(), game);
damagedCreatures.add(event.getTargetId()); if (!damagedCreatures.contains(mor)) {
damagedCreatures.add(mor);
} }
} }
} }
@ -74,4 +77,15 @@ public class DamagedByWatcher extends Watcher {
damagedCreatures.clear(); 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));
}
} }