diff --git a/Mage.Sets/src/mage/cards/c/Conservator.java b/Mage.Sets/src/mage/cards/c/Conservator.java index 71569c84b3..4d4f57523a 100644 --- a/Mage.Sets/src/mage/cards/c/Conservator.java +++ b/Mage.Sets/src/mage/cards/c/Conservator.java @@ -32,28 +32,26 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.target.TargetPlayer; /** * * @author KholdFuzion - + * */ public class Conservator extends CardImpl { public Conservator(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{4}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); // {3}, {tap}: Prevent the next 2 damage that would be dealt to you this turn. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConservatorEffect(), new GenericManaCost(3)); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, 2), new GenericManaCost(3)); ability.addTarget(new TargetPlayer()); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -68,56 +66,3 @@ public class Conservator extends CardImpl { return new Conservator(this); } } - -class ConservatorEffect extends PreventionEffectImpl { - - private int amount = 2; - - public ConservatorEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 2 damage that would be dealt to you this turn"; - } - - public ConservatorEffect(final ConservatorEffect effect) { - super(effect); - this.amount = effect.amount; - } - - @Override - public ConservatorEffect copy() { - return new ConservatorEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage >= this.amount) { - event.setAmount(damage - this.amount); - damage = this.amount; - this.used = true; - } else { - event.setAmount(0); - this.amount -= damage; - } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), damage)); - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DecoratedGriffin.java b/Mage.Sets/src/mage/cards/d/DecoratedGriffin.java index b6f3b85798..2d728288d1 100644 --- a/Mage.Sets/src/mage/cards/d/DecoratedGriffin.java +++ b/Mage.Sets/src/mage/cards/d/DecoratedGriffin.java @@ -29,18 +29,15 @@ package mage.cards.d; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; /** * @@ -49,7 +46,7 @@ import mage.game.events.GameEvent; public class DecoratedGriffin extends CardImpl { public DecoratedGriffin(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{W}"); this.subtype.add("Griffin"); this.power = new MageInt(2); @@ -57,8 +54,8 @@ public class DecoratedGriffin extends CardImpl { // Flying this.addAbility(FlyingAbility.getInstance()); - // {1}{W}: Prevent the next 1 damage that would be dealt to you this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new DecoratedGriffinPreventEffect(), new ManaCostsImpl("{1}{W}"))); + // {1}{W}: Prevent the next 1 combat damage that would be dealt to you this turn. + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, true, true, 1), new ManaCostsImpl("{1}{W}"))); } public DecoratedGriffin(final DecoratedGriffin card) { @@ -70,33 +67,3 @@ public class DecoratedGriffin extends CardImpl { return new DecoratedGriffin(this); } } - -class DecoratedGriffinPreventEffect extends PreventionEffectImpl { - - public DecoratedGriffinPreventEffect() { - super(Duration.EndOfTurn, 1, false, true); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - public DecoratedGriffinPreventEffect(final DecoratedGriffinPreventEffect effect) { - super(effect); - } - - @Override - public DecoratedGriffinPreventEffect copy() { - return new DecoratedGriffinPreventEffect(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) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/d/DruidsDeliverance.java b/Mage.Sets/src/mage/cards/d/DruidsDeliverance.java index 1ff726690d..4fd41b50ae 100644 --- a/Mage.Sets/src/mage/cards/d/DruidsDeliverance.java +++ b/Mage.Sets/src/mage/cards/d/DruidsDeliverance.java @@ -28,16 +28,12 @@ package mage.cards.d; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.abilities.Ability; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.common.PopulateEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.game.Game; -import mage.game.events.DamageEvent; -import mage.game.events.GameEvent; +import mage.constants.CardType; +import mage.constants.Duration; /** * @@ -46,12 +42,11 @@ import mage.game.events.GameEvent; public class DruidsDeliverance extends CardImpl { public DruidsDeliverance(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{1}{G}"); - + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{G}"); // Prevent all combat damage that would be dealt to you this turn. Populate. // (Create a token that's a copy of a creature token you control.) - this.getSpellAbility().addEffect(new DruidsDeliverancePreventCombatDamageEffect()); + this.getSpellAbility().addEffect(new PreventDamageToControllerEffect(Duration.EndOfTurn, true, false, Integer.MAX_VALUE)); this.getSpellAbility().addEffect(new PopulateEffect()); } @@ -64,49 +59,3 @@ public class DruidsDeliverance extends CardImpl { return new DruidsDeliverance(this); } } - -class DruidsDeliverancePreventCombatDamageEffect extends PreventionEffectImpl { - - public DruidsDeliverancePreventCombatDamageEffect() { - super(Duration.EndOfTurn); - staticText = "Prevent all combat damage that would be dealt to you this turn"; - } - - public DruidsDeliverancePreventCombatDamageEffect(final DruidsDeliverancePreventCombatDamageEffect effect) { - super(effect); - } - - @Override - public DruidsDeliverancePreventCombatDamageEffect copy() { - return new DruidsDeliverancePreventCombatDamageEffect(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.getSourceId(), 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.getSourceId(), source.getControllerId(), damage)); - return true; - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (super.applies(event, source, game)) { - DamageEvent damageEvent = (DamageEvent) event; - if (event.getTargetId().equals(source.getControllerId()) && damageEvent.isCombatDamage()) { - return true; - } - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/e/EsperBattlemage.java b/Mage.Sets/src/mage/cards/e/EsperBattlemage.java index 95d078b526..6314f09209 100644 --- a/Mage.Sets/src/mage/cards/e/EsperBattlemage.java +++ b/Mage.Sets/src/mage/cards/e/EsperBattlemage.java @@ -28,21 +28,18 @@ package mage.cards.e; import java.util.UUID; +import mage.MageInt; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.ColoredManaCost; +import mage.abilities.effects.common.PreventDamageToControllerEffect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.ColoredManaSymbol; import mage.constants.Duration; import mage.constants.Zone; -import mage.MageInt; -import mage.abilities.Ability; -import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.costs.mana.ColoredManaCost; -import mage.abilities.effects.PreventionEffectImpl; -import mage.abilities.effects.common.continuous.BoostTargetEffect; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.target.common.TargetCreaturePermanent; /** @@ -52,7 +49,7 @@ import mage.target.common.TargetCreaturePermanent; public class EsperBattlemage extends CardImpl { public EsperBattlemage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{2}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}{U}"); this.subtype.add("Human"); this.subtype.add("Wizard"); @@ -60,7 +57,7 @@ public class EsperBattlemage extends CardImpl { this.toughness = new MageInt(2); // {W}, {tap}: Prevent the next 2 damage that would be dealt to you this turn. SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new EsperBattlemageEffect(), + new PreventDamageToControllerEffect(Duration.EndOfTurn, 2), new ColoredManaCost(ColoredManaSymbol.W)); ability.addCost(new TapSourceCost()); this.addAbility(ability); @@ -82,56 +79,3 @@ public class EsperBattlemage extends CardImpl { return new EsperBattlemage(this); } } - -class EsperBattlemageEffect extends PreventionEffectImpl { - - private int amount = 2; - - public EsperBattlemageEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 2 damage that would be dealt to you this turn"; - } - - public EsperBattlemageEffect(final EsperBattlemageEffect effect) { - super(effect); - this.amount = effect.amount; - } - - @Override - public EsperBattlemageEffect copy() { - return new EsperBattlemageEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage >= this.amount) { - event.setAmount(damage - this.amount); - damage = this.amount; - this.used = true; - } else { - event.setAmount(0); - this.amount -= damage; - } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), damage)); - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/g/GlacialChasm.java b/Mage.Sets/src/mage/cards/g/GlacialChasm.java index 9297cfee82..d08dde2007 100644 --- a/Mage.Sets/src/mage/cards/g/GlacialChasm.java +++ b/Mage.Sets/src/mage/cards/g/GlacialChasm.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.PayLifeCost; -import mage.abilities.effects.common.PreventAllDamageToControllerEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.effects.common.SacrificeControllerEffect; import mage.abilities.effects.common.combat.CantAttackAnyPlayerAllEffect; import mage.abilities.keyword.CumulativeUpkeepAbility; @@ -63,7 +63,7 @@ public class GlacialChasm extends CardImpl { filter.add(new ControllerPredicate(TargetController.YOU)); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantAttackAnyPlayerAllEffect(Duration.WhileOnBattlefield, filter))); // Prevent all damage that would be dealt to you. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToControllerEffect(Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.WhileOnBattlefield))); } public GlacialChasm(final GlacialChasm card) { diff --git a/Mage.Sets/src/mage/cards/p/PalliationAccord.java b/Mage.Sets/src/mage/cards/p/PalliationAccord.java index 6a8c024505..a928063103 100644 --- a/Mage.Sets/src/mage/cards/p/PalliationAccord.java +++ b/Mage.Sets/src/mage/cards/p/PalliationAccord.java @@ -28,11 +28,10 @@ package mage.cards.p; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.BecomesTappedTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.RemoveCountersSourceCost; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -43,8 +42,6 @@ import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.ControllerPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; /** * @@ -59,13 +56,15 @@ public class PalliationAccord extends CardImpl { } public PalliationAccord(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{W}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{U}"); // Whenever a creature an opponent controls becomes tapped, put a shield counter on Palliation Accord. this.addAbility(new BecomesTappedTriggeredAbility(new AddCountersSourceEffect(CounterType.SHIELD.createInstance()), false, filter)); // Remove a shield counter from Palliation Accord: Prevent the next 1 damage that would be dealt to you this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PalliationAccordPreventionEffect(), new RemoveCountersSourceCost(CounterType.SHIELD.createInstance()))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, + new PreventDamageToControllerEffect(Duration.EndOfTurn, 1), + new RemoveCountersSourceCost(CounterType.SHIELD.createInstance()))); } public PalliationAccord(final PalliationAccord card) { @@ -77,49 +76,3 @@ public class PalliationAccord extends CardImpl { return new PalliationAccord(this); } } - -class PalliationAccordPreventionEffect extends PreventionEffectImpl { - - public PalliationAccordPreventionEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - public PalliationAccordPreventionEffect(final PalliationAccordPreventionEffect effect) { - super(effect); - } - - @Override - public PalliationAccordPreventionEffect copy() { - return new PalliationAccordPreventionEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage > 0) { - event.setAmount(damage - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), 1)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/r/ReinforcedBulwark.java b/Mage.Sets/src/mage/cards/r/ReinforcedBulwark.java index a749851d0f..1454a9ca4b 100644 --- a/Mage.Sets/src/mage/cards/r/ReinforcedBulwark.java +++ b/Mage.Sets/src/mage/cards/r/ReinforcedBulwark.java @@ -28,19 +28,16 @@ package mage.cards.r; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Zone; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.keyword.DefenderAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Zone; /** * @@ -49,7 +46,7 @@ import mage.game.events.GameEvent; public class ReinforcedBulwark extends CardImpl { public ReinforcedBulwark(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{3}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); this.subtype.add("Wall"); this.power = new MageInt(0); this.toughness = new MageInt(4); @@ -57,7 +54,7 @@ public class ReinforcedBulwark extends CardImpl { // Defender this.addAbility(DefenderAbility.getInstance()); // {tap}: Prevent the next 1 damage that would be dealt to you this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReinforcedBulwarkEffect(), new TapSourceCost())); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, 1), new TapSourceCost())); } public ReinforcedBulwark(final ReinforcedBulwark card) { @@ -69,49 +66,3 @@ public class ReinforcedBulwark extends CardImpl { return new ReinforcedBulwark(this); } } - -class ReinforcedBulwarkEffect extends PreventionEffectImpl { - - public ReinforcedBulwarkEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - public ReinforcedBulwarkEffect(final ReinforcedBulwarkEffect effect) { - super(effect); - } - - @Override - public ReinforcedBulwarkEffect copy() { - return new ReinforcedBulwarkEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage > 0) { - event.setAmount(damage - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), 1)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/r/RiotControl.java b/Mage.Sets/src/mage/cards/r/RiotControl.java index 632b79d852..5c4b0f4d8b 100644 --- a/Mage.Sets/src/mage/cards/r/RiotControl.java +++ b/Mage.Sets/src/mage/cards/r/RiotControl.java @@ -34,7 +34,7 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount; import mage.abilities.effects.common.GainLifeEffect; -import mage.abilities.effects.common.PreventAllDamageToControllerEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.TargetController; @@ -60,7 +60,7 @@ public class RiotControl extends CardImpl { // Gain 1 life for each creature your opponents control. Prevent all damage that would be dealt to you this turn. this.getSpellAbility().addEffect(new GainLifeEffect(new PermanentsOnBattlefieldCount(filter))); - this.getSpellAbility().addEffect(new PreventAllDamageToControllerEffect(Duration.EndOfTurn)); + this.getSpellAbility().addEffect(new PreventDamageToControllerEffect(Duration.EndOfTurn)); } diff --git a/Mage.Sets/src/mage/cards/s/SecurityBlockade.java b/Mage.Sets/src/mage/cards/s/SecurityBlockade.java index 8eb67b5301..8e6168853d 100644 --- a/Mage.Sets/src/mage/cards/s/SecurityBlockade.java +++ b/Mage.Sets/src/mage/cards/s/SecurityBlockade.java @@ -25,29 +25,26 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.cards.s; import java.util.UUID; -import mage.constants.AttachmentType; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.AttachmentType; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.permanent.token.KnightToken; import mage.target.TargetPermanent; import mage.target.common.TargetLandPermanent; @@ -60,8 +57,8 @@ public class SecurityBlockade extends CardImpl { static final String rule = "Enchanted land has \"{T}: Prevent the next 1 damage that would be dealt to you this turn.\""; - public SecurityBlockade (UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{W}"); + public SecurityBlockade(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}"); this.subtype.add("Aura"); this.color.setWhite(true); @@ -76,11 +73,11 @@ public class SecurityBlockade extends CardImpl { this.addAbility(new EntersBattlefieldTriggeredAbility(new CreateTokenEffect(new KnightToken()))); // Enchanted land has "{T}: Prevent the next 1 damage that would be dealt to you this turn." - ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SecurityBlockadePreventionEffect(), new TapSourceCost()); + ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, 1), new TapSourceCost()); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(ability, AttachmentType.AURA, Duration.WhileOnBattlefield, rule))); } - public SecurityBlockade (final SecurityBlockade card) { + public SecurityBlockade(final SecurityBlockade card) { super(card); } @@ -90,48 +87,3 @@ public class SecurityBlockade extends CardImpl { } } -class SecurityBlockadePreventionEffect extends PreventionEffectImpl { - - public SecurityBlockadePreventionEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - public SecurityBlockadePreventionEffect(final SecurityBlockadePreventionEffect effect) { - super(effect); - } - - @Override - public SecurityBlockadePreventionEffect copy() { - return new SecurityBlockadePreventionEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage > 0) { - event.setAmount(damage - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), 1)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/s/ShieldOfTheAges.java b/Mage.Sets/src/mage/cards/s/ShieldOfTheAges.java index f0c8a0e08a..e82e27b816 100644 --- a/Mage.Sets/src/mage/cards/s/ShieldOfTheAges.java +++ b/Mage.Sets/src/mage/cards/s/ShieldOfTheAges.java @@ -28,17 +28,14 @@ package mage.cards.s; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import mage.game.Game; -import mage.game.events.GameEvent; /** * @@ -47,10 +44,10 @@ import mage.game.events.GameEvent; public class ShieldOfTheAges extends CardImpl { public ShieldOfTheAges(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{2}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}"); // {2}: Prevent the next 1 damage that would be dealt to you this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ShieldOfTheAgesEffect(), new GenericManaCost(2))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, 1), new GenericManaCost(2))); } public ShieldOfTheAges(final ShieldOfTheAges card) { @@ -62,49 +59,3 @@ public class ShieldOfTheAges extends CardImpl { return new ShieldOfTheAges(this); } } - -class ShieldOfTheAgesEffect extends PreventionEffectImpl { - - public ShieldOfTheAgesEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - public ShieldOfTheAgesEffect(final ShieldOfTheAgesEffect effect) { - super(effect); - } - - @Override - public ShieldOfTheAgesEffect copy() { - return new ShieldOfTheAgesEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage > 0) { - event.setAmount(damage - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), 1)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/s/SolitaryConfinement.java b/Mage.Sets/src/mage/cards/s/SolitaryConfinement.java index 328e1d400f..5aea33bc1e 100644 --- a/Mage.Sets/src/mage/cards/s/SolitaryConfinement.java +++ b/Mage.Sets/src/mage/cards/s/SolitaryConfinement.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.DiscardTargetCost; -import mage.abilities.effects.common.PreventAllDamageToControllerEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.effects.common.SacrificeSourceUnlessPaysEffect; import mage.abilities.effects.common.SkipDrawStepEffect; import mage.abilities.effects.common.continuous.GainAbilityControllerEffect; @@ -63,7 +63,7 @@ public class SolitaryConfinement extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControllerEffect(ShroudAbility.getInstance()))); // Prevent all damage that would be dealt to you. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToControllerEffect(Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.WhileOnBattlefield))); } public SolitaryConfinement(final SolitaryConfinement card) { diff --git a/Mage.Sets/src/mage/cards/s/SpiritOfResistance.java b/Mage.Sets/src/mage/cards/s/SpiritOfResistance.java index 9fcf83a586..b7aad6b8fb 100644 --- a/Mage.Sets/src/mage/cards/s/SpiritOfResistance.java +++ b/Mage.Sets/src/mage/cards/s/SpiritOfResistance.java @@ -36,7 +36,7 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.condition.Condition; import mage.abilities.decorator.ConditionalReplacementEffect; import mage.abilities.effects.Effect; -import mage.abilities.effects.common.PreventAllDamageToControllerEffect; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -57,7 +57,7 @@ public class SpiritOfResistance extends CardImpl { // As long as you control a permanent of each color, prevent all damage that would be dealt to you. Effect effect = new ConditionalReplacementEffect( - new PreventAllDamageToControllerEffect(Duration.WhileOnBattlefield), + new PreventDamageToControllerEffect(Duration.WhileOnBattlefield), SpiritOfResistanceCondition.getInstance()); effect.setText("As long as you control a permanent of each color, prevent all damage that would be dealt to you."); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); diff --git a/Mage.Sets/src/mage/cards/t/ThoughtLash.java b/Mage.Sets/src/mage/cards/t/ThoughtLash.java index b664f06ec1..07056ee4d8 100644 --- a/Mage.Sets/src/mage/cards/t/ThoughtLash.java +++ b/Mage.Sets/src/mage/cards/t/ThoughtLash.java @@ -33,7 +33,7 @@ import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.ExileFromTopOfLibraryCost; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.keyword.CumulativeUpkeepAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; @@ -55,7 +55,7 @@ import mage.players.Player; public class ThoughtLash extends CardImpl { public ThoughtLash(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{U}{U}"); // Cumulative upkeep - Exile the top card of your library. this.addAbility(new CumulativeUpkeepAbility(new ExileFromTopOfLibraryCost(1))); @@ -64,7 +64,7 @@ public class ThoughtLash extends CardImpl { this.addAbility(new ThoughtLashTriggeredAbility()); // Exile the top card of your library: Prevent the next 1 damage that would be dealt to you this turn. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ThoughtLashPreventionEffect(), new ExileFromTopOfLibraryCost(1))); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PreventDamageToControllerEffect(Duration.EndOfTurn, 1), new ExileFromTopOfLibraryCost(1))); } public ThoughtLash(final ThoughtLash card) { @@ -136,46 +136,3 @@ class ThoughtLashExileLibraryEffect extends OneShotEffect { return false; } } - -class ThoughtLashPreventionEffect extends PreventionEffectImpl { - - ThoughtLashPreventionEffect() { - super(Duration.EndOfTurn); - this.staticText = "Prevent the next 1 damage that would be dealt to you this turn"; - } - - ThoughtLashPreventionEffect(final ThoughtLashPreventionEffect effect) { - super(effect); - } - - @Override - public ThoughtLashPreventionEffect copy() { - return new ThoughtLashPreventionEffect(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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - if (damage > 0) { - event.setAmount(damage - 1); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), 1)); - } - } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return !this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId()); - } -} diff --git a/Mage.Sets/src/mage/cards/v/VengefulArchon.java b/Mage.Sets/src/mage/cards/v/VengefulArchon.java index 4f884c54fe..66d1c3f846 100644 --- a/Mage.Sets/src/mage/cards/v/VengefulArchon.java +++ b/Mage.Sets/src/mage/cards/v/VengefulArchon.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,26 +20,26 @@ * 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.cards.v; import java.util.UUID; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.PreventionEffectData; +import mage.abilities.effects.common.PreventDamageToControllerEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; @@ -52,13 +52,16 @@ import mage.target.TargetPlayer; public class VengefulArchon extends CardImpl { public VengefulArchon(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{4}{W}{W}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{W}{W}{W}"); this.subtype.add("Archon"); this.power = new MageInt(7); this.toughness = new MageInt(7); + // Flying this.addAbility(FlyingAbility.getInstance()); + + // {X}: Prevent the next X damage that would be dealt to you this turn. If damage is prevented this way, Vengeful Archon deals that much damage to target player. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new VengefulArchonEffect(), new ManaCostsImpl("{X}")); ability.addTarget(new TargetPlayer()); this.addAbility(ability); @@ -75,18 +78,15 @@ public class VengefulArchon extends CardImpl { } -class VengefulArchonEffect extends PreventionEffectImpl { - - protected int amount = 0; +class VengefulArchonEffect extends PreventDamageToControllerEffect { public VengefulArchonEffect() { - super(Duration.EndOfTurn); + super(Duration.EndOfTurn, 0, false, true, new ManacostVariableValue()); staticText = "Prevent the next X damage that would be dealt to you this turn. If damage is prevented this way, {this} deals that much damage to target player"; } public VengefulArchonEffect(final VengefulArchonEffect effect) { super(effect); - this.amount = effect.amount; } @Override @@ -95,46 +95,16 @@ class VengefulArchonEffect extends PreventionEffectImpl { } @Override - public void init(Ability source, Game game) { - super.init(source, game); - amount = source.getManaCostsToPay().getX(); - } - - @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.getControllerId(), source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { + protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) { + PreventionEffectData preventionEffectData = super.preventDamageAction(event, source, game); + int damage = preventionEffectData.getPreventedDamage(); + if (damage > 0) { Player player = game.getPlayer(source.getFirstTarget()); if (player != null) { - int damage = event.getAmount(); - if (event.getAmount() >= this.amount) { - event.setAmount(damage - this.amount); - damage = this.amount; - this.used = true; - } else { - event.setAmount(0); - this.amount -= damage; - } - player.damage(damage, source.getSourceId(), game, false, true); - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, - source.getControllerId(), source.getSourceId(), source.getControllerId(), damage)); } } - return false; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game) && event.getTargetId().equals(source.getControllerId())) { - return true; - } - return false; + return preventionEffectData; } } diff --git a/Mage/src/main/java/mage/abilities/effects/PreventionEffectImpl.java b/Mage/src/main/java/mage/abilities/effects/PreventionEffectImpl.java index 89217c3bc8..d5ae0822a7 100644 --- a/Mage/src/main/java/mage/abilities/effects/PreventionEffectImpl.java +++ b/Mage/src/main/java/mage/abilities/effects/PreventionEffectImpl.java @@ -1,16 +1,16 @@ /* * 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 @@ -20,29 +20,29 @@ * 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; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; import mage.constants.Duration; import mage.constants.EffectType; import mage.constants.Outcome; -import mage.abilities.Ability; import mage.game.Game; import mage.game.events.DamageEvent; import mage.game.events.GameEvent; - /** * * @author BetaSteward_at_googlemail.com */ public abstract class PreventionEffectImpl extends ReplacementEffectImpl implements PreventionEffect { - + + protected DynamicValue amountToPreventDynamic; protected int amountToPrevent; protected final boolean onlyCombat; protected boolean consumable; @@ -54,10 +54,25 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat) { this(duration, amountToPrevent, onlyCombat, true); } + public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable) { + this(duration, amountToPrevent, onlyCombat, consumable, null); + } + + /** + * + * @param duration + * @param amountToPrevent + * @param onlyCombat + * @param consumable + * @param amountToPreventDynamic if set, on init amountToPrevent is set to + * calculated value of amountToPreventDynamic + */ + public PreventionEffectImpl(Duration duration, int amountToPrevent, boolean onlyCombat, boolean consumable, DynamicValue amountToPreventDynamic) { super(duration, Outcome.PreventDamage); this.effectType = EffectType.PREVENTION; this.amountToPrevent = amountToPrevent; + this.amountToPreventDynamic = amountToPreventDynamic; this.onlyCombat = onlyCombat; this.consumable = consumable; } @@ -65,10 +80,18 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme public PreventionEffectImpl(final PreventionEffectImpl effect) { super(effect); this.amountToPrevent = effect.amountToPrevent; + this.amountToPreventDynamic = effect.amountToPreventDynamic; this.onlyCombat = effect.onlyCombat; this.consumable = effect.consumable; } + @Override + public void init(Ability source, Game game) { + super.init(source, game); + if (amountToPreventDynamic != null) { + amountToPrevent = amountToPreventDynamic.calculate(game, source, this); + } + } @Override public boolean apply(Game game, Ability source) { @@ -84,11 +107,11 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme } if (amountToPrevent == 0) { this.discard(); - } + } } return preventionData; } - + @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { preventDamageAction(event, source, game); @@ -109,7 +132,7 @@ public abstract class PreventionEffectImpl extends ReplacementEffectImpl impleme @Override public boolean applies(GameEvent event, Ability source, Game game) { - return event.getFlag() && (!onlyCombat || ((DamageEvent)event).isCombatDamage()); + return event.getFlag() && (!onlyCombat || ((DamageEvent) event).isCombatDamage()); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java similarity index 58% rename from Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToControllerEffect.java rename to Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java index 1603da8bcd..f802b73bba 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java @@ -25,41 +25,48 @@ * 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.constants.Duration; import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.PreventionEffectImpl; +import mage.constants.Duration; import mage.game.Game; import mage.game.events.GameEvent; -/** - * - * @author LevelX2 - */ +public class PreventDamageToControllerEffect extends PreventionEffectImpl { + public PreventDamageToControllerEffect(Duration duration) { + this(duration, false, false, Integer.MAX_VALUE); + } -public class PreventAllDamageToControllerEffect extends PreventionEffectImpl { + public PreventDamageToControllerEffect(Duration duration, int amountToPrevent) { + this(duration, false, true, amountToPrevent); + } - public PreventAllDamageToControllerEffect(Duration duration) { - super(duration, Integer.MAX_VALUE, false); + public PreventDamageToControllerEffect(Duration duration, boolean onlyCombat, boolean consumable, int amountToPrevent) { + super(duration, amountToPrevent, onlyCombat, consumable, null); + } + + public PreventDamageToControllerEffect(Duration duration, boolean onlyCombat, boolean consumable, DynamicValue amountToPreventDynamic) { + super(duration, 0, onlyCombat, consumable, amountToPreventDynamic); staticText = setText(); } - public PreventAllDamageToControllerEffect(final PreventAllDamageToControllerEffect effect) { + public PreventDamageToControllerEffect(final PreventDamageToControllerEffect effect) { super(effect); + staticText = setText(); } @Override - public PreventAllDamageToControllerEffect copy() { - return new PreventAllDamageToControllerEffect(this); + public PreventDamageToControllerEffect copy() { + return new PreventDamageToControllerEffect(this); } @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId())){ + if (event.getTargetId().equals(source.getControllerId())) { return true; } @@ -68,9 +75,21 @@ public class PreventAllDamageToControllerEffect extends PreventionEffectImpl { } private String setText() { - StringBuilder sb = new StringBuilder("Prevent all damage that would be dealt to you"); + // Prevent the next X damage that would be dealt to you this turn + StringBuilder sb = new StringBuilder("Prevent "); + if (amountToPrevent == Integer.MAX_VALUE) { + sb.append("all "); + } else if (amountToPreventDynamic != null) { + sb.append("the next ").append(amountToPreventDynamic.toString()).append(" "); + } else { + sb.append("the next ").append(amountToPrevent).append(" "); + } + if (onlyCombat) { + sb.append("combat "); + } + sb.append("damage that would be dealt to you"); if (duration.equals(Duration.EndOfTurn)) { - sb.append(" this turn"); + sb.append(" this turn"); } return sb.toString(); }