- Fixed #8334. Refactored and simplified some aspects of the Foretell ability.

This commit is contained in:
Jeff Wadsworth 2021-09-28 16:49:43 -05:00
parent b37dd094e1
commit 6f76c3371e
4 changed files with 14 additions and 23 deletions

View file

@ -177,6 +177,7 @@ class EtherealValkyrieEffect extends OneShotEffect {
foretellAbility.activate(game, true);
ContinuousEffect effect = foretellAbility.new ForetellAddCostEffect(new MageObjectReference(exileCard, game));
game.addEffect(effect, source);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.FORETOLD, exileCard.getId(), null, null));
return true;
}
}

View file

@ -119,7 +119,10 @@ public class ForetellAbility extends SpecialAction {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null
&& card != null) {
// get main card id
UUID mainCardId = card.getMainCard().getId();
// retrieve the exileId of the foretold card
UUID exileId = CardUtil.getExileZoneId(mainCardId.toString() + "foretellAbility", game);

View file

@ -464,6 +464,7 @@ public class GameEvent implements Serializable {
VENTURE, VENTURED,
DUNGEON_COMPLETED,
REMOVED_FROM_COMBAT, // targetId id of permanent removed from combat
FORETOLD, // targetId id of card foretold
//custom events
CUSTOM_EVENT
}

View file

@ -6,11 +6,8 @@ import java.util.UUID;
import mage.abilities.keyword.ForetellAbility;
import mage.cards.Card;
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;
/**
@ -21,7 +18,7 @@ public class ForetoldWatcher extends Watcher {
// If foretell was activated or a card was Foretold by the controller this turn, this list stores it. Cleared at the end of the turn.
private final Set<UUID> foretellCardsThisTurn = new HashSet<>();
private final Set<UUID> foretoldCardsThisTurn = new HashSet<>();
private final Set<UUID> foretoldCards = new HashSet<>();
public ForetoldWatcher() {
super(WatcherScope.GAME);
@ -35,41 +32,30 @@ public class ForetoldWatcher extends Watcher {
&& card.getAbilities(game).containsClass(ForetellAbility.class)
&& controllerId == event.getPlayerId()) {
foretellCardsThisTurn.add(card.getId());
foretoldCards.add(card.getId());
}
}
if (event.getType() == GameEvent.EventType.SPELL_CAST
&& event.getZone() == Zone.EXILED) {
Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null
&& controllerId == event.getPlayerId()) {
UUID exileId = CardUtil.getExileZoneId(spell.getSourceId().toString() + "foretellAbility", game);
if (exileId != null) {
foretoldCardsThisTurn.add(spell.getSourceId());
}
// Ethereal Valkyrie
if (event.getType() == GameEvent.EventType.FORETOLD) {
Card card = game.getCard(event.getTargetId());
if (card != null) {
// Ethereal Valkyrie does not Foretell the card, it becomes Foretold, so don't add it to the Foretell list
foretoldCards.add(card.getId());
}
}
}
public boolean cardUsedForetell(UUID sourceId) {
return foretellCardsThisTurn.contains(sourceId);
}
public boolean cardWasForetold(UUID sourceId) {
return foretoldCardsThisTurn.contains(sourceId);
return foretoldCards.contains(sourceId);
}
public int countNumberForetellThisTurn() {
return foretellCardsThisTurn.size();
}
public int countNumberForetoldThisTurn() {
return foretoldCardsThisTurn.size();
}
@Override
public void reset() {
super.reset();
foretellCardsThisTurn.clear();
foretoldCardsThisTurn.clear();
}
}