From 966cb7ccb723c4789c5da7bf3f6f116d5dcf0aa8 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 16 Mar 2022 17:29:49 -0400 Subject: [PATCH] replaced some cast for free effects with newer method --- .../src/mage/cards/a/AllureOfTheUnknown.java | 11 +-- Mage.Sets/src/mage/cards/b/BringToLight.java | 57 ++++++-------- Mage.Sets/src/mage/cards/c/ChaosWand.java | 25 ++---- .../src/mage/cards/c/CreativeTechnique.java | 15 +--- .../src/mage/cards/d/DazzlingSphinx.java | 18 +---- .../src/mage/cards/d/DescendantsPath.java | 76 +++++++------------ Mage/src/main/java/mage/util/CardUtil.java | 5 ++ 7 files changed, 71 insertions(+), 136 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AllureOfTheUnknown.java b/Mage.Sets/src/mage/cards/a/AllureOfTheUnknown.java index ec7bd69d8f7..b48c1b930a2 100644 --- a/Mage.Sets/src/mage/cards/a/AllureOfTheUnknown.java +++ b/Mage.Sets/src/mage/cards/a/AllureOfTheUnknown.java @@ -12,9 +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.UUID; -import mage.ApprovingObject; /** * @author TheElk801 @@ -85,12 +85,7 @@ class AllureOfTheUnknownEffect extends OneShotEffect { cards.remove(card); } player.moveCards(cards, Zone.HAND, source, game); - if (opponent.chooseUse(outcome, "Cast the exiled card without paying its mana cost?", source, game)) { - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE); - opponent.cast(opponent.chooseAbilityForCast(card, game, true), - game, true, new ApprovingObject(source, game)); - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null); - } + CardUtil.castSpellWithAttributesForFree(opponent, source, game, card); return true; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/cards/b/BringToLight.java b/Mage.Sets/src/mage/cards/b/BringToLight.java index 5e229d42f1c..795f1e95e7f 100644 --- a/Mage.Sets/src/mage/cards/b/BringToLight.java +++ b/Mage.Sets/src/mage/cards/b/BringToLight.java @@ -1,23 +1,21 @@ package mage.cards.b; -import java.util.UUID; -import mage.ApprovingObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.common.ColorsOfManaSpentToCastCount; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.ComparisonType; -import mage.constants.Outcome; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.FilterCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.ManaValuePredicate; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInLibrary; +import mage.util.CardUtil; + +import java.util.UUID; /** * @author LevelX2 @@ -31,6 +29,7 @@ public final class BringToLight extends CardImpl { // cost less than or equal to the number of colors of mana spent to cast Bring to Light, exile that card, // then shuffle your library. You may cast that card without paying its mana cost. this.getSpellAbility().addEffect(new BringToLightEffect()); + this.getSpellAbility().setAbilityWord(AbilityWord.CONVERGE); } private BringToLight(final BringToLight card) { @@ -47,8 +46,8 @@ class BringToLightEffect extends OneShotEffect { public BringToLightEffect() { super(Outcome.PlayForFree); - this.staticText = "Converge — Search your library for a creature, instant, or sorcery card with mana " - + "value less than or equal to the number of colors of mana spent to cast this spell, exile that card, " + this.staticText = "search your library for a creature, instant, or sorcery card with mana value " + + "less than or equal to the number of colors of mana spent to cast this spell, exile that card, " + "then shuffle. You may cast that card without paying its mana cost"; } @@ -64,31 +63,23 @@ class BringToLightEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - int numberColors = ColorsOfManaSpentToCastCount.getInstance().calculate(game, source, this); - FilterCard filter = new FilterCard("a creature, instant, or sorcery card with mana value " - + "less than or equal to " + numberColors); - filter.add(Predicates.or(CardType.CREATURE.getPredicate(), - CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate())); - filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, numberColors + 1)); - TargetCardInLibrary target = new TargetCardInLibrary(filter); - controller.searchLibrary(target, source, game); - Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); - if (card != null) { - controller.moveCards(card, Zone.EXILED, source, game); - } - controller.shuffleLibrary(source, game); - if (card != null) { - if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() - + " without paying its mana cost?", source, game)) { - 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); - } - } - return true; + if (controller == null) { + return false; } - return false; + int numberColors = ColorsOfManaSpentToCastCount.getInstance().calculate(game, source, this); + FilterCard filter = new FilterCard("a creature, instant, or sorcery card with mana value " + + "less than or equal to " + numberColors); + filter.add(Predicates.or(CardType.CREATURE.getPredicate(), + CardType.INSTANT.getPredicate(), CardType.SORCERY.getPredicate())); + filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, numberColors + 1)); + TargetCardInLibrary target = new TargetCardInLibrary(filter); + controller.searchLibrary(target, source, game); + Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); + if (card != null) { + controller.moveCards(card, Zone.EXILED, source, game); + } + controller.shuffleLibrary(source, game); + CardUtil.castSpellWithAttributesForFree(controller, source, game, card); + return true; } } diff --git a/Mage.Sets/src/mage/cards/c/ChaosWand.java b/Mage.Sets/src/mage/cards/c/ChaosWand.java index 9fc955531ee..0f9fd6e5693 100644 --- a/Mage.Sets/src/mage/cards/c/ChaosWand.java +++ b/Mage.Sets/src/mage/cards/c/ChaosWand.java @@ -12,9 +12,9 @@ import mage.constants.Zone; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetOpponent; +import mage.util.CardUtil; import java.util.UUID; -import mage.ApprovingObject; /** * @author TheElk801 @@ -28,10 +28,7 @@ public final class ChaosWand extends CardImpl { // until they exile an instant or sorcery card. You may cast that card // without paying its mana cost. Then put the exiled cards that weren't // cast this way on the bottom of that library in a random order. - Ability ability = new SimpleActivatedAbility( - new ChaosWandEffect(), - new GenericManaCost(4) - ); + Ability ability = new SimpleActivatedAbility(new ChaosWandEffect(), new GenericManaCost(4)); ability.addCost(new TapSourceCost()); ability.addTarget(new TargetOpponent()); this.addAbility(ability); @@ -80,25 +77,15 @@ class ChaosWandEffect extends OneShotEffect { if (card == null) { break; } + cardsToShuffle.add(card); opponent.moveCards(card, Zone.EXILED, source, game); - controller.revealCards(source, new CardsImpl(card), game); if (card.isInstantOrSorcery(game)) { - boolean cardWasCast = false; - if (controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getName() - + " without paying its mana cost?", source, game)) { - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE); - cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), - game, true, new ApprovingObject(source, game)); - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null); - } - if (!cardWasCast) { - cardsToShuffle.add(card); - } + CardUtil.castSpellWithAttributesForFree(controller, source, game, card); break; - } else { - cardsToShuffle.add(card); } } + cardsToShuffle.retainZone(Zone.EXILED, game); + controller.revealCards(source, cardsToShuffle, game); return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false); } } diff --git a/Mage.Sets/src/mage/cards/c/CreativeTechnique.java b/Mage.Sets/src/mage/cards/c/CreativeTechnique.java index 8ad5c336c5a..a243785617b 100644 --- a/Mage.Sets/src/mage/cards/c/CreativeTechnique.java +++ b/Mage.Sets/src/mage/cards/c/CreativeTechnique.java @@ -1,6 +1,5 @@ package mage.cards.c; -import mage.ApprovingObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.DemonstrateAbility; @@ -10,6 +9,7 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.players.Player; +import mage.util.CardUtil; import java.util.UUID; @@ -78,18 +78,7 @@ class CreativeTechniqueEffect extends OneShotEffect { player.moveCards(toCast, Zone.EXILED, source, game); } player.putCardsOnBottomOfLibrary(cards, game, source, false); - if (toCast == null || !player.chooseUse( - Outcome.PlayForFree, "Cast " + toCast.getIdName() - + " without paying its mana cost?", source, game - )) { - return true; - } - game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE); - player.cast( - player.chooseAbilityForCast(toCast, game, true), - game, true, new ApprovingObject(source, game) - ); - game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null); + CardUtil.castSpellWithAttributesForFree(player, source, game, toCast); return true; } } diff --git a/Mage.Sets/src/mage/cards/d/DazzlingSphinx.java b/Mage.Sets/src/mage/cards/d/DazzlingSphinx.java index 172a3f0a1f8..50f72e6b55e 100644 --- a/Mage.Sets/src/mage/cards/d/DazzlingSphinx.java +++ b/Mage.Sets/src/mage/cards/d/DazzlingSphinx.java @@ -1,6 +1,5 @@ package mage.cards.d; -import mage.ApprovingObject; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; @@ -13,6 +12,7 @@ import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; import mage.players.Player; +import mage.util.CardUtil; import java.util.UUID; @@ -73,24 +73,14 @@ class DazzlingSphinxEffect extends OneShotEffect { return false; } Cards cards = new CardsImpl(); - Card toCast = null; for (Card card : opponent.getLibrary().getCards(game)) { cards.add(card); + opponent.moveCards(card, Zone.EXILED, source, game); if (card.isInstantOrSorcery(game)) { - toCast = card; + CardUtil.castSpellWithAttributesForFree(controller, source, game, card); + break; } } - opponent.moveCards(cards, Zone.EXILED, source, game); - if (toCast != null && controller.chooseUse( - outcome, "Cast " + toCast.getName() + " without paying its mana cost?", source, game - )) { - game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), Boolean.TRUE); - controller.cast( - controller.chooseAbilityForCast(toCast, game, true), - game, true, new ApprovingObject(source, game) - ); - game.getState().setValue("PlayFromNotOwnHandZone" + toCast.getId(), null); - } cards.retainZone(Zone.EXILED, game); opponent.putCardsOnBottomOfLibrary(cards, game, source, false); return true; diff --git a/Mage.Sets/src/mage/cards/d/DescendantsPath.java b/Mage.Sets/src/mage/cards/d/DescendantsPath.java index 60ea0e591d7..f2eb872f118 100644 --- a/Mage.Sets/src/mage/cards/d/DescendantsPath.java +++ b/Mage.Sets/src/mage/cards/d/DescendantsPath.java @@ -1,8 +1,5 @@ package mage.cards.d; -import java.util.UUID; -import mage.ApprovingObject; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.effects.OneShotEffect; @@ -13,15 +10,16 @@ import mage.cards.CardsImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.TargetController; -import mage.filter.common.FilterControlledCreaturePermanent; +import mage.constants.Zone; +import mage.filter.StaticFilters; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.players.Player; +import mage.util.CardUtil; + +import java.util.UUID; /** - * * @author noxx - * */ public final class DescendantsPath extends CardImpl { @@ -31,8 +29,7 @@ public final class DescendantsPath extends CardImpl { // At the beginning of your upkeep, reveal the top card of your library. // If it's a creature card that shares a creature type with a creature you control, // you may cast that card without paying its mana cost. Otherwise, put that card on the bottom of your library. - Ability ability = new BeginningOfUpkeepTriggeredAbility(new DescendantsPathEffect(), TargetController.YOU, false); - this.addAbility(ability); + this.addAbility(new BeginningOfUpkeepTriggeredAbility(new DescendantsPathEffect(), TargetController.YOU, false)); } private DescendantsPath(final DescendantsPath card) { @@ -67,46 +64,27 @@ class DescendantsPathEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = source.getSourceObject(game); - if (controller != null && sourceObject != null) { - if (controller.getLibrary().hasCards()) { - Card card = controller.getLibrary().getFromTop(game); - if (card == null) { - return false; - } - controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game); - if (card.isCreature(game)) { - FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); - boolean found = false; - for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) { - if (card.shareCreatureTypes(game, permanent)) { - found = true; - break; - } - } - if (found) { - game.informPlayers(sourceObject.getLogName() + ": Found a creature that shares a creature type with the revealed card."); - if (controller.chooseUse(Outcome.Benefit, "Cast the card?", source, game)) { - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE); - controller.cast(controller.chooseAbilityForCast(card, game, true), - game, true, new ApprovingObject(source, game)); - game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null); - } else { - game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " canceled casting the card."); - controller.getLibrary().putOnBottom(card, game); - } - } else { - game.informPlayers(sourceObject.getLogName() + ": No creature that shares a creature type with the revealed card."); - controller.getLibrary().putOnBottom(card, game); - } - } else { - game.informPlayers(sourceObject.getLogName() + ": Put " + card.getLogName() + " on the bottom."); - controller.getLibrary().putOnBottom(card, game); - } - - return true; - } + if (controller == null) { + return false; } - return false; + Card card = controller.getLibrary().getFromTop(game); + if (card == null) { + return false; + } + controller.revealCards(source, new CardsImpl(card), game); + if (card.isCreature(game) + && game + .getBattlefield() + .getActivePermanents( + StaticFilters.FILTER_CONTROLLED_CREATURE, + source.getControllerId(), source.getControllerId(), game + ).stream() + .anyMatch(permanent -> permanent.shareCreatureTypes(game, card))) { + CardUtil.castSpellWithAttributesForFree(controller, source, game, card); + } + if (game.getState().getZone(card.getId()) == Zone.LIBRARY) { + controller.putCardsOnBottomOfLibrary(card, game, source, false); + } + return true; } } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 9af3ac25ff0..6d5236433f0 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -25,6 +25,7 @@ import mage.constants.*; import mage.counters.Counter; import mage.filter.Filter; import mage.filter.FilterCard; +import mage.filter.StaticFilters; import mage.filter.predicate.mageobject.NamePredicate; import mage.game.CardState; import mage.game.Game; @@ -1231,6 +1232,10 @@ public final class CardUtil { private static final FilterCard defaultFilter = new FilterCard("card to cast"); + public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Card card) { + return castSpellWithAttributesForFree(player, source, game, new CardsImpl(card), StaticFilters.FILTER_CARD); + } + public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Cards cards, FilterCard filter) { return castSpellWithAttributesForFree(player, source, game, cards, filter, null); }