mirror of
https://github.com/correl/mage.git
synced 2024-11-14 11:09:31 +00:00
replaced some cast for free effects with newer method
This commit is contained in:
parent
8b7a5c370a
commit
966cb7ccb7
7 changed files with 71 additions and 136 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = "<i>Converge</i> — 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue