diff --git a/Mage/src/mage/abilities/keyword/AnnihilatorAbility.java b/Mage/src/mage/abilities/keyword/AnnihilatorAbility.java index bd0d516fb99..42c27a509af 100644 --- a/Mage/src/mage/abilities/keyword/AnnihilatorAbility.java +++ b/Mage/src/mage/abilities/keyword/AnnihilatorAbility.java @@ -25,7 +25,6 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.abilities.keyword; import mage.constants.Outcome; @@ -47,43 +46,44 @@ import mage.target.common.TargetControlledPermanent; import java.util.UUID; /** - * 702.84. Annihilator - * 702.84a Annihilator is a triggered ability. "Annihilator N" means "Whenever this - * creature attacks, defending player sacrifices N permanents." + * 702.84. Annihilator 702.84a Annihilator is a triggered ability. "Annihilator + * N" means "Whenever this creature attacks, defending player sacrifices N + * permanents." + * + * 702.84b If a creature has multiple instances of annihilator, each triggers + * separately. * - * 702.84b If a creature has multiple instances of annihilator, each triggers separately. - * * @author maurer.it_at_gmail.com */ public class AnnihilatorAbility extends TriggeredAbilityImpl { int count; - public AnnihilatorAbility ( int count ) { + public AnnihilatorAbility(int count) { super(Zone.BATTLEFIELD, new AnnihilatorEffect(count), false); this.count = count; } - public AnnihilatorAbility ( final AnnihilatorAbility ability ) { + public AnnihilatorAbility(final AnnihilatorAbility ability) { super(ability); this.count = ability.count; } @Override - public boolean checkTrigger ( GameEvent event, Game game ) { - if ( event.getType() == EventType.ATTACKER_DECLARED && event.getSourceId().equals(this.getSourceId()) ) { + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == EventType.ATTACKER_DECLARED && event.getSourceId().equals(this.getSourceId())) { return true; } return false; } @Override - public String getRule ( ) { + public String getRule() { return "Annihilator " + count; } @Override - public AnnihilatorAbility copy ( ) { + public AnnihilatorAbility copy() { return new AnnihilatorAbility(this); } @@ -92,12 +92,15 @@ public class AnnihilatorAbility extends TriggeredAbilityImpl class AnnihilatorEffect extends OneShotEffect { private final int count; - private static final FilterControlledPermanent filter = new FilterControlledPermanent();; + private static final FilterControlledPermanent filter = new FilterControlledPermanent(); + + ; + static { filter.add(new ControllerPredicate(TargetController.YOU)); } - AnnihilatorEffect ( int count ) { + AnnihilatorEffect(int count) { super(Outcome.Sacrifice); this.count = count; } @@ -113,32 +116,35 @@ class AnnihilatorEffect extends OneShotEffect { Player player = game.getPlayer(defenderId); //Defender may be a planeswalker. - if ( player == null ) { + if (player == null) { Permanent permanent = game.getPermanent(defenderId); - player = game.getPlayer(permanent.getControllerId()); + if (permanent != null) { + player = game.getPlayer(permanent.getControllerId()); + } } + + if (player != null) { + int amount = Math.min(count, game.getBattlefield().countAll(filter, player.getId(), game)); + Target target = new TargetControlledPermanent(amount, amount, filter, false); - - int amount = Math.min(count, game.getBattlefield().countAll(filter, player.getId(), game)); - Target target = new TargetControlledPermanent(amount, amount, filter, false); - - //A spell or ability could have removed the only legal target this player - //had, if thats the case this ability should fizzle. - if (target.canChoose(player.getId(), game)) { - boolean abilityApplied = false; - while (!target.isChosen() && target.canChoose(player.getId(), game) && player.isInGame()) { - player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); - } - - for ( int idx = 0; idx < target.getTargets().size(); idx++) { - Permanent permanent = game.getPermanent((UUID)target.getTargets().get(idx)); - - if ( permanent != null ) { - abilityApplied |= permanent.sacrifice(source.getId(), game); + //A spell or ability could have removed the only legal target this player + //had, if thats the case this ability should fizzle. + if (target.canChoose(player.getId(), game)) { + boolean abilityApplied = false; + while (!target.isChosen() && target.canChoose(player.getId(), game) && player.isInGame()) { + player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } - } - return abilityApplied; + for (int idx = 0; idx < target.getTargets().size(); idx++) { + Permanent permanent = game.getPermanent((UUID) target.getTargets().get(idx)); + + if (permanent != null) { + abilityApplied |= permanent.sacrifice(source.getId(), game); + } + } + + return abilityApplied; + } } return false; }