From 5a6ee98b4106aa0dd82ea79ea106a3f908fb2255 Mon Sep 17 00:00:00 2001 From: Susucre <34709007+Susucre@users.noreply.github.com> Date: Thu, 3 Aug 2023 06:25:54 +0200 Subject: [PATCH] [LTC] Implement The Black Gate (#10725) --- Mage.Sets/src/mage/cards/t/TheBlackGate.java | 151 ++++++++++++++++++ .../sets/TalesOfMiddleEarthCommander.java | 1 + .../main/java/mage/filter/FilterPlayer.java | 2 +- .../main/java/mage/target/TargetPlayer.java | 2 +- 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/t/TheBlackGate.java diff --git a/Mage.Sets/src/mage/cards/t/TheBlackGate.java b/Mage.Sets/src/mage/cards/t/TheBlackGate.java new file mode 100644 index 00000000000..fcf794f4072 --- /dev/null +++ b/Mage.Sets/src/mage/cards/t/TheBlackGate.java @@ -0,0 +1,151 @@ +package mage.cards.t; + +import mage.abilities.Ability; +import mage.abilities.ActivatedAbility; +import mage.abilities.common.AsEntersBattlefieldAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.PayLifeCost; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.ContinuousEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.TapSourceUnlessPaysEffect; +import mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect; +import mage.abilities.mana.BlackManaAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPlayer; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.ObjectSourcePlayer; +import mage.filter.predicate.ObjectSourcePlayerPredicate; +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.target.common.TargetCreaturePermanent; +import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class TheBlackGate extends CardImpl { + + public TheBlackGate(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.LAND}, ""); + + this.supertype.add(SuperType.LEGENDARY); + this.subtype.add(SubType.GATE); + + // As The Black Gate enters the battlefield, you may pay 3 life. If you don't, it enters the battlefield tapped. + this.addAbility(new AsEntersBattlefieldAbility( + new TapSourceUnlessPaysEffect(new PayLifeCost(3)), + "you may pay 3 life. If you don't, it enters the battlefield tapped" + )); + + // {T}: Add {B}. + this.addAbility(new BlackManaAbility()); + + // {1}{B}, {T}: Choose a player with the most life or tied for most life. Target creature can't be blocked by creatures that player controls this turn. + ActivatedAbility ability = new SimpleActivatedAbility( + new BlackGateEffect(), + new ManaCostsImpl("{1}{B}") + ); + ability.addCost(new TapSourceCost()); + ability.addTarget(new TargetCreaturePermanent()); + this.addAbility(ability); + } + + private TheBlackGate(final TheBlackGate card) { + super(card); + } + + @Override + public TheBlackGate copy() { + return new TheBlackGate(this); + } +} + +enum BlackGatePredicate implements ObjectSourcePlayerPredicate { + instance; + + @Override + public boolean apply(ObjectSourcePlayer input, Game game) { + Player player = input.getObject(); + UUID playerId = input.getPlayerId(); + if (player == null || playerId == null) { + return false; + } + + int life = player.getLife(); + for (UUID otherPlayerId : game.getState().getPlayersInRange(playerId, game)) { + Player otherPlayer = game.getPlayer(otherPlayerId); + if (otherPlayer == null) { + continue; + } + if (life < otherPlayer.getLife()) { + return false; + } + } + return true; + } +} + +class BlackGateEffect extends OneShotEffect { + + private static final FilterPlayer filter = new FilterPlayer("player with the most life or tied for most life"); + + static { + filter.add(BlackGatePredicate.instance); + } + + BlackGateEffect() { + super(Outcome.Benefit); + staticText = "Choose a player with the most life or tied for most life. " + + "Target creature can't be blocked by creatures that player controls this turn."; + } + + private BlackGateEffect(final BlackGateEffect effect) { + super(effect); + } + + @Override + public BlackGateEffect copy() { + return new BlackGateEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + Permanent creature = game.getPermanent(source.getFirstTarget()); + if (controller == null || creature == null) { + return false; + } + + TargetPlayer target = new TargetPlayer(filter); + target.setNotTarget(true); + if (!controller.choose(Outcome.Detriment, target, source, game)) { + return false; + } + + Player player = game.getPlayer(target.getFirstTarget()); + if (player == null) { + return false; + } + + game.informPlayers(controller.getLogName() + " chose " + player.getLogName() + CardUtil.getSourceLogName(game, source)); + + FilterCreaturePermanent filterCantBlock = new FilterCreaturePermanent("creatures controlled by" + player.getName()); + filterCantBlock.add(new ControllerIdPredicate(player.getId())); + + ContinuousEffect effect = new CantBeBlockedByAllTargetEffect(filterCantBlock, Duration.EndOfTurn); + effect.setTargetPointer(new FixedTarget(creature, game)); + game.addEffect(effect, source); + + return true; + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java b/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java index f4cfa00429d..f012e4ec71b 100644 --- a/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java +++ b/Mage.Sets/src/mage/sets/TalesOfMiddleEarthCommander.java @@ -266,6 +266,7 @@ public final class TalesOfMiddleEarthCommander extends ExpansionSet { cards.add(new SetCardInfo("Taunt from the Rampart", 71, Rarity.RARE, mage.cards.t.TauntFromTheRampart.class)); cards.add(new SetCardInfo("Terramorphic Expanse", 337, Rarity.COMMON, mage.cards.t.TerramorphicExpanse.class)); cards.add(new SetCardInfo("The Balrog of Moria", 46, Rarity.RARE, mage.cards.t.TheBalrogOfMoria.class)); + cards.add(new SetCardInfo("The Black Gate", 80, Rarity.RARE, mage.cards.t.TheBlackGate.class)); cards.add(new SetCardInfo("The Gaffer", 12, Rarity.RARE, mage.cards.t.TheGaffer.class)); cards.add(new SetCardInfo("The Great Henge", 348, Rarity.MYTHIC, mage.cards.t.TheGreatHenge.class)); cards.add(new SetCardInfo("The Ozolith", 351, Rarity.MYTHIC, mage.cards.t.TheOzolith.class)); diff --git a/Mage/src/main/java/mage/filter/FilterPlayer.java b/Mage/src/main/java/mage/filter/FilterPlayer.java index d28e4e08d5d..4fbb9063d5f 100644 --- a/Mage/src/main/java/mage/filter/FilterPlayer.java +++ b/Mage/src/main/java/mage/filter/FilterPlayer.java @@ -26,7 +26,7 @@ public class FilterPlayer extends FilterImpl { super(name); } - public FilterPlayer(final FilterPlayer filter) { + protected FilterPlayer(final FilterPlayer filter) { super(filter); this.extraPredicates.addAll(filter.extraPredicates); } diff --git a/Mage/src/main/java/mage/target/TargetPlayer.java b/Mage/src/main/java/mage/target/TargetPlayer.java index a5f59b11b52..acacb9a75b6 100644 --- a/Mage/src/main/java/mage/target/TargetPlayer.java +++ b/Mage/src/main/java/mage/target/TargetPlayer.java @@ -41,7 +41,7 @@ public class TargetPlayer extends TargetImpl { this.notTarget = notTarget; } - public TargetPlayer(final TargetPlayer target) { + protected TargetPlayer(final TargetPlayer target) { super(target); this.filter = target.filter.copy(); }