From d4f8224ee96b7be175cdfc0218ebf595c0c0437e Mon Sep 17 00:00:00 2001 From: JOAC69 Date: Wed, 21 Sep 2016 23:48:31 -0500 Subject: [PATCH] Refactor - remove duplicate DamageCantBePreventedEffect classes --- .../src/mage/sets/fatereforged/WildSlash.java | 38 ++------------- .../src/mage/sets/gatecrash/Skullcrack.java | 48 +++---------------- .../src/mage/sets/judgment/FlaringPain.java | 41 ++-------------- .../sets/shadowmoor/EverlastingTorment.java | 37 ++------------ .../DamageCantBePreventedEffect.java | 39 +++++++++++++++ 5 files changed, 56 insertions(+), 147 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/effects/common/continuous/DamageCantBePreventedEffect.java diff --git a/Mage.Sets/src/mage/sets/fatereforged/WildSlash.java b/Mage.Sets/src/mage/sets/fatereforged/WildSlash.java index 97894c7fea..146735aa67 100644 --- a/Mage.Sets/src/mage/sets/fatereforged/WildSlash.java +++ b/Mage.Sets/src/mage/sets/fatereforged/WildSlash.java @@ -27,23 +27,20 @@ */ package mage.sets.fatereforged; -import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.condition.LockedInCondition; import mage.abilities.condition.common.FerociousCondition; import mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect; import mage.abilities.effects.ContinuousRuleModifyingEffect; -import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.continuous.DamageCantBePreventedEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.target.common.TargetCreatureOrPlayer; +import java.util.UUID; + /** * * @author jeffwadsworth @@ -55,7 +52,7 @@ public class WildSlash extends CardImpl { this.expansionSetCode = "FRF"; // Ferocious If you control a creature with power 4 or greater, damage can't be prevented this turn. - ContinuousRuleModifyingEffect effect = new DamageCantBePreventedEffect(); + ContinuousRuleModifyingEffect effect = new DamageCantBePreventedEffect(Duration.EndOfTurn, "damage can't be prevented this turn", false, false); effect.setText("Ferocious — If you control a creature with power 4 or greater, damage can't be prevented this turn.
"); this.getSpellAbility().addEffect(new ConditionalContinuousRuleModifyingEffect(effect, new LockedInCondition(FerociousCondition.getInstance()))); @@ -75,30 +72,3 @@ public class WildSlash extends CardImpl { return new WildSlash(this); } } - -class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { - - public DamageCantBePreventedEffect() { - super(Duration.EndOfTurn, Outcome.Benefit, false, false); - staticText = "damage can't be prevented this turn"; - } - - public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) { - super(effect); - } - - @Override - public DamageCantBePreventedEffect copy() { - return new DamageCantBePreventedEffect(this); - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.PREVENT_DAMAGE; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return true; - } -} diff --git a/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java b/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java index 37ecc4d21e..526ac393cb 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java +++ b/Mage.Sets/src/mage/sets/gatecrash/Skullcrack.java @@ -27,21 +27,17 @@ */ package mage.sets.gatecrash; -import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.abilities.Ability; -import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.common.DamageTargetEffect; import mage.abilities.effects.common.continuous.CantGainLifeAllEffect; +import mage.abilities.effects.common.continuous.DamageCantBePreventedEffect; import mage.cards.CardImpl; +import mage.constants.CardType; import mage.constants.Duration; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.Rarity; import mage.target.TargetPlayer; +import java.util.UUID; + /** * * @author LevelX2 @@ -55,7 +51,7 @@ public class Skullcrack extends CardImpl { // Players can't gain life this turn. Damage can't be prevented this turn. Skullcrack deals 3 damage to target player. this.getSpellAbility().addEffect(new CantGainLifeAllEffect(Duration.EndOfTurn)); - this.getSpellAbility().addEffect(new DamageCantBePreventedEffect()); + this.getSpellAbility().addEffect(new DamageCantBePreventedEffect(Duration.EndOfTurn, "Damage can't be prevented this turn", true, false)); this.getSpellAbility().addEffect(new DamageTargetEffect(3)); this.getSpellAbility().addTarget(new TargetPlayer()); @@ -70,35 +66,3 @@ public class Skullcrack extends CardImpl { return new Skullcrack(this); } } - -class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { - - public DamageCantBePreventedEffect() { - super(Duration.EndOfTurn, Outcome.Benefit); - staticText = "Damage can't be prevented this turn"; - } - - public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) { - super(effect); - } - - @Override - public DamageCantBePreventedEffect copy() { - return new DamageCantBePreventedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.PREVENT_DAMAGE; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return true; - } -} diff --git a/Mage.Sets/src/mage/sets/judgment/FlaringPain.java b/Mage.Sets/src/mage/sets/judgment/FlaringPain.java index 77695d977b..c3a90465aa 100644 --- a/Mage.Sets/src/mage/sets/judgment/FlaringPain.java +++ b/Mage.Sets/src/mage/sets/judgment/FlaringPain.java @@ -27,19 +27,16 @@ */ package mage.sets.judgment; -import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.common.continuous.DamageCantBePreventedEffect; import mage.abilities.keyword.FlashbackAbility; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.TimingRule; -import mage.game.Game; -import mage.game.events.GameEvent; + +import java.util.UUID; /** * @@ -53,7 +50,7 @@ public class FlaringPain extends CardImpl { // Damage can't be prevented this turn. - this.getSpellAbility().addEffect(new DamageCantBePreventedEffect()); + this.getSpellAbility().addEffect(new DamageCantBePreventedEffect(Duration.EndOfTurn, "Damage can't be prevented this turn", false, false)); // Flashback {R} this.addAbility(new FlashbackAbility(new ManaCostsImpl("{R}"), TimingRule.INSTANT)); } @@ -67,33 +64,3 @@ public class FlaringPain extends CardImpl { return new FlaringPain(this); } } - -class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { - - public DamageCantBePreventedEffect() { - super(Duration.EndOfTurn, Outcome.Benefit, false, false); - staticText = "Damage can't be prevented this turn"; - } - - public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) { - super(effect); - } - - @Override - public DamageCantBePreventedEffect copy() { - return new DamageCantBePreventedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE)) { - return true; - } - return false; - } -} diff --git a/Mage.Sets/src/mage/sets/shadowmoor/EverlastingTorment.java b/Mage.Sets/src/mage/sets/shadowmoor/EverlastingTorment.java index 90088643d4..382d70e0ff 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/EverlastingTorment.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/EverlastingTorment.java @@ -30,9 +30,9 @@ package mage.sets.shadowmoor; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ReplacementEffectImpl; import mage.abilities.effects.common.continuous.CantGainLifeAllEffect; +import mage.abilities.effects.common.continuous.DamageCantBePreventedEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; @@ -60,7 +60,8 @@ public class EverlastingTorment extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantGainLifeAllEffect())); // Damage can't be prevented. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DamageCantBePreventedEffect(Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new DamageCantBePreventedEffect(Duration.WhileOnBattlefield, "Damage can't be prevented", true, false))); // All damage is dealt as though its source had wither. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DamageDealtAsIfSourceHadWitherEffect())); @@ -77,38 +78,6 @@ public class EverlastingTorment extends CardImpl { } } -class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { - - public DamageCantBePreventedEffect(Duration duration) { - super(duration, Outcome.Benefit); - staticText = "Damage can't be prevented"; - } - - public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) { - super(effect); - } - - @Override - public DamageCantBePreventedEffect copy() { - return new DamageCantBePreventedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE); - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - return true; - } -} - class DamageDealtAsIfSourceHadWitherEffect extends ReplacementEffectImpl { public DamageDealtAsIfSourceHadWitherEffect() { diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/DamageCantBePreventedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/DamageCantBePreventedEffect.java new file mode 100644 index 0000000000..08b432f31b --- /dev/null +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/DamageCantBePreventedEffect.java @@ -0,0 +1,39 @@ +package mage.abilities.effects.common.continuous; + +import mage.abilities.Ability; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.game.Game; +import mage.game.events.GameEvent; + +public class DamageCantBePreventedEffect extends ContinuousRuleModifyingEffectImpl { + public DamageCantBePreventedEffect(Duration duration, String staticText, boolean messageToUser, boolean messageToLog) { + super(duration, Outcome.Benefit, messageToUser, messageToLog); + this.staticText = staticText; + } + + public DamageCantBePreventedEffect(final DamageCantBePreventedEffect effect) { + super(effect); + } + + @Override + public DamageCantBePreventedEffect copy() { + return new DamageCantBePreventedEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE); + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + return true; + } +}