From 294ccedc4501d1e5846cb5810b9376d178dbc62b Mon Sep 17 00:00:00 2001 From: theelk801 Date: Sat, 3 Jun 2023 10:06:39 -0400 Subject: [PATCH] [LTR] Implement Last March of the Ents --- .../src/mage/cards/l/LastMarchOfTheEnts.java | 77 +++++++++++++++++++ .../TheLordOfTheRingsTalesOfMiddleEarth.java | 1 + ...oughnessAmongControlledCreaturesValue.java | 21 +++-- 3 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/l/LastMarchOfTheEnts.java diff --git a/Mage.Sets/src/mage/cards/l/LastMarchOfTheEnts.java b/Mage.Sets/src/mage/cards/l/LastMarchOfTheEnts.java new file mode 100644 index 0000000000..667fc2454a --- /dev/null +++ b/Mage.Sets/src/mage/cards/l/LastMarchOfTheEnts.java @@ -0,0 +1,77 @@ +package mage.cards.l; + +import mage.abilities.Ability; +import mage.abilities.common.CantBeCounteredSourceAbility; +import mage.abilities.dynamicvalue.common.GreatestToughnessAmongControlledCreaturesValue; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; +import mage.target.common.TargetCardInHand; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class LastMarchOfTheEnts extends CardImpl { + + public LastMarchOfTheEnts(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{6}{G}{G}"); + + // This spell can't be countered. + this.addAbility(new CantBeCounteredSourceAbility()); + + // Draw cards equal to the greatest toughness among creatures you control, then put any number of creature cards from your hand onto the battlefield. + this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect( + GreatestToughnessAmongControlledCreaturesValue.instance + ).setText("draw cards equal to the greatest toughness among creatures you control")); + this.getSpellAbility().addEffect(new LastMarchOfTheEntsEffect()); + } + + private LastMarchOfTheEnts(final LastMarchOfTheEnts card) { + super(card); + } + + @Override + public LastMarchOfTheEnts copy() { + return new LastMarchOfTheEnts(this); + } +} + +class LastMarchOfTheEntsEffect extends OneShotEffect { + + LastMarchOfTheEntsEffect() { + super(Outcome.Benefit); + staticText = ", then put any number of creature cards from your hand onto the battlefield"; + } + + private LastMarchOfTheEntsEffect(final LastMarchOfTheEntsEffect effect) { + super(effect); + } + + @Override + public LastMarchOfTheEntsEffect copy() { + return new LastMarchOfTheEntsEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURES); + player.choose(outcome, player.getHand(), target, source, game); + player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java index 574427054e..efaccba0f1 100644 --- a/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java +++ b/Mage.Sets/src/mage/sets/TheLordOfTheRingsTalesOfMiddleEarth.java @@ -60,6 +60,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet { cards.add(new SetCardInfo("Island", 264, Rarity.LAND, mage.cards.basiclands.Island.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Knight of the Keep", 291, Rarity.COMMON, mage.cards.k.KnightOfTheKeep.class)); cards.add(new SetCardInfo("Knights of Dol Amroth", 59, Rarity.COMMON, mage.cards.k.KnightsOfDolAmroth.class)); + cards.add(new SetCardInfo("Last March of the Ents", 172, Rarity.MYTHIC, mage.cards.l.LastMarchOfTheEnts.class)); cards.add(new SetCardInfo("Lobelia Sackville-Baggins", 93, Rarity.RARE, mage.cards.l.LobeliaSackvilleBaggins.class)); cards.add(new SetCardInfo("Long List of the Ents", 174, Rarity.UNCOMMON, mage.cards.l.LongListOfTheEnts.class)); cards.add(new SetCardInfo("Lotho, Corrupt Shirriff", 213, Rarity.RARE, mage.cards.l.LothoCorruptShirriff.class)); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/GreatestToughnessAmongControlledCreaturesValue.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/GreatestToughnessAmongControlledCreaturesValue.java index 6889642901..bd60ddb158 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/GreatestToughnessAmongControlledCreaturesValue.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/GreatestToughnessAmongControlledCreaturesValue.java @@ -1,12 +1,13 @@ package mage.abilities.dynamicvalue.common; +import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.effects.Effect; import mage.filter.StaticFilters; import mage.game.Game; -import mage.game.permanent.Permanent; /** * @author TheElk801 @@ -16,13 +17,17 @@ public enum GreatestToughnessAmongControlledCreaturesValue implements DynamicVal @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - int amount = 0; - for (Permanent p : game.getBattlefield().getActivePermanents( - StaticFilters.FILTER_CONTROLLED_CREATURE, sourceAbility.getControllerId(), game - )) { - amount = Math.max(p.getToughness().getValue(), amount); - } - return amount; + return game + .getBattlefield() + .getActivePermanents( + StaticFilters.FILTER_CONTROLLED_CREATURE, + sourceAbility.getControllerId(), game + ) + .stream() + .map(MageObject::getToughness) + .mapToInt(MageInt::getValue) + .max() + .orElse(0); } @Override