From 7532d1228be66f8771ac288663aa7eaa33c69533 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 14:23:54 -0700 Subject: [PATCH 01/13] improve PutLandFromHandOntoBattlefieldEffect so that Elvish Pioneer and Terrain Generator can use it --- Mage.Sets/src/mage/cards/e/ElvishPioneer.java | 64 +------------------ .../src/mage/cards/k/KrosanWayfarer.java | 3 +- .../src/mage/cards/s/SkyshroudRanger.java | 4 +- .../src/mage/cards/t/TerrainGenerator.java | 51 +-------------- Mage.Sets/src/mage/cards/w/WalkingAtlas.java | 5 +- .../PutLandFromHandOntoBattlefieldEffect.java | 12 +++- .../mage/filter/common/FilterLandCard.java | 7 ++ 7 files changed, 27 insertions(+), 119 deletions(-) diff --git a/Mage.Sets/src/mage/cards/e/ElvishPioneer.java b/Mage.Sets/src/mage/cards/e/ElvishPioneer.java index 04326615808..77adf19b9af 100644 --- a/Mage.Sets/src/mage/cards/e/ElvishPioneer.java +++ b/Mage.Sets/src/mage/cards/e/ElvishPioneer.java @@ -29,24 +29,13 @@ package mage.cards.e; import java.util.UUID; +import mage.abilities.effects.common.PutLandFromHandOntoBattlefieldEffect; import mage.constants.CardType; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; -import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.Outcome; -import mage.constants.Zone; -import mage.filter.FilterCard; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.filter.predicate.mageobject.SupertypePredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; -import mage.target.common.TargetCardInHand; +import mage.filter.common.FilterLandCard; /** * @@ -63,7 +52,7 @@ public class ElvishPioneer extends CardImpl { this.toughness = new MageInt(1); // When Elvish Pioneer enters the battlefield, you may put a basic land card from your hand onto the battlefield tapped. - this.addAbility(new EntersBattlefieldTriggeredAbility(new PutLandOnBattlefieldEffect(), false)); + this.addAbility(new EntersBattlefieldTriggeredAbility(new PutLandFromHandOntoBattlefieldEffect(true, FilterLandCard.basicLandCard()), false)); } public ElvishPioneer(final ElvishPioneer card) { @@ -75,50 +64,3 @@ public class ElvishPioneer extends CardImpl { return new ElvishPioneer(this); } } - -class PutLandOnBattlefieldEffect extends OneShotEffect { - - private static final FilterCard filter = new FilterCard("card other than a basic land card"); - - static { - filter.add(Predicates.and(new CardTypePredicate(CardType.LAND), new SupertypePredicate("Basic"))); - } - - private static final String choiceText = "Put a basic land card from your hand onto the battlefield?"; - - public PutLandOnBattlefieldEffect() { - super(Outcome.PutLandInPlay); - this.staticText = "put a basic land card from your hand onto the battlefield"; - } - - public PutLandOnBattlefieldEffect(final PutLandOnBattlefieldEffect effect) { - super(effect); - } - - @Override - public PutLandOnBattlefieldEffect copy() { - return new PutLandOnBattlefieldEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null || !player.chooseUse(Outcome.PutLandInPlay, choiceText, source, game)) { - return false; - } - - TargetCardInHand target = new TargetCardInHand(filter); - if (player.choose(Outcome.PutLandInPlay, target, source.getSourceId(), game)) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId()); - Permanent permanent = game.getPermanent(card.getId()); - if (permanent != null) { - permanent.setTapped(true); - } - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/k/KrosanWayfarer.java b/Mage.Sets/src/mage/cards/k/KrosanWayfarer.java index d24f5f30071..514b76319ba 100644 --- a/Mage.Sets/src/mage/cards/k/KrosanWayfarer.java +++ b/Mage.Sets/src/mage/cards/k/KrosanWayfarer.java @@ -52,8 +52,7 @@ public class KrosanWayfarer extends CardImpl { this.toughness = new MageInt(1); // Sacrifice Krosan Wayfarer: You may put a land card from your hand onto the battlefield. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new SacrificeSourceCost()); - this.addAbility(ability); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new SacrificeSourceCost())); } public KrosanWayfarer(final KrosanWayfarer card) { diff --git a/Mage.Sets/src/mage/cards/s/SkyshroudRanger.java b/Mage.Sets/src/mage/cards/s/SkyshroudRanger.java index e2aeaea23f5..338f5174500 100644 --- a/Mage.Sets/src/mage/cards/s/SkyshroudRanger.java +++ b/Mage.Sets/src/mage/cards/s/SkyshroudRanger.java @@ -54,9 +54,7 @@ public class SkyshroudRanger extends CardImpl { this.toughness = new MageInt(1); // {tap}: You may put a land card from your hand onto the battlefield. Activate this ability only any time you could cast a sorcery. - Ability ability = new ActivateAsSorceryActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new TapSourceCost()); - ability.addTarget(new TargetCardInHand(0, 1, new FilterLandCard())); - this.addAbility(ability); + this.addAbility(new ActivateAsSorceryActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new TapSourceCost())); } diff --git a/Mage.Sets/src/mage/cards/t/TerrainGenerator.java b/Mage.Sets/src/mage/cards/t/TerrainGenerator.java index f0568f060e4..69084a04be6 100644 --- a/Mage.Sets/src/mage/cards/t/TerrainGenerator.java +++ b/Mage.Sets/src/mage/cards/t/TerrainGenerator.java @@ -33,6 +33,7 @@ import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.PutLandFromHandOntoBattlefieldEffect; import mage.abilities.mana.ColorlessManaAbility; import mage.cards.Card; import mage.cards.CardImpl; @@ -41,6 +42,7 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterCard; +import mage.filter.common.FilterLandCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.SupertypePredicate; @@ -62,7 +64,7 @@ public class TerrainGenerator extends CardImpl { this.addAbility(new ColorlessManaAbility()); // {2}, {tap}: You may put a basic land card from your hand onto the battlefield tapped. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandOnBattlefieldEffect(), new ManaCostsImpl("{2}")); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(true, FilterLandCard.basicLandCard()), new ManaCostsImpl("{2}")); ability.addCost(new TapSourceCost()); this.addAbility(ability); } @@ -76,50 +78,3 @@ public class TerrainGenerator extends CardImpl { return new TerrainGenerator(this); } } - -class PutLandOnBattlefieldEffect extends OneShotEffect { - - private static final FilterCard filter = new FilterCard("card other than a basic land card"); - - static { - filter.add(Predicates.and(new CardTypePredicate(CardType.LAND), new SupertypePredicate("Basic"))); - } - - private static final String choiceText = "Put a basic land card from your hand onto the battlefield?"; - - public PutLandOnBattlefieldEffect() { - super(Outcome.PutLandInPlay); - this.staticText = "put a basic land card from your hand onto the battlefield"; - } - - public PutLandOnBattlefieldEffect(final PutLandOnBattlefieldEffect effect) { - super(effect); - } - - @Override - public PutLandOnBattlefieldEffect copy() { - return new PutLandOnBattlefieldEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - if (player == null || !player.chooseUse(Outcome.PutLandInPlay, choiceText, source, game)) { - return false; - } - - TargetCardInHand target = new TargetCardInHand(filter); - if (player.choose(Outcome.PutLandInPlay, target, source.getSourceId(), game)) { - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), source.getControllerId()); - Permanent permanent = game.getPermanent(card.getId()); - if (permanent != null) { - permanent.setTapped(true); - } - return true; - } - } - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/w/WalkingAtlas.java b/Mage.Sets/src/mage/cards/w/WalkingAtlas.java index 4b87e8551c7..8e24c7fd032 100644 --- a/Mage.Sets/src/mage/cards/w/WalkingAtlas.java +++ b/Mage.Sets/src/mage/cards/w/WalkingAtlas.java @@ -52,10 +52,9 @@ public class WalkingAtlas extends CardImpl { this.subtype.add("Construct"); this.power = new MageInt(1); this.toughness = new MageInt(1); + // {tap}: You may put a land card from your hand onto the battlefield. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new TapSourceCost()); - ability.addTarget(new TargetCardInHand(new FilterLandCard())); - this.addAbility(ability); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new PutLandFromHandOntoBattlefieldEffect(), new TapSourceCost())); } public WalkingAtlas (final WalkingAtlas card) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/PutLandFromHandOntoBattlefieldEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PutLandFromHandOntoBattlefieldEffect.java index 15893ba5be5..45edec3a94e 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PutLandFromHandOntoBattlefieldEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PutLandFromHandOntoBattlefieldEffect.java @@ -32,6 +32,7 @@ import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.constants.Outcome; import mage.constants.Zone; +import mage.filter.FilterCard; import mage.filter.common.FilterLandCard; import mage.game.Game; import mage.players.Player; @@ -44,6 +45,7 @@ import mage.target.common.TargetCardInHand; */ public class PutLandFromHandOntoBattlefieldEffect extends OneShotEffect { + private FilterCard filter; private boolean tapped; public PutLandFromHandOntoBattlefieldEffect() { @@ -51,21 +53,27 @@ public class PutLandFromHandOntoBattlefieldEffect extends OneShotEffect { } public PutLandFromHandOntoBattlefieldEffect(boolean tapped) { + this(tapped, new FilterLandCard()); + } + + public PutLandFromHandOntoBattlefieldEffect(boolean tapped, FilterCard filter) { super(Outcome.PutLandInPlay); this.tapped = tapped; - staticText = "you may put a land card from your hand onto the battlefield" + (tapped ? " tapped" : ""); + this.filter = filter; + staticText = "you may put a " + filter.getMessage() + " from your hand onto the battlefield" + (tapped ? " tapped" : ""); } public PutLandFromHandOntoBattlefieldEffect(final PutLandFromHandOntoBattlefieldEffect effect) { super(effect); this.tapped = effect.tapped; + this.filter = effect.filter; } @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Target target = new TargetCardInHand(new FilterLandCard("land card")); + Target target = new TargetCardInHand(filter); if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.chooseUse(outcome, "Put land onto battlefield?", source, game) && controller.choose(outcome, target, source.getSourceId(), game)) { diff --git a/Mage/src/main/java/mage/filter/common/FilterLandCard.java b/Mage/src/main/java/mage/filter/common/FilterLandCard.java index b488debb58c..0d6525cc427 100644 --- a/Mage/src/main/java/mage/filter/common/FilterLandCard.java +++ b/Mage/src/main/java/mage/filter/common/FilterLandCard.java @@ -31,6 +31,7 @@ package mage.filter.common; import mage.constants.CardType; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.mageobject.SupertypePredicate; /** * @@ -47,6 +48,12 @@ public class FilterLandCard extends FilterCard { this.add(new CardTypePredicate(CardType.LAND)); } + public static FilterLandCard basicLandCard() { + FilterLandCard filter = new FilterLandCard("basic land card"); + filter.add(new SupertypePredicate("Basic")); + return filter; + } + public FilterLandCard(final FilterLandCard filter) { super(filter); } From 24c5513d86912cdb3f217af02294ef5d35833c6d Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 14:37:48 -0700 Subject: [PATCH 02/13] Abyssal Hunter: remove custom effect --- Mage.Sets/src/mage/cards/a/AbyssalHunter.java | 47 ++++--------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AbyssalHunter.java b/Mage.Sets/src/mage/cards/a/AbyssalHunter.java index a899f96022e..550629cbafc 100644 --- a/Mage.Sets/src/mage/cards/a/AbyssalHunter.java +++ b/Mage.Sets/src/mage/cards/a/AbyssalHunter.java @@ -33,14 +33,14 @@ import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.SourcePermanentPowerCount; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.effects.common.TapTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.common.TargetCreaturePermanent; /** @@ -58,7 +58,10 @@ public class AbyssalHunter extends CardImpl { this.toughness = new MageInt(1); // {B}, {tap}: Tap target creature. Abyssal Hunter deals damage equal to Abyssal Hunter's power to that creature. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AbyssalHunterEffect(), new ManaCostsImpl("{B}")); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new TapTargetEffect(), new ManaCostsImpl("{B}")); + Effect effect = new DamageTargetEffect(new SourcePermanentPowerCount()); + effect.setText("{source} deals damage equal to {source}'s power to that creature."); + ability.addEffect(effect); ability.addCost(new TapSourceCost()); ability.addTarget(new TargetCreaturePermanent()); this.addAbility(ability); @@ -73,37 +76,3 @@ public class AbyssalHunter extends CardImpl { return new AbyssalHunter(this); } } - -class AbyssalHunterEffect extends OneShotEffect { - - public AbyssalHunterEffect() { - super(Outcome.Damage); - staticText = "Tap target creature. Abyssal Hunter deals damage equal to Abyssal Hunter's power to that creature"; - } - - public AbyssalHunterEffect(final AbyssalHunterEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent hunter = game.getPermanent(source.getSourceId()); - if (hunter == null) { - hunter = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD); - } - Permanent targetCreature = game.getPermanent(source.getTargets().getFirstTarget()); - if (targetCreature != null) { - targetCreature.tap(game); - if (hunter != null) { - targetCreature.damage(hunter.getPower().getValue(), hunter.getId(), game, false, true); - } - return true; - } - return false; - } - - @Override - public AbyssalHunterEffect copy() { - return new AbyssalHunterEffect(this); - } -} From 51f0b551c8be11923a30ea9b025fed78873146dc Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 15:47:10 -0700 Subject: [PATCH 03/13] use ReturnToHandFromBattlefieldAllEffect --- .../src/mage/cards/d/DevastationTide.java | 2 +- Mage.Sets/src/mage/cards/e/Evacuation.java | 38 +--------------- Mage.Sets/src/mage/cards/h/Hibernation.java | 45 +++---------------- Mage.Sets/src/mage/cards/r/Rebuild.java | 34 +------------- Mage.Sets/src/mage/cards/s/Sunder.java | 34 +------------- 5 files changed, 14 insertions(+), 139 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DevastationTide.java b/Mage.Sets/src/mage/cards/d/DevastationTide.java index 5f405d9122e..413a35a3241 100644 --- a/Mage.Sets/src/mage/cards/d/DevastationTide.java +++ b/Mage.Sets/src/mage/cards/d/DevastationTide.java @@ -46,7 +46,7 @@ public class DevastationTide extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{U}{U}"); // Return all nonland permanents to their owners' hands. - this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterNonlandPermanent())); + this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterNonlandPermanent("nonland permanents"))); // Miracle {1}{U} this.addAbility(new MiracleAbility(this, new ManaCostsImpl("{1}{U}"))); diff --git a/Mage.Sets/src/mage/cards/e/Evacuation.java b/Mage.Sets/src/mage/cards/e/Evacuation.java index 1285d5ef9e9..b6eed7398d2 100644 --- a/Mage.Sets/src/mage/cards/e/Evacuation.java +++ b/Mage.Sets/src/mage/cards/e/Evacuation.java @@ -29,16 +29,11 @@ package mage.cards.e; import java.util.UUID; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; import mage.constants.CardType; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -51,7 +46,7 @@ public class Evacuation extends CardImpl { // Return all creatures to their owners' hands. - this.getSpellAbility().addEffect(new EvacuationEffect()); + this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterCreaturePermanent("creatures"))); } public Evacuation(final Evacuation card) { @@ -63,32 +58,3 @@ public class Evacuation extends CardImpl { return new Evacuation(this); } } - - -class EvacuationEffect extends OneShotEffect { - - - - public EvacuationEffect() { - super(Outcome.ReturnToHand); - staticText = "Return all creatures to their owners' hands"; - } - - public EvacuationEffect(final EvacuationEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent creature : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) { - creature.moveToZone(Zone.HAND, source.getSourceId(), game, true); - } - return true; - } - - @Override - public EvacuationEffect copy() { - return new EvacuationEffect(this); - } -} - diff --git a/Mage.Sets/src/mage/cards/h/Hibernation.java b/Mage.Sets/src/mage/cards/h/Hibernation.java index f7e0634cef3..4d03f9208ae 100644 --- a/Mage.Sets/src/mage/cards/h/Hibernation.java +++ b/Mage.Sets/src/mage/cards/h/Hibernation.java @@ -29,18 +29,13 @@ package mage.cards.h; import java.util.UUID; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; import mage.constants.CardType; import mage.ObjectColor; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.filter.FilterPermanent; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -48,12 +43,17 @@ import mage.game.permanent.Permanent; */ public class Hibernation extends CardImpl { + private static final FilterPermanent filter = new FilterPermanent("green permanents"); + static { + filter.add(new ColorPredicate(ObjectColor.GREEN)); + } + public Hibernation(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{U}"); // Return all green permanents to their owners' hands. - this.getSpellAbility().addEffect(new HibernationEffect()); + this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(filter)); } public Hibernation(final Hibernation card) { @@ -65,34 +65,3 @@ public class Hibernation extends CardImpl { return new Hibernation(this); } } - - -class HibernationEffect extends OneShotEffect { - - private static final FilterPermanent filter = new FilterPermanent("green permanents"); - static { - filter.add(new ColorPredicate(ObjectColor.GREEN)); - } - - public HibernationEffect() { - super(Outcome.ReturnToHand); - staticText = "Return all green permanents to their owners' hands"; - } - - public HibernationEffect(final HibernationEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - permanent.moveToZone(Zone.HAND, source.getSourceId(), game, true); - } - return true; - } - - @Override - public HibernationEffect copy() { - return new HibernationEffect(this); - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/Rebuild.java b/Mage.Sets/src/mage/cards/r/Rebuild.java index 2e34dcf4612..832edc49adf 100644 --- a/Mage.Sets/src/mage/cards/r/Rebuild.java +++ b/Mage.Sets/src/mage/cards/r/Rebuild.java @@ -29,18 +29,13 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; import mage.constants.CardType; -import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.filter.common.FilterArtifactPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -53,7 +48,7 @@ public class Rebuild extends CardImpl { // Return all artifacts to their owners' hands. - this.getSpellAbility().addEffect(new RebuildEffect()); + this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterArtifactPermanent("artifacts"))); // Cycling {2} this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } @@ -67,28 +62,3 @@ public class Rebuild extends CardImpl { return new Rebuild(this); } } - -class RebuildEffect extends OneShotEffect { - public RebuildEffect() { - super(Outcome.ReturnToHand); - staticText = "Return all artifacts to their owner's hand."; - } - - public RebuildEffect(final RebuildEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent creature : game.getBattlefield().getActivePermanents(new FilterArtifactPermanent(), source.getControllerId(), source.getSourceId(), game)) { - creature.moveToZone(Zone.HAND, source.getSourceId(), game, true); - } - return true; - } - - @Override - public RebuildEffect copy() { - return new RebuildEffect(this); - } - -} diff --git a/Mage.Sets/src/mage/cards/s/Sunder.java b/Mage.Sets/src/mage/cards/s/Sunder.java index f6f2f4cd73e..c759c0578bf 100644 --- a/Mage.Sets/src/mage/cards/s/Sunder.java +++ b/Mage.Sets/src/mage/cards/s/Sunder.java @@ -28,16 +28,11 @@ package mage.cards.s; import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.filter.common.FilterLandPermanent; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -49,7 +44,7 @@ public class Sunder extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{3}{U}{U}"); // Return all lands to their owners' hands. - this.getSpellAbility().addEffect(new SunderEffect()); + this.getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterLandPermanent("lands"))); } public Sunder(final Sunder card) { @@ -61,28 +56,3 @@ public class Sunder extends CardImpl { return new Sunder(this); } } - -class SunderEffect extends OneShotEffect { - - public SunderEffect() { - super(Outcome.ReturnToHand); - staticText = "Return all lands to their owners' hands"; - } - - public SunderEffect(final SunderEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - for (Permanent land : game.getBattlefield().getActivePermanents(new FilterLandPermanent(), source.getControllerId(), source.getSourceId(), game)) { - land.moveToZone(Zone.HAND, source.getSourceId(), game, true); - } - return true; - } - - @Override - public SunderEffect copy() { - return new SunderEffect(this); - } -} From 00951279eae776435aaff9b6655fb0ba9d1e0d63 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 15:48:13 -0700 Subject: [PATCH 04/13] Academy Elite, Aggravate, Agonizing Demise, Akki Underminer removed custom effects --- Mage.Sets/src/mage/cards/a/AcademyElite.java | 46 ++--------------- Mage.Sets/src/mage/cards/a/Aggravate.java | 40 +-------------- .../src/mage/cards/a/AgonizingDemise.java | 40 ++------------- .../src/mage/cards/a/AkkiUnderminer.java | 51 +------------------ 4 files changed, 11 insertions(+), 166 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AcademyElite.java b/Mage.Sets/src/mage/cards/a/AcademyElite.java index 3d018cdb933..90de9a89081 100644 --- a/Mage.Sets/src/mage/cards/a/AcademyElite.java +++ b/Mage.Sets/src/mage/cards/a/AcademyElite.java @@ -30,24 +30,19 @@ package mage.cards.a; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.SpellAbility; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.RemoveCountersSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.common.CardsInAllGraveyardsCount; -import mage.abilities.effects.EntersBattlefieldEffect; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DrawDiscardControllerEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.common.FilterInstantOrSorceryCard; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -65,7 +60,9 @@ public class AcademyElite extends CardImpl { // Academy Elite enters the battlefield with X +1/+1 counters on it, where X is the number of instant and // sorcery cards in all graveyards. - this.addAbility(new EntersBattlefieldAbility(new AcademyEliteEffect1(), "with X +1/+1 counters on it, where X is the number of instant and sorcery cards in all graveyards")); + this.addAbility(new EntersBattlefieldAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(), + new CardsInAllGraveyardsCount(new FilterInstantOrSorceryCard()), false), + "with X +1/+1 counters on it, where X is the number of instant and sorcery cards in all graveyards")); // {2}{U}, Remove a +1/+1 counter from Academy Elite: Draw a card, then discard a card. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new DrawDiscardControllerEffect(1, 1, false), new ManaCostsImpl("{2}{U}")); @@ -83,38 +80,3 @@ public class AcademyElite extends CardImpl { } } - -class AcademyEliteEffect1 extends OneShotEffect { - - public AcademyEliteEffect1() { - super(Outcome.BoostCreature); - staticText = "{this} enters the battlefield with X +1/+1 counters on it, where X is the number of instant and sorcery cards in all graveyards"; - } - - public AcademyEliteEffect1(final AcademyEliteEffect1 effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanentEntering(source.getSourceId()); - if (permanent != null) { - SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY); - if (spellAbility != null - && spellAbility.getSourceId().equals(source.getSourceId()) - && permanent.getZoneChangeCounter(game) == spellAbility.getSourceObjectZoneChangeCounter()) { - CardsInAllGraveyardsCount instantsAndSorceries = new CardsInAllGraveyardsCount(new FilterInstantOrSorceryCard("instant or sorcery cards")); - int instantsAndSorceriesCount = instantsAndSorceries.calculate(game, source, this); - if (instantsAndSorceriesCount > 0) { - permanent.addCounters(CounterType.P1P1.createInstance(instantsAndSorceriesCount), game); - } - } - } - return true; - } - - @Override - public AcademyEliteEffect1 copy() { - return new AcademyEliteEffect1(this); - } -} diff --git a/Mage.Sets/src/mage/cards/a/Aggravate.java b/Mage.Sets/src/mage/cards/a/Aggravate.java index 62179dea21a..ba4826ab1af 100644 --- a/Mage.Sets/src/mage/cards/a/Aggravate.java +++ b/Mage.Sets/src/mage/cards/a/Aggravate.java @@ -27,21 +27,17 @@ */ package mage.cards.a; -import java.util.List; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.RequirementEffect; +import mage.abilities.effects.common.DamageAllControlledTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.TargetPlayer; import mage.watchers.common.DamagedByWatcher; @@ -56,7 +52,7 @@ public class Aggravate extends CardImpl { // Aggravate deals 1 damage to each creature target player controls. - this.getSpellAbility().addEffect(new AggravateEffect()); + this.getSpellAbility().addEffect(new DamageAllControlledTargetEffect(1, new FilterCreaturePermanent())); this.getSpellAbility().addTarget(new TargetPlayer()); // Each creature dealt damage this way attacks this turn if able. this.getSpellAbility().addEffect(new AggravateRequirementEffect()); @@ -73,38 +69,6 @@ public class Aggravate extends CardImpl { } } -class AggravateEffect extends OneShotEffect { - - public AggravateEffect() { - super(Outcome.Damage); - this.staticText = "{this} deals 1 damage to each creature target player controls"; - } - - public AggravateEffect(final AggravateEffect effect) { - super(effect); - } - - @Override - public AggravateEffect copy() { - return new AggravateEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getFirstTarget()); - if (player != null) { - FilterCreaturePermanent filter = new FilterCreaturePermanent(); - filter.add(new ControllerIdPredicate(player.getId())); - List creatures = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game); - for (Permanent creature : creatures) { - creature.damage(1, source.getSourceId(), game, false, true); - } - return true; - } - return false; - } -} - class AggravateRequirementEffect extends RequirementEffect { public AggravateRequirementEffect() { diff --git a/Mage.Sets/src/mage/cards/a/AgonizingDemise.java b/Mage.Sets/src/mage/cards/a/AgonizingDemise.java index 4e11d736499..9de2d4ec720 100644 --- a/Mage.Sets/src/mage/cards/a/AgonizingDemise.java +++ b/Mage.Sets/src/mage/cards/a/AgonizingDemise.java @@ -29,22 +29,18 @@ package mage.cards.a; import java.util.UUID; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.condition.common.KickedCondition; import mage.abilities.decorator.ConditionalOneShotEffect; -import mage.abilities.effects.OneShotEffect; +import mage.abilities.dynamicvalue.common.TargetPermanentPowerCount; +import mage.abilities.effects.common.DamageTargetControllerEffect; import mage.abilities.effects.common.DestroyTargetEffect; import mage.abilities.keyword.KickerAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.permanent.Permanent; -import mage.players.Player; import mage.target.common.TargetCreaturePermanent; /** @@ -70,7 +66,7 @@ public class AgonizingDemise extends CardImpl { //If Agonizing Demise was kicked, it deals damage equal to that creature's power to the creature's controller. this.getSpellAbility().addEffect(new ConditionalOneShotEffect( - new AgonizingDemiseEffect(), + new DamageTargetControllerEffect(new TargetPermanentPowerCount()), KickedCondition.getInstance(), "If {this} was kicked, it deals damage equal to that creature's power to the creature's controller.")); @@ -85,33 +81,3 @@ public class AgonizingDemise extends CardImpl { return new AgonizingDemise(this); } } - -class AgonizingDemiseEffect extends OneShotEffect { - - public AgonizingDemiseEffect() { - super(Outcome.Damage); - } - - public AgonizingDemiseEffect(final AgonizingDemiseEffect effect) { - super(effect); - } - - @Override - public AgonizingDemiseEffect copy() { - return new AgonizingDemiseEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent permanent = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source)); - if(permanent != null) { - Player controller = game.getPlayer(permanent.getControllerId()); - if(controller != null) { - int amount = permanent.getPower().getValue(); - controller.damage(amount, source.getSourceId(), game, false, true); - return true; - } - } - return false; - } -} diff --git a/Mage.Sets/src/mage/cards/a/AkkiUnderminer.java b/Mage.Sets/src/mage/cards/a/AkkiUnderminer.java index 7a56048e5c9..07f0006058a 100644 --- a/Mage.Sets/src/mage/cards/a/AkkiUnderminer.java +++ b/Mage.Sets/src/mage/cards/a/AkkiUnderminer.java @@ -30,19 +30,12 @@ package mage.cards.a; import java.util.UUID; import mage.MageInt; -import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.effects.Effect; +import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.effects.common.SacrificeEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Zone; import mage.filter.FilterPermanent; -import mage.game.Game; -import mage.game.events.DamagedPlayerEvent; -import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; -import mage.target.targetpointer.FixedTarget; /** * @@ -58,7 +51,7 @@ public class AkkiUnderminer extends CardImpl { this.power = new MageInt(1); this.toughness = new MageInt(1); - this.addAbility(new AkkiUnderminerAbility()); + this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new SacrificeEffect(new FilterPermanent(), 1, "that player"), false, true)); } public AkkiUnderminer (final AkkiUnderminer card) { @@ -71,43 +64,3 @@ public class AkkiUnderminer extends CardImpl { } } - -class AkkiUnderminerAbility extends TriggeredAbilityImpl { - - public AkkiUnderminerAbility() { - super(Zone.BATTLEFIELD, new SacrificeEffect(new FilterPermanent(), 1, "")); - } - - public AkkiUnderminerAbility(final AkkiUnderminerAbility ability) { - super(ability); - } - - @Override - public AkkiUnderminerAbility copy() { - return new AkkiUnderminerAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.DAMAGED_PLAYER; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event; - if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) { - for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(event.getPlayerId())); - } - return true; - } - return false; - } - - @Override - public String getRule() { - return "Whenever {this} deals combat damage to a player, that player sacrifices a permanent."; - } -} - - From 1a874262e1c734e7b5bdd49810b8dded647f9d01 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 17:29:29 -0700 Subject: [PATCH 05/13] Rune of Protection: use PreventNextDamageFromChosenSourceToYouEffect --- .../cards/r/RuneOfProtectionArtifacts.java | 90 +++---------------- .../mage/cards/r/RuneOfProtectionBlack.java | 89 +++--------------- .../mage/cards/r/RuneOfProtectionBlue.java | 89 +++--------------- .../mage/cards/r/RuneOfProtectionGreen.java | 89 +++--------------- .../mage/cards/r/RuneOfProtectionLands.java | 90 +++---------------- .../src/mage/cards/r/RuneOfProtectionRed.java | 89 +++--------------- .../mage/cards/r/RuneOfProtectionWhite.java | 89 +++--------------- 7 files changed, 84 insertions(+), 541 deletions(-) diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionArtifacts.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionArtifacts.java index 932253c4fbf..862151ca4dd 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionArtifacts.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionArtifacts.java @@ -28,22 +28,18 @@ package mage.cards.r; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -51,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionArtifacts extends CardImpl { + private static final FilterObject filter = new FilterObject("artifact source"); + static { + filter.add(new CardTypePredicate(CardType.ARTIFACT)); + } + public RuneOfProtectionArtifacts(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a black source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionArtifactsEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time an artifact source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionArtifacts(final RuneOfProtectionArtifacts card) { @@ -70,71 +72,3 @@ public class RuneOfProtectionArtifacts extends CardImpl { return new RuneOfProtectionArtifacts(this); } } - -class RuneOfProtectionArtifactsEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("artifact source"); - - static { - filter.add(new CardTypePredicate(CardType.ARTIFACT)); - } - - private TargetSource target; - - public RuneOfProtectionArtifactsEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time an artifact source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionArtifactsEffect(final RuneOfProtectionArtifactsEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionArtifactsEffect copy() { - return new RuneOfProtectionArtifactsEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlack.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlack.java index c4f471bedc0..2efa0b730e3 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlack.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlack.java @@ -29,20 +29,17 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.constants.*; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -50,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionBlack extends CardImpl { + private static final FilterObject filter = new FilterObject("black source"); + static { + filter.add(new ColorPredicate(ObjectColor.BLACK)); + } + public RuneOfProtectionBlack(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a black source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionBlackEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a black source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionBlack(final RuneOfProtectionBlack card) { @@ -69,71 +72,3 @@ public class RuneOfProtectionBlack extends CardImpl { return new RuneOfProtectionBlack(this); } } - -class RuneOfProtectionBlackEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("black source"); - - static { - filter.add(new ColorPredicate(ObjectColor.BLACK)); - } - - private TargetSource target; - - public RuneOfProtectionBlackEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a black source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionBlackEffect(final RuneOfProtectionBlackEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionBlackEffect copy() { - return new RuneOfProtectionBlackEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlue.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlue.java index c18fec2256a..166e39c81cc 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlue.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionBlue.java @@ -29,20 +29,17 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.constants.*; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -50,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionBlue extends CardImpl { + private static final FilterObject filter = new FilterObject("blue source"); + static { + filter.add(new ColorPredicate(ObjectColor.BLUE)); + } + public RuneOfProtectionBlue(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a blue source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionBlueEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a blue source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionBlue(final RuneOfProtectionBlue card) { @@ -69,71 +72,3 @@ public class RuneOfProtectionBlue extends CardImpl { return new RuneOfProtectionBlue(this); } } - -class RuneOfProtectionBlueEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("blue source"); - - static { - filter.add(new ColorPredicate(ObjectColor.BLUE)); - } - - private TargetSource target; - - public RuneOfProtectionBlueEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a blue source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionBlueEffect(final RuneOfProtectionBlueEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionBlueEffect copy() { - return new RuneOfProtectionBlueEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionGreen.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionGreen.java index a37883d5343..7d50bb6d0d5 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionGreen.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionGreen.java @@ -29,20 +29,17 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.constants.*; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -50,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionGreen extends CardImpl { + private static final FilterObject filter = new FilterObject("green source"); + static { + filter.add(new ColorPredicate(ObjectColor.GREEN)); + } + public RuneOfProtectionGreen(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a green source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionGreenEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a green source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionGreen(final RuneOfProtectionGreen card) { @@ -69,71 +72,3 @@ public class RuneOfProtectionGreen extends CardImpl { return new RuneOfProtectionGreen(this); } } - -class RuneOfProtectionGreenEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("green source"); - - static { - filter.add(new ColorPredicate(ObjectColor.GREEN)); - } - - private TargetSource target; - - public RuneOfProtectionGreenEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a green source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionGreenEffect(final RuneOfProtectionGreenEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionGreenEffect copy() { - return new RuneOfProtectionGreenEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionLands.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionLands.java index daef3e39c53..0c5b789be18 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionLands.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionLands.java @@ -28,22 +28,18 @@ package mage.cards.r; import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -51,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionLands extends CardImpl { + private static final FilterObject filter = new FilterObject("land source"); + static { + filter.add(new CardTypePredicate(CardType.LAND)); + } + public RuneOfProtectionLands(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a black source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionLandsEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a land source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionLands(final RuneOfProtectionLands card) { @@ -70,71 +72,3 @@ public class RuneOfProtectionLands extends CardImpl { return new RuneOfProtectionLands(this); } } - -class RuneOfProtectionLandsEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("land source"); - - static { - filter.add(new CardTypePredicate(CardType.LAND)); - } - - private TargetSource target; - - public RuneOfProtectionLandsEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a land source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionLandsEffect(final RuneOfProtectionLandsEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionLandsEffect copy() { - return new RuneOfProtectionLandsEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionRed.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionRed.java index b146c219870..88e7ced2cea 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionRed.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionRed.java @@ -29,20 +29,17 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.constants.*; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -50,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionRed extends CardImpl { + private static final FilterObject filter = new FilterObject("red source"); + static { + filter.add(new ColorPredicate(ObjectColor.RED)); + } + public RuneOfProtectionRed(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a red source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionRedEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a red source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionRed(final RuneOfProtectionRed card) { @@ -69,71 +72,3 @@ public class RuneOfProtectionRed extends CardImpl { return new RuneOfProtectionRed(this); } } - -class RuneOfProtectionRedEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("red source"); - - static { - filter.add(new ColorPredicate(ObjectColor.RED)); - } - - private TargetSource target; - - public RuneOfProtectionRedEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a red source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionRedEffect(final RuneOfProtectionRedEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionRedEffect copy() { - return new RuneOfProtectionRedEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} diff --git a/Mage.Sets/src/mage/cards/r/RuneOfProtectionWhite.java b/Mage.Sets/src/mage/cards/r/RuneOfProtectionWhite.java index e993974c8a2..962a86447e4 100644 --- a/Mage.Sets/src/mage/cards/r/RuneOfProtectionWhite.java +++ b/Mage.Sets/src/mage/cards/r/RuneOfProtectionWhite.java @@ -29,20 +29,17 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.PreventNextDamageFromChosenSourceToYouEffect; import mage.constants.*; import mage.ObjectColor; -import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.CyclingAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.filter.FilterObject; import mage.filter.predicate.mageobject.ColorPredicate; -import mage.game.Game; -import mage.game.events.GameEvent; -import mage.target.TargetSource; /** * @@ -50,14 +47,20 @@ import mage.target.TargetSource; */ public class RuneOfProtectionWhite extends CardImpl { + private static final FilterObject filter = new FilterObject("white source"); + static { + filter.add(new ColorPredicate(ObjectColor.WHITE)); + } + public RuneOfProtectionWhite(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}"); - // {W}: The next time a white source of your choice would deal damage to you this turn, prevent that damage. - this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RuneOfProtectionWhiteEffect() , new ManaCostsImpl("W"))); - // Cycling {2} ({2}, Discard this card: Draw a card.) - this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); + // {W}: The next time a white source of your choice would deal damage to you this turn, prevent that damage. + Effect effect = new PreventNextDamageFromChosenSourceToYouEffect(Duration.EndOfTurn, filter); + this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new ManaCostsImpl("W"))); + // Cycling {2} ({2}, Discard this card: Draw a card.) + this.addAbility(new CyclingAbility(new ManaCostsImpl("{2}"))); } public RuneOfProtectionWhite(final RuneOfProtectionWhite card) { @@ -69,71 +72,3 @@ public class RuneOfProtectionWhite extends CardImpl { return new RuneOfProtectionWhite(this); } } - -class RuneOfProtectionWhiteEffect extends PreventionEffectImpl { - - private static final FilterObject filter = new FilterObject("white source"); - - static { - filter.add(new ColorPredicate(ObjectColor.WHITE)); - } - - private TargetSource target; - - public RuneOfProtectionWhiteEffect() { - super(Duration.EndOfTurn); - target = new TargetSource(filter); - - staticText = "The next time a white source of your choice would deal damage to you this turn, prevent that damage"; - } - - public RuneOfProtectionWhiteEffect(final RuneOfProtectionWhiteEffect effect) { - super(effect); - this.target = effect.target.copy(); - } - - @Override - public RuneOfProtectionWhiteEffect copy() { - return new RuneOfProtectionWhiteEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - return true; - } - - @Override - public void init(Ability source, Game game) { - this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game); - } - - @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - preventDamage(event, source, target.getFirstTarget(), game); - return true; - } - return false; - } - - private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { - GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false); - if (!game.replaceEvent(preventEvent)) { - int damage = event.getAmount(); - event.setAmount(0); - this.used = true; - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage)); - } - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (!this.used && super.applies(event, source, game)) { - if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { - return true; - } - } - return false; - } - -} From bea125bab585a769a0e555d7c1f4c1d770116b2f Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 17:29:43 -0700 Subject: [PATCH 06/13] Runner's Bane: use TapEnchantedEffect --- Mage.Sets/src/mage/cards/r/RunnersBane.java | 33 ++------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/Mage.Sets/src/mage/cards/r/RunnersBane.java b/Mage.Sets/src/mage/cards/r/RunnersBane.java index e8b220fbfa4..da95240dc90 100644 --- a/Mage.Sets/src/mage/cards/r/RunnersBane.java +++ b/Mage.Sets/src/mage/cards/r/RunnersBane.java @@ -29,6 +29,7 @@ package mage.cards.r; import java.util.UUID; +import mage.abilities.effects.common.TapEnchantedEffect; import mage.constants.CardType; import mage.constants.Zone; import mage.abilities.Ability; @@ -53,8 +54,6 @@ import mage.target.common.TargetCreaturePermanent; * * @author LevelX2 */ - - public class RunnersBane extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature with power 3 or less"); @@ -74,7 +73,7 @@ public class RunnersBane extends CardImpl { this.addAbility(ability); // When Runner's Bane enters the battlefield, tap enchanted creature. - this.addAbility(new EntersBattlefieldTriggeredAbility(new RunnersBaneEffect())); + this.addAbility(new EntersBattlefieldTriggeredAbility(new TapEnchantedEffect())); // Enchanted creature doesn't untap during its controller's the untap step. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DontUntapInControllersUntapStepEnchantedEffect())); } @@ -88,31 +87,3 @@ public class RunnersBane extends CardImpl { return new RunnersBane(this); } } - -class RunnersBaneEffect extends OneShotEffect { - RunnersBaneEffect() { - super(Outcome.Tap); - staticText = "tap enchanted creature"; - } - - RunnersBaneEffect(final RunnersBaneEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent permanent = game.getPermanent(enchantment.getAttachedTo()); - if (permanent != null) { - return permanent.tap(game); - } - } - return false; - } - - @Override - public RunnersBaneEffect copy() { - return new RunnersBaneEffect(); - } -} From f67bdc4b6b600da73631ce8a653bb33beaefe8c2 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 21:58:00 -0700 Subject: [PATCH 07/13] Wall of Roots: use PutCounterSourceCost --- Mage.Sets/src/mage/cards/w/WallOfRoots.java | 40 ++------------------- 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/Mage.Sets/src/mage/cards/w/WallOfRoots.java b/Mage.Sets/src/mage/cards/w/WallOfRoots.java index 0f252f4a5de..276eb41ecf3 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfRoots.java +++ b/Mage.Sets/src/mage/cards/w/WallOfRoots.java @@ -28,21 +28,18 @@ package mage.cards.w; import java.util.UUID; + +import mage.abilities.costs.common.PutCountersSourceCost; import mage.constants.CardType; import mage.constants.Zone; import mage.MageInt; import mage.Mana; -import mage.abilities.Ability; -import mage.abilities.costs.Cost; -import mage.abilities.costs.CostImpl; import mage.abilities.effects.common.BasicManaEffect; import mage.abilities.keyword.DefenderAbility; import mage.abilities.mana.ActivateOncePerTurnManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.counters.BoostCounter; -import mage.game.Game; -import mage.game.permanent.Permanent; /** * @@ -61,7 +58,7 @@ public class WallOfRoots extends CardImpl { // Defender this.addAbility(DefenderAbility.getInstance()); // Put a -0/-1 counter on Wall of Roots: Add {G} to your mana pool. Activate this ability only once each turn. - this.addAbility(new ActivateOncePerTurnManaAbility(Zone.BATTLEFIELD, new BasicManaEffect(Mana.GreenMana(1)), new WallOfRootsCost())); + this.addAbility(new ActivateOncePerTurnManaAbility(Zone.BATTLEFIELD, new BasicManaEffect(Mana.GreenMana(1)), new PutCountersSourceCost(new BoostCounter(0, -1)))); } public WallOfRoots(final WallOfRoots card) { @@ -73,34 +70,3 @@ public class WallOfRoots extends CardImpl { return new WallOfRoots(this); } } - -class WallOfRootsCost extends CostImpl { - - public WallOfRootsCost() { - this.text = "Put a -0/-1 counter on {this}"; - } - - public WallOfRootsCost(WallOfRootsCost cost) { - super(cost); - } - - @Override - public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) { - return true; - } - - @Override - public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { - Permanent permanent = game.getPermanent(sourceId); - if (permanent != null) { - permanent.addCounters(new BoostCounter(0, -1), game); - this.paid = true; - } - return paid; - } - - @Override - public WallOfRootsCost copy() { - return new WallOfRootsCost(this); - } -} From 3ae8b257d530a7aef637f0501465edc32c3b9ade Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 23:24:10 -0700 Subject: [PATCH 08/13] Budoka Pupil, etc: flipping is optional flag was being ignored in OnEventTriggerAbility constructor, and not set at all for the other cards. --- Mage.Sets/src/mage/cards/c/CallowJushi.java | 2 +- Mage.Sets/src/mage/cards/c/CunningBandit.java | 2 +- Mage.Sets/src/mage/cards/f/FaithfulSquire.java | 2 +- Mage.Sets/src/mage/cards/h/HiredMuscle.java | 2 +- .../abilities/common/OnEventTriggeredAbility.java | 12 ++++-------- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/CallowJushi.java b/Mage.Sets/src/mage/cards/c/CallowJushi.java index 64336309448..680866b2a32 100644 --- a/Mage.Sets/src/mage/cards/c/CallowJushi.java +++ b/Mage.Sets/src/mage/cards/c/CallowJushi.java @@ -73,7 +73,7 @@ public class CallowJushi extends CardImpl { // At the beginning of the end step, if there are two or more ki counters on Callow Jushi, you may flip it. this.addAbility(new ConditionalTriggeredAbility( - new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new JarakuTheInterloper())), + new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new JarakuTheInterloper()), true), new SourceHasCounterCondition(CounterType.KI, 2, Integer.MAX_VALUE), "At the beginning of the end step, if there are two or more ki counters on {this}, you may flip it.")); } diff --git a/Mage.Sets/src/mage/cards/c/CunningBandit.java b/Mage.Sets/src/mage/cards/c/CunningBandit.java index a1dbc3f4872..1df46cfe346 100644 --- a/Mage.Sets/src/mage/cards/c/CunningBandit.java +++ b/Mage.Sets/src/mage/cards/c/CunningBandit.java @@ -73,7 +73,7 @@ public class CunningBandit extends CardImpl { // At the beginning of the end step, if there are two or more ki counters on Cunning Bandit, you may flip it. this.addAbility(new ConditionalTriggeredAbility( - new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new AzamukiTreacheryIncarnate())), + new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new AzamukiTreacheryIncarnate()), true), new SourceHasCounterCondition(CounterType.KI, 2, Integer.MAX_VALUE), "At the beginning of the end step, if there are two or more ki counters on {this}, you may flip it.")); } diff --git a/Mage.Sets/src/mage/cards/f/FaithfulSquire.java b/Mage.Sets/src/mage/cards/f/FaithfulSquire.java index b28238592b9..989a3ad6745 100644 --- a/Mage.Sets/src/mage/cards/f/FaithfulSquire.java +++ b/Mage.Sets/src/mage/cards/f/FaithfulSquire.java @@ -75,7 +75,7 @@ public class FaithfulSquire extends CardImpl { // At the beginning of the end step, if there are two or more ki counters on Faithful Squire, you may flip it this.addAbility(new ConditionalTriggeredAbility( - new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new KaisoMemoryOfLoyalty())), + new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new KaisoMemoryOfLoyalty()), true), new SourceHasCounterCondition(CounterType.KI, 2, Integer.MAX_VALUE), "At the beginning of the end step, if there are two or more ki counters on {this}, you may flip it.")); diff --git a/Mage.Sets/src/mage/cards/h/HiredMuscle.java b/Mage.Sets/src/mage/cards/h/HiredMuscle.java index 06b2c14d69c..964645e6611 100644 --- a/Mage.Sets/src/mage/cards/h/HiredMuscle.java +++ b/Mage.Sets/src/mage/cards/h/HiredMuscle.java @@ -74,7 +74,7 @@ public class HiredMuscle extends CardImpl { // At the beginning of the end step, if there are two or more ki counters on Hired Muscle, you may flip it. this.addAbility(new ConditionalTriggeredAbility( - new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new Scarmaker())), + new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new FlipSourceEffect(new Scarmaker()), true), new SourceHasCounterCondition(CounterType.KI, 2, Integer.MAX_VALUE), "At the beginning of the end step, if there are two or more ki counters on {this}, you may flip it.")); } diff --git a/Mage/src/main/java/mage/abilities/common/OnEventTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/OnEventTriggeredAbility.java index c724b43fbe3..fbe6c32a91c 100644 --- a/Mage/src/main/java/mage/abilities/common/OnEventTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/OnEventTriggeredAbility.java @@ -42,18 +42,14 @@ public class OnEventTriggeredAbility extends TriggeredAbilityImpl { private final EventType eventType; private final String eventName; - private boolean allPlayers = false; + private final boolean allPlayers; public OnEventTriggeredAbility(EventType eventType, String eventName, Effect effect) { - super(Zone.BATTLEFIELD, effect); - this.eventType = eventType; - this.eventName = eventName; + this(eventType, eventName, effect, false); } public OnEventTriggeredAbility(EventType eventType, String eventName, Effect effect, boolean optional) { - super(Zone.BATTLEFIELD, effect, optional); - this.eventType = eventType; - this.eventName = eventName; + this(eventType, eventName, false, effect, optional); } public OnEventTriggeredAbility(EventType eventType, String eventName, boolean allPlayers, Effect effect) { @@ -61,7 +57,7 @@ public class OnEventTriggeredAbility extends TriggeredAbilityImpl { } public OnEventTriggeredAbility(EventType eventType, String eventName, boolean allPlayers, Effect effect, boolean optional) { - super(Zone.BATTLEFIELD, effect); + super(Zone.BATTLEFIELD, effect, optional); this.eventType = eventType; this.eventName = eventName; this.allPlayers = allPlayers; From f51d71254cca41f0e3801f29cb503fd98dbba213 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 23:44:59 -0700 Subject: [PATCH 09/13] Mark of the Oni: only count demons you control --- Mage.Sets/src/mage/cards/m/MarkOfTheOni.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MarkOfTheOni.java b/Mage.Sets/src/mage/cards/m/MarkOfTheOni.java index 35f6c7188a4..32cd1a07348 100644 --- a/Mage.Sets/src/mage/cards/m/MarkOfTheOni.java +++ b/Mage.Sets/src/mage/cards/m/MarkOfTheOni.java @@ -44,8 +44,7 @@ import mage.abilities.keyword.EnchantAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.TargetController; -import mage.filter.common.FilterCreaturePermanent; -import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.filter.common.FilterControlledCreaturePermanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -54,10 +53,6 @@ import mage.target.common.TargetCreaturePermanent; * @author LevelX2 */ public class MarkOfTheOni extends CardImpl { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("if you control no Demons"); - static { - filter.add(new SubtypePredicate("Demon")); - } public MarkOfTheOni(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{B}"); @@ -78,7 +73,9 @@ public class MarkOfTheOni extends CardImpl { this.addAbility(new BeginningOfEndStepTriggeredAbility(Zone.BATTLEFIELD, new SacrificeSourceEffect(), TargetController.ANY, - new PermanentsOnTheBattlefieldCondition(filter, PermanentsOnTheBattlefieldCondition.CountType.FEWER_THAN, 1), + new PermanentsOnTheBattlefieldCondition( + new FilterControlledCreaturePermanent("Demon", "if you control no Demons"), + PermanentsOnTheBattlefieldCondition.CountType.FEWER_THAN, 1), false)); } From 722d290d0d13492938105203bdc078dd653718c6 Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 23:46:00 -0700 Subject: [PATCH 10/13] Glimmervoid, Thran Quarry: remove custom triggered ability --- Mage.Sets/src/mage/cards/g/Glimmervoid.java | 53 ++++----------------- Mage.Sets/src/mage/cards/t/ThranQuarry.java | 47 ++++-------------- 2 files changed, 18 insertions(+), 82 deletions(-) diff --git a/Mage.Sets/src/mage/cards/g/Glimmervoid.java b/Mage.Sets/src/mage/cards/g/Glimmervoid.java index b9f75bfddef..d8440a7f8ab 100644 --- a/Mage.Sets/src/mage/cards/g/Glimmervoid.java +++ b/Mage.Sets/src/mage/cards/g/Glimmervoid.java @@ -28,17 +28,18 @@ package mage.cards.g; import java.util.UUID; -import mage.abilities.TriggeredAbilityImpl; + +import mage.abilities.TriggeredAbility; +import mage.abilities.common.OnEventTriggeredAbility; +import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; +import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.SacrificeSourceEffect; import mage.abilities.mana.AnyColorManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Zone; -import mage.filter.common.FilterArtifactPermanent; -import mage.game.Game; +import mage.filter.common.FilterControlledArtifactPermanent; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; /** * @@ -50,7 +51,9 @@ public class Glimmervoid extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.LAND},""); // At the beginning of the end step, if you control no artifacts, sacrifice Glimmervoid. - this.addAbility(new GlimmervoidTriggeredAbility()); + TriggeredAbility triggered = new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect()); + this.addAbility(new ConditionalTriggeredAbility(triggered, new PermanentsOnTheBattlefieldCondition(new FilterControlledArtifactPermanent(), PermanentsOnTheBattlefieldCondition.CountType.FEWER_THAN, 1), + "At the beginning of the end step, if you control no artifacts, sacrifice {this}.")); // {tap}: Add one mana of any color to your mana pool. this.addAbility(new AnyColorManaAbility()); } @@ -64,41 +67,3 @@ public class Glimmervoid extends CardImpl { return new Glimmervoid(this); } } - -class GlimmervoidTriggeredAbility extends TriggeredAbilityImpl { - - static final FilterArtifactPermanent filter = new FilterArtifactPermanent(); - - GlimmervoidTriggeredAbility() { - super(Zone.BATTLEFIELD, new SacrificeSourceEffect()); - } - - GlimmervoidTriggeredAbility(final GlimmervoidTriggeredAbility ability) { - super(ability); - } - - @Override - public GlimmervoidTriggeredAbility copy() { - return new GlimmervoidTriggeredAbility(this); - } - - @Override - public boolean checkInterveningIfClause(Game game) { - return game.getBattlefield().countAll(filter, controllerId, game) == 0; - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.END_TURN_STEP_PRE; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - return true; - } - - @Override - public String getRule() { - return "At the beginning of the end step, if you control no artifacts, sacrifice {this}."; - } -} diff --git a/Mage.Sets/src/mage/cards/t/ThranQuarry.java b/Mage.Sets/src/mage/cards/t/ThranQuarry.java index 9e37982f724..0b6521e3397 100644 --- a/Mage.Sets/src/mage/cards/t/ThranQuarry.java +++ b/Mage.Sets/src/mage/cards/t/ThranQuarry.java @@ -28,17 +28,18 @@ package mage.cards.t; import java.util.UUID; -import mage.abilities.TriggeredAbilityImpl; + +import mage.abilities.TriggeredAbility; +import mage.abilities.common.OnEventTriggeredAbility; +import mage.abilities.condition.common.CreatureCountCondition; +import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.SacrificeSourceEffect; import mage.abilities.mana.AnyColorManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; +import mage.constants.TargetController; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; /** * @@ -50,7 +51,9 @@ public class ThranQuarry extends CardImpl { super(ownerId,setInfo,new CardType[]{CardType.LAND},""); // At the beginning of the end step, if you control no creatures, sacrifice Thran Quarry. - this.addAbility(new ThranQuarryTriggeredAbility()); + TriggeredAbility triggered = new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect()); + this.addAbility(new ConditionalTriggeredAbility(triggered, new CreatureCountCondition(0, TargetController.YOU), + "At the beginning of the end step, if you control no creatures, sacrifice {this}.")); // {tap}: Add one mana of any color to your mana pool. this.addAbility(new AnyColorManaAbility()); @@ -66,35 +69,3 @@ public class ThranQuarry extends CardImpl { return new ThranQuarry(this); } } - -class ThranQuarryTriggeredAbility extends TriggeredAbilityImpl { - - ThranQuarryTriggeredAbility() { - super(Zone.BATTLEFIELD, new SacrificeSourceEffect()); - } - - ThranQuarryTriggeredAbility(final ThranQuarryTriggeredAbility ability) { - super(ability); - } - - @Override - public ThranQuarryTriggeredAbility copy() { - return new ThranQuarryTriggeredAbility(this); - } - - @Override - public boolean checkEventType(GameEvent event, Game game) { - return event.getType() == EventType.END_TURN_STEP_PRE; - } - - @Override - public boolean checkTrigger(GameEvent event, Game game) { - FilterCreaturePermanent filter = new FilterCreaturePermanent(); - return !game.getBattlefield().contains(filter, controllerId, 1, game); - } - - @Override - public String getRule() { - return "At the beginning of the end step, if you control no creatures, sacrifice {this}."; - } -} From 797a3979afde3dfbd95257a8cbe300da5fe7a05e Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sun, 16 Oct 2016 23:51:00 -0700 Subject: [PATCH 11/13] Mark of Fury, Skizzik, Viashino Cutthroat: trigger on every end step not just controller's --- Mage.Sets/src/mage/cards/m/MarkOfFury.java | 2 +- Mage.Sets/src/mage/cards/s/Skizzik.java | 2 +- Mage.Sets/src/mage/cards/v/ViashinoCutthroat.java | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Mage.Sets/src/mage/cards/m/MarkOfFury.java b/Mage.Sets/src/mage/cards/m/MarkOfFury.java index f59c2550158..7e9909a74ec 100644 --- a/Mage.Sets/src/mage/cards/m/MarkOfFury.java +++ b/Mage.Sets/src/mage/cards/m/MarkOfFury.java @@ -65,7 +65,7 @@ public class MarkOfFury extends CardImpl { // Enchanted creature has haste. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAttachedEffect(HasteAbility.getInstance(), AttachmentType.AURA))); // At the beginning of the end step, return Mark of Fury to its owner's hand. - this.addAbility(new BeginningOfEndStepTriggeredAbility(new ReturnToHandSourceEffect(true), TargetController.YOU, false)); + this.addAbility(new BeginningOfEndStepTriggeredAbility(new ReturnToHandSourceEffect(true), TargetController.ANY, false)); } public MarkOfFury(final MarkOfFury card) { diff --git a/Mage.Sets/src/mage/cards/s/Skizzik.java b/Mage.Sets/src/mage/cards/s/Skizzik.java index 749ab03a858..55bc2f5e9cc 100644 --- a/Mage.Sets/src/mage/cards/s/Skizzik.java +++ b/Mage.Sets/src/mage/cards/s/Skizzik.java @@ -60,7 +60,7 @@ public class Skizzik extends CardImpl { // Haste this.addAbility(HasteAbility.getInstance()); // At the beginning of the end step, sacrifice Skizzik unless it was kicked. - this.addAbility(new BeginningOfEndStepTriggeredAbility(new SacrificeSourceUnlessConditionEffect(KickedCondition.getInstance()), TargetController.YOU, false)); + this.addAbility(new BeginningOfEndStepTriggeredAbility(new SacrificeSourceUnlessConditionEffect(KickedCondition.getInstance()), TargetController.ANY, false)); } public Skizzik(final Skizzik card) { diff --git a/Mage.Sets/src/mage/cards/v/ViashinoCutthroat.java b/Mage.Sets/src/mage/cards/v/ViashinoCutthroat.java index bbfe598987e..51be97d6aca 100644 --- a/Mage.Sets/src/mage/cards/v/ViashinoCutthroat.java +++ b/Mage.Sets/src/mage/cards/v/ViashinoCutthroat.java @@ -28,13 +28,15 @@ package mage.cards.v; import java.util.UUID; + +import mage.abilities.common.BeginningOfEndStepTriggeredAbility; import mage.constants.CardType; import mage.MageInt; -import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility; import mage.abilities.effects.common.ReturnToHandSourceEffect; import mage.abilities.keyword.HasteAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.TargetController; /** * @@ -52,7 +54,7 @@ public class ViashinoCutthroat extends CardImpl { // Haste this.addAbility(HasteAbility.getInstance()); // At the beginning of the end step, return Viashino Cutthroat to its owner's hand. - this.addAbility(new BeginningOfYourEndStepTriggeredAbility(new ReturnToHandSourceEffect(true), false)); + this.addAbility(new BeginningOfEndStepTriggeredAbility(new ReturnToHandSourceEffect(true), TargetController.ANY, false)); } public ViashinoCutthroat(final ViashinoCutthroat card) { From 9e24bff19f8b8610e237d55c8167c5c708e461ea Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sat, 15 Oct 2016 20:25:03 -0700 Subject: [PATCH 12/13] Resurrection: just use ReturnFromGraveyardToBattlefieldTargetEffect --- Mage.Sets/src/mage/cards/r/Resurrection.java | 40 +------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/Mage.Sets/src/mage/cards/r/Resurrection.java b/Mage.Sets/src/mage/cards/r/Resurrection.java index 7ac4d2b2170..34d1be82240 100644 --- a/Mage.Sets/src/mage/cards/r/Resurrection.java +++ b/Mage.Sets/src/mage/cards/r/Resurrection.java @@ -28,23 +28,16 @@ package mage.cards.r; import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; +import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Zone; import mage.filter.common.FilterCreatureCard; -import mage.game.Game; -import mage.players.Player; import mage.target.common.TargetCardInYourGraveyard; /** * * @author KholdFuzion - */ public class Resurrection extends CardImpl { @@ -53,7 +46,7 @@ public class Resurrection extends CardImpl { // Return target creature card from your graveyard to the battlefield. - this.getSpellAbility().addEffect(new ResurrectionEffect()); + this.getSpellAbility().addEffect(new ReturnFromGraveyardToBattlefieldTargetEffect()); this.getSpellAbility().addTarget(new TargetCardInYourGraveyard(new FilterCreatureCard("creature card from your graveyard"))); } @@ -67,32 +60,3 @@ public class Resurrection extends CardImpl { return new Resurrection(this); } } - -class ResurrectionEffect extends OneShotEffect { - - public ResurrectionEffect() { - super(Outcome.PutCreatureInPlay); - this.staticText = "Return target creature card from your graveyard to the battlefield."; - } - - public ResurrectionEffect(final ResurrectionEffect effect) { - super(effect); - } - - @Override - public ResurrectionEffect copy() { - return new ResurrectionEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Card card = game.getCard(source.getFirstTarget()); - Player player = game.getPlayer(card.getOwnerId()); - if (card != null && player != null) { - card.putOntoBattlefield(game, Zone.GRAVEYARD, source.getSourceId(), source.getControllerId()); - return true; - } - - return false; - } -} From 115b6b88f44a246bf9a21086826adde2a4398bdb Mon Sep 17 00:00:00 2001 From: Neil Gentleman Date: Sat, 15 Oct 2016 17:44:46 -0700 Subject: [PATCH 13/13] simplify auras copied from Burrowing don't need a custom effect to add landwalk --- Mage.Sets/src/mage/cards/b/Burrowing.java | 63 ++-------------- Mage.Sets/src/mage/cards/d/DryadsFavor.java | 61 ++-------------- Mage.Sets/src/mage/cards/f/FishliverOil.java | 3 +- .../src/mage/cards/g/GoblinWarPaint.java | 72 ++++--------------- .../src/mage/cards/i/ImprisonedInTheMoon.java | 3 - .../src/mage/cards/v/VolcanicStrength.java | 72 +++---------------- 6 files changed, 37 insertions(+), 237 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/Burrowing.java b/Mage.Sets/src/mage/cards/b/Burrowing.java index a7a18d5b3df..0cca74a0a40 100644 --- a/Mage.Sets/src/mage/cards/b/Burrowing.java +++ b/Mage.Sets/src/mage/cards/b/Burrowing.java @@ -30,20 +30,16 @@ package mage.cards.b; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.MountainwalkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.AttachmentType; import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Layer; import mage.constants.Outcome; -import mage.constants.SubLayer; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -60,13 +56,15 @@ public class Burrowing extends CardImpl { // Enchant creature - // Enchanted creature has mountainwalk. TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BurrowingEffect())); + + // Enchanted creature has mountainwalk. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new GainAbilityAttachedEffect(new MountainwalkAbility(), AttachmentType.AURA))); } public Burrowing(final Burrowing card) { @@ -77,51 +75,4 @@ public class Burrowing extends CardImpl { public Burrowing copy() { return new Burrowing(this); } -} - -class BurrowingEffect extends ContinuousEffectImpl { - - public BurrowingEffect() { - super(Duration.WhileOnBattlefield, Outcome.BoostCreature); - staticText = "Enchanted creature has mountainwalk"; - } - - public BurrowingEffect(final BurrowingEffect effect) { - super(effect); - } - - @Override - public BurrowingEffect copy() { - return new BurrowingEffect(this); - } - - @Override - public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - switch (layer) { - case AbilityAddingRemovingEffects_6: - if (sublayer == SubLayer.NA) { - creature.addAbility(new MountainwalkAbility(), game); - } - break; - } - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean hasLayer(Layer layer) { - return layer == Layer.AbilityAddingRemovingEffects_6; - } - } \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/d/DryadsFavor.java b/Mage.Sets/src/mage/cards/d/DryadsFavor.java index e49671a9e4d..69e42f4ef9a 100644 --- a/Mage.Sets/src/mage/cards/d/DryadsFavor.java +++ b/Mage.Sets/src/mage/cards/d/DryadsFavor.java @@ -31,20 +31,16 @@ package mage.cards.d; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.ForestwalkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.AttachmentType; import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Layer; import mage.constants.Outcome; -import mage.constants.SubLayer; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -61,11 +57,13 @@ public class DryadsFavor extends CardImpl { // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); - this.getSpellAbility().addEffect(new AttachEffect(Outcome.Benefit)); + this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); + // Enchanted creature has forestwalk. - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new DryadsFavorEffect())); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, + new GainAbilityAttachedEffect(new ForestwalkAbility(), AttachmentType.AURA))); } public DryadsFavor(final DryadsFavor card) { @@ -77,50 +75,3 @@ public class DryadsFavor extends CardImpl { return new DryadsFavor(this); } } - -class DryadsFavorEffect extends ContinuousEffectImpl { - - public DryadsFavorEffect() { - super(Duration.WhileOnBattlefield, Outcome.Detriment); - staticText = "Enchanted creature has forestwalk"; - } - - public DryadsFavorEffect(final DryadsFavorEffect effect) { - super(effect); - } - - @Override - public DryadsFavorEffect copy() { - return new DryadsFavorEffect(this); - } - - @Override - public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - switch (layer) { - case AbilityAddingRemovingEffects_6: - if (sublayer == SubLayer.NA) { - creature.addAbility(new ForestwalkAbility(), source.getSourceId(), game); - } - break; - } - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean hasLayer(Layer layer) { - return layer == Layer.AbilityAddingRemovingEffects_6; - } - -} diff --git a/Mage.Sets/src/mage/cards/f/FishliverOil.java b/Mage.Sets/src/mage/cards/f/FishliverOil.java index e7c9d625fbf..7733efa521c 100644 --- a/Mage.Sets/src/mage/cards/f/FishliverOil.java +++ b/Mage.Sets/src/mage/cards/f/FishliverOil.java @@ -38,7 +38,6 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.AttachmentType; import mage.constants.CardType; -import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; import mage.target.TargetPermanent; @@ -62,7 +61,7 @@ public class FishliverOil extends CardImpl { // Enchanted creature has islandwalk. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, - new GainAbilityAttachedEffect(new IslandwalkAbility(), AttachmentType.AURA, Duration.WhileOnBattlefield))); + new GainAbilityAttachedEffect(new IslandwalkAbility(), AttachmentType.AURA))); } public FishliverOil(final FishliverOil card) { diff --git a/Mage.Sets/src/mage/cards/g/GoblinWarPaint.java b/Mage.Sets/src/mage/cards/g/GoblinWarPaint.java index 37fadc71cdc..8ea6a0d0848 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinWarPaint.java +++ b/Mage.Sets/src/mage/cards/g/GoblinWarPaint.java @@ -29,22 +29,20 @@ package mage.cards.g; import java.util.UUID; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.continuous.BoostEnchantedEffect; +import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; +import mage.constants.AttachmentType; import mage.constants.CardType; -import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.common.AttachEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.HasteAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.Layer; -import mage.constants.SubLayer; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -59,12 +57,19 @@ public class GoblinWarPaint extends CardImpl { this.subtype.add("Aura"); + // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); this.addAbility(ability); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GoblinWarPaintEffect())); + + // Enchanted creature gets +2/+2 and has haste. + Effect effect = new GainAbilityAttachedEffect(HasteAbility.getInstance(), AttachmentType.AURA); + effect.setText("and has haste"); + ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, 2)); + ability.addEffect(effect); + this.addAbility(ability); } public GoblinWarPaint(final GoblinWarPaint card) { @@ -76,56 +81,3 @@ public class GoblinWarPaint extends CardImpl { return new GoblinWarPaint(this); } } - -class GoblinWarPaintEffect extends ContinuousEffectImpl { - - public GoblinWarPaintEffect() { - super(Duration.WhileOnBattlefield, Outcome.Benefit); - staticText = "Enchanted creature gets +2/+2 and has haste"; - } - - public GoblinWarPaintEffect(final GoblinWarPaintEffect effect) { - super(effect); - } - - @Override - public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - switch (layer) { - case PTChangingEffects_7: - if (sublayer == SubLayer.ModifyPT_7c) { - creature.addPower(2); - creature.addToughness(2); - } - break; - case AbilityAddingRemovingEffects_6: - if (sublayer == SubLayer.NA) { - creature.addAbility(HasteAbility.getInstance(), game); - } - break; - } - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean hasLayer(Layer layer) { - return layer == Layer.AbilityAddingRemovingEffects_6 || layer == layer.PTChangingEffects_7; - } - - @Override - public GoblinWarPaintEffect copy() { - return new GoblinWarPaintEffect(this); - } - -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java b/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java index a3cdade254f..d0172a61ed6 100644 --- a/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java +++ b/Mage.Sets/src/mage/cards/i/ImprisonedInTheMoon.java @@ -39,9 +39,6 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Layer; -import static mage.constants.Layer.AbilityAddingRemovingEffects_6; -import static mage.constants.Layer.ColorChangingEffects_5; -import static mage.constants.Layer.TypeChangingEffects_4; import mage.constants.Outcome; import mage.constants.SubLayer; import mage.constants.Zone; diff --git a/Mage.Sets/src/mage/cards/v/VolcanicStrength.java b/Mage.Sets/src/mage/cards/v/VolcanicStrength.java index 0adc5922f40..fe0b988dbbc 100644 --- a/Mage.Sets/src/mage/cards/v/VolcanicStrength.java +++ b/Mage.Sets/src/mage/cards/v/VolcanicStrength.java @@ -30,20 +30,18 @@ package mage.cards.v; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.Effect; import mage.abilities.effects.common.AttachEffect; +import mage.abilities.effects.common.continuous.BoostEnchantedEffect; +import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect; import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.MountainwalkAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; +import mage.constants.AttachmentType; import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Layer; import mage.constants.Outcome; -import mage.constants.SubLayer; import mage.constants.Zone; -import mage.game.Game; -import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; @@ -62,9 +60,14 @@ public class VolcanicStrength extends CardImpl { this.getSpellAbility().addTarget(auraTarget); this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature)); Ability ability = new EnchantAbility(auraTarget.getTargetName()); - // Enchanted creature gets +2/+2 and has mountainwalk. this.addAbility(ability); - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new VolcanicStrengthEffect())); + + // Enchanted creature gets +2/+2 and has mountainwalk. + Effect effect = new GainAbilityAttachedEffect(new MountainwalkAbility(), AttachmentType.AURA); + effect.setText("and has mountainwalk"); + ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(2, 2)); + ability.addEffect(effect); + this.addAbility(ability); } public VolcanicStrength(final VolcanicStrength card) { @@ -76,56 +79,3 @@ public class VolcanicStrength extends CardImpl { return new VolcanicStrength(this); } } - -class VolcanicStrengthEffect extends ContinuousEffectImpl { - - public VolcanicStrengthEffect() { - super(Duration.WhileOnBattlefield, Outcome.BoostCreature); - staticText = "Enchanted creature gets +2/+2 and has mountainwalk"; - } - - public VolcanicStrengthEffect(final VolcanicStrengthEffect effect) { - super(effect); - } - - @Override - public VolcanicStrengthEffect copy() { - return new VolcanicStrengthEffect(this); - } - - @Override - public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent enchantment = game.getPermanent(source.getSourceId()); - if (enchantment != null && enchantment.getAttachedTo() != null) { - Permanent creature = game.getPermanent(enchantment.getAttachedTo()); - if (creature != null) { - switch (layer) { - case PTChangingEffects_7: - if (sublayer == SubLayer.ModifyPT_7c) { - creature.addPower(2); - creature.addToughness(2); - } - break; - case AbilityAddingRemovingEffects_6: - if (sublayer == SubLayer.NA) { - creature.addAbility(new MountainwalkAbility(), game); - } - break; - } - return true; - } - } - return false; - } - - @Override - public boolean apply(Game game, Ability source) { - return false; - } - - @Override - public boolean hasLayer(Layer layer) { - return layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.PTChangingEffects_7; - } - -}