From 767c66251a21392fae35b80f0511b5b0aa8b5553 Mon Sep 17 00:00:00 2001 From: theelk801 Date: Sun, 11 Jun 2023 08:53:45 -0400 Subject: [PATCH] [LTR] Implement Elrond, Master of Healing --- Mage.Sets/src/mage/cards/b/BattleMammoth.java | 4 +- .../mage/cards/e/ElrondMasterOfHealing.java | 80 +++++++++++++++++++ .../src/mage/cards/m/MilaCraftyCompanion.java | 4 +- .../TheLordOfTheRingsTalesOfMiddleEarth.java | 1 + ...mesTargetOpponentAllTriggeredAbility.java} | 26 ++++-- 5 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/e/ElrondMasterOfHealing.java rename Mage/src/main/java/mage/abilities/common/{BecomesTargetControlledPermanentTriggeredAbility.java => BecomesTargetOpponentAllTriggeredAbility.java} (68%) diff --git a/Mage.Sets/src/mage/cards/b/BattleMammoth.java b/Mage.Sets/src/mage/cards/b/BattleMammoth.java index 3255852857a..27095dc028a 100644 --- a/Mage.Sets/src/mage/cards/b/BattleMammoth.java +++ b/Mage.Sets/src/mage/cards/b/BattleMammoth.java @@ -1,7 +1,7 @@ package mage.cards.b; import mage.MageInt; -import mage.abilities.common.BecomesTargetControlledPermanentTriggeredAbility; +import mage.abilities.common.BecomesTargetOpponentAllTriggeredAbility; import mage.abilities.effects.common.DrawCardSourceControllerEffect; import mage.abilities.keyword.ForetellAbility; import mage.abilities.keyword.TrampleAbility; @@ -28,7 +28,7 @@ public final class BattleMammoth extends CardImpl { this.addAbility(TrampleAbility.getInstance()); // Whenever a permanent you control becomes the target of a spell or ability an opponent controls, you may draw a card. - this.addAbility(new BecomesTargetControlledPermanentTriggeredAbility( + this.addAbility(new BecomesTargetOpponentAllTriggeredAbility( new DrawCardSourceControllerEffect(1), true )); diff --git a/Mage.Sets/src/mage/cards/e/ElrondMasterOfHealing.java b/Mage.Sets/src/mage/cards/e/ElrondMasterOfHealing.java new file mode 100644 index 00000000000..8b394ce3735 --- /dev/null +++ b/Mage.Sets/src/mage/cards/e/ElrondMasterOfHealing.java @@ -0,0 +1,80 @@ +package mage.cards.e; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.BecomesTargetOpponentAllTriggeredAbility; +import mage.abilities.common.ScryTriggeredAbility; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.counter.AddCountersTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.counters.CounterType; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.game.Game; +import mage.target.common.TargetCreaturePermanent; +import mage.target.targetadjustment.TargetAdjuster; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ElrondMasterOfHealing extends CardImpl { + + private static final FilterPermanent filter + = new FilterControlledCreaturePermanent("a creature you control with a +1/+1 counter on it"); + + static { + filter.add(CounterType.P1P1.getPredicate()); + } + + public ElrondMasterOfHealing(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{U}"); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.ELF); + this.subtype.add(SubType.NOBLE); + this.power = new MageInt(4); + this.toughness = new MageInt(4); + + // Whenever you scry, put a +1/+1 counter on each of up to X target creatures, where X is the number of cards looked at while scrying this way. + this.addAbility(new ScryTriggeredAbility(new AddCountersTargetEffect(CounterType.P1P1.createInstance()) + .setText("put a +1/+1 counter on each of up to X target creatures, " + + "where X is the number of cards looked at while scrying this way")) + .setTargetAdjuster(ElrondMasterOfHealingAdjuster.instance)); + + // Whenever a creature you control with a +1/+1 counter on it becomes the target of a spell or ability an opponent controls, you may draw a card. + this.addAbility(new BecomesTargetOpponentAllTriggeredAbility( + new DrawCardSourceControllerEffect(1), filter, true + )); + } + + private ElrondMasterOfHealing(final ElrondMasterOfHealing card) { + super(card); + } + + @Override + public ElrondMasterOfHealing copy() { + return new ElrondMasterOfHealing(this); + } +} + +enum ElrondMasterOfHealingAdjuster implements TargetAdjuster { + instance; + + @Override + public void adjustTargets(Ability ability, Game game) { + int amount = ability + .getEffects() + .stream() + .mapToInt(effect -> (Integer) effect.getValue("amount")) + .findFirst() + .orElse(0); + ability.getTargets().clear(); + ability.addTarget(new TargetCreaturePermanent(0, amount)); + } +} diff --git a/Mage.Sets/src/mage/cards/m/MilaCraftyCompanion.java b/Mage.Sets/src/mage/cards/m/MilaCraftyCompanion.java index b09aacac911..d61185b90c8 100644 --- a/Mage.Sets/src/mage/cards/m/MilaCraftyCompanion.java +++ b/Mage.Sets/src/mage/cards/m/MilaCraftyCompanion.java @@ -3,7 +3,7 @@ package mage.cards.m; import mage.abilities.Ability; import mage.abilities.LoyaltyAbility; import mage.abilities.TriggeredAbilityImpl; -import mage.abilities.common.BecomesTargetControlledPermanentTriggeredAbility; +import mage.abilities.common.BecomesTargetOpponentAllTriggeredAbility; import mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; @@ -54,7 +54,7 @@ public final class MilaCraftyCompanion extends ModalDoubleFacedCard { this.getLeftHalfCard().addAbility(new MilaCraftyCompanionTriggeredAbility()); // Whenever a permanent you control becomes the target of a spell or ability and opponent controls, you may draw a card. - this.getLeftHalfCard().addAbility(new BecomesTargetControlledPermanentTriggeredAbility( + this.getLeftHalfCard().addAbility(new BecomesTargetOpponentAllTriggeredAbility( new DrawCardSourceControllerEffect(1), true )); diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index bca94b6eec3..1294433b141 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -54,6 +54,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Easterling Vanguard", 83, Rarity.COMMON, mage.cards.e.EasterlingVanguard.class)); cards.add(new SetCardInfo("Eastfarthing Farmer", 8, Rarity.COMMON, mage.cards.e.EastfarthingFarmer.class)); cards.add(new SetCardInfo("Elrond, Lord of Rivendell", 49, Rarity.UNCOMMON, mage.cards.e.ElrondLordOfRivendell.class)); + cards.add(new SetCardInfo("Elrond, Master of Healing", 200, Rarity.RARE, mage.cards.e.ElrondMasterOfHealing.class)); cards.add(new SetCardInfo("Elven Chorus", 160, Rarity.RARE, mage.cards.e.ElvenChorus.class)); cards.add(new SetCardInfo("Elven Farsight", 161, Rarity.COMMON, mage.cards.e.ElvenFarsight.class)); cards.add(new SetCardInfo("Elvish Mariner", 283, Rarity.RARE, mage.cards.e.ElvishMariner.class)); diff --git a/Mage/src/main/java/mage/abilities/common/BecomesTargetControlledPermanentTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/BecomesTargetOpponentAllTriggeredAbility.java similarity index 68% rename from Mage/src/main/java/mage/abilities/common/BecomesTargetControlledPermanentTriggeredAbility.java rename to Mage/src/main/java/mage/abilities/common/BecomesTargetOpponentAllTriggeredAbility.java index 980dadc3b09..598ee6ad0a3 100644 --- a/Mage/src/main/java/mage/abilities/common/BecomesTargetControlledPermanentTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/BecomesTargetOpponentAllTriggeredAbility.java @@ -3,6 +3,8 @@ package mage.abilities.common; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; import mage.constants.Zone; +import mage.filter.FilterPermanent; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; @@ -14,20 +16,28 @@ import java.util.*; /** * @author weirddan455 */ -public class BecomesTargetControlledPermanentTriggeredAbility extends TriggeredAbilityImpl { +public class BecomesTargetOpponentAllTriggeredAbility extends TriggeredAbilityImpl { - public BecomesTargetControlledPermanentTriggeredAbility(Effect effect, boolean optional) { - super(Zone.BATTLEFIELD, effect, optional); - setTriggerPhrase("Whenever a permanent you control becomes the target of a spell or ability an opponent controls, "); + private final FilterPermanent filter; + + public BecomesTargetOpponentAllTriggeredAbility(Effect effect, boolean optional) { + this(effect, StaticFilters.FILTER_CONTROLLED_A_PERMANENT, optional); } - private BecomesTargetControlledPermanentTriggeredAbility(final BecomesTargetControlledPermanentTriggeredAbility ability) { + public BecomesTargetOpponentAllTriggeredAbility(Effect effect, FilterPermanent filter, boolean optional) { + super(Zone.BATTLEFIELD, effect, optional); + this.filter = filter; + setTriggerPhrase("Whenever " + filter + " becomes the target of a spell or ability an opponent controls, "); + } + + private BecomesTargetOpponentAllTriggeredAbility(final BecomesTargetOpponentAllTriggeredAbility ability) { super(ability); + this.filter = ability.filter; } @Override - public BecomesTargetControlledPermanentTriggeredAbility copy() { - return new BecomesTargetControlledPermanentTriggeredAbility(this); + public BecomesTargetOpponentAllTriggeredAbility copy() { + return new BecomesTargetOpponentAllTriggeredAbility(this); } @Override @@ -46,7 +56,7 @@ public class BecomesTargetControlledPermanentTriggeredAbility extends TriggeredA return false; } Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId()); - if (permanent == null || !permanent.isControlledBy(this.getControllerId())) { + if (permanent == null || !filter.match(permanent, getControllerId(), this, game)) { return false; } // If a spell or ability an opponent controls targets a single permanent you control more than once,