mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
Refactor - remove duplicate CantBeBlockedByWallsEffect and replace with CantBeBlockedByCreatureAttachedEffect
This commit is contained in:
parent
d4f8224ee9
commit
d1f18ced96
3 changed files with 35 additions and 127 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue