mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
* Magma Spray - Fixed a bug of dies replacement handling (#3359). Other cards with same rule text not fixed yet.
This commit is contained in:
parent
5ce813ad87
commit
351095a904
2 changed files with 114 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue