1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-03-30 01:03:57 -09:00

added common class for searching and exiling

This commit is contained in:
Evan Kranzler 2022-03-16 09:10:30 -04:00
parent 3ea7f5df3b
commit d1b328a2da
9 changed files with 136 additions and 405 deletions

View file

@ -1,18 +1,11 @@
package mage.cards.b;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.abilities.keyword.GravestormAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
@ -25,7 +18,7 @@ public final class BitterOrdeal extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{B}");
// Search target player's library for a card and exile it. Then that player shuffles their library.
this.getSpellAbility().addEffect(new BitterOrdealEffect());
this.getSpellAbility().addEffect(new SearchLibraryAndExileTargetEffect(1, false));
this.getSpellAbility().addTarget(new TargetPlayer());
// Gravestorm
@ -41,37 +34,3 @@ public final class BitterOrdeal extends CardImpl {
return new BitterOrdeal(this);
}
}
class BitterOrdealEffect extends OneShotEffect {
BitterOrdealEffect() {
super(Outcome.Exile);
staticText = "Search target player's library for a card and exile it. Then that player shuffles.";
}
BitterOrdealEffect(final BitterOrdealEffect effect) {
super(effect);
}
@Override
public BitterOrdealEffect copy() {
return new BitterOrdealEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller == null || targetPlayer == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary();
controller.searchLibrary(target, source, game, targetPlayer.getId());
Card card = targetPlayer.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
}

View file

@ -1,19 +1,10 @@
package mage.cards.d;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
@ -26,7 +17,7 @@ public final class DenyingWind extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{7}{U}{U}");
// Search target player's library for up to seven cards and exile them. Then that player shuffles their library.
getSpellAbility().addEffect(new DenyingWindEffect());
getSpellAbility().addEffect(new SearchLibraryAndExileTargetEffect(7, true));
getSpellAbility().addTarget(new TargetPlayer());
}
@ -39,39 +30,3 @@ public final class DenyingWind extends CardImpl {
return new DenyingWind(this);
}
}
class DenyingWindEffect extends OneShotEffect {
public DenyingWindEffect() {
super(Outcome.Neutral);
staticText = "search target player's library for up to seven cards and exile them. Then that player shuffles";
}
public DenyingWindEffect(final DenyingWindEffect effect) {
super(effect);
}
@Override
public DenyingWindEffect copy() {
return new DenyingWindEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || player == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(7, StaticFilters.FILTER_CARD);
controller.searchLibrary(target, source, game, player.getId());
Cards cards = new CardsImpl();
target.getTargets()
.stream()
.map(uuid -> player.getLibrary().getCard(uuid, game))
.forEach(cards::add);
controller.moveCards(cards, Zone.EXILED, source, game);
player.shuffleLibrary(source, game);
return true;
}
}

View file

@ -5,21 +5,13 @@ import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.condition.common.ProwlCostWasPaidCondition;
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.abilities.hint.common.ProwlCostWasPaidHint;
import mage.abilities.keyword.ProwlAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetOpponent;
import java.util.UUID;
@ -42,8 +34,9 @@ public final class EarwigSquad extends CardImpl {
// When Earwig Squad enters the battlefield, if its prowl cost was paid, search target opponent's library for three cards and exile them. Then that player shuffles their library.
Ability ability = new ConditionalInterveningIfTriggeredAbility(
new EntersBattlefieldTriggeredAbility(new EarwigSquadEffect(), false),
ProwlCostWasPaidCondition.instance, "When {this} enters the battlefield, " +
new EntersBattlefieldTriggeredAbility(
new SearchLibraryAndExileTargetEffect(3, true), false
), ProwlCostWasPaidCondition.instance, "When {this} enters the battlefield, " +
"if its prowl cost was paid, search target opponent's library for three cards " +
"and exile them. Then that player shuffles."
);
@ -61,39 +54,3 @@ public final class EarwigSquad extends CardImpl {
return new EarwigSquad(this);
}
}
class EarwigSquadEffect extends OneShotEffect {
public EarwigSquadEffect() {
super(Outcome.Benefit);
staticText = "search target opponent's library for three cards and exile them. Then that player shuffles";
}
public EarwigSquadEffect(final EarwigSquadEffect effect) {
super(effect);
}
@Override
public EarwigSquadEffect copy() {
return new EarwigSquadEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player == null || opponent == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(3, StaticFilters.FILTER_CARD_CARDS);
player.searchLibrary(target, source, game, opponent.getId());
Cards cards = new CardsImpl();
target.getTargets()
.stream()
.map(uuid -> opponent.getLibrary().getCard(uuid, game))
.forEach(cards::add);
player.moveCards(cards, Zone.EXILED, source, game);
opponent.shuffleLibrary(source, game);
return true;
}
}

View file

@ -1,17 +1,10 @@
package mage.cards.e;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
@ -24,7 +17,7 @@ public final class Extract extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{U}");
// Search target player's library for a card and exile it. Then that player shuffles their library.
this.getSpellAbility().addEffect(new ExtractEffect());
this.getSpellAbility().addEffect(new SearchLibraryAndExileTargetEffect(1, false));
this.getSpellAbility().addTarget(new TargetPlayer());
}
@ -37,37 +30,3 @@ public final class Extract extends CardImpl {
return new Extract(this);
}
}
class ExtractEffect extends OneShotEffect {
public ExtractEffect() {
super(Outcome.Exile);
staticText = "Search target player's library for a card and exile it. Then that player shuffles.";
}
public ExtractEffect(final ExtractEffect effect) {
super(effect);
}
@Override
public ExtractEffect copy() {
return new ExtractEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player == null || targetPlayer == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary();
player.searchLibrary(target, source, game, targetPlayer.getId());
Card card = targetPlayer.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
player.moveCards(card, Zone.EXILED, source, game);
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
}

View file

@ -1,36 +1,30 @@
package mage.cards.j;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class JestersCap extends CardImpl {
public JestersCap(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{4}");
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
// {2}, {tap}, Sacrifice Jester's Cap: Search target player's library for three cards and exile them. Then that player shuffles their library.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new JestersCapEffect(), new ManaCostsImpl("{2}"));
Ability ability = new SimpleActivatedAbility(
new SearchLibraryAndExileTargetEffect(3, false), new GenericManaCost(2)
);
ability.addCost(new TapSourceCost());
ability.addCost(new SacrificeSourceCost());
ability.addTarget(new TargetPlayer());
@ -46,39 +40,3 @@ public final class JestersCap extends CardImpl {
return new JestersCap(this);
}
}
class JestersCapEffect extends OneShotEffect {
public JestersCapEffect() {
super(Outcome.Benefit);
this.staticText = "Search target player's library for three cards and exile them. Then that player shuffles";
}
public JestersCapEffect(final JestersCapEffect effect) {
super(effect);
}
@Override
public JestersCapEffect copy() {
return new JestersCapEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
TargetCardInLibrary target = new TargetCardInLibrary(3, 3, new FilterCard());
player.searchLibrary(target, source, game, targetPlayer.getId());
for (UUID cardId : target.getTargets()) {
final Card targetCard = game.getCard(cardId);
if (targetCard != null) {
applied |= player.moveCardToExileWithInfo(targetCard, null, null, source, game, Zone.LIBRARY, true);
}
}
targetPlayer.shuffleLibrary(source, game);
}
return applied;
}
}

View file

@ -1,46 +1,43 @@
package mage.cards.r;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DoIfCostPaid;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.constants.SubType;
import java.util.UUID;
/**
*
* @author LoneFox
*/
public final class RootwaterThief extends CardImpl {
public RootwaterThief(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}");
this.subtype.add(SubType.MERFOLK);
this.subtype.add(SubType.ROGUE);
this.power = new MageInt(1);
this.toughness = new MageInt(2);
// {U}: Rootwater Thief gains flying until end of turn.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.EndOfTurn), new ManaCostsImpl("{U}")));
this.addAbility(new SimpleActivatedAbility(new GainAbilitySourceEffect(
FlyingAbility.getInstance(), Duration.EndOfTurn
), new ManaCostsImpl<>("{U}")));
// Whenever Rootwater Thief deals combat damage to a player, you may pay {2}. If you do, search that player's library for a card and exile it, then the player shuffles their library.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new RootwaterThiefEffect(), false, true));
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new DoIfCostPaid(
new SearchLibraryAndExileTargetEffect(1, false), new GenericManaCost(2)
), false, true));
}
private RootwaterThief(final RootwaterThief card) {
@ -52,47 +49,3 @@ public final class RootwaterThief extends CardImpl {
return new RootwaterThief(this);
}
}
class RootwaterThiefEffect extends OneShotEffect {
RootwaterThiefEffect() {
super(Outcome.Exile);
staticText = "you may pay {2}. If you do, search that player's library for a card and exile it, then the player shuffles.";
}
RootwaterThiefEffect(final RootwaterThiefEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || damagedPlayer == null) {
return false;
}
String message = "Pay {2} to exile a card from damaged player's library?";
Cost cost = new ManaCostsImpl("{2}");
if(controller.chooseUse(Outcome.Benefit, message, source, game) && cost.pay(source, game, source, controller.getId(), false, null))
{
TargetCardInLibrary target = new TargetCardInLibrary();
if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) {
if (!target.getTargets().isEmpty()) {
Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
}
}
}
damagedPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
@Override
public RootwaterThiefEffect copy() {
return new RootwaterThiefEffect(this);
}
}

View file

@ -1,34 +1,27 @@
package mage.cards.s;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.condition.common.KickedCondition;
import mage.abilities.decorator.ConditionalOneShotEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.abilities.keyword.KickerAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/**
*
* @author North
*/
public final class SadisticSacrament extends CardImpl {
private static final String ruleText = "Search target player's library for up to three cards, exile them, then that player shuffles. If this spell was kicked, instead search that player's library for up to fifteen cards, exile them, then that player shuffles";
private static final String ruleText = "Search target player's library for up to three cards, exile them, " +
"then that player shuffles. If this spell was kicked, instead search that player's library " +
"for up to fifteen cards, exile them, then that player shuffles";
public SadisticSacrament(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{B}{B}{B}");
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{B}{B}{B}");
this.color.setBlack(true);
@ -38,10 +31,10 @@ public final class SadisticSacrament extends CardImpl {
// Search target player's library for up to three cards, exile them, then that player shuffles their library.
// If Sadistic Sacrament was kicked, instead search that player's library for up to fifteen cards, exile them, then that player shuffles their library.
this.getSpellAbility().addEffect(new ConditionalOneShotEffect(
new SadisticSacramentEffect(15),
new SadisticSacramentEffect(3),
KickedCondition.instance,
ruleText));
new SearchLibraryAndExileTargetEffect(15, true),
new SearchLibraryAndExileTargetEffect(3, true),
KickedCondition.instance, ruleText
));
this.getSpellAbility().addTarget(new TargetPlayer());
}
@ -54,45 +47,3 @@ public final class SadisticSacrament extends CardImpl {
return new SadisticSacrament(this);
}
}
class SadisticSacramentEffect extends OneShotEffect {
private int amount;
public SadisticSacramentEffect(int amount) {
super(Outcome.Exile);
this.amount = amount;
}
public SadisticSacramentEffect(final SadisticSacramentEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
public SadisticSacramentEffect copy() {
return new SadisticSacramentEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard("cards to exile"));
if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = targetPlayer.getLibrary().remove(targetId, game);
if (card != null) {
card.moveToExile(null, "", source, game);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
}

View file

@ -1,31 +1,22 @@
package mage.cards.s;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapTargetCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.search.SearchLibraryAndExileTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetControlledPermanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class SupremeInquisitor extends CardImpl {
@ -38,7 +29,7 @@ public final class SupremeInquisitor extends CardImpl {
}
public SupremeInquisitor(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{U}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{U}{U}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.WIZARD);
@ -46,7 +37,10 @@ public final class SupremeInquisitor extends CardImpl {
this.toughness = new MageInt(3);
// Tap five untapped Wizards you control: Search target player's library for up to five cards and exile them. Then that player shuffles their library.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SupremeInquisitorEffect(), new TapTargetCost(new TargetControlledPermanent(5, 5, filter, true)));
Ability ability = new SimpleActivatedAbility(
new SearchLibraryAndExileTargetEffect(5, true),
new TapTargetCost(new TargetControlledPermanent(5, filter))
);
ability.addTarget(new TargetPlayer());
this.addAbility(ability);
}
@ -60,43 +54,3 @@ public final class SupremeInquisitor extends CardImpl {
return new SupremeInquisitor(this);
}
}
class SupremeInquisitorEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard();
public SupremeInquisitorEffect() {
super(Outcome.Exile);
staticText = "Search target player's library for up to five cards and exile them. Then that player shuffles";
}
public SupremeInquisitorEffect(final SupremeInquisitorEffect effect) {
super(effect);
}
@Override
public SupremeInquisitorEffect copy() {
return new SupremeInquisitorEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 5, filter);
if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
List<UUID> targetId = target.getTargets();
for (UUID targetCard : targetId) {
Card card = targetPlayer.getLibrary().remove(targetCard, game);
if (card != null) {
player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
}

View file

@ -0,0 +1,85 @@
package mage.abilities.effects.common.search;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
/**
* @author TheElk801
*/
public class SearchLibraryAndExileTargetEffect extends OneShotEffect {
private final int amount;
private final boolean upTo;
public SearchLibraryAndExileTargetEffect(int amount, boolean upTo) {
super(Outcome.Benefit);
this.amount = amount;
this.upTo = upTo;
}
private SearchLibraryAndExileTargetEffect(final SearchLibraryAndExileTargetEffect effect) {
super(effect);
this.amount = effect.amount;
this.upTo = effect.upTo;
}
@Override
public SearchLibraryAndExileTargetEffect copy() {
return new SearchLibraryAndExileTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller == null || player == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(upTo ? 0 : amount, amount, StaticFilters.FILTER_CARD);
controller.searchLibrary(target, source, game, player.getId());
Cards cards = new CardsImpl();
target.getTargets()
.stream()
.map(uuid -> player.getLibrary().getCard(uuid, game))
.forEach(cards::add);
if (cards.isEmpty()) {
return false;
}
controller.moveCards(cards, Zone.EXILED, source, game);
player.shuffleLibrary(source, game);
return true;
}
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder("search ");
if (mode.getTargets().isEmpty()) {
sb.append("that player");
} else {
sb.append("target ");
sb.append(mode.getTargets().get(0).getTargetName());
}
sb.append("'s library for ");
if (amount > 1) {
if (upTo) {
sb.append("up to ");
}
sb.append(CardUtil.numberToText(amount));
sb.append(" cards and exile them");
} else {
sb.append("a card and exile it");
}
sb.append(". Then that player shuffles");
return sb.toString();
}
}