diff --git a/Mage.Sets/src/mage/cards/a/AchHansRun.java b/Mage.Sets/src/mage/cards/a/AchHansRun.java index 619615a29a3..e8b9c2e6ec0 100644 --- a/Mage.Sets/src/mage/cards/a/AchHansRun.java +++ b/Mage.Sets/src/mage/cards/a/AchHansRun.java @@ -78,7 +78,7 @@ class AchHansRunEffect extends OneShotEffect { if (!controller.searchLibrary(target, source, game)) { return false; } - Card card = controller.getLibrary().remove(target.getFirstTarget(), game); + Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) { return false; } diff --git a/Mage.Sets/src/mage/cards/c/CongregationAtDawn.java b/Mage.Sets/src/mage/cards/c/CongregationAtDawn.java index 3c106d17b35..9d48fa444ea 100644 --- a/Mage.Sets/src/mage/cards/c/CongregationAtDawn.java +++ b/Mage.Sets/src/mage/cards/c/CongregationAtDawn.java @@ -68,7 +68,7 @@ class CongregationAtDawnEffect extends OneShotEffect { if (!target.getTargets().isEmpty()) { Cards revealed = new CardsImpl(); for (UUID cardId : target.getTargets()) { - Card card = controller.getLibrary().remove(cardId, game); + Card card = controller.getLibrary().getCard(cardId, game); revealed.add(card); } controller.revealCards(sourceObject.getName(), revealed, game); diff --git a/Mage.Sets/src/mage/cards/d/DistantMemories.java b/Mage.Sets/src/mage/cards/d/DistantMemories.java index 715ef508ca8..9ae05462efa 100644 --- a/Mage.Sets/src/mage/cards/d/DistantMemories.java +++ b/Mage.Sets/src/mage/cards/d/DistantMemories.java @@ -63,7 +63,7 @@ class DistantMemoriesEffect extends OneShotEffect { TargetCardInLibrary target = new TargetCardInLibrary(); if (controller.searchLibrary(target, source, game)) { - Card card = controller.getLibrary().remove(target.getFirstTarget(), game); + Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); if (card != null) { controller.moveCards(card, Zone.EXILED, source, game); controller.shuffleLibrary(source, game); diff --git a/Mage.Sets/src/mage/cards/e/EarwigSquad.java b/Mage.Sets/src/mage/cards/e/EarwigSquad.java index 516afaaaddc..2141ead6e97 100644 --- a/Mage.Sets/src/mage/cards/e/EarwigSquad.java +++ b/Mage.Sets/src/mage/cards/e/EarwigSquad.java @@ -8,20 +8,20 @@ import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.hint.common.ProwlCostWasPaidHint; import mage.abilities.keyword.ProwlAbility; -import mage.cards.Card; 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.FilterCard; +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.List; import java.util.UUID; /** @@ -41,11 +41,14 @@ public final class EarwigSquad extends CardImpl { this.addAbility(new ProwlAbility(this, "{2}{B}")); // 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. - EntersBattlefieldTriggeredAbility ability = new EntersBattlefieldTriggeredAbility(new EarwigSquadEffect(), false); + Ability ability = new ConditionalInterveningIfTriggeredAbility( + new EntersBattlefieldTriggeredAbility(new EarwigSquadEffect(), 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." + ); ability.addTarget(new TargetOpponent()); - this.addAbility(new ConditionalInterveningIfTriggeredAbility(ability, 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.") - .addHint(ProwlCostWasPaidHint.instance)); + this.addAbility(ability.addHint(ProwlCostWasPaidHint.instance)); } @@ -79,20 +82,18 @@ class EarwigSquadEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(source.getFirstTarget()); Player player = game.getPlayer(source.getControllerId()); - if (player != null && opponent != null) { - TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCard("cards from opponents library to exile")); - if (player.searchLibrary(target, source, game, opponent.getId())) { - List targets = target.getTargets(); - for (UUID targetId : targets) { - Card card = opponent.getLibrary().remove(targetId, game); - if (card != null) { - player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true); - } - } - } - opponent.shuffleLibrary(source, game); - return true; + if (player == null || opponent == null) { + return false; } - 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; } } diff --git a/Mage.Sets/src/mage/cards/e/Extract.java b/Mage.Sets/src/mage/cards/e/Extract.java index ee436168bb5..b989867c2f6 100644 --- a/Mage.Sets/src/mage/cards/e/Extract.java +++ b/Mage.Sets/src/mage/cards/e/Extract.java @@ -1,7 +1,5 @@ - package mage.cards.e; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; @@ -10,26 +8,24 @@ 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 cbt33, jeffwadsworth (Supreme Inquisitor) */ public final class Extract extends CardImpl { public Extract(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{U}"); - + 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().addTarget(new TargetPlayer()); - } private Extract(final Extract card) { @@ -44,8 +40,6 @@ public final class Extract extends CardImpl { class ExtractEffect extends OneShotEffect { - private static final FilterCard filter = new FilterCard(); - public ExtractEffect() { super(Outcome.Exile); staticText = "Search target player's library for a card and exile it. Then that player shuffles."; @@ -64,17 +58,16 @@ class ExtractEffect extends OneShotEffect { 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(1, 1, filter); - if (player.searchLibrary(target, source, game, targetPlayer.getId())) { - Card card = targetPlayer.getLibrary().remove(target.getFirstTarget(), game); - if (card != null) { - player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true); - } - } - targetPlayer.shuffleLibrary(source, game); - return true; + if (player == null || targetPlayer == null) { + return false; } - 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; } } diff --git a/Mage.Sets/src/mage/cards/g/GiftsUngiven.java b/Mage.Sets/src/mage/cards/g/GiftsUngiven.java index 34ef730d9f4..930e7e6d22b 100644 --- a/Mage.Sets/src/mage/cards/g/GiftsUngiven.java +++ b/Mage.Sets/src/mage/cards/g/GiftsUngiven.java @@ -12,7 +12,9 @@ import mage.players.Player; import mage.target.TargetCard; import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetOpponent; +import mage.util.CardUtil; +import java.util.Objects; import java.util.UUID; /** @@ -40,9 +42,13 @@ public final class GiftsUngiven extends CardImpl { class GiftsUngivenEffect extends OneShotEffect { + private static final FilterCard filter = new FilterCard("cards to put in graveyard"); + public GiftsUngivenEffect() { super(Outcome.DrawCard); - this.staticText = "Search your library for up to four cards with different names and reveal them. Target opponent chooses two of those cards. Put the chosen cards into your graveyard and the rest into your hand. Then shuffle"; + this.staticText = "Search your library for up to four cards with different names and reveal them. " + + "Target opponent chooses two of those cards. Put the chosen cards into your graveyard " + + "and the rest into your hand. Then shuffle"; } public GiftsUngivenEffect(final GiftsUngivenEffect effect) { @@ -57,54 +63,48 @@ class GiftsUngivenEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - Card sourceCard = game.getCard(source.getSourceId()); - if (player == null || sourceCard == null) { - return false; - } Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source)); - if (opponent == null) { + if (player == null || opponent == null) { return false; } GiftsUngivenTarget target = new GiftsUngivenTarget(); - 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); - - CardsImpl cardsToKeep = new CardsImpl(); - if (cards.size() > 2) { - cardsToKeep.addAll(cards); - TargetCard targetDiscard = new TargetCard(2, Zone.LIBRARY, new FilterCard("cards to put in graveyard")); - if (opponent.choose(Outcome.Discard, cards, targetDiscard, game)) { - cardsToKeep.removeAll(targetDiscard.getTargets()); - cards.removeAll(cardsToKeep); - } - } - - player.moveCards(cards, Zone.GRAVEYARD, source, game); - player.moveCards(cardsToKeep, Zone.HAND, source, game); - } + player.searchLibrary(target, source, game); + Cards cards = new CardsImpl(); + target.getTargets() + .stream() + .map(uuid -> player.getLibrary().getCard(uuid, game)) + .forEach(cards::add); + if (cards.isEmpty()) { player.shuffleLibrary(source, game); - return true; } + player.revealCards(source, cards, game); + + if (cards.size() > 2) { + Cards cardsToKeep = new CardsImpl(); + cardsToKeep.addAll(cards); + TargetCard targetDiscard = new TargetCard(2, Zone.LIBRARY, filter); + if (opponent.choose(Outcome.Discard, cards, targetDiscard, game)) { + cardsToKeep.removeIf(targetDiscard.getTargets()::contains); + cards.removeAll(cardsToKeep); + } + player.moveCards(cardsToKeep, Zone.HAND, source, game); + } + + player.moveCards(cards, Zone.GRAVEYARD, source, game); player.shuffleLibrary(source, game); - return false; + return true; } } class GiftsUngivenTarget extends TargetCardInLibrary { - public GiftsUngivenTarget() { - super(0, 4, new FilterCard("cards with different names")); + private static final FilterCard filter = new FilterCard("cards with different names"); + + GiftsUngivenTarget() { + super(0, 4, filter); } - public GiftsUngivenTarget(final GiftsUngivenTarget target) { + private GiftsUngivenTarget(final GiftsUngivenTarget target) { super(target); } @@ -115,16 +115,16 @@ class GiftsUngivenTarget extends TargetCardInLibrary { @Override public boolean canTarget(UUID playerId, UUID id, Ability source, Cards cards, Game game) { - Card card = cards.get(id, game); - if (card != null) { - for (UUID targetId : this.getTargets()) { - Card iCard = game.getCard(targetId); - if (iCard != null && iCard.getName().equals(card.getName())) { - return false; - } - } - return filter.match(card, playerId, game); + if (!super.canTarget(playerId, id, source, cards, game)) { + return false; } - return false; + Card card = cards.get(id, game); + return card != null + && this + .getTargets() + .stream() + .map(game::getCard) + .filter(Objects::nonNull) + .noneMatch(c -> CardUtil.haveSameNames(c, card)); } } diff --git a/Mage.Sets/src/mage/cards/g/GrinningTotem.java b/Mage.Sets/src/mage/cards/g/GrinningTotem.java index f9a1a54ddbe..68f87f212e3 100644 --- a/Mage.Sets/src/mage/cards/g/GrinningTotem.java +++ b/Mage.Sets/src/mage/cards/g/GrinningTotem.java @@ -1,8 +1,5 @@ - package mage.cards.g; -import java.util.UUID; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.DelayedTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; @@ -10,7 +7,6 @@ import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.AsThoughEffectImpl; -import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; @@ -19,26 +15,26 @@ import mage.constants.*; import mage.game.ExileZone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.players.Player; import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetOpponent; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; +import java.util.UUID; + /** - * * @author Quercitron */ public final class GrinningTotem extends CardImpl { public GrinningTotem(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{4}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}"); // {2}, {tap}, Sacrifice Grinning Totem: Search target opponent's library for a card and exile it. Then that player shuffles their library. // Until the beginning of your next upkeep, you may play that card. // At the beginning of your next upkeep, if you haven't played it, put it into its owner's graveyard. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GrinningTotemSearchAndExileEffect(), new ManaCostsImpl("{2}")); + Ability ability = new SimpleActivatedAbility(new GrinningTotemSearchAndExileEffect(), new ManaCostsImpl<>("{2}")); ability.addCost(new TapSourceCost()); ability.addCost(new SacrificeSourceCost()); ability.addTarget(new TargetOpponent()); @@ -63,7 +59,7 @@ class GrinningTotemSearchAndExileEffect extends OneShotEffect { "Until the beginning of your next upkeep, you may play that card. " + "At the beginning of your next upkeep, if you haven't played it, put it into its owner's graveyard"; } - + public GrinningTotemSearchAndExileEffect(final GrinningTotemSearchAndExileEffect effect) { super(effect); } @@ -72,45 +68,38 @@ class GrinningTotemSearchAndExileEffect extends OneShotEffect { public GrinningTotemSearchAndExileEffect copy() { return new GrinningTotemSearchAndExileEffect(this); } - + @Override public boolean apply(Game game, Ability source) { Player you = game.getPlayer(source.getControllerId()); Player targetOpponent = game.getPlayer(source.getFirstTarget()); - MageObject sourceObject = game.getObject(source.getSourceId()); - if (you != null && targetOpponent != null && sourceObject != null) { - if (targetOpponent.getLibrary().hasCards()) { - TargetCardInLibrary targetCard = new TargetCardInLibrary(); - if (you.searchLibrary(targetCard, source, game, targetOpponent.getId())) { - Card card = targetOpponent.getLibrary().remove(targetCard.getFirstTarget(), game); - if (card != null) { - UUID exileZoneId = CardUtil.getCardExileZoneId(game, source); - you.moveCardToExileWithInfo(card, exileZoneId, sourceObject.getIdName(), source, game, Zone.LIBRARY, true); - ContinuousEffect effect = new GrinningTotemMayPlayEffect(); - effect.setTargetPointer(new FixedTarget(card.getId())); - game.addEffect(effect, source); - - game.addDelayedTriggeredAbility(new GrinningTotemDelayedTriggeredAbility(exileZoneId), source); - } - } - } - targetOpponent.shuffleLibrary(source, game); - return true; + if (you == null || targetOpponent == null) { + return false; } - return false; + TargetCardInLibrary targetCard = new TargetCardInLibrary(); + you.searchLibrary(targetCard, source, game, targetOpponent.getId()); + Card card = targetOpponent.getLibrary().remove(targetCard.getFirstTarget(), game); + if (card != null) { + UUID exileZoneId = CardUtil.getCardExileZoneId(game, source); + you.moveCardsToExile(card, source, game, true, exileZoneId, CardUtil.getSourceName(game, source)); + game.addEffect(new GrinningTotemMayPlayEffect().setTargetPointer(new FixedTarget(card.getId())), source); + game.addDelayedTriggeredAbility(new GrinningTotemDelayedTriggeredAbility(exileZoneId), source); + } + targetOpponent.shuffleLibrary(source, game); + return true; } - + } class GrinningTotemMayPlayEffect extends AsThoughEffectImpl { - + private boolean sameStep = true; public GrinningTotemMayPlayEffect() { super(AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, Duration.Custom, Outcome.Benefit); this.staticText = "Until the beginning of your next upkeep, you may play that card."; } - + public GrinningTotemMayPlayEffect(final GrinningTotemMayPlayEffect effect) { super(effect); } @@ -131,7 +120,7 @@ class GrinningTotemMayPlayEffect extends AsThoughEffectImpl { } return false; } - + @Override public boolean apply(Game game, Ability source) { return true; @@ -142,7 +131,7 @@ class GrinningTotemMayPlayEffect extends AsThoughEffectImpl { return source.isControlledBy(affectedControllerId) && sourceId.equals(getTargetPointer().getFirst(game, source)); } - + } class GrinningTotemDelayedTriggeredAbility extends DelayedTriggeredAbility { @@ -194,7 +183,7 @@ class GrinningTotemPutIntoGraveyardEffect extends OneShotEffect { super(Outcome.Detriment); this.exileZoneId = exileZoneId; } - + public GrinningTotemPutIntoGraveyardEffect(final GrinningTotemPutIntoGraveyardEffect effect) { super(effect); this.exileZoneId = effect.exileZoneId; @@ -204,7 +193,7 @@ class GrinningTotemPutIntoGraveyardEffect extends OneShotEffect { public GrinningTotemPutIntoGraveyardEffect copy() { return new GrinningTotemPutIntoGraveyardEffect(this); } - + @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); @@ -214,5 +203,5 @@ class GrinningTotemPutIntoGraveyardEffect extends OneShotEffect { } return false; } - + } diff --git a/Mage.Sets/src/mage/cards/g/Grozoth.java b/Mage.Sets/src/mage/cards/g/Grozoth.java index efd51bc413e..9bafeffc8be 100644 --- a/Mage.Sets/src/mage/cards/g/Grozoth.java +++ b/Mage.Sets/src/mage/cards/g/Grozoth.java @@ -1,55 +1,57 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.effects.SearchEffect; import mage.abilities.effects.common.continuous.LoseAbilitySourceEffect; +import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect; import mage.abilities.keyword.DefenderAbility; import mage.abilities.keyword.TransmuteAbility; -import mage.cards.*; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.ComparisonType; import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.SubType; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.ManaValuePredicate; -import mage.game.Game; -import mage.players.Player; import mage.target.common.TargetCardInLibrary; +import java.util.UUID; + /** - * * @author fireshoes */ public final class Grozoth extends CardImpl { + private static final FilterCard filter = new FilterCard("cards that have mana value 9"); + + static { + filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, 9)); + } + public Grozoth(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{6}{U}{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{6}{U}{U}{U}"); this.subtype.add(SubType.LEVIATHAN); this.power = new MageInt(9); this.toughness = new MageInt(9); // Defender this.addAbility(DefenderAbility.getInstance()); - + // When Grozoth enters the battlefield, you may search your library for any number of cards that have converted mana cost 9, reveal them, and put them into your hand. If you do, shuffle your library. - this.addAbility(new EntersBattlefieldTriggeredAbility(new GrozothEffect(), true)); - + this.addAbility(new EntersBattlefieldTriggeredAbility(new SearchLibraryPutInHandEffect( + new TargetCardInLibrary(0, Integer.MAX_VALUE, filter), true, true + ), true)); + // {4}: Grozoth loses defender until end of turn. - this.addAbility(new SimpleActivatedAbility( - Zone.BATTLEFIELD, - new LoseAbilitySourceEffect(DefenderAbility.getInstance(), Duration.EndOfTurn), - new ManaCostsImpl("{4}"))); - + this.addAbility(new SimpleActivatedAbility(new LoseAbilitySourceEffect( + DefenderAbility.getInstance(), Duration.EndOfTurn + ), new ManaCostsImpl<>("{4}"))); + // Transmute {1}{U}{U} - this.addAbility(new TransmuteAbility("{1}{U}{U}")); + this.addAbility(new TransmuteAbility("{1}{U}{U}")); } private Grozoth(final Grozoth card) { @@ -61,48 +63,3 @@ public final class Grozoth extends CardImpl { return new Grozoth(this); } } - -class GrozothEffect extends SearchEffect { - - private static final FilterCard filter = new FilterCard(); - - static { - filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, 9)); - } - - public GrozothEffect() { - super(new TargetCardInLibrary(0, Integer.MAX_VALUE, filter), Outcome.DrawCard); - staticText = "search your library for any number of cards that have mana value 9, reveal them, put them into your hand, then shuffle"; - } - - public GrozothEffect(final GrozothEffect effect) { - super(effect); - } - - @Override - public GrozothEffect copy() { - return new GrozothEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(source.getControllerId()); - Card sourceCard = game.getCard(source.getSourceId()); - if (sourceCard != null && player != null && 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; - } - return false; - } -} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/h/HideSeek.java b/Mage.Sets/src/mage/cards/h/HideSeek.java index 632d508671b..3a54072136b 100644 --- a/Mage.Sets/src/mage/cards/h/HideSeek.java +++ b/Mage.Sets/src/mage/cards/h/HideSeek.java @@ -1,4 +1,3 @@ - package mage.cards.h; import mage.abilities.Ability; @@ -21,7 +20,6 @@ import mage.target.common.TargetOpponent; import java.util.UUID; /** - * * @author LevelX2 */ public final class HideSeek extends SplitCard { @@ -31,14 +29,13 @@ public final class HideSeek extends SplitCard { // Hide // Put target artifact or enchantment on the bottom of its owner's library. - getLeftHalfCard().getSpellAbility().addEffect(new PutOnLibraryTargetEffect(false)); - getLeftHalfCard().getSpellAbility().addTarget(new TargetPermanent(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT)); + this.getLeftHalfCard().getSpellAbility().addEffect(new PutOnLibraryTargetEffect(false)); + this.getLeftHalfCard().getSpellAbility().addTarget(new TargetPermanent(StaticFilters.FILTER_PERMANENT_ARTIFACT_OR_ENCHANTMENT)); // Seek // Search target opponent's library for a card and exile it. You gain life equal to its converted mana cost. Then that player shuffles their library.. - getRightHalfCard().getSpellAbility().addEffect(new SeekEffect()); - getRightHalfCard().getSpellAbility().addTarget(new TargetOpponent()); - + this.getRightHalfCard().getSpellAbility().addEffect(new SeekEffect()); + this.getRightHalfCard().getSpellAbility().addTarget(new TargetOpponent()); } private HideSeek(final HideSeek card) { @@ -71,24 +68,17 @@ class SeekEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player opponent = game.getPlayer(source.getFirstTarget()); Player player = game.getPlayer(source.getControllerId()); - if (player != null && opponent != null) { - if (opponent.getLibrary().hasCards()) { - TargetCardInLibrary target = new TargetCardInLibrary(); - if (player.searchLibrary(target, source, game, opponent.getId())) { - UUID targetId = target.getFirstTarget(); - Card card = opponent.getLibrary().remove(targetId, game); - if (card != null) { - player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true); - int cmc = card.getManaValue(); - if (cmc > 0) { - player.gainLife(cmc, game, source); - } - } - } - } - opponent.shuffleLibrary(source, game); - return true; + if (player == null || opponent == null) { + return false; } - return false; + TargetCardInLibrary target = new TargetCardInLibrary(); + player.searchLibrary(target, source, game, opponent.getId()); + Card card = opponent.getLibrary().getCard(target.getFirstTarget(), game); + if (card != null) { + player.moveCards(card, Zone.EXILED, source, game); + player.gainLife(card.getManaValue(), game, source); + } + opponent.shuffleLibrary(source, game); + return true; } } diff --git a/Mage.Sets/src/mage/cards/i/InsidiousDreams.java b/Mage.Sets/src/mage/cards/i/InsidiousDreams.java index af18bb4ef80..afe920eacf8 100644 --- a/Mage.Sets/src/mage/cards/i/InsidiousDreams.java +++ b/Mage.Sets/src/mage/cards/i/InsidiousDreams.java @@ -1,18 +1,18 @@ package mage.cards.i; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.costs.common.DiscardXTargetCost; import mage.abilities.dynamicvalue.common.GetXValue; import mage.abilities.effects.OneShotEffect; -import mage.cards.*; +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.FilterCard; +import mage.filter.StaticFilters; import mage.game.Game; import mage.players.Player; -import mage.target.TargetCard; import mage.target.common.TargetCardInLibrary; import java.util.UUID; @@ -26,11 +26,10 @@ public final class InsidiousDreams extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{3}{B}"); // As an additional cost to cast Insidious Dreams, discard X cards. - this.getSpellAbility().addCost(new DiscardXTargetCost(new FilterCard("cards"), true)); + this.getSpellAbility().addCost(new DiscardXTargetCost(StaticFilters.FILTER_CARD_CARDS, true)); // Search your library for X cards. Then shuffle your library and put those cards on top of it in any order. this.getSpellAbility().addEffect(new InsidiousDreamsEffect()); - } private InsidiousDreams(final InsidiousDreams card) { @@ -45,8 +44,6 @@ public final class InsidiousDreams extends CardImpl { class InsidiousDreamsEffect extends OneShotEffect { - static final private String textTop = "card to put on your library (last chosen will be on top)"; - public InsidiousDreamsEffect() { super(Outcome.Benefit); this.staticText = "Search your library for up to X cards. Then shuffle and put those cards on top of it in any order"; @@ -64,39 +61,17 @@ class InsidiousDreamsEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = game.getObject(source.getSourceId()); - int amount = GetXValue.instance.calculate(game, source, this); - - if (controller != null && sourceObject != null) { - TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard()); - if (controller.searchLibrary(target, source, game)) { - Cards chosen = new CardsImpl(); - for (UUID cardId : target.getTargets()) { - Card card = controller.getLibrary().remove(cardId, game); - chosen.add(card); - } - controller.shuffleLibrary(source, game); - - TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop)); - - while (chosen.size() > 1 && controller.canRespond()) { - controller.choose(Outcome.Neutral, chosen, targetToLib, game); - Card card = chosen.get(targetToLib.getFirstTarget(), game); - if (card != null) { - chosen.remove(card); - controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false); - - } - targetToLib.clearChosen(); - } - - if (chosen.size() == 1) { - Card card = chosen.get(chosen.iterator().next(), game); - controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false); - } - } - return true; + if (controller == null) { + return false; } - return false; + TargetCardInLibrary target = new TargetCardInLibrary( + 0, GetXValue.instance.calculate(game, source, this), StaticFilters.FILTER_CARD_CARDS + ); + controller.searchLibrary(target, source, game); + Cards chosen = new CardsImpl(); + target.getTargets().stream().forEach(cardId -> controller.getLibrary().getCard(cardId, game)); + controller.shuffleLibrary(source, game); + controller.putCardsOnTopOfLibrary(chosen, game, source, true); + return true; } } diff --git a/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java b/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java index f30379f876d..b14153cddbb 100644 --- a/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java +++ b/Mage.Sets/src/mage/cards/j/JaceArchitectOfThought.java @@ -8,25 +8,19 @@ import mage.abilities.effects.common.continuous.BoostTargetEffect; import mage.cards.*; import mage.constants.*; import mage.filter.FilterCard; -import mage.filter.FilterPlayer; -import mage.filter.common.FilterNonlandCard; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.other.PlayerIdPredicate; -import mage.game.ExileZone; +import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetCard; -import mage.target.TargetPlayer; -import mage.target.common.TargetCardInExile; import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetOpponent; import mage.target.targetpointer.FixedTarget; import mage.util.CardUtil; -import java.util.*; -import mage.ApprovingObject; +import java.util.ArrayList; +import java.util.Set; +import java.util.UUID; /** * @author LevelX2 @@ -50,7 +44,6 @@ public final class JaceArchitectOfThought extends CardImpl { // -8: For each player, search that player's library for a nonland card and exile it, // then that player shuffles their library. You may cast those cards without paying their mana costs. this.addAbility(new LoyaltyAbility(new JaceArchitectOfThoughtEffect3(), -8)); - } private JaceArchitectOfThought(final JaceArchitectOfThought card) { @@ -90,7 +83,7 @@ class JaceArchitectOfThoughtStartEffect1 extends OneShotEffect { class JaceArchitectOfThoughtDelayedTriggeredAbility extends DelayedTriggeredAbility { - private int startingTurn; + private final int startingTurn; public JaceArchitectOfThoughtDelayedTriggeredAbility(int startingTurn) { super(new BoostTargetEffect(-1, 0, Duration.EndOfTurn), Duration.Custom, false); @@ -228,83 +221,33 @@ class JaceArchitectOfThoughtEffect3 extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); - if (controller == null || sourcePermanent == null) { + if (controller == null) { return false; } - if (controller.chooseUse(Outcome.Benefit, "Look at all players' libraries before card select?", null, game)) { + if (controller.chooseUse(Outcome.Benefit, "Look at all players' libraries before card select?", source, game)) { game.informPlayers(controller.getLogName() + " is looking at all players' libraries."); controller.lookAtAllLibraries(source, game); } - List playerList = new ArrayList<>(); - playerList.addAll(game.getState().getPlayersInRange(controller.getId(), game)); - Set checkList = new HashSet<>(); - while (!playerList.isEmpty()) { - FilterPlayer filter = new FilterPlayer(); - List playerPredicates = new ArrayList<>(); - playerList.forEach((playerId) -> { - playerPredicates.add(new PlayerIdPredicate(playerId)); - }); - filter.add(Predicates.or(playerPredicates)); - TargetPlayer targetPlayer = new TargetPlayer(1, 1, true, filter); - targetPlayer.setRequired(!checkList.containsAll(playerList)); - if (controller.chooseTarget(outcome, targetPlayer, source, game)) { - UUID playerId = targetPlayer.getFirstTarget(); - Player player = game.getPlayer(playerId); - if (player != null) { - String playerName = player.getLogName() + "'s"; - if (source.isControlledBy(player.getId())) { - playerName = "your"; - } - TargetCardInLibrary target = new TargetCardInLibrary(new FilterNonlandCard("nonland card from " + playerName + " library")); - if (controller.searchLibrary(target, source, game, playerId)) { - checkList.add(playerId); - UUID targetId = target.getFirstTarget(); - Card card = player.getLibrary().remove(targetId, game); - if (card != null) { - controller.moveCardsToExile(card, source, game, true, CardUtil.getCardExileZoneId(game, source), sourcePermanent.getName()); - playerList.remove(playerId); - } - } else { - playerList.remove(playerId); - } - } else { - playerList.remove(playerId); - } - } else { - break; + Cards cards = new CardsImpl(); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + Player player = game.getPlayer(playerId); + if (player == null) { + continue; } - - // remove disconnected or quit players - playerList.removeIf(playerId -> game.getPlayer(playerId) == null || !game.getPlayer(playerId).canRespond()); - } - checkList.stream().map((playerId) -> game.getPlayer(playerId)).filter((player) -> (player != null)).forEachOrdered((player) -> { + TargetCardInLibrary target = new TargetCardInLibrary( + 0, 1, StaticFilters.FILTER_CARD_A_NON_LAND + ); + controller.searchLibrary(target, source, game, playerId); + Card card = player.getLibrary().getCard(target.getFirstTarget(), game); + if (card == null) { + continue; + } + cards.add(card); + controller.moveCards(card, Zone.EXILED, source, game); player.shuffleLibrary(source, game); - }); - ExileZone jaceExileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); - if (jaceExileZone == null) { - return true; - } - FilterCard filter = new FilterCard("card to cast without mana costs"); - TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId()); - Cards cardsToChoose = new CardsImpl(jaceExileZone.getCards(game)); - while (controller.canRespond() - && cardsToChoose.count(filter, game) > 0 - && controller.chooseUse(Outcome.Benefit, "Cast another spell from exile zone for free?", source, game)) { - controller.choose(Outcome.PlayForFree, cardsToChoose, target, game); - Card card = game.getCard(target.getFirstTarget()); - if (card != null) { - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE); - Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), - game, true, new ApprovingObject(source, game)); - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null); - cardsToChoose.remove(card); - if (cardWasCast) { - game.getExile().removeCard(card, game); - } - } - target.clearChosen(); } + cards.retainZone(Zone.EXILED, game); + CardUtil.castMultipleWithAttributeForFree(controller, source, game, cards, StaticFilters.FILTER_CARD); return true; } } diff --git a/Mage.Sets/src/mage/cards/l/LongTermPlans.java b/Mage.Sets/src/mage/cards/l/LongTermPlans.java index 3b799b4e2a2..a5b82b22f8b 100644 --- a/Mage.Sets/src/mage/cards/l/LongTermPlans.java +++ b/Mage.Sets/src/mage/cards/l/LongTermPlans.java @@ -1,7 +1,5 @@ - package mage.cards.l; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; @@ -13,8 +11,9 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInLibrary; +import java.util.UUID; + /** - * * @author emerald000 */ public final class LongTermPlans extends CardImpl { @@ -55,18 +54,16 @@ class LongTermPlansEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - TargetCardInLibrary target = new TargetCardInLibrary(); - if (player.searchLibrary(target, source, game)) { - Card card = player.getLibrary().remove(target.getFirstTarget(), game); - if (card != null) { - player.shuffleLibrary(source, game); - // must hides the card name from other players - player.putCardOnTopXOfLibrary(card, game, source, 3, false); - } - } - return true; + if (player == null) { + return false; } - return false; + TargetCardInLibrary target = new TargetCardInLibrary(); + player.searchLibrary(target, source, game); + Card card = player.getLibrary().getCard(target.getFirstTarget(), game); + player.shuffleLibrary(source, game); + if (card != null) { + player.putCardOnTopXOfLibrary(card, game, source, 3, false); + } + return true; } }