* Fixed / reworked prevent damage by source effect (related to Burrenton Forge-Tender, Pay no Heed, Prahv, Spires of Order).

This commit is contained in:
LevelX2 2015-02-01 16:05:35 +01:00
parent da26df4c7b
commit 8192744697
7 changed files with 114 additions and 111 deletions

View file

@ -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;
}
}

View file

@ -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()));
}

View file

@ -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;
}
}

View file

@ -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<MageObjectReference> {
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<MageObjectReference> {
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);
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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;