* Defend of Hearth - Fixd that prevention effect was applied also to permanents instead only to players.

This commit is contained in:
LevelX2 2013-09-20 14:22:09 +02:00
parent 24baf63cf1
commit b7ae1305bb
4 changed files with 113 additions and 5 deletions

View file

@ -28,7 +28,7 @@
package mage.sets.theros; package mage.sets.theros;
import java.util.UUID; import java.util.UUID;
import mage.abilities.effects.common.PreventAllDamageEffect; import mage.abilities.effects.common.PreventAllDamageToPlayersEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
@ -47,7 +47,7 @@ public class DefendTheHearth extends CardImpl<DefendTheHearth> {
this.color.setGreen(true); this.color.setGreen(true);
// Prevent all combat damage that would be dealt to players this turn. // Prevent all combat damage that would be dealt to players this turn.
this.getSpellAbility().addEffect(new PreventAllDamageEffect(Duration.EndOfTurn, true)); this.getSpellAbility().addEffect(new PreventAllDamageToPlayersEffect(Duration.EndOfTurn, true));
} }
public DefendTheHearth(final DefendTheHearth card) { public DefendTheHearth(final DefendTheHearth card) {

View file

@ -57,6 +57,7 @@ public abstract class PreventionEffectImpl<T extends PreventionEffectImpl<T>> ex
case DAMAGE_CREATURE: case DAMAGE_CREATURE:
case DAMAGE_PLAYER: case DAMAGE_PLAYER:
case DAMAGE_PLANESWALKER: case DAMAGE_PLANESWALKER:
// return preventable flag
return event.getFlag(); return event.getFlag();
default: default:
return false; return false;

View file

@ -44,15 +44,15 @@ import mage.game.permanent.Permanent;
public class PreventAllDamageEffect extends PreventionEffectImpl<PreventAllDamageEffect> { public class PreventAllDamageEffect extends PreventionEffectImpl<PreventAllDamageEffect> {
private FilterPermanent filter; private FilterPermanent filter;
private Boolean onlyCombat; private boolean onlyCombat;
public PreventAllDamageEffect(FilterPermanent filter, Duration duration, Boolean onlyCombat) { public PreventAllDamageEffect(FilterPermanent filter, Duration duration, boolean onlyCombat) {
super(duration); super(duration);
this.filter = filter; this.filter = filter;
this.onlyCombat = onlyCombat; this.onlyCombat = onlyCombat;
} }
public PreventAllDamageEffect(Duration duration, Boolean onlyCombat) { public PreventAllDamageEffect(Duration duration, boolean onlyCombat) {
super(duration); super(duration);
this.onlyCombat = onlyCombat; this.onlyCombat = onlyCombat;
} }

View file

@ -0,0 +1,107 @@
/*
* 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;
import mage.abilities.Ability;
import mage.abilities.effects.PreventionEffectImpl;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class PreventAllDamageToPlayersEffect extends PreventionEffectImpl<PreventAllDamageToPlayersEffect> {
private boolean onlyCombat;
public PreventAllDamageToPlayersEffect(Duration duration, boolean onlyCombat) {
super(duration);
this.onlyCombat = onlyCombat;
staticText = setText();
}
public PreventAllDamageToPlayersEffect(final PreventAllDamageToPlayersEffect effect) {
super(effect);
this.onlyCombat = effect.onlyCombat;
}
@Override
public PreventAllDamageToPlayersEffect copy() {
return new PreventAllDamageToPlayersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER)) {
DamageEvent damageEvent = (DamageEvent) event;
if ((damageEvent.isCombatDamage() || !onlyCombat) && damageEvent.isPreventable()) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && controller.getInRange().contains(event.getTargetId())){
return true;
}
}
}
return false;
}
private String setText() {
StringBuilder sb = new StringBuilder("Prevent all ");
if (onlyCombat) {
sb.append("combat ");
}
sb.append("damage that would be dealt to players");
if (duration.equals(Duration.EndOfTurn)) {
sb.append(" this turn");
}
return sb.toString();
}
}