diff --git a/Mage.Sets/src/mage/cards/j/JoltedAwake.java b/Mage.Sets/src/mage/cards/j/JoltedAwake.java new file mode 100644 index 00000000000..453dce29dbd --- /dev/null +++ b/Mage.Sets/src/mage/cards/j/JoltedAwake.java @@ -0,0 +1,51 @@ +package mage.cards.j; + +import mage.abilities.costs.common.PayEnergyCost; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.dynamicvalue.common.TargetManaValue; +import mage.abilities.effects.common.DoIfCostPaid; +import mage.abilities.effects.common.InfoEffect; +import mage.abilities.effects.common.ReturnFromGraveyardToBattlefieldTargetEffect; +import mage.abilities.effects.common.counter.GetEnergyCountersControllerEffect; +import mage.abilities.keyword.CyclingAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.filter.StaticFilters; +import mage.target.common.TargetCardInYourGraveyard; + +import java.util.UUID; + +/** + * @author Susucr + */ +public final class JoltedAwake extends CardImpl { + + public JoltedAwake(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{W}"); + + // Choose up to one target artifact or creature card in your graveyard. You get {E}{E}. Then you may pay an amount of {E} equal to that card's mana value. If you do, return it from your graveyard to the battlefield. + this.getSpellAbility().addTarget(new TargetCardInYourGraveyard(0, 1, StaticFilters.FILTER_CARD_ARTIFACT_OR_CREATURE)); + this.getSpellAbility().addEffect(new InfoEffect("Choose up to one target artifact or creature card in your graveyard.")); + this.getSpellAbility().addEffect(new GetEnergyCountersControllerEffect(2)); + this.getSpellAbility().addEffect(new DoIfCostPaid( + new ReturnFromGraveyardToBattlefieldTargetEffect() + .setText("return it from your graveyard to the battlefield"), + new PayEnergyCost(TargetManaValue.instance, "pay an amount of {E} equal to that card's mana value"), + "pay an amount of {E} equal to that card's mana value?", + true + ).concatBy("Then")); + + // Cycling {2} + this.addAbility(new CyclingAbility(new ManaCostsImpl<>("{2}"))); + } + + private JoltedAwake(final JoltedAwake card) { + super(card); + } + + @Override + public JoltedAwake copy() { + return new JoltedAwake(this); + } +} diff --git a/Mage.Sets/src/mage/sets/ModernHorizons3.java b/Mage.Sets/src/mage/sets/ModernHorizons3.java index 474fbb3f305..041bad6958a 100644 --- a/Mage.Sets/src/mage/sets/ModernHorizons3.java +++ b/Mage.Sets/src/mage/sets/ModernHorizons3.java @@ -142,6 +142,7 @@ public final class ModernHorizons3 extends ExpansionSet { cards.add(new SetCardInfo("It That Heralds the End", 9, Rarity.UNCOMMON, mage.cards.i.ItThatHeraldsTheEnd.class)); cards.add(new SetCardInfo("Izzet Generatorium", 191, Rarity.UNCOMMON, mage.cards.i.IzzetGeneratorium.class)); cards.add(new SetCardInfo("Jet Medallion", 292, Rarity.RARE, mage.cards.j.JetMedallion.class)); + cards.add(new SetCardInfo("Jolted Awake", 33, Rarity.COMMON, mage.cards.j.JoltedAwake.class)); cards.add(new SetCardInfo("Junk Diver", 293, Rarity.UNCOMMON, mage.cards.j.JunkDiver.class)); cards.add(new SetCardInfo("K'rrik, Son of Yawgmoth", 274, Rarity.RARE, mage.cards.k.KrrikSonOfYawgmoth.class)); cards.add(new SetCardInfo("Kaalia of the Vast", 290, Rarity.MYTHIC, mage.cards.k.KaaliaOfTheVast.class)); diff --git a/Mage/src/main/java/mage/abilities/costs/common/PayEnergyCost.java b/Mage/src/main/java/mage/abilities/costs/common/PayEnergyCost.java index 90d5101f9cd..4cb39780f60 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/PayEnergyCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/PayEnergyCost.java @@ -4,6 +4,8 @@ package mage.abilities.costs.common; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.counters.CounterType; import mage.game.Game; import mage.players.Player; @@ -11,18 +13,20 @@ import mage.util.CardUtil; import java.util.UUID; -import java.util.UUID; - /** * @author emerald000 */ public class PayEnergyCost extends CostImpl { - private final int amount; + private final DynamicValue amount; public PayEnergyCost(int amount) { + this(StaticValue.get(amount), makeText(amount)); + } + + public PayEnergyCost(DynamicValue amount, String text) { this.amount = amount; - this.text = makeText(amount); + this.text = text; } public PayEnergyCost(PayEnergyCost cost) { @@ -33,14 +37,16 @@ public class PayEnergyCost extends CostImpl { @Override public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { Player player = game.getPlayer(controllerId); - return player != null && player.getCountersCount(CounterType.ENERGY) >= amount; + int energyToPayAmount = amount.calculate(game, ability, null); + return player != null && player.getCountersCount(CounterType.ENERGY) >= energyToPayAmount; } @Override public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { Player player = game.getPlayer(controllerId); - if (player != null && player.getCountersCount(CounterType.ENERGY) >= amount) { - player.loseCounters(CounterType.ENERGY.getName(), amount, source, game); + int energyToPayAmount = amount.calculate(game, ability, null); + if (player != null && player.getCountersCount(CounterType.ENERGY) >= energyToPayAmount) { + player.loseCounters(CounterType.ENERGY.getName(), energyToPayAmount, source, game); paid = true; } return paid; diff --git a/Mage/src/main/java/mage/abilities/costs/common/PayLifeCost.java b/Mage/src/main/java/mage/abilities/costs/common/PayLifeCost.java index a0ea7366138..65ef04d0d86 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/PayLifeCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/PayLifeCost.java @@ -35,16 +35,20 @@ public class PayLifeCost extends CostImpl { @Override public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { + Player player = game.getPlayer(controllerId); + if (player == null) { + return false; + } //118.4. If a cost or effect allows a player to pay an amount of life greater than 0, //the player may do so only if their life total is greater than or equal to the //amount of the payment. If a player pays life, the payment is subtracted from their //life total; in other words, the player loses that much life. (Players can always pay 0 life.) int lifeToPayAmount = amount.calculate(game, ability, null); // Paying 0 life is not considered paying any life. - if (lifeToPayAmount > 0 && !game.getPlayer(controllerId).canPayLifeCost(ability)) { + if (lifeToPayAmount > 0 && !player.canPayLifeCost(ability)) { return false; } - return game.getPlayer(controllerId).getLife() >= lifeToPayAmount || lifeToPayAmount == 0; + return player.getLife() >= lifeToPayAmount || lifeToPayAmount == 0; } @Override