Refactor - remove duplicate CantBeBlockedByWallsEffect and replace with CantBeBlockedByCreatureAttachedEffect

This commit is contained in:
JOAC69 2016-09-23 01:36:35 -05:00
parent d4f8224ee9
commit d1f18ced96
3 changed files with 35 additions and 127 deletions

View file

@ -32,13 +32,13 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesAttachedEffect;
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.*;
import mage.constants.Duration; import mage.filter.common.FilterCreaturePermanent;
import mage.constants.Outcome; import mage.filter.predicate.Predicates;
import mage.constants.Rarity; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
@ -50,12 +50,16 @@ import mage.target.common.TargetCreaturePermanent;
*/ */
public class Invisibility extends CardImpl { 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) { public Invisibility(UUID ownerId) {
super(ownerId, 60, "Invisibility", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{U}{U}"); super(ownerId, 60, "Invisibility", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{U}{U}");
this.expansionSetCode = "LEA"; this.expansionSetCode = "LEA";
this.subtype.add("Aura"); this.subtype.add("Aura");
// Enchant creature // Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent(); TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addTarget(auraTarget);
@ -64,7 +68,8 @@ public class Invisibility extends CardImpl {
this.addAbility(ability); this.addAbility(ability);
// Enchanted creature can't be blocked except by Walls. // 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) { public Invisibility(final Invisibility card) {
@ -76,39 +81,3 @@ public class Invisibility extends CardImpl {
return new Invisibility(this); 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);
}
}

View file

@ -32,6 +32,7 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.AttachEffect; import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.combat.CantBeBlockedByCreaturesAttachedEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.abilities.keyword.PhasingAbility; import mage.abilities.keyword.PhasingAbility;
@ -42,6 +43,9 @@ import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; 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.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
@ -52,6 +56,10 @@ import mage.target.common.TargetCreaturePermanent;
* @author fireshoes * @author fireshoes
*/ */
public class CloakOfInvisibility extends CardImpl { 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) { public CloakOfInvisibility(UUID ownerId) {
super(ownerId, 58, "Cloak of Invisibility", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{U}"); 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. // Enchanted creature has phasing and can't be blocked except by Walls.
ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(PhasingAbility.getInstance(), AttachmentType.AURA)); 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); this.addAbility(ability);
} }
@ -80,39 +88,3 @@ public class CloakOfInvisibility extends CardImpl {
return new CloakOfInvisibility(this); 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);
}
}

View file

@ -27,20 +27,17 @@
*/ */
package mage.sets.theros; package mage.sets.theros;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost; 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.abilities.keyword.EquipAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.*;
import mage.constants.Duration; import mage.filter.common.FilterCreaturePermanent;
import mage.constants.Outcome; import mage.filter.predicate.Predicates;
import mage.constants.Rarity; import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.constants.Zone;
import mage.game.Game; import java.util.UUID;
import mage.game.permanent.Permanent;
/** /**
* *
@ -48,13 +45,19 @@ import mage.game.permanent.Permanent;
*/ */
public class ProwlersHelm extends CardImpl { 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) { public ProwlersHelm(UUID ownerId) {
super(ownerId, 219, "Prowler's Helm", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}"); super(ownerId, 219, "Prowler's Helm", Rarity.UNCOMMON, new CardType[]{CardType.ARTIFACT}, "{2}");
this.expansionSetCode = "THS"; this.expansionSetCode = "THS";
this.subtype.add("Equipment"); this.subtype.add("Equipment");
// Equipped creature can't be blocked except by Walls. // 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} // Equip {2}
this.addAbility(new EquipAbility(Outcome.Benefit, new GenericManaCost(2))); this.addAbility(new EquipAbility(Outcome.Benefit, new GenericManaCost(2)));
@ -69,39 +72,3 @@ public class ProwlersHelm extends CardImpl {
return new ProwlersHelm(this); 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);
}
}