From 8192744697e74251757704e13d3281041294d966 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 1 Feb 2015 16:05:35 +0100 Subject: [PATCH] * Fixed / reworked prevent damage by source effect (related to Burrenton Forge-Tender, Pay no Heed, Prahv, Spires of Order). --- .../sets/dissension/PrahvSpiresOfOrder.java | 50 ++--------- .../sets/lorwyn/BurrentonForgeTender.java | 15 +--- .../src/mage/sets/magic2014/PayNoHeed.java | 48 +--------- Mage/src/mage/MageObjectReference.java | 13 ++- .../common/PreventDamageBySourceEffect.java | 89 +++++++++++++++++++ Mage/src/mage/target/TargetSource.java | 9 +- .../targetpointer/FirstTargetPointer.java | 1 - 7 files changed, 114 insertions(+), 111 deletions(-) create mode 100644 Mage/src/mage/abilities/effects/common/PreventDamageBySourceEffect.java diff --git a/Mage.Sets/src/mage/sets/dissension/PrahvSpiresOfOrder.java b/Mage.Sets/src/mage/sets/dissension/PrahvSpiresOfOrder.java index ca888bddbd..960079e9a3 100644 --- a/Mage.Sets/src/mage/sets/dissension/PrahvSpiresOfOrder.java +++ b/Mage.Sets/src/mage/sets/dissension/PrahvSpiresOfOrder.java @@ -32,18 +32,12 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageBySourceEffect; import mage.abilities.mana.ColorlessManaAbility; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.DamageEvent; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -55,10 +49,11 @@ public class PrahvSpiresOfOrder extends CardImpl { super(ownerId, 177, "Prahv, Spires of Order", Rarity.UNCOMMON, new CardType[]{CardType.LAND}, ""); this.expansionSetCode = "DIS"; - // {tap}: Add {1} to your mana pool. + // {T}: Add {1} to your mana pool. this.addAbility(new ColorlessManaAbility()); - // {4}{W}{U}, {tap}: Prevent all damage a source of your choice would deal this turn. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PrahvSpiresOfOrderPreventionEffect(), new ManaCostsImpl("{4}{W}{U}")); + + // {4}{W}{U}, {T}: Prevent all damage a source of your choice would deal this turn. + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageBySourceEffect(), new ManaCostsImpl("{4}{W}{U}")); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -73,38 +68,3 @@ public class PrahvSpiresOfOrder extends CardImpl { return new PrahvSpiresOfOrder(this); } } - -class PrahvSpiresOfOrderPreventionEffect extends PreventionEffectImpl { - private TargetSource target = new TargetSource(); - - public PrahvSpiresOfOrderPreventionEffect() { - super(Duration.EndOfTurn); - staticText = "Prevent all damage a source of your choice would deal to you this turn"; - } - - public PrahvSpiresOfOrderPreventionEffect(final PrahvSpiresOfOrderPreventionEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public PrahvSpiresOfOrderPreventionEffect copy() { - return new PrahvSpiresOfOrderPreventionEffect(this); - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event instanceof DamageEvent && super.applies(event, source, game)) { - if (event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/lorwyn/BurrentonForgeTender.java b/Mage.Sets/src/mage/sets/lorwyn/BurrentonForgeTender.java index b75b2c5987..3071d7a9de 100644 --- a/Mage.Sets/src/mage/sets/lorwyn/BurrentonForgeTender.java +++ b/Mage.Sets/src/mage/sets/lorwyn/BurrentonForgeTender.java @@ -30,21 +30,17 @@ package mage.sets.lorwyn; import java.util.UUID; import mage.MageInt; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeSourceCost; -import mage.abilities.effects.Effect; -import mage.abilities.effects.common.PreventDamageByTargetEffect; +import mage.abilities.effects.common.PreventDamageBySourceEffect; import mage.abilities.keyword.ProtectionAbility; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Duration; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.FilterCard; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.target.TargetSource; /** * @@ -53,7 +49,7 @@ import mage.target.TargetSource; public class BurrentonForgeTender extends CardImpl { private static final FilterCard filter = new FilterCard("Red"); - private static final FilterObject filterObject = new FilterObject("red source of your choice"); + private static final FilterObject filterObject = new FilterObject("a red"); static { filter.add(new ColorPredicate(ObjectColor.RED)); @@ -74,12 +70,7 @@ public class BurrentonForgeTender extends CardImpl { this.addAbility(new ProtectionAbility(filter)); // Sacrifice Burrenton Forge-Tender: Prevent all damage a red source of your choice would deal this turn. - Effect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, Integer.MAX_VALUE, false); - effect.setText("Prevent all damage a red source of your choice would deal this turn"); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new SacrificeSourceCost()); - TargetSource targetSource = new TargetSource(filterObject); - ability.addTarget(targetSource); - this.addAbility(ability); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageBySourceEffect(filterObject), new SacrificeSourceCost())); } diff --git a/Mage.Sets/src/mage/sets/magic2014/PayNoHeed.java b/Mage.Sets/src/mage/sets/magic2014/PayNoHeed.java index d48519924f..a17b0b702d 100644 --- a/Mage.Sets/src/mage/sets/magic2014/PayNoHeed.java +++ b/Mage.Sets/src/mage/sets/magic2014/PayNoHeed.java @@ -28,17 +28,10 @@ package mage.sets.magic2014; import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.effects.Effect; -import mage.abilities.effects.PreventionEffectImpl; -import mage.abilities.effects.common.PreventDamageByTargetEffect; +import mage.abilities.effects.common.PreventDamageBySourceEffect; import mage.cards.CardImpl; import mage.constants.CardType; -import mage.constants.Duration; import mage.constants.Rarity; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -53,11 +46,7 @@ public class PayNoHeed extends CardImpl { this.color.setWhite(true); // Prevent all damage a source of your choice would deal this turn. - Effect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, Integer.MAX_VALUE, false); - effect.setText("Prevent all damage a source of your choice would deal this turn"); - this.getSpellAbility().addEffect(effect); - TargetSource targetSource = new TargetSource(); - this.getSpellAbility().addTarget(targetSource); + this.getSpellAbility().addEffect(new PreventDamageBySourceEffect()); } @@ -70,36 +59,3 @@ public class PayNoHeed extends CardImpl { return new PayNoHeed(this); } } - -class PayNoHeedEffect extends PreventionEffectImpl { - - public PayNoHeedEffect() { - super(Duration.EndOfTurn, Integer.MAX_VALUE, false); - staticText = "Prevent all damage a source of your choice would deal this turn"; - } - - public PayNoHeedEffect(final PayNoHeedEffect effect) { - super(effect); - } - - @Override - public PayNoHeedEffect copy() { - return new PayNoHeedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (super.applies(event, source, game)) { - if (event.getSourceId().equals(this.getTargetPointer().getFirst(game, source))) { - return true; - } - } - return false; - } - -} diff --git a/Mage/src/mage/MageObjectReference.java b/Mage/src/mage/MageObjectReference.java index 7033489927..e7ea3f1d86 100644 --- a/Mage/src/mage/MageObjectReference.java +++ b/Mage/src/mage/MageObjectReference.java @@ -32,6 +32,7 @@ import java.util.UUID; import mage.cards.Card; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.game.stack.Spell; /** * A object reference that takes zone changes into account. @@ -61,6 +62,8 @@ public class MageObjectReference implements Comparable { this.zoneChangeCounter = ((Permanent)mageObject).getZoneChangeCounter(); } else if (mageObject instanceof Card) { this.zoneChangeCounter = ((Card)mageObject).getZoneChangeCounter(); + } else if (mageObject instanceof Spell) { + this.zoneChangeCounter = ((Spell)mageObject).getZoneChangeCounter(); } else { zoneChangeCounter = 0; } @@ -111,11 +114,17 @@ public class MageObjectReference implements Comparable { return card.getZoneChangeCounter()== zoneChangeCounter && card.getId().equals(sourceId); } + public boolean refersTo(Spell spell) { + return spell.getZoneChangeCounter()== zoneChangeCounter && spell.getSourceId().equals(sourceId); + } + public boolean refersTo(MageObject mageObject) { if (mageObject instanceof Permanent) { - return equals(((Permanent)mageObject)); + return refersTo(((Permanent)mageObject)); + } else if (mageObject instanceof Spell) { + return refersTo(((Spell)mageObject)); } else if (mageObject instanceof Card) { - return equals(((Card)mageObject)); + return refersTo(((Card)mageObject)); } return mageObject.getId().equals(sourceId); } diff --git a/Mage/src/mage/abilities/effects/common/PreventDamageBySourceEffect.java b/Mage/src/mage/abilities/effects/common/PreventDamageBySourceEffect.java new file mode 100644 index 0000000000..088c35baea --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/PreventDamageBySourceEffect.java @@ -0,0 +1,89 @@ +/* + * 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.MageObject; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.effects.PreventionEffectImpl; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.filter.FilterObject; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.TargetSource; + +/** + * + * @author LevelX2 + */ + +public class PreventDamageBySourceEffect extends PreventionEffectImpl { + + private TargetSource target; + private MageObjectReference mageObjectReference; + + public PreventDamageBySourceEffect() { + this(new FilterObject("a")); + } + + public PreventDamageBySourceEffect(FilterObject filterObject) { + super(Duration.EndOfTurn); + this.target = new TargetSource(filterObject); + staticText = "Prevent all damage " + filterObject.getMessage() + " source of your choice would deal this turn"; + } + + public PreventDamageBySourceEffect(final PreventDamageBySourceEffect effect) { + super(effect); + this.target = effect.target.copy(); + this.mageObjectReference = effect.mageObjectReference; + } + + @Override + public PreventDamageBySourceEffect copy() { + return new PreventDamageBySourceEffect(this); + } + + @Override + public void init(Ability source, Game game) { + this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); + mageObjectReference = new MageObjectReference(target.getFirstTarget(), game); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (super.applies(event, source, game)) { + MageObject mageObject = game.getObject(event.getSourceId()); + if (mageObject != null && mageObjectReference.refersTo(mageObject)) { + return true; + } + } + return false; + } + +} diff --git a/Mage/src/mage/target/TargetSource.java b/Mage/src/mage/target/TargetSource.java index 5eced2dae6..e57b2760ea 100644 --- a/Mage/src/mage/target/TargetSource.java +++ b/Mage/src/mage/target/TargetSource.java @@ -28,20 +28,19 @@ package mage.target; -import mage.constants.Zone; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.cards.Card; +import mage.constants.Zone; import mage.filter.FilterObject; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.stack.StackObject; import mage.players.Player; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - /** * * @author BetaSteward_at_googlemail.com diff --git a/Mage/src/mage/target/targetpointer/FirstTargetPointer.java b/Mage/src/mage/target/targetpointer/FirstTargetPointer.java index ce66a348cc..236d0ce7d7 100644 --- a/Mage/src/mage/target/targetpointer/FirstTargetPointer.java +++ b/Mage/src/mage/target/targetpointer/FirstTargetPointer.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.UUID; import mage.abilities.Ability; import mage.cards.Card; -import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent;