mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
improved implementation of second draw triggers
This commit is contained in:
parent
1c701ecf7c
commit
0982e36002
3 changed files with 83 additions and 124 deletions
|
@ -1,7 +1,7 @@
|
||||||
package mage.cards.f;
|
package mage.cards.f;
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.common.DrawSecondCardTriggeredAbility;
|
||||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||||
import mage.abilities.keyword.FlashAbility;
|
import mage.abilities.keyword.FlashAbility;
|
||||||
import mage.abilities.keyword.FlyingAbility;
|
import mage.abilities.keyword.FlyingAbility;
|
||||||
|
@ -9,18 +9,13 @@ import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.SubType;
|
import mage.constants.SubType;
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.events.GameEvent;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jmharmon
|
* @author jmharmon
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public final class FaerieVandal extends CardImpl {
|
public final class FaerieVandal extends CardImpl {
|
||||||
|
|
||||||
public FaerieVandal(UUID ownerId, CardSetInfo setInfo) {
|
public FaerieVandal(UUID ownerId, CardSetInfo setInfo) {
|
||||||
|
@ -38,10 +33,12 @@ public final class FaerieVandal extends CardImpl {
|
||||||
this.addAbility(FlyingAbility.getInstance());
|
this.addAbility(FlyingAbility.getInstance());
|
||||||
|
|
||||||
// Whenever you draw your second card each turn, put a +1/+1 counter on Faerie Vandal.
|
// 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);
|
super(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,58 +47,3 @@ public final class FaerieVandal extends CardImpl {
|
||||||
return new FaerieVandal(this);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
package mage.cards.j;
|
package mage.cards.j;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.LoyaltyAbility;
|
import mage.abilities.LoyaltyAbility;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.common.DrawSecondCardTriggeredAbility;
|
||||||
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
|
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
|
||||||
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
|
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
|
||||||
import mage.abilities.effects.common.combat.CantBeBlockedAllEffect;
|
import mage.abilities.effects.common.combat.CantBeBlockedAllEffect;
|
||||||
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
|
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
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.counters.CounterType;
|
||||||
import mage.filter.StaticFilters;
|
import mage.filter.StaticFilters;
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.events.GameEvent;
|
|
||||||
import mage.target.common.TargetControlledCreaturePermanent;
|
import mage.target.common.TargetControlledCreaturePermanent;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -30,7 +32,11 @@ public final class JaceArcaneStrategist extends CardImpl {
|
||||||
this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(4));
|
this.addAbility(new PlaneswalkerEntersWithLoyaltyCountersAbility(4));
|
||||||
|
|
||||||
// Whenever you draw your second card each turn, put a +1/+1 counter on target creature you control.
|
// 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.
|
// +1: Draw a card.
|
||||||
this.addAbility(new LoyaltyAbility(new DrawCardSourceControllerEffect(1), 1));
|
this.addAbility(new LoyaltyAbility(new DrawCardSourceControllerEffect(1), 1));
|
||||||
|
@ -50,59 +56,3 @@ public final class JaceArcaneStrategist extends CardImpl {
|
||||||
return new JaceArcaneStrategist(this);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue