diff --git a/Mage.Sets/src/mage/cards/d/DreamLeash.java b/Mage.Sets/src/mage/cards/d/DreamLeash.java
index a68a361904d..f0f15cdb1b7 100644
--- a/Mage.Sets/src/mage/cards/d/DreamLeash.java
+++ b/Mage.Sets/src/mage/cards/d/DreamLeash.java
@@ -3,6 +3,7 @@ package mage.cards.d;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
+import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.ControlEnchantedEffect;
import mage.abilities.keyword.EnchantAbility;
@@ -11,11 +12,8 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
-import mage.constants.Zone;
-import mage.filter.StaticFilters;
-import mage.game.Game;
-import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
+import mage.target.common.TargetTappedPermanentAsYouCast;
import java.util.UUID;
@@ -30,15 +28,18 @@ public final class DreamLeash extends CardImpl {
this.subtype.add(SubType.AURA);
// Enchant permanent
- // You can't choose an untapped permanent as Dream Leash's target as you cast Dream Leash.
- TargetPermanent auraTarget = new DreamLeashTarget();
+ TargetPermanent auraTarget = new TargetTappedPermanentAsYouCast();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.GainControl));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
+ // You can't choose an untapped permanent as Dream Leash's target as you cast Dream Leash.
+ Effect effect = new ControlEnchantedEffect("permanent");
+ effect.setText("You can't choose an untapped permanent as {this}'s target as you cast {this}.
" + effect.getText(null));
+
// You control enchanted permanent.
- this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ControlEnchantedEffect("permanent")));
+ this.addAbility(new SimpleStaticAbility(effect));
}
private DreamLeash(final DreamLeash card) {
@@ -49,35 +50,4 @@ public final class DreamLeash extends CardImpl {
public DreamLeash copy() {
return new DreamLeash(this);
}
-}
-
-
-class DreamLeashTarget extends TargetPermanent {
-
- DreamLeashTarget() {}
-
- private DreamLeashTarget(DreamLeashTarget target) {
- super(target);
- }
-
- @Override
- public DreamLeashTarget copy() {
- return new DreamLeashTarget(this);
- }
-
- @Override
- public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
- if (super.canTarget(controllerId, id, source, game)) {
- Permanent permanent = game.getPermanent(id);
- return permanent.isTapped();
- }
- return false;
- }
-
- // See ruling: https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/253345-dream-leash
- @Override
- public boolean stillLegalTarget(UUID id, Ability source, Game game) {
- Permanent permanent = game.getPermanent(id);
- return permanent != null && StaticFilters.FILTER_PERMANENT.match(permanent, game);
- }
-}
+}
\ No newline at end of file
diff --git a/Mage.Sets/src/mage/cards/e/EnthrallingHold.java b/Mage.Sets/src/mage/cards/e/EnthrallingHold.java
index f1a53c0a3fa..94ff85687b6 100644
--- a/Mage.Sets/src/mage/cards/e/EnthrallingHold.java
+++ b/Mage.Sets/src/mage/cards/e/EnthrallingHold.java
@@ -11,12 +11,9 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
-import mage.constants.Zone;
import mage.filter.StaticFilters;
-import mage.game.Game;
-import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
-import mage.target.common.TargetCreaturePermanent;
+import mage.target.common.TargetTappedPermanentAsYouCast;
import java.util.UUID;
@@ -32,18 +29,18 @@ public final class EnthrallingHold extends CardImpl {
this.subtype.add(SubType.AURA);
// Enchant creature
- TargetPermanent auraTarget = new EnthrallingHoldTarget();
+ TargetPermanent auraTarget = new TargetTappedPermanentAsYouCast(StaticFilters.FILTER_PERMANENT_CREATURE);
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.GainControl));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// You can't choose an untapped creature as this spell's target as you cast it.
- Effect controlEnchantedEffect = new ControlEnchantedEffect();
- controlEnchantedEffect.setText("You can't choose an untapped creature as this spell's target as you cast it.
" + controlEnchantedEffect.getText(null));
+ Effect effect = new ControlEnchantedEffect();
+ effect.setText("You can't choose an untapped creature as this spell's target as you cast it.
" + effect.getText(null));
// You control enchanted creature.
- this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, controlEnchantedEffect));
+ this.addAbility(new SimpleStaticAbility(effect));
}
private EnthrallingHold(final EnthrallingHold card) {
@@ -54,34 +51,4 @@ public final class EnthrallingHold extends CardImpl {
public EnthrallingHold copy() {
return new EnthrallingHold(this);
}
-}
-
-class EnthrallingHoldTarget extends TargetCreaturePermanent {
-
- EnthrallingHoldTarget() {}
-
- private EnthrallingHoldTarget(EnthrallingHoldTarget target) {
- super(target);
- }
-
- @Override
- public EnthrallingHoldTarget copy() {
- return new EnthrallingHoldTarget(this);
- }
-
- @Override
- public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
- if (super.canTarget(controllerId, id, source, game)) {
- Permanent permanent = game.getPermanent(id);
- return permanent.isTapped();
- }
- return false;
- }
-
- // See ruling: https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/253345-dream-leash
- @Override
- public boolean stillLegalTarget(UUID id, Ability source, Game game) {
- Permanent permanent = game.getPermanent(id);
- return permanent != null && StaticFilters.FILTER_PERMANENT_CREATURE.match(permanent, game);
- }
}
\ No newline at end of file
diff --git a/Mage/src/main/java/mage/target/common/TargetTappedPermanentAsYouCast.java b/Mage/src/main/java/mage/target/common/TargetTappedPermanentAsYouCast.java
new file mode 100644
index 00000000000..c64ca6c767e
--- /dev/null
+++ b/Mage/src/main/java/mage/target/common/TargetTappedPermanentAsYouCast.java
@@ -0,0 +1,60 @@
+package mage.target.common;
+
+import mage.abilities.Ability;
+import mage.filter.FilterPermanent;
+import mage.game.Game;
+import mage.game.permanent.Permanent;
+import mage.target.TargetPermanent;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.stream.Collectors;
+
+public class TargetTappedPermanentAsYouCast extends TargetPermanent {
+
+ public TargetTappedPermanentAsYouCast() {}
+
+ public TargetTappedPermanentAsYouCast(FilterPermanent filter) {
+ this.filter = filter;
+ this.targetName = filter.getMessage();
+ }
+
+ private TargetTappedPermanentAsYouCast(TargetTappedPermanentAsYouCast target) {
+ super(target);
+ }
+
+ @Override
+ public TargetTappedPermanentAsYouCast copy() {
+ return new TargetTappedPermanentAsYouCast(this);
+ }
+
+ @Override
+ public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
+ return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
+ .filter(Permanent::isTapped)
+ .map(Permanent::getId)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
+ return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
+ .anyMatch(Permanent::isTapped);
+ }
+
+ @Override
+ public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
+ if (super.canTarget(controllerId, id, source, game)) {
+ Permanent permanent = game.getPermanent(id);
+ return permanent != null && permanent.isTapped();
+ }
+ return false;
+ }
+
+ // See ruling: https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/253345-dream-leash
+ @Override
+ public boolean stillLegalTarget(UUID id, Ability source, Game game) {
+ Permanent permanent = game.getPermanent(id);
+ return permanent != null && getFilter().match(permanent, game);
+ }
+}