refactored a few more remove instances

This commit is contained in:
Evan Kranzler 2022-03-16 09:56:55 -04:00
parent d1b328a2da
commit ddabfacbe7
7 changed files with 133 additions and 217 deletions

View file

@ -78,7 +78,7 @@ class GrinningTotemSearchAndExileEffect extends OneShotEffect {
} }
TargetCardInLibrary targetCard = new TargetCardInLibrary(); TargetCardInLibrary targetCard = new TargetCardInLibrary();
you.searchLibrary(targetCard, source, game, targetOpponent.getId()); you.searchLibrary(targetCard, source, game, targetOpponent.getId());
Card card = targetOpponent.getLibrary().remove(targetCard.getFirstTarget(), game); Card card = targetOpponent.getLibrary().getCard(targetCard.getFirstTarget(), game);
if (card != null) { if (card != null) {
UUID exileZoneId = CardUtil.getCardExileZoneId(game, source); UUID exileZoneId = CardUtil.getCardExileZoneId(game, source);
you.moveCardsToExile(card, source, game, true, exileZoneId, CardUtil.getSourceName(game, source)); you.moveCardsToExile(card, source, game, true, exileZoneId, CardUtil.getSourceName(game, source));

View file

@ -1,78 +1,75 @@
package mage.cards.m; package mage.cards.m;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.SearchEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterLandCard; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/** /**
*
* @author nick.myers * @author nick.myers
*/ */
public final class ManaSeverance extends CardImpl { public final class ManaSeverance extends CardImpl {
public ManaSeverance(UUID ownerId, CardSetInfo setInfo) { public ManaSeverance(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{1}{U}"); super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{U}");
// Search your library for any number of land cards and remove them from the game. // Search your library for any number of land cards and remove them from the game.
// Shuffle your library afterwards. // Shuffle your library afterwards.
this.getSpellAbility().addEffect(new ManaSeveranceEffect()); this.getSpellAbility().addEffect(new ManaSeveranceEffect());
} }
private ManaSeverance(final ManaSeverance card) { private ManaSeverance(final ManaSeverance card) {
super(card); super(card);
} }
@Override @Override
public ManaSeverance copy() { public ManaSeverance copy() {
return new ManaSeverance(this); return new ManaSeverance(this);
} }
} }
class ManaSeveranceEffect extends SearchEffect { class ManaSeveranceEffect extends OneShotEffect {
public ManaSeveranceEffect() { public ManaSeveranceEffect() {
super(new TargetCardInLibrary(0, Integer.MAX_VALUE, new FilterLandCard()), Outcome.Exile); super(Outcome.Benefit);
this.staticText = "search your library for any number of land cards, exile them, then shuffle"; this.staticText = "search your library for any number of land cards, exile them, then shuffle";
} }
public ManaSeveranceEffect(final ManaSeveranceEffect effect) { public ManaSeveranceEffect(final ManaSeveranceEffect effect) {
super(effect); super(effect);
} }
@Override @Override
public ManaSeveranceEffect copy() { public ManaSeveranceEffect copy() {
return new ManaSeveranceEffect(this); return new ManaSeveranceEffect(this);
} }
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
if (card != null) {
controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.LIBRARY, true);
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
} }
return false; TargetCardInLibrary target = new TargetCardInLibrary(
0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_LANDS
);
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl(target.getTargets());
cards.retainZone(Zone.LIBRARY, game);
player.moveCards(cards, Zone.EXILED, source, game);
player.shuffleLibrary(source, game);
return true;
} }
} }

View file

@ -1,9 +1,11 @@
package mage.cards.s; package mage.cards.s;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.*; import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
@ -23,13 +25,15 @@ import java.util.UUID;
*/ */
public final class SecretSalvage extends CardImpl { public final class SecretSalvage extends CardImpl {
private static final FilterCard filter = new FilterNonlandCard("nonland card from your graveyard");
public SecretSalvage(UUID ownerId, CardSetInfo setInfo) { public SecretSalvage(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{B}{B}"); super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{B}{B}");
// Exile target nonland card from your graveyard. Search your library for any number of cards with the same name as that card, // Exile target nonland card from your graveyard. Search your library for any number of cards with the same name as that card,
// reveal them, and put them into your hand. Then shuffle your library. // reveal them, and put them into your hand. Then shuffle your library.
getSpellAbility().addEffect(new SecretSalvageEffect()); getSpellAbility().addEffect(new SecretSalvageEffect());
getSpellAbility().addTarget(new TargetCardInYourGraveyard(new FilterNonlandCard("nonland card from your graveyard"))); getSpellAbility().addTarget(new TargetCardInYourGraveyard(filter));
} }
private SecretSalvage(final SecretSalvage card) { private SecretSalvage(final SecretSalvage card) {
@ -46,8 +50,9 @@ class SecretSalvageEffect extends OneShotEffect {
public SecretSalvageEffect() { public SecretSalvageEffect() {
super(Outcome.DrawCard); super(Outcome.DrawCard);
staticText = "Exile target nonland card from your graveyard. Search your library for any number of cards with the same name as that card, " staticText = "Exile target nonland card from your graveyard. " +
+ "reveal them, put them into your hand, then shuffle"; "Search your library for any number of cards with the same name as that card, " +
"reveal them, put them into your hand, then shuffle";
} }
public SecretSalvageEffect(final SecretSalvageEffect effect) { public SecretSalvageEffect(final SecretSalvageEffect effect) {
@ -62,34 +67,16 @@ class SecretSalvageEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game); Card targetCard = game.getCard(getTargetPointer().getFirst(game, source));
if (controller != null && sourceObject != null) { if (controller == null || targetCard == null) {
Card targetCard = game.getCard(getTargetPointer().getFirst(game, source)); return false;
if (targetCard != null) {
controller.moveCards(targetCard, Zone.EXILED, source, game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(targetCard);
FilterCard nameFilter = new FilterCard();
nameFilter.add(new NamePredicate(nameToSearch));
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, nameFilter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
}
}
controller.revealCards(sourceObject.getIdName(), cards, game);
controller.moveCards(cards, Zone.HAND, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
}
} }
return false; controller.moveCards(targetCard, Zone.EXILED, source, game);
String nameToSearch = CardUtil.getCardNameForSameNameSearch(targetCard);
FilterCard nameFilter = new FilterCard("card named " + nameToSearch);
nameFilter.add(new NamePredicate(nameToSearch));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(
0, Integer.MAX_VALUE, nameFilter
), true, true).apply(game, source);
} }
} }

View file

@ -1,28 +1,28 @@
package mage.cards.s; package mage.cards.s;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.filter.common.FilterNonlandCard; import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/** /**
*
* @author North * @author North
*/ */
public final class SelectiveMemory extends CardImpl { public final class SelectiveMemory extends CardImpl {
public SelectiveMemory(UUID ownerId, CardSetInfo setInfo) { public SelectiveMemory(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{3}{U}"); super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{U}");
// Search your library for any number of nonland cards and exile them. Then shuffle your library. // Search your library for any number of nonland cards and exile them. Then shuffle your library.
this.getSpellAbility().addEffect(new SelectiveMemoryEffect()); this.getSpellAbility().addEffect(new SelectiveMemoryEffect());
@ -57,20 +57,17 @@ class SelectiveMemoryEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player == null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, new FilterNonlandCard()); return false;
if (player.searchLibrary(target, source, game)) {
for (UUID targetId : target.getTargets()) {
Card card = player.getLibrary().remove(targetId, game);
if (card != null) {
card.moveToExile(null, "", source, game);
}
}
}
player.shuffleLibrary(source, game);
return true;
} }
return false; TargetCardInLibrary target = new TargetCardInLibrary(
0, Integer.MAX_VALUE, StaticFilters.FILTER_CARDS_NON_LAND
);
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl(target.getTargets());
cards.retainZone(Zone.LIBRARY, game);
player.moveCards(cards, Zone.EXILED, source, game);
player.shuffleLibrary(source, game);
return true;
} }
} }

View file

@ -1,33 +1,29 @@
package mage.cards.t; package mage.cards.t;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.asthought.PlayFromNotOwnHandZoneTargetEffect;
import mage.abilities.keyword.IslandwalkAbility; import mage.abilities.keyword.IslandwalkAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.*;
import mage.filter.common.FilterArtifactCard; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public final class ThadaAdelAcquisitor extends CardImpl { public final class ThadaAdelAcquisitor extends CardImpl {
public ThadaAdelAcquisitor(UUID ownerId, CardSetInfo setInfo) { public ThadaAdelAcquisitor(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}{U}"); super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{U}{U}");
addSuperType(SuperType.LEGENDARY); addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.MERFOLK); this.subtype.add(SubType.MERFOLK);
this.subtype.add(SubType.ROGUE); this.subtype.add(SubType.ROGUE);
@ -39,7 +35,9 @@ public final class ThadaAdelAcquisitor extends CardImpl {
this.addAbility(new IslandwalkAbility()); this.addAbility(new IslandwalkAbility());
// Whenever Thada Adel, Acquisitor deals combat damage to a player, search that player's library for an artifact card and exile it. Then that player shuffles their library. Until end of turn, you may play that card. // Whenever Thada Adel, Acquisitor deals combat damage to a player, search that player's library for an artifact card and exile it. Then that player shuffles their library. Until end of turn, you may play that card.
this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(new ThadaAdelAcquisitorEffect(), false, true)); this.addAbility(new DealsCombatDamageToAPlayerTriggeredAbility(
new ThadaAdelAcquisitorEffect(), false, true
));
} }
private ThadaAdelAcquisitor(final ThadaAdelAcquisitor card) { private ThadaAdelAcquisitor(final ThadaAdelAcquisitor card) {
@ -67,22 +65,16 @@ class ThadaAdelAcquisitorEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source)); Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId()); if (controller == null || damagedPlayer == null) {
if (controller == null || damagedPlayer == null || sourceObject == null) {
return false; return false;
} }
TargetCardInLibrary target = new TargetCardInLibrary(new FilterArtifactCard()); TargetCardInLibrary target = new TargetCardInLibrary(StaticFilters.FILTER_CARD_ARTIFACT);
if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) { controller.searchLibrary(target, source, game, damagedPlayer.getId());
if (!target.getTargets().isEmpty()) { Card card = damagedPlayer.getLibrary().getCard(target.getFirstTarget(), game);
Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game); PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(
if (card != null) { game, source, card, TargetController.YOU, Duration.EndOfTurn,
controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.LIBRARY, true); false, false, false
ContinuousEffect effect = new ThadaAdelPlayFromExileEffect(); );
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
}
}
damagedPlayer.shuffleLibrary(source, game); damagedPlayer.shuffleLibrary(source, game);
return true; return true;
} }
@ -92,31 +84,3 @@ class ThadaAdelAcquisitorEffect extends OneShotEffect {
return new ThadaAdelAcquisitorEffect(this); return new ThadaAdelAcquisitorEffect(this);
} }
} }
class ThadaAdelPlayFromExileEffect extends AsThoughEffectImpl {
public ThadaAdelPlayFromExileEffect() {
super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.EndOfTurn, Outcome.Benefit);
staticText = "You may play this card from exile";
}
public ThadaAdelPlayFromExileEffect(final ThadaAdelPlayFromExileEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public ThadaAdelPlayFromExileEffect copy() {
return new ThadaAdelPlayFromExileEffect(this);
}
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
return source.isControlledBy(affectedControllerId)
&& sourceId.equals(getTargetPointer().getFirst(game, source));
}
}

View file

@ -2,15 +2,18 @@ package mage.cards.u;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.*; import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard; import mage.filter.common.FilterCreatureCard;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -46,7 +49,8 @@ class UncageTheMenagerieEffect extends OneShotEffect {
public UncageTheMenagerieEffect() { public UncageTheMenagerieEffect() {
super(Outcome.DrawCard); super(Outcome.DrawCard);
this.staticText = "Search your library for up to X creature cards with different names that each have mana value X, reveal them, put them into your hand, then shuffle."; this.staticText = "Search your library for up to X creature cards with different names " +
"that each have mana value X, reveal them, put them into your hand, then shuffle.";
} }
public UncageTheMenagerieEffect(final UncageTheMenagerieEffect effect) { public UncageTheMenagerieEffect(final UncageTheMenagerieEffect effect) {
@ -60,38 +64,15 @@ class UncageTheMenagerieEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); return new SearchLibraryPutInHandEffect(new UncageTheMenagerieTarget(
Card sourceCard = game.getCard(source.getSourceId()); source.getManaCostsToPay().getX()), true, true
if (player == null || sourceCard == null) { ).apply(game, source);
return false;
}
int xValue = source.getManaCostsToPay().getX();
UncageTheMenagerieTarget target = new UncageTheMenagerieTarget(xValue);
if (player.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
}
}
player.revealCards(sourceCard.getIdName(), cards, game);
player.moveCards(cards, Zone.HAND, source, game);
}
player.shuffleLibrary(source, game);
return true;
}
player.shuffleLibrary(source, game);
return false;
} }
} }
class UncageTheMenagerieTarget extends TargetCardInLibrary { class UncageTheMenagerieTarget extends TargetCardInLibrary {
private int xValue; private final int xValue;
public UncageTheMenagerieTarget(int xValue) { public UncageTheMenagerieTarget(int xValue) {
super(0, xValue, new FilterCreatureCard(xValue + " creature cards with different names with mana value " + xValue)); super(0, xValue, new FilterCreatureCard(xValue + " creature cards with different names with mana value " + xValue));
@ -110,21 +91,15 @@ class UncageTheMenagerieTarget extends TargetCardInLibrary {
@Override @Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Cards cards, Game game) { public boolean canTarget(UUID playerId, UUID id, Ability source, Cards cards, Game game) {
Card card = cards.get(id, game); if (!super.canTarget(playerId, id, source, cards, game)) {
if (card != null) { return false;
for (UUID targetId : this.getTargets()) {
Card iCard = game.getCard(targetId);
if (iCard != null && iCard.getName().equals(card.getName())) {
return false;
}
}
if (!(card.isCreature(game) && card.getManaValue() == xValue)) {
return false;
}
return filter.match(card, playerId, game);
} }
return false; Card card = cards.get(id, game);
return card.getManaValue() == xValue
&& this
.getTargets()
.stream()
.map(game::getCard)
.noneMatch(c -> CardUtil.haveSameNames(c, card));
} }
} }

View file

@ -1,8 +1,5 @@
package mage.cards.w; package mage.cards.w;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
@ -10,39 +7,42 @@ import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterEnchantmentCard;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/** /**
*
* @author emerald000 * @author emerald000
*/ */
public final class WildResearch extends CardImpl { public final class WildResearch extends CardImpl {
private static final FilterCard filterEnchantment = new FilterCard("enchantment card"); private static final FilterCard filterEnchantment = new FilterEnchantmentCard();
private static final FilterCard filterInstant = new FilterCard("instant card"); private static final FilterCard filterInstant = new FilterCard("instant card");
static { static {
filterEnchantment.add(CardType.ENCHANTMENT.getPredicate());
filterInstant.add(CardType.INSTANT.getPredicate()); filterInstant.add(CardType.INSTANT.getPredicate());
} }
public WildResearch(UUID ownerId, CardSetInfo setInfo) { public WildResearch(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{R}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{R}");
// {1}{W}: Search your library for an enchantment card and reveal that card. Put it into your hand, then discard a card at random. Then shuffle your library. // {1}{W}: Search your library for an enchantment card and reveal that card. Put it into your hand, then discard a card at random. Then shuffle your library.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new WildResearchEffect(filterEnchantment), new ManaCostsImpl<>("{1}{W}"))); this.addAbility(new SimpleActivatedAbility(
new WildResearchEffect(filterEnchantment), new ManaCostsImpl<>("{1}{W}")
));
// {1}{U}: Search your library for an instant card and reveal that card. Put it into your hand, then discard a card at random. Then shuffle your library. // {1}{U}: Search your library for an instant card and reveal that card. Put it into your hand, then discard a card at random. Then shuffle your library.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new WildResearchEffect(filterInstant), new ManaCostsImpl<>("{1}{U}"))); this.addAbility(new SimpleActivatedAbility(
new WildResearchEffect(filterInstant), new ManaCostsImpl<>("{1}{U}")
));
} }
private WildResearch(final WildResearch card) { private WildResearch(final WildResearch card) {
@ -61,11 +61,12 @@ class WildResearchEffect extends OneShotEffect {
WildResearchEffect(FilterCard filter) { WildResearchEffect(FilterCard filter) {
super(Outcome.DrawCard); super(Outcome.DrawCard);
this.staticText = "Search your library for an " + filter.getMessage() + " and reveal that card. Put it into your hand, then discard a card at random. Then shuffle."; this.staticText = "Search your library for an " + filter.getMessage() + " and reveal that card. " +
"Put it into your hand, then discard a card at random. Then shuffle.";
this.filter = filter; this.filter = filter;
} }
WildResearchEffect(final WildResearchEffect effect) { private WildResearchEffect(final WildResearchEffect effect) {
super(effect); super(effect);
this.filter = effect.filter; this.filter = effect.filter;
} }
@ -78,23 +79,18 @@ class WildResearchEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId()); if (controller == null) {
if (controller != null && sourceObject != null) { return false;
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
Cards cards = new CardsImpl(card);
controller.revealCards(sourceObject.getIdName(), cards, game, true);
}
}
}
controller.discardOne(true, false, source, game);
controller.shuffleLibrary(source, game);
return true;
} }
return false; TargetCardInLibrary target = new TargetCardInLibrary(filter);
controller.searchLibrary(target, source, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.revealCards(source, new CardsImpl(card), game);
controller.moveCards(card, Zone.HAND, source, game);
}
controller.discardOne(true, false, source, game);
controller.shuffleLibrary(source, game);
return true;
} }
} }