added TransformIntoSourceTriggeredAbility to simplify copied code

This commit is contained in:
Evan Kranzler 2021-11-07 08:31:23 -05:00
parent 76a7e4fe2c
commit 3801325a04
9 changed files with 160 additions and 460 deletions

View file

@ -1,26 +1,21 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.Ability;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.effects.common.SacrificeEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.common.TargetOpponent;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class AbolisherOfBloodlines extends CardImpl {
@ -39,7 +34,11 @@ public final class AbolisherOfBloodlines extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// When this creature transforms into Abolisher of Bloodlines, target opponent sacrifices three creatures.
this.addAbility(new AbolisherOfBloodlinesAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(new SacrificeEffect(
StaticFilters.FILTER_PERMANENT_CREATURE, 3, "target opponent"
));
ability.addTarget(new TargetOpponent());
this.addAbility(ability);
}
private AbolisherOfBloodlines(final AbolisherOfBloodlines card) {
@ -51,44 +50,3 @@ public final class AbolisherOfBloodlines extends CardImpl {
return new AbolisherOfBloodlines(this);
}
}
class AbolisherOfBloodlinesAbility extends TriggeredAbilityImpl {
static final String RULE_TEXT = "When this creature transforms into Abolisher of Bloodlines, target opponent sacrifices three creatures";
public AbolisherOfBloodlinesAbility() {
super(Zone.BATTLEFIELD, new SacrificeEffect(StaticFilters.FILTER_PERMANENT_CREATURE, 3, "Target opponent"), false);
Target target = new TargetOpponent();
this.addTarget(target);
}
public AbolisherOfBloodlinesAbility(final AbolisherOfBloodlinesAbility ability) {
super(ability);
}
@Override
public AbolisherOfBloodlinesAbility copy() {
return new AbolisherOfBloodlinesAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return RULE_TEXT + '.';
}
}

View file

@ -2,20 +2,20 @@ package mage.cards.a;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.effects.common.DamageAllEffect;
import mage.abilities.effects.common.DamagePlayersEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.TargetController;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.List;
import java.util.UUID;
/**
@ -23,6 +23,12 @@ import java.util.UUID;
*/
public final class AvacynThePurifier extends CardImpl {
private static final FilterPermanent filter = new FilterCreaturePermanent("other creature");
static {
filter.add(AnotherPredicate.instance);
}
public AvacynThePurifier(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "");
addSuperType(SuperType.LEGENDARY);
@ -38,7 +44,11 @@ public final class AvacynThePurifier extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// When this creature transforms into Avacyn, the Purifier, it deals 3 damage to each other creature and each opponent.
this.addAbility(new AvacynThePurifierAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(
new DamageAllEffect(3, "it", filter)
);
ability.addEffect(new DamagePlayersEffect(3, TargetController.OPPONENT).setText("and each opponent"));
this.addAbility(ability);
}
private AvacynThePurifier(final AvacynThePurifier card) {
@ -50,71 +60,3 @@ public final class AvacynThePurifier extends CardImpl {
return new AvacynThePurifier(this);
}
}
class AvacynThePurifierAbility extends TriggeredAbilityImpl {
public AvacynThePurifierAbility() {
super(Zone.BATTLEFIELD, new AvacynThePurifierEffect(), false);
}
public AvacynThePurifierAbility(final AvacynThePurifierAbility ability) {
super(ability);
}
@Override
public AvacynThePurifierAbility copy() {
return new AvacynThePurifierAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
return permanent != null && permanent.isTransformed();
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into Avacyn, the Purifier, it deals 3 damage to each other creature and each opponent.";
}
}
class AvacynThePurifierEffect extends OneShotEffect {
public AvacynThePurifierEffect() {
super(Outcome.Damage);
}
public AvacynThePurifierEffect(final AvacynThePurifierEffect effect) {
super(effect);
}
@Override
public AvacynThePurifierEffect copy() {
return new AvacynThePurifierEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("each other creature");
filter.add(AnotherPredicate.instance);
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : permanents) {
permanent.damage(3, source.getSourceId(), source, game, false, true);
}
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
opponent.damage(3, source.getSourceId(), source, game);
}
}
return true;
}
}

View file

@ -1,29 +1,30 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class AwokenHorror extends CardImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Horror creatures");
static {
filter.add(Predicates.not(SubType.HORROR.getPredicate()));
}
public AwokenHorror(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "");
this.subtype.add(SubType.KRAKEN);
this.subtype.add(SubType.HORROR);
this.power = new MageInt(7);
@ -33,7 +34,7 @@ public final class AwokenHorror extends CardImpl {
this.nightCard = true;
// When this creature transforms into Awoken Horrow, return all non-Horror creatures to their owners' hands.
this.addAbility(new AwokenHorrorAbility());
this.addAbility(new TransformIntoSourceTriggeredAbility(new ReturnToHandFromBattlefieldAllEffect(filter)));
}
private AwokenHorror(final AwokenHorror card) {
@ -45,46 +46,3 @@ public final class AwokenHorror extends CardImpl {
return new AwokenHorror(this);
}
}
class AwokenHorrorAbility extends TriggeredAbilityImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Horror creatures");
static {
filter.add(Predicates.not(SubType.HORROR.getPredicate()));
}
public AwokenHorrorAbility() {
super(Zone.BATTLEFIELD, new ReturnToHandFromBattlefieldAllEffect(filter), false);
}
public AwokenHorrorAbility(final AwokenHorrorAbility ability) {
super(ability);
}
@Override
public AwokenHorrorAbility copy() {
return new AwokenHorrorAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into Awoken Horror, return all non-Horror creatures to their owners' hands.";
}
}

View file

@ -1,32 +1,25 @@
package mage.cards.d;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.Ability;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class DemonPossessedWitch extends CardImpl {
private static final String rule = "When this creature transforms into Demon-Possessed Witch, you may destroy target creature";
public DemonPossessedWitch(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.SHAMAN);
this.power = new MageInt(4);
@ -37,7 +30,9 @@ public final class DemonPossessedWitch extends CardImpl {
this.nightCard = true;
// When this creature transforms into Demon-Possessed Witch, you may destroy target creature.
this.addAbility(new DemonPossessedWitchAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(new DestroyTargetEffect(), true);
ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability);
}
private DemonPossessedWitch(final DemonPossessedWitch card) {
@ -49,42 +44,3 @@ public final class DemonPossessedWitch extends CardImpl {
return new DemonPossessedWitch(this);
}
}
class DemonPossessedWitchAbility extends TriggeredAbilityImpl {
public DemonPossessedWitchAbility() {
super(Zone.BATTLEFIELD, new DestroyTargetEffect(), true);
Target target = new TargetPermanent(new FilterCreaturePermanent());
this.addTarget(target);
}
public DemonPossessedWitchAbility(final DemonPossessedWitchAbility ability) {
super(ability);
}
@Override
public DemonPossessedWitchAbility copy() {
return new DemonPossessedWitchAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "When this creature transforms into Demon-Possessed Witch, you may destroy target creature.";
}
}

View file

@ -1,36 +1,35 @@
package mage.cards.l;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.ExileTargetEffect;
import mage.abilities.effects.common.ExileUntilSourceLeavesEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.target.TargetPermanent;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class LunarchInquisitors extends CardImpl {
private static final String rule = "Whenever this creature transforms into Lunarch Inquisitors, you may exile another target creature until Lunarch Inquisitors leaves the battlefield";
private static final FilterPermanent filter = new FilterCreaturePermanent("another target creature");
static {
filter.add(AnotherPredicate.instance);
}
public LunarchInquisitors(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.CLERIC);
this.power = new MageInt(4);
@ -41,8 +40,9 @@ public final class LunarchInquisitors extends CardImpl {
this.nightCard = true;
// When this creature transforms into Lunarch Inquisitors, you may exile another target creature until Lunarch Inquisitors leaves the battlefield.
Ability ability = new LunarchInquisitorsAbility();
ability.addTarget(new TargetCreaturePermanent());
Ability ability = new TransformIntoSourceTriggeredAbility(new ExileUntilSourceLeavesEffect("")
.setText("exile another target creature until {this} leaves the battlefield"), true);
ability.addTarget(new TargetPermanent(filter));
ability.addEffect(new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()));
this.addAbility(ability);
}
@ -56,70 +56,3 @@ public final class LunarchInquisitors extends CardImpl {
return new LunarchInquisitors(this);
}
}
class LunarchInquisitorsAbility extends TriggeredAbilityImpl {
public LunarchInquisitorsAbility() {
super(Zone.BATTLEFIELD, new LunarchInquisitorsExileEffect(), true);
// Rule only shown on the night side
this.setRuleVisible(false);
}
public LunarchInquisitorsAbility(final LunarchInquisitorsAbility ability) {
super(ability);
}
@Override
public LunarchInquisitorsAbility copy() {
return new LunarchInquisitorsAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into Lunarch Inquisitors, you may exile another target creature until Lunarch Inquisitors leaves the battlefield.";
}
}
class LunarchInquisitorsExileEffect extends OneShotEffect {
public LunarchInquisitorsExileEffect() {
super(Outcome.Benefit);
this.staticText = "exile target creature until {this} leaves the battlefield";
}
public LunarchInquisitorsExileEffect(final LunarchInquisitorsExileEffect effect) {
super(effect);
}
@Override
public LunarchInquisitorsExileEffect copy() {
return new LunarchInquisitorsExileEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
// If Lunarch Inquisitors leaves the battlefield before its triggered ability resolves,
// the target won't be exiled.
if (permanent != null) {
return new ExileTargetEffect(CardUtil.getCardExileZoneId(game, source), permanent.getIdName()).apply(game, source);
}
return false;
}
}

View file

@ -3,7 +3,7 @@ package mage.cards.r;
import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.common.WerewolfBackTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.TrampleAbility;
@ -12,14 +12,11 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.common.TargetOpponentOrPlaneswalker;
@ -47,7 +44,12 @@ public final class RavagerOfTheFells extends CardImpl {
this.addAbility(TrampleAbility.getInstance());
// Whenever this creature transforms into Ravager of the Fells, it deals 2 damage to target opponent and 2 damage to up to one target creature that player controls.
this.addAbility(new RavagerOfTheFellsAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(
new RavagerOfTheFellsEffect(), false, true
);
ability.addTarget(new TargetOpponentOrPlaneswalker());
ability.addTarget(new RavagerOfTheFellsTarget());
this.addAbility(ability);
// At the beginning of each upkeep, if a player cast two or more spells last turn, transform Ravager of the Fells.
this.addAbility(new WerewolfBackTriggeredAbility());
@ -63,53 +65,12 @@ public final class RavagerOfTheFells extends CardImpl {
}
}
class RavagerOfTheFellsAbility extends TriggeredAbilityImpl {
RavagerOfTheFellsAbility() {
super(Zone.BATTLEFIELD, new RavagerOfTheFellsEffect(), false);
Target target1 = new TargetOpponentOrPlaneswalker();
this.addTarget(target1);
this.addTarget(new RavagerOfTheFellsTarget());
}
private RavagerOfTheFellsAbility(final RavagerOfTheFellsAbility ability) {
super(ability);
}
@Override
public RavagerOfTheFellsAbility copy() {
return new RavagerOfTheFellsAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into {this}, "
+ "it deals 2 damage to target opponent or planeswalker "
+ "and 2 damage to up to one target creature that player or that planeswalker's controller controls.";
}
}
class RavagerOfTheFellsEffect extends OneShotEffect {
RavagerOfTheFellsEffect() {
super(Outcome.Damage);
staticText = "it deals 2 damage to target opponent or planeswalker and 2 damage " +
"to up to one target creature that player or that planeswalker's controller controls.";
}
private RavagerOfTheFellsEffect(final RavagerOfTheFellsEffect effect) {

View file

@ -1,19 +1,19 @@
package mage.cards.u;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.Ability;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.common.WerewolfBackTriggeredAbility;
import mage.abilities.effects.common.FightTargetSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.constants.TargetController;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.common.TargetCreaturePermanent;
import mage.target.TargetPermanent;
import java.util.UUID;
@ -22,6 +22,14 @@ import java.util.UUID;
*/
public final class UlrichUncontestedAlpha extends CardImpl {
private static final FilterCreaturePermanent filter
= new FilterCreaturePermanent("non-Werewolf creature you don't control");
static {
filter.add(Predicates.not(SubType.WEREWOLF.getPredicate()));
filter.add(TargetController.NOT_YOU.getControllerPredicate());
}
public UlrichUncontestedAlpha(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "");
addSuperType(SuperType.LEGENDARY);
@ -35,7 +43,13 @@ public final class UlrichUncontestedAlpha extends CardImpl {
this.nightCard = true;
// Whenever this creature transforms into Ulrich, Uncontested Alpha, you may have it fight target non-Werewolf creature you don't control.
this.addAbility(new UlrichUncontestedAlphaAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(
new FightTargetSourceEffect()
.setText("you may have it fight target non-Werewolf creature you don't control"),
true, true
);
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
// At the beginning of each upkeep, if a player cast two or more spells last turn, transform Ulrich, Uncontested Alpha.
this.addAbility(new WerewolfBackTriggeredAbility());
@ -50,49 +64,3 @@ public final class UlrichUncontestedAlpha extends CardImpl {
return new UlrichUncontestedAlpha(this);
}
}
class UlrichUncontestedAlphaAbility extends TriggeredAbilityImpl {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("non-Werewolf creature you don't control");
static {
filter.add(Predicates.not(SubType.WEREWOLF.getPredicate()));
filter.add(TargetController.NOT_YOU.getControllerPredicate());
}
public UlrichUncontestedAlphaAbility() {
super(Zone.BATTLEFIELD, new FightTargetSourceEffect(), true);
Target target = new TargetCreaturePermanent(filter);
this.addTarget(target);
}
public UlrichUncontestedAlphaAbility(final UlrichUncontestedAlphaAbility ability) {
super(ability);
}
@Override
public UlrichUncontestedAlphaAbility copy() {
return new UlrichUncontestedAlphaAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.isTransformed()) {
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into Ulrich, Uncontested Alpha, you may have it fight target non-Werewolf creature you don't control.";
}
}

View file

@ -2,7 +2,7 @@ package mage.cards.w;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.TransformIntoSourceTriggeredAbility;
import mage.abilities.common.WerewolfBackTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
@ -12,7 +12,6 @@ import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetArtifactPermanent;
@ -36,7 +35,9 @@ public final class WerewolfRansacker extends CardImpl {
this.toughness = new MageInt(4);
// Whenever this creature transforms into Werewolf Ransacker, you may destroy target artifact. If that artifact is put into a graveyard this way, Werewolf Ransacker deals 3 damage to that artifact's controller.
this.addAbility(new WerewolfRansackerAbility());
Ability ability = new TransformIntoSourceTriggeredAbility(new WerewolfRansackerEffect(), true, true);
ability.addTarget(new TargetArtifactPermanent());
this.addAbility(ability);
// At the beginning of each upkeep, if a player cast two or more spells last turn, transform Werewolf Ransacker.
this.addAbility(new WerewolfBackTriggeredAbility());
@ -52,47 +53,12 @@ public final class WerewolfRansacker extends CardImpl {
}
}
class WerewolfRansackerAbility extends TriggeredAbilityImpl {
WerewolfRansackerAbility() {
super(Zone.BATTLEFIELD, new WerewolfRansackerEffect(), true);
this.addTarget(new TargetArtifactPermanent());
}
private WerewolfRansackerAbility(final WerewolfRansackerAbility ability) {
super(ability);
}
@Override
public WerewolfRansackerAbility copy() {
return new WerewolfRansackerAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(sourceId)) {
Permanent permanent = game.getPermanent(sourceId);
return permanent != null && permanent.isTransformed();
}
return false;
}
@Override
public String getRule() {
return "Whenever this creature transforms into {this}, you may destroy target artifact. If that artifact " +
"is put into a graveyard this way, {this} deals 3 damage to that artifact's controller";
}
}
class WerewolfRansackerEffect extends OneShotEffect {
WerewolfRansackerEffect() {
super(Outcome.DestroyPermanent);
staticText = "destroy target artifact. If that artifact is put into a graveyard this way, " +
"{this} deals 3 damage to that artifact's controller";
}
private WerewolfRansackerEffect(final WerewolfRansackerEffect effect) {

View file

@ -0,0 +1,58 @@
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.game.permanent.Permanent;
/**
* @author TheElk801
*/
public class TransformIntoSourceTriggeredAbility extends TriggeredAbilityImpl {
private final boolean whenever;
public TransformIntoSourceTriggeredAbility(Effect effect) {
this(effect, false);
}
public TransformIntoSourceTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public TransformIntoSourceTriggeredAbility(Effect effect, boolean optional, boolean whenever) {
super(Zone.BATTLEFIELD, effect, optional);
this.whenever = whenever;
}
private TransformIntoSourceTriggeredAbility(final TransformIntoSourceTriggeredAbility ability) {
super(ability);
this.whenever = ability.whenever;
}
@Override
public TransformIntoSourceTriggeredAbility copy() {
return new TransformIntoSourceTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TRANSFORMED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getTargetId().equals(this.getSourceId())) {
return false;
}
Permanent permanent = getSourcePermanentIfItStillExists(game);
return permanent != null && permanent.isTransformed();
}
@Override
public String getTriggerPhrase() {
return "When" + (whenever ? "ever" : "") + " this creature transforms into this {this}, ";
}
}