[AFR] Wish - Add watcher to limit for single use

This commit is contained in:
Daniel Bomar 2021-07-20 13:26:17 -05:00
parent 1c3b42996d
commit 3414aa9959
No known key found for this signature in database
GPG key ID: C86C8658F4023918
2 changed files with 58 additions and 26 deletions

View file

@ -1,19 +1,23 @@
package mage.cards.w; package mage.cards.w;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageIdentifier;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.AsThoughEffectType; import mage.constants.*;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.watchers.Watcher;
/** /**
* *
@ -26,6 +30,8 @@ public final class Wish extends CardImpl {
// You may play a card you own from outside the game this turn. // You may play a card you own from outside the game this turn.
this.getSpellAbility().addEffect(new WishEffect()); this.getSpellAbility().addEffect(new WishEffect());
this.getSpellAbility().setIdentifier(MageIdentifier.WishWatcher);
this.getSpellAbility().addWatcher(new WishWatcher());
} }
private Wish(final Wish card) { private Wish(final Wish card) {
@ -69,7 +75,7 @@ class WishEffect extends OneShotEffect {
class WishPlayFromSideboardEffect extends AsThoughEffectImpl { class WishPlayFromSideboardEffect extends AsThoughEffectImpl {
public WishPlayFromSideboardEffect() { public WishPlayFromSideboardEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit); super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit, true);
} }
private WishPlayFromSideboardEffect(final WishPlayFromSideboardEffect effect) { private WishPlayFromSideboardEffect(final WishPlayFromSideboardEffect effect) {
@ -90,15 +96,40 @@ class WishPlayFromSideboardEffect extends AsThoughEffectImpl {
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (source.getControllerId().equals(affectedControllerId)) { if (source.getControllerId().equals(affectedControllerId)) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
UUID mainCardId = CardUtil.getMainCardId(game, objectId); UUID mainCardId = CardUtil.getMainCardId(game, objectId);
if (controller != null && controller.getSideboard().contains(mainCardId)) { if (controller != null && sourceObject != null && controller.getSideboard().contains(mainCardId)) {
// Only allow one card to be played WishWatcher watcher = game.getState().getWatcher(WishWatcher.class);
if (!game.inCheckPlayableState()) { return watcher != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game));
discard();
}
return true;
} }
} }
return false; return false;
} }
} }
class WishWatcher extends Watcher {
private final Set<MageObjectReference> usedFrom = new HashSet<>();
WishWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if ((GameEvent.EventType.SPELL_CAST.equals(event.getType()) || GameEvent.EventType.LAND_PLAYED.equals(event.getType()))
&& event.hasApprovingIdentifier(MageIdentifier.WishWatcher)) {
usedFrom.add(event.getAdditionalReference().getApprovingMageObjectReference());
}
}
@Override
public void reset() {
super.reset();
usedFrom.clear();
}
boolean isAbilityUsed(MageObjectReference mor) {
return usedFrom.contains(mor);
}
}

View file

@ -11,5 +11,6 @@ public enum MageIdentifier {
KaradorGhostChieftainWatcher, KaradorGhostChieftainWatcher,
KessDissidentMageWatcher, KessDissidentMageWatcher,
LurrusOfTheDreamDenWatcher, LurrusOfTheDreamDenWatcher,
MuldrothaTheGravetideWatcher MuldrothaTheGravetideWatcher,
WishWatcher
} }