clean up treetop bracers impl

This commit is contained in:
Jason Wall 2015-03-14 12:24:44 -06:00
parent b79344ab27
commit be5d568da6

View file

@ -31,15 +31,20 @@ import java.util.UUID;
import mage.abilities.Abilities; import mage.abilities.Abilities;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.StaticAbility;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
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.BoostEnchantedEffect; import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.*; import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AbilityPredicate;
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;
@ -65,8 +70,7 @@ public class TreetopBracers extends CardImpl {
this.addAbility(ability); this.addAbility(ability);
// Enchanted creature gets +1/+1 and can't be blocked except by creatures with flying. // Enchanted creature gets +1/+1 and can't be blocked except by creatures with flying.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(1, 1, Duration.WhileOnBattlefield))); this.addAbility(new TreetopBracersAbility());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new TreetopBracersEffect()));
} }
public TreetopBracers(final TreetopBracers card) { public TreetopBracers(final TreetopBracers card) {
@ -79,34 +83,30 @@ public class TreetopBracers extends CardImpl {
} }
} }
class TreetopBracersEffect extends RestrictionEffect { class TreetopBracersAbility extends StaticAbility {
private static FilterCreaturePermanent onlyFlyingCreatures = new FilterCreaturePermanent("except by creatures with flying");
public TreetopBracersEffect() { static {
super(Duration.WhileOnBattlefield); onlyFlyingCreatures.add(new AbilityPredicate(FlyingAbility.class));
staticText = "Enchanted creature can't be blocked except by creatures with flying.";
} }
public TreetopBracersEffect(final TreetopBracersEffect effect) { public TreetopBracersAbility() {
super(effect); super(Zone.BATTLEFIELD, new BoostEnchantedEffect(1, 1, Duration.WhileOnBattlefield));
Effect cantBeBlocked = new CantBeBlockedByCreaturesAttachedEffect(Duration.WhileOnBattlefield, onlyFlyingCreatures, AttachmentType.AURA);
cantBeBlocked.setText("and can't be blocked except by creatures with flying.");
} }
public TreetopBracersAbility(TreetopBracersAbility ability) {
super(ability);
}
/**
* Creates a fresh copy of this ability.
*
* @return A new copy of this ability.
*/
@Override @Override
public boolean applies(Permanent permanent, Ability source, Game game) { public TreetopBracersAbility copy() {
Permanent aura = game.getPermanent(source.getSourceId()); return new TreetopBracersAbility(this);
if(aura != null && aura.getAttachedTo() != null) {
Permanent enchanted = game.getPermanent(aura.getAttachedTo());
return permanent.getId().equals(enchanted.getId());
}
return false;
}
@Override
public boolean canBeBlocked(Permanent attacker, Permanent blocker, Ability source, Game game) {
return blocker.getAbilities().contains(FlyingAbility.getInstance());
}
@Override
public TreetopBracersEffect copy() {
return new TreetopBracersEffect(this);
} }
} }