updated various cards to improve how they handle exiling with info (#7615)

This commit is contained in:
Evan Kranzler 2021-02-22 15:26:58 -05:00 committed by GitHub
parent bb0a995541
commit bd3777997e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 349 additions and 442 deletions

View file

@ -1,44 +1,40 @@
package mage.abilities.effects.common;
import java.util.List;
import java.util.UUID;
import mage.constants.Outcome;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
*
* @author LevelX2
*/
public class ExileAllEffect extends OneShotEffect {
private FilterPermanent filter;
private String exileZone = null;
private UUID exileId = null;
private final FilterPermanent filter;
private final boolean forSource;
public ExileAllEffect(FilterPermanent filter) {
this(filter, null, null);
this(filter, false);
}
public ExileAllEffect(FilterPermanent filter, UUID exileId, String exileZone) {
public ExileAllEffect(FilterPermanent filter, boolean forSource) {
super(Outcome.Exile);
this.filter = filter;
this.exileZone = exileZone;
this.exileId = exileId;
this.forSource = forSource;
setText();
}
public ExileAllEffect(final ExileAllEffect effect) {
super(effect);
this.filter = effect.filter.copy();
this.exileZone = effect.exileZone;
this.exileId = effect.exileId;
this.forSource = effect.forSource;
}
@Override
@ -49,14 +45,18 @@ public class ExileAllEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : permanents) {
controller.moveCardToExileWithInfo(permanent, exileId, exileZone, source, game, Zone.BATTLEFIELD, true);
}
return true;
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
return false;
Cards cards = new CardsImpl();
game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source.getSourceId(), game
).stream().forEach(cards::add);
if (forSource) {
return controller.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), sourceObject.getName());
}
return controller.moveCards(cards, Zone.EXILED, source, game);
}

View file

@ -1,14 +1,15 @@
package mage.abilities.effects.common;
import java.util.Locale;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.Target;
@ -16,29 +17,32 @@ import mage.target.common.TargetCardInHand;
import mage.target.common.TargetCardInYourGraveyard;
import mage.util.CardUtil;
import java.util.Locale;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ExileFromZoneTargetEffect extends OneShotEffect {
private Zone zone;
private FilterCard filter;
private UUID exileId;
private String exileName;
private int amount;
private final Zone zone;
private final FilterCard filter;
private final int amount;
private final boolean withSource;
public ExileFromZoneTargetEffect(Zone zone, UUID exileId, String exileName, FilterCard filter) {
this(zone, exileId, exileName, filter, 1);
public ExileFromZoneTargetEffect(Zone zone, boolean withSource) {
this(zone, StaticFilters.FILTER_CARD, withSource);
}
public ExileFromZoneTargetEffect(Zone zone, UUID exileId, String exileName, FilterCard filter, int amount) {
public ExileFromZoneTargetEffect(Zone zone, FilterCard filter, boolean withSource) {
this(zone, filter, 1, withSource);
}
public ExileFromZoneTargetEffect(Zone zone, FilterCard filter, int amount, boolean withSource) {
super(Outcome.Exile);
this.zone = zone;
this.filter = filter;
this.exileId = exileId;
this.exileName = exileName;
this.amount = amount;
this.withSource = withSource;
setText();
}
@ -46,33 +50,36 @@ public class ExileFromZoneTargetEffect extends OneShotEffect {
super(effect);
this.zone = effect.zone;
this.filter = effect.filter.copy();
this.exileId = effect.exileId;
this.exileName = effect.exileName;
this.amount = effect.amount;
this.withSource = effect.withSource;
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
Target target = null;
switch (zone) {
case HAND:
target = new TargetCardInHand(Math.min(player.getHand().count(filter, game), amount), filter);
break;
case GRAVEYARD:
target = new TargetCardInYourGraveyard(Math.min(player.getGraveyard().count(filter, game), amount), filter);
break;
default:
}
if (target != null && target.canChoose(source.getSourceId(), player.getId(), game)) {
if (target.chooseTarget(Outcome.Exile, player.getId(), source, game)) {
player.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, true, exileId, exileName);
}
}
MageObject mageObject = source.getSourceObject(game);
if (player == null) {
return false;
}
Target target = null;
switch (zone) {
case HAND:
target = new TargetCardInHand(Math.min(player.getHand().count(filter, game), amount), filter);
break;
case GRAVEYARD:
target = new TargetCardInYourGraveyard(Math.min(player.getGraveyard().count(filter, game), amount), filter);
break;
default:
}
if (target == null || !target.canChoose(source.getSourceId(), player.getId(), game)) {
return true;
}
return false;
target.chooseTarget(Outcome.Exile, player.getId(), source, game);
Cards cards = new CardsImpl(target.getTargets());
if (withSource) {
return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), mageObject.getName());
}
return player.moveCards(cards, Zone.EXILED, source, game);
}
@Override
@ -81,6 +88,7 @@ public class ExileFromZoneTargetEffect extends OneShotEffect {
}
private void setText() {
staticText = "target player exiles " + CardUtil.numberToText(amount, "a") + ' ' + filter.getMessage() + " from their " + zone.toString().toLowerCase(Locale.ENGLISH);
staticText = "target player exiles " + CardUtil.numberToText(amount, "a")
+ ' ' + filter.getMessage() + " from their " + zone.toString().toLowerCase(Locale.ENGLISH);
}
}

View file

@ -1,5 +1,6 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -7,6 +8,8 @@ import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;
/**
* Created by Eric on 9/24/2016.
@ -18,22 +21,21 @@ public class MistmeadowWitchEffect extends OneShotEffect {
staticText = "Exile target creature. Return that card to the battlefield under its owner's control at the beginning of the next end step";
}
public MistmeadowWitchEffect(final MistmeadowWitchEffect effect) {
private MistmeadowWitchEffect(final MistmeadowWitchEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
if (permanent.moveToExile(source.getSourceId(), "Mistmeadow Witch Exile", source, game)) {
//create delayed triggered ability
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD));
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
MageObject sourceObject = source.getSourceObject(game);
if (player == null || permanent == null || sourceObject == null) {
return false;
}
return false;
player.moveCardsToExile(permanent, source, game, true, CardUtil.getExileZoneId(game, source), sourceObject.getName());
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(Zone.BATTLEFIELD, "return the exiled card to the battlefield under its owner's control")), source);
return true;
}
@Override

View file

@ -1,7 +1,6 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
@ -9,29 +8,27 @@ import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ReturnFromExileEffect extends OneShotEffect {
private UUID exileId;
private Zone zone;
private boolean tapped;
private final Zone zone;
private final boolean tapped;
public ReturnFromExileEffect(UUID exileId, Zone zone) {
this(exileId, zone, false);
public ReturnFromExileEffect(Zone zone) {
this(zone, false);
}
public ReturnFromExileEffect(UUID exileId, Zone zone, String text) {
this(exileId, zone, false);
public ReturnFromExileEffect(Zone zone, String text) {
this(zone, false);
staticText = text;
}
public ReturnFromExileEffect(UUID exileId, Zone zone, boolean tapped) {
public ReturnFromExileEffect(Zone zone, boolean tapped) {
super(Outcome.PutCardInPlay);
this.exileId = exileId;
this.zone = zone;
this.tapped = tapped;
setText();
@ -39,7 +36,6 @@ public class ReturnFromExileEffect extends OneShotEffect {
public ReturnFromExileEffect(final ReturnFromExileEffect effect) {
super(effect);
this.exileId = effect.exileId;
this.zone = effect.zone;
this.tapped = effect.tapped;
}
@ -51,19 +47,15 @@ public class ReturnFromExileEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
ExileZone exile = game.getExile().getExileZone(exileId);
ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && exile != null) {
switch (zone) {
case LIBRARY:
controller.putCardsOnTopOfLibrary(exile, game, source, false);
break;
default:
controller.moveCards(exile.getCards(game), zone, source, game, tapped, false, true, null);
}
return true;
if (controller == null || exile == null) {
return false;
}
return false;
if (zone == Zone.LIBRARY) {
return controller.putCardsOnTopOfLibrary(exile, game, source, false);
}
return controller.moveCards(exile.getCards(game), zone, source, game, tapped, false, true, null);
}
private void setText() {

View file

@ -74,7 +74,7 @@ class TibaltCosmicImpostorPlayFromExileEffect extends AsThoughEffectImpl {
if (exile.contains(mainCardId)
&& affectedControllerId.equals(source.getControllerId())
&& game.getState().getZone(mainCardId).equals(Zone.EXILED)) {
CardUtil.makeCardPlayableAndSpendManaAsAnyColor(game, source, cardInExile, Duration.Custom);
CardUtil.makeCardPlayable(game, source, cardInExile, Duration.Custom, true);
return true;
}
return false;

View file

@ -1102,8 +1102,8 @@ public final class CardUtil {
}
}
public static void makeCardPlayableAndSpendManaAsAnyColor(Game game, Ability source, Card card, Duration duration) {
makeCardPlayableAndSpendManaAsAnyColor(game, source, card, duration, null);
public static void makeCardPlayable(Game game, Ability source, Card card, Duration duration, boolean anyColor) {
makeCardPlayable(game, source, card, duration, anyColor, null);
}
/**
@ -1115,9 +1115,10 @@ public final class CardUtil {
* @param game
* @param card
* @param duration
* @param anyColor
* @param condition can be null
*/
public static void makeCardPlayableAndSpendManaAsAnyColor(Game game, Ability source, Card card, Duration duration, Condition condition) {
public static void makeCardPlayable(Game game, Ability source, Card card, Duration duration, boolean anyColor, Condition condition) {
// Effect can be used for cards in zones and permanents on battlefield
// PermanentCard's ZCC is static, but we need updated ZCC from the card (after moved to another zone)
// So there is a workaround to get actual card's ZCC
@ -1125,7 +1126,9 @@ public final class CardUtil {
UUID objectId = card.getMainCard().getId();
int zcc = game.getState().getZoneChangeCounter(objectId);
game.addEffect(new CanPlayCardControllerEffect(game, objectId, zcc, duration, condition), source);
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration, condition).setTargetPointer(new FixedTarget(objectId, zcc)), source);
if (anyColor) {
game.addEffect(new YouMaySpendManaAsAnyColorToCastTargetEffect(duration, condition).setTargetPointer(new FixedTarget(objectId, zcc)), source);
}
}
/**