From 1772b560860eb72b6e4550a28a985fcaa8b97ffb Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 6 Nov 2022 17:13:11 -0500 Subject: [PATCH] [BRC] Implement Smelting Vat --- Mage.Sets/src/mage/cards/s/SmeltingVat.java | 143 ++++++++++++++++++ .../mage/sets/TheBrothersWarCommander.java | 1 + 2 files changed, 144 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/s/SmeltingVat.java diff --git a/Mage.Sets/src/mage/cards/s/SmeltingVat.java b/Mage.Sets/src/mage/cards/s/SmeltingVat.java new file mode 100644 index 00000000000..80c333db217 --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/SmeltingVat.java @@ -0,0 +1,143 @@ +package mage.cards.s; + +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.SacrificeTargetCost; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.OneShotEffect; +import mage.cards.*; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.filter.FilterCard; +import mage.filter.common.FilterArtifactCard; +import mage.filter.common.FilterControlledArtifactPermanent; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.AnotherPredicate; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; +import mage.target.common.TargetCardInLibrary; +import mage.util.CardUtil; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class SmeltingVat extends CardImpl { + + private static final FilterControlledPermanent filter + = new FilterControlledArtifactPermanent("another artifact"); + + static { + filter.add(AnotherPredicate.instance); + } + + public SmeltingVat(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); + + // {1}, {T}, Sacrifice another artifact: Reveal the top eight cards of your library. Put up to two noncreature artifact cards with total mana value less than or equal to the sacrificed artifact's mana value from among them onto the battlefield and the rest on the bottom of your library in a random order. + Ability ability = new SimpleActivatedAbility(new SmeltingVatEffect(), new GenericManaCost(1)); + ability.addCost(new TapSourceCost()); + ability.addCost(new SacrificeTargetCost(filter)); + this.addAbility(ability); + } + + private SmeltingVat(final SmeltingVat card) { + super(card); + } + + @Override + public SmeltingVat copy() { + return new SmeltingVat(this); + } +} + +class SmeltingVatEffect extends OneShotEffect { + + SmeltingVatEffect() { + super(Outcome.Benefit); + staticText = "reveal the top eight cards of your library. Put up to two noncreature artifact cards " + + "with total mana value less than or equal to the sacrificed artifact's mana value " + + "from among them onto the battlefield and the rest on the bottom of your library in a random order"; + } + + private SmeltingVatEffect(final SmeltingVatEffect effect) { + super(effect); + } + + @Override + public SmeltingVatEffect copy() { + return new SmeltingVatEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 8)); + player.revealCards(source, cards, game); + TargetCard target = new SmeltingVatTarget(source); + player.choose(outcome, cards, target, game); + player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game); + cards.retainZone(Zone.LIBRARY, game); + player.putCardsOnBottomOfLibrary(cards, game, source, false); + return true; + } +} + +class SmeltingVatTarget extends TargetCardInLibrary { + + private static final FilterCard filter = new FilterArtifactCard("noncreature artifact cards"); + + static { + filter.add(Predicates.not(CardType.CREATURE.getPredicate())); + } + + private final int value; + + SmeltingVatTarget(Ability source) { + super(0, Integer.MAX_VALUE, filter); + this.value = CardUtil + .castStream(source.getCosts().stream(), SacrificeTargetCost.class) + .map(SacrificeTargetCost::getPermanents) + .flatMap(Collection::stream) + .mapToInt(MageObject::getManaValue) + .sum(); + } + + private SmeltingVatTarget(final SmeltingVatTarget target) { + super(target); + this.value = target.value; + } + + @Override + public SmeltingVatTarget copy() { + return new SmeltingVatTarget(this); + } + + @Override + public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) { + if (!super.canTarget(playerId, id, source, game)) { + return false; + } + Card card = game.getCard(id); + return card != null + && card.getManaValue() + + this + .getTargets() + .stream() + .map(game::getCard) + .filter(Objects::nonNull) + .mapToInt(MageObject::getManaValue) + .sum() <= this.value; + } +} diff --git a/Mage.Sets/src/mage/sets/TheBrothersWarCommander.java b/Mage.Sets/src/mage/sets/TheBrothersWarCommander.java index 73bb305f861..bc47220c7f7 100644 --- a/Mage.Sets/src/mage/sets/TheBrothersWarCommander.java +++ b/Mage.Sets/src/mage/sets/TheBrothersWarCommander.java @@ -136,6 +136,7 @@ public final class TheBrothersWarCommander extends ExpansionSet { cards.add(new SetCardInfo("Skullclamp", 159, Rarity.UNCOMMON, mage.cards.s.Skullclamp.class)); cards.add(new SetCardInfo("Skycloud Expanse", 201, Rarity.RARE, mage.cards.s.SkycloudExpanse.class)); cards.add(new SetCardInfo("Slobad, Goblin Tinkerer", 118, Rarity.RARE, mage.cards.s.SlobadGoblinTinkerer.class)); + cards.add(new SetCardInfo("Smelting Vat", 18, Rarity.RARE, mage.cards.s.SmeltingVat.class)); cards.add(new SetCardInfo("Smoldering Marsh", 202, Rarity.RARE, mage.cards.s.SmolderingMarsh.class)); cards.add(new SetCardInfo("Sol Ring", 160, Rarity.UNCOMMON, mage.cards.s.SolRing.class)); cards.add(new SetCardInfo("Solemn Simulacrum", 161, Rarity.RARE, mage.cards.s.SolemnSimulacrum.class));