diff --git a/Mage.Sets/src/mage/cards/b/BlindingFog.java b/Mage.Sets/src/mage/cards/b/BlindingFog.java index cd3628ef37e..fd0094616e3 100644 --- a/Mage.Sets/src/mage/cards/b/BlindingFog.java +++ b/Mage.Sets/src/mage/cards/b/BlindingFog.java @@ -1,7 +1,5 @@ - package mage.cards.b; -import java.util.UUID; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; import mage.abilities.keyword.HexproofAbility; @@ -9,11 +7,13 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; +import mage.filter.StaticFilters; + +import java.util.UUID; + import static mage.filter.StaticFilters.FILTER_PERMANENT_CREATURE; -import static mage.filter.StaticFilters.FILTER_PERMANENT_CREATURES; /** - * * @author LevelX2 */ public final class BlindingFog extends CardImpl { @@ -22,7 +22,8 @@ public final class BlindingFog extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{G}"); // Prevent all damage that would be dealt to creatures this turn. - this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, FILTER_PERMANENT_CREATURES)); + this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, StaticFilters.FILTER_PERMANENT_CREATURES)); + // Creatures you control gain hexproof until end of turn. this.getSpellAbility().addEffect(new GainAbilityControlledEffect(HexproofAbility.getInstance(), Duration.EndOfTurn, FILTER_PERMANENT_CREATURE, false)); } diff --git a/Mage.Sets/src/mage/cards/b/BubbleMatrix.java b/Mage.Sets/src/mage/cards/b/BubbleMatrix.java index 625af565777..3fe59d7157c 100644 --- a/Mage.Sets/src/mage/cards/b/BubbleMatrix.java +++ b/Mage.Sets/src/mage/cards/b/BubbleMatrix.java @@ -1,7 +1,5 @@ - package mage.cards.b; -import java.util.UUID; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.cards.CardImpl; @@ -9,10 +7,11 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import static mage.filter.StaticFilters.FILTER_PERMANENT_CREATURES; +import mage.filter.StaticFilters; + +import java.util.UUID; /** - * * @author LoneFox */ public final class BubbleMatrix extends CardImpl { @@ -21,7 +20,7 @@ public final class BubbleMatrix extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); // Prevent all damage that would be dealt to creatures. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, FILTER_PERMANENT_CREATURES))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, StaticFilters.FILTER_PERMANENT_CREATURES))); } public BubbleMatrix(final BubbleMatrix card) { diff --git a/Mage.Sets/src/mage/cards/d/DolmenGate.java b/Mage.Sets/src/mage/cards/d/DolmenGate.java index 24cad2f4d3d..734349f2b7a 100644 --- a/Mage.Sets/src/mage/cards/d/DolmenGate.java +++ b/Mage.Sets/src/mage/cards/d/DolmenGate.java @@ -1,7 +1,5 @@ - package mage.cards.d; -import java.util.UUID; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.cards.CardImpl; @@ -9,23 +7,24 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import mage.filter.common.FilterControlledCreatureInPlay; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.permanent.AttackingPredicate; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class DolmenGate extends CardImpl { - private static final FilterControlledCreatureInPlay filter = new FilterControlledCreatureInPlay("attacking creatures you control"); + private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("attacking creatures you control"); static { - filter.getCreatureFilter().add(AttackingPredicate.instance); + filter.add(AttackingPredicate.instance); } public DolmenGate(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{2}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}"); // Prevent all combat damage that would be dealt to attacking creatures you control. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, filter, true))); diff --git a/Mage.Sets/src/mage/cards/e/EmmaraTandris.java b/Mage.Sets/src/mage/cards/e/EmmaraTandris.java index 11d0794557e..fff826969d5 100644 --- a/Mage.Sets/src/mage/cards/e/EmmaraTandris.java +++ b/Mage.Sets/src/mage/cards/e/EmmaraTandris.java @@ -1,33 +1,32 @@ - package mage.cards.e; -import java.util.UUID; import mage.MageInt; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.common.FilterCreatureOrPlayer; -import mage.filter.predicate.other.PlayerIdPredicate; +import mage.filter.StaticFilters; +import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.ControllerPredicate; import mage.filter.predicate.permanent.TokenPredicate; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class EmmaraTandris extends CardImpl { - private static final FilterCreatureOrPlayer filter = new FilterCreatureOrPlayer("creature tokens you control"); + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature tokens you control"); + static { - filter.getCreatureFilter().add(TokenPredicate.instance); - filter.getCreatureFilter().add(new ControllerPredicate(TargetController.YOU)); - filter.getPlayerFilter().add(new PlayerIdPredicate(UUID.randomUUID())); + filter.add(TokenPredicate.instance); + filter.add(new ControllerPredicate(TargetController.YOU)); } public EmmaraTandris(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{5}{G}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{G}{W}"); addSuperType(SuperType.LEGENDARY); this.subtype.add(SubType.ELF); this.subtype.add(SubType.SHAMAN); @@ -36,7 +35,7 @@ public final class EmmaraTandris extends CardImpl { this.toughness = new MageInt(7); // Prevent all damage that would be dealt to creature tokens you control. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, filter))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, StaticFilters.FILTER_CREATURE_TOKENS))); } public EmmaraTandris(final EmmaraTandris card) { diff --git a/Mage.Sets/src/mage/cards/i/InnerSanctum.java b/Mage.Sets/src/mage/cards/i/InnerSanctum.java index 0e73a30da6b..390d41ac7fc 100644 --- a/Mage.Sets/src/mage/cards/i/InnerSanctum.java +++ b/Mage.Sets/src/mage/cards/i/InnerSanctum.java @@ -1,7 +1,5 @@ - package mage.cards.i; -import java.util.UUID; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.common.PayLifeCost; import mage.abilities.effects.common.PreventAllDamageToAllEffect; @@ -11,10 +9,11 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Zone; -import mage.filter.common.FilterControlledCreatureInPlay; +import mage.filter.StaticFilters; + +import java.util.UUID; /** - * * @author TheElk801 */ public final class InnerSanctum extends CardImpl { @@ -27,7 +26,7 @@ public final class InnerSanctum extends CardImpl { // Prevent all damage that would be dealt to creatures you control. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, - new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, new FilterControlledCreatureInPlay("creatures you control")) + new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, StaticFilters.FILTER_PERMANENT_CREATURES_CONTROLLED) )); } diff --git a/Mage.Sets/src/mage/cards/i/IroasGodOfVictory.java b/Mage.Sets/src/mage/cards/i/IroasGodOfVictory.java index daade1b2155..e2462a2fcc5 100644 --- a/Mage.Sets/src/mage/cards/i/IroasGodOfVictory.java +++ b/Mage.Sets/src/mage/cards/i/IroasGodOfVictory.java @@ -14,7 +14,7 @@ import mage.abilities.keyword.MenaceAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.*; -import mage.filter.common.FilterControlledCreatureInPlay; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.AttackingPredicate; import mage.filter.predicate.permanent.ControllerPredicate; @@ -27,11 +27,11 @@ import java.util.UUID; public final class IroasGodOfVictory extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("Creatures you control"); - private static final FilterControlledCreatureInPlay filterAttacking = new FilterControlledCreatureInPlay("attacking creatures you control"); + private static final FilterControlledCreaturePermanent filterAttacking = new FilterControlledCreaturePermanent("attacking creatures you control"); static { filter.add(new ControllerPredicate(TargetController.YOU)); - filterAttacking.getCreatureFilter().add(AttackingPredicate.instance); + filterAttacking.add(AttackingPredicate.instance); } private static final DynamicValue xValue = new DevotionCount(ColoredManaSymbol.R, ColoredManaSymbol.W); @@ -57,7 +57,6 @@ public final class IroasGodOfVictory extends CardImpl { // Prevent all damage that would be dealt to attacking creatures you control. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, filterAttacking))); - } public IroasGodOfVictory(final IroasGodOfVictory card) { diff --git a/Mage.Sets/src/mage/cards/r/RuneTailKitsuneAscendant.java b/Mage.Sets/src/mage/cards/r/RuneTailKitsuneAscendant.java index 3f40636c58e..d316ea1c25e 100644 --- a/Mage.Sets/src/mage/cards/r/RuneTailKitsuneAscendant.java +++ b/Mage.Sets/src/mage/cards/r/RuneTailKitsuneAscendant.java @@ -1,7 +1,5 @@ - package mage.cards.r; -import java.util.UUID; import mage.MageInt; import mage.abilities.StateTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -9,26 +7,22 @@ import mage.abilities.effects.common.FlipSourceEffect; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.SubType; -import mage.constants.Duration; -import mage.constants.SuperType; -import mage.constants.Zone; -import mage.filter.common.FilterControlledCreatureInPlay; +import mage.constants.*; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.token.TokenImpl; -import mage.game.permanent.token.Token; import mage.players.Player; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class RuneTailKitsuneAscendant extends CardImpl { public RuneTailKitsuneAscendant(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{W}"); addSuperType(SuperType.LEGENDARY); this.subtype.add(SubType.FOX); this.subtype.add(SubType.MONK); @@ -94,8 +88,9 @@ class RuneTailEssence extends TokenImpl { // Prevent all damage that would be dealt to creatures you control. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, - new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, new FilterControlledCreatureInPlay("creatures you control")))); + new PreventAllDamageToAllEffect(Duration.WhileOnBattlefield, StaticFilters.FILTER_CONTROLLED_CREATURES))); } + public RuneTailEssence(final RuneTailEssence token) { super(token); } diff --git a/Mage.Sets/src/mage/cards/s/SafePassage.java b/Mage.Sets/src/mage/cards/s/SafePassage.java index 9b5a2b732ea..500efab8dd7 100644 --- a/Mage.Sets/src/mage/cards/s/SafePassage.java +++ b/Mage.Sets/src/mage/cards/s/SafePassage.java @@ -1,33 +1,26 @@ - - package mage.cards.s; -import java.util.UUID; import mage.abilities.effects.common.PreventAllDamageToAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.TargetController; -import mage.filter.common.FilterCreatureOrPlayer; -import mage.filter.predicate.other.PlayerPredicate; -import mage.filter.predicate.permanent.ControllerPredicate; +import mage.filter.StaticFilters; +import mage.filter.common.FilterPermanentOrPlayer; + +import java.util.UUID; /** - * * @author BetaSteward_at_googlemail.com */ -public final class SafePassage extends CardImpl { +public final class SafePassage extends CardImpl { - private static final FilterCreatureOrPlayer filter = new FilterCreatureOrPlayer("you and creatures you control"); - - static { - filter.getCreatureFilter().add(new ControllerPredicate(TargetController.YOU)); - filter.getPlayerFilter().add(new PlayerPredicate(TargetController.YOU)); - } + private static final FilterPermanentOrPlayer filter = new FilterPermanentOrPlayer("you and creatures you control", + StaticFilters.FILTER_PERMANENT_CREATURES_CONTROLLED, + StaticFilters.FILTER_PLAYER_CONTROLLER); public SafePassage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}"); this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, filter)); } diff --git a/Mage.Sets/src/mage/cards/s/SivvisRuse.java b/Mage.Sets/src/mage/cards/s/SivvisRuse.java index 0ebc135c69e..c8d3b108abb 100644 --- a/Mage.Sets/src/mage/cards/s/SivvisRuse.java +++ b/Mage.Sets/src/mage/cards/s/SivvisRuse.java @@ -1,7 +1,5 @@ - package mage.cards.s; -import java.util.UUID; import mage.abilities.condition.CompoundCondition; import mage.abilities.condition.Condition; import mage.abilities.condition.common.OpponentControlsPermanentCondition; @@ -14,15 +12,16 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.SubType; import mage.filter.FilterPermanent; -import mage.filter.common.FilterControlledCreatureInPlay; +import mage.filter.StaticFilters; import mage.filter.predicate.mageobject.SubtypePredicate; +import java.util.UUID; + /** - * * @author fireshoes */ public final class SivvisRuse extends CardImpl { - + private static final FilterPermanent filterMountain = new FilterPermanent(); private static final FilterPermanent filterPlains = new FilterPermanent(); @@ -32,16 +31,16 @@ public final class SivvisRuse extends CardImpl { } public SivvisRuse(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{W}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{W}{W}"); // If an opponent controls a Mountain and you control a Plains, you may cast this spell without paying its mana cost. Condition condition = new CompoundCondition("If an opponent controls a Mountain and you control a Plains", new OpponentControlsPermanentCondition(filterMountain), new PermanentsOnTheBattlefieldCondition(filterPlains)); this.addAbility(new AlternativeCostSourceAbility(null, condition)); - + // Prevent all damage that would be dealt this turn to creatures you control. - this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, new FilterControlledCreatureInPlay())); + this.getSpellAbility().addEffect(new PreventAllDamageToAllEffect(Duration.EndOfTurn, StaticFilters.FILTER_PERMANENT_CREATURES_CONTROLLED)); } public SivvisRuse(final SivvisRuse card) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java index 93394e11808..b0d619a381e 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PreventAllDamageToAllEffect.java @@ -1,44 +1,46 @@ - - package mage.abilities.effects.common; -import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.PreventionEffectImpl; import mage.constants.Duration; -import mage.filter.FilterInPlay; -import mage.filter.common.FilterCreatureOrPlayer; -import mage.filter.common.FilterCreaturePermanent; +import mage.filter.FilterPermanent; +import mage.filter.FilterPlayer; +import mage.filter.common.FilterPermanentOrPlayer; import mage.filter.predicate.other.PlayerIdPredicate; +import mage.filter.predicate.permanent.PermanentIdPredicate; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; -import mage.players.Player; + +import java.util.UUID; /** - * * @author BetaSteward_at_googlemail.com */ public class PreventAllDamageToAllEffect extends PreventionEffectImpl { - protected FilterInPlay filter; - - public PreventAllDamageToAllEffect(Duration duration, FilterCreaturePermanent filter) { - this(duration, createFilter(filter)); + protected FilterPermanentOrPlayer filter; + + public PreventAllDamageToAllEffect(Duration duration, FilterPermanent filterPermanent) { + this(duration, createFilter(filterPermanent, null)); } - public PreventAllDamageToAllEffect(Duration duration, FilterInPlay filter) { + public PreventAllDamageToAllEffect(Duration duration, FilterPermanent filterPermanent, boolean onlyCombat) { + this(duration, createFilter(filterPermanent, null), onlyCombat); + } + + public PreventAllDamageToAllEffect(Duration duration, FilterPermanentOrPlayer filter) { this(duration, filter, false); } - public PreventAllDamageToAllEffect(Duration duration, FilterInPlay filter, boolean onlyCombat) { + public PreventAllDamageToAllEffect(Duration duration, FilterPermanentOrPlayer filter, boolean onlyCombat) { super(duration, Integer.MAX_VALUE, onlyCombat); this.filter = filter; staticText = "Prevent all " - + (onlyCombat ? "combat ":"") - + "damage that would be dealt to " + + (onlyCombat ? "combat " : "") + + "damage that would be dealt to " + filter.getMessage() - + (duration.toString().isEmpty() ?"": ' ' + duration.toString()); + + (duration.toString().isEmpty() ? "" : ' ' + duration.toString()); } public PreventAllDamageToAllEffect(final PreventAllDamageToAllEffect effect) { @@ -46,13 +48,25 @@ public class PreventAllDamageToAllEffect extends PreventionEffectImpl { this.filter = effect.filter.copy(); } - private static FilterInPlay createFilter(FilterCreaturePermanent filter) { - FilterCreatureOrPlayer newfilter = new FilterCreatureOrPlayer(filter.getMessage()); - newfilter.setCreatureFilter(filter); - newfilter.getPlayerFilter().add(new PlayerIdPredicate(UUID.randomUUID())); - return newfilter; + private static FilterPermanentOrPlayer createFilter(FilterPermanent filterPermanent, FilterPlayer filterPlayer) { + String message = String.join( + " and ", + filterPermanent != null ? filterPermanent.getMessage() : "", + filterPlayer != null ? filterPlayer.getMessage() : ""); + FilterPermanent filter1 = filterPermanent; + if (filter1 == null) { + filter1 = new FilterPermanent(); + filter1.add(new PermanentIdPredicate(UUID.randomUUID())); // disable filter + } + FilterPlayer filter2 = filterPlayer; + if (filter2 == null) { + filter2 = new FilterPlayer(); + filter2.add(new PlayerIdPredicate(UUID.randomUUID())); // disable filter + } + + return new FilterPermanentOrPlayer(message, filter1, filter2); } - + @Override public PreventAllDamageToAllEffect copy() { return new PreventAllDamageToAllEffect(this); @@ -66,17 +80,9 @@ public class PreventAllDamageToAllEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { if (super.applies(event, source, game)) { - Permanent permanent = game.getPermanent(event.getTargetId()); - if (permanent != null) { - if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) { - return true; - } - } - else { - Player player = game.getPlayer(event.getTargetId()); - if (player != null && filter.match(player, source.getSourceId(), source.getControllerId(), game)) { - return true; - } + MageObject object = game.getObject(event.getTargetId()); + if (object != null) { + return filter.match(object, source.getSourceId(), source.getControllerId(), game); } } return false; diff --git a/Mage/src/main/java/mage/filter/StaticFilters.java b/Mage/src/main/java/mage/filter/StaticFilters.java index a09c1f08e80..68097a1fa22 100644 --- a/Mage/src/main/java/mage/filter/StaticFilters.java +++ b/Mage/src/main/java/mage/filter/StaticFilters.java @@ -15,6 +15,7 @@ import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.MulticoloredPredicate; import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SupertypePredicate; +import mage.filter.predicate.other.PlayerPredicate; import mage.filter.predicate.permanent.AnotherPredicate; import mage.filter.predicate.permanent.AttackingPredicate; import mage.filter.predicate.permanent.ControllerPredicate; @@ -607,4 +608,10 @@ public final class StaticFilters { FILTER_CARD_ARTIFACT_OR_CREATURE.setLockedFilter(true); } + public static final FilterPlayer FILTER_PLAYER_CONTROLLER = new FilterPlayer("you"); + + static { + FILTER_PLAYER_CONTROLLER.add(new PlayerPredicate(TargetController.YOU)); + FILTER_PLAYER_CONTROLLER.setLockedFilter(true); + } }