diff --git a/Mage.Sets/src/mage/sets/theros/DefendTheHearth.java b/Mage.Sets/src/mage/sets/theros/DefendTheHearth.java index 830e103456..d2c3733e30 100644 --- a/Mage.Sets/src/mage/sets/theros/DefendTheHearth.java +++ b/Mage.Sets/src/mage/sets/theros/DefendTheHearth.java @@ -28,7 +28,7 @@ package mage.sets.theros; import java.util.UUID; -import mage.abilities.effects.common.PreventAllDamageEffect; +import mage.abilities.effects.common.PreventAllDamageToPlayersEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; @@ -47,7 +47,7 @@ public class DefendTheHearth extends CardImpl { this.color.setGreen(true); // 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) { diff --git a/Mage/src/mage/abilities/effects/PreventionEffectImpl.java b/Mage/src/mage/abilities/effects/PreventionEffectImpl.java index 7769cbb67c..03450480af 100644 --- a/Mage/src/mage/abilities/effects/PreventionEffectImpl.java +++ b/Mage/src/mage/abilities/effects/PreventionEffectImpl.java @@ -57,6 +57,7 @@ public abstract class PreventionEffectImpl> ex case DAMAGE_CREATURE: case DAMAGE_PLAYER: case DAMAGE_PLANESWALKER: + // return preventable flag return event.getFlag(); default: return false; diff --git a/Mage/src/mage/abilities/effects/common/PreventAllDamageEffect.java b/Mage/src/mage/abilities/effects/common/PreventAllDamageEffect.java index 4b67842210..1744ba5edf 100644 --- a/Mage/src/mage/abilities/effects/common/PreventAllDamageEffect.java +++ b/Mage/src/mage/abilities/effects/common/PreventAllDamageEffect.java @@ -44,15 +44,15 @@ import mage.game.permanent.Permanent; public class PreventAllDamageEffect extends PreventionEffectImpl { 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); this.filter = filter; this.onlyCombat = onlyCombat; } - public PreventAllDamageEffect(Duration duration, Boolean onlyCombat) { + public PreventAllDamageEffect(Duration duration, boolean onlyCombat) { super(duration); this.onlyCombat = onlyCombat; } diff --git a/Mage/src/mage/abilities/effects/common/PreventAllDamageToPlayersEffect.java b/Mage/src/mage/abilities/effects/common/PreventAllDamageToPlayersEffect.java new file mode 100644 index 0000000000..6bb47c2b6b --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/PreventAllDamageToPlayersEffect.java @@ -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 { + + 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(); + } +}