replaced some cast for free effects with newer method

This commit is contained in:
Evan Kranzler 2022-03-16 17:29:49 -04:00
parent 8b7a5c370a
commit 966cb7ccb7
7 changed files with 71 additions and 136 deletions

View file

@ -12,9 +12,9 @@ import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
import mage.ApprovingObject;
/** /**
* @author TheElk801 * @author TheElk801
@ -85,12 +85,7 @@ class AllureOfTheUnknownEffect extends OneShotEffect {
cards.remove(card); cards.remove(card);
} }
player.moveCards(cards, Zone.HAND, source, game); player.moveCards(cards, Zone.HAND, source, game);
if (opponent.chooseUse(outcome, "Cast the exiled card without paying its mana cost?", source, game)) { CardUtil.castSpellWithAttributesForFree(opponent, source, game, card);
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);
}
return true; return true;
} }
} }

View file

@ -1,23 +1,21 @@
package mage.cards.b; package mage.cards.b;
import java.util.UUID;
import mage.ApprovingObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.dynamicvalue.common.ColorsOfManaSpentToCastCount; import mage.abilities.dynamicvalue.common.ColorsOfManaSpentToCastCount;
import mage.abilities.effects.OneShotEffect; 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.constants.CardType; import mage.constants.*;
import mage.constants.ComparisonType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.ManaValuePredicate; import mage.filter.predicate.mageobject.ManaValuePredicate;
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.util.CardUtil;
import java.util.UUID;
/** /**
* @author LevelX2 * @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, // 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. // then shuffle your library. You may cast that card without paying its mana cost.
this.getSpellAbility().addEffect(new BringToLightEffect()); this.getSpellAbility().addEffect(new BringToLightEffect());
this.getSpellAbility().setAbilityWord(AbilityWord.CONVERGE);
} }
private BringToLight(final BringToLight card) { private BringToLight(final BringToLight card) {
@ -47,8 +46,8 @@ class BringToLightEffect extends OneShotEffect {
public BringToLightEffect() { public BringToLightEffect() {
super(Outcome.PlayForFree); super(Outcome.PlayForFree);
this.staticText = "<i>Converge</i> &mdash; Search your library for a creature, instant, or sorcery card with mana " this.staticText = "search your library for a creature, instant, or sorcery card with mana value " +
+ "value less than or equal to the number of colors of mana spent to cast this spell, exile that card, " "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"; + "then shuffle. You may cast that card without paying its mana cost";
} }
@ -64,7 +63,9 @@ class BringToLightEffect 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());
if (controller != null) { if (controller == null) {
return false;
}
int numberColors = ColorsOfManaSpentToCastCount.getInstance().calculate(game, source, this); int numberColors = ColorsOfManaSpentToCastCount.getInstance().calculate(game, source, this);
FilterCard filter = new FilterCard("a creature, instant, or sorcery card with mana value " FilterCard filter = new FilterCard("a creature, instant, or sorcery card with mana value "
+ "less than or equal to " + numberColors); + "less than or equal to " + numberColors);
@ -78,17 +79,7 @@ class BringToLightEffect extends OneShotEffect {
controller.moveCards(card, Zone.EXILED, source, game); controller.moveCards(card, Zone.EXILED, source, game);
} }
controller.shuffleLibrary(source, game); controller.shuffleLibrary(source, game);
if (card != null) { CardUtil.castSpellWithAttributesForFree(controller, source, game, card);
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; return true;
} }
return false;
}
} }

View file

@ -12,9 +12,9 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
import mage.ApprovingObject;
/** /**
* @author TheElk801 * @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 // 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 // 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. // cast this way on the bottom of that library in a random order.
Ability ability = new SimpleActivatedAbility( Ability ability = new SimpleActivatedAbility(new ChaosWandEffect(), new GenericManaCost(4));
new ChaosWandEffect(),
new GenericManaCost(4)
);
ability.addCost(new TapSourceCost()); ability.addCost(new TapSourceCost());
ability.addTarget(new TargetOpponent()); ability.addTarget(new TargetOpponent());
this.addAbility(ability); this.addAbility(ability);
@ -80,25 +77,15 @@ class ChaosWandEffect extends OneShotEffect {
if (card == null) { if (card == null) {
break; break;
} }
cardsToShuffle.add(card);
opponent.moveCards(card, Zone.EXILED, source, game); opponent.moveCards(card, Zone.EXILED, source, game);
controller.revealCards(source, new CardsImpl(card), game);
if (card.isInstantOrSorcery(game)) { if (card.isInstantOrSorcery(game)) {
boolean cardWasCast = false; CardUtil.castSpellWithAttributesForFree(controller, source, game, card);
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);
}
break; break;
} else {
cardsToShuffle.add(card);
} }
} }
cardsToShuffle.retainZone(Zone.EXILED, game);
controller.revealCards(source, cardsToShuffle, game);
return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false); return opponent.putCardsOnBottomOfLibrary(cardsToShuffle, game, source, false);
} }
} }

View file

@ -1,6 +1,5 @@
package mage.cards.c; package mage.cards.c;
import mage.ApprovingObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.DemonstrateAbility; import mage.abilities.keyword.DemonstrateAbility;
@ -10,6 +9,7 @@ import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -78,18 +78,7 @@ class CreativeTechniqueEffect extends OneShotEffect {
player.moveCards(toCast, Zone.EXILED, source, game); player.moveCards(toCast, Zone.EXILED, source, game);
} }
player.putCardsOnBottomOfLibrary(cards, game, source, false); player.putCardsOnBottomOfLibrary(cards, game, source, false);
if (toCast == null || !player.chooseUse( CardUtil.castSpellWithAttributesForFree(player, source, game, toCast);
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);
return true; return true;
} }
} }

View file

@ -1,6 +1,5 @@
package mage.cards.d; package mage.cards.d;
import mage.ApprovingObject;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
@ -13,6 +12,7 @@ import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
@ -73,24 +73,14 @@ class DazzlingSphinxEffect extends OneShotEffect {
return false; return false;
} }
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
Card toCast = null;
for (Card card : opponent.getLibrary().getCards(game)) { for (Card card : opponent.getLibrary().getCards(game)) {
cards.add(card); cards.add(card);
opponent.moveCards(card, Zone.EXILED, source, game);
if (card.isInstantOrSorcery(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); cards.retainZone(Zone.EXILED, game);
opponent.putCardsOnBottomOfLibrary(cards, game, source, false); opponent.putCardsOnBottomOfLibrary(cards, game, source, false);
return true; return true;

View file

@ -1,8 +1,5 @@
package mage.cards.d; package mage.cards.d;
import java.util.UUID;
import mage.ApprovingObject;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -13,15 +10,16 @@ import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil;
import java.util.UUID;
/** /**
*
* @author noxx * @author noxx
*
*/ */
public final class DescendantsPath extends CardImpl { 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. // 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, // 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. // 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(new BeginningOfUpkeepTriggeredAbility(new DescendantsPathEffect(), TargetController.YOU, false));
this.addAbility(ability);
} }
private DescendantsPath(final DescendantsPath card) { private DescendantsPath(final DescendantsPath card) {
@ -67,46 +64,27 @@ class DescendantsPathEffect 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); if (controller == null) {
if (controller != null && sourceObject != null) { return false;
if (controller.getLibrary().hasCards()) { }
Card card = controller.getLibrary().getFromTop(game); Card card = controller.getLibrary().getFromTop(game);
if (card == null) { if (card == null) {
return false; return false;
} }
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game); controller.revealCards(source, new CardsImpl(card), game);
if (card.isCreature(game)) { if (card.isCreature(game)
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(); && game
boolean found = false; .getBattlefield()
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) { .getActivePermanents(
if (card.shareCreatureTypes(game, permanent)) { StaticFilters.FILTER_CONTROLLED_CREATURE,
found = true; source.getControllerId(), source.getControllerId(), game
break; ).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);
} }
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; return true;
} }
}
return false;
}
} }

View file

@ -25,6 +25,7 @@ import mage.constants.*;
import mage.counters.Counter; import mage.counters.Counter;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.StaticFilters;
import mage.filter.predicate.mageobject.NamePredicate; import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.CardState; import mage.game.CardState;
import mage.game.Game; import mage.game.Game;
@ -1231,6 +1232,10 @@ public final class CardUtil {
private static final FilterCard defaultFilter = new FilterCard("card to cast"); 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) { public static boolean castSpellWithAttributesForFree(Player player, Ability source, Game game, Cards cards, FilterCard filter) {
return castSpellWithAttributesForFree(player, source, game, cards, filter, null); return castSpellWithAttributesForFree(player, source, game, cards, filter, null);
} }