diff --git a/Mage.Sets/src/mage/cards/m/MantleOfTheAncients.java b/Mage.Sets/src/mage/cards/m/MantleOfTheAncients.java
index d01b21e9f6f..dca9f88ccd6 100644
--- a/Mage.Sets/src/mage/cards/m/MantleOfTheAncients.java
+++ b/Mage.Sets/src/mage/cards/m/MantleOfTheAncients.java
@@ -4,7 +4,7 @@ import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
-import mage.abilities.effects.Effect;
+import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
@@ -15,8 +15,10 @@ import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.FilterCard;
+import mage.filter.FilterPermanent;
import mage.filter.common.FilterPermanentCard;
import mage.filter.predicate.Predicates;
+import mage.filter.predicate.permanent.AttachedToAttachedPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@@ -34,14 +36,22 @@ import java.util.stream.Collectors;
*/
public final class MantleOfTheAncients extends CardImpl {
private static final FilterCard filter = new FilterPermanentCard();
+ private static final FilterPermanent filter2 = new FilterPermanent("Aura and Equipment attached to it");
static {
filter.add(Predicates.or(
SubType.AURA.getPredicate(),
SubType.EQUIPMENT.getPredicate()
));
+ filter2.add(Predicates.or(
+ SubType.AURA.getPredicate(),
+ SubType.EQUIPMENT.getPredicate()
+ ));
+ filter2.add(AttachedToAttachedPredicate.instance);
}
+ private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter2);
+
public MantleOfTheAncients(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{W}");
@@ -59,9 +69,7 @@ public final class MantleOfTheAncients extends CardImpl {
this.addAbility(ability);
// Enchanted creature gets +1/+1 for each Aura and Equipment attached to it.
- this.addAbility(new SimpleStaticAbility(new BoostEnchantedEffect(
- MantleOfTheAncientsValue.instance, MantleOfTheAncientsValue.instance
- )));
+ this.addAbility(new SimpleStaticAbility(new BoostEnchantedEffect(xValue, xValue)));
}
private MantleOfTheAncients(final MantleOfTheAncients card) {
@@ -116,39 +124,3 @@ class MantleOfTheAncientsEffect extends OneShotEffect {
return true;
}
}
-
-enum MantleOfTheAncientsValue implements DynamicValue {
- instance;
-
- @Override
- public int calculate(Game game, Ability sourceAbility, Effect effect) {
- Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game);
- if (sourcePermanent == null) {
- return 0;
- }
- Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
- return permanent == null ? 0 : permanent
- .getAttachments()
- .stream()
- .map(game::getPermanentOrLKIBattlefield)
- .filter(Objects::nonNull)
- .map(p -> p.hasSubtype(SubType.EQUIPMENT, game) || p.hasSubtype(SubType.AURA, game))
- .mapToInt(b -> b ? 1 : 0)
- .sum();
- }
-
- @Override
- public MantleOfTheAncientsValue copy() {
- return instance;
- }
-
- @Override
- public String getMessage() {
- return "Aura and Equipment attached to it";
- }
-
- @Override
- public String toString() {
- return "1";
- }
-}
diff --git a/Mage.Sets/src/mage/cards/t/ThranPowerSuit.java b/Mage.Sets/src/mage/cards/t/ThranPowerSuit.java
index 1522f930017..1abb7c6fbc6 100644
--- a/Mage.Sets/src/mage/cards/t/ThranPowerSuit.java
+++ b/Mage.Sets/src/mage/cards/t/ThranPowerSuit.java
@@ -4,7 +4,7 @@ import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.dynamicvalue.DynamicValue;
-import mage.abilities.effects.Effect;
+import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
import mage.abilities.effects.common.continuous.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility;
@@ -14,10 +14,10 @@ import mage.cards.CardSetInfo;
import mage.constants.AttachmentType;
import mage.constants.CardType;
import mage.constants.SubType;
-import mage.game.Game;
-import mage.game.permanent.Permanent;
+import mage.filter.FilterPermanent;
+import mage.filter.predicate.Predicates;
+import mage.filter.predicate.permanent.AttachedToAttachedPredicate;
-import java.util.Objects;
import java.util.UUID;
/**
@@ -25,15 +25,25 @@ import java.util.UUID;
*/
public final class ThranPowerSuit extends CardImpl {
+ private static final FilterPermanent filter = new FilterPermanent("Aura and Equipment attached to it");
+
+ static {
+ filter.add(Predicates.or(
+ SubType.AURA.getPredicate(),
+ SubType.EQUIPMENT.getPredicate()
+ ));
+ filter.add(AttachedToAttachedPredicate.instance);
+ }
+
+ private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter, 2);
+
public ThranPowerSuit(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}");
this.subtype.add(SubType.EQUIPMENT);
// Equipped creature gets +1/+1 for each Aura and Equipment attached to it and has ward {2}.
- Ability ability = new SimpleStaticAbility(new BoostEquippedEffect(
- ThranPowerSuitValue.instance, ThranPowerSuitValue.instance
- ));
+ Ability ability = new SimpleStaticAbility(new BoostEquippedEffect(xValue, xValue));
ability.addEffect(new GainAbilityAttachedEffect(new WardAbility(
new GenericManaCost(2), false
), AttachmentType.EQUIPMENT).setText("and has ward {2}. (Whenever equipped creature becomes the target of a spell or ability an opponent controls, counter it unless that player pays {2}.)"));
@@ -52,39 +62,3 @@ public final class ThranPowerSuit extends CardImpl {
return new ThranPowerSuit(this);
}
}
-
-enum ThranPowerSuitValue implements DynamicValue {
- instance;
-
- @Override
- public int calculate(Game game, Ability sourceAbility, Effect effect) {
- Permanent sourcePermanent = sourceAbility.getSourcePermanentOrLKI(game);
- if (sourcePermanent == null) {
- return 0;
- }
- Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
- return permanent == null ? 0 : permanent
- .getAttachments()
- .stream()
- .map(game::getPermanentOrLKIBattlefield)
- .filter(Objects::nonNull)
- .map(p -> p.hasSubtype(SubType.EQUIPMENT, game) || p.hasSubtype(SubType.AURA, game))
- .mapToInt(b -> b ? 1 : 0)
- .sum();
- }
-
- @Override
- public ThranPowerSuitValue copy() {
- return instance;
- }
-
- @Override
- public String getMessage() {
- return "Aura and Equipment attached to it";
- }
-
- @Override
- public String toString() {
- return "1";
- }
-}
diff --git a/Mage.Sets/src/mage/cards/w/WithGreatPower.java b/Mage.Sets/src/mage/cards/w/WithGreatPower.java
new file mode 100644
index 00000000000..9af1610bde3
--- /dev/null
+++ b/Mage.Sets/src/mage/cards/w/WithGreatPower.java
@@ -0,0 +1,114 @@
+package mage.cards.w;
+
+import mage.abilities.Ability;
+import mage.abilities.common.SimpleStaticAbility;
+import mage.abilities.dynamicvalue.DynamicValue;
+import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
+import mage.abilities.effects.ReplacementEffectImpl;
+import mage.abilities.effects.common.AttachEffect;
+import mage.abilities.effects.common.continuous.BoostEquippedEffect;
+import mage.abilities.keyword.EnchantAbility;
+import mage.cards.CardImpl;
+import mage.cards.CardSetInfo;
+import mage.constants.CardType;
+import mage.constants.Duration;
+import mage.constants.Outcome;
+import mage.constants.SubType;
+import mage.filter.FilterPermanent;
+import mage.filter.StaticFilters;
+import mage.filter.predicate.Predicates;
+import mage.filter.predicate.permanent.AttachedToAttachedPredicate;
+import mage.game.Game;
+import mage.game.events.DamagePlayerEvent;
+import mage.game.events.GameEvent;
+import mage.game.permanent.Permanent;
+import mage.target.TargetPermanent;
+
+import java.util.Optional;
+import java.util.UUID;
+
+/**
+ * @author TheElk801
+ */
+public final class WithGreatPower extends CardImpl {
+
+ private static final FilterPermanent filter = new FilterPermanent("Aura and Equipment attached to it");
+
+ static {
+ filter.add(Predicates.or(
+ SubType.AURA.getPredicate(),
+ SubType.EQUIPMENT.getPredicate()
+ ));
+ filter.add(AttachedToAttachedPredicate.instance);
+ }
+
+ private static final DynamicValue xValue = new PermanentsOnBattlefieldCount(filter, 2);
+
+ public WithGreatPower(UUID ownerId, CardSetInfo setInfo) {
+ super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}");
+
+ this.subtype.add(SubType.AURA);
+
+ // Enchant creature you control
+ TargetPermanent auraTarget = new TargetPermanent(StaticFilters.FILTER_CONTROLLED_CREATURE);
+ this.getSpellAbility().addTarget(auraTarget);
+ this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
+ this.addAbility(new EnchantAbility(auraTarget));
+
+ // Enchanted creature gets +2/+2 for each Aura and Equipment attached to it.
+ this.addAbility(new SimpleStaticAbility(new BoostEquippedEffect(xValue, xValue)));
+
+ // All damage that would be dealt to you is dealt to enchanted creature instead.
+ this.addAbility(new SimpleStaticAbility(new WithGreatPowerEffect()));
+ }
+
+ private WithGreatPower(final WithGreatPower card) {
+ super(card);
+ }
+
+ @Override
+ public WithGreatPower copy() {
+ return new WithGreatPower(this);
+ }
+}
+
+class WithGreatPowerEffect extends ReplacementEffectImpl {
+ WithGreatPowerEffect() {
+ super(Duration.WhileOnBattlefield, Outcome.RedirectDamage);
+ staticText = "all damage that would be dealt to you is dealt to enchanted creature instead";
+ }
+
+ private WithGreatPowerEffect(final WithGreatPowerEffect effect) {
+ super(effect);
+ }
+
+ @Override
+ public boolean replaceEvent(GameEvent event, Ability source, Game game) {
+ DamagePlayerEvent damageEvent = (DamagePlayerEvent) event;
+ Optional.ofNullable(event)
+ .map(GameEvent::getSourceId)
+ .map(game::getPermanent)
+ .map(Permanent::getAttachedTo)
+ .map(game::getPermanent)
+ .ifPresent(permanent -> permanent.damage(
+ damageEvent.getAmount(), event.getSourceId(), source,
+ game, damageEvent.isCombatDamage(), damageEvent.isPreventable()
+ ));
+ return true;
+ }
+
+ @Override
+ public boolean checksEventType(GameEvent event, Game game) {
+ return event.getType() == GameEvent.EventType.DAMAGE_PLAYER;
+ }
+
+ @Override
+ public boolean applies(GameEvent event, Ability source, Game game) {
+ return source.isControlledBy(event.getPlayerId());
+ }
+
+ @Override
+ public WithGreatPowerEffect copy() {
+ return new WithGreatPowerEffect(this);
+ }
+}
diff --git a/Mage.Sets/src/mage/sets/MarvelsSpiderMan.java b/Mage.Sets/src/mage/sets/MarvelsSpiderMan.java
index 0a40741f654..51a19a58f2c 100644
--- a/Mage.Sets/src/mage/sets/MarvelsSpiderMan.java
+++ b/Mage.Sets/src/mage/sets/MarvelsSpiderMan.java
@@ -134,5 +134,6 @@ public final class MarvelsSpiderMan extends ExpansionSet {
cards.add(new SetCardInfo("Web-Warriors", 203, Rarity.UNCOMMON, mage.cards.w.WebWarriors.class, NON_FULL_USE_VARIOUS));
cards.add(new SetCardInfo("Whoosh!", 48, Rarity.COMMON, mage.cards.w.Whoosh.class));
cards.add(new SetCardInfo("Wild Pack Squad", 23, Rarity.COMMON, mage.cards.w.WildPackSquad.class));
+ cards.add(new SetCardInfo("With Great Power...", 24, Rarity.RARE, mage.cards.w.WithGreatPower.class));
}
}
diff --git a/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToAttachedPredicate.java b/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToAttachedPredicate.java
new file mode 100644
index 00000000000..13ebc21e42d
--- /dev/null
+++ b/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToAttachedPredicate.java
@@ -0,0 +1,30 @@
+package mage.filter.predicate.permanent;
+
+import mage.filter.predicate.ObjectSourcePlayer;
+import mage.filter.predicate.ObjectSourcePlayerPredicate;
+import mage.game.Game;
+import mage.game.permanent.Permanent;
+
+import java.util.Optional;
+
+/**
+ * @author TheElk801
+ */
+public enum AttachedToAttachedPredicate implements ObjectSourcePlayerPredicate {
+ instance;
+
+ @Override
+ public boolean apply(ObjectSourcePlayer input, Game game) {
+ return Optional
+ .ofNullable(input.getSource().getSourcePermanentOrLKI(game))
+ .map(Permanent::getAttachedTo)
+ .filter(input.getObject()::isAttachedTo)
+ .isPresent();
+ }
+
+ @Override
+ public String toString() {
+ return "attached to attached permanent";
+ }
+
+}