From 351095a904a28ca55e503e47f30172278584ca41 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 16 May 2017 17:40:04 +0200 Subject: [PATCH] * Magma Spray - Fixed a bug of dies replacement handling (#3359). Other cards with same rule text not fixed yet. --- Mage.Sets/src/mage/cards/m/MagmaSpray.java | 55 ++++++++++---- .../replacement/DiesReplacementEffect.java | 72 +++++++++++++++++++ 2 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/effects/common/replacement/DiesReplacementEffect.java diff --git a/Mage.Sets/src/mage/cards/m/MagmaSpray.java b/Mage.Sets/src/mage/cards/m/MagmaSpray.java index a908e63872..a568e5d634 100644 --- a/Mage.Sets/src/mage/cards/m/MagmaSpray.java +++ b/Mage.Sets/src/mage/cards/m/MagmaSpray.java @@ -28,15 +28,19 @@ package mage.cards.m; import java.util.UUID; -import mage.abilities.effects.Effect; -import mage.abilities.effects.common.DamageTargetEffect; -import mage.abilities.effects.common.replacement.DealtDamageToCreatureBySourceDies; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.replacement.DiesReplacementEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCreaturePermanent; -import mage.watchers.common.DamagedByWatcher; /** * @@ -45,17 +49,11 @@ import mage.watchers.common.DamagedByWatcher; public class MagmaSpray extends CardImpl { public MagmaSpray(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{R}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{R}"); - - // Magma Spray deals 2 damage to target creature. - this.getSpellAbility().addEffect(new DamageTargetEffect(2)); + // Magma Spray deals 2 damage to target creature. If that creature would die this turn, exile it instead. + this.getSpellAbility().addEffect(new MagmaSprayEffect()); this.getSpellAbility().addTarget(new TargetCreaturePermanent()); - // If that creature would die this turn, exile it instead. - Effect effect = new DealtDamageToCreatureBySourceDies(this, Duration.EndOfTurn); - effect.setText("If that creature would die this turn, exile it instead"); - this.getSpellAbility().addEffect(effect); - this.getSpellAbility().addWatcher(new DamagedByWatcher()); } public MagmaSpray(final MagmaSpray card) { @@ -67,3 +65,34 @@ public class MagmaSpray extends CardImpl { return new MagmaSpray(this); } } + +class MagmaSprayEffect extends OneShotEffect { + + public MagmaSprayEffect() { + super(Outcome.Damage); + this.staticText = "{this} deals 2 damage to target creature. 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) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (targetCreature != null) { + game.addEffect(new DiesReplacementEffect(new MageObjectReference(targetCreature, game), Duration.EndOfTurn), source); + targetCreature.damage(2, source.getSourceId(), game, false, true); + } + return true; + } + return false; + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/replacement/DiesReplacementEffect.java b/Mage/src/main/java/mage/abilities/effects/common/replacement/DiesReplacementEffect.java new file mode 100644 index 0000000000..bf08c67125 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/replacement/DiesReplacementEffect.java @@ -0,0 +1,72 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.effects.common.replacement; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.effects.ReplacementEffectImpl; +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; + +/** + * + * @author LevelX2 + */ +public class DiesReplacementEffect extends ReplacementEffectImpl { + + private final MageObjectReference objectRef; + + public DiesReplacementEffect(MageObjectReference objectRef, Duration duration) { + super(duration, Outcome.Exile); + this.objectRef = objectRef; + staticText = "If that creature would die " + (duration.equals(Duration.EndOfTurn) ? "this turn" : "") + ", exile it instead"; + } + + public DiesReplacementEffect(final DiesReplacementEffect effect) { + super(effect); + this.objectRef = effect.objectRef; + } + + @Override + public DiesReplacementEffect copy() { + return new DiesReplacementEffect(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, true); + } + return false; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + ZoneChangeEvent zce = (ZoneChangeEvent) event; + return zce.isDiesEvent() + && objectRef.equals(new MageObjectReference(zce.getTarget(), game)); + } + +}