From aa06893f4d2b837accdd4ff82d1b8ab15a350d75 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 13 Jul 2021 08:19:27 -0400 Subject: [PATCH] [AFC] Implemented Diviner's Portent --- .../src/mage/cards/d/DivinersPortent.java | 77 +++++++++++++++++++ .../mage/sets/ForgottenRealmsCommander.java | 1 + .../common/RollDieWithResultTableEffect.java | 22 +++++- 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/d/DivinersPortent.java diff --git a/Mage.Sets/src/mage/cards/d/DivinersPortent.java b/Mage.Sets/src/mage/cards/d/DivinersPortent.java new file mode 100644 index 00000000000..c127f3b36b0 --- /dev/null +++ b/Mage.Sets/src/mage/cards/d/DivinersPortent.java @@ -0,0 +1,77 @@ +package mage.cards.d; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.CardsInControllerHandCount; +import mage.abilities.dynamicvalue.common.ManacostVariableValue; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.abilities.effects.common.RollDieWithResultTableEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class DivinersPortent extends CardImpl { + + public DivinersPortent(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{U}{U}{U}"); + + // Roll a d20 and add the number of cards in your hand. + RollDieWithResultTableEffect effect = new RollDieWithResultTableEffect( + 20, "roll a d20 and add the number " + + "of cards in your hand", CardsInControllerHandCount.instance + ); + this.getSpellAbility().addEffect(effect); + + // 1-14 | Draw X cards. + effect.addTableEntry(1, 14, new DrawCardSourceControllerEffect(ManacostVariableValue.REGULAR)); + + // 15+ | Scry X, then draw X cards. + effect.addTableEntry(15, Integer.MAX_VALUE, new DivinersPortentEffect()); + } + + private DivinersPortent(final DivinersPortent card) { + super(card); + } + + @Override + public DivinersPortent copy() { + return new DivinersPortent(this); + } +} + +class DivinersPortentEffect extends OneShotEffect { + + DivinersPortentEffect() { + super(Outcome.Benefit); + staticText = "scry X, then draw X cards"; + } + + private DivinersPortentEffect(final DivinersPortentEffect effect) { + super(effect); + } + + @Override + public DivinersPortentEffect copy() { + return new DivinersPortentEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + int xValue = source.getManaCostsToPay().getX(); + if (player == null || xValue < 1) { + return false; + } + player.scry(xValue, source, game); + player.drawCards(xValue, source, game); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/ForgottenRealmsCommander.java b/Mage.Sets/src/mage/sets/ForgottenRealmsCommander.java index c33c58eccc4..7d85e57819b 100644 --- a/Mage.Sets/src/mage/sets/ForgottenRealmsCommander.java +++ b/Mage.Sets/src/mage/sets/ForgottenRealmsCommander.java @@ -76,6 +76,7 @@ public final class ForgottenRealmsCommander extends ExpansionSet { cards.add(new SetCardInfo("Dimir Aqueduct", 234, Rarity.UNCOMMON, mage.cards.d.DimirAqueduct.class)); cards.add(new SetCardInfo("Dire Fleet Daredevil", 121, Rarity.RARE, mage.cards.d.DireFleetDaredevil.class)); cards.add(new SetCardInfo("Disrupt Decorum", 122, Rarity.RARE, mage.cards.d.DisruptDecorum.class)); + cards.add(new SetCardInfo("Diviner's Portent", 15, Rarity.RARE, mage.cards.d.DivinersPortent.class)); cards.add(new SetCardInfo("Doomed Necromancer", 98, Rarity.RARE, mage.cards.d.DoomedNecromancer.class)); cards.add(new SetCardInfo("Dragon's Hoard", 204, Rarity.RARE, mage.cards.d.DragonsHoard.class)); cards.add(new SetCardInfo("Dragonlord's Servant", 123, Rarity.UNCOMMON, mage.cards.d.DragonlordsServant.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/RollDieWithResultTableEffect.java b/Mage/src/main/java/mage/abilities/effects/common/RollDieWithResultTableEffect.java index cb566ca6a74..d2137e358c1 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/RollDieWithResultTableEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/RollDieWithResultTableEffect.java @@ -2,6 +2,8 @@ package mage.abilities.effects.common; import mage.abilities.Ability; import mage.abilities.Mode; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; @@ -24,6 +26,7 @@ public class RollDieWithResultTableEffect extends OneShotEffect { protected final int sides; private final String prefixText; private final List resultsTable = new ArrayList<>(); + private final DynamicValue modifier; public RollDieWithResultTableEffect() { this(20); @@ -34,9 +37,14 @@ public class RollDieWithResultTableEffect extends OneShotEffect { } public RollDieWithResultTableEffect(int sides, String prefixText) { + this(sides, prefixText, StaticValue.get(0)); + } + + public RollDieWithResultTableEffect(int sides, String prefixText, DynamicValue modifier) { super(Outcome.Benefit); this.sides = sides; this.prefixText = prefixText; + this.modifier = modifier; } protected RollDieWithResultTableEffect(final RollDieWithResultTableEffect effect) { @@ -46,6 +54,7 @@ public class RollDieWithResultTableEffect extends OneShotEffect { for (TableEntry tableEntry : effect.resultsTable) { this.resultsTable.add(tableEntry.copy()); } + this.modifier = effect.modifier.copy(); } @Override @@ -59,7 +68,7 @@ public class RollDieWithResultTableEffect extends OneShotEffect { if (player == null) { return false; } - int result = player.rollDice(source, game, sides); + int result = player.rollDice(source, game, sides) + modifier.calculate(game, source, this); this.applyResult(result, game, source); return true; } @@ -79,11 +88,16 @@ public class RollDieWithResultTableEffect extends OneShotEffect { sb.append(prefixText).append('.'); for (TableEntry tableEntry : this.resultsTable) { sb.append("
"); - if (tableEntry.min != tableEntry.max) { + if (tableEntry.max == Integer.MAX_VALUE) { sb.append(tableEntry.min); - sb.append('-'); + sb.append('+'); + } else { + if (tableEntry.min != tableEntry.max) { + sb.append(tableEntry.min); + sb.append('-'); + } + sb.append(tableEntry.max); } - sb.append(tableEntry.max); sb.append(" | "); sb.append(CardUtil.getTextWithFirstCharUpperCase(tableEntry.effects.getText(mode))); }