diff --git a/Mage.Sets/src/mage/cards/f/FaerieVandal.java b/Mage.Sets/src/mage/cards/f/FaerieVandal.java index 7f45e7d8b9..dff975f655 100644 --- a/Mage.Sets/src/mage/cards/f/FaerieVandal.java +++ b/Mage.Sets/src/mage/cards/f/FaerieVandal.java @@ -1,7 +1,7 @@ package mage.cards.f; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.DrawSecondCardTriggeredAbility; import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.keyword.FlashAbility; import mage.abilities.keyword.FlyingAbility; @@ -9,18 +9,13 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.counters.CounterType; -import mage.game.Game; -import mage.game.events.GameEvent; import java.util.UUID; /** * @author jmharmon */ - - public final class FaerieVandal extends CardImpl { public FaerieVandal(UUID ownerId, CardSetInfo setInfo) { @@ -38,10 +33,12 @@ public final class FaerieVandal extends CardImpl { this.addAbility(FlyingAbility.getInstance()); // Whenever you draw your second card each turn, put a +1/+1 counter on Faerie Vandal. - this.addAbility(new FaerieVandalTriggeredAbility()); + this.addAbility(new DrawSecondCardTriggeredAbility( + new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false + )); } - public FaerieVandal(final FaerieVandal card) { + private FaerieVandal(final FaerieVandal card) { super(card); } @@ -50,58 +47,3 @@ public final class FaerieVandal extends CardImpl { return new FaerieVandal(this); } } - -class FaerieVandalTriggeredAbility extends TriggeredAbilityImpl { - - private boolean triggeredOnce = false; - private boolean triggeredTwice = false; - - FaerieVandalTriggeredAbility() { - super(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance()), false); - } - - private FaerieVandalTriggeredAbility(final FaerieVandalTriggeredAbility ability) { - super(ability); - this.triggeredOnce = ability.triggeredOnce; - this.triggeredTwice = ability.triggeredTwice; - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DREW_CARD - || event.getType() == GameEvent.EventType.END_PHASE_POST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.END_PHASE_POST) { - triggeredOnce = triggeredTwice = false; - return false; - } - if (event.getType() == GameEvent.EventType.DREW_CARD - && event.getPlayerId().equals(controllerId)) { - if (triggeredOnce) { - if (triggeredTwice) { - return false; - } else { - triggeredTwice = true; - return true; - } - } else { - triggeredOnce = true; - return false; - } - } - return false; - } - - @Override - public String getRule() { - return "Whenever you draw your second card each turn, put a +1/+1 counter on {this}."; - } - - @Override - public FaerieVandalTriggeredAbility copy() { - return new FaerieVandalTriggeredAbility(this); - } -} diff --git a/Mage.Sets/src/mage/cards/j/JaceArcaneStrategist.java b/Mage.Sets/src/mage/cards/j/JaceArcaneStrategist.java index bbaeeef62d..cec4fe502c 100644 --- a/Mage.Sets/src/mage/cards/j/JaceArcaneStrategist.java +++ b/Mage.Sets/src/mage/cards/j/JaceArcaneStrategist.java @@ -1,18 +1,20 @@ package mage.cards.j; +import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; -import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.DrawSecondCardTriggeredAbility; import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.effects.common.combat.CantBeBlockedAllEffect; import mage.abilities.effects.common.counter.AddCountersTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.SubType; +import mage.constants.SuperType; import mage.counters.CounterType; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.game.events.GameEvent; import mage.target.common.TargetControlledCreaturePermanent; import java.util.UUID; @@ -30,7 +32,11 @@ public final class JaceArcaneStrategist extends CardImpl { this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(4)); // Whenever you draw your second card each turn, put a +1/+1 counter on target creature you control. - this.addAbility(new JaceArcaneStrategistTriggeredAbility()); + Ability ability = new DrawSecondCardTriggeredAbility( + new AddCountersTargetEffect(CounterType.P1P1.createInstance()), false + ); + ability.addTarget(new TargetControlledCreaturePermanent()); + this.addAbility(ability); // +1: Draw a card. this.addAbility(new LoyaltyAbility(new DrawCardSourceControllerEffect(1), 1)); @@ -50,59 +56,3 @@ public final class JaceArcaneStrategist extends CardImpl { return new JaceArcaneStrategist(this); } } - -class JaceArcaneStrategistTriggeredAbility extends TriggeredAbilityImpl { - - private boolean triggeredOnce = false; - private boolean triggeredTwice = false; - - JaceArcaneStrategistTriggeredAbility() { - super(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.P1P1.createInstance()), false); - this.addTarget(new TargetControlledCreaturePermanent()); - } - - private JaceArcaneStrategistTriggeredAbility(final JaceArcaneStrategistTriggeredAbility ability) { - super(ability); - this.triggeredOnce = ability.triggeredOnce; - this.triggeredTwice = ability.triggeredTwice; - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.DREW_CARD - || event.getType() == GameEvent.EventType.END_PHASE_POST; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.END_PHASE_POST) { - triggeredOnce = triggeredTwice = false; - return false; - } - if (event.getType() == GameEvent.EventType.DREW_CARD - && event.getPlayerId().equals(controllerId)) { - if (triggeredOnce) { - if (triggeredTwice) { - return false; - } else { - triggeredTwice = true; - return true; - } - } else { - triggeredOnce = true; - return false; - } - } - return false; - } - - @Override - public String getRule() { - return "Whenever you draw your second card each turn, put a +1/+1 counter on target creature you control."; - } - - @Override - public JaceArcaneStrategistTriggeredAbility copy() { - return new JaceArcaneStrategistTriggeredAbility(this); - } -} diff --git a/Mage/src/main/java/mage/abilities/common/DrawSecondCardTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DrawSecondCardTriggeredAbility.java new file mode 100644 index 0000000000..becd3c41d1 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/common/DrawSecondCardTriggeredAbility.java @@ -0,0 +1,67 @@ +package mage.abilities.common; + +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.effects.Effect; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.watchers.common.CardsAmountDrawnThisTurnWatcher; + +/** + * @author TheElk801 + */ +public class DrawSecondCardTriggeredAbility extends TriggeredAbilityImpl { + + private boolean triggeredOnce = false; + + public DrawSecondCardTriggeredAbility(Effect effect, boolean optional) { + super(Zone.ALL, effect, optional); + this.addWatcher(new CardsAmountDrawnThisTurnWatcher()); + } + + private DrawSecondCardTriggeredAbility(final DrawSecondCardTriggeredAbility ability) { + super(ability); + this.triggeredOnce = ability.triggeredOnce; + } + + @Override + public boolean checkEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.DREW_CARD + || event.getType() == GameEvent.EventType.END_PHASE_POST; + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.END_PHASE_POST) { + triggeredOnce = false; + return false; + } + if (event.getType() != GameEvent.EventType.DREW_CARD + || !event.getPlayerId().equals(controllerId) + || game.getPermanent(sourceId) == null) { + return false; + } + if (triggeredOnce) { + return false; + } + CardsAmountDrawnThisTurnWatcher watcher = game.getState().getWatcher(CardsAmountDrawnThisTurnWatcher.class); + if (watcher == null) { + return false; + } + if (watcher.getAmountCardsDrawn(controllerId) > 1) { + triggeredOnce = true; + return true; + } + return false; + } + + @Override + public String getRule() { + return "Whenever you draw your second card each turn, " + super.getRule(); + } + + @Override + public DrawSecondCardTriggeredAbility copy() { + return new DrawSecondCardTriggeredAbility(this); + } +}