diff --git a/Mage.Sets/src/mage/sets/limitedalpha/Invisibility.java b/Mage.Sets/src/mage/sets/limitedalpha/Invisibility.java index 18d294fd41..dac6d92316 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/Invisibility.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/Invisibility.java @@ -32,13 +32,13 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesAttachedEffect; import mage.abilities.keyword.EnchantAbility; 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.constants.*; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; @@ -50,12 +50,16 @@ import mage.target.common.TargetCreaturePermanent; */ public class Invisibility extends CardImpl { + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("except by Walls"); + static { + filter.add(Predicates.not(new SubtypePredicate("Wall"))); + } + public Invisibility(UUID ownerId) { super(ownerId, 60, "Invisibility", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{U}{U}"); this.expansionSetCode = "LEA"; this.subtype.add("Aura"); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); @@ -64,7 +68,8 @@ public class Invisibility extends CardImpl { this.addAbility(ability); // Enchanted creature can't be blocked except by Walls. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantBeBlockedByWallsEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new CantBeBlockedByCreaturesAttachedEffect(Duration.WhileOnBattlefield, filter, AttachmentType.AURA))); } public Invisibility(final Invisibility card) { @@ -76,39 +81,3 @@ public class Invisibility extends CardImpl { return new Invisibility(this); } } - -class CantBeBlockedByWallsEffect extends RestrictionEffect { - - public CantBeBlockedByWallsEffect() { - super(Duration.WhileOnBattlefield); - staticText = "Enchanted creature can't be blocked except by Walls"; - } - - public CantBeBlockedByWallsEffect(final CantBeBlockedByWallsEffect effect) { - super(effect); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - if (permanent.getId().equals(enchantment.getAttachedTo())) { - return true; - } - } - return false; - } - - @Override - public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) { - if (!blocker.hasSubtype("Wall", game)) { - return false; - } - return true; - } - - @Override - public CantBeBlockedByWallsEffect copy() { - return new CantBeBlockedByWallsEffect(this); - } -} diff --git a/Mage.Sets/src/mage/sets/mirage/CloakOfInvisibility.java b/Mage.Sets/src/mage/sets/mirage/CloakOfInvisibility.java index 62851f72d7..3a0347e40a 100644 --- a/Mage.Sets/src/mage/sets/mirage/CloakOfInvisibility.java +++ b/Mage.Sets/src/mage/sets/mirage/CloakOfInvisibility.java @@ -32,6 +32,7 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesAttachedEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.PhasingAbility; @@ -42,6 +43,9 @@ import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; @@ -52,6 +56,10 @@ import mage.target.common.TargetCreaturePermanent; * @author fireshoes */ public class CloakOfInvisibility extends CardImpl { + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("except by Walls"); + static { + filter.add(Predicates.not(new SubtypePredicate("Wall"))); + } public CloakOfInvisibility(UUID ownerId) { super(ownerId, 58, "Cloak of Invisibility", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{U}"); @@ -67,7 +75,7 @@ public class CloakOfInvisibility extends CardImpl { // Enchanted creature has phasing and can't be blocked except by Walls. ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(PhasingAbility.getInstance(), AttachmentType.AURA)); - ability.addEffect(new CantBeBlockedByWallsEffect()); + ability.addEffect(new CantBeBlockedByCreaturesAttachedEffect(Duration.WhileOnBattlefield, filter, AttachmentType.AURA)); this.addAbility(ability); } @@ -80,39 +88,3 @@ public class CloakOfInvisibility extends CardImpl { return new CloakOfInvisibility(this); } } - -class CantBeBlockedByWallsEffect extends RestrictionEffect { - - public CantBeBlockedByWallsEffect() { - super(Duration.WhileOnBattlefield); - staticText = "Enchanted creature can't be blocked except by Walls"; - } - - public CantBeBlockedByWallsEffect(final CantBeBlockedByWallsEffect effect) { - super(effect); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - if (permanent.getId().equals(enchantment.getAttachedTo())) { - return true; - } - } - return false; - } - - @Override - public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) { - if (!blocker.hasSubtype("Wall", game)) { - return false; - } - return true; - } - - @Override - public CantBeBlockedByWallsEffect copy() { - return new CantBeBlockedByWallsEffect(this); - } -} diff --git a/Mage.Sets/src/mage/sets/theros/ProwlersHelm.java b/Mage.Sets/src/mage/sets/theros/ProwlersHelm.java index dbb4683ce9..86f0f5873d 100644 --- a/Mage.Sets/src/mage/sets/theros/ProwlersHelm.java +++ b/Mage.Sets/src/mage/sets/theros/ProwlersHelm.java @@ -27,20 +27,17 @@ */ package mage.sets.theros; -import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.mana.GenericManaCost; -import mage.abilities.effects.RestrictionEffect; +import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesAttachedEffect; import mage.abilities.keyword.EquipAbility; 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.permanent.Permanent; +import mage.constants.*; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.SubtypePredicate; + +import java.util.UUID; /** * @@ -48,13 +45,19 @@ import mage.game.permanent.Permanent; */ public class ProwlersHelm extends CardImpl { + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("except by Walls"); + static { + filter.add(Predicates.not(new SubtypePredicate("Wall"))); + } + public ProwlersHelm(UUID ownerId) { super(ownerId, 219, "Prowler's Helm", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}"); this.expansionSetCode = "THS"; this.subtype.add("Equipment"); // Equipped creature can't be blocked except by Walls. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantBeBlockedByWallsEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new CantBeBlockedByCreaturesAttachedEffect(Duration.WhileOnBattlefield, filter, AttachmentType.EQUIPMENT))); // Equip {2} this.addAbility(new EquipAbility(Outcome.Benefit, new GenericManaCost(2))); @@ -69,39 +72,3 @@ public class ProwlersHelm extends CardImpl { return new ProwlersHelm(this); } } - -class CantBeBlockedByWallsEffect extends RestrictionEffect { - - public CantBeBlockedByWallsEffect() { - super(Duration.WhileOnBattlefield); - staticText = "Equipped creature can't be blocked except by Walls"; - } - - public CantBeBlockedByWallsEffect(final CantBeBlockedByWallsEffect effect) { - super(effect); - } - - @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent equipment = game.getPermanent(source.getSourceId()); - if (equipment != null && equipment.getAttachedTo() != null) { - if (permanent.getId().equals(equipment.getAttachedTo())) { - return true; - } - } - return false; - } - - @Override - public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) { - if (!blocker.hasSubtype("Wall", game)) { - return false; - } - return true; - } - - @Override - public CantBeBlockedByWallsEffect copy() { - return new CantBeBlockedByWallsEffect(this); - } -}