* Nettling Impl - Fixed that the conditional delayed destroy ability did not work corretly (fixes #4142).

This commit is contained in:
LevelX2 2017-11-03 14:59:26 +01:00
parent 583033ff3b
commit 9e4beb6b51
3 changed files with 131 additions and 18 deletions

View file

@ -30,13 +30,14 @@ package mage.cards.n;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.condition.Condition;
import mage.abilities.condition.InvertCondition;
import mage.abilities.condition.common.TargetAttackedThisTurnCondition;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.decorator.ConditionalActivatedAbility;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.common.DestroyTargetAtBeginningOfNextEndStepEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -49,6 +50,7 @@ import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
import mage.watchers.common.AttackedThisTurnWatcher;
/**
@ -56,30 +58,33 @@ import mage.watchers.common.AttackedThisTurnWatcher;
* @author MTGfan
*/
public class NettlingImp extends CardImpl {
final static FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Wall");
static {
filter.add(Predicates.not(new SubtypePredicate(SubType.WALL)));
filter.add(new ControlledFromStartOfControllerTurnPredicate());
filter.add(new ControlledFromStartOfControllerTurnPredicate());
filter.add(new ControllerPredicate(TargetController.ACTIVE));
filter.setMessage("non-Wall creature the active player has controlled continuously since the beginning of the turn.");
}
public NettlingImp(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}");
this.subtype.add(SubType.IMP);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
// {tap}: Choose target non-Wall creature the active player has controlled continuously since the beginning of the turn. That creature attacks this turn if able. If it doesn't, destroy it at the beginning of the next end step. Activate this ability only during an opponent's turn, before attackers are declared.
Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new AttacksIfAbleTargetEffect(Duration.EndOfTurn), new TapSourceCost(), new NettlingImpTurnCondition(), "{T}: Choose target non-Wall creature the active player has controlled continuously since the beginning of the turn. That creature attacks this turn if able. If it doesn't, destroy it at the beginning of the next end step. Activate this ability only during an opponent's turn, before attackers are declared.");
ability.addEffect(new ConditionalOneShotEffect(new DestroyTargetAtBeginningOfNextEndStepEffect(), new InvertCondition(TargetAttackedThisTurnCondition.instance)));
// {T}: Choose target non-Wall creature the active player has controlled continuously since the beginning of the turn. That creature attacks this turn if able. If it doesn't, destroy it at the beginning of the next end step. Activate this ability only during an opponent's turn, before attackers are declared.
Ability ability = new ConditionalActivatedAbility(Zone.BATTLEFIELD, new AttacksIfAbleTargetEffect(Duration.EndOfTurn),
new TapSourceCost(), new NettlingImpTurnCondition(),
"{T}: Choose target non-Wall creature the active player has controlled continuously since the beginning of the turn. "
+ "That creature attacks this turn if able. If it doesn't, destroy it at the beginning of the next end step. "
+ "Activate this ability only during an opponent's turn, before attackers are declared.");
ability.addEffect(new NettlingImpDelayedDestroyEffect());
ability.addTarget(new TargetCreaturePermanent(filter));
this.addAbility(ability, new AttackedThisTurnWatcher());
}
public NettlingImp(final NettlingImp card) {
@ -96,7 +101,7 @@ class NettlingImpTurnCondition implements Condition {
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(game.getActivePlayerId());
Player activePlayer = game.getPlayer(game.getActivePlayerId());
return activePlayer != null && activePlayer.hasOpponent(source.getControllerId(), game) && game.getPhase().getStep().getType().getIndex() < 5;
}
@ -105,3 +110,32 @@ class NettlingImpTurnCondition implements Condition {
return "";
}
}
class NettlingImpDelayedDestroyEffect extends OneShotEffect {
public NettlingImpDelayedDestroyEffect() {
super(Outcome.Detriment);
this.staticText = "If it doesn't, destroy it at the beginning of the next end step";
}
public NettlingImpDelayedDestroyEffect(final NettlingImpDelayedDestroyEffect effect) {
super(effect);
}
@Override
public NettlingImpDelayedDestroyEffect copy() {
return new NettlingImpDelayedDestroyEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
DestroyTargetEffect effect = new DestroyTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility
= new AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone.ALL, effect, TargetController.ANY, new InvertCondition(TargetAttackedThisTurnCondition.instance));
delayedAbility.getDuration();
delayedAbility.getTargets().addAll(source.getTargets());
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
}