* Fixed PreventDamageByTargetEffect to handle delayed spell damge (fixes #2822).

This commit is contained in:
LevelX2 2017-01-30 21:19:17 +01:00
parent 64ff81af75
commit 034ef22468
4 changed files with 81 additions and 12 deletions

View file

@ -25,17 +25,18 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.target.Target;
import mage.target.TargetSpell;
/**
* @author nantuko
@ -71,8 +72,15 @@ public class PreventDamageByTargetEffect extends PreventionEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {
MageObject mageObject = game.getObject(event.getSourceId());
if (mageObject instanceof Spell){
return this.getTargetPointer().getTargets(game, source).contains(mageObject.getId());
if (mageObject != null
&& (mageObject.getCardType().contains(CardType.INSTANT) || mageObject.getCardType().contains(CardType.SORCERY))) {
for (Target target : source.getTargets()) {
if (target instanceof TargetSpell) {
if (((TargetSpell) target).getSourceIds().contains(event.getSourceId())) {
return true;
}
}
}
}
return this.getTargetPointer().getTargets(game, source).contains(event.getSourceId());
}

View file

@ -44,6 +44,7 @@ import mage.game.stack.StackObject;
public class TargetSpell extends TargetObject {
protected final FilterSpell filter;
private final Set<UUID> sourceIds = new HashSet<>();
public TargetSpell() {
this(1, 1, new FilterSpell());
@ -68,6 +69,7 @@ public class TargetSpell extends TargetObject {
public TargetSpell(final TargetSpell target) {
super(target);
this.filter = target.filter.copy();
this.sourceIds.addAll(target.sourceIds);
}
@Override
@ -134,4 +136,18 @@ public class TargetSpell extends TargetObject {
&& game.getState().getPlayersInRange(sourceControllerId, game).contains(stackObject.getControllerId())
&& filter.match(stackObject, sourceID, sourceControllerId, game);
}
@Override
public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) {
Spell spell = game.getStack().getSpell(id);
if (spell != null) { // remember the original sourceID
sourceIds.add(spell.getSourceId());
}
super.addTarget(id, source, game, skipEvent);
}
public Set<UUID> getSourceIds() {
return sourceIds;
}
}