Implemented "Until your next end step" duration (#8831)

* initial implementation of until next end step duration

* added test, reworked effect duration
This commit is contained in:
Evan Kranzler 2022-04-10 17:57:58 -04:00 committed by GitHub
parent 1807565ef0
commit 6e65db284c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 160 additions and 90 deletions

View file

@ -1,26 +1,19 @@
package mage.cards.r;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.condition.Condition;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileGraveyardAllTargetPlayerEffect;
import mage.abilities.effects.common.ExileTopXMayPlayUntilEndOfTurnEffect;
import mage.abilities.effects.common.SacrificeEffect;
import mage.cards.*;
import mage.constants.*;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreatureOrPlaneswalkerPermanent;
import mage.filter.predicate.permanent.MaxManaValueControlledPermanentPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetOpponent;
import mage.util.CardUtil;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
@ -46,8 +39,9 @@ public final class RiveteersCharm extends CardImpl {
this.getSpellAbility().addTarget(new TargetOpponent());
// Exile the top three cards of your library. Until your next end step, you may play those cards.
this.getSpellAbility().addMode(new Mode(new RiveteersCharmEffect()));
this.getSpellAbility().addWatcher(new RiveteersCharmWatcher());
this.getSpellAbility().addMode(new Mode(new ExileTopXMayPlayUntilEndOfTurnEffect(
3, false, Duration.UntilYourNextEndStep
)));
// Exile target player's graveyard.
this.getSpellAbility().addMode(new Mode(new ExileGraveyardAllTargetPlayerEffect()).addTarget(new TargetPlayer()));
@ -62,69 +56,3 @@ public final class RiveteersCharm extends CardImpl {
return new RiveteersCharm(this);
}
}
class RiveteersCharmEffect extends OneShotEffect {
RiveteersCharmEffect() {
super(Outcome.Benefit);
staticText = "exile the top three cards of your library. Until your next end step, you may play those cards";
}
private RiveteersCharmEffect(final RiveteersCharmEffect effect) {
super(effect);
}
@Override
public RiveteersCharmEffect copy() {
return new RiveteersCharmEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
if (cards.isEmpty()) {
return false;
}
player.moveCards(cards, Zone.EXILED, source, game);
int count = RiveteersCharmWatcher.getCount(game, source);
Condition condition = (g, s) -> RiveteersCharmWatcher.getCount(g, s) == count;
for (Card card : cards.getCards(game)) {
CardUtil.makeCardPlayable(game, source, card, Duration.Custom, false, null, condition);
}
return true;
}
}
class RiveteersCharmWatcher extends Watcher {
private final Map<UUID, Integer> playerMap = new HashMap<>();
RiveteersCharmWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
switch (event.getType()) {
case END_TURN_STEP_PRE:
playerMap.compute(game.getActivePlayerId(), CardUtil::setOrIncrementValue);
return;
case BEGINNING_PHASE_PRE:
if (game.getTurnNum() == 1) {
playerMap.clear();
}
}
}
static int getCount(Game game, Ability source) {
return game
.getState()
.getWatcher(RiveteersCharmWatcher.class)
.playerMap
.getOrDefault(source.getControllerId(), 0);
}
}