From 5be6e9398aaacc7e1bcf6aaebf276a1333d2e776 Mon Sep 17 00:00:00 2001 From: jeffwadsworth Date: Fri, 10 Jul 2020 16:14:05 -0500 Subject: [PATCH] - Fixed #6803 --- Mage.Sets/src/mage/cards/t/TwinningGlass.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/Mage.Sets/src/mage/cards/t/TwinningGlass.java b/Mage.Sets/src/mage/cards/t/TwinningGlass.java index fee84016c8..64d6480603 100644 --- a/Mage.Sets/src/mage/cards/t/TwinningGlass.java +++ b/Mage.Sets/src/mage/cards/t/TwinningGlass.java @@ -1,5 +1,6 @@ package mage.cards.t; +import java.util.ArrayList; import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; @@ -12,17 +13,17 @@ import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Zone; -import mage.filter.FilterCard; import mage.filter.predicate.Predicates; -import mage.filter.predicate.mageobject.NamePredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.players.Player; import mage.watchers.common.SpellsCastWatcher; - import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; +import mage.filter.common.FilterNonlandCard; +import mage.filter.predicate.mageobject.NamePredicate; import mage.target.TargetCard; /** @@ -72,8 +73,7 @@ class TwinningGlassEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - FilterCard filterCard = new FilterCard(); - filterCard.add(Predicates.not(CardType.LAND.getPredicate())); + List spells = new ArrayList<>(); Permanent twinningGlass = game.getPermanent(source.getSourceId()); Player controller = game.getPlayer(source.getControllerId()); SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class); @@ -84,19 +84,28 @@ class TwinningGlassEffect extends OneShotEffect { && controller != null && watcher != null) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { - List spells = watcher.getSpellsCastThisTurn(playerId); - if (spells != null - && !spells.isEmpty()) { - for (Spell spell : spells) { - filterCard.add(new NamePredicate(spell.getName())); + if (watcher.getSpellsCastThisTurn(playerId) != null) { + for (Spell spell : watcher.getSpellsCastThisTurn(playerId)) { + spells.add(spell); } } } + if (spells.isEmpty()) { + return false; + } + List predicates = spells.stream() + .map(Spell::getName) + .filter(s -> !"".equals(s)) + .map(NamePredicate::new) + .collect(Collectors.toList()); + FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn"); + filterCard.add(Predicates.or(predicates)); TargetCard target = new TargetCard(0, 1, Zone.HAND, filterCard); if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) { Card chosenCard = game.getCard(target.getFirstTarget()); if (chosenCard != null) { - if (controller.chooseUse(Outcome.PlayForFree, "Cast the card without paying mana cost?", source, game)) { + if (controller.chooseUse(Outcome.PlayForFree, "Cast " + + chosenCard.getName() + " without paying its mana cost?", source, game)) { game.getState().setValue("PlayFromNotOwnHandZone" + chosenCard.getId(), Boolean.TRUE); Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(chosenCard, game, true), game, true, new MageObjectReference(source.getSourceObject(game), game));