From 68f2a3d032c4bbfd2c7833e63f022de145933a27 Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Tue, 26 Jan 2021 10:59:46 -0600 Subject: [PATCH] - Added ForetoldWatcher, ForetoldCondition. Added card from weirddan455 [KHM] Poison the Cup that uses it. --- Mage.Sets/src/mage/cards/p/PoisonTheCup.java | 41 ++++++++++++++ Mage.Sets/src/mage/sets/Kaldheim.java | 2 + .../condition/common/ForetoldCondition.java | 29 ++++++++++ .../abilities/keyword/ForetellAbility.java | 6 +- .../mage/watchers/common/ForetoldWatcher.java | 56 +++++++++++++++++++ 5 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/p/PoisonTheCup.java create mode 100644 Mage/src/main/java/mage/abilities/condition/common/ForetoldCondition.java create mode 100644 Mage/src/main/java/mage/watchers/common/ForetoldWatcher.java diff --git a/Mage.Sets/src/mage/cards/p/PoisonTheCup.java b/Mage.Sets/src/mage/cards/p/PoisonTheCup.java new file mode 100644 index 0000000000..7af17d9685 --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PoisonTheCup.java @@ -0,0 +1,41 @@ +package mage.cards.p; + +import java.util.UUID; + +import mage.abilities.condition.common.ForetoldCondition; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.effects.common.DestroyTargetEffect; +import mage.abilities.effects.keyword.ScryEffect; +import mage.abilities.keyword.ForetellAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author weirddan455 + */ +public final class PoisonTheCup extends CardImpl { + + public PoisonTheCup(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{B}{B}"); + + // Destroy target creature. If this spell was foretold, scry 2. + this.getSpellAbility().addEffect(new DestroyTargetEffect()); + this.getSpellAbility().addEffect(new ConditionalOneShotEffect(new ScryEffect(2), ForetoldCondition.instance)); + this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + + // Foretell {1}{B} + this.addAbility(new ForetellAbility(this, "{1}{B}")); + } + + private PoisonTheCup(final PoisonTheCup card) { + super(card); + } + + @Override + public PoisonTheCup copy() { + return new PoisonTheCup(this); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/Kaldheim.java b/Mage.Sets/src/mage/sets/Kaldheim.java index 7a888dcb88..f7798102b4 100644 --- a/Mage.Sets/src/mage/sets/Kaldheim.java +++ b/Mage.Sets/src/mage/sets/Kaldheim.java @@ -83,6 +83,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Cleaving Reaper", 376, Rarity.RARE, mage.cards.c.CleavingReaper.class)); cards.add(new SetCardInfo("Codespell Cleric", 7, Rarity.COMMON, mage.cards.c.CodespellCleric.class)); cards.add(new SetCardInfo("Colossal Plow", 236, Rarity.UNCOMMON, mage.cards.c.ColossalPlow.class)); + cards.add(new SetCardInfo("Cosima, God of the Voyage", 50, Rarity.MYTHIC, mage.cards.c.CosimaGodOfTheVoyage.class)); cards.add(new SetCardInfo("Cosmos Elixir", 237, Rarity.RARE, mage.cards.c.CosmosElixir.class)); cards.add(new SetCardInfo("Craven Hulk", 127, Rarity.COMMON, mage.cards.c.CravenHulk.class)); cards.add(new SetCardInfo("Crippling Fear", 82, Rarity.RARE, mage.cards.c.CripplingFear.class)); @@ -212,6 +213,7 @@ public final class Kaldheim extends ExpansionSet { cards.add(new SetCardInfo("Path to the World Tree", 186, Rarity.UNCOMMON, mage.cards.p.PathToTheWorldTree.class)); cards.add(new SetCardInfo("Pilfering Hawk", 71, Rarity.COMMON, mage.cards.p.PilferingHawk.class)); cards.add(new SetCardInfo("Plains", 394, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Poison the Cup", 103, Rarity.UNCOMMON, mage.cards.p.PoisonTheCup.class)); cards.add(new SetCardInfo("Port of Karfell", 265, Rarity.UNCOMMON, mage.cards.p.PortOfKarfell.class)); cards.add(new SetCardInfo("Priest of the Haunted Edge", 104, Rarity.COMMON, mage.cards.p.PriestOfTheHauntedEdge.class)); cards.add(new SetCardInfo("Provoke the Trolls", 144, Rarity.UNCOMMON, mage.cards.p.ProvokeTheTrolls.class)); diff --git a/Mage/src/main/java/mage/abilities/condition/common/ForetoldCondition.java b/Mage/src/main/java/mage/abilities/condition/common/ForetoldCondition.java new file mode 100644 index 0000000000..cdbaad4cdc --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/ForetoldCondition.java @@ -0,0 +1,29 @@ +package mage.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.watchers.common.ForetoldWatcher; + +/** + * + * @author jeffwadsworth + */ +public enum ForetoldCondition implements Condition { + + instance; + + @Override + public boolean apply(Game game, Ability source) { + ForetoldWatcher watcher = game.getState().getWatcher(ForetoldWatcher.class); + if (watcher != null) { + return watcher.foretoldSpellWasCast(source.getSourceId()); + } + return false; + } + + @Override + public String toString() { + return "this card was foretold"; + } +} \ No newline at end of file diff --git a/Mage/src/main/java/mage/abilities/keyword/ForetellAbility.java b/Mage/src/main/java/mage/abilities/keyword/ForetellAbility.java index 810dab8c6b..30bcd274e3 100644 --- a/Mage/src/main/java/mage/abilities/keyword/ForetellAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/ForetellAbility.java @@ -28,6 +28,7 @@ import mage.game.Game; import mage.players.Player; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; +import mage.watchers.common.ForetoldWatcher; /** * @author jeffwadsworth @@ -50,6 +51,7 @@ public class ForetellAbility extends SpecialAction { // look at face-down card anytime addSubAbility(new SimpleStaticAbility(Zone.ALL, new ForetellLookAtCardEffect())); this.setRuleVisible(false); + this.addWatcher(new ForetoldWatcher()); } private ForetellAbility(ForetellAbility ability) { @@ -196,10 +198,6 @@ class ForetellCostAbility extends SpellAbility { && exileZone.isEmpty()) { return ActivationStatus.getFalse(); } - // Cards with no Mana Costs cant't be flashbacked (e.g. Ancestral Vision) - if (card.getManaCost().isEmpty()) { - return ActivationStatus.getFalse(); - } if (card instanceof SplitCard) { if (((SplitCard) card).getLeftHalfCard().getName().equals(abilityName)) { return ((SplitCard) card).getLeftHalfCard().getSpellAbility().canActivate(playerId, game); diff --git a/Mage/src/main/java/mage/watchers/common/ForetoldWatcher.java b/Mage/src/main/java/mage/watchers/common/ForetoldWatcher.java new file mode 100644 index 0000000000..5108b37c40 --- /dev/null +++ b/Mage/src/main/java/mage/watchers/common/ForetoldWatcher.java @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.watchers.common; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.constants.WatcherScope; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.stack.Spell; +import mage.util.CardUtil; +import mage.watchers.Watcher; + +/** + * + * @author jeffwadsworth + */ +public class ForetoldWatcher extends Watcher { + + // If a card was Foretold during a turn, this list stores it. Cleared at the end of the turn. + + private final Set foretoldCardsThisTurn = new HashSet<>(); + + public ForetoldWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.SPELL_CAST + && event.getZone() == Zone.EXILED) { + Spell spell = (Spell) game.getObject(event.getTargetId()); + if (spell != null) { + UUID exileId = CardUtil.getExileZoneId(spell.getSourceId().toString() + "foretellAbility", game); + if (exileId != null) { + foretoldCardsThisTurn.add(spell.getSourceId()); + } + } + } + } + + public boolean foretoldSpellWasCast(UUID sourceId) { + return foretoldCardsThisTurn.contains(sourceId); + } + + @Override + public void reset() { + super.reset(); + foretoldCardsThisTurn.clear(); + } +}