diff --git a/Mage.Sets/src/mage/cards/i/InfernalHarvest.java b/Mage.Sets/src/mage/cards/i/InfernalHarvest.java new file mode 100644 index 00000000000..74f128ab3ef --- /dev/null +++ b/Mage.Sets/src/mage/cards/i/InfernalHarvest.java @@ -0,0 +1,127 @@ +package mage.cards.i; + +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.abilities.costs.CostImpl; +import mage.abilities.costs.VariableCostImpl; +import mage.abilities.dynamicvalue.common.GetXValue; +import mage.abilities.effects.common.DamageMultiEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.Zone; +import mage.filter.common.FilterControlledPermanent; +import mage.game.Game; +import mage.players.Player; +import mage.target.Target; +import mage.target.common.TargetControlledPermanent; +import mage.target.common.TargetCreaturePermanentAmount; + +import java.util.Collection; +import java.util.Objects; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public final class InfernalHarvest extends CardImpl { + + public InfernalHarvest(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}"); + + // As an additional cost to cast Infernal Harvest, return X Swamps you control to their owner's hand. + this.getSpellAbility().addCost(new InfernalHarvestVariableCost()); + + // Infernal Harvest deals X damage divided as you choose among any number of target creatures. + this.getSpellAbility().addEffect(new DamageMultiEffect(GetXValue.instance)); + this.getSpellAbility().addTarget(new TargetCreaturePermanentAmount(GetXValue.instance)); + } + + private InfernalHarvest(final InfernalHarvest card) { + super(card); + } + + @Override + public InfernalHarvest copy() { + return new InfernalHarvest(this); + } +} + +class InfernalHarvestVariableCost extends VariableCostImpl { + + private static final FilterControlledPermanent filter = new FilterControlledPermanent(SubType.SWAMP); + + InfernalHarvestVariableCost() { + super("Swamps to return"); + this.text = "return " + xText + " Swamps you control to their owner's hand"; + } + + private InfernalHarvestVariableCost(final InfernalHarvestVariableCost cost) { + super(cost); + } + + @Override + public InfernalHarvestVariableCost copy() { + return new InfernalHarvestVariableCost(this); + } + + @Override + public int getMaxValue(Ability source, Game game) { + return game.getBattlefield().countAll(filter, source.getControllerId(), game); + } + + @Override + public Cost getFixedCostsFromAnnouncedValue(int xValue) { + return new InfernalHarvestCost(xValue); + } + + private static final class InfernalHarvestCost extends CostImpl { + + private final int xValue; + + private InfernalHarvestCost(int xValue) { + super(); + this.xValue = xValue; + this.text = "return " + xValue + " Swamps you control to their owner's hand"; + this.addTarget(new TargetControlledPermanent(xValue, xValue, filter, true)); + } + + private InfernalHarvestCost(final InfernalHarvestCost cost) { + super(cost); + this.xValue = cost.xValue; + } + + @Override + public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) { + return game.getBattlefield().countAll(filter, controllerId, game) >= xValue; + } + + @Override + public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { + if (!this.canPay(ability, sourceId, controllerId, game)) { + return false; + } + Player player = game.getPlayer(controllerId); + if (player == null || !targets.choose(Outcome.ReturnToHand, controllerId, sourceId, game)) { + return false; + } + return paid = player.moveCards( + targets.stream() + .map(Target::getTargets) + .flatMap(Collection::stream) + .map(game::getCard) + .filter(Objects::nonNull) + .collect(Collectors.toSet()), + Zone.HAND, ability, game + ); + } + + @Override + public Cost copy() { + return new InfernalHarvestCost(this); + } + } +} diff --git a/Mage.Sets/src/mage/sets/Visions.java b/Mage.Sets/src/mage/sets/Visions.java index 63ca9aeb987..31852388b5a 100644 --- a/Mage.Sets/src/mage/sets/Visions.java +++ b/Mage.Sets/src/mage/sets/Visions.java @@ -86,6 +86,7 @@ public final class Visions extends ExpansionSet { cards.add(new SetCardInfo("Hulking Cyclops", 84, Rarity.UNCOMMON, mage.cards.h.HulkingCyclops.class)); cards.add(new SetCardInfo("Impulse", 34, Rarity.COMMON, mage.cards.i.Impulse.class)); cards.add(new SetCardInfo("Infantry Veteran", 9, Rarity.COMMON, mage.cards.i.InfantryVeteran.class)); + cards.add(new SetCardInfo("Infernal Harvest", 62, Rarity.COMMON, mage.cards.i.InfernalHarvest.class)); cards.add(new SetCardInfo("Inspiration", 35, Rarity.COMMON, mage.cards.i.Inspiration.class)); cards.add(new SetCardInfo("Iron-Heart Chimera", 146, Rarity.UNCOMMON, mage.cards.i.IronHeartChimera.class)); cards.add(new SetCardInfo("Jamuraan Lion", 10, Rarity.COMMON, mage.cards.j.JamuraanLion.class));