- Fixed #5510. Refactored As Foretold.

This commit is contained in:
Jeff 2019-01-18 08:26:20 -06:00
parent f223bdab31
commit 232781cc1f

View file

@ -16,19 +16,13 @@ import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.watchers.Watcher;
/** /**
* *
* @author stravant * @author stravant
* *
* Note, this card is pretty hacky in its implementation due to the fact that
* the alternative cost system doesn't really support "once each turn"
* alternative costs in an obvious way, but it should work in all scenarios as
* far as I can see.
*/ */
public final class AsForetold extends CardImpl { public final class AsForetold extends CardImpl {
@ -43,13 +37,12 @@ public final class AsForetold extends CardImpl {
new StaticValue(1), new StaticValue(1),
true), true),
TargetController.YOU, TargetController.YOU,
/* optional = */ false)); false));
// Once each turn, you may pay {0} rather than pay the mana cost for a spell you cast with converted mana cost X or less, where X is the number of time counters on As Foretold. // Once each turn, you may pay {0} rather than pay the mana cost for a spell you cast with converted mana cost X or less, where X is the number of time counters on As Foretold.
addAbility(new SimpleStaticAbility( addAbility(new SimpleStaticAbility(
Zone.BATTLEFIELD, Zone.BATTLEFIELD,
new AsForetoldAddAltCostEffect()), new AsForetoldAddAltCostEffect()));
new AsForetoldAltCostUsedWatcher());
} }
@ -115,15 +108,13 @@ class AsForetoldAlternativeCost extends AlternativeCostSourceAbility {
Permanent asForetold = game.getPermanent(sourceAsForetold); Permanent asForetold = game.getPermanent(sourceAsForetold);
if (controller != null if (controller != null
&& asForetold != null) { && asForetold != null) {
if (controller.chooseUse(Outcome.Neutral, "Do you wish to use " + asForetold.getLogName() + " to pay the alternative cost ?", ability, game)) { if (controller.chooseUse(Outcome.Neutral, "Do you wish to use "
+ asForetold.getLogName() + " to pay the alternative cost ?", ability, game)) {
wasActivated = super.askToActivateAlternativeCosts(ability, game); wasActivated = super.askToActivateAlternativeCosts(ability, game);
if (wasActivated) { if (wasActivated) {
// Get the watcher game.getState().setValue(asForetold.getId().toString()
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher + asForetold.getZoneChangeCounter(game)
= game.getState().getWatcher(AsForetoldAltCostUsedWatcher.class, sourceAsForetold); + asForetold.getTurnsOnBattlefield(), true);
// Mark as used
asForetoldAltCostUsedWatcher.markUsedThisTurn();
} }
} }
} }
@ -158,17 +149,16 @@ class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
if (controller != null) { if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) { if (sourcePermanent != null) {
// Get the watcher Boolean wasItUsed = (Boolean) game.getState().getValue(
AsForetoldAltCostUsedWatcher asForetoldAltCostUsedWatcher sourcePermanent.getId().toString()
= game.getState().getWatcher( + sourcePermanent.getZoneChangeCounter(game)
AsForetoldAltCostUsedWatcher.class, sourcePermanent.getId()); + sourcePermanent.getTurnsOnBattlefield());
// If we haven't used it yet this turn, give the option of using the zero alternative cost // If we haven't used it yet this turn, give the option of using the zero alternative cost
if (!asForetoldAltCostUsedWatcher.hasBeenUsedThisTurn()) { if (wasItUsed == null) {
int timeCounters = sourcePermanent.getCounters(game).getCount("time"); int timeCounters = sourcePermanent.getCounters(game).getCount("time");
controller.getAlternativeSourceCosts().add(new AsForetoldAlternativeCost(sourcePermanent.getId(), timeCounters)); controller.getAlternativeSourceCosts().add(
new AsForetoldAlternativeCost(sourcePermanent.getId(), timeCounters));
} }
// Return true even if we didn't add the alt cost. We still applied the effect // Return true even if we didn't add the alt cost. We still applied the effect
return true; return true;
} }
@ -186,40 +176,3 @@ class AsForetoldAddAltCostEffect extends ContinuousEffectImpl {
return layer == Layer.RulesEffects; return layer == Layer.RulesEffects;
} }
} }
/**
* Watcher used as extra storage to record whether a given As Foretold has been
* used this turn. Technically speaking this watcher doesn't *watch* any
* GameEvents, but it does "watch" the alternative cost being used. That just
* isn't possible to watch through a game event. It's still helpful to co-op the
* Watcher system for this since it automatically handles ZoneChangeCounter
* stuff and resetting the condition at the end of the turn.
*/
class AsForetoldAltCostUsedWatcher extends Watcher {
public AsForetoldAltCostUsedWatcher() {
super("asForetoldAltCostUsedWatcher", WatcherScope.CARD);
}
public AsForetoldAltCostUsedWatcher(final AsForetoldAltCostUsedWatcher watcher) {
super(watcher);
}
@Override
public void watch(GameEvent event, Game game) {
// Nothing to do, we explicitly mark used in the alternative cost
}
public boolean hasBeenUsedThisTurn() {
return conditionMet();
}
public void markUsedThisTurn() {
condition = true;
}
@Override
public AsForetoldAltCostUsedWatcher copy() {
return new AsForetoldAltCostUsedWatcher(this);
}
}