- Added ForetoldWatcher, ForetoldCondition. Added card from

weirddan455 [KHM] Poison the Cup that uses it.
This commit is contained in:
jeffwadsworth 2021-01-26 10:59:46 -06:00
parent dacf30f4b9
commit 68f2a3d032
5 changed files with 130 additions and 4 deletions

View file

@ -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";
}
}

View file

@ -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);

View file

@ -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<UUID> 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();
}
}